From 277461c62786e8b88a60aaa3f195f0a852b87f30 Mon Sep 17 00:00:00 2001 From: Peter Kajsa Date: Thu, 20 Aug 2015 12:51:25 +0200 Subject: [PATCH] Bug 3670 (part 3/5): Use of new statement parser in yang-maven-plugin (original header: Yangtools changes-fixes necessary for parser switch in Controller) Parser fixes: - bug4136 fix - enhanced javadoc comments - mapped effective build implementation and test - Module source and sourcePath implementation and test - EffectiveSchemaContext IdentifierToSources implementation and test - EffectiveSchemaContext resolveSchemaContext from modules implementation - Bug3799 test - Antlr4 identifier vs. string fix sal-dom-broker fix - QName parsing for unknown nodes - QName prefix parsing for unknown nodes from augmentation - uses nodes reusing - uses nodes reusing skip on top level - uses nodes dont copy description and reference of grouping to target node (TODO? add other not to copy) Change-Id: Iab104439f9b03977850c4d05b9ab933382919a09 Signed-off-by: Peter Kajsa --- .../yang/model/api/stmt/UnknownStatement.java | 3 +- .../src/main/antlr/YangStatementLexer.g4 | 2 +- .../api/AugmentationSchemaBuilder.java | 8 +- .../yang/parser/builder/api/Builder.java | 4 +- .../builder/api/ConstraintsBuilder.java | 2 +- .../builder/api/DataNodeContainerBuilder.java | 9 +- .../builder/api/DataSchemaNodeBuilder.java | 2 +- .../builder/api/DocumentedNodeBuilder.java | 6 +- .../parser/builder/api/GroupingMember.java | 2 +- .../parser/builder/api/SchemaNodeBuilder.java | 2 +- .../builder/api/TypeDefinitionBuilder.java | 2 + .../parser/builder/api/UsesNodeBuilder.java | 4 +- .../parser/builder/impl/BuilderUtils.java | 4 +- .../builder/impl/ModuleIdentifierImpl.java | 25 +- .../yang/parser/impl/YangParserImpl.java | 2 + .../parser/impl/YangParserListenerImpl.java | 8 +- .../impl/YangStatementParserListenerImpl.java | 4 +- .../impl/util/URLSchemaContextResolver.java | 2 + .../parser/repo/URLSchemaContextResolver.java | 1 + .../parser/spi/meta/ModelActionBuilder.java | 2 + .../parser/spi/meta/NamespaceBehaviour.java | 27 +- .../yang/parser/spi/meta/StmtContext.java | 2 + .../spi/source/DeclarationInTextSource.java | 44 +- .../reactor/CrossSourceStatementReactor.java | 35 +- .../NamespaceBehaviourWithListeners.java | 27 +- .../stmt/reactor/NamespaceStorageSupport.java | 34 +- .../stmt/reactor/RootStatementContext.java | 4 +- .../stmt/reactor/StatementContextBase.java | 19 +- .../stmt/rfc6020/AugmentStatementImpl.java | 1 - .../parser/stmt/rfc6020/AugmentUtils.java | 29 +- .../parser/stmt/rfc6020/GroupingUtils.java | 41 +- .../rfc6020/ImportStatementDefinition.java | 2 +- .../stmt/rfc6020/ModuleStatementSupport.java | 20 +- .../stmt/rfc6020/SubmoduleStatementImpl.java | 12 +- .../stmt/rfc6020/UnknownStatementImpl.java | 22 +- .../yang/parser/stmt/rfc6020/Utils.java | 74 ++- .../effective/EffectiveSchemaContext.java | 52 +- .../ModuleEffectiveStatementImpl.java | 7 +- .../UnknownEffectiveStatementImpl.java | 23 +- .../yang/parser/util/ASTSchemaSource.java | 1 + .../parser/util/ModuleDependencySort.java | 2 + .../yang/parser/util/TopologicalSort.java | 1 + .../build/test/MappedEffectiveBuildTest.java | 42 ++ .../stmt/retest/AugmentToExtensionTest.java | 6 +- .../yangtools/yang/stmt/test/Bug3799Test.java | 57 ++ .../stmt/test/ControllerStmtParserTest.java | 179 ++++++ .../yang/stmt/test/ModuleSourceTest.java | 57 ++ .../yang/stmt/test/MoreRevisionsTest.java | 252 +++++++- .../yang/stmt/test/StmtTestUtils.java | 18 +- .../resources/bugs/bug3799/test_module.yang | 25 + .../bugs/bug3799/test_submodule.yang | 25 + .../src/test/resources/mapped-build/bar.yang | 10 + .../src/test/resources/mapped-build/foo.yang | 10 + .../test/resources/mapped-build/sub-bar.yang | 9 + .../test/resources/mapped-build/sub-foo.yang | 9 + .../module-source/simple-module.yang | 4 + .../resources/sal-broker-impl/config.yang | 179 ++++++ .../sal-broker-impl/ietf-yang-types.yang | 396 ++++++++++++ .../opendaylight-config-dom-datastore.yang | 21 + .../opendaylight-dom-broker-impl.yang | 218 +++++++ .../opendaylight-md-sal-common.yang | 70 +++ .../opendaylight-md-sal-dom.yang | 30 + ...pendaylight-operational-dom-datastore.yang | 22 + .../opendaylight-pingpong-broker.yang | 39 ++ .../sal-broker-impl/rpc-context.yang | 32 + .../full/ietf-inet-types.yang | 418 ++++++++++++ .../full/ietf-interfaces.yang | 469 ++++++++++++++ .../full/ietf-netconf-monitoring.yang | 593 ++++++++++++++++++ .../full/ietf-yang-types.yang | 396 ++++++++++++ .../full/ietf-yang-types@2013-05-16.yang | 471 ++++++++++++++ .../full/ietf-yang-types@2013-07-15.yang | 467 ++++++++++++++ .../importedtestrev@2015-05-02.yang | 4 +- .../importedtestrev@2015-06-02.yang | 4 +- .../importedtestrev@2015-08-02.yang | 4 +- .../importedtestrev@2015-09-02.yang | 4 +- ....yang => importedtestrev@z2015-04-02.yang} | 8 +- .../simple/ietf-interfaces.yang | 13 + .../simple/ietf-netconf-monitoring.yang | 15 + .../simple/ietf-yang-types.yang | 14 + .../simple/ietf-yang-types@2013-05-16.yang | 16 + .../simple/ietf-yang-types@2013-07-15.yang | 16 + .../multiple-revisions/testrev.yang | 10 +- 82 files changed, 4991 insertions(+), 214 deletions(-) create mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/MappedEffectiveBuildTest.java create mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug3799Test.java create mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ControllerStmtParserTest.java create mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ModuleSourceTest.java create mode 100644 yang/yang-parser-impl/src/test/resources/bugs/bug3799/test_module.yang create mode 100644 yang/yang-parser-impl/src/test/resources/bugs/bug3799/test_submodule.yang create mode 100644 yang/yang-parser-impl/src/test/resources/mapped-build/bar.yang create mode 100644 yang/yang-parser-impl/src/test/resources/mapped-build/foo.yang create mode 100644 yang/yang-parser-impl/src/test/resources/mapped-build/sub-bar.yang create mode 100644 yang/yang-parser-impl/src/test/resources/mapped-build/sub-foo.yang create mode 100644 yang/yang-parser-impl/src/test/resources/module-source/simple-module.yang create mode 100644 yang/yang-parser-impl/src/test/resources/sal-broker-impl/config.yang create mode 100644 yang/yang-parser-impl/src/test/resources/sal-broker-impl/ietf-yang-types.yang create mode 100644 yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-config-dom-datastore.yang create mode 100644 yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-dom-broker-impl.yang create mode 100644 yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-md-sal-common.yang create mode 100644 yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-md-sal-dom.yang create mode 100644 yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-operational-dom-datastore.yang create mode 100644 yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-pingpong-broker.yang create mode 100644 yang/yang-parser-impl/src/test/resources/sal-broker-impl/rpc-context.yang create mode 100644 yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-inet-types.yang create mode 100644 yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-interfaces.yang create mode 100644 yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-netconf-monitoring.yang create mode 100644 yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-yang-types.yang create mode 100644 yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-yang-types@2013-05-16.yang create mode 100644 yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-yang-types@2013-07-15.yang rename yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/{importedtestrev.yang => importedtestrev@z2015-04-02.yang} (67%) create mode 100644 yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-interfaces.yang create mode 100644 yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-netconf-monitoring.yang create mode 100644 yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-yang-types.yang create mode 100644 yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-yang-types@2013-05-16.yang create mode 100644 yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-yang-types@2013-07-15.yang diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/UnknownStatement.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/UnknownStatement.java index 9ec4d1c779..e057cf7aff 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/UnknownStatement.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/UnknownStatement.java @@ -12,5 +12,6 @@ import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement; public interface UnknownStatement extends DeclaredStatement { - @Nullable String getArgument(); + @Nullable S getArgument(); + } diff --git a/yang/yang-parser-impl/src/main/antlr/YangStatementLexer.g4 b/yang/yang-parser-impl/src/main/antlr/YangStatementLexer.g4 index b5fc095a4c..b717fbc8c5 100644 --- a/yang/yang-parser-impl/src/main/antlr/YangStatementLexer.g4 +++ b/yang/yang-parser-impl/src/main/antlr/YangStatementLexer.g4 @@ -39,7 +39,7 @@ fragment ESC : '\\' (["\\/bfnrt] | UNICODE); fragment UNICODE : 'u' HEX HEX HEX HEX; fragment HEX : [0-9a-fA-F] ; -STRING : ((~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '"' | '\'' | ':' | '/' | '=' | '[' | ']' | '+' )~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | ':' | '/' | '=' | '[' | ']')* ) | SUB_STRING ); +STRING : ((~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '"' | '\'' | '/' | '=' | '[' | ']' | '+' )~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '/' | '=' | '[' | ']')* ) | SUB_STRING ); mode BLOCK_COMMENT_MODE; END_BLOCK_COMMENT : '*/' -> popMode, skip; diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/AugmentationSchemaBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/AugmentationSchemaBuilder.java index a3eab72ba1..58beef0e87 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/AugmentationSchemaBuilder.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/AugmentationSchemaBuilder.java @@ -36,7 +36,7 @@ public interface AugmentationSchemaBuilder extends DataNodeContainerBuilder,Docu * for a particular instance, then the node defined by the parent data * definition statement is valid; otherwise, it is not. * - * @param whenCondition + * @param whenCondition string representation of when condition */ void addWhenCondition(String whenCondition); @@ -72,7 +72,7 @@ public interface AugmentationSchemaBuilder extends DataNodeContainerBuilder,Docu /** * Set information about augmentation process. * - * @param resolved + * @param resolved information about augmentation process */ void setResolved(boolean resolved); @@ -88,12 +88,16 @@ public interface AugmentationSchemaBuilder extends DataNodeContainerBuilder,Docu /** * Set true if target of augment is unsupported (e.g. node in body of extension). * In such case, augmentation is skipped and AugmentationSchema is not built. + * + * @param unsupportedTarget information about target of augment statement */ void setUnsupportedTarget(boolean unsupportedTarget); /** * Return true if target of augment is unsupported (e.g. node in body of extension). * In such case, augmentation is skipped and AugmentationSchema is not built. + * + * @return information about target of augment statement */ boolean isUnsupportedTarget(); } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/Builder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/Builder.java index 5270396c57..b208c8a314 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/Builder.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/Builder.java @@ -26,7 +26,7 @@ public interface Builder extends Mutable { /** * Set name of module in which this node is declared. * - * @param moduleName + * @param moduleName name of module * @deprecated Module name should be set during creation of builder. */ @Deprecated @@ -62,7 +62,7 @@ public interface Builder extends Mutable { * method, this builder is also built and unknown node is added * as child to the product of this builder. * - * @param unknownNode + * @param unknownNode an unknown node builder */ void addUnknownNodeBuilder(UnknownSchemaNodeBuilder unknownNode); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/ConstraintsBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/ConstraintsBuilder.java index c03406d9f7..b15966294e 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/ConstraintsBuilder.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/ConstraintsBuilder.java @@ -113,7 +113,7 @@ public interface ConstraintsBuilder extends Builder { /** * Sets mandatory status of parent node * - * @param mandatory + * @param mandatory mandatory status */ void setMandatory(boolean mandatory); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/DataNodeContainerBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/DataNodeContainerBuilder.java index d7367acab3..f72afed490 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/DataNodeContainerBuilder.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/DataNodeContainerBuilder.java @@ -61,14 +61,15 @@ public interface DataNodeContainerBuilder extends Builder { /** * Add builder of child node to this node. * - * @param childNode + * @param childNode name of child node to add */ void addChildNode(DataSchemaNodeBuilder childNode); /** * Add builder of child node to this node at specified position. * - * @param childNode + * @param index position at which the child node will be added + * @param childNode name of child node to add at specified position */ void addChildNode(int index, DataSchemaNodeBuilder childNode); @@ -93,7 +94,7 @@ public interface DataNodeContainerBuilder extends Builder { /** * Add builder of grouping statement to this node. * - * @param groupingBuilder + * @param groupingBuilder grouping statement builder */ void addGrouping(GroupingBuilder groupingBuilder); @@ -107,7 +108,7 @@ public interface DataNodeContainerBuilder extends Builder { /** * Add builder of uses statement to this node. * - * @param usesBuilder + * @param usesBuilder uses statement builder */ void addUsesNode(UsesNodeBuilder usesBuilder); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/DataSchemaNodeBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/DataSchemaNodeBuilder.java index 8d86c1d3b9..fe230e898f 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/DataSchemaNodeBuilder.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/DataSchemaNodeBuilder.java @@ -42,7 +42,7 @@ public interface DataSchemaNodeBuilder extends SchemaNodeBuilder, GroupingMember /** * Set if the product of the builder node is introduced by augmentation. * - * @param augmenting + * @param augmenting information about augmentation */ void setAugmenting(boolean augmenting); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/DocumentedNodeBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/DocumentedNodeBuilder.java index 4ff4fb87ee..72a3c510ed 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/DocumentedNodeBuilder.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/DocumentedNodeBuilder.java @@ -26,7 +26,7 @@ public interface DocumentedNodeBuilder { /** * Set description to this node. * - * @param description + * @param description description of this node */ void setDescription(String description); @@ -40,7 +40,7 @@ public interface DocumentedNodeBuilder { /** * Set reference to this node. * - * @param reference + * @param reference reference to this node */ void setReference(String reference); @@ -54,7 +54,7 @@ public interface DocumentedNodeBuilder { /** * Set status to this node. * - * @param status + * @param status status of this node */ void setStatus(Status status); } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/GroupingMember.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/GroupingMember.java index 3e2eea30e3..b6137fd036 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/GroupingMember.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/GroupingMember.java @@ -22,7 +22,7 @@ public interface GroupingMember extends Builder { /** * Set if this node is added by uses. * - * @param addedByUses + * @param addedByUses information about uses statement */ void setAddedByUses(boolean addedByUses); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/SchemaNodeBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/SchemaNodeBuilder.java index 2c9fe3aa1b..f81813c454 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/SchemaNodeBuilder.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/SchemaNodeBuilder.java @@ -33,7 +33,7 @@ public interface SchemaNodeBuilder extends DocumentedNodeBuilder, Builder { /** * Updates schema path to resulting {@link SchemaNode}. * - * @param path + * @param path schema path */ void setPath(SchemaPath path); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/TypeDefinitionBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/TypeDefinitionBuilder.java index 6ca496b8ad..dff64b38cc 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/TypeDefinitionBuilder.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/TypeDefinitionBuilder.java @@ -89,6 +89,8 @@ public interface TypeDefinitionBuilder extends TypeAwareBuilder, SchemaNodeBuild /** * Sets fractions digits of resulting type if it is derived from * decimal built-in type. + * + * @param fractionDigits fraction digits */ void setFractionDigits(Integer fractionDigits); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/UsesNodeBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/UsesNodeBuilder.java index 268ca0cd2a..5b17b1a9df 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/UsesNodeBuilder.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/UsesNodeBuilder.java @@ -81,7 +81,7 @@ public interface UsesNodeBuilder extends GroupingMember { /** * Set information if this uses node is defined in augment. * - * @param augmenting + * @param augmenting information about augmentation */ void setAugmenting(boolean augmenting); @@ -155,6 +155,8 @@ public interface UsesNodeBuilder extends GroupingMember { * * @deprecated Do not use this, this should be internal to the implementation * and public API contract. + * + * @param resolved resolved */ @Deprecated void setResolved(boolean resolved); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/BuilderUtils.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/BuilderUtils.java index e98553e800..9bf130e884 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/BuilderUtils.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/BuilderUtils.java @@ -343,7 +343,7 @@ public final class BuilderUtils { /** * Set addedByUses flag to true for node and all its child nodes. * - * @param node + * @param node grouping member node */ public static void setNodeAddedByUses(final GroupingMember node) { node.setAddedByUses(true); @@ -693,7 +693,7 @@ public final class BuilderUtils { /** * Get module in which this node is defined. * - * @param node + * @param node node * @return builder of module where this node is defined */ public static ModuleBuilder getParentModule(final Builder node) { diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java index 6e825dd666..5a32774036 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java @@ -9,8 +9,6 @@ package org.opendaylight.yangtools.yang.parser.builder.impl; import static com.google.common.base.Preconditions.checkNotNull; -import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; - import com.google.common.base.Optional; import java.net.URI; import java.util.Date; @@ -79,29 +77,8 @@ public class ModuleIdentifierImpl implements ModuleIdentifier { if (getNamespace() != null && !getNamespace().equals(that.getNamespace())) { return false; } - - Date defaultRev = SimpleDateFormatUtil.DEFAULT_DATE_REV; - Date defaultImp = SimpleDateFormatUtil.DEFAULT_DATE_IMP; - - // if revision is in import only, spec says that it is undefined which - // revision to take - if (getRevision() == defaultImp ^ that.getRevision() == defaultImp) { - return true; - } - - // default and none revisions taken as equal - if ((defaultRev.equals(getRevision()) && that.getRevision() == null) - || (defaultRev.equals(that.getRevision()) && getRevision() == null)) { - return true; - } - - // else if none of them is default and one null - if (getRevision() == null ^ that.getRevision() == null) { - return false; - } - // only fail if this revision is non-null - if (getRevision() != null && that.getRevision() != null && !getRevision().equals(that.getRevision())) { + if (getRevision() != null && !getRevision().equals(that.getRevision())) { return false; } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserImpl.java index d41a2f4ea3..25abb54e83 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserImpl.java @@ -666,6 +666,8 @@ public final class YangParserImpl implements YangContextParser { * Mini parser: This parsing context does not validate full YANG module, * only parses header up to the revisions and imports. * + * @param yangStream input stream containing a yang module + * @return new instance of YangContext * @see org.opendaylight.yangtools.yang.parser.impl.util.YangModelDependencyInfo */ public static YangContext parseStreamWithoutErrorListeners(final InputStream yangStream) { diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserListenerImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserListenerImpl.java index 1e71e4d2c5..0a3c7fe6ef 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserListenerImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserListenerImpl.java @@ -138,10 +138,10 @@ public final class YangParserListenerImpl extends YangParserBaseListener { * the "BaseListener" aspect, which need not be exposed to the user. Maybe * factor out a base class into repo.spi? * - * @param namespaceContext - * @param sourcePath - * @param walker - * @param tree + * @param namespaceContext namespaceContext + * @param sourcePath sourcePath + * @param walker walker + * @param tree tree * @return new instance of YangParserListenerImpl */ public static YangParserListenerImpl create(final Map> namespaceContext, diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangStatementParserListenerImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangStatementParserListenerImpl.java index 526f9d1adc..da76c3aec9 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangStatementParserListenerImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangStatementParserListenerImpl.java @@ -57,7 +57,7 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList @Override public void enterStatement(YangStatementParser.StatementContext ctx) { - final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, ctx + final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, ctx.getText(), ctx .getStart().getLine(), ctx.getStart().getCharPositionInLine()); boolean action = true; QName identifier; @@ -112,7 +112,7 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList @Override public void exitStatement(YangStatementParser.StatementContext ctx) { - final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, ctx.getStart().getLine(), ctx + final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, ctx.getText(), ctx.getStart().getLine(), ctx .getStart().getCharPositionInLine()); for (int i = 0; i < ctx.getChildCount(); i++) { ParseTree child = ctx.getChild(i); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/URLSchemaContextResolver.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/URLSchemaContextResolver.java index 91c5c18028..440df89299 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/URLSchemaContextResolver.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/URLSchemaContextResolver.java @@ -54,6 +54,8 @@ public class URLSchemaContextResolver implements AdvancedSchemaSourceProvider registerSource(final URL source) { checkArgument(source != null, "Supplied source must not be null"); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/URLSchemaContextResolver.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/URLSchemaContextResolver.java index 97d0c64c51..deb13e1f99 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/URLSchemaContextResolver.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/URLSchemaContextResolver.java @@ -83,6 +83,7 @@ public class URLSchemaContextResolver implements AutoCloseable, SchemaSourceProv * @throws YangSyntaxErrorException When the YANG file is syntactically invalid * @throws IOException when the URL is not readable * @throws SchemaSourceException When parsing encounters general error + * @return new instance of AbstractURLRegistration if the URL is not null */ public URLRegistration registerSource(final URL url) throws SchemaSourceException, IOException, YangSyntaxErrorException { checkArgument(url != null, "Supplied URL must not be null"); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/ModelActionBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/ModelActionBuilder.java index a16e36a306..41d22500e4 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/ModelActionBuilder.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/ModelActionBuilder.java @@ -129,6 +129,8 @@ public interface ModelActionBuilder { * @throws InferenceException If inference action can not be processed. * Note that this exception be used for user to debug YANG sources, * so should provide helpful context to fix issue in sources. + * + * @param failed collection of prerequisites which were not met */ void prerequisiteFailed(Collection> failed) throws InferenceException; } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java index 1d996d97e1..735bcb9ae0 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java @@ -73,6 +73,10 @@ public abstract class NamespaceBehaviour type parameter + * @param type parameter + * @param type parameter + * * @return global namespace behaviour for supplied namespace type. */ public static @Nonnull > NamespaceBehaviour global( @@ -89,6 +93,10 @@ public abstract class NamespaceBehaviour type parameter + * @param type parameter + * @param type parameter + * * @return source-local namespace behaviour for supplied namespace type. */ public static > NamespaceBehaviour sourceLocal( @@ -104,7 +112,11 @@ public abstract class NamespaceBehaviour type parameter + * @param type parameter + * @param type parameter + * * @return tree-scoped namespace behaviour for supplied namespace type. */ public static > NamespaceBehaviour treeScoped(Class identifier) { @@ -113,16 +125,29 @@ public abstract class NamespaceBehaviour getAllFrom(NamespaceStorageNode storage); /** * adds key and value to corresponding namespace storage according to param class + * + * @param storage namespace storage + * @param key type parameter + * @param value type parameter */ public abstract void addTo(NamespaceStorageNode storage, K key, V value); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java index 46cdb16628..ee6007ee29 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java @@ -64,6 +64,8 @@ public interface StmtContext, E extends Effect Collection> effectiveSubstatements(); + Collection> substatements(); + D buildDeclared(); E buildEffective(); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/DeclarationInTextSource.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/DeclarationInTextSource.java index b782618065..6ff73908b9 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/DeclarationInTextSource.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/DeclarationInTextSource.java @@ -20,12 +20,12 @@ import org.opendaylight.yangtools.yang.model.api.meta.StatementSource; * * To create source reference use one of this static factories: *
    - *
  • {@link #atPosition(String, int, int)} - provides most specific reference of statement location, + *
  • {@link #atPosition(String, String, int, int)} - provides most specific reference of statement location, * this is most prefered since it provides most context to debug YANG model. *
  • - *
  • {@link #atLine(String, int)}- provides source and line of statement location. + *
  • {@link #atLine(String, String, int)}- provides source and line of statement location. *
  • - *
  • {@link #inSource(String)} - least specific reference, should be used only if any of previous + *
  • {@link #inSource(String, String)} - least specific reference, should be used only if any of previous * references are unable to create / derive from source. *
  • *
@@ -33,14 +33,20 @@ import org.opendaylight.yangtools.yang.model.api.meta.StatementSource; */ public abstract class DeclarationInTextSource implements StatementSourceReference { - private final String source; + private final String sourceText; + private final String sourceName; - DeclarationInTextSource(String source) { - this.source = source; + DeclarationInTextSource(String sourceName, String sourceText) { + this.sourceName = sourceName; + this.sourceText = sourceText; } public String getSourceName() { - return source; + return sourceName; + } + + public String getSourceText() { + return sourceText; } @Override @@ -51,22 +57,22 @@ public abstract class DeclarationInTextSource implements StatementSourceReferenc @Override public abstract String toString(); - public static final DeclarationInTextSource inSource(String sourceName) { - return new InSource(sourceName); + public static final DeclarationInTextSource inSource(String sourceName, String sourceText) { + return new InSource(sourceName, sourceText); } - public static final DeclarationInTextSource atLine(String sourceName, int line) { - return new AtLine(sourceName,line); + public static final DeclarationInTextSource atLine(String sourceName, String sourceText, int line) { + return new AtLine(sourceName, sourceText, line); } - public static final DeclarationInTextSource atPosition(String sourceName, int line, int position) { - return new AtPosition(sourceName,line,position); + public static final DeclarationInTextSource atPosition(String sourceName, String sourceText, int line, int position) { + return new AtPosition(sourceName, sourceText, line,position); } private static class InSource extends DeclarationInTextSource { - public InSource(String source) { - super(source); + public InSource(String sourceName, String sourceText) { + super(sourceName, sourceText); } @Override @@ -80,8 +86,8 @@ public abstract class DeclarationInTextSource implements StatementSourceReferenc private final int line; - public AtLine(String source,int line) { - super(source); + public AtLine(String sourceName, String sourceText, int line) { + super(sourceName, sourceText); this.line = line; } @@ -97,8 +103,8 @@ public abstract class DeclarationInTextSource implements StatementSourceReferenc private int line; private int character; - public AtPosition(String source, int line, int character) { - super(source); + public AtPosition(String sourceName, String sourceText, int line, int character) { + super(sourceName, sourceText); this.line = line; this.character = character; } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java index fc3b31222e..3b8b11007f 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java @@ -7,8 +7,15 @@ */ package org.opendaylight.yangtools.yang.parser.stmt.reactor; +import java.util.Set; + +import java.io.FileNotFoundException; +import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; +import java.util.HashMap; +import java.util.Collections; +import org.opendaylight.yangtools.yang.model.api.Module; +import java.io.File; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; - import org.opendaylight.yangtools.yang.model.api.SchemaContext; import java.io.InputStream; import java.util.List; @@ -107,7 +114,31 @@ public class CrossSourceStatementReactor { return buildEffective(); } - } + public Map buildEffectiveMappedToSource( + List yangFiles) throws SourceException, ReactorException, + FileNotFoundException { + + if (yangFiles == null || yangFiles.isEmpty()) { + return Collections.emptyMap(); + } + + Map pathToFile = new HashMap<>(); + Map sourceFileToModule = new HashMap<>(); + for (File yangFile : yangFiles) { + addSource(new YangStatementSourceImpl(new NamedFileInputStream( + yangFile, yangFile.getPath()))); + pathToFile.put(yangFile.getPath(), yangFile); + } + + EffectiveSchemaContext schema = buildEffective(); + Set modules = schema.getModules(); + for (Module module : modules) { + sourceFileToModule.put( + pathToFile.get(module.getModuleSourcePath()), module); + } + return sourceFileToModule; + } + } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceBehaviourWithListeners.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceBehaviourWithListeners.java index b05594466d..14f3300c84 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceBehaviourWithListeners.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceBehaviourWithListeners.java @@ -7,11 +7,16 @@ */ package org.opendaylight.yangtools.yang.parser.stmt.reactor; +import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; + +import com.google.common.base.Optional; +import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl; +import java.util.Collection; +import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import java.util.Iterator; import java.util.Map; - import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour; @@ -50,6 +55,26 @@ final class NamespaceBehaviourWithListeners defaultImportListeners = getDefaultImportListeners((ModuleIdentifier) key); + Iterator defaultImportsIterator = defaultImportListeners.iterator(); + while(defaultImportsIterator.hasNext()) { + ValueAddedListener listener = defaultImportsIterator.next(); + if(listener.ctxNode == storage || hasIdentiticalValue(listener.ctxNode,key,value)) { + defaultImportsIterator.remove(); + listener.onValueAdded(key, value); + } + } + } + } + + private Collection getDefaultImportListeners( + ModuleIdentifier key) { + ModuleIdentifier defaultImportKey = new ModuleIdentifierImpl( + key.getName(), Optional.fromNullable(key.getNamespace()), + Optional.of(SimpleDateFormatUtil.DEFAULT_DATE_IMP)); + return listeners.get((K)defaultImportKey); } private boolean hasIdentiticalValue(NamespaceBehaviour.NamespaceStorageNode ctxNode, K key, V value) { diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java index 65dc89ab70..27914951ba 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java @@ -7,6 +7,11 @@ */ package org.opendaylight.yangtools.yang.parser.stmt.reactor; +import java.util.Map.Entry; + +import java.util.Set; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils; +import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; import java.util.HashMap; import java.util.Map; import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; @@ -60,13 +65,38 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode { getBehaviourRegistry().getNamespaceBehaviour((Class)type).addTo(this, key, value); } + @SuppressWarnings("unchecked") @Override public > V getFromLocalStorage(Class type, K key) { - @SuppressWarnings("unchecked") Map localNamespace = (Map) namespaces.get(type); + + V potential = null; if(localNamespace != null) { - return localNamespace.get(key); + potential = localNamespace.get(key); + } + + if(potential == null && Utils.isModuleIdentifierWithoutSpecifiedRevision(key)) { + potential = getRegardlessOfRevision((ModuleIdentifier)key,(Map)localNamespace); + } + + return potential; + } + + private > V getRegardlessOfRevision(ModuleIdentifier key, + Map localNamespace) { + + if(localNamespace == null) { + return null; } + + Set> entrySet = localNamespace.entrySet(); + for (Entry entry : entrySet) { + ModuleIdentifier moduleIdentifierInMap = entry.getKey(); + if(moduleIdentifierInMap.getName().equals(key.getName())) { + return entry.getValue(); + } + } + return null; } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java index 8108cd810e..03ce9c8c5f 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java @@ -120,7 +120,7 @@ public class RootStatementContext, E extends E /** * @return copy of this considering {@link TypeOfCopy} (augment, uses) * - * @throws SourceException + * @throws SourceException instance of SourceException */ @Override public StatementContextBase createCopy(StatementContextBase newParent, TypeOfCopy typeOfCopy) @@ -131,7 +131,7 @@ public class RootStatementContext, E extends E /** * @return copy of this considering {@link TypeOfCopy} (augment, uses) * - * @throws SourceException + * @throws SourceException instance of SourceException */ @Override public StatementContextBase createCopy(QNameModule newQNameModule, diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java index 83356ed615..cd42c25b2d 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java @@ -234,6 +234,14 @@ public abstract class StatementContextBase, E return Collections.unmodifiableCollection(declared); } + /** + * @return collection of substatements + */ + @Override + public Collection> substatements() { + return Collections.unmodifiableCollection(substatements.values()); + } + /** * @return collection of effective substatements */ @@ -263,6 +271,8 @@ public abstract class StatementContextBase, E * if added in declared phase * @throws NullPointerException * if statement parameter is null + * + * @param substatement substatement */ public void addEffectiveSubstatement(StatementContextBase substatement) { @@ -282,6 +292,8 @@ public abstract class StatementContextBase, E * if added in effective phase * @throws NullPointerException * if statement parameter is null + * + * @param substatement substatement */ public void addDeclaredSubstatement(StatementContextBase substatement) { @@ -295,6 +307,11 @@ public abstract class StatementContextBase, E /** * builds new substatement from statement definition context and statement source reference + * + * @param def definition context + * @param ref source reference + * + * @return instance of ContextBuilder */ @SuppressWarnings({ "rawtypes", "unchecked" }) public ContextBuilder substatementBuilder(StatementDefinitionContext def, @@ -451,7 +468,7 @@ public abstract class StatementContextBase, E /** * occurs when an item is added to model namespace * - * @throws SourceException + * @throws SourceException instance of SourceException */ @Override protected > void onNamespaceElementAdded(Class type, K key, V value) { diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.java index b79f75709e..9e39f9009f 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.java @@ -87,7 +87,6 @@ public class AugmentStatementImpl extends @Override public void apply() throws InferenceException { - final StatementContextBase augmentTargetCtx = AugmentUtils .getAugmentTargetCtx(augmentNode); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentUtils.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentUtils.java index 5a92e31c6e..9076c6873b 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentUtils.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentUtils.java @@ -277,22 +277,19 @@ public final class AugmentUtils { if (substatementArgument instanceof QName) { substatementQName = (QName) substatementArgument; - if (isSupportedAugmentTarget(substatement) - && nextPathQName.getLocalName().equals(substatementQName.getLocalName())) { - return substatement; - } - } // augment to extension - else if (StmtContextUtils.producesDeclared(substatement, UnknownStatementImpl.class) - && substatementArgument instanceof String) { - - final String nextPathName = nextPathQName.getLocalName(); - - if (nextPathName.equals(substatementArgument) - || nextPathName.equals(substatement.getPublicDefinition().getStatementName().getLocalName())) { - String message = "Module '" + substatement.getRoot().getStatementArgument() - + "': augment into extension '" + substatementArgument + "'."; - LOG.warn(message); - return substatement; + if (nextPathQName.getLocalName().equals( + substatementQName.getLocalName())) { + if (isSupportedAugmentTarget(substatement)) { + return substatement; + } else if (Utils.isUnknownNode(substatement)) { + // augment into unknown node + String message = "Module '" + + substatement.getRoot().getStatementArgument() + + "': augment into unknown node '" + + substatementArgument + "'."; + LOG.warn(message); + return substatement; + } } } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/GroupingUtils.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/GroupingUtils.java index e6f496b0a4..83a3746965 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/GroupingUtils.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/GroupingUtils.java @@ -12,7 +12,6 @@ import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName; import org.opendaylight.yangtools.yang.parser.stmt.reactor.RootStatementContext; import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType; import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace; -import java.util.Iterator; import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy; import java.util.Collection; @@ -37,9 +36,10 @@ public final class GroupingUtils { } /** - * @param sourceGrpStmtCtx - * @param targetCtx - * @throws SourceException + * @param sourceGrpStmtCtx source grouping statement context + * @param targetCtx target context + * @param usesNode uses node + * @throws SourceException instance of SourceException */ public static void copyFromSourceToTarget( StatementContextBase sourceGrpStmtCtx, @@ -69,7 +69,7 @@ public final class GroupingUtils { TypeOfCopy.ADDED_BY_USES); targetCtx.addEffectiveSubstatement(copy); usesNode.addAsEffectOfStatement(copy); - } else if (isReusedByUses(originalStmtCtx)) { + } else if (isReusedByUsesOnTop(originalStmtCtx)) { targetCtx.addEffectiveSubstatement(originalStmtCtx); usesNode.addAsEffectOfStatement(originalStmtCtx); } @@ -90,7 +90,7 @@ public final class GroupingUtils { TypeOfCopy.ADDED_BY_USES); targetCtx.addEffectiveSubstatement(copy); usesNode.addAsEffectOfStatement(copy); - } else if (isReusedByUses(originalStmtCtx)) { + } else if (isReusedByUsesOnTop(originalStmtCtx)) { targetCtx.addEffectiveSubstatement(originalStmtCtx); usesNode.addAsEffectOfStatement(originalStmtCtx); } @@ -120,14 +120,7 @@ public final class GroupingUtils { QName targetQName = (QName) targetStmtArgument; QNameModule targetQNameModule = targetQName.getModule(); - QName sourceQName = (QName) sourceStmtArgument; - QNameModule sourceQNameModule = sourceQName.getModule(); - - if (targetQNameModule.equals(sourceQNameModule)) { - return null; - } else { - return targetQNameModule; - } + return targetQNameModule; } else { return null; } @@ -148,12 +141,30 @@ public final class GroupingUtils { noCopyDefSet.add(Rfc6020Mapping.TYPEDEF); noCopyDefSet.add(Rfc6020Mapping.TYPE); + final Set noCopyFromGroupingSet = new HashSet<>(); + noCopyFromGroupingSet.add(Rfc6020Mapping.DESCRIPTION); + noCopyFromGroupingSet.add(Rfc6020Mapping.REFERENCE); + StatementDefinition def = stmtContext.getPublicDefinition(); - return !noCopyDefSet.contains(def); + boolean dontCopyFromParentGrouping = noCopyFromGroupingSet.contains(def) && stmtContext.getParentContext() + .getPublicDefinition().equals(Rfc6020Mapping.GROUPING); + + return !noCopyDefSet.contains(def) && !dontCopyFromParentGrouping; } public static boolean isReusedByUses(StmtContext stmtContext) { + Set reusedDefSet = new HashSet<>(); + reusedDefSet.add(Rfc6020Mapping.TYPEDEF); + reusedDefSet.add(Rfc6020Mapping.TYPE); + reusedDefSet.add(Rfc6020Mapping.USES); + + StatementDefinition def = stmtContext.getPublicDefinition(); + return reusedDefSet.contains(def); + } + + public static boolean isReusedByUsesOnTop(StmtContext stmtContext) { + Set reusedDefSet = new HashSet<>(); reusedDefSet.add(Rfc6020Mapping.TYPEDEF); reusedDefSet.add(Rfc6020Mapping.TYPE); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ImportStatementDefinition.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ImportStatementDefinition.java index 05b7431690..8d3c0cc8ac 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ImportStatementDefinition.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ImportStatementDefinition.java @@ -145,7 +145,7 @@ public class ImportStatementDefinition }); } - private static ModuleIdentifier getImportedModuleIdentifier( + private ModuleIdentifier getImportedModuleIdentifier( Mutable stmt) throws SourceException { String moduleName = stmt.getStatementArgument(); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ModuleStatementSupport.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ModuleStatementSupport.java index 2dd4cb0d40..bd7175879b 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ModuleStatementSupport.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ModuleStatementSupport.java @@ -22,7 +22,6 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement; import org.opendaylight.yangtools.yang.model.api.stmt.NamespaceStatement; import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement; -import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement; import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl; import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace; import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule; @@ -74,7 +73,7 @@ public class ModuleStatementSupport extends + "] is missing."); } - Optional revisionDate = Optional.fromNullable(getLatestRevision(stmt.declaredSubstatements())); + Optional revisionDate = Optional.fromNullable(Utils.getLatestRevision(stmt.declaredSubstatements())); if (!revisionDate.isPresent()) { revisionDate = Optional.of(SimpleDateFormatUtil.DEFAULT_DATE_REV); } @@ -108,21 +107,4 @@ public class ModuleStatementSupport extends stmt.addContext(NamespaceToModule.class, qNameModule, stmt); } - - private static Date getLatestRevision(Iterable> subStmts) { - Date revision = null; - for (StmtContext subStmt : subStmts) { - if (subStmt.getPublicDefinition().getDeclaredRepresentationClass().isAssignableFrom(RevisionStatement - .class)) { - if (revision == null && subStmt.getStatementArgument() != null) { - revision = (Date) subStmt.getStatementArgument(); - } else if (subStmt.getStatementArgument() != null && ((Date) subStmt.getStatementArgument()).compareTo - (revision) > 0) { - revision = (Date) subStmt.getStatementArgument(); - } - } - } - return revision; - } - } \ No newline at end of file diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SubmoduleStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SubmoduleStatementImpl.java index 9a3b134615..803b5e48e0 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SubmoduleStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SubmoduleStatementImpl.java @@ -9,6 +9,9 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020; import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.findFirstDeclaredSubstatement; import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf; + +import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; + import java.net.URI; import java.util.Date; import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; @@ -16,7 +19,6 @@ import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement; import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement; -import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement; import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement; import org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement; import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl; @@ -67,10 +69,10 @@ public class SubmoduleStatementImpl extends Mutable> stmt) throws SourceException { - Optional revisionDate = Optional - .fromNullable(firstAttributeOf( - stmt.declaredSubstatements(), - RevisionStatement.class)); + Optional revisionDate = Optional.fromNullable(Utils.getLatestRevision(stmt.declaredSubstatements())); + if (!revisionDate.isPresent()) { + revisionDate = Optional.of(SimpleDateFormatUtil.DEFAULT_DATE_REV); + } ModuleIdentifier submoduleIdentifier = new ModuleIdentifierImpl( stmt.getStatementArgument(), Optional. absent(), diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UnknownStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UnknownStatementImpl.java index f3aa9357af..60db0b3bc0 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UnknownStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UnknownStatementImpl.java @@ -7,6 +7,8 @@ */ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020; +import org.opendaylight.yangtools.yang.common.QName; + import javax.annotation.Nullable; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition; @@ -17,40 +19,40 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnknownEffectiveStatementImpl; -public class UnknownStatementImpl extends AbstractDeclaredStatement implements UnknownStatement { +public class UnknownStatementImpl extends AbstractDeclaredStatement implements UnknownStatement { - protected UnknownStatementImpl(final StmtContext context) { + protected UnknownStatementImpl(final StmtContext context) { super(context); } public static class Definition extends - AbstractStatementSupport, EffectiveStatement>> { + AbstractStatementSupport, EffectiveStatement>> { public Definition(final StatementDefinition publicDefinition) { super(publicDefinition); } @Override - public String parseArgumentValue(final StmtContext ctx, final String value) throws SourceException { - return value == null ? "" : value; + public QName parseArgumentValue(final StmtContext ctx, final String value) throws SourceException { + return Utils.qNameFromArgument(ctx, value); } @Override - public UnknownStatement createDeclared(final StmtContext, ?> ctx) { + public UnknownStatement createDeclared(final StmtContext, ?> ctx) { return new UnknownStatementImpl(ctx); } @Override - public EffectiveStatement> createEffective( - final StmtContext, EffectiveStatement>> ctx) { + public EffectiveStatement> createEffective( + final StmtContext, EffectiveStatement>> ctx) { return new UnknownEffectiveStatementImpl(ctx); } } @Nullable @Override - public String getArgument() { - return rawArgument(); + public QName getArgument() { + return argument(); } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java index 2f4c55be38..9d0fe34126 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java @@ -9,10 +9,14 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020; import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf; +import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement; + +import org.opendaylight.yangtools.yang.parser.stmt.reactor.RootStatementContext; +import java.util.Date; +import org.opendaylight.yangtools.yang.model.api.stmt.RefineStatement; import com.google.common.base.CharMatcher; import com.google.common.base.Splitter; import com.google.common.collect.Iterables; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -22,19 +26,16 @@ import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; - import javax.annotation.Nullable; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; - import org.antlr.v4.runtime.tree.TerminalNode; import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; import org.opendaylight.yangtools.yang.common.YangConstants; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.Deviation; import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; import org.opendaylight.yangtools.yang.model.api.SchemaPath; @@ -48,7 +49,6 @@ import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Relat import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement; import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils; import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName; import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier; @@ -69,8 +69,6 @@ public final class Utils { private static final CharMatcher DOUBLE_QUOTE_MATCHER = CharMatcher.is('"'); private static final CharMatcher SINGLE_QUOTE_MATCHER = CharMatcher.is('\''); - public static final QName EMPTY_QNAME = QName.create("empty", "empty"); - private static final char SEPARATOR_NODENAME = '/'; private static final String REGEX_PATH_ABS = "/[^/].*"; @@ -222,7 +220,7 @@ public final class Utils { public static QName qNameFromArgument(StmtContext ctx, String value) { if (value == null || value.equals("")) { - return EMPTY_QNAME; + return ctx.getPublicDefinition().getStatementName(); } String prefix; @@ -235,7 +233,7 @@ public final class Utils { localName = namesParts[0]; qNameModule = getRootModuleQName(ctx); break; - case 2: + default: prefix = namesParts[0]; localName = namesParts[1]; qNameModule = getModuleQNameByPrefix(ctx, prefix); @@ -252,20 +250,11 @@ public final class Utils { qNameModule = getModuleQNameByPrefix(ctx, prefix); } break; - default: - break; } if (qNameModule == null) { - if (StmtContextUtils.producesDeclared(ctx, UnknownStatementImpl.class) - && StmtContextUtils.producesDeclared(ctx.getParentContext(), UnknownStatementImpl.class)) { - - qNameModule = getRootModuleQName(ctx); - localName = value; - } else { - throw new IllegalArgumentException("Error in module '" + ctx.getRoot().rawStatementArgument() - + "': can not resolve QNameModule for '" + value + "'."); - } + throw new IllegalArgumentException("Error in module '" + ctx.getRoot().rawStatementArgument() + + "': can not resolve QNameModule for '" + value + "'."); } QNameModule resultQNameModule = qNameModule.getRevision() == null ? QNameModule.create( @@ -298,7 +287,7 @@ public final class Utils { if (StmtContextUtils.producesDeclared(rootCtx, ModuleStatement.class)) { qNameModule = rootCtx.getFromNamespace(ModuleCtxToModuleQName.class, rootCtx); } else if (StmtContextUtils.producesDeclared(rootCtx, SubmoduleStatement.class)) { - String belongsToModuleName = firstAttributeOf(ctx.getRoot().declaredSubstatements(), + String belongsToModuleName = firstAttributeOf(rootCtx.substatements(), BelongsToStatement.class); qNameModule = rootCtx.getFromNamespace(ModuleNameToModuleQName.class, belongsToModuleName); } @@ -383,13 +372,17 @@ public final class Utils { } qNamesFromRoot.add(qname); } else if (nextStmtArgument instanceof String) { - QName qName = qNameFromArgument(ctx, ((String) nextStmtArgument)); + StatementContextBase originalCtx = ctx + .getOriginalCtx(); + final QName qName = (originalCtx != null) ? qNameFromArgument( + originalCtx, (String) nextStmtArgument) + : qNameFromArgument(ctx, (String) nextStmtArgument); qNamesFromRoot.add(qName); - } else if (StmtContextUtils.producesDeclared(nextStmtCtx, AugmentStatement.class) + } else if ((StmtContextUtils.producesDeclared(nextStmtCtx, AugmentStatement.class) + || StmtContextUtils.producesDeclared(nextStmtCtx, RefineStatement.class)) && nextStmtArgument instanceof SchemaNodeIdentifier) { addQNamesFromSchemaNodeIdentifierToList(qNamesFromRoot, (SchemaNodeIdentifier) nextStmtArgument); - } else if (nextStmtCtx.getPublicDefinition().getDeclaredRepresentationClass() - .isAssignableFrom(UnknownStatementImpl.class)) { + } else if (isUnknownNode(nextStmtCtx)) { qNamesFromRoot.add(nextStmtCtx.getPublicDefinition().getStatementName()); } else { return SchemaPath.SAME; @@ -400,6 +393,11 @@ public final class Utils { return schemaPath; } + public static boolean isUnknownNode(StmtContext stmtCtx) { + return stmtCtx.getPublicDefinition().getDeclaredRepresentationClass() + .isAssignableFrom(UnknownStatementImpl.class); + } + private static boolean isSupportedAsShorthandCase(StmtContext statementCtx) { Collection supportedCaseShorthands = statementCtx.getFromNamespace(ValidationBundlesNamespace.class, @@ -456,4 +454,30 @@ public final class Utils { public static SchemaPath SchemaNodeIdentifierToSchemaPath(SchemaNodeIdentifier identifier) { return SchemaPath.create(identifier.getPathFromRoot(), identifier.isAbsolute()); } + + public static Date getLatestRevision(RootStatementContext root) { + return getLatestRevision(root.declaredSubstatements()); + } + + public static Date getLatestRevision(Iterable> subStmts) { + Date revision = null; + for (StmtContext subStmt : subStmts) { + if (subStmt.getPublicDefinition().getDeclaredRepresentationClass().isAssignableFrom(RevisionStatement + .class)) { + if (revision == null && subStmt.getStatementArgument() != null) { + revision = (Date) subStmt.getStatementArgument(); + } else if (subStmt.getStatementArgument() != null && ((Date) subStmt.getStatementArgument()).compareTo + (revision) > 0) { + revision = (Date) subStmt.getStatementArgument(); + } + } + } + return revision; + } + + public static boolean isModuleIdentifierWithoutSpecifiedRevision(Object o) { + return (o instanceof ModuleIdentifier) + && (((ModuleIdentifier) o).getRevision() == SimpleDateFormatUtil.DEFAULT_DATE_IMP || + ((ModuleIdentifier) o).getRevision() == SimpleDateFormatUtil.DEFAULT_BELONGS_TO_DATE); + } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveSchemaContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveSchemaContext.java index 2f885e788b..031d4cb879 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveSchemaContext.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveSchemaContext.java @@ -7,8 +7,12 @@ */ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective; -import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort; +import java.util.HashMap; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import com.google.common.collect.ImmutableMap; +import java.util.LinkedHashMap; +import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort; import java.util.HashSet; import com.google.common.collect.ImmutableList; import java.util.List; @@ -60,18 +64,60 @@ public class EffectiveSchemaContext extends AbstractEffectiveSchemaContext { new TreeMap>(), MODULE_SET_SUPPLIER); final SetMultimap nameMap = Multimaps.newSetMultimap( new TreeMap>(), MODULE_SET_SUPPLIER); + final Map isMap = new LinkedHashMap<>(); for (Module m : modulesInit) { nameMap.put(m.getName(), m); nsMap.put(m.getNamespace(), m); + isMap.put(m, m.getSource()); + } + + namespaceToModules = ImmutableSetMultimap.copyOf(nsMap); + nameToModules = ImmutableSetMultimap.copyOf(nameMap); + identifiersToSources = ImmutableMap.copyOf(isMap); + + } + + public EffectiveSchemaContext(final Set modules, final Map identifiersToSources) { + this.identifiersToSources = ImmutableMap.copyOf(identifiersToSources); + + /* + * Instead of doing this on each invocation of getModules(), pre-compute + * it once and keep it around -- better than the set we got in. + */ + this.modules = ImmutableSet.copyOf(ModuleDependencySort.sort(modules.toArray(new Module[modules.size()]))); + + /* + * The most common lookup is from Namespace->Module. + * + * RESTCONF performs lookups based on module name only, where it wants + * to receive the latest revision + * + * Invest some quality time in building up lookup tables for both. + */ + final SetMultimap nsMap = Multimaps.newSetMultimap( + new TreeMap>(), MODULE_SET_SUPPLIER); + final SetMultimap nameMap = Multimaps.newSetMultimap( + new TreeMap>(), MODULE_SET_SUPPLIER); + + for (Module m : modules) { + nameMap.put(m.getName(), m); + nsMap.put(m.getNamespace(), m); } namespaceToModules = ImmutableSetMultimap.copyOf(nsMap); nameToModules = ImmutableSetMultimap.copyOf(nameMap); - // :TODO init identifiersToSources - this.identifiersToSources = null; + rootDeclaredStatements = null; + rootEffectiveStatements = null; + } + public static SchemaContext resolveSchemaContext(final Set modules) { + Map identifiersToSources = new HashMap<>(); + for (Module module : modules) { + identifiersToSources.put(module, module.getSource()); + } + return new EffectiveSchemaContext(modules, identifiersToSources); } public ImmutableList> getRootDeclaredStatements() { diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ModuleEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ModuleEffectiveStatementImpl.java index 95f6a15c8d..ebbac6d177 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ModuleEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ModuleEffectiveStatementImpl.java @@ -118,10 +118,9 @@ public class ModuleEffectiveStatementImpl extends yangVersion = "1"; } - sourcePath = ((DeclarationInTextSource) ctx - .getStatementSourceReference()).getSourceName(); - // TODO source - // source = + DeclarationInTextSource sourceReference = (DeclarationInTextSource) ctx.getStatementSourceReference(); + sourcePath = sourceReference.getSourceName(); + source = sourceReference.getSourceText(); initSubmodules(ctx); initSubstatementCollections(ctx); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnknownEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnknownEffectiveStatementImpl.java index 220b5d8305..f6ab150de4 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnknownEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnknownEffectiveStatementImpl.java @@ -23,7 +23,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils; -public class UnknownEffectiveStatementImpl extends EffectiveStatementBase> implements +public class UnknownEffectiveStatementImpl extends EffectiveStatementBase> implements UnknownSchemaNode { private boolean augmenting; @@ -40,33 +40,24 @@ public class UnknownEffectiveStatementImpl extends EffectiveStatementBase, ?> ctx) { + public UnknownEffectiveStatementImpl(final StmtContext, ?> ctx) { super(ctx); final StmtContext> extensionInit = ctx .getAllFromNamespace(ExtensionNamespace.class).get(ctx.getPublicDefinition().getStatementName()); + if (extensionInit == null) { extension = null; nodeType = ctx.getPublicDefinition().getArgumentName(); - - if (argument() == null || argument().isEmpty()) { - qName = nodeType; - } else { - qName = QName.create(Utils.qNameFromArgument(ctx, ctx.getStatementArgument()).getModule(), argument()); - } } else { extension = (ExtensionEffectiveStatementImpl) extensionInit.buildEffective(); nodeType = extension.getQName(); - - if (argument() == null || argument().isEmpty()) { - qName = extension.getQName(); - } else { - qName = QName.create(Utils.qNameFromArgument(ctx, ctx.getStatementArgument()).getModule(), argument()); - } } + qName = ctx.getStatementArgument(); path = Utils.getSchemaPath(ctx); - nodeParameter = argument(); + + nodeParameter = (ctx.rawStatementArgument() == null) ? "" : ctx.rawStatementArgument(); // TODO init other fields (see Bug1412Test) @@ -85,7 +76,7 @@ public class UnknownEffectiveStatementImpl extends EffectiveStatementBase, ?> ctx) { + private void initCopyType(final StmtContext, ?> ctx) { List copyTypesFromOriginal = ctx.getCopyHistory(); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ASTSchemaSource.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ASTSchemaSource.java index 3f78eed6c5..ab57ab74f9 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ASTSchemaSource.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ASTSchemaSource.java @@ -91,6 +91,7 @@ public final class ASTSchemaSource implements SchemaSourceRepresentation { * * @param name YANG source name. Used only for error reporting. * @param tree ANTLR abstract syntax tree + * @param text YANG text source * @return A new representation instance. * @throws YangSyntaxErrorException if we fail to extract dependency information. * diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ModuleDependencySort.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ModuleDependencySort.java index 03979a1a47..15a0cb36d4 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ModuleDependencySort.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ModuleDependencySort.java @@ -80,6 +80,7 @@ public final class ModuleDependencySort { /** * Topological sort of module builder dependency graph. * + * @param builders builders of Module object * @return Sorted list of Module builders. Modules can be further processed * in returned order. */ @@ -118,6 +119,7 @@ public final class ModuleDependencySort { /** * Topological sort of module dependency graph. * + * @param modules YANG modules * @return Sorted list of Modules. Modules can be further processed in * returned order. */ diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TopologicalSort.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TopologicalSort.java index 7d3ba2aee4..e227972ee9 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TopologicalSort.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TopologicalSort.java @@ -27,6 +27,7 @@ public final class TopologicalSort { /** * Topological sort of dependent nodes in acyclic graphs. * + * @param nodes graph nodes * @return Sorted {@link List} of {@link Node}s. Order: Nodes with no * dependencies starting. * @throws IllegalStateException diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/MappedEffectiveBuildTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/MappedEffectiveBuildTest.java new file mode 100644 index 0000000000..ced700c974 --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/MappedEffectiveBuildTest.java @@ -0,0 +1,42 @@ +package org.opendaylight.yangtools.yang.stmt.effective.build.test; + +import static org.junit.Assert.assertEquals; +import java.io.FileNotFoundException; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; +import java.util.Map.Entry; +import java.util.Set; +import java.util.Map; +import org.opendaylight.yangtools.yang.model.api.Module; +import java.util.List; +import java.util.Arrays; +import java.net.URISyntaxException; +import java.io.File; +import org.junit.Test; + +public class MappedEffectiveBuildTest { + + @Test + public void mappedBuildTest() throws URISyntaxException, SourceException, + FileNotFoundException, ReactorException { + File sourceDir = new File(getClass().getResource("/mapped-build/") + .toURI()); + List yangFiles = Arrays.asList(sourceDir.listFiles()); + + assertEquals(4, yangFiles.size()); + + BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); + Map parseYangModelsMapped = reactor + .buildEffectiveMappedToSource(yangFiles); + + assertEquals(2, parseYangModelsMapped.size()); + + Set> mapEntrySet = parseYangModelsMapped.entrySet(); + for (Entry entry : mapEntrySet) { + assertEquals(entry.getKey().getPath(), entry.getValue() + .getModuleSourcePath()); + } + } +} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentToExtensionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentToExtensionTest.java index 644514beb7..511a4be5b9 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentToExtensionTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentToExtensionTest.java @@ -3,9 +3,10 @@ */ package org.opendaylight.yangtools.yang.stmt.retest; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; + import org.opendaylight.yangtools.yang.stmt.test.StmtTestUtils; + import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException; import java.net.URISyntaxException; import java.util.Set; @@ -33,7 +34,8 @@ public class AugmentToExtensionTest { modules = TestUtils.loadModules(getClass().getResource( "/augment-to-extension-test/correct-path-into-unsupported-target").toURI()); } catch (Exception e) { - StmtTestUtils.log(e, " "); + StmtTestUtils.log(e, " "); + throw e; } Module devicesModule = TestUtils.findModule(modules, "augment-module"); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug3799Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug3799Test.java new file mode 100644 index 0000000000..aa948710ba --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug3799Test.java @@ -0,0 +1,57 @@ +package org.opendaylight.yangtools.yang.stmt.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; +import java.util.Collection; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; +import java.util.Set; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import java.io.IOException; +import java.net.URISyntaxException; +import org.junit.Test; + +public class Bug3799Test { + + @Test + public void test() throws IOException, URISyntaxException, SourceException, + ReactorException { + SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug3799"); + assertNotNull(schema); + + Set modules = schema.getModules(); + assertNotNull(modules); + assertEquals(1, modules.size()); + + Module testModule = modules.iterator().next(); + Set subModules = testModule.getSubmodules(); + assertNotNull(subModules); + assertEquals(1, subModules.size()); + + Module testSubmodule = subModules.iterator().next(); + + Set notifications = testSubmodule + .getNotifications(); + assertNotNull(notifications); + assertEquals(1, notifications.size()); + + NotificationDefinition bazNotification = notifications.iterator() + .next(); + Collection childNodes = bazNotification.getChildNodes(); + assertNotNull(childNodes); + assertEquals(1, childNodes.size()); + + DataSchemaNode child = childNodes.iterator().next(); + assertTrue(child instanceof LeafSchemaNode); + + LeafSchemaNode leafBar = (LeafSchemaNode) child; + String bar = leafBar.getQName().getLocalName(); + assertEquals("bar", bar); + } + +} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ControllerStmtParserTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ControllerStmtParserTest.java new file mode 100644 index 0000000000..e9e7eb1763 --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ControllerStmtParserTest.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.yangtools.yang.stmt.test; + +import static org.junit.Assert.*; + +import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; + +import org.opendaylight.yangtools.yang.model.api.UsesNode; +import java.net.URI; +import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; +import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; +import java.util.List; +import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; +import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; +import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import java.util.Set; +import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; +import java.text.ParseException; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import java.io.FileNotFoundException; +import java.net.URISyntaxException; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.junit.Test; + +public class ControllerStmtParserTest { + + @Test + public void test() throws SourceException, FileNotFoundException, + ReactorException, URISyntaxException, ParseException { + SchemaContext context = StmtTestUtils + .parseYangSources("/sal-broker-impl"); + assertNotNull(context); + + salDomBrokerImplModuleTest(context); + configModuleTest(context); + } + + private void salDomBrokerImplModuleTest(SchemaContext context) + throws ParseException { + Module module = context.findModuleByName( + "opendaylight-sal-dom-broker-impl", SimpleDateFormatUtil + .getRevisionFormat().parse("2013-10-28")); + assertNotNull(module); + + Set augmentations = module.getAugmentations(); + boolean checked = false; + for (AugmentationSchema augmentationSchema : augmentations) { + DataSchemaNode dataNode = augmentationSchema + .getDataChildByName("dom-broker-impl"); + if (dataNode instanceof ChoiceCaseNode) { + ChoiceCaseNode caseNode = (ChoiceCaseNode) dataNode; + DataSchemaNode dataNode2 = caseNode + .getDataChildByName("async-data-broker"); + if (dataNode2 instanceof ContainerSchemaNode) { + ContainerSchemaNode containerNode = (ContainerSchemaNode) dataNode2; + DataSchemaNode leaf = containerNode + .getDataChildByName("type"); + List unknownSchemaNodes = leaf + .getUnknownSchemaNodes(); + assertEquals(1, unknownSchemaNodes.size()); + + UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes + .get(0); + assertEquals("dom-async-data-broker", unknownSchemaNode + .getQName().getLocalName()); + assertEquals(unknownSchemaNode.getQName(), + unknownSchemaNode.getPath().getLastComponent()); + + checked = true; + } + } + } + assertTrue(checked); + } + + private void configModuleTest(SchemaContext context) throws ParseException, + URISyntaxException { + Module configModule = context.findModuleByName("config", + SimpleDateFormatUtil.getRevisionFormat().parse("2013-04-05")); + assertNotNull(configModule); + + DataSchemaNode dataNode = configModule.getDataChildByName("modules"); + assertTrue(dataNode instanceof ContainerSchemaNode); + + ContainerSchemaNode moduleContainer = (ContainerSchemaNode) dataNode; + DataSchemaNode dataChildList = moduleContainer + .getDataChildByName("module"); + + assertTrue(dataChildList instanceof ListSchemaNode); + + ListSchemaNode listModule = (ListSchemaNode) dataChildList; + DataSchemaNode dataChildChoice = listModule + .getDataChildByName("configuration"); + + assertTrue(dataChildChoice instanceof ChoiceSchemaNode); + + ChoiceSchemaNode confChoice = (ChoiceSchemaNode) dataChildChoice; + ChoiceCaseNode caseNodeByName = confChoice + .getCaseNodeByName("dom-broker-impl"); + + assertNotNull(caseNodeByName); + DataSchemaNode dataNode2 = caseNodeByName + .getDataChildByName("async-data-broker"); + assertTrue(dataNode2 instanceof ContainerSchemaNode); + + ContainerSchemaNode containerNode = (ContainerSchemaNode) dataNode2; + DataSchemaNode leaf = containerNode.getDataChildByName("type"); + List unknownSchemaNodes = leaf + .getUnknownSchemaNodes(); + + assertEquals(1, unknownSchemaNodes.size()); + + UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.get(0); + + assertEquals(unknownSchemaNode.getQName(), unknownSchemaNode.getPath() + .getLastComponent()); + assertEquals("dom-async-data-broker", unknownSchemaNode.getQName() + .getLocalName()); + + ChoiceCaseNode domInmemoryDataBroker = confChoice + .getCaseNodeByName("dom-inmemory-data-broker"); + + assertNotNull(domInmemoryDataBroker); + DataSchemaNode schemaService = domInmemoryDataBroker + .getDataChildByName("schema-service"); + assertTrue(schemaService instanceof ContainerSchemaNode); + + ContainerSchemaNode schemaServiceContainer = (ContainerSchemaNode) schemaService; + + assertEquals(1, schemaServiceContainer.getUses().size()); + UsesNode uses = schemaServiceContainer.getUses().iterator().next(); + QName groupingQName = QName.create("urn:opendaylight:params:xml:ns:yang:controller:config","2013-04-05","service-ref"); + QName usesGroupingPathLastComponent = uses.getGroupingPath().getLastComponent(); + assertEquals(groupingQName, usesGroupingPathLastComponent); + assertEquals(0, getChildNodeSizeWithoutUses(schemaServiceContainer)); + + DataSchemaNode type = schemaServiceContainer.getDataChildByName("type"); + List typeUnknownSchemaNodes = type + .getUnknownSchemaNodes(); + + assertEquals(1, typeUnknownSchemaNodes.size()); + + UnknownSchemaNode typeUnknownSchemaNode = typeUnknownSchemaNodes.get(0); + + QNameModule qNameModule = QNameModule + .create(new URI( + "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:impl"), + SimpleDateFormatUtil.getRevisionFormat().parse( + "2013-10-28")); + QName qName = QName.create(qNameModule, "schema-service"); + + assertEquals(qName, typeUnknownSchemaNode.getQName()); + assertEquals(typeUnknownSchemaNode.getQName(), typeUnknownSchemaNode + .getPath().getLastComponent()); + } + + private int getChildNodeSizeWithoutUses(final DataNodeContainer csn) { + int result = 0; + for (DataSchemaNode dsn : csn.getChildNodes()) { + if (dsn.isAddedByUses() == false) { + result++; + } + } + return result; + } + +} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ModuleSourceTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ModuleSourceTest.java new file mode 100644 index 0000000000..b18a258650 --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/ModuleSourceTest.java @@ -0,0 +1,57 @@ +package org.opendaylight.yangtools.yang.stmt.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + +import java.io.FileReader; +import java.io.BufferedReader; +import java.io.File; +import java.util.Set; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import java.net.URISyntaxException; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.junit.Test; + +public class ModuleSourceTest { + + @Test + public void test() throws SourceException, ReactorException, URISyntaxException, IOException { + SchemaContext schema = StmtTestUtils.parseYangSources("/module-source"); + + assertNotNull(schema); + + Set modules = schema.getModules(); + assertNotNull(modules); + assertEquals(1,modules.size()); + + Module simpleModule = modules.iterator().next(); + String source = simpleModule.getSource(); + String moduleSourcePath = simpleModule.getModuleSourcePath(); + + File simpleYang = new File(getClass().getResource("/module-source/simple-module.yang").toURI()); + + assertEquals(simpleYang.getPath(), moduleSourcePath); + assertEquals(readFile(moduleSourcePath), source); + } + + private String readFile(String fileName) throws IOException { + BufferedReader br = new BufferedReader(new FileReader(fileName)); + try { + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + + while (line != null) { + sb.append(line); + sb.append(System.lineSeparator()); + line = br.readLine(); + } + return sb.toString(); + } finally { + br.close(); + } + } +} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/MoreRevisionsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/MoreRevisionsTest.java index b46e65ebbf..0fbec5b9fc 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/MoreRevisionsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/MoreRevisionsTest.java @@ -10,10 +10,19 @@ package org.opendaylight.yangtools.yang.stmt.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import org.opendaylight.yangtools.yang.model.api.ModuleImport; +import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.TypeDefinition; +import java.text.ParseException; +import java.util.Date; +import org.opendaylight.yangtools.yang.common.QName; +import java.net.URI; +import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; import java.io.FileNotFoundException; import java.net.URISyntaxException; - import org.opendaylight.yangtools.yang.model.api.SchemaContext; import java.util.Set; import org.junit.Test; @@ -125,11 +134,250 @@ public class MoreRevisionsTest { @Test public void multipleRevisionsTest() throws SourceException, ReactorException, FileNotFoundException, URISyntaxException { - for (int i = 0; i < 25; i++) { + for (int i = 0; i < 100; i++) { SchemaContext context = StmtTestUtils .parseYangSources("/semantic-statement-parser/multiple-revisions"); assertNotNull(context); } } + @Test + public void multipleRevisionsFullTest() throws SourceException, + ReactorException, FileNotFoundException, URISyntaxException, + ParseException { + for (int i = 0; i < 100; i++) { + SchemaContext context = StmtTestUtils + .parseYangSources("/semantic-statement-parser/multiple-revisions/full"); + assertNotNull(context); + assertEquals(6, context.getModules().size()); + checkContentFullTest(context); + } + } + + private void checkContentFullTest(SchemaContext context) throws ParseException, + URISyntaxException { + + String yangTypesNSStr = "urn:ietf:params:xml:ns:yang:ietf-yang-types"; + URI yangTypesNS = new URI(yangTypesNSStr); + + Date rev20100924 = SimpleDateFormatUtil.getRevisionFormat().parse( + "2010-09-24"); + Date rev20130516 = SimpleDateFormatUtil.getRevisionFormat().parse( + "2013-05-16"); + Date rev20130715 = SimpleDateFormatUtil.getRevisionFormat().parse( + "2013-07-15"); + + final QNameModule yangTypes_20100924 = QNameModule.create(yangTypesNS, + rev20100924); + final QNameModule yangTypes_20130516 = QNameModule.create(yangTypesNS, + rev20130516); + final QNameModule yangTypes_20130715 = QNameModule.create(yangTypesNS, + rev20130715); + + final QName dateTimeTypeDef_20100924 = QName.create(yangTypes_20100924, + "date-and-time"); + final QName dateTimeTypeDef_20130516 = QName.create(yangTypes_20130516, + "date-and-time"); + final QName dateTimeTypeDef_20130715 = QName.create(yangTypes_20130715, + "date-and-time"); + + Module yangTypesModule_20100924 = context.findModuleByName( + "ietf-yang-types", rev20100924); + Module yangTypesModule_20130516 = context.findModuleByName( + "ietf-yang-types", rev20130516); + Module yangTypesModule_20130715 = context.findModuleByName( + "ietf-yang-types", rev20130715); + + assertNotNull(yangTypesModule_20100924); + assertNotNull(yangTypesModule_20130516); + assertNotNull(yangTypesModule_20130715); + + assertTrue(findTypeDef(yangTypesModule_20100924, + dateTimeTypeDef_20100924)); + assertTrue(findTypeDef(yangTypesModule_20130516, + dateTimeTypeDef_20130516)); + assertTrue(findTypeDef(yangTypesModule_20130715, + dateTimeTypeDef_20130715)); + + checkNetconfMonitoringModuleFullTest(context, rev20130715, + dateTimeTypeDef_20130715); + + checkInterfacesModuleFullTest(context, rev20100924, dateTimeTypeDef_20100924); + + } + + private void checkInterfacesModuleFullTest(SchemaContext context, Date rev20100924, + final QName dateTimeTypeDef_20100924) throws URISyntaxException, + ParseException { + Date rev20121115 = SimpleDateFormatUtil.getRevisionFormat().parse( + "2012-11-15"); + + Module interfacesModule_20121115 = context.findModuleByName( + "ietf-interfaces", rev20121115); + assertNotNull(interfacesModule_20121115); + + Set imports = interfacesModule_20121115.getImports(); + assertEquals(1, imports.size()); + ModuleImport interfacesImport = imports.iterator().next(); + assertEquals("ietf-yang-types", interfacesImport.getModuleName()); + assertEquals(rev20100924, interfacesImport.getRevision()); + } + + private void checkNetconfMonitoringModuleFullTest(SchemaContext context, + Date rev20130715, final QName dateTimeTypeDef_20130715) + throws ParseException, URISyntaxException { + Date rev20101004 = SimpleDateFormatUtil.getRevisionFormat().parse( + "2010-10-04"); + + Module monitoringModule_20101004 = context.findModuleByName( + "ietf-netconf-monitoring", rev20101004); + assertNotNull(monitoringModule_20101004); + + Set imports = monitoringModule_20101004.getImports(); + assertEquals(2, imports.size()); + for (ModuleImport monitoringImport : imports) { + if (monitoringImport.getModuleName().equals("ietf-yang-types")) { + assertEquals(rev20130715, monitoringImport.getRevision()); + } + } + } + + @Test + public void multipleRevisionsSimpleTest() throws SourceException, + ReactorException, FileNotFoundException, URISyntaxException, + ParseException { + for (int i = 0; i < 1000; i++) { + SchemaContext context = StmtTestUtils + .parseYangSources("/semantic-statement-parser/multiple-revisions/simple"); + assertNotNull(context); + assertEquals(5, context.getModules().size()); + checkContentSimpleTest(context); + } + } + + private void checkContentSimpleTest(SchemaContext context) + throws ParseException, URISyntaxException { + + String yangTypesNSStr = "urn:ietf:params:xml:ns:yang:ietf-yang-types"; + URI yangTypesNS = new URI(yangTypesNSStr); + + Date rev20100924 = SimpleDateFormatUtil.getRevisionFormat().parse( + "2010-09-24"); + Date rev20130516 = SimpleDateFormatUtil.getRevisionFormat().parse( + "2013-05-16"); + Date rev20130715 = SimpleDateFormatUtil.getRevisionFormat().parse( + "2013-07-15"); + + final QNameModule yangTypes_20100924 = QNameModule.create(yangTypesNS, + rev20100924); + final QNameModule yangTypes_20130516 = QNameModule.create(yangTypesNS, + rev20130516); + final QNameModule yangTypes_20130715 = QNameModule.create(yangTypesNS, + rev20130715); + + final QName dateTimeTypeDef_20100924 = QName.create(yangTypes_20100924, + "date-and-time"); + final QName dateTimeTypeDef_20130516 = QName.create(yangTypes_20130516, + "date-and-time"); + final QName dateTimeTypeDef_20130715 = QName.create(yangTypes_20130715, + "date-and-time"); + + Module yangTypesModule_20100924 = context.findModuleByName( + "ietf-yang-types", rev20100924); + Module yangTypesModule_20130516 = context.findModuleByName( + "ietf-yang-types", rev20130516); + Module yangTypesModule_20130715 = context.findModuleByName( + "ietf-yang-types", rev20130715); + + assertNotNull(yangTypesModule_20100924); + assertNotNull(yangTypesModule_20130516); + assertNotNull(yangTypesModule_20130715); + + assertTrue(findTypeDef(yangTypesModule_20100924, + dateTimeTypeDef_20100924)); + assertTrue(findTypeDef(yangTypesModule_20130516, + dateTimeTypeDef_20130516)); + assertTrue(findTypeDef(yangTypesModule_20130715, + dateTimeTypeDef_20130715)); + + checkNetconfMonitoringModuleSimpleTest(context, rev20130715, + dateTimeTypeDef_20130715); + + checkInterfacesModuleSimpleTest(context, rev20100924, + dateTimeTypeDef_20100924); + + } + + private void checkInterfacesModuleSimpleTest(SchemaContext context, + Date rev20100924, final QName dateTimeTypeDef_20100924) + throws URISyntaxException, ParseException { + String interfacesNSStr = "urn:ietf:params:xml:ns:yang:ietf-interfaces"; + URI interfacesNS = new URI(interfacesNSStr); + Date rev20121115 = SimpleDateFormatUtil.getRevisionFormat().parse( + "2012-11-15"); + final QNameModule interfacesNS_20121115 = QNameModule.create( + interfacesNS, rev20121115); + QName lastChange = QName.create(interfacesNS_20121115, "last-change"); + + Module interfacesModule_20121115 = context.findModuleByName( + "ietf-interfaces", rev20121115); + assertNotNull(interfacesModule_20121115); + + DataSchemaNode leafLastChange = interfacesModule_20121115 + .getDataChildByName(lastChange); + assertNotNull(leafLastChange); + + assertTrue(leafLastChange instanceof LeafSchemaNode); + QName lastChangeTypeQName = ((LeafSchemaNode) leafLastChange).getType() + .getQName(); + assertEquals(dateTimeTypeDef_20100924, lastChangeTypeQName); + + Set imports = interfacesModule_20121115.getImports(); + assertEquals(1, imports.size()); + ModuleImport interfacesImport = imports.iterator().next(); + assertEquals("ietf-yang-types", interfacesImport.getModuleName()); + assertEquals(rev20100924, interfacesImport.getRevision()); + } + + private void checkNetconfMonitoringModuleSimpleTest(SchemaContext context, + Date rev20130715, final QName dateTimeTypeDef_20130715) + throws ParseException, URISyntaxException { + String monitoringNSStr = "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"; + URI monitoringNS = new URI(monitoringNSStr); + + Date rev19700101 = SimpleDateFormatUtil.getRevisionFormat().parse( + "1970-01-01"); + final QNameModule monitoring_19700101 = QNameModule.create( + monitoringNS, rev19700101); + QName lockedTime = QName.create(monitoring_19700101, "locked-time"); + + Module monitoringModule_19700101 = context.findModuleByName( + "ietf-netconf-monitoring", rev19700101); + assertNotNull(monitoringModule_19700101); + + DataSchemaNode leafLockedTime = monitoringModule_19700101 + .getDataChildByName(lockedTime); + assertNotNull(leafLockedTime); + + assertTrue(leafLockedTime instanceof LeafSchemaNode); + QName lockedTimeTypeQName = ((LeafSchemaNode) leafLockedTime).getType() + .getQName(); + assertEquals(dateTimeTypeDef_20130715, lockedTimeTypeQName); + + Set imports = monitoringModule_19700101.getImports(); + assertEquals(1, imports.size()); + ModuleImport monitoringImport = imports.iterator().next(); + assertEquals("ietf-yang-types", monitoringImport.getModuleName()); + assertEquals(rev20130715, monitoringImport.getRevision()); + } + + private boolean findTypeDef(Module module, QName typedef) { + Set> typeDefinitions = module.getTypeDefinitions(); + for (TypeDefinition typeDefinition : typeDefinitions) { + if (typeDefinition.getQName().equals(typedef)) { + return true; + } + } + return false; + } } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/StmtTestUtils.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/StmtTestUtils.java index 9cbe4d4dbc..e264b19208 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/StmtTestUtils.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/StmtTestUtils.java @@ -8,11 +8,12 @@ package org.opendaylight.yangtools.yang.stmt.test; -import java.net.URISyntaxException; +import java.io.FileFilter; +import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; +import java.net.URISyntaxException; import java.net.URL; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; @@ -33,6 +34,14 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceIm public class StmtTestUtils { + final public static FileFilter YANG_FILE_FILTER = new FileFilter() { + @Override + public boolean accept(File file) { + String name = file.getName().toLowerCase(); + return name.endsWith(".yang") && file.isFile(); + } + }; + private static final Logger LOG = LoggerFactory .getLogger(StmtTestUtils.class); @@ -108,8 +117,7 @@ public class StmtTestUtils { StatementStreamSource[] sources = new StatementStreamSource[files.length]; for (int i = 0; i < files.length; i++) { - sources[i] = new YangStatementSourceImpl(new FileInputStream( - files[i])); + sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath())); } return parseYangSources(sources); @@ -126,6 +134,6 @@ public class StmtTestUtils { URL resourceDir = StmtTestUtils.class.getResource(yangSourcesDirectoryPath); File testSourcesDir = new File(resourceDir.toURI()); - return parseYangSources(testSourcesDir.listFiles()); + return parseYangSources(testSourcesDir.listFiles(YANG_FILE_FILTER)); } } diff --git a/yang/yang-parser-impl/src/test/resources/bugs/bug3799/test_module.yang b/yang/yang-parser-impl/src/test/resources/bugs/bug3799/test_module.yang new file mode 100644 index 0000000000..f0b30e3f3e --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/bugs/bug3799/test_module.yang @@ -0,0 +1,25 @@ +module test_module { + + namespace "http://www.example.com/test"; + prefix "test"; + + include "test_submodule"; + + organization "some organisation"; + + description + "Testing including a submodule with a different revision number"; + + revision 2014-06-15 { + description "some more changes"; + } + revision 2013-06-15 { + description "some changes"; + } + + container some_container { + + description + "some container"; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/bugs/bug3799/test_submodule.yang b/yang/yang-parser-impl/src/test/resources/bugs/bug3799/test_submodule.yang new file mode 100644 index 0000000000..346f139f1a --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/bugs/bug3799/test_submodule.yang @@ -0,0 +1,25 @@ +submodule test_submodule { + + belongs-to "test_module" { + prefix "sub"; + } + + organization "some organisation"; + + revision 2015-05-05 { + description + "submodule for testing with grouping"; + } + + grouping foo { + leaf bar { + description "some description"; + type uint64; + } + } + + notification baz { + description "container using grouping"; + uses foo; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/mapped-build/bar.yang b/yang/yang-parser-impl/src/test/resources/mapped-build/bar.yang new file mode 100644 index 0000000000..f97ebda1db --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/mapped-build/bar.yang @@ -0,0 +1,10 @@ +module bar { + namespace bar; + prefix bar; + + include sub-bar { revision-date 2015-03-01; } + + revision "2015-01-01" { + description "Initial version"; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/mapped-build/foo.yang b/yang/yang-parser-impl/src/test/resources/mapped-build/foo.yang new file mode 100644 index 0000000000..0ce367513b --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/mapped-build/foo.yang @@ -0,0 +1,10 @@ +module foo { + namespace foo; + prefix foo; + + include sub-foo { revision-date 2015-02-01; } + + revision "2015-01-02" { + description "Initial version"; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/mapped-build/sub-bar.yang b/yang/yang-parser-impl/src/test/resources/mapped-build/sub-bar.yang new file mode 100644 index 0000000000..761d30f4b9 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/mapped-build/sub-bar.yang @@ -0,0 +1,9 @@ +submodule sub-bar { + belongs-to bar { + prefix bar-m; + } + + revision "2015-03-01" { + description "Initial version"; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/mapped-build/sub-foo.yang b/yang/yang-parser-impl/src/test/resources/mapped-build/sub-foo.yang new file mode 100644 index 0000000000..cf0d31ce1d --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/mapped-build/sub-foo.yang @@ -0,0 +1,9 @@ +submodule sub-foo { + belongs-to foo { + prefix foo-m; + } + + revision "2015-02-01" { + description "Initial version"; + } +} \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/module-source/simple-module.yang b/yang/yang-parser-impl/src/test/resources/module-source/simple-module.yang new file mode 100644 index 0000000000..6aea830874 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/module-source/simple-module.yang @@ -0,0 +1,4 @@ +module simple-module { + namespace "test"; + prefix test; +} diff --git a/yang/yang-parser-impl/src/test/resources/sal-broker-impl/config.yang b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/config.yang new file mode 100644 index 0000000000..c0afa1b9db --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/config.yang @@ -0,0 +1,179 @@ +module config { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:config"; + prefix "config"; + + description + "This module contains the base YANG definitions for NS-OS configuration + subsystem. The system modeled revolves around two major concepts: + modules and services."; + + revision "2013-04-05" { + description + "Reworked to give modules their own space."; + } + + revision "2013-04-03" { + description + "Initial revision."; + } + + extension java-class { + description + "YANG language extension carrying the fully-qualified name of + a Java class. Code generation tools use the provided reference + to tie a specific construct to its Java representation."; + + argument "name"; + } + + extension required-identity { + description + "YANG language extension which indicates that a particular leafref, + which points to a identityref, should additionally require the + target node is actually set to a descendant to of a particular + identity. This is a workaround to two YANG deficiencies: 1) not + being able to leafref instances of identityref 2) not being able + to refine an identityref This extension takes one argument, name, + which MUST be the name of an identity. Furthermore, that identity + MUST be based, directly or indirectly, on the identity, which + is referenced by the leaf reference, which is annotated with this + extension."; + + argument "name"; + } + + extension inner-state-bean { + description + "YANG language extension which indicates that a particular list + located under module's state should be treated as a list of child + state beans instead of just an ordinary list attribute"; + } + + extension provided-service { + description + "YANG language extension which indicates that a particular module + provides certain service. This extension can be placed on identities + that are based on module-type. Zero or more services can be provided. + This extension takes one argument - name - which MUST be the name + of an identity. Furthermore, this identity MUST be based on service-type."; + + argument "name"; + } + + extension java-name-prefix { + description + "YANG language extension carrying java simple class name prefix + that will be taken into account when generating java code from + identities that are based on module-type."; + argument "java-prefix"; + } + + identity module-type { + description + "Module identity base type. All module identities must be derived + from this type. A module type uniquely defines a single atomic + component, such as an application. Each such component is assumed + to have its unique, stable and versioned configuration structure."; + } + + identity service-type { + description + "Service identity base type. All service identities must be derived + from this type. A service type uniquely defines a single atomic + API contract, such as a Java interface, a set of C function declarations, + or similar. If the service type has a corresponding Java interface, + the name of that interface should be attached to the derived identity + MUST include a java-class keyword, whose name argument points + to that interface."; + } + + typedef service-type-ref { + description + "Internal type of references to service type identity."; + + type identityref { + base service-type; + } + } + + grouping service-ref { + description + "Type of references to a particular service instance. This type + can be used when defining module configuration to refer to a particular + service instance. Containers using this grouping should not define + anything else. The run-time implementation is expected to inject + a reference to the service as the value of the container."; + + leaf type { + description + "Type of the service being referenced. Users of this grouping + should refine this leaf with required-identity pointing to the + actual service-type which is actually required."; + + mandatory true; + type leafref { + path "/config:services/config:service/config:type"; + } + } + + leaf name { + mandatory true; + type leafref { + path "/config:services/config:service[config:type=current()/../type]/config:instance/config:name"; + } + } + } + + container modules { + description + "Top level container encapsulating configuration of all modules."; + + list module { + key "type name"; + leaf name { + description "Unique module instance name"; + type string; + mandatory true; + } + + leaf type { + type identityref { + base module-type; + } + mandatory true; + } + + choice configuration { + mandatory true; + config true; + } + + choice state { + config false; + } + } + } + + container services { + list service { + key "type"; + leaf type { + type service-type-ref; + } + list instance { + key "name"; + leaf name { + type string; + } + + leaf provider { + mandatory true; + type leafref { + path "/modules/module/name"; + } + } + } + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/sal-broker-impl/ietf-yang-types.yang b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/ietf-yang-types.yang new file mode 100644 index 0000000000..51d9f8b887 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/ietf-yang-types.yang @@ -0,0 +1,396 @@ + module ietf-yang-types { + + namespace "urn:ietf:params:xml:ns:yang:ietf-yang-types"; + prefix "yang"; + + organization + "IETF NETMOD (NETCONF Data Modeling Language) Working Group"; + + contact + "WG Web: + WG List: + + WG Chair: David Partain + + + WG Chair: David Kessens + + + Editor: Juergen Schoenwaelder + "; + + description + "This module contains a collection of generally useful derived + YANG data types. + + Copyright (c) 2010 IETF Trust and the persons identified as + authors of the code. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, is permitted pursuant to, and subject to the license + terms contained in, the Simplified BSD License set forth in Section + 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info). + + This version of this YANG module is part of RFC 6021; see + the RFC itself for full legal notices."; + + revision 2010-09-24 { + description + "Initial revision."; + reference + "RFC 6021: Common YANG Data Types"; + } + + /*** collection of counter and gauge types ***/ + + typedef counter32 { + type uint32; + description + "The counter32 type represents a non-negative integer + that monotonically increases until it reaches a + maximum value of 2^32-1 (4294967295 decimal), when it + wraps around and starts increasing again from zero. + + Counters have no defined 'initial' value, and thus, a + single value of a counter has (in general) no information + content. Discontinuities in the monotonically increasing + value normally occur at re-initialization of the + management system, and at other times as specified in the + description of a schema node using this type. If such + other times can occur, for example, the creation of + a schema node of type counter32 at times other than + re-initialization, then a corresponding schema node + should be defined, with an appropriate type, to indicate + the last discontinuity. + + The counter32 type should not be used for configuration + schema nodes. A default statement SHOULD NOT be used in + combination with the type counter32. + + In the value set and its semantics, this type is equivalent + to the Counter32 type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 (SMIv2)"; + } + + typedef zero-based-counter32 { + type yang:counter32; + default "0"; + description + "The zero-based-counter32 type represents a counter32 + that has the defined 'initial' value zero. + + A schema node of this type will be set to zero (0) on creation + and will thereafter increase monotonically until it reaches + a maximum value of 2^32-1 (4294967295 decimal), when it + wraps around and starts increasing again from zero. + + Provided that an application discovers a new schema node + of this type within the minimum time to wrap, it can use the + 'initial' value as a delta. It is important for a management + station to be aware of this minimum time and the actual time + between polls, and to discard data if the actual time is too + long or there is no defined minimum time. + + In the value set and its semantics, this type is equivalent + to the ZeroBasedCounter32 textual convention of the SMIv2."; + reference + "RFC 4502: Remote Network Monitoring Management Information + Base Version 2"; + } + + typedef counter64 { + type uint64; + description + "The counter64 type represents a non-negative integer + that monotonically increases until it reaches a + maximum value of 2^64-1 (18446744073709551615 decimal), + when it wraps around and starts increasing again from zero. + + Counters have no defined 'initial' value, and thus, a + single value of a counter has (in general) no information + content. Discontinuities in the monotonically increasing + value normally occur at re-initialization of the + management system, and at other times as specified in the + description of a schema node using this type. If such + other times can occur, for example, the creation of + a schema node of type counter64 at times other than + re-initialization, then a corresponding schema node + should be defined, with an appropriate type, to indicate + the last discontinuity. + + The counter64 type should not be used for configuration + schema nodes. A default statement SHOULD NOT be used in + combination with the type counter64. + + In the value set and its semantics, this type is equivalent + to the Counter64 type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 (SMIv2)"; + } + + typedef zero-based-counter64 { + type yang:counter64; + default "0"; + description + "The zero-based-counter64 type represents a counter64 that + has the defined 'initial' value zero. + + A schema node of this type will be set to zero (0) on creation + and will thereafter increase monotonically until it reaches + a maximum value of 2^64-1 (18446744073709551615 decimal), + when it wraps around and starts increasing again from zero. + + Provided that an application discovers a new schema node + of this type within the minimum time to wrap, it can use the + 'initial' value as a delta. It is important for a management + station to be aware of this minimum time and the actual time + between polls, and to discard data if the actual time is too + long or there is no defined minimum time. + + In the value set and its semantics, this type is equivalent + to the ZeroBasedCounter64 textual convention of the SMIv2."; + reference + "RFC 2856: Textual Conventions for Additional High Capacity + Data Types"; + } + + typedef gauge32 { + type uint32; + description + "The gauge32 type represents a non-negative integer, which + may increase or decrease, but shall never exceed a maximum + value, nor fall below a minimum value. The maximum value + cannot be greater than 2^32-1 (4294967295 decimal), and + the minimum value cannot be smaller than 0. The value of + a gauge32 has its maximum value whenever the information + being modeled is greater than or equal to its maximum + value, and has its minimum value whenever the information + being modeled is smaller than or equal to its minimum value. + If the information being modeled subsequently decreases + below (increases above) the maximum (minimum) value, the + gauge32 also decreases (increases). + + In the value set and its semantics, this type is equivalent + to the Gauge32 type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 (SMIv2)"; + } + + typedef gauge64 { + type uint64; + description + "The gauge64 type represents a non-negative integer, which + may increase or decrease, but shall never exceed a maximum + value, nor fall below a minimum value. The maximum value + cannot be greater than 2^64-1 (18446744073709551615), and + the minimum value cannot be smaller than 0. The value of + a gauge64 has its maximum value whenever the information + being modeled is greater than or equal to its maximum + value, and has its minimum value whenever the information + being modeled is smaller than or equal to its minimum value. + If the information being modeled subsequently decreases + below (increases above) the maximum (minimum) value, the + gauge64 also decreases (increases). + + In the value set and its semantics, this type is equivalent + to the CounterBasedGauge64 SMIv2 textual convention defined + in RFC 2856"; + reference + "RFC 2856: Textual Conventions for Additional High Capacity + Data Types"; + } + + /*** collection of identifier related types ***/ + + typedef object-identifier { + type string { + pattern '(([0-1](\.[1-3]?[0-9]))|(2\.(0|([1-9]\d*))))' + + '(\.(0|([1-9]\d*)))*'; + } + description + "The object-identifier type represents administratively + assigned names in a registration-hierarchical-name tree. + + Values of this type are denoted as a sequence of numerical + non-negative sub-identifier values. Each sub-identifier + value MUST NOT exceed 2^32-1 (4294967295). Sub-identifiers + are separated by single dots and without any intermediate + whitespace. + + The ASN.1 standard restricts the value space of the first + sub-identifier to 0, 1, or 2. Furthermore, the value space + of the second sub-identifier is restricted to the range + 0 to 39 if the first sub-identifier is 0 or 1. Finally, + the ASN.1 standard requires that an object identifier + has always at least two sub-identifier. The pattern + captures these restrictions. + + Although the number of sub-identifiers is not limited, + module designers should realize that there may be + implementations that stick with the SMIv2 limit of 128 + sub-identifiers. + + This type is a superset of the SMIv2 OBJECT IDENTIFIER type + since it is not restricted to 128 sub-identifiers. Hence, + this type SHOULD NOT be used to represent the SMIv2 OBJECT + IDENTIFIER type, the object-identifier-128 type SHOULD be + used instead."; + reference + "ISO9834-1: Information technology -- Open Systems + Interconnection -- Procedures for the operation of OSI + Registration Authorities: General procedures and top + arcs of the ASN.1 Object Identifier tree"; + } + + + + + typedef object-identifier-128 { + type object-identifier { + pattern '\d*(\.\d*){1,127}'; + } + description + "This type represents object-identifiers restricted to 128 + sub-identifiers. + + In the value set and its semantics, this type is equivalent + to the OBJECT IDENTIFIER type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 (SMIv2)"; + } + + /*** collection of date and time related types ***/ + + typedef date-and-time { + type string { + pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?' + + '(Z|[\+\-]\d{2}:\d{2})'; + } + description + "The date-and-time type is a profile of the ISO 8601 + standard for representation of dates and times using the + Gregorian calendar. The profile is defined by the + date-time production in Section 5.6 of RFC 3339. + + The date-and-time type is compatible with the dateTime XML + schema type with the following notable exceptions: + + (a) The date-and-time type does not allow negative years. + + (b) The date-and-time time-offset -00:00 indicates an unknown + time zone (see RFC 3339) while -00:00 and +00:00 and Z all + represent the same time zone in dateTime. + + (c) The canonical format (see below) of data-and-time values + differs from the canonical format used by the dateTime XML + schema type, which requires all times to be in UTC using the + time-offset 'Z'. + + This type is not equivalent to the DateAndTime textual + convention of the SMIv2 since RFC 3339 uses a different + separator between full-date and full-time and provides + higher resolution of time-secfrac. + + The canonical format for date-and-time values with a known time + zone uses a numeric time zone offset that is calculated using + the device's configured known offset to UTC time. A change of + the device's offset to UTC time will cause date-and-time values + to change accordingly. Such changes might happen periodically + in case a server follows automatically daylight saving time + (DST) time zone offset changes. The canonical format for + date-and-time values with an unknown time zone (usually referring + to the notion of local time) uses the time-offset -00:00."; + reference + "RFC 3339: Date and Time on the Internet: Timestamps + RFC 2579: Textual Conventions for SMIv2 + XSD-TYPES: XML Schema Part 2: Datatypes Second Edition"; + } + + typedef timeticks { + type uint32; + description + "The timeticks type represents a non-negative integer that + represents the time, modulo 2^32 (4294967296 decimal), in + hundredths of a second between two epochs. When a schema + node is defined that uses this type, the description of + the schema node identifies both of the reference epochs. + + In the value set and its semantics, this type is equivalent + to the TimeTicks type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 (SMIv2)"; + } + + typedef timestamp { + type yang:timeticks; + description + "The timestamp type represents the value of an associated + timeticks schema node at which a specific occurrence happened. + The specific occurrence must be defined in the description + of any schema node defined using this type. When the specific + occurrence occurred prior to the last time the associated + timeticks attribute was zero, then the timestamp value is + zero. Note that this requires all timestamp values to be + reset to zero when the value of the associated timeticks + attribute reaches 497+ days and wraps around to zero. + + The associated timeticks schema node must be specified + in the description of any schema node using this type. + + In the value set and its semantics, this type is equivalent + to the TimeStamp textual convention of the SMIv2."; + reference + "RFC 2579: Textual Conventions for SMIv2"; + } + + /*** collection of generic address types ***/ + + typedef phys-address { + type string { + pattern '([0-9a-fA-F]{2}(:[0-9a-fA-F]{2})*)?'; + } + description + "Represents media- or physical-level addresses represented + as a sequence octets, each octet represented by two hexadecimal + numbers. Octets are separated by colons. The canonical + representation uses lowercase characters. + + In the value set and its semantics, this type is equivalent + to the PhysAddress textual convention of the SMIv2."; + reference + "RFC 2579: Textual Conventions for SMIv2"; + } + + typedef mac-address { + type string { + pattern '[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}'; + } + description + "The mac-address type represents an IEEE 802 MAC address. + The canonical representation uses lowercase characters. + + In the value set and its semantics, this type is equivalent + to the MacAddress textual convention of the SMIv2."; + reference + "IEEE 802: IEEE Standard for Local and Metropolitan Area + Networks: Overview and Architecture + RFC 2579: Textual Conventions for SMIv2"; + } + + /*** collection of XML specific types ***/ + + typedef xpath1.0 { + type string; + description + "This type represents an XPATH 1.0 expression. + + When a schema node is defined that uses this type, the + description of the schema node MUST specify the XPath + context in which the XPath expression is evaluated."; + reference + "XPATH: XML Path Language (XPath) Version 1.0"; + } + + } diff --git a/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-config-dom-datastore.yang b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-config-dom-datastore.yang new file mode 100644 index 0000000000..470d02d92c --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-config-dom-datastore.yang @@ -0,0 +1,21 @@ +module opendaylight-config-dom-datastore { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:core:spi:config-dom-store"; + prefix "config-dom-store-spi"; + + import config { prefix config; revision-date 2013-04-05; } + + description + "DOM Service Provider Interface definition for MD-SAL config store"; + + revision "2014-06-17" { + description + "Initial revision"; + } + + identity config-dom-datastore { + base "config:service-type"; + config:java-class "org.opendaylight.controller.sal.core.spi.data.DOMStore"; + } + +} diff --git a/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-dom-broker-impl.yang b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-dom-broker-impl.yang new file mode 100644 index 0000000000..944a63dbf6 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-dom-broker-impl.yang @@ -0,0 +1,218 @@ +module opendaylight-sal-dom-broker-impl { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:impl"; + prefix "broker"; + + import config { prefix config; revision-date 2013-04-05; } + import ietf-yang-types { prefix yang; } + import opendaylight-md-sal-dom { prefix sal; } + import opendaylight-md-sal-common { prefix common; } + import opendaylight-config-dom-datastore { prefix config-dom-store-spi; } + import opendaylight-operational-dom-datastore { prefix operational-dom-store-spi; } + import rpc-context { prefix rpcx; revision-date 2013-06-17; } + + description + "Service definition for Binding Aware MD-SAL. Note: The dom-inmemory-data-broker + utilizes configurable config-dom-datastore and operation-dom-datastore. + If configuration is not done for this stores then it defaults + to InMemoryDOMDataStore"; + + revision "2013-10-28" { + description + "Initial revision"; + } + + identity dom-broker-impl { + base config:module-type; + config:provided-service sal:dom-broker-osgi-registry; + config:java-name-prefix DomBrokerImpl; + } + + identity dom-inmemory-data-broker { + base config:module-type; + config:provided-service sal:dom-async-data-broker; + } + + identity schema-service-singleton { + base config:module-type; + config:provided-service sal:schema-service; + config:java-name-prefix SchemaServiceImplSingleton; + } + + typedef max-queue-depth { + type uint32 { + range 1..1073741824; + } + } + + augment "/config:modules/config:module/config:configuration" { + case dom-broker-impl { + when "/config:modules/config:module/config:type = 'dom-broker-impl'"; + + container async-data-broker { + uses config:service-ref { + refine type { + mandatory false; + config:required-identity sal:dom-async-data-broker; + } + } + } + + container root-schema-service { + uses config:service-ref { + refine type { + mandatory false; + config:required-identity sal:schema-service; + } + } + } + + leaf notification-queue-depth { + description "Maximum number of elements in the notification queue, must be + power-of-two."; + type max-queue-depth; + default 65536; + } + leaf notification-queue-spin { + description "Number of milliseconds notification queue should spin for new + requests before parking."; + type uint16; + units milliseconds; + default 1; + } + leaf notification-queue-park { + description "Number of milliseconds notification queue should park for new + requests before blocking."; + type uint16; + units milliseconds; + default 30; + } + } + } + + grouping dom-broker-config { + container schema-service { + uses config:service-ref { + refine type { + mandatory false; + config:required-identity sal:schema-service; + } + } + } + + container config-data-store { + uses config:service-ref { + refine type { + mandatory false; + config:required-identity config-dom-store-spi:config-dom-datastore; + } + } + } + + container operational-data-store { + uses config:service-ref { + refine type { + mandatory false; + config:required-identity operational-dom-store-spi:operational-dom-datastore; + } + } + } + + leaf max-data-broker-future-callback-queue-size { + default 1000; + type uint16; + description "The maximum queue size for the data broker's commit future callback + executor."; + } + + leaf max-data-broker-future-callback-pool-size { + default 20; + type uint16; + description "The maximum thread pool size for the data broker's commit future + callback executor."; + } + + leaf max-data-broker-commit-queue-size { + default 5000; + type uint16; + description "The maximum queue size for the data broker's commit executor."; + } + } + + grouping dom-broker-operational { + leaf total-commits { + type uint64; + } + + leaf average-commit { + type uint64; + units ns; + } + + leaf longest-commit-duration { + type uint64; + units ns; + } + + leaf longest-commit-timestamp { + type yang:date-and-time; + } + + leaf shortest-commit-duration { + type uint64; + units ns; + } + + leaf shortest-commit-timestamp { + type yang:date-and-time; + } + + rpcx:rpc-context-instance dom-broker-rpc-ctx; + } + + identity dom-broker-rpc-ctx; + + rpc reset-statistics { + description + "JMX call to clear the toasts-made counter."; + + input { + uses rpcx:rpc-context-ref { + refine context-instance { + rpcx:rpc-context-instance dom-broker-rpc-ctx; + } + } + } + } + + augment "/config:modules/config:module/config:configuration" { + case dom-inmemory-data-broker { + when "/config:modules/config:module/config:type = 'dom-inmemory-data-broker'"; + + uses dom-broker-config; + } + } + + augment "/config:modules/config:module/config:state" { + case dom-inmemory-data-broker { + when "/config:modules/config:module/config:type = 'dom-inmemory-data-broker'"; + + uses dom-broker-operational; + } + } + + augment "/config:modules/config:module/config:state" { + case schema-service-singleton { + when "/config:modules/config:module/config:type = 'schema-service-singleton'"; + } + } + + augment "/config:modules/config:module/config:state" { + case dom-broker-impl { + when "/config:modules/config:module/config:type = 'dom-broker-impl'"; + container data { + uses common:data-state; + } + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-md-sal-common.yang b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-md-sal-common.yang new file mode 100644 index 0000000000..bdfdb50167 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-md-sal-common.yang @@ -0,0 +1,70 @@ +module opendaylight-md-sal-common { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:common"; + prefix "md-sal-common"; + + description + "Common definition for MD-SAL."; + + revision "2013-10-28" { + description + "Initial revision"; + } + + grouping rpc-routing-table { + + leaf routing-context { + type string; + } + list routes { + leaf path { + type string; + } + leaf destination { + type string; + } + } + } + + grouping rpc-router { + leaf module { + type string; + } + container routing-tables { + list routing-table { + uses rpc-routing-table; + } + } + } + + grouping rpc-state { + list rpc-router { + uses rpc-router; + } + } + + grouping notification-state { + container notifications { + leaf published { + type uint32; + } + } + } + + grouping data-state { + container transactions { + leaf created { + type uint32; + } + leaf submitted { + type uint32; + } + leaf successful { + type uint32; + } + leaf failed { + type uint32; + } + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-md-sal-dom.yang b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-md-sal-dom.yang new file mode 100644 index 0000000000..1960c1f4c6 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-md-sal-dom.yang @@ -0,0 +1,30 @@ +module opendaylight-md-sal-dom { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom"; + prefix "md-sal-dom"; + + import config { prefix config; revision-date 2013-04-05; } + + description + "Service definition for Binding Aware MD-SAL."; + + revision "2013-10-28" { + description + "Initial revision"; + } + + identity dom-broker-osgi-registry { + base "config:service-type"; + config:java-class "org.opendaylight.controller.sal.core.api.Broker"; + } + + identity dom-async-data-broker { + base "config:service-type"; + config:java-class "org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"; + } + + identity schema-service { + base "config:service-type"; + config:java-class "org.opendaylight.controller.sal.core.api.model.SchemaService"; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-operational-dom-datastore.yang b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-operational-dom-datastore.yang new file mode 100644 index 0000000000..90197eaa69 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-operational-dom-datastore.yang @@ -0,0 +1,22 @@ +module opendaylight-operational-dom-datastore { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:core:spi:operational-dom-store"; + prefix "operational-dom-store-spi"; + + import config { prefix config; revision-date 2013-04-05; } + + description + "DOM Service Provider Interface definition for MD-SAL operational + store"; + + revision "2014-06-17" { + description + "Initial revision"; + } + + identity operational-dom-datastore { + base "config:service-type"; + config:java-class "org.opendaylight.controller.sal.core.spi.data.DOMStore"; + } + +} diff --git a/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-pingpong-broker.yang b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-pingpong-broker.yang new file mode 100644 index 0000000000..0ed1bbd4b9 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/opendaylight-pingpong-broker.yang @@ -0,0 +1,39 @@ +module opendaylight-pingpong-broker { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:pingpong"; + prefix "pingpong"; + + import config { prefix config; revision-date 2013-04-05; } + import opendaylight-md-sal-dom {prefix sal;} + import opendaylight-md-sal-common {prefix common;} + import opendaylight-config-dom-datastore {prefix config-dom-store-spi;} + import opendaylight-operational-dom-datastore {prefix operational-dom-store-spi;} + + description + "Service definition for Ping-Pong DOM broker"; + + revision "2014-11-07" { + description + "Initial revision"; + } + + identity pingpong-data-broker { + base config:module-type; + config:provided-service sal:dom-async-data-broker; + } + + augment "/config:modules/config:module/config:configuration" { + case pingpong-data-broker { + when "/config:modules/config:module/config:type = 'pingpong-data-broker'"; + + container data-broker { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity sal:dom-async-data-broker; + } + } + } + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/sal-broker-impl/rpc-context.yang b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/rpc-context.yang new file mode 100644 index 0000000000..5c8b113412 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/sal-broker-impl/rpc-context.yang @@ -0,0 +1,32 @@ +module rpc-context { + yang-version 1; + namespace "urn:ietf:params:xml:ns:yang:rpc-context"; + prefix "rpcx"; + + organization "TBD"; + + contact "TBD"; + + description ""; + + revision 2013-06-17 { + description "Initial mock"; + } + + + grouping rpc-context-ref { + description "A reference to RPC context."; + leaf context-instance { + type instance-identifier; + description "Pointer to the context. "; + } + } + + extension "rpc-context-instance" { + description + "Marks enclosing (parent) schema node as suitable RPC context. + The argument is identity which is used to identify RPC context + type."; + argument "context-type"; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-inet-types.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-inet-types.yang new file mode 100644 index 0000000000..de20febbb7 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-inet-types.yang @@ -0,0 +1,418 @@ + module ietf-inet-types { + + namespace "urn:ietf:params:xml:ns:yang:ietf-inet-types"; + prefix "inet"; + + organization + "IETF NETMOD (NETCONF Data Modeling Language) Working Group"; + + contact + "WG Web: + WG List: + + WG Chair: David Partain + + + WG Chair: David Kessens + + + Editor: Juergen Schoenwaelder + "; + + description + "This module contains a collection of generally useful derived + YANG data types for Internet addresses and related things. + + Copyright (c) 2010 IETF Trust and the persons identified as + authors of the code. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, is permitted pursuant to, and subject to the license + terms contained in, the Simplified BSD License set forth in Section + 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info). + + This version of this YANG module is part of RFC 6021; see + the RFC itself for full legal notices."; + + revision 2010-09-24 { + description + "Initial revision."; + reference + "RFC 6021: Common YANG Data Types"; + } + + /*** collection of protocol field related types ***/ + + typedef ip-version { + type enumeration { + enum unknown { + value "0"; + description + "An unknown or unspecified version of the Internet protocol."; + } + enum ipv4 { + value "1"; + description + "The IPv4 protocol as defined in RFC 791."; + } + enum ipv6 { + value "2"; + description + "The IPv6 protocol as defined in RFC 2460."; + } + } + description + "This value represents the version of the IP protocol. + + In the value set and its semantics, this type is equivalent + to the InetVersion textual convention of the SMIv2."; + reference + "RFC 791: Internet Protocol + RFC 2460: Internet Protocol, Version 6 (IPv6) Specification + RFC 4001: Textual Conventions for Internet Network Addresses"; + } + + typedef dscp { + type uint8 { + range "0..63"; + } + description + "The dscp type represents a Differentiated Services Code-Point + that may be used for marking packets in a traffic stream. + + In the value set and its semantics, this type is equivalent + to the Dscp textual convention of the SMIv2."; + reference + "RFC 3289: Management Information Base for the Differentiated + Services Architecture + RFC 2474: Definition of the Differentiated Services Field + (DS Field) in the IPv4 and IPv6 Headers + RFC 2780: IANA Allocation Guidelines For Values In + the Internet Protocol and Related Headers"; + } + + typedef ipv6-flow-label { + type uint32 { + range "0..1048575"; + } + description + "The flow-label type represents flow identifier or Flow Label + in an IPv6 packet header that may be used to discriminate + traffic flows. + + In the value set and its semantics, this type is equivalent + to the IPv6FlowLabel textual convention of the SMIv2."; + reference + "RFC 3595: Textual Conventions for IPv6 Flow Label + RFC 2460: Internet Protocol, Version 6 (IPv6) Specification"; + } + + typedef port-number { + type uint16 { + range "0..65535"; + } + description + "The port-number type represents a 16-bit port number of an + Internet transport layer protocol such as UDP, TCP, DCCP, or + SCTP. Port numbers are assigned by IANA. A current list of + all assignments is available from . + + Note that the port number value zero is reserved by IANA. In + situations where the value zero does not make sense, it can + be excluded by subtyping the port-number type. + + In the value set and its semantics, this type is equivalent + to the InetPortNumber textual convention of the SMIv2."; + reference + "RFC 768: User Datagram Protocol + RFC 793: Transmission Control Protocol + RFC 4960: Stream Control Transmission Protocol + RFC 4340: Datagram Congestion Control Protocol (DCCP) + RFC 4001: Textual Conventions for Internet Network Addresses"; + } + + /*** collection of autonomous system related types ***/ + + typedef as-number { + type uint32; + description + "The as-number type represents autonomous system numbers + which identify an Autonomous System (AS). An AS is a set + of routers under a single technical administration, using + an interior gateway protocol and common metrics to route + packets within the AS, and using an exterior gateway + protocol to route packets to other ASs'. IANA maintains + the AS number space and has delegated large parts to the + regional registries. + + Autonomous system numbers were originally limited to 16 + bits. BGP extensions have enlarged the autonomous system + number space to 32 bits. This type therefore uses an uint32 + base type without a range restriction in order to support + a larger autonomous system number space. + + In the value set and its semantics, this type is equivalent + to the InetAutonomousSystemNumber textual convention of + the SMIv2."; + reference + "RFC 1930: Guidelines for creation, selection, and registration + of an Autonomous System (AS) + RFC 4271: A Border Gateway Protocol 4 (BGP-4) + RFC 4893: BGP Support for Four-octet AS Number Space + RFC 4001: Textual Conventions for Internet Network Addresses"; + } + + /*** collection of IP address and hostname related types ***/ + + typedef ip-address { + type union { + type inet:ipv4-address; + type inet:ipv6-address; + } + description + "The ip-address type represents an IP address and is IP + version neutral. The format of the textual representations + implies the IP version."; + } + + typedef ipv4-address { + type string { + pattern + '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}' + + '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])' + + '(%[\p{N}\p{L}]+)?'; + } + description + "The ipv4-address type represents an IPv4 address in + dotted-quad notation. The IPv4 address may include a zone + index, separated by a % sign. + + The zone index is used to disambiguate identical address + values. For link-local addresses, the zone index will + typically be the interface index number or the name of an + interface. If the zone index is not present, the default + zone of the device will be used. + + The canonical format for the zone index is the numerical + format"; + } + + typedef ipv6-address { + type string { + pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}' + + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|' + + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}' + + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))' + + '(%[\p{N}\p{L}]+)?'; + pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|' + + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)' + + '(%.+)?'; + } + description + "The ipv6-address type represents an IPv6 address in full, + mixed, shortened, and shortened-mixed notation. The IPv6 + address may include a zone index, separated by a % sign. + + The zone index is used to disambiguate identical address + values. For link-local addresses, the zone index will + typically be the interface index number or the name of an + interface. If the zone index is not present, the default + zone of the device will be used. + + The canonical format of IPv6 addresses uses the compressed + format described in RFC 4291, Section 2.2, item 2 with the + following additional rules: the :: substitution must be + applied to the longest sequence of all-zero 16-bit chunks + in an IPv6 address. If there is a tie, the first sequence + of all-zero 16-bit chunks is replaced by ::. Single + all-zero 16-bit chunks are not compressed. The canonical + format uses lowercase characters and leading zeros are + not allowed. The canonical format for the zone index is + the numerical format as described in RFC 4007, Section + 11.2."; + reference + "RFC 4291: IP Version 6 Addressing Architecture + RFC 4007: IPv6 Scoped Address Architecture + RFC 5952: A Recommendation for IPv6 Address Text Representation"; + } + + typedef ip-prefix { + type union { + type inet:ipv4-prefix; + type inet:ipv6-prefix; + } + description + "The ip-prefix type represents an IP prefix and is IP + version neutral. The format of the textual representations + implies the IP version."; + } + + typedef ipv4-prefix { + type string { + pattern + '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}' + + '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])' + + '/(([0-9])|([1-2][0-9])|(3[0-2]))'; + } + description + "The ipv4-prefix type represents an IPv4 address prefix. + The prefix length is given by the number following the + slash character and must be less than or equal to 32. + + A prefix length value of n corresponds to an IP address + mask that has n contiguous 1-bits from the most + significant bit (MSB) and all other bits set to 0. + + The canonical format of an IPv4 prefix has all bits of + the IPv4 address set to zero that are not part of the + IPv4 prefix."; + } + + typedef ipv6-prefix { + type string { + pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}' + + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|' + + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}' + + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))' + + '(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))'; + pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|' + + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)' + + '(/.+)'; + } + description + "The ipv6-prefix type represents an IPv6 address prefix. + The prefix length is given by the number following the + slash character and must be less than or equal 128. + + A prefix length value of n corresponds to an IP address + mask that has n contiguous 1-bits from the most + significant bit (MSB) and all other bits set to 0. + + The IPv6 address should have all bits that do not belong + to the prefix set to zero. + + The canonical format of an IPv6 prefix has all bits of + the IPv6 address set to zero that are not part of the + IPv6 prefix. Furthermore, IPv6 address is represented + in the compressed format described in RFC 4291, Section + 2.2, item 2 with the following additional rules: the :: + substitution must be applied to the longest sequence of + all-zero 16-bit chunks in an IPv6 address. If there is + a tie, the first sequence of all-zero 16-bit chunks is + replaced by ::. Single all-zero 16-bit chunks are not + compressed. The canonical format uses lowercase + characters and leading zeros are not allowed."; + reference + "RFC 4291: IP Version 6 Addressing Architecture"; + } + + /*** collection of domain name and URI types ***/ + + typedef domain-name { + type string { + pattern '((([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.)*' + + '([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.?)' + + '|\.'; + length "1..253"; + } + description + "The domain-name type represents a DNS domain name. The + name SHOULD be fully qualified whenever possible. + + Internet domain names are only loosely specified. Section + 3.5 of RFC 1034 recommends a syntax (modified in Section + 2.1 of RFC 1123). The pattern above is intended to allow + for current practice in domain name use, and some possible + future expansion. It is designed to hold various types of + domain names, including names used for A or AAAA records + (host names) and other records, such as SRV records. Note + that Internet host names have a stricter syntax (described + in RFC 952) than the DNS recommendations in RFCs 1034 and + 1123, and that systems that want to store host names in + schema nodes using the domain-name type are recommended to + adhere to this stricter standard to ensure interoperability. + + The encoding of DNS names in the DNS protocol is limited + to 255 characters. Since the encoding consists of labels + prefixed by a length bytes and there is a trailing NULL + byte, only 253 characters can appear in the textual dotted + notation. + + The description clause of schema nodes using the domain-name + type MUST describe when and how these names are resolved to + IP addresses. Note that the resolution of a domain-name value + may require to query multiple DNS records (e.g., A for IPv4 + and AAAA for IPv6). The order of the resolution process and + which DNS record takes precedence can either be defined + explicitely or it may depend on the configuration of the + resolver. + + Domain-name values use the US-ASCII encoding. Their canonical + format uses lowercase US-ASCII characters. Internationalized + domain names MUST be encoded in punycode as described in RFC + 3492"; + reference + "RFC 952: DoD Internet Host Table Specification + RFC 1034: Domain Names - Concepts and Facilities + RFC 1123: Requirements for Internet Hosts -- Application + and Support + RFC 2782: A DNS RR for specifying the location of services + (DNS SRV) + RFC 3492: Punycode: A Bootstring encoding of Unicode for + Internationalized Domain Names in Applications + (IDNA) + RFC 5891: Internationalizing Domain Names in Applications + (IDNA): Protocol"; + } + + typedef host { + type union { + type inet:ip-address; + type inet:domain-name; + } + description + "The host type represents either an IP address or a DNS + domain name."; + } + + typedef uri { + type string; + description + "The uri type represents a Uniform Resource Identifier + (URI) as defined by STD 66. + + Objects using the uri type MUST be in US-ASCII encoding, + and MUST be normalized as described by RFC 3986 Sections + 6.2.1, 6.2.2.1, and 6.2.2.2. All unnecessary + percent-encoding is removed, and all case-insensitive + characters are set to lowercase except for hexadecimal + digits, which are normalized to uppercase as described in + Section 6.2.2.1. + + The purpose of this normalization is to help provide + unique URIs. Note that this normalization is not + sufficient to provide uniqueness. Two URIs that are + textually distinct after this normalization may still be + equivalent. + + Objects using the uri type may restrict the schemes that + they permit. For example, 'data:' and 'urn:' schemes + might not be appropriate. + + A zero-length URI is not a valid URI. This can be used to + express 'URI absent' where required. + + In the value set and its semantics, this type is equivalent + to the Uri SMIv2 textual convention defined in RFC 5017."; + reference + "RFC 3986: Uniform Resource Identifier (URI): Generic Syntax + RFC 3305: Report from the Joint W3C/IETF URI Planning Interest + Group: Uniform Resource Identifiers (URIs), URLs, + and Uniform Resource Names (URNs): Clarifications + and Recommendations + RFC 5017: MIB Textual Conventions for Uniform Resource + Identifiers (URIs)"; + } + + } diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-interfaces.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-interfaces.yang new file mode 100644 index 0000000000..481a5d2ed1 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-interfaces.yang @@ -0,0 +1,469 @@ +module ietf-interfaces { + + namespace "urn:ietf:params:xml:ns:yang:ietf-interfaces"; + prefix if; + + import ietf-yang-types { + prefix yang; + revision-date 2010-09-24; + } + + organization + "IETF NETMOD (NETCONF Data Modeling Language) Working Group"; + + contact + "WG Web: + WG List: + + WG Chair: David Kessens + + + WG Chair: Juergen Schoenwaelder + + + Editor: Martin Bjorklund + "; + + description + "This module contains a collection of YANG definitions for + managing network interfaces. + + Copyright (c) 2012 IETF Trust and the persons identified as + authors of the code. All rights reserved. + + Redistribution and use in source and binary forms, with or + without modification, is permitted pursuant to, and subject + to the license terms contained in, the Simplified BSD License + set forth in Section 4.c of the IETF Trust's Legal Provisions + Relating to IETF Documents + (http://trustee.ietf.org/license-info). + + This version of this YANG module is part of RFC XXXX; see + the RFC itself for full legal notices."; + + // RFC Ed.: replace XXXX with actual RFC number and remove this + // note. + + // RFC Ed.: update the date below with the date of RFC publication + // and remove this note. + revision 2012-11-15 { + description + "Initial revision."; + reference + "RFC XXXX: A YANG Data Model for Interface Management"; + } + + /* Typedefs */ + + typedef interface-ref { + type leafref { + path "/if:interfaces/if:interface/if:name"; + } + description + "This type is used by data models that need to reference + interfaces."; + } + + /* Features */ + + feature arbitrary-names { + description + "This feature indicates that the server allows interfaces to + be named arbitrarily."; + } + + feature if-mib { + description + "This feature indicates that the server implements IF-MIB."; + reference + "RFC 2863: The Interfaces Group MIB"; + } + + /* Data nodes */ + + container interfaces { + description + "Interface parameters."; + + list interface { + key "name"; + unique "type location"; + + description + "The list of interfaces on the device."; + + leaf name { + type string; + description + "The name of the interface. + + A device MAY restrict the allowed values for this leaf, + possibly depending on the type and location. + + If the device allows arbitrarily named interfaces, the + feature 'arbitrary-names' is advertised. + + This leaf MAY be mapped to ifName by an implementation. + Such an implementation MAY restrict the allowed values for + this leaf so that it matches the restrictions of ifName. + If a NETCONF server that implements this restriction is + sent a value that doesn't match the restriction, it MUST + reply with an rpc-error with the error-tag + 'invalid-value'."; + reference + "RFC 2863: The Interfaces Group MIB - ifName"; + } + + leaf description { + type string; + description + "A textual description of the interface. + + This leaf MAY be mapped to ifAlias by an implementation. + Such an implementation MAY restrict the allowed values for + this leaf so that it matches the restrictions of ifAlias. + If a NETCONF server that implements this restriction is + sent a value that doesn't match the restriction, it MUST + reply with an rpc-error with the error-tag + 'invalid-value'."; + reference + "RFC 2863: The Interfaces Group MIB - ifAlias"; + } + + leaf location { + type string; + description + "The device-specific location of the interface of a + particular type. The format of the location string + depends on the interface type and the device. + + If the interface's type represents a physical interface, + this leaf MUST be set. + + When an interface entry is created, a server MAY + initialize the location leaf with a valid value, e.g., if + it is possible to derive the location from the name of + the interface."; + } + + leaf enabled { + type boolean; + default "true"; + description + "The desired state of the interface. + + This leaf contains the configured, desired state of the + interface. Systems that implement the IF-MIB use the + value of this leaf to set IF-MIB.ifAdminStatus to 'up' or + 'down' after an ifEntry has been initialized, as described + in RFC 2863."; + reference + "RFC 2863: The Interfaces Group MIB - ifAdminStatus"; + } + + leaf last-change { + type yang:date-and-time; + config false; + description + "The time the interface entered its current operational + state. If the current state was entered prior to the + last re-initialization of the local network management + subsystem, then this node is not present."; + reference + "RFC 2863: The Interfaces Group MIB - ifLastChange"; + } + + leaf if-index { + if-feature if-mib; + type int32 { + range "1..2147483647"; + } + config false; + description + "The ifIndex value for the ifEntry represented by this + interface. + + Media-specific modules must specify how the type is + mapped to entries in the ifTable."; + reference + "RFC 2863: The Interfaces Group MIB - ifIndex"; + } + + leaf phys-address { + type yang:phys-address; + config false; + description + "The interface's address at its protocol sub-layer. For + example, for an 802.x interface, this object normally + contains a MAC address. The interface's media-specific + modules must define the bit and byte ordering and the + format of the value of this object. For interfaces that do + not have such an address (e.g., a serial line), this node + is not present."; + reference + "RFC 2863: The Interfaces Group MIB - ifPhysAddress"; + } + + leaf-list higher-layer-if { + type interface-ref; + config false; + description + "A list of references to interfaces layered on top of this + interface."; + reference + "RFC 2863: The Interfaces Group MIB - ifStackTable"; + } + + leaf-list lower-layer-if { + type interface-ref; + config false; + description + "A list of references to interfaces layered underneath this + interface."; + reference + "RFC 2863: The Interfaces Group MIB - ifStackTable"; + } + + leaf speed { + type yang:gauge64; + units "bits / second"; + config false; + description + "An estimate of the interface's current bandwidth in bits + per second. For interfaces which do not vary in + bandwidth or for those where no accurate estimation can + be made, this node should contain the nominal bandwidth. + For interfaces that has no concept of bandwidth, this + node is not present."; + reference + "RFC 2863: The Interfaces Group MIB - + ifSpeed, ifHighSpeed"; + } + + container statistics { + config false; + description + "A collection of interface-related statistics objects."; + + leaf discontinuity-time { + type yang:date-and-time; + description + "The time on the most recent occasion at which any one or + more of this interface's counters suffered a + discontinuity. If no such discontinuities have occurred + since the last re-initialization of the local management + subsystem, then this node contains the time the local + management subsystem re-initialized itself."; + } + + leaf in-octets { + type yang:counter64; + description + "The total number of octets received on the interface, + including framing characters. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifHCInOctets"; + } + leaf in-unicast-pkts { + type yang:counter64; + description + "The number of packets, delivered by this sub-layer to a + higher (sub-)layer, which were not addressed to a + multicast or broadcast address at this sub-layer. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifHCInUcastPkts"; + } + leaf in-broadcast-pkts { + type yang:counter64; + description + "The number of packets, delivered by this sub-layer to a + higher (sub-)layer, which were addressed to a broadcast + address at this sub-layer. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - + ifHCInBroadcastPkts"; + } + leaf in-multicast-pkts { + type yang:counter64; + description + "The number of packets, delivered by this sub-layer to a + higher (sub-)layer, which were addressed to a multicast + address at this sub-layer. For a MAC layer protocol, + this includes both Group and Functional addresses. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - + ifHCInMulticastPkts"; + } + leaf in-discards { + type yang:counter32; + description + "The number of inbound packets which were chosen to be + discarded even though no errors had been detected to + prevent their being deliverable to a higher-layer + protocol. One possible reason for discarding such a + packet could be to free up buffer space. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifInDiscards"; + } + leaf in-errors { + type yang:counter32; + description + "For packet-oriented interfaces, the number of inbound + packets that contained errors preventing them from being + deliverable to a higher-layer protocol. For character- + oriented or fixed-length interfaces, the number of + inbound transmission units that contained errors + preventing them from being deliverable to a higher-layer + protocol. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifInErrors"; + } + leaf in-unknown-protos { + type yang:counter32; + description + "For packet-oriented interfaces, the number of packets + received via the interface which were discarded because + of an unknown or unsupported protocol. For + character-oriented or fixed-length interfaces that + support protocol multiplexing the number of transmission + units received via the interface which were discarded + because of an unknown or unsupported protocol. For any + interface that does not support protocol multiplexing, + this counter is not present. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifInUnknownProtos"; + } + + leaf out-octets { + type yang:counter64; + description + "The total number of octets transmitted out of the + interface, including framing characters. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifHCOutOctets"; + } + leaf out-unicast-pkts { + type yang:counter64; + description + "The total number of packets that higher-level protocols + requested be transmitted, and which were not addressed + to a multicast or broadcast address at this sub-layer, + including those that were discarded or not sent. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifHCOutUcastPkts"; + } + leaf out-broadcast-pkts { + type yang:counter64; + description + "The total number of packets that higher-level protocols + requested be transmitted, and which were addressed to a + broadcast address at this sub-layer, including those + that were discarded or not sent. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - + ifHCOutBroadcastPkts"; + } + leaf out-multicast-pkts { + type yang:counter64; + description + "The total number of packets that higher-level protocols + requested be transmitted, and which were addressed to a + multicast address at this sub-layer, including those + that were discarded or not sent. For a MAC layer + protocol, this includes both Group and Functional + addresses. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - + ifHCOutMulticastPkts"; + } + leaf out-discards { + type yang:counter32; + description + "The number of outbound packets which were chosen to be + discarded even though no errors had been detected to + prevent their being transmitted. One possible reason + for discarding such a packet could be to free up buffer + space. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifOutDiscards"; + } + leaf out-errors { + type yang:counter32; + description + "For packet-oriented interfaces, the number of outbound + packets that could not be transmitted because of errors. + For character-oriented or fixed-length interfaces, the + number of outbound transmission units that could not be + transmitted because of errors. + + Discontinuities in the value of this counter can occur + at re-initialization of the management system, and at + other times as indicated by the value of + 'discontinuity-time'."; + reference + "RFC 2863: The Interfaces Group MIB - ifOutErrors"; + } + } + } + } +} \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-netconf-monitoring.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-netconf-monitoring.yang new file mode 100644 index 0000000000..b4ad89b558 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-netconf-monitoring.yang @@ -0,0 +1,593 @@ +module ietf-netconf-monitoring { + + yang-version 1; + + namespace + "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"; + + prefix ncm; + + import ietf-yang-types { + prefix yang; + } + import ietf-inet-types { + prefix inet; + } + + organization + "IETF NETCONF (Network Configuration) Working Group"; + + contact + "WG Web: + WG List: + + WG Chair: Mehmet Ersue + + + WG Chair: Bert Wijnen + + + Editor: Mark Scott + + + Editor: Martin Bjorklund + "; + + description + "NETCONF Monitoring Module. + All elements in this module are read-only. + + Copyright (c) 2010 IETF Trust and the persons identified as + authors of the code. All rights reserved. + + Redistribution and use in source and binary forms, with or + without modification, is permitted pursuant to, and subject + to the license terms contained in, the Simplified BSD + License set forth in Section 4.c of the IETF Trust's + Legal Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info). + + This version of this YANG module is part of RFC 6022; see + the RFC itself for full legal notices."; + + revision "2010-10-04" { + description "Initial revision."; + reference + "RFC 6022: YANG Module for NETCONF Monitoring"; + + } + + + typedef netconf-datastore-type { + type enumeration { + enum "running" { + value 0; + } + enum "candidate" { + value 1; + } + enum "startup" { + value 2; + } + } + description + "Enumeration of possible NETCONF datastore types."; + reference + "RFC 4741: NETCONF Configuration Protocol"; + + } + + identity transport { + description + "Base identity for NETCONF transport types."; + } + + identity netconf-ssh { + base transport; + description + "NETCONF over Secure Shell (SSH)."; + reference + "RFC 4742: Using the NETCONF Configuration Protocol + over Secure SHell (SSH)"; + + } + + identity netconf-soap-over-beep { + base transport; + description + "NETCONF over Simple Object Access Protocol (SOAP) over + Blocks Extensible Exchange Protocol (BEEP)."; + reference + "RFC 4743: Using NETCONF over the Simple Object + Access Protocol (SOAP)"; + + } + + identity netconf-soap-over-https { + base transport; + description + "NETCONF over Simple Object Access Protocol (SOAP) + over Hypertext Transfer Protocol Secure (HTTPS)."; + reference + "RFC 4743: Using NETCONF over the Simple Object + Access Protocol (SOAP)"; + + } + + identity netconf-beep { + base transport; + description + "NETCONF over Blocks Extensible Exchange Protocol (BEEP)."; + reference + "RFC 4744: Using the NETCONF Protocol over the + Blocks Extensible Exchange Protocol (BEEP)"; + + } + + identity netconf-tls { + base transport; + description + "NETCONF over Transport Layer Security (TLS)."; + reference + "RFC 5539: NETCONF over Transport Layer Security (TLS)"; + + } + + identity schema-format { + description + "Base identity for data model schema languages."; + } + + identity xsd { + base schema-format; + description + "W3C XML Schema Definition."; + reference + "W3C REC REC-xmlschema-1-20041028: + XML Schema Part 1: Structures"; + + } + + identity yang { + base schema-format; + description + "The YANG data modeling language for NETCONF."; + reference + "RFC 6020: YANG - A Data Modeling Language for the + Network Configuration Protocol (NETCONF)"; + + } + + identity yin { + base schema-format; + description "The YIN syntax for YANG."; + reference + "RFC 6020: YANG - A Data Modeling Language for the + Network Configuration Protocol (NETCONF)"; + + } + + identity rng { + base schema-format; + description + "Regular Language for XML Next Generation (RELAX NG)."; + reference + "ISO/IEC 19757-2:2008: RELAX NG"; + + } + + identity rnc { + base schema-format; + description "Relax NG Compact Syntax"; + reference + "ISO/IEC 19757-2:2008: RELAX NG"; + + } + + grouping common-counters { + description + "Counters that exist both per session, and also globally, + accumulated from all sessions."; + leaf in-rpcs { + type yang:zero-based-counter32; + description + "Number of correct messages received."; + } + + leaf in-bad-rpcs { + type yang:zero-based-counter32; + description + "Number of messages received when an message was expected, + that were not correct messages. This includes XML parse + errors and errors on the rpc layer."; + } + + leaf out-rpc-errors { + type yang:zero-based-counter32; + description + "Number of messages sent that contained an + element."; + } + + leaf out-notifications { + type yang:zero-based-counter32; + description + "Number of messages sent."; + } + } // grouping common-counters + + container netconf-state { + config false; + description + "The netconf-state container is the root of the monitoring + data model."; + container capabilities { + description + "Contains the list of NETCONF capabilities supported by the + server."; + leaf-list capability { + type inet:uri; + description + "List of NETCONF capabilities supported by the server."; + } + } // container capabilities + + container datastores { + description + "Contains the list of NETCONF configuration datastores."; + list datastore { + key "name"; + description + "List of NETCONF configuration datastores supported by + the NETCONF server and related information."; + leaf name { + type netconf-datastore-type; + description + "Name of the datastore associated with this list entry."; + } + + container locks { + presence + "This container is present only if the datastore + is locked."; + description + "The NETCONF and operations allow + a client to lock specific resources in a datastore. The + NETCONF server will prevent changes to the locked + resources by all sessions except the one that acquired + the lock(s). + + Monitoring information is provided for each datastore + entry including details such as the session that acquired + the lock, the type of lock (global or partial) and the + list of locked resources. Multiple locks per datastore + are supported."; + grouping lock-info { + description + "Lock related parameters, common to both global and + partial locks."; + leaf locked-by-session { + type uint32; + mandatory true; + description + "The session ID of the session that has locked + this resource. Both a global lock and a partial + lock MUST contain the NETCONF session-id. + + If the lock is held by a session that is not managed + by the NETCONF server (e.g., a CLI session), a session + id of 0 (zero) is reported."; + reference + "RFC 4741: NETCONF Configuration Protocol"; + + } + + leaf locked-time { + type yang:date-and-time; + mandatory true; + description + "The date and time of when the resource was + locked."; + } + } // grouping lock-info + choice lock-type { + description + "Indicates if a global lock or a set of partial locks + are set."; + container global-lock { + description + "Present if the global lock is set."; + uses lock-info; + } // container global-lock + list partial-lock { + key "lock-id"; + description + "List of partial locks."; + reference + "RFC 5717: Partial Lock Remote Procedure Call (RPC) for + NETCONF"; + + leaf lock-id { + type uint32; + description + "This is the lock id returned in the + response."; + } + + uses lock-info; + + leaf-list select { + type yang:xpath1.0; + min-elements 1; + description + "The xpath expression that was used to request + the lock. The select expression indicates the + original intended scope of the lock."; + } + + leaf-list locked-node { + type instance-identifier; + description + "The list of instance-identifiers (i.e., the + locked nodes). + + The scope of the partial lock is defined by the list + of locked nodes."; + } + } // list partial-lock + } // choice lock-type + } // container locks + } // list datastore + } // container datastores + + container schemas { + description + "Contains the list of data model schemas supported by the + server."; + list schema { + key "identifier version format"; + description + "List of data model schemas supported by the server."; + leaf identifier { + type string; + description + "Identifier to uniquely reference the schema. The + identifier is used in the operation and may + be used for other purposes such as file retrieval. + + For modeling languages that support or require a data + model name (e.g., YANG module name) the identifier MUST + match that name. For YANG data models, the identifier is + the name of the module or submodule. In other cases, an + identifier such as a filename MAY be used instead."; + } + + leaf version { + type string; + description + "Version of the schema supported. Multiple versions MAY be + supported simultaneously by a NETCONF server. Each + version MUST be reported individually in the schema list, + i.e., with same identifier, possibly different location, + but different version. + + For YANG data models, version is the value of the most + recent YANG 'revision' statement in the module or + submodule, or the empty string if no 'revision' statement + is present."; + } + + leaf format { + type identityref { + base schema-format; + } + description + "The data modeling language the schema is written + in (currently xsd, yang, yin, rng, or rnc). + For YANG data models, 'yang' format MUST be supported and + 'yin' format MAY also be provided."; + } + + leaf namespace { + type inet:uri; + mandatory true; + description + "The XML namespace defined by the data model. + + For YANG data models, this is the module's namespace. + If the list entry describes a submodule, this field + contains the namespace of the module to which the + submodule belongs."; + } + + leaf-list location { + type union { + type enumeration { + enum "NETCONF" { + value 0; + } + } + type inet:uri; + } + description + "One or more locations from which the schema can be + retrieved. This list SHOULD contain at least one + entry per schema. + + A schema entry may be located on a remote file system + (e.g., reference to file system for ftp retrieval) or + retrieved directly from a server supporting the + operation (denoted by the value 'NETCONF')."; + } + } // list schema + } // container schemas + + container sessions { + description + "The sessions container includes session-specific data for + NETCONF management sessions. The session list MUST include + all currently active NETCONF sessions."; + list session { + key "session-id"; + description + "All NETCONF sessions managed by the NETCONF server + MUST be reported in this list."; + leaf session-id { + type uint32 { + range "1..max"; + } + description + "Unique identifier for the session. This value is the + NETCONF session identifier, as defined in RFC 4741."; + reference + "RFC 4741: NETCONF Configuration Protocol"; + + } + + leaf transport { + type identityref { + base transport; + } + mandatory true; + description + "Identifies the transport for each session, e.g., + 'netconf-ssh', 'netconf-soap', etc."; + } + + leaf username { + type string; + mandatory true; + description + "The username is the client identity that was authenticated + by the NETCONF transport protocol. The algorithm used to + derive the username is NETCONF transport protocol specific + and in addition specific to the authentication mechanism + used by the NETCONF transport protocol."; + } + + leaf source-host { + type inet:host; + description + "Host identifier of the NETCONF client. The value + returned is implementation specific (e.g., hostname, + IPv4 address, IPv6 address)"; + } + + leaf login-time { + type yang:date-and-time; + mandatory true; + description + "Time at the server at which the session was established."; + } + + uses common-counters { + description + "Per-session counters. Zero based with following reset + behaviour: + - at start of a session + - when max value is reached"; + } + } // list session + } // container sessions + + container statistics { + description + "Statistical data pertaining to the NETCONF server."; + leaf netconf-start-time { + type yang:date-and-time; + description + "Date and time at which the management subsystem was + started."; + } + + leaf in-bad-hellos { + type yang:zero-based-counter32; + description + "Number of sessions silently dropped because an + invalid message was received. This includes + messages with a 'session-id' attribute, bad namespace, and + bad capability declarations."; + } + + leaf in-sessions { + type yang:zero-based-counter32; + description + "Number of sessions started. This counter is incremented + when a message with a is sent. + + 'in-sessions' - 'in-bad-hellos' = + 'number of correctly started netconf sessions'"; + } + + leaf dropped-sessions { + type yang:zero-based-counter32; + description + "Number of sessions that were abnormally terminated, e.g., + due to idle timeout or transport close. This counter is not + incremented when a session is properly closed by a + operation, or killed by a + operation."; + } + + uses common-counters { + description + "Global counters, accumulated from all sessions. + Zero based with following reset behaviour: + - re-initialization of NETCONF server + - when max value is reached"; + } + } // container statistics + } // container netconf-state + + rpc get-schema { + description + "This operation is used to retrieve a schema from the + NETCONF server. + + Positive Response: + The NETCONF server returns the requested schema. + + Negative Response: + If requested schema does not exist, the is + 'invalid-value'. + + If more than one schema matches the requested parameters, the + is 'operation-failed', and is + 'data-not-unique'."; + input { + leaf identifier { + type string; + mandatory true; + description + "Identifier for the schema list entry."; + } + + leaf version { + type string; + description + "Version of the schema requested. If this parameter is not + present, and more than one version of the schema exists on + the server, a 'data-not-unique' error is returned, as + described above."; + } + + leaf format { + type identityref { + base schema-format; + } + description + "The data modeling language of the schema. If this + parameter is not present, and more than one formats of + the schema exists on the server, a 'data-not-unique' error + is returned, as described above."; + } + } + + output { + anyxml data { + description + "Contains the schema content."; + } + } + } // rpc get-schema +} // module \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-yang-types.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-yang-types.yang new file mode 100644 index 0000000000..51d9f8b887 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-yang-types.yang @@ -0,0 +1,396 @@ + module ietf-yang-types { + + namespace "urn:ietf:params:xml:ns:yang:ietf-yang-types"; + prefix "yang"; + + organization + "IETF NETMOD (NETCONF Data Modeling Language) Working Group"; + + contact + "WG Web: + WG List: + + WG Chair: David Partain + + + WG Chair: David Kessens + + + Editor: Juergen Schoenwaelder + "; + + description + "This module contains a collection of generally useful derived + YANG data types. + + Copyright (c) 2010 IETF Trust and the persons identified as + authors of the code. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, is permitted pursuant to, and subject to the license + terms contained in, the Simplified BSD License set forth in Section + 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info). + + This version of this YANG module is part of RFC 6021; see + the RFC itself for full legal notices."; + + revision 2010-09-24 { + description + "Initial revision."; + reference + "RFC 6021: Common YANG Data Types"; + } + + /*** collection of counter and gauge types ***/ + + typedef counter32 { + type uint32; + description + "The counter32 type represents a non-negative integer + that monotonically increases until it reaches a + maximum value of 2^32-1 (4294967295 decimal), when it + wraps around and starts increasing again from zero. + + Counters have no defined 'initial' value, and thus, a + single value of a counter has (in general) no information + content. Discontinuities in the monotonically increasing + value normally occur at re-initialization of the + management system, and at other times as specified in the + description of a schema node using this type. If such + other times can occur, for example, the creation of + a schema node of type counter32 at times other than + re-initialization, then a corresponding schema node + should be defined, with an appropriate type, to indicate + the last discontinuity. + + The counter32 type should not be used for configuration + schema nodes. A default statement SHOULD NOT be used in + combination with the type counter32. + + In the value set and its semantics, this type is equivalent + to the Counter32 type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 (SMIv2)"; + } + + typedef zero-based-counter32 { + type yang:counter32; + default "0"; + description + "The zero-based-counter32 type represents a counter32 + that has the defined 'initial' value zero. + + A schema node of this type will be set to zero (0) on creation + and will thereafter increase monotonically until it reaches + a maximum value of 2^32-1 (4294967295 decimal), when it + wraps around and starts increasing again from zero. + + Provided that an application discovers a new schema node + of this type within the minimum time to wrap, it can use the + 'initial' value as a delta. It is important for a management + station to be aware of this minimum time and the actual time + between polls, and to discard data if the actual time is too + long or there is no defined minimum time. + + In the value set and its semantics, this type is equivalent + to the ZeroBasedCounter32 textual convention of the SMIv2."; + reference + "RFC 4502: Remote Network Monitoring Management Information + Base Version 2"; + } + + typedef counter64 { + type uint64; + description + "The counter64 type represents a non-negative integer + that monotonically increases until it reaches a + maximum value of 2^64-1 (18446744073709551615 decimal), + when it wraps around and starts increasing again from zero. + + Counters have no defined 'initial' value, and thus, a + single value of a counter has (in general) no information + content. Discontinuities in the monotonically increasing + value normally occur at re-initialization of the + management system, and at other times as specified in the + description of a schema node using this type. If such + other times can occur, for example, the creation of + a schema node of type counter64 at times other than + re-initialization, then a corresponding schema node + should be defined, with an appropriate type, to indicate + the last discontinuity. + + The counter64 type should not be used for configuration + schema nodes. A default statement SHOULD NOT be used in + combination with the type counter64. + + In the value set and its semantics, this type is equivalent + to the Counter64 type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 (SMIv2)"; + } + + typedef zero-based-counter64 { + type yang:counter64; + default "0"; + description + "The zero-based-counter64 type represents a counter64 that + has the defined 'initial' value zero. + + A schema node of this type will be set to zero (0) on creation + and will thereafter increase monotonically until it reaches + a maximum value of 2^64-1 (18446744073709551615 decimal), + when it wraps around and starts increasing again from zero. + + Provided that an application discovers a new schema node + of this type within the minimum time to wrap, it can use the + 'initial' value as a delta. It is important for a management + station to be aware of this minimum time and the actual time + between polls, and to discard data if the actual time is too + long or there is no defined minimum time. + + In the value set and its semantics, this type is equivalent + to the ZeroBasedCounter64 textual convention of the SMIv2."; + reference + "RFC 2856: Textual Conventions for Additional High Capacity + Data Types"; + } + + typedef gauge32 { + type uint32; + description + "The gauge32 type represents a non-negative integer, which + may increase or decrease, but shall never exceed a maximum + value, nor fall below a minimum value. The maximum value + cannot be greater than 2^32-1 (4294967295 decimal), and + the minimum value cannot be smaller than 0. The value of + a gauge32 has its maximum value whenever the information + being modeled is greater than or equal to its maximum + value, and has its minimum value whenever the information + being modeled is smaller than or equal to its minimum value. + If the information being modeled subsequently decreases + below (increases above) the maximum (minimum) value, the + gauge32 also decreases (increases). + + In the value set and its semantics, this type is equivalent + to the Gauge32 type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 (SMIv2)"; + } + + typedef gauge64 { + type uint64; + description + "The gauge64 type represents a non-negative integer, which + may increase or decrease, but shall never exceed a maximum + value, nor fall below a minimum value. The maximum value + cannot be greater than 2^64-1 (18446744073709551615), and + the minimum value cannot be smaller than 0. The value of + a gauge64 has its maximum value whenever the information + being modeled is greater than or equal to its maximum + value, and has its minimum value whenever the information + being modeled is smaller than or equal to its minimum value. + If the information being modeled subsequently decreases + below (increases above) the maximum (minimum) value, the + gauge64 also decreases (increases). + + In the value set and its semantics, this type is equivalent + to the CounterBasedGauge64 SMIv2 textual convention defined + in RFC 2856"; + reference + "RFC 2856: Textual Conventions for Additional High Capacity + Data Types"; + } + + /*** collection of identifier related types ***/ + + typedef object-identifier { + type string { + pattern '(([0-1](\.[1-3]?[0-9]))|(2\.(0|([1-9]\d*))))' + + '(\.(0|([1-9]\d*)))*'; + } + description + "The object-identifier type represents administratively + assigned names in a registration-hierarchical-name tree. + + Values of this type are denoted as a sequence of numerical + non-negative sub-identifier values. Each sub-identifier + value MUST NOT exceed 2^32-1 (4294967295). Sub-identifiers + are separated by single dots and without any intermediate + whitespace. + + The ASN.1 standard restricts the value space of the first + sub-identifier to 0, 1, or 2. Furthermore, the value space + of the second sub-identifier is restricted to the range + 0 to 39 if the first sub-identifier is 0 or 1. Finally, + the ASN.1 standard requires that an object identifier + has always at least two sub-identifier. The pattern + captures these restrictions. + + Although the number of sub-identifiers is not limited, + module designers should realize that there may be + implementations that stick with the SMIv2 limit of 128 + sub-identifiers. + + This type is a superset of the SMIv2 OBJECT IDENTIFIER type + since it is not restricted to 128 sub-identifiers. Hence, + this type SHOULD NOT be used to represent the SMIv2 OBJECT + IDENTIFIER type, the object-identifier-128 type SHOULD be + used instead."; + reference + "ISO9834-1: Information technology -- Open Systems + Interconnection -- Procedures for the operation of OSI + Registration Authorities: General procedures and top + arcs of the ASN.1 Object Identifier tree"; + } + + + + + typedef object-identifier-128 { + type object-identifier { + pattern '\d*(\.\d*){1,127}'; + } + description + "This type represents object-identifiers restricted to 128 + sub-identifiers. + + In the value set and its semantics, this type is equivalent + to the OBJECT IDENTIFIER type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 (SMIv2)"; + } + + /*** collection of date and time related types ***/ + + typedef date-and-time { + type string { + pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?' + + '(Z|[\+\-]\d{2}:\d{2})'; + } + description + "The date-and-time type is a profile of the ISO 8601 + standard for representation of dates and times using the + Gregorian calendar. The profile is defined by the + date-time production in Section 5.6 of RFC 3339. + + The date-and-time type is compatible with the dateTime XML + schema type with the following notable exceptions: + + (a) The date-and-time type does not allow negative years. + + (b) The date-and-time time-offset -00:00 indicates an unknown + time zone (see RFC 3339) while -00:00 and +00:00 and Z all + represent the same time zone in dateTime. + + (c) The canonical format (see below) of data-and-time values + differs from the canonical format used by the dateTime XML + schema type, which requires all times to be in UTC using the + time-offset 'Z'. + + This type is not equivalent to the DateAndTime textual + convention of the SMIv2 since RFC 3339 uses a different + separator between full-date and full-time and provides + higher resolution of time-secfrac. + + The canonical format for date-and-time values with a known time + zone uses a numeric time zone offset that is calculated using + the device's configured known offset to UTC time. A change of + the device's offset to UTC time will cause date-and-time values + to change accordingly. Such changes might happen periodically + in case a server follows automatically daylight saving time + (DST) time zone offset changes. The canonical format for + date-and-time values with an unknown time zone (usually referring + to the notion of local time) uses the time-offset -00:00."; + reference + "RFC 3339: Date and Time on the Internet: Timestamps + RFC 2579: Textual Conventions for SMIv2 + XSD-TYPES: XML Schema Part 2: Datatypes Second Edition"; + } + + typedef timeticks { + type uint32; + description + "The timeticks type represents a non-negative integer that + represents the time, modulo 2^32 (4294967296 decimal), in + hundredths of a second between two epochs. When a schema + node is defined that uses this type, the description of + the schema node identifies both of the reference epochs. + + In the value set and its semantics, this type is equivalent + to the TimeTicks type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 (SMIv2)"; + } + + typedef timestamp { + type yang:timeticks; + description + "The timestamp type represents the value of an associated + timeticks schema node at which a specific occurrence happened. + The specific occurrence must be defined in the description + of any schema node defined using this type. When the specific + occurrence occurred prior to the last time the associated + timeticks attribute was zero, then the timestamp value is + zero. Note that this requires all timestamp values to be + reset to zero when the value of the associated timeticks + attribute reaches 497+ days and wraps around to zero. + + The associated timeticks schema node must be specified + in the description of any schema node using this type. + + In the value set and its semantics, this type is equivalent + to the TimeStamp textual convention of the SMIv2."; + reference + "RFC 2579: Textual Conventions for SMIv2"; + } + + /*** collection of generic address types ***/ + + typedef phys-address { + type string { + pattern '([0-9a-fA-F]{2}(:[0-9a-fA-F]{2})*)?'; + } + description + "Represents media- or physical-level addresses represented + as a sequence octets, each octet represented by two hexadecimal + numbers. Octets are separated by colons. The canonical + representation uses lowercase characters. + + In the value set and its semantics, this type is equivalent + to the PhysAddress textual convention of the SMIv2."; + reference + "RFC 2579: Textual Conventions for SMIv2"; + } + + typedef mac-address { + type string { + pattern '[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}'; + } + description + "The mac-address type represents an IEEE 802 MAC address. + The canonical representation uses lowercase characters. + + In the value set and its semantics, this type is equivalent + to the MacAddress textual convention of the SMIv2."; + reference + "IEEE 802: IEEE Standard for Local and Metropolitan Area + Networks: Overview and Architecture + RFC 2579: Textual Conventions for SMIv2"; + } + + /*** collection of XML specific types ***/ + + typedef xpath1.0 { + type string; + description + "This type represents an XPATH 1.0 expression. + + When a schema node is defined that uses this type, the + description of the schema node MUST specify the XPath + context in which the XPath expression is evaluated."; + reference + "XPATH: XML Path Language (XPath) Version 1.0"; + } + + } diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-yang-types@2013-05-16.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-yang-types@2013-05-16.yang new file mode 100644 index 0000000000..6c82d9dea6 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-yang-types@2013-05-16.yang @@ -0,0 +1,471 @@ +module ietf-yang-types { + + namespace "urn:ietf:params:xml:ns:yang:ietf-yang-types"; + prefix "yang"; + + organization + "IETF NETMOD (NETCONF Data Modeling Language) Working Group"; + + contact + "WG Web: + WG List: + + WG Chair: David Kessens + + + WG Chair: Juergen Schoenwaelder + + + Editor: Juergen Schoenwaelder + "; + + description + "This module contains a collection of generally useful derived + YANG data types. + + Copyright (c) 2013 IETF Trust and the persons identified as + authors of the code. All rights reserved. + + Redistribution and use in source and binary forms, with or + without modification, is permitted pursuant to, and subject + to the license terms contained in, the Simplified BSD License + set forth in Section 4.c of the IETF Trust's Legal Provisions + Relating to IETF Documents + (http://trustee.ietf.org/license-info). + + This version of this YANG module is part of RFC XXXX; see + the RFC itself for full legal notices."; + + revision 2013-05-16 { + description + "This revision adds the following new data types: + - yang-identifier + - hex-string + - uuid + - dotted-quad"; + reference + "RFC XXXX: Common YANG Data Types"; + } + + revision 2010-09-24 { + description + "Initial revision."; + reference + "RFC 6021: Common YANG Data Types"; + } + + /*** collection of counter and gauge types ***/ + + typedef counter32 { + type uint32; + description + "The counter32 type represents a non-negative integer + that monotonically increases until it reaches a + maximum value of 2^32-1 (4294967295 decimal), when it + wraps around and starts increasing again from zero. + + Counters have no defined 'initial' value, and thus, a + single value of a counter has (in general) no information + content. Discontinuities in the monotonically increasing + value normally occur at re-initialization of the + management system, and at other times as specified in the + description of a schema node using this type. If such + other times can occur, for example, the creation of + a schema node of type counter32 at times other than + re-initialization, then a corresponding schema node + should be defined, with an appropriate type, to indicate + the last discontinuity. + + The counter32 type should not be used for configuration + schema nodes. A default statement SHOULD NOT be used in + combination with the type counter32. + + In the value set and its semantics, this type is equivalent + to the Counter32 type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 + (SMIv2)"; + } + + typedef zero-based-counter32 { + type yang:counter32; + default "0"; + description + "The zero-based-counter32 type represents a counter32 + that has the defined 'initial' value zero. + + A schema node of this type will be set to zero (0) on creation + and will thereafter increase monotonically until it reaches + a maximum value of 2^32-1 (4294967295 decimal), when it + wraps around and starts increasing again from zero. + + Provided that an application discovers a new schema node + of this type within the minimum time to wrap, it can use the + 'initial' value as a delta. It is important for a management + station to be aware of this minimum time and the actual time + between polls, and to discard data if the actual time is too + long or there is no defined minimum time. + + In the value set and its semantics, this type is equivalent + to the ZeroBasedCounter32 textual convention of the SMIv2."; + reference + "RFC 4502: Remote Network Monitoring Management Information + Base Version 2"; + } + + typedef counter64 { + type uint64; + description + "The counter64 type represents a non-negative integer + that monotonically increases until it reaches a + maximum value of 2^64-1 (18446744073709551615 decimal), + when it wraps around and starts increasing again from zero. + + Counters have no defined 'initial' value, and thus, a + single value of a counter has (in general) no information + content. Discontinuities in the monotonically increasing + value normally occur at re-initialization of the + management system, and at other times as specified in the + description of a schema node using this type. If such + other times can occur, for example, the creation of + a schema node of type counter64 at times other than + re-initialization, then a corresponding schema node + should be defined, with an appropriate type, to indicate + the last discontinuity. + + The counter64 type should not be used for configuration + schema nodes. A default statement SHOULD NOT be used in + combination with the type counter64. + + In the value set and its semantics, this type is equivalent + to the Counter64 type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 + (SMIv2)"; + } + + typedef zero-based-counter64 { + type yang:counter64; + default "0"; + description + "The zero-based-counter64 type represents a counter64 that + has the defined 'initial' value zero. + + A schema node of this type will be set to zero (0) on creation + and will thereafter increase monotonically until it reaches + a maximum value of 2^64-1 (18446744073709551615 decimal), + when it wraps around and starts increasing again from zero. + + Provided that an application discovers a new schema node + of this type within the minimum time to wrap, it can use the + 'initial' value as a delta. It is important for a management + station to be aware of this minimum time and the actual time + between polls, and to discard data if the actual time is too + long or there is no defined minimum time. + + In the value set and its semantics, this type is equivalent + to the ZeroBasedCounter64 textual convention of the SMIv2."; + reference + "RFC 2856: Textual Conventions for Additional High Capacity + Data Types"; + } + + typedef gauge32 { + type uint32; + description + "The gauge32 type represents a non-negative integer, which + may increase or decrease, but shall never exceed a maximum + value, nor fall below a minimum value. The maximum value + cannot be greater than 2^32-1 (4294967295 decimal), and + the minimum value cannot be smaller than 0. The value of + a gauge32 has its maximum value whenever the information + being modeled is greater than or equal to its maximum + value, and has its minimum value whenever the information + being modeled is smaller than or equal to its minimum value. + If the information being modeled subsequently decreases + below (increases above) the maximum (minimum) value, the + gauge32 also decreases (increases). + + In the value set and its semantics, this type is equivalent + to the Gauge32 type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 + (SMIv2)"; + } + + typedef gauge64 { + type uint64; + description + "The gauge64 type represents a non-negative integer, which + may increase or decrease, but shall never exceed a maximum + value, nor fall below a minimum value. The maximum value + cannot be greater than 2^64-1 (18446744073709551615), and + the minimum value cannot be smaller than 0. The value of + a gauge64 has its maximum value whenever the information + being modeled is greater than or equal to its maximum + value, and has its minimum value whenever the information + being modeled is smaller than or equal to its minimum value. + If the information being modeled subsequently decreases + below (increases above) the maximum (minimum) value, the + gauge64 also decreases (increases). + + In the value set and its semantics, this type is equivalent + to the CounterBasedGauge64 SMIv2 textual convention defined + in RFC 2856"; + reference + "RFC 2856: Textual Conventions for Additional High Capacity + Data Types"; + } + + /*** collection of identifier related types ***/ + + typedef object-identifier { + type string { + pattern '(([0-1](\.[1-3]?[0-9]))|(2\.(0|([1-9]\d*))))' + + '(\.(0|([1-9]\d*)))*'; + } + description + "The object-identifier type represents administratively + assigned names in a registration-hierarchical-name tree. + + Values of this type are denoted as a sequence of numerical + non-negative sub-identifier values. Each sub-identifier + value MUST NOT exceed 2^32-1 (4294967295). Sub-identifiers + are separated by single dots and without any intermediate + whitespace. + + The ASN.1 standard restricts the value space of the first + sub-identifier to 0, 1, or 2. Furthermore, the value space + of the second sub-identifier is restricted to the range + 0 to 39 if the first sub-identifier is 0 or 1. Finally, + the ASN.1 standard requires that an object identifier + has always at least two sub-identifier. The pattern + captures these restrictions. + + Although the number of sub-identifiers is not limited, + module designers should realize that there may be + implementations that stick with the SMIv2 limit of 128 + sub-identifiers. + + This type is a superset of the SMIv2 OBJECT IDENTIFIER type + since it is not restricted to 128 sub-identifiers. Hence, + this type SHOULD NOT be used to represent the SMIv2 OBJECT + IDENTIFIER type, the object-identifier-128 type SHOULD be + used instead."; + reference + "ISO9834-1: Information technology -- Open Systems + Interconnection -- Procedures for the operation of OSI + Registration Authorities: General procedures and top + arcs of the ASN.1 Object Identifier tree"; + } + + typedef object-identifier-128 { + type object-identifier { + pattern '\d*(\.\d*){1,127}'; + } + description + "This type represents object-identifiers restricted to 128 + sub-identifiers. + + In the value set and its semantics, this type is equivalent + to the OBJECT IDENTIFIER type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 + (SMIv2)"; + } + + typedef yang-identifier { + type string { + length "1..max"; + pattern '[a-zA-Z_][a-zA-Z0-9\-_.]*'; + pattern '.|..|[^xX].*|.[^mM].*|..[^lL].*'; + } + description + "A YANG identifier string as defined in RFC 6020, page 163. + An identifier must start with an alphabetic character or + an underscore followed by an arbitrary sequence of + alphabetic or numeric characters, underscores, hyphens + or dots. + + A YANG identifier MUST NOT start with any possible + combination of the lower-case or upper-case character + sequence 'xml'."; + reference + "RFC 6020: YANG - A Data Modeling Language for the Network + Configuration Protocol (NETCONF)"; + } + + /*** collection of date and time related types ***/ + + typedef date-and-time { + type string { + pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?' + + '(Z|[\+\-]\d{2}:\d{2})'; + } + description + "The date-and-time type is a profile of the ISO 8601 + standard for representation of dates and times using the + Gregorian calendar. The profile is defined by the + date-time production in Section 5.6 of RFC 3339. + + The date-and-time type is compatible with the dateTime XML + schema type with the following notable exceptions: + + (a) The date-and-time type does not allow negative years. + + (b) The date-and-time time-offset -00:00 indicates an unknown + time zone (see RFC 3339) while -00:00 and +00:00 and Z all + represent the same time zone in dateTime. + + (c) The canonical format (see below) of data-and-time values + differs from the canonical format used by the dateTime XML + schema type, which requires all times to be in UTC using + the time-offset 'Z'. + + This type is not equivalent to the DateAndTime textual + convention of the SMIv2 since RFC 3339 uses a different + separator between full-date and full-time and provides + higher resolution of time-secfrac. + The canonical format for date-and-time values with a known time + zone uses a numeric time zone offset that is calculated using + the device's configured known offset to UTC time. A change of + the device's offset to UTC time will cause date-and-time values + to change accordingly. Such changes might happen periodically + in case a server follows automatically daylight saving time + (DST) time zone offset changes. The canonical format for + date-and-time values with an unknown time zone (usually + referring to the notion of local time) uses the time-offset + -00:00."; + reference + "RFC 3339: Date and Time on the Internet: Timestamps + RFC 2579: Textual Conventions for SMIv2 + XSD-TYPES: XML Schema Part 2: Datatypes Second Edition"; + } + + typedef timeticks { + type uint32; + description + "The timeticks type represents a non-negative integer that + represents the time, modulo 2^32 (4294967296 decimal), in + hundredths of a second between two epochs. When a schema + node is defined that uses this type, the description of + the schema node identifies both of the reference epochs. + + In the value set and its semantics, this type is equivalent + to the TimeTicks type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 + (SMIv2)"; + } + + typedef timestamp { + type yang:timeticks; + description + "The timestamp type represents the value of an associated + timeticks schema node at which a specific occurrence + happened. The specific occurrence must be defined in the + description of any schema node defined using this type. When + the specific occurrence occurred prior to the last time the + associated timeticks attribute was zero, then the timestamp + value is zero. Note that this requires all timestamp values + to be reset to zero when the value of the associated timeticks + attribute reaches 497+ days and wraps around to zero. + + The associated timeticks schema node must be specified + in the description of any schema node using this type. + In the value set and its semantics, this type is equivalent + to the TimeStamp textual convention of the SMIv2."; + reference + "RFC 2579: Textual Conventions for SMIv2"; + } + + /*** collection of generic address types ***/ + + typedef phys-address { + type string { + pattern '([0-9a-fA-F]{2}(:[0-9a-fA-F]{2})*)?'; + } + description + "Represents media- or physical-level addresses represented + as a sequence octets, each octet represented by two hexadecimal + numbers. Octets are separated by colons. The canonical + representation uses lowercase characters. + + In the value set and its semantics, this type is equivalent + to the PhysAddress textual convention of the SMIv2."; + reference + "RFC 2579: Textual Conventions for SMIv2"; + } + + typedef mac-address { + type string { + pattern '[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}'; + } + description + "The mac-address type represents an IEEE 802 MAC address. + The canonical representation uses lowercase characters. + + In the value set and its semantics, this type is equivalent + to the MacAddress textual convention of the SMIv2."; + reference + "IEEE 802: IEEE Standard for Local and Metropolitan Area + Networks: Overview and Architecture + RFC 2579: Textual Conventions for SMIv2"; + } + + /*** collection of XML specific types ***/ + + typedef xpath1.0 { + type string; + description + "This type represents an XPATH 1.0 expression. + + When a schema node is defined that uses this type, the + description of the schema node MUST specify the XPath + context in which the XPath expression is evaluated."; + reference + "XPATH: XML Path Language (XPath) Version 1.0"; + } + + /*** collection of string types ***/ + + typedef hex-string { + type string { + pattern '([0-9a-fA-F]{2}(:[0-9a-fA-F]{2})*)?'; + } + description + "A hexadecimal string with octets represented as hex digits + separated by colons. The canonical representation uses + lowercase characters."; + } + + typedef uuid { + type string { + pattern '[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-' + + '[0-9a-fA-F]{4}-[0-9a-fA-F]{12}'; + } + description + "A Universally Unique IDentifier in the string representation + defined in RFC 4122. The canonical representation uses + lowercase characters. + + The following is an example of a UUID in string representation: + f81d4fae-7dec-11d0-a765-00a0c91e6bf6 + "; + reference + "RFC 4122: A Universally Unique IDentifier (UUID) URN + Namespace"; + } + + typedef dotted-quad { + type string { + pattern + '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}' + + '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'; + } + description + "An unsigned 32-bit number expressed in the dotted-quad + notation, i.e., four octets written as decimal numbers + and separated with the '.' (full stop) character."; + } +} \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-yang-types@2013-07-15.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-yang-types@2013-07-15.yang new file mode 100644 index 0000000000..bdff18cc4b --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/full/ietf-yang-types@2013-07-15.yang @@ -0,0 +1,467 @@ +module ietf-yang-types { + + namespace "urn:ietf:params:xml:ns:yang:ietf-yang-types"; + prefix "yang"; + + organization + "IETF NETMOD (NETCONF Data Modeling Language) Working Group"; + + contact + "WG Web: + WG List: + WG Chair: David Kessens + + + WG Chair: Juergen Schoenwaelder + + + Editor: Juergen Schoenwaelder + "; + + description + "This module contains a collection of generally useful derived + YANG data types. + + Copyright (c) 2013 IETF Trust and the persons identified as + authors of the code. All rights reserved. + + Redistribution and use in source and binary forms, with or + without modification, is permitted pursuant to, and subject + to the license terms contained in, the Simplified BSD License + set forth in Section 4.c of the IETF Trust's Legal Provisions + Relating to IETF Documents + (http://trustee.ietf.org/license-info). + + This version of this YANG module is part of RFC 6991; see + the RFC itself for full legal notices."; + + revision 2013-07-15 { + description + "This revision adds the following new data types: + - yang-identifier + - hex-string + - uuid + - dotted-quad"; + reference + "RFC 6991: Common YANG Data Types"; + } + + revision 2010-09-24 { + description + "Initial revision."; + reference + "RFC 6021: Common YANG Data Types"; + } + + /*** collection of counter and gauge types ***/ + + typedef counter32 { + type uint32; + description + "The counter32 type represents a non-negative integer + that monotonically increases until it reaches a + maximum value of 2^32-1 (4294967295 decimal), when it + wraps around and starts increasing again from zero. + + Counters have no defined 'initial' value, and thus, a + single value of a counter has (in general) no information + content. Discontinuities in the monotonically increasing + value normally occur at re-initialization of the + management system, and at other times as specified in the + description of a schema node using this type. If such + other times can occur, for example, the creation of + a schema node of type counter32 at times other than + re-initialization, then a corresponding schema node + should be defined, with an appropriate type, to indicate + the last discontinuity. + + The counter32 type should not be used for configuration + schema nodes. A default statement SHOULD NOT be used in + combination with the type counter32. + + In the value set and its semantics, this type is equivalent + to the Counter32 type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 + (SMIv2)"; + } + + typedef zero-based-counter32 { + type yang:counter32; + default "0"; + description + "The zero-based-counter32 type represents a counter32 + that has the defined 'initial' value zero. + + A schema node of this type will be set to zero (0) on creation + and will thereafter increase monotonically until it reaches + a maximum value of 2^32-1 (4294967295 decimal), when it + wraps around and starts increasing again from zero. + + Provided that an application discovers a new schema node + of this type within the minimum time to wrap, it can use the + 'initial' value as a delta. It is important for a management + station to be aware of this minimum time and the actual time + between polls, and to discard data if the actual time is too + long or there is no defined minimum time. + In the value set and its semantics, this type is equivalent + to the ZeroBasedCounter32 textual convention of the SMIv2."; + reference + "RFC 4502: Remote Network Monitoring Management Information + Base Version 2"; + } + + typedef counter64 { + type uint64; + description + "The counter64 type represents a non-negative integer + that monotonically increases until it reaches a + maximum value of 2^64-1 (18446744073709551615 decimal), + when it wraps around and starts increasing again from zero. + + Counters have no defined 'initial' value, and thus, a + single value of a counter has (in general) no information + content. Discontinuities in the monotonically increasing + value normally occur at re-initialization of the + management system, and at other times as specified in the + description of a schema node using this type. If such + other times can occur, for example, the creation of + a schema node of type counter64 at times other than + re-initialization, then a corresponding schema node + should be defined, with an appropriate type, to indicate + the last discontinuity. + + The counter64 type should not be used for configuration + schema nodes. A default statement SHOULD NOT be used in + combination with the type counter64. + + In the value set and its semantics, this type is equivalent + to the Counter64 type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 + (SMIv2)"; + } + + typedef zero-based-counter64 { + type yang:counter64; + default "0"; + description + "The zero-based-counter64 type represents a counter64 that + has the defined 'initial' value zero. + A schema node of this type will be set to zero (0) on creation + and will thereafter increase monotonically until it reaches + a maximum value of 2^64-1 (18446744073709551615 decimal), + when it wraps around and starts increasing again from zero. + + Provided that an application discovers a new schema node + of this type within the minimum time to wrap, it can use the + 'initial' value as a delta. It is important for a management + station to be aware of this minimum time and the actual time + between polls, and to discard data if the actual time is too + long or there is no defined minimum time. + + In the value set and its semantics, this type is equivalent + to the ZeroBasedCounter64 textual convention of the SMIv2."; + reference + "RFC 2856: Textual Conventions for Additional High Capacity + Data Types"; + } + + typedef gauge32 { + type uint32; + description + "The gauge32 type represents a non-negative integer, which + may increase or decrease, but shall never exceed a maximum + value, nor fall below a minimum value. The maximum value + cannot be greater than 2^32-1 (4294967295 decimal), and + the minimum value cannot be smaller than 0. The value of + a gauge32 has its maximum value whenever the information + being modeled is greater than or equal to its maximum + value, and has its minimum value whenever the information + being modeled is smaller than or equal to its minimum value. + If the information being modeled subsequently decreases + below (increases above) the maximum (minimum) value, the + gauge32 also decreases (increases). + + In the value set and its semantics, this type is equivalent + to the Gauge32 type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 + (SMIv2)"; + } + + typedef gauge64 { + type uint64; + description + "The gauge64 type represents a non-negative integer, which + may increase or decrease, but shall never exceed a maximum + value, nor fall below a minimum value. The maximum value + cannot be greater than 2^64-1 (18446744073709551615), and + the minimum value cannot be smaller than 0. The value of + a gauge64 has its maximum value whenever the information + being modeled is greater than or equal to its maximum + value, and has its minimum value whenever the information + being modeled is smaller than or equal to its minimum value. + If the information being modeled subsequently decreases + below (increases above) the maximum (minimum) value, the + gauge64 also decreases (increases). + + In the value set and its semantics, this type is equivalent + to the CounterBasedGauge64 SMIv2 textual convention defined + in RFC 2856"; + reference + "RFC 2856: Textual Conventions for Additional High Capacity + Data Types"; + } + + /*** collection of identifier-related types ***/ + + typedef object-identifier { + type string { + pattern '(([0-1](\.[1-3]?[0-9]))|(2\.(0|([1-9]\d*))))' + + '(\.(0|([1-9]\d*)))*'; + } + description + "The object-identifier type represents administratively + assigned names in a registration-hierarchical-name tree. + + Values of this type are denoted as a sequence of numerical + non-negative sub-identifier values. Each sub-identifier + value MUST NOT exceed 2^32-1 (4294967295). Sub-identifiers + are separated by single dots and without any intermediate + whitespace. + + The ASN.1 standard restricts the value space of the first + sub-identifier to 0, 1, or 2. Furthermore, the value space + of the second sub-identifier is restricted to the range + 0 to 39 if the first sub-identifier is 0 or 1. Finally, + the ASN.1 standard requires that an object identifier + has always at least two sub-identifiers. The pattern + captures these restrictions. + + Although the number of sub-identifiers is not limited, + module designers should realize that there may be + implementations that stick with the SMIv2 limit of 128 + sub-identifiers. + This type is a superset of the SMIv2 OBJECT IDENTIFIER type + since it is not restricted to 128 sub-identifiers. Hence, + this type SHOULD NOT be used to represent the SMIv2 OBJECT + IDENTIFIER type; the object-identifier-128 type SHOULD be + used instead."; + reference + "ISO9834-1: Information technology -- Open Systems + Interconnection -- Procedures for the operation of OSI + Registration Authorities: General procedures and top + arcs of the ASN.1 Object Identifier tree"; + } + + typedef object-identifier-128 { + type object-identifier { + pattern '\d*(\.\d*){1,127}'; + } + description + "This type represents object-identifiers restricted to 128 + sub-identifiers. + + In the value set and its semantics, this type is equivalent + to the OBJECT IDENTIFIER type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 + (SMIv2)"; + } + + typedef yang-identifier { + type string { + length "1..max"; + pattern '[a-zA-Z_][a-zA-Z0-9\-_.]*'; + pattern '.|..|[^xX].*|.[^mM].*|..[^lL].*'; + } + description + "A YANG identifier string as defined by the 'identifier' + rule in Section 12 of RFC 6020. An identifier must + start with an alphabetic character or an underscore + followed by an arbitrary sequence of alphabetic or + numeric characters, underscores, hyphens, or dots. + + A YANG identifier MUST NOT start with any possible + combination of the lowercase or uppercase character + sequence 'xml'."; + reference + "RFC 6020: YANG - A Data Modeling Language for the Network + Configuration Protocol (NETCONF)"; + } + /*** collection of types related to date and time***/ + + typedef date-and-time { + type string { + pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?' + + '(Z|[\+\-]\d{2}:\d{2})'; + } + description + "The date-and-time type is a profile of the ISO 8601 + standard for representation of dates and times using the + Gregorian calendar. The profile is defined by the + date-time production in Section 5.6 of RFC 3339. + + The date-and-time type is compatible with the dateTime XML + schema type with the following notable exceptions: + + (a) The date-and-time type does not allow negative years. + + (b) The date-and-time time-offset -00:00 indicates an unknown + time zone (see RFC 3339) while -00:00 and +00:00 and Z + all represent the same time zone in dateTime. + + (c) The canonical format (see below) of data-and-time values + differs from the canonical format used by the dateTime XML + schema type, which requires all times to be in UTC using + the time-offset 'Z'. + + This type is not equivalent to the DateAndTime textual + convention of the SMIv2 since RFC 3339 uses a different + separator between full-date and full-time and provides + higher resolution of time-secfrac. + + The canonical format for date-and-time values with a known time + zone uses a numeric time zone offset that is calculated using + the device's configured known offset to UTC time. A change of + the device's offset to UTC time will cause date-and-time values + to change accordingly. Such changes might happen periodically + in case a server follows automatically daylight saving time + (DST) time zone offset changes. The canonical format for + date-and-time values with an unknown time zone (usually + referring to the notion of local time) uses the time-offset + -00:00."; + reference + "RFC 3339: Date and Time on the Internet: Timestamps + RFC 2579: Textual Conventions for SMIv2 + XSD-TYPES: XML Schema Part 2: Datatypes Second Edition"; + } + typedef timeticks { + type uint32; + description + "The timeticks type represents a non-negative integer that + represents the time, modulo 2^32 (4294967296 decimal), in + hundredths of a second between two epochs. When a schema + node is defined that uses this type, the description of + the schema node identifies both of the reference epochs. + + In the value set and its semantics, this type is equivalent + to the TimeTicks type of the SMIv2."; + reference + "RFC 2578: Structure of Management Information Version 2 + (SMIv2)"; + } + + typedef timestamp { + type yang:timeticks; + description + "The timestamp type represents the value of an associated + timeticks schema node at which a specific occurrence + happened. The specific occurrence must be defined in the + description of any schema node defined using this type. When + the specific occurrence occurred prior to the last time the + associated timeticks attribute was zero, then the timestamp + value is zero. Note that this requires all timestamp values + to be reset to zero when the value of the associated timeticks + attribute reaches 497+ days and wraps around to zero. + + The associated timeticks schema node must be specified + in the description of any schema node using this type. + + In the value set and its semantics, this type is equivalent + to the TimeStamp textual convention of the SMIv2."; + reference + "RFC 2579: Textual Conventions for SMIv2"; + } + + /*** collection of generic address types ***/ + + typedef phys-address { + type string { + pattern '([0-9a-fA-F]{2}(:[0-9a-fA-F]{2})*)?'; + } + description + "Represents media- or physical-level addresses represented + as a sequence octets, each octet represented by two hexadecimal + numbers. Octets are separated by colons. The canonical + representation uses lowercase characters. + + In the value set and its semantics, this type is equivalent + to the PhysAddress textual convention of the SMIv2."; + reference + "RFC 2579: Textual Conventions for SMIv2"; + } + + typedef mac-address { + type string { + pattern '[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}'; + } + description + "The mac-address type represents an IEEE 802 MAC address. + The canonical representation uses lowercase characters. + + In the value set and its semantics, this type is equivalent + to the MacAddress textual convention of the SMIv2."; + reference + "IEEE 802: IEEE Standard for Local and Metropolitan Area + Networks: Overview and Architecture + RFC 2579: Textual Conventions for SMIv2"; + } + + /*** collection of XML-specific types ***/ + + typedef xpath1.0 { + type string; + description + "This type represents an XPATH 1.0 expression. + + When a schema node is defined that uses this type, the + description of the schema node MUST specify the XPath + context in which the XPath expression is evaluated."; + reference + "XPATH: XML Path Language (XPath) Version 1.0"; + } + + /*** collection of string types ***/ + + typedef hex-string { + type string { + pattern '([0-9a-fA-F]{2}(:[0-9a-fA-F]{2})*)?'; + } + description + "A hexadecimal string with octets represented as hex digits + separated by colons. The canonical representation uses + lowercase characters."; + } + + typedef uuid { + type string { + pattern '[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-' + + '[0-9a-fA-F]{4}-[0-9a-fA-F]{12}'; + } + description + "A Universally Unique IDentifier in the string representation + defined in RFC 4122. The canonical representation uses + lowercase characters. + + The following is an example of a UUID in string representation: + f81d4fae-7dec-11d0-a765-00a0c91e6bf6 + "; + reference + "RFC 4122: A Universally Unique IDentifier (UUID) URN + Namespace"; + } + + typedef dotted-quad { + type string { + pattern + '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}' + + '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'; + } + description + "An unsigned 32-bit number expressed in the dotted-quad + notation, i.e., four octets written as decimal numbers + and separated with the '.' (full stop) character."; + } + } \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-05-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-05-02.yang index 283fd414dc..1c8210e000 100644 --- a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-05-02.yang +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-05-02.yang @@ -8,6 +8,8 @@ module importedrevtest { revision 2015-05-02; typedef date-and-time { - type string; + type string { + pattern "[0-9]+"; + } } } \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-06-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-06-02.yang index 6c025039e6..b0104daaff 100644 --- a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-06-02.yang +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-06-02.yang @@ -8,6 +8,8 @@ module importedrevtest { revision 2015-06-02; typedef date-and-time { - type string; + type string { + pattern "[0-9]+"; + } } } \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-08-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-08-02.yang index d532636d77..f50d90b989 100644 --- a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-08-02.yang +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-08-02.yang @@ -8,6 +8,8 @@ module importedrevtest { revision 2015-08-02; typedef date-and-time { - type string; + type string { + pattern "[0-9]+"; + } } } \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-09-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-09-02.yang index 5ad34ecaeb..e4046a4f9b 100644 --- a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-09-02.yang +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-09-02.yang @@ -8,6 +8,8 @@ module importedrevtest { revision 2015-09-02; typedef date-and-time { - type string; + type string { + pattern "[0-9]+"; + } } } \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@z2015-04-02.yang similarity index 67% rename from yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev.yang rename to yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@z2015-04-02.yang index 9be77d0348..ea687936fd 100644 --- a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev.yang +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@z2015-04-02.yang @@ -5,9 +5,11 @@ module importedrevtest { description "This is a test module"; - revision 2015-07-02; + revision 2015-04-02; typedef date-and-time { - type string; + type string { + pattern "[0-9]+"; + } } -} \ No newline at end of file +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-interfaces.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-interfaces.yang new file mode 100644 index 0000000000..24afaad8ca --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-interfaces.yang @@ -0,0 +1,13 @@ +module ietf-interfaces { + + namespace "urn:ietf:params:xml:ns:yang:ietf-interfaces"; + prefix if; + + import ietf-yang-types { prefix yang; revision-date 2010-09-24; } + + revision 2012-11-15; + + leaf last-change { + type yang:date-and-time; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-netconf-monitoring.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-netconf-monitoring.yang new file mode 100644 index 0000000000..5fb888bddf --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-netconf-monitoring.yang @@ -0,0 +1,15 @@ +module ietf-netconf-monitoring { + + yang-version 1; + + namespace + "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"; + + prefix ncm; + + import ietf-yang-types { prefix yang; } + + leaf locked-time { + type yang:date-and-time; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-yang-types.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-yang-types.yang new file mode 100644 index 0000000000..071a24f157 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-yang-types.yang @@ -0,0 +1,14 @@ + module ietf-yang-types { + + namespace "urn:ietf:params:xml:ns:yang:ietf-yang-types"; + prefix "yang"; + + revision 2010-09-24; + + typedef date-and-time { + type string { + pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?' + + '(Z|[\+\-]\d{2}:\d{2})'; + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-yang-types@2013-05-16.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-yang-types@2013-05-16.yang new file mode 100644 index 0000000000..21e9279881 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-yang-types@2013-05-16.yang @@ -0,0 +1,16 @@ +module ietf-yang-types { + + namespace "urn:ietf:params:xml:ns:yang:ietf-yang-types"; + prefix "yang"; + + revision 2013-05-16; + + revision 2010-09-24; + + typedef date-and-time { + type string { + pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?' + + '(Z|[\+\-]\d{2}:\d{2})'; + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-yang-types@2013-07-15.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-yang-types@2013-07-15.yang new file mode 100644 index 0000000000..3ee48ab1b6 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/simple/ietf-yang-types@2013-07-15.yang @@ -0,0 +1,16 @@ +module ietf-yang-types { + + namespace "urn:ietf:params:xml:ns:yang:ietf-yang-types"; + prefix "yang"; + + revision 2013-07-15; + + revision 2010-09-24; + + typedef date-and-time { + type string { + pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?' + + '(Z|[\+\-]\d{2}:\d{2})'; + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/testrev.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/testrev.yang index 2600dd4726..a643c1f298 100644 --- a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/testrev.yang +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/testrev.yang @@ -3,17 +3,17 @@ module testrev { namespace "urn:tstrev:yang"; prefix "tstrev"; - import importedrevtest { - prefix "imprevtst"; - } + import importedrevtest { prefix "imprevtst"; } description "This is a test module"; - revision 2015-07-02; + revision 2001-01-01 { + description "initial version"; + } container mycontainer { leaf myleaf { type imprevtst:date-and-time; } } -} \ No newline at end of file +} -- 2.36.6