cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1459
Views
0
Helpful
2
Replies

Help understanding ../ or ../../ and Deref in YANG

vikassri
Cisco Employee
Cisco Employee

Hi Team ,

Hope you are doing well .  I am trying to wrap my head around the  ../  or ../../  use in the XPATH  with no success .  I have read the reference for the same in RFC but does not help much . I would appreciate if someone could explain this to me with an example.

For example on the youtube video on YANG training below , could someone please explain what does "/client[ip=current()/../v-ip]/port" expand to ?  What does ip=current() point to and then where does the ../ notation point to in the hierarchy .

markdown-img-paste-2018042802003507.png

Also appreciate if someone could explain the expansion of the path without deref() and with deref() .

markdown-img-paste-20180428020523200.png

Regards,

Vikas Srivastava

2 Replies 2

rogaglia
Cisco Employee
Cisco Employee

Hi,

current() means your current node. Imagine it as the linux directory system and current() = pwd().

So, with ../ you go back one level in the tree structure and with ../../ you do it twice.

Example: if video/v-ip="1.1.1.1"

     /client[ip=current()/../v-ip]/port

          would mean "/client[ip="1.1.1.1"]/port

Roque

Thank you Rogue , That helps .


At some places its use of the ../  is clear , like the example you provided. What about the  ..   in the XML template below ( the one just after the /link[1]/var1_router_name ?


My understanding is that link[1]/var1_router_name expands to /ncs:devices/device[PE11]/config so why is there the two .. in this case ?

XML Template

              <address>

                {

                  deref(/link[1]/var1_router_name)/../config/interface/Loopback[name='0']/ip/address/primary/address |

                  deref(/link[1]/var1_router_name)/../config/interface/Loopback[id='0']/ipv4/address/ip

                }

              </address>

YANG

module learning_deref2 {

  namespace "http://com/example/learning_deref2";

  prefix learning_deref2;

  import ietf-inet-types { prefix inet; }

  import tailf-ncs { prefix ncs; }

  import tailf-common { prefix tailf; }

  import tailf-ned-cisco-ios { prefix ios;}

  augment "/ncs:services"  // AUGMENT is used to add to another data model , OR augment it. So in the example we are adding/augumenting the learning_deref to it.

  {

    list learning_deref2

    {

      key "name";

      uses ncs:service-data;

      ncs:servicepoint "learning_deref2";

      leaf name

      {

        mandatory true;

        type string;

      }

      list link

      {

        min-elements 2;

        max-elements 2;

        key "var1_router_name";

            leaf var1_router_name

            {

              mandatory true;

              type leafref

              {

                path "/ncs:devices/ncs:device/ncs:name";  // This path points to a list of routers , not a sepcific router

              }

            } //routername

            container ios

            {

              //  name=current()/../var1_router_name = PE11

              //  ncs:name=current()/../var1_router_name  EXPANDS to ncs:name=/ncs:services/learning_deref/link/var1_router_name

              when "/ncs:devices/ncs:device[ncs:name=current()/../var1_router_name]/ncs:device-type/ncs:cli/ncs:ned-id='ios-id:cisco-ios'"

              {

                //tailf:dependency "../device";

                //tailf:dependency "/ncs:devices/ncs:device/ncs:device-type";

              }

              leaf intf-number

              {

                mandatory true;

                type leafref

                {

                  path "deref(../../var1_router_name)/../ncs:config/ios:interface/ios:GigabitEthernet/ios:name";

                }

              } //intf-number

            } //ios

      }

    }

  }

}