Versions Compared

Key

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

...

Please refer submodule example section.

Leaf

Overview

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

Java mapping

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

Example

 

 

 

Code Block
titleInput YANG file
File : acme-system.yang
module acme-system {
         .
         .
         .
    leaf host-name {
        type string;
    }
}

 

 

 

Code Block
titleGenerated Java files
File : AcmeSystemService.java
public interface AcmeSystemService {
    String getHostName();
    void setHostName(String hostName);
}

File: AcmeSystemManager.java
@Component (immediate = true)
@Service
public class AcmeSystemManager implements AcmeSystemService {

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

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

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

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

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

 

Leaf-list

 

Overview

 

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

 

Java mapping

 

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

 

Example

 

Code Block
titleInput YANG file
File : AcmeSystemService.java
public interface AcmeSystemService {
    List<Short> getDomainSearch();
    void setDomainSearch(List<Short> domainSearch);
}

 

 

 

Code Block
titleGenerated Java files
File : AcmeSystemManager.java
@Component (immediate = true)
@Service
public class AcmeSystemManager implements AcmeSystemService {

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

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

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

    @Override
    public List<Short> getDomainSearch() {
        //TODO: YANG utils generated code
        return null;
    }

    @Override
    public void setDomainSearch(List<Short> domainSearch) {
        //TODO: YANG utils generated code
    }
}

 

Container

 

Overview

 

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

 

Java mapping

 

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

 

Example

 

Code Block
titleInput YANG file
File : acme-system.yang
module acme-system {                   
                    .
                    .
                    .
    container holder {
            container system {
              leaf host-name {
                type string;
               }
               leaf-list domain-search {
                type string;
               }
            }
    }
}

 

 

 

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

File : SystemBuilder.java
public class SystemBuilder implements System.SystemBuilder {
    private String hostName;
    private List<String> domainSearch;
    public String hostName() {
        return hostName;
    }
    public List<String> domainSearch() {
        return domainSearch;
    }
    public SystemBuilder hostName(String hostName) {
        this.hostName = hostName;
        return this;
    }
    public SystemBuilder domainSearch(List<String> domainSearch) {
        this.domainSearch = domainSearch;
        return this;
    }
      .
      .
      .
    public final class SystemImpl implements System {
      .
      .
      .
    }
}

File : Holder.java
public interface Holder extends AugmentationHolder  {
    System system();
    interface HolderBuilder {
        System system();
        HolderBuilder system(System system);
        Holder build();
    }
}

File : HolderBuilder.java
public class HolderBuilder implements Holder.HolderBuilder {
    private System system;
    public System system() {
        return system;
    }
    public HolderBuilder system(System system) {
        this.system = system;
        return this;
    }
    public Holder build() {
        return new HolderImpl(this);
    }
      .
      .
      .
    public final class HolderImpl implements Holder {
      .
      .
      .
    }
}

 

List

 

Overview

 

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

 

Java mapping

 

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

 

Example
Code Block
titleInput YANG file
	File : acme-system.yang
module acme-system {
                    .
                    .
                    .
    list user {
            key "name";
            list user {
              key "name";
               leaf name {
                  type string;
               }
               leaf full-name {
                  type string;
               }
               leaf class {
                type string;
               }
             }
             leaf name {
               type string;
             }
    }
 }
Code Block
titleGenerated Java files
File : User.java
public interface User extends AugmentationHolder  {
    String name();
    String fullName();
    String yangAutoPrefixClass();
    interface UserBuilder {
        String name();
        String fullName();
        String yangAutoPrefixClass();
        UserBuilder name(String name);
        UserBuilder fullName(String fullName);
        UserBuilder yangAutoPrefixClass(String yangAutoPrefixClass);
        User build();
    }
}

File : UserBuilder.java
public class UserBuilder implements User.UserBuilder {
    private String name;
    private String fullName;
    private String yangAutoPrefixClass;

    public String name() {
        return name;
    }

    public String fullName() {
        return fullName;
    }

    public String yangAutoPrefixClass() {
        return yangAutoPrefixClass;
    }

    public UserBuilder name(String name) {
        this.name = name;
        return this;
    }

    public UserBuilder fullName(String fullName) {
        this.fullName = fullName;
        return this;
    }

    public UserBuilder yangAutoPrefixClass(String yangAutoPrefixClass) {
        this.yangAutoPrefixClass = yangAutoPrefixClass;
        return this;
    }
     .
     .
     .
    public final class UserImpl implements User {
     .
     .
     .
    }
}


File : User.java
public interface User extends AugmentationHolder  {

    String name();
    List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20160520.acmesystem.user.User> user();

    interface UserBuilder {
        String name(); 
        List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20160520.acmesystem.user.User> user();
        UserBuilder name(String name);
        UserBuilder user(List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20160520.acmesystem.user.User> user);
        User build();
    }
}

File : UserBuilder.java
public class UserBuilder implements User.UserBuilder {

    private String name;
    private List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20160520.acmesystem.user.User> user;

    public String name() {
        return name;
    }

    public List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20160520.acmesystem.user.User> user() {
        return user;
    }

    public UserBuilder name(String name) {
        this.name = name;
        return this;
    }

    public UserBuilder user(List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20160520.acmesystem.user.User> user) {
        this.user = user;
        return this;
    }
     .
     .
     .
    public final class UserImpl implements User {
     .
     .
     .
    }
}

 

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 nodes under grouping are completely copied, wherever uses is present. Later the java file generation takes place according to the new yang nodes added. Grouping and uses itself will not have any impact in java file generation.

 
Example
Code Block
titleInput YANG file
File : Test.yang
module Test {
         .
         .
         .
    grouping Percentage {
    leaf mark{
            type String;
        }
    }
    container classroom {
        leaf student{
            type String;
        }
        uses Percentage;
    }
}

 

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.

...

  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
Input YANG file:

File : link.yang
module link {
    yang-version 1;
    namespace http://huawei.com;
    prefix Ant;

    container link {
        choice interfaceType {
            case ethernerType {
                leaf ethernet { type string; }
            }
            case p2pType {
               leaf p2p { type string; }
            }
        }
     }
}

Generated JAVA files :

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

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

public interface InterfaceType extends AugmentationHolder  {
}

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

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

public interface EthernerType extends AugmentationHolder, InterfaceType  {

    String ethernet();

    interface EthernerTypeBuilder {

        String ethernet();

        EthernerTypeBuilder ethernet(String ethernet);

        EthernerType build();
    }
}

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

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

public class EthernerTypeBuilder implements EthernerType.EthernerTypeBuilder {

    private String ethernet;

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

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

   @Override
   public EthernerType build() {
       return new EthernerTypeImpl(this);
   }

   public EthernerTypeBuilder() {
   }

   public final class EthernerTypeImpl implements EthernerType {

        private String ethernet;

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

        public EthernerTypeImpl() {
        }

          public EthernerTypeImpl(EthernerTypeBuilder builderObject) {
                this.ethernet = builderObject.ethernet();
        }
    }
}

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.

...

  1. When input is present and no output statement.
     

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

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

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

  2. When no input  and  output statement is present.
     

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

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

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

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

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

Example
Code Block
Input YANG file :

File: sfc.yang
module Sfc {
    yang-version 1;
    namespace http://huawei.com;
    prefix Ant;
    rpc SFP {
        input {
            leaf port {
                type string;
            }
          }
          output {
            leaf path {
                type string;
            }
          }
    }
}

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

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

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

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

public interface SfpInput {

    String port();

    interface SfpInputBuilder {

        String port();

        SfpInputBuilder port(String port);

        SfpInput build();
    }
}

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

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

public class SfpInputBuilder implements SfpInput.SfpInputBuilder {

     private String port;

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

    @Override
    public SfpInputBuilder port(String port) {
         this.port = port;
         return this;
    }

    @Override
    public SfpInput build() {
         return new SfpInputImpl(this);
    }

    public SfpInputBuilder() {
    }

    public final class SfpInputImpl implements SfpInput {

         private String port;

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

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

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

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

        public SfpInputImpl(SfpInputBuilder builderObject) {
                 this.port = builderObject.port();
        }
    }
}

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

public interface SfpOutput {

    String path();

    interface SfpOutputBuilder {

        String path();

        SfpOutputBuilder path(String path);

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

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

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

     private String path;

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

    @Override
    public SfpOutputBuilder path(String path) {
         this.path = path;
         return this;
    }

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

    public SfpOutputBuilder() {
    }

    public final class SfpOutputImpl implements SfpOutput {

         private String path;

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

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

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

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

         public SfpOutputImpl(SfpOutputBuilder builderObject) {
            this.path = builderObject.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.

...

Manager Extends ListenerRegistry with event and eventListener.

Example

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

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

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
        extends ListenerRegistry<OspfEvent, OspfListener>
        implements OspfService {

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

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
        extends ListenerService<OspfEvent, OspfListener> {
}

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

import org.onosproject.event.AbstractEvent;

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

    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 {

    private Test test;

    public Test test() {
            return test;
    }

    public void test(Test test) {
            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 {

            String eventClass();

            String severity();

            TestBuilder eventClass(String eventClass);

       TestBuilder severity(String severity);

        Test build();
    }
}

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

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

public class TestBuilder implements Test.TestBuilder {

    private String eventClass;
    private String severity;

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

    @Override
    public String severity() {
            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 = new ArrayList<>();
            private String eventClass;
            private String severity;

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

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

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

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

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

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

            @Override
            public void addAugmentation(AugmentedInfo value) {
                getAugmentedInfoList().add(value);
            }

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

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

 

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.

...

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

Java mapping

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

...

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" {
          leaf ds0ChannelNumber {
               type int16;
         }
    }
}
Code Block
titleGenerated Java files
File : AugmentedInterface.java


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

public interface AugmentedInterface extends AugmentedInfo  {
   
    short getDs0ChannelNumber();
   
    interface AugmentedInterfaceBuilder {
 
        short getDs0ChannelNumber();

        AgmentedInterfaceBuilder setDs0ChannelNumber(short ds0ChannelNumber);

       AugmentedInterface build();
    }
}

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

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

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

   @Override
   public AugmentedInterfaceBuilder setDs0ChannelNumber(short ds0ChannelNumber)  {
       this.ds0ChannelNumber = ds0ChannelNumber;
       return this;
   }

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

   public AugmentedInterfaceBuilder() {
   }

   public final class AugmentedInterfaceImpl implements AugmentedInterface {

       private short ds0ChannelNumber;

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

       @Override
       Public int hashCode() {
           return Objects.hash(ds0ChannelNumber);
       }

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

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

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

       Public AugmentedInterfaceImpl(AugmentedInterfaceBuilder builderObject) {
           this.ds0ChannelNumber = builderObject.getDs0ChannelNumber();
          InterfaceImpl interfaceImpl = new InterfaceBuilder().new InterfaceImpl();
          interfaceImpl.addAugmentation(this);
       }
   }
}

Type

Overview

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

Java mapping

 

YANG

Description

JAVA

binary

Any binary data

To be implemented

bits

A set of bits or flags

To be implemented

boolean

"True" or "false"

boolean

decimal64

64-bit    signed decimal number

To be implemented

empty

A leaf that does not have any value

boolean

enumeration

Enumerated strings

Enum class will be generated

identityref

A reference to an abstract identity

To be implemented

instance-identifier

References a data tree node

To be implemented

int8

8-bit signed integer

byte   

int16

16-bit signed integer

short

int32

32-bit signed integer

int

int64

64-bit signed integer

long   

leafref   

A reference to a leaf instance

To be implemented

string   

Human-readable string

String

uint8   

8-bit unsigned integer

short

uint16   

16-bit unsigned integer        

int   

uint32

32-bit unsigned integer

long   

uint64   

64-bit unsigned integer

BigInteger

union   

Choice of member types

Union  class will be generated

 

Example
Code Block
titleInput YANG file
leaf one {                         
    type string;
}

leaf two {                           
    type int32;
}

leaf-list three {
    type boolean;
}

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

private int two;

private List<Boolean> three;

private List<Short> four;

Typedef

Overview

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

Java mapping

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

Example
Code Block
titleInput YANG file
File : test.yang

module test {

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

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

    leaf completed {
        type percent;
    }
}

...

Code Block
titleGenerated Java files
File : PacketTypeEnum.java

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

public enum PacketTypeEnum {

    UNBOUNDED(0),

    ZERO(1),

    TWO(2),

    FOUR(3);

    private int packetTypeEnum;

    PacketTypeEnum(int value) {
        packetTypeEnum = value;
    }

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


    public int packetTypeEnum() {
            return packetTypeEnum;
    }

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

Union

Overview

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

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

Java mapping

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

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

    typedef ip-address {
        type union {
            type int32;
            type uint32;
        }
    }
}

...