Versions Compared

Key

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

...

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

Example

 

 

 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

         The following is an example of a UUID in string representation:
         f81d4fae-7dec-11d0-a765-00a0c91e6bf6
         ";
       reference
        "RFC 4122: A Universally Unique IDentifier (UUID) URN
                   Namespace";
     }
}
 

 

 

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;/** * Abstraction of an entity which represents the functionality of flowClassifierService. */public interface FlowClassifierService { /** * Returns the attribute id. * * @return value of id */ Uuid getId(); /** * Sets the value to attribute id. * * @param id value of id */ void setId(Uuid id);}

...

titleGenerated Java files

 

 

 

 

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.

...

Code Block
titleGenerated java files
File : IpAddressUnion.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.test.ipaddress;

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

public final class IpAddressUnion {

    private int int32;
    private long uint32;

    private IpAddressUnion() {
    }

    public IpAddressUnion(int value) {
        this.int32 = value;
    }

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

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

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

    public int int32() {
        return int32;
    }

    public long uint32() {
        return uint32;
    }

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

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

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

    public static IpAddressUnion fromString(String valInString) {
        try {
          int tmpVal = Integer.parseInt(valInString);
          return of(tmpVal);
        } catch (Exception e) {
        }
        try {
          long tmpVal = Long.parseLong(valInString);
          return of(tmpVal);
        } catch (Exception e) {
        }
        return null;
   }
}
Code Block
titleGenerated Java files
File : 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
        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.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");
    }

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

File : Uuid.java
package org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20100924.ietfyangtypes;
import java.util.Objects;
import com.google.common.base.MoreObjects;

public final class Uuid {
    private String string;

    private Uuid() {
    }

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

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

    public String string() {
        return string;
    }

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

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

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

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