YANG Leafref Example

module: lref-1

  grouping parms
    +-- mod-con-1
    |  +-- mod-leaf-1-1?   uint32
    |  +-- mod-leaf-1-2?   uint32
    +-- mod-con-2
    |  +-- mod-leaf-2-1?          uint32
    |  +-- mod-leaf-2-2?          uint32
    |  +-- (mod-choice)?
    |     +--:(wildcard)
    |     |  +-- wildcard?        empty
    |     +--:(stream-handle)
    |        +-- stream-handle?   empty
    +-- mod-con-3
       +-- mod-instance-table* [mod-instance-id]
          +-- mod-instance-id?   uint32

module: lref-2
  +--rw mod-con-1
  |  +--rw mod-leaf-1-1?   uint32
  |  +--rw mod-leaf-1-2?   uint32
  +--rw mod-con-2
  |  +--rw mod-leaf-2-1?          uint32
  |  +--rw mod-leaf-2-2?          uint32
  |  +--rw (mod-choice)?
  |     +--:(wildcard)
  |     |  +--rw wildcard?        empty
  |     +--:(stream-handle)
  |     |  +--rw stream-handle?   empty
  |     +--:(null-handle)
  |        +--rw null-handle?     empty
  +--rw mod-con-3
     +--rw mod-instance-table* [mod-instance-id]
     |  +--rw mod-instance-id    uint32
     +--rw some-container
        +--rw mod-con-3-id?   -> ../../../mod-con-3/mod-instance-table/mod-instance-id


module lref-1 {
   yang-version "1.1";
   namespace
      urn:ieee:exp:yang:lref-1;
   prefix l1;
   organization
      "IEEE";
   contact
      "IEEE";
   description
      "leafref test module 1";
   revision 2021-03-01 {
      description
         "leafref 1";
   }
   grouping parms {
      description
         "parms";
      container mod-con-1 {
         description "mod-con-1";
         leaf mod-leaf-1-1 {
            type uint32;
            description
               "mod-leaf-1-1";
         }
         leaf mod-leaf-1-2 {
            type uint32;
            description
               "mod-leaf-1-2";
         }
      }
      container mod-con-2 {
         description "mod-con-2";
         leaf mod-leaf-2-1 {
            type uint32;
            description
               "mod-leaf-2-1";
         }
         leaf mod-leaf-2-2 {
            type uint32;
            description
               "mod-leaf-2-1";
         }
         choice mod-choice {
            description "mod-choice";
            case wildcard {
               leaf wildcard {
                  type empty;
                  description
                     "wildcard";
                }
            }
            case stream-handle {
               leaf stream-handle {
                  type empty;
                  description
                     "stream-handle";
                }
            }
         }
      }
      container mod-con-3 {
         list mod-instance-table {
            key "mod-instance-id";
            description
               "Some list";
            leaf mod-instance-id {
               type uint32;
               description
                  "Id for an instance in the list";
            }
         }
      }
   }
}


module lref-2 {
   yang-version "1.1";
   namespace
      urn:ieee:exp:yang:lref-2;
   prefix l2;
   import lref-1 {
      prefix l1;
   }
   organization
      "IEEE";
   contact
      "IEEE";
   description
      "leafref test module 2";
   revision 2021-03-01 {
      description
         "leafref 2";
   }

   uses l1:parms {
      augment
         "mod-con-2/mod-choice" {
         case null-handle {
            leaf null-handle {
               type empty;
               description
                  "null-handle";
            }
         }
      }
      augment
         "mod-con-3" {
         container some-container {
            description
               "A container that holds a leaf that points to an id in another grouping";
            leaf mod-con-3-id {
               type leafref {
                  path
                     '..'+
                     '/..'+
                     '/..'+
                     '/mod-con-3'+
                     '/mod-instance-table'+
                     '/mod-instance-id';
               }
               description
                  "Leafref to a mod-instance-table instance";
            }
         }
      }
   }
}
Sidebar