janani b
Committed by Patrick Liu

[ONOS-4744] Leafref implementation and UT

Change-Id: I151797185e0bb1695c0640b667ae76ef87c4d4b0
Showing 73 changed files with 2037 additions and 112 deletions
......@@ -34,5 +34,10 @@ public enum ResolvableType {
/**
* Identifies the if-feature.
*/
YANG_IF_FEATURE
YANG_IF_FEATURE,
/**
* Identifies the leafref.
*/
YANG_LEAFREF
}
......
......@@ -24,6 +24,11 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import com.google.common.base.Strings;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processLengthRestriction;
import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processRangeRestriction;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN;
......@@ -34,11 +39,6 @@ import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangData
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UNION;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType;
import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processLengthRestriction;
import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processRangeRestriction;
/**
* Represents the derived information.
......@@ -334,6 +334,9 @@ public class YangDerivedInfo<T>
return RESOLVED;
}
}
} else if (baseType.getDataType() == LEAFREF) {
setEffectiveBuiltInType(baseType.getDataType());
return RESOLVED;
} else {
setEffectiveBuiltInType(baseType.getDataType());
/*
......@@ -412,7 +415,6 @@ public class YangDerivedInfo<T>
}
}
}
/*
* Check if the data type is the one which can't be restricted, in this
* case check whether no self restrictions should be present.
......@@ -426,7 +428,6 @@ public class YangDerivedInfo<T>
throw new DataModelException("YANG file error: Restrictions can't be applied to a given type");
}
}
// Throw exception for unsupported types
throw new DataModelException("Linker error: Unable to process the derived type.");
}
......
......@@ -211,6 +211,11 @@ public class YangModule
private List<YangResolutionInfo> ifFeatureResolutionList;
/**
* leafref resolution list.
*/
private List<YangResolutionInfo> leafrefResolutionList;
/**
* Creates a YANG node of module type.
*/
public YangModule() {
......@@ -219,6 +224,7 @@ public class YangModule
derivedTypeResolutionList = new LinkedList<>();
usesResolutionList = new LinkedList<>();
ifFeatureResolutionList = new LinkedList<>();
leafrefResolutionList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
......@@ -589,8 +595,10 @@ public class YangModule
return derivedTypeResolutionList;
} else if (type == ResolvableType.YANG_USES) {
return usesResolutionList;
} else {
} else if (type == ResolvableType.YANG_IF_FEATURE) {
return ifFeatureResolutionList;
} else {
return leafrefResolutionList;
}
}
......@@ -603,6 +611,8 @@ public class YangModule
usesResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add(resolutionInfo);
} else {
leafrefResolutionList.add(resolutionInfo);
}
}
......@@ -615,6 +625,8 @@ public class YangModule
usesResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList = resolutionList;
}
}
......
......@@ -209,6 +209,11 @@ public class YangSubModule
private List<YangResolutionInfo> ifFeatureResolutionList;
/**
* leafref resolution list.
*/
private List<YangResolutionInfo> leafrefResolutionList;
/**
* Creates a sub module node.
*/
public YangSubModule() {
......@@ -216,6 +221,7 @@ public class YangSubModule
derivedTypeResolutionList = new LinkedList<>();
usesResolutionList = new LinkedList<>();
ifFeatureResolutionList = new LinkedList<>();
leafrefResolutionList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
......@@ -551,8 +557,10 @@ public class YangSubModule
return derivedTypeResolutionList;
} else if (type == ResolvableType.YANG_USES) {
return usesResolutionList;
} else {
} else if (type == ResolvableType.YANG_IF_FEATURE) {
return ifFeatureResolutionList;
} else {
return leafrefResolutionList;
}
}
......@@ -565,6 +573,8 @@ public class YangSubModule
usesResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add(resolutionInfo);
} else {
leafrefResolutionList.add(resolutionInfo);
}
}
......@@ -576,7 +586,9 @@ public class YangSubModule
} else if (type == ResolvableType.YANG_USES) {
usesResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList = resolutionList;
ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList = resolutionList;
}
}
......
......@@ -17,6 +17,7 @@
package org.onosproject.yangutils.datamodel;
import java.io.Serializable;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
......@@ -43,7 +44,7 @@ import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangData
* | bit | 9.7.4 | 0..n | - YangBit used in YangBits |
* | enum | 9.6.4 | 0..n | - YangEnum used in YangEnumeration |
* | length | 9.4.4 | 0..1 | - used for string |
* | path | 9.9.2 | 0..1 | - TODO leaf-ref |
* | path | 9.9.2 | 0..1 | - path for referred leaf/leaf-list |
* | pattern | 9.4.6 | 0..n | - used for string |
* | range | 9.2.4 | 0..1 | - used for integer data type |
* | require-instance | 9.13.2 | 0..1 | - TODO instance-identifier |
......@@ -67,11 +68,6 @@ public class YangType<T>
private YangNodeIdentifier nodeIdentifier;
/**
* Java package in which the Java type is defined.
*/
private String javaPackage;
/**
* YANG data type.
*/
private YangDataTypes dataType;
......@@ -137,24 +133,6 @@ public class YangType<T>
}
/**
* Returns the Java package where the type is defined.
*
* @return Java package where the type is defined
*/
public String getJavaPackage() {
return javaPackage;
}
/**
* Sets Java package where the type is defined.
*
* @param javaPackage Java package where the type is defined
*/
public void setJavaPackage(String javaPackage) {
this.javaPackage = javaPackage;
}
/**
* Returns the type of data.
*
* @return the data type
......@@ -209,6 +187,16 @@ public class YangType<T>
}
/**
* Resets the class attributes to its default value.
*/
public void resetYangType() {
nodeIdentifier = new YangNodeIdentifier();
resolvableStatus = ResolvableStatus.UNRESOLVED;
dataType = null;
dataTypeExtendedInfo = null;
}
/**
* Returns the type of the parsed data.
*
* @return returns TYPE_DATA
......
......@@ -24,6 +24,7 @@ import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
......@@ -171,6 +172,10 @@ public final class DataModelUtils {
.getEntityToResolve() instanceof YangIfFeature) {
resolutionNode.addToResolutionList(resolutionInfo,
ResolvableType.YANG_IF_FEATURE);
} else if (resolutionInfo.getEntityToResolveInfo()
.getEntityToResolve() instanceof YangLeafRef) {
resolutionNode.addToResolutionList(resolutionInfo,
ResolvableType.YANG_LEAFREF);
}
}
......
......@@ -25,14 +25,14 @@ public enum YangDataTypes {
*
* int8 represents integer values between -128 and 127, inclusively.
*/
INT8,
INT8("int8"),
/**
* Reference:RFC 6020.
*
* int16 represents integer values between -32768 and 32767, inclusively.
*/
INT16,
INT16("int16"),
/**
* Reference:RFC 6020.
......@@ -40,7 +40,7 @@ public enum YangDataTypes {
* int32 represents integer values between -2147483648 and 2147483647,
* inclusively.
*/
INT32,
INT32("int32"),
/**
* Reference:RFC 6020.
......@@ -48,28 +48,28 @@ public enum YangDataTypes {
* int64 represents integer values between -9223372036854775808 and
* 9223372036854775807, inclusively.
*/
INT64,
INT64("int64"),
/**
* Reference:RFC 6020.
*
* uint8 represents integer values between 0 and 255, inclusively.
*/
UINT8,
UINT8("uint8"),
/**
* Reference:RFC 6020.
*
* uint16 represents integer values between 0 and 65535, inclusively.
*/
UINT16,
UINT16("uint16"),
/**
* Reference:RFC 6020.
*
* uint32 represents integer values between 0 and 4294967295, inclusively.
*/
UINT32,
UINT32("uint32"),
/**
* Reference:RFC 6020.
......@@ -77,7 +77,7 @@ public enum YangDataTypes {
* uint64 represents integer values between 0 and 18446744073709551615,
* inclusively.
*/
UINT64,
UINT64("uint64"),
/**
* Reference:RFC 6020.
......@@ -88,7 +88,7 @@ public enum YangDataTypes {
* a negative power of ten, i.e., expressible as "i x 10^-n" where i is an
* integer64 and n is an integer between 1 and 18, inclusively.
*/
DECIMAL64, // TODO: need to implement in type.
DECIMAL64("decimal64"), // TODO: need to implement in type.
/**
* Reference:RFC 6020.
......@@ -97,14 +97,14 @@ public enum YangDataTypes {
* characters are tab, carriage return, line feed, and the legal characters
* of Unicode and ISO/IEC 10646
*/
STRING,
STRING("string"),
/**
* Reference:RFC 6020.
*
* The boolean built-in type represents a boolean value.
*/
BOOLEAN,
BOOLEAN("boolean"),
/**
* Reference:RFC 6020.
......@@ -112,7 +112,7 @@ public enum YangDataTypes {
* The enumeration built-in type represents values from a set of assigned
* names.
*/
ENUMERATION,
ENUMERATION("enumeration"),
/**
* Reference:RFC 6020.
......@@ -121,7 +121,7 @@ public enum YangDataTypes {
* set of flags identified by small integer position numbers starting at 0.
* Each bit number has an assigned name.
*/
BITS,
BITS("bits"),
/**
* Reference:RFC 6020.
......@@ -129,7 +129,7 @@ public enum YangDataTypes {
* The binary built-in type represents any binary data, i.e., a sequence of
* octets.
*/
BINARY,
BINARY("binary"),
/**
* Reference:RFC 6020.
......@@ -150,14 +150,14 @@ public enum YangDataTypes {
* more features, then the leaf with the leafref type MUST also be
* conditional based on at least the same set of features.
*/
LEAFREF, // TODO: need to implement in type.
LEAFREF("leafref"),
/**
* Reference:RFC 6020.
*
* The identityref type is used to reference an existing identity.
*/
IDENTITYREF,
IDENTITYREF("identityref"),
/**
* Reference:RFC 6020.
......@@ -167,7 +167,7 @@ public enum YangDataTypes {
*
* An empty type cannot have a default value.
*/
EMPTY,
EMPTY("empty"),
/**
* Reference:RFC 6020.
......@@ -189,7 +189,7 @@ public enum YangDataTypes {
* Any default value or "units" property defined in the member types is not
* inherited by the union type.
*/
UNION,
UNION("union"),
/**
* Reference:RFC 6020.
......@@ -212,12 +212,26 @@ public enum YangDataTypes {
* valid data. All such leaf nodes MUST reference existing nodes or leaf
* nodes with their default value in use for the data to be valid.
*/
INSTANCE_IDENTIFIER,
INSTANCE_IDENTIFIER("instance-identifier"),
/**
* Derived data type.
*/
DERIVED;
DERIVED("derived");
/**
* Defined type from the enum value.
*/
private String definedType;
/**
* Constructs type value from enum.
*
* @param definedType value of enum
*/
YangDataTypes(String definedType) {
this.definedType = definedType;
}
/**
* Returns YANG data type for corresponding type name.
......@@ -228,7 +242,7 @@ public enum YangDataTypes {
public static YangDataTypes getType(String name) {
name = name.replace("\"", "");
for (YangDataTypes yangDataType : values()) {
if (yangDataType.name().toLowerCase().equals(name)) {
if (yangDataType.definedType.toLowerCase().equals(name)) {
return yangDataType;
}
}
......
......@@ -161,6 +161,8 @@ public class YangLinkerManager
((YangReferenceResolver) yangNode).resolveInterFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_LEAFREF);
} catch (DataModelException e) {
String errorInfo = "Error in file: " + yangNode.getName() + " at line: "
+ e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage();
......
......@@ -16,7 +16,6 @@
// Generated from GeneratedYang.g4 by ANTLR 4.5
package org.onosproject.yangutils.parser.antlrgencode;
import org.antlr.v4.runtime.tree.ParseTreeListener;
......@@ -1950,4 +1949,18 @@ public interface GeneratedYangListener extends ParseTreeListener {
*/
void exitAnnotationIdentifier(GeneratedYangParser.AnnotationIdentifierContext
currentContext);
/**
* Enters a parse tree produced by GeneratedYangParser for grammar rule require instance.
*
* @param currentContext current context in the parsed tree
*/
void enterRequireInstance(GeneratedYangParser.RequireInstanceContext currentContext);
/**
* Exits a parse tree produced by GeneratedYangParser for grammar require instance.
*
* @param currentContext current context in the parsed tree
*/
void exitRequireInstance(GeneratedYangParser.RequireInstanceContext currentContext);
}
......
......@@ -49,6 +49,7 @@ import org.onosproject.yangutils.parser.impl.listeners.InputListener;
import org.onosproject.yangutils.parser.impl.listeners.KeyListener;
import org.onosproject.yangutils.parser.impl.listeners.LeafListListener;
import org.onosproject.yangutils.parser.impl.listeners.LeafListener;
import org.onosproject.yangutils.parser.impl.listeners.LeafrefListener;
import org.onosproject.yangutils.parser.impl.listeners.LengthRestrictionListener;
import org.onosproject.yangutils.parser.impl.listeners.ListListener;
import org.onosproject.yangutils.parser.impl.listeners.MandatoryListener;
......@@ -56,16 +57,18 @@ import org.onosproject.yangutils.parser.impl.listeners.MaxElementsListener;
import org.onosproject.yangutils.parser.impl.listeners.MinElementsListener;
import org.onosproject.yangutils.parser.impl.listeners.ModuleListener;
import org.onosproject.yangutils.parser.impl.listeners.MustListener;
import org.onosproject.yangutils.parser.impl.listeners.NotificationListener;
import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener;
import org.onosproject.yangutils.parser.impl.listeners.NotificationListener;
import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener;
import org.onosproject.yangutils.parser.impl.listeners.OutputListener;
import org.onosproject.yangutils.parser.impl.listeners.PathListener;
import org.onosproject.yangutils.parser.impl.listeners.PatternRestrictionListener;
import org.onosproject.yangutils.parser.impl.listeners.PositionListener;
import org.onosproject.yangutils.parser.impl.listeners.PrefixListener;
import org.onosproject.yangutils.parser.impl.listeners.PresenceListener;
import org.onosproject.yangutils.parser.impl.listeners.RangeRestrictionListener;
import org.onosproject.yangutils.parser.impl.listeners.ReferenceListener;
import org.onosproject.yangutils.parser.impl.listeners.RequireInstanceListener;
import org.onosproject.yangutils.parser.impl.listeners.RevisionDateListener;
import org.onosproject.yangutils.parser.impl.listeners.RevisionListener;
import org.onosproject.yangutils.parser.impl.listeners.RpcListener;
......@@ -81,9 +84,9 @@ import org.onosproject.yangutils.parser.impl.listeners.ValueListener;
import org.onosproject.yangutils.parser.impl.listeners.VersionListener;
import org.onosproject.yangutils.parser.impl.listeners.WhenListener;
import static org.onosproject.yangutils.utils.UtilConstants.UNSUPPORTED_YANG_CONSTRUCT;
import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.handleUnsupportedYangConstruct;
import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
import static org.onosproject.yangutils.utils.UtilConstants.UNSUPPORTED_YANG_CONSTRUCT;
/**
* Represents ANTLR generates parse-tree. ANTLR generates a parse-tree listener interface that responds to events
......@@ -667,17 +670,17 @@ public class TreeWalkListener implements GeneratedYangListener {
@Override
public void enterLeafrefSpecification(GeneratedYangParser.LeafrefSpecificationContext ctx) {
// do nothing.
LeafrefListener.processLeafrefEntry(this, ctx);
}
@Override
public void exitLeafrefSpecification(GeneratedYangParser.LeafrefSpecificationContext ctx) {
// do nothing.
LeafrefListener.processLeafrefExit(this, ctx);
}
@Override
public void enterPathStatement(GeneratedYangParser.PathStatementContext ctx) {
handleUnsupportedYangConstruct(YangConstructType.PATH_DATA, ctx, CURRENTLY_UNSUPPORTED);
PathListener.processPathEntry(this, ctx);
}
@Override
......@@ -687,7 +690,7 @@ public class TreeWalkListener implements GeneratedYangListener {
@Override
public void enterRequireInstanceStatement(GeneratedYangParser.RequireInstanceStatementContext ctx) {
handleUnsupportedYangConstruct(YangConstructType.REQUIRE_INSTANCE_DATA, ctx, UNSUPPORTED_YANG_CONSTRUCT);
RequireInstanceListener.processRequireInstanceEntry(this, ctx);
}
@Override
......@@ -1489,6 +1492,16 @@ public class TreeWalkListener implements GeneratedYangListener {
}
@Override
public void enterRequireInstance(GeneratedYangParser.RequireInstanceContext ctx) {
// do nothing.
}
@Override
public void exitRequireInstance(GeneratedYangParser.RequireInstanceContext ctx) {
// do nothing.
}
@Override
public void enterFraction(GeneratedYangParser.FractionContext ctx) {
// TODO: implement the method.
}
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.LEAFREF_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
* type-body-stmts = numerical-restrictions /
* decimal64-specification /
* string-restrictions /
* enum-specification /
* leafref-specification /
* identityref-specification /
* instance-identifier-specification /
* bits-specification /
* union-specification
*
* leafref-specification =
* ;; these stmts can appear in any order
* path-stmt stmtsep
* [require-instance-stmt stmtsep]
*
* ANTLR grammar rule
*
* typeBodyStatements : numericalRestrictions | stringRestrictions | enumSpecification
* | leafrefSpecification | identityrefSpecification | instanceIdentifierSpecification
* | bitsSpecification | unionSpecification;
*
* leafrefSpecification : (pathStatement (requireInstanceStatement)?) | ((requireInstanceStatement)? pathStatement);
*/
/**
* Represents listener based call back function corresponding to the
* "leafref" rule defined in ANTLR grammar file for corresponding ABNF rule
* in RFC 6020.
*/
public final class LeafrefListener {
/**
* Creates a new leafref listener.
*/
private LeafrefListener() {
}
/**
* It is called when parser receives an input matching the grammar rule
* (leafref), perform validations and updates the data model tree.
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processLeafrefEntry(TreeWalkListener listener,
GeneratedYangParser.LeafrefSpecificationContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAFREF_DATA, "", ENTRY);
int errorLine = ctx.getStart().getLine();
int errorPosition = ctx.getStart().getCharPositionInLine();
YangLeafRef<?> leafRef = new YangLeafRef<>();
Parsable typeData = listener.getParsedDataStack().pop();
if (!(typeData instanceof YangType)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAFREF_DATA,
"", ENTRY));
}
YangType type = (YangType) typeData;
type.setDataTypeExtendedInfo(leafRef);
// Setting by default the value of require-instance as true.
leafRef.setRequireInstance(true);
Parsable tmpData = listener.getParsedDataStack().peek();
switch (tmpData.getYangConstructType()) {
case LEAF_DATA:
// Parent YANG node of leaf to be added in resolution information.
YangLeaf leaf = (YangLeaf) listener.getParsedDataStack().pop();
Parsable parentNodeOfLeaf = listener.getParsedDataStack().peek();
listener.getParsedDataStack().push(leaf);
// Verify parent node of leaf.
if (!(parentNodeOfLeaf instanceof YangNode)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAFREF_DATA,
"", ENTRY));
}
leafRef.setResolvableStatus(UNRESOLVED);
// Add resolution information to the list.
YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangLeafRef>(leafRef,
(YangNode) parentNodeOfLeaf, errorLine, errorPosition);
addToResolutionList(resolutionInfo);
break;
case LEAF_LIST_DATA:
// Parent YANG node of leaf-list to be added in resolution information.
YangLeafList leafList = (YangLeafList) listener.getParsedDataStack().pop();
Parsable parentNodeOfLeafList = listener.getParsedDataStack().peek();
listener.getParsedDataStack().push(leafList);
// Verify parent node of leaf-list.
if (!(parentNodeOfLeafList instanceof YangNode)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAFREF_DATA,
"", ENTRY));
}
leafRef.setResolvableStatus(UNRESOLVED);
// Add resolution information to the list.
YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<YangLeafRef>(leafRef,
(YangNode) parentNodeOfLeafList, errorLine, errorPosition);
addToResolutionList(resolutionInfoImpl);
break;
case TYPEDEF_DATA:
/*
* Do not add the leaf ref to resolution list. It needs to be
* added to resolution list, when leaf/leaf list references to
* this typedef. At this time that leaf/leaf-list becomes the
* parent for the leafref.
*/
break;
default:
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAFREF_DATA,
"", ENTRY));
}
listener.getParsedDataStack().push(typeData);
listener.getParsedDataStack().push(leafRef);
}
/**
* It is called when parser exits from grammar rule (leafref), it performs
* validation and updates the data model tree.
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processLeafrefExit(TreeWalkListener listener,
GeneratedYangParser.LeafrefSpecificationContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, LEAFREF_DATA, "", EXIT);
Parsable parsableType = listener.getParsedDataStack().pop();
if (!(parsableType instanceof YangLeafRef)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAFREF_DATA,
"", EXIT));
}
}
/**
* Adds to resolution list.
*
* @param resolutionInfo resolution information
*/
private static void addToResolutionList(YangResolutionInfoImpl resolutionInfo) {
try {
addResolutionInfo(resolutionInfo);
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
LEAFREF_DATA, "", ENTRY, e.getMessage()));
}
}
}
......@@ -128,6 +128,8 @@ public final class ModuleListener {
.peek()).resolveSelfFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) listener.getParsedDataStack()
.peek()).resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
((YangReferenceResolver) listener.getParsedDataStack()
.peek()).resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
} catch (DataModelException e) {
LinkerException linkerException = new LinkerException(e.getMessage());
linkerException.setLine(e.getLineNumber());
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.validatePathArgument;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.PATH_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
* leafref-specification =
* ;; these stmts can appear in any order
* path-stmt stmtsep
* [require-instance-stmt stmtsep]
*
* path-stmt = path-keyword sep path-arg-str stmtend
*
* ANTLR grammar rule
*
* leafrefSpecification : (pathStatement (requireInstanceStatement)?) | ((requireInstanceStatement)? pathStatement);
*
* pathStatement : PATH_KEYWORD path STMTEND;
*/
/**
* Represents listener based call back function corresponding to the
* "path" rule defined in ANTLR grammar file for corresponding ABNF rule
* in RFC 6020.
*/
public final class PathListener {
/**
* Creates a new path listener.
*/
private PathListener() {
}
/**
* It is called when parser receives an input matching the grammar rule
* (path), performs validation and updates the data model tree.
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processPathEntry(TreeWalkListener listener,
GeneratedYangParser.PathStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, PATH_DATA, ctx.path().getText(), ENTRY);
Parsable curData = listener.getParsedDataStack().peek();
// Checks the holder of path as leafref, else throws error.
if (curData instanceof YangLeafRef) {
// Splitting the path argument and updating it in the datamodel tree.
validatePathArgument(ctx.path().getText(), PATH_DATA, ctx, (YangLeafRef) curData);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, PATH_DATA,
ctx.path().getText(), ENTRY));
}
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REQUIRE_INSTANCE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidBooleanValue;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
* require-instance-stmt = require-instance-keyword sep
* require-instance-arg-str stmtend
*
* require-instance-arg-str = < a string that matches the rule
* require-instance-arg >
*
* require-instance-arg = true-keyword / false-keyword
*
* ANTLR grammar rule
*
* requireInstanceStatement : REQUIRE_INSTANCE_KEYWORD requireInstance STMTEND;
*
* requireInstance : string;
*/
/**
* Represents listener based call back function corresponding to the
* "require-instance" rule defined in ANTLR grammar file for corresponding ABNF rule
* in RFC 6020.
*/
public final class RequireInstanceListener {
/**
* Creates a new require instance listener.
*/
private RequireInstanceListener() {
}
/**
* It is called when parser receives an input matching the grammar rule
* (require-instance), performs validation and updates the data model tree.
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processRequireInstanceEntry(TreeWalkListener listener,
GeneratedYangParser.RequireInstanceStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, REQUIRE_INSTANCE_DATA, "", ENTRY);
Parsable curData = listener.getParsedDataStack().peek();
// Gets the status of require instance
boolean isRequireInstance = getValidBooleanValue(ctx.requireInstance().getText(), REQUIRE_INSTANCE_DATA, ctx);
// Checks the holder of require-instance as leafref or type, else throws error.
if (curData instanceof YangLeafRef) {
// Sets the require-instance status to leafref.
((YangLeafRef) curData).setRequireInstance(isRequireInstance);
} else if (curData instanceof YangType) {
// Checks type should be instance-identifier, else throw error.
if (((YangType) curData).getDataType() == YangDataTypes.INSTANCE_IDENTIFIER) {
// Sets the require-instance status to instance-identifier type.
((YangType) curData).setDataTypeExtendedInfo(isRequireInstance);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REQUIRE_INSTANCE_DATA,
ctx.getText(), ENTRY));
}
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REQUIRE_INSTANCE_DATA,
ctx.getText(), ENTRY));
}
}
}
......@@ -133,6 +133,8 @@ public final class SubModuleListener {
.resolveSelfFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) listener.getParsedDataStack().peek())
.resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
((YangReferenceResolver) listener.getParsedDataStack().peek())
.resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
} catch (DataModelException e) {
LinkerException linkerException = new LinkerException(e.getMessage());
linkerException.setLine(e.getLineNumber());
......
......@@ -101,6 +101,9 @@ public final class TypeListener {
type.setNodeIdentifier(nodeIdentifier);
type.setDataType(yangDataTypes);
// Set default require instance value as true for instance identifier.
setDefaultRequireInstanceForInstanceIdentifier(type);
int errorLine = ctx.getStart().getLine();
int errorPosition = ctx.getStart().getCharPositionInLine();
......@@ -233,6 +236,18 @@ public final class TypeListener {
}
/**
* Sets the default require instance value as true when the type is instance identifier.
*
* @param type type to which the value has to be set
*/
private static void setDefaultRequireInstanceForInstanceIdentifier(YangType<?> type) {
if (type.getDataType() == YangDataTypes.INSTANCE_IDENTIFIER) {
((YangType<Boolean>) type).setDataTypeExtendedInfo(true);
}
}
/**
* It is called when parser exits from grammar rule (type), it perform
* validations and update the data model tree.
*
......@@ -291,7 +306,11 @@ public final class TypeListener {
parserException = new ParserException("YANG file error : a type bits" +
" must have atleast one bit statement.");
break;
// TODO : decimal64, identity ref, leafref
case LEAFREF:
parserException = new ParserException("YANG file error : a type leafref" +
" must have one path statement.");
break;
// TODO : decimal64, identity ref
default:
return;
}
......
......@@ -19,6 +19,8 @@ package org.onosproject.yangutils.translator.tojava;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
......@@ -80,7 +82,20 @@ public final class JavaCodeGeneratorUtil {
if (!(codeGenNode instanceof JavaCodeGenerator)) {
throw new TranslatorException("Unsupported node to generate code");
}
if (codeGenNode instanceof YangTypeDef) {
YangTypeDef typeDef = (YangTypeDef) codeGenNode;
if (typeDef.getTypeDefBaseType().getDataType() == YangDataTypes.LEAFREF
|| typeDef.getTypeDefBaseType().getDataType() == YangDataTypes.IDENTITYREF) {
if (codeGenNode.getNextSibling() != null) {
curTraversal = SIBILING;
codeGenNode = codeGenNode.getNextSibling();
} else {
curTraversal = PARENT;
codeGenNode = codeGenNode.getParent();
}
continue;
}
}
setCurNode(codeGenNode);
try {
generateCodeEntry(codeGenNode, yangPlugin);
......
......@@ -17,13 +17,15 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.util.Stack;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangEnumeration;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUnion;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
......@@ -101,6 +103,10 @@ public final class AttributesJavaDataType {
return STRING_DATA_TYPE;
case BOOLEAN:
return BOOLEAN_DATA_TYPE;
case INSTANCE_IDENTIFIER:
return STRING_DATA_TYPE;
case LEAFREF:
return getJavaDataType(getReferredTypeFromLeafref(yangType));
default:
throw new TranslatorException("given data type is not supported.");
}
......@@ -152,8 +158,8 @@ public final class AttributesJavaDataType {
case BINARY:
return YANG_BINARY_CLASS;
case LEAFREF:
//TODO:LEAFREF
break;
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportClass(referredType, isListAttr, pluginConfig);
case IDENTITYREF:
//TODO:IDENTITYREF
break;
......@@ -163,8 +169,7 @@ public final class AttributesJavaDataType {
return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
pluginConfig));
case INSTANCE_IDENTIFIER:
//TODO:INSTANCE_IDENTIFIER
break;
return STRING_DATA_TYPE;
case DERIVED:
return getCapitalCase(
getCamelCase(yangType.getDataTypeName(), pluginConfig));
......@@ -188,8 +193,8 @@ public final class AttributesJavaDataType {
case BINARY:
return YANG_BINARY_CLASS;
case LEAFREF:
//TODO:LEAFREF
break;
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportClass(referredType, isListAttr, pluginConfig);
case IDENTITYREF:
//TODO:IDENTITYREF
break;
......@@ -199,8 +204,7 @@ public final class AttributesJavaDataType {
return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
pluginConfig));
case INSTANCE_IDENTIFIER:
//TODO:INSTANCE_IDENTIFIER
break;
return STRING_DATA_TYPE;
case DERIVED:
return getCapitalCase(
getCamelCase(yangType.getDataTypeName(), pluginConfig));
......@@ -246,16 +250,15 @@ public final class AttributesJavaDataType {
case BINARY:
return YANG_TYPES_PKG;
case LEAFREF:
//TODO:LEAFREF
break;
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportPackage(referredType, isListAttr, conflictResolver);
case IDENTITYREF:
//TODO:IDENTITYREF
break;
case UNION:
return getUnionPackage(yangType, conflictResolver);
case INSTANCE_IDENTIFIER:
//TODO:INSTANCE_IDENTIFIER
break;
return JAVA_LANG;
case DERIVED:
return getTypDefsPackage(yangType, conflictResolver);
default:
......@@ -274,8 +277,8 @@ public final class AttributesJavaDataType {
case BINARY:
return YANG_TYPES_PKG;
case LEAFREF:
//TODO:LEAFREF
break;
YangType<?> referredType = getReferredTypeFromLeafref(yangType);
return getJavaImportPackage(referredType, isListAttr, conflictResolver);
case IDENTITYREF:
//TODO:IDENTITYREF
break;
......@@ -284,8 +287,7 @@ public final class AttributesJavaDataType {
case UNION:
return getUnionPackage(yangType, conflictResolver);
case INSTANCE_IDENTIFIER:
//TODO:INSTANCE_IDENTIFIER
break;
return JAVA_LANG;
case DERIVED:
return getTypDefsPackage(yangType, conflictResolver);
default:
......@@ -444,4 +446,15 @@ public final class AttributesJavaDataType {
.getPackage()));
}
}
/**
* Returns the referred type from leaf/leaf-list.
*
* @param type current type in leaf
* @return type from the leafref
*/
private static YangType<?> getReferredTypeFromLeafref(YangType type) {
YangLeafRef<?> leafRefInfo = (YangLeafRef<?>) type.getDataTypeExtendedInfo();
return leafRefInfo.getEffectiveDataType();
}
}
......
......@@ -18,8 +18,9 @@ package org.onosproject.yangutils.translator.tojava.utils;
import java.util.List;
import java.util.Map;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
......@@ -118,6 +119,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTA
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
......@@ -127,7 +129,6 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MAN
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
......
......@@ -282,6 +282,16 @@ public final class UtilConstants {
public static final String INPUT = "input";
/**
* Static attribute for output string.
*/
public static final String OUTPUT = "output";
/**
* Static attribute for current string.
*/
public static final String CURRENT = "current";
/**
* Static attribute for leafref string.
*/
public static final String LEAFREF = "leafref";
......@@ -342,6 +352,41 @@ public final class UtilConstants {
public static final String COMMA = ",";
/**
* Static attribute for slash character.
*/
public static final char CHAR_OF_SLASH = '/';
/**
* Static attribute for open square bracket character.
*/
public static final char CHAR_OF_OPEN_SQUARE_BRACKET = '[';
/**
* Static attribute for close square bracket character.
*/
public static final char CHAR_OF_CLOSE_SQUARE_BRACKET = ']';
/**
* Static attribute for slash string.
*/
public static final String SLASH_FOR_STRING = "/";
/**
* Static attribute for open square bracket.
*/
public static final String OPEN_SQUARE_BRACKET = "[";
/**
* Static attribute for ancestor accessor.
*/
public static final String ANCESTOR_ACCESSOR = "..";
/**
* Static attribute for ancestor accessor along with path.
*/
public static final String ANCESTOR_ACCESSOR_IN_PATH = "../";
/**
* Static attribute for add syntax.
*/
public static final String ADD_STRING = "add";
......@@ -1110,7 +1155,6 @@ public final class UtilConstants {
*/
public static final String YANG_DECIMAL64_CLASS = "YangDecimal64";
/**
* Static attribute for YANG file error.
*/
......@@ -1140,12 +1184,18 @@ public final class UtilConstants {
+ "grouping for given uses";
/**
* Static attribute for grouping linker error information.
* Static attribute for if-feature linker error information.
*/
public static final String FEATURE_LINKER_ERROR = "YANG file error: Unable to find feature "
+ "for given if-feature";
/**
* Static attribute for leafref linker error information.
*/
public static final String LEAFREF_LINKER_ERROR = "YANG file error: Unable to find base "
+ "leaf/leaf-list for given leafref";
/**
* Static attribute for reference.
*/
public static final String REFERENCE = "Reference";
......
......@@ -534,7 +534,7 @@ package org.onosproject.yangutils.parser.antlrgencode;
* require-instance-arg >
* require-instance-arg = true-keyword / false-keyword
*/
requireInstanceStatement : REQUIRE_INSTANCE_KEYWORD (TRUE_KEYWORD | FALSE_KEYWORD) STMTEND;
requireInstanceStatement : REQUIRE_INSTANCE_KEYWORD requireInstance STMTEND;
/**
* instance-identifier-specification =
......@@ -1279,6 +1279,8 @@ package org.onosproject.yangutils.parser.antlrgencode;
refine : string;
requireInstance : string;
augment : string;
deviation : string;
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import java.util.ListIterator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
/**
* Test cases for require-instance listener.
*/
public class RequireInstanceListenerTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks require-statement with true as status.
*/
@Test
public void processRequireInstanceTrue() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/RequireInstanceTrue.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("PathListener"));
YangContainer container = (YangContainer) yangNode.getChild().getNextSibling();
ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
// Check whether the require-instance value is set correctly in leafref.
assertThat(leafInfo.getName(), is("ifname"));
YangLeafRef yangLeafRef = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo();
assertThat(yangLeafRef.getRequireInstance(), is(true));
}
/**
* Checks require-statement with false as status.
*/
@Test
public void processRequireInstanceFalse() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/RequireInstanceFalse.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("PathListener"));
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
// Check whether the require-instance value is set correctly in instance-identifier.
assertThat(leafInfo.getName(), is("admin-status"));
YangType type = leafInfo.getDataType();
assertThat(type.getDataType(), is(YangDataTypes.INSTANCE_IDENTIFIER));
boolean status = ((YangType<Boolean>) type).getDataTypeExtendedInfo();
assertThat(status, is(false));
}
/**
* Checks require-statement default value when its not there in YANG under instance-identifier.
*/
@Test
public void processRequireInstanceDefaultValueInInstanceIdentifier() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/RequireInstanceDefaultValueInInstanceIdentifier.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("PathListener"));
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
// Check whether the require-instance value is set correctly in instance-identifier.
assertThat(leafInfo.getName(), is("admin-status"));
YangType type = leafInfo.getDataType();
assertThat(type.getDataType(), is(YangDataTypes.INSTANCE_IDENTIFIER));
boolean status = ((YangType<Boolean>) type).getDataTypeExtendedInfo();
assertThat(status, is(true));
}
/**
* Checks require-statement default value when its not there in YANG under leafref.
*/
@Test
public void processRequireInstanceDefaultValueForLeafref() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/RequireInstanceDefaultValueForLeafref.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("PathListener"));
YangContainer container = (YangContainer) yangNode.getChild().getNextSibling();
ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
// Check whether the require-instance value is set correctly in leafref.
assertThat(leafInfo.getName(), is("ifname"));
YangLeafRef yangLeafRef = (YangLeafRef) leafInfo.getDataType().getDataTypeExtendedInfo();
assertThat(yangLeafRef.getRequireInstance(), is(true));
}
}
......@@ -20,6 +20,7 @@ import java.util.ListIterator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
......@@ -121,20 +122,6 @@ public class TypeListenerTest {
}
/**
* Checks for unsupported type leafref.
*/
@Test
public void processLeafrefType() throws IOException, ParserException {
thrown.expect(ParserException.class);
thrown.expectMessage("YANG file error : \"leafref\" is not supported in current version,"
+ " please check wiki for YANG utils road map.");
YangNode node = manager
.getDataModel("src/test/resources/LeafrefInvalidIdentifier.yang");
}
/**
* Checks for unsupported type identityref.
*/
@Test
......@@ -149,16 +136,29 @@ public class TypeListenerTest {
}
/**
* Checks for unsupported type instance identifier.
* Checks for type instance-identifier.
*/
@Test
public void processInstanceIdentifierType() throws IOException, ParserException {
thrown.expect(ParserException.class);
thrown.expectMessage("YANG file error : \"instance-identifier\" is not supported in current version,"
+ " please check wiki for YANG utils road map.");
YangNode node = manager
.getDataModel("src/test/resources/InstanceIdentifierInvalidIdentifier.yang");
.getDataModel("src/test/resources/InstanceIdentifierListener.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
YangContainer container = (YangContainer) yangNode.getChild();
ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("instance-identifier"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.INSTANCE_IDENTIFIER));
}
}
......
......@@ -18,11 +18,15 @@ package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.List;
import java.util.ListIterator;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangFeature;
import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
......@@ -217,4 +221,111 @@ public class IntraFileIfFeatureLinkingTest {
assertThat(ifFeature.getName().getName(), is("local-storage"));
assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
}
/**
* Checks addition of if-feature list to leafref.
*/
@Test
public void processSelfFileLinkingWithFeatureReferredByLeafref()
throws IOException, ParserException {
YangNode node = manager
.getDataModel("src/test/resources/SelfFileLinkingWithFeatureReferredByLeafref.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("syslog"));
List<YangFeature> featureList = yangNode.getFeatureList();
YangFeature feature = featureList.iterator().next();
assertThat(feature.getName(), is("local-storage"));
YangContainer container = (YangContainer) yangNode.getChild();
assertThat(container.getName(), is("speed"));
List<YangLeaf> listOfLeaf = container.getListOfLeaf();
YangLeaf leaf = listOfLeaf.iterator().next();
assertThat(leaf.getName(), is("local-storage-limit"));
List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
YangIfFeature ifFeature = ifFeatureList.iterator().next();
assertThat(ifFeature.getName().getName(), is("local-storage"));
assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
ListIterator<YangLeaf> listOfLeafInModule = yangNode.getListOfLeaf().listIterator();
YangLeaf yangLeaf = listOfLeafInModule.next();
assertThat(yangLeaf.getName(), is("storage-value"));
YangLeafRef leafRef = (YangLeafRef) yangLeaf.getDataType().getDataTypeExtendedInfo();
assertThat(leafRef.getEffectiveDataType().getDataType(), is(YangDataTypes.UINT64));
List<YangIfFeature> ifFeatureListInLeafref = leafRef.getIfFeatureList();
YangIfFeature ifFeatureInLeafref = ifFeatureListInLeafref.iterator().next();
assertThat(ifFeatureInLeafref.getName().getName(), is("local-storage"));
assertThat(ifFeatureInLeafref.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
}
/**
* Checks addition of if-feature list to leafref when referred leaf is again having leafref in it.
*/
@Test
public void processSelfFileLinkingWithFeatureReferredByMultiLeafref()
throws IOException, ParserException {
YangNode node = manager
.getDataModel("src/test/resources/SelfFileLinkingWithFeatureReferredByMultiLeafref.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("syslog"));
List<YangFeature> featureList = yangNode.getFeatureList();
YangFeature feature = featureList.iterator().next();
assertThat(feature.getName(), is("local-storage"));
YangContainer container = (YangContainer) yangNode.getChild();
assertThat(container.getName(), is("speed"));
List<YangLeaf> listOfLeaf = container.getListOfLeaf();
YangLeaf leaf = listOfLeaf.iterator().next();
assertThat(leaf.getName(), is("local-storage-limit"));
List<YangIfFeature> ifFeatureList = leaf.getIfFeatureList();
YangIfFeature ifFeature = ifFeatureList.iterator().next();
assertThat(ifFeature.getName().getName(), is("local-storage"));
assertThat(ifFeature.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
ListIterator<YangLeaf> listOfLeafInModule = yangNode.getListOfLeaf().listIterator();
YangLeaf yangLeaf = listOfLeafInModule.next();
assertThat(yangLeaf.getName(), is("storage-value"));
YangLeafRef leafRef = (YangLeafRef) yangLeaf.getDataType().getDataTypeExtendedInfo();
assertThat(leafRef.getEffectiveDataType().getDataType(), is(YangDataTypes.UINT64));
List<YangIfFeature> ifFeatureListInLeafref = leafRef.getIfFeatureList();
YangIfFeature ifFeatureInLeafref = ifFeatureListInLeafref.iterator().next();
assertThat(ifFeatureInLeafref.getName().getName(), is("main-storage"));
assertThat(ifFeatureInLeafref.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
YangIfFeature ifFeatureInLeafref1 = ifFeatureListInLeafref.iterator().next();
assertThat(ifFeatureInLeafref1.getName().getName(), is("main-storage"));
assertThat(ifFeatureInLeafref1.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
}
}
......
module PathListener {
namespace "test";
prefix test;
list interface {
key "name";
leaf name {
type string;
}
leaf admin-status {
type string;
}
list address {
key "ip";
leaf ip {
type string;
}
}
}
container default-address {
leaf ifname {
type leafref {
path "../../test:interface/test:name";
}
}
leaf status {
type leafref {
path "/test:interface[name = current()/../ifname]/test:admin-status";
}
}
}
}
\ No newline at end of file
module PathListener {
namespace "test";
prefix test;
list interface {
key "name";
leaf name {
type string;
}
leaf admin-status {
type string;
}
list address {
key "ip";
leaf ip {
type string;
}
}
}
container default-address {
leaf ifname {
type leafref {
path "../../test:interface/test:name";
}
}
leaf status {
type leafref {
path "/test:interface[name = current()/../ifname]/test:admin-status";
}
}
}
}
\ No newline at end of file
module PathListener {
namespace "test";
prefix test;
leaf admin-status {
type instance-identifier;
}
}
\ No newline at end of file
module PathListener {
namespace "test";
prefix test;
leaf admin-status {
type instance-identifier {
require-instance "false";
}
}
}
\ No newline at end of file
module PathListener {
namespace "test";
prefix test;
list interface {
key "name";
leaf name {
type string;
}
leaf admin-status {
type string;
}
list address {
key "ip";
leaf ip {
type string;
}
}
}
container default-address {
leaf ifname {
type leafref {
path "../../test:interface/test:name";
require-instance true;
}
}
leaf status {
type leafref {
path "/test:interface[name = current()/../ifname]/test:admin-status";
}
}
}
}
\ No newline at end of file
module syslog {
yang-version 1;
namespace http://huawei.com;
prefix "sys";
feature local-storage {
description
"This feature means the device supports local
storage (memory, flash or disk) that can be used to
store syslog messages.";
}
container speed {
leaf local-storage-limit {
if-feature local-storage;
type uint64;
units "kilobyte";
config false;
description
"The amount of local storage that can be
used to hold syslog messages.";
}
}
leaf storage-value {
type leafref {
path "/speed/local-storage-limit";
}
}
}
module syslog {
yang-version 1;
namespace http://huawei.com;
prefix "sys";
feature local-storage {
description
"This feature means the device supports local
storage (memory, flash or disk) that can be used to
store syslog messages.";
}
feature main-storage {
description
"This feature means the device supports main
storage that can be used to
store syslog messages.";
}
container speed {
leaf local-storage-limit {
if-feature local-storage;
type leafref {
path "/value";
}
units "kilobyte";
config false;
description
"The amount of local storage that can be
used to hold syslog messages.";
}
}
leaf storage-value {
type leafref {
path "/speed/local-storage-limit";
}
}
leaf value {
if-feature main-storage;
type uint64;
}
}
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
container networks {
description
"Serves as top-level container for a list of networks.";
leaf network-id {
type status;
description
"Identifies a network.";
}
}
typedef status {
type uint8;
}
leaf network-ref {
type leafref {
path "/networks";
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
container networks {
description
"Serves as top-level container for a list of networks.";
leaf network-id {
type uint8;
description
"Identifies a network.";
}
}
leaf-list network-ref {
type leafref;
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
rpc networks {
description
"Serves as top-level container for a list of networks.";
grouping input {
leaf network-id {
type string;
description
"Identifies a network.";
}
}
input {
leaf network-id {
type uint8;
description
"Identifies a network.";
}
}
output {
}
}
leaf network-ref {
type leafref {
path "/networks/input/network-id";
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
grouping networks {
leaf network-id {
type uint8;
description
"Identifies a network.";
}
}
container current {
leaf network-ref {
type leafref {
path "/networks/network-id";
}
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
rpc networks {
description
"Serves as top-level container for a list of networks.";
grouping input {
leaf network-id {
type string;
description
"Identifies a network.";
}
}
input {
leaf network-id {
type uint8;
description
"Identifies a network.";
}
}
}
leaf network-ref {
type leafref {
path "/networks/input/network-id";
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
rpc networks {
description
"Serves as top-level container for a list of networks.";
grouping input {
leaf network-id {
type string;
description
"Identifies a network.";
}
}
input {
leaf network-id {
type uint8;
description
"Identifies a network.";
}
}
}
leaf network-ref {
type leafref {
path "../networks/input/network-id";
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
container networks {
description
"Serves as top-level container for a list of networks.";
leaf network-id {
type uint8;
description
"Identifies a network.";
}
}
leaf network-ref {
type leafref {
path "/define/network-id";
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
container networks {
description
"Serves as top-level container for a list of networks.";
leaf network-id {
type uint8;
description
"Identifies a network.";
}
}
leaf network-ref {
type leafref {
path "../define/network-id";
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
container networks {
description
"Serves as top-level container for a list of networks.";
leaf network-id {
type uint8;
description
"Identifies a network.";
}
}
leaf network-ref {
type leafref {
path "../../../define/network-id";
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
rpc networks {
description
"Serves as top-level container for a list of networks.";
input {
leaf network-id {
type uint8;
description
"Identifies a network.";
}
}
output {
}
}
leaf network-ref {
type leafref {
path "/networks/input/network-id";
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
rpc networks {
description
"Serves as top-level container for a list of networks.";
input {
leaf-list network-id {
type uint8;
description
"Identifies a network.";
}
}
output {
}
}
leaf-list network-ref {
type leafref {
path "/networks/input/network-id";
}
}
}
\ No newline at end of file
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
list valid {
key "define";
leaf define {
type string;
}
container standard {
typedef node {
type leafref {
path "/invalid-interval";
}
}
container present {
typedef name {
type node;
}
leaf interval {
type name;
}
}
}
}
leaf-list invalid-interval {
type enumeration {
enum 10m;
enum 100m;
enum auto;
}
}
}
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
rpc networks {
description
"Serves as top-level container for a list of networks.";
input {
leaf-list network-id {
type network-ref;
description
"Identifies a network.";
}
leaf id {
type uint8;
}
}
output {
}
}
typedef network-ref {
type leafref {
path "/networks/input/id";
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
container networks {
description
"Serves as top-level container for a list of networks.";
leaf network-id {
type network-ref;
description
"Identifies a network.";
}
leaf id {
type uint8;
}
}
typedef network-ref {
type leafref {
path "/networks/id";
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
container networks {
description
"Serves as top-level container for a list of networks.";
leaf network-id {
type network-ref;
description
"Identifies a network.";
}
leaf id {
type uint8;
}
}
typedef network-ref {
type leafref {
path "../id";
}
}
}
\ No newline at end of file
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
list valid {
key "define";
leaf define {
type string;
}
container standard {
container present {
leaf name {
type leafref {
path "/invalid-interval";
}
}
}
}
}
leaf invalid-interval {
type union {
type int32;
type enumeration {
enum "unbounded";
}
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
list valid {
key "define";
leaf define {
type string;
}
container standard {
container present {
leaf-list name {
type leafref {
path "/invalid-interval";
}
}
}
}
}
leaf-list invalid-interval {
type enumeration {
enum 10m;
enum 100m;
enum auto;
}
}
}
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
container networks {
description
"Serves as top-level container for a list of networks.";
leaf network-id {
type status;
description
"Identifies a network.";
}
}
typedef status {
type uint8;
}
leaf network-ref {
type leafref {
path "/networks/network-id";
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
container networks {
description
"Serves as top-level container for a list of networks.";
leaf network-id {
type leafref {
path "/status/current";
}
description
"Identifies a network.";
}
}
container status {
leaf current {
type uint8;
}
}
leaf network-ref {
type leafref {
path "/networks/network-id";
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
container networks {
description
"Serves as top-level container for a list of networks.";
leaf network-id {
type uint8;
description
"Identifies a network.";
}
}
leaf network-ref {
type leafref {
path "/networks/network-id";
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
container networks {
description
"Serves as top-level container for a list of networks.";
leaf network-id {
type uint8;
description
"Identifies a network.";
}
}
leaf-list network-ref {
type leafref {
path "/networks/network-id";
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
container networks {
description
"Serves as top-level container for a list of networks.";
leaf network-id {
type uint8;
description
"Identifies a network.";
}
}
leaf network-ref {
type leafref {
path "../networks/network-id";
}
}
}
\ No newline at end of file
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
list valid {
key "define";
leaf define {
type string;
}
container standard {
container present {
leaf-list name {
type transmitter;
}
}
}
}
container reference {
list found {
key "define";
leaf define {
type string;
}
container reciever {
leaf remove {
type leafref {
path "/valid/standard/present/name";
}
}
}
}
}
typedef transmitter {
type leafref {
path "/invalid-interval";
}
}
leaf invalid-interval {
type enumeration {
enum 10m;
enum 100m;
enum auto;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
list valid {
key "define";
leaf define {
type string;
}
container standard {
container present {
leaf-list name {
type transmitter;
}
}
}
}
container reference {
list found {
key "define";
leaf define {
type string;
}
container reciever {
leaf remove {
type leafref {
path "../../../../valid/standard/present/name";
}
}
}
}
}
typedef transmitter {
type leafref {
path "../../../../invalid-interval";
}
}
leaf invalid-interval {
type enumeration {
enum 10m;
enum 100m;
enum auto;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
list valid {
key "define";
leaf define {
type string;
}
container standard {
container present {
leaf-list name {
type leafref {
path "/transmitter/send";
}
}
}
}
}
container reference {
list found {
key "define";
leaf define {
type string;
}
container reciever {
leaf remove {
type leafref {
path "/valid/standard/present/name";
}
}
}
}
}
list transmitter {
key "send";
leaf send {
type leafref {
path "/invalid-interval";
}
}
}
leaf-list invalid-interval {
type enumeration {
enum 10m;
enum 100m;
enum auto;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
list valid {
key "define";
leaf define {
type string;
}
container standard {
container present {
leaf-list name {
type leafref {
path "../../../../transmitter/send";
}
}
}
}
}
container reference {
list found {
key "define";
leaf define {
type string;
}
container reciever {
leaf remove {
type leafref {
path "../../../../valid/standard/present/name";
}
}
}
}
}
list transmitter {
key "send";
leaf send {
type leafref {
path "../../invalid-interval";
}
}
}
leaf-list invalid-interval {
type enumeration {
enum 10m;
enum 100m;
enum auto;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
list valid {
key "define";
leaf define {
type string;
}
container standard {
container present {
leaf-list name {
type transmitter;
}
}
}
}
container reference {
list found {
key "define";
leaf define {
type string;
}
container reciever {
leaf remove {
type leafref {
path "/valid/standard/present/name";
}
}
}
}
}
typedef transmitter {
type invalid-interval;
}
typedef invalid-interval {
type enumeration {
enum 10m;
enum 100m;
enum auto;
}
}
}
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
container networks {
description
"Serves as top-level container for a list of networks.";
leaf network-id {
type uint8;
description
"Identifies a network.";
}
}
leaf network-ref {
type leafref {
path "/define/network-id";
}
}
}
\ No newline at end of file
module module1 {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
import module2 {
prefix p;
}
leaf invalid-interval {
type leafref {
path "/p:hello";
}
}
leaf hello {
type string;
}
}
\ No newline at end of file
module Test {
module module2 {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
leaf-list invalid-interval {
type leafref;
prefix Ant2;
leaf hello {
type string;
}
}
......
module module1 {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-te-topology";
prefix "tet";
import module2 {
prefix "nt";
}
grouping te-node-tunnel-termination-capability {
description
"Termination capability of a tunnel termination point on a
TE node.";
list termination-capability {
key "link-tp";
description
"The termination capabilities between
tunnel-termination-point and link termination-point.
The capability information can be used to compute
the tunnel path.";
leaf link-tp {
type leafref {
path "/nt:termination-point/nt:tp-id";
}
description
"Link termination point.";
}
} // termination-capability
} // te-node-tunnel-termination-capability
}
\ No newline at end of file
module module2 {
yang-version 1;
namespace
"urn:ietf:params:xml:ns:yang:ietf-inet-types";
prefix inet;
container termination-point {
leaf tp-id {
type string;
}
}
}
\ No newline at end of file
module ietf-inet-types {
yang-version 1;
namespace
"urn:ietf:params:xml:ns:yang:ietf-inet-types";
prefix inet;
typedef tp-ref {
type leafref {
path "/nwtp:value";
}
}
}
\ No newline at end of file
module ietf-network-topology {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-te-topology";
prefix "tet";
import ietf-network {
prefix "nt";
}
grouping te-node-tunnel-termination-capability {
description
"Termination capability of a tunnel termination point on a
TE node.";
list termination-capability {
key "link-tp";
description
"The termination capabilities between
tunnel-termination-point and link termination-point.
The capability information can be used to compute
the tunnel path.";
leaf link-tp {
type leafref {
path "/nt:termination-point/nt:tp-id";
}
description
"Link termination point.";
}
} // termination-capability
} // te-node-tunnel-termination-capability
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace
"urn:ietf:params:xml:ns:yang:ietf-inet-types";
prefix nw;
import ietf-inet-types {
prefix inet;
}
container termination-point {
leaf tp-id {
type string;
}
}
}
\ No newline at end of file
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
container networks {
description
"Serves as top-level container for a list of networks.";
leaf network-id {
type status;
description
"Identifies a network.";
}
}
typedef status {
type uint8;
}
leaf network-ref {
type leafref {
path "/networks";
}
}
}
\ No newline at end of file