I'm quite new in YANG. While reading Module and Submodule section, I confused about the access right of submodule.
RFC7950#section-5.1 indicated that:
"A submodule can reference any definition in the module it belongs to and in all submodules included by the module"
but it also indicated:
"For a module or submodule to reference definitions in an external module, the external module MUST be imported"
So my understand is that if A have two submodules B and C, C import D. Then B could access to any definition in C but NOT definitions in D.
Am I correct? If yes, Could B access definitions that using D in C?
Thank you in advance
If A have two submodules B and C, C import D. Then B could access to any definition in C but NOT definitions in D. Am I correct?
Yes, you are correct. Submodules still need their own imports. This is to ensure that each file (note that I did not say "module") has a well defined prefix mapping. Prefixes are not inherited in YANG.
Could B access definitions that using D in C?
B and C see all definitions that are defined in A, B, and C. When you import D in C, you are not defining any new definitions, you are making it possible to re-use already defined ones. B would need an explicit import for D in order to see its definitions.
The RFC is meant to be read a whole. I suggest you also read the section for the "import" statement and then the section for the "include" statement in addition to the one you stated. Those are the sections that define the actual mechanism behind importing and including. The section for "belongs-to" is also relevant.
Import:
The "import" statement makes definitions from one module available inside another module or submodule. The argument is the name of the module to import, and the statement is followed by a block of substatements that holds detailed import information. When a module is imported, the importing module may:
o use any grouping and typedef defined at the top level in the imported module or its submodules.
o use any extension, feature, and identity defined in the imported module or its submodules.
o use any node in the imported module's schema tree in "must", "path", and "when" statements, or as the target node in "augment" and "deviation" statements.
Include:
The "include" statement is used to make content from a submodule available to that submodule's parent module. The argument is an identifier that is the name of the submodule to include. Modules are only allowed to include submodules that belong to that module, as defined by the "belongs-to" statement (see Section 7.2.2).
When a module includes a submodule, it incorporates the contents of the submodule into the node hierarchy of the module.
Belongs-to:
The "belongs-to" statement specifies the module to which the submodule belongs. The argument is an identifier that is the name of the module.
A submodule MUST only be included by either the module to which it belongs or another submodule that belongs to that module.
The mandatory "prefix" substatement assigns a prefix for the module to which the submodule belongs. All definitions in the module that the submodule belongs to and all its submodules can be accessed by using the prefix.
Note that the "include" statement's scoping rules are different in YANG 1 (RFC6020). What I described only applies to YANG 1.1. In YANG 1, submodules need to explicitly include another submodule to see its definitions and a submodule cannot see definitions defined in the including module.
You can also read more here.