ietf-netmod-yang

Is it possible to have a must statement in a YANG file where we can use arithmetic operations?


Can I use arithmetic operations in a must stament in a YANG file? example:

 container interface {
     leaf ifNumber{
       type uint32;
     }
     must "ifNumber" % 8 = 0 {
         error-message "Must be multiple of 8";
     }

 }

Solution

  • Yes it is possible. Can you the mod keyword. See link: https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-AdditiveExpr Section: 3.5 Numbers

     container interface {
         leaf ifNumber{
           type uint32;
         }
         must "number(ifNumber) mod 8 = 0" {
             error-message "Must be multiple of 8";
         }
    
     }