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

Requirements for Hummingbird Release

Requested ByRequirementsSuggested Priority (high - Middle -Low)Current Status
Thomas Vachuska
Thanks for the demo of the YANG utilities at today’s TST meeting. While a lot of good work was done in the last release, I was a little bit surprised that the codec functionality was pushed off to the next release - and that NB-related concerns superseded SB-related ones. In my view, this is the basic value of using the YANG models - as it provides the ability to consume/produce XML payloads that are complaint with the model in a structured manner via Java API.
We have a set of use-cases for this to control/configure devices via NETCONF. Presently we have to accomplish this using hand-crafted XML and we were hoping to use the YANG tools-generated codecs for this. Consequently the SB use of YANG is of much more importance to us than the NB use of YANG - at least for the near-term.
In the Hummingbird release we need to be able to use the YANG tools generated artifacts together with our existing NETCONF sub-controller to produce driver implementations for several packet and optical devices. For this reason, I would like to request that this work be prioritized over anything else with respect to other YANG-related work. In order for that to happen, I think a number of other important questions will have to be answered and accounted for in the overall design of the YANG utilities:
  • Generated code for device models needs to be able to facilitate interactions with multiple devices that support the same model. This means that generated code should be stateless and avoid singleton service pattern. It should also take care not to intertwine transport concerns with encoding concerns (it should really only cover the latter).
  • Generated code should avoid commingling of code that is pure codec and not expected to be touched by humans versus RPC skeletal code whose innards are expected to be manually ‘implemented’ by humans and checked-in. This should simplify code re-generation as the model evolves
Highreviewing
Ali Al-ShabibiJSON or JSON-Schema Intermediary Representation. It would be nice if we could go from YANG to JSON or JSON-Schema because from this IR format we can easily go to XML or JSON or some other format that another protocol may want to use. As you probably know, Netconf is only one of the southbound to deliver payloads other ones such as gRPC or REST can be used.medium 
Marc De Leenheer

Support for OpenROADM YANG models. The specification contains two parts, a service-level model (NB) and a device-level model (SB). The first phase has already started, we want to integrate the device model into ONOS by early Q3 2016. In Q4 we will do the service level models. This is high priority work in collaboration with AT&T.

http://openroadm.org/home.html

high 
Aihua GuoIn order to support the use of standard IETF YANG models as an NBI for hierarchical SDN control, it is expected that the following YANG data constructs be supported in the H releases: augment (partially supported in G release), identity, feature/if-feature, when, must, leafref, path, require-instance. These data constructs are defined by YANG 1.1, and most of the IETF YANG models contain those constructs written in YANG 1.1.high 


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 are the basic building block to achieve the final goal of abstracting the language based Syntax/Semantics processing by APPs.

 Image Modified

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

  1. syntax/semantics processing of the request/response being exchanged. 
  2. 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 utils

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

Code Block
<build>
  <plugins>
    <plugin>
      <groupId>org.onosproject</groupId>
      <artifactId>yangutils-maven-plugin</artifactId>
      <version>1.0.0-SNAPSHOT</version>
      <executions>
        <execution>
          <configuration>
          </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-datamodel</artifactId>
        <version>1.7.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.onosproject</groupId>
        <artifactId>yangutils-javamodel</artifactId>
        <version>1.7.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>

Step 3 : Plugin configuration supported in YANG utils 

  1. Create a folder structure as “src/main/yang” in the test app folder and place your YANG files in it. 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>
        <yangFilesDir>DesiredYangFilesPath</yangFilesDir>
        <genFilesDir>DesiredGeneratedJavaFilesPath</genFilesDir> 
    </configuration>
  2. Plugin provides user to give configuration if he wants to generate manager/service classes or not. for this if he do not wants to generate service and manager classes he can set flag to "sbi" , and plugin will not generate manager/service classes.
     

    Code Block
    <configuration>
        <generateJavaFileForsbi>sbi</generateJavaFileForsbi>
    </configuration>

Step 4 : Execution  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:

  1. If user does not provide any configurations for code generation , code will be generated in 2 different packages. Manager class will be generate in default "src/main/java" package and other classes including service interface will be generated in "target/generated-sources" folder.
  2. If a yang file contains only typedef/grouping nodes , there will not be any generation of manager class.
Info
titleCode generated is as per ONOS coding guidelines.

 

YANG utils constructs support/plan

YANG ConstructSupported/Planned version
anyxmlNot planned
argumentHummingbird
augmentGoldeneye
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
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-byNot planned
organization

Goldeneye

Enhancement in Hummingbird
outputGoldeneye
pathHummingbird
patternGoldeneye
positionGoldeneye
prefixGoldeneye
presenceGoldeneye
rangeGoldeneye
reference

Goldeneye

Enhancement in Hummingbird
refineNot planned
require-instanceHummingbird
revision

Goldeneye

Enhancement in Hummingbird
revision-date

Goldeneye

rpcGoldeneye
status

Goldeneye

Enhancement in Hummingbird
submoduleGoldeneye
typeGoldeneye
typedefGoldeneye
uniqueNot Planned
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 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-l.e_nder will be mapped to caLeNder
      • tric-._k will be mapped to trick  
  • If users input has capital case, the following will be the conversion methods.

    • TESTNAME will be mapped to testname

    • TEST-NAME will be mapped to 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.

 

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. The conversion from YANG namespace to the java package will take place as below.

    • 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
  • 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.";
     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 {
                 type string;
                 description
                     "Message given at start of login session";
             }
        }
    }
    .
    .
    .
}

...

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

File : Login.java
package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.system;
    .
    .
    .
public interface Login extends AugmentationHolder  {
    .
    .
    .
}

Javadocs

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

Info
titleHere 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  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
Code Block
titleInput YANG file
File : network.yang
  module network {
     yang-version 1;
     namespace "urn:TBD:params:xml:ns:yang:nodes";
     prefix nd;

     organization "TBD";
     contact
       "WILL-BE-DEFINED-LATER";
     description
       "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.";

     revision 2014-03-09 {
       description
         "Initial revision.";
       reference "draft-clemm-i2rs-yang-network-topo-04";
     }
     
     list networklist {
       key "network-id";

       leaf network-id {
         type string;
       }

       leaf server-provided {
         type boolean;
         config false;
       }
     }
     ….
}
Code Block
titleGenerated Java files
File : NetworkService.java

package org.onosproject.yang.gen.v1.urn.tbd.params.xml.ns.yang.nodes.rev20140309;

public interface NetworkService {
    Network getNetwork();
    void setNetwork(Network network);
}


File : NetworkManager.java
package org.onosproject.yang.gen.v1.urn.tbd.params.xml.ns.yang.nodes.rev20140309;
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 NetworkManager implements NetworkService {
    private final Logger log = getLogger(getClass());
    @Activate
    public void activate() {
        //TODO: YANG utils generated code
        log.info("Started");
    }
    @Deactivate
    public void deactivate() {
        //TODO: YANG utils generated code
        log.info("Stopped");
    }
    @Override
    public Network getNetwork() {
        //TODO: YANG utils generated code
        return null;
    }
    @Override
    public void setNetwork(Network network) {
        //TODO: YANG utils generated code
    }
}
 
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;
public interface Network {
    List<Networklist> networklist();
    interface NetworkBuilder {
        List<Networklist> networklist();
        NetworkBuilder networklist(List<Networklist> networklist);
        Network build();
    }
}
 
File:DefaultNetwork.java
 

package org.onosproject.yang.gen.v1.urn.tbd.params.xml.ns.yang.nodes.rev20140309;
import com.google.common.base.MoreObjects;
import java.util.List;
import java.util.Objects;
import org.onosproject.yang.gen.v1.urn.tbd.params.xml.ns.yang.nodes.rev20140309.network.Networklist;
public class DefaultNetwork implements Network {
    protected List<Networklist> networklist;
    @Override
    public List<Networklist> networklist() {
        return networklist;
    }
    @Override
    public int hashCode() {
        return Objects.hash(networklist);
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof DefaultNetwork) {
            DefaultNetwork other = (DefaultNetwork) obj;
            return
                 Objects.equals(networklist, other.networklist);
        }
        return false;
    }
    @Override
    public String toString() {
        return MoreObjects.toStringHelper(getClass())
            .add("networklist", networklist)
            .toString();
    }
    public DefaultNetwork(NetworkBuilder builderObject) {
        this.networklist = builderObject.networklist();
    }
    public class NetworkBuilder implements Network.NetworkBuilder {
        protected List<Networklist> networklist;

        @Override
        public List<Networklist> networklist() {
            return networklist;
        }
        @Override
        public NetworkBuilder networklist(List<Networklist> networklist) {
            this.networklist = networklist;
            return this;
        }
        @Override
        public Network build() {
            return new DefaultNetwork(this);
        }
        public NetworkBuilder() {
        }
    }
} 
Code Block
titleInput YANG file
File : network.yang with an augment node.
  module network {
     yang-version 1;
     namespace "urn:TBD:params:xml:ns:yang:nodes";
     prefix nd;
     organization "TBD";
     contact
       "WILL-BE-DEFINED-LATER";
     description
       "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.";
     revision 2014-03-09 {
       description
         "Initial revision.";
       reference "draft-clemm-i2rs-yang-network-topo-04";
     }
     
     list networklist {
       key "network-id";
       leaf network-id {
         type string;
       }
       leaf server-provided {
         type boolean;
         config false;
       }
     }
    
     augment /networklist {
          leaf network-ip {
              type int32;
          }
     }
     ....
}

 

Code Block
titleGenerated Java files
File : NetworkService.java
package org.onosproject.yang.gen.v1.urn.tbd.params.xml.ns.yang.nodes.rev20140309;
public interface NetworkService {
    Network getNetwork();
    void setNetwork(Network network);
    Network getAugmentedNetworkNetworklist();
	
    void setAugmentedNetworkNetworklist(Network augmentedNetworkNetworklist);
}
File : NetworkManager.java
 
package org.onosproject.yang.gen.v1.urn.tbd.params.xml.ns.yang.nodes.rev20140309;
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 NetworkManager implements NetworkService {
    private final Logger log = getLogger(getClass());
    @Activate
    public void activate() {
        //TODO: YANG utils generated code
        log.info("Started");
    }
    @Deactivate
    public void deactivate() {
        //TODO: YANG utils generated code
        log.info("Stopped");
    }
    @Override
    public Network getNetwork() {
        //TODO: YANG utils generated code
        return null;
    }
    @Override
    public void setNetwork(Network network) {
        //TODO: YANG utils generated code
    }
    @Override
    public Network getAugmentedNetworkNetworklist() {
        //TODO: YANG utils generated code
        return null;
    }
    @Override
    public void setAugmentedNetworkNetworklist(Network augmentedNetworkNetworklist) {
        //TODO: YANG utils generated code
    }
}
 
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;
public interface Network {
    List<Networklist> networklist();
    interface NetworkBuilder {
        List<Networklist> networklist();
        NetworkBuilder networklist(List<Networklist> networklist);
        Network build();
    }
}
 
File:DefaultNetwork.java
 
package org.onosproject.yang.gen.v1.urn.tbd.params.xml.ns.yang.nodes.rev20140309;
import com.google.common.base.MoreObjects;
import java.util.List;
import java.util.Objects;
import org.onosproject.yang.gen.v1.urn.tbd.params.xml.ns.yang.nodes.rev20140309.network.Networklist;
public class DefaultNetwork implements Network {
    protected List<Networklist> networklist;
    @Override
    public List<Networklist> networklist() {
        return networklist;
    }
    @Override
    public int hashCode() {
        return Objects.hash(networklist);
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof DefaultNetwork) {
            DefaultNetwork other = (DefaultNetwork) obj;
            return
                 Objects.equals(networklist, other.networklist);
        }
        return false;
    }
    @Override
    public String toString() {
        return MoreObjects.toStringHelper(getClass())
            .add("networklist", networklist)
            .toString();
    }
    public DefaultNetwork(NetworkBuilder builderObject) {
        this.networklist = builderObject.networklist();
    }
    public class NetworkBuilder implements Network.NetworkBuilder {
        protected List<Networklist> networklist;

        @Override
        public List<Networklist> networklist() {
            return networklist;
        }
        @Override
        public NetworkBuilder networklist(List<Networklist> networklist) {
            this.networklist = networklist;
            return this;
        }
        @Override
        public Network build() {
            return new DefaultNetwork(this);
        }
        public NetworkBuilder() {
        }
    }
}

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;
        }
    }
}
Code Block
titleGenerated Java files
File : AcmeSystemManager.java
package org.onosproject.yang.gen.v1.http.yang.central.org.ns.example.acme.rev20160720;
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() {
        //TODO: YANG utils generated code
        log.info("Started");
    }
    @Deactivate
    public void deactivate() {
        //TODO: YANG utils generated code
        log.info("Stopped");
    }
    @Override
    public AcmeSystem getAcmeSystem() {
        //TODO: YANG utils generated code
        return null;
    }
    @Override
    public void setAcmeSystem(AcmeSystem acmeSystem) {
        //TODO: YANG utils generated code
    }
}

File : AcmeSystemService.java

package org.onosproject.yang.gen.v1.http.yang.central.org.ns.example.acme.rev20160720;
public interface AcmeSystemService {
    AcmeSystem getAcmeSystem();
    void setAcmeSystem(AcmeSystem acmeSystem);
}

File : AcmeTypesManager.java

package org.onosproject.yang.gen.v1.http.yang.central.org.ns.example.acme.rev20160720;
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() {
        //TODO: YANG utils generated code
        log.info("Started");
    }
    @Deactivate
    public void deactivate() {
        //TODO: YANG utils generated code
        log.info("Stopped");
    }
    @Override
    public AcmeTypes getAcmeTypes() {
        //TODO: YANG utils generated code
        return null;
    }
    @Override
    public void setAcmeTypes(AcmeTypes acmeTypes) {
        //TODO: YANG utils generated code
    }
}

File : AcmeTypesService.java
package org.onosproject.yang.gen.v1.http.yang.central.org.ns.example.acme.rev20160720;


public interface AcmeTypesService {
    AcmeTypes getAcmeTypes();
    void setAcmeTypes(AcmeTypes acmeTypes);
}

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 : FlowClassifierManager.java

there will be no manager file generation because flowclassifier yang only contains one leaf.
File : FlowClassifierService

package org.onosproject.yang.gen.v1.sfc.flowclassifier.rev20160524;
public interface FlowClassifierService {

    FlowClassifier getFlowClassifier();
    void setFlowClassifier(FlowClassifier flowClassifier);
}

File : IetfYangTypesManager.java

there will be no manager file generation because yang files contains only typedef.
File : IetfYangTypesService.java

package org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20130715;

public interface IetfYangTypesService {
    IetfYangTypes getIetfYangTypes();
    void setIetfYangTypes(IetfYangTypes ietfYangTypes);
}
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;
    }
}

 

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  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 {
    String hostName();
    interface SystemBuilder {
        String hostName();
        SystemBuilder hostName(String hostName);
        System build();
    }
}

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.HashMap;
import java.util.Map;
import java.util.Objects;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;

public class DefaultSystem implements System {
    private Map<Class<?>, YangAugmentedInfo> yangAugmentedInfoMap = new HashMap<>();
    protected 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 {
    String hostName();
    interface SystemBuilder {
        String hostName();
        SystemBuilder hostName(String hostName);
        System build();
    }
}

File : DefaultSystem.java
public class DefaultSystem implements System {
    private Map<Class<?>, YangAugmentedInfo> yangAugmentedInfoMap = new HashMap<>();
    protected String hostName;
    @Override
    public String hostName() {
        return hostName;
    }
   .
   .
   .
}

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.
  2. Builder Class File
    It includes:
    a) Builder class which is the implementation of builder interface defined in interface file.
    b) Impl  Impl class which is the implementation of interface file. 
    c) hashCode(), equals(), toString() methods overridden in it. 
  3. OpParam class File:
    it inlcudes:
    a) Operation types for restconf/netconf operations.
    b) setter method for leaf and leaf list if present.
    c) isFilterContentMatch() method for matching the contents if they are set in object or not.
    d) setter and getter for bitset values of present leaves/leaf-lists.
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 {
         container login {
             leaf message {
                 type string;
                 description
                     "Message given at start of login session";
             }
        }
    }
    .
    .
    .
}

 

Code Block
titleGenerated Java files
File : System.java
 
package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem;
import org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.system.Login;
public interface System {
    Login login();
    interface SystemBuilder {
        Login login();
        SystemBuilder login(Login login);
        System build();
    }
}

 
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.HashMap;
import java.util.Map;
import java.util.Objects;
import org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.system.Login;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;

public class DefaultSystem implements System {

    private Map<Class<?>, YangAugmentedInfo> yangAugmentedInfoMap = new HashMap<>();
    protected Login login;

    @Override
    public Login login() {
        return login;
    }

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

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

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

    public DefaultSystem(SystemBuilder builderObject) {
        this.login = builderObject.login();
    }

    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;
    }

    public class SystemBuilder implements System.SystemBuilder {

        protected Login login;


        @Override
        public Login login() {
            return login;
        }

        @Override
        public SystemBuilder login(Login login) {
            this.login = login;
            return this;
        }
        @Override
        public System build() {
            return new DefaultSystem(this);
        }

        public SystemBuilder() {
        }
    }
}

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 {
   
 
File: SystemOpParam.java

package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem;
import org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.system.Login;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
import org.onosproject.yangutils.datamodel.YangAugmentedOpParamInfo;
import java.util.BitSet;
public class SystemOpParam extends DefaultSystem  {
    public static enum OperationType {
        MERGE,
        REPLACE,
        CREATE,
        DELETE,
        REMOVE
    }
    private OperationType opParamType;

    public OperationType getOpertionType() {
        return key "name"opParamType;
    }
    public boolean   leaf nameisFilterContentMatch(Object obj) {
        DefaultSystem appInstance = (DefaultSystem)obj;
     type string;
  for (YangAugmentedInfo yangAugmentedInfo : this.getYangAugmentedInfoMap().values()) {
     }
       if (!(yangAugmentedInfo  instanceof  leaf full-name YangAugmentedOpParamInfo)) {
                typethrow string;
            }new IllegalArgumentException("provided augmented info is invalid for content match.");
            leaf class {}
            YangAugmentedInfo yangAugmentedOpParamInfo =  type string;appInstance
            }.getAugmentedInfo(((YangAugmentedOpParamInfo) yangAugmentedInfo).getBaseClass());
        }
    if(!((YangAugmentedOpParamInfo) yangAugmentedInfo).isFilterContentMatch(yangAugmentedOpParamInfo)) {
  leaf name {
            typereturn stringfalse;
        }
    }
    .
    .}
      .
}
Code Block
titleGenerated Java files
File : Login.java

package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem;
import java.util.List;
public interface Login {

 return true;
    }
    Stringpublic nameSystemOpParam(SystemOpParamBuilder builderObject); {
     List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login.Login> login(   super(builderObject);
    interface LoginBuilder {
}
    public class SystemOpParamBuilder extends String name();DefaultSystem.SystemBuilder {
        List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login.Login> login()private OperationType opParamType;
        LoginBuilderpublic OperationType namegetOpertionType(String) name);
{
            LoginBuilder login(List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystemreturn opParamType;
        }
        .login
public void setOpertionType(OperationType operationType) {
            this.Login> login);
opParamType = operationType;
        Login build();}
    }
}

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.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;

public class DefaultLogin implements Login {

    private Map<Class<?>, YangAugmentedInfo> yangAugmentedInfoMap = new HashMap<>();
    protected String name;
    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 List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login.Login> login() 

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 {
        returnkey login"name";
    }

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

    @Override
    publicleaf boolean equals(Object obj) name {
        if (this == obj) {
    type string;
       return true;
    }
    }
        if (obj instanceof DefaultLogin) leaf full-name {
             DefaultLogin other = (DefaultLogin)type objstring;
            return}
            leaf class    Objects.equals(name, other.name) &&
{
                type string;
   Objects.equals(login, other.login);
        }
        return false;}
    }

    @Override
leaf name {
  public String toString() {
        return MoreObjects.toStringHelper(getClass())type string;
        }
    .add("name", name)}
    .
    .
    .
}
Code Block
titleGenerated Java files
File : Login.java

package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem;
import java.util.List;
public interface Login {

add("login", login)
           String .toStringname();
    }
List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login.Login> login();
    publicinterface DefaultLogin(LoginBuilder builderObject) {

        String this.name = builderObject.name();
        this.login = builderObject.List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login.Login> login();
    }

    publicLoginBuilder void addAugmentedInfoname(YangAugmentedInfo value, Class classObject) {String name);
        yangAugmentedInfoMap.put(classObject, value);LoginBuilder login(List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem
    }

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

    public Map<Class<?>, YangAugmentedInfo> getYangAugmentedInfoMap() { .Login> login);

        returnLogin yangAugmentedInfoMapbuild();
    }
}

File    public class LoginBuilder implements Login.LoginBuilder {

        protected String name;
        protected List<org: DefaultLogin.java


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


        @Overrideimport com.google.common.base.MoreObjects;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;

public class DefaultLogin implements Login {

    private Map<Class<?>, YangAugmentedInfo> yangAugmentedInfoMap public= Stringnew nameHashMap<>() {;
    protected String name;
    protected  return name;List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login.Login> login;

    @Override
    }

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

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

        @Override
        public LoginBuilderint namehashCode(String name) {
        return    this.name = name;
Objects.hash(name, login);
    }

    @Override
    public return this;
boolean equals(Object obj) {
        if (this == obj) }
{
            return true;
        @Override}
        if public LoginBuilder login(List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609(obj instanceof DefaultLogin) {
            DefaultLogin other =  .acmesystem(DefaultLogin) obj;
            return
    .login.Login> login) {
            this.login = login;
Objects.equals(name, other.name) &&
                 return thisObjects.equals(login, other.login);
        }
        return  @Overridefalse;
    }

    @Override
    public LoginString buildtoString() {
        return MoreObjects.toStringHelper(getClass())
   return new DefaultLogin(this);
        }

.add("name", name)
           public LoginBuilder() {
.add("login", login)
            }.toString();
    }
}
 

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 wherever it is used.

Example
Code Block
titleInput YANG file
module Test {
    namespace "http://test.example.com/"
    public DefaultLogin(LoginBuilder builderObject) {
        this.name = builderObject.name();
    prefix "test";
    organization "ACME Inc."this.login = builderObject.login();
    grouping endpoint { }

    public void addAugmentedInfo(YangAugmentedInfo value, leafClass addressclassObject) {
        yangAugmentedInfoMap.put(classObject, value);
   type int32; }

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

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

    public class LoginBuilder  }
implements Login.LoginBuilder {

       container connectionprotected {String name;
        container source {protected List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login
            uses.Login> endpointlogin;


        }@Override
        container destinationpublic String name() {
            usesreturn endpointname;
        }

    }
    .@Override
    .
    .
}
Code Block
titleGenerated Java files
File : Connection.java
package org.public List<org.onosproject.yang.gen.v1.http.testacme.example.com.rev20160718.test;

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

public interface Connection {

system.rev20070609.acmesystem.login
       Source source();

    interface ConnectionBuilder.Login> login() {

            Sourcereturn source()login;

        }

 ConnectionBuilder source(Source source);

      @Override
        public ConnectionLoginBuilder buildname(String name) {
            this.name = name;
      }
      return this;
        }

File : Source.java

package org        @Override
        public LoginBuilder login(List<org.onosproject.yang.gen.v1.http.testacme.example.com.rev20160718.test.connection;

public interface Source {

system.rev20070609
          int address();

    byte port();

 .acmesystem
      interface SourceBuilder {

        int address();

.login.Login> login) {
            byte port();

this.login = login;
           SourceBuilder address(int address)return this;

        }
    SourceBuilder   port(byte port);

 @Override
        Sourcepublic Login build(); {
    }
}

 

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        return new DefaultLogin(this);
        }

        public LoginBuilder() {
        }
    }
}
 
File:LoginOpParam.java

package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
import org.onosproject.yangutils.datamodel.YangAugmentedOpParamInfo;
import java.util.BitSet;
public class LoginOpParam extends DefaultLogin  {
    public static enum  choice interfaceTypeOperationType {
        MERGE,
    case ethernerType {
  REPLACE,
        CREATE,
      leaf ethernet { type string; } DELETE,
        REMOVE
    }
    private OperationType opParamType;
    private BitSet filterLeafFlags case= p2pType {new BitSet();
    private BitSet selectLeafFlags = new BitSet();

    public BitSet leafgetFilterLeafFlags() p2p {
 type string; }
     return   filterLeafFlags;
    }
    public BitSet getSelectLeafFlags() {
 }
     }
}
Code Block
titleGenerated Java files
File : InterfaceType.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160509.choicecasetest.link1;

public interface InterfaceType {
}

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;

public interface EthernerType extends InterfaceType  {

    String ethernet();

    interface EthernerTypeBuilder {

return selectLeafFlags;
    }
    public OperationType getOpertionType() {
        return opParamType;
    }
    public boolean isFilterContentMatch(Object obj) {
        DefaultLogin StringappInstance = ethernet(DefaultLogin)obj;

        EthernerTypeBuilderfor ethernet(String ethernet);

YangAugmentedInfo yangAugmentedInfo : this.getYangAugmentedInfoMap().values()) {
          EthernerType build();
 if (!(yangAugmentedInfo  }
}

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

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 EthernerTypeBuilder implements EthernerType.EthernerTypeBuilder {

    private String ethernet;

    @Override
    public String ethernet() {instanceof  YangAugmentedOpParamInfo)) {
                throw new IllegalArgumentException("provided augmented info is invalid for content match.");
        return ethernet;
    }

    @Override
    public EthernerTypeBuilder ethernet(String ethernet) {
YangAugmentedInfo yangAugmentedOpParamInfo = appInstance
     this.ethernet = ethernet;
        return this.getAugmentedInfo(((YangAugmentedOpParamInfo) yangAugmentedInfo).getBaseClass());
    }

   @Override
   public EthernerType buildif(!((YangAugmentedOpParamInfo) {
yangAugmentedInfo).isFilterContentMatch(yangAugmentedOpParamInfo)) {
                return new EthernerTypeImpl(this)false;
   }

    public EthernerTypeBuilder() {
   }

   public final class EthernerTypeImpl implements EthernerType {}

        private String ethernet;
if (getFilterLeafFlags().get(1)) {
        @Override
    if (appInstance.name() == null public String ethernet(|| !(name().equals(appInstance.name()))) {
                return ethernetfalse;
            }
        }
        return true;
    }
    public EthernerTypeImplLoginOpParam(LoginOpParamBuilder builderObject) {
        }
super(builderObject);
        filterLeafFlags = builderObject.getFilterLeafFlags();
    }
    public EthernerTypeImpl(EthernerTypeBuilder builderObject)class LoginOpParamBuilder extends DefaultLogin.LoginBuilder {
        private OperationType opParamType;
         this.ethernetprivate BitSet filterLeafFlags = builderObject.ethernetnew BitSet();
        }
private BitSet selectLeafFlags = new }
}

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.

Example
Code Block
titleInput YANG file
File: sfc.yang
module Sfc {
    yang-version 1;BitSet();

        @Override
    namespace http://huawei.com;
   public prefix Ant;
    rpc SFP LoginBuilder name(String recvname) {
        input {
   name =  recvname;
      leaf port {
    getFilterLeafFlags().set(1);
            typereturn stringthis;
        }
      }
      public BitSet getFilterLeafFlags() {
            return filterLeafFlags;
        }
        public BitSet outputgetSelectLeafFlags() {
            return leafselectLeafFlags;
 path {
      }
        public OperationType type string;getOpertionType() {
            }return opParamType;
          }
    }
}
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 public void setOpertionType(OperationType operationType) {
    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());

    @Activate
    public void activate()         this.opParamType = operationType;
        }
    }
}
 

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 wherever it is used.

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 {
        //TODO: YANG utils generated code    type int8; 
        log.info("Started");}
    }

    container connection @Deactivate{ 
       public voidcontainer deactivate()source {
        //TODO:  YANG utils generateduses codeendpoint;
        log.info("Stopped");}
     }

   container destination @Override{
     public SfpOutput sfp(SfpInput inputVar) {      uses endpoint;
        //TODO: YANG utils generated code}
    }
    .
    return null;.
     }.
}

Code Block
titleGenerated Java files
File : SfpInputConnection.java
package org.onosproject.yang.gen.v1.http.test.example.com.rev20160718.test;

import org.onosproject.yang.gen.v1.http.test.huaweiexample.com.rev20160718.rev20160526test.sfcconnection.sfpSource;

public interface SfpInputConnection {

    StringSource portsource();

    interface SfpInputBuilderConnectionBuilder {

        StringSource portsource();

        SfpInputBuilderConnectionBuilder portsource(StringSource portsource);

        SfpInputConnection build();
    }
}

File : SfpinputBuilderSource.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 test.example.com.rev20160718.test.connection;

public interface Source {

     private String portint address();

    @Overridebyte port();

    publicinterface StringSourceBuilder port() {

        returnint portaddress();
    }

    @Override
    publicbyte SfpInputBuilder port(String port) {);

         this.port = port;
         return this;SourceBuilder address(int address);

    }

    SourceBuilder port(byte port);

        Source build();
    }
}

 

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.
  4. OpParam class File:
    it inlcudes:
    a) Operation types for restconf/netconf operations.
    b) setter method for leaf and leaf list if present.
    c) isFilterContentMatch() method for matching the contents if they are set in object or not.
    d) setter and getter for bitset values of present leaves/leaf-lists.

Example
Code Block
titleInput YANG file
File : link.yang
module link {
    yang-version 1;
    namespace http://huawei.com;
    prefix Ant;
    container link {
@Override
    public SfpInput build() {
         return new SfpInputImpl(this);
    }

    public SfpInputBuilder() {
    }

    public final class SfpInputImpl implements SfpInput {

         private String port;

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

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

        @Override
        public boolean equals(Object obj) {
             if (this == obj)choice interfaceType {
            case     return true;
 ethernerType {
            }
    leaf ethernet { type     if (obj instanceof SfpInputImpl) {string; }
                SfpInputImpl other = (SfpInputImpl) obj;}
            case p2pType   return{
               leaf p2p { type   Objects.equals(port, other.port);string; }
            }
        }
    return }
}
Code Block
titleGenerated Java files
File : InterfaceType.java

package org.onosproject.yang.gen.v1.http.huawei.com.rev20160721.link.link;
public interface InterfaceType {
}

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

public interface EthernerType extends InterfaceType  {
    String ethernet();false;
         }

        @Override
        public String toString() {
    interface EthernerTypeBuilder {
          return MoreObjects.toStringHelper(getClass())String ethernet();
                   .add("port", port)EthernerTypeBuilder ethernet(String ethernet);
                   .toStringEthernerType build();
        }
}

File        public SfpInputImpl(SfpInputBuilder builderObject) {
                 this.port = builderObject.port: DefaultEthernerType.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160721.link.link.interfacetype;
import com.google.common.base.MoreObjects;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
public class DefaultEthernerType implements EthernerType {
    private Map<Class<?>, YangAugmentedInfo> yangAugmentedInfoMap = new HashMap<>();
    protected String   }ethernet;
    }@Override
}
File  : Sfpoutput.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.sfc.sfp;

public interfaceString SfpOutputethernet() {

        Stringreturn path()ethernet;

    interface}
 SfpOutputBuilder {

  @Override
    public int String pathhashCode(); {

        SfpOutputBuilderreturn path(String pathObjects.hash(ethernet);
    }
    @Override
    SfpOutputpublic boolean buildequals(Object obj); {
     }
}
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 (this == obj) {
           private Stringreturn pathtrue;

        @Override}
      public  Stringif path(obj instanceof DefaultEthernerType) {
            return path;
DefaultEthernerType other = (DefaultEthernerType) obj;
        }

    @Overridereturn
    public SfpOutputBuilder path(String path) {
         this.path = pathObjects.equals(ethernet, other.ethernet);
        }
        return thisfalse;
    }

    @Override
    public SfpOutputString buildtoString() {
         return new SfpOutputImpl(this);MoreObjects.toStringHelper(getClass())
    }

    public SfpOutputBuilder() {
    }

.add("ethernet", ethernet)
    public final class SfpOutputImpl implements SfpOutput {

   .toString();
    }
  private String path;

  public DefaultEthernerType(EthernerTypeBuilder builderObject) {
        this.ethernet  @Override= builderObject.ethernet();
     }
    public Stringvoid path(addAugmentedInfo(YangAugmentedInfo value, Class classObject) {
        yangAugmentedInfoMap.put(classObject, value);
   return path;}
    public YangAugmentedInfo getAugmentedInfo(Class classObject)  }{

         @Overridereturn yangAugmentedInfoMap.get(classObject);
    }
    public public int hashCodeMap<Class<?>, YangAugmentedInfo> getYangAugmentedInfoMap() {
        return yangAugmentedInfoMap;
   return Objects.hash(path); }
    public class EthernerTypeBuilder implements EthernerType.EthernerTypeBuilder {
        protected }String ethernet;

         @Override
         public booleanString equalsethernet(Object obj) {
            return ethernet;
    if (this == obj) {}
        @Override
        public EthernerTypeBuilder ethernet(String ethernet) {
 return true;
          this.ethernet = }ethernet;
            if (obj instanceof SfpOutputImpl) {
return this;
        }
        @Override
        SfpOutputImplpublic otherEthernerType = build(SfpOutputImpl) obj;{
            return new DefaultEthernerType(this);
       return Objects.equals(path, other.path); }
        public    }EthernerTypeBuilder() {
        }
    return false;
         }

}
}
 
File:EthernerTypeOpParam.java
 
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160721.link.link.interfacetype;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
import org.onosproject.yangutils.datamodel.YangAugmentedOpParamInfo;
import java.util.BitSet;
public class EthernerTypeOpParam extends DefaultEthernerType {
    public static enum OperationType {
  @Override
      MERGE,
   public String toString() {
  REPLACE,
        CREATE,
  return MoreObjects.toStringHelper(getClass())
     DELETE,
        REMOVE
   .add("path", path) }
    private OperationType opParamType;
    private BitSet filterLeafFlags = new  .toStringBitSet();
    private BitSet selectLeafFlags = new }BitSet();

    public     public SfpOutputImpl(SfpOutputBuilder builderObjectBitSet getFilterLeafFlags() {
        return filterLeafFlags;
    this.path}
 = builderObject.path();   public BitSet getSelectLeafFlags() {
        return selectLeafFlags;
    }
    public OperationType getOpertionType() {
        return opParamType;
    }
    public boolean isFilterContentMatch(Object obj) {
        DefaultEthernerType appInstance = (DefaultEthernerType)obj;
         }
}

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.

Manager Extends ListenerRegistry with event and eventListener.

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

    notification test for (YangAugmentedInfo yangAugmentedInfo : this.getYangAugmentedInfoMap().values()) {
            if (!(yangAugmentedInfo  instanceof  YangAugmentedOpParamInfo)) {
                throw new IllegalArgumentException("provided augmented info is invalid for content match.");
            }
            YangAugmentedInfo yangAugmentedOpParamInfo = appInstance
            .getAugmentedInfo(((YangAugmentedOpParamInfo) yangAugmentedInfo).getBaseClass());
            if(!((YangAugmentedOpParamInfo) yangAugmentedInfo).isFilterContentMatch(yangAugmentedOpParamInfo)) {
                return false;
            }
        }
        if (getFilterLeafFlags().get(1)) {
            if (appInstance.ethernet() == null leaf event-class|| !(ethernet().equals(appInstance.ethernet()))) {
               type return stringfalse;
            }
        }
   leaf severity {     return true;
    }
    public EthernerTypeOpParam(EthernerTypeOpParamBuilder builderObject) {
       type stringsuper(builderObject);
        filterLeafFlags = builderObject.getFilterLeafFlags();
    }
    }
}
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
public class EthernerTypeOpParamBuilder extends DefaultEthernerType.EthernerTypeBuilder {
        private OperationType opParamType;
        private BitSet filterLeafFlags = new BitSet();
        private BitSet selectLeafFlags = new BitSet();

        @Override
        public EthernerTypeBuilder ethernet(String recvethernet) {
            extendsethernet ListenerRegistry<OspfEvent,= OspfListener>recvethernet;
         implements  OspfService {

 getFilterLeafFlags().set(1);
        private final Logger log = getLogger(getClass());
return this;
        }
    @Activate
    public voidBitSet activategetFilterLeafFlags() {
         //TODO: YANG utils generatedreturn code
    filterLeafFlags;
    log.info("Started");
    }

    @Deactivate
    public voidBitSet deactivategetSelectLeafFlags() {
        //TODO:  YANG utils generatedreturn codeselectLeafFlags;
        }
   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
 public OperationType getOpertionType() {
            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> {

return opParamType;
        }
        public enum Typevoid setOpertionType(OperationType operationType) {

    TEST
    }

    public OspfEvent(Type type, OspfEventSubject subject) {this.opParamType = operationType;
        super(type, subject);}
    }
}

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.

Example
Code Block
titleInput YANG file
File: sfc.yang
module Sfc
    public OspfEvent(Type type, OspfEventSubject subject, long time) {
        super(type, subject, time)yang-version 1;
    }
}

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

public class OspfEventSubject {

    private Test test;

    public Test test() {
namespace http://huawei.com;
    prefix Ant;
    rpc SFP {
        input {
            leaf port {
           return test     type string;
            }
          }
          output {
    public void test(Test test)        leaf path {
               this.test =type teststring;
            }
          }
    }
}
Code Block
titleGenerated Java files
File : OspfListenerSfcService.java

package org.onosproject.yang.gen.v1.http.examplehuawei.com.ospf.rev20160519.ospfrev20160721;

import org.onosproject.yang.gen.event.EventListener;

public interface OspfListener extends EventListener<OspfEvent> {
}

File : Test.java

packagev1.http.huawei.com.rev20160721.sfc.sfp.SfpInput;
import org.onosproject.yang.gen.v1.http.examplehuawei.com.ospfrev20160721.rev20160519.ospf;

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

sfc.sfp.SfpOutput;
public interface Test extends AugmentationHolder SfcService {

    StringSfc eventClassgetSfc();

    Stringvoid severity();

    interface TestBuilder {

         String eventClass(setSfc(Sfc sfc);

         String severity();

         TestBuilder eventClass(String eventClass);

         TestBuilder severity(String severity);

         Test build();
    }
}

SfpOutput sfp(SfpInput inputVar);
}
File : TestBuilderSfcManager.java

package org.onosproject.yang.gen.v1.http.examplehuawei.com.ospf.rev20160519.ospfrev20160721;

import comorg.apache.googlefelix.commonscr.baseannotations.MoreObjectsActivate;
import java.util.ArrayListorg.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import java.util.Listorg.apache.felix.scr.annotations.Service;
import java.util.Objectsorg.onosproject.yang.gen.v1.http.huawei.com.rev20160721.sfc.sfp.SfpInput;
import org.onosproject.yangutils.translator.tojava.AugmentedInfo;

.yang.gen.v1.http.huawei.com.rev20160721.sfc.sfp.SfpOutput;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;
@Component(immediate = true)
@Service
public class TestBuilderSfcManager implements Test.TestBuilderSfcService {

    private Stringfinal eventClass;
Logger log   private String severity= getLogger(getClass());

    @Override@Activate
    public Stringvoid eventClassactivate() {
        return eventClass;
    }

//TODO: YANG utils generated code
    @Override
    public String severity() {
        return severitylog.info("Started");
    }

    @Override@Deactivate
    public TestBuildervoid eventClassdeactivate(String eventClass) {
        this.eventClass = eventClass;//TODO: YANG utils generated code
        return thislog.info("Stopped");
    }

    @Override
    public TestBuilderSfc severitygetSfc(String severity) {
        this.severity = severity;//TODO: YANG utils generated code
        return thisnull;
    }

    @Override
    public Testvoid buildsetSfc(Sfc sfc) {
        return new TestImpl(this);//TODO: YANG utils generated code
    }

    @Override
    public SfpOutput TestBuildersfp(SfpInput inputVar) {
    }

    public final class TestImpl implements Test {

//TODO: YANG utils generated code
        private List<AugmentedInfo> augmentedInfoList = new ArrayList<>()return null;
    }
}

File :   private String eventClass;
   SfpInput.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160721.sfc.sfp;
public interface SfpInput {
     private String severityport();

    interface SfpInputBuilder   @Override{
        public String eventClassport() {;
        SfpInputBuilder port(String port);
   return  eventClass;
   SfpInput build();
    }
}
File : DefaultSfpInput.java

package org.onosproject.yang.gen.v1.http.huawei.com.rev20160721.sfc.sfp;
import com.google.common.base.MoreObjects;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
public class DefaultSfpInput implements SfpInput @Override{
    private Map<Class<?>, YangAugmentedInfo> yangAugmentedInfoMap public= Stringnew severityHashMap<>();
 {
   protected String port;
    @Override
   return severity;
public String port() {
     }

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

        @Override
        public boolean equals(Object obj) {
           if (this == obj) {
               return true;
            }
            if (obj instanceof TestImplDefaultSfpInput) {
            DefaultSfpInput    TestImpl other = (TestImplDefaultSfpInput) obj;
            return
      return           Objects.equals(eventClassport, other.eventClassport) &&;
        }
        return false;
    }
  Objects.equals(severity, other.severity);  @Override
    public String toString() {
     }
   return MoreObjects.toStringHelper(getClass())
        return false;
   .add("port", port)
    }

        @Override.toString();
    }
    public String toString(DefaultSfpInput(SfpInputBuilder builderObject) {
        this.port =   return MoreObjects.toStringHelper(getClass())builderObject.port();
    }
    public void addAugmentedInfo(YangAugmentedInfo value, Class classObject) {
        yangAugmentedInfoMap.addput("eventClass"classObject, eventClassvalue);
    }
    public YangAugmentedInfo getAugmentedInfo(Class classObject) {
        return yangAugmentedInfoMap.add("severity", severity)get(classObject);
    }
    public Map<Class<?>, YangAugmentedInfo> getYangAugmentedInfoMap() {
        return .toString()yangAugmentedInfoMap;
        }

    public class SfpInputBuilder  public TestImpl(TestBuilder builderObject) implements SfpInput.SfpInputBuilder {
        protected String port;

  this.eventClass = builderObject.eventClass();
    @Override
        this.severitypublic =String builderObject.severityport(); {
            return port;
        }

        @Override
        public voidSfpInputBuilder addAugmentationport(AugmentedInfoString valueport) {
            getAugmentedInfoList().add(value)this.port = port;
            return this;
        }

        @Override
        public List<AugmentedInfo>SfpInput getAugmentedInfoListbuild() {
            return augmentedInfoList new DefaultSfpInput(this);
        }
        public SfpInputBuilder() {
        @Override}
    }
}
 
File: SfpInputOpParam.java

package org.onosproject.yang.gen.v1.http.huawei.com.rev20160721.sfc.sfp;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
import org.onosproject.yangutils.datamodel.YangAugmentedOpParamInfo;
import java.util.BitSet;
public void removeAugmentation()class SfpInputOpParam extends DefaultSfpInput  {
    public static enum OperationType {
       getAugmentedInfoList().clear(); MERGE,
        }REPLACE,
    }
}

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
titleA 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 YANG utils 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
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 {    CREATE,
        DELETE,
        REMOVE
    }
    private OperationType opParamType;
    private BitSet filterLeafFlags = new BitSet();
    private BitSet selectLeafFlags = new BitSet();

    public BitSet getFilterLeafFlags() {
        return filterLeafFlags;
    }
    public BitSet getSelectLeafFlags() {
        return selectLeafFlags;
    }
    public OperationType getOpertionType() {
        return opParamType;
    }
    public boolean isFilterContentMatch(Object obj) {
        DefaultSfpInput appInstance = (DefaultSfpInput)obj;
        for (YangAugmentedInfo yangAugmentedInfo : this.getYangAugmentedInfoMap().values()) {
            if (!(yangAugmentedInfo  instanceof  YangAugmentedOpParamInfo)) {
                throw new IllegalArgumentException("provided augmented info is invalid for content match.");
            }
            YangAugmentedInfo yangAugmentedOpParamInfo = appInstance
            .getAugmentedInfo(((YangAugmentedOpParamInfo) yangAugmentedInfo).getBaseClass());
            if(!((YangAugmentedOpParamInfo) yangAugmentedInfo).isFilterContentMatch(yangAugmentedOpParamInfo)) {
                return false;
            }
        }
        if (getFilterLeafFlags().get(1)) {
            if (appInstance.port() == null || !(port().equals(appInstance.port()))) {
                return false;
          leaf ifType {}
        }
        typereturn stringtrue;
    }
    public SfpInputOpParam(SfpInputOpParamBuilder builderObject) }{
     }

   super(builderObject);
  augment "/Test/interface" {
      filterLeafFlags = builderObject.getFilterLeafFlags();
    }
 leaf ds0ChannelNumber {
 public class SfpInputOpParamBuilder extends DefaultSfpInput.SfpInputBuilder {
        private typeOperationType int16opParamType;
        private }
BitSet filterLeafFlags = new }
}
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 {
 
BitSet();
        private BitSet selectLeafFlags = new BitSet();

        @Override
        public SfpInputBuilder port(String recvport) {
            port = recvport;
           short getDs0ChannelNumbergetFilterLeafFlags().set(1);

           AgmentedInterfaceBuilder setDs0ChannelNumber(short ds0ChannelNumber);

return this;
        }
        public AugmentedInterfaceBitSet buildgetFilterLeafFlags(); {
    }
}

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        return filterLeafFlags;
        }
        public BitSet getSelectLeafFlags() {
   private short ds0ChannelNumber;

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

   @Override
   public AugmentedInterfaceBuilderOperationType setDs0ChannelNumbergetOpertionType(short ds0ChannelNumber)  {
          this.ds0ChannelNumber  =return ds0ChannelNumberopParamType;
       return this;}
   }

   @Override
   public AugmentedInterfacevoid buildsetOpertionType(OperationType operationType) {
          return new AugmentedInterfaceImpl(this)this.opParamType = operationType;
   }

   public AugmentedInterfaceBuilder() {}
    }
}
File : Sfpoutput.java

package org.onosproject.yang.gen.v1.http.huawei.com.rev20160721.sfc.sfp;
public finalinterface class AugmentedInterfaceImpl implements AugmentedInterface SfpOutput {

       private short ds0ChannelNumber;
String path();
    interface SfpOutputBuilder  @Override{
       public shortString getDs0ChannelNumberpath() {;
        SfpOutputBuilder path(String path);
 return ds0ChannelNumber;
      SfpOutput }build();

    }
}
File :  @Override
       Public int hashCode()DefaultSfpOutput.java

package org.onosproject.yang.gen.v1.http.huawei.com.rev20160721.sfc.sfp;
import com.google.common.base.MoreObjects;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
public class DefaultSfpOutput implements SfpOutput {
    private Map<Class<?>, YangAugmentedInfo> yangAugmentedInfoMap =   return Objects.hash(ds0ChannelNumbernew HashMap<>();
    protected String  }path;

       @Override
       public booleanString equalspath(Object obj) {
        return path;
    if}
 (this == obj) {@Override
    public int hashCode() {
        return trueObjects.hash(path);
    }
    @Override
   }

 public boolean equals(Object obj) {
        if (objthis instanceof== AugmentedInterfaceImplobj) {
               AugmentedInterfaceImpl other = (AugmentedInterfaceImpl) obj;return true;
        }
        if (obj instanceof DefaultSfpOutput) {
            DefaultSfpOutput other  return
= (DefaultSfpOutput) obj;
            return
                 Objects.equals(ds0ChannelNumberpath, other.ds0ChannelNumberpath);
           }
           return false;
       }

       @Override
       public String toString() {
           return MoreObjects.toStringHelper(getClass())
               .add("ds0ChannelNumberpath", ds0ChannelNumberpath)
               .toString();
    }
    public DefaultSfpOutput(SfpOutputBuilder builderObject) }{

        Public AugmentedInterfaceImpl(AugmentedInterfaceBuilderthis.path = builderObject.path() {
;
    }
    public void addAugmentedInfo(YangAugmentedInfo value, Class classObject) {
      this.ds0ChannelNumber = builderObjectyangAugmentedInfoMap.getDs0ChannelNumberput(classObject, value);
    }
    public  InterfaceImpl interfaceImpl = new InterfaceBuilder().new InterfaceImpl(YangAugmentedInfo getAugmentedInfo(Class classObject) {
        return yangAugmentedInfoMap.get(classObject);
    }
    public  interfaceImpl.addAugmentation(this);Map<Class<?>, YangAugmentedInfo> getYangAugmentedInfoMap() {
       } return yangAugmentedInfoMap;
    }
}

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

...

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 {    public class SfpOutputBuilder implements SfpOutput.SfpOutputBuilder {
        protected String path;

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

leaf two {      @Override
        public SfpOutputBuilder path(String path) {
         
   this.path type= int32path;
}

leaf-list three {
    type boolean;
}

leaf-list four {   return this;
        }
     type int16;
}
Code Block
titleGenerated Java file
private String one;@Override

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 1;
    namespace "http://huawei.com";
    prefix "test";

    typedef percent { public SfpOutput build() {
            return new DefaultSfpOutput(this);
        type uint8;}
           description "Percentage";
    }

    leaf completedpublic SfpOutputBuilder() {
        type percent;}
    }
}
Code Block
titleGenerated Java file
File 
 
File: PercentSfpOutputOpParam.java

package org.onosproject.yang.gen.v1.http.huawei.com.rev20160721.rev20160526sfc.testsfp;

import java.util.Objectsorg.onosproject.yangutils.datamodel.YangAugmentedInfo;
import comorg.googleonosproject.commonyangutils.basedatamodel.MoreObjectsYangAugmentedOpParamInfo;
import java.util.BitSet;
public final class Percentclass SfpOutputOpParam extends DefaultSfpOutput  {

    privatepublic short uint8;

  static enum OperationType {
  private Percent() {
    }MERGE,


     public Percent(short value) {REPLACE,
        CREATE,
  this.uint8 = value;
    }
DELETE,
    public static Percent of(short value) { REMOVE
    }
    returnprivate new Percent(value)OperationType opParamType;
    }

private BitSet filterLeafFlags = publicnew short uint8BitSet() {;
    private BitSet selectLeafFlags = returnnew uint8;
    }BitSet();

    @Override
    public intBitSet hashCodegetFilterLeafFlags() {
        return Objects.hash(uint8)filterLeafFlags;
    }

    @Override
    public booleanBitSet equalsgetSelectLeafFlags(Object obj) {
        if (this == obj) {return selectLeafFlags;
    }
    public OperationType getOpertionType() {
        return trueopParamType;
        }
    public boolean   if (obj instanceof PercentisFilterContentMatch(Object obj) {
        DefaultSfpOutput appInstance   Percent other = (PercentDefaultSfpOutput) obj;
        for (YangAugmentedInfo yangAugmentedInfo : return Objectsthis.equals(uint8, other.uint8);getYangAugmentedInfoMap().values()) {
        }
    if (!(yangAugmentedInfo  instanceof  return false;YangAugmentedOpParamInfo)) {
    }

     @Override
    public String toString() {
throw new IllegalArgumentException("provided augmented info is invalid for returncontent MoreObjects.toStringHelper(getClass())match.");
            .add("uint8", uint8)}
            .toString();
    }

YangAugmentedInfo yangAugmentedOpParamInfo = appInstance
            .getAugmentedInfo(((YangAugmentedOpParamInfo) yangAugmentedInfo).getBaseClass());
         public static Percent fromString(String valInString) {
if(!((YangAugmentedOpParamInfo) yangAugmentedInfo).isFilterContentMatch(yangAugmentedOpParamInfo)) {
                return false;
           try {}
        }
    short   tmpVal = Short.parseShort(valInString);if (getFilterLeafFlags().get(1)) {
            return of(tmpVal);
if (appInstance.path() == null || !(path().equals(appInstance.path()))) {
             } catch (Exception e)return {false;
            }
        }
        return nulltrue;
    }
}

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 {

    public SfpOutputOpParam(SfpOutputOpParamBuilder builderObject) {
        super(builderObject);
    yang-version 1;
   filterLeafFlags namespace "http://huawei.com"= builderObject.getFilterLeafFlags();
    prefix}
 Ant;
   public descriptionclass "IntervalSfpOutputOpParamBuilder beforeextends a route is declared invalid";

DefaultSfpOutput.SfpOutputBuilder {
       leaf private packetTypeOperationType {opParamType;
        private type enumeration {BitSet filterLeafFlags = new BitSet();
        private BitSet selectLeafFlags =  enum "unbounded"new BitSet();

        @Override
      enum ZERO;
 public SfpOutputBuilder path(String recvpath) {
      enum two;
     path = recvpath;
      enum four;
     getFilterLeafFlags().set(1);
    }        return this;
        }
}
Code Block
titleGenerated Java files
File : PacketTypeEnum.java

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

public enum PacketTypeEnum {

  public BitSet UNBOUNDEDgetFilterLeafFlags(0), {

     ZERO(1),

    TWO(2),

   return FOUR(3)filterLeafFlags;
        }
    private int packetTypeEnum;

  public BitSet PacketTypeEnumgetSelectLeafFlags(int value) {
        packetTypeEnum = value;
  return  }selectLeafFlags;

    public static PacketTypeEnum of(int value) {
 }
        public switchOperationType getOpertionType(value) {
            casereturn 0:opParamType;
        }
        return PacketTypeEnum.UNBOUNDED;
    public void setOpertionType(OperationType operationType) {
        case 1:
                    return PacketTypeEnum.ZERO;
            case 2:
                    return PacketTypeEnum.TWO;
            case 3:
           this.opParamType = operationType;
         return PacketTypeEnum.FOUR;
            default :
                    return null;
            }
    }


    public int packetTypeEnum() {
            return packetTypeEnum;
    }

    public static PacketTypeEnum fromString(String valInString) {
            try {
                int tmpVal = Integer.parseInt(valInString);
                return of(tmpVal);
            } catch (Exception e) {
        }
        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
}

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.

Manager Extends ListenerRegistry with event and eventListener. 

Example
Code Block
titleInput YANG files
File : ospf.yang
module ospf {
Code Block
titleInput YANG file
File : test.yang
module test {
    yang-version 1;
    namespace "http://huaweiexample.com/ospf";
    prefix "testospf";

    typedefnotification ip-addresstest {
          type union leaf event-class {
              type int32;
string;
           }
           leaf severity {
              type uint32string;
           }
    }
}
Code Block
titleGenerated java Java files
File : IpAddressUnionOspfManager.java

package org.onosproject.yang.gen.v1.http.huaweiexample.com.rev20160526ospf.test.ipaddressrev20160721;

import java.util.Objectsorg.apache.felix.scr.annotations.Activate;
import comorg.apache.googlefelix.commonscr.baseannotations.MoreObjectsComponent;

public final class IpAddressUnion {

    private int int32;
    private long uint32;

    private IpAddressUnion() {
    }

    public IpAddressUnion(int value) {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.rev20160721.ospf.OspfEvent;
import org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160721.ospf.OspfEventListener;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;

@Component(immediate = true)
@Service
public class OspfManager
        this.int32 = value;extends ListenerRegistry<OspfEvent, OspfEventListener>
    }

    publicimplements IpAddressUnion(long value) OspfService {
    private final Logger  this.uint32log = valuegetLogger(getClass());
    }@Activate

    public staticvoid IpAddressUnion of(int valueactivate() {
        return new IpAddressUnion(value);
    }

//TODO: YANG utils generated code
      public static IpAddressUnion of(long value) { log.info("Started");
        return new IpAddressUnion(value);}
    }
@Deactivate
    public intvoid int32deactivate() {
        return int32;
    }

//TODO: YANG utils generated code
      public long uint32() {log.info("Stopped");
    }
    return uint32;
    }

@Override
    public Ospf getOspf() {
     @Override
   //TODO: publicYANG intutils hashCode()generated {code
        return Objects.hash(int32, uint32)null;
    }

    @Override
    public booleanvoid equalssetOspf(ObjectOspf objospf) {
        if (this == obj) {//TODO: YANG utils generated code
    }
}
File : OspfService.java

package org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160721;
import org.onosproject.event.ListenerService;
import    return true;
      }org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160721.ospf.OspfEvent;
import org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160721.ospf.OspfEventListener;
public interface OspfService
        ifextends (obj instanceof IpAddressUnion)ListenerService<OspfEvent, OspfEventListener> {
    Ospf getOspf();
    void setOspf(Ospf  IpAddressUnion other = (IpAddressUnion) obj;
     ospf);
}

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> {

    public enum Type return{

    TEST
    }

    public OspfEvent(Type type,   Objects.equals(int32, other.int32) &&OspfEventSubject subject) {
        super(type, subject);
    }

    public Objects.equals(uint32, other.uint32);
    OspfEvent(Type type, OspfEventSubject subject, long time) {
    }
    super(type,    return falsesubject, time);
    }
}

File :   @Override
    public String toString() {OspfEventSubject.java
package org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160519.ospf;

public class OspfEventSubject {

    private Test test;

  return MoreObjects.toStringHelper(getClass())  public Test test() {
            .omitNullValues()return test;
    }

    public void   .add("int32", int32)test(Test test) {
        this.test = test;
   .add("uint32", uint32)
            .toString();
    }

    public static IpAddressUnion fromString(String valInString) { }
}

File : OspfEventListener.java

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

import org.onosproject.event.EventListener;

public interface OspfEventListener extends EventListener<OspfEvent> {
}

File : Test.java

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

public interface Test {
    String eventClass();
    String severity();
    interface TestBuilder   try {
          int tmpVal = Integer.parseInt(valInStringString eventClass();
        String  return ofseverity(tmpVal);
        }TestBuilder catch eventClass(ExceptionString eeventClass) {;
        }
TestBuilder        try {
          long tmpVal = Long.parseLong(valInStringseverity(String severity);
        Test  return ofbuild(tmpVal);
        } catch (Exception e) {
        }
        return null;
   }
}
Code Block
titleGenerated Java files
File : FlowClassifierServiceDefaultTest.java
package org.onosproject.yang.gen.v1.sfc.flowclassifier.rev20160524.http.example.com.ospf.rev20160721.ospf;

import orgcom.onosprojectgoogle.yangcommon.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20100924.ietfyangtypes.Uuidbase.MoreObjects;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;

public interface FlowClassifierServiceclass DefaultTest implements Test {

    Uuid getIdprivate Map<Class<?>, YangAugmentedInfo> yangAugmentedInfoMap = new HashMap<>();

    voidprotected setId(Uuid id)String eventClass;
}

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 protected String severity;

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

    @Override
    public voidString activateseverity() {
        //TODO: YANG utils generated codereturn severity;
    }

    @Override
     log.info("Started"public int hashCode() {
        return Objects.hash(eventClass, severity);
    }

    @Deactivate@Override
    public voidboolean deactivateequals(Object obj) {
        //TODO: YANG utils generated code
if (this == obj) {
          log.info("Stopped")  return true;
        }

     @Override
   if public(obj Uuidinstanceof getId(DefaultTest) {
        //TODO: YANG utils generated code
    DefaultTest other = (DefaultTest) obj;
            return
 null;
      }

    @Override
    public void setId(Uuid id) {Objects.equals(eventClass, other.eventClass) &&
        //TODO: YANG utils generated code
    }

}

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() {
Objects.equals(severity, other.severity);
        }
        return false;
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(getClass())
            .add("eventClass", eventClass)
         //TODO: YANG utils generated code .add("severity", severity)
        log.info("Started"    .toString();
    }

    public DefaultTest(TestBuilder builderObject) @Deactivate{
    public void deactivate() {
 this.eventClass = builderObject.eventClass();
     //TODO: YANG utils generated code
        log.info("Stopped"this.severity = builderObject.severity();
    }
}

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 public void addAugmentedInfo(YangAugmentedInfo value, Class classObject) {
    private String string;

    private Uuid() {yangAugmentedInfoMap.put(classObject, value);
    }

    public YangAugmentedInfo UuidgetAugmentedInfo(StringClass valueclassObject) {
        return this.string = valueyangAugmentedInfoMap.get(classObject);
    }

    public static Uuid of(String valueMap<Class<?>, YangAugmentedInfo> getYangAugmentedInfoMap() {
        return new Uuid(value)yangAugmentedInfoMap;
    }

    public class String string()TestBuilder implements Test.TestBuilder {

        protected returnString stringeventClass;
    }

    protected String severity;


        @Override
        public intString hashCodeeventClass() {
            return Objects.hash(string)eventClass;
    }

    @Override}

    public boolean equals(Object obj) {@Override
        public ifString severity(this == obj) {
            return trueseverity;
        }

        if (obj instanceof Uuid) {@Override
        public TestBuilder   Uuid other = (Uuid) obj;eventClass(String eventClass) {
            return
this.eventClass = eventClass;
               Objects.equals(string, other.string)return this;
        }

        return false;@Override
    }

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

    public staticTest Uuid fromString(String valInStringbuild() {
        try {
   return new DefaultTest(this);
       String tmpVal = (valInString); }

        public TestBuilder() {
        }
    }
}
 
File:TestOpParam.java
package org.onosproject.yang.gen.v1.http.example.com.ospf.rev20160721.ospf;

import  return of(tmpVal);
        } catch (Exception e) {org.onosproject.yangutils.datamodel.YangAugmentedInfo;
import org.onosproject.yangutils.datamodel.YangAugmentedOpParamInfo;
import java.util.BitSet;

public class TestOpParam extends DefaultTest  {
    public static enum OperationType {
        MERGE,
        REPLACE,
        CREATE,
        DELETE,
        REMOVE
    }
    private OperationType opParamType;
    private BitSet filterLeafFlags = returnnew nullBitSet();
    }
}

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.

Example
Code Block
titleinput YANG file
File : ietf-network.yang
module ietf-networkprivate BitSet selectLeafFlags = new BitSet();


    public BitSet getFilterLeafFlags() {
    yang-version 1;
    namespace "urn:ietf:params:xml:ns:yang:ietf-network"return filterLeafFlags;
    prefix nd;}

    container networkspublic BitSet getSelectLeafFlags() {
        descriptionreturn selectLeafFlags;
    }

    public OperationType getOpertionType() {
  "Serves as top-level container for a listreturn ofopParamType;
    }

    public boolean isFilterContentMatch(Object  networks.";obj) {
        leaf network-id {DefaultTest appInstance = (DefaultTest)obj;
        for (YangAugmentedInfo yangAugmentedInfo  type uint8;: this.getYangAugmentedInfoMap().values()) {
            description
 if (!(yangAugmentedInfo  instanceof  YangAugmentedOpParamInfo)) {
      "Identifies a network.";
        }
throw new IllegalArgumentException("provided augmented }
info is invalid for container network-id {content match.");
        description
    }

        "Serves as top-level container forYangAugmentedInfo ayangAugmentedOpParamInfo list= ofappInstance
            networks.".getAugmentedInfo(((YangAugmentedOpParamInfo) yangAugmentedInfo).getBaseClass());
        leaf network-id {
  if(!((YangAugmentedOpParamInfo) yangAugmentedInfo).isFilterContentMatch(yangAugmentedOpParamInfo)) {
        type leafref {
      return false;
         path "/nd:networks/nd:network-id";
    }
        }
        }
    }
}
Code Block
titleGenerated java files
File : Networks.java
public interface Networks { 
    short networkId(); if (getFilterLeafFlags().get(1)) {
            if (appInstance.eventClass() == null || !(eventClass().equals(appInstance.eventClass()))) {
    interface  NetworksBuilder { 
        shortreturn networkId()false;
            }
     NetworksBuilder networkId(short networkId); }
        Networks build();
if (getFilterLeafFlags().get(2)) {
      }
}

File : NetworkId.java
public interface NetworkId { 
    short networkRef(); if (appInstance.severity() == null || !(severity().equals(appInstance.severity()))) {
    interface  NetworkIdBuilder { 
        shortreturn networkRef()false;
        NetworkIdBuilder networkRef(short networkRef);     }
        }
        NetworkIdreturn build()true;
    }

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 {
    yang-version 1

    public TestOpParam(TestOpParamBuilder builderObject) {
        super(builderObject);
    namespace "urn:ietf:params:xml:ns:yang:ietf-network"    filterLeafFlags = builderObject.getFilterLeafFlags();
    prefix nd;}

    public identity tunnel-typeclass TestOpParamBuilder extends DefaultTest.TestBuilder {
      description  "Baseprivate identityOperationType fromopParamType;
 which specific tunnel types are derived.";
  private  }

}
Code Block
titleGenerated java files
File : TunnelType.java
public abstract class TunnelType {
}

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;BitSet filterLeafFlags = new BitSet();
        private BitSet selectLeafFlags = new BitSet();


    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
    prefix nd;
@Override
    identity tunnel-type {
  public TestBuilder eventClass(String recveventClass) description{
  "Base identity from which specific tunnel types are derived.";
  eventClass = }recveventClass;

      container network-id {
    getFilterLeafFlags().set(1);
    description "Serves as top-level container for a list ofreturn networks."this;
        }
 leaf leaf-network-id {
     @Override
       type identityrefpublic {
TestBuilder severity(String recvseverity) {
            severity base= tunnel-typerecvseverity;
            }getFilterLeafFlags().set(2);
        }
    }

}
Code Block
titleGenerated java files
File : TunnelType.java
public abstract class TunnelType {
}
 
File : NetworkId.java
public interface NetworkId { 
    TunnelType leafNetworkId(); 
    interface NetworkIdBuilder { 
  return this;
        }

        public BitSet getFilterLeafFlags() {
            return filterLeafFlags;
      TunnelType leafNetworkId(); }

        NetworkIdBuilderpublic BitSet leafNetworkIdgetSelectLeafFlags(TunnelType leafNetworkId); {
        NetworkId build();
    return selectLeafFlags;
        }

 

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;

        public OperationType getOpertionType() {
    namespace http://huawei.com;
    prefix Ant;
  return opParamType;
 typedef MyBits {
        type bits {
             bit disable-nagle {
                 position 0;
             }
             bit auto-sense-speed {
        public void setOpertionType(OperationType       position 1;
             }
             bit Mb-only operationType) {
            this.opParamType     position 2= operationType;
             }
         }
    }
}

...

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
titleA 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 utils 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 YangUtils.

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"
Code Block
titleGenerated java files
File: MyBits.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160718.test;
import java.util.BitSet;
import java.util.Objects;
import com.google.common.base.MoreObjects;
/**
 * Represents the implementation of myBits.
 */
public final class MyBits {
    private BitSet bits;
    /**
     * Creates an instance of myBits.
     */
    private MyBits() {
    }
    /**
     * Creates an instance of myBitsForTypeBits.
     *
     * @param value value of myBitsForTypeBits
     */
    public MyBits(BitSet value) {
        this.bits = value;
    }
    /**
     * Returns the object of myBitsForTypeBits.
     *
     * @param value value of myBitsForTypeBits
     * @return Object of myBitsForTypeBits
     */
    public static MyBits of(BitSet value) {
        return new MyBits(value);
    } leaf ds0ChannelNumber {
    /**
     * Returns the attribute bits.
    type *int16;
     * @return value of bits}
     */
    public BitSet bits() {
}
}
Code Block
titleGenerated Java files
 
File: TestService.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160721;

public interface TestService {

        return bits;Test getTest();

    }
void    @OverridesetTest(Test test);

    publicTest int hashCodegetAugmentedTestYangAutoPrefixInterface() {;

    void    return Objects.hash(bitssetAugmentedTestYangAutoPrefixInterface(Test augmentedTestYangAutoPrefixInterface);
    
}
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        } 
File: TestManager.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160721;

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 TestManager implements TestService {

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

    @Activate
    public void activate() {
        //TODO: YANG utils generated code
        if (obj instanceof MyBits) {log.info("Started");
    }

    @Deactivate
    MyBitspublic othervoid = deactivate(MyBits) obj;{
        //TODO: YANG utils generated returncode
                 Objects.equals(bits, other.bitslog.info("Stopped");
    }

    }@Override
    public Test   return false;getTest() {
    }
    @Override
 //TODO: YANG utils public String toString() {generated code
        return bits.toString()null;
    }

    /**@Override
    public *void Returns the object of myBits fromString input String.setTest(Test test) {
     *
   //TODO: YANG *utils @param valInString input Stringgenerated code
     * @return Object of myBits}

     */@Override
    public staticTest MyBits fromString(String valInStringgetAugmentedTestYangAutoPrefixInterface() {
        try {
   //TODO: YANG utils generated code
         BitSet tmpVal = new BitSet()return null;
    }

    @Override
    valInStringpublic =void valInString.replace('{', ' ');setAugmentedTestYangAutoPrefixInterface(Test augmentedTestYangAutoPrefixInterface) {
        //TODO: YANG utils generated valInStringcode
 = valInString.replace('}', ' ');
            valInString = valInString.trim(); }

}
 
File : AugmentedYangAutoPrefixInterface.java

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

import org.onosproject.yangutils.datamodel.YangAugmentedInfo;

public interface AugmentedYangAutoPrefixInterface extends YangAugmentedInfo  {

    short ds0ChannelNumber();

    interface AugmentedYangAutoPrefixInterfaceBuilder {

      String[] bitsTemp =short valInString.split(",", 0ds0ChannelNumber();

        AugmentedYangAutoPrefixInterfaceBuilder    for (String bitTemp : bitsTemp) {ds0ChannelNumber(short ds0ChannelNumber);

        AugmentedYangAutoPrefixInterface build();
    }
}

File :  bitTemp = bitTemp.trim();
     DefaultAugmentedYangAutoPrefixInterface.java

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

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

public class DefaultAugmentedYangAutoPrefixInterface implements AugmentedYangAutoPrefixInterface {

    protected short ds0ChannelNumber;

     tmpVal.set(Integer.parseInt(bitTemp));@Override
    public short ds0ChannelNumber() {
     }
   return ds0ChannelNumber;
    }

    return of(tmpVal);@Override
    public    } catch (Exception eint hashCode() {
        }return Objects.hash(ds0ChannelNumber);
    }

    return null;@Override
    }
}

 

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 Testpublic boolean equals(Object obj) {
   yang-version 1;
   namespace http://huawei.com;
   prefix Ant;
 if (this == obj) {
   typedef MyBinary {
      type binaryreturn {true;
         length "4";}
      }
   }
}

 

Code Block
titleGenerated java files
File: MyBinary.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160718.test;
import java.util.Objects;
import com.google.common.base.MoreObjects;
import java.util.Base64;
/**
 * Represents the implementation of myBinary.
 */
public final class MyBinary {
   private byte[] binary;

   /**
   * Creates an instance of myBinary.
   */
   private MyBinary() {
   }

   /**
   * Creates an instance of myBinaryForTypeBinary.
   *
   * @param value value of myBinaryForTypeBinary
   */
   public MyBinary(byte[] valueif (obj instanceof DefaultAugmentedYangAutoPrefixInterface) {
            DefaultAugmentedYangAutoPrefixInterface other = (DefaultAugmentedYangAutoPrefixInterface) obj;
            return
                 Objects.equals(ds0ChannelNumber, other.ds0ChannelNumber);
        }
        return false;
    }

    @Override
    public String toString() {
      this.binary  = value;return MoreObjects.toStringHelper(getClass())
   }         .add("ds0ChannelNumber", ds0ChannelNumber)
 
   /**
   * Returns the object of myBinaryForTypeBinary.toString();
   * }

    public * @param value value of myBinaryForTypeBinary
DefaultAugmentedYangAutoPrefixInterface(AugmentedYangAutoPrefixInterfaceBuilder builderObject) {
      * @return Objectthis.ds0ChannelNumber of myBinaryForTypeBinary= builderObject.ds0ChannelNumber();
   */ }

    public static MyBinary of(byte[] value) class AugmentedYangAutoPrefixInterfaceBuilder implements AugmentedYangAutoPrefixInterface
                .AugmentedYangAutoPrefixInterfaceBuilder {

      return  protected new MyBinary(value)short ds0ChannelNumber;


   }
 
   /**
     @Override
        public short ds0ChannelNumber() {
         * Returns the attributereturn binary.ds0ChannelNumber;
   *
     }

    * @return value of binary@Override
   */
     public byte[]AugmentedYangAutoPrefixInterfaceBuilder binaryds0ChannelNumber(short ds0ChannelNumber) {
         return binary;
  this.ds0ChannelNumber }
= ds0ChannelNumber;
   @Override
   public int hashCode() {
      return Objects.hash(binary);
   }
 
   @Override
   public boolean equals(Object obj) {
      if (this == obj) {
         return true;
      }
      if (obj instanceof MyBinary) {
         MyBinary other = (MyBinary) obj;
         return Objects.equals(binary, other.binary);
      }
      return false;
   }
 
   @Override
   public String toString() {
      return Base64.getEncoder().encodeToString(binary);
   }
 
   /**
   * Returns the object of myBinary fromString input String.
   *
   * @param valInString input String
   * @return Object of myBinary
   */
   public static MyBinary fromString(String valInString) {
      try {
         byte[] tmpVal = Base64.getDecoder().decode(valInString);
         return of(tmpVal);
      } catch (Exception e) {
      }
      return null;
   }
}

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
         return this;
        }
        @Override
        public AugmentedYangAutoPrefixInterface build() {
            return new DefaultAugmentedYangAutoPrefixInterface(this);
        }

        public AugmentedYangAutoPrefixInterfaceBuilder() {
        }
    }
}
 
File:AugmentedYangAutoPrefixInterfaceOpParam.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160721.test;

import java.util.BitSet;
import org.onosproject.yangutils.datamodel.YangAugmentedOpParamInfo;

public class AugmentedYangAutoPrefixInterfaceOpParam extends DefaultAugmentedYangAutoPrefixInterface  implements
            YangAugmentedOpParamInfo {
    public static enum OperationType {
        MERGE,
        REPLACE,
        CREATE,
        DELETE,
        REMOVE
    }
    private OperationType opParamType;
    private BitSet filterLeafFlags = new BitSet();
    private BitSet selectLeafFlags = new BitSet();


    public BitSet getFilterLeafFlags() {
        return filterLeafFlags;
    }

    public BitSet getSelectLeafFlags() {
        return selectLeafFlags;
    }

    public OperationType getOpertionType() {
        return opParamType;
    }

    public boolean isFilterContentMatch(Object obj) {
        DefaultAugmentedYangAutoPrefixInterface appInstance = (DefaultAugmentedYangAutoPrefixInterface)obj;
        if (getFilterLeafFlags().get(1)) {
            if (appInstance.ds0ChannelNumber() != ds0ChannelNumber()) {
                return false;
            }
        }
        return true;
    }

    public AugmentedYangAutoPrefixInterfaceOpParam(AugmentedYangAutoPrefixInterfaceOpParamBuilder builderObject) {
        super(builderObject);
        filterLeafFlags = builderObject.getFilterLeafFlags();
    }

    @Override
    public Class<?> getBaseClass() {
        return DefaultAugmentedYangAutoPrefixInterface.class;
    }

    public class AugmentedYangAutoPrefixInterfaceOpParamBuilder extends DefaultAugmentedYangAutoPrefixInterface
                .AugmentedYangAutoPrefixInterfaceBuilder {
        private OperationType opParamType;
        private BitSet filterLeafFlags = new BitSet();
        private BitSet selectLeafFlags = new BitSet();


        @Override
        public AugmentedYangAutoPrefixInterfaceBuilder ds0ChannelNumber(short recvds0ChannelNumber) {
            ds0ChannelNumber = recvds0ChannelNumber;
            getFilterLeafFlags().set(1);
            return this;
        }

        public BitSet getFilterLeafFlags() {
            return filterLeafFlags;
        }

        public BitSet getSelectLeafFlags() {
            return selectLeafFlags;
        }

        public OperationType getOpertionType() {
            return opParamType;
        }

        public void setOpertionType(OperationType operationType) {
            this.opParamType = operationType;
        }
    }
}

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

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 {                         
    type string;
}

leaf two {                           
    type int32;
}

leaf-list three {
    type boolean;
}

leaf-list four {            
    type int16;
}
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 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.rev20160526.test;

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

public final class Percent {

    private short uint8;

    private Percent() {
    }


    public Percent(short value) {
        this.uint8 = value;
    }

    public static Percent of(short value) {
        return new Percent(value);
    }

    public short uint8() {
        return uint8;
    }

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

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

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

    public static Percent fromString(String valInString) {
        try {
            short tmpVal = Short.parseShort(valInString);
            return of(tmpVal);
          } catch (Exception e) {
          }
          return null;
    }
}

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;
    namespace "http://huawei.com";
    prefix Ant;
    description "Interval before a route is declared invalid";

    leaf  packetType {
         type enumeration {
             enum "unbounded";
             enum ZERO;
           enum two;
             enum four;
         }         
       }
}
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) {
        packetTypeEnum = value;
    }

    public static PacketTypeEnum of(int value) {
        switch (value) {
            case 0:
                return PacketTypeEnum.UNBOUNDED;
            case 1:
                    return PacketTypeEnum.ZERO;
            case 2:
                    return PacketTypeEnum.TWO;
            case 3:
                    return PacketTypeEnum.FOUR;
            default :
                    return null;
            }
    }


    public int packetTypeEnum() {
            return packetTypeEnum;
    }

    public static PacketTypeEnum fromString(String valInString) {
            try {
                int tmpVal = Integer.parseInt(valInString);
                return of(tmpVal);
            } catch (Exception e) {
        }
        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 {
        type union {
            type int32;
            type uint32;
        }
    }
}
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.int32 = value;
    }

    public IpAddressUnion(long value) {
        this.uint32 = value;
    }

    public static IpAddressUnion of(int value) {
        return new IpAddressUnion(value);
    }

    public static IpAddressUnion of(long value) {
        return new IpAddressUnion(value);
    }

    public int int32() {
        return int32;
    }

    public long uint32() {
        return uint32;
    }

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

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

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

    public static IpAddressUnion fromString(String valInString) {
        try {
          int tmpVal = Integer.parseInt(valInString);
          return of(tmpVal);
        } catch (Exception e) {
        }
        try {
          long tmpVal = Long.parseLong(valInString);
          return of(tmpVal);
        } catch (Exception e) {
        }
        return null;
   }
}

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 {
    yang-version 1;
    namespace "http://huawei.com";
    prefix "test";

    typedef ip-address {
        type union {
            type int32;
            type uint16;
            type int64;
            type uint32;
            type string;
        }
    }
}
Code Block
titleGenerated java files
File : IpAddressUnion.java

package org.onosproject.yang.gen.v1.http.huawei.com.rev20160721.test.ipaddress;
import com.google.common.base.MoreObjects;
import java.math.BigInteger;
import java.util.Objects;
public final class IpAddressUnion {
    private static final int INT32_MIN_RANGE = -2147483648;
    private static final int INT32_MAX_RANGE = 2147483647;
    private static final BigInteger INT64_MIN_RANGE = new BigInteger("-9223372036854775808");
    private static final BigInteger INT64_MAX_RANGE = new BigInteger("9223372036854775807");
    private int int32;
    private int uint16;
    private long int64;
    private long uint32;
    private String string;
    private IpAddressUnion() {
    }
    public IpAddressUnion(String value) {
        this.string = value;
    }
    public IpAddressUnion(int value) {
        if (validateRange(INT32_MIN_RANGE, INT32_MAX_RANGE, value)) {
            this.int32 = value;
        } else {
            this.uint16 = value;
        }
    }
    public IpAddressUnion(long value) {
        if (validateRange(INT64_MIN_RANGE, INT64_MAX_RANGE, value)) {
            this.int64 = value;
        } else {
            this.uint32 = value;
        }
    }
    public static IpAddressUnion of(String value) {
        return new IpAddressUnion(value);
    }
    public static IpAddressUnion of(int value) {
        return new IpAddressUnion(value);
    }
    public static IpAddressUnion of(long value) {
        return new IpAddressUnion(value);
    }
    public String string() {
        return string;
    }
    public int int32() {
        return int32;
    }
    public long int64() {
        return int64;
    }
    @Override
    public int hashCode() {
        return Objects.hash(int32, uint16, int64, uint32, string);
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof IpAddressUnion) {
            IpAddressUnion other = (IpAddressUnion) obj;
            return
                 Objects.equals(int32, other.int32) &&
                 Objects.equals(uint16, other.uint16) &&
                 Objects.equals(int64, other.int64) &&
                 Objects.equals(uint32, other.uint32) &&
                 Objects.equals(string, other.string);
        }
        return false;
    }
    @Override
    public String toString() {
        return MoreObjects.toStringHelper(getClass())
            .omitNullValues()
            .add("int32", int32)
            .add("uint16", uint16)
            .add("int64", int64)
            .add("uint32", uint32)
            .add("string", string)
            .toString();
    }
    public static IpAddressUnion fromString(String valInString) {
        try {
            String tmpVal = (valInString);
            return of(tmpVal);
        } catch (Exception e) {
        }
        try {
            int tmpVal = Integer.parseInt(valInString);
            return of(tmpVal);
        } catch (Exception e) {
        }
        try {
            long tmpVal = Long.parseLong(valInString);
            return of(tmpVal);
        } catch (Exception e) {
        }
        return null;
    }
    private boolean validateRange(int minRange, int maxRange, int value) {
        return value >= minRange && value<= maxRange;
    }
    private boolean validateRange(BigInteger minRange, BigInteger maxRange, long value) {
        BigInteger bigInteger = new BigInteger(" " + value);
        return bigInteger.compareTo(minRange) == 1 && bigInteger.compareTo(maxRange) == 1;
    }
}

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.

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;

    container networks {
        description
            "Serves as top-level container for a list of
            networks.";
        leaf network-id {
            type uint8;
            description
            "Identifies a network.";
        }
    }
    container network-id {
        description
            "Serves as top-level container for a list of
            networks.";
        leaf network-id {
            type leafref {
                path "/nd:networks/nd:network-id";
            }
        }
    }
}
Code Block
titleGenerated java files
File : Networks.java
public interface Networks { 
    short networkId(); 
    interface NetworksBuilder { 
        short networkId();
        NetworksBuilder networkId(short networkId); 
        Networks build();
    }
}

File : NetworkId.java
public interface NetworkId { 
    short networkRef(); 
    interface NetworkIdBuilder { 
        short networkRef();
        NetworkIdBuilder networkRef(short networkRef); 
        NetworkId build();
    }
} 

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 {
    yang-version 1;
    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
public abstract class TunnelType {
}

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 tunnel-type {
      description  "Base identity from which specific tunnel types are derived.";
    }

    container network-id {
        description "Serves as top-level container for a list of networks.";
        leaf leaf-network-id {
            type identityref {
                base tunnel-type;
            }
        }
    }

}
Code Block
titleGenerated java files
File : TunnelType.java
public abstract class TunnelType {
}
 
File : NetworkId.java
public interface NetworkId { 
    TunnelType leafNetworkId(); 
    interface NetworkIdBuilder { 
        TunnelType leafNetworkId(); 
        NetworkIdBuilder leafNetworkId(TunnelType leafNetworkId); 
        NetworkId build();
    }
} 

 

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 {
        type bits {
             bit disable-nagle {
                 position 0;
             }
             bit auto-sense-speed {
                 position 1;
             }
             bit Mb-only {
                 position 2;
             }
         }
    }
}

 

Code Block
titleGenerated java files
File: MyBits.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160718.test;
import java.util.BitSet;
import java.util.Objects;
import com.google.common.base.MoreObjects;
/**
 * Represents the implementation of myBits.
 */
public final class MyBits {
    private BitSet bits;
    /**
     * Creates an instance of myBits.
     */
    private MyBits() {
    }
    /**
     * Creates an instance of myBitsForTypeBits.
     *
     * @param value value of myBitsForTypeBits
     */
    public MyBits(BitSet value) {
        this.bits = value;
    }
    /**
     * Returns the object of myBitsForTypeBits.
     *
     * @param value value of myBitsForTypeBits
     * @return Object of myBitsForTypeBits
     */
    public static MyBits of(BitSet value) {
        return new MyBits(value);
    }
    /**
     * Returns the attribute bits.
     *
     * @return value of bits
     */
    public BitSet bits() {
        return bits;
    }
    @Override
    public int hashCode() {
        return Objects.hash(bits);
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof MyBits) {
            MyBits other = (MyBits) obj;
            return
                 Objects.equals(bits, other.bits);
        }
        return false;
    }
    @Override
    public String toString() {
        return bits.toString();
    }
    /**
     * Returns the object of myBits fromString input String.
     *
     * @param valInString input String
     * @return Object of myBits
     */
    public static MyBits fromString(String valInString) {
        try {
            BitSet tmpVal = new BitSet();
            valInString = valInString.replace('{', ' ');
            valInString = valInString.replace('}', ' ');
            valInString = valInString.trim();
            String[] bitsTemp = valInString.split(",", 0);
            for (String bitTemp : bitsTemp) {
                bitTemp = bitTemp.trim();
                tmpVal.set(Integer.parseInt(bitTemp));
            }
            return of(tmpVal);
        } catch (Exception e) {
        }
        return null;
    }
}

 

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";
      }
   }
}

 

Code Block
titleGenerated java files
File: MyBinary.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160718.test;
import java.util.Objects;
import com.google.common.base.MoreObjects;
import java.util.Base64;
/**
 * Represents the implementation of myBinary.
 */
public final class MyBinary {
   private byte[] binary;

   /**
   * Creates an instance of myBinary.
   */
   private MyBinary() {
   }

   /**
   * Creates an instance of myBinaryForTypeBinary.
   *
   * @param value value of myBinaryForTypeBinary
   */
   public MyBinary(byte[] value) {
      this.binary = value;
   }
 
   /**
   * Returns the object of myBinaryForTypeBinary.
   *
   * @param value value of myBinaryForTypeBinary
   * @return Object of myBinaryForTypeBinary
   */
   public static MyBinary of(byte[] value) {
      return new MyBinary(value);
   }
 
   /**
   * Returns the attribute binary.
   *
   * @return value of binary
   */
   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) {
         MyBinary other = (MyBinary) obj;
         return Objects.equals(binary, other.binary);
      }
      return false;
   }
 
   @Override
   public String toString() {
      return Base64.getEncoder().encodeToString(binary);
   }
 
   /**
   * Returns the object of myBinary fromString input String.
   *
   * @param valInString input String
   * @return Object of myBinary
   */
   public static MyBinary fromString(String valInString) {
      try {
         byte[] tmpVal = Base64.getDecoder().decode(valInString);
         return of(tmpVal);
      } catch (Exception e) {
      }
      return null;
   }
}

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;

/**
 * Represents the implementation of myDecimal.
 */
public final class MyDecimal {
    private BigDecimal decimal64;

    /**
     * Creates an instance of myDecimal.
     */
    private MyDecimal() {
    }

    /**
     * Creates an instance of myDecimalForTypeDecimal64.
     *
     * @param value value of myDecimalForTypeDecimal64
     */
    public MyDecimal(BigDecimal value) {
        this.decimal64 = value;
    }

    /**
     * Returns the object of myDecimalForTypeDecimal64.
     *
     * @param value value of myDecimalForTypeDecimal64
     * @return Object of myDecimalForTypeDecimal64
     */
    public static MyDecimal of(BigDecimal value) {
        return new MyDecimal(value);
    }

    /**
     * Returns the attribute decimal64.
     *
     * @return value of decimal64
     */
    public BigDecimal decimal64() {
        return decimal64;
    }

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

    @Override
    public boolean equals(Object obj) {
        if (this == obj)

 

Code Block
titleinput YANG file
File : test.yang
module Test {
    yang-version 1;
    namespace http://huawei.com;
    prefix Ant;

    typedef MyDecimal {
        type decimal64 {
            fraction-digitsreturn 2;true;
        }
        if (obj instanceof  range "1 .. 3.14 | 10 | 20..max";
MyDecimal) {
            MyDecimal other = (MyDecimal) obj;
          }
  return
             }
}
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;

/**
 * Represents the implementation of myDecimal.
 */
public final class MyDecimal     Objects.equals(decimal64, other.decimal64);
        }
        return false;
    }

    @Override
    public String toString() {
    private  BigDecimal decimal64;

 return MoreObjects.toStringHelper(getClass())
  /**
     * Creates an instance of myDecimal..add("decimal64", decimal64)
     */
      private MyDecimal.toString() {;
    }

    /**
     * CreatesReturns anthe instanceobject of myDecimalForTypeDecimal64 myDecimal fromString input String.
     *
     * @param value value valInString input String
     * @return Object of myDecimalForTypeDecimal64myDecimal
     */
    public static MyDecimal fromString(BigDecimalString valuevalInString) {
        this.decimal64 = value;
    }
try {
            BigDecimal tmpVal = new BigDecimal(valInString);
    /**
     * Returns the objectreturn of myDecimalForTypeDecimal64.(tmpVal);
     *
   } catch *(Exception @parame) value{
 value of myDecimalForTypeDecimal64
     *}
 @return Object of myDecimalForTypeDecimal64
    return */null;
    public static MyDecimal of(BigDecimal value) {
        return new MyDecimal(value);
    }

    /**
     * Returns the attribute decimal64.
     *
     * @return value of decimal64
     */
    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();
    }

    /**
     * Returns the object of myDecimal fromString input String.
     *
     * @param valInString input String
     * @return Object of myDecimal
     */
    public static MyDecimal fromString(String valInString) {
        try {
            BigDecimal tmpVal = new BigDecimal(valInString);
            return of(tmpVal);
        } catch (Exception e) {
        }
        return null;
    }
}

 

Golden Eye Demo 

Link: https://www.youtube.com/watch?v=ipbu0x0LcDk

Presentation: YANG Demo.pptx

References

RFC6020 - https://tools.ietf.org/html/rfc6020

 

NameOrganizationEmail
Adarsh MHuawei Technologiesadarsh.m@huawei.com
Bharat SaraswalHuawei Technologiesbharat.saraswal@huawei.com
 }
}

 

Golden Eye Demo 

Link: https://www.youtube.com/watch?v=ipbu0x0LcDk

Presentation: YANG Demo.pptx

References

RFC6020 - https://tools.ietf.org/html/rfc6020

 

NameOrganizationEmail
Adarsh MHuawei Technologiesadarsh.m@huawei.com
Bharat SaraswalHuawei Technologiesbharat.saraswal@huawei.com

 



package org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem;
import com.google.common.base.MoreObjects;import java.util.HashMap;import java.util.Map;import java.util.Objects;import org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.system.Login;import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
public class DefaultSystem implements System {
    private Map<Class<?>, YangAugmentedInfo> yangAugmentedInfoMap = new HashMap<>();    protected Login login;
    @Override    public Login login() {        return login;    }
    @Override    public int hashCode() {        return Objects.hash(login);    }
    @Override    public boolean equals(Object obj) {        if (this == obj) {            return true;        }        if (obj instanceof DefaultSystem) {            DefaultSystem other = (DefaultSystem) obj;            return                 Objects.equals(login, other.login);        }        return false;    }
    @Override    public String toString() {        return MoreObjects.toStringHelper(getClass())            .add("login", login)            .toString();    }
    public DefaultSystem(SystemBuilder builderObject) {        this.login = builderObject.login();    }
    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;    }
    public class SystemBuilder implements System.SystemBuilder {
        protected Login login;

        @Override        public Login login() {            return login;        }
        @Override        public SystemBuilder login(Login login) {            this.login = login;            return this;        }        @Override        public System build() {            return new DefaultSystem(this);        }
        public SystemBuilder() {        }    }} 



package org.onosproject.yang.gen.v1.http.acme.example.com.systemospf.rev20070609rev20160721.acmesystemospf;
import com.google.common.base.MoreObjects;import java.util.HashMap;import java.util.Map;import java.util.Objects;import org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.system.Login;import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
public class DefaultSystem DefaultTest implements System Test {
    private Map<Class<?>, YangAugmentedInfo> yangAugmentedInfoMap = new HashMap<>();    protected String eventClass;    protected String severity;
    @Override    public String eventClass() {        return eventClass;    protected Login login;}
    @Override    public Login loginString severity() {        return loginseverity;    }
    @Override    public int hashCode() {        return Objects.hash(logineventClass, severity);    }
    @Override    public boolean equals(Object obj) {        if (this == obj) {            return true;        }        if (obj instanceof DefaultSystemDefaultTest) {            DefaultSystem DefaultTest other = (DefaultSystemDefaultTest) obj;            return                 Objects.equals(eventClass, other.eventClass) &&                 Objects.equals(loginseverity, other.loginseverity);        }        return false;    }
    @Override    public String toString() {        return MoreObjects.toStringHelper(getClass())            .add("eventClass", eventClass)            .add("loginseverity", loginseverity)            .toString();    }
    public DefaultSystemDefaultTest(SystemBuilder TestBuilder builderObject) {        this.eventClass = builderObject.eventClass();        this.login severity = builderObject.loginseverity();    }
    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;    }
    public class SystemBuilder TestBuilder implements SystemTest.SystemBuilder TestBuilder {
        protected Login login;String eventClass;        protected String severity;

        @Override        public String eventClass() {            return eventClass;        }
        @Override        public String severity() {            return severity;        }
        @Override        public Login loginTestBuilder eventClass(String eventClass) {            return loginthis.eventClass = eventClass;            return this;        }
        @Override        public SystemBuilder login(Login loginTestBuilder severity(String severity) {            this.login severity = loginseverity;            return this;        }        @Override        public System Test build() {            return new DefaultSystemDefaultTest(this);        }
        public SystemBuilderTestBuilder() {        }    }}