Reference

  • 什么是NETCONF
  • 什么是YANG
  • NetConf YANG原理
  • 对YANG的解读
  • NETCONF&YANG简介.pdf

    发展过程

    NetConf YANG简介 - 图1

    NetConf Protocol

    Netconf定义了对数据的获取(get)与调整(config),YANG model描述的世界的数据yang data封装操作,实现对网络世界的管理。

    Architecture

    NetConf YANG简介 - 图2

  • 客户端:

    • 发送RPC请求(RPC通信模式),查询和修改参数
    • 接收NETCONF Server主动发送的告警和事件
  • 服务器:

    • 收到Client的请求后会进行数据解析,然后给 Client返回响应
    • 当设备发生故障或其他事件时,利用Notification机制主动将设备的告警和事件通知给Client

      会话建立过程

      NetConf YANG简介 - 图3
      能力集是一组基于NETCONF协议实现的基础功能和扩展功能的集合。NETCONF能力集包括由IETF标准组织定义的标准能力集,以及由各设备制造商定义的各自的扩展能力集。设备可以通过能力集增加协议操作,扩展已有配置对象的操作范围.
      能力协商是在会话建立阶段,双方通过发送消息给对方来通告自己支持的能力。
      NETCONF会话一旦建立,Client和Server端会立即向对端发送Hello消息(含有本端支持的能力集列表元素),通告各自支持的能力集。这样双方就能利用协商后的能力实现特定的管理功能。
      NetConf YANG简介 - 图4

      四层分层结构

      NETCONF协议采用了分层结构。每层分别对协议的某一方面进行包装,并向上层提供相关服务。分层结构使每层只关注协议的一个方面,实现起来更简单,同时使各层之间的依赖、内部实现的变更对其他层的影响降到最低:
      NetConf YANG简介 - 图5

      报文格式

      NetConf YANG简介 - 图6
      下面对各部分详细描述一下

      rpc通信模式

      上面xml第一个节点是通信模式, 对应不同的信息:
  • : 用来封装Client发送给Server的请求

  • : 用来封装rpc>请求的应答消息,Server给每个rpc操作回应一个使用rpc-reply元素封装的应答信息

    • : Server在处理请求的过程中,如果发生任何错误或告警,则在rpc-reply元素内只封装rpc-error元素返回给Client
    • : Server在处理请求的过程中,如果没有发生任何错误或告警,则在rpc-reply元素内封装一个ok元素返回给Client

      操作类型

      上面的edit-config是一种Netconf操作, 是下面基本操作中的一种
      NetConf YANG简介 - 图7
      除基本的读写, 还支持事务操作回滚, 锁定防干扰等动作.

      Target

      NETCONF定义了一个或多个配置数据库的存在,并允许对它们进行配置操作, 每次rpc请求要指定要操作的target数据库是哪个:
  • running: 运行配置数据库,保存网络设备上当前处于活动状态的完整配置

  • candidate: 备用配置数据库,存放设备将要提交到running的各项配置数据的集合
  • startup: 启动配置数据库,存放设备启动时所加载的配置数据,相当于已保存的配置文件

NetConf YANG简介 - 图8

content数据

内容部分是具体的config参数或者获取到的data, 此部分对应YANG模型对数据内容进行标准化.

Notification通知

NETCONF Base notification:IETF定义的5个基本通知

  • netconf-config-change
  • netconf-capability-change
  • netconf-session-start
  • netconf-session-end
  • netconf-confirmed-commit

    YANG Model

    YANG = Yet Another Next Generation (Yang) Data Modeling Language。它是一种建模语言,用于描述网络概念的。YANG可以很好的转换成XML数据,包裹在Netconf协议之中进行传输
    NetConf YANG简介 - 图9

    YANG example

    module example-foo{
    yang-version 1.1;
    namespace “urn:example:foo”;
    prefix “foo”;

    import example-extensions{
    prefix “myext”;
    }
    organization “BTR Technologies Co., Ltd.”;
    contact
    “Barret Ren Personal
    People’s Republic of China
    Email: barretren@qq.com”;
    description “Basic example YANG module file.”;
    revision 2022-05-12 {
    description “Add units attribute.”;
    reference “barret private.”;
    }

    container example-list {
    description “List of example parameters.”;

    list interface{
    key “namea”;
    leaf namea{
    type string;
    }
    }

    leaf mtu{
    type uint32;
    description “the MTU of the interface”;
    myext:c-define “MY_MTU”;
    }
    }
    }
    使用pyang工具可以把YANG模型转换成YANG Tree视图,整个YANG模型以一棵树的形式展示。命令为pyang -f tree example.yang -o example.tree
    module: example-foo
    +—rw example-list
    +—rw interface* [namea]
    | +—rw namea string
    +—rw mtu? uint32

    YANG Statement

    | 语句 | 功能说明 | 语句 | 功能说明 | | —- | —- | —- | —- | | module | YANG将数据模型构建为模块,模块名与YANG文件名一致 | namespace | 模块的名字空间,是全球唯一的URI。 | | prefix | namespace的简写 | organization | YANG归属组织名 | | contact | YANG模块联系信息 | description | 功能描述 | | revision | 版本信息,提供编辑版本历史 | container | 容器节点,若干节点的集合 | | list | 列表节点,定义列表条目 | key | list的key,唯一标识列表 | | max-elements | 列表的最大实例个数 | min-elements | 列表的最小实例个数 | | leaf | 叶子节点,包含简单数据 | leaf-list | 定义叶子列表 | | augment | 对其他模型进行扩展 | choice | 定义互斥选择分支 | | extension | 定义YANG的扩展 | feature | 特性声明 | | grouping | 可重用的数据结构 | uses | 引用grouping定义的数据结构 | | rpc | 定义RPC操作,需要代码实现 | typedef | 定义派生类型 | | notification | 定义通知 | length | 字符串长度 | | mandatory | 节点必须出现 | must | 定义节点必须满足的约束 | | pattern | 正则表达式约束 | range | 参数取值范围 | | reference | 参考或引用说明 | unique | 值必须和指定数据相等 | | when | 定义节点满足什么条件才可见 | import | 导入其他YANG模型文件 | | config | true表示配置数据,false表示状态数据 | case | 表示choice里的不同分支 |

YANG Types

类型 说明 类型 说明
binary Any binary data bits A set of bits or flags
boolean “true” or “false” decimal64 64-bit signed decimal number
empty A leaf that does not have any value enumeration Enumerated strings
identityref A reference to an abstract identity instance-identifier References a data tree node
int8 8-bit signed integer int16 16-bit signed integer
int32 32-bit signed integer int64 64-bit signed integer
leafref A reference to a leaf instance string Human-readable string
uint8 8-bit unsigned integer uint16 16-bit unsigned integer
uint32 32-bit unsigned integer uint64 64-bit unsigned integer
union Choice of member types

YANG允许用户使用typedef来定义自己需要的type,可以基于build-in type或是另外一个派生的type.

YANG and XML

为了利用各编程语言中现有的XML解析器等工具, YANG模型在填充数据后转换为XML数据在NetConf消息中传递. 对端再根据YANG模型解析XML得到真正的数据:
可以使用pyang -f yin example.yang -o example.yin手动生产xml文件
NetConf YANG简介 - 图10