YIN and YANG
“Equally Balanced, as all things should be”. The idea of YIN and YANG reminds of the chinese concept of dualism, the balance between positive and negative forces.
(Un)fortunately in computer networking, YIN and YANG refers instead to data models used in network management protocols such as NETCONF and RESTCONF.
What about YANG?
YANG - Yet Another Next Generation, is a data model language defined in RFC 6020. YANG models data in a (upside down) tree format where each node has a name, and either a value or a set of child nodes. Nodes are created and defined in modules and submodules, which have their own set of hierarchy.
The power of YANG comes in automation processes, where YANG can be used in a similar way to JSON in programs and scripts. Network administrators can make use of YANG in their workprocesses, saving time and effort when retrieving network statistics or when pushing network configurations.
Also defined in RFC 6020 are YIN modules, which are essentially YANG modules translated into XML-based syntax. YIN and YANG are equivalent, just in different notations. This is important because YIN is directly used in NETCONF instead of YANG.
Trying NETCONF
I had access to a school-owned Cisco 3850 Switch so I decided to try NETCONF while I could. On my end, I provided a ethernet cable and a ubuntu raspberry pi to serve as the management device.
To start, I checked that the Cisco IOS version was compatible (v16) then enabled NETCONF using the command switch(config)# netconf-yang
. I also had to create a local user for
my pi to use via netconf username netconf privilege 15 password 0 cisco
.
On the raspberry pi, I installed python, python-pip and then netconf-console through pip.
pi# apt install -y python3 python3-pip
pi# pip3 install netconf-console
After ensuring network connectivity between the switch and pi, I was ready to start trying NETCONF commands.
The hello command will show all the YANG models that the network device supports.
pi# netconf-console --host <switch ip addr> --port 830 -u netconf -p cisco --hello
To get the running configuration, I’d send the get-config
command in place of “hello”.
pi# netconf-console --host <switch ip addr> --port 830 -u netconf -p cisco --get-config
Let’s say I wanted to check, then edit the configuration of interface Gi1/0/1 to use a different vlan:
pi#netconf-console --host 192.168.68.1 --port 830 -u netconf -p cisco \
--get-config -x "native/interface/GigabitEthernet[name='1/0/1']"
I would create an edit XML file in the style of the output shown above, editing the VLAN number to the one I desired.
Then send the edit-config command with the edit.xml file to make the configuration changes.
pi#netconf-console --host 192.168.68.1 --port 830 -u netconf -p cisco --edit-config=/tmp/edit.xml
Future of network programmability
NETCONF and YANG represent the future of network programming and configuration.
Networks in the future will be configured in this way. It is simply too troublesome and difficult to configure network devices though the command line especially when there are many of them.
While this post was just a quick overview, I hope to be learning more about network programming and development through Cisco’s DevNet courses in the near future.