Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents
maxLevel4
Team


NameOrganizationEmail
Adarsh MHuawei Technologiesadarsh.m@huawei.com
Bharat SaraswalHuawei Technologiesbharat.saraswal@huawei.com
Gaurav Agrawal Huawei Technologiesgaurav.agrawal@huawei.com
Janani BHuawei Technologiesjanani.b@huawei.com
Sathish Kumar MHuawei Technologiessathishkumar.m@huawei.com
Suchitra H NHuawei Technologiessuchitra.hn@huawei.com
Vidyashree RamaHuawei Technologiesvidyashree.rama@huawei.com
Vinod Kumar SHuawei Technologiesvinods.kumar@huawei.com
ShankaraHuawei Technologies

shankara@huawei.com

Mahesh Poojary SHuawei Technologies

mahesh.poojary@huawei.com

Rama Subba Reddy SHuawei Technologies

Rama.Subba.Reddy.S@huawei.com

Sonu GuptaHuawei Technologiessonu.gupta@huawei.com
A U suryaHuawei Technologies

A.u.surya@huawei.com

Overview

    YANG is a data modeling language used to model configuration & state data. Modeling languages such as SMI (SNMP), UML, XML Schema, and others already existed. However, none of these languages were specifically targeted to the needs of configuration management. They lacked critical capabilities like being easily read and understood by human implementers, and fell short in providing mechanisms to validate models of configuration data for semantics and syntax.

          YANG Utils tools are the basic building block to achieve the final goal of abstracting the language based Syntax/Semantics processing by APPs.Image Removed

 Image Added

The YANG modeled interfaces need to be implemented by corresponding application component. There are 2 parts in implementing the interface:

  1. syntaxSyntax/semantics processing of the request/response being exchanged.
     
  2. business Business logic to compute the request. 

We intend to abstract the applications from syntactic processing of information encoding with external world.We intend to provide a framework in which the applications only need to implement the business logic and seamlessly support any interface language like REST, NETCONF etc.    

Steps to use YANG

...

tools

Yang Buck Plugin :

Step 1

...

: Create a test app and add

...

yang dependency as shown below.

Code Block
<build>
COMPILE_DEPS = <plugins>[
    <plugin>'//lib:CORE_DEPS',
  '//lib:onos-yang-model',
]
yang_osgi_jar(
  deps    <groupId>org.onosproject</groupId>= COMPILE_DEPS,
  name    <artifactId>yangutils-maven-plugin</artifactId>= 'onos-apps-l3vpn-yangmodel',
  srcs = glob(['src/main/**/*.yang']),
  visibility = [
    'PUBLIC'
  ],
)

Step 2: Create a folder structure as “src/main/yang” in the test app folder and place your YANG files in it.

Step 3 : Build using buck build onos command. Generated java code will be placed in default directory or in desired destination folder configured by user.


Yang Maven Plugin :

Step1 : Create a test app and add YANG tools maven plugin to pom file’s build section

Code Block
<build>
  <plugins>
    <plugin>
      <groupId>org.onosproject</groupId>
      <artifactId>onos-yang-maven-plugin</artifactId>
      <version>1.9<  <version>1.0.0-SNAPSHOT</version>
      <executions>
        <execution>
          <configuration><configuration>
             <classFileDir>src/main/java</classFileDir>
          </configuration>
          <goals>
            <goal>yang2java</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Step 2 : Add dependency to pom file’s dependency section

Code Block
<dependencies>
    <dependency>
        <groupId>org.onosproject</groupId>
        <artifactId>yangutils-maven-plugin</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.onosproject</groupId>
        <artifactId>onos-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.felix</groupId>
        <artifactId>org.apache.felix.scr.annotations</artifactId>
    </dependency>
</dependencies>

only if your yang file contains notification in it. You need to add dependencies for "onos-api".

Step 3 : Step 3 : Plugin configuration supported in YANG utilstools 

  1. Create a folder structure as “src/main/yang” in the test app folder and place your YANG files in it.

  2. If incase
  3. In case user want to give desired path for source YANG files and generated java files, the following configuration can be appended to the above pom.xml file. 

    Code Block
    <configuration>
        
  4. <yangFilesDir>/opt/src/yang/</
  5. <yangFilesDir>DesiredYangFilesPath</yangFilesDir>
        
  6. <genFilesDir>/opt/src/java/</genFilesDir>
  7. <classFileDir>DesiredGeneratedJavaFilesPath</classFileDir> 
    </configuration>
  8.  

  9. In YANG, identifier has the support of having “.”, ”-”, “_”. But, in java, we cannot use these characters in class name or attribute name. Hence, by default, these characters will be removed and the successive character will be capitalized for making it camel case. Similarly, in YANG, we can have java keywords and starting with digits, in namespace and identifiers. But, in java, we cannot use it in class name or attribute name or package. Hence, by default, a prefix "yangAutoPrefix" will be added to the identifier name.Here users are given options to change this default behaviour.“.”, ”-”, “_” in identifier name can be replaced by the values given inside the configuration of pom.xml and will be used in java, respectively. Similarly, the prefix value can also be provided in configuration of pom.xml and that will be used as prefix for identifiers.(refer identifier for more details)

    Code Block
    <configuration>
        <replacementForPeriod>dot</replacementForPeriod>
        <replacementForHyphen>hyphen</replacementForHyphen>
        <replacementForUnderscore>underscore</replacementForUnderscore>
        <prefixForIdentifier>prefix</prefixForIdentifier>
    </configuration>
      1. yang-._constuct-generation will be mapped as yangHyphenDotUnderscoreConstuctHyphenGeneration 

      2. const will be mapped as prefixConst

  10.  Default package/folder structure for generated code will be constructed from the namespace of the YANG file and if user wants to generated code with specific folder structure/package he can configure it , using below configurations.

    Code Block
    <configuration>
        <defaultPackage>org.onosproject.sfc</defaultPackage>
    </configuration>

    In above example code will be generated in org.onosproject.sfc package.

  11. As Grouping construct being an special case in YANG. we are giving user a flexibility to choose whether to generate code for grouping node or not. So if user does not wants to generate code he should set the configurations  as false. By default code will be generated. 

    Code Block
    <configuration>
        <groupingCodeGenFlag>true</groupingCodeGenFlag>
    </configuration>

     

  12. In case of RPC construct we have given flexibility for controlling the generation of code for input and output sub statements in a special cases where Input or output contains only one leaf/leaf-list/Yang construct. In such case user can configure whether he wants to generate code for input or output. By default code will be generated and in case input or output contains multiple leaf/leaf-list/Yang constructs code will be generated even the configuration is false.

    Code Block
    <configuration>
        <rpcSubStatementCodeGenFlag>true</rpcSubStatementCodeGenFlag>
    </configuration>

Step 4 : Execution of application

Build using mvn clean install/ mvn install. Generated java code will be placed in default directory or in desired destination folder configured by user.

Note : Code generated is as per ONOS coding guidelines.

YANG utils constructs support/plan

Step 4 : Execution of application

Build using mvn clean install/ mvn install. Generated java code will be placed in default directory or in desired destination folder configured by user.

Info
titleCode generated is as per ONOS coding guidelines.

Note:

  1. If user does not provide any configurations for code generation , code will be generated in "target/generated-sources" folder. This folder conatains majorly,
    i) Service interface for module.
    ii) Module interface and its param class.
    iii) Interfaces of child constructs of module and their default implementation class.
  2. If a yang file contains only typedef/grouping nodes, there will not be any generation of service class only one interface will be generated.

YANG tools constructs support/plan

YANG ConstructSupported/Planned version
anyxmlNot planned
argumentHummingbird(partial support)
augmentGoldeneye
uses-augmentLoon
baseHummingbird
belongs-toGoldeneye
bitHummingbird
caseGoldeneye
choiceGoldeneye
configFalcon
contact

Goldeneye

Enhancement in Hummingbird

containerFalcon
default

Goldeneye

Enhancement in Humminbird

description

Goldeneye

Enhancement in Hummingbird

deviateNot planned
deviationNot planned
enumGoldeneye
error-app-tagHummingbird
error-messageHummingbird
extensionHummingbird(partial support)
featureHummingbird
fraction-digitsHummingbird
groupingGoldeneye
identityHummingbird
if-featureHummingbird
import

Goldeneye

Enhancement in Hummingbird

include

Goldeneye

Enhancement in Hummingbird

inputGoldeneye
keyGoldeneye
leafFalcon
leaf-listFalcon
lengthGoldeneye
listFalcon
mandatoryFalcon
max-elementsGoldeneye
min-elementsGoldeneye
moduleFalcon
mustHummingbird
namespaceGoldeneye
notificationGoldeneye
ordered-
YANG ConstructSupported/Planned versionanyxmlNot plannedargumentNot plannedaugmentGoldeneyebaseHummingbirdbelongs-toGoldeneyebitGoldeneyecaseGoldeneyechoiceGoldeneyeconfigFalconcontact

Goldeneye

Enhancement in Hummingbird

containerFalcondefault

Goldeneye

Enhancement in Humminbird

description

Goldeneye

Enhancement in Hummingbird

deviateNot planneddeviationNot plannedenumGoldeneyeerror-app-tagNot plannederror-messageNot plannedextensionNot plannedfeatureHummingbirdfraction-digitsGoldeneyegroupingGoldeneyeidentityHummingbirdif-featureHummingbirdimport

Goldeneye

Enhancement in Hummingbird

include

Goldeneye

Enhancement in Hummingbird

inputGoldeneyekeyGoldeneyeleafFalconleaf-listFalconlengthGoldeneyelistFalconmandatoryFalconmax-elementsGoldeneyemin-elementsGoldeneyemoduleFalconmustHummingbirdnamespaceGoldeneyenotificationGoldeneyeordered-
byNot planned
organization

Goldeneye

Enhancement in Hummingbird
outputGoldeneye
pathHummingbird
patternGoldeneye
positionGoldeneye
prefixGoldeneye
presenceGoldeneye
rangeGoldeneye
reference

Goldeneye

Enhancement in Hummingbird
refineNot planned
require-instance
Not planned
Hummingbird
revision

Goldeneye

Enhancement in Hummingbird
revision-date

Goldeneye

rpcGoldeneye
status

Goldeneye

Enhancement in Hummingbird
submoduleGoldeneye
typeGoldeneye
typedefGoldeneye
unique
Not Planned
  Kingfisher
unknown Kingfisher
units

Goldeneye

uses

Goldeneye

Enhancement in Hummingbird

valueGoldeneye
whenHummingbird
yang-versionGoldeneye
yin-elementNot Planned

Built-in YANG data types support/plan

Binary

Goldeneye

Enhancement in Hummingbird
Bits

Goldeneye

Enhancement in Hummingbird
booleanGoldeneye
decimal64

Goldeneye

Enhancement in Hummingbird
emptyGoldeneye
enumerationGoldeneye
identityrefHummingbird
instance-identifierHummingbird
int8Goldeneye
int16Goldeneye
int32Goldeneye
int64Goldeneye
leafrefHummingbird
stringFalcon
uint8Goldeneye
uint16Goldeneye
uint32Goldeneye
uint64Goldeneye
unionGoldeneye

Generated JAVA Details

Common behavior

Identifier

The identifier name of yang YANG constructs are taken, and are used in java by converting it to lower camel case. Identifier names are allowed to have three special characters such as “-”, ”_”, “.”. Whereas, in java, we cannot use these special characters. These characters will be removed during conversion. Conversion takes place by following the below rules of lower camel case.

  • The first letter of the identifier will be a small letter. If the three special characters occur alone or in group, they will be removed and the consecutive letter will be capitalized.

    • name-conversion will be mapped as nameConversion

    • yang-._constuct-generation will be mapped as yangConstuctGeneration

  • When identifier name has a special character followed by a number, the following letter from the digits will be capitalized.

    • yang_123construct will be mapped to yang123Construct

  • In java file, class name or attribute name cannot have java keyword or start with digits. During the conversion into java, we add prefix to the identifier “yangAutoPrefix”, by default.

    • _123date will be mapped to yangAutoPrefix123Date

    • const will be mapped to yangAutoPrefixConst

  • As per camelcase conversion rules, no two consecutive letters will have capitalization and the last letter will also not be capitalized. 

  • ca
      • ca-l.e_nder will be mapped to caLeNder
  • tric
      • tric-._k will be mapped to trick
  •     
      •   
  •  

  • If users input has capital case, the following will be the conversion methods.

    • TESTNAME
    • TESTNAME will be mapped to testname

    • TEST
    • TEST-NAME will be mapped to testName

    • TestName
    • TestName will be mapped to testName

    •  TEST3NAME will be mapped to test3Name

...

Info
titleWhen the identifier has to be used as java class name, after the above conversion, the first letter will be capitalized and if consecutive capital letters are present, it will be corrected and assigned as java class name.

...

If an identifier for a construct contains java keywords, then it name will be prefixed with "yangAutoPrefix" in generated code.

Namespace

The namespace is a mandatory statement in the module. We define namespace for URL/URI and for folder structure of generated java code. Here in ONOS YANG plugin, namespace forms a folder structure which in turn will be the package name in java.

  • The package will have “org.onosproject.yang.gen.v1.” by default in it. The namespace will be added to the above and the folder structure will also be formed respectively. This becomes the parent package.

  • When a node occurs in yang, a new package will be generated under the parent package. The new package name is the node name and class for that node will be placed under this newly created package. The conversion from yang namespace to the java package will take place as below.

  • The conversion from YANG namespace to the java package will take place as below.

    • The

  • The
    • complete namespace will be changed to lowercase letters. When special characters or a group of special characters are found, it replaces those characters by dot.

  • as
  • as
  • yang
    • YANG file current date will be appended to the package.

Javadocs

Currently Java doc will be generated as per ONOS javadoc guidelines.
Note: Here in wiki for the given examples for each YANG construct we have removed generated javadocs for documentation purpose. Code will contain all the default javadoc which we are providing in golden-eye release. Javadocs support will be enhanced in hummingbird release.

YANG statements

Module

Overview

The primary unit of YANG is module. The module statement groups all the statements that belong to module together. The module statement argument is name of the module followed by sub-statements. 

JAVA mapping

Module statement is mapped to

  1. Service interface 
    It includes:
    a) java methods corresponding to the YANG RPC (Refer RPC section for more details)
    b) If module contains notification, generated service interface will extend listener service (refer notification for more details)
  2. Manager class
    It includes:
    a ) Activate/Deactivate methods
    b) If module contains child data nodes, getters and setters for those nodes will be generated for app developers to implement.
    c)If module contains notification, generated manager class will extend ListenerRegistry(refer notification for more details) .
     
    The manager class implements the service interface. The name of service interface and manager class is <module_name>Service.java and <module_name>Manager.java.
Example
    •   
  • When a node appears, with child node in it, a new package will be generated under the parent package, for that node. The new package is, parent package appended with the node name. The class for that node will be placed under this newly created package.

Example
Code Block
titleInput YANG file
File : acme-system.yang
module acme-system {
     namespace "http://acme.example.com/system";
     prefix "acme";
     organization "ACME Inc."
Code Block
titleInput YANG file
File : network.yang
  module network {
     yang-version 1;
     namespace "urn:TBD:params:xml:ns:yang:nodescontact "joe@acme.example.com";
     description
 prefix nd;

     organization "TBD";
     contactThe module for entities implementing the ACME system.";
     revision  "WILL2007-BE-DEFINED-LATER";
06-09 {
      description
   description "Initial revision.";
   "This module defines}
 a common base model forcontainer asystem collection{
        of nodescontainer inlogin a{
 network. Node definitions s are further used
      leaf message in{
 network topologies and inventories.";

     revision 2014-03-09 {
      type descriptionstring;
         "Initial revision.";
        description
 reference "draft-clemm-i2rs-yang-network-topo-04";
     }
     
     list networklist {
  "Message given at start of keylogin session"network-id";

       leaf network-id {
    }
     type string;
   }
    }

    .
   leaf server-provided {
         type boolean;
         config false;
       } .
     }
     ….
}


Code Block
titleGenerated Java files
File : NetworkServiceSystem.java
package org.onosproject.yang.gen.v1.urnhttp.tbdacme.paramsexample.xmlcom.nssystem.yangrev20070609.nodes.rev20140309acmesystem;

import java.util.List; 

import org.onosproject.yang.gen.v1.urnhttp.tbdacme.paramsexample.xmlcom.nssystem.yangrev20070609.nodesacmesystem.rev20140309.network.Networklist;
system.Login; 

/** 
 * Abstraction of an entity which represents the functionality of system. 
 */ 
public interface NetworkServiceSystem { 

    List<Networklist> getNetworklist();
/** 
     * Returns the attribute login. 
    void setNetworklist(List<Networklist> networklist);
}


File : NetworkManager.java
package org.onosproject.yang.gen.v1.urn.tbd.params.xml.ns.yang.nodes.rev20140309;

import java.util.List;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.yang.gen.v1.urn.tbd.params.xml.ns.yang.nodes.rev20140309.network.Networklist;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;

@Component (immediate = true)
@Service
public class NetworkManager implements NetworkService {

    private final Logger log = getLogger(getClass());

    @Activate
    public void activate() {* 
     * @return login value of login 
     */ 
    Login login(); 

    /** 
     * Sets the attribute login. 
     * 
     * @param login value of login 
     */ 
  //TODO: YANG utilsvoid generated code
          log.info("Started");
    }

    @Deactivate
    public void deactivate() {
        //TODO: YANG utils generated code
          log.info("Stopped");
    }

    @Override
    public List<Networklist> getNetworklist() {login(Login login); 

}

Javadocs

Currently Java doc will be generated as per ONOS javadoc guidelines.

YANG statements

Module

Overview

The primary unit of YANG is module. The module statement groups all the statements that belong to module together. The module statement argument is name of the module followed by sub-statements. 

JAVA mapping

Module statement is mapped to

  1. Service interface  
    It includes:
    a) java methods corresponding to the YANG RPC (Refer RPC section for more details)
    b) If module contains notification, generated service interface will extend listener service (refer notification for more details).The name of service interface is <module_name>Service.java .
    c) If module contains augment the get and setter for augmented module will be generated.

    Info

    Service file will be generated only if RPC/Notification is present.

  2. Interface and implementation class (Note: for module implementation class will have name xxxxOpParam.java)
Example
Code Block
titleInput YANG file
File : network.yang
  module network { 
     yang-version 1; 
     namespace   //TODO: YANG utils generated code"urn:TBD:params:xml:ns:yang:nodes"; 
     prefix nd; 
 
     organization "TBD"; 
     returncontact null;
      }

 "WILL-BE-DEFINED-LATER"; 
     @Overridedescription 
    public void setNetworklist(List<Networklist> networklist) {
          //TODO: YANG utils generated code
    }
}

Sub Module

 Overview

The “submodule” groups all the statements that belongs to the submodule together. The "submodule" statement's argument is the name of the submodule, followed by a block of sub statements.

JAVA mapping

Submodule mapping to java is same as module and files with be generated in module’s namespace.

Example
Code Block
titleInput YANG files
File : acme-system.yang
module acme-system {
    namespace "http://yang-central.org/ns/example/acme";
    prefix acme;

    include "acme-types"; "This module defines a common base model for a collection 
        of nodes in a network. Node definitions s are further used 
        in network topologies and inventories."; 
 
    leaf id revision 2014-03-09 { 
       description type
 string;
    }
}
File : acme-types.yang
submodule acme-types {
    yang-version 1;
 "Initial revision."; 
       belongs-toreference "acme-system" {draft-clemm-i2rs-yang-network-topo-04"; 
     }  
 prefix "acme";
    }
    leaf access-timeout list networklist { 
        type uint32;key "network-id"; 
 
   }
    leaf retriesnetwork-id { 
         type uint8string; 
    }
}
Code Block
titleGenerated Java files
File : AcmeSystemManager.java
package org.onosproject.yang.gen.v1.http.yang.central.org.ns.example.acme.rev20160526;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;

@Component (immediate = true)
@Service
public class AcmeSystemManager implements AcmeSystemService {

    private final Logger log = getLogger(getClass());

    @Activate
    public void activate() { } 
 
       leaf server-provided { 
         type boolean; 
         config false; 
       } //TODO:
 YANG utils generated code
          log.info("Started"); } 
    }

 rpc rpc-test { @Deactivate
    public void deactivate()input { 
        //TODO: YANG utils generated code
 container cont { 
         log.info("Stopped");
   leaf }

lf {   @Override
    public String getId() {
          //TODO: YANG utilstype generatedstring; code
          return null;
 }   }

    @Override
    public void setId(String id) {} 
      } 
 //TODO: YANG utils generated code
   }  }
}

Code Block
titleGenerated Java files
File : AcmeSystemServiceNetworkService.java

package org.onosproject.yang.gen.v1.httpurn.yangtbd.centralparams.orgxml.ns.exampleyang.acmenodes.rev20160526rev20140309;

public interface AcmeSystemService {

    String getId();

    void setId(String id);
}

File : AcmeTypesManager.java
package import org.onosproject.yang.gen.v1.httpurn.yangtbd.centralparams.orgxml.ns.exampleyang.acme.rev20160526;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;

@Component (immediate = true)
@Service
public class AcmeTypesManager implements AcmeTypesService {

    private final Logger log = getLogger(getClass());

    @Activate
    public void activate() {nodes.rev20140309.network.rpctest.RpcTestInput; 

/** 
 * Abstraction of an entity which represents the functionality of network. 
 */ 
public interface NetworkService { 
    /** 
     * Service interface of rpcTest. 
        //TODO: YANG utils generated code
          log.info("Started");* 
     * @param inputVar input of service interface rpcTest 
    }

    @Deactivate
  */ 
   public void deactivaterpcTest() {
        //TODO: YANG utils generated code
          log.info("Stopped");
    }

    @Override
    public long getAccessTimeout() {
        //TODO: YANG utils generated codeRpcTestInput inputVar); 

}


File : Network.java
 
package org.onosproject.yang.gen.v1.urn.tbd.params.xml.ns.yang.nodes.rev20140309; 

import java.util.List; 
import org.onosproject.yang.gen.v1.urn.tbd.params.xml.ns.yang.nodes.rev20140309.network.Networklist; 

/** 
 * Abstraction of an entity which represents the functionality of network. 
 */ 
public interface Network { 

    /** 
     * Returns the attribute networklist. 
     * 
     * @return networklist list of returnnetworklist 0;
    }

  */  @Override
    publicList<Networklist> short getRetriesnetworklist(); {
 
    /** 
    //TODO: YANG utils generated code * Sets the attribute networklist. 
     * 
    return 0;
    }

 * @param networklist list of networklist 
     @Override*/ 
    public void setAccessTimeoutnetworklist(longList<Networklist> accessTimeoutnetworklist); {

    /** 
   //TODO: YANG utils generated code
    }
  * Adds to the list of networklist. 
    @Override
 * 
  public void setRetries(short retries)* {
@param addTo value of networklist 
     /*/TODO: YANG
 utils generated code
 void addToNetworklist(Networklist addTo); }

}
 
File : AcmeTypesServiceNetworkOpParam.java

package org.onosproject.yang.gen.v1.httpurn.yangtbd.centralparams.orgxml.ns.exampleyang.acmenodes.rev20160526rev20140309; 

public interface AcmeTypesService {
    long getAccessTimeout();

    short getRetries();

    void setAccessTimeout(long accessTimeout);

    void setRetries(short retries);
}

Prefix 

Overview

Prefix is used to define prefix associated with module. It is used as a hint to other module developers when they import our module.

JAVA mapping

There is no java mapping for prefix statement.

Example
Code Block
module dhcp {
  namespace "http://yang-central.org/ns/example/dhcp";
  prefix dhcp;

 import ietf-yang-types { prefix yang; }
 import ietf-inet-types { prefix inet; }
}

Note the prefixes above. In order to refer to the yang-module from now on, we use the prefix, e.g. the statement:

type yang:date-and-time;

refers to the date-and-time type defined in the yang-types module.

We use the prefix defined in the module itself, e.g. in the yang-types module, the prefix is defined as yang. You can use which prefix you want in your import, as long as it is unique within the module, but by using the prefix from the module, your module will be easier to read for others.

Import

Overview

A module can import definitions from other module or submodule by using import statement. It takes an argument, the name of the module or submodule followed by sub statements prefix and revision statement. Multiple import statements may be specified to import from different modules. Prefix statement inside import is mandatory and its scope is within the imported module or sub-module.

JAVA mapping

When imported YANG file is used in any of the nodes in current YANG file, then Java code will genereted for imported YANG file. If it is imported YANG file is not used in any of the node in current YANG file then Java code for imported file will not be genereted.

Example
import com.google.common.base.MoreObjects; 
import java.util.ArrayList; 
import java.util.List; 
import java.util.Map; 
import java.util.Objects; 
import org.onosproject.yang.gen.v1.urn.tbd.params.xml.ns.yang.nodes.rev20140309.network.Networklist; 
import org.onosproject.yang.model.InnerModelObject; 

/** 
 * Represents the implementation of network. 
 * 
 * <p> 
 * valueLeafFlags identify the leafs whose value are explicitly set 
 * Applicable in protocol edit and query operation. 
 * </p> 
 */ 
public class NetworkOpParam extends InnerModelObject implements Network { 
    protected List<Networklist> networklist; 

    @Override 
    public List<Networklist> networklist() { 
        return networklist; 
    } 

    @Override 
    public void networklist(List<Networklist> networklist) { 
        this.networklist = networklist; 
    } 

    @Override 
    public void addToNetworklist(Networklist addTo) { 
        if (networklist == null) { 
            networklist = new ArrayList<>(); 
        } 
        networklist.add(addTo); 
    } 


    @Override 
    public int hashCode() { 
        return Objects.hash(networklist); 
    } 

    @Override 
    public boolean equals(Object obj) { 
        if (this == obj) { 
            return true; 
        } 
        if (obj instanceof NetworkOpParam) { 
            NetworkOpParam other = (NetworkOpParam) obj; 
            return 
                Objects.equals(networklist, other.networklist); 
        } 
        return false; 
    } 

    @Override 
    public String toString() { 
        return MoreObjects.toStringHelper(getClass()) 
            .omitNullValues() 
            .add("networklist", networklist) 
            .toString(); 
    } 

    /** 
     * Creates an instance of networkOpParam. 
     */ 
    public NetworkOpParam() { 
    } 


    @Override 
    public void addAugmentation(InnerModelObject obj) { 
    } 

    @Override 
    public void removeAugmentation(InnerModelObject obj) { 
    } 

    @Override 
    public Map<Class<? extends InnerModelObject>, InnerModelObject> augmentations() { 

        return null; 
    } 

    @Override 
    public <T extends InnerModelObject> T augmentation(Class<T> c) { 

        return null; 
    } 
}


Sub Module

Overview

The “submodule” groups all the statements that belongs to the submodule together. The "submodule" statement's argument is the name of the submodule, followed by a block of sub statements.

JAVA mapping

Submodule mapping to java is same as module and files with be generated in module’s namespace.

Example
Code Block
titleInput YANG files
File : acme-system.yang
module acme-system {
    namespace "http://yang-central.org/ns/example/acme";
    prefix acme;
    include "acme-types";
 
    container access {
        leaf id {
            type uint32;
        }
        
    }
}
File : acme-types.yang
submodule acme-types {
    yang-version 1;
    belongs-to "acme-system" {
        prefix "acme";
    }
    
    container access {
        leaf access-timeout {
            type uint32;
        }
        leaf retries {
            type uint8;
        }
    }
}
Info

Code generation will be same as module.


Prefix 

Overview

Prefix is used to define prefix associated with module. It is used as a hint to other module developers when they import our module.

JAVA mapping

There is no java mapping for prefix statement.

Example
Code Block
module dhcp {
  namespace "http://yang-central.org/ns/example/dhcp";
  prefix dhcp;

 import ietf-yang-types { prefix yang; }
 import ietf-inet-types { prefix inet; }
}

Note the prefixes above. In order to refer to the yang-module from now on, we use the prefix, e.g. the statement:

type yang:date-and-time;

refers to the date-and-time type defined in the yang-types module.

We use the prefix defined in the module itself, e.g. in the yang-types module, the prefix is defined as yang. You can use which prefix you want in your import, as long as it is unique within the module, but by using the prefix from the module, your module will be easier to read for others.

Import

Overview

A module can import definitions from other module or submodule by using import statement. It takes an argument, the name of the module or submodule followed by sub statements prefix and revision statement. Multiple import statements may be specified to import from different modules. Prefix statement inside import is mandatory and its scope is within the imported module or sub-module.

JAVA mapping

When imported YANG file is used in any of the nodes in current YANG file, then Java code will genereted for imported YANG file. If it is imported YANG file is not used in any of the node in current YANG file then Java code for imported file will not be genereted.

Example
Code Block
titleInput YANG files
File : flow-classifier.yang
module flow-classifier {
    yang-version 1;
    namespace "sfc.flowclassifier";
    prefix "flow-classifier";
    import "ietf-yang-types" {
        prefix "yang";
    } 
    
    organization "ON-LAB";
    description "This submodule defines for flow classifier.";
    revision "2016-05-24" {
        description "Initial revision.";
    }
   
    leaf id {
        type yang:uuid;
    }
}

File : ietf-yang-types.yang
module ietf-yang-types {

     namespace "urn:ietf:params:xml:ns:yang:ietf-yang-types";
     prefix "yang";

     organization
      "IETF NETMOD (NETCONF Data Modeling Language) Working Group";

     contact
      "WG Web:   <http://tools.ietf.org/wg/netmod/>
       WG List:  <mailto:netmod@ietf.org>

       WG Chair: David Kessens
                 <mailto:david.kessens@nsn.com>

       WG Chair: Juergen Schoenwaelder
                 <mailto:j.schoenwaelder@jacobs-university.de>

       Editor:   Juergen Schoenwaelder
                 <mailto:j.schoenwaelder@jacobs-university.de>";

     description
      "This module contains a collection of generally useful derived
       YANG data types.

       Copyright (c) 2013 IETF Trust and the persons identified as
       authors of the code.  All rights reserved.

       Redistribution and use in source and binary forms, with or
       without modification, is permitted pursuant to, and subject
       to the license terms contained in, the Simplified BSD License
       set forth in Section 4.c of the IETF Trust's Legal Provisions
       Relating to IETF Documents
       (http://trustee.ietf.org/license-info).

       This version of this YANG module is part of RFC 6991; see
       the RFC itself for full legal notices.";

     revision 2013-07-15 {
       description
        "This revision adds the following new data types:
         - yang-identifier
         - hex-string
         - uuid
         - dotted-quad";
       reference
        "RFC 6991: Common YANG Data Types";
     }

     revision 2010-09-24 {
       description
        "Initial revision.";
       reference
        "RFC 6021: Common YANG Data Types";
     }

     typedef uuid {
       type string {
         pattern '[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-'
               + '[0-9a-fA-F]{4}-[0-9a-fA-F]{12}';
       }
       description
        "A Universally Unique IDentifier in the string representation
         defined in RFC 4122.  The canonical representation uses
         lowercase characters.

         The following is an example of a UUID in string representation:
         f81d4fae-7dec-11d0-a765-00a0c91e6bf6
         ";
       reference
        "RFC 4122: A Universally Unique IDentifier (UUID) URN
                   Namespace";
     }
}
Code Block
titleGenerated Java files
File : Uuid.java
package org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20100924.ietfyangtypes;
import java.util.Objects;
import com.google.common.base.MoreObjects;

public final class Uuid {
    private String string;

    private Uuid() {
    }

    public Uuid(String value) {
        this.string = value;
    }

    public static Uuid of(String value) {
        return new Uuid(value);
    }

    public String string() {
        return string;
    }

    @Override
    public int hashCode() {
        return Objects.hash(string);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof Uuid) {
            Uuid other = (Uuid) obj;
            return
                 Objects.equals(string, other.string);
        }
        return false;
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(getClass())
            .add("string", string)
            .toString();
    }

    public static Uuid fromString(String valInString) {
        try {
            String tmpVal = (valInString);
            return of(tmpVal);
        } catch (Exception e) {
        }
        return null;
    }
}
 
File : DefaultCont1.java

package org.onosproject.yang.gen.v1.sfc.flowclassifier.rev20160524.flowclassifier; 

import com.google.common.base.MoreObjects; 
import java.util.BitSet; 
import java.util.Objects; 
import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20130715.ietfyangtypes.Uuid; 
import org.onosproject.yang.model.InnerModelObject; 

/** 
 * Represents the implementation of cont1. 
 * 
 * <p> 
 * valueLeafFlags identify the leafs whose value are explicitly set 
 * Applicable in protocol edit and query operation. 
 * </p> 
 */ 
public class DefaultCont1 extends InnerModelObject implements Cont1 { 
    protected Uuid id; 
    protected BitSet valueLeafFlags = new BitSet(); 

    @Override 
    public Uuid id() { 
        return id; 
    } 

    @Override 
    public BitSet valueLeafFlags() { 
        return valueLeafFlags; 
    } 

    @Override 
    public void id(Uuid id) { 
        valueLeafFlags.set(LeafIdentifier.ID.getLeafIndex()); 
        this.id = id; 
    } 

    @Override 
    public int hashCode() { 
        return Objects.hash(id, valueLeafFlags); 
    } 

    @Override 
    public boolean equals(Object obj) { 
        if (this == obj) { 
            return true; 
        } 
        if (obj instanceof DefaultCont1) { 
            DefaultCont1 other = (DefaultCont1) obj; 
            return 
                Objects.equals(id, other.id) && 
                Objects.equals(valueLeafFlags, other.valueLeafFlags); 
        } 
        return false; 
    } 

    @Override 
    public String toString() { 
        return MoreObjects.toStringHelper(getClass()) 
            .omitNullValues() 
            .add("id", id) 
            .add("valueLeafFlags", valueLeafFlags) 
            .toString(); 
    } 


    /** 
     * Creates an instance of defaultCont1. 
     */ 
    public DefaultCont1() { 
    } 


    @Override 
    public boolean isLeafValueSet(LeafIdentifier leaf) { 
        return valueLeafFlags.get(leaf.getLeafIndex()); 
    } 

}


Include

Overview

A module uses a include statement to include sub-module that belongs to module. The argument is the name of sub-module. Modules are only allowed to include sub-module that belongs to module, as defined by belongs-to statement. When a module includes a submodule, it incorporates the contents of the submodule into the node hierarchy of the module.

JAVA mapping

There is no java mapping for include statement.

Example

Please refer submodule example

Organization

Overview

   The "organization" statement defines the party responsible for this module.  The argument is a string that is used to specify a textual description of the organization(s) under whose auspices this module was developed.

JAVA mapping

 Organization will be used as javadoc in generated java code in Hummingbird release version. Currently it is not used in generated java code.

Example

Please refer module example section

Contact

Overview

  The "contact" statement provides contact information for the module. The argument is a string that is used to specify contact information for the person or persons to whom technical queries concerning this  module should be sent, such as their name, postal address, telephone number, and electronic mail address.

JAVA mapping

 Contact information will be used as javadoc in generated java code in Hummingbird release version. Currently it is not used in generated java code.

Example

Please refer module example section

Belongs to

Overview

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 the module to which it belongs, or by another submodule that belongs to that module.

JAVA mapping

No java mapping for belongs to statement in generated code.

Example

Please refer submodule example section.

Leaf

Overview

A leaf is an atomic element in YANG. It has value, but does not have child. It is used for defining the scalar variable of a built-in type or a derived type.

Java mapping

In java leaf is converted to define variable with its respective java built-in type or derived type.

Example
Code Block
titleInput YANG file
File : acme-system.yang
module acme-system {
     namespace "http://acme.example.com/system";
     prefix "acme";
     organization "ACME Inc.";
     contact "joe@acme.example.com";
     description
        "The module for entities implementing the ACME system.";
     revision 2007-06-09 {
         description "Initial revision.";
     }
     container system {
            leaf host-name {
                type string;
                description "Hostname for this system";
           }
     }
    .
    .
    .
}

  

Code Block
titleGenerated Java files
File: System.java
package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem; 

import java.util.BitSet; 

/** 
 * Abstraction of an entity which represents the functionality of system. 
 */ 
public interface System { 

    /** 
     * Identify the leaf of System. 
     */ 
    public enum LeafIdentifier implements org.onosproject.yang.model.LeafIdentifier{ 
        /** 
         * Represents hostName. 
         */ 
        HOSTNAME(1); 

        private int leafIndex; 

        public int getLeafIndex() { 
            return leafIndex; 
        } 

        LeafIdentifier(int value) { 
            this.leafIndex = value; 
        } 
    } 
 
    /** 
     * Returns the attribute hostName. 
     * 
     * @return hostName value of hostName 
     */ 
    String hostName(); 

    /** 
     * Returns the attribute valueLeafFlags. 
     * 
     * @return valueLeafFlags value of valueLeafFlags 
     */ 
    BitSet valueLeafFlags(); 

    /** 
     * Sets the attribute hostName. 
     * 
     * @param hostName value of hostName 
     */ 
    void hostName(String hostName); 


    /** 
     * Checks if the leaf value is set. 
     * 
     * @param leaf leaf whose value status needs to checked 
     * @return result of leaf value set in object 
     */ 
    boolean isLeafValueSet(LeafIdentifier leaf); 
}


File : DefaultSystem.java

package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem; 

import com.google.common.base.MoreObjects; 
import java.util.BitSet; 
import java.util.Objects; 
import org.onosproject.yang.model.InnerModelObject; 

/** 
 * Represents the implementation of system. 
 * 
 * <p> 
 * valueLeafFlags identify the leafs whose value are explicitly set 
 * Applicable in protocol edit and query operation. 
 * </p> 
 */ 
public class DefaultSystem extends InnerModelObject implements System { 
    protected String hostName; 
    protected BitSet valueLeafFlags = new BitSet(); 

    @Override 
    public String hostName() { 
        return hostName; 
    } 

    @Override 
    public BitSet valueLeafFlags() { 
        return valueLeafFlags; 
    } 

    @Override 
    public void hostName(String hostName) { 
        valueLeafFlags.set(LeafIdentifier.HOSTNAME.getLeafIndex()); 
        this.hostName = hostName; 
    } 

    @Override 
    public int hashCode() { 
        return Objects.hash(hostName, valueLeafFlags); 
    } 

    @Override 
    public boolean equals(Object obj) { 
        if (this == obj) { 
            return true; 
        } 
        if (obj instanceof DefaultSystem) { 
            DefaultSystem other = (DefaultSystem) obj; 
            return 
                Objects.equals(hostName, other.hostName) && 
                Objects.equals(valueLeafFlags, other.valueLeafFlags); 
        } 
        return false; 
    } 

    @Override 
    public String toString() { 
        return MoreObjects.toStringHelper(getClass()) 
            .omitNullValues() 
            .add("hostName", hostName) 
            .add("valueLeafFlags", valueLeafFlags) 
            .toString(); 
    } 


    /** 
     * Creates an instance of defaultSystem. 
     */ 
    public DefaultSystem() { 
    } 


    @Override 
    public boolean isLeafValueSet(LeafIdentifier leaf) { 
        return valueLeafFlags.get(leaf.getLeafIndex()); 
    } 

}


Leaf-list

 Overview

A leaf-list is also used for defining scalar variable, like leaf, but in an array of a particular type. The type of the variable can be either built-in type or a derived type.

Java mapping

In java leaf-list is stored in List, with respect to, java built-in type or derived type.

Example
Code Block
titleInput YANG file
File : acme-system.yang
module acme-system {
     namespace "http://acme.example.com/system";
     prefix "acme";
     organization "ACME Inc.";
     contact "joe@acme.example.com";
     description
        "The module for entities implementing the ACME system.";
     revision 2007-06-09 {
         description "Initial revision.";
     }
     container system {
             leaf-list domain-search {
                 type string;
                 description "List of domain names to search";
             }
     }
    .
    .
    .
}

 

Code Block
titleGenerated Java files
File : System.java
package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem; 

import java.util.BitSet; 
import java.util.List; 

/** 
 * Abstraction of an entity which represents the functionality of system. 
 */ 
public interface System { 

    /** 
     * Identify the leaf of System. 
     */ 
    public enum LeafIdentifier implements org.onosproject.yang.model.LeafIdentifier{ 
        /** 
         * Represents domainSearch. 
         */ 
        DOMAINSEARCH(1); 

        private int leafIndex; 
 
        public int getLeafIndex() { 
            return leafIndex; 
        } 

        LeafIdentifier(int value) { 
            this.leafIndex = value; 
        } 
    } 

    /** 
     * Returns the attribute domainSearch. 
     * 
     * @return domainSearch list of domainSearch 
     */ 
    List<String> domainSearch(); 

    /** 
     * Returns the attribute valueLeafFlags. 
     * 
     * @return valueLeafFlags value of valueLeafFlags 
     */ 
    BitSet valueLeafFlags(); 

    /** 
     * Sets the attribute domainSearch. 
     * 
     * @param domainSearch list of domainSearch 
     */ 
    void domainSearch(List<String> domainSearch); 

    /** 
     * Adds to the list of domainSearch. 
     * 
     * @param addTo value of domainSearch 
     */ 
    void addToDomainSearch(String addTo); 


    /** 
     * Checks if the leaf value is set. 
     * 
     * @param leaf leaf whose value status needs to checked 
     * @return result of leaf value set in object 
     */ 
    boolean isLeafValueSet(LeafIdentifier leaf); 
}

File : DefaultSystem.java

package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem; 

import com.google.common.base.MoreObjects; 
import java.util.ArrayList; 
import java.util.BitSet; 
import java.util.List; 
import java.util.Objects; 
import org.onosproject.yang.model.InnerModelObject; 

/** 
 * Represents the implementation of system. 
 * 
 * <p> 
 * valueLeafFlags identify the leafs whose value are explicitly set 
 * Applicable in protocol edit and query operation. 
 * </p> 
 */ 
public class DefaultSystem extends InnerModelObject implements System { 
    protected List<String> domainSearch; 
    protected BitSet valueLeafFlags = new BitSet(); 

    @Override 
    public List<String> domainSearch() { 
        return domainSearch; 
    } 

    @Override 
    public BitSet valueLeafFlags() { 
        return valueLeafFlags; 
    } 

    @Override 
    public void domainSearch(List<String> domainSearch) { 
        valueLeafFlags.set(LeafIdentifier.DOMAINSEARCH.getLeafIndex()); 
        this.domainSearch = domainSearch; 
    } 

    @Override 
    public void addToDomainSearch(String addTo) { 
        if (domainSearch == null) { 
            domainSearch = new ArrayList<>(); 
        } 
        domainSearch.add(addTo); 
    } 


    @Override 
    public int hashCode() { 
        return Objects.hash(domainSearch, valueLeafFlags); 
    } 

    @Override 
    public boolean equals(Object obj) { 
        if (this == obj) { 
            return true; 
        } 
        if (obj instanceof DefaultSystem) { 
            DefaultSystem other = (DefaultSystem) obj; 
            return 
                Objects.equals(domainSearch, other.domainSearch) && 
                Objects.equals(valueLeafFlags, other.valueLeafFlags); 
        } 
        return false; 
    } 

    @Override 
    public String toString() { 
        return MoreObjects.toStringHelper(getClass()) 
            .omitNullValues() 
            .add("domainSearch", domainSearch) 
            .add("valueLeafFlags", valueLeafFlags) 
            .toString(); 
    } 


    /** 
     * Creates an instance of defaultSystem. 
     */ 
    public DefaultSystem() { 
    } 


    @Override 
    public boolean isLeafValueSet(LeafIdentifier leaf) { 
        return valueLeafFlags.get(leaf.getLeafIndex()); 
    } 

}


Container

Overview

Container is a holder that can hold many nodes within it. It is used for logically grouping certain set of nodes.

Java mapping 

In java, container acts as a class which can hold information contained within. A class of the container is formed only when container has nodes in it. In addition to that, container's parent holder will have container class’s information.

Container statement is mapped to java as                  

  1. Interface File
    It includes:
    a) Getters for the attributes. 
    b) Builder interface which contains getters/setters and build method.
    c) If container contains a leaf then one LeafIdentifier enum will be generated in interface.

  2. Default implementation Class File
    It includes:
    a) Builder class which is the implementation of builder interface defined in interface file.
    b) Impl class which is the implementation of interface file. 
    c) hashCode(), equals(), toString() methods overridden in it. 
Example
Code Block
titleInput YANG file
File : acme-system.yang
File : acme-system.yang
module acme-system {
     namespace "http://acme.example.com/system";
     prefix "acme";
     organization "ACME Inc.";
     contact "joe@acme.example.com";
     description
        "The module for entities implementing the ACME system.";
     revision 2007-06-09 {
         description "Initial revision.";
     }
     container system {
            leaf host-name {
                type string;
                description "Hostname for this system";
           }
     }
    .
    .
    .
}

 

Code Block
titleGenerated Java files
File: System.java
package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem; 

import java.util.BitSet; 

/** 
 * Abstraction of an entity which represents the functionality of system. 
 */ 
public interface System { 

    /** 
     * Identify the leaf of System. 
     */ 
    public enum LeafIdentifier implements org.onosproject.yang.model.LeafIdentifier{ 
        /** 
         * Represents hostName. 
         */ 
        HOSTNAME(1); 

        private int leafIndex; 

        public int getLeafIndex() { 
            return leafIndex; 
        } 

        LeafIdentifier(int value) { 
            this.leafIndex = value; 
        } 
    } 

    /** 
     * Returns the attribute hostName. 
     * 
     * @return hostName value of hostName 
     */ 
    String hostName(); 

    /** 
     * Returns the attribute valueLeafFlags. 
     * 
     * @return valueLeafFlags value of valueLeafFlags 
     */ 
    BitSet valueLeafFlags(); 

    /** 
     * Sets the attribute hostName. 
     * 
     * @param hostName value of hostName 
     */ 
    void hostName(String hostName); 


    /** 
     * Checks if the leaf value is set. 
     * 
     * @param leaf leaf whose value status needs to checked 
     * @return result of leaf value set in object 
     */ 
    boolean isLeafValueSet(LeafIdentifier leaf); 
}


File : DefaultSystem.java

package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem; 

import com.google.common.base.MoreObjects; 
import java.util.BitSet; 
import java.util.Objects; 
import org.onosproject.yang.model.InnerModelObject; 

/** 
 * Represents the implementation of system. 
 * 
 * <p> 
 * valueLeafFlags identify the leafs whose value are explicitly set 
 * Applicable in protocol edit and query operation. 
 * </p> 
 */ 
public class DefaultSystem extends InnerModelObject implements System { 
    protected String hostName; 
    protected BitSet valueLeafFlags = new BitSet(); 

    @Override 
    public String hostName() { 
        return hostName; 
    } 

    @Override 
    public BitSet valueLeafFlags() { 
        return valueLeafFlags; 
    } 

    @Override 
    public void hostName(String hostName) { 
        valueLeafFlags.set(LeafIdentifier.HOSTNAME.getLeafIndex()); 
        this.hostName = hostName; 
    } 

    @Override 
    public int hashCode() { 
        return Objects.hash(hostName, valueLeafFlags); 
    } 

    @Override 
    public boolean equals(Object obj) { 
        if (this == obj) { 
            return true; 
        } 
        if (obj instanceof DefaultSystem) { 
            DefaultSystem other = (DefaultSystem) obj; 
            return 
                Objects.equals(hostName, other.hostName) && 
                Objects.equals(valueLeafFlags, other.valueLeafFlags); 
        } 
        return false; 
    } 

    @Override 
    public String toString() { 
        return MoreObjects.toStringHelper(getClass()) 
            .omitNullValues() 
            .add("hostName", hostName) 
            .add("valueLeafFlags", valueLeafFlags) 
            .toString(); 
    } 


    /** 
     * Creates an instance of defaultSystem. 
     */ 
    public DefaultSystem() { 
    } 


    @Override 
    public boolean isLeafValueSet(LeafIdentifier leaf) { 
        return valueLeafFlags.get(leaf.getLeafIndex()); 
    } 

}

List

Overview

List is also like container that can hold many nodes by logically grouping. The only difference is, list can have multiple instances whereas container has only one instance.

Java mapping 

    In java, list acts as a class which can hold information contained within. A class of the list is formed only when list has nodes in it. In addition to that, list's parent holder will have list information by creating the list information in java List so that many instances of the class can be stored in it.

   The list statement mapping in java is as same as container for the generation of java (refer container to know what files are generated).

   In the below example the list holder is also a list with the same name. In such cases the complete path is defined for attribute in parent, in order to make sure that they are not referring to themselves. This case is same for any class generating YANG constructs.

Example

Code Block
titleInput YANG file
File : acme-system.yang
module acme-system {
    namespace "http://acme.example.com/system";
    prefix "acme";
    organization "ACME Inc.";
    contact "joe@acme.example.com";
    description
        "The module for entities implementing the ACME system.";
    revision 2007-06-09 {
        description "Initial revision.";
    }
    list login {
        key "name";
        list login {
            key "name";
            leaf name {
                type string;
            }
            leaf full-name {
                type string;
            }
            leaf class {
                type string;
            }
        }
        leaf name {
            type string;
        }
    }
    .
    .
    .
}
Code Block
titleGenerated Java files
Note: Qualified name is used for child node "login".  
 
File : Login.java
package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem; 

import java.util.BitSet; 
import java.util.List; 

/** 
 * Abstraction of an entity which represents the functionality of login. 
 */ 
public interface Login { 

    /** 
     * Identify the leaf of Login. 
     */ 
    public enum LeafIdentifier implements org.onosproject.yang.model.LeafIdentifier{ 
        /** 
         * Represents name. 
         */ 
        NAME(1); 

        private int leafIndex; 

        public int getLeafIndex() { 
            return leafIndex; 
        } 

        LeafIdentifier(int value) { 
            this.leafIndex = value; 
        } 
    } 

    /** 
     * Returns the attribute name. 
     * 
     * @return name value of name 
     */ 
    String name(); 

    /** 
     * Returns the attribute valueLeafFlags. 
     * 
     * @return valueLeafFlags value of valueLeafFlags 
     */ 
    BitSet valueLeafFlags(); 

    /** 
     * Returns the attribute login. 
     * 
     * @return login list of login 
     */ 
    List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login.Login> login(); 

    /** 
     * Sets the attribute name. 
     * 
     * @param name value of name 
     */ 
    void name(String name); 

    /** 
     * Sets the attribute login. 
     * 
     * @param login list of login 
     */ 
    void login(List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login 
            .Login> login); 

    /** 
     * Adds to the list of login. 
     * 
     * @param addTo value of login 
     */ 
    void addToLogin(org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login 
            .Login addTo); 


    /** 
     * Checks if the leaf value is set. 
     * 
     * @param leaf leaf whose value status needs to checked 
     * @return result of leaf value set in object 
     */ 
    boolean isLeafValueSet(LeafIdentifier leaf); 
}

File : DefaultLogin.java

package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem; 

import com.google.common.base.MoreObjects; 
import java.util.ArrayList; 
import java.util.BitSet; 
import java.util.List; 
import java.util.Objects; 
import org.onosproject.yang.model.InnerModelObject; 
import org.onosproject.yang.model.MultiInstanceObject; 

/** 
 * Represents the implementation of login. 
 * 
 * <p> 
 * valueLeafFlags identify the leafs whose value are explicitly set 
 * Applicable in protocol edit and query operation. 
 * </p> 
 */ 
public class DefaultLogin extends InnerModelObject 
        implements Login, MultiInstanceObject<LoginKeys> { 
    protected String name; 
    protected BitSet valueLeafFlags = new BitSet(); 
    protected List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login 
            .Login> login; 

    @Override 
    public String name() { 
        return name; 
    } 

    @Override 
    public BitSet valueLeafFlags() { 
        return valueLeafFlags; 
    } 

    @Override 
    public List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem 
            .login.Login> login() { 
        return login; 
    } 

    @Override 
    public void name(String name) { 
        valueLeafFlags.set(LeafIdentifier.NAME.getLeafIndex()); 
        this.name = name; 
    } 

    @Override 
    public void login(List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem 
            .login.Login> login) { 
        this.login = login; 
    } 

    @Override 
    public void addToLogin(org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem 
            .login.Login addTo) { 
        if (login == null) { 
            login = new ArrayList<>(); 
        } 
        login.add(addTo); 
    } 


    @Override 
    public int hashCode() { 
        return Objects.hash(name, valueLeafFlags, login); 
    } 

    @Override 
    public boolean equals(Object obj) { 
        if (this == obj) { 
            return true; 
        } 
        if (obj instanceof DefaultLogin) { 
            DefaultLogin other = (DefaultLogin) obj; 
            return 
                Objects.equals(name, other.name) && 
                Objects.equals(valueLeafFlags, other.valueLeafFlags) && 
                Objects.equals(login, other.login); 
        } 
        return false; 
    } 

    @Override 
    public String toString() { 
        return MoreObjects.toStringHelper(getClass()) 
            .omitNullValues() 
            .add("name", name) 
            .add("valueLeafFlags", valueLeafFlags) 
            .add("login", login) 
            .toString(); 
    } 


    /** 
     * Creates an instance of defaultLogin. 
     */ 
    public DefaultLogin() { 
    } 


    @Override 
    public boolean isLeafValueSet(LeafIdentifier leaf) { 
        return valueLeafFlags.get(leaf.getLeafIndex()); 
    } 

}
 
 
File : LoginKeys.java

package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem;
import java.lang.String;
import org.onosproject.yang.model.KeyInfo;
import java.util.Objects;
/**
 * Represents the implementation of login.
 */
public class LoginKeys implements KeyInfo<DefaultLogin> {
    protected String name;
    /**
     * Returns the attribute name.
     *
     * @return name value of name
     */
    public String name() {
        return name;
    }
    /**
     * Sets the value to attribute name.
     *
     * @param name value of name
     */
    public void name(String name) {
        this.name = name;
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof LoginKeys) {
            LoginKeys other = (LoginKeys) obj;
            return
                Objects.equals(name, other.name);
        }
        return false;
    }
}


 

Grouping and uses

Overview

Grouping the nodes together, for reusing them at many places, can be done in YANG. Grouping the nodes is done by grouping statement and using those grouped nodes at different places is done by uses statement.

Java mapping

During YANG to java conversion, the contents of grouping is copied wherever uses statement is used and code will be generated for nodes inside grouping's generated package. 

Note: if a yang file only contains grouping then for that module no service interface will be generated. one interface will be generated but there will not be any OpParam file for module. For other nodes code generation will be same.

Example
Code Block
titleInput YANG file
module Test {
    namespace "http://test.example.com/";
    prefix "test";
    organization "ACME Inc.";
    grouping endpoint { 
        leaf address {
            type int32; 
        } 
        leaf port {
            type int8; 
        }
    }
    container connection { 
        container source {
            uses endpoint;
        }
        container destination {
            uses endpoint;
        }
    }
    .
    .
    .
}
Code Block
titleGenerated Java files
File : Connection.java
package org.onosproject.yang.gen.v1.http.test.example.com.test; 

import org.onosproject.yang.gen.v1.http.test.example.com.test.connection.Destination; 
import org.onosproject.yang.gen.v1.http.test.example.com.test.connection.Source; 

/** 
 * Abstraction of an entity which represents the functionality of connection. 
 */ 
public interface Connection { 

    /** 
     * Returns the attribute source. 
     * 
     * @return source value of source 
     */ 
    Source source(); 

    /** 
     * Returns the attribute destination. 
     * 
     * @return destination value of destination 
     */ 
    Destination destination(); 

    /** 
     * Sets the attribute source. 
     * 
     * @param source value of source 
     */ 
    void source(Source source); 

    /** 
     * Sets the attribute destination. 
     * 
     * @param destination value of destination 
     */ 
    void destination(Destination destination); 

}


Choice and case 

Overview

The choice statement defines a set of alternatives, only one of which may exist at any one time. The argument is an identifier, followed by a block of sub-statements that holds detailed choice information.

A choice consists of a number of branches, defined with the “case” substatement. Each branch contains a number of child nodes. The nodes from at most one of the choice's branches exist at the same time.
The case statement is used to define branches of the choice. It takes identifier as an argument, followed by a block of sub-statements that holds detailed case information.

JAVA mapping

Choice is mapped to interface(marker interface).

Case statement are mapped to the JAVA interfaces 

It includes

  1. Interface file which extends choice marker interface

  2. Builder class which implements the builder interface and impl class which implements the interface

  3. Impl class includes overridden methods, hashcode, equals, toString methods.
Example
Code Block
titleInput YANG file
File : link.yang
module link {
    yang-version 1;
    namespace http://huawei.com;
    prefix Ant;
    container link {
        choice interfaceType {
            case ethernerType {
                leaf ethernet { type string; }
            }
            case p2pType {
               leaf p2p { type string; }
            }
        }
     }
}
Code Block
titleGenerated Java files
File : InterfaceType.java

package org.onosproject.yang.gen.v1.http.huawei.com.link.link; 

/** 
 * Abstraction of an entity which represents the functionality of interfaceType. 
 */ 
public interface InterfaceType { 
}


File : EthernerType.java
package org.onosproject.yang.gen.v1.http.huawei.com.link.link.interfacetype; 

import java.util.BitSet; 
import org.onosproject.yang.gen.v1.http.huawei.com.link.link.InterfaceType; 

/** 
 * Abstraction of an entity which represents the functionality of ethernerType. 
 */ 
public interface EthernerType extends InterfaceType  { 

    /** 
     * Identify the leaf of EthernerType. 
     */ 
    public enum LeafIdentifier implements org.onosproject.yang.model.LeafIdentifier{ 
        /** 
         * Represents ethernet. 
         */ 
        ETHERNET(1); 

        private int leafIndex; 

        public int getLeafIndex() { 
            return leafIndex; 
        } 

        LeafIdentifier(int value) { 
            this.leafIndex = value; 
        } 
    } 

    /** 
     * Returns the attribute ethernet. 
     * 
     * @return ethernet value of ethernet 
     */ 
    String ethernet(); 

    /** 
     * Returns the attribute valueLeafFlags. 
     * 
     * @return valueLeafFlags value of valueLeafFlags 
     */ 
    BitSet valueLeafFlags(); 

    /** 
     * Sets the attribute ethernet. 
     * 
     * @param ethernet value of ethernet 
     */ 
    void ethernet(String ethernet); 


    /** 
     * Checks if the leaf value is set. 
     * 
     * @param leaf leaf whose value status needs to checked 
     * @return result of leaf value set in object 
     */ 
    boolean isLeafValueSet(LeafIdentifier leaf); 
}



File : DefaultEthernerType.java
package org.onosproject.yang.gen.v1.http.huawei.com.link.link.interfacetype; 

import com.google.common.base.MoreObjects; 
import java.util.BitSet; 
import java.util.Objects; 
import org.onosproject.yang.gen.v1.http.huawei.com.link.link.InterfaceType; 
import org.onosproject.yang.model.InnerModelObject; 

/** 
 * Represents the implementation of ethernerType. 
 * 
 * <p> 
 * valueLeafFlags identify the leafs whose value are explicitly set 
 * Applicable in protocol edit and query operation. 
 * </p> 
 */ 
public class DefaultEthernerType extends InnerModelObject implements EthernerType { 
    protected String ethernet; 
    protected BitSet valueLeafFlags = new BitSet(); 

    @Override 
    public String ethernet() { 
        return ethernet; 
    } 

    @Override 
    public BitSet valueLeafFlags() { 
        return valueLeafFlags; 
    } 

    @Override 
    public void ethernet(String ethernet) { 
        valueLeafFlags.set(LeafIdentifier.ETHERNET.getLeafIndex()); 
        this.ethernet = ethernet; 
    } 

    @Override 
    public int hashCode() { 
        return Objects.hash(ethernet, valueLeafFlags); 
    } 

    @Override 
    public boolean equals(Object obj) { 
        if (this == obj) { 
            return true; 
        } 
        if (obj instanceof DefaultEthernerType) { 
            DefaultEthernerType other = (DefaultEthernerType) obj; 
            return 
                Objects.equals(ethernet, other.ethernet) && 
                Objects.equals(valueLeafFlags, other.valueLeafFlags); 
        } 
        return false; 
    } 

    @Override 
    public String toString() { 
        return MoreObjects.toStringHelper(getClass()) 
            .omitNullValues() 
            .add("ethernet", ethernet) 
            .add("valueLeafFlags", valueLeafFlags) 
            .toString(); 
    } 


    /** 
     * Creates an instance of defaultEthernerType. 
     */ 
    public DefaultEthernerType() { 
    } 


    @Override 
    public boolean isLeafValueSet(LeafIdentifier leaf) { 
        return valueLeafFlags.get(leaf.getLeafIndex()); 
    } 

}


RPC

Overview

RPCs are modeled with RPC statement. The input statement is used to define input parameters to the RPC and output statement is used to define output parameters to the RPC.

JAVA mapping

Rpc statement is mapped to a method in module manager class and service interface.

The generated method will depends on the sub statements input and output. Input and Output will have there own java classes and RPC method will contain Output class's object as return type and Input class's object will be input for the method. If no output node is present , return type will be "void". Same way if no input is present , there will be no input parameter for the method.

Rpc node is an non operation type node so all the nodes under it will not contain operationType, processSubTreeFiltereing, select leaf flags in their generated code.

Example
Code Block
titleInput YANG file
File: sfc.yang
module Sfc {
    yang-version 1;
    namespace http://huawei.com;
    prefix Ant;
    rpc SFP {
        input {
            leaf port {
                type string;
            }
          }
          output {
            leaf path {
                type string;
            }
          }
    }
}
Code Block
titleGenerated Java files
File : SfcService.java
package org.onosproject.yang.gen.v1.http.huawei.com; 

import org.onosproject.yang.gen.v1.http.huawei.com.sfc.sfp.SfpInput; 
import org.onosproject.yang.gen.v1.http.huawei.com.sfc.sfp.SfpOutput; 

/** 
 * Abstraction of an entity which represents the functionality of sfc. 
 */ 
public interface SfcService { 
    /** 
     * Service interface of sfp. 
     * 
     * @param inputVar input of service interface sfp 
     * @return sfpOutput output of service interface sfp 
     */ 
    SfpOutput sfp(SfpInput inputVar); 

}

File : SfpInput.java
package org.onosproject.yang.gen.v1.http.huawei.com.sfc.sfp; 

import java.util.BitSet; 

/** 
 * Abstraction of an entity which represents the functionality of sfpInput. 
 */ 
public interface SfpInput { 

    /** 
     * Identify the leaf of SfpInput. 
     */ 
    public enum LeafIdentifier implements org.onosproject.yang.model.LeafIdentifier{ 
        /** 
         * Represents port. 
         */ 
        PORT(1); 

        private int leafIndex; 

        public int getLeafIndex() { 
            return leafIndex; 
        } 

        LeafIdentifier(int value) { 
            this.leafIndex = value; 
        } 
    } 

    /** 
     * Returns the attribute port. 
     * 
     * @return port value of port 
     */ 
    String port(); 

    /** 
     * Returns the attribute valueLeafFlags. 
     * 
     * @return valueLeafFlags value of valueLeafFlags 
     */ 
    BitSet valueLeafFlags(); 

    /** 
     * Sets the attribute port. 
     * 
     * @param port value of port 
     */ 
    void port(String port); 


    /** 
     * Checks if the leaf value is set. 
     * 
     * @param leaf leaf whose value status needs to checked 
     * @return result of leaf value set in object 
     */ 
    boolean isLeafValueSet(LeafIdentifier leaf); 
}


File : DefaultSfpInput.java
package org.onosproject.yang.gen.v1.http.huawei.com.sfc.sfp; 

import com.google.common.base.MoreObjects; 
import java.util.BitSet; 
import java.util.Objects; 
import org.onosproject.yang.model.InnerModelObject; 

/** 
 * Represents the implementation of sfpInput. 
 */ 
public class DefaultSfpInput extends InnerModelObject implements SfpInput { 
    protected String port; 
    protected BitSet valueLeafFlags = new BitSet(); 

    @Override 
    public String port() { 
        return port; 
    } 

    @Override 
    public BitSet valueLeafFlags() { 
        return valueLeafFlags; 
    } 

    @Override 
    public void port(String port) { 
        valueLeafFlags.set(LeafIdentifier.PORT.getLeafIndex()); 
        this.port = port; 
    } 

    @Override 
    public int hashCode() { 
        return Objects.hash(port, valueLeafFlags); 
    } 

    @Override 
    public boolean equals(Object obj) { 
        if (this == obj) { 
            return true; 
        } 
        if (obj instanceof DefaultSfpInput) { 
            DefaultSfpInput other = (DefaultSfpInput) obj; 
            return 
                Objects.equals(port, other.port) && 
                Objects.equals(valueLeafFlags, other.valueLeafFlags); 
        } 
        return false; 
    } 

    @Override 
    public String toString() { 
        return MoreObjects.toStringHelper(getClass()) 
            .omitNullValues() 
            .add("port", port) 
            .add("valueLeafFlags", valueLeafFlags) 
            .toString(); 
    } 


    /** 
     * Creates an instance of defaultSfpInput. 
     */ 
    public DefaultSfpInput() { 
    } 


    @Override 
    public boolean isLeafValueSet(LeafIdentifier leaf) { 
        return valueLeafFlags.get(leaf.getLeafIndex()); 
    } 

}


File : Sfpoutput.java

package org.onosproject.yang.gen.v1.http.huawei.com.sfc.sfp; 

import java.util.BitSet; 

/** 
 * Abstraction of an entity which represents the functionality of sfpOutput. 
 */ 
public interface SfpOutput { 

    /** 
     * Identify the leaf of SfpOutput. 
     */ 
    public enum LeafIdentifier implements org.onosproject.yang.model.LeafIdentifier{ 
        /** 
         * Represents path. 
         */ 
        PATH(1); 

        private int leafIndex; 

        public int getLeafIndex() { 
            return leafIndex; 
        } 

        LeafIdentifier(int value) { 
            this.leafIndex = value; 
        } 
    } 

    /** 
     * Returns the attribute path. 
     * 
     * @return path value of path 
     */ 
    String path(); 

    /** 
     * Returns the attribute valueLeafFlags. 
     * 
     * @return valueLeafFlags value of valueLeafFlags 
     */ 
    BitSet valueLeafFlags(); 

    /** 
     * Sets the attribute path. 
     * 
     * @param path value of path 
     */ 
    void path(String path); 


    /** 
     * Checks if the leaf value is set. 
     * 
     * @param leaf leaf whose value status needs to checked 
     * @return result of leaf value set in object 
     */ 
    boolean isLeafValueSet(LeafIdentifier leaf); 
}


File : DefaultSfpOutput.java

package org.onosproject.yang.gen.v1.http.huawei.com.sfc.sfp; 

import com.google.common.base.MoreObjects; 
import java.util.BitSet; 
import java.util.Objects; 
import org.onosproject.yang.model.InnerModelObject; 

/** 
 * Represents the implementation of sfpOutput. 
 */ 
public class DefaultSfpOutput extends InnerModelObject implements SfpOutput { 
    protected String path; 
    protected BitSet valueLeafFlags = new BitSet(); 

    @Override 
    public String path() { 
        return path; 
    } 

    @Override 
    public BitSet valueLeafFlags() { 
        return valueLeafFlags; 
    } 

    @Override 
    public void path(String path) { 
        valueLeafFlags.set(LeafIdentifier.PATH.getLeafIndex()); 
        this.path = path; 
    } 

    @Override 
    public int hashCode() { 
        return Objects.hash(path, valueLeafFlags); 
    } 

    @Override 
    public boolean equals(Object obj) { 
        if (this == obj) { 
            return true; 
        } 
        if (obj instanceof DefaultSfpOutput) { 
            DefaultSfpOutput other = (DefaultSfpOutput) obj; 
            return 
                Objects.equals(path, other.path) && 
                Objects.equals(valueLeafFlags, other.valueLeafFlags); 
        } 
        return false; 
    } 

    @Override 
    public String toString() { 
        return MoreObjects.toStringHelper(getClass()) 
            .omitNullValues() 
            .add("path", path) 
            .add("valueLeafFlags", valueLeafFlags) 
            .toString(); 
    } 


    /** 
     * Creates an instance of defaultSfpOutput. 
     */ 
    public DefaultSfpOutput() { 
    } 


    @Override 
    public boolean isLeafValueSet(LeafIdentifier leaf) { 
        return valueLeafFlags.get(leaf.getLeafIndex()); 
    } 

}
 
 
File : DefaultRpcHandler.java
 
package org.onosproject.yang.gen.v1.http.huawei.com;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.onosproject.config.RpcHandler;
import org.onosproject.config.RpcCommand;
import org.onosproject.config.RpcInput;
/**
 * Represents the implementation of RPC handler.
 */
public class DefaultRpcHandler implements RpcHandler {
    private ExecutorService executor;
    @Override
    public void executeRpc(Integer msgId, RpcCommand cmd, RpcInput input) {
        executor = Executors.newSingleThreadExecutor();
        executor.execute(new RpcExecuter(msgId, (RpcExtendedCommand) cmd, input));
    }
    /**
     * Runnable capable of invoking the appropriate RPC command's execute method.
     */
    public class RpcExecuter implements Runnable {
        Integer msgId;
        RpcExtendedCommand cmd;
        RpcInput input;
        /**
         * Constructs a RPC executor for the given msg id, RPC command and
         * RPC input.
         *
         * @param msgId msgId of the RPC message to be executed
         * @param cmd RPC command to be executed
         * @param input input data to the RPC command
         */
        public RpcExecuter(Integer msgId, RpcExtendedCommand cmd, RpcInput input) {
            this.msgId = msgId;
            this.cmd = cmd;
            this.input = input;
        }
        @Override
        public void run() {
            cmd.execute(input, msgId);
        }
    }
}
 
 
File : RegisterRpc.java
 
package org.onosproject.yang.gen.v1.http.huawei.com;
import org.onosproject.yang.gen.v1.http.huawei.com.sfc.SfpCommand;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.config.RpcCommand;
import org.onosproject.config.RpcHandler;
import org.onosproject.config.DynamicConfigService;
import org.onosproject.yang.model.ModelConverter;
/**
 * Represents the implementation of register RPC.
 */
public class RegisterRpc {
    private List<RpcCommand> rpcCommands;
    private RpcHandler rpcHandler;
    private DynamicConfigService storeService;
    private ModelConverter modelConverter;
    private SfcService sfcService;
    /**
     * Constructs a register rpc for the given store service, mode converter and
     * application service.
     *
     * @param store dynamic config service
     * @param modelConverter model converter for convertion
     * @param allService application service
     */
    public RegisterRpc(DynamicConfigService store, ModelConverter modelConverter, SfcService sfcService) {
        this.rpcCommands = new LinkedList<RpcCommand>();
        this.rpcHandler = new DefaultRpcHandler();
        this.storeService = store;
        this.modelConverter = modelConverter;
        this.sfcService = sfcService;
    }
    /**
     * Registers RPC handler with dynamic config service.
     */
    public void registerRpc() {
        createRpcCommands();
        for (RpcCommand rpcCommand : rpcCommands) {
            storeService.registerHandler(rpcHandler, rpcCommand);
        }
    }
    /**
     * Creates RPC command for all the RPC.
     */
    public void createRpcCommands() {
        RpcCommand sfp = new SfpCommand(storeService, modelConverter, sfcService);
        rpcCommands.add(sfp);
    }
}
 
 
File : RpcExtendedCommand.java
 
package org.onosproject.yang.gen.v1.http.huawei.com;
import org.onosproject.yang.model.ResourceId;
import org.onosproject.config.RpcInput;
import org.onosproject.config.RpcCommand;
/**
 * Abstract implementation of an RPC extended command.
 */
public abstract class RpcExtendedCommand extends RpcCommand {
    /**
     * Creates an instance of RPC extended command.
     *
     * @param cmdId of RPC command
     */
    public RpcExtendedCommand(ResourceId cmdId) {
        super(cmdId);
    }
    /**
     * Executes the RPC command.
     *
     * @param input input data to the RPC command
     * @param msgId of the RPC message to be executed
     */
    public abstract void execute(RpcInput rpcInput, int msgId);
}
 
 
File : SfpCommand.java
 
package org.onosproject.yang.gen.v1.http.huawei.com.sfc;
import org.onosproject.yang.gen.v1.http.huawei.com.RpcExtendedCommand;
import org.onosproject.yang.gen.v1.http.huawei.com.SfcService;
import org.onosproject.yang.gen.v1.http.huawei.com.sfc.sfp.DefaultSfpOutput;
import org.onosproject.yang.gen.v1.http.huawei.com.sfc.sfp.SfpInput;
import org.onosproject.yang.model.ModelConverter;
import org.onosproject.yang.model.ResourceId;
import org.onosproject.config.RpcInput;
import org.onosproject.config.RpcOutput;
import org.onosproject.config.DynamicConfigService;
import org.onosproject.yang.model.ResourceData;
import org.onosproject.yang.model.ModelObjectData;
import org.onosproject.yang.runtime.DefaultResourceData;
import org.onosproject.yang.model.DefaultModelObjectData;
import static org.onosproject.config.RpcOutput.Status.RPC_SUCCESS;
/**
 * Represents the implementation of sfp.
 */
public class SfpCommand extends RpcExtendedCommand {
    private ModelConverter modelConverter;
    private SfcService sfcService;
    private DynamicConfigService storeService;
    /**
     * Constructs a sfp command for the given cmd id, model converter,
     * application service.
     *
     * @param cmdId identifier of RPC command
     * @param modelConverter model converter for convertion
     * @param allService application service
     */
    public SfpCommand(DynamicConfigService store, ModelConverter modelConverter, SfcService sfcService) {
        super(getResourceId());
        this.storeService = store;
        this.modelConverter = modelConverter;
        this.sfcService = sfcService;
    }
    @Override
    public void execute(RpcInput rpcInput) {
    }
    /**
     * Executes the RPC command.
     *
     * @param rpcInput input data to the RPC command
     * @param msgId msgId of the RPC message to be executed
     */
    public void execute(RpcInput rpcInput, int msgId) {
        ResourceData inputData = DefaultResourceData.builder()
                .resourceId(getResourceId())
                .addDataNode(rpcInput.input()).build();
        ModelObjectData inputMo = modelConverter.createModel(inputData);
        SfpInput inputObject = ((SfpInput) inputMo.modelObjects().get(0));
        DefaultSfpOutput outputObject = (DefaultSfpOutput) sfcService.sfp(inputObject);
        ModelObjectData outputMo = DefaultModelObjectData.builder()
                .addModelObject(outputObject).build();
        ResourceData outputData = modelConverter.createDataNode(outputMo);
        RpcOutput output = new RpcOutput(RPC_SUCCESS, outputData.dataNodes().get(0));
        storeService.rpcResponse(msgId, output);
    }
    private static ResourceId getResourceId() {
        return new ResourceId.Builder().addBranchPointSchema("/", null)
                .addBranchPointSchema("SFP", "http://huawei.com").build();
    }
}

Notification 

Overview

The "notification" statement is used to define a notification.  It takes one argument, which is an identifier, followed by a block of substatements that holds detailed notification information.

JAVA mapping

Notification is mapped to events and event listeners in ONOS. Events are used by Managers to notify its listeners about changes in the network or topology etc, and by Stores to notify their peers of events in a distributed setting. An Event is comprised of a event type and a subject built of model objects.

When notification statement is present in YANG, an event class , event subject class, event listener interface and notification interface  and builder will be generated.

When multiple notifications are present event class include the an enum with types of events for all notification  like DEVICE_ADDED, DEVICE_REMOVED and it extends AbstractEvent with event type and event subject class. It is used to notify EventListeners about the event.

xxxEvent Subject class will have all the objects of events for multiple notifications and getters and setters for the events.

xxxEvent Listener is interface which extends EventListener.

Notification is an non operation type node so all the nodes under it will not contains operation type, process sub tree filtering and select leaf flag in generated code.

Example
Code Block
titleInput YANG files
File : ospf.yang
module ospf {
    namespace "http://example.com/ospf";
    prefix "ospf";

    notification test {
           leaf event-class {
              type string;
           }
           leaf severity {
              type string;
           }
    }
}
Code Block
titleGenerated Java files
File : OspfService.java

package org.onosproject.yang.gen.v1.http.example.com.ospf; 

import org.onosproject.event.ListenerService; 
import org.onosproject.yang.gen.v1.http.example.com.ospf.ospf.OspfEvent; 
import org.onosproject.yang.gen.v1.http.example.com.ospf.ospf.OspfEventListener; 

/** 
 * Abstraction of an entity which represents the functionality of ospf. 
 */ 
public interface OspfService extends ListenerService<OspfEvent, OspfEventListener> { 
}


File : OspfEvent.java

package org.onosproject.yang.gen.v1.http.example.com.ospf.ospf; 

import org.onosproject.event.AbstractEvent; 

/** 
 * Represents event implementation of ospf. 
 */ 
public class OspfEvent extends AbstractEvent<OspfEvent.Type, OspfEventSubject> { 

    public enum Type { 

        /** 
         * Represents test. 
         */ 
        TEST 
    } 

    /** 
     * Creates OspfEventSubject event with type and subject. 
     * 
     * @param type event type 
     * @param subject subject OspfEventSubject 
     */ 
    public OspfEvent(Type type, OspfEventSubject subject) { 
        super(type, subject); 
    } 

    /** 
     * Creates OspfEventSubject event with type, subject and time. 
     * 
     * @param type event type 
     * @param subject subject OspfEventSubject 
     * @param time time of event 
     */ 
    public OspfEvent(Type type, OspfEventSubject subject, long time) { 
        super(type, subject, time); 
    } 

}


File : OspfEventSubject.java

package org.onosproject.yang.gen.v1.http.example.com.ospf.ospf; 
/** 
 * Represents the implementation of ospf. 
 */ 
public class OspfEventSubject { 

    protected Test test; 
    /** 
     * Returns the attribute test. 
     * 
     * @return test value of test 
     */ 
    public Test test() { 
        return test; 
    } 

    /** 
     * Sets the value to attribute test. 
     * 
     * @param test value of test 
     */ 
    public void test(Test test) { 
        this.test = test; 
    } 

}


File : OspfEventListener.java

package org.onosproject.yang.gen.v1.http.example.com.ospf.ospf; 

import org.onosproject.event.EventListener; 

/** 
 * Abstraction for event listener of ospf. 
 */ 
public interface OspfEventListener extends EventListener<OspfEvent> { 
}


File : Test.java

package org.onosproject.yang.gen.v1.http.example.com.ospf.ospf; 

import java.util.BitSet; 

/** 
 * Abstraction of an entity which represents the functionality of test. 
 */ 
public interface Test { 

    /** 
     * Identify the leaf of Test. 
     */ 
    public enum LeafIdentifier implements org.onosproject.yang.model.LeafIdentifier{ 
        /** 
         * Represents eventClass. 
         */ 
        EVENTCLASS(1), 
        /** 
         * Represents severity. 
         */ 
        SEVERITY(2); 

        private int leafIndex; 

        public int getLeafIndex() { 
            return leafIndex; 
        } 
 
        LeafIdentifier(int value) { 
            this.leafIndex = value; 
        } 
    } 

    /** 
     * Returns the attribute eventClass. 
     * 
     * @return eventClass value of eventClass 
     */ 
    String eventClass(); 

    /** 
     * Returns the attribute severity. 
     * 
     * @return severity value of severity 
     */ 
    String severity(); 

    /** 
     * Returns the attribute valueLeafFlags. 
     * 
     * @return valueLeafFlags value of valueLeafFlags 
     */ 
    BitSet valueLeafFlags(); 

    /** 
     * Sets the attribute eventClass. 
     * 
     * @param eventClass value of eventClass 
     */ 
    void eventClass(String eventClass); 

    /** 
     * Sets the attribute severity. 
     * 
     * @param severity value of severity 
     */ 
    void severity(String severity); 


    /** 
     * Checks if the leaf value is set. 
     * 
     * @param leaf leaf whose value status needs to checked 
     * @return result of leaf value set in object 
     */ 
    boolean isLeafValueSet(LeafIdentifier leaf); 
}


File : DefaultTest.java

package org.onosproject.yang.gen.v1.http.example.com.ospf.ospf; 

import com.google.common.base.MoreObjects; 
import java.util.BitSet; 
import java.util.Objects; 
import org.onosproject.yang.model.InnerModelObject; 

/** 
 * Represents the implementation of test. 
 */ 
public class DefaultTest extends InnerModelObject implements Test { 
    protected String eventClass; 
    protected String severity; 
    protected BitSet valueLeafFlags = new BitSet(); 

    @Override 
    public String eventClass() { 
        return eventClass; 
    } 

    @Override 
    public String severity() { 
        return severity; 
    } 

    @Override 
    public BitSet valueLeafFlags() { 
        return valueLeafFlags; 
    } 

    @Override 
    public void eventClass(String eventClass) { 
        valueLeafFlags.set(LeafIdentifier.EVENTCLASS.getLeafIndex()); 
        this.eventClass = eventClass; 
    } 

    @Override 
    public void severity(String severity) { 
        valueLeafFlags.set(LeafIdentifier.SEVERITY.getLeafIndex()); 
        this.severity = severity; 
    } 

    @Override 
    public int hashCode() { 
        return Objects.hash(eventClass, severity, valueLeafFlags); 
    } 

    @Override 
    public boolean equals(Object obj) { 
        if (this == obj) { 
            return true; 
        } 
        if (obj instanceof DefaultTest) { 
            DefaultTest other = (DefaultTest) obj; 
            return 
                Objects.equals(eventClass, other.eventClass) && 
                Objects.equals(severity, other.severity) && 
                Objects.equals(valueLeafFlags, other.valueLeafFlags); 
        } 
        return false; 
    } 

    @Override 
    public String toString() { 
        return MoreObjects.toStringHelper(getClass()) 
            .omitNullValues() 
            .add("eventClass", eventClass) 
            .add("severity", severity) 
            .add("valueLeafFlags", valueLeafFlags) 
            .toString(); 
    } 


    /** 
     * Creates an instance of defaultTest. 
     */ 
    public DefaultTest() { 
    } 


    @Override 
    public boolean isLeafValueSet(LeafIdentifier leaf) { 
        return valueLeafFlags.get(leaf.getLeafIndex()); 
    } 

}

Augment

Overview

Augment means “make (something) greater by adding to it; increase.” in YANG augment adds some information in target node. Here in YANG, container, list, choice, case, input, output, or notification node can come as a target node.

As the child node of augment node only "container", "leaf", "list", "leaf-list", "uses", and "choice" can come. If augment comes under a module or submodule.

If a target node is a choice node the "case" statement, or a case shorthand statement can be come as a child node of augment node.

If a target node is from some other YANG file than a mandatory node which is is one of:

  • A leaf, choice, or anyxml node with a "mandatory" statement with   the value "true".

  • A list or leaf-list node with a "min-elements" statement with a value greater than zero.

  • A container node without a "presence" statement, which has at least one mandatory node as a child.

should not come as a child node of augment node.

Info

 A augment node can't add the same augmented info to an augmented node multiple times.

Java mapping

For a given augment node in the YANG file one interface file and one builder class file will be generated. Generated files will be having attributes, getters and setters for augment node's child nodes and leaf or leaf-list.

For augment we have given one interface named as "YangAugmentedInfo” as part of YANG tools plugin.

File generated for augment node will be implementing AugmentedInfo class.

Node in data model tree which can be augmented as per the YANG rules for them we have given 3 methods , which are :


 public void addAugmentedInfo(YangAugmentedInfo value, Class classObject) {
        yangAugmentedInfoMap.put(classObject, value);
    }

    public YangAugmentedInfo getAugmentedInfo(Class classObject) {
        return yangAugmentedInfoMap.get(classObject);
    }

    public Map<Class<?>, YangAugmentedInfo> getYangAugmentedInfoMap() {
        return yangAugmentedInfoMap;
    }

these methods will be providing augmentation functionalities for augmentable nodes. These class will be storing augmentedInfo , which is nothing but a augment node which are augmenting this node. Also we have provides one code snippet in OpParam file which checks if augmented info is set or not in IsFilterMatchMethod().

OpParam file will extend "YangAugmentedOpParamInfo" interface provides by Yangtools.

Example
Code Block
titleInput YANG file
File : Test.yang
module Test {
     yang-version 1;
     namespace "http://huawei.com";
     prefix Ant;
     description "Interval before a route is declared invalid";

     container interface {
          leaf ifType {
                type string;
          }
     }

     augment "/interface" {
          leaf ds0ChannelNumber {
               type int16;
         }
    }
}
Code Block
titleGenerated Java files
 
File : AugmentedInterface.java

package org.onosproject.yang.gen.v1.http.huawei.com.test.yangautoprefixinterface; 

import java.util.BitSet; 

/** 
 * Abstraction of an entity which represents the functionality of augmentedInterface. 
 */ 
public interface AugmentedInterface { 

    /** 
     * Identify the leaf of AugmentedInterface. 
     */ 
    public enum LeafIdentifier implements org.onosproject.yang.model.LeafIdentifier{ 
        /** 
         * Represents ds0ChannelNumber. 
         */ 
        DS0CHANNELNUMBER(1); 

        private int leafIndex; 

        public int getLeafIndex() { 
            return leafIndex; 
        } 

        LeafIdentifier(int value) { 
            this.leafIndex = value; 
        } 
    } 

    /** 
     * Returns the attribute ds0ChannelNumber. 
     * 
     * @return ds0ChannelNumber value of ds0ChannelNumber 
     */ 
    short ds0ChannelNumber(); 

    /** 
     * Returns the attribute valueLeafFlags. 
     * 
     * @return valueLeafFlags value of valueLeafFlags 
     */ 
    BitSet valueLeafFlags(); 

    /** 
     * Sets the attribute ds0ChannelNumber. 
     * 
     * @param ds0ChannelNumber value of ds0ChannelNumber 
     */ 
    void ds0ChannelNumber(short ds0ChannelNumber); 


    /** 
     * Checks if the leaf value is set. 
     * 
     * @param leaf leaf whose value status needs to checked 
     * @return result of leaf value set in object 
     */ 
    boolean isLeafValueSet(LeafIdentifier leaf); 
}


File : DefaultAugmentedInterface.java
package org.onosproject.yang.gen.v1.http.huawei.com.test.yangautoprefixinterface; 

import com.google.common.base.MoreObjects; 
import java.util.BitSet; 
import java.util.Objects; 
import org.onosproject.yang.model.InnerModelObject; 

/** 
 * Represents the implementation of augmentedInterface. 
 * 
 * <p> 
 * valueLeafFlags identify the leafs whose value are explicitly set 
 * Applicable in protocol edit and query operation. 
 * </p> 
 */ 
public class DefaultAugmentedInterface extends InnerModelObject implements AugmentedInterface { 
    protected short ds0ChannelNumber; 
    protected BitSet valueLeafFlags = new BitSet(); 

    @Override 
    public short ds0ChannelNumber() { 
        return ds0ChannelNumber; 
    } 

    @Override 
    public BitSet valueLeafFlags() { 
        return valueLeafFlags; 
    } 

    @Override 
    public void ds0ChannelNumber(short ds0ChannelNumber) { 
        valueLeafFlags.set(LeafIdentifier.DS0CHANNELNUMBER.getLeafIndex()); 
        this.ds0ChannelNumber = ds0ChannelNumber; 
    } 

    @Override 
    public int hashCode() { 
        return Objects.hash(ds0ChannelNumber, valueLeafFlags); 
    } 

    @Override 
    public boolean equals(Object obj) { 
        if (this == obj) { 
            return true; 
        } 
        if (obj instanceof DefaultAugmentedInterface) { 
Code Block
titleInput YANG files
File : flow-classifier.yang
module flow-classifier {
    yang-version 1;
    namespace "sfc.flowclassifier";
    prefix "flow-classifier";
    import "ietf-yang-types" {
        prefix "yang";
    } 
    
    organization "ON-LAB";
    description "This submodule defines for flow classifier.";
    revision "2016-05-24" {
        description "Initial revision.";
    }
   
    leaf id {
        type yang:uuid;
    }
}

File : ietf-yang-types.yang
module ietf-yang-types {

     namespace "urn:ietf:params:xml:ns:yang:ietf-yang-types";
     prefix "yang";

     organization
      "IETF NETMOD (NETCONF Data Modeling Language) Working Group";

     contact
      "WG Web:   <http://tools.ietf.org/wg/netmod/>
       WG List:  <mailto:netmod@ietf.org>

       WG Chair: David Kessens
                 <mailto:david.kessens@nsn.com>

       WG Chair: Juergen Schoenwaelder
                 <mailto:j.schoenwaelder@jacobs-university.de>

       Editor:   Juergen Schoenwaelder
            DefaultAugmentedInterface other =   <mailto:j.schoenwaelder@jacobs-university.de>";

     description
 (DefaultAugmentedInterface) obj; 
     "This module contains a collection of generally usefulreturn derived
       YANG data types.

       Copyright (c) 2013 IETF Trust and the persons identified as
Objects.equals(ds0ChannelNumber, other.ds0ChannelNumber) && 
              authors of the code.  All rights reserved.

 Objects.equals(valueLeafFlags, other.valueLeafFlags); 
        } 
 Redistribution and use in source and binary forms,return withfalse; or
    } 

    without modification, is permitted pursuant to, and subject@Override 
    public String toString() { 
       to the license terms contained in, the Simplified BSD License
return MoreObjects.toStringHelper(getClass()) 
            .omitNullValues() set
 forth in Section 4.c of the IETF Trust's Legal Provisions
  .add("ds0ChannelNumber", ds0ChannelNumber) 
   Relating to IETF Documents
       (http://trustee.ietf.org/license-info).

.add("valueLeafFlags", valueLeafFlags) 
         This version of this YANG module is part of RFC 6991; see
   .toString(); 
    } 


    /** 
    the RFC* itselfCreates foran fullinstance legalof noticesdefaultAugmentedInterface."; 

     revision 2013-07-15 {*/ 
    public DefaultAugmentedInterface() { description
    } 


   "This revision@Override adds
 the following new datapublic types:
    boolean isLeafValueSet(LeafIdentifier leaf) { 
     - yang-identifier
  return valueLeafFlags.get(leaf.getLeafIndex()); 
    } - hex-string
 

}


Type

Overview

The "type" statement takes as an argument a string that is the name of a YANG built-in type or a derived type, followed by an optional block of sub statements that are used to put further restrictions on the type.

Java mapping


YANG

Description

JAVA

binary

Any binary data

byte[]

bits

A set of bits or flags

BitSet in container class (A enum class for bits leaf)

boolean

"True" or "false"

boolean

decimal64

64-bit    signed decimal number

        

...

 

...

      BigDecimal

empty

A leaf that does not have any value

boolean

enumeration

Enumerated strings

Enum class will be generated

identityref

A reference to an abstract identity

To be implemented

instance-identifier

References a data tree node

String

int8

8-bit signed integer

byte   

int16

16-bit signed integer

short

int32

32-bit signed integer

int

int64

64-bit signed integer

long   

leafref   

A reference to a leaf instance

The type of referenced leaf/leaf-list will be used

string   

Human-readable string

String

uint8   

8-bit unsigned integer

short

uint16   

16-bit unsigned integer        

int   

uint32

32-bit unsigned integer

long   

uint64   

64-bit unsigned integer

BigInteger

union   

Choice of member types

Union  class will be generated

Example
Code Block
titleInput YANG file
leaf one {   - dotted-quad";
       reference
        "RFC 6991: Common YANG Data Types";
     }

     revision 2010-09-24 {
       description
        "Initial revision.";
       reference
        "RFC 6021: Common YANG Data Types";
     }

     typedef uuid {
       type string {
         pattern '[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-'
               + '[0-9a-fA-F]{4}-[0-9a-fA-F]{12}';
;
}

leaf two {                           }
    type int32;
}

leaf-list three description{
    type boolean;
}

leaf-list four { "A Universally Unique IDentifier in the string representation
    
     defined in RFC 4122.  The canonical representation usestype int16;
}
leaf mybits {
    type bits {
        bit lowercase characters.

disable-nagle {
           The followingposition is0;
 an example of a UUID in string representation:}
        bit f81d4faeauto-7dec-11d0-a765-00a0c91e6bf6
sense-speed {
            position "1;
       reference }
        "RFC 4122: A Universally Unique IDentifier (UUID) URN
 bit Mb-only {
            position 2;
        }
    Namespace";}
     }
}

Include

Overview

A module uses a include statement to include sub-module that belongs to module. The argument is the name of sub-module. Modules are only allowed to include sub-module that belongs to module, as defined by belongs-to statement. When a module includes a submodule, it incorporates the contents of the submodule into the node hierarchy of the module.

JAVA mapping

There is no java mapping for include statement.

Example

Please refer submodule example

Organization

Overview

   The "organization" statement defines the party responsible for this module.  The argument is a string that is used to specify a textual description of the organization(s) under whose auspices this module was developed.

JAVA mapping

 Organization will be used as javadoc in generated java code in Hummingbird release version. Currently it is not used in generated java code.

Example

Please refer module example section

Contact

Overview

  The "contact" statement provides contact information for the module. The argument is a string that is used to specify contact information for the person or persons to whom technical queries concerning this  module should be sent, such as their name, postal address, telephone number, and electronic mail address.

JAVA mapping

 Contact information will be used as javadoc in generated java code in Hummingbird release version. Currently it is not used in generated java code.

Example

Please refer module example section

Belongs to

Overview

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 the module to which it belongs, or by another submodule that belongs to that module.

JAVA mapping

No java mapping for belongs to statement in generated code.

Example

Please refer submodule example section.

Leaf

Overview

A leaf is an atomic element in YANG. It has value, but does not have child. It is used for defining the scalar variable of a built-in type or a derived type.

Java mapping

In java leaf is converted to define variable with its respective java built-in type or derived type.

Example
Code Block
titleInput YANG file
File : acme-system.yang
module acme-system {
     namespace "http://acme.example.com/system";
     prefix "acme";
     organization "ACME Inc.";
     contact "joe@acme.example.com";
     description
        "The module for entities implementing the ACME system.";
     revision 2007-06-09 {
         description "Initial revision.";
     }
     container system {
            leaf host-name {
                type string;
                description "Hostname for this system";
           }
     }
    .
    .
    .
}

 

Code Block
titleGenerated Java files
File: System.java
public interface System extends AugmentationHolder  {
    String hostName();
    interface SystemBuilder {
        String hostName();
        SystemBuilder hostName(String hostName);
        System build();
    }
}

File : SystemBuilder.java
public class SystemBuilder implements System.SystemBuilder {
    private String hostName;

    @Override
    public String hostName() {
        return hostName;
    }

    @Override
    public SystemBuilder hostName(String hostName) {
        this.hostName = hostName;
        return this;
    }
    .
    .
    .
    public final class SystemImpl implements System {
        private String hostName;
        @Override
        public String hostName() {
            return hostName;
        }
    .
    .
    .
    }
}

Leaf-list

 Overview

A leaf-list is also used for defining scalar variable, like leaf, but in an array of a particular type. The type of the variable can be either built-in type or a derived type.

Java mapping

In java leaf-list is stored in List, with respect to, java built-in type or derived type.

Example
Code Block
titleInput YANG file
File : acme-system.yang
module acme-system {
     namespace "http://acme.example.com/system";
     prefix "acme";
     organization "ACME Inc.";
     contact "joe@acme.example.com";
     description
        "The module for entities implementing the ACME system.";
     revision 2007-06-09 {
         description "Initial revision.";
     }
     container system {
             leaf-list domain-search {
                 type string;
                 description "List of domain names to search";
             }
     }
    .
    .
    .
}

 

Code Block
titleGenerated Java files
File : System.java
public interface System extends AugmentationHolder  {
    String hostName();
    interface SystemBuilder {
        String hostName();
        SystemBuilder hostName(String hostName);
        System build();
    }
}

File : SystemBuilder.java
public class SystemBuilder implements System.SystemBuilder {
    private List<String> domainSearch;

    @Override
    public List<String> domainSearch() {
        return domainSearch;
    }

    @Override
    public SystemBuilder domainSearch(List<String> domainSearch) {
        this.domainSearch = domainSearch;
        return this;
    }
    .
    .
    .
    public final class SystemImpl implements System {
        private List<String> domainSearch;

        @Override
        public List<String> domainSearch() {
            return domainSearch;
        }
    .
    .
    .
        }
}

Container

Overview

Container is a holder that can hold many nodes within it. It is used for logically grouping certain set of nodes.

Java mapping

In java, container acts as a class which can hold information contained within. A class of the container is formed only when container has nodes in it. In addition to that, container's parent holder will have container class’s information.

Container statement is mapped to java as                  

  1.  Interface
    It includes:
    a) The interface file has two interfaces defined. One interface which is for the impl class and one for the builder class. 
    b) The interface for builder class contains method for getter and setters of the attributes without get and set prefix respectively. And a method to create object of impl class. The interface for impl class contains only a getter of the attribute without get prefix
  2. Builder Class
    It includes:
    a) Builder class implements the builder interface.
    b) It has impl class inside which also implements impl interface. This also has hashCode(), equals(), toString() methods overridden in it. Further augmentation also is implemented here(refer augmentation for more details).
Example
default "auto-sense-speed";
}
Code Block
titleGenerated Java file
File : Test.java

package org.onosproject.yang.gen.v1.http.huawei.com;

import java.util.BitSet;
import java.util.List;

/**
 * Abstraction of an entity which represents the functionality of test.
 */
public interface Test {

    /**
     * Identify the leaf of Test.
     */
    public enum LeafIdentifier implements org.onosproject.yang.model.LeafIdentifier{
        
        ONE(1),
        /**
         * Represents two.
         */
        TWO(2),
        /**
         * Represents mybits.
         */
        MYBITS(3),
        /**
         * Represents three.
         */
        THREE(4),
        /**
         * Represents four.
         */
        FOUR(5);

        private int leafIndex;

        public int getLeafIndex() {
            return leafIndex;
        }

        LeafIdentifier(int value) {
            this.leafIndex = value;
        }
    }

    /**
     * Returns the attribute one.
     *
     * @return one value of one
     */
    String one();

    /**
     * Returns the attribute two.
     *
     * @return two value of two
     */
    int two();

    /**
     * Returns the attribute mybits.
     *
     * @return mybits value of mybits
     */
    BitSet mybits();

    /**
     * Returns the attribute three.
     *
     * @return three list of three
     */
    List<Boolean> three();

    /**
     * Returns the attribute four.
     *
     * @return four list of four
     */
    List<Short> four();

    /**
     * Returns the attribute valueLeafFlags.
     *
     * @return valueLeafFlags value of valueLeafFlags
     */
    BitSet valueLeafFlags();

    /**
     * Sets the attribute one.
     *
     * @param one value of one
     */
    void one(String one);

    /**
     * Sets the attribute two.
     *
     * @param two value of two
     */
    void two(int two);

    /**
     * Sets the attribute mybits.
     *
     * @param mybits value of mybits
     */
    void mybits(BitSet mybits);

    /**
     * Sets the attribute three.
     *
     * @param three list of three
     */
    void three(List<Boolean> three);

    /**
     * Sets the attribute four.
     *
     * @param four list of four
     */
    void four(List<Short> four);

    /**
     * Adds to the list of three.
     *
     * @param addTo value of three
     */
    void addToThree(Boolean addTo);

    /**
     * Adds to the list of four.
     *
     * @param addTo value of four
     */
    void addToFour(Short addTo);


    /**
     * Checks if the leaf value is set.
     *
     * @param leaf leaf whose value status needs to checked
     * @return result of leaf value set in object
     */
    boolean isLeafValueSet(LeafIdentifier leaf);
}



File : TestOpParam

package org.onosproject.yang.gen.v1.http.huawei.com;

import com.google.common.base.MoreObjects;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.onosproject.yang.model.InnerModelObject;

/**
 * Represents the implementation of test.
 *
 * <p>
 * valueLeafFlags identify the leafs whose value are explicitly set
 * Applicable in protocol edit and query operation.
 * </p>
 */
public class TestOpParam extends InnerModelObject implements Test {
    protected String one;
    protected int two;
    protected BitSet mybits;
    protected List<Boolean> three;
    protected List<Short> four;
    protected BitSet valueLeafFlags = new BitSet();

    @Override
    public String one() {
        return one;
    }

    @Override
    public int two() {
        return two;
    }

    @Override
    public BitSet mybits() {
        return mybits;
    }

    @Override
    public List<Boolean> three() {
        return three;
    }

    @Override
    public List<Short> four() {
        return four;
    }

    @Override
    public BitSet valueLeafFlags() {
        return valueLeafFlags;
    }

    @Override
    public void one(String one) {
        valueLeafFlags.set(LeafIdentifier.ONE.getLeafIndex());
        this.one = one;
    }

    @Override
    public void two(int two) {
        valueLeafFlags.set(LeafIdentifier.TWO.getLeafIndex());
        this.two = two;
    }

    @Override
    public void mybits(BitSet mybits)
Code Block
titleInput YANG file
File : acme-system.yang
module acme-system {
     namespace "http://acme.example.com/system";
     prefix "acme";
     organization "ACME Inc.";
     contact "joe@acme.example.com";
     description
        "The module for entities implementing the ACME system.";
     revision 2007-06-09 {
         description "Initial revision.";
     }
     container system {
         container login {
             leaf message {
        valueLeafFlags.set(LeafIdentifier.MYBITS.getLeafIndex());
        this.mybits type= stringmybits;
    }

    @Override
    public void three(List<Boolean> three)  description{
            valueLeafFlags.set(LeafIdentifier.THREE.getLeafIndex());
        this.three "Message given at start of login session";= three;
    }

    @Override
    public void four(List<Short> four)  }{
        }valueLeafFlags.set(LeafIdentifier.FOUR.getLeafIndex());
    }
    this.four = four;
    .}

    .
}

 

Code Block
titleGenerated Java files
File : Login.java
public interface Login extends AugmentationHolder @Override
    public void addToThree(Boolean addTo) {
    String message();
   if interface LoginBuilder(three == null) {
        String message();
   three = new   LoginBuilder message(String messageArrayList<>();
        Login build();}
    }
}

File : SystemBuilder.java
public class LoginBuilder implements Login.LoginBuilder {three.add(addTo);
    private String message;}


    @Override
    public Stringvoid messageaddToFour(Short addTo) {
        return message;
    }

if (four == null) {
    @Override
    public LoginBuilder message(String message) {
        this.messagefour = messagenew ArrayList<>();
        }
    return this    four.add(addTo);
    }


    @Override
    public Loginint buildhashCode() {
        return new LoginImpl(this Objects.hash(one, two, mybits, three, four, valueLeafFlags);
    }
    public LoginBuilder() {
    }@Override
    public finalboolean class LoginImpl implements Loginequals(Object obj) {
        privateif List<AugmentedInfo>(this augmentedInfoList == new ArrayList<>();obj) {
        private    Stringreturn messagetrue;

        @Override}
        public String message(if (obj instanceof TestOpParam) {
             return messageTestOpParam other = (TestOpParam) obj;
         }

   return
     @Override
         public int hashCode(Objects.equals(one, other.one) {&&
            return    Objects.hash(message);equals(two, other.two) &&
        }

        @Override
Objects.equals(mybits, other.mybits) &&
           public    boolean Objects.equals(Object objthree, other.three) {&&
            if (this == obj) {    Objects.equals(four, other.four) &&
                return true;
    Objects.equals(valueLeafFlags, other.valueLeafFlags);
        }
        return false;
   if (obj instanceof LoginImpl) { }

    @Override
    public String toString() {
         LoginImpl other = (LoginImpl) obj;return MoreObjects.toStringHelper(getClass())
            .omitNullValues()
    return
        .add("one", one)
            Objects.equalsadd(message"two", other.messagetwo);
            }.add("mybits", mybits)
            return false;.add("three", three)
        }

    .add("four", four)
   @Override
        public String toString() { .add("valueLeafFlags", valueLeafFlags)
            return MoreObjects.toStringHelper(getClass.toString());
    }

            .add("message", message)/**
     * Creates an instance of testOpParam.
      .toString();*/
    public TestOpParam() {
    }


    @Override
    public boolean LoginImplisLeafValueSet(LoginBuilderLeafIdentifier builderObjectleaf) {
        return    this.message = builderObject.message(valueLeafFlags.get(leaf.getLeafIndex());
        }


        @Override
        public void addAugmentation(AugmentedInfoInnerModelObject valueobj) {
    }

    @Override
    getAugmentedInfoList().add(value);
    public void removeAugmentation(InnerModelObject obj) {
    }

        @Override
    public Map<Class<? extends InnerModelObject>, publicInnerModelObject> List<AugmentedInfo> getAugmentedInfoListaugmentations() {

            return augmentedInfoListnull;
        }

        @Override
    public <T extends InnerModelObject> publicT void removeAugmentation(augmentation(Class<T> c) {

            getAugmentedInfoList().clear();
        }return null;
    }
}

...


Typedef

Overview

List is also like container that can hold many nodes by logically grouping. The only difference is, list can have multiple instances whereas container has only one instance.

Java mapping

    In java, list acts as a class which can hold information contained within. A class of the list is formed only when list has nodes in it. In addition to that, list's parent holder will have list information by creating the list information in java List so that many instances of the class can be stored in it.

   The list statement mapping in java is as same as container for the generation of java (refer container to know what files are generated).

...

Typedef is user defined type for his implementation. It has the base type which is must for typedef. To give more information about the typedef there should be sub statements to describe it. Unit statement is optional for typedef which give info about the unit of the type. Default is like a value which will be assigned to the typedef if no value is given.default value should follow all restriction defined for the base-type.

Java mapping

For a given typedef node one class file will be generated which will have an attribute with the base type of typedef. There will be a constructor and a getter method, of method and implementation of hashcode, equals and toString methods.

Example
Code Block
titleInput YANG file
File : test.yang

module test {

    yang-version 1;
    namespace "http://huawei.com";
    prefix "test";

    typedef percent {
        type uint8;
           description "Percentage";
    }

    leaf completed {
        type percent;
    }
}
Code Block
titleGenerated Java file
File : Percent.java
package org.onosproject.yang.gen.v1.http.huawei.com.test;

import java.util.Objects;

/**
 * Represents the implementation of percent.
 */
public final class Percent {

    private short uint8;

    /**
     * Creates an instance of percent.
     */
    private Percent() {
    }

    /**
     * Creates an instance of uint8.
     *
     * @param uint8 value of uint8
     */
    public Percent(short uint8) {
  : acme-system.yang
module acme-system {
    namespace "http://acme.example.com/system";
    prefix "acme";
    organization "ACME Inc.";
    contact "joe@acme.example.com";
    description
        "The module for entities implementing the ACME system.";
    revision 2007-06-09 {
        description "Initial revision.";
    }
    list login {
       this.uint8 key= "name"uint8;
    }

    list login {/**
     * Returns the object of percent for key "name";type uint8.
     *
     * @param value leafvalue nameof {
percent for type uint8
     * @return percent for type uint8
    type string;*/
     public static Percent of(short value)   }{
        return new Percent(value);
  leaf full-name {}

    /**
     * Returns the attribute uint8.
    type string;*
     * @return uint8 value of   }uint8
     */
    public   leaf classshort uint8() {
        return uint8;
    }
   type string;
/**
     * Sets the attribute uint8.
     }*
     * @param uint8 value of }uint8
     */
   leaf namepublic {
void uint8(short uint8) {
        this.uint8 type= stringuint8;
    }

    }@Override
    }
public int hashCode()  .{
    .
    return Objects.
}
Code Block
titleGenerated Java files
File : Login.java
public interface Login extends AugmentationHolder  {
    String name();hash(uint8);
    }

    @Override
    public boolean equals(Object obj) {
    String fullName();
   if String addThisBeforeClass();
    interface LoginBuilder {
(this == obj) {
            Stringreturn name()true;
        String fullName();}
        Stringif addThisBeforeClass();
obj instanceof Percent)  {
    LoginBuilder name(String name);
      Percent other LoginBuilder= fullName(StringPercent) fullName)obj;
        LoginBuilder   addThisBeforeClass(String addThisBeforeClass); return
        Login build();
       }
}

File : LoginBuilder.java
public class LoginBuilder implements Login.LoginBuilder {
    private String name;
 Objects.equals(uint8, other.uint8);
        }
       private Stringreturn fullNamefalse;
    private String addThisBeforeClass;}

    @Override
    public String nametoString() {
        return nameString.valueOf(uint8);
    }

    @Override/**
    public * StringReturns fullName() {
        return fullName;
    }

    @Override
    public String addThisBeforeClass() {
        return addThisBeforeClass;
    }

    @Override
    public LoginBuilder name(String name) {
the object of percent fromString input String percent.
     *
     * @param valInString value of input String
     * @return percent
     */
    public static Percent fromString(String valInString) {
        try {
            short this.nametmpVal = nameShort.parseShort(valInString);
        return this;
    }
return of(tmpVal);
    @Override
    public} LoginBuildercatch fullName(StringException fullNamee) {
        this.fullName = fullName;
  throw new IllegalArgumentException("not a valid  return thisinput element");
    }

    @Override}
    public LoginBuilder addThisBeforeClass(String addThisBeforeClass) {
        this.addThisBeforeClass = addThisBeforeClass}
}

Enumeration

Overview

Enum statement only can come when a leaf is of type enumeration. Each enum has one string then should be unique . The string must not be empty string and must not have white spaces. Enum can have sub statements, value statement will give the info about its value. If the enum statement in enumeration has no value statement then its value is considered as zero and subsequently incremented by one for next values.

Java mapping

For a given enumeration node one enum file will be generated which will have all the enum as its attributes. There will be a constructor and a getter method for the values.

Example
Code Block
titleInput YANG file
File: test.yang
module Test {

    yang-version 1;
        return thisnamespace "http://huawei.com";
    }

    @Overrideprefix Ant;
    publicdescription Login build() {
        return new LoginImpl(this);
"Interval before a route is declared invalid";

    }
leaf  packetType  public LoginBuilder() {
    }
    public final class LoginImpl implementstype Loginenumeration {
         private List<AugmentedInfo> augmentedInfoList = new ArrayList<>()enum "unbounded";
        private String name;
   enum ZERO;
    private String fullName;
        private String addThisBeforeClassenum two;

        @Override
     enum four;
  public String name() {
    }        return name;
        }
}
Code Block
titleGenerated Java files
File : PacketTypeEnum.java

package org.onosproject.yang.gen.v1.http.huawei.com.test;

/**
 * Represents ENUM data of packetTypeEnum.
 */
public enum PacketTypeEnum {

        @Override
        public String fullName() {
    /**
     * Represents unbounded.
 return fullName;
   */
     }UNBOUNDED(0, "unbounded"),

    /**
    @Override * Represents zERO.
     */
   public String addThisBeforeClass() {ZERO(1, "ZERO"),

    /**
     * Represents two.
 return addThisBeforeClass;
   */
     }TWO(2, "two"),

        @Override/**
     *   public int hashCode() {Represents four.
     */
       return Objects.hash(name, fullName, addThisBeforeClassFOUR(3, "four");

    private int   }packetTypeEnum;

    private    @OverrideString schemaName;

        public boolean equals(Object obj) {/**
     * Creates an instance of packetTypeEnum.
  if (this == obj) { *
     * @param packetTypeEnum value of packetTypeEnum
      return true;*/
     PacketTypeEnum(int packetTypeEnum, String schemaName) {
    }
    this.packetTypeEnum = packetTypeEnum;
      if (obj instanceof LoginImpl) {this.schemaName = schemaName;
    }

    /**
     * Returns the LoginImplobject otherof = (LoginImpl) obj;packetTypeEnum for.
     *
     * @param value value of packetTypeEnum returnfor
     * @return packetTypeEnum for
     */
    public static PacketTypeEnum  Objects.equals(name, other.name) &&of(int value) {
        switch (value) {
           Objects.equals(fullName, other.fullName) && case 0:
                return PacketTypeEnum.UNBOUNDED;
    Objects.equals(addThisBeforeClass, other.addThisBeforeClass);
       case 1:
    }
            return falsePacketTypeEnum.ZERO;
        }

        @Overridecase 2:
        public String toString() {
            return MoreObjects.toStringHelper(getClass())PacketTypeEnum.TWO;
            case 3:
   .add("name", name)
            return    .add("fullName", fullName)PacketTypeEnum.FOUR;
            default :
   .add("addThisBeforeClass", addThisBeforeClass)
             throw new IllegalArgumentException("not a valid input .toString(element");
        }
    }
    public LoginImpl(LoginBuilder builderObject) {
      /**
     * Returns the object of packetTypeEnum for.
     *
 this.name = builderObject.name();
  * @param value value of packetTypeEnum for
    this.fullName = builderObject.fullName();
  * @return packetTypeEnum for
     */
    public this.addThisBeforeClassstatic =PacketTypeEnum builderObject.addThisBeforeClass();of(String value) {
        }

  switch (value) {
      @Override
      case "unbounded":
 public void addAugmentation(AugmentedInfo value) {
           return getAugmentedInfoList().add(value)PacketTypeEnum.UNBOUNDED;
        }

    case "ZERO":
   @Override
        public List<AugmentedInfo> getAugmentedInfoList() {
  return PacketTypeEnum.ZERO;
         return augmentedInfoList;
  case "two":
     }

        @Override
   return PacketTypeEnum.TWO;
    public void removeAugmentation() {
     case  "four":
     getAugmentedInfoList().clear();
        }
   return }
}

Generated java files for list's holder(another list):

File : Login.java
public interface Login extends AugmentationHolder  {PacketTypeEnum.FOUR;
            default :
    String name();
List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login.Login> login();
    interface LoginBuilder {
    throw new IllegalArgumentException("not a String name();
List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login.Login> login(valid input element");
        LoginBuilder}
 name(String name);
  }
    /**
  LoginBuilder login(List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem
  * Returns the attribute packetTypeEnum.
     *
     .login
* @return packetTypeEnum value of packetTypeEnum
     */
    public  .Login> login);int packetTypeEnum() {
        Loginreturn build()packetTypeEnum;
    }
}

File   : LoginBuilder.java
public class LoginBuilder implements Login.LoginBuilder@Override
    public String toString() {
       private Stringreturn nameschemaName;
    }
}


Union

Overview

Union is a built in type which represents its member types. Union can have multiple member types. To use union there must be a type statement. Except empty and leafref all types can come under union.

When a value comes for union , which can match to multiple member types of union, then in that case to whichever type value matches from the member types defined in union value, will be taken from union as the values type.

Java mapping

For a given union node one class file will be generated which will have all the an attribute with the type union is having. There will be a constructor , getter method, of method, fromString, HashCode, equals and ToString methods for the values.

Example
Code Block
titleInput YANG file
File : private List<orgtest.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login.Login> login;

    @Override
    public String name()
module test {
        return nameyang-version 1;
    }

    @Override
    public List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.loginnamespace "http://huawei.com";
    prefix "test";

       .Login> login() typedef ip-address {
        type returnunion login;{
    }

    @Override
    publictype LoginBuilder name(String name) {
int32;
           this.name =type nameuint32;
        return this;}
    }
}
Code Block
titleGenerated java files
File : IpAddressUnion.java
package org
    @Override
    public LoginBuilder login(List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609
            .acmesystem
            .login.Login> login) {huawei.com.test.ipaddress;

import java.util.Objects;
import java.util.BitSet;

/**
 * Represents the implementation of ipAddressUnion.
 */
public final class IpAddressUnion {
    private int int32;
    private    this.login = loginlong uint32;
    private BitSet setValue = returnnew thisBitSet();

    }/**
    .
 * Creates an .
instance of   ipAddressUnion.
    public */
 final class LoginImpl implementsprivate LoginIpAddressUnion() {
    .}

    ./**
    .
  *  }
}

Grouping and uses

Overview

Grouping the nodes together, for reusing them at many places, can be done in YANG. Grouping the nodes is done by grouping statement and using those grouped nodes at different places is done by uses statement.

Java mapping

During YANG to java conversion, wherever the grouping is present a class as similar as to that of a container is created.Wherever uses is present object of this class is used as an attribute.

Example
Code Block
titleInput YANG file
module Test {Creates an instance of int32.
     *
     * @param int32 value of int32
    namespace "http://test.example.com/"; */
    prefix "test";
 public IpAddressUnion(int int32) {
      organization "ACME Inc."setValue.set(0);
    grouping  endpoint { 
this.int32 = int32;
    }

  leaf address {/**
     * Creates an instance of uint32.
   type int32; *
     * @param uint32 }value of uint32
     */
    public leaf portIpAddressUnion(long uint32) {
        setValue.set(1);
    type int8; 
  this.uint32 = uint32;
    }

    }
    container connection { /**
     * Returns the object of ipAddressUnion for type int32.
     *
     * @param value  container source {
value of ipAddressUnion for type int32
     * @return ipAddressUnion for type int32
    uses endpoint;*/
    public static IpAddressUnion  }of(int value) {
        containerreturn destination {new IpAddressUnion(value);
    }

    /**
    uses endpoint;
* Returns the object of ipAddressUnion for type }uint32.
    } *
    .
 * @param value value .
of ipAddressUnion for type .
}
Code Block
titleGenerated Java files
File : Endpoint.java
public interface Endpoint {
    .uint32
     * @return ipAddressUnion for type uint32
    . */
    .
public static IpAddressUnion  interface EndpointBuilderof(long value) {
    .
    .
return    .new IpAddressUnion(value);
    }
}

File   : EndpointBuilder.java
public class EndpointBuilder implements Endpoint.EndpointBuilder {
     /**
     * Returns the attribute int32.
    .
    . *
    public final* class@return EndpointImplint32 implementsvalue Endpointof {int32
    . */
    .
public int int32()  .{
    }
}

File : Source.java
public interface Source extends AugmentationHolder  {  return int32;
    }
    ./**
    .
 * Returns the attribute uint32.
    Endpoint endpoint();*
    interface SourceBuilder* {
@return uint32 value of .uint32
     .*/
    . public long uint32() {
        Endpointreturn endpoint()uint32;
    }
    /**
 SourceBuilder endpoint(Endpoint endpoint);
  *  }
}

File : SourceBuilder.java
public class SourceBuilder implements Source.SourceBuilder {Sets the attribute int32.
     *
    private Endpoint endpoint;

 * @param int32 value of int32
     @Override*/
    public Endpointvoid endpointint32(int int32) {
        return endpointthis.int32 = int32;
    }
    /**
     * @Override
Sets the attribute uint32.
 public SourceBuilder endpoint(Endpoint endpoint) {*
     * @param uint32 this.endpointvalue =of endpoint;uint32
     */
   return this;
public void uint32(long uint32) }{
    .
    this.uint32 = uint32;
    .}

    @Override
 public final class SourceImplpublic implementsint SourcehashCode() {
        private Endpoint endpointreturn Objects.hash(int32, uint32);

    }

    @Override
        public Endpointboolean endpointequals(Object obj) {
        if (this == obj) return{
 endpoint;
        }
   return .true;
    .
    .}
    }
}

File : Destination.java
public interface Destinationif extends(obj AugmentationHolderinstanceof IpAddressUnion) {
    .
    .
    .
IpAddressUnion other   Endpoint= endpoint(IpAddressUnion) obj;
    interface DestinationBuilder {
    .
    .return
    .
       Endpoint endpoint();
       DestinationBuilder endpoint(Endpoint endpoint);
Objects.equals(int32, other.int32) &&
    }
}

File : DestinationBuilder.java
public class DestinationBuilder implements Destination.DestinationBuilder {
    private Endpoint endpoint;

    @Override
 Objects.equals(uint32, other.uint32);
      public Endpoint endpoint() {}
        return endpointfalse;
    }

    @Override
    public DestinationBuilderString endpointtoString(Endpoint endpoint) {
        this.endpoint = endpoint;
   if (setValue.get(0)) {
     return this;
    }
  return  String.valueOf(int32);
    .
    .}
    public final class DestinationImpl implements Destinationif (setValue.get(1)) {
        private    Endpoint endpointreturn String.valueOf(uint32);

        @Override}
        public Endpoint endpoint() {return null;
    }
    /**
    return endpoint;
* Returns the object of ipAddressUnion fromString input }
    String ipAddressUnion.
    . *
    .
    }
}

 

Choice and case

Overview

The choice statement defines a set of alternatives, only one of which may exist at any one time. The argument is an identifier, followed by a block of sub-statements that holds detailed choice information.

A choice consists of a number of branches, defined with the “case” substatement. Each branch contains a number of child nodes. The nodes from at most one of the choice's branches exist at the same time.
The case statement is used to define branches of the choice. It takes identifier as an argument, followed by a block of sub-statements that holds detailed case information.

JAVA mapping

Choice is mapped to interface(marker interface).

Case statement are mapped to the JAVA interfaces

It includes

  1. Interface file which extends choice marker interface

  2. Builder class which implements the builder interface and impl class which implements the interface

  3. Impl class includes overridden methods, hashcode, equals, toString methods.
Example
Code Block
titleInput YANG file
File : link.yang
module link * @param valInString value of input String
     * @return ipAddressUnion
     */
    public static IpAddressUnion fromString(String valInString) {
        try {
            int tmpVal = Integer.parseInt(valInString);
            return of(tmpVal);
        } catch (Exception e) {
    yang-version 1;
    }
      namespace http://huawei.com;
   try {
  prefix Ant;

    container link {
   long tmpVal = Long.parseLong(valInString);
  choice interfaceType {
        return of(tmpVal);
   case ethernerType {
   } catch (Exception e) {
         leaf ethernet { typethrow string; }
    new IllegalArgumentException("not a valid input element");
        }
    }
}

When there are two types with same java mapping. for resolving this conflict we will be checking the range of the value and then we will assign it to the right attribute. Order will be taken care of while code generation and conflict range validation . for example : if union have type int32 followed by uint16, then range validation will be done on basis of int32 , in other case range will be validated on basis of uint16.

Code Block
titleInput YANG file
File : test.yang
module test {
    case p2pType {yang-version 1;
    namespace "http://huawei.com";
    prefix "test";

     leaf p2p { type string; }typedef ip-address {
        type union   }{
        }
    type }
}
Code Block
titleGenerated Java files
File : InterfaceType.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160509.choicecasetest.link1;

import org.onosproject.yangutils.translator.tojava.AugmentationHolder;

public interface InterfaceType extends AugmentationHolder  {
}

File : EthernerType.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160509.choicecasetest.link1.interfacetype;

import org.onosproject.yang.gen.v1.http.huawei.com.rev20160509.choicecasetest.link1.InterfaceType;
import org.onosproject.yangutils.translator.tojava.AugmentationHolder;

public interface EthernerType extends AugmentationHolder, InterfaceType  {

    String ethernet();

    interface EthernerTypeBuilder {

int32;
            type uint16;
            type int64;
            Stringtype ethernet()uint32;

           EthernerTypeBuilder ethernet(String ethernet);
type string;
        EthernerType build();}
    }
}

Code Block
titleGenerated java files
File : EthernerTypeBuilderIpAddressUnion.java

package org.onosproject.yang.gen.v1.http.huawei.com.rev20160509.choicecasetest.link1.interfacetype;

import com.google.common.base.MoreObjects;test.ipaddress;

import java.utilmath.ArrayListBigInteger;
import java.util.ListBitSet;
import java.util.Objects;
import org.onosproject.yangutils.translator.tojava.AugmentedInfo;

public class EthernerTypeBuilder implements EthernerType.EthernerTypeBuilder {

    private String ethernet;

    @Override
    public String ethernet() {
        return ethernet;
    }

    @Override
    public EthernerTypeBuilder ethernet(String ethernet) {
        this.ethernet = ethernet;
        return this;
    }

   @Override
   public EthernerType build();

/**
 * Represents the implementation of ipAddressUnion.
 */
public final class IpAddressUnion {
    private static  return new EthernerTypeImpl(this);
   }

   public EthernerTypeBuilder() {final int INT32_MIN_RANGE = -2147483648;
    private static final int INT32_MAX_RANGE = 2147483647;
   }

 private  publicstatic final class EthernerTypeImpl implements EthernerType {

BigInteger INT64_MIN_RANGE = new BigInteger("-9223372036854775808");
    private static final  private String ethernet;

BigInteger INT64_MAX_RANGE = new BigInteger("9223372036854775807");
    private int   @Overrideint32;
    private    public String ethernet() {int uint16;
    private long int64;
    private long return ethernetuint32;
    private String   }string;

    private BitSet setValue = publicnew EthernerTypeImplBitSet() {;

        }
/**
     * Creates an publicinstance EthernerTypeImpl(EthernerTypeBuilder builderObject) {
        of ipAddressUnion.
     */
   this.ethernet =private builderObject.ethernetIpAddressUnion(); {
        }

    }
}

RPC

Overview

RPCs are modeled with RPC statement. The input statement is used to define input parameters to the RPC and output statement is used to define output parameters to the RPC.

JAVA mapping

Rpc statement is mapped to a method in module manager class and service interface.

The generated method will depends on the sub statements input and output. There can be following java mapping for different combinations of input output statement,

  1. When input is present and no output statement.
     

    1. When input has only one leaf/leaf-list. In this case method signature will have return type as “void” and member attribute with type of leaf.

    2. When input has only one YANG construct. In this case method signature will have return type as “void” and a class will be generated for construct which will be used as the type of method’s attribute..

    3. When input has multiple leaf/leaf-list/YANG construct, one class will be generated for input and that will be used as type of method’s attribute and return type will be void.

  2. When no input  and  output statement is present.
     

    1. When output has only one leaf/leaf-list. In this case method signature will have return type as type of leaf and no member attribute.

    2. When output has only one YANG construct. In this case method signature will have return type as class which is generated for construct and no method  attribute will be generated.

    3. When output has multiple leaf/leaf-list/YANG construct, one class will be generated for output and that will be used as type of method’s return type.
  3. When input is present and  output statement is present.
     
    1. When input has only one leaf/leaf-list and output has only leaf/leaf-list. In this case method signature will have return type as type of leaf/list of output and member attribute with type of leaf/leaf-lists type input.

    2. When input has only one YANG construct and output has one YANG construct. In this case method signature will have return type as generated class of outputs construct and a class will be generated for inputs construct which will be used as the type of method’s attribute.

    3. When input has multiple leaf/leaf-list/YANG construct, and output has leaf/leaf-list/YANG construct one class will be generated for input and that will be used as type of method’s attribute and class will be generated for output which will be used as return type of method.
Example
Code Block
titleInput YANG file
File: sfc.yang
module Sfc {
    yang-version 1;
    namespace http://huawei.com;
    prefix Ant;
    rpc SFP {
        input {
            leaf port/**
     * Creates an instance of string.
     *
     * @param string value of string
     */
    public IpAddressUnion(String string) {
        setValue.set(4);
        this.string = string;
    }

    /**
     * Creates an instance of int32.
     *
     * @param int32 value of int32
     */
    public IpAddressUnion(int int32) {
        setValue.set(0);
        if (validateRange(INT32_MIN_RANGE, INT32_MAX_RANGE, int32)) {
            this.int32 = int32;
        } else {
            this.uint16 = int32;
    }
        }

    /**
     * Creates an instance of int64.
     *
     * @param int64 value of int64
     */
    public IpAddressUnion(long int64) {
        setValue.set(2);
        if (validateRange(INT64_MIN_RANGE, INT64_MAX_RANGE, int64)) {
            this.int64 = int64;
        } else {
            this.uint32 = int64;
    }
        }

    /**
     * Returns the object of ipAddressUnion for type string.
     *
     * @param value value of ipAddressUnion for type string
     * @return ipAddressUnion for type string
     */
    public static IpAddressUnion of(String value) {
        return new IpAddressUnion(value);
      type string;}

    /**
     * Returns the }
object of ipAddressUnion for type int32.
     }*
     * @param value value of outputipAddressUnion {
for type int32
     * @return ipAddressUnion for type leaf path {int32
     */
    public static IpAddressUnion of(int value) {
  type string;
     return   new IpAddressUnion(value);
    }

    /**
     * }
Returns the object  }
}
Code Block
titleGenerated Java files
File : SfcService.java

package org.onosproject.yang.gen.v1.http.huawei.com.rev20160526;

import org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.sfc.sfp.SfpInput;
import org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.sfc.sfp.SfpOutput;

public interface SfcService {
    SfpOutput sfp(SfpInput inputVar);
}
File : SfcManager.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160526;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.sfc.sfp.SfpInput;
import org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.sfc.sfp.SfpOutput;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;

@Component (immediate = true)
@Service
public class SfcManager implements SfcService {

    private final Logger log = getLogger(getClass());

    @Activateof ipAddressUnion for type int64.
     *
     * @param value value of ipAddressUnion for type int64
     * @return ipAddressUnion for type int64
     */
    public static IpAddressUnion of(long value) {
        return new IpAddressUnion(value);
    }

    /**
     * Returns the attribute int32.
     *
     * @return int32 value of int32
     */
    public voidint activateint32() {
        //TODO: YANG utils generated codereturn int32;
    }
    /**
     * Returns the log.info("Started");
attribute int64.
     }
*
     * @return int64 value of int64
    @Deactivate */
    public voidlong deactivateint64() {
         //TODO: YANG utils generated codereturn int64;
    }
    /**
    log.info("Stopped");
     }

 * Returns the attribute string.
     *
     * @return string value of string
     @Override*/
     public SfpOutputString sfpstring(SfpInput inputVar) {
        //TODO: YANG utils generated codereturn string;
    }
    /**
    return null;
* Sets the   }
}

File : SfpInput.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.sfc.sfp;

public interface SfpInput {

attribute int32.
     *
     String port();

    interface SfpInputBuilder {

   * @param int32 value of int32
     */
    public Stringvoid portint32(int int32); {

        SfpInputBuilder port(String port)this.int32 = int32;

    }
    SfpInput build();/**
    }
}
File : SfpinputBuilder.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.sfc.sfp;

import com.google.common.base.MoreObjects;
import java.util.Objects;

public class SfpInputBuilder implements SfpInput.SfpInputBuilder {

     private String port;

    @Override* Sets the attribute uint16.
     *
     * @param uint16 value of uint16
     */
    public Stringvoid portuint16(int uint16) {
        this.uint16 return= portuint16;
    }
    /**
     * Sets the attribute int64.
     @Override*
    public SfpInputBuilder port(String port) { * @param int64 value of int64
     */
    public  this.port = port;void int64(long int64) {
        this.int64 return= thisint64;
    }

    @Override/**
     * publicSets SfpInputthe build() {
attribute uint32.
     *
     * return new SfpInputImpl(this);@param uint32 value of uint32
    }
 */
    public void SfpInputBuilderuint32(long uint32) {
    }

    publicthis.uint32 final= classuint32;
 SfpInputImpl implements SfpInput {
}
    /**
     * Sets the  private String port;

attribute string.
     *
     * @param string value of @Overridestring
     */
    public void string(String port(string) {
        this.string =   return portstring;
        }

        @Override
        public int hashCode() {
            return Objects.hash(port);
    int32, uint16, int64, uint32, string);
    }

        @Override
        public boolean equals(Object obj) {
             if (this == obj) {
                 return true;
             }
            if (obj instanceof SfpInputImplIpAddressUnion) {
                SfpInputImplIpAddressUnion other = (SfpInputImplIpAddressUnion) obj;
                return
                     Objects.equals(portint32, other.portint32);
            } &&
            return false;
   Objects.equals(uint16,      }
other.uint16) &&
        @Override
        public String toString() {
                return MoreObjects.toStringHelper(getClass())Objects.equals(int64, other.int64) &&
                   Objects.addequals("port"uint32, port)
  other.uint32) &&
                Objects.equals(string, other.toString(string);
        }

        return false;
 public SfpInputImpl(SfpInputBuilder builderObject) {}

    @Override
    public String toString() {
       this.port =if builderObject(setValue.portget(0);) {
        }
    }
}
File :return Sfpoutput.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.sfc.sfp;

public interface SfpOutput {

String.valueOf(int32);
       String path();
}
    interface SfpOutputBuilder {

  if (setValue.get(1)) {
    String path();

        SfpOutputBuilder path(String pathreturn String.valueOf(uint16);

        SfpOutput build();}
     }
}
File : SfpOutputBuilder.java

package org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.sfc.sfp;

import com.google.common.base.MoreObjects;
import java.util.Objects;
public class SfpOutputBuilder implements SfpOutput.SfpOutputBuilder {

 if (setValue.get(2)) {
            privatereturn String path.valueOf(int64);

        @Override}
       public String path()if (setValue.get(3)) {
            return pathString.valueOf(uint32);
        }

    @Override
    public SfpOutputBuilder path(String pathif (setValue.get(4)) {
           this.path =return pathstring;
        }
        return thisnull;
    }
    /**
     * @Override
Returns the object of ipAddressUnion publicfromString SfpOutputinput build() {
String ipAddressUnion.
     *
     return* new SfpOutputImpl(this);
    }

@param valInString value of input String
     public* SfpOutputBuilder()@return {ipAddressUnion
    } */

    public finalstatic classIpAddressUnion SfpOutputImpl implements SfpOutput {

fromString(String valInString) {
        try {
    private String path;

      int tmpVal  @Override
= Integer.parseInt(valInString);
           public Stringreturn pathof(tmpVal) {;
        } catch (Exception  return path;
 e) {
        }

        try @Override{
         public int hashCode() {   long tmpVal = Long.parseLong(valInString);
            return Objects.hashof(pathtmpVal);
         }

 catch (Exception e) {
     @Override
   }
      public boolean equals(Object obj) try {
            ifString (thistmpVal == obj) {
(valInString);
            return of(tmpVal);
        } catch (Exception returne) true;{
            }throw new IllegalArgumentException("not a valid input element");
        }
    if}
 (obj instanceof SfpOutputImpl) {/**
     * Validates if value is in given range.validateRange.
     *
     * SfpOutputImpl@param otherminRange =value (SfpOutputImpl) obj;of minRange
     * @param minRange value of maxRange
     * @return  true if value return Objects.equals(path, other.path);is in range
     */
    private boolean  }
    validateRange(int minRange, int maxRange, int value) {
        return false;
      value >= minRange && value <= maxRange;
    }

    /**
     * @Override
Validates if value is in given range.validateRange.
   public String toString() {*
     * @param minRange value of minRange
  return MoreObjects.toStringHelper(getClass())
  * @param minRange value of maxRange
     * @return   .add("path", path)
   true if value is in range
     */
    private boolean validateRange(BigInteger  .toString();
    minRange, BigInteger maxRange, long value) {
     }

   BigInteger bigInteger = new BigInteger(" " public SfpOutputImpl(SfpOutputBuilder builderObject) {+ value);
        return bigInteger.compareTo(minRange) == 1 this.path = builderObject.path();
         }
 && bigInteger.compareTo(maxRange) == 1;
    }
}

Notification 

Overview

The "notification" statement is used to define a notification.  It takes one argument, which is an identifier, followed by a block of substatements that holds detailed notification information.

JAVA mapping

Notification is mapped to events and event listeners in ONOS. Events are used by Managers to notify its listeners about changes in the network, and by Stores to notify their peers of events in a distributed setting. An Event is comprised of a event type and a subject built of model objects.

When notification statement is present in YANG, an event class , event subject class, event listener interface and notification interface  and builder will be generated.

When multiple notifications are present event class include the an enum with types of events for all notification  like DEVICE_ADDED, DEVICE_REMOVED and it extends AbstractEvent with event type and event subject class. It is used to notify EventListeners about the event.

Event Subject class will have all the objects of events for multiple notifications and getters and setters for the events.

Event Listener is interface which extends EventListener.


Leafref

Overview

The leafref type is used to reference a particular leaf instance in the data tree. Path statement must be present for leafref type. The path under leafref must refer to existing leaf or leaf-list. The leaf or leaf-list with leafref will use the instance of the referred leaf or leaf-list.

If leafref comes under grouping and typedef, it will be resolved where it is used. It will not be resolved where it is defined.

 

Java mapping

The leaf or leaf-list with type leafref, will copy the type of referred leaf or leaf-list, during java file generation. If leaf-ref is directly inside grouping then the generated return type of that leaf will be ObjectManager Extends ListenerRegistry with event and eventListener.

Example
Code Block
titleInput input YANG filesfile
File : ospfietf-network.yang
module ospfietf-network {
    namespace "http://example.com/ospf"yang-version 1;
    prefixnamespace "ospfurn:ietf:params:xml:ns:yang:ietf-network";

    notification test {
           leaf event-class {
              type string;
           }
           leaf severity {
              type string;
    prefix nd;

    container networks {
       } description
    }
}
Code Block
titleGenerated Java files
File : OspfManager.java
package org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160519;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160519.ospf.OspfEvent;
import org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160519.ospf.OspfListener;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;

@Component (immediate = true)
@Service
public class OspfManager
 "Serves as top-level container for a list of
          extends ListenerRegistry<OspfEvent, OspfListener> networks.";
        implementsleaf OspfServiceid {

    private final Logger log = getLogger(getClass());

   type @Activateuint8;
    public void activate() {
      description
  //TODO: YANG utils generated code
      "Identifies a lognetwork.info("Started");
        }

    @Deactivate
    public void deactivate()container network {
          //TODO: YANG utilsleaf generatednetwork-id code{
        log.info("Stopped");
        }
}

File : OspfService.java
package org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160519;

import org.onosproject.event.ListenerService;
import org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160519.ospf.OspfEvent;
import org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160519.ospf.OspfListener;

public interface OspfService
type leafref {
               extends ListenerService<OspfEvent, OspfListener> {
}

File : OspfEvent.java
package org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160527.ospf;

import org.onosproject.event.AbstractEvent;

public class OspfEvent extends AbstractEvent<OspfEvent.Type, OspfEventSubject> {

path "/nd:networks/nd:id";
             public enum Type {

}
        TEST
    }

    public OspfEvent(Type type, OspfEventSubject subject) {}
        super(type, subject)uses network-id;
    }
    grouping network-id {
        description
  public OspfEvent(Type type, OspfEventSubject subject, long time) {
   "Serves as top-level container for super(type, subject, time);
a list of
         }
}

File : OspfEventSubject.java
package org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160519.ospf;

public class OspfEventSubject {

networks.";
        leaf network-id {
     private Test test;

    public Testtype test()leafref {
        return test        path "/nd:networks/nd:id";
    }

    public void test(Test test) {}
        this.test = test;}
    }
}

Code Block
titleGenerated java files
File : OspfListenerNetworks.java

package org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160519.ospf.urn.ietf.params.xml.ns.yang.ietf.network.ietfnetwork;

import orgjava.onosprojectutil.event.EventListener;

public interface OspfListener extends EventListener<OspfEvent> {
}

File : Test.java

package BitSet;
import org.onosproject.yang.gen.v1.httpurn.exampleietf.comparams.ospfxml.rev20160519.ospf;

import org.onosproject.yangutils.translator.tojava.AugmentationHolder;

public interface Test extends AugmentationHolder  {

    String eventClass();
ns.yang.ietf.network.ietfnetwork.networks.Network;

/**
 * Abstraction of an entity which represents the functionality of networks.
 */
public interface Networks {

    /**
     * Identify the leaf of Networks.
    String severity();

 */
    public enum interfaceLeafIdentifier TestBuilder {
implements org.onosproject.yang.model.LeafIdentifier{
         String eventClass();

/**
         * Represents id.
  String severity();

      */
   TestBuilder eventClass(String eventClass);

   ID(1),
      TestBuilder severity(String severity);

 /**
         * Test build();Represents networkId.
    }
}

File : TestBuilder.java
package org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160519.ospf;

import com.google.common.base.MoreObjects;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.onosproject.yangutils.translator.tojava.AugmentedInfo;

public class TestBuilder implements Test.TestBuilder {

    private String eventClass;
    private String severity */
        NETWORKID(2);

        private int leafIndex;

    @Override
    public Stringint eventClassgetLeafIndex() {
            return eventClassleafIndex;
        }

    @Override
    public String severity(LeafIdentifier(int value) {
            return severity;this.leafIndex = value;
        }
    }

    @Override
/**
     *  public TestBuilder eventClass(String eventClass) {Returns the attribute id.
     *
     * @return id this.eventClassvalue =of eventClass;id
     */
    returnshort thisid();

    }

/**
     * @Override
Returns the attribute networkId.
 public TestBuilder severity(String severity) {*
     * @return networkId this.severityvalue =of severity;networkId
     */
   return this; Object networkId();

    }/**

     @Override
* Returns the attribute publicvalueLeafFlags.
   Test build() {*
     * @return valueLeafFlags returnvalue new TestImpl(this);
of valueLeafFlags
     }*/

    publicBitSet TestBuildervalueLeafFlags() {;

    }/**

    public final* classReturns TestImplthe implements Test {

attribute network.
        private List<AugmentedInfo> augmentedInfoList = new ArrayList<>();*
     * @return network privatevalue Stringof eventClass;network
     */
   private StringNetwork severitynetwork();

    /**
    @Override
 * Sets the attribute id.
   public String eventClass() {*
     * @param id value of id
  return eventClass;
  */
    void  }id(short id);

    /**
    @Override
 * Sets the attribute networkId.
   public String severity() {*
     * @param networkId value of networkId
  return severity;
  */
    void  }networkId(Object networkId);

    /**
    @Override
 * Sets the attribute network.
   public int hashCode() {*
     * @param network value of network
   return Objects.hash(eventClass, severity); */
    void    }network(Network network);


    /**
    @Override
 * Checks if the leaf value is set.
 public boolean equals(Object obj) {*
     * @param leaf leaf whose value ifstatus (thisneeds == obj) {to checked
     * @return result of leaf value set    return true;in object
     */
    boolean   }
            if (obj instanceof TestImpl) {
       isLeafValueSet(LeafIdentifier leaf);
}


File : Networks.java
package org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.ietfnetwork.networks;

import java.util.BitSet;

/**
 * Abstraction of an entity which represents the functionality of network.
 */
public interface Network {

    /**
     * Identify the leaf TestImpl other = (TestImpl) obj;of Network.
     */
    public enum LeafIdentifier     return Objects.equals(eventClass, other.eventClass) &&implements org.onosproject.yang.model.LeafIdentifier{
        /**
         * Represents networkId.
    Objects.equals(severity, other.severity);
    */
        }NETWORKID(1);

        private int   return falseleafIndex;

        }

public int getLeafIndex() {
     @Override
       return publicleafIndex;
 String toString() {
     }

       return MoreObjects.toStringHelper(getClass())LeafIdentifier(int value) {
            this.leafIndex = value;
       .add("eventClass", eventClass) }
    }

    /**
     * Returns the attribute networkId.
    .add("severity", severity) *
     * @return networkId value of networkId
     */
    short .toStringnetworkId();

    /**
     * Returns the }attribute valueLeafFlags.

     *
   public TestImpl(TestBuilder builderObject)* {
@return valueLeafFlags value of valueLeafFlags
     */
   this.eventClass =BitSet builderObject.eventClassvalueLeafFlags();

    /**
     * Sets the this.severity = builderObject.severity();attribute networkId.
     *
   }

  * @param networkId value of  @OverridenetworkId
     */
   public void addAugmentationnetworkId(AugmentedInfoshort value) {networkId);


    /**
     * Checks if the leaf value is getAugmentedInfoList().add(value);set.
        }
*
     * @param leaf @Override
leaf whose value status needs to checked
  public List<AugmentedInfo> getAugmentedInfoList() {
* @return result of leaf value set in object
    return augmentedInfoList;*/
    boolean    }

        @Override
        public void removeAugmentation() isLeafValueSet(LeafIdentifier leaf);
}


Identity

Overview

The identity is used to define a new globally unique, abstract, and untyped identity. Its only purpose is to denote its name, semantics, and existence. An identity can iether be defined from scratch or derived from a base identity. The base statement, which is optional, takes as an argument a string that is the name of an existing identity, from which the new identity is derived.

Java mapping

For a given identity one abstract class file will be generated.

Example
Code Block
titleinput YANG file
File : ietf-network.yang
module ietf-network {
            getAugmentedInfoList().clear()yang-version 1;
        }
    }
}

Augment

Overview

Augment means “make (something) greater by adding to it; increase.” in yang augment adds some information in target node. Here in yang, container, list, choice, case, input, output, or notification node can come as a target node.

As the child node of augment node only "container", "leaf", "list", "leaf-list", "uses", and "choice" can come. If augment comes under a module or submodule.

If a target node is a choice node the "case" statement, or a case shorthand statement can be come as a child node of augment node.

If a target node is from some other yang file than a mandatory node which is is one of:

  • A leaf, choice, or anyxml node with a "mandatory" statement with   the value "true".

  • A list or leaf-list node with a "min-elements" statement with a value greater than zero.

  • A container node without a "presence" statement, which has at least one mandatory node as a child.

should not come as a child node of augment node.

Note : A augment node can't add the same augmented info to an augmented node multiple times.

Java mapping

For a given augment node in the yang file one interface file and one builder class file will be generated. Generated files will be having attributes, getters and setters for augment node's child nodes and leaf or leaf-list.

For augment we have given two interface named as “AugmentationHolder” and “AugmentedInfo” as part of yangutils plugin.

File generated for augment node will be implementing AugmentedInfo class.

Node in data model tree which can be augmented as per the yang rules, will be implementing AugmentationHolder class. We have given 3 api in AugmentationHolder class, which are :

addAugmentation(AugmentedInfo augmentedInfo);

removeAugmentation();

getAugmentation();

these apis will be providing augmentation functionalities for augmented nodes. These class will be keeping a list of augmentedInfo , which is nothing but a list of augment nodes which are augmenting this node.

Example
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
    prefix nd;

    identity tunnel-type {
      description  "Base identity from which specific tunnel types are derived.";
    }

}
Code Block
titleGenerated java files
File : TunnelType.java

package org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.ietfnetwork;
/**
 * Represents the implementation of tunnelType.
 */
public abstract class TunnelType {

    /**
     * Returns the attribute tunnel-type.
     *
     * @return tunnel-type value of tunnel-type
     */
    public static String tunnelTypeToString() {
        return "tunnel-type";
    }

    /**
     * Returns the object of tunnelType fromString input String tunnelType.
     *
     * @param valInString value of input String
     * @return tunnelType
     */
    public static Class fromString(String valInString) {
        if (valInString.equals("tunnel-type")) {
            return TunnelType.class;
        }
Code Block
titleInput YANG file
File : Test.yang
module Test {
     yang-version 1;
     namespace "http://huawei.com";
     prefix Ant;
     description "Interval before a route is declared invalid";

     container interface {
        throw new leaf ifType {
                type stringIllegalArgumentException("not a valid input element");
    }
}

Identityref

Overview

The identityref type is used to reference an existing identity. Base statement, which is a substatement to the type statement,  must be present if the type is identityref. The base under identityref must refer to existing identity.

If identityref comes under grouping and typedef, it will be resolved where it is used. It will not be resolved where it is defined.

Java mapping

The leaf or leaf-list with type identityref, will referred to identity, during java file generation.

Example
Code Block
titleinput YANG file
File : ietf-network.yang
module ietf-network {
    yang-version 1;
          }namespace "urn:ietf:params:xml:ns:yang:ietf-network";
    prefix }nd;

    identity augment "/Test/interface" tunnel-type {
      description  "Base identity leaffrom ds0ChannelNumberwhich {
specific tunnel types are derived.";
    }

    container network-id {
 type int16;
      description "Serves as }
top-level container for  }
}
Code Block
titleGenerated Java files
File : AugmentedInterface.java


package org.onosproject.yang.gen.v1.http.huawei.com.rev20160428.test;
import org.onosproject.yangutils.utils.AugmentedInfo;

public interface AugmentedInterface extends AugmentedInfo  {
   
    short getDs0ChannelNumber();
   
    interface AugmentedInterfaceBuilder {
 
a list of networks.";
        leaf leaf-network-id {
            type identityref {
                short getDs0ChannelNumber()base tunnel-type;

          AgmentedInterfaceBuilder setDs0ChannelNumber(short ds0ChannelNumber);
 }
       AugmentedInterface build();}
    }

}
Code Block
titleGenerated java files
File : TunnelType.java

package}

File : AugmentedInterfaceBuilder.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160428.test;
import java.util.Objects;
import com.google.common.base.MoreObjects;
import org.onosproject.yang.gen.v1.http.huawei.com.rev20160428.test.InterfaceBuilder.InterfaceImpl;

public class AugmentedInterfaceBuilder implements AugmentedInterface.AugmentedInterfaceBuilder {
   private short ds0ChannelNumber;urn.ietf.params.xml.ns.yang.ietf.network.ietfnetwork;
/**
 * Represents the implementation of tunnelType.
 */
public abstract class TunnelType {

   @Override /**
   public short getDs0ChannelNumber() {
   * Returns the attribute tunnel-type.
    return ds0ChannelNumber;*
   }

   @Override
   public AugmentedInterfaceBuilder setDs0ChannelNumber(short ds0ChannelNumber)  {* @return tunnel-type value of tunnel-type
     */
    public static  this.ds0ChannelNumber = ds0ChannelNumber;
String tunnelTypeToString() {
        return this"tunnel-type";
    }

   @Override /**
   public  AugmentedInterface* build() {
       return new AugmentedInterfaceImpl(this);
   }

   public AugmentedInterfaceBuilder() {
   }

   public final class AugmentedInterfaceImpl implements AugmentedInterface {
Returns the object of tunnelType fromString input String tunnelType.
     *
     * @param valInString value of input String
     * @return tunnelType
     */
  private short ds0ChannelNumber;

public static Class fromString(String valInString)   @Override{
       public short getDs0ChannelNumber(if (valInString.equals("tunnel-type")) {
            return ds0ChannelNumberTunnelType.class;
        }

        throw new  @Override
   IllegalArgumentException("not a valid input element");
    Public int hashCode() {
           return Objects.hash(ds0ChannelNumber);
       }
}
}
 
File : NetworkId.java

package org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.ietfnetwork;

import java.util.BitSet;

/**
 * Abstraction of an entity which represents the functionality of networkId.
 */
public interface NetworkId {

    /**
     *  @OverrideIdentify the leaf of NetworkId.
     */
    public boolean equals(Object obj) {
enum LeafIdentifier implements org.onosproject.yang.model.LeafIdentifier{
        /**
       if (this ==* obj)Represents {leafNetworkId.
         */
       return trueLEAFNETWORKID(1);

        private int  }leafIndex;

        public int  if (obj instanceof AugmentedInterfaceImplgetLeafIndex() {
            return leafIndex;
  AugmentedInterfaceImpl other = (AugmentedInterfaceImpl) obj;
  }

        LeafIdentifier(int value) {
   return
         this.leafIndex = value;
        }
   Objects.equals(ds0ChannelNumber, other.ds0ChannelNumber); }

    /**
     *  }Returns the attribute leafNetworkId.
     *
     * @return returnleafNetworkId false;
value of leafNetworkId
     }
*/
    Class<? extends TunnelType> @OverrideleafNetworkId();

    /**
   public String toString() {
   * Returns the attribute valueLeafFlags.
     *
    return MoreObjects.toStringHelper(getClass())
      * @return valueLeafFlags value of valueLeafFlags
     */
    BitSet .add("ds0ChannelNumber", ds0ChannelNumber)
valueLeafFlags();

    /**
     * Sets the    .toString();attribute leafNetworkId.
       }*

     * @param PublicleafNetworkId AugmentedInterfaceImpl(AugmentedInterfaceBuilder builderObject) {value of leafNetworkId
     */
    void  this.ds0ChannelNumber = builderObject.getDs0ChannelNumber();leafNetworkId(Class<? extends TunnelType> leafNetworkId);


    /**
     * InterfaceImpl interfaceImpl = new InterfaceBuilder().new InterfaceImpl();Checks if the leaf value is set.
     *
     * @param leaf leaf whose  interfaceImpl.addAugmentation(this);
   value status needs to checked
    }
 *  }
}

Type

Overview

The "type" statement takes as an argument a string that is the name of a YANG built-in type or a derived type, followed by an optional block of sub statements that are used to put further restrictions on the type.

Java mapping

 

...

YANG

...

Description

...

JAVA

...

binary

...

Any binary data

...

To be implemented

...

bits

...

A set of bits or flags

...

To be implemented

...

boolean

...

"True" or "false"

...

boolean

...

decimal64

...

64-bit    signed decimal number

...

To be implemented

...

empty

...

A leaf that does not have any value

...

boolean

...

enumeration

...

Enumerated strings

...

Enum class will be generated

...

identityref

...

A reference to an abstract identity

...

To be implemented

...

instance-identifier

...

References a data tree node

...

To be implemented

...

int8

...

8-bit signed integer

...

byte   

...

int16

...

16-bit signed integer

...

short

...

int32

...

32-bit signed integer

...

int

...

int64

...

64-bit signed integer

...

long   

...

leafref   

...

A reference to a leaf instance

...

To be implemented

...

string   

...

Human-readable string

...

String

...

uint8   

...

8-bit unsigned integer

...

short

...

uint16   

...

16-bit unsigned integer        

...

int   

...

uint32

...

32-bit unsigned integer

...

long   

...

uint64   

...

64-bit unsigned integer

...

BigInteger

...

union   

...

Choice of member types

...

Union  class will be generated

Example
@return result of leaf value set in object
     */
    boolean isLeafValueSet(LeafIdentifier leaf);
}



Bits

Overview

The bits built-in type represents a bit set.  That is, a bits value is a set of flags identified by small integer position numbers starting at 0.

The "bit" statement, which is a substatement to the "type" statement, MUST be present if the type is "bits". It is repeatedly used to specify each assigned named bit of a bits type. It takes as an argument a string that is the assigned name of the bit. All assigned names in a bits type MUST be unique.

The "position" statement, which is optional, takes as an argument a non-negative integer value that specifies the bit's position.

Java mapping

Container BitSet is used to store bits during code generation.

Example 
Code Block
titleinput YANG file
File : test.yang
module Test {
    yang-version 1;
    namespace http://huawei.com;
    prefix Ant;
    typedef MyBits {
Code Block
titleInput YANG file
leaf one {                         
    type string;
}

leaf two {            type bits  {
            
    type int32;
}

leaf-list three {
    type boolean;
}

leaf-list four {bit disable-nagle {
             
    typeposition int160;
}
Code Block
titleGenerated Java file
private String one;

private int two;

private List<Boolean> three;

private List<Short> four;

Typedef

Overview

Typedef is user defined type for his implementation. It has the base type which is must for typedef. To give more information about the typedef there should be sub statements to describe it. Unit statement is optional for typedef which give info about the unit of the type. Default is like a value which will be assigned to the typedef if no value is given.default value should follow all restriction defined for the base-type.

Java mapping

For a given typedef node one class file will be generated which will have an attribute with the base type of typedef. There will be a constructor and a getter method, of method and implementation of hashcode, equals and toString methods.

Example
Code Block
titleInput YANG file
File : test.yang

module test {

    yang-version             }
             bit auto-sense-speed {
                 position 1;
    namespace "http://huawei.com";
        prefix "test";
}
    typedef percent {
       bit type uint8;
Mb-only {
             description "Percentage"    position 2;
       }

    leaf completed {}
        type percent;}
    }
}

 

Code Block
titleGenerated Java filebits generated enum
File : PercentBits.java

package org.onosproject.yang.gen.v1.http.huawei.com.rev20160526test.testmybits;

import java.util.Objects;
import com.google.common.base.MoreObjects;

public final class Percent {

    private short uint8;

    private Percent() {
    }


    public Percent(short value) {.util.BitSet;
import java.util.regex.Pattern;

/**
 * Represents ENUM data of bits.
 */
public enum Bits {

    /**
     * Represents disable-nagle.
     */
    DISABLE_NAGLE(0, "disable-nagle"),

    /**
     * Represents auto-sense-speed.
     */
    AUTO_SENSE_SPEED(1, "auto-sense-speed"),

    /**
     * Represents mb-only.
     */
   this.uint8 = value;
    }

    public static Percent of(short value) { MB_ONLY(2, "Mb-only");

    private int bits;
    private String schemaName;

    /**
     * Creates an returninstance new Percent(value);
of bits.
     }*

     * @param publicbits shortvalue uint8()of {bits
     */
    return uint8;
    }

 Bits(int bits, String schemaName) {
    @Override
    public int hashCode() {this.bits = bits;
        return Objects.hash(uint8)this.schemaName = schemaName;
    }

    @Override/**
    public boolean* equals(Object obj) {
   Returns the object of bits for.
     if*
 (this == obj) {
 * @param value value of bits for
     return* true;
@return bits for
      }*/
    public static Bits  if of(objint instanceof Percentvalue) {
            Percent other =switch (Percentvalue) obj;{
            return Objects.equals(uint8, other.uint8);case 0:
        }
        return falseBits.DISABLE_NAGLE;
    }

        case @Override1:
    public  String toString() {
        return MoreObjects.toStringHelper(getClass())Bits.AUTO_SENSE_SPEED;
            .add("uint8", uint8)
case 2:
               .toString() return Bits.MB_ONLY;
    }

    public static Percent fromString(String valInString)default {:
        try {
       throw     short tmpVal = Short.parseShort(valInStringnew IllegalArgumentException("not a valid input element");
        }
    return of(tmpVal);}
    /**
     * Returns the object of }bits catchfor.
 (Exception e) {
  *
     * @param value }
value of bits for
     * @return returnbits null;for
    }
}

Enumeration

Overview

Enum statement only can come when a leaf is of type enumeration. Each enum has one string then should be unique . The string must not be empty string and must not have white spaces. Enum can have sub statements, value statement will give the info about its value. If the enum statement in enumeration has no value statement then its value is considered as zero and subsequently incremented by one for next values.

Java mapping

For a given enumeration node one enum file will be generated which will have all the enum as its attributes. There will be a constructor and a getter method for the values.

Example
Code Block
titleInput YANG file
File: test.yang
module Test {

    yang-version 1; */
    public static Bits of(String value) {
    namespace "http://huawei.com";
   switch prefix Ant;(value) {
    description   "Interval before a route is declared invalid";

 case "disable-nagle":
   leaf  packetType {
         type enumeration {return Bits.DISABLE_NAGLE;
             enumcase "unbounded";
auto-sense-speed":
               enum ZERO return Bits.AUTO_SENSE_SPEED;
            enum two;case "Mb-only":
             enum four;
   return Bits.MB_ONLY;
            default :
            }    throw new IllegalArgumentException("not a valid input element");
        }
}
Code Block
titleGenerated Java files
File : PacketTypeEnum.java

package org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.test;

public enum PacketTypeEnum {

    UNBOUNDED(0),

    ZERO(1),

    TWO(2),

    FOUR(3);

    private int packetTypeEnum;

    PacketTypeEnum(int value    }
    /**
     * Returns the attribute bits.
     *
     * @return bits value of bits
     */
    public int bits() {
        packetTypeEnumreturn = valuebits;
    }

     public static PacketTypeEnum of(int value) {/**
     * Returns the object of bits fromString input String bits.
     *
     switch* @param valInString (value) {
 of input String
     * @return bits
     */
 case 0:
        public static BitSet fromString(String valInString) {
        BitSet tmpVal = return PacketTypeEnum.UNBOUNDEDnew BitSet();
        String[] bitNames =  case 1:
      valInString.trim().split(Pattern.quote(" "));
        for (String bitName : bitNames) {
            Bits bits return PacketTypeEnum.ZERO= of(bitName);
            if (bits != casenull) 2:{
                tmpVal.set(bits.bits());
      return PacketTypeEnum.TWO;
     }
       case 3:}
        if (tmpVal.isEmpty()) {
            return PacketTypeEnum.FOUR;
     throw new IllegalArgumentException("not a valid input element");
       default :}
        return tmpVal;
    }
    public static String toString(BitSet returnbits) null;{
        StringBuilder sBuild =  }new StringBuilder("");
    }


    public int packetTypeEnum()if (bits.get(Bits.DISABLE_NAGLE.bits())) {
            return packetTypeEnumsBuild.append("disable-nagle");
    }

     public static PacketTypeEnum fromStringsBuild.append(String" valInString") {;
        }
    try {
   if (bits.get(Bits.AUTO_SENSE_SPEED.bits())) {
           int tmpVal = Integer.parseInt(valInStringsBuild.append("auto-sense-speed");
                return of(tmpValsBuild.append(" ");
        }
       } catch (Exception eif (bits.get(Bits.MB_ONLY.bits())) {
        }
    sBuild.append("Mb-only");
    return null;
    }
}

Union

Overview

Union is a built in type which represents its member types. Union can have multiple member types. To use union there must be a type statement. Except empty and leafref all types can come under union.

When a value comes for union , which can match to multiple member types of union, then in that case to whichever type value matches from the member types defined in union value, will be taken from union as the values type.

Java mapping

For a given union node one class file will be generated which will have all the an attribute with the type union is having. There will be a constructor , getter method, of method, fromString, HashCode, equals and ToString methods for the values.

Example
Code Block
titleInput YANG file
File : test.yang
module test {
    yang-version 1;
    namespace "http://huawei.com";
    prefix "test";

    typedef ip-address          sBuild.append(" ");
        }
        return sBuild.toString();
    }
}
 
 
File: MyBits.java

package org.onosproject.yang.gen.v1.http.huawei.com.test;

import java.util.BitSet;
import org.onosproject.yang.gen.v1.http.huawei.com.test.mybits.Bits;
import java.util.Objects;

/**
 * Represents the implementation of myBits.
 */
public final class MyBits {

    private BitSet bits;

    /**
     * Creates an instance of myBits.
     */
    private MyBits() {
    }

    type/**
 union {
   * Creates an instance of bits.
    type int32;*
     * @param bits value of bits
    type uint32;*/
    public MyBits(BitSet bits) {
  }
    }
}
Code Block
titleGenerated java files
File : IpAddressUnion.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.test.ipaddress;

import java.util.Objects;
import com.google.common.base.MoreObjects;

public final class IpAddressUnion {

    private int int32;
    private long uint32;

    private IpAddressUnion() {
    }

    public IpAddressUnion(int value) {this.bits = bits;
    }

    /**
     * Returns the object of myBits for type bits.
     *
     * @param value value of myBits for type bits
     * @return myBits this.int32for =type value;bits
    } */

    public static MyBits IpAddressUnionof(longBitSet value) {
        return this.uint32 = valuenew MyBits(value);
    }

    public static IpAddressUnion of(int value) {
   /**
     * Returns the attribute bits.
     *
     return* @return newbits IpAddressUnion(value);value of bits
    } */

    public staticBitSet IpAddressUnion of(long valuebits() {
        return new IpAddressUnion(value)bits;
    }
    /**
     * Sets the attribute bits.
 public  int int32() {*
     * @param bits return int32;value of bits
    }
 */
    public longvoid uint32bits(BitSet bits) {
        this.bits return= uint32bits;
    }

    @Override
    public int hashCode() {
        return Objects.hash(int32, uint32bits);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof IpAddressUnionMyBits) {
            IpAddressUnionMyBits other = (IpAddressUnionMyBits) obj;
            return
                 Objects.equals(int32bits, other.int32) &&
                 Objects.equals(uint32, other.uint32)bits);
        }
        return false;
    }

    @Override
    public String toString() {
        return MoreObjectsBits.toStringHelpertoString(getClass(bits));
    }
        .omitNullValues()/**
     * Returns the object of   .add("int32", int32)
  myBits fromString input String myBits.
     *
     .add("uint32", uint32)
     * @param valInString value of input String
     * @return .toString();myBits
     }*/

    public static IpAddressUnionMyBits fromString(String valInString) {
        try {
          int  BitSet tmpVal = IntegerBits.parseIntfromString(valInString);
            return of(tmpVal);
        } catch (Exception e) {
        }
    throw new IllegalArgumentException("not a valid try {input element");
        }
   long tmpVal = Long.parseLong(valInString);
          return of(tmpVal);
        } catch (Exception e) }
}
 



Binary

Overview

The binary built-in type represents any binary data, i.e., a sequence of octets.

A binary can be restricted with the "length" statement. The length of a binary value is the number of octets it contains.

Binary values are encoded with the base64 encoding scheme.

Java mapping

Byte array is used to store decoded binary during code generation.

Example
Code Block
titleinput YANG file
File : test.yang
module Test {
   yang-version 1;
   namespace http://huawei.com;
   prefix Ant;

   typedef MyBinary {
      type binary {
        }
 length "4";
      return null;}
   }
}

 

Code Block
titleGenerated Java java files
File : FlowClassifierServiceMyBinary.java
package org.onosproject.yang.gen.v1.http.sfchuawei.com.flowclassifierrev20160718.rev20160524test;

import orgjava.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20100924.ietfyangtypes.Uuid;

public interface FlowClassifierService {

    Uuid getId();

    void setId(Uuid id);
}

File : FlowClassifierManager.java
package org.onosproject.yang.gen.v1.sfc.flowclassifier.rev20160524;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20100924.ietfyangtypes.Uuid;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;

@Component (immediate = true)
@Service
public class FlowClassifierManager implements FlowClassifierService {

    private final Logger log = getLogger(getClass());

    @Activate
    public void activate() {
util.Objects;
import com.google.common.base.MoreObjects;
import java.util.Base64;

public final class MyBinary {
   private byte[] binary;
   private MyBinary() {
   }

   public MyBinary(byte[] value) {
      this.binary = value;
   }

   public static MyBinary of(byte[] value) {
      return new MyBinary(value);
   }
 
   public byte[] binary() {
      return binary;
   }
 
   @Override
   public int hashCode() {
      return Objects.hash(binary);
   }
 
   @Override
   public boolean equals(Object obj) {
      if (this == obj) {
         return true;
      }
      if (obj instanceof MyBinary) {
         //TODO: YANG utils generated codeMyBinary other = (MyBinary) obj;
        log.info("Started" return Objects.equals(binary, other.binary);
      }

    @Deactivate
   return publicfalse;
 void deactivate() {}
 
   @Override
   public //TODO: YANG utils generated codeString toString() {
        log.info("Stopped"return Base64.getEncoder().encodeToString(binary);
    }

    @Override
   public publicstatic UuidMyBinary getIdfromString(String valInString) {
      try {
 //TODO: YANG utils generated code
    byte[] tmpVal =  return null;
Base64.getDecoder().decode(valInString);
      }

   return @Overrideof(tmpVal);
    public  } voidcatch setId(UuidException ide) {
      }
  //TODO:  YANG utils generatedreturn codenull;
    }

}

File : IetfYangTypesService.java
package org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20100924;

public interface IetfYangTypesService {
}

File : IetfYangTypesManager.java
package org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20100924;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;

@Component (immediate = true)
@Service
public class IetfYangTypesManager implements IetfYangTypesService {

    private final Logger log = getLogger(getClass());

    @Activate
    public void activate() 


Decimal64

Overview

The decimal64 type represents a subset of the real numbers, which can be represented by decimal numerals.

A decimal64 type can be restricted with the "range" statement.

The "fraction-digits" statement, which is a substatement to the "type" statement, MUST be present if the type is "decimal64".  It takes as an argument an integer between 1 and 18, inclusively. It controls the size of the minimum difference between values of a decimal64 type.

The Minimum and Maximum decimal64 value table for each fraction-digit value.

fraction-digitsminmax
1-922337203685477580.8922337203685477580.7
2-92233720368547758.0892233720368547758.07
3-9223372036854775.8089223372036854775.807
4-922337203685477.5808922337203685477.5807
5-92233720368547.7580892233720368547.75807
6-9223372036854.7758089223372036854.775807
7-922337203685.4775808922337203685.4775807
8-92233720368.5477580892233720368.54775807
9-9223372036.8547758089223372036.854775807
10-922337203.6854775808922337203.6854775807
11-92233720.3685477580892233720.36854775807
12-9223372.0368547758089223372.036854775807
13-922337.2036854775808922337.2036854775807
14-92233.7203685477580892233.72036854775807
15-9223.3720368547758089223.372036854775807
16-922.3372036854775808922.3372036854775807
17-92.2337203685477580892.23372036854775807
18-9.2233720368547758089.223372036854775807
Java mapping

BigDecimal is used to store decimal64 value during code generation.

Example


Code Block
titleinput YANG file
File : test.yang
module Test {
    yang-version 1;
    namespace http://huawei.com;
    prefix Ant;

    typedef MyDecimal {
        

...

type decimal64 {
        

...

    

...

fraction-digits 2;
    

...

 

...

 

...

 

...

     range "1 

...

.. 3.14 | 10 | 20..max";
        

...

}
    }
}

...

Code Block
titleGenerated java files
File: 

...

MyDecimal.java
package org.onosproject.yang.gen.v1.

...

http.

...

huawei.

...

com.

...

rev20160718.test;
import java.math.BigDecimal;
import java.util.Objects;
import com.google.common.base.MoreObjects;

public final class 

...

MyDecimal {
    private 

...

BigDecimal 

...

decimal64;

    private 

...

MyDecimal() {
    }

    public 

...

MyDecimal(

...

BigDecimal value) {
        this.

...

decimal64 = value;
    }

    public static 

...

MyDecimal of(

...

BigDecimal value) {
        return new 

...

MyDecimal(value);
    }

    public 

...

BigDecimal 

...

decimal64() {
        return 

...

decimal64;
    }

    @Override
    public int hashCode() {
        return Objects.hash(

...

decimal64);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof 

...

MyDecimal) {
            

...

MyDecimal other = (

...

MyDecimal) obj;
            return
                 Objects.equals(

...

decimal64, other.

...

decimal64);
        }
        return false;
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(getClass())
            .add("

...

decimal64", 

...

decimal64)
            .toString();
    }

    public static 

...

MyDecimal fromString(String valInString) {
        try {
            

...

BigDecimal tmpVal = new BigDecimal(valInString);
            return of(tmpVal);
        } catch (Exception e) {
        }
        return null;
    }
}
 

Unknown Statement

Overview
If a YANG compiler does not support a particular extension, which appears in a YANG module as an unknown-statement, 
the entire unknown-statement is ignored by the onos-yang-tools and it is logged.

Golden Eye Demo 

Link:   https://www.youtube.com/watch?v=ipbu0x0LcDk  

Presentation: YANG Demo.pptx

Note :

In case of typedef or identity when both have same name, But follow different typographical conventions is supported in compilation (It is limited to only one pair of identity and typedef naming conflict), other then that any name conflict is not supported as of now.

References

RFC6020 - https://tools.ietf.org/html/rfc6020