Subject: Re: [yang-doctors] question regarding conditional/optional statements

From: Kent Watsen <[email-masked]>
Date: Wed, 16 Aug 2017 21:58:50 +0000

Helen,

The downside to option #1 is a potentially large number of features that would have to be listed in Yang Library, right?  How many features are we talking about?  Since your third example uses an int32, no more than 32?   That doesn't sound excessive to me.  The space-savings isn't much, unless we're talking about itty-bitty IoT devices (hopefully running CoAP).

Kent

On 8/16/17, 2:09 PM, "yang-doctors on behalf of Ing-Wher Chen" <[email-masked]<mailto:[email-masked]> on behalf of [email-masked]<mailto:[email-masked]>> wrote:

Hello YANG doctors,

We wish to define a YANG model with several counters.  The counters that we wish to model are the union of all the counters supported by our sample of vendors.  This means that the model will define some counters supported by both vendor_1 and vendor_2 (or more), but some counters will be supported only by one of the vendors.  We would like the model to allow each vendor to indicate the counters it supports.

We can think of 3 approaches below, and would like your feedback regarding which approach we should choose.  We’re also open to suggestions of other approaches.

Option 1: Define an optional feature (if-feature) for each counter.

Sample:
  container queuing-statistics-opt-1 {
    config false;
    description
      "queue related statistics ";
    leaf output-pkts {
      if-feature "output-pkts";
      type uint64;
      description
        "Number of packets transmitted from queue ";
    }
    leaf output-bytes {
      if-feature "output-bytes";
      type uint64;
      description
        "Number of bytes transmitted from queue ";
    }
    leaf queue-size-pkts {
      if-feature "queue-size-pkts";
      type uint64;
      description
      "Number of packets currently buffered ";
    }
    /* etc. */
  }

Advantage: This is the standard approach built into the language to make a statement conditional.

Disadvantage: There are many counters, and each counter will be an optional feature, resulting in many optional features in the model.

Option 2: Define a leaf of the type bits, where each bit indicates that a particular counter is supported.

Example:
  container queuing-statistics-opt-2 {
    config false;
    description
      "queue related statistics ";
    leaf supported-counters {
      type bits {
        bit queue-output-pkts;
        bit queue-output-bytes;
        bit queue-size-pkts;
      }
    }
    leaf output-pkts {
      type uint64;
      description
        "Number of packets transmitted from queue ";
    }
    leaf output-bytes {
      type uint64;
      description
        "Number of bytes transmitted from queue ";
    }
    leaf queue-size-pkts {
      type uint64;
      description
      "Number of packets currently buffered ";
    }
    /* etc. */
  }

Advantage: This reduces the number of optional features in the model.

Disadvantage: The output that indicates which counters are supported might be too verbose to be user friendly.  This is not YANG’s standard approach to make a statement conditional.

Option 3: Define a leaf of the type integer, where each bit in the integer indicates that a particular counter is supported.

Example:
  container queuing-statistics-opt-3 {
    config false;
    description
      "queue related statistics ";
    leaf supported-counters {
      type uint32;
      description
        "Bit 0 indicates whether output-pkts counter is supported
         Bit 1 indicates whether output-bytes counter is supported
         Bit 2 indicates whether queue-size-pkts counter is supported";
    }
    leaf output-pkts {
      type uint64;
      description
        "Number of packets transmitted from queue ";
    }
    leaf output-bytes {
      type uint64;
      description
        "Number of bytes transmitted from queue ";
    }
    leaf queue-size-pkts {
      type uint64;
      description
      "Number of packets currently buffered ";
    }

Advantage: The output, in the form of a single integer, that indicates which counters are supported is compact.

Disadvantage: The model is vague/implicit---the meaning of each bit in supported-counters is embedded in the description, rather than modeled explicitly.  This is also not YANG’s standard approach to make a statement conditional.

Thanks,

Helen