240 likes | 386 Views
YANG Boot Camp. The YANG Gang IETF 70. WANTED: a DML for NETCONF. NETCONF base protocol defined in RFC4741 Defines RPC mechanism and operations Left content and data models for future work <get>, <get-config> and <edit-config> allow any XML No data modeling language == no data models.
E N D
YANG Boot Camp The YANG Gang IETF 70
WANTED: a DML for NETCONF • NETCONF base protocol defined in RFC4741 • Defines RPC mechanism and operations • Left content and data models for future work • <get>, <get-config> and <edit-config> allow any XML • No data modeling language == no data models
YANG is …. • A language for modeling NETCONF data models • An SMI for NETCONF • Able to model config data, state data, RPCs, and notifications • Based on SMIng syntax • Text-based • Email, patch, and RFC friendly
YANG .... • Preserves investment in SNMP MIBs • libsmi translates MIBs to YANG • See tools at www.yang-central.org • Directly maps to XML content (on the wire) • Extensible • Add new content to existing data models • Add new statements to the YANG language
YANG rocks, dude! • Readability Rules! • Doesn't boil the ocean • Limited scope • But maximize utility within that scope • Based on three proprietary DMLs • Years of experience within multiple vendors • Quality draft backed by running code • Usable in current form • Download the code and use it today • www.yang-central.org
Modules and submodules • Header statements • yang-version, namespace, prefix • Linkage statement • import and include • Meta information • organization, contact • Revision history • revision
module acme-module { namespace "http://acme.example.com/module"; prefix "acme"; import “yang-types” { prefix yang; } include “acme-system”; organization "ACME Inc."; contact "joe@acme.example.com"; description "The module for entities implementing the ACME products"; revision 2007-06-09 { description "Initial revision."; } … }
leaf • one value, no children, one instance YANG Example: leaf host-name { type string; mandatory true; config true; description "Hostname for this system"; } NETCONF XML Encoding: <host-name>my.example.com</host-name>
leaf-list • one value, no children, multiple instances YANG Example: leaf-list domain-search { type string; ordered-by user; description "List of domain names to search"; } NETCONF XML Encoding: <domain-search>high.example.com</domain-search> <domain-search>low.example.com</domain-search> <domain-search>everywhere.example.com</domain-search>
container • no value, holds related children, one instance • may have specific meaning, or may simply contain other nodes • presence
YANG Example: container system { container services { container ssh { presence "Enables SSH"; description "SSH service specific configuration"; // more leafs, containers and stuff here... } } } NETCONF XML Encoding: <system> <services> <ssh/> </services> </system>
must • Constrains nodes by XPath expression container timeout { leaf access-timeout { description "Maximum time without server response"; units seconds; mandatory true; type uint32; } leaf retry-timer { description "Period to retry operation"; units seconds; type uint32; must "$this < ../access-timeout" { error-app-tag retry-timer-invalid; error-message "The retry timer must be " + "less than the access timeout"; } } }
list • uniquely identified by keys, holds children • no value, holds related children (including keys), multiple instances
YANG Example: list user { key name; unique uid; leaf name { type string; } leaf uid { type uint32; } leaf full-name { type string; } leaf class { type string; default viewer; } } NETCONF XML Encoding: <user> <name>glocks</name> <full-name>Goldie</full-name> <class>intruder</class> </user> <user> <name>snowey</name> <full-name>Snow</full-name> <class>free-loader</class> </user> <user> <name>rzull</name> <full-name>Repun</full-name> </user>
augment • Extends data model • Current or imported modules • Inserts nodes into an existing hierarchy • Nodes appear in current module's namespace • Original (augmented) module is unchanged • "when" makes sparse augmentation • Nodes are only added when condition is true • "when" is XPath expression
YANG Example: augment system/login/user { when "class != 'wheel'"; leaf uid { type uint16 { range "1000 .. 30000"; } } } NETCONF XML Encoding: <user> <name>alicew</name> <full-name>Alice N. Wonderland</full-name> <class>drop-out</class> <other:uid>1024</other:uid> </user>
rpc • Defines RPC method names, input parameters, and output parameters rpc activate-software-image { input { leaf image-name { type string; } } output { leaf status { type string; } } }
notification notification link-failure { description "A link failure has been detected"; leaf if-index { type int32 { range "1 .. max"; } } leaf if-name { type keyref { path "/interfaces/interface/name"; } } }
Semantic Differentiators • YANG gives the syntax, but that's not all • Here are some you just saw: • unique • must • keyref • config • default • error-app-tag/error-message • mandatory • presence • ordered-by
Built-in types +---------------------+-------------+-------------------------------+ | Name | Type | Description | +---------------------+-------------+-------------------------------+ | int8 | Number | 8-bit signed integer | | int16 | Number | 16-bit signed integer | | int32 | Number | 32-bit signed integer | | int64 | Number | 64-bit signed integer | | uint8 | Number | 8-bit unsigned integer | | uint16 | Number | 16-bit unsigned integer | | uint32 | Number | 32-bit unsigned integer | | uint64 | Number | 64-bit unsigned integer | | float32 | Number | 32-bit IEEE floating point | | | | real number | | float64 | Number | 64-bit IEEE floating point | | | | real number | | string | Text | Human readable string | | boolean | Text | "true" or "false" | | enumeration | Text/Number | Enumerated strings with | | | | associated numeric values | | bits | Text/Number | A set of bits or flags | | binary | Text | Any binary data | | keyref | Text/Number | A reference to a list's key | | | | value | | empty | Empty | A leaf that does not have any | | | | value | | anyxml | Text | Represents any XML data | | union | Text/Number | Choice of member types | | instance-identifier | Text | References a data tree node | +---------------------+-------------+-------------------------------+
Derived types YANG Example typedef percent { type uint16 { range "0 .. 100"; } description "Percentage"; } leaf completed { type percent; } NETCONF XML Encoding: <completed>20</completed> • Constraints • range • length • pattern
grouping YANG Example grouping target { leaf address { type inet:ip-address; description "Target IP address"; } } container peer { container destination { uses target; } } NETCONF XML Encoding: <peer> <destination> <address>192.0.2.1</address> </destination> </peer> • struct / record • Define once • Use multiple times • Refinement
choice YANG Example choice snack { case sports-arena { leaf pretzel { type empty; } leaf beer { type empty; } } case late-night { leaf chocolate { type enumeration { enum dark; enum light; } } } } NETCONF XML Encoding: <chocolate>dark</chocolate> • Constrains data to the contents of one "case" • choice and case names do not appear in XML content • Used by augment
What can you do to help? • Read the draft • There's a lot more in there • Join the mailing list • yang@ietf.org • https://www.ietf.org/mailman/listinfo/yang • Try out the tools • www.yang-central.org