Versions Compared

Key

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

...

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

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

...

Code Block
titleGenerated Java files
File : LoginSystem.java
public interface Login extends AugmentationHolder   
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 {
    StringLogin messagelogin();
    interface LoginBuilderSystemBuilder {
        StringLogin messagelogin();
        LoginBuilderSystemBuilder messagelogin(StringLogin messagelogin);
        LoginSystem build();
    }
}

 
File : SystemBuilderDefaultSystem.java

public class LoginBuilder implements Login.LoginBuilder {
    private String message;

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

    @Override
    public LoginBuilder message(String message) {
        this.message = message;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 thislogin;
    }

    @Override
    public Loginint buildhashCode() {
        return new LoginImpl(thisObjects.hash(login);
    }
    public LoginBuilder() {
    }@Override
    public finalboolean class LoginImpl implements Loginequals(Object obj) {
        privateif List<AugmentedInfo>(this augmentedInfoList == new ArrayList<>();
obj) {
          private  Stringreturn messagetrue;

        @Override}
        if public(obj Stringinstanceof message(DefaultSystem) {
            DefaultSystem other = return(DefaultSystem) messageobj;
        }    return

        @Override
        public int hashCode() {
 Objects.equals(login, other.login);
        }
        return Objects.hash(message)false;
    }

    }
@Override
    public String toString()  @Override{
        public boolean equals(Object obj) {return MoreObjects.toStringHelper(getClass())
            if (this == obj) {
.add("login", login)
            .toString();
    }

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

    public ifvoid addAugmentedInfo(obj instanceof LoginImplYangAugmentedInfo value, Class classObject) {
        yangAugmentedInfoMap.put(classObject, value);
    }

   LoginImpl otherpublic =YangAugmentedInfo getAugmentedInfo(LoginImplClass classObject) obj;{
        return yangAugmentedInfoMap.get(classObject);
    }

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

    Objects.equals(message, other.message);
            }public class SystemBuilder implements System.SystemBuilder {

        protected Login   return falselogin;
        }

        @Override
        public StringLogin toStringlogin() {
            return MoreObjects.toStringHelper(getClass())login;
        }

        .add("message", message)@Override
        public SystemBuilder login(Login      .toString();login) {
        }
    this.login = login;
  public LoginImpl(LoginBuilder builderObject) {
        return    this.message = builderObject.message();
        }

        @Override
        public voidSystem addAugmentationbuild(AugmentedInfo value) {
            return new getAugmentedInfoList().add(valueDefaultSystem(this);
        }

        @Override
        public List<AugmentedInfo> getAugmentedInfoListSystemBuilder() {
            return augmentedInfoList;
    }
    }

        @Override
        public void removeAugmentation() {
            getAugmentedInfoList().clear();
        }
    }
}

List

Overview
}

List

Overview

List is also like container that 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.

...

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

    String name();
    String fullNameList<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login.Login> login();
    String addThisBeforeClass();
    interface LoginBuilder {

        String name();
        String fullNameList<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login.Login> login();
        LoginBuilder name(String addThisBeforeClass(name);
        LoginBuilder name(String name);login(List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem
        LoginBuilder fullName(String fullName);
        .login
               LoginBuilder addThisBeforeClass(String addThisBeforeClass.Login> login);

        Login build();
    }
}

File : LoginBuilderDefaultLogin.java


public class LoginBuilder implements Login.LoginBuilder {
    private String name;
    private String fullName;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 String addThisBeforeClass;

    @OverrideMap<Class<?>, YangAugmentedInfo> yangAugmentedInfoMap = new HashMap<>();
    publicprotected String name() {;
        return name;
    }protected List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login.Login> login;

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

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

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

    @Override
    public LoginBuilderboolean fullNameequals(StringObject fullNameobj) {
        if (this.fullName = fullName;
= obj) {
            return thistrue;
        }

    @Override
    publicif LoginBuilder addThisBeforeClass(String addThisBeforeClass(obj instanceof DefaultLogin) {
            DefaultLogin this.addThisBeforeClassother = (DefaultLogin) addThisBeforeClassobj;
            return
   this;
    }

    @Override
    public Login build(Objects.equals(name, other.name) {&&
        return new LoginImpl(this         Objects.equals(login, other.login);
        }
    public LoginBuilder() {    return false;
    }

    @Override
 public final class LoginImplpublic implementsString LogintoString() {
        private List<AugmentedInfo> augmentedInfoList = new ArrayList<>();return MoreObjects.toStringHelper(getClass())
        private String name;
  .add("name", name)
     private String fullName;
     .add("login", login)
  private String addThisBeforeClass;

        @Override.toString();
    }

    public String name(DefaultLogin(LoginBuilder builderObject) {
        this.name    return name= builderObject.name();
        }

  this.login = builderObject.login();
      @Override}

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

    public YangAugmentedInfo getAugmentedInfo(Class classObject) @Override{
        public String addThisBeforeClass() {return yangAugmentedInfoMap.get(classObject);
    }

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

    public class LoginBuilder implements Login.LoginBuilder @Override{

        publicprotected int hashCode() {String name;
        protected List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login
   return Objects.hash(name, fullName, addThisBeforeClass);
        }.Login> login;


        @Override
        public booleanString equalsname(Object obj) {
            if (this == obj) {return name;
        }

        return true;@Override
            }public List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.login
            if.Login> login(obj instanceof LoginImpl) {
                LoginImpl other = (LoginImpl) objreturn login;
        }

        return@Override
        public             Objects.equals(name, other.LoginBuilder name(String name) &&{
            this.name = name;
       Objects.equals(fullName, other.fullName) &&
   return this;
        }

         Objects.equals(addThisBeforeClass, other.addThisBeforeClass);@Override
        public    }LoginBuilder login(List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609
            return false;
        }

.acmesystem
        @Override
        public String toString(.login.Login> login) {
            return MoreObjects.toStringHelper(getClass())
  this.login = login;
              .add("name", name)return this;
        }
        .add("fullName", fullName)@Override
        public        .add("addThisBeforeClass", addThisBeforeClass)Login build() {
            return new   .toStringDefaultLogin(this);
        }

        public LoginImplLoginBuilder(LoginBuilder builderObject) {
        }
    this.name = builderObject.name();}
}
 

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";
    this.fullName = builderObject.fullName()organization "ACME Inc.";
    grouping endpoint { 
        this.addThisBeforeClassleaf = builderObject.addThisBeforeClass();
address {
            type int32; }

        } @Override
        public void addAugmentation(AugmentedInfo value)leaf port {
             getAugmentedInfoList().add(value);type int8; 
        }
    }
    container connection {  @Override
        publiccontainer List<AugmentedInfo>source getAugmentedInfoList() {
            returnuses augmentedInfoListendpoint;
        }

        @Override
        public void removeAugmentation() container destination {
            getAugmentedInfoList().clear() uses endpoint;
        }
    }
}

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

File : Login.java
public interface Login extends AugmentationHolder  {
    String name();
List<org.
    .
    .
}
Code Block
titleGenerated Java files
File : Connection.java
package org.onosproject.yang.gen.v1.http.acmetest.example.com.system.rev20070609.acmesystem.login.Login> login();
    interface LoginBuilder {
        String name();
List<orgrev20160718.test;

import org.onosproject.yang.gen.v1.http.acmetest.example.com.systemrev20160718.rev20070609test.acmesystem.login.Login> login();
   connection.Source;

public interface Connection {

    Source LoginBuilder name(String namesource();

    interface    LoginBuilder login(List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystemConnectionBuilder {

                .loginSource source();

        ConnectionBuilder        .Login> loginsource(Source source);

        LoginConnection build();
    }
}

File : LoginBuilderSource.java
public class LoginBuilder implements Login.LoginBuilder {
    private String name;
    private List<org
package org.onosproject.yang.gen.v1.http.acmetest.example.com.systemrev20160718.rev20070609.acmesystem.login.Login> logintest.connection;

public interface Source  @Override{

    publicint String nameaddress() {;

    byte port();

   return name;
interface SourceBuilder   }{

    @Override
    public List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609.acmesystem.loginint address();

        byte port();

   .Login> login() {
   SourceBuilder     return login;
    }address(int address);

    @Override
    publicSourceBuilder LoginBuilder nameport(Stringbyte nameport) {
        this.name = name;;

        returnSource thisbuild();
    }

    @Override
    public LoginBuilder login(}

 

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 {
List<org.onosproject.yang.gen.v1.http.acme.example.com.system.rev20070609
            .acmesystem
            .login.Login> login)choice interfaceType {
           this.login = login;
 case ethernerType {
                leaf ethernet { returntype thisstring; }
    }
    .
    .}
    .
    public final class LoginImpl implementscase Loginp2pType {
    .
    .
    .
    }
}

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 p2p { type string; }
            }
        leaf address {}
            type int32; 
        } 
        leaf port {
            type int8; 
        }
    }
    container connection { 
        container source {}
}
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 {

            uses endpoint;
        }String ethernet();

        containerEthernerTypeBuilder destination {ethernet(String ethernet);

            uses endpointEthernerType build();
        }
    }

File :   EthernerTypeBuilder.java
package    .
    .
}
Code Block
titleGenerated Java files
File : Connection.java
package org.org.onosproject.yang.gen.v1.http.huawei.testcom.examplerev20160509.comchoicecasetest.rev20160718link1.testinterfacetype;

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

public interface Connectioncom.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 {

    Source source();
private String ethernet;

    @Override
    public interfaceString ConnectionBuilderethernet() {

        Sourcereturn source();ethernet;
    }

    @Override
    public ConnectionBuilderEthernerTypeBuilder sourceethernet(SourceString source)ethernet) {
        this.ethernet = ethernet;

        Connectionreturn build()this;
    }
}
   @Override
File  : Source.java

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

public interface Source {

    int address(); public EthernerType build() {
       return new EthernerTypeImpl(this);
   }

   public byte portEthernerTypeBuilder(); {
   }

   public final class EthernerTypeImpl interfaceimplements SourceBuilderEthernerType {

        private intString address()ethernet;

        @Override
        public byteString portethernet() {
            return ethernet;
        }

        SourceBuilderpublic address(int address);EthernerTypeImpl() {
        }

        SourceBuilderpublic portEthernerTypeImpl(byteEthernerTypeBuilder portbuilderObject);

 {
                this.ethernet Source= buildbuilderObject.ethernet();
        }
    }
}

 

...

RPC

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 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 branches of the choice. It takes identifier as an argument, followed by a block of sub-statements that holds detailed case information.output parameters to the RPC.

JAVA mapping

Choice Rpc statement is mapped to interface(marker interface).

Case statement are mapped to the JAVA interfaces

It includes

...

Interface file which extends choice marker interface

...

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

...

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 : linksfc.yang
module linkSfc {
    yang-version 1;
    namespace http://huawei.com;
    prefix Ant;

    containerrpc linkSFP {
        choice interfaceTypeinput {
            caseleaf ethernerTypeport {
                leaf ethernet { type string; }
            }
          }
         case p2pTypeoutput {
            leaf path {
   leaf p2p {             type string; }
            }
          }
     }
}
Code Block
titleGenerated Java files
File : InterfaceTypeSfcService.java

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

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

public interface SfcService {
  InterfaceType extends AugmentationHolderSfpOutput  {sfp(SfpInput inputVar);
}

File : EthernerTypeSfcManager.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160509.choicecasetest.link1.interfacetype;
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.rev20160509rev20160526.choicecasetestsfc.link1sfp.InterfaceTypeSfpInput;
import org.onosproject.yangutils.translator.tojava.AugmentationHolder;

public interface EthernerType extends AugmentationHolder, InterfaceType  {

    String ethernet().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());

    interface EthernerTypeBuilder {
@Activate
    public void activate() {
 String ethernet();

      //TODO: YANG EthernerTypeBuilderutils ethernet(String ethernet);
generated code
        EthernerType build(log.info("Started");
    }
}

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 {
 @Deactivate
    public void deactivate() {
    private String ethernet;

  //TODO: YANG @Override
utils    public String ethernet() {generated code
        return ethernetlog.info("Stopped");
     }

     @Override
     public EthernerTypeBuilderSfpOutput ethernetsfp(StringSfpInput ethernetinputVar) {
        //TODO: YANG this.ethernetutils =generated ethernet;code
        return thisnull;
     }
}
   @Override
File   public EthernerType build() {
       return new EthernerTypeImpl(this);
   }: SfpInput.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.sfc.sfp;

public interface SfpInput {

   public String EthernerTypeBuilderport() {
   };

   public final class EthernerTypeImpl implements EthernerTypeinterface SfpInputBuilder {

        private String ethernetport();

        SfpInputBuilder  @Overrideport(String port);

        publicSfpInput String ethernetbuild();
 {
   }
}
File : SfpinputBuilder.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.sfc.sfp;

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

public class SfpInputBuilder implements return ethernet;SfpInput.SfpInputBuilder {

     private String  }port;

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

    @Override
    public SfpInputBuilder EthernerTypeImplport(EthernerTypeBuilderString builderObjectport) {
         this.port = port;
      this.ethernet = builderObject.ethernet()   return this;
    }

    }@Override
    }
}

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;
    namespace http://huawei.com;
    prefix Ant;
    rpc SFP {
public SfpInput build() {
         return new SfpInputImpl(this);
    }

    public SfpInputBuilder() {
    }

    public final class SfpInputImpl implements SfpInput {

         private inputString {
port;

        @Override
        public leafString port() {
            return port;
       type string;
 }

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

        @Override
     output   public boolean equals(Object obj) {
             if (this leaf== pathobj) {
                type return stringtrue;
             }
            if (obj instanceof SfpInputImpl) }{
     }
}
Code Block
titleGenerated Java files
File : SfcService.java

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

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

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

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

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

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

    @Activate
    public void activate() {
         SfpInputImpl other = (SfpInputImpl) obj;
                return
                     Objects.equals(port, other.port);
            }
            return false;
         }

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

    @Deactivate
    public void deactivate.toString() {;
        //TODO: YANG utils generated code
}

        public    log.info("Stopped");
     }

     @Override
SfpInputImpl(SfpInputBuilder builderObject) {
      public SfpOutput sfp(SfpInput inputVar) {
        //TODO: YANG utils generated codethis.port = builderObject.port();
        return null;}
     }
}

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

public interface SfpInputSfpOutput {

    String portpath();

    interface SfpInputBuilderSfpOutputBuilder {

        String portpath();

        SfpInputBuilderSfpOutputBuilder portpath(String portpath);

        SfpInputSfpOutput build();
     }
}
File : SfpinputBuilderSfpOutputBuilder.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 SfpInputBuilderSfpOutputBuilder implements SfpInputSfpOutput.SfpInputBuilderSfpOutputBuilder {

     private String portpath;

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

    @Override
    public SfpInputBuilderSfpOutputBuilder portpath(String portpath) {
         this.portpath = portpath;
         return this;
    }

    @Override
    public SfpInputSfpOutput build() {
         return new SfpInputImplSfpOutputImpl(this);
    }

    public SfpInputBuilderSfpOutputBuilder() {
    }

    public final class SfpInputImplSfpOutputImpl implements SfpInputSfpOutput {

         private String portpath;

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

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

         @Override
         public boolean equals(Object obj) {
             if (this == obj) {
                     return true;
             }
            if (obj instanceof SfpInputImplSfpOutputImpl) {
                 SfpInputImpl other = (SfpInputImpl SfpOutputImpl other = (SfpOutputImpl) obj;
                return
                     return Objects.equals(portpath, other.portpath);
            }
            return false;
         }

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

         public SfpInputImplSfpOutputImpl(SfpInputBuilderSfpOutputBuilder builderObject) {
                 this.portpath = builderObject.portpath();
         }
     }
}
File : Sfpoutput.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.sfc.sfp;

public interface SfpOutput {

    String path()

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

    interfacenotification SfpOutputBuildertest {

        String path();

  leaf event-class {
    SfpOutputBuilder path(String path);

        SfpOutputtype build()string;
     }
}
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 {

 }
          private String path;

    @Override
    public String path() {
leaf severity {
              returntype path;
    }
string;
    @Override
    public SfpOutputBuilder path(String path) { }
    }
}
Code Block
titleGenerated Java files
File :    this.path = path;
         return this;
    }

    @Override
    public SfpOutput build() {
         return new SfpOutputImpl(this);
    }

    public SfpOutputBuilder() {
    }

    public final class SfpOutputImpl implements SfpOutputOspfManager.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
        extends ListenerRegistry<OspfEvent, OspfListener>
        implements OspfService {

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

    @Activate
    public @Override
void activate() {
       public String path() {
  //TODO: YANG utils generated code
          return pathlog.info("Started");
    }

     }
@Deactivate
    public void    @Overridedeactivate() {
        //TODO: publicYANG intutils hashCode()generated {code
            return Objects.hash(pathlog.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  @OverrideOspfService
        extends public boolean equals(Object obj) {
            if (this == obj) {
                     return true;
            }
            if (obj instanceof SfpOutputImplListenerService<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> {

    public enum Type {

    TEST
    }

    public OspfEvent(Type type, OspfEventSubject subject) {
        super(type, subject);
    }

    public OspfEvent(Type type, OspfEventSubject subject, long time) {
        super(type, subject, time);
    }
}

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

public class OspfEventSubject {

  SfpOutputImpl other =private (SfpOutputImpl)Test objtest;

    public Test test() {
              return Objects.equals(path, other.path)test;
    }

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

          @Override }
}

File : OspfListener.java

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

import org.onosproject.event.EventListener;

public interface OspfListener extends EventListener<OspfEvent> {
}

File : Test.java

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

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

public interface Test extends AugmentationHolder  {

      String eventClass();

   public String toStringseverity() {
   ;

    interface TestBuilder {

         return MoreObjects.toStringHelper(getClassString eventClass());

         String severity();

        .add("path", path)
 TestBuilder eventClass(String eventClass);

         TestBuilder severity(String severity);

       .toString  Test build();
    }
}

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

import com.google.common.base.MoreObjects;
import  }

         public SfpOutputImpl(SfpOutputBuilder builderObject) {java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.onosproject.yangutils.translator.tojava.AugmentedInfo;

public class TestBuilder implements Test.TestBuilder {

    private String eventClass;
    private String severity;

    @Override
    this.pathpublic =String builderObject.patheventClass();
 {
        return eventClass;
    }

    @Override
    public String severity() }
}

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 {{
        return severity;
    }

    @Override
    public TestBuilder eventClass(String eventClass) {
        this.eventClass = eventClass;
        return this;
    }

    @Override
    public TestBuilder severity(String severity) {
        this.severity = severity;
        return this;
    }

    @Override
    public Test build() {
        return new TestImpl(this);
    }

    public TestBuilder() {
    }

    public final class TestImpl implements Test {

        private List<AugmentedInfo> augmentedInfoList leaf= event-class {
new ArrayList<>();
        private String eventClass;
        private typeString string;severity;

        @Override
        public String eventClass() }{
           leaf severityreturn {eventClass;
        }

       type string;@Override
        public String severity() }{
    }
}
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
        return severity;
        }

        @Override
        public int hashCode() {
            extends ListenerRegistry<OspfEventreturn Objects.hash(eventClass, OspfListener>severity);
        implements OspfService {}

    private final Logger log = getLogger(getClass());
 @Override
    @Activate
    public voidboolean activateequals(Object obj) {
        //TODO: YANG utils generated codeif (this == obj) {
        log.info("Started");
       return true;
            }

       @Deactivate
    public voidif deactivate(obj instanceof TestImpl) {
        //TODO: YANG utils generated code
     TestImpl other = log.info("Stopped");
(TestImpl) obj;
             }
}

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
   return Objects.equals(eventClass, other.eventClass) &&
           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<OspfEventObjects.Typeequals(severity, OspfEventSubject> {

other.severity);
     public enum Type {

    TEST}
    }

    public OspfEvent(Type type, OspfEventSubject subject)return {false;
        }

   super(type, subject);
    }@Override

    public OspfEvent(Type type, OspfEventSubject subject,public longString timetoString() {
          super(type, subject, time);  return MoreObjects.toStringHelper(getClass())
    }
}

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

public class OspfEventSubject {

    private Test test;

    public Test test() {
.add("eventClass", eventClass)
         return test;
    }

    public void test(Test test) {
.add("severity", severity)
           this.test = test;
    }
}

File : OspfListener.java

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

import org.onosproject.event.EventListener;

public interface OspfListener extends EventListener<OspfEvent> {
}

File : Test.java

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

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

public interface Test extends AugmentationHolder  {

    String eventClass();

    String severity();

    interface TestBuilder {

.toString();
        }

        public TestImpl(TestBuilder builderObject) {
            this.eventClass = builderObject.eventClass();
            this.severity   String eventClass= builderObject.severity();

         String severity();}

         TestBuilder eventClass(String eventClass);
@Override
        public TestBuildervoid severityaddAugmentation(StringAugmentedInfo severityvalue); {

           Test buildgetAugmentedInfoList().add(value);
    }
}

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

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

public class TestBuilder implements Test.TestBuilder {

 }

        @Override
     private String eventClass;
 public List<AugmentedInfo> getAugmentedInfoList() private{
 String severity;

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

    }

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

    @Override
    public TestBuildervoid eventClassremoveAugmentation(String eventClass) {
        this.eventClass = eventClass;
        return this;
    }

    @Override
    public TestBuilder severity(String severity) {
        this.severity = severitygetAugmentedInfoList().clear();
        return this;}
    }

    @Override
    public Test build() {
        return new TestImpl(this);
    }

    public TestBuilder() {
    }

    public final class TestImpl implements Test {

        private List<AugmentedInfo> augmentedInfoList = new ArrayList<>();
}

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

     augment "/Test/interface" {
          privateleaf Stringds0ChannelNumber eventClass;{
        private String severity;
       type int16;
         }
    }
}
Code Block
titleGenerated Java files
File : AugmentedInterface.java


package  @Override
        public String eventClass() org.onosproject.yang.gen.v1.http.huawei.com.rev20160428.test;
import org.onosproject.yangutils.utils.AugmentedInfo;

public interface AugmentedInterface extends AugmentedInfo  {
   
         return eventClass;
     short getDs0ChannelNumber();
   }

    interface AugmentedInterfaceBuilder  {
 @Override
        publicshort String severitygetDs0ChannelNumber() {;

        AgmentedInterfaceBuilder    return severity;
        }setDs0ChannelNumber(short ds0ChannelNumber);

        @Override
        public int hashCode() {AugmentedInterface build();
    }
}

File : AugmentedInterfaceBuilder.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160428.test;
import java.util.Objects;
import    return Objects.hash(eventClass, severity);
        }
com.google.common.base.MoreObjects;
import org.onosproject.yang.gen.v1.http.huawei.com.rev20160428.test.InterfaceBuilder.InterfaceImpl;

public class AugmentedInterfaceBuilder implements AugmentedInterface.AugmentedInterfaceBuilder {
   private short ds0ChannelNumber;

   @Override
   public short getDs0ChannelNumber() {
    public boolean equals(Object obj)return {ds0ChannelNumber;
   }

   @Override
   public AugmentedInterfaceBuilder if setDs0ChannelNumber(thisshort ==ds0ChannelNumber) obj) {
       this.ds0ChannelNumber = ds0ChannelNumber;
       return truethis;
   }

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

 if (obj instanceofpublic TestImplAugmentedInterfaceBuilder() {
   }

   public final class AugmentedInterfaceImpl implements AugmentedInterface {

     TestImpl other =private (TestImpl)short objds0ChannelNumber;

       @Override
       public short return Objects.equals(eventClass, other.eventClassgetDs0ChannelNumber() &&{
           return ds0ChannelNumber;
       }

    Objects.equals(severity, other.severity);
  @Override
       Public int hashCode() }{
            return falseObjects.hash(ds0ChannelNumber);
        }

        @Override
        public Stringboolean toStringequals(Object obj) {
           if (this return MoreObjects.toStringHelper(getClass())
 == obj) {
               return true;
   .add("eventClass", eventClass)
       }

           if  .add("severity", severity)(obj instanceof AugmentedInterfaceImpl) {
               AugmentedInterfaceImpl other   = .toString(AugmentedInterfaceImpl) obj;
          }

     return
   public   TestImpl(TestBuilder builderObject) {
            this.eventClass = builderObjectObjects.eventClass(equals(ds0ChannelNumber, other.ds0ChannelNumber);
           }
          this.severity = builderObject.severity()return false;
        }

        @Override
        public voidString addAugmentationtoString(AugmentedInfo value) {
           return getAugmentedInfoListMoreObjects.toStringHelper(getClass().add(value);
        }

        @Override
.add("ds0ChannelNumber", ds0ChannelNumber)
             public List<AugmentedInfo> getAugmentedInfoList.toString() {
;
       }

       Public AugmentedInterfaceImpl(AugmentedInterfaceBuilder returnbuilderObject) augmentedInfoList;{
         }

  this.ds0ChannelNumber = builderObject.getDs0ChannelNumber();
    @Override
      InterfaceImpl interfaceImpl public= voidnew removeAugmentationInterfaceBuilder() {
  .new InterfaceImpl();
          getAugmentedInfoList()interfaceImpl.clearaddAugmentation(this);
        }
    }
}

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();

...

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
File : Test.yang
module Testleaf one {
     yang-version 1;
     namespace "http://huawei.com";
     prefix Ant;
     description "Interval before
 a route is declaredtype invalid"string;

     container interface {
          leaf ifType {
}

leaf two {                type string;
          }
    type int32;
}

     augment "/Test/interface" leaf-list three {
          leaf ds0ChannelNumber {
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
Code Block
titleGenerated Java files
File : AugmentedInterfacetest.javayang


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

public interface AugmentedInterface extends AugmentedInfo  {
   module test {

    yang-version 1;
    namespace "http://huawei.com";
    short getDs0ChannelNumber();
   
prefix "test";

    typedef percent {
       interface AugmentedInterfaceBuildertype {uint8;
   
        short getDs0ChannelNumber();
description "Percentage";
    }

    AgmentedInterfaceBuilderleaf setDs0ChannelNumber(short ds0ChannelNumber);

completed {
        AugmentedInterfacetype build()percent;
    }
}
Code Block
titleGenerated Java file


File : AugmentedInterfaceBuilderPercent.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160428rev20160526.test;

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

public class AugmentedInterfaceBuilder implements AugmentedInterface.AugmentedInterfaceBuilder {
   private short ds0ChannelNumber;

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

   @Override
   public AugmentedInterfaceBuilderfinal setDs0ChannelNumber(short ds0ChannelNumber)  class Percent {

    private   this.ds0ChannelNumber = ds0ChannelNumbershort uint8;

    private   return this;
Percent() {
    }

  
 @Override
   public AugmentedInterface build(Percent(short value) {
       return new AugmentedInterfaceImpl(this);
   }

   public AugmentedInterfaceBuilder() {
this.uint8 = value;
    }

    public finalstatic classPercent AugmentedInterfaceImpl implements AugmentedInterfaceof(short value) {

        privatereturn short ds0ChannelNumbernew Percent(value);

       @Override}

       public short getDs0ChannelNumberuint8() {
           return ds0ChannelNumberuint8;
       }

       @Override
       Publicpublic int hashCode() {
           return Objects.hash(ds0ChannelNumberuint8);
       }

       @Override
       public boolean equals(Object obj) {
           if (this == obj) {
               return true;
           }

           if (obj instanceof AugmentedInterfaceImplPercent) {
               AugmentedInterfaceImpl other = (AugmentedInterfaceImpl) obj;
               return
     Percent other = (Percent) obj;
            return Objects.equals(ds0ChannelNumberuint8, other.ds0ChannelNumberuint8);
           }
           return false;
       }

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

    public static Percent Public AugmentedInterfaceImplfromString(AugmentedInterfaceBuilderString builderObject)valInString) {
        try {
            short this.ds0ChannelNumbertmpVal = builderObjectShort.getDs0ChannelNumberparseShort(valInString);
          InterfaceImpl interfaceImpl =return new InterfaceBuilder().new InterfaceImpl(of(tmpVal);
          } catch interfaceImpl.addAugmentation(this);
(Exception e) {
          }
         }
}

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

 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) {
Example
Code Block
titleInput YANG file
leaf one {                         
    type string;
}

leaf two {              case 0:
            
    typereturn int32;
}

leaf-list three {
PacketTypeEnum.UNBOUNDED;
            case 1:
                    typereturn boolean;
}

leaf-list four {PacketTypeEnum.ZERO;
            case 2:
                    return PacketTypeEnum.TWO;
            typecase 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 {
3:
                    return PacketTypeEnum.FOUR;
            default :
                    typereturn uint8null;
           description "Percentage";}
    }


    public leafint completedpacketTypeEnum() {
            typereturn percentpacketTypeEnum;
    }
}
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 {


    public static PacketTypeEnum fromString(String valInString) {
     private short uint8;

    private Percent()try {
    }

            int tmpVal = Integer.parseInt(valInString);
    public Percent(short value) {
        this.uint8 = value;
return of(tmpVal);
       }

    public static} Percentcatch of(shortException valuee) {
        }
        return new Percent(value)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 :  }

    public short uint8() test.yang
module test {
        return uint8yang-version 1;
    }

    @Override
    public int hashCode() {
        return Objects.hash(uint8)namespace "http://huawei.com";
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof Percent) {
            Percent other = (Percent) obj;prefix "test";

    typedef ip-address {
      return Objects.equals(uint8, other.uint8);  type union {
        }
    type int32;
    return false;
    }

   type @Overrideuint32;
    public  String toString() {}
    }
}
Code Block
titleGenerated java files
File : IpAddressUnion.java
package  return MoreObjects.toStringHelper(getClass())
    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    .add("uint8", uint8)int int32;
    private long uint32;

    private  .toStringIpAddressUnion(); {
    }

    public static Percent fromString(String valInStringIpAddressUnion(int value) {
        try {
            short tmpValthis.int32 = Short.parseShort(valInString)value;
    }

    public IpAddressUnion(long   return of(tmpVal);value) {
        this.uint32 = }value;
 catch (Exception e) {}

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

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

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

    public int int32() {
        return int32;
    }

    public long uint32() {
        return uint32;
    }

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

    @Override
    public boolean equals(Object obj)  enum "unbounded";{
        if (this == obj) {
            return enum ZEROtrue;
      }
       enum two;
if (obj instanceof IpAddressUnion) {
         enum four;
  IpAddressUnion other = (IpAddressUnion) obj;
   }         return
       }
}
Code Block
titleGenerated Java files
File : PacketTypeEnum.java

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

public enum PacketTypeEnum {

    UNBOUNDED(0),
Objects.equals(int32, other.int32) &&
    ZERO(1),

    TWO(2),

    FOUR(3);

    private int packetTypeEnum;

 Objects.equals(uint32, other.uint32);
      PacketTypeEnum(int value) {}
        packetTypeEnumreturn = valuefalse;
    }

    @Override
    public staticString PacketTypeEnum of(int valuetoString() {
        switchreturn MoreObjects.toStringHelper(getClass(value)) {
            case 0:.omitNullValues()
                return PacketTypeEnum.UNBOUNDED;.add("int32", int32)
            case 1:
      .add("uint32", uint32)
              return PacketTypeEnum.ZERO.toString();
    }

    public static IpAddressUnion fromString(String casevalInString) 2:{
        try {
          int tmpVal return= PacketTypeEnum.TWOInteger.parseInt(valInString);
            case 3:return of(tmpVal);
        } catch (Exception e) {
        return PacketTypeEnum.FOUR;}
        try {
   default :
      long tmpVal   = Long.parseLong(valInString);
          return nullof(tmpVal);
        } catch (Exception e) }{
    }


    public int packetTypeEnum() {
    }
        return packetTypeEnumnull;
    }
}
Code Block
titleGenerated Java files
File : FlowClassifierService.java
package    public static PacketTypeEnum fromString(String valInString) {
            try {org.onosproject.yang.gen.v1.sfc.flowclassifier.rev20160524;

import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20100924.ietfyangtypes.Uuid;

public interface FlowClassifierService {

                int tmpVal = Integer.parseInt(valInString);Uuid getId();

    void            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 : IpAddressUnionsetId(Uuid id);
}

File : FlowClassifierManager.java
package org.onosproject.yang.gen.v1.sfc.flowclassifier.rev20160524;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20100924.ietfyangtypes.Uuid;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;

@Component (immediate = true)
@Service
public class FlowClassifierManager implements FlowClassifierService {

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

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

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

    @Override
    public Uuid getId() {
        //TODO: YANG utils generated code
        return null;
    }

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

}

File : IetfYangTypesService.java
package org.onosproject.yang.gen.v1.httpurn.huaweiietf.comparams.rev20160526xml.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);
    }
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 intvoid int32activate() {
        return int32;
    }

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

    @Override@Deactivate
    public intvoid hashCodedeactivate() {
        return Objects.hash(int32, uint32);
    }

//TODO: YANG utils generated code
    @Override
    public boolean equals(Object obj) {log.info("Stopped");
    }
}

File : Uuid.java
package  if (this == obj) {
       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 returnString truestring;

    private Uuid() }{
    }

    ifpublic Uuid(objString instanceof IpAddressUnionvalue) {
        this.string = value;
  IpAddressUnion other = (IpAddressUnion) obj; }

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

    public String Objects.equals(int32, other.int32string() &&{
        return string;
    }

    Objects.equals(uint32, other.uint32);@Override
    public int hashCode()  }{
        return falseObjects.hash(string);
    }

    @Override
    public Stringboolean toStringequals(Object obj) {
        returnif MoreObjects.toStringHelper(getClass())
   (this == obj) {
         .omitNullValues()
   return true;
        .add("int32", int32)}
        if (obj instanceof  .add("uint32", uint32)
        Uuid) {
    .toString();
    }

    publicUuid staticother IpAddressUnion= fromString(String valInStringUuid) {obj;
           try {return
          int     tmpVal = IntegerObjects.parseInt(valInStringequals(string, other.string);
        }
    return of(tmpVal);
   return false;
    }

 catch (Exception e) {@Override
    public String toString()  }{
        try {
 return MoreObjects.toStringHelper(getClass())
         long tmpVal = Long.parseLong(valInString);
add("string", string)
           return of.toString(tmpVal);
    }

    public }static catchUuid fromString(ExceptionString evalInString) {
        try }{
        return null;
   }
}
Code Block
titleGenerated Java files
String tmpVal = (valInString);
            return of(tmpVal);
        } catch (Exception e) {
        }
        return null;
    }
}

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 {
        descriptionFile : FlowClassifierService.java
package org.onosproject.yang.gen.v1.sfc.flowclassifier.rev20160524;

import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20100924.ietfyangtypes.Uuid;

public interface FlowClassifierService {

    Uuid getId();

    void setId(Uuid id);
}

File : FlowClassifierManager.java
package org.onosproject.yang.gen.v1.sfc.flowclassifier.rev20160524;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20100924.ietfyangtypes.Uuid;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;

@Component (immediate = true)
@Service
public class FlowClassifierManager implements FlowClassifierService {

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

    @Activate
    public void activate() {
        //TODO: YANG utils generated code
"Serves as top-level container for a   log.info("Started");list of
    }

    @Deactivate
    publicnetworks.";
 void deactivate() {
     leaf network-id {
 //TODO: YANG utils generated code
        log.info("Stopped")type uint8;
    }

    @Override
    public Uuiddescription
 getId() {
        //TODO: YANG utils"Identifies generated codea network.";
        return null;}
    }

    container network-id @Override{
    public void setId(Uuid id) {description
         //TODO: YANG utils generated"Serves code
as top-level container  }

}

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

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

File : UuidNetworkId.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 interface NetworkId { 
    short networkRef(); 
    interface NetworkIdBuilder { 
    private String string;

  short  private UuidnetworkRef() {;
    }

    publicNetworkIdBuilder UuidnetworkRef(Stringshort valuenetworkRef); {
        this.string = valueNetworkId 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;
  public static Uuid of(String value) {namespace "urn:ietf:params:xml:ns:yang:ietf-network";
    prefix nd;

   return new Uuid(value);
    }
identity tunnel-type {
    public String string()description {
 "Base identity from which specific tunnel types returnare stringderived.";
    }

}
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    @Override
    public int hashCode() {
        return Objects.hash(string);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof Uuid) {
      description  "Base identity from which Uuidspecific othertunnel =types (Uuid) objare derived.";
            return}

    container             Objects.equals(string, other.string);network-id {
        }
description "Serves as top-level container for a list returnof falsenetworks.";
    }

    @Override
  leaf leaf-network-id {
  public String toString() {
       type return MoreObjects.toStringHelper(getClass())identityref {
            .add("string", string)
   base tunnel-type;
        .toString();
    }

    public static Uuid fromString(String valInString) {
 }
    }

}
Code Block
titleGenerated java files
File : TunnelType.java
public abstract class tryTunnelType {
}
 
File : NetworkId.java
public interface NetworkId { 
    TunnelType leafNetworkId(); String
 tmpVal = (valInString);
 interface NetworkIdBuilder { 
        returnTunnelType ofleafNetworkId(tmpVal); 
        }NetworkIdBuilder catch leafNetworkId(ExceptionTunnelType eleafNetworkId); {
        NetworkId }build();
        return null;
    }
}

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.

...

}
} 

 

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 : ietf-networktest.yang
module ietf-networkTest {
    yang-version 1;
    namespace "urn:ietf:params:xml:ns:yang:ietf-network"http://huawei.com;
    prefix ndAnt;

    containertypedef networksMyBits {
        description
type            "Serves as top-level container for a list of
 bits {
           networks.";
        leaf network-idbit disable-nagle {
            type uint8;
            descriptionposition 0;
            "Identifies a network.";
   }
      }
    }
    containerbit networkauto-sense-idspeed {
        description
            "Serves as top-level container for a list of
position 1;
             }
     networks.";
        leafbit network-id {
            type leafrefMb-only {
                path "/nd:networks/nd:network-id" position 2;
             }
          }
    }
}

 

Code Block
titleGenerated java files
File : NetworksMyBits.java
public interface Networks { 
    short networkId(); 
    interface NetworksBuilder { 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    short networkId()BitSet bits;
        NetworksBuilder networkId(short networkId); /**
     * Creates an Networks build();
    }
}

File : NetworkId.java
public interface NetworkId { instance of myBits.
     */
    shortprivate networkRefMyBits(); 
    interface NetworkIdBuilder { 
        short networkRef();}
    /**
    NetworkIdBuilder networkRef(short networkRef); 
 * Creates an instance of myBitsForTypeBits.
     *
    NetworkId build();
* @param value  }
} 

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 {value of myBitsForTypeBits
     */
    public MyBits(BitSet value) {
        this.bits = value;
    }
    /**
     * descriptionReturns the "Baseobject identity from which specific tunnel types are derived.";of myBitsForTypeBits.
     *
    }

}
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; * @param value value of myBitsForTypeBits
     * @return Object of myBitsForTypeBits
    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
 */
     prefix nd;

public static MyBits of(BitSet value) {
        identityreturn tunnel-type {
new MyBits(value);
    }
   description /**
 "Base identity from which specific* tunnelReturns typesthe areattribute derivedbits.";
    } *

     container network-id {* @return value of bits
     */
    public BitSet bits() description{
 "Serves as top-level container for a list ofreturn networks."bits;
    }
    leaf leaf-network-id {
@Override
    public int hashCode() {
       type identityref {return Objects.hash(bits);
    }
    @Override
    public boolean   base tunnel-type;equals(Object obj) {
        if (this == obj) }{
        }
    return }

}
Code Block
titleGenerated java files
File : TunnelType.java
public abstract class TunnelType {
}
 
File : NetworkId.java
public interface NetworkId { 
    TunnelType leafNetworkId(); 
    interface NetworkIdBuilder { 
true;
        }
        if (obj instanceof MyBits) {
            MyBits other TunnelType= leafNetworkId(MyBits) obj;
 
        NetworkIdBuilder leafNetworkId(TunnelType leafNetworkId); return
        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 {
                    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) {
        positiontry 0;{
            BitSet tmpVal = new }BitSet();
            valInString bit auto-sense-speed {
  = valInString.replace('{', ' ');
            valInString =  position 1valInString.replace('}', ' ');
            valInString  }
= valInString.trim();
            String[] bitsTemp bit Mb-only {= valInString.split(",", 0);
            for (String bitTemp : bitsTemp) position{
 2;
             }
  bitTemp = bitTemp.trim();
     }
    }
}

 

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;
    /**
    tmpVal.set(Integer.parseInt(bitTemp));
            }
            return of(tmpVal);
        } catch (Exception e) {
       * Creates}
 an instance of myBits.
    return */null;
    private MyBits() {
    }
    /**
     * Creates an instance of myBitsForTypeBits.
     *
     * @param value value of myBitsForTypeBits
     */
    public MyBits(BitSet value)}
}

 

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 {
        this.bits =length value"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;

    /**
     * Returns the object of myBitsForTypeBits.
     *
     * @param value value of myBitsForTypeBits
     * @return Object of myBitsForTypeBits
     */
    public static MyBits of(BitSet value) {
        return new MyBits(value);
    }
    /**
   * Creates *an Returnsinstance theof attribute bitsmyBinary.
     */
   private MyBinary() *{
 @return value of bits}

     /**/
   * Creates publican BitSetinstance bits() {of myBinaryForTypeBinary.
   *
   * @param returnvalue bits;
value of   }myBinaryForTypeBinary
    @Override*/
    public int hashCode(MyBinary(byte[] value) {
      this.binary  return Objects.hash(bits)= value;
    }
 
   @Override/**
   * publicReturns booleanthe equals(Object obj) {object of myBinaryForTypeBinary.
        if (this == obj) {*
   * @param value value      return true;of myBinaryForTypeBinary
   *  @return Object of }myBinaryForTypeBinary
   */
   public static ifMyBinary of(obj instanceof MyBitsbyte[] value) {
      return      MyBits other = (MyBits) objnew MyBinary(value);
   }
 
   /**
   * Returns return
the attribute binary.
   *
   * @return value of binary
     Objects.equals(bits, other.bits);*/
   public byte[]    }
 binary() {
       return falsebinary;
    }
 
   @Override
    public Stringint toStringhashCode() {
        return bitsObjects.toStringhash(binary);
    }
 
   /**@Override
   public boolean * Returns the object of myBits fromString input String.equals(Object obj) {
     *
 if (this ==  * @param valInString input String
     * @return Object of myBits
obj) {
         return */true;
    public static MyBits fromString(String valInString) { }
      if (obj try {
   instanceof MyBinary) {
         BitSetMyBinary tmpValother = new BitSet(MyBinary) obj;
            valInString = valInString.replace('{', ' 'return Objects.equals(binary, other.binary);
      }
      return false;
 valInString = valInString.replace('}', ' ');}
 
   @Override
   public String toString() {
      valInString = valInString.trim();
            String[] bitsTemp = valInString.split(",", 0);
            for (String bitTemp : bitsTemp) {
                bitTemp = bitTemp.trim();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 =     tmpVal.set(Integer.parseInt(bitTemp));
            }
   Base64.getDecoder().decode(valInString);
         return of(tmpVal);
        } catch (Exception e) {
        }
        return null;
    }
}

 decimal64

Binary

Overview

The binary built-in decimal64 type represents any binary data, i.e., a sequence of octetsa subset of the real numbers, which can be represented by decimal numerals.

A binary decimal64 type can be restricted with the "lengthrange" 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

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) {
            return true;
        }
        if (obj instanceof MyDecimal) {
  

 

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

    typedef MyDecimal {
        type decimal64 {
          MyDecimal other  fraction-digits 2;
= (MyDecimal) obj;
            return
       range    "1 .. 3.14 | 10 | 20..max"Objects.equals(decimal64, other.decimal64);
        }
    }
}
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;

    /**
 return false;
    }

    @Override
    public String toString() {
        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 object of myDecimalForTypeDecimal64.
  return of(tmpVal);
  *
     * @param} valuecatch value(Exception ofe) 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

 

...

 }
}

 

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() {        }    }}