From eb6a31778d4f89ec816b7ebf97238aaab809eca8 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Thu, 8 Aug 2013 15:56:22 +0200 Subject: [PATCH] Added model generation from ietf-topology models - Moved precompilation of reusable models to org.opendaylight.yangtools.yang group - Added topology models from draft-clemm-netmod-yang-network-topo-00 - Fixed bug in grouping resolving - Disabled generation of uncessary files for some models Change-Id: I5eafae1fda0e854e60851725921bc8844c2f14e0 Signed-off-by: Tony Tkacik --- .../generator/impl/BindingGeneratorImpl.java | 20 +- .../GroupingDefinitionDependencySort.java | 33 +- .../generator/impl/GenEnumResolvingTest.java | 421 +++--- .../generator/impl/GenTypesSubSetTest.java | 197 ++- .../generator/impl/GeneratedTypesTest.java | 1226 ++++++++--------- .../test/ClassCodeGeneratorTest.java | 4 +- code-generator/pom.xml | 4 + .../samples/modeling-sample/pom.xml | 2 +- model/ietf/ietf-inet-types/pom.xml | 5 +- model/ietf/ietf-ted/pom.xml | 30 + .../src/main/yang/ted@2013-07-12.yang | 301 ++++ model/ietf/ietf-topology-isis/pom.xml | 32 + .../main/yang/isis-topology@2013-07-12.yang | 140 ++ .../ietf/ietf-topology-l3-unicast-igp/pom.xml | 25 + .../l3-unicast-igp-topology@2013-07-12.yang | 232 ++++ model/ietf/ietf-topology-ospf/pom.xml | 31 + .../main/yang/ospf-topology@2013-07-12.yang | 173 +++ model/ietf/ietf-topology/pom.xml | 30 + .../yang/network-topology@2013-07-12.yang | 316 +++++ model/ietf/ietf-yang-types/pom.xml | 5 +- model/ietf/pom.xml | 12 +- model/model-openflow/pom.xml | 10 - model/model-openflow/src/main/yang/.gitignore | 0 model/model-topology-bgp/pom.xml | 10 - model/model-topology/pom.xml | 21 - .../src/main/yang/topology.yang | 160 --- model/pom.xml | 22 +- pom.xml | 2 +- yang/yang-ext/pom.xml | 194 +-- yang/yang-parser-impl/pom.xml | 2 + .../yang/parser/impl/YangParserImpl.java | 2 + 31 files changed, 2424 insertions(+), 1238 deletions(-) create mode 100644 model/ietf/ietf-ted/pom.xml create mode 100644 model/ietf/ietf-ted/src/main/yang/ted@2013-07-12.yang create mode 100644 model/ietf/ietf-topology-isis/pom.xml create mode 100644 model/ietf/ietf-topology-isis/src/main/yang/isis-topology@2013-07-12.yang create mode 100644 model/ietf/ietf-topology-l3-unicast-igp/pom.xml create mode 100644 model/ietf/ietf-topology-l3-unicast-igp/src/main/yang/l3-unicast-igp-topology@2013-07-12.yang create mode 100644 model/ietf/ietf-topology-ospf/pom.xml create mode 100644 model/ietf/ietf-topology-ospf/src/main/yang/ospf-topology@2013-07-12.yang create mode 100644 model/ietf/ietf-topology/pom.xml create mode 100644 model/ietf/ietf-topology/src/main/yang/network-topology@2013-07-12.yang delete mode 100644 model/model-openflow/pom.xml delete mode 100644 model/model-openflow/src/main/yang/.gitignore delete mode 100644 model/model-topology-bgp/pom.xml delete mode 100644 model/model-topology/pom.xml delete mode 100644 model/model-topology/src/main/yang/topology.yang diff --git a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java index b6611accfa..d0cbc34dd2 100644 --- a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java +++ b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java @@ -40,6 +40,7 @@ import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTy import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder; import org.opendaylight.yangtools.sal.binding.yang.types.GroupingDefinitionDependencySort; import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl; +import org.opendaylight.yangtools.yang.binding.DataRoot; import org.opendaylight.yangtools.yang.binding.Notification; import org.opendaylight.yangtools.yang.binding.RpcService; import org.opendaylight.yangtools.yang.common.QName; @@ -97,8 +98,12 @@ public final class BindingGeneratorImpl implements BindingGenerator { final Set modules = context.getModules(); genTypeBuilders = new HashMap<>(); for (final Module module : modules) { + generatedTypes.addAll(allGroupingsToGenTypes(module)); - generatedTypes.add(moduleToDataType(module)); + + if(false == module.getChildNodes().isEmpty()) { + generatedTypes.add(moduleToDataType(module)); + } generatedTypes.addAll(allTypeDefinitionsToGenTypes(module)); generatedTypes.addAll(allContainersToGenTypes(module)); generatedTypes.addAll(allListsToGenTypes(module)); @@ -133,7 +138,9 @@ public final class BindingGeneratorImpl implements BindingGenerator { final List generatedTypes = new ArrayList<>(); generatedTypes.addAll(allGroupingsToGenTypes(contextModule)); - generatedTypes.add(moduleToDataType(contextModule)); + if(false == contextModule.getChildNodes().isEmpty()) { + generatedTypes.add(moduleToDataType(contextModule)); + } generatedTypes.addAll(allTypeDefinitionsToGenTypes(contextModule)); generatedTypes.addAll(allContainersToGenTypes(contextModule)); generatedTypes.addAll(allListsToGenTypes(contextModule)); @@ -305,6 +312,7 @@ public final class BindingGeneratorImpl implements BindingGenerator { final GeneratedTypeBuilder moduleDataTypeBuilder = moduleTypeBuilder(module, "Data"); addInterfaceDefinition(module, moduleDataTypeBuilder); + moduleDataTypeBuilder.addImplementsType(Types.typeForClass(DataRoot.class)); final String basePackageName = moduleNamespaceToPackageName(module); if (moduleDataTypeBuilder != null) { @@ -330,6 +338,11 @@ public final class BindingGeneratorImpl implements BindingGenerator { final String basePackageName = moduleNamespaceToPackageName(module); final Set rpcDefinitions = module.getRpcs(); + + if(rpcDefinitions.isEmpty()) { + return Collections.emptyList(); + } + final List genRPCTypes = new ArrayList<>(); final GeneratedTypeBuilder interfaceBuilder = moduleTypeBuilder(module, "Service"); interfaceBuilder.addImplementsType(Types.typeForClass(RpcService.class)); @@ -1257,6 +1270,9 @@ public final class BindingGeneratorImpl implements BindingGenerator { for (UsesNode usesNode : dataNodeContainer.getUses()) { if (usesNode.getGroupingPath() != null) { GeneratedType genType = allGroupings.get(usesNode.getGroupingPath()); + if(genType == null) { + throw new IllegalStateException("Grouping " +usesNode.getGroupingPath() + "is not resolved for " + builder.getName()); + } builder.addImplementsType(genType); } } diff --git a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/GroupingDefinitionDependencySort.java b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/GroupingDefinitionDependencySort.java index c065cf3a43..cfae12617e 100644 --- a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/GroupingDefinitionDependencySort.java +++ b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/GroupingDefinitionDependencySort.java @@ -8,10 +8,15 @@ package org.opendaylight.yangtools.sal.binding.yang.types; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; +import org.opendaylight.yangtools.yang.model.api.ChoiceNode; +import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.UsesNode; @@ -59,7 +64,7 @@ public class GroupingDefinitionDependencySort { final GroupingNode groupingNode = (GroupingNode) node; final GroupingDefinition groupingDefinition = groupingNode.getGroupingDefinition(); - Set usesNodes = groupingDefinition.getUses(); + Set usesNodes =getAllUsesNodes(groupingDefinition); for (UsesNode usesNode : usesNodes) { SchemaPath schemaPath = usesNode.getGroupingPath(); if (schemaPath != null) { @@ -72,6 +77,32 @@ public class GroupingDefinitionDependencySort { return resultNodes; } + private static Set getAllUsesNodes(DataNodeContainer container) { + Set ret = new HashSet<>(); + ret.addAll(container.getUses()); + + Set groupings = container.getGroupings(); + for (GroupingDefinition groupingDefinition : groupings) { + ret.addAll(getAllUsesNodes(groupingDefinition)); + } + Set children = container.getChildNodes(); + for (DataSchemaNode dataSchemaNode : children) { + if(dataSchemaNode instanceof DataNodeContainer) { + ret.addAll(getAllUsesNodes((DataNodeContainer) dataSchemaNode)); + } else if (dataSchemaNode instanceof ChoiceNode) { + Set cases = ((ChoiceNode) dataSchemaNode).getCases(); + for (ChoiceCaseNode choiceCaseNode : cases) { + ret.addAll(getAllUsesNodes(choiceCaseNode)); + } + + } + } + + return ret; + + } + + private static final class GroupingNode extends NodeImpl { private final GroupingDefinition groupingDefinition; diff --git a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenEnumResolvingTest.java b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenEnumResolvingTest.java index 89389dd173..e9ed3a982f 100644 --- a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenEnumResolvingTest.java +++ b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenEnumResolvingTest.java @@ -1,211 +1,210 @@ -/* - * Copyright (c) 2013 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.sal.binding.generator.impl; - -import static org.junit.Assert.*; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.junit.Test; -import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.Enumeration; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; - -public class GenEnumResolvingTest { - - private SchemaContext resolveSchemaContextFromFiles( - final String... yangFiles) { - final YangModelParser parser = new YangParserImpl(); - - final List inputFiles = new ArrayList(); - for (int i = 0; i < yangFiles.length; ++i) { - inputFiles.add(new File(yangFiles[i])); - } - - final Set modules = parser.parseYangModels(inputFiles); - return parser.resolveSchemaContext(modules); - } - - @Test - public void testLeafEnumResolving() { - final String ietfInterfacesPath = getClass().getResource( - "/enum-test-models/ietf-interfaces@2012-11-15.yang").getPath(); - final String ifTypePath = getClass().getResource( - "/enum-test-models/iana-if-type@2012-06-05.yang").getPath(); - final String yangTypesPath = getClass().getResource( - "/enum-test-models/ietf-yang-types@2010-09-24.yang").getPath(); - - final SchemaContext context = resolveSchemaContextFromFiles( - ietfInterfacesPath, ifTypePath, yangTypesPath); - assertTrue(context != null); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(context); - assertTrue(genTypes != null); - - assertEquals("Expected count of all Generated Types from yang models " + - "is 22", 25, genTypes.size()); - - GeneratedType genInterface = null; - for (final Type type : genTypes) { - if (type instanceof GeneratedType) { - if (type.getName().equals("Interface")) { - genInterface = (GeneratedType) type; - } - } - } - assertNotNull("Generated Type Interface is not present in list of " + - "Generated Types", genInterface); - - Enumeration linkUpDownTrapEnable = null; - Enumeration operStatus = null; - final List enums = genInterface.getEnumerations(); - assertNotNull("Generated Type Interface cannot contain NULL reference" + - " to Enumeration types!", enums); - assertEquals("Generated Type Interface MUST contain 2 Enumeration " + - "Types", 2, enums.size()); - for (final Enumeration e : enums) { - if (e.getName().equals("LinkUpDownTrapEnable")) { - linkUpDownTrapEnable = e; - } else if (e.getName().equals("OperStatus")) { - operStatus = e; - } - } - - assertNotNull("Expected Enum LinkUpDownTrapEnable, but was NULL!", - linkUpDownTrapEnable); - assertNotNull("Expected Enum OperStatus, but was NULL!", operStatus); - - assertNotNull("Enum LinkUpDownTrapEnable MUST contain Values definition " + - "not NULL reference!", linkUpDownTrapEnable.getValues()); - assertNotNull("Enum OperStatus MUST contain Values definition not " + - "NULL reference!", operStatus.getValues()); - assertEquals("Enum LinkUpDownTrapEnable MUST contain 2 values!", 2, - linkUpDownTrapEnable.getValues().size()); - assertEquals("Enum OperStatus MUST contain 7 values!", 7, - operStatus.getValues().size()); - - final List methods = genInterface - .getMethodDefinitions(); - - assertNotNull("Generated Interface cannot contain NULL reference for " + - "Method Signature Definitions!", methods); - - assertEquals("Expected count of method signature definitions is 14", - 14, methods.size()); - Enumeration ianaIfType = null; - for (final MethodSignature method : methods) { - if (method.getName().equals("getType")) { - if (method.getReturnType() instanceof Enumeration) { - ianaIfType = (Enumeration)method.getReturnType(); - } - } - } - - assertNotNull("Method getType MUST return Enumeration Type, " + - "not NULL reference!", ianaIfType); - assertEquals("Enumeration getType MUST contain 272 values!", 272, - ianaIfType.getValues().size()); - } - - @Test - public void testTypedefEnumResolving() { - final String ianaIfTypePath = getClass().getResource( - "/leafref-test-models/iana-if-type@2012-06-05.yang").getPath(); - - final SchemaContext context = resolveSchemaContextFromFiles(ianaIfTypePath); - assertTrue(context != null); - final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(context); - assertTrue(genTypes != null); - assertEquals(3, genTypes.size()); - - final Type type = genTypes.get(1); - assertTrue(type instanceof Enumeration); - - final Enumeration enumer = (Enumeration) type; - assertEquals("Enumeration type MUST contain 272 values!", 272, - enumer.getValues().size()); - } - - @Test - public void testLeafrefEnumResolving() { - final String ietfInterfacesPath = getClass().getResource( - "/enum-test-models/ietf-interfaces@2012-11-15.yang").getPath(); - final String ifTypePath = getClass().getResource( - "/enum-test-models/iana-if-type@2012-06-05.yang").getPath(); - final String yangTypesPath = getClass().getResource( - "/enum-test-models/ietf-yang-types@2010-09-24.yang").getPath(); - final String topologyPath = getClass().getResource( - "/enum-test-models/abstract-topology@2013-02-08.yang") - .getPath(); - final String inetTypesPath = getClass().getResource( - "/enum-test-models/ietf-inet-types@2010-09-24.yang") - .getPath(); - final SchemaContext context = resolveSchemaContextFromFiles( - ietfInterfacesPath, ifTypePath, yangTypesPath, topologyPath, - inetTypesPath); - - assertNotNull(context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(context); - assertNotNull(genTypes); - assertTrue(!genTypes.isEmpty()); - - GeneratedType genInterface = null; - for (final Type type : genTypes) { - if (type instanceof GeneratedType) { - if (type.getPackageName().equals("org.opendaylight.yang.gen.v1.urn.model._abstract.topology.rev201328.topology.interfaces") - && type.getName().equals("Interface")) { - genInterface = (GeneratedType) type; - } - } - } - assertNotNull("Generated Type Interface is not present in list of " + - "Generated Types", genInterface); - - Type linkUpDownTrapEnable = null; - Type operStatus = null; - final List methods = genInterface.getMethodDefinitions(); - assertNotNull("Generated Type Interface cannot contain NULL reference" + - " to Enumeration types!", methods); - assertEquals("Generated Type Interface MUST contain 4 Methods ", - 4, methods.size()); - for (final MethodSignature method : methods) { - if (method.getName().equals("getLinkUpDownTrapEnable")) { - linkUpDownTrapEnable = method.getReturnType(); - } else if (method.getName().equals("getOperStatus")) { - operStatus = method.getReturnType(); - } - } - - assertNotNull("Expected Referenced Enum LinkUpDownTrapEnable, but was NULL!", - linkUpDownTrapEnable); - assertTrue("Expected LinkUpDownTrapEnable of type ReferencedTypeImpl", - linkUpDownTrapEnable instanceof ReferencedTypeImpl); - assertEquals(linkUpDownTrapEnable.getPackageName(), - "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev20121115.interfaces.Interface"); - - assertNotNull("Expected Referenced Enum OperStatus, but was NULL!", - operStatus); - assertTrue("Expected OperStatus of type ReferencedTypeImpl", - operStatus instanceof ReferencedTypeImpl); - assertEquals(operStatus.getPackageName(), - "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev20121115.interfaces.Interface"); - } -} +/* + * Copyright (c) 2013 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.sal.binding.generator.impl; + +import static org.junit.Assert.*; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.junit.Test; +import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl; +import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; +import org.opendaylight.yangtools.sal.binding.model.api.Enumeration; +import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; +import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; +import org.opendaylight.yangtools.sal.binding.model.api.Type; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser; +import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; + +public class GenEnumResolvingTest { + + private SchemaContext resolveSchemaContextFromFiles( + final String... yangFiles) { + final YangModelParser parser = new YangParserImpl(); + + final List inputFiles = new ArrayList(); + for (int i = 0; i < yangFiles.length; ++i) { + inputFiles.add(new File(yangFiles[i])); + } + + final Set modules = parser.parseYangModels(inputFiles); + return parser.resolveSchemaContext(modules); + } + + @Test + public void testLeafEnumResolving() { + final String ietfInterfacesPath = getClass().getResource( + "/enum-test-models/ietf-interfaces@2012-11-15.yang").getPath(); + final String ifTypePath = getClass().getResource( + "/enum-test-models/iana-if-type@2012-06-05.yang").getPath(); + final String yangTypesPath = getClass().getResource( + "/enum-test-models/ietf-yang-types@2010-09-24.yang").getPath(); + + final SchemaContext context = resolveSchemaContextFromFiles( + ietfInterfacesPath, ifTypePath, yangTypesPath); + assertTrue(context != null); + + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List genTypes = bindingGen.generateTypes(context); + assertTrue(genTypes != null); + + assertEquals("Expected count of all Generated Types", 20, genTypes.size()); + + GeneratedType genInterface = null; + for (final Type type : genTypes) { + if (type instanceof GeneratedType) { + if (type.getName().equals("Interface")) { + genInterface = (GeneratedType) type; + } + } + } + assertNotNull("Generated Type Interface is not present in list of " + + "Generated Types", genInterface); + + Enumeration linkUpDownTrapEnable = null; + Enumeration operStatus = null; + final List enums = genInterface.getEnumerations(); + assertNotNull("Generated Type Interface cannot contain NULL reference" + + " to Enumeration types!", enums); + assertEquals("Generated Type Interface MUST contain 2 Enumeration " + + "Types", 2, enums.size()); + for (final Enumeration e : enums) { + if (e.getName().equals("LinkUpDownTrapEnable")) { + linkUpDownTrapEnable = e; + } else if (e.getName().equals("OperStatus")) { + operStatus = e; + } + } + + assertNotNull("Expected Enum LinkUpDownTrapEnable, but was NULL!", + linkUpDownTrapEnable); + assertNotNull("Expected Enum OperStatus, but was NULL!", operStatus); + + assertNotNull("Enum LinkUpDownTrapEnable MUST contain Values definition " + + "not NULL reference!", linkUpDownTrapEnable.getValues()); + assertNotNull("Enum OperStatus MUST contain Values definition not " + + "NULL reference!", operStatus.getValues()); + assertEquals("Enum LinkUpDownTrapEnable MUST contain 2 values!", 2, + linkUpDownTrapEnable.getValues().size()); + assertEquals("Enum OperStatus MUST contain 7 values!", 7, + operStatus.getValues().size()); + + final List methods = genInterface + .getMethodDefinitions(); + + assertNotNull("Generated Interface cannot contain NULL reference for " + + "Method Signature Definitions!", methods); + + assertEquals("Expected count of method signature definitions is 14", + 14, methods.size()); + Enumeration ianaIfType = null; + for (final MethodSignature method : methods) { + if (method.getName().equals("getType")) { + if (method.getReturnType() instanceof Enumeration) { + ianaIfType = (Enumeration)method.getReturnType(); + } + } + } + + assertNotNull("Method getType MUST return Enumeration Type, " + + "not NULL reference!", ianaIfType); + assertEquals("Enumeration getType MUST contain 272 values!", 272, + ianaIfType.getValues().size()); + } + + @Test + public void testTypedefEnumResolving() { + final String ianaIfTypePath = getClass().getResource( + "/leafref-test-models/iana-if-type@2012-06-05.yang").getPath(); + + final SchemaContext context = resolveSchemaContextFromFiles(ianaIfTypePath); + assertTrue(context != null); + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List genTypes = bindingGen.generateTypes(context); + assertTrue(genTypes != null); + assertEquals(1, genTypes.size()); + + final Type type = genTypes.get(0); + assertTrue(type instanceof Enumeration); + + final Enumeration enumer = (Enumeration) type; + assertEquals("Enumeration type MUST contain 272 values!", 272, + enumer.getValues().size()); + } + + @Test + public void testLeafrefEnumResolving() { + final String ietfInterfacesPath = getClass().getResource( + "/enum-test-models/ietf-interfaces@2012-11-15.yang").getPath(); + final String ifTypePath = getClass().getResource( + "/enum-test-models/iana-if-type@2012-06-05.yang").getPath(); + final String yangTypesPath = getClass().getResource( + "/enum-test-models/ietf-yang-types@2010-09-24.yang").getPath(); + final String topologyPath = getClass().getResource( + "/enum-test-models/abstract-topology@2013-02-08.yang") + .getPath(); + final String inetTypesPath = getClass().getResource( + "/enum-test-models/ietf-inet-types@2010-09-24.yang") + .getPath(); + final SchemaContext context = resolveSchemaContextFromFiles( + ietfInterfacesPath, ifTypePath, yangTypesPath, topologyPath, + inetTypesPath); + + assertNotNull(context); + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List genTypes = bindingGen.generateTypes(context); + assertNotNull(genTypes); + assertTrue(!genTypes.isEmpty()); + + GeneratedType genInterface = null; + for (final Type type : genTypes) { + if (type instanceof GeneratedType) { + if (type.getPackageName().equals("org.opendaylight.yang.gen.v1.urn.model._abstract.topology.rev201328.topology.interfaces") + && type.getName().equals("Interface")) { + genInterface = (GeneratedType) type; + } + } + } + assertNotNull("Generated Type Interface is not present in list of " + + "Generated Types", genInterface); + + Type linkUpDownTrapEnable = null; + Type operStatus = null; + final List methods = genInterface.getMethodDefinitions(); + assertNotNull("Generated Type Interface cannot contain NULL reference" + + " to Enumeration types!", methods); + assertEquals("Generated Type Interface MUST contain 4 Methods ", + 4, methods.size()); + for (final MethodSignature method : methods) { + if (method.getName().equals("getLinkUpDownTrapEnable")) { + linkUpDownTrapEnable = method.getReturnType(); + } else if (method.getName().equals("getOperStatus")) { + operStatus = method.getReturnType(); + } + } + + assertNotNull("Expected Referenced Enum LinkUpDownTrapEnable, but was NULL!", + linkUpDownTrapEnable); + assertTrue("Expected LinkUpDownTrapEnable of type ReferencedTypeImpl", + linkUpDownTrapEnable instanceof ReferencedTypeImpl); + assertEquals(linkUpDownTrapEnable.getPackageName(), + "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev20121115.interfaces.Interface"); + + assertNotNull("Expected Referenced Enum OperStatus, but was NULL!", + operStatus); + assertTrue("Expected OperStatus of type ReferencedTypeImpl", + operStatus instanceof ReferencedTypeImpl); + assertEquals(operStatus.getPackageName(), + "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev20121115.interfaces.Interface"); + } +} diff --git a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenTypesSubSetTest.java b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenTypesSubSetTest.java index 006aeea2aa..bd6d46146c 100644 --- a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenTypesSubSetTest.java +++ b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenTypesSubSetTest.java @@ -1,99 +1,98 @@ -/* - * Copyright (c) 2013 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.sal.binding.generator.impl; - -import static org.junit.Assert.*; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; - -public class GenTypesSubSetTest { - - private final static List yangModels = new ArrayList<>(); - private final static String yangModelsFolder = AugmentedTypeTest.class - .getResource("/leafref-test-models").getPath(); - - @BeforeClass - public static void loadTestResources() { - final File augFolder = new File(yangModelsFolder); - - for (final File fileEntry : augFolder.listFiles()) { - if (fileEntry.isFile()) { - yangModels.add(fileEntry); - } - } - } - - @Test - public void genTypesFromSubsetOfTwoModulesTest() { - final YangModelParser parser = new YangParserImpl(); - final Set modules = parser.parseYangModels(yangModels); - final SchemaContext context = parser.resolveSchemaContext(modules); - - final Set toGenModules = new HashSet<>(); - for (final Module module : modules) { - if (module.getName().equals("abstract-topology")) { - toGenModules.add(module); - } else if (module.getName().equals("ietf-interfaces")) { - toGenModules.add(module); - } - } - - assertEquals("Set of to Generate Modules must contain 2 modules", 2, - toGenModules.size()); - assertNotNull("Schema Context is null", context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(context, toGenModules); - assertNotNull("genTypes is null", genTypes); - assertFalse("genTypes is empty", genTypes.isEmpty()); - assertEquals("Expected Generated Types from provided sub set of " + - "modules should be 23!", 25, - genTypes.size()); - } - - @Test - public void genTypesFromSubsetOfThreeModulesTest() { - final YangModelParser parser = new YangParserImpl(); - final Set modules = parser.parseYangModels(yangModels); - final SchemaContext context = parser.resolveSchemaContext(modules); - - final Set toGenModules = new HashSet<>(); - for (final Module module : modules) { - if (module.getName().equals("abstract-topology")) { - toGenModules.add(module); - } else if (module.getName().equals("ietf-interfaces")) { - toGenModules.add(module); - } else if (module.getName().equals("iana-if-type")) { - toGenModules.add(module); - } - } - - assertEquals("Set of to Generate Modules must contain 3 modules", 3, - toGenModules.size()); - - assertNotNull("Schema Context is null", context); - final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(context, toGenModules); - assertNotNull("genTypes is null", genTypes); - assertFalse("genTypes is empty", genTypes.isEmpty()); - assertEquals("Expected Generated Types from provided sub set of " + - "modules should be 25!", 28, genTypes.size()); - } -} +/* + * Copyright (c) 2013 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.sal.binding.generator.impl; + +import static org.junit.Assert.*; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; +import org.opendaylight.yangtools.sal.binding.model.api.Type; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser; +import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; + +public class GenTypesSubSetTest { + + private final static List yangModels = new ArrayList<>(); + private final static String yangModelsFolder = AugmentedTypeTest.class + .getResource("/leafref-test-models").getPath(); + + @BeforeClass + public static void loadTestResources() { + final File augFolder = new File(yangModelsFolder); + + for (final File fileEntry : augFolder.listFiles()) { + if (fileEntry.isFile()) { + yangModels.add(fileEntry); + } + } + } + + @Test + public void genTypesFromSubsetOfTwoModulesTest() { + final YangModelParser parser = new YangParserImpl(); + final Set modules = parser.parseYangModels(yangModels); + final SchemaContext context = parser.resolveSchemaContext(modules); + + final Set toGenModules = new HashSet<>(); + for (final Module module : modules) { + if (module.getName().equals("abstract-topology")) { + toGenModules.add(module); + } else if (module.getName().equals("ietf-interfaces")) { + toGenModules.add(module); + } + } + + assertEquals("Set of to Generate Modules must contain 2 modules", 2, + toGenModules.size()); + assertNotNull("Schema Context is null", context); + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List genTypes = bindingGen.generateTypes(context, toGenModules); + assertNotNull("genTypes is null", genTypes); + assertFalse("genTypes is empty", genTypes.isEmpty()); + assertEquals("Expected Generated Types from provided sub set of " + + "modules should be 23!", 23, + genTypes.size()); + } + + @Test + public void genTypesFromSubsetOfThreeModulesTest() { + final YangModelParser parser = new YangParserImpl(); + final Set modules = parser.parseYangModels(yangModels); + final SchemaContext context = parser.resolveSchemaContext(modules); + + final Set toGenModules = new HashSet<>(); + for (final Module module : modules) { + if (module.getName().equals("abstract-topology")) { + toGenModules.add(module); + } else if (module.getName().equals("ietf-interfaces")) { + toGenModules.add(module); + } else if (module.getName().equals("iana-if-type")) { + toGenModules.add(module); + } + } + + assertEquals("Set of to Generate Modules must contain 3 modules", 3, + toGenModules.size()); + + assertNotNull("Schema Context is null", context); + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List genTypes = bindingGen.generateTypes(context, toGenModules); + assertNotNull("genTypes is null", genTypes); + assertFalse("genTypes is empty", genTypes.isEmpty()); + assertEquals("Expected Generated Types", 24, genTypes.size()); + } +} diff --git a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesTest.java b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesTest.java index df24a06da5..e82b24ba40 100644 --- a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesTest.java +++ b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesTest.java @@ -1,613 +1,613 @@ -/* - * Copyright (c) 2013 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.sal.binding.generator.impl; - -import static org.junit.Assert.*; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.junit.Test; -import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; -import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; -import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; - -public class GeneratedTypesTest { - - private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) { - final YangModelParser parser = new YangParserImpl(); - - final List inputFiles = new ArrayList(); - for (int i = 0; i < yangFiles.length; ++i) { - inputFiles.add(new File(yangFiles[i])); - } - - final Set modules = parser.parseYangModels(inputFiles); - return parser.resolveSchemaContext(modules); - } - - @Test - public void testMultipleModulesResolving() { - final String topologyPath = getClass().getResource("/abstract-topology.yang").getPath(); - final String typesPath = getClass().getResource("/ietf-inet-types@2010-09-24.yang").getPath(); - final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, typesPath); - assertNotNull(context); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull(genTypes); - assertEquals(29, genTypes.size()); - } - - @Test - public void testLeafrefResolving() { - final String topologyPath = getClass().getResource("/leafref-test-models/abstract-topology@2013-02-08.yang") - .getPath(); - final String interfacesPath = getClass().getResource("/leafref-test-models/ietf-interfaces@2012-11-15.yang") - .getPath(); - // final String ifTypePath = getClass().getResource( - // "/leafref-test-models/iana-if-type@2012-06-05.yang").getPath(); - final String inetTypesPath = getClass().getResource("/leafref-test-models/ietf-inet-types@2010-09-24.yang") - .getPath(); - final String yangTypesPath = getClass().getResource("/leafref-test-models/ietf-yang-types@2010-09-24.yang") - .getPath(); - - assertNotNull(topologyPath); - assertNotNull(interfacesPath); - // assertTrue(ifTypePath != null); - assertNotNull(inetTypesPath); - assertNotNull(yangTypesPath); - - // final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, interfacesPath, ifTypePath, - // inetTypesPath, yangTypesPath); - final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, interfacesPath, inetTypesPath, - yangTypesPath); - assertNotNull(context); - assertEquals(4, context.getModules().size()); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(context); - - assertEquals(57, genTypes.size()); - assertNotNull(genTypes); - - GeneratedTransferObject gtIfcKey = null; - GeneratedType gtIfc = null; - GeneratedType gtNetworkLink = null; - GeneratedType gtSource = null; - GeneratedType gtDest = null; - GeneratedType gtTunnel = null; - GeneratedTransferObject gtTunnelKey = null; - GeneratedType gtTopology = null; - for (final Type type : genTypes) { - String name = type.getName(); - if ("InterfaceKey".equals(name)) { - gtIfcKey = (GeneratedTransferObject) type; - } else if ("Interface".equals(name)) { - gtIfc = (GeneratedType) type; - } else if ("NetworkLink".equals(name)) { - gtNetworkLink = (GeneratedType) type; - } else if ("SourceNode".equals(name)) { - gtSource = (GeneratedType) type; - } else if ("DestinationNode".equals(name)) { - gtDest = (GeneratedType) type; - } else if ("Tunnel".equals(name)) { - gtTunnel = (GeneratedType) type; - } else if ("TunnelKey".equals(name)) { - gtTunnelKey = (GeneratedTransferObject) type; - } else if ("Topology".equals(name)) { - gtTopology = (GeneratedType) type; - } - } - - assertNotNull(gtIfcKey); - assertNotNull(gtIfc); - assertNotNull(gtNetworkLink); - assertNotNull(gtSource); - assertNotNull(gtDest); - assertNotNull(gtTunnel); - assertNotNull(gtTunnelKey); - assertNotNull(gtTopology); - - // Topology - final List gtTopoMethods = gtTopology.getMethodDefinitions(); - assertNotNull(gtTopoMethods); - MethodSignature condLeafref = null; - for (final MethodSignature method : gtTopoMethods) { - if (method.getName().equals("getCondLeafref")) { - condLeafref = method; - } - } - assertNotNull(condLeafref); - Type condLeafRT = condLeafref.getReturnType(); - assertNotNull(condLeafRT); - assertEquals("java.lang.Object", condLeafRT.getFullyQualifiedName()); - - // InterfaceId - final List gtIfcKeyProps = gtIfcKey.getProperties(); - assertNotNull(gtIfcKeyProps); - GeneratedProperty ifcIdProp = null; - for (final GeneratedProperty property : gtIfcKeyProps) { - if (property.getName().equals("InterfaceId")) { - ifcIdProp = property; - } - } - assertNotNull(ifcIdProp); - Type ifcIdPropType = ifcIdProp.getReturnType(); - assertNotNull(ifcIdPropType); - assertEquals("java.lang.String", ifcIdPropType.getFullyQualifiedName()); - - // Interface - final List gtIfcMethods = gtIfc.getMethodDefinitions(); - assertNotNull(gtIfcMethods); - MethodSignature getIfcKey = null; - MethodSignature getHigherLayerIf = null; - for (final MethodSignature method : gtIfcMethods) { - if (method.getName().equals("getInterfaceKey")) { - getIfcKey = method; - } else if (method.getName().equals("getHigherLayerIf")) { - getHigherLayerIf = method; - } - } - assertNotNull(getIfcKey); - Type getIfcKeyType = getIfcKey.getReturnType(); - assertNotNull(getIfcKeyType); - assertNotSame("java.lang.Void", getIfcKeyType); - assertEquals("InterfaceKey", getIfcKeyType.getName()); - - assertNotNull(getHigherLayerIf); - Type getHigherLayerIfType = getHigherLayerIf.getReturnType(); - assertNotNull(getHigherLayerIfType); - assertNotSame("java.lang.Void", getHigherLayerIfType); - assertEquals("List", getHigherLayerIfType.getName()); - - // NetworkLink - final List gtNetworkLinkMethods = gtNetworkLink.getMethodDefinitions(); - assertNotNull(gtNetworkLinkMethods); - MethodSignature getIfc = null; - for (MethodSignature method : gtNetworkLinkMethods) { - if (method.getName().equals("getInterface")) { - getIfc = method; - } - } - assertNotNull(getIfc); - Type getIfcType = getIfc.getReturnType(); - assertNotNull(getIfcType); - assertNotSame("java.lang.Void", getIfcType); - assertEquals("String", getIfcType.getName()); - - // SourceNode - final List gtSourceMethods = gtSource.getMethodDefinitions(); - assertNotNull(gtSourceMethods); - MethodSignature getIdSource = null; - for (MethodSignature method : gtSourceMethods) { - if (method.getName().equals("getId")) { - getIdSource = method; - } - } - assertNotNull(getIdSource); - Type getIdType = getIdSource.getReturnType(); - assertNotNull(getIdType); - assertNotSame("java.lang.Void", getIdType); - assertEquals("Uri", getIdType.getName()); - - // DestinationNode - final List gtDestMethods = gtDest.getMethodDefinitions(); - assertNotNull(gtDestMethods); - MethodSignature getIdDest = null; - for (MethodSignature method : gtDestMethods) { - if (method.getName().equals("getId")) { - getIdDest = method; - } - } - assertNotNull(getIdDest); - Type getIdDestType = getIdDest.getReturnType(); - assertNotNull(getIdDestType); - assertNotSame("java.lang.Void", getIdDestType); - assertEquals("Uri", getIdDestType.getName()); - - // Tunnel - final List gtTunnelMethods = gtTunnel.getMethodDefinitions(); - assertNotNull(gtTunnelMethods); - MethodSignature getTunnelKey = null; - for (MethodSignature method : gtTunnelMethods) { - if (method.getName().equals("getTunnelKey")) { - getTunnelKey = method; - } - } - assertNotNull(getTunnelKey); - Type getTunnelKeyType = getTunnelKey.getReturnType(); - assertNotNull(getTunnelKeyType); - assertNotSame("java.lang.Void", getTunnelKeyType); - assertEquals("TunnelKey", getTunnelKeyType.getName()); - - // TunnelKey - final List gtTunnelKeyProps = gtTunnelKey.getProperties(); - assertNotNull(gtTunnelKeyProps); - GeneratedProperty tunnelId = null; - for (final GeneratedProperty property : gtTunnelKeyProps) { - if (property.getName().equals("TunnelId")) { - tunnelId = property; - } - } - assertNotNull(tunnelId); - Type tunnelIdType = tunnelId.getReturnType(); - assertNotNull(tunnelIdType); - assertNotSame("java.lang.Void", tunnelIdType); - assertEquals("Uri", tunnelIdType.getName()); - } - - @Test - public void testContainerResolving() { - final String filePath = getClass().getResource("/simple-container-demo.yang").getPath(); - final SchemaContext context = resolveSchemaContextFromFiles(filePath); - assert (context != null); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull(genTypes); - assertEquals(4, genTypes.size()); - - final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1); - final GeneratedType nestedContainer = (GeneratedType) genTypes.get(2); - - assertEquals("SimpleContainer", simpleContainer.getName()); - assertEquals("NestedContainer", nestedContainer.getName()); - assertEquals(3, simpleContainer.getMethodDefinitions().size()); - assertEquals(2, nestedContainer.getMethodDefinitions().size()); - - int getFooMethodCounter = 0; - int getBarMethodCounter = 0; - int getNestedContainerCounter = 0; - - String getFooMethodReturnTypeName = ""; - String getBarMethodReturnTypeName = ""; - String getNestedContainerReturnTypeName = ""; - for (final MethodSignature method : simpleContainer.getMethodDefinitions()) { - if (method.getName().equals("getFoo")) { - getFooMethodCounter++; - getFooMethodReturnTypeName = method.getReturnType().getName(); - } - - if (method.getName().equals("getBar")) { - getBarMethodCounter++; - getBarMethodReturnTypeName = method.getReturnType().getName(); - } - - if (method.getName().equals("getNestedContainer")) { - getNestedContainerCounter++; - getNestedContainerReturnTypeName = method.getReturnType().getName(); - } - } - - assertEquals(1, getFooMethodCounter); - assertEquals("Integer", getFooMethodReturnTypeName); - - assertEquals(1, getBarMethodCounter); - assertEquals("String", getBarMethodReturnTypeName); - - assertEquals(1, getNestedContainerCounter); - assertEquals("NestedContainer", getNestedContainerReturnTypeName); - - getFooMethodCounter = 0; - getBarMethodCounter = 0; - - getFooMethodReturnTypeName = ""; - getBarMethodReturnTypeName = ""; - - for (final MethodSignature method : nestedContainer.getMethodDefinitions()) { - - if (method.getName().equals("getFoo")) { - getFooMethodCounter++; - getFooMethodReturnTypeName = method.getReturnType().getName(); - } - - if (method.getName().equals("getBar")) { - getBarMethodCounter++; - getBarMethodReturnTypeName = method.getReturnType().getName(); - } - } - - assertEquals(1, getFooMethodCounter); - assertEquals("Short", getFooMethodReturnTypeName); - - assertEquals(1, getBarMethodCounter); - assertEquals("String", getBarMethodReturnTypeName); - } - - @Test - public void testLeafListResolving() { - final String filePath = getClass().getResource("/simple-leaf-list-demo.yang").getPath(); - final SchemaContext context = resolveSchemaContextFromFiles(filePath); - assertNotNull(context); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull(genTypes); - assertEquals(4, genTypes.size()); - - final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1); - final GeneratedType nestedContainer = (GeneratedType) genTypes.get(2); - - assertEquals("SimpleContainer", simpleContainer.getName()); - assertEquals("NestedContainer", nestedContainer.getName()); - assertEquals(3, simpleContainer.getMethodDefinitions().size()); - assertEquals(2, nestedContainer.getMethodDefinitions().size()); - - int getFooMethodCounter = 0; - int getBarMethodCounter = 0; - int getNestedContainerCounter = 0; - - String getFooMethodReturnTypeName = ""; - String getBarMethodReturnTypeName = ""; - String getNestedContainerReturnTypeName = ""; - for (final MethodSignature method : simpleContainer.getMethodDefinitions()) { - if (method.getName().equals("getFoo")) { - getFooMethodCounter++; - getFooMethodReturnTypeName = method.getReturnType().getName(); - } - - if (method.getName().equals("getBar")) { - getBarMethodCounter++; - getBarMethodReturnTypeName = method.getReturnType().getName(); - } - - if (method.getName().equals("getNestedContainer")) { - getNestedContainerCounter++; - getNestedContainerReturnTypeName = method.getReturnType().getName(); - } - } - - assertEquals(1, getFooMethodCounter); - assertEquals("List", getFooMethodReturnTypeName); - - assertEquals(1, getBarMethodCounter); - assertEquals("String", getBarMethodReturnTypeName); - - assertEquals(1, getNestedContainerCounter); - assertEquals("NestedContainer", getNestedContainerReturnTypeName); - - getFooMethodCounter = 0; - getBarMethodCounter = 0; - - getFooMethodReturnTypeName = ""; - getBarMethodReturnTypeName = ""; - - for (final MethodSignature method : nestedContainer.getMethodDefinitions()) { - if (method.getName().equals("getFoo")) { - getFooMethodCounter++; - getFooMethodReturnTypeName = method.getReturnType().getName(); - } - - if (method.getName().equals("getBar")) { - getBarMethodCounter++; - getBarMethodReturnTypeName = method.getReturnType().getName(); - } - } - - assertEquals(1, getFooMethodCounter); - assertEquals("Short", getFooMethodReturnTypeName); - - assertEquals(1, getBarMethodCounter); - assertEquals("List", getBarMethodReturnTypeName); - } - - @Test - public void testListResolving() { - final String filePath = getClass().getResource("/simple-list-demo.yang").getPath(); - final SchemaContext context = resolveSchemaContextFromFiles(filePath); - assertNotNull(context); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull(genTypes); - assertEquals(6, genTypes.size()); - - int listParentContainerMethodsCount = 0; - int simpleListMethodsCount = 0; - int listChildContainerMethodsCount = 0; - int listKeyClassCount = 0; - - int getSimpleListKeyMethodCount = 0; - int getListChildContainerMethodCount = 0; - int getFooMethodCount = 0; - int setFooMethodCount = 0; - int getSimpleLeafListMethodCount = 0; - int setSimpleLeafListMethodCount = 0; - int getBarMethodCount = 0; - - String getSimpleListKeyMethodReturnTypeName = ""; - String getListChildContainerMethodReturnTypeName = ""; - - int listKeyClassPropertyCount = 0; - String listKeyClassPropertyName = ""; - String listKeyClassPropertyTypeName = ""; - boolean listKeyClassPropertyReadOnly = false; - - int hashMethodParameterCount = 0; - String hashMethodParameterName = ""; - String hashMethodParameterReturnTypeName = ""; - - int equalMethodParameterCount = 0; - String equalMethodParameterName = ""; - String equalMethodParameterReturnTypeName = ""; - - for (final Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - final GeneratedType genType = (GeneratedType) type; - if (genType.getName().equals("ListParentContainer")) { - listParentContainerMethodsCount = genType.getMethodDefinitions().size(); - } else if (genType.getName().equals("SimpleList")) { - simpleListMethodsCount = genType.getMethodDefinitions().size(); - final List methods = genType.getMethodDefinitions(); - for (final MethodSignature method : methods) { - if (method.getName().equals("getSimpleListKey")) { - getSimpleListKeyMethodCount++; - getSimpleListKeyMethodReturnTypeName = method.getReturnType().getName(); - } else if (method.getName().equals("getListChildContainer")) { - getListChildContainerMethodCount++; - getListChildContainerMethodReturnTypeName = method.getReturnType().getName(); - } else if (method.getName().equals("getFoo")) { - getFooMethodCount++; - } else if (method.getName().equals("setFoo")) { - setFooMethodCount++; - } else if (method.getName().equals("getSimpleLeafList")) { - getSimpleLeafListMethodCount++; - } else if (method.getName().equals("setSimpleLeafList")) { - setSimpleLeafListMethodCount++; - } else if (method.getName().equals("getBar")) { - getBarMethodCount++; - } - } - } else if (genType.getName().equals("ListChildContainer")) { - listChildContainerMethodsCount = genType.getMethodDefinitions().size(); - } - } else if (type instanceof GeneratedTransferObject) { - final GeneratedTransferObject genTO = (GeneratedTransferObject) type; - final List properties = genTO.getProperties(); - final List hashProps = genTO.getHashCodeIdentifiers(); - final List equalProps = genTO.getEqualsIdentifiers(); - - listKeyClassCount++; - listKeyClassPropertyCount = properties.size(); - listKeyClassPropertyName = properties.get(0).getName(); - listKeyClassPropertyTypeName = properties.get(0).getReturnType().getName(); - listKeyClassPropertyReadOnly = properties.get(0).isReadOnly(); - - hashMethodParameterCount = hashProps.size(); - hashMethodParameterName = hashProps.get(0).getName(); - hashMethodParameterReturnTypeName = hashProps.get(0).getReturnType().getName(); - - equalMethodParameterCount = equalProps.size(); - equalMethodParameterName = equalProps.get(0).getName(); - equalMethodParameterReturnTypeName = equalProps.get(0).getReturnType().getName(); - - } - } - - assertEquals(1, listParentContainerMethodsCount); - assertEquals(1, listChildContainerMethodsCount); - assertEquals(1, getSimpleListKeyMethodCount); - assertEquals(1, listKeyClassCount); - - assertEquals(1, listKeyClassPropertyCount); - assertEquals("ListKey", listKeyClassPropertyName); - assertEquals("Byte", listKeyClassPropertyTypeName); - assertEquals(true, listKeyClassPropertyReadOnly); - assertEquals(1, hashMethodParameterCount); - assertEquals("ListKey", hashMethodParameterName); - assertEquals("Byte", hashMethodParameterReturnTypeName); - assertEquals(1, equalMethodParameterCount); - assertEquals("ListKey", equalMethodParameterName); - assertEquals("Byte", equalMethodParameterReturnTypeName); - - assertEquals("SimpleListKey", getSimpleListKeyMethodReturnTypeName); - - assertEquals(1, getListChildContainerMethodCount); - assertEquals("ListChildContainer", getListChildContainerMethodReturnTypeName); - assertEquals(1, getFooMethodCount); - assertEquals(0, setFooMethodCount); - assertEquals(1, getSimpleLeafListMethodCount); - assertEquals(0, setSimpleLeafListMethodCount); - assertEquals(1, getBarMethodCount); - - assertEquals(5, simpleListMethodsCount); - } - - @Test - public void testListCompositeKeyResolving() { - final String filePath = getClass().getResource("/list-composite-key.yang").getPath(); - final SchemaContext context = resolveSchemaContextFromFiles(filePath); - - assertNotNull(context); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull(genTypes); - assertEquals(8, genTypes.size()); - - int genTypesCount = 0; - int genTOsCount = 0; - - int compositeKeyListKeyPropertyCount = 0; - int compositeKeyListKeyCount = 0; - int innerListKeyPropertyCount = 0; - - for (final Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - genTypesCount++; - } else if (type instanceof GeneratedTransferObject) { - final GeneratedTransferObject genTO = (GeneratedTransferObject) type; - - if (genTO.getName().equals("CompositeKeyListKey")) { - compositeKeyListKeyCount++; - final List properties = genTO.getProperties(); - for (final GeneratedProperty prop : properties) { - if (prop.getName().equals("Key1")) { - compositeKeyListKeyPropertyCount++; - } else if (prop.getName().equals("Key2")) { - compositeKeyListKeyPropertyCount++; - } - } - genTOsCount++; - } else if (genTO.getName().equals("InnerListKey")) { - final List properties = genTO.getProperties(); - innerListKeyPropertyCount = properties.size(); - genTOsCount++; - } - } - } - assertEquals(1, compositeKeyListKeyCount); - assertEquals(2, compositeKeyListKeyPropertyCount); - - assertEquals(1, innerListKeyPropertyCount); - - assertEquals(6, genTypesCount); - assertEquals(2, genTOsCount); - } - - @Test - public void testGeneratedTypes() { - final String filePath = getClass().getResource("/demo-topology.yang").getPath(); - final SchemaContext context = resolveSchemaContextFromFiles(filePath); - assertNotNull(context); - - final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(context); - - assertNotNull(genTypes); - assertEquals(15, genTypes.size()); - - int genTypesCount = 0; - int genTOsCount = 0; - for (final Type type : genTypes) { - if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { - genTypesCount++; - } else if (type instanceof GeneratedTransferObject) { - genTOsCount++; - } - } - - assertEquals(12, genTypesCount); - assertEquals(3, genTOsCount); - } -} +/* + * Copyright (c) 2013 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.sal.binding.generator.impl; + +import static org.junit.Assert.*; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.junit.Test; +import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator; +import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; +import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject; +import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; +import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; +import org.opendaylight.yangtools.sal.binding.model.api.Type; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser; +import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; + +public class GeneratedTypesTest { + + private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) { + final YangModelParser parser = new YangParserImpl(); + + final List inputFiles = new ArrayList(); + for (int i = 0; i < yangFiles.length; ++i) { + inputFiles.add(new File(yangFiles[i])); + } + + final Set modules = parser.parseYangModels(inputFiles); + return parser.resolveSchemaContext(modules); + } + + @Test + public void testMultipleModulesResolving() { + final String topologyPath = getClass().getResource("/abstract-topology.yang").getPath(); + final String typesPath = getClass().getResource("/ietf-inet-types@2010-09-24.yang").getPath(); + final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, typesPath); + assertNotNull(context); + + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List genTypes = bindingGen.generateTypes(context); + + assertNotNull(genTypes); + assertEquals(26, genTypes.size()); + } + + @Test + public void testLeafrefResolving() { + final String topologyPath = getClass().getResource("/leafref-test-models/abstract-topology@2013-02-08.yang") + .getPath(); + final String interfacesPath = getClass().getResource("/leafref-test-models/ietf-interfaces@2012-11-15.yang") + .getPath(); + // final String ifTypePath = getClass().getResource( + // "/leafref-test-models/iana-if-type@2012-06-05.yang").getPath(); + final String inetTypesPath = getClass().getResource("/leafref-test-models/ietf-inet-types@2010-09-24.yang") + .getPath(); + final String yangTypesPath = getClass().getResource("/leafref-test-models/ietf-yang-types@2010-09-24.yang") + .getPath(); + + assertNotNull(topologyPath); + assertNotNull(interfacesPath); + // assertTrue(ifTypePath != null); + assertNotNull(inetTypesPath); + assertNotNull(yangTypesPath); + + // final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, interfacesPath, ifTypePath, + // inetTypesPath, yangTypesPath); + final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, interfacesPath, inetTypesPath, + yangTypesPath); + assertNotNull(context); + assertEquals(4, context.getModules().size()); + + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List genTypes = bindingGen.generateTypes(context); + + assertEquals(51, genTypes.size()); + assertNotNull(genTypes); + + GeneratedTransferObject gtIfcKey = null; + GeneratedType gtIfc = null; + GeneratedType gtNetworkLink = null; + GeneratedType gtSource = null; + GeneratedType gtDest = null; + GeneratedType gtTunnel = null; + GeneratedTransferObject gtTunnelKey = null; + GeneratedType gtTopology = null; + for (final Type type : genTypes) { + String name = type.getName(); + if ("InterfaceKey".equals(name)) { + gtIfcKey = (GeneratedTransferObject) type; + } else if ("Interface".equals(name)) { + gtIfc = (GeneratedType) type; + } else if ("NetworkLink".equals(name)) { + gtNetworkLink = (GeneratedType) type; + } else if ("SourceNode".equals(name)) { + gtSource = (GeneratedType) type; + } else if ("DestinationNode".equals(name)) { + gtDest = (GeneratedType) type; + } else if ("Tunnel".equals(name)) { + gtTunnel = (GeneratedType) type; + } else if ("TunnelKey".equals(name)) { + gtTunnelKey = (GeneratedTransferObject) type; + } else if ("Topology".equals(name)) { + gtTopology = (GeneratedType) type; + } + } + + assertNotNull(gtIfcKey); + assertNotNull(gtIfc); + assertNotNull(gtNetworkLink); + assertNotNull(gtSource); + assertNotNull(gtDest); + assertNotNull(gtTunnel); + assertNotNull(gtTunnelKey); + assertNotNull(gtTopology); + + // Topology + final List gtTopoMethods = gtTopology.getMethodDefinitions(); + assertNotNull(gtTopoMethods); + MethodSignature condLeafref = null; + for (final MethodSignature method : gtTopoMethods) { + if (method.getName().equals("getCondLeafref")) { + condLeafref = method; + } + } + assertNotNull(condLeafref); + Type condLeafRT = condLeafref.getReturnType(); + assertNotNull(condLeafRT); + assertEquals("java.lang.Object", condLeafRT.getFullyQualifiedName()); + + // InterfaceId + final List gtIfcKeyProps = gtIfcKey.getProperties(); + assertNotNull(gtIfcKeyProps); + GeneratedProperty ifcIdProp = null; + for (final GeneratedProperty property : gtIfcKeyProps) { + if (property.getName().equals("InterfaceId")) { + ifcIdProp = property; + } + } + assertNotNull(ifcIdProp); + Type ifcIdPropType = ifcIdProp.getReturnType(); + assertNotNull(ifcIdPropType); + assertEquals("java.lang.String", ifcIdPropType.getFullyQualifiedName()); + + // Interface + final List gtIfcMethods = gtIfc.getMethodDefinitions(); + assertNotNull(gtIfcMethods); + MethodSignature getIfcKey = null; + MethodSignature getHigherLayerIf = null; + for (final MethodSignature method : gtIfcMethods) { + if (method.getName().equals("getInterfaceKey")) { + getIfcKey = method; + } else if (method.getName().equals("getHigherLayerIf")) { + getHigherLayerIf = method; + } + } + assertNotNull(getIfcKey); + Type getIfcKeyType = getIfcKey.getReturnType(); + assertNotNull(getIfcKeyType); + assertNotSame("java.lang.Void", getIfcKeyType); + assertEquals("InterfaceKey", getIfcKeyType.getName()); + + assertNotNull(getHigherLayerIf); + Type getHigherLayerIfType = getHigherLayerIf.getReturnType(); + assertNotNull(getHigherLayerIfType); + assertNotSame("java.lang.Void", getHigherLayerIfType); + assertEquals("List", getHigherLayerIfType.getName()); + + // NetworkLink + final List gtNetworkLinkMethods = gtNetworkLink.getMethodDefinitions(); + assertNotNull(gtNetworkLinkMethods); + MethodSignature getIfc = null; + for (MethodSignature method : gtNetworkLinkMethods) { + if (method.getName().equals("getInterface")) { + getIfc = method; + } + } + assertNotNull(getIfc); + Type getIfcType = getIfc.getReturnType(); + assertNotNull(getIfcType); + assertNotSame("java.lang.Void", getIfcType); + assertEquals("String", getIfcType.getName()); + + // SourceNode + final List gtSourceMethods = gtSource.getMethodDefinitions(); + assertNotNull(gtSourceMethods); + MethodSignature getIdSource = null; + for (MethodSignature method : gtSourceMethods) { + if (method.getName().equals("getId")) { + getIdSource = method; + } + } + assertNotNull(getIdSource); + Type getIdType = getIdSource.getReturnType(); + assertNotNull(getIdType); + assertNotSame("java.lang.Void", getIdType); + assertEquals("Uri", getIdType.getName()); + + // DestinationNode + final List gtDestMethods = gtDest.getMethodDefinitions(); + assertNotNull(gtDestMethods); + MethodSignature getIdDest = null; + for (MethodSignature method : gtDestMethods) { + if (method.getName().equals("getId")) { + getIdDest = method; + } + } + assertNotNull(getIdDest); + Type getIdDestType = getIdDest.getReturnType(); + assertNotNull(getIdDestType); + assertNotSame("java.lang.Void", getIdDestType); + assertEquals("Uri", getIdDestType.getName()); + + // Tunnel + final List gtTunnelMethods = gtTunnel.getMethodDefinitions(); + assertNotNull(gtTunnelMethods); + MethodSignature getTunnelKey = null; + for (MethodSignature method : gtTunnelMethods) { + if (method.getName().equals("getTunnelKey")) { + getTunnelKey = method; + } + } + assertNotNull(getTunnelKey); + Type getTunnelKeyType = getTunnelKey.getReturnType(); + assertNotNull(getTunnelKeyType); + assertNotSame("java.lang.Void", getTunnelKeyType); + assertEquals("TunnelKey", getTunnelKeyType.getName()); + + // TunnelKey + final List gtTunnelKeyProps = gtTunnelKey.getProperties(); + assertNotNull(gtTunnelKeyProps); + GeneratedProperty tunnelId = null; + for (final GeneratedProperty property : gtTunnelKeyProps) { + if (property.getName().equals("TunnelId")) { + tunnelId = property; + } + } + assertNotNull(tunnelId); + Type tunnelIdType = tunnelId.getReturnType(); + assertNotNull(tunnelIdType); + assertNotSame("java.lang.Void", tunnelIdType); + assertEquals("Uri", tunnelIdType.getName()); + } + + @Test + public void testContainerResolving() { + final String filePath = getClass().getResource("/simple-container-demo.yang").getPath(); + final SchemaContext context = resolveSchemaContextFromFiles(filePath); + assert (context != null); + + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List genTypes = bindingGen.generateTypes(context); + + assertNotNull(genTypes); + assertEquals(3, genTypes.size()); + + final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1); + final GeneratedType nestedContainer = (GeneratedType) genTypes.get(2); + + assertEquals("SimpleContainer", simpleContainer.getName()); + assertEquals("NestedContainer", nestedContainer.getName()); + assertEquals(3, simpleContainer.getMethodDefinitions().size()); + assertEquals(2, nestedContainer.getMethodDefinitions().size()); + + int getFooMethodCounter = 0; + int getBarMethodCounter = 0; + int getNestedContainerCounter = 0; + + String getFooMethodReturnTypeName = ""; + String getBarMethodReturnTypeName = ""; + String getNestedContainerReturnTypeName = ""; + for (final MethodSignature method : simpleContainer.getMethodDefinitions()) { + if (method.getName().equals("getFoo")) { + getFooMethodCounter++; + getFooMethodReturnTypeName = method.getReturnType().getName(); + } + + if (method.getName().equals("getBar")) { + getBarMethodCounter++; + getBarMethodReturnTypeName = method.getReturnType().getName(); + } + + if (method.getName().equals("getNestedContainer")) { + getNestedContainerCounter++; + getNestedContainerReturnTypeName = method.getReturnType().getName(); + } + } + + assertEquals(1, getFooMethodCounter); + assertEquals("Integer", getFooMethodReturnTypeName); + + assertEquals(1, getBarMethodCounter); + assertEquals("String", getBarMethodReturnTypeName); + + assertEquals(1, getNestedContainerCounter); + assertEquals("NestedContainer", getNestedContainerReturnTypeName); + + getFooMethodCounter = 0; + getBarMethodCounter = 0; + + getFooMethodReturnTypeName = ""; + getBarMethodReturnTypeName = ""; + + for (final MethodSignature method : nestedContainer.getMethodDefinitions()) { + + if (method.getName().equals("getFoo")) { + getFooMethodCounter++; + getFooMethodReturnTypeName = method.getReturnType().getName(); + } + + if (method.getName().equals("getBar")) { + getBarMethodCounter++; + getBarMethodReturnTypeName = method.getReturnType().getName(); + } + } + + assertEquals(1, getFooMethodCounter); + assertEquals("Short", getFooMethodReturnTypeName); + + assertEquals(1, getBarMethodCounter); + assertEquals("String", getBarMethodReturnTypeName); + } + + @Test + public void testLeafListResolving() { + final String filePath = getClass().getResource("/simple-leaf-list-demo.yang").getPath(); + final SchemaContext context = resolveSchemaContextFromFiles(filePath); + assertNotNull(context); + + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List genTypes = bindingGen.generateTypes(context); + + assertNotNull(genTypes); + assertEquals(3, genTypes.size()); + + final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1); + final GeneratedType nestedContainer = (GeneratedType) genTypes.get(2); + + assertEquals("SimpleContainer", simpleContainer.getName()); + assertEquals("NestedContainer", nestedContainer.getName()); + assertEquals(3, simpleContainer.getMethodDefinitions().size()); + assertEquals(2, nestedContainer.getMethodDefinitions().size()); + + int getFooMethodCounter = 0; + int getBarMethodCounter = 0; + int getNestedContainerCounter = 0; + + String getFooMethodReturnTypeName = ""; + String getBarMethodReturnTypeName = ""; + String getNestedContainerReturnTypeName = ""; + for (final MethodSignature method : simpleContainer.getMethodDefinitions()) { + if (method.getName().equals("getFoo")) { + getFooMethodCounter++; + getFooMethodReturnTypeName = method.getReturnType().getName(); + } + + if (method.getName().equals("getBar")) { + getBarMethodCounter++; + getBarMethodReturnTypeName = method.getReturnType().getName(); + } + + if (method.getName().equals("getNestedContainer")) { + getNestedContainerCounter++; + getNestedContainerReturnTypeName = method.getReturnType().getName(); + } + } + + assertEquals(1, getFooMethodCounter); + assertEquals("List", getFooMethodReturnTypeName); + + assertEquals(1, getBarMethodCounter); + assertEquals("String", getBarMethodReturnTypeName); + + assertEquals(1, getNestedContainerCounter); + assertEquals("NestedContainer", getNestedContainerReturnTypeName); + + getFooMethodCounter = 0; + getBarMethodCounter = 0; + + getFooMethodReturnTypeName = ""; + getBarMethodReturnTypeName = ""; + + for (final MethodSignature method : nestedContainer.getMethodDefinitions()) { + if (method.getName().equals("getFoo")) { + getFooMethodCounter++; + getFooMethodReturnTypeName = method.getReturnType().getName(); + } + + if (method.getName().equals("getBar")) { + getBarMethodCounter++; + getBarMethodReturnTypeName = method.getReturnType().getName(); + } + } + + assertEquals(1, getFooMethodCounter); + assertEquals("Short", getFooMethodReturnTypeName); + + assertEquals(1, getBarMethodCounter); + assertEquals("List", getBarMethodReturnTypeName); + } + + @Test + public void testListResolving() { + final String filePath = getClass().getResource("/simple-list-demo.yang").getPath(); + final SchemaContext context = resolveSchemaContextFromFiles(filePath); + assertNotNull(context); + + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List genTypes = bindingGen.generateTypes(context); + + assertNotNull(genTypes); + assertEquals(5, genTypes.size()); + + int listParentContainerMethodsCount = 0; + int simpleListMethodsCount = 0; + int listChildContainerMethodsCount = 0; + int listKeyClassCount = 0; + + int getSimpleListKeyMethodCount = 0; + int getListChildContainerMethodCount = 0; + int getFooMethodCount = 0; + int setFooMethodCount = 0; + int getSimpleLeafListMethodCount = 0; + int setSimpleLeafListMethodCount = 0; + int getBarMethodCount = 0; + + String getSimpleListKeyMethodReturnTypeName = ""; + String getListChildContainerMethodReturnTypeName = ""; + + int listKeyClassPropertyCount = 0; + String listKeyClassPropertyName = ""; + String listKeyClassPropertyTypeName = ""; + boolean listKeyClassPropertyReadOnly = false; + + int hashMethodParameterCount = 0; + String hashMethodParameterName = ""; + String hashMethodParameterReturnTypeName = ""; + + int equalMethodParameterCount = 0; + String equalMethodParameterName = ""; + String equalMethodParameterReturnTypeName = ""; + + for (final Type type : genTypes) { + if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { + final GeneratedType genType = (GeneratedType) type; + if (genType.getName().equals("ListParentContainer")) { + listParentContainerMethodsCount = genType.getMethodDefinitions().size(); + } else if (genType.getName().equals("SimpleList")) { + simpleListMethodsCount = genType.getMethodDefinitions().size(); + final List methods = genType.getMethodDefinitions(); + for (final MethodSignature method : methods) { + if (method.getName().equals("getSimpleListKey")) { + getSimpleListKeyMethodCount++; + getSimpleListKeyMethodReturnTypeName = method.getReturnType().getName(); + } else if (method.getName().equals("getListChildContainer")) { + getListChildContainerMethodCount++; + getListChildContainerMethodReturnTypeName = method.getReturnType().getName(); + } else if (method.getName().equals("getFoo")) { + getFooMethodCount++; + } else if (method.getName().equals("setFoo")) { + setFooMethodCount++; + } else if (method.getName().equals("getSimpleLeafList")) { + getSimpleLeafListMethodCount++; + } else if (method.getName().equals("setSimpleLeafList")) { + setSimpleLeafListMethodCount++; + } else if (method.getName().equals("getBar")) { + getBarMethodCount++; + } + } + } else if (genType.getName().equals("ListChildContainer")) { + listChildContainerMethodsCount = genType.getMethodDefinitions().size(); + } + } else if (type instanceof GeneratedTransferObject) { + final GeneratedTransferObject genTO = (GeneratedTransferObject) type; + final List properties = genTO.getProperties(); + final List hashProps = genTO.getHashCodeIdentifiers(); + final List equalProps = genTO.getEqualsIdentifiers(); + + listKeyClassCount++; + listKeyClassPropertyCount = properties.size(); + listKeyClassPropertyName = properties.get(0).getName(); + listKeyClassPropertyTypeName = properties.get(0).getReturnType().getName(); + listKeyClassPropertyReadOnly = properties.get(0).isReadOnly(); + + hashMethodParameterCount = hashProps.size(); + hashMethodParameterName = hashProps.get(0).getName(); + hashMethodParameterReturnTypeName = hashProps.get(0).getReturnType().getName(); + + equalMethodParameterCount = equalProps.size(); + equalMethodParameterName = equalProps.get(0).getName(); + equalMethodParameterReturnTypeName = equalProps.get(0).getReturnType().getName(); + + } + } + + assertEquals(1, listParentContainerMethodsCount); + assertEquals(1, listChildContainerMethodsCount); + assertEquals(1, getSimpleListKeyMethodCount); + assertEquals(1, listKeyClassCount); + + assertEquals(1, listKeyClassPropertyCount); + assertEquals("ListKey", listKeyClassPropertyName); + assertEquals("Byte", listKeyClassPropertyTypeName); + assertEquals(true, listKeyClassPropertyReadOnly); + assertEquals(1, hashMethodParameterCount); + assertEquals("ListKey", hashMethodParameterName); + assertEquals("Byte", hashMethodParameterReturnTypeName); + assertEquals(1, equalMethodParameterCount); + assertEquals("ListKey", equalMethodParameterName); + assertEquals("Byte", equalMethodParameterReturnTypeName); + + assertEquals("SimpleListKey", getSimpleListKeyMethodReturnTypeName); + + assertEquals(1, getListChildContainerMethodCount); + assertEquals("ListChildContainer", getListChildContainerMethodReturnTypeName); + assertEquals(1, getFooMethodCount); + assertEquals(0, setFooMethodCount); + assertEquals(1, getSimpleLeafListMethodCount); + assertEquals(0, setSimpleLeafListMethodCount); + assertEquals(1, getBarMethodCount); + + assertEquals(5, simpleListMethodsCount); + } + + @Test + public void testListCompositeKeyResolving() { + final String filePath = getClass().getResource("/list-composite-key.yang").getPath(); + final SchemaContext context = resolveSchemaContextFromFiles(filePath); + + assertNotNull(context); + + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List genTypes = bindingGen.generateTypes(context); + + assertNotNull(genTypes); + assertEquals(7, genTypes.size()); + + int genTypesCount = 0; + int genTOsCount = 0; + + int compositeKeyListKeyPropertyCount = 0; + int compositeKeyListKeyCount = 0; + int innerListKeyPropertyCount = 0; + + for (final Type type : genTypes) { + if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { + genTypesCount++; + } else if (type instanceof GeneratedTransferObject) { + final GeneratedTransferObject genTO = (GeneratedTransferObject) type; + + if (genTO.getName().equals("CompositeKeyListKey")) { + compositeKeyListKeyCount++; + final List properties = genTO.getProperties(); + for (final GeneratedProperty prop : properties) { + if (prop.getName().equals("Key1")) { + compositeKeyListKeyPropertyCount++; + } else if (prop.getName().equals("Key2")) { + compositeKeyListKeyPropertyCount++; + } + } + genTOsCount++; + } else if (genTO.getName().equals("InnerListKey")) { + final List properties = genTO.getProperties(); + innerListKeyPropertyCount = properties.size(); + genTOsCount++; + } + } + } + assertEquals(1, compositeKeyListKeyCount); + assertEquals(2, compositeKeyListKeyPropertyCount); + + assertEquals(1, innerListKeyPropertyCount); + + assertEquals(5, genTypesCount); + assertEquals(2, genTOsCount); + } + + @Test + public void testGeneratedTypes() { + final String filePath = getClass().getResource("/demo-topology.yang").getPath(); + final SchemaContext context = resolveSchemaContextFromFiles(filePath); + assertNotNull(context); + + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List genTypes = bindingGen.generateTypes(context); + + assertNotNull(genTypes); + assertEquals(14, genTypes.size()); + + int genTypesCount = 0; + int genTOsCount = 0; + for (final Type type : genTypes) { + if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) { + genTypesCount++; + } else if (type instanceof GeneratedTransferObject) { + genTOsCount++; + } + } + + assertEquals(11, genTypesCount); + assertEquals(3, genTOsCount); + } +} diff --git a/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/ClassCodeGeneratorTest.java b/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/ClassCodeGeneratorTest.java index 2c50b8561f..fdd445ef8e 100644 --- a/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/ClassCodeGeneratorTest.java +++ b/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/ClassCodeGeneratorTest.java @@ -49,7 +49,7 @@ public class ClassCodeGeneratorTest { final List genTypes = bindingGen.generateTypes(context); assertTrue(genTypes != null); - assertEquals(8, genTypes.size()); + assertEquals(7, genTypes.size()); int genTypesCount = 0; int genTOsCount = 0; @@ -100,7 +100,7 @@ public class ClassCodeGeneratorTest { } } - assertEquals(6, genTypesCount); + assertEquals(5, genTypesCount); assertEquals(2, genTOsCount); } diff --git a/code-generator/pom.xml b/code-generator/pom.xml index 9a4d411d78..fda59c0675 100644 --- a/code-generator/pom.xml +++ b/code-generator/pom.xml @@ -13,6 +13,10 @@ pom ${project.artifactId} ${project.artifactId} + + + 0.5.7-SNAPSHOT + binding-model-api diff --git a/code-generator/samples/modeling-sample/pom.xml b/code-generator/samples/modeling-sample/pom.xml index e004b162f4..3e8564baf8 100644 --- a/code-generator/samples/modeling-sample/pom.xml +++ b/code-generator/samples/modeling-sample/pom.xml @@ -13,7 +13,7 @@ org.opendaylight.yangtools yang-maven-plugin - ${yang.version} + 0.5.7-SNAPSHOT diff --git a/model/ietf/ietf-inet-types/pom.xml b/model/ietf/ietf-inet-types/pom.xml index e2bac1a86d..72281e0fa2 100644 --- a/model/ietf/ietf-inet-types/pom.xml +++ b/model/ietf/ietf-inet-types/pom.xml @@ -3,8 +3,8 @@ model-ietf - org.opendaylight.yangtools - 0.5.1-SNAPSHOT + org.opendaylight.yangtools.model + 0.5.7-SNAPSHOT 4.0.0 @@ -13,4 +13,5 @@ ${project.artifactId} ${project.artifactId} + bundle diff --git a/model/ietf/ietf-ted/pom.xml b/model/ietf/ietf-ted/pom.xml new file mode 100644 index 0000000000..f848125272 --- /dev/null +++ b/model/ietf/ietf-ted/pom.xml @@ -0,0 +1,30 @@ + + + + model-ietf + org.opendaylight.yangtools.model + 0.5.7-SNAPSHOT + + + 4.0.0 + ietf-ted + 2013.07.12-SNAPSHOT + ${project.artifactId} + ${project.artifactId} + + bundle + + + + org.opendaylight.yangtools.model + ietf-inet-types + 2010.09.24-SNAPSHOT + + + org.opendaylight.yangtools.model + ietf-yang-types + 2010.09.24-SNAPSHOT + + + diff --git a/model/ietf/ietf-ted/src/main/yang/ted@2013-07-12.yang b/model/ietf/ietf-ted/src/main/yang/ted@2013-07-12.yang new file mode 100644 index 0000000000..0d0063d437 --- /dev/null +++ b/model/ietf/ietf-ted/src/main/yang/ted@2013-07-12.yang @@ -0,0 +1,301 @@ +module ted { + yang-version 1; + namespace "urn:TBD:params:xml:ns:yang:network:ted"; + // replace with IANA namespace when assigned + prefix ted; + + import ietf-inet-types { + prefix inet; + } + + organization "TBD"; + contact + "TBD"; + description + "Helper module to hold TED attributes for OSPF/ISIS"; + + revision 2013-07-12 { + description + "Initial revision"; + } + + typedef switching-capabilities { + description + "Switching Capabilities of an interface."; + reference + "RFC 5307: IS-IS Extensions in Support of Generalized + Multi-Protocol Label Switching (GMPLS)"; + type enumeration { + enum "PSC-1" { + description + "Packet-Switch Capable-1 (PSC-1)"; + value 1; + } + enum "PSC-2" { + description + "Packet-Switch Capable-2 (PSC-2)"; + value 2; + } + enum "PSC-3" { + description + "Packet-Switch Capable-3 (PSC-3)"; + value 3; + } + enum "PSC-4" { + description + "Packet-Switch Capable-4 (PSC-4)"; + value 4; + } + enum "L2SC" { + description + "Layer-2 Switch Capable (L2SC)"; + value 51; + } + enum "TDM" { + description + "Time-Division-Multiplex Capable (TDM)"; + value 100; + } + enum "LSC" { + description + "Lambda-Switch Capable (LSC)"; + value 150; + } + enum "FSC" { + description + "Fiber-Switch Capable (FSC)"; + value 200; + } + } + } + + typedef pcc-capabilities { + description + "Path Computation Capabilities."; + reference + "RFC 5088, draft-ietf-pce-disco-protoc-isis-07.txt + OSPF/ISIS Protocol Extensions for Path Computation Element (PCE) Discovery."; + type bits { + bit path-computation-with-gmpls-link-constraints { + position 0; + } + bit bidirectional-path-computation { + position 1; + } + bit diverse-path-computation { + position 2; + } + bit load-balanced-path-computation { + position 3; + } + bit synchronized-path-computation { + position 4; + } + bit support-for-multiple-objective-functions { + position 5; + } + bit support-for-additive-path-constraints { + position 6; + } + bit support-for-request-prioritization { + position 7; + } + bit support-for-multiple-requests-per-message { + position 8; + } + } + } + + +grouping srlg-attributes { + description + "Shared Risk Link Group Attributes"; + reference + "RFC 5307, RFC 4203: ISIS / OSPF Extensions in Support of + Generalized Multi-Protocol Label Switching (GMPLS)"; + list interface-switching-capabilities { + description + "List of interface capabilities for this interface"; + key "switching-capability"; + leaf switching-capability { + description + "Switching Capability for this interface"; + type ted:switching-capabilities; + } + leaf encoding { + description + "Encoding supported by this interface"; + type uint8; + } + list max-lsp-bandwidth { + description + "Maximum LSP Bandwidth at priorities 0-7"; + max-elements "8"; + key "priority"; + leaf priority { + type uint8 { + range "0..7"; + } + } + leaf bandwidth { + description + "Max LSP Bandwidth for this level"; + type decimal64 { + fraction-digits 2; + } + } + } + container packet-switch-capable { + when "../switching-capability = PSC-1 or ../switching-capability = PSC-2 or ../switching-capability = PSC-3 or ../switching-capability = PSC-4"; + description + "Interface has packet-switching capabilities"; + leaf minimum-lsp-bandwidth { + description + "Minimum LSP Bandwidth. Units in bytes per second"; + type decimal64 { + fraction-digits 2; + } + } + leaf interface-mtu { + description + "Interface MTU"; + type uint16; + } + } + container time-division-multiplex-capable { + when "../switching-capability = TDM"; + description + "Interface has time-division multiplex capabilities"; + leaf minimum-lsp-bandwidth { + description + "Minimum LSP Bandwidth. Units in bytes per second"; + type decimal64 { + fraction-digits 2; + } + } + leaf indication { + description + "Indication whether the interface supports Standard or Arbitrary SONET/SDH"; + type uint16; + } + } + } + list srlg-values { + description + "List of Shared Risk Link Group this interface belongs to."; + key "srlg-value"; + leaf srlg-value { + description + "Shared Risk Link Group value"; + type uint32; + } + } + leaf link-protection-type { + description + "Link Protection Type desired for this link"; + type uint16; + } + } + + grouping ted-node-attributes { + description + "Identifier to uniquely identify a node in TED"; + reference "RFC 5305, RFC 6119: IPv6 Traffic Engineering in IS-IS/OSPF"; + leaf te-router-id-ipv4 { + description + "Globally unique IPv4 Traffic Engineering Router ID."; + type inet:ipv4-address; + } + leaf te-router-id-ipv6 { + description + "Globally unique IPv6 Traffic Engineering Router ID"; + type inet:ipv6-address; + } + list ipv4-local-address { + description + "List of IPv4 Local Address(OSPF). RFC 5786"; + key "ipv4-prefix"; + leaf ipv4-prefix { + description + "Local IPv4 address for the node"; + type inet:ipv4-prefix; + } + } + list ipv6-local-address { + description + "List of IPv6 Local Address."; + reference + "RFC 5786: Advertising a Router's Local Addresses + in OSPF Traffic Engineering (TE) Extensions"; + key "ipv6-prefix"; + leaf ipv6-prefix { + description + "Local IPv6 address for the node"; + type inet:ipv6-prefix; + } + leaf prefix-option { + description + "IPv6 prefix option."; + type uint8; + } + } + leaf pcc-capabilities { + description + "OSPF/ISIS PCC capabilities"; + type pcc-capabilities; + } + } + + grouping ted-link-attributes { + description + "TED Attributes associated with the link."; + reference "RFC 3630, RFC 3784: IS-IS / OSPF Traffic Engineering (TE)"; + leaf color { + description + "Administrative group or color of the link"; + type uint32; + } + leaf max-link-bandwidth { + description + "Maximum bandwidth that can be see on this link in this direction. Units in bytes per second"; + type decimal64 { + fraction-digits 2; + } + } + leaf max-resv-link-bandwidth { + description + "Maximum amount of bandwidth that can be reserved in this direction in this link. Units in bytes per second"; + type decimal64 { + fraction-digits 2; + } + } + list unreserved-bandwidth { + description + "Unreserved bandwidth for 0-7 priority levels. Units in bytes per second"; + max-elements "8"; + key "priority"; + leaf priority { + type uint8 { + range "0..7"; + } + } + leaf bandwidth { + description + "Unreserved bandwidth for this level"; + type decimal64 { + fraction-digits 2; + } + } + } + leaf te-default-metric { + description + "Traffic Engineering Metric"; + type uint32; + } + container srlg { + description + "Shared Risk Link Group Attributes"; + uses srlg-attributes; + } + } +} diff --git a/model/ietf/ietf-topology-isis/pom.xml b/model/ietf/ietf-topology-isis/pom.xml new file mode 100644 index 0000000000..835b8f5394 --- /dev/null +++ b/model/ietf/ietf-topology-isis/pom.xml @@ -0,0 +1,32 @@ + + + + model-ietf + org.opendaylight.yangtools.model + 0.5.7-SNAPSHOT + + + 4.0.0 + ietf-topology-isis + 2013.07.12-SNAPSHOT + ${project.artifactId} + ${project.artifactId} + + bundle + + + + org.opendaylight.yangtools.model + ietf-topology-l3-unicast-igp + 2013.07.12-SNAPSHOT + + + org.opendaylight.yangtools.model + ietf-ted + 2013.07.12-SNAPSHOT + + + + + diff --git a/model/ietf/ietf-topology-isis/src/main/yang/isis-topology@2013-07-12.yang b/model/ietf/ietf-topology-isis/src/main/yang/isis-topology@2013-07-12.yang new file mode 100644 index 0000000000..9ccf06cc05 --- /dev/null +++ b/model/ietf/ietf-topology-isis/src/main/yang/isis-topology@2013-07-12.yang @@ -0,0 +1,140 @@ +module isis-topology { + yang-version 1; + namespace "urn:TBD:params:xml:ns:yang:network:isis-topology"; + // replace with IANA namespace when assigned + prefix "isis"; + import network-topology { + prefix nt; + } + import l3-unicast-igp-topology { + prefix igp; + } + import ted { + prefix ted; + } + + organization "TBD"; + contact "TBD"; + description "ISIS Topology model"; + + revision "2013-07-12" { + description "Initial version"; + } + typedef iso-system-id { + description "ISO System ID. RFC 1237"; + type string { + pattern '[0-9a-fA-F]{4}(.[0-9a-fA-F]{4}){2}'; + } + } + + typedef iso-pseudonode-id { + description "ISO pseudonode id for broadcast network"; + type string { + pattern '[0-9a-fA-F]{2}'; + } + } + + typedef iso-net-id { + description "ISO NET ID. RFC 1237"; + type string { + pattern '[0-9a-fA-F]{2}((.[0-9a-fA-F]{4}){6}*)'; + } + } + + grouping isis-topology-type { + container isis { + presence "Indicates ISIS Topology"; + } + } + + augment "/nt:network-topology/nt:topology/nt:topology-types/igp:l3-unicast-igp-topology" { + uses isis-topology-type; + } + + augment "/nt:network-topology/nt:topology/igp:igp-topology-attributes" { + when "../../topology-types/isis"; + container isis-topogloy-attributes { + leaf net { + type iso-net-id; + } + } + } + + augment "/nt:network-topology/nt:topology/nt:node/igp:igp-node-attributes" { + when "../../../topology-types/isis"; + uses isis-node-attributes; + } + + augment "/nt:network-topology/nt:topology/nt:link/igp:igp-link-attributes" { + when "../../../../topology-types/isis"; + uses isis-link-attributes; + } + + grouping isis-node-attributes { + container isis-node-attributes { + container iso { + leaf iso-system-id { + type iso-system-id; + } + leaf iso-pseudonode-id { + default "0"; + type iso-pseudonode-id; + } + } + leaf-list net { + max-elements 3; + type iso-net-id; + } + leaf-list multi-topology-id { + description "List of Multi Topology Identifier upto 128 (0-127). RFC 4915"; + max-elements "128"; + type uint8 { + range "0..127"; + } + } + choice router-type { + case level-2 { + leaf level-2 { + type empty; + } + } + case level-1 { + leaf level-1 { + type empty; + } + } + case level-1-2 { + leaf level-1-2 { + type empty; + } + } + } + container ted { + uses ted:ted-node-attributes; + } + } + } + + grouping isis-link-attributes { + container isis-link-attributes { + leaf multi-topology-id { + type uint8 { + range "0..127"; + } + } + container ted { + uses ted:ted-link-attributes; + } + } + } + /* + augment "/igp:igp-node-event" { + uses isis-topology-type; + uses isis-node-attributes; + } + + augment "/igp:igp-link-event" { + uses isis-topology-type; + uses isis-link-attributes; + }*/ +} // Module isis-topology diff --git a/model/ietf/ietf-topology-l3-unicast-igp/pom.xml b/model/ietf/ietf-topology-l3-unicast-igp/pom.xml new file mode 100644 index 0000000000..ca298f39e4 --- /dev/null +++ b/model/ietf/ietf-topology-l3-unicast-igp/pom.xml @@ -0,0 +1,25 @@ + + + + model-ietf + org.opendaylight.yangtools.model + 0.5.7-SNAPSHOT + + + 4.0.0 + ietf-topology-l3-unicast-igp + 2013.07.12-SNAPSHOT + ${project.artifactId} + ${project.artifactId} + + bundle + + + + org.opendaylight.yangtools.model + ietf-topology + 2013.07.12-SNAPSHOT + + + diff --git a/model/ietf/ietf-topology-l3-unicast-igp/src/main/yang/l3-unicast-igp-topology@2013-07-12.yang b/model/ietf/ietf-topology-l3-unicast-igp/src/main/yang/l3-unicast-igp-topology@2013-07-12.yang new file mode 100644 index 0000000000..2a10d690f0 --- /dev/null +++ b/model/ietf/ietf-topology-l3-unicast-igp/src/main/yang/l3-unicast-igp-topology@2013-07-12.yang @@ -0,0 +1,232 @@ +module l3-unicast-igp-topology { + yang-version 1; + namespace "urn:TBD:params:xml:ns:yang:nt:l3-unicast-igp-topology"; + // replace with IANA namespace when assigned + prefix "l3t"; + import network-topology { + prefix "nt"; + } + + import ietf-inet-types { + prefix "inet"; + } + + organization "TBD"; + contact "TBD"; + + revision "2013-07-12" { + description "Initial revision"; + reference "TBD"; + } + + typedef igp-event-type { + description "IGP Event type for notifications"; + type enumeration { + enum "add" { + value 0; + description "An IGP node or link or prefix or termination-point has been added"; + } + enum "remove" { + value 1; + description "An IGP node or link or prefix or termination-point has been removed"; + } + enum "update" { + value 2; + description "An IGP node or link or prefix or termination-point has been updated"; + } + } + } // igp-event-type + + identity flag-identity { + description "Base type for flags"; + } + identity undefined-flag { + base "flag-identity"; + } + + typedef flag-type { + type identityref { + base "flag-identity"; + } + } + + grouping igp-prefix-attributes { + leaf prefix { + type inet:ip-prefix; + } + leaf metric { + type uint32; + } + leaf-list flag { + type flag-type; + } + } + + grouping l3-unicast-igp-topology-type { + container l3-unicast-igp-topology { + presence "indicates L3 Unicast IGP Topology"; + } + } + + grouping igp-topology-attributes { + container igp-topology-attributes { + leaf name { + description "Name of the topology"; + type string; + } + leaf-list flag { + description "Topology flags"; + type flag-type; + } + } + } + + grouping igp-node-attributes { + container igp-node-attributes { + leaf name { + description "Node name"; + type inet:domain-name; + } + leaf-list flag { + description "Node operational flags"; + type flag-type; + } + + leaf-list router-id { + description "Router-id for the node"; + type inet:ip-address; + } + + list prefix { + key "prefix"; + uses igp-prefix-attributes; + } + } + } + + grouping igp-link-attributes { + container igp-link-attributes { + leaf name { + description "Link Name"; + type string; + } + leaf-list flag { + description "Link flags"; + type flag-type; + } + leaf metric { + description "Link Metric"; + type uint32 { + range "0..16777215" { + description " + "; + // OSPF/ISIS supports max 3 byte metric. + // Ideally we would like this restriction to be + // defined in the derived models, however, + // we are not allowed to augment a "must" statement. + } + } + } + } + } // grouping igp-link-attributes + + grouping igp-termination-point-attributes { + container igp-termination-point-attributes { + choice termination-point-type { + case ip { + leaf-list ip-address { + description "IPv4 or IPv6 address"; + type inet:ip-address; + } + } + case unnumbered { + leaf unnumbered-id { + description "Unnumbered interface identifier"; + type uint32; + } + } + } + } + } // grouping igp-termination-point-attributes + + + augment "/nt:network-topology/nt:topology/nt:topology-types" { + uses l3-unicast-igp-topology-type; + } + + + augment "/nt:network-topology/nt:topology" { + when "topology-types/l3-unicast-igp-topology"; + uses igp-topology-attributes; + } + + augment "/nt:network-topology/nt:topology/nt:node" { + when "../../topology-types/l3-unicast-igp-topology"; + uses igp-node-attributes; + } + + + augment "/nt:network-topology/nt:topology/nt:link" { + when "../../topology-types/l3-unicast-igp-topology"; + uses igp-link-attributes; + } + augment "/nt:network-topology/nt:topology/nt:node/nt:termination-point" { + when "../../topology-types/l3-unicast-igp-topology"; + uses igp-termination-point-attributes; + } + + notification igp-node-event { + leaf igp-event-type { + type igp-event-type; + } + leaf topology-ref { + type nt:topology-ref; + } + uses l3-unicast-igp-topology-type; + uses nt:node-attributes; + uses igp-node-attributes; + } + + notification igp-link-event { + leaf igp-event-type { + type igp-event-type; + } + leaf topology-ref { + type nt:topology-ref; + } + uses l3-unicast-igp-topology-type; + uses nt:link-attributes; + uses igp-link-attributes; + } + + notification igp-prefix-event { + leaf igp-event-type { + type igp-event-type; + } + leaf topology-ref { + type nt:topology-ref; + } + leaf node-ref { + type nt:node-ref; + } + uses l3-unicast-igp-topology-type; + container prefix { + uses igp-prefix-attributes; + } + } + + notification termination-point-event { + leaf igp-event-type { + type igp-event-type; + } + leaf topology-ref { + type nt:topology-ref; + } + leaf node-ref { + type nt:node-ref; + } + uses l3-unicast-igp-topology-type; + uses nt:tp-attributes; + uses igp-termination-point-attributes; + } +} diff --git a/model/ietf/ietf-topology-ospf/pom.xml b/model/ietf/ietf-topology-ospf/pom.xml new file mode 100644 index 0000000000..c21599332c --- /dev/null +++ b/model/ietf/ietf-topology-ospf/pom.xml @@ -0,0 +1,31 @@ + + + + model-ietf + org.opendaylight.yangtools.model + 0.5.7-SNAPSHOT + + + 4.0.0 + ietf-topology-ospf + 2013.07.12-SNAPSHOT + ${project.artifactId} + ${project.artifactId} + + bundle + + + + org.opendaylight.yangtools.model + model-l3-unicast-igp-topology + 2013.07.12-SNAPSHOT + + + org.opendaylight.yangtools.model + model-ted + 2013.07.12-SNAPSHOT + + + + diff --git a/model/ietf/ietf-topology-ospf/src/main/yang/ospf-topology@2013-07-12.yang b/model/ietf/ietf-topology-ospf/src/main/yang/ospf-topology@2013-07-12.yang new file mode 100644 index 0000000000..49df1fb870 --- /dev/null +++ b/model/ietf/ietf-topology-ospf/src/main/yang/ospf-topology@2013-07-12.yang @@ -0,0 +1,173 @@ +ňmodule ospf-topology { + yang-version 1; + namespace "urn:ietf:params:xml:ns:yang:ospf-topology"; + // replace with IANA namespace when assigned + prefix "ospf"; + + import network-topology { + prefix "nt"; + } + + import l3-unicast-igp-topology { + prefix "igp"; + } + import ietf-inet-types { + prefix "inet"; + } + import ted { + prefix "ted"; + } + + organization "TBD"; + contact "TBD"; + description "OSPF Topology model"; + + revision "2013-07-12" { + description "Initial revision"; + reference "TBD"; + } + + typedef area-id { + description "OSPF Area ID"; + type uint32; + } + + grouping ospf-topology-type { + container ospf { + presence "indiates OSPF Topology"; + } + } + + augment "/nt:network-topology/nt:topology/nt:topology-types/igp:l3-unicast-igp-topology" { + uses ospf-topology-type; + } + + augment "/nt:network-topology/nt:topology/igp:igp-topology-attributes" { + when "../topology-types/ospf"; + container ospf-topology-attributes { + leaf area-id { + type area-id; + } + } + } + + augment "/nt:network-topology/nt:topology/nt:node/igp:igp-node-attributes" { + when "../../../topology-types/ospf"; + uses ospf-node-attributes; + } + + augment "/nt:network-topology/nt:topology/nt:link/igp:igp-link-attributes" { + when "../../../topology-types/ospf"; + uses ospf-link-attributes; + } + + augment "/nt:network-topology/nt:topology/nt:node/igp:igp-node-attributes/igp:prefix" { + when "../../../../topology-types/ospf"; + uses ospf-prefix-attributes; + } + + grouping ospf-node-attributes { + container ospf-node-attributes { + choice router-type { + case abr { + leaf abr { + type empty; + } + } + case asbr { + leaf asbr { + type empty; + } + } + case internal { + leaf internal { + type empty; + } + } + case pseudonode { + leaf pseudonode { + type empty; + } + } + } + leaf dr-interface-id { + when "../router-type/pseudonode"; + description "For pseudonodes, DR interface-id"; + default "0"; + type uint32; + } + leaf-list multi-topology-id { + description "List of Multi-Topology Identifier up-to 128 (0-127). RFC 4915"; + max-elements "128"; + type uint8 { + range "0..127"; + } + } + leaf capabilities { + description "OSPF capabilities as bit vector. RFC 4970"; + type bits { + bit graceful-restart-capable { + position 0; + } + bit graceful-restart-helper { + position 1; + } + bit stub-router-support { + position 2; + } + bit traffic-engineering-support { + position 3; + } + bit point-to-point-over-lan { + position 4; + } + bit experimental-te { + position 5; + } + } + } + container ted { + uses ted:ted-node-attributes; + } + } // ospf + } // ospf-node-attributes + + grouping ospf-link-attributes { + container ospf-link-attributes { + leaf multi-topology-id { + type uint8 { + range "0..127"; + } + } + container ted { + uses ted:ted-link-attributes; + } + } + } // ospf-link-attributes + + grouping ospf-prefix-attributes { + container ospf-prefix-attributes { + leaf forwarding-address { + when "../../igp:l3-unicast-igp-topology/igp:ospf/igp:router-type/igp:asbr"; + type inet:ipv4-address; + } + } + } + + /* + augment "/igp:igp-node-event" { + uses ospf-topology-type; + uses ospf:ospf-node-attributes; + } + + augment "/igp:igp-link-event" { + uses ospf-topology-type; + uses ospf:ospf-link-attributes; + } + + augment "/igp:igp-prefix-event" { + uses ospf-topology-type; + uses ospf:ospf-prefix-attributes; + } + */ +} diff --git a/model/ietf/ietf-topology/pom.xml b/model/ietf/ietf-topology/pom.xml new file mode 100644 index 0000000000..64678ca0c7 --- /dev/null +++ b/model/ietf/ietf-topology/pom.xml @@ -0,0 +1,30 @@ + + + + model-ietf + org.opendaylight.yangtools.model + 0.5.7-SNAPSHOT + + + 4.0.0 + ietf-topology + 2013.07.12-SNAPSHOT + ${project.artifactId} + ${project.artifactId} + + bundle + + + + org.opendaylight.yangtools.model + ietf-inet-types + 2010.09.24-SNAPSHOT + + + org.opendaylight.yangtools.model + ietf-yang-types + 2010.09.24-SNAPSHOT + + + diff --git a/model/ietf/ietf-topology/src/main/yang/network-topology@2013-07-12.yang b/model/ietf/ietf-topology/src/main/yang/network-topology@2013-07-12.yang new file mode 100644 index 0000000000..833b9fd205 --- /dev/null +++ b/model/ietf/ietf-topology/src/main/yang/network-topology@2013-07-12.yang @@ -0,0 +1,316 @@ +module network-topology { + yang-version 1; + namespace "urn:TBD:params:xml:ns:yang:network-topology"; + // replace with IANA namespace when assigned + prefix "nt"; + + import ietf-inet-types { prefix "inet"; } + + organization "TBD"; + + contact "WILL-BE-DEFINED-LATER"; +/* + description + "This module defines a model for the topology of a network. + Key design decisions are as follows: + A topology consists of a set of nodes and links. + Links are point-to-point and unidirectional. + Bidirectional connections need to be represented through + two separate links. + Multipoint connections, broadcast domains etc can be represented + through a hierarchy of nodes, then connecting nodes at + upper layers of the hierarchy."; +*/ + revision 2013-07-12 { + description + "Initial revision."; + } + + typedef topology-id { + type inet:uri; + description + "An identifier for a topology."; + } + + typedef node-id { + type inet:uri; + description + "An identifier for a node in a topology. + The identifier may be opaque. + The identifier SHOULD be chosen such that the same node in a + real network topology will always be identified through the + same identifier, even if the model is instantiated in separate + datastores. An implementation MAY choose to capture semantics + in the identifier, for example to indicate the type of node + and/or the type of topology that the node is a part of."; + } + + typedef link-id { + type inet:uri; + description + "An identifier for a link in a topology. + The identifier may be opaque. + The identifier SHOULD be chosen such that the same link in a + real network topology will always be identified through the + same identifier, even if the model is instantiated in separate + datastores. An implementation MAY choose to capture semantics + in the identifier, for example to indicate the type of link + and/or the type of topology that the link is a part of."; + } + + typedef tp-id { + type inet:uri; + description + "An identifier for termination points on a node. + The identifier may be opaque. + The identifier SHOULD be chosen such that the same TP in a + real network topology will always be identified through the + same identifier, even if the model is instantiated in separate + datastores. An implementation MAY choose to capture semantics + in the identifier, for example to indicate the type of TP + and/or the type of node and topology that the TP is a part of."; + } + + typedef tp-ref { + type leafref { + path "/network-topology/topology/node/termination-point/tp-id"; + } + description + "A type for an absolute reference to a termination point. + (This type should not be used for relative references. + In such a case, a relative path should be used instead.)"; + } + typedef topology-ref { + type leafref { + path "/network-topology/topology/topology-id"; + } + description + "A type for an absolute reference a topology instance."; + } + + typedef node-ref { + type leafref { + path "/network-topology/topology/node/node-id"; + } + description + "A type for an absolute reference to a node instance. + (This type should not be used for relative references. + In such a case, a relative path should be used instead.)"; + } + + typedef link-ref { + type leafref { + path "/network-topology/topology/link/link-id"; + } + description + "A type for an absolute reference a link instance. + (This type should not be used for relative references. + In such a case, a relative path should be used instead.)"; + } + + grouping tp-attributes { + description + "The data objects needed to define a termination point. + (This only includes a single leaf at this point, used + to identify the termination point.) + Provided in a grouping so that in addition to the datastore, + the data can also be included in notifications."; + leaf tp-id { + type tp-id; + } + leaf-list tp-ref { + type tp-ref; + config false; + description + "The leaf list identifies any termination points that the + termination point is dependent on, or maps onto. + Those termination points will themselves be contained + in a supporting node. + This dependency information can be inferred from + the dependencies between links. For this reason, + this item is not separately configurable. Hence no + corresponding constraint needs to be articulated. + The corresponding information is simply provided by the + implementing system."; + } + } + + grouping node-attributes { + description + "The data objects needed to define a node. + The objects are provided in a grouping so that in addition to + the datastore, the data can also be included in notifications + as needed."; + leaf node-id { + type node-id; + description + "The identifier of a node in the topology. + A node is specific to a topology to which it belongs."; + } + list supporting-node { + description + "This list defines vertical layering information for nodes. + It allows to capture for any given node, which node (or nodes) + in the corresponding underlay topology it maps onto. + A node can map to zero, one, or more nodes below it; + accordingly there can be zero, one, or more elements in the list. + If there are specific layering requirements, for example + specific to a particular type of topology that only allows + for certain layering relationships, the choice + below can be augmented with additional cases. + A list has been chosen rather than a leaf-list in order + to provide room for augmentations, e.g. for + statistics or priorization information associated with + supporting nodes."; + key "node-ref"; + leaf node-ref { + type node-ref; + } + } + } + + grouping link-attributes { + // This is a grouping, not defined inline with the link definition itself, + // so it can be included in a notification, if needed + leaf link-id { + type link-id; + description + "The identifier of a link in the topology. + A link is specific to a topology to which it belongs."; + } + container source { + leaf source-node { + mandatory true; + type node-ref; + description + "Source node identifier, must be in same topology."; + } + leaf source-tp { + type tp-ref; + description + "Termination point within source node that terminates the link."; + } + } + container destination { + leaf dest-node { + mandatory true; + type node-ref; + description + "Destination node identifier, must be in same topology."; + } + leaf dest-tp { + type tp-ref; + description + "Termination point within destination node that terminates the link."; + } + } + list supporting-link { + key "link-ref"; + leaf link-ref { + type link-ref; + } + } + } + + + container network-topology { + list topology { + description " + This is the model of an abstract topology. + A topology contins nodes and links. + Each topology MUST be identified by + unique topology-id for reason that a network could contain many + topologies. + "; + key "topology-id"; + leaf topology-id { + type topology-id; + description " + It is presumed that a datastore will contain many topologies. To + distinguish between topologies it is vital to have UNIQUE + topology identifiers. + "; + } + container topology-types { + description + "This container is used to identify the type, or types + (as a topology can support several types simultaneously), + of the topology. + Topology types are the subject of several integrity constraints + that an implementing server can validate in order to + maintain integrity of the datastore. + Topology types are indicated through separate data nodes; + the set of topology types is expected to increase over time. + To add support for a new topology, an augmenting module + needs to augment this container with a new empty optional + container to indicate the new topology type. + The use of a container allows to indicate a subcategorization + of topology types. + The container SHALL NOT be augmented with any data nodes + that serve a purpose other than identifying a particular + topology type. + "; + } + list underlay-topology { + key "topology-ref"; + leaf topology-ref { + type topology-ref; + } + // a list, not a leaf-list, to allow for potential augmentation + // with properties specific to the underlay topology, + // such as statistics, preferences, or cost. + description + "Identifies the topology, or topologies, that this topology + is dependent on."; + } + + list node { + description "The list of network nodes defined for the topology."; + key "node-id"; + uses node-attributes; + must "boolean(../underlay-topology[*]/node[./supporting-nodes/node-ref])"; + // This constraint is meant to ensure that a referenced node is in fact + // a node in an underlay topology. + list termination-point { + description + "A termination point can terminate a link. + Depending on the type of topology, a termination point could, + for example, refer to a port or an interface."; + key "tp-id"; + uses tp-attributes; + } + } + + list link { + description " + A Network Link connects a by Local (Source) node and + a Remote (Destination) Network Nodes via a set of the + nodes' termination points. + As it is possible to have several links between the same + source and destination nodes, and as a link could potentially + be re-homed between termination points, to ensure that we + would always know to distinguish between links, every link + is identified by a dedicated link identifier. + Note that a link models a point-to-point link, not a multipoint + link. + Layering dependencies on links in underlay topologies are + not represented as the layering information of nodes and of + termination points is sufficient. + "; + key "link-id"; + uses link-attributes; + must "boolean(../underlay-topology/link[./supporting-link]"; + // Constraint: any supporting link must be part of an underlay topology + must "boolean(../node[./source/source-node])"; + // Constraint: A link must have as source a node of the same topology + must "boolean(../node[./destination/dest-node])"; + // Constraint: A link must have as source a destination of the same topology + must "boolean(../node/termination-point[./source/source-tp])"; + // Constraint: The source termination point must be contained in the source node + must "boolean(../node/termination-point[./destination/dest-tp])"; + // Constraint: The destination termination point must be contained + // in the destination node + } + } + } +} diff --git a/model/ietf/ietf-yang-types/pom.xml b/model/ietf/ietf-yang-types/pom.xml index 6222c39eb9..10a1ef8d23 100644 --- a/model/ietf/ietf-yang-types/pom.xml +++ b/model/ietf/ietf-yang-types/pom.xml @@ -3,8 +3,8 @@ model-ietf - org.opendaylight.yangtools - 0.5.1-SNAPSHOT + org.opendaylight.yangtools.model + 0.5.7-SNAPSHOT 4.0.0 @@ -13,4 +13,5 @@ ${project.artifactId} ${project.artifactId} + bundle diff --git a/model/ietf/pom.xml b/model/ietf/pom.xml index 995dfbddc6..ae8f0627d9 100644 --- a/model/ietf/pom.xml +++ b/model/ietf/pom.xml @@ -3,8 +3,8 @@ model-parent - org.opendaylight.yangtools - 0.5.1-SNAPSHOT + org.opendaylight.yangtools.model + 0.5.7-SNAPSHOT 4.0.0 @@ -16,6 +16,12 @@ ietf-inet-types ietf-yang-types + ietf-ted + ietf-topology + - diff --git a/model/model-openflow/pom.xml b/model/model-openflow/pom.xml deleted file mode 100644 index 63513ba0f4..0000000000 --- a/model/model-openflow/pom.xml +++ /dev/null @@ -1,10 +0,0 @@ - - 4.0.0 - - model-parent - org.opendaylight.yangtools - 0.5.1-SNAPSHOT - - model-openflow - diff --git a/model/model-openflow/src/main/yang/.gitignore b/model/model-openflow/src/main/yang/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/model/model-topology-bgp/pom.xml b/model/model-topology-bgp/pom.xml deleted file mode 100644 index 764a10de7e..0000000000 --- a/model/model-topology-bgp/pom.xml +++ /dev/null @@ -1,10 +0,0 @@ - - 4.0.0 - - model-parent - org.opendaylight.yangtools - 0.5.1-SNAPSHOT - - model-topology-bgp - diff --git a/model/model-topology/pom.xml b/model/model-topology/pom.xml deleted file mode 100644 index 8098023444..0000000000 --- a/model/model-topology/pom.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - model-parent - org.opendaylight.yangtools - 0.5.1-SNAPSHOT - - - 4.0.0 - model-topology - - - - org.opendaylight.yangtools - ietf-inet-types - 2010.09.24-SNAPSHOT - - - - diff --git a/model/model-topology/src/main/yang/topology.yang b/model/model-topology/src/main/yang/topology.yang deleted file mode 100644 index ad382c8432..0000000000 --- a/model/model-topology/src/main/yang/topology.yang +++ /dev/null @@ -1,160 +0,0 @@ -module topology { - yang-version 1; - namespace "urn:ietf:params:xml:ns:yang:topology"; - prefix "tp"; - - import ietf-inet-types { prefix "inet"; } - - organization "TBD"; - - contact "WILL-BE-DEFINED-LATER"; - - description ""; - - revision 2013-06-11 { - description "Updated model with review comments. - Removed top-level container network. - Moved network elements to separate module."; - } - - typedef topology-id { - type inet:uri; - } - - typedef node-id { - description "Node abstract identifier, schema for URI will be defined by augmentation"; - type inet:uri; - } - - typedef link-id { - description "Node abstract identifier, schema for URI will be defined by augmentation"; - type inet:uri; - } - - typedef tp-id { - type inet:uri; - description "identifier for termination points on a port"; - } - - typedef tp-ref { - type leafref { - path "/topologies/topology/nodes/node/termination-points/termination-point/tp-id"; - } - } - typedef topology-ref { - type leafref { - path "/topologies/topology/topology-id"; - } - description "This type is used for leafs that reference topology identifier instance."; - // currently not used - } - - typedef node-ref { - type leafref { - path "/topologies/topology/nodes/node/node-id"; - } - description "This type is used for leafs that reference a node instance."; - } - - typedef link-ref { - type leafref { - path "/topologies/topology/links/link/link-id"; - } - description "This type is used for leafs that reference a link instance."; - // currently not used - } - - container topologies { - list topology { - description " - This is the model of abstract topology which contains only Network - Nodes and Network Links. Each topology MUST be identified by - unique topology-id for reason that the store could contain many - topologies. - "; - key "topology-id"; - leaf topology-id { - type topology-id; - description " - It is presumed that datastore will contain many topologies. To - distinguish between topologies it is vital to have UNIQUE - topology identifier. - "; - } - - container types { - description " - The container for definition of topology types. - The augmenting modules should add empty optional leaf - to this container to signalize topology type. - "; - } - - container nodes { - list node { - description "The list of network nodes defined for topology."; - - key "node-id"; - leaf node-id { - type node-id; - description "The Topology identifier of network-node."; - } - - //leaf supporting-ne { - // type network-element-ref; - //} - - container termination-points { - list termination-point { - key "tp-id"; - leaf tp-id { - type tp-id; - } - } - } - } - } - - container links { - list link { - description " - The Network Link which is defined by Local (Source) and - Remote (Destination) Network Nodes. Every link MUST be - defined either by identifier and his local and remote - Network Nodes (in real applications it is common that many - links are originated from one node and end up in same - remote node). To ensure that we would always know to - distinguish between links, every link SHOULD have - identifier. - "; - key "link-id"; - - leaf link-id { - type link-id; - description ""; - } - - container source { - leaf source-node { - type node-ref; - description "Source node identifier."; - } - leaf source-tp { - type tp-ref; - } - } - - container destination { - leaf dest-node { - type node-ref; - description "Destination node identifier."; - } - leaf dest-tp { - type tp-ref; - } - } - } - } - } - } -} diff --git a/model/pom.xml b/model/pom.xml index 37fca037ed..0b705b997b 100644 --- a/model/pom.xml +++ b/model/pom.xml @@ -8,21 +8,37 @@ 4.0.0 + org.opendaylight.yangtools.model model-parent - 0.5.1-SNAPSHOT + 0.5.7-SNAPSHOT pom ${project.artifactId} ${project.artifactId} + + 0.5.7-SNAPSHOT + UTF-8 + 2.4.0 + + ietf - model-topology - model-openflow + + org.apache.felix + maven-bundle-plugin + ${maven.bundle.version} + true + + + ${project.groupId}.${project.artifactId} + + + org.opendaylight.yangtools yang-maven-plugin diff --git a/pom.xml b/pom.xml index 547720c426..84941a01b7 100644 --- a/pom.xml +++ b/pom.xml @@ -15,9 +15,9 @@ + yang code-generator model - yang diff --git a/yang/yang-ext/pom.xml b/yang/yang-ext/pom.xml index f3b2451ac8..9f931e1655 100644 --- a/yang/yang-ext/pom.xml +++ b/yang/yang-ext/pom.xml @@ -1,97 +1,97 @@ - - - - org.opendaylight.yangtools - yang - 0.5.7-SNAPSHOT - - - 4.0.0 - yang-ext - 2013.09.07-SNAPSHOT - ${project.artifactId} - ${project.artifactId} - - - - - org.opendaylight.yangtools - yang-maven-plugin - ${yang.version} - - - - generate-sources - - - src/main/yang - - - false - - - - - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 1.7 - - - generate-sources - - add-source - - - - target/generated-sources/sal - - - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - - org.opendaylight.yangtools - - - yang-maven-plugin - - - [0.5.7,) - - - - generate-sources - - - - - - - - - - - - - - - - + + + + org.opendaylight.yangtools + yang + 0.5.7-SNAPSHOT + + + 4.0.0 + yang-ext + 2013.09.07-SNAPSHOT + ${project.artifactId} + ${project.artifactId} + + + + + org.opendaylight.yangtools + yang-maven-plugin + ${parent.version} + + + + generate-sources + + + src/main/yang + + + false + + + + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.7 + + + generate-sources + + add-source + + + + target/generated-sources/sal + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.opendaylight.yangtools + + + yang-maven-plugin + + + [0.5,) + + + + generate-sources + + + + + + + + + + + + + + + + diff --git a/yang/yang-parser-impl/pom.xml b/yang/yang-parser-impl/pom.xml index 8107a77fb7..1fe896a242 100644 --- a/yang/yang-parser-impl/pom.xml +++ b/yang/yang-parser-impl/pom.xml @@ -38,11 +38,13 @@ org.slf4j slf4j-simple 1.7.2 + test org.mockito mockito-all 1.8.4 + test com.google.guava 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 98fdc57f71..330c673bfe 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 @@ -430,6 +430,8 @@ public final class YangParserImpl implements YangModelParser { nextModule = allModulesIterator.next(); resolveAugment(modules, nextModule); } catch (NoSuchElementException e) { + + throw new YangParseException("Failed to resolve augments in module '" + module.getName() + "'.", e); } // then try to resolve first module again -- 2.36.6