0

在过去的几天里,我试图对此进行研究,但我的研究很短,似乎没有很多关于在YANG模型中使用must()子句的材料。

背景

我正在尝试使用一些客户特定的信息来扩展 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 文件中将上下文节点设置为链接使用节点的情况下。

有没有人对我所缺少的有任何指示?

4

1 回答 1

0

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

于 2018-11-28T19:16:12.457 回答