Skip to content
This repository has been archived by the owner on Oct 11, 2020. It is now read-only.

YANG modules validation and tree representation

Khelil Sator edited this page Feb 10, 2019 · 3 revisions

About pyang

You can use pyang to:

  • Validate YANG modules against YANG RFCs
  • Convert YANG modules into equivalent YIN module (XML).
  • Generate a tree representation of YANG models for quick visualization.

Pyang installation

pyang installation from pypi:

$ pip install pyang

validate yang modules

Example: let's validate the modules openconfig-bgp.yang and openconfig-interfaces.yang from openconfig github repository

Get Openconfig yang modules

clone the openconfig repository

$ git clone https://github.com/openconfig/public.git
$ ls public

move all the yang files from Openconfig to the same directory

The YANG modules openconfig-bgp.yang and openconfig-interfaces.yang import other YANG modules: so we need to make sure pyang can find all these yang modules

move all the yang files to the directory yang_modules

$ mkdir yang_modules
$ cp public/release/models/*.yang yang_modules/.
$ cp -R public/release/models/*/*.yang yang_modules/.
$ ls yang_modules
$ cd yang_modules

validate yang modules

$ pyang openconfig-bgp.yang
$ pyang openconfig-interfaces.yang 

Generate a tree representation of YANG modules for quick visualization

$ pyang -f tree openconfig-bgp.yang 
$ pyang -f tree openconfig-interfaces.yang
$ pyang openconfig-interfaces.yang -f tree --tree-path=/interfaces/interface/state
module: openconfig-interfaces
  +--rw interfaces
     +--rw interface* [name]
        +--ro state
           +--ro name?            string
           +--ro type             identityref
           +--ro mtu?             uint16
           +--ro loopback-mode?   boolean
           +--ro description?     string
           +--ro enabled?         boolean
           +--ro ifindex?         uint32
           +--ro admin-status     enumeration
           +--ro oper-status      enumeration
           +--ro last-change?     oc-types:timeticks64
           +--ro logical?         boolean
           +--ro counters
              +--ro in-octets?             oc-yang:counter64
              +--ro in-pkts?               oc-yang:counter64
              +--ro in-unicast-pkts?       oc-yang:counter64
              +--ro in-broadcast-pkts?     oc-yang:counter64
              +--ro in-multicast-pkts?     oc-yang:counter64
              +--ro in-discards?           oc-yang:counter64
              +--ro in-errors?             oc-yang:counter64
              +--ro in-unknown-protos?     oc-yang:counter64
              +--ro in-fcs-errors?         oc-yang:counter64
              +--ro out-octets?            oc-yang:counter64
              +--ro out-pkts?              oc-yang:counter64
              +--ro out-unicast-pkts?      oc-yang:counter64
              +--ro out-broadcast-pkts?    oc-yang:counter64
              +--ro out-multicast-pkts?    oc-yang:counter64
              +--ro out-discards?          oc-yang:counter64
              +--ro out-errors?            oc-yang:counter64
              +--ro carrier-transitions?   oc-yang:counter64
              +--ro last-clear?            oc-types:timeticks64

Old openconfig BGP path, used by Junos 16.1R3 to 17.2

$ pyang openconfig-bgp.yang -f tree --tree-path=/bgp/neighbors/neighbor/state --tree-depth=5
module: openconfig-bgp
  +--rw bgp
     +--rw neighbors
        +--rw neighbor* [neighbor-address]
           +--ro state
              +--ro peer-group?                -> ../../../../peer-groups/peer-group/peer-group-name
              +--ro neighbor-address?          oc-inet:ip-address
              +--ro enabled?                   boolean
              +--ro peer-as?                   oc-inet:as-number
              +--ro local-as?                  oc-inet:as-number
              +--ro peer-type?                 oc-bgp-types:peer-type
              +--ro auth-password?             oc-types:routing-password
              +--ro remove-private-as?         oc-bgp-types:remove-private-as-option
              +--ro route-flap-damping?        boolean
              +--ro send-community?            oc-bgp-types:community-type
              +--ro description?               string
              +--ro session-state?             enumeration
              +--ro last-established?          oc-types:timeticks64
              +--ro established-transitions?   oc-yang:counter64
              +--ro supported-capabilities*    identityref
              +--ro messages
              |     ...
              +--ro queues
              |     ...
              +--ro dynamically-configured?    boolean

New openconfig BGP path, used from Junos 17.3

$ pyang openconfig-network-instance.yang --tree-path=/network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/state -f tree
module: openconfig-network-instance
  +--rw network-instances
     +--rw network-instance* [name]
        +--rw protocols
           +--rw protocol* [identifier name]
              +--rw bgp
                 +--rw neighbors
                    +--rw neighbor* [neighbor-address]
                       +--ro state
                          +--ro peer-group?                -> ../../../../peer-groups/peer-group/peer-group-name
                          +--ro neighbor-address?          oc-inet:ip-address
                          +--ro enabled?                   boolean
                          +--ro peer-as?                   oc-inet:as-number
                          +--ro local-as?                  oc-inet:as-number
                          +--ro peer-type?                 oc-bgp-types:peer-type
                          +--ro auth-password?             oc-types:routing-password
                          +--ro remove-private-as?         oc-bgp-types:remove-private-as-option
                          +--ro route-flap-damping?        boolean
                          +--ro send-community?            oc-bgp-types:community-type
                          +--ro description?               string
                          +--ro session-state?             enumeration
                          +--ro last-established?          oc-types:timeticks64
                          +--ro established-transitions?   oc-yang:counter64
                          +--ro supported-capabilities*    identityref
                          +--ro messages
                          |  +--ro sent
                          |  |  +--ro UPDATE?                            uint64
                          |  |  +--ro NOTIFICATION?                      uint64
                          |  |  +--ro last-notification-time?            oc-types:timeticks64
                          |  |  +--ro last-notification-error-code?      identityref
                          |  |  +--ro last-notification-error-subcode?   identityref
                          |  +--ro received
                          |     +--ro UPDATE?                            uint64
                          |     +--ro NOTIFICATION?                      uint64
                          |     +--ro last-notification-time?            oc-types:timeticks64
                          |     +--ro last-notification-error-code?      identityref
                          |     +--ro last-notification-error-subcode?   identityref
                          +--ro queues
                          |  +--ro input?    uint32
                          |  +--ro output?   uint32
                          +--ro dynamically-configured?    boolean
Clone this wiki locally