yang模型初解

来源:互联网 发布:apache hadoop 安装 编辑:程序博客网 时间:2024/06/15 02:35

【背景】

换项目组,新搞netconf,遇见的第一个任务是解释netconfyang的关系。

于是从国外的网站中摘抄了点材料,梳理了下。

 

【什么是yang

提到yang,首先要提netconf。因为YANGNETCONF的数据模型。

IETF20035成立Netconf工作组,该工作组主要是为了提出一个全新的基于XML网络配置(NETCONF)协议而成立的。该工作组已于200612月通过了NETCONF协议的基本标准RFC4741-474420116RFC6241RFC6242替代了原有的 RFC4741RFC4742RFC4743 RFC4744则被标记为历史资料。



上面这张四层的图定义了NETCON的协议结构,YANG实现的就是对内容层数据对象建模。

对于网络设备,通常来说应该包含底层、数据管理面、协议控制面和管理面等部分。每个部分下面又包含了各类协议。

根据我的理解,一台大型的网络设备应该包含了几十种协议。那也意味每一协议可能都有需要配置数据或者状态数据

对外提供接口。如何提供一种公共的机制,让世界上成千上外个网络管理软件或者设备高效、可靠管理设备。在历史上通过命令行下发配置数据和通过SNMP查询设备状态数据,但是随着云化、SDN等等诉求的提出,命令行下发包含的业务逻辑、SNMP协议的

可靠性等都成为设备云化的瓶颈,由此NETCONF的地位日渐提升。NETCONF本身的数据模型除了

YANG之外还有SCHEMA等数据模型。但是随着时间推移,YANG似乎逐渐成为了主流。

 

【为什么选择yang

 <http://www.yang-central.org/twiki/bin/view/Main/WhyYang> 网站给出了以下几点原因

  1. YANG is easy and targets the right audience
  2. YANG is written for NETCONF and network management
  3. Modular, flexible, and not!
  4. YANG has its heritage in the IETF network management community
  5. YANG continues the IETF tradition of being backed by "running code"
  6. YANG developed openly
  7. YANG gaining acceptance

根据我自己的理解应该主要是以下几点:

1、继承了SNMP SMI数据模型的优点,简单、可读性、可扩展性好;

2、在NETCONF开发前期就已经被大量使用,基础好。

 

YANG是啥样子】

SNMP V3用户信息为例

Submodule'ietf-snmp-usm'

This YANGsubmodule imports YANG extensions from [RFC6536].

<CODEBEGINS> file "ietf-snmp-usm.yang"

submoduleietf-snmp-usm {

belongs-toietf-snmp {
       prefix snmp;
     }

Bjorklund& Schoenwaelder    StandardsTrack                   [Page55]

RFC 7407         YANG Data Model for SNMPConfiguration    December 2014

importietf-yang-types {
       prefix yang;
     }
     import ietf-netconf-acm {
       prefix nacm;
     }

includeietf-snmp-common;
     include ietf-snmp-target;
     include ietf-snmp-proxy;

organization
       "IETF NETMOD (NETCONF DataModeling Language) Working Group";

contact
       "WG Web:   <http://tools.ietf.org/wg/netmod/>
        WG List:  <mailto:netmod@ietf.org>

WG Chair:Thomas Nadeau
                  <mailto:tnadeau@lucidvision.com>

WG Chair:Juergen Schoenwaelder
                  <mailto:j.schoenwaelder@jacobs-university.de>

Editor:   Martin Bjorklund
                  <mailto:mbj@tail-f.com>

Editor:   Juergen Schoenwaelder
                  <mailto:j.schoenwaelder@jacobs-university.de>";

description
       "This submodule contains acollection of YANG definitions for
        configuring the User-basedSecurity Model (USM) of SNMP.

Copyright(c) 2014 IETF Trust and the persons identified as
        authors of the code.  All rights reserved.

Redistributionand use in source and binary forms, with or
        without modification, ispermitted pursuant to, and subject
        to the license terms contained in,the Simplified BSD License
        set forth in Section 4.c of theIETF Trust's Legal Provisions
        Relating to IETF Documents
        (http://trustee.ietf.org/license-info).

Thisversion of this YANG module is part of RFC 7407; see
        the RFC itself for full legalnotices.";

Bjorklund& Schoenwaelder    StandardsTrack                   [Page56]

RFC 7407         YANG Data Model for SNMPConfiguration    December 2014

reference
       "RFC 3414: User-basedSecurity Model (USM) for version 3 of the
          Simple Network ManagementProtocol (SNMPv3)";

revision2014-12-10 {
       description
         "Initialrevision.";
       reference
         "RFC 7407: A YANG DataModel for SNMP Configuration";
     }

groupingkey {
       leaf key {
         type yang:hex-string;
         mandatory true;
        nacm:default-deny-all;
         description
           "Localized key specifiedas a list of colon-specified
            hexadecimaloctets.";
       }
     }

groupinguser-list {
       list user {
         key "name";

reference
           "RFC 3414: User-basedSecurity Model (USM) for version 3
              of the Simple NetworkManagement Protocol (SNMPv3).
             SNMP-USER-BASED-SM-MIB.usmUserTable";

leaf name{
           typesnmp:identifier;
           reference
             "RFC 3414: User-basedSecurity Model (USM) for version 3
                of the Simple NetworkManagement Protocol (SNMPv3).
               SNMP-USER-BASED-SM-MIB.usmUserName";
         }
         container auth {
           presence "enablesauthentication";
           description
             "Enables authenticationof the user.";
           choice protocol {
             mandatory true;
             reference
               "RFC 3414: User-basedSecurity Model (USM) for version 3
                  of the Simple NetworkManagement Protocol (SNMPv3).
                 SNMP-USER-BASED-SM-MIB.usmUserAuthProtocol";

Bjorklund& Schoenwaelder    StandardsTrack                   [Page57]

RFC 7407         YANG Data Model for SNMPConfiguration    December 2014

containermd5 {
               uses key;
               reference
                 "RFC 3414:User-based Security Model (USM) for
                    version 3 of theSimple Network Management Protocol
                    (SNMPv3).
                   SNMP-USER-BASED-SM-MIB.usmHMACMD5AuthProtocol";
             }
             container sha {
               uses key;
               reference
                 "RFC 3414:User-based Security Model (USM) for
                    version 3 of theSimple Network Management Protocol
                    (SNMPv3).
                   SNMP-USER-BASED-SM-MIB.usmHMACSHAAuthProtocol";
             }
           }
         }
         container priv {
           must "../auth"{
             error-message
               "when privacy(confidentiality) is used, "
             + "authentication mustalso be used";
           }
           presence "enablesencryption";
           description
             "Enables encryption ofSNMP messages.";

choiceprotocol {
             mandatory true;
             reference
               "RFC 3414: User-basedSecurity Model (USM) for version 3
                  of the Simple NetworkManagement Protocol (SNMPv3).
                 SNMP-USER-BASED-SM-MIB.usmUserPrivProtocol";
             container des {
               uses key;
               reference
                 "RFC 3414:User-based Security Model (USM) for
                    version 3 of theSimple Network Management Protocol
                    (SNMPv3).
                   SNMP-USER-BASED-SM-MIB.usmDESPrivProtocol";
             }
             container aes {
               uses key;

Bjorklund& Schoenwaelder    StandardsTrack                   [Page58]

RFC 7407         YANG Data Model for SNMPConfiguration    December 2014

reference
                 "RFC 3826: TheAdvanced Encryption Standard (AES)
                    Cipher Algorithm inthe SNMP User-based Security
                    Model.
                   SNMP-USM-AES-MIB.usmAesCfb128Protocol";
             }
           }
         }
       }
     }

augment/snmp:snmp {

containerusm {
         description
           "Configuration of theUser-based Security Model.";
         container local {
           uses user-list;
         }

list remote{
           key "engine-id";

leafengine-id {
             typesnmp:engine-id;
             reference
               "RFC 3414: User-basedSecurity Model (USM) for version 3
                  of the Simple NetworkManagement Protocol (SNMPv3).
                 SNMP-USER-BASED-SM-MIB.usmUserEngineID";
           }

usesuser-list;
         }
       }
     }

groupingusm-target-params {
       container usm {
         description
           "User-based SNMPv3parameters type.

RepresentssnmpTargetParamsMPModel '3' and
            snmpTargetParamsSecurityModel'3'.";
         leaf user-name {
           typesnmp:security-name;
           mandatory true;

Bjorklund& Schoenwaelder    StandardsTrack                   [Page59]

RFC 7407         YANG Data Model for SNMPConfiguration    December 2014

reference
             "RFC 3413: SimpleNetwork Management Protocol (SNMP).
                Applications.
               SNMP-TARGET-MIB.snmpTargetParamsSecurityName";
         }
         leaf security-level {
           type snmp:security-level;
           mandatory true;
           reference
             "RFC 3413: SimpleNetwork Management Protocol (SNMP).
                Applications.
               SNMP-TARGET-MIB.snmpTargetParamsSecurityLevel";
         }
       }
     }

augment/snmp:snmp/snmp:target-params/snmp:params {
       case usm {
         usesusm-target-params;
       }
     }

}

<CODEENDS>

 

来自 <http://www.rfc-editor.org/rfc/rfc7407.txt