Skip to content

Instantly share code, notes, and snippets.

@qlyoung
Last active September 11, 2019 19:21
Show Gist options
  • Save qlyoung/587fa0575208786f95a1c997d3af776d to your computer and use it in GitHub Desktop.
Save qlyoung/587fa0575208786f95a1c997d3af776d to your computer and use it in GitHub Desktop.
YANG & FRR Northbound gotchas

A list of some interesting edge cases in YANG and the FRR Northbound API.

leafrefs as list keys

A leafref is a reference to a leaf in another part of the data tree. Being leaves themselves, they can be used as the key for a list:

list mylist {

  key "mykey";

  leaf "mykey" {
    type leafref {
      path "../example-leaf";
    }
  }

  leaf "example-leaf" {
    type uint8;
  }
}

Now we have an interesting situation. List keys are always mandatory, so mykey will always exist. mykey is a leafref, and leafref by default has require-instance true, which means the referenced leaf is required to exist in the data tree. However, example-leaf is not marked mandatory true, which makes it optional by default. Now if we delete example-leaf, the resulting data tree is invalid as it violates the require-instance true constraint placed on it by the leafref. So effectively, any leaf which is referenced by a leafref where the leafref has require-instance true and the leafref itself is the key of a list, implicitly has mandatory true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment