首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在YANG模型中使用count()子句?

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

Stack Overflow用户
提问于 2015-03-16 08:08:17
回答 1查看 3.4K关注 0票数 0

在过去的几天里,我试图研究这个问题,但我的研究却很短,似乎没有太多关于在YANG模型中使用子句的材料。

背景

我试图用一些特定于客户的信息扩展I2RS YANG模型(基于网络拓扑的I2RS数据模型)的NETCONF模型。因此,我的模型增强了模型的相关部分(在这里以缩写形式显示)。我陷入困境的地方是制定一种适当的方法来实现输入数据上的一些语义限制,特别是围绕具有特定链接使用的链接的数量。下面的讨论使用pyang作为工具链。

增强的杨模块

简化的模块如下所示:

代码语言:javascript
复制
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;
}
} 

输入文件

试图验证以下输入:

代码语言:javascript
复制
<?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验证输出

代码语言:javascript
复制
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

问题:为什么布尔值(计数(./nd:link)= 1)不能计算为真?

很明显里面有一个联系。我在这里错过了什么?

完成的其他验证

我确实使用了XPath表达式测试来找出我所缺少的指针,但是这个工具给了我预期的结果。无论是在没有上下文节点的情况下进行验证,还是在上述XML文件中将上下文节点设置为链接使用节点的情况下。

有人知道我错过了什么吗?

EN

回答 1

Stack Overflow用户

发布于 2018-11-28 19:16:12

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29072119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档