7.2. “子模块”声明

YANG中的主要单元是一个模块,而YANG模块本身可以由几个子模块构成。子模块允许模块设计人员将复杂模型拆分为多个子模块,其中所有子模块对包含子模块的模块定义的单个名称空间起作用。

submodule”语句定义子模块的名称,并将属于子模块的所有语句组合在一起。 “submodule”语句的参数是子模块的名称,后面跟着一个包含详细子模块信息的子语句块。子模块名称是一个标识符(见第6.2节)。

RFC流发布的子模块的名称必须由IANA分配;参见[RFC6020]中的第14节

私有子模块名称由拥有子模块的组织分配,没有中央注册表。有关如何命名子模块的建议,请参见第5.1节

子模块通常具有以下布局:

  1. submodule <module-name> {
  2. <yang-version statement>
  3. // module identification
  4. <belongs-to statement>
  5. // linkage statements
  6. <import statements>
  7. // meta-information
  8. <organization statement>
  9. <contact statement>
  10. <description statement>
  11. <reference statement>
  12. // revision history
  13. <revision statements>
  14. // module definitions
  15. <other statements>
  16. }

7.2.1. 子模块的子语句

submodule的子语句基本上和module的子语句(参见7.1.1节)一致,只是多了一个belongs-to子语句

  1. +--------------+---------+-------------+
  2. | substatement | section | cardinality |
  3. +--------------+---------+-------------+
  4. | anydata | 7.10 | 0..n |
  5. | anyxml | 7.11 | 0..n |
  6. | augment | 7.17 | 0..n |
  7. | belongs-to | 7.2.2 | 1 |
  8. | choice | 7.9 | 0..n |
  9. | contact | 7.1.8 | 0..1 |
  10. | container | 7.5 | 0..n |
  11. | description | 7.21.3 | 0..1 |
  12. | deviation | 7.20.3 | 0..n |
  13. | extension | 7.19 | 0..n |
  14. | feature | 7.20.1 | 0..n |
  15. | grouping | 7.12 | 0..n |
  16. | identity | 7.18 | 0..n |
  17. | import | 7.1.5 | 0..n |
  18. | include | 7.1.6 | 0..n |
  19. | leaf | 7.6 | 0..n |
  20. | leaf-list | 7.7 | 0..n |
  21. | list | 7.8 | 0..n |
  22. | notification | 7.16 | 0..n |
  23. | organization | 7.1.7 | 0..1 |
  24. | reference | 7.21.4 | 0..1 |
  25. | revision | 7.1.9 | 0..n |
  26. | rpc | 7.14 | 0..n |
  27. | typedef | 7.3 | 0..n |
  28. | uses | 7.13 | 0..n |
  29. | yang-version | 7.1.2 | 1 |
  30. +--------------+---------+-------------+

7.2.2。 “belongs-to”声明

belongs-to”语句指定子模块所属的模块。 参数是一个标识符,即模块的名称。

一个子模块只能被它所属的模块或属于该模块的另一个子模块所包含。

强制的“prefix”子状态为子模块所属的模块分配一个前缀。 子模块所属模块中的所有定义及其所有子模块都可以使用前缀进行访问。

“belongs-to”的子语句

  1. +--------------+---------+-------------+
  2. | substatement | section | cardinality |
  3. +--------------+---------+-------------+
  4. | prefix | 7.1.4 | 1 |
  5. +--------------+---------+-------------+

7.2.3 使用示例

  1. submodule example-types {
  2. yang-version 1.1;
  3. belongs-to "example-system" {
  4. prefix "sys";
  5. }
  6. import ietf-yang-types {
  7. prefix "yang";
  8. }
  9. organization "Example Inc.";
  10. contact
  11. "Joe L. User
  12. Example Inc.
  13. 42 Anywhere Drive
  14. Nowhere, CA 95134
  15. USA
  16. Phone: +1 800 555 0100
  17. Email: joe@example.com";
  18. description
  19. "This submodule defines common Example types.";
  20. revision "2007-06-09" {
  21. description "Initial revision.";
  22. }
  23. // definitions follow...
  24. }