Data Formats and Data Models
Data Formats and Data Models
command-line interface (CLI). The CLI is great for humans, but not so great for
Unit 1: Cloud
computers.
Unit 2: Network
programmability (SDN)
We use con guration commands to con gure everything and show or debug commands
Data Models and Structures
to verify our work. The output of show (and debug) commands is formatted, so it’s easy
Device Programmability
to read for humans. However, it’s a pain to use the CLI for scripts or network automation
Controller Based Network Design
tools. You have to parse a show command to get the information you want, and the
Con guration Management Tools
output is di erent for each show command.
and Version Control Systems
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Con guration commands are also an issue. On Cisco IOS, when you enter a command,
Unit 3: Internet of Things
(IoT)
there is no con rmation of whether the router or switch accepts the command or not.
Unit 4: Practice Exam
You only see the empty prompt. If you paste a lot of commands, sometimes the console
can’t keep up. For us humans, it’s easy to spot this and work around it. For CLI scripts or
network automation tools, it’s a problem and you have to take this into account.
Data Formats
There are two common data formats that APIs often use:
We also call these data formats “data serialization languages”. Another data format we
often use for device con guration is YAML. Let’s talk about these three data formats.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
01:25
Each item you add has to start with < and end with >. Here is a simple example:
<router>
<name>CSR1000V</name>
<vendor>Cisco</vendor>
<type>virtual</type>
</router>
<router>
<name>1921</name>
<vendor>Cisco</vendor>
<type>hardware</type>
</router>
</devices>
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
The output above shows the tag with two tags in it. The rst tag contains information
about a CSR1000V router. The second tag contains information about a 1921 router.
Let me show you the output of an actual router. Here is the output of show running-
con guration as seen from the CLI:
hostname R1
!
ip cef
!
interface GigabitEthernet0/1
ip address 192.168.12.1 255.255.255.0
duplex auto
speed auto
media-type rj45
!
interface GigabitEthernet0/2
ip address 192.168.1.254 255.255.255.0
duplex auto
speed auto
media-type rj45
!
end
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
R1#show running-config | format
<?xml version="1.0" encoding="UTF-8"?>
<Device-Configuration
xmlns="urn:cisco:xml-pi">
<version>
<Param>15.6</Param>
</version>
<service>
<timestamps>
<debug>
<datetime>
<msec/>
</datetime>
</debug>
</timestamps>
</service>
<service>
<timestamps>
<log>
<datetime>
<msec/>
</datetime>
</log>
</timestamps>
</service>
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
<service operation="delete" >
<password-encryption/>
</service>
<hostname>
<SystemNetworkName>R1</SystemNetworkName>
</hostname>
<ip>
<cef/>
</ip>
<interface>
<Param>GigabitEthernet0/1</Param>
<ConfigIf-Configuration>
<ip>
<address>
<IPAddress>192.168.12.1</IPAddress>
<IPSubnetMask>255.255.255.0</IPSubnetMask>
</address>
</ip>
<duplex>
<auto/>
</duplex>
<speed>
<auto/>
</speed>
<media-type>
<rj45/>
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
</media-type>
</ConfigIf-Configuration>
</interface>
<interface>
<Param>GigabitEthernet0/2</Param>
<ConfigIf-Configuration>
<ip>
<address>
<IPAddress>192.168.1.254</IPAddress>
<IPSubnetMask>255.255.255.0</IPSubnetMask>
</address>
</ip>
<duplex>
<auto/>
</duplex>
<speed>
<auto/>
</speed>
<media-type>
<rj45/>
</media-type>
</ConfigIf-Configuration>
</interface>
<end></end>
</Device-Configuration>
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
One more example. Here is show arp with the CLI output:
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
<entry>
<Protocol>Internet</Protocol>
<Address>192.168.1.2</Address>
<Age>8 </Age>
<MAC>fa16.3ee0.c9b2</MAC>
<Type>ARPA</Type>
<Interface>FastEthernet0/0</Interface>
</entry>
<entry>
<Protocol>Internet</Protocol>
<Address>192.168.1.3</Address>
<MAC>fa16.3ee0.a5a5</MAC>
<Type>ARPA</Type>
<Interface>FastEthernet0/0</Interface>
</entry>
</ARPTable>
</ShowArp>
These XML outputs are indented which makes them easier to read for us humans.
Indentation however, is not a requirement of XML.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Objects start with { and end with }.
Commas separate objects.
Double quotes wrap names and strings.
Lists start with [ and end with ].
XML:
<router>
<name>CSR1000V</name>
<vendor>Cisco</vendor>
<type>virtual</type>
</router>
<router>
<name>1921</name>
<vendor>Cisco</vendor>
<type>hardware</type>
</router>
</devices>
JSON:
"devices": {
"router": [
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
{
"name": "CSR1000V",
"vendor": "Cisco",
"type": "virtual"
},
{
"name": "1921",
"vendor": "Cisco",
"type": "hardware"
}
]
}
}
If you look at the output above, you can see we used the tag twice in XML. In JSON, we
only need a single “router” object. This is a list with two objects.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Lists begin with a – (hyphen).
Indentation is a requirement. You have to use spaces, you can’t use tabs.
You can add comments with a #.
We often use YAML les for con guration management because it’s easy to read and
comments are useful.
Let’s compare JSON with YAML. Here’s the JSON object I showed you before:
JSON:
{
"devices": {
"router": [
{
"name": "CSR1000V",
"vendor": "Cisco",
"type": "virtual"
},
{
"name": "1921",
"vendor": "Cisco",
"type": "hardware"
}
]
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
}
}
Here it is in YAML:
devices:
router:
- name: CSR1000V
vendor: Cisco
type: virtual
- name: 1921
vendor: Cisco
type: hardware
YAML is easier to read without the commas and brackets of JSON. One disadvantage of
YAML is that indentation with spaces is a requirement. It’s easy to make indentation
errors where you have a space too few or too many.
When you work with XML, JSON, or YAML les, you can make your life much
easier if you use an editor that helps with visualization and indentation. I use
Visual Studio Code for almost everything nowadays.
Data Models
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Data models describe the things you can con gure, monitor, and the actions you can
perform on a network device. In this section, we will discuss YANG.
01:09
YANG is a modeling language and uses data models that are similar to to SNMP
Management Information Base (MIBs). YANG is a standard, described in RFC 6020
and increasing in popularity. YANG uses data models that describe:
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
What you can con gure on a device.
What you can monitor on a device.
Administrative actions you can perform on a device like clearing interface counters
or resetting the OSPF process.
These data models allow a uniform way for us to con gure, monitor, and interact with
network devices. Network automation tools like NETCONF, RESTCONF, and gRPC require
YANG data models. YANG uses a hierarchical tree structure, similar to the XML data
format. There is a clear distinction between con guration data and state
information.
A YANG module de nes a data model through the data of a network device, and the
hierarchical organization and constraints of that data. YANG identi es each module with
a namespace URL.
You can nd a collection of YANG modules in the YANG git repository. In this repository,
there are also Cisco modules. For example, take a look at the modules for IOX XE 16.10.1
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
There are many module les in the repository. Here is the ARP module to create a static
ARP entry:[teaser]
module Cisco-IOS-XE-arp {
namespace "http://cisco.com/ns/yang/Cisco-IOS-XE-arp";
prefix ios-arp;
import ietf-inet-types {
prefix inet;
}
import Cisco-IOS-XE-native {
prefix ios;
}
organization
"Cisco Systems, Inc.";
contact
"Cisco Systems, Inc.
Customer Service
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Tel: +1 1800 553-NETS
E-mail: [email protected]";
description
"Cisco XE Native Access Point (AP) Group Yang model.
Copyright (c) 2018 by Cisco Systems, Inc.
All rights reserved.";
//
=================================================================
========
// REVISION
//
=================================================================
========
revision 2018-06-28{
description
"Added must constraints for deleting vrf";
}
revision 2018-06-17{
description
"Add arp alias";
}
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
revision 2017-11-07 {
description
"Add arp vrf";
}
revision 2017-01-16 {
description
"Initial Revision";
}
grouping arp-entry-grouping {
list arp-entry {
description
"Configure an arp entry";
key "ip";
leaf ip {
description
"IP address of ARP entry";
type inet:ip-address;
}
leaf hardware-address {
description
"48-bit hardware address of ARP entry";
type string;
}
leaf arp-type {
type enumeration {
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
enum ARPA;
enum SAP;
enum SMDS;
enum SNAP;
enum SRP-A;
enum SRP-B;
}
}
leaf alias {
description
"Respond to ARP requests for the IP address";
type empty;
}
}
}
grouping config-arp-grouping {
container arp {
description
"Set a static ARP entry";
uses arp-entry-grouping;
list vrf {
description
"Configure static ARP for a VPN Routing/Forwarding
instance";
key "vrf-name";
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
leaf vrf-name {
description
"VPN Routing/Forwarding instance name";
must
"/ios:native/ios:vrf/ios:definition[ios:name=current()] or
/ios:native/ios:ip/ios:vrf[ios:name=current()]" {
error-message "VRF must be created 1st, deleted
last";
}
type string;
}
uses arp-entry-grouping;
}
}
}
/////////////////////////////////////////////////////////
// native
/////////////////////////////////////////////////////////
augment "/ios:native" {
uses config-arp-grouping;
} //augment
} //module
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Above you can see that “Cisco-IOS-XE-arp” is the name of the YANG module. This
module describes the data model to create static ARP entries.
The output above is di cult to read. There is a useful tool called pyang that creates an
easily readable tree format. Pyang also shows all user con gurable elds (rw) and state
values (ro). Here is an example:
module: Cisco-IOS-XE-arp
augment /ios:native:
+--rw arp
+--rw arp-entry* [ip]
| +--rw ip inet:ip-address
| +--rw hardware-address? string
| +--rw arp-type? enumeration
| +--rw alias? empty
+--rw vrf* [vrf-name]
+--rw vrf-name string
+--rw arp-entry* [ip]
+--rw ip inet:ip-address
+--rw hardware-address? string
+--rw arp-type? enumeration
+--rw alias? empty
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Above, you see all the user con gurable elds to create an ARP entry.
In the device programmability lesson, you can see how we use YANG to con gure and
monitor Cisco devices.
Conclusion
You have now learned about data models and structures:
The CLI is great for humans, but not so great for script and network automation.
Di cult to parse show commands.
Pasting commands is unreliable.
APIs are an alternative to the CLI.
APIs use data formats (data serialization languages) to exchange information.
XML is a tag-based language.
Each item starts with < and ends with >.
JSON stores information in key-value pairs and uses objects.
Rules:
Objects start with { and end with }.
Commas separate objects.
Double quotes wrap names and strings.
Lists start with [ and end with ].
Easier to read than XML.
Less overhead than XML.
YAML is a superset of JSON.
Human friendly format, easy to read.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Rules:
We separate key-value pairs with : (colon).
Lists begin with a – (hyphen).
Indentation with spaces is a requirement. You can’t use tabs.
You can add comments with a #.
YAML les are popular for con guration management:
It’s easy to read.
Comments are useful.
YANG is a modeling language, described in RFC 6020 and an alternative to SNMP.
YANG uses data models to describe what you can con gure and monitor on
network devices.
Data models can be common industry-wide standards or vendor speci c.
YANG uses a hierarchical tree structure, similar to XML
There is a clear distinction between con guration data and state information.
I hope you enjoyed this lesson. If you have any questions, feel free to leave a comment.
« Previous Lesson
Network Automation and
Orchestration
Next Lesson
Device Programmability »
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Hello There! New Lessons
I am René IoT Edge and Fog computing
Molenaar IoT Security
(CCIE #41726),
IoT Standards and Protocols
Your main
IoT Technology Stack
Instructor. My
goal is to teach you everything Connect ESP32 MicroPython to
about Cisco, Wireless and AWS IoT
Security. I am here to Help You
Master Networking!
Read my story
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD