- [Instructor] In the last couple of videos,
we've talked about different ways of formatting data.
We've talked about JSON formatting and XML formatting.
Well in this video, we want to talk about data modeling
using YANG data modeling.
Let's think about why that might be useful.
We could write, as an example, a Python program
to send configuration commands
to our Cisco devices using utilities like netmiko
or paramiko, where we actually send the commands
of configure terminal and interface gigabit zero slash one
and the IP address, all those regular Cisco IOS commands.
But what if we had equipment from multiple vendors?
Maybe we've got Juniper gear or Cisco gear
or some other vendor.
In that instance, we could use something called NETCONF,
which we'll talk about later on in this course.
But when we are using NETCONF, as we'll see later,
we'll typically see a YANG data model.
But for now, just understand that with the YANG data model
we don't have to know specific syntax that's used by Juniper
or Cisco or some other vendor to perform a specific task.
Instead, we're just going to use
a data model for their equipment.
Think of a configuration element like configuring
an interface with a speed and a duplex.
We can have a data model for doing that configuration.
Let's say, interface gigabit one.
We want it to have full duplex.
We want it to have a certain description.
Well, we can put that configuration into
a data model and use that instead of going in
and giving platform-specific configuration commands.
That's going to make it a lot easier for us
to configure a wide variety of network gear.
And the concept of YANG was developed by the IETF,
that was back around the year 2010,
and you can read about it in a couple of RFCs,
like 6020 and 6021.
And if you want to see some examples of data models,
here is a URL that you might want to go check out
and you can peruse some of the different examples.
But in this video, I just want you to understand what
a YANG data model is used for.
To do that, let's consider a really simplified example
of a data model.
Let's say that we wanted a data model
to describe what kind of iPhone somebody has.
And, of course, there are many different models
of iPhones, but I'm just going to use some
of the current iPhone models, just to make this point.
Now personally, the model that I have is an 11 Pro Max.
That would be my model.
Or if it was something else, we could say other.
And for the 11 Pro Max, the diagonal display size
is 6.5 inches.
So as I'm filling out the data model for my specific iPhone,
I'm specifying all these characteristics.
Here's the model, here's the display size.
What's the color?
Well, in my case, it's space gray.
Its capacity is 256 gigabytes.
So what I could do is just use this data model
where we're specifying model, display size, color,
and capacity, and I could just fill it in with my data.
So here is a populated data model describing my iPhone.
It's an 11 Pro Max with a 6.5 inch display.
It's space gray.
It's got 256 gigabytes of storage.
And that's a very simplified example
of what a data model is.
Now let's look at an IETF data model for an interface.
And this interface could be from a Cisco router
or a router from some other vendor.
By the way, this a screenshot from one
of the DevNet labs Cisco makes available to us.
And I'll take you out to the DevNet labs later
and you can go through some of their lessons on YANG
and learn YANG at an even deeper level.
But here I wanted us to use this as an example
and dissect it a bit here in this video.
And this YANG data model is for a network interface.
First, up top, notice there is a module name.
We're thinking of this as
a module that describes an interface.
This module has a couple of containers.
Notice that the top one says rw, for read/write, interfaces.
And the other one says ro,
for read only, interfaces-state.
Those are my two containers.
Again, notice the first one is read/write.
This is where I could set some information.
I could do some configuration of parameters.
Ro, that's read only, that's only going to get information.
I can monitor this type of information
and that includes interface statistics in this example.
And inside each container we have a list.
As an example, take a look at the list in the top container.
We have a list and it says, rw interface*
and that's followed by the word name in brackets.
Notice we're not specifying an interface name here.
We're just going to put the interface name
in where it says name.
That means we could have multiple instances of this.
We could have a list of several interfaces.
This is going to act as a guide,
but we could create a list for interface gigabit one,
gigabit two, and so on.
In fact, the name of the interface,
since we're talking about interfaces,
we could be talking about routing protocols
but here we're talking about interfaces.
We call that name the key.
And in our instance, each interface is going to have
a unique key, a unique name.
And the interface, which is what we have in this example,
has several attributes.
Each attribute is called a leaf.
For example, rw description?,
that's going to be a description for this specific interface.
Rw means that we can write or set this value,
while ro would mean that we could only read the value.
And notice in the right column of the leaf
we have the word string.
This is telling us what kind
of data can populate this attribute.
In here, we could have a string of characters
to give a description for this interface.
But sometimes we have to be more specific.
For example, if we're talking about time,
we have yang:date-and-time.
This field is the type field.
It can be something as simple as a string
or it could be, as we see here, another data model.
Here, we have a YANG data model of date-and-time
and this is type data that can go
into this last-change? attribute.
And this model that we're seeing on screen is
a model without any specific information.
Let's look at it when it's populated
with some specific information that we might
be sending out to do some configuration on a router.
Again, I got this screen from one of the DevNet labs
and we'll go take a look at how to get
to those DevNet labs later on in this video.
But this is the same data model,
except this time it's populated with a few things.
First of all, up top we have xmlns.
That's the XML namespace.
And what's it telling us?
If you look at the end of the string
it says ietf-interfaces.
It's telling us the specific YANG model that we're using.
And notice that we have an interfaces container
and when we talked about XML in the previous video,
remember that we said we had a start tag and an end tag?
That's what we have here.
We have the word interfaces inside of those less than
or greater than sign brackets, that's our start tag.
And then if you look a little bit further down in the file,
you see /interfaces inside of those less than,
greater than brackets.
That's our end tag.
And we have an interface node that's named gigabit one.
And we've got some information about it including
a description, the fact that it's enabled,
but notice there's another node inside.
There's an IPv4 node, and that's giving us information about
the IP version four addressing.
It's saying that this interface has
an IP version four address of 10.10.10.10,
it's got a subnet mask of 255.255.255.0
and is a reminder of something we said a few moments ago.
We said that a leaf was an attribute.
Here, the name of gigabit one is an attribute
of the interface.
And we've been focusing on gigabit one,
but if you look further down the file
there's also information, not much of it,
but we do have some information
for interface gigabit ethernet two
and gigabit ethernet three.
So what if we did this?
What if we entered our configuration information in
a data model like this and sent it to our device?
Whether it's Cisco, whether it's Juniper,
whether it's Ericsson, or some other vendor out there.
The point is, we don't have
to know vendor-specific configuration commands.
We just put it in the data model
and we can use a utility like NETCONF
to send the information out in XML format.
Think of it this way.
NETCONF is carrying, in XML format, the YANG data.
That means we put our configuration in the YANG data model.
We then encode that in XML format
and we send that XML formatted data using NETCONF.
And we'll talk about NETCONF later on in this course,
but if you want to take a closer look at YANG
and go through some additional examples,
I mentioned that DevNet made some labs available to us.
And to access those labs, you can go over
to learninglabs.cisco.com.
Here we're sitting at the DevNet Learning Labs
and you can get logged in.
If you don't have an account, you can get a free account.
But we click on Labs and then we can search for YANG
and press enter.
And we can scroll down and there
are several different YANG labs that we can go through.
And I think that will be time well spent.
It's going to help you better understand
how YANG data modeling works.