Subtree Filtering

Overview

Subtree filtering allows an application to include particular XML subtrees in the <rpc-reply> elements for a <get> or <get-config> operation.

Subtree filtering provides a small set of filters for inclusion, simple content exact-match, and selection. The NETCONF agent does not need to use any data-model-specific semantics during processing, allowing for simple and centralized implementation policies.

Subtree Filter Components

Each node specified in subtree filtering represents a filter. The filter only selects nodes associated with the basic data model of a specified database on the NETCONF server. A node matching any filtering rule and element hierarchy is selected. Table 1 describes subtree filter components.

Table 1 Subtree filter components

Component

Description

Namespace selection

If namespaces are used, then the filter output will include only elements from the specified namespace.

Containment node

A containment node is a node that contains child elements within a subtree filter.

For each containment node specified in a subtree filter, all data model instances which are exact matches for the specified namespaces and element hierarchy are included in the filter output.

Content match node

A content match node is a leaf node which contains simple content within a subtree filter.

A content match node is used to select some or all of its relevant nodes for filter output and represents an exact-match filter of the leaf node element content.

Selection node

A selection node is an empty leaf node within a subtree filter.

A selection node represents an explicit selection filter of the underlying data model. Presence of any selection nodes within a set of sibling nodes will cause the filter to select the specified subtrees and suppress automatic selection of the entire set of sibling nodes in the underlying data model.

  • Namespace selection

    If the XML namespace associated with a specific node in the <filter> element is the same as that in the underlying data model, the namespace is matched.

    <filter type="subtree">
     <top xmlns="http://example.com/schema/1.2/config"/>
    </filter>

    In this example, the <top> element is a selection node. If the node namespace complies with http://example.com/schema/1.2/config, the node and its child nodes will be included in the filter for output.

  • Containment node

    The child element of a containment node can be a node of any type, including another containment node. For each containment node specified in the subtree filter, all data model instances that completely match the specified namespace and element hierarchy, and any attribute matching expression are included in the output result.

    <filter type="subtree">
     <top xmlns="http://example.com/schema/1.2/config">
      <users/>
     </top>
    </filter>

    In this example, the <top> element is a containment node.

  • Content match node

    A leaf node that contains simple content is called a content match node. It is used to select some or all of its sibling nodes for filter output and represents exact match of the leaf node element content.

    <filter type="subtree">
     <top xmlns="http://example.com/schema/1.2/config">
      <users>
       <user>
        <name>fred</name>
       </user>
      </users>
     </top>
    </filter>

    In this example, both the <users> and <user> nodes are containment nodes, and the <name> node is a content match node. Because the sibling nodes of the <name> node are not specified, only <user> nodes that comply with namespace http://example.com/schema/1.2/config, with their element hierarchies matching the name element and their values being fred, can be included in the filter output. All sibling nodes of the <name> node are included in the filter output.

    The support-filter statement in the YANG model indicates whether to support content filtering for a node when the node is being operated:

    1. Content filtering is supported for key nodes by default.

    2. Content filtering is not supported for non-key nodes by default. If the value of the support-filter statement is set to true for a non-key node, content filtering is supported.

  • Selection node

    Selection nodes represent a basic data model for an explicit selection of filters. If any selection node appears in a group of same-level sibling nodes, the filter selects a specified subtree and suppresses the automatic selection of the entire sibling node set in the basic data model. In a filtering expression, an empty tag (such as <foo/>) or an expression with explicit start and end tags (such as <foo> </ foo>) can be used to specify an empty leaf node. In this case, all blank characters will be ignored.

    <filter type="subtree">
     <top xmlns="http://example.com/schema/1.2/config">
      <users/>
     </top>
    </filter>

    In this example, the <top> node is a containment node, and the <users> node is a selection node. The <users> node can be included for filter output only when the <users> node complies with namespace http://example.com/schema/1.2/config and is contained in the <top> element in the root directory of the configuration database.

Subtree Filter Processing

First, the subtree filter output is set as empty. Each subtree filter can contain one or more data model segments, each of which represents one of the selected output parts of the selected data model. Each subtree data segment is composed of data models supported by the NETCONF server. If the entire subtree data segment completely matches part of the data models supported by the NETCONF server, all nodes and child nodes of the subtree data segment are selected and output to the query result.
  • If no filter is used, all data in the current data model is returned in the query result.

    RPC request

    <rpc message-id="101"
    xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
     <get/>
    </rpc>

    RPC reply

    <rpc-reply message-id="101"
    xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
     <data>
      <!-- ... entire set of data returned ... -->
     </data>
    </rpc-reply>
  • If an empty filter is used, the query result contains no data output, in that no content match or selection node is specified.

    RPC request

    <rpc message-id="101"
    xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
     <get>
      <filter type="subtree">
      </filter>
     </get>
    </rpc>

    RPC reply

    <rpc-reply message-id="101"
    xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
     <data>
     </data>
    </rpc-reply>
  • Multi-subtree filtering

    The following example uses the root, fred, and barney subtree filters.

    The root subtree filter contains two containment nodes (<users> and <user>), one content match node (<name>), and one selection node (<company-info>). As for subtrees that meet selection criteria, only <company-info> is selected.

    The fred subtree filter contains three containment nodes (<users>, <user>, and <company-info>), one content match node (<name>), and one selection node (<id>). As for subtrees that meet the selection criteria, only the <id> element in <company-info> is selected.

    The barney subtree filter contains three containment nodes (<users>, <user>, and <company-info>), two content match nodes (<name> and <type>), and one selection node (<dept>). User barney is not a superuser and does not comply with the subtree filtering rule. Therefore, the entire subtree of barney (including its parent node <user>) is not selected.

    RPC request

    <?xml version="1.0" encoding="utf-8"?>
    <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="55">
      <get-config>
        <source>
          <running/>
        </source>
        <filter type="subtree">
          <acl xmlns="urn:huawei:yang:huawei-acl">
            <groups>
              <group>
                <identity>2100</identity>
                <rule-basics>
                  <rule-basic/>
                </rule-basics>
              </group>
              <group>
                <identity>2200</identity>
                <rule-basics>
                  <rule-basic>
                    <name/>
                  </rule-basic>
                </rule-basics>
              </group>
              <group>
                <identity>2300</identity>
                <type>basic</type>
                <rule-basics>
                  <rule-basic>
                    <id/>
                  </rule-basic>
                </rule-basics>
              </group>
            </groups>
          </acl>
        </filter>
      </get-config>
    </rpc>
    

    RPC reply

    <?xml version="1.0" encoding="utf-8"?>
    <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="56">
      <data>
        <acl xmlns="urn:huawei:yang:huawei-acl">
          <groups>
            <group>
              <identity>2100</identity>
              <rule-basics>
                <rule-basic>
                  <name>rule_3</name>
                  <id>1</id>
                  <action>deny</action>
                  <source-ipaddr>0.0.0.0</source-ipaddr>
                  <source-wild>0.0.0.255</source-wild>
                  <vpn-name>_public_</vpn-name>
                </rule-basic>
              </rule-basics>
            </group>
            <group>
              <identity>2200</identity>
            </group>
            <group>
              <identity>2300</identity>
              <type>basic</type>
              <rule-basics>
                <rule-basic>
                  <name>rule_3</name>
                  <id>1</id>
                </rule-basic>
              </rule-basics>
            </group>
          </groups>
        </acl>
      </data>
    </rpc-reply>
    
Copyright © Huawei Technologies Co., Ltd.
Copyright © Huawei Technologies Co., Ltd.
< Previous topic