Have questions? Stuck? Please check our FAQ for some common questions and answers.

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Team

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

Overview

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

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

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

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

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

Steps to use YANG utils

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

<build>
  <plugins>
    <plugin>
      <groupId>org.onosproject</groupId>
      <artifactId>yangutils-maven-plugin</artifactId>
      <version>1.0.0-SNAPSHOT</version>
      <executions>
        <execution>
          <configuration>
          </configuration>
          <goals>
            <goal>yang2java</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

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

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

Step 3 : Plugin configuration supported in YANG utils 

  1. Create a folder structure as “src/main/yang” in the test app folder and place your YANG files in it. If incase user want to give desired path for source YANG files and generated java files, the following configuration can be appended to the above pom.xml file.

    <configuration>
        <yangFilesDir>/opt/src/yang/</yangFilesDir>
        <genFilesDir>/opt/src/java/</genFilesDir> 
    </configuration>

     

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

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

      2. const will be mapped as prefixConst

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

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

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

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

    <configuration>
        <groupingCodeGenFlag>true</groupingCodeGenFlag>
    </configuration>

     

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

    <configuration>
        <rpcSubStatementCodeGenFlag>true</rpcSubStatementCodeGenFlag>
    </configuration>

Step 4 : Execution of application

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

Note : Code generated is as per ONOS coding guidelines.

YANG utils constructs support/plan

YANG ConstructSupported/Planned version
anyxmlNot planned
argumentNot planned
augmentGoldeneye
baseHummingbird
belongs-toGoldeneye
bitGoldeneye
caseGoldeneye
choiceGoldeneye
configFalcon
contact

Goldeneye

Enhancement in Hummingbird

containerFalcon
default

Goldeneye

Enhancement in Humminbird

description

Goldeneye

Enhancement in Hummingbird

deviateNot planned
deviationNot planned
enumGoldeneye
error-app-tagNot planned
error-messageNot planned
extensionNot planned
featureHummingbird
fraction-digitsGoldeneye
groupingGoldeneye
identityHummingbird
if-featureHummingbird
import

Goldeneye

Enhancement in Hummingbird

include

Goldeneye

Enhancement in Hummingbird

inputGoldeneye
keyGoldeneye
leafFalcon
leaf-listFalcon
lengthGoldeneye
listFalcon
mandatoryFalcon
max-elementsFalcon
min-elementsFalcon
moduleFalcon
mustHummingbird
namespaceGoldeneye
notificationGoldeneye
ordered-byNot planned
organization

Goldeneye

Enhancement in Hummingbird
outputGoldeneye
pathHummingbird
patternGoldeneye
positionGoldeneye
prefixGoldeneye
presenceGoldeneye
rangeGoldeneye
reference

Goldeneye

Enhancement in Hummingbird
refineNot planned
require-instanceNot planned
revision

Goldeneye

Enhancement in Hummingbird

revision-date

Goldeneye

rpcGoldeneye
status

Goldeneye

Enhancement in Hummingbird
submoduleGoldeneye
typeGoldeneye
typedefGoldeneye
uniqueNot Planned
units

Goldeneye

usesGoldeneye
valueGoldeneye
whenHummingbird
yang-versionGoldeneye
yin-elementNot Planned

Built-in YANG data types support/plan

Binary

Goldeneye

Enhancement in Hummingbird
Bits

Goldeneye

Enhancement in Hummingbird
booleanGoldeneye
decimal64

Goldeneye

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

Generated JAVA Details

Common behavior

Identifier

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

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

      • name-conversion will be mapped as nameConversion

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

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

      • yang_123construct will be mapped to yang123Construct

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

      • _123date will be mapped to yangAutoPrefix123Date

      • const will be mapped to yangAutoPrefixConst

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

      • ca-l.e_nder will be mapped to caLeNder

      • tric-._k will be mapped to trick        

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

      • TESTNAME will be mapped to testname

      • TEST-NAME will be mapped to testName

      • TestName will be mapped to testName

      • TEST3NAME will be mapped to test3Name

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

Namespace

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

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

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

Javadocs

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

YANG statements

Module

Overview

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

JAVA mapping

Module statement is mapped to

  1. Service interface 
    It includes:
    a) java methods corresponding to the YANG RPC (Refer RPC section for more details)
    b) If module contains notification, generated service interface will extend listener service (refer notification for more details)
  2. Manager class
    It includes:
    a ) Activate/Deactivate methods
    b) If module contains child data nodes, getters and setters for those nodes will be generated for app developers to implement.
    c)If module contains notification, generated manager class will extend ListenerRegistry(refer notification for more details) .
     
    The manager class implements the service interface. The name of service interface and manager class is <module_name>Service.java and <module_name>Manager.java.
Example
Input YANG file :

File : network.yang
module network {
     yang-version 1;
     namespace "urn:TBD:params:xml:ns:yang:nodes";
     prefix nd;

     organization "TBD";
     contact
       "WILL-BE-DEFINED-LATER";
     description
       "This module defines a common base model for a collection
        of nodes in a network. Node definitions s are further used
        in network topologies and inventories.";

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

       leaf network-id {
         type string;
       }

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

Generated JAVA files :

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

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

public interface NetworkService {

    List<Networklist> getNetworklist();

    void setNetworklist(List<Networklist> networklist);
}

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

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

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

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

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

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

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

    @Override
    public void setNetworklist(List<Networklist> networklist) {
          //TODO: YANG utils generated code
    }
}

Sub Module

 Overview

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

JAVA mapping

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

Example
Input YANG File:

File : acme-system.yang
module acme-system {
    namespace "http://yang-central.org/ns/example/acme";
    prefix acme;

    include "acme-types";
 
    leaf id {
        type string;
    }
}

File : acme-types.yang
submodule acme-types {
    yang-version 1;
    belongs-to "acme-system" {
        prefix "acme";
    }
    leaf access-timeout {
        type uint32;
    }
    leaf retries {
        type uint8;
    }
}

Generated JAVA files :

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

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

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

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

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

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

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

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

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

public interface AcmeSystemService {

    String getId();

    void setId(String id);
}

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

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

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

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

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

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

    @Override
    public long getAccessTimeout() {
        //TODO: YANG utils generated code
          return 0;
    }

    @Override
    public short getRetries() {
          //TODO: YANG utils generated code
          return 0;
    }

    @Override
    public void setAccessTimeout(long accessTimeout) {
        //TODO: YANG utils generated code
    }

    @Override
    public void setRetries(short retries) {
          //TODO: YANG utils generated code
    }
}

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

public interface AcmeTypesService {
    long getAccessTimeout();

    short getRetries();

    void setAccessTimeout(long accessTimeout);

    void setRetries(short retries);
}

Prefix 

Overview

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

JAVA mapping

There is no java mapping for prefix statement.

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

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

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

type yang:date-and-time;

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

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

Import

Overview

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

JAVA mapping
Example

Include

 Overview

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

JAVA mapping

 

Example

 

 

Organization

 Overview

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

JAVA mapping

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

Example

Please refer module example section

Contact

Overview

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

JAVA mapping

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

Example

Please refer module example section

Belongs to

Overview

 The "belongs-to" statement specifies the module to which the submodule belongs.  The argument is an identifier that is the name of the module. A submodule must only be included by the module to which it belongs, or by another submodule that belongs to that module.

JAVA mapping

 No java mapping for belongs to statement in generated code.

Example

Please refer submodule example section.

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

JAVA mapping

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

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

  1. When input is present and no output statement.
     

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

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

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

  2. When no input  and  output statement is present.
     

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

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

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

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

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

Example
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.

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

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

 

 

 


Goldeneye

Enhancement in Hummingbird

  • No labels