Translating YANG to Other Formats

The yangdump-pro program can be used to translate YANG files to other formats, using the --format parameter. This section describes the available translation modes.

In all cases:

  • the :ref:--subtree` or --module parameter is required to specify the input files. Any number of these parameters can be entered, given in any order.

  • the --deviation parameter will affect how objects are generated, if --objview=cooked.

  • the --output parameter is usually specified to cause the files to be copied to a different directory. If this parameter is not present, then the current directory will be used for generation of output files. The default is either STDOUT, or to the current directory if --defnames is set to 'true'.

  • the --indent parameter can be used to specify the number of spaces to indent each new nest level. The default value is 3 spaces.

  • the --defnames parameter can be used to force the default naming scheme. For many translation modes, this parameter is the assumed default, and cannot be changed.

  • the --urlstart parameter can be used to specify the string to start all URLs, if URLs are generated in the output.

YIN Format

The standard YIN format can be generated with the --format=yin parameter value.

The YIN representation of a YANG module is an XML instance document consisting of a <module> or a <submodule> element.

The set of YANG prefixes used in the module will be used as the XML prefixes available in the document. These namespace attributes are added to the top-level element for the module prefix and any imported modules.

The following example shows the XML instance document that is generated for --module=test4 and --format=yin:.

> yangdump-pro --module=test4 --format=yin --output=test4.yin

The file "test4.yin" will be created with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<module 
  name="test4"
  xmlns="urn:ietf:params:xml:ns:yang:yin:1"
  xmlns:t4="http://netconfcentral.org/ns/test4">
  <namespace uri="http://netconfcentral.org/ns/test4" />
  <prefix value="t4" />
  <revision date="2009-09-09">
    <description>
      <text>Initial revision.</text>
    </description>
  </revision>
  <typedef name="aa-type">
    <description>
      <text>test type</text>
    </description>
    <type name="int32">
      <range value="1..10&#32;|&#32;20..30" />
    </type>
  </typedef>
  <container name="a">
    <leaf-list name="aa">
      <type name="aa-type" />
      <max-elements value="5" />
    </leaf-list>
  </container>
  <leaf name="b">
    <type name="leafref">
      <path value="../a/aa" />
    </type>
  </leaf>
  <list name="c">
    <key value="x" />
    <leaf name="x">
      <type name="uint16" />
    </leaf>
    <leaf name="y">
      <type name="instance-identifier" />
    </leaf>
  </list>
</module>

HTML Translation

xHTML 1.0 files can be generated by using the --format=html parameter value.

An HTML version of a YANG file will contain color-coded YANG tokens to make the file easier to read. There will also be links created whenever possible, for statements which reference typedefs, groupings, extensions, etc.

The following configuration parameters are available to control some of the details:

  • --html-div: If 'true', create a single <div> element that can be integrated into other WEB pages. The default is 'false', to create an entire WEB page (<html> element).

  • --html-toc: controls how (or if) a table of contents section is generated. The default is to create a drop-down menu type ToC, which requires that Javascript is enabled in the browser.

  • --objview: controls whether raw (with uses, augments, refine, and deviation statements) or cooked (final object tree without uses, etc). The default is the 'raw' (original) view.

  • --simurls: controls how URLs with parameter fragments are generated. The default is 'false', which is to use traditional encoded parameters.

  • --unified: controls whether submodules are combined into the main module, or if the 'include' statements are left in place. The default is 'false', to treat each file separately, and not expand any include statements.

  • --urlstart: specifies the string that starts every generated URL in all A and HREF attributes. There is no default for this parameter.

The following example shows the HTML that is generated for --module=test4, using default values for all HTML generation parameters:

> yangdump-pro --module=test4 --format=html --output=test4.html

The file "test4.html" will be created with the following contents:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>YANG Module test4 Version 2009-09-09</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="description" content="YANG data model documentation"/>
  <meta name="generator" content="yangdump 21.10-3 (http://www.netconfcentral.org/)"/>
  <link rel="stylesheet" href="http://netconfcentral.org/static/css/style.css" type="text/css"/>
</head>
<body>
  <h1 class="yang">test4@2009-09-09</h1>

  <ul id="nav">
    <li><a href="#">Typedefs</a>
      <ul>
        <li><a href="#aa-type.10">aa-type</a></li>
      </ul>
    </li>
    <li><a href="#">Objects</a>
      <ul>
        <li class="daddy"><a href="#a.15">a</a>
          <ul>
            <li><a href="#aa.16">aa</a></li>
          </ul>
        </li>
        <li><a href="#b.22">b</a></li>
        <li class="daddy"><a href="#c.26">c</a>
          <ul>
            <li><a href="#x.28">x</a></li>
            <li><a href="#y.29">y</a></li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>

<br />
<div class="yang">
<pre>

  <span class="yang_kw">module</span> <span class="yang_id">test4</span> {

    <span class="yang_kw">yang-version</span> <span class="yang_str">1</span>;

    <span class="yang_kw">namespace</span>
      <span class="yang_str">"http://netconfcentral.org/ns/test4"</span>;

    <span class="yang_kw">prefix</span> <span class="yang_str">t4</span>;

    <span class="yang_kw">revision</span> <span class="yang_str">"2009-09-09"</span> {
      <span class="yang_kw">description</span> <span class="yang_str">"Initial revision."</span>;
    }


    <a name="aa-type.10"></a><span class="yang_kw">typedef</span> <span class="yang_id">aa-type</span> {
      <span class="yang_kw">type</span> <span class="yang_id">int32</span> {
        <span class="yang_kw">range</span> <span class="yang_str">"1..10 | 20..30"</span>;
      }
      <span class="yang_kw">description</span> <span class="yang_str">"test type"</span>;
    }

    <a name="a.15"></a><span class="yang_kw">container</span> <span class="yang_id">a</span> {
      <a name="aa.16"></a><span class="yang_kw">leaf-list</span> <span class="yang_id">aa</span> {
        <span class="yang_kw">type</span> <span class="yang_id"><a href="#aa-type.10">aa-type</a></span>;
        <span class="yang_kw">max-elements</span> <span class="yang_str">5</span>;
      }
    }  <span class="yang_cmt">// container a</span>

    <a name="b.22"></a><span class="yang_kw">leaf</span> <span class="yang_id">b</span> {
      <span class="yang_kw">type</span> <span class="yang_id">leafref</span> {
        <span class="yang_kw">path</span> <a href="#aa.16"><span class="yang_str">"../a/aa"</span></a>;
      }
    }

    <a name="c.26"></a><span class="yang_kw">list</span> <span class="yang_id">c</span> {
      <span class="yang_kw">key</span> "<a href="#x.28">x</a>";
      <a name="x.28"></a><span class="yang_kw">leaf</span> <span class="yang_id">x</span> {
        <span class="yang_kw">type</span> <span class="yang_id">uint16</span>;
      }

      <a name="y.29"></a><span class="yang_kw">leaf</span> <span class="yang_id">y</span> {
        <span class="yang_kw">type</span> <span class="yang_id">instance-identifier</span>;
      }
    }  <span class="yang_cmt">// list c</span>
  }  <span class="yang_cmt">// module test4</span>
</pre>
</div>
</body>
</html>

The following picture shows how this WEB page looks in a WEB browser:

../_images/test4_html.png

XSD Translation

Note

Note: This feature is obsolete and no longer supported. Do not use.

SQL Translation

Note

SQL translation is reserved for future use. The --format=sql enumeration is not supported.

SQL Documentation Database Translation

SQL documentation database translation for the Netconf Central documentation database can be generated using the --format=sqldb parameter value.

Canonical YANG Translation

Note

This feature is deprecated. Do not use!

Canonical YANG files can be generated by using the --format=yang parameter value.

In this translation mode, all YANG constructs are generated in the same order, with the same indentation.

The order used is the order defined in the YANG specification ABNF. The order is somewhat arbitrary, but the purpose of this translation mode is to generate consistent documentation.

Normally, the order of top-level statements within a module is preserved in the canonical YANG translation. Only the sub-statements within the top-level statements may be reordered. Child objects are never reordered, just the sub-statements within them.

Range statements will be converted to canonical form. If there are contiguous range parts, then they will be combined.

Note

Comments are not preserved in the translation.

Example range statement:

range "1 .. 10 \| 11 \| 12 .. 20";

Canonical form for this example:

range "1 .. 20";

If the --unified parameter is set to 'true', then all statements of a similar type will be grouped together, from all sub-modules included by the main module.

The ncx:hidden extension will cause objects containing this extension to be omitted during translation.

Copy and Rename YANG Files

Exact copies of a YANG file can be copied to another directory and renamed to the default naming scheme, using the --format=copy parameter value.

Only YANG files that have no errors will be copied. If the validation phase produces a non-zero error count, then the file will not be copied and renamed.

The --defnames parameter is set to 'true' in this mode. The default YANG file names will be created for each input file.

Example file foo.yang:

module foo {
   namespace http://example.com/ns/foo;
   prefix foo;
   // header skipped
   revision 2009-02-03 {
      description "Initial version";
   }
}

Example renamed file, if --output=~/workdir: