1

I'm trying to build a CLI. I choose to use 'yang' to do so. I'm new to it and can't find out how to import existing moduls. As exemple I found a module for ospf on github (https://github.com/YangModels/yang/blob/master/vendor/cisco/xe/1631/ietf-ospf.yang) and I would like to import it in my own moduls. Can this be done? how?

EDIT1:

module mininet {

 /* name space */
 namespace "http://tail-f.com/ns/example/mininet";
 prefix mininet;

 import ietf-ospf {
     prefix ospf;
     revision-date 2015-03-09
 }

 leaf area-id-type {
     type yang:area-id-type;
 }
}

So I tried to do it this way using Piotr Babij help. Unfortunately this isn't working. What do I need to change? area-id-type is a typedef of ietf-ospf. The error I have is te following one:

mininet.yang:12:3: error: trailing garbage after module
mininet.yang:12:3: error: unterminated statement
B3th4
  • 113
  • 1
  • 2
  • 10
  • 1
    `What do I need to change?` Well, you are missing a semicolon (`;`) for the `revision-date` statement. The parser of the tool you are using got confused a bit because of it, giving you those non descriptive error messages. Plus, you are still using the wrong `prefix` for the type reference from the imported module. – predi Dec 05 '16 at 07:41

1 Answers1

4

You may import other modules in your own modules by using the import statement. It is described in both RFC 7950 for YANG 1.1 and in RFC 6020 for YANG 1.0. In YANG 1.1 you may import two different revisions of the same module. Other that that, the import statement works the same in both versions.

In practice the basic import looks like this:

 module acme-system {
     namespace "http://acme.example.com/system";
     prefix "acme";

     import ietf-yang-types {
         prefix "yang";
         revision-date 2013-07-15;
     }

     leaf acme-ip-address {
         type yang:dotted-quad;
     }
 }

If you omit the optional revision-date statement then an undefined module revision is imported. So, in general, it is a good practive to use it.

The mandatory prefix statement lets you to refer to the things in the imported module. In the example the prefix of the imported ietf-yang-types module is yang and, thanks to that, it is clear that yang:dotted-quad refers to a type from that module. In your case you have set the prefix to ospf, so you should have ospf:area-id-type to refer to a type definition from that module. If you import multiple modules you need to ensure their prefixes are unique.

Additionally, you are importing the oldest available revision of the ietf-ospf module. I just hope that this is what you really want to do.

Anyway, once you import a module you are allowed to:

  • use any grouping and typedef defined at the top level in the imported module or its submodules.

  • use any extension, feature, and identity defined in the imported module or its submodules.

  • 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.

In the above example the typedef dotted-quad from the ietf-yang-types is used in the acme-system module.

Community
  • 1
  • 1
Piotr Babij
  • 837
  • 5
  • 12