Learn YANG! Full Tutorial for Beginners (Yet Another Next Generation)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right welcome back everyone to ultra config tutorials as I'm sure you've noticed we are living in a time of explosive growth for the network automation industry a core component of modern automation technology is the language yang yet another next generation in today's tutorial let's do a deep dive and learn the language from scratch so what is yang in short yang is a language used to describe data models of network devices the language is maintained by net mod an IETF working group that's the internet Engineering Task Force the latest version of yang is 1.1 and the full specification of the language is documented in RFC number seven nine five zero with that said what is a data model of a network device to answer that let's imagine a hypothetical scenario where your friend asks you what IP interface attributes can be configured on a specific router you might say well to configure an interface on this router you need to supply an interface name an IP address and a subnet mask you also need to enable the interface the router will keep the interface disabled if you don't now as simple as this response sounds what we just did there was described a data model for an IP interface a yang model will do the exact same thing but use strict syntax rules to make the model standardized and easy to process with computers note that in our response to our friend we didn't provide any specific values for an interface we only described the data structure this is an important distinction to note as it will make the bigger picture much easier to understand when we later talk about Netcom but first let's redo our IP interface example but this time we will describe the model using yang rather than plain English I'll be working on Ubuntu 18.04 for this demo as well as Windows for the text editor before we write our yang model let's install an excellent Python utility called pi yang which will allow us to interact with our model we'll also need two dependencies for the utility to work let's install them now I'll now install PI yang by cloning the repo from github and running the install script with that done let's create a new file for defining our yang model the file extension must be yang I'll name my file ultra config interfaces dot yang will now open the file in the text editor I'm using Visual Studio code but any text editor will work at the top of the file we'll add a module statement followed by the name of our module and a braces block the module name must match the name of our file all of the content we now add to the file will go inside the module braces next let's add header information meta information and revision history to our module you'll notice that in yang syntax strings are terminated by semicolons rather than newline characters this allows long strings to be spread over multiple lines preserving readability the labels yang version name space organization etc are known as statements in yang terminology let's go over the function of each statement we just added yang version this identifies the yang language specification that the module will conform to we will ensure our module conforms to yang 1.1 which is defined in RFC seven nine five zero namespace this is an XML namespace which must be unique for the module we used a URL but you can use a you RNA URI or any other unique identifier here the namespace specified here must match the name space of any XML objects which conform to our yang model we'll show you one of these XML instances later in the video prefix this is a short and unique string to identify our module this prefix may be used in other young modules to import definitions contained in this one organization simply a string identifying the entity responsible for the module we also have contact details for the entity responsible for the module and a description of the module and finally a revision statement used for version control each edit to a yang module will add a new revision statement detailing the changes in sub statements with the header and meta information out of the way we can now move on to our actual module definition the yang language includes a set of built-in data types the language also allows however the ability for developers to define their own data types we'll do that now for our ipv4 address and subnet masks both of these attributes should conform to the dotted quad data type that we will now define or add this definition to our yang module you may be thinking why not just use a string instead of defining a custom data type while this would work it would certainly be a bad practice in all programming it is always best to add constraints on the lowest layers to avoid a later Alliance on higher layers for error checking our dotted quad definition is quite simple once you get the idea our definition says to find a new type called don''t quad a value it will conform to this data type if it is a string and matches the regular expression defined in the pattern statement moving on let's now add a container for our interfaces our interfaces container will hold the child nodes for our configuration data and state data let's now distinguish between the meaning of these two data types understanding the difference is very important for yang and net comp development configuration data these are readwrite configuration fields for our interface example this would be the interface name IP address subnet mask and whether the interface is enabled or disabled from an admin point of view we also have state data these are read-only operational data fields for our interface example this could include a packet counter and operational State whether the port is physically up or down basically everything you can see on a router when you run show commands again remember that yang modules will only define the structure of configuration and state data it will not contain an instantiated value of the data all right will now add a list to our container for defining our interface configuration data our interface configuration data is quite readable we have four leaf nodes which define the attributes of an interface these are labeled with the identifier name address subnet mask and enabled three of the leaf nodes are marked as mandatory the enabled node is optional and will have a default value of false if not specified you'll also notice that the data type of the address and subnet mask is dotted quad this matches the identifiers from our earlier definition let's now add our state data to the interfaces container looking at the state data you'll notice that one key difference is the config statement which is set to false this indicates that the child nodes belonging to this list are read-only you'll also notice the enumeration data type which we haven't used before this is another built-in data type which allows us to restrict the valid values for this opera status node to a finite set in our case the operational status will only ever be up or down that concludes the construction of our yang module for an interface we may now proceed to interact with the module using pi yang let's copy our yang module over to our a burn to machine the first cool trick to learn with pi yang is basic validation if we run the utility without any options the command will ensure our yang module is syntactically correct if all is well the output should come out clean as it did just now if there are any syntax errors in the module the command will print a message explaining the issue to demonstrate this let's introduce a typographical error by replacing the type enumeration with the word spelled incorrectly I numeration running the validation command again we'll highlight the error alright now that we have confirmed that let's fix our spelling mistake the next great trick to learn is how to view the schema tree of a yang module the schema tree is a summarized visual form of a yang data model you can view the tree by adding the format specifier option within your command that's - F followed by the word tree let's run that now and there we go there are W acronym is short for read/write the RO acronym is short for read-only the question mark next to the enabled node indicates that this object is optional the rest of the tree is quite self-explanatory let's now move on to another awesome utility called yang 2d STL this binary is bundled into the PI yang project and should have been added to your system path upon installation the utility is short for yang to document schema definition languages the primary purpose of this tool is to convert yang modules 2d STL schemers but we can also use the tool to validate instances of data to ensure they conform to a yang module this will be easier to understand with an example here we have an XML instance of the yang module which we define today you can see the attributes we described in our yang module if you're familiar with net kampf this XML data object will look familiar to you this is what a payload looks like in a net comp request to edit the configuration of a network device will now use yang 2d STL to ensure the XML object is valid let's save the XML object to a file we'll call our file data dot XML we can now run the command to generate the dfdl schemas of our yang module and validate our data instance all looks well let's put an invalid IP address into our XML file and rerun the validation as expected we see that the validation has failed there we go that's everything essential you need to learn about yang with a solid grasp of the concepts of the yang language you'll find that network automation solutions built on top of the Netcom protocol become demystified neck omphh is the protocol for sending and receiving configuration data and state data of network devices and yang is the language which describes the structure of this data I hope you enjoyed this tutorial as much as I enjoyed making it you can download the full yang module we developed today on the ultra config website I'll leave a link to it in the description we'll also leave you with a few other resources the IETF maintained a large number of foundational yang modules check them out on net conf central another great resource is the open config github the open config workgroup maintained a large number of yang modules on github the intention of this project is to create common yang models that all network vendors can conform to this enables end users to use the same net kampf payloads across different devices and of course or leave a link to pi yang which was one of the best tools for yang developers out there before I end today's tutorial we'll also shout out ultra config net conf is great at pushing configuration to network devices but how do you actually automate the generation of network config ultra config is a powerful piece of software for automating the generation of network config if you work in the network engineering industry I highly recommend you to check it out the software includes an API to fully enable end-to-end network automation a link to the software will be in the description I'll also put a link in the description to a written form of today's tutorial for you to try it yourself so that's it for today already thanks for watching and I'll see you all in my next video
Info
Channel: Ultra Config
Views: 12,384
Rating: 4.9307361 out of 5
Keywords: yang, yet another next generation, yang tutorial, learn yang, pyang, pythondev, ietf, netconf
Id: zy9QA-uU0u4
Channel Id: undefined
Length: 16min 19sec (979 seconds)
Published: Sat Jan 04 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.