Subject: [netmod] three questions about YANG deviation statement

From: "Zhengguangying (Walker)" <[email-masked]>
Date: Wed, 11 Jul 2018 03:05:16 +0000

Hi all,
   When we try to implementing, there are 3 questions want to clear on WG, please expert help to answer the questions, thanks.

[Question 1]: whether "mandatory true" node can be deviated as "not-supported" ?

[Question 2]: Whether can deviation YANG to expand the range of type?

   example:

 target YANG node:
 leaf a {
  type uint 8 {
    range "1..50";
  }
}

deviation yang:

deviation "/a:a" {
  replace type {
    range "1..100";
  }
}

[Question 3]: How to use a new type defined by "typedef" to deviate replace the target module's type.

example:
module example-base {
      namespace "urn:example-base";
      prefix base;

      container system {
        description
         "System group configuration.";
        leaf daytime {
           type string;
        }
        leaf date {
           type string;
        }
        leaf interface {
           type string;
        }
        leaf status {
           type string;
           config false;
        }
      }
}

module example-deviations {
       yang-version 1.1;
       namespace "urn:example:deviations";
       prefix md;

       import example-base {
         prefix base;
       }

       import ietf-interfaces {
         prefix if;
       }

       // here, define a new type with typedef statement
       typedef date-and-time {
         type string {
           pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?'
             + '(Z|[\+\-]\d{2}:\d{2})';
         }
        }

       // try to replace the target node's type with new typedef type
       deviation /base:system/base:date {
         deviate replace {
            type date-and-time;
         }
       }

        deviation /base:system/base:interface {
         deviate replace {
            type leafref {
                    path "/if:interfaces/if:interface/if:name";
                }              }
       }
       ...
     }

problem 1: when use new type defined in deviation YANG file to replace the target node's type, some tools give compile error, because they can not find the definition of new type "date-and-time" . From the YANG language view, this error looks reasonable, but how to replace the target node with newly deifned type?

problem 2: when try to replace the type to leafref a xpath which not imported in the target module, it have the compile error too, then how to replace the target node with another module's xpath?

Thanks
Walker(Guangying zheng)

---

From: Alex Campbell <[email-masked]>
Date: Wed, 11 Jul 2018 05:50:14 +0000

Hi,

[Note I haven't tested these answers. Also this is a source level view, with no regards for compatibility]

[1] If you want to make a node optional (not mandatory), the way to do that is:

  deviation "/a:a" {

    deviate replace {

      mandatory false;

    }

  }

[2] Deviation statements can replace types arbitrarily. Example:

  deviation "/a:a" {

    deviate replace {

      type uint8 {

        range "1..100";

      }

    }

  }

The whole type is replaced, there isn't a way to replace just the range.

[3] Based on RFC 7950 section 5.4, it looks like your YANG is correct. If some tools cannot process the module it is a bug in the tool.

However as a workaround, you could always define the type inline without a typedef.

Perhaps also try 'type md:date-and-time;' (i.e. add the prefix for the deviation module)

I think your leafref problem is related. It seems that the tool is searching for prefixes imported in the target module, which is not correct according to the RFC.

________________________________
From: netmod <[email-masked]> on behalf of Zhengguangying (Walker) <[email-masked]>
Sent: Wednesday, 11 July 2018 3:05 p.m.
To: [email-masked]; Yangang (Routing Design); Yangshouchuan; Qudan (Beijing-NOS); Qin Wu
Subject: [netmod] three questions about YANG deviation statement

Hi all,

   example:

 target YANG node:
 leaf a {
  type uint 8 {
    range "1..50";
  }
}

deviation yang:

deviation "/a:a" {
  replace type {
    range "1..100";
  }
}

example:
module example-base {

      container system {
        description

       import example-base {
         prefix base;
       }

       import ietf-interfaces {
         prefix if;
       }

Thanks
Walker(Guangying zheng)