netmod-wg/yang-next

The next step of XPath

lllyfeng opened this issue · 4 comments

Scenarios:

  • The expression of when/must of YANG using XPath 1.0 is not readable and error-prone.
  • The XPath filtering of NETCONF has the same problem. In addition, the function is limited. For example, the XPath filtering cannot be sorted, join cannot be performed, and complex conditions cannot be supported.
  • List Pagination: the parameters defined by List Pagination are similar to those of SQL. There is no need to redefine these parameters when the prior art already exists. It is expected that a query language that meets this function requirement can be used in List Pagination.
  • The ECA model can realize some intelligence through condition judgment on the device side. The current solution is not readable and its functions are not perfect. A new syntax similar to a programming language is required to express the ECA model.
  • The conditions for adaptive subscription are also written using the XPATH syntax. In some cases, the readability is not high and error-prone.

Summary:

XPath is derived from the path language and is used to indicate paths. It is not a strong point in querying data and expressing complex logical relationships. A new language or algorithm is required to replace or strengthen XPath.

Solutions:

  • xQuery. If complex logic or query needs to be expressed, use xQuery instead.
  • Define a new query language for YANG.

XPath VS XQuery(must simplification)
original XPath:

current()< (/l2vpn:l2vpn/l2vpn:common/l2vpn:vpws-bgp-vpns/l2vpn:vpws-bgp-vpn[l2vpn:name=current()/../../../l2vpn:vpn-instance]/l2vpn:sites/l2vpn:site[l2vpn:name = current()/../../../l2vpn:local-site]/range + /l2vpn:l2vpn/l2vpn:common/l2vpn:vpws-bgp-vpns/l2vpn:vpws-bgp-vpn[l2vpn:name = current()/../../../l2vpn:vpn-instance]/l2vpn:sites/l2vpn:site[l2vpn:name = current()/../../../l2vpn:local-site]/default-offset) and current() >= /l2vpn:l2vpn/l2vpn:common/l2vpn:vpws-bgp-vpns/l2vpn:vpws-bgp-vpn[l2vpn:name = current()/../../../l2vpn:vpn-instance]/l2vpn:sites/l2vpn:site[l2vpn:name = current()/../../../l2vpn:local-site]/default-offset

xquery:

for  $site in (/l2vpn:l2vpn/l2vpn:common/l2vpn:vpws-bgp-vpns/l2vpn:vpws-bgp-vpn[l2vpn:name=current()/../../../l2vpn:vpn-instance]/l2vpn:sites/l2vpn:site[l2vpn:name = current()/../../../l2vpn:local-site]
where current() < ($site/range+ $site/ default-offset) and current() >= $site/default-offset

List pagination:
original request:

<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="42">
     <get-config>
       <source>
         <running/>
       </source>
       <filter type="xpath" select="/es:members/es:member"
         xmlns:es="http://example.com/ns/example-social"/>
         <list-pagination
           xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-list-paginat\
   ion">true</list-pagination>
         <where>//stats//joined[starts-with(@timestamp,'2020')]</where>
         <sort-by>timestamp</sort-by>
         <direction>backwards</direction>
         <offset>2</offset>
         <limit>2</limit>
         <sublist-limit>1</sublist-limit>
       </filter>
     </get-config>
   </rpc>

the request using xQuery:

<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="42">
     <get-config>
       <source>
         <running/>
       </source>
       <filter type="xquery“>
          <script>
                for $member in /es:members/es:member
                where $member//stats/joined[starts-with(@timestamp,'2020')]
                order by $member/timestamp descending
           </script>
        </filter>
         <list-pagination>
             <offset>2</offset>
             <limit>2</limit>
             <sublist-limit>1</sublist-limit>
         </list-pagination>
     </get-config>
   </rpc>

adaptive subscription:

original condition:

      xmlns:as="urn:ietf:params:xml:ns:yang:ietf-adaptive-subscription">
      <as:adaptive-period>
       <as:xpath-external-eval>
        /wnd:server/wnd:rssi&lt;-65
       </as:xpath-external-eval>
       <as:period>5</as:period>
      </as:adaptive-period>
      <as:adaptive-period>
       <as:xpath-external-eval>
        /wnd:server/wnd:rssi&gt;=-65
       </as:xpath-external-eval>
       <as:period>60</as:period>
     </as:adaptive-period>
     </as:adaptive-subscriptions>

the condition using xQuery:

<as:adaptive-subscriptions
      xmlns:as="urn:ietf:params:xml:ns:yang:ietf-adaptive-subscription">
      <as:adaptive-period>
         if (/wnd:server/wnd:rssi <-65) \
         then \
         return 5 \
         else \
         return 60 \
      </as:adaptive-period>
</as:adaptive-subscriptions>

This is a netconf-next issue.
I think a draft to augment protocol operations is already in progress.

Close