Vidyashree Rama
Committed by Vidyashree-Huawei

[ONOS-4894][ONOS-4890][ONOS-4887][ONOS-4923]extension and argument

datamodel and listener + defect fix

Change-Id: Icefe046d9848935bb6c40a6d7688feb084edd65d
Showing 25 changed files with 915 additions and 66 deletions
......@@ -354,7 +354,7 @@ public class YangCase
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType)
throws DataModelException {
if (!(getParent() instanceof YangChoice)) {
if (!(getParent() instanceof YangChoice || getParent() instanceof YangAugment)) {
throw new DataModelException("Internal Data Model Tree Error: Invalid/Missing holder in case " +
getName());
}
......
/*
* 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.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.YangConstructType;
/*-
* Reference RFC 6020.
*
* The "extension" statement allows the definition of new statements
* within the YANG language. This new statement definition can be
* imported and used by other modules.
*
* The statement's argument is an identifier that is the new keyword for
* the extension and must be followed by a block of sub-statements that
* holds detailed extension information. The purpose of the "extension"
* statement is to define a keyword, so that it can be imported and used
* by other modules.
*
* The extension can be used like a normal YANG statement, with the
* statement name followed by an argument if one is defined by the
* extension, and an optional block of sub-statements. The statement's
* name is created by combining the prefix of the module in which the
* extension was defined, a colon (":"), and the extension's keyword,
* with no interleaving whitespace. The sub-statements of an extension
* are defined by the extension, using some mechanism outside the scope
* of this specification. Syntactically, the sub-statements MUST be YANG
* statements, or also defined using "extension" statements.
*
* The extension's Sub-statements
*
* +--------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | description | 7.19.3 | 0..1 | -string |
* | reference | 7.19.4 | 0..1 | -string |
* | status | 7.19.2 | 0..1 | -YangStatus |
* | argument | 7.17.2 | 0..1 | -string |
* +--------------+---------+-------------+------------------+
*/
/**
* Represents data model node to maintain information defined in YANG extension.
*/
public class YangExtension
implements YangCommonInfo, Serializable, Parsable {
private static final long serialVersionUID = 806201605L;
/**
* Name of the extension.
*/
private String name;
/**
* Name of the argument.
*/
private String argumentName;
/**
* Description of extension.
*/
private String description;
/**
* Reference of the extension.
*/
private String reference;
/**
* Status of the extension.
*/
private YangStatusType status = YangStatusType.CURRENT;
/**
* Returns the YANG name of extension.
*
* @return the name of extension as defined in YANG file
*/
public String getName() {
return name;
}
/**
* Sets the YANG name of extension.
*
* @param name the name of extension as defined in YANG file
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns the YANG argument name of extension.
*
* @return the name of argument as defined in YANG file
*/
public String getArgumentName() {
return argumentName;
}
/**
* Sets the YANG argument name of extension.
*
* @param argumentName the name of argument as defined in YANG file
*/
public void setArgumentName(String argumentName) {
this.argumentName = argumentName;
}
/**
* Returns the description.
*
* @return the description
*/
@Override
public String getDescription() {
return description;
}
/**
* Sets the description.
*
* @param description set the description
*/
@Override
public void setDescription(String description) {
this.description = description;
}
/**
* Returns the textual reference.
*
* @return the reference
*/
@Override
public String getReference() {
return reference;
}
/**
* Sets the textual reference.
*
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
this.reference = reference;
}
/**
* Returns the status.
*
* @return the status
*/
@Override
public YangStatusType getStatus() {
return status;
}
/**
* Sets the status.
*
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
this.status = status;
}
/**
* Returns the type of the data.
*
* @return returns EXTENSION_DATA
*/
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.EXTENSION_DATA;
}
/**
* Validates the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validates the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit()
throws DataModelException {
// TODO : to be implemented
}
}
......@@ -231,6 +231,11 @@ public class YangModule
private List<YangResolutionInfo> augmentResolutionList;
/**
* extension list.
*/
private List<YangExtension> extensionList;
/**
* Creates a YANG node of module type.
*/
public YangModule() {
......@@ -247,6 +252,7 @@ public class YangModule
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
listOfLeafList = new LinkedList<YangLeafList>();
extensionList = new LinkedList<YangExtension>();
}
/**
......@@ -557,6 +563,33 @@ public class YangModule
}
/**
* Adds extension in extension list.
*
* @param extension the extension to be added
*/
public void addExtension(YangExtension extension) {
getExtensionList().add(extension);
}
/**
* Returns the extension list.
*
* @return the extension list
*/
public List<YangExtension> getExtensionList() {
return extensionList;
}
/**
* Sets the extension list.
*
* @param extensionList the list of extension
*/
public void setExtensionList(List<YangExtension> extensionList) {
this.extensionList = extensionList;
}
/**
* Returns the type of the parsed data.
*
* @return returns MODULE_DATA
......@@ -639,7 +672,7 @@ public class YangModule
leafrefResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_AUGMENT) {
} else if (type == ResolvableType.YANG_AUGMENT) {
augmentResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList.add(resolutionInfo);
......@@ -659,7 +692,7 @@ public class YangModule
leafrefResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_AUGMENT) {
} else if (type == ResolvableType.YANG_AUGMENT) {
augmentResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList = resolutionList;
......
......@@ -224,6 +224,11 @@ public class YangSubModule
private List<YangResolutionInfo> identityrefResolutionList;
/**
* extension list.
*/
private List<YangExtension> extensionList;
/**
* Augment resolution list.
*/
private List<YangResolutionInfo> augmentResolutionList;
......@@ -244,6 +249,7 @@ public class YangSubModule
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
listOfLeafList = new LinkedList<YangLeafList>();
extensionList = new LinkedList<YangExtension>();
}
/**
......@@ -601,7 +607,7 @@ public class YangSubModule
leafrefResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_AUGMENT) {
} else if (type == ResolvableType.YANG_AUGMENT) {
augmentResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList.add(resolutionInfo);
......@@ -621,7 +627,7 @@ public class YangSubModule
leafrefResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_AUGMENT) {
} else if (type == ResolvableType.YANG_AUGMENT) {
augmentResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList = resolutionList;
......@@ -684,4 +690,31 @@ public class YangSubModule
public void setListOfFeature(List<YangFeature> listOfFeature) {
this.listOfFeature = listOfFeature;
}
/**
* Adds extension in extension list.
*
* @param extension the extension to be added
*/
public void addExtension(YangExtension extension) {
getExtensionList().add(extension);
}
/**
* Returns the extension list.
*
* @return the extension list
*/
public List<YangExtension> getExtensionList() {
return extensionList;
}
/**
* Sets the extension list.
*
* @param extensionList the list of extension
*/
public void setExtensionList(List<YangExtension> extensionList) {
this.extensionList = extensionList;
}
}
......
......@@ -382,7 +382,12 @@ public enum YangConstructType {
/**
* Identifies the YANG anyxml element parsed data.
*/
ANYXML_DATA;
ANYXML_DATA,
/**
* Identifies the YANG argument element parsed data.
*/
ARGUMENT_DATA;
/**
* Returns the YANG construct keyword corresponding to enum values.
......@@ -539,6 +544,8 @@ public enum YangConstructType {
return "deviation";
case ANYXML_DATA:
return "anyxml";
case ARGUMENT_DATA:
return "argument";
default:
return "yang";
}
......
......@@ -16,8 +16,14 @@
package org.onosproject.yangutils.linker.impl;
import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import org.onosproject.yangutils.datamodel.Resolvable;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.TraversalType;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
......@@ -58,12 +64,10 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.linker.YangLinkingPhase;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTER_FILE_LINKED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
......@@ -1007,16 +1011,33 @@ public class YangResolutionInfoImpl<T>
/**
* Search the grouping node's children for presence of uses node.
*/
TraversalType curTraversal = ROOT;
YangNode curNode = node.getChild();
while (curNode != null) {
if (curNode.getName().equals(node.getName())) {
// if we have traversed all the child nodes, then exit from loop
return;
}
// if child nodes has uses, then add it to resolution stack
if (curNode instanceof YangUses) {
YangEntityToResolveInfoImpl<YangUses> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>();
unResolvedEntityInfo.setEntityToResolve((YangUses) curNode);
unResolvedEntityInfo.setHolderOfEntityToResolve(node);
addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo);
}
// Traversing all the child nodes of grouping
if (curTraversal != PARENT && curNode.getChild() != null) {
curTraversal = CHILD;
curNode = curNode.getChild();
} else if (curNode.getNextSibling() != null) {
curTraversal = SIBILING;
curNode = curNode.getNextSibling();
} else {
curTraversal = PARENT;
curNode = curNode.getParent();
}
curNode = curNode.getNextSibling();
}
}
......@@ -1421,7 +1442,7 @@ public class YangResolutionInfoImpl<T>
* @param resolutionInfo information about the YANG construct which has to be resolved
* @throws DataModelException a violation of data model rules
*/
public void setAbsolutePathFromRelativePathInLeafref(T resolutionInfo) throws DataModelException {
public void setAbsolutePathFromRelativePathInLeafref(T resolutionInfo) throws DataModelException {
if (resolutionInfo instanceof YangLeafRef) {
YangNode parentOfLeafref = ((YangLeafRef) resolutionInfo).getParentNodeOfLeafref();
......
......@@ -24,6 +24,7 @@ import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangListener;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.impl.listeners.ArgumentListener;
import org.onosproject.yangutils.parser.impl.listeners.AugmentListener;
import org.onosproject.yangutils.parser.impl.listeners.BaseFileListener;
import org.onosproject.yangutils.parser.impl.listeners.BaseListener;
......@@ -42,6 +43,7 @@ import org.onosproject.yangutils.parser.impl.listeners.EnumListener;
import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener;
import org.onosproject.yangutils.parser.impl.listeners.ErrorAppTagListener;
import org.onosproject.yangutils.parser.impl.listeners.ErrorMessageListener;
import org.onosproject.yangutils.parser.impl.listeners.ExtensionListener;
import org.onosproject.yangutils.parser.impl.listeners.FeatureListener;
import org.onosproject.yangutils.parser.impl.listeners.FractionDigitsListener;
import org.onosproject.yangutils.parser.impl.listeners.GroupingListener;
......@@ -436,12 +438,12 @@ public class TreeWalkListener implements GeneratedYangListener {
@Override
public void enterExtensionStatement(GeneratedYangParser.ExtensionStatementContext ctx) {
handleUnsupportedYangConstruct(YangConstructType.EXTENSION_DATA, ctx, UNSUPPORTED_YANG_CONSTRUCT);
ExtensionListener.processExtensionEntry(this, ctx);
}
@Override
public void exitExtensionStatement(GeneratedYangParser.ExtensionStatementContext ctx) {
// do nothing
ExtensionListener.processExtensionExit(this, ctx);
}
@Override
......@@ -456,7 +458,7 @@ public class TreeWalkListener implements GeneratedYangListener {
@Override
public void enterArgumentStatement(GeneratedYangParser.ArgumentStatementContext ctx) {
// do nothing.
ArgumentListener.processArgumentEntry(this, ctx);
}
@Override
......
/*
* 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.YangExtension;
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.datamodel.utils.YangConstructType.ARGUMENT_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
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_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
* argument-stmt = argument-keyword sep identifier-arg-str optsep
* (";" /
* "{" stmtsep
* [yin-element-stmt stmtsep]
* "}")
* *
* ANTLR grammar rule
* argumentStatement : ARGUMENT_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE argumentBody RIGHT_CURLY_BRACE);
* argumentBody : yinElementStatement?;
*/
/**
* Represents listener based call back function corresponding to the "argument"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class ArgumentListener {
/**
* Creates a new argument listener.
*/
private ArgumentListener() {
}
/**
* It is called when parser receives an input matching the grammar rule
* (argument), performs validation and updates the data model tree.
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processArgumentEntry(TreeWalkListener listener,
GeneratedYangParser.ArgumentStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, ARGUMENT_DATA, ctx.identifier().getText(), ENTRY);
String identifier = getValidIdentifier(ctx.identifier().getText(), ARGUMENT_DATA, ctx);
Parsable curData = listener.getParsedDataStack().peek();
if (curData instanceof YangExtension) {
YangExtension extension = ((YangExtension) curData);
extension.setArgumentName(identifier);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ARGUMENT_DATA,
ctx.identifier().getText(), ENTRY));
}
}
}
......@@ -52,8 +52,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidAbsoluteSchemaNodeId;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityEitherOne;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds;
import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangAugmentNode;
/*
......@@ -176,8 +176,8 @@ public final class AugmentListener {
validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, AUGMENT_DATA, ctx.augment().getText());
validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, AUGMENT_DATA, ctx.augment().getText());
validateCardinalityMaxOne(ctx.whenStatement(), WHEN_DATA, AUGMENT_DATA, ctx.augment().getText());
validateMutuallyExclusiveChilds(ctx.dataDefStatement(), DATA_DEF_DATA, ctx.caseStatement(),
CASE_DATA, AUGMENT_DATA, ctx.augment().getText());
validateCardinalityEitherOne(ctx.dataDefStatement(), DATA_DEF_DATA, ctx.caseStatement(),
CASE_DATA, AUGMENT_DATA, ctx.augment().getText(), ctx);
}
/**
......
......@@ -16,6 +16,7 @@
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangNode;
......@@ -104,7 +105,7 @@ public final class CaseListener {
int charPositionInLine = ctx.getStart().getCharPositionInLine();
detectCollidingChildUtil(listener, line, charPositionInLine, identifier, CASE_DATA);
if (curData instanceof YangChoice) {
if (curData instanceof YangChoice || curData instanceof YangAugment) {
YangCase caseNode = getYangCaseNode(JAVA_GENERATION);
caseNode.setName(identifier);
YangNode curNode = (YangNode) curData;
......
......@@ -35,14 +35,12 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CONFIG_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DEFAULT_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MANDATORY_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.SHORT_CASE_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.WHEN_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
......@@ -57,7 +55,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds;
import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangChoiceNode;
/*
......@@ -181,7 +178,5 @@ public final class ChoiceListener {
validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, CHOICE_DATA,
ctx.identifier().getText());
validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, CHOICE_DATA, ctx.identifier().getText());
validateMutuallyExclusiveChilds(ctx.shortCaseStatement(), SHORT_CASE_DATA, ctx.caseStatement(), CASE_DATA,
CHOICE_DATA, ctx.identifier().getText());
}
}
......
......@@ -171,8 +171,11 @@ public final class ContainerListener {
try {
yangContainer.validateDataOnExit();
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
CONTAINER_DATA, ctx.identifier().getText(), EXIT, e.getMessage()));
ParserException parserException = new ParserException(constructExtendedListenerErrorMessage(
UNHANDLED_PARSED_DATA, CONTAINER_DATA, ctx.identifier().getText(), EXIT, e.getMessage()));
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
}
listener.getParsedDataStack().pop();
} else {
......
/*
* 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.YangExtension;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangSubModule;
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.datamodel.utils.YangConstructType.EXTENSION_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.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.ListenerUtil.getValidIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
* extension-stmt = extension-keyword sep identifier-arg-str optsep
* (";" /
* "{" stmtsep
* ;; these stmts can appear in any order
* [argument-stmt stmtsep]
* [status-stmt stmtsep]
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
* "}")
*
* ANTLR grammar rule
* extensionStatement : EXTENSION_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE extensionBody RIGHT_CURLY_BRACE);
*/
/**
* Represents listener based call back function corresponding to the "extension"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class ExtensionListener {
/**
* Creates a new extension listener.
*/
private ExtensionListener() {
}
/**
* Performs validation and updates the data model tree. It is called when parser
* receives an input matching the grammar rule (extension).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processExtensionEntry(TreeWalkListener listener,
GeneratedYangParser.ExtensionStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, EXTENSION_DATA, ctx.identifier().getText(), ENTRY);
String identifier = getValidIdentifier(ctx.identifier().getText(), EXTENSION_DATA, ctx);
YangExtension extension = new YangExtension();
extension.setName(identifier);
Parsable curData = listener.getParsedDataStack().peek();
switch (curData.getYangConstructType()) {
case MODULE_DATA:
YangModule module = ((YangModule) curData);
module.addExtension(extension);
break;
case SUB_MODULE_DATA:
YangSubModule subModule = ((YangSubModule) curData);
subModule.addExtension(extension);
break;
default:
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, EXTENSION_DATA,
ctx.identifier().getText(), ENTRY));
}
listener.getParsedDataStack().push(extension);
}
/**
* Performs validation and updates the data model tree. It is called when parser exits
* from grammar rule(extension).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processExtensionExit(TreeWalkListener listener,
GeneratedYangParser.ExtensionStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, EXTENSION_DATA, ctx.identifier().getText(), EXIT);
if (!(listener.getParsedDataStack().peek() instanceof YangExtension)) {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, EXTENSION_DATA,
ctx.identifier().getText(), EXIT));
}
listener.getParsedDataStack().pop();
}
}
......@@ -37,7 +37,6 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRI
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.GROUPING_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPEDEF_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
......@@ -50,7 +49,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds;
import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangGroupingNode;
/*
......@@ -172,7 +170,5 @@ public final class GroupingListener {
validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, GROUPING_DATA,
ctx.identifier().getText());
validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, GROUPING_DATA, ctx.identifier().getText());
validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA,
GROUPING_DATA, ctx.identifier().getText());
}
}
......
......@@ -28,11 +28,9 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.GROUPING_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.NOTIFICATION_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPEDEF_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
......@@ -45,7 +43,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds;
import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangNotificationNode;
/*
......@@ -159,7 +156,5 @@ public final class NotificationListener {
ctx.identifier().getText());
validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, NOTIFICATION_DATA,
ctx.identifier().getText());
validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA,
NOTIFICATION_DATA, ctx.identifier().getText());
}
}
......
......@@ -16,9 +16,9 @@
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
......@@ -28,23 +28,23 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.GROUPING_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.INPUT_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.OUTPUT_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.RPC_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPEDEF_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
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.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
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.ListenerUtil.getValidIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds;
import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangRpcNode;
/*
......@@ -157,8 +157,6 @@ public final class RpcListener {
validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, RPC_DATA, ctx.identifier().getText());
validateCardinalityMaxOne(ctx.inputStatement(), INPUT_DATA, RPC_DATA, ctx.identifier().getText());
validateCardinalityMaxOne(ctx.outputStatement(), OUTPUT_DATA, RPC_DATA, ctx.identifier().getText());
validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA,
RPC_DATA, ctx.identifier().getText());
}
}
......
......@@ -208,29 +208,30 @@ public final class ListenerValidation {
/**
* Checks if a either of one construct occurrence.
*
* @param child1Context first optional child's context
* @param child1Context first optional child's context
* @param yangChild1Construct first child construct for whom cardinality is
* to be validated
* @param child2Context second optional child's context
* @param child2Context second optional child's context
* @param yangChild2Construct second child construct for whom cardinality is
* to be validated
* @param yangParentConstruct parent construct
* @param parentName parent name
* @param parentName parent name
* @param parentContext parents's context
* @throws ParserException exception if cardinality check fails
*/
public static void validateMutuallyExclusiveChilds(List<?> child1Context, YangConstructType yangChild1Construct,
List<?> child2Context, YangConstructType yangChild2Construct,
YangConstructType yangParentConstruct, String parentName)
public static void validateCardinalityEitherOne(List<?> child1Context, YangConstructType yangChild1Construct,
List<?> child2Context, YangConstructType yangChild2Construct,
YangConstructType yangParentConstruct, String parentName,
ParserRuleContext parentContext)
throws ParserException {
if (!child1Context.isEmpty() && !child2Context.isEmpty()) {
ParserException parserException = new ParserException("YANG file error: \""
+ getYangConstructType(yangChild1Construct) + "\" & \"" + getYangConstructType(yangChild2Construct)
+ "\" should be mutually exclusive in \"" + getYangConstructType(yangParentConstruct) + " "
if (child1Context.isEmpty() && child2Context.isEmpty()) {
ParserException parserException = new ParserException("YANG file error: Either \""
+ getYangConstructType(yangChild1Construct) + "\" or \"" + getYangConstructType(yangChild2Construct)
+ "\" should be present in \"" + getYangConstructType(yangParentConstruct) + " "
+ parentName + "\".");
parserException.setLine(((ParserRuleContext) child2Context).getStart().getLine());
parserException.setCharPosition(((ParserRuleContext) child2Context).getStart().getCharPositionInLine());
parserException.setLine(parentContext.getStart().getLine());
parserException.setCharPosition(parentContext.getStart().getCharPositionInLine());
throw parserException;
}
}
......
......@@ -103,6 +103,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE_CARDINALIT
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
......@@ -1688,6 +1689,12 @@ public class TempJavaFragmentFiles {
*/
private void removeAugmentedInfoImport(List<String> imports) {
imports.remove(getJavaImportData().getYangAugmentedInfoImport());
for (JavaQualifiedTypeInfo type : getJavaImportData().getImportSet()) {
if (type.getClassInfo().equals(YANG_AUGMENTED_INFO)) {
getJavaImportData().getImportSet().remove(type);
getJavaExtendsListHolder().getExtendsList().remove(type);
}
}
}
/**
......
......@@ -16,9 +16,10 @@
package org.onosproject.yangutils.parser.impl.listeners;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import java.io.IOException;
import java.util.ListIterator;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangContainer;
......@@ -29,8 +30,8 @@ import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import java.io.IOException;
import java.util.ListIterator;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
/**
* Test cases for case listener.
......@@ -202,4 +203,36 @@ public class CaseListenerTest {
YangLeaf leafInfo2 = leafIterator2.next();
assertThat(leafInfo2.getName(), is("beer"));
}
/**
* Checks case substatement of augment.
*/
@Test
public void processCaseSubStatementOfAugment() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/CaseSubStatementOfAugment.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("event"));
YangAugment augment = ((YangAugment) yangNode.getChild());
assertThat(augment.getName(), is("/snmp:snmp/snmp:engine/snmp:listen/snmp:transport"));
YangCase yangCase = ((YangCase) augment.getChild());
assertThat(yangCase.getName(), is("tls"));
YangCase yangCase1 = ((YangCase) yangCase.getNextSibling());
assertThat(yangCase1.getName(), is("dtls"));
YangContainer container = ((YangContainer) yangCase.getChild());
assertThat(container.getName(), is("tls"));
assertThat(container.getListOfLeaf().iterator().next().getName(), is("ip"));
}
}
......
/*
* 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 org.junit.Test;
import org.onosproject.yangutils.datamodel.YangExtension;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
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 testing extension listener.
*/
public class ExtensionListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks extension statement as sub-statement of module.
*/
@Test
public void processValidExtensionStatement() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ValidExtensionStatement.yang");
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("ietf-yang-compiler-annotation"));
YangExtension extension = yangNode.getExtensionList().iterator().next();
assertThat(extension.getName(), is("compiler-annotation"));
assertThat(extension.getArgumentName(), is("target"));
assertThat(extension.getDescription(), is("\"This extension allows for defining compiler annotations\""));
}
}
......@@ -16,13 +16,19 @@
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.Iterator;
import java.util.ListIterator;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
......@@ -36,10 +42,6 @@ import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import java.io.IOException;
import java.util.Iterator;
import java.util.ListIterator;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
......@@ -779,4 +781,60 @@ public class InterFileLinkingTest {
assertThat(referredNode1.getName(), is("module2"));
assertThat(referredNode1.getPriority(), is(3));
}
/**
* Checks contents of uses are copied as child of grouping.
*/
@Test
public void usesInsideChildOfGrouping()
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/usesInsideChildOfGrouping";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
YangNode selfNode = null;
YangNode refNode1 = null;
for (YangNode rootNode : utilManager.getYangNodeSet()) {
if (rootNode.getName().equals("ietf-network")) {
selfNode = rootNode;
} else if (rootNode.getName().equals("ietf-te-topology")) {
refNode1 = rootNode;
}
}
// Check whether the data model tree returned is of type module.
assertThat(selfNode instanceof YangModule, is(true));
assertThat(selfNode.getNodeType(), is(MODULE_NODE));
YangModule yangNode = (YangModule) selfNode;
assertThat(yangNode.getName(), is("ietf-network"));
YangModule refNode = (YangModule) refNode1;
assertThat(refNode.getName(), is("ietf-te-topology"));
YangAugment augment = ((YangAugment) refNode.getChild().getNextSibling().
getNextSibling().getNextSibling().getNextSibling());
assertThat(augment.getName(), is("/nw:networks/nw:network/nw:node"));
YangUses uses = ((YangUses) augment.getChild());
YangContainer container = ((YangContainer) uses.getNextSibling());
assertThat(container.getName(), is("te"));
container = ((YangContainer) container.getChild());
assertThat(container.getName(), is("config"));
uses = ((YangUses) container.getChild().getNextSibling());
assertThat(uses.getName(), is("te-node-config-attributes"));
YangContainer container1 = ((YangContainer) uses.getNextSibling());
assertThat(container1.getName(), is("te-node-attributes"));
uses = ((YangUses) container1.getChild());
assertThat(uses.getName(), is("te-node-connectivity-matrix"));
YangList list = ((YangList) uses.getNextSibling());
assertThat(list.getName(), is("connectivity-matrix"));
}
}
......
module event {
namespace "http://example.com/event";
prefix "ev";
augment /snmp:snmp/snmp:engine/snmp:listen/snmp:transport {
if-feature tlstm;
case tls {
container tls {
description
"A list of IPv4 and IPv6 addresses and ports to which the
engine listens for SNMP messages over TLS.";
leaf ip {
type inet:ip-address;
mandatory true;
description
"The IPv4 or IPv6 address on which the engine listens
for SNMP messages over TLS.";
}
leaf port {
type inet:port-number;
description
"The TCP port on which the engine listens for SNMP
messages over TLS.
If the port is not configured, an engine that
acts as a Command Responder uses port 10161, and
an engine that acts as a Notification Receiver
uses port 10162.";
}
}
}
case dtls {
container dtls1 {
description
"A list of IPv4 and IPv6 addresses and ports to which the
engine listens for SNMP messages over DTLS.";
leaf ip {
type inet:ip-address;
mandatory true;
description
"The IPv4 or IPv6 address on which the engine listens
for SNMP messages over DTLS.";
}
leaf port {
type inet:port-number;
description
"The UDP port on which the engine listens for SNMP
messages over DTLS.
If the port is not configured, an engine that
acts as a Command Responder uses port 10161, and
an engine that acts as a Notification Receiver
uses port 10162.";
}
}
}
}
}
module ietf-yang-compiler-annotation {
namespace "urn:ietf:params:xml:ns:yang:ietf-yang-compiler-annotation";
prefix "ca";
organization
"IETF NETMOD (NETCONF Data Modeling Language) Working Group";
contact
"WG Web: <http://tools.ietf.org/wg/netmod/>
WG List: <mailto:netmod@ietf.org>";
description
"This YANG module defines an extension statement that allows for
defining compiler annotations.
The key words 'MUST', 'MUST NOT', 'REQUIRED', 'SHALL', 'SHALL
NOT', 'SHOULD', 'SHOULD NOT', 'RECOMMENDED', 'MAY', and
'OPTIONAL' in the module text are to be interpreted as described
in RFC 2119 (http://tools.ietf.org/html/rfc2119).";
revision 2016-07-08 {
description
"Initial revision.";
reference
"draft-agv-netmod-yang-compiler-metadata:
Defining and Using compiler annotations with YANG";
}
extension compiler-annotation {
argument target;
description "This extension allows for defining compiler annotations";
} // compiler-annotation
} //module agv-yang-compiler-annotation
module ietf-network {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-network";
prefix nd;
revision 2015-12-08 {
description
"Initial revision.
NOTE TO RFC EDITOR: Please replace the following reference
to draft-ietf-i2rs-yang-network-topo-02 with
RFC number when published (i.e. RFC xxxx).";
}
container networks {
list network {
key "network-id";
leaf network-id {
type string;
}
list node {
key "node-id";
leaf node-id {
type string;
}
}
}
}
}
module ietf-te-topology {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-te-topology";
prefix "tet";
import ietf-network {
prefix "nw";
}
revision "2016-03-17" {
description "Initial revision";
}
grouping te-node-augment {
container te {
presence "TE support.";
leaf te-node-id {
type string;
mandatory true;
}
container config {
uses te-node-config;
} // config
} // te
} // te-node-augment
grouping te-node-config {
leaf-list te-node-template {
if-feature template;
type string;
}
uses te-node-config-attributes;
} // te-node-config
grouping te-node-config-attributes {
container te-node-attributes {
leaf admin-status {
type string;
}
uses te-node-connectivity-matrix;
} // te-node-attributes
} // te-node-config-attributes
grouping te-node-connectivity-matrix {
list connectivity-matrix {
key "id";
leaf id {
type uint32;
description "Identifies the connectivity-matrix entry.";
}
}
} // te-node-connectivity-matrix
augment "/nw:networks/nw:network/nw:node" {
uses te-node-augment;
}
}