Key from union of identity ref and uint8

Hi ,

Is it possible to create a key from union of identity ref and uint8 like below.

typedef sr-algo-type {
union {
identityref sr-stat-algo; // SPF, STRICT_SPF
uint8;
}
}
list prefix-sids {
container prefix-sid {
key “algo”
leaf algo {
type sr-algo-type
}
uses sid-definition; // index/absolute, label-option
}
}
Thanks,
Kotesh

Yes. See YANG RFC 7950 for documentation and usage examples on the union, identityref, and integer types.

Thanks Cohult. I have one more query.

I have another list where i want to make a key from neighbour and a set of choices. Basically my requirement here is to make key either from {neighbour, value} or {neighbour, index}. Is this possible?

  • grouping igp-adjacency-sid-config {
  • description
  •  "This grouping defines ISIS Adjacency SID.";
    
  •  container adjacency-sids {
    
  •    description
    
  •      "Configuration and operational state parameters relating to
    
  •      the advertisement of a segment routing adjacency SID for this
    
  •      interface.";
    
  •    list adjacency-sid {
    
  •      key "neighbor value index";
    
  •      description
    
  •        "An Adjacency SID to be advertised for the specified interface.
    
  •        The Adj-SID's identifier (the SID ID) must be unique, with flags
    
  •        specified indicating the parameters that should be set for the SID.
    
  •        Where a SID value is specified that is allocated from the SRGB, the
    
  •        global flag must be set by the system.";
    
  •      leaf neighbor {
    
  •        type leafref {
    
  •          path "../config/neighbor";
    
  •        }
    
  •        description
    
  •          "Reference to the neighbor with which the Adjacency SID is
    
  •          associated.";
    
  •      }
    
  •      container config {
    
  •        description
    
  •          "Configuraton parameters relating to the AdjSID.";
    
  •        leaf neighbor {
    
  •           type inet:ip-address;
    
  •           description
    
  •             "The remote system on the interface with which the Adj-SID is
    
  •              associated.(0.0.0.0 for p2p)";
    
  •        }
    
  •        choice SID-TYPE {
    
  •          case SID-VALUE {
    
  •            leaf value {
    
  •               type uint32;
    
  •               description
    
  •               "IGP Prefix-SID value.";
    
  •            }
    
  •          }
    
  •          case SID-INDEX {
    
  •            leaf index {
    
  •               type uint32;
    
  •               description
    
  •               "IGP Prefix-SID value.";
    
  •            }
    
  •          }
    
  •        }
    
  •     }
    
  •   }
    
  • }
    
  • }

Thanks,
Kotesh

Have you used the " YANG Data Model for Segment Routing" draft as a reference https://tools.ietf.org/html/draft-ietf-spring-sr-yang-15 ?

YANG list keys are mandatory, so you can’t select one key or the other.
See YANG RFC 7950 “key” statement and “unique” statement. Also note that for non-config (config false) you have an option to not use keys.

Best regards