### Define instance-identifier examples
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Examples of instance-identifier paths for various YANG data structures including containers, lists, and leaf-lists.
```text
/* instance-identifier for a container */
/ex:system/ex:services/ex:ssh
/* instance-identifier for a leaf */
/ex:system/ex:services/ex:ssh/ex:port
/* instance-identifier for a list entry */
/ex:system/ex:user[ex:name='fred']
/* instance-identifier for a leaf in a list entry */
/ex:system/ex:user[ex:name='fred']/ex:type
/* instance-identifier for a list entry with two keys */
/ex:system/ex:server[ex:ip='192.0.2.1'][ex:port='80']
/* instance-identifier for a list entry where the second
key ("enabled") is of type "empty" */
/ex:system/ex:service[ex:name='foo'][ex:enabled='']
/* instance-identifier for a leaf-list entry */
/ex:system/ex:services/ex:ssh/ex:cipher[.='blowfish-cbc']
/* instance-identifier for a list entry without keys */
/ex:stats/ex:port[3]
```
--------------------------------
### XML Instance Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
A basic XML representation of an HTTP server configuration.
```xml
extern-web
192.0.2.1
80
```
--------------------------------
### YANG Module Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
An example YANG module demonstrating the use of organization, contact, description, and revision statements, along with importing common types.
```yang
module example-system {
yang-version 1.1;
namespace "urn:example:system";
prefix "sys";
import ietf-yang-types {
prefix "yang";
reference "RFC 6991: Common YANG Data Types";
}
include example-types;
organization "Example Inc.";
contact
"Joe L. User
Example Inc.
42 Anywhere Drive
Nowhere, CA 95134
USA
Phone: +1 800 555 0100
Email: joe@example.com";
description
"The module for entities implementing the Example system.";
revision 2007-06-09 {
description "Initial revision.";
}
// definitions follow...
}
```
--------------------------------
### XML Instances for Protocol Choice
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
XML examples showing the protocol choice extension.
```xml
or
```
--------------------------------
### YANG Integer Lexical Representation Examples
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Examples of valid and invalid integer representations in YANG modules, including decimal, hexadecimal, and octal formats.
```YANG
// legal values
+4711 // legal positive value
4711 // legal positive value
-123 // legal negative value
0xf00f // legal positive hexadecimal value
-0xf // legal negative hexadecimal value
052 // legal positive octal value
// illegal values
- 1 // illegal intermediate space
```
--------------------------------
### Define Example Module
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
A complete YANG module definition combining containers, lists, and leaf-lists.
```yang
// Contents of "example-system.yang"
module example-system {
yang-version 1.1;
namespace "urn:example:system";
prefix "sys";
organization "Example Inc.";
contact "joe@example.com";
description
"The module for entities implementing the Example system.";
revision 2007-06-09 {
description "Initial revision.";
}
container system {
leaf host-name {
type string;
description
"Hostname for this system.";
}
leaf-list domain-search {
type string;
description
"List of domain names to search.";
}
container login {
leaf message {
type string;
description
"Message given at start of login session.";
}
list user {
key "name";
leaf name {
type string;
}
leaf full-name {
type string;
}
leaf class {
type string;
}
}
}
}
}
```
--------------------------------
### Define an identityref module
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
A module example demonstrating the use of identityref with a base statement.
```YANG
module example-my-crypto {
yang-version 1.1;
namespace "urn:example:my-crypto";
prefix mc;
import "example-crypto-base" {
prefix "crypto";
}
identity aes {
base "crypto:crypto-alg";
}
leaf crypto {
type identityref {
base "crypto:crypto-alg";
}
}
container aes-parameters {
when "../crypto = 'mc:aes'";
...
}
}
```
--------------------------------
### YANG 1.1 Leafref Path Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example demonstrating the usage of leafref with a path statement to reference other nodes.
```APIDOC
## Leafref Path Usage
### Description
This example shows how leafref can be used to reference specific nodes within the data tree, including conditional referencing based on other node values.
### YANG Data Model Snippet
```yang
list interface {
key "name type";
leaf name {
type string;
}
leaf type {
type string;
}
leaf enabled {
type boolean;
}
}
container mgmt-interface {
leaf name {
type leafref {
path "/interface/name";
}
}
leaf type {
type leafref {
path "/interface[name=current()/../name]/type";
}
must 'deref(.)/../enabled = "true"' {
error-message
"The management interface cannot be disabled.";
}
}
}
```
```
--------------------------------
### YANG Leafref Path Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Demonstrates the use of leafref with path statements to reference other nodes within a YANG data model. The example shows how to reference a leaf in a list and how to use predicates with current() for conditional referencing.
```yang
list interface {
key "name type";
leaf name { ... }
leaf type { ... }
leaf enabled {
type boolean;
}
...
}
container mgmt-interface {
leaf name {
type leafref {
path "/interface/name";
}
}
leaf type {
type leafref {
path "/interface[name=current()/../name]/type";
}
must 'deref(.)/../enabled = "true"' {
error-message
"The management interface cannot be disabled.";
}
}
}
```
--------------------------------
### NETCONF operations for ordered lists
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
RPC examples for inserting or moving entries within an ordered-by user list.
```XML
barney
rubble
admin
```
```XML
barney
rubble
```
--------------------------------
### XML notification example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
An example of an XML notification corresponding to the link-failure definition.
```XML
2008-04-01T00:01:00Z
eth0
up
```
--------------------------------
### Define a YANG Module with Imports and Features
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example structure of a YANG module demonstrating versioning, namespace, imports, and feature definitions.
```yang
module a {
yang-version 1.1;
namespace "urn:example:a";
prefix "a";
import b {
revision-date 2015-01-01;
}
import c;
revision 2015-01-01;
feature foo;
augment "/b:x" {
```
--------------------------------
### NETCONF edit-config operations
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
RPC examples for creating new list entries and modifying existing ones.
```XML
barney
admin
Barney Rubble
```
```XML
fred
superuser
```
--------------------------------
### YANG 'must' Statement Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Demonstrates the use of the 'must' statement with 'error-message' to enforce conditional constraints on data. This example shows how to validate interface type and MTU values.
```yang
container interface {
leaf ifType {
type enumeration {
enum ethernet;
enum atm;
}
}
leaf ifMTU {
type uint32;
}
must 'ifType != "ethernet" or ifMTU = 1500' {
error-message "An Ethernet MTU must be 1500";
}
must 'ifType != "atm" or'
+ ' (ifMTU <= 17966 and ifMTU >= 64)' {
error-message "An ATM MTU must be 64 .. 17966";
}
}
```
--------------------------------
### XPath Functions Reference
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Definitions and usage examples for XPath functions used in YANG 1.1.
```APIDOC
## XPath Functions
### current()
- **Description**: Returns a node set with the initial context node as its only member.
- **Signature**: node-set current()
### re-match()
- **Description**: Returns true if the subject string matches the regular expression pattern.
- **Signature**: boolean re-match(string subject, string pattern)
- **Note**: Uses XML Schema regular expressions [XSD-TYPES] with implicit anchoring.
### deref()
- **Description**: Follows the reference defined by the first node in the argument node-set and returns the nodes it refers to.
- **Signature**: node-set deref(node-set nodes)
- **Behavior**:
- If type is 'instance-identifier', returns the single node referred to.
- If type is 'leafref', returns the nodes the leafref refers to.
```
--------------------------------
### Define an anydata statement in YANG
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example of an anydata statement within a list structure.
```YANG
list logged-notification {
key time;
leaf time {
type yang:date-and-time;
}
anydata data;
}
```
--------------------------------
### Represent a notification as an XML instance
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example of the XML encoding for a notification defined in a YANG module.
```xml
2008-07-08T00:01:00Z
fault
/ex:interface[ex:name='Ethernet0']
major
```
--------------------------------
### YANG Description Statement with Extension
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Shows an example of a YANG 'description' statement with a vendor-specific extension substatement, illustrating extensibility.
```yang
description "Some text." {
ex:documentation-flag 5;
}
```
--------------------------------
### YANG RPC Operation Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Defines a top-level RPC operation named 'activate-software-image' with string input 'image-name' and string output 'status'.
```yang
rpc activate-software-image {
input {
leaf image-name {
type string;
}
}
output {
leaf status {
type string;
}
}
}
```
--------------------------------
### XML Data Tree Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Represents a data tree in XML format, used as a basis for demonstrating accessible trees in YANG.
```xml
1
2
```
--------------------------------
### Define XML Server List Entries
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example of XML-encoded server list entries with name, IP, and port elements.
```xml
smtp
192.0.2.1
25
http
192.0.2.1
25
```
--------------------------------
### YANG Module Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
This YANG module defines an 'interface' list with 'name' and 'mtu' leaves, including a custom extension 'myext:c-define'.
```yang
module example-foo {
yang-version 1.1;
namespace "urn:example:foo";
prefix "foo";
import example-extensions {
prefix "myext";
}
list interface {
key "name";
leaf name {
type string;
}
leaf mtu {
type uint32;
description "The MTU of the interface.";
myext:c-define "MY_MTU";
}
}
}
```
--------------------------------
### XML representation of default-address data
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example XML data showing the relationship between interface and default-address.
```xml
eth0
up
192.0.2.1
192.0.2.2
lo
up
127.0.0.1
eth0
192.0.2.2
```
--------------------------------
### YANG Action Operation Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Defines an 'action' named 'ping' tied to a 'list' of 'interface' data nodes. It includes input and output parameters.
```yang
list interface {
key "name";
leaf name {
type string;
}
action ping {
input {
leaf destination {
type inet:ip-address;
}
}
output {
leaf packet-loss {
type uint8;
}
}
}
}
```
--------------------------------
### XML Instance of Augmented Interface
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example XML encoding for the augmented interface data nodes.
```xml
1
Flintstone Inc Ethernet A562
ethernetCsmacd
1500
2
Flintstone Inc DS0
ds0
1
```
--------------------------------
### YANG Choice Statement Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Demonstrates a YANG 'choice' statement with two cases: 'sports-arena' and 'late-night'. Only one case can be active at a time.
```yang
container food {
choice snack {
case sports-arena {
leaf pretzel {
type empty;
}
leaf beer {
type empty;
}
}
case late-night {
leaf chocolate {
type enumeration {
enum dark;
enum milk;
enum first-available;
}
}
}
}
}
```
--------------------------------
### NETCONF XML RPC and RPC-Reply Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Shows the XML encoding for an RPC request to 'rock-the-house' with a zip code, and its corresponding RPC-reply containing an element. This illustrates how YANG RPCs are represented in NETCONF XML.
```xml
27606-0100
```
--------------------------------
### Define YANG Module Structures
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Examples of YANG module definitions including typedefs, containers, and revision history.
```YANG
if-feature foo;
leaf y {
type b:myenum;
}
}
container a {
leaf x {
type c:bar;
}
}
}
```
```YANG
module b {
yang-version 1.1;
namespace "urn:example:b";
prefix "b";
revision 2015-01-01;
typedef myenum {
type enumeration {
enum zero;
}
}
container x {
}
}
```
```YANG
module b {
yang-version 1.1;
namespace "urn:example:b";
prefix "b";
revision 2015-04-04;
revision 2015-01-01;
typedef myenum {
type enumeration {
enum zero; // added in 2015-01-01
enum one; // added in 2015-04-04
}
}
container x { // added in 2015-01-01
container y; // added in 2015-04-04
}
}
```
```YANG
module c {
yang-version 1.1;
namespace "urn:example:c";
prefix "c";
revision 2015-02-02;
typedef bar {
...
}
}
```
```YANG
module c {
yang-version 1.1;
namespace "urn:example:c";
prefix "c";
revision 2015-03-03;
revision 2015-02-02;
typedef bar {
...
}
}
```
--------------------------------
### XML representation of interface data
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example XML data corresponding to the interface list structure.
```xml
eth0
lo
eth0
```
--------------------------------
### XML representation of leaf-list entries
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example of how leaf-list entries appear in an XML instance.
```XML
alice
bob
```
--------------------------------
### XML Instance Example for Container
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
An XML instance representing the 'system' container with the 'ssh' service enabled. The presence of the element signifies that SSH is enabled.
```xml
```
--------------------------------
### YANG String Pattern Matching Examples
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Illustrates valid and invalid string values based on length and pattern constraints. The type allows strings of length '0..4' matching hexadecimal characters.
```yang
type string {
length "0..4";
pattern "[0-9a-fA-F]*";
}
```
--------------------------------
### Define Valid XML Server List Configuration
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example of a valid configuration where entries without all referenced leafs are ignored for unique constraint enforcement.
```xml
smtp
192.0.2.1
25
http
192.0.2.1
ftp
192.0.2.1
```
--------------------------------
### YANG Augment Statement Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Illustrates augmenting the '/system/login/user' data node with a 'uid' leaf, conditional on the 'class' not being 'wheel'.
```yang
augment /system/login/user {
when "class != 'wheel'";
leaf uid {
type uint16 {
range "1000 .. 30000";
}
}
}
```
--------------------------------
### Define a top-level notification in YANG
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example of a notification defined at the top level of a YANG module.
```yang
module example-event {
yang-version 1.1;
namespace "urn:example:event";
prefix "ev";
notification event {
leaf event-class {
type string;
}
leaf reporting-entity {
type instance-identifier;
}
leaf severity {
type string;
}
}
}
```
--------------------------------
### Define YANG Interface Module
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Defines a container with a list of interfaces in the urn:example:interface-module namespace.
```yang
container interfaces {
list ifEntry {
key "ifIndex";
leaf ifIndex {
type uint32;
}
leaf ifDescr {
type string;
}
leaf ifType {
type iana:IfType;
}
leaf ifMtu {
type int32;
}
}
}
```
--------------------------------
### YIN Translation Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
This YIN XML represents the 'example-foo' YANG module, showing the structure and elements in XML format.
```xml
The MTU of the interface.
```
--------------------------------
### NETCONF XML Notification Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Represents a 'link-failure' notification in NETCONF XML format. Includes event time and specific details about the link failure.
```xml
2007-09-01T10:00:00Z
so-1/2/3.0
up
down
```
--------------------------------
### Use re-match() for string validation
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Examples of using re-match() to validate strings and filter nodes based on patterns.
```text
re-match("1.22.333", "\d{1,3}\.\d{1,3}\.\d{1,3}")
count(/interface[re-match(name, "eth0\.\d+")])
```
--------------------------------
### NETCONF edit-config merge operation
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example of using the merge operation to add a new element to a leaf-list.
```XML
eric
```
--------------------------------
### Modify a choice via NETCONF RPC
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
An example of an RPC request to change the protocol configuration from TCP to UDP using the 'create' operation.
```XML
```
--------------------------------
### YANG Schema Node Identifier Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Demonstrates the syntax for an absolute schema node identifier in YANG, used to reference nodes within a schema tree.
```yang
/a/b
```
--------------------------------
### Define a bits typedef and leaf
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example of defining a bits type with explicit positions and a leaf using that type with a default value.
```YANG
typedef mybits-type {
type bits {
bit disable-nagle {
position 0;
}
bit auto-sense-speed {
position 1;
}
bit ten-mb-only {
position 2;
}
}
}
leaf mybits {
type mybits-type;
default "auto-sense-speed";
}
```
--------------------------------
### YANG String Length Refinement Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Demonstrates legal and illegal length refinements for a YANG string type. The base type has a length of '1..255'.
```yang
typedef my-base-str-type {
type string {
length "1..255";
}
}
type my-base-str-type {
// legal length refinement
length "11 | 42..max"; // 11 | 42..255
}
type my-base-str-type {
// illegal length refinement
length "1..999";
}
```
--------------------------------
### YANG Module Definition Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Defines a YANG module with a container, list, notification, action, and leafref. Used to illustrate accessible tree concepts.
```yang
module example-a {
yang-version 1.1;
namespace urn:example:a;
prefix a;
container a {
list b {
key id;
leaf id {
type string;
}
notification down {
leaf reason {
type string;
}
}
action reset {
input {
leaf delay {
type uint32;
}
}
output {
leaf result {
type string;
}
}
}
}
}
notification failure {
leaf b-ref {
type leafref {
path "/a/b/id";
}
}
}
}
```
--------------------------------
### YANG String Pattern with Invert Match Modifier
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Shows a YANG string type with multiple patterns, including one using the 'invert-match' modifier. This example restricts strings that start with 'xml' case-insensitively.
```yang
type string {
length "1..max";
pattern '[a-zA-Z_][a-zA-Z0-9\-_.]*';
pattern '[xX][mM][lL].*' {
modifier invert-match;
}
}
```
--------------------------------
### YANG Container Definition Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Defines a 'system' container with nested 'services' and 'ssh' containers. The 'ssh' container uses a 'presence' statement to indicate its meaning when present.
```yang
container system {
description
"Contains various system parameters.";
container services {
description
"Configure externally available services.";
container "ssh" {
presence "Enables SSH";
description
"SSH service-specific configuration.";
// more leafs, containers, and stuff here...
}
}
}
```
--------------------------------
### YANG enum-value() Function Example
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Provides an example of the enum-value() function in YANG, which returns the integer value of an enumeration. The example defines a list with a severity leaf using enumeration types.
```yang
list alarm {
...
leaf severity {
type enumeration {
enum cleared {
value 1;
}
enum indeterminate {
value 2;
}
enum minor {
value 3;
}
enum warning {
value 4;
}
enum major {
value 5;
}
enum critical {
value 6;
}
}
}
}
```
--------------------------------
### Importing a YANG Module with Revision
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Demonstrates how module 'b' imports a specific revision of module 'a' to ensure compatibility.
```YANG
module a {
yang-version 1.1;
namespace "urn:example:a";
prefix "a";
revision 2008-01-01 { ... }
grouping a {
leaf eh { .... }
}
}
module b {
yang-version 1.1;
namespace "urn:example:b";
prefix "b";
import a {
prefix "p";
revision-date 2008-01-01;
}
container bee {
uses p:a;
}
}
```
--------------------------------
### Invoke an action and receive a reply in XML
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Shows the XML structure for invoking an action via NETCONF and the corresponding reply.
```XML
apache-1
2014-07-29T13:42:00Z
2014-07-29T13:42:12Z
```
--------------------------------
### XML representation of packet-filter data
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example XML data for a packet-filter referencing an interface.
```xml
eth0
up
192.0.2.1
192.0.2.2
eth0
1
...
```
--------------------------------
### Refine a bits type
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Examples of legal and illegal refinements for an existing bits type.
```YANG
type mybits-type {
// legal bit refinement
bit disable-nagle {
position 0;
}
bit auto-sense-speed {
position 1;
}
}
```
```YANG
type mybits-type {
// illegal bit refinement
bit disable-nagle {
position 2; // illegal position change
}
bit hundred-mb-only; // illegal addition of new name
}
```
--------------------------------
### Define and Use Reusable Groupings
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Shows how to define a reusable grouping of nodes and instantiate it within a container using the uses statement.
```YANG
grouping target {
leaf address {
type inet:ip-address;
description "Target IP address.";
}
leaf port {
type inet:port-number;
description "Target port number.";
}
}
container peer {
container destination {
uses target;
}
}
```
```XML
2001:db8::2
830
```
--------------------------------
### Encode a union value
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example XML encoding for a union type containing a leafref value.
```XML
http
http
```
--------------------------------
### Encode identityref values
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Examples of how the crypto leaf can be encoded using different prefixes or namespaces.
```XML
des:des3
```
```XML
x:des3
```
```XML
mc:aes
```
--------------------------------
### Use a YANG extension
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Imports and applies a custom extension within a container definition.
```yang
module example-interfaces {
yang-version 1.1;
...
import example-extensions {
prefix "myext";
}
...
container interfaces {
...
myext:c-define "MY_INTERFACES";
}
}
```
--------------------------------
### Configure a leaf using NETCONF edit-config
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Demonstrates how to set the value of a leaf node using the NETCONF edit-config RPC.
```XML
2022
```
--------------------------------
### Define Domain Search Leaf-List
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example of leaf-list XML encoding for domain search entries.
```xml
high.example.com
low.example.com
everywhere.example.com
```
--------------------------------
### Define an ordered-by user list
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Defines a list where the order of entries is user-defined.
```YANG
list user {
description
"This is a list of users in the system.";
ordered-by user;
config true;
key "first-name surname";
leaf first-name {
type string;
}
leaf surname {
type string;
}
leaf type {
type string;
}
}
```
--------------------------------
### Declare NETCONF Capability for YANG Library
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
The required capability string to be advertised in the NETCONF message.
```text
urn:ietf:params:netconf:capability:yang-library:1.0?
revision=&module-set-id=
```
--------------------------------
### Define a URI typedef in YANG
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example of a custom typedef using the string base type and a reference statement.
```YANG
typedef uri {
type string;
reference
"RFC 3986: Uniform Resource Identifier (URI): Generic Syntax";
...
}
```
--------------------------------
### Define a YANG Submodule with belongs-to
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example of a submodule definition using the belongs-to statement to associate with a parent module.
```yang
submodule example-types {
yang-version 1.1;
belongs-to "example-system" {
prefix "sys";
}
import ietf-yang-types {
prefix "yang";
}
organization "Example Inc.";
contact
"Joe L. User
Example Inc.
42 Anywhere Drive
Nowhere, CA 95134
USA
Phone: +1 800 555 0100
Email: joe@example.com";
description
"This submodule defines common Example types.";
revision "2007-06-09" {
description "Initial revision.";
}
// definitions follow...
}
```
--------------------------------
### NETCONF XML for Action Operation
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Illustrates the NETCONF XML request for invoking the 'ping' action on a specific 'interface' instance, including input parameters.
```xml
eth1
192.0.2.1
```
--------------------------------
### Define a simple YANG choice
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
A basic example of a choice statement containing two cases, 'a' and 'b', each with a single leaf.
```YANG
container protocol {
choice name {
case a {
leaf udp {
type empty;
}
}
case b {
leaf tcp {
type empty;
}
}
}
}
```
--------------------------------
### List Definition with Multiple Keys
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Defines a list of servers where both IP and port serve as unique keys.
```yang
list server {
key "ip port";
leaf name {
type string;
}
uses sys:endpoint;
}
```
--------------------------------
### Use current() in a must expression
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Example showing the use of current() within a must expression to validate a leafref against a list entry.
```yang
list interface {
key "name";
...
leaf enabled {
type boolean;
}
...
}
leaf outgoing-interface {
type leafref {
path "/interface/name";
}
must '/interface[name=current()]/enabled = "true"';
}
```
--------------------------------
### Define a YANG choice with a default case
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Demonstrates a container with a choice statement that defaults to the 'interval' case, applying default values when no other nodes are present.
```YANG
container transfer {
choice how {
default interval;
case interval {
leaf interval {
type uint16;
units minutes;
default 30;
}
}
case daily {
leaf daily {
type empty;
}
leaf time-of-day {
type string;
units 24-hour-clock;
default "01.00";
}
}
case manual {
leaf manual {
type empty;
}
}
}
}
```
--------------------------------
### Define and Use Derived Types
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
Demonstrates creating a custom type using typedef and applying it to a leaf node.
```YANG
typedef percent {
type uint8 {
range "0 .. 100";
}
}
leaf completed {
type percent;
}
```
```XML
20
```
--------------------------------
### Define a union with leafref and enumeration
Source: https://www.rfc-editor.org/rfc/rfc7950.txt
This example demonstrates a union containing a leafref and an enumeration, showing how validation proceeds if a referenced instance is removed.
```YANG
list filter {
key name;
leaf name {
type string;
}
...
}
leaf outbound-filter {
type union {
type leafref {
path "/filter/name";
}
type enumeration {
enum default-filter;
}
}
}
```