On Wed, Oct 1, 2025 at 12:56 AM Phú Liên <[email protected]> wrote:

> Hi RFC 8791 authors,
>
> I have a question regarding YANG data structure extensions (RFC 8791) and
> the use of augment-structure. Specifically, is it possible to augment the
> root of a YANG data structure?
>
> For example, with the YANG model below, yanglint validates successfully if
> the last "sx:augment-structure /foo:mystruct" statement is commented out.
> However, if that statement is included, yanglint reports an error:
>
> * Yang model
>
> ```
> module foo {
>   namespace "foo";
>   prefix foo;
>
>   import ietf-yang-structure-ext { prefix sx; }
>
>   sx:structure mystruct {
>     container mycontainer {
>       leaf leaf1 {
>         type string;
>       }
>     }
>   }
>
>   sx:augment-structure /foo:mystruct/foo:mycontainer {
>     leaf leaf2 {
>       type string;
>     }
>   }
>
>   // Augment to the root of the structure, so `leaf3` will be a sibling of
> `mycontainer`.
>   sx:augment-structure /foo:mystruct {
>     leaf leaf3 {
>       type string;
>     }
>   }
> }
> ```
>
> * Yanglint error
>
> ```
> libyang err : Augment extension target node "/foo:mystruct" from module
> "foo" was not found.
> (/foo:{extension='sx:augment-structure'}/{augment='/foo:mystruct'})
> ```
>
> Moreover, if we cannot use augment-structure to add augments to the root
> of a structure, could you please suggest how to make the following leafref
> path valid in the YANG model below?
>
>

I do not see any text in RFC 8791 that prohibits augmenting the structure.
A valid path argument is provided to the extension.

    sx:augment-structure /foo:mystruct

The structure 'mystruct' should be treated like a top-level NP container.
It shares the same namespace as real data-def-stmts.


Andy

* a.yang
>
> ```
> module a {
>   namespace "urn:a";
>   prefix a;
>
>   import b {
>     prefix b;
>   }
>   import ietf-yang-structure-ext {
>     prefix sx;
>   }
>
>   grouping leafrefs {
>     leaf leaf1 {
>       type leafref {
>         path "/a:top/a:leaf2";
>       }
>     }
>   }
>
>   grouping leaves {
>     leaf leaf2 {
>       type string;
>     }
>   }
>
>   container top {
>     config false;
>     uses leaves;
>   }
>
>
>   // Augments 'a:leaf1' into '/b:mystruct/b:mycontainer'. This augmented
>   // 'a:leaf1' will be a sibling of 'b:myleaf'.
>   //
>   // XPath within a structure can only reference nodes inside the same
>   // structure. Therefore, '/a:top/a:leaf2' must also be augmented into
>   // 'b:mystruct' to satisfy the leafref path.
>   sx:augment-structure "/b:mystruct/b:mycontainer" {
>     uses leafrefs;
>   }
>
>   // This 'augment-structure' attempts to satisfy the leafref path by
> augmenting
>   // '/a:top/a:leaf2' into the root of '/b:mystruct'. However, yanglint
> reports
>   // an error because we are augmenting to the root of a structure.
>   sx:augment-structure "/b:mystruct" {
>     container top {
>       uses leaves;
>     }
>   }
>
>   // This 'augment-structure' is valid in yanglint but does not satisfy the
>   // leafref path because it augments '/b:top/a:leaf2', not
> '/a:top/a:leaf2'.
>   sx:augment-structure "/b:mystruct/b:top" {
>     uses leaves;
>   }
> }
> ```
>
> * b.yang
>
> ```
> module b {
>   namespace "urn:b";
>   prefix b;
>
>   import ietf-yang-structure-ext {
>     prefix sx;
>   }
>
>   sx:structure mystruct {
>     container mycontainer {
>       leaf myleaf {
>         type string;
>       }
>     }
>     container top { }
>   }
> }
> ```
>
> Yanglint reports the following error for the second augment-structure
> statement:
>
> ```
> libyang err : Augment extension target node "/b:mystruct" from module "a"
> was not found.
> (/a:{extension='sx:augment-structure'}/{augment='/b:mystruct'})
> ```
>
> And the following error for the third augment-structure statement:
>
> ```
> libyang err : Not found node "top" in path. (/b:mycontainer/a:leaf1)
> ```
>
> By the way, we found that this use of augment-structure is claimed to be
> supported in the following links:
>
> * https://docs.yumaworks.com/en/latest/yangauto/define-abstract-yang.html
> *
> https://dr2lopez.github.io/yang-provenance/draft-lopez-opsawg-yang-provenance.html
>
> BR/Phu
> _______________________________________________
> netmod mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
>
_______________________________________________
netmod mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to