SDN学习笔记——YANG数据建模语言初学习

一、什么是YANG语言

YANG is Yet Another Next Generation modeling language for Network Configuration Protocol. It
is first designed for state synchronization between devices and state storage but is also used for service layer abstraction.
YANG是网络配置协议的另一种下一代建模语言。它最初被设计 用于设备和状态存储之间的状态同步 ,但也用于服务层抽象。


Martin Björklund. YANG - a Data Modeling Language for the Network Configuration

Protocol (NETCONF) . RFC 6020. Oct. 2010. uRl:
https://rfc-editor.org/rfc/rfc6020.txt

 

 二、YANG语言数据结构

1.Module

YANG的顶层结构是Module

A module contains
statements to express meta information about the module (namespace, prefix, date revision)
statements to import dependent modules
statements to define data trees

一个模块包含

•表达模块元信息的语句(命名空间,前缀,日期修订)

•导入依赖模块的语句

•定义数据树的语句

 子声明类型:

 Module规范和导入示例

定义 module ``example1'':
module example1 {
    namespace "urn:examples:example1";
    prefix "example1";

    revision "2021-09-15" {
    description "Initial revision.";
    }

    typedef score {
    type uint8 {
    range "0..100";
        }
    }
...
}
定义 module ``example2'' 并导入 module ``example1'' (重命名为 ``abc'')
module example2 {
    namespace "urn:examples:example2";
    prefix "example2";

    revision "2021-09-15" {
        description "Initial revision.";
    }
    import "example1" {
        prefix "abc";
    }

...

    typedef score-s {
        type "abc:score" {
            range "90..100";
        }
    }
}

2.类型系统

YANG语言用于将数据模型指定为树状结构

Types for leaf and leaf-list nodes:
built-in types
types defined by ``typedef'' statement
Types for non-leaf nodes:
container
list

叶节点和叶列表节点的类型:

•内置类型

•由“typedef”语句定义的类型

非叶节点类型:

•容器

•列表

内置类型: 

示例程序: 

我们使用下面的示例来说明如何为不同类型的节点构建数据树

该代码建立如下的树形结构: 

 

每个模块都有一个隐式根节点 root,按名称查找顶级节点。

容器节点 a 有一个实例,并按成员名查找子树

一个列表节点 b 包含多个实例

列表中的实例是一个数据容器,它按成员名查找子树

叶节点 c 的类型为“string”,值为字符串

叶列表节点 d 的类型为“int32”,值是一个32位整数列表

 3.顶级类型

(1)Data Tree

任何数据树语句(container, list, leaf, leaf-list, etc.)都会在Module中创建一个数据树

(2)RPC

RPC是用RPC语句创建的
•input语句中的数据树指定输入格式
•output语句中的数据树指定输出格式

(3)Notifications

使用notification语句创建通知

定义方法示例: 

 

4.Config v.s. Operational 

在数据树中,可以使用config参数指定它是属于配置操作数据树,还是只属于操作数据树

 

5.List 

YANG uses list with keys to realize maps 

YANG 使用 带有 keys 的 List 来实现 maps 


6.代码重用 

The grouping statement allows the same subtree structure to be reused

分组语句允许重用相同的子树结构

 

右边的模型重用了左边的模型中的 grouping 结构中声明的子树类型

 7.使用 Augmentation 进行扩展

YANG allows a new module to extend an old module's data/rpc/notification tree

YANG允许新模块扩展旧模块的data/rpc/notification树

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值