Questions tagged [ietf-netmod-yang]

YANG is a data modeling language originally designed to model data manipulated by the Network Configuration Protocol (NETCONF). Since the publication of YANG version 1 (RFC6020), YANG has been used or proposed to be used for other protocols (e.g., RESTCONF and CoMI). Use this tag for questions related to the YANG data modeling language and tools that process it.

YANG is the data modeling language for the Network Configuration Protocol (NETCONF). The name is an acronym for Yet Another Next Generation. The YANG data modeling language was developed by the NETMOD working group (NETMOD WG) in the Internet Engineering Task Force (IETF) and was published as RFC 6020 in October 2010. A new maintenance release of the core YANG specification has been published by the NETMOD WG in August 2016 (YANG 1.1, RFC 7950).

YANG is a language originally designed to model data for the NETCONF protocol. A YANG module defines a hierarchy of data that can be used for NETCONF-based operations, including configuration, state data, Remote Procedure Calls (RPCs), and notifications. This allows a complete description of all data sent between a NETCONF client and server. Although out of scope for YANG specification, YANG can also be used with protocols other than NETCONF.

YANG models the hierarchical organization of data as a tree in which each node has a name, and either a value or a set of child nodes. It provides clear and concise descriptions of the nodes, as well as the interaction between those nodes.

An example YANG module:

module example-forest {

  namespace "http://example.org/example-forest";
  prefix et;
  revision 2015-11-26;

  import ietf-yang-types {
    prefix yang;
  }

  typedef tree-species {
    type string;
    description "Defines the species of a tree.";
  }

  typedef a-tree {
    type leafref {
      path "/et:forest/et:trees/et:tree/et:id";
    }
    description "Represents a known tree.";
  }

  /*
   * Our forest.
   */
  container forest {
    description "A forest full of trees and potentially other stuff.";

    container trees {
      description "The trees of a forest.";

      list tree {
        description "Describes one tree in a forest.";        
        key id;

        leaf id {
          type string;
          description "A unique identifier of a tree.";
        }
        leaf species {
          type et:tree-species;
          description "The tree species.";
          mandatory true;
        }        
        leaf description {
          type string;
          description "A short description of the tree.";
        }
        leaf location {
          type string;
          mandatory true;
          description "The location of the tree";
        }
        leaf height {
          type uint8;
          units "meters";
          description "The height of the tree.";
        }

      }
    }
  }

  /**
   * Cutting schedules.
   */
  container cutting-schedules {
    description "Our cutting schedules.";

    list cutting-schedule {
      description "A cutting schedule.";    
      key "name date";

      leaf name {
        type string;
        description "A name for the schedule.";
      }
      leaf date {
        type yang:date-and-time;
        description "When to start cutting down trees.";
      }
      leaf-list tree {
        type a-tree;
        min-elements 1;
        description "Which trees to cut down.";
      }
    }
  }
}

Sample data in XML encoding:

<?xml version="1.0" encoding="utf-8"?>
<data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">

  <forest xmlns="http://example.org/example-forest">
    <trees>
      <tree>
        <id>Lisa</id>
        <species>pine</species>
        <location>Right in the centre of the forest.</location>
        <height>15</height>
      </tree>
      <tree>
        <id>Bob</id>
        <species>oak</species>
        <location>At the first Y split of the path through forest.</location>
        <height>20</height>
      </tree>
      <tree>
        <id>John</id>
        <species>birch</species>
        <description>Struck by lightning a few years ago.</description>
        <location>Next to the burnt down tree-house debris.</location>
        <height>10</height>
      </tree>
    </trees>
  </forest>

  <cutting-schedules xmlns="http://example.org/example-forest">
    <cutting-schedule>
      <name>High priority cleanup</name>
      <date>2015-11-30T16:00:00Z</date>
      <tree>Bob</tree>
      <tree>John</tree>
    </cutting-schedule>
  </cutting-schedules>

</data>

Learn more about YANG here:

161 questions
3
votes
1 answer

Conditional assignment of default values in yang

I have two properties in a model: leaf protocol, leaf port. I want to specify that: if protocol = 'ssh' then default port value is 22, if protocol = 'http' then default port value is 80, etc. How do I express this in yang ?
user19937
  • 587
  • 1
  • 7
  • 25
3
votes
1 answer

Can you have a custom attribute in yang schema?

I wanted to know if we could define a custom field or attribute in one of the elements leaf,list etc. For eg: Is this possible? How can we define such fields if its possible. model Animal{ leaf amphibian{ type String; custom "Frog"; …
Shrenik Gala
  • 283
  • 1
  • 7
  • 19
3
votes
0 answers

Yang to Web UI forms

I'm looking for ideas for directly generating Web input forms from Yang models. One complex way I came across is to use pyang to generate XSLT and then using custom transformations to convert it into HTML forms. Appreciate your input on this…
user3364247
  • 1,477
  • 3
  • 14
  • 24
2
votes
2 answers

What is the standard way to generate XML RPC NETCONF requests from YANG data model

I am trying to find a better way to generate XML RPC requests to be sent to a device with NETCONF tags in it. We know how request should look like, so what I am doing is, just hard coding the XML-RPC request XML with placeholders in it. Those…
Bala
  • 105
  • 1
  • 10
2
votes
2 answers

how to generate code with ODL Yangtools maven plugin for yang-version 1.1 module

How to generate Java code from a yang-version 1.1 module with the OpenDaylight Yangtools maven plugin? I have a yang-version 1.1 model (first part shown next) module o-ran-sc-my-desc-v1 { yang-version 1.1; namespace "urn:o-ran:my-desc:1.0"; …
chrisinmtown
  • 3,571
  • 3
  • 34
  • 43
2
votes
1 answer

XPath current() for Yang

This is my follow up question for Xpath current() in Yang After the earlier discussion, I implemented a customized function current() for libxml2 with implementation shown below. The function works fine as expected when it evaluates Xpath…
Ram
  • 301
  • 2
  • 12
2
votes
0 answers

Xpath current() in Yang

I have a leaf defined in Yang as: leaf test-must { type int32; description "Test must"; must "current() > 0" { error-message "test-must value should be > 0"; } } Looks like the underlying library, libxml2, I use does not…
Ram
  • 301
  • 2
  • 12
2
votes
1 answer

How to refine a leaf's range in YANG model?

I have a grouping like - grouping threshold-value-grouping { container threshold-value { description "Threshold value"; leaf upper-limit-val { description "Upper limit"; type uint32 { range…
Darshan L
  • 824
  • 8
  • 30
2
votes
1 answer

Yang Model recursive search for must condition

I have a problem with a restriction on my CLI. I've been investigating yang RFC7950 (https://www.rfc-editor.org/rfc/rfc7950) but I've found nothing. Here is an example. grouping httpGroup { list http-list{ key "value"; leaf value { …
2
votes
1 answer

YANG - mandatory choice

From RFC 7950#7.9.4: The behavior of the [mandatory] constraint depends on the type of the choice's closest ancestor node in the schema tree that is not a non-presence(see Section 7.5.1): If no such ancestor exists in the schema tree, the…
Fylax
  • 1,138
  • 2
  • 15
  • 24
2
votes
1 answer

What's the difference between the include and import statement in NETCONF (.Yin/Yang files)

I understand that you can create a separate yang file (Something like a textual Convention to store syntax values for MIBS)and import it into another yang file to make the data more organised and structured, but I can't seem to understand what the…
Spdollaz
  • 165
  • 10
2
votes
2 answers

Yang : How to convert yang schema to XML

I have a Yang file, i want to send data using yang schema in an xml format how do i do that. Suppose i have yang file like below module jtest { namespace "jtest"; prefix jtest; container jtest { container mycontainer1 { …
Jin
  • 21
  • 1
  • 3
2
votes
1 answer

YANG: how to model nested lists configuration data without key

I am trying to build YANG model for this configuration file that has lists without keys. However, Due to the necessity of key in YANG list, I wasn't able to build exact YANG model. Is there any idea how to represents list of list without key in…
2
votes
1 answer

Yang model for remainder operation (%)

I want to create yang model with for some integer range e.g from 1000 to maximum and values must be entered in steps of 500. Is there any way I can make use of remainder(modulus) % operator in yang or range function like python with steps. Or I…
HPG
  • 33
  • 5
2
votes
2 answers

YANG: How can I include a container from another module?

I am writing a YANG module where I want to include a container from another module i.e. I want to define a NEW container in the module that I am writing that references a container from another module. Example of failed attempt: module newmodule { …
1
2
3
10 11