YANG Data Types
Configuration and State Data
YANG can model state data and configuration data based on the "config" statement. If a node is tagged with "config false", its subhierarchy is flagged as state data. If a node is tagged with "config true", its subhierarchy is flagged as configuration data. When state data is queried using NETCONF's <get> operation, parent containers, lists, and key leaf nodes are also reported, providing a specific context for the state data.
In the following example, two leaf nodes are defined for each interface, a configured interface status and an observed speed. The observed speed is not configurable, so it can be returned with NETCONF's <get> operations, but not with <get-config> operations.
container interfaces { list interface { key "name"; leaf name { type string; } leaf status { type boolean; default "true"; } leaf observed-speed { type yang:gauge64; units "bits/second"; config false; } } }
Built-in Types
Like many programming languages, YANG has a set of built-in types, but differs in terms of special requirements from the management domain. Table 8-8 summarizes the built-in types.
Type Name | Description |
---|---|
binary |
Any binary data |
bits |
Set of bits or flags |
boolean |
"true" or "false" |
decimal64 |
64-bit signed decimal number |
empty |
Leaf node without a value |
enumeration |
Enumerated strings |
identityref |
Reference to an abstract identity |
instance-identifier |
Reference to a data tree node |
int8 |
8-bit signed integer |
int16 |
16-bit signed integer |
int32 |
32-bit signed integer |
int64 |
64-bit signed integer |
leafref |
Reference to a leaf instance |
string |
Human-readable string |
uint8 |
8-bit unsigned integer |
uint16 |
16-bit unsigned integer |
uint32 |
32-bit unsigned integer |
uint64 |
64-bit unsigned integer |
union |
Choice of member types |
Derived Types
YANG can define derived types from base types using the "typedef" statement. Base types can be built-in types or derived types.
YANG example:
typedef percent { type uint8 { range "0 .. 100"; } description "Percentage"; } leaf completed { type percent; }
NETCONF XML example:
<completed>20</completed>
Extending Data Models
Extending data models (augment)
YANG allows a module to insert additional nodes into data models. This is useful for helping vendors to add vendor-specific parameters to standard data models in an interoperable way.
The "augment" statement defines the location in the data model hierarchy where new nodes are inserted, and the "when" statement defines the conditions when the new nodes are valid.
YANG example:
augment /system/login/user { when "class != 'wheel'"; leaf uid { type uint16 { range "1000 .. 30000"; } } }
This example defines a "uid" node that is valid only when the user's "class" is not "wheel".