...
| YANG Construct | Supported/Planned version |
|---|---|
| anyxml | Not planned |
| argument | Not planned |
| augment | Goldeneye |
| base | Hummingbird |
| belongs-to | Goldeneye |
| bit | Goldeneye |
| case | Goldeneye |
| choice | Goldeneye |
| config | Falcon |
| contact | Goldeneye Enhancement in Hummingbird |
| container | Falcon |
| default | Goldeneye Enhancement in Humminbird |
| description | Goldeneye Enhancement in Hummingbird |
| deviate | Not planned |
| deviation | Not planned |
| enum | Goldeneye |
| error-app-tag | Not planned |
| error-message | Not planned |
| extension | Not planned |
| feature | Hummingbird |
| fraction-digits | Goldeneye |
| grouping | Goldeneye |
| identity | Hummingbird |
| if-feature | Hummingbird |
| import | Goldeneye Enhancement in Hummingbird |
| include | Goldeneye Enhancement in Hummingbird |
| input | Goldeneye |
| key | Goldeneye |
| leaf | Falcon |
| leaf-list | Falcon |
| length | Goldeneye |
| list | Falcon |
| mandatory | Falcon |
| max-elements | FalconGoldeneye |
| min-elements | FalconGoldeneye |
| module | Falcon |
| must | Hummingbird |
| namespace | Goldeneye |
| notification | Goldeneye |
| ordered-by | Not planned |
| organization | Goldeneye Enhancement in Hummingbird |
| output | Goldeneye |
| path | Hummingbird |
| pattern | Goldeneye |
| position | Goldeneye |
| prefix | Goldeneye |
| presence | Goldeneye |
| range | Goldeneye |
| reference | Goldeneye Enhancement in Hummingbird |
| refine | Not planned |
| require-instance | Not planned |
| revision | Goldeneye Enhancement in Hummingbird |
| revision-date | Goldeneye |
| rpc | Goldeneye |
| status | Goldeneye Enhancement in Hummingbird |
| submodule | Goldeneye |
| type | Goldeneye |
| typedef | Goldeneye |
| unique | Not Planned |
| units | Goldeneye |
| uses | Goldeneye |
| value | Goldeneye |
| when | Hummingbird |
| yang-version | Goldeneye |
| yin-element | Not Planned |
...
| Binary | Goldeneye Enhancement in Hummingbird |
| Bits | Goldeneye Enhancement in Hummingbird |
| boolean | Goldeneye |
| decimal64 | Goldeneye Enhancement in Hummingbird |
| empty | Goldeneye |
| enumeration | Goldeneye |
| identityref | Hummingbird |
| instance-identifier | Hummingbird |
| int8 | Goldeneye |
| int16 | Goldeneye |
| int32 | Goldeneye |
| int64 | Goldeneye |
| leafref | Hummingbird |
| string | Falcon |
| uint8 | Goldeneye |
| uint16 | Goldeneye |
| uint32 | Goldeneye |
| uint64 | Goldeneye |
| union | Goldeneye |
...
| 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.
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.
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.
For augment we have given two interface named as “AugmentationHolder” and “AugmentedInfo” as part of yangutils 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 | ||
|---|---|---|
| ||
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 | ||
|---|---|---|
| ||
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 | ||
|---|---|---|
| ||
leaf one {
type string;
}
leaf two {
type int32;
}
leaf-list three {
type boolean;
}
leaf-list four {
type int16;
} |
| Code Block | ||
|---|---|---|
| ||
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 | ||
|---|---|---|
| ||
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 | ||
|---|---|---|
| ||
File : Percent.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160526.test;
import java.util.Objects;
import com.google.common.base.MoreObjects;
public final class Percent {
private short uint8;
private Percent() {
}
public Percent(short value) {
this.uint8 = value;
}
public static Percent of(short value) {
return new Percent(value);
}
public short uint8() {
return uint8;
}
@Override
public int hashCode() {
return Objects.hash(uint8);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof Percent) {
Percent other = (Percent) obj;
return Objects.equals(uint8, other.uint8);
}
return false;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("uint8", uint8)
.toString();
}
public static Percent fromString(String valInString) {
try {
short tmpVal = Short.parseShort(valInString);
return of(tmpVal);
} catch (Exception e) {
}
return null;
}
} |
Enumeration
Overview
Enum statement only can come when a leaf is of type enumeration. Each enum has one string then should be unique . The string must not be empty string and must not have white spaces. Enum can have sub statements, value statement will give the info about its value. If the enum statement in enumeration has no value statement then its value is considered as zero and subsequently incremented by one for next values.
Java mapping
For a given enumeration node one enum file will be generated which will have all the enum as its attributes. There will be a constructor and a getter method for the values.
Example
| Code Block | ||
|---|---|---|
| ||
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 | ||
|---|---|---|
| ||
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 | ||
|---|---|---|
| ||
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 | ||
|---|---|---|
| ||
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;
}
} |