如何在YANG模型的must()子句中使用count()?

时间:2015-03-16 08:08:17

标签: xpath opendaylight ietf-netmod-yang

我在过去几天尝试研究这个问题,但我的研究很短暂,似乎没有很多关于在 must()子句中使用的材料strong> YANG 模型。

背景

我正在尝试使用某些客户特定信息扩展I2RS YANG模型的NETCONF模型(基于IETF I2RS Data Model for Network Topologies)。因此,我的模型增加了模型的相关部分(在此处以缩写形式显示)。我陷入困境的是制定一种正确的方法来对输入数据实施一些语义约束,特别是围绕具有特定链接用法的链接数量。 pyang用作以下讨论的工具链。

增强型YANG模块

缩写模块如下所示:

module bsc-topology {
yang-version 1;

namespace "urn:TBD:params:xml:ns:yang:bsc:bsc-topology";

prefix "bsc";

import nodes {
    prefix "nd";
    revision-date 2015-03-09;
}

import network-topology {
    prefix "nt";
    revision-date 2015-03-09;
}

import ietf-inet-types {    
    prefix "inet";
}

organization "TBD";
contact "TBD";

revision "2015-03-11" {
    description "Initial revision";
    reference "TBD";
}

identity flag-identity {
    description "Base type for flags";
}

identity undefined-flag {
    base "flag-identity";
}

typedef bsc-link-service-type {
    type enumeration {
        enum "Ater" {
            value 1;
            description "This link describes the Ater topology";
        }
        enum "Gb" {
            value 2;
            description "This link describes the Gb topology";
        }
    }
}

typedef flag-type {

    type identityref {
        base "flag-identity";
    }
}

grouping ater-attributes {
    leaf prefix {
        type inet:ip-prefix;
    }
    leaf metric {
        type uint32;
    }
    leaf-list flag {
        type flag-type;
    }
}

grouping bsc-topology-type {
    container bsc-topology {
        presence "Indicates BSC Topology";
    }
}

grouping bsc-link-attributes {
    container bsc-link-attributes {
        leaf name {
            description "Link Name";
            type string;
        }

        leaf link-usage {
            type bsc-link-service-type;

            description "Type of Service described through this link (Ater or Gb)";

            must "boolean(count(../../../nd:link) = 1)";    
        }       
    }       
} 


augment "/nd:network/nd:network-types" {
    uses bsc-topology-type;
}

augment "/nd:network/nt:link" {
    when "/nd:network/nd:network-types/bsc-topology";
    uses bsc:bsc-link-attributes;
}
} 

输入文件

尝试验证以下输入:

<?xml version="1.0" encoding="UTF-8"?>
    <config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
      <nd:network xmlns:nd="urn:TBD:params:xml:ns:yang:nodes">
        <nd:network-id>Test</nd:network-id>
        <nd:network-types>
          <bsc:bsc-topology xmlns:bsc="urn:TBD:params:xml:ns:yang:bsc:bsc-topology"/>
        </nd:network-types>
        <nd:node>
          <nd:node-id>407201001A</nd:node-id>
          <nt:termination-point xmlns:nt="urn:TBD:params:xml:ns:yang:links">
            <nt:tp-id>SERVICE_TP</nt:tp-id>
          </nt:termination-point>
        </nd:node>
        <nd:node>
          <nd:node-id>407850001A</nd:node-id>
          <nt:termination-point xmlns:nt="urn:TBD:params:xml:ns:yang:links">
            <nt:tp-id>SERVICE_TP</nt:tp-id>
          </nt:termination-point>
        </nd:node>
        <nt:link xmlns:nt="urn:TBD:params:xml:ns:yang:links">
          <nt:link-id>407201001A-407850001A-Ater</nt:link-id>
          <nt:source>
            <nt:source-node>407201001A</nt:source-node>
            <nt:source-tp>SERVICE_TP</nt:source-tp>
          </nt:source>
          <nt:destination>
            <nt:dest-node>407850001A</nt:dest-node>
            <nt:dest-tp>SERVICE_TP</nt:dest-tp>
          </nt:destination>
          <bsc:bsc-link-attributes xmlns:bsc="urn:TBD:params:xml:ns:yang:bsc:bsc-topology">
            <bsc:link-usage>Ater</bsc:link-usage>
          </bsc:bsc-link-attributes>
        </nt:link>
      </nd:network>
    </config>

Pyang验证输出

yang2dsdl -j -s -b nodes_network-topology_bsc-topology -t config -v foo3.xml
== Using pre-generated schemas

== Validating grammar and datatypes ...
foo3.xml validates.

== Adding default values... done.

== Validating semantic constraints ...
--- Failed assert at "/nc:config/nd:network/lnk:link/bsc:bsc-link-attributes/bsc:link-usage":
    Condition "boolean(count(../../../nd:link) = 1)" must be true

问题:为什么boolean(count(../../../ nd:link)= 1)没有评估为true?

那里显然有一个链接。那我在这里错过了什么?

已完成其他验证

我确实使用了XPath Expression Testbed来指出我错过的指针,但该工具给了我预期的结果。在我没有上下文节点的情况下进行验证的情况以及我将上下文节点设置为上述XML文件中的 link-usage 节点的情况。

有没有人对我错过的内容有任何指示?

1 个答案:

答案 0 :(得分:0)

无需添加布尔值。只需“ count(../../../ nd:link)= 1”即可。