- [Instructor] We have different ways
of configuring a network device,
like a router as an example.
We could connect via Telnet or preferably Secure Shell
and access the command line interface, the CLI
and we could give commands there.
Or, we could use something like SNMP,
the Simple Network Management Protocol.
SNMP has been around for a while,
it's gone through different versions
and SNMP version 3.0 has added quite a bit
of security but honestly,
there's a lot of SNMP version 2c out there
which is not nearly as secure.
And while SNMP is technically capable of doing
configuration on a device, most people
just use it for monitoring and it's not going to
be a scalable configuration option for us
in today's networks.
So in this video, we're going to take a look
at a new approach to configuration.
Instead of using something like Secure Shell
or SNMP, we're going to use NETCONF.
And why do we need this?
Well for one thing, we want our applications
to have a deeper integration into the network
and with devops, we've got the ability
to develop and deliver software to network devices
not just by traditional network engineers
but also developers.
And we also have cloud resources and web applications
that need a tighter integration with the network.
So while SNMP used to do a great job
of monitoring the network, it's not going to meet
our configuration needs today.
For example, we want a way that the network
can provide a service across multiple devices
and we're much more concerned about that,
instead of doing configuration on devices one at a time
and we want our solution to be vendor interoperable.
Different vendors have different syntax
to do things like, for example,
adding an IP address to an interface.
We want to be able to say, here's what we want to do
and it just occurs.
In other words, we want to express our intent,
that's why Cisco often uses the term,
intent-based networking.
Well, NETCONF is going to allow us to do that
and the term NETCONF comes from Network Configuration.
We just combine those words together
and NETCONF is an IETF standard.
It was released originally way back in 2006.
There's been updates since then
but 2006 is when it was originally introduced.
Now let's talk about how it works
and we're actually going to go out and do a live demo
later in this video, we're going to see it in action
but to begin to understand how NETCONF works,
let's go back and think about
the traditional client server model.
With a client server model, we would have a client
that maybe wants to retrieve a file from a server.
Well it's going to send a request to that server
and the server might respond with a reply
saying, okay, here's your file.
Well in the NETCONF world, instead of having
a client and a server, we're going to have
a manager and an agent and the manager's running
some sort of application, like a Python application
and it's going to send some sort of request to an agent.
And that agent might be a router, it might be a switch,
as a couple of examples.
This request might be a request for information,
or the request might be a configuration request,
where as an example, we're setting an IP address
of an interface and the format of this request
is typically going to be using the YANG Data model.
And we talked about YANG earlier in this course
and we're going to review it briefly,
later on in this video but YANG,
we said, was our way of modeling data
and that YANG data is encoded in XML format
using XML tags and what transports
this YANG data encoded in XML is NETCONF.
And by the way, NETCONF, it typically uses
Secure Shell to communicate between devices
and certainly, we could go in and use
Secure Shell ourselves and give commands
from that command line interface
but we don't want to do that.
Instead, we want to use one
of the utilities that are out there
and I'm going to show you NC Client
as a utility that we could use.
But for now, I just need you to understand
that this is the format.
We've got the data representing interface parameters
or routing protocol parameters as a couple of examples
and we've got that data in a YANG data model
and it's encoded in XML, inside of XML tags
and that's being transported using NETCONF,
going back and forth between the manager and the agent.
Now let's do a quick review of YANG data modeling
that we discussed earlier in the course.
Back earlier in the course, you might remember
that I gave you an example of an Apple iPhone.
I said that we could use the YANG data model
to describe an iPhone.
This model could specify the different
characteristics of an iPhone.
For example, we could say what model is it?
And we've got these options from current iPhones
at the time of this recording.
We could specify the display size available,
we could specify the color, we could specify
the storage capacity and my phone,
as an example is an Apple iPhone 11 Pro Max.
It's got a 6.5" display, the color is Space Gray
and it's got a storage capacity of 256 gigabytes.
That's a way to model an iPhone.
Well with YANG, we're typically going to model
the characteristics of a network device.
Here's an example that I showed you earlier in the course.
This is an IETF model of a network interface.
And by the way, some of the YANG data models
are created by a standards body like the IETF
and some YANG data models
are created by vendors, like Cisco.
Now up at the top, we see that we have a module name.
This is the name of the IETF YANG data model.
It's called ietf-interfaces.
And this model has a couple of containers.
The top container is called interfaces
and the bottom container is called interfaces-state
and the rw next to the interfaces up top,
that means that we can write information,
because rw stands for read-write.
So in this example, we can set the name
and the description as a couple of examples.
However, the interface state container
says our ro, for read-only.
Here, we can only retrieve information,
such as when was the last change made?
Or what is the device's physical address?
And under each container, we have a list
and take a look at the top container, if you would.
It's got a list called rw interface*
and then in brackets, we have name.
What goes in this name field?
That's kind of acting like a variable.
We could put different interface instances in there,
maybe gigabitethernet1,
or gigabitethernet2 and so on.
In other words, we can have multiple instances
of this list when we're populating it with real data
for real network devices.
And this is just the structure and the format
that we're going to be using and that variable,
the name in brackets, we're going to refer to that
as a Key and the characteristics under the list,
like rw description?,
that's called a Leaf.
And notice that leaf, if you look over to the right,
has the word, string.
That tells us that this is the datatype of this leaf.
Its populated with a string.
If we look further down though, we see that the type
of the data for the ro last-change? leaf
is yang:date-and-time
what's going on here?
Well here, the type of data
is actually another data model itself.
It's a data model within a data model.
Specifically, it's a model that shows
how we represent date and time and again,
this model is the structure that we're going to use
to populate with real data.
Now let's take a look at an example
where we have some actual, real data
and this is encoded in XML format,
which is the format that NETCONF is going to use
when it's sending a request over to an agent.
Up at the top, we have interfaces xmlns=
and then we have the namespace in quotes.
And this is all in the interfaces container.
Notice we're beginning the container
with a tag of interfaces, then we're ending the container
with a tag of /interfaces
and notice that the first interface node
has a name of GigabitEthernet1.
The description is "DON'T TOUCH ME".
And also notice that we have a node within a node.
We've got an IPv4 node inside of the interface node
and this is giving us information
about that interface's IPv4 addressing.
We see that the IP address is 10.10.10.10
with a /24 subnet mask.
And in this example, GigabitEthernet1
is the name of a leaf inside of this interface node.
And something to understand about YANG
is that it wasn't standardized until 2010
but remember I said that NETCONF
was standardized in 2006?
That means that for a while, vendors had to use
their own proprietary data modeling.
So NETCONF was working with vendor-specific data models.
But since YANG was standardized, people were gravitating
towards using a YANG data model.
Now let's take a look at NETCONF in action
by going out to some real gear that you can access.
Cisco does us a huge favor.
Cisco DevNet gives us a sandbox of real gear,
some of which we can reserve and use and configure
to learn and other devices are on all the time.
They're read-only, we're not able to update those
but we can access data from those devices.
That's what we're going to do here.
The Cisco DevNet sandbox, at the time
of this recording has a CSR1000v router
and it's running Cisco IOS XE
and what we want to do in this video
is have a Python program that's going to use
a YANG data model to pull down the configuration
of that router that's out of the Cisco DevNet sandbox.
And by the way, Cisco DevNet is continually updating
and changing what they have available.
They do an amazing job, all that to say
that what I'm showing you in this video
may be a little bit different when you go out
to Cisco DevNet but they're very likely to have
something out there that is going to be a read-only router
that you're going to be able to connect to.
It just might be a different sandbox
when you go check it out.
So let's hop out to that live interface.
Well we're setting out at the DevNet site now,
specifically to get to this page.
I went to develop.cisco.com/site/sandbox
and please keep in mind that the DevNet folks
are continually making improvements
and adding things to their site,
so it might be a different URL
than the one you see in this video
but you can always search
for Cisco DevNet sandbox and find it.
But I've already logged in.
If you haven't logged in, you need to go ahead
and log yourself in and I'm going to say
go to the sandbox catalog and this is very likely
to change by the time you watch this video
because they're always adding things
but I'm going to do a search for NETCONF.
And there are a few that say NETCONF in them.
Here's the one I'm looking for.
IOS XE on a Cloud Services Router.
Notice it's always on, we don't have to reserve this.
We don't have to set up a VPN connection
into the sandbox, we can just click on this
and it's going to give us credentials
for how we can communicate with this router.
Now it's going to be ready-only,
so we're not going to be doing configuration,
otherwise that could cause problems with multiple users
doing configurations, so it's going to be read-only for us
and that's fine, we'll use a Python program
that just retrieves information
instead of setting information but the concept is the same.
Notice here is our host name
and we're going to be using NETCONF,
which is going to be port 10000 here.
We see the username and the password.
We're going to be giving those arguments
as part of our Python command, when we execute the program.
If we scroll it just a little bit,
we see that we've got DevNet Python code samples.
Let's click on that and you see
several different samples that you can go through
and explore at your leisure.
There's a lot to be learned
just by looking through these Python programs.
But here, I just want to do a really basic one
as an example, let's get the configuration
from this CSR1000v router
and I want to use NC-get-config to do that.
And here's the Python program.
Notice it ends in a .py?
I'm going to click on this and I'll say Raw
and that's going to give me the actual program
and what I'm going to do is copy this
and I'm going to paste it into a text editor.
Now let's take a look at some of the things going on here.
First, I want you to notice that we're going
to be using a couple of modules
that you might not have installed.
We're going to be using a module called argparse,
which is argument parsing and ncclient is another module.
If we don't have those modules, we need to install those.
Let's talk about how we do that.
To install these extra packages that we need,
we're going to be using the Python
package manager, or PIP for short.
Here's the command we use.
It's pip and we're using version 3.8.
I'm going to say pip install argparse.
Now again, I've already got it installed
and it says the requirement is already satisfied,
so it's telling me that I already have it installed.
The other package or the other module
we might want to install is ncclient
and we can say pip3.8 install ncclient.
Again, I've already got it installed
and it says the requirement is already satisfied
but now, I think we have all of our dependencies in place.
So let's take a closer look at this Python file
and then let's run it.
We've got our packages or our modules installed.
Notice that we're going to be giving some arguments
as part of this Python command.
We're going to do a --host and then we're going to follow that
with the IP address or the domain name of our host
and remember, the host, if we go back
to our sandbox page, the host is io-xe-mgmt.cisco.com,
so we're going to specify that as an argument,
as part of our command.
It'll do a -u followed by the username,
a -p followed by the password and a --port
followed by the port, which is 10000.
And of course, as part of this Python program,
we're going to be referencing a YANG data model
and we can see that YANG data model right here.
Now let's save this file, I'm going to say Save.
In fact, I already have this file saved,
I called it nc-get-config.py
and I've got it in a Python directory.
Let's go out to that directory.
If I do a pwd for present working directory.
We see that I'm in my Python directory for my user.
Now let's issue this command
and I'll just paste it in to save time
but we're saying that Python 3.8,
'cause that's the version of Python we're running,
then we give the name of the Python file,
nc-get-config.py, then we give those arguments.
I say --host, followed by the host name
that we're given on the sandbox page, -u followed
by the username of developer, -p followed
by the password of C1sco12345
and for the port number, it told us that for NETCONF,
we're using 10000, so we have a --port 10000.
We're ready to press enter.
We press enter, we go out to Cisco DevNet sandbox
and it's going to retrieve the configuration
from this CSR1000v router and it's going to present it
to us as we see here, in XML format.
But XML, one of the great things about XML format
is that it's very readable.
So for example, if we scroll up just a bit,
we can see interface information, IP address information.
Notice under the interface node, I've got GigabitEthernet1
and we see a description for that interface,
we see its IP address is 10.10.20.48.
We've got a /24 subnet mask, we've also got GigabitEthernet2
and we see its IP address and its subnet mask.
We scroll up just a bit more,
we can see a default route that's been entered.
Under route, we have a prefix of all zeroes
and a mask of all zeroes, that means a default route
and we're going to be forwarding that default routes
to a next top address of 10.10.20.254
and again, because we're working with a router
that gives us read-only permissions,
we were only able to retrieve some information
but the process is the same.
We're typically going to either write
or own Python program, or more commonly,
we're going to get some existing code from GitHub
and we might modify it based on our needs
and we're going to see if we have all of the packages
that are required and if not, we'll install those.
And then we'll run it and let's all look
at how we can use NETCONF to, in this case,
get some information from our router.