Added Support for Union Type def resolving and bug fixes. 65/465/3
authorlsedlak <lsedlak@cisco.com>
Tue, 11 Jun 2013 15:08:25 +0000 (17:08 +0200)
committerlsedlak <lsedlak@cisco.com>
Wed, 12 Jun 2013 17:59:40 +0000 (19:59 +0200)
Added implementation into TypeProviderImpl to proper resolve union type definitions;
Added UnionDependencySort for correct resolution of multiple unions in same yang model;
Added support for resolving of imported union types from multiple modules;
Added tests for Union Type def resolving;

Fixed Resolving of typedef Enumerations - now the Enumeration is resolved as standalone enum typedef name .java;
Fixed resolving of Inner Enumerations;
Fixed resolving of referenced Inner Enumerations through leafref definition;
Added EnumGenerator class for generating of Enum definitions and inner Enum definitions;
Fixed generation of Enumeration type through code writer;
Fixed generation of Enumeration package name in case of inner enum definition in Class and Generated Transfer Objects;
Added capability to generate inner enums into ClassCodeGenerator and InterfaceGenerator;

Fixed of missing apostrophe in createToString method in GeneratorUtil.java in case when more than one property should be generated in toString method;

Fixed platform specific bug in maven-yang-plugin incorrect retieval of maven dependency in YangToSourcesProcessor.java;
Fixed platform specific bug in maven-yang-plugin-it - hard coded resource paths replaced for getClass().getResource calls;

Added support into BindingGenerator API to suppor of generation of Types with restriction of specified modules that will be generated;
Added implementation of generateTypes in BindingGeneratorImpl;

Added tests and test resources for testing Enumeration gen. types
Added test resources for augment relative xpath testing;

Fixed improper implementation of hashCode and equals in ExtendedType in yang-model-util;
Fixed findParentModule method in SchemaContextUtil in yang-model-util project;

Change-Id: I144acbeec9ce547da856e2979d27b2c072174a52
Signed-off-by: Lukas Sedlak <lsedlak@cisco.com>
41 files changed:
opendaylight/sal/yang-prototype/code-generator/binding-generator-api/src/main/java/org/opendaylight/controller/sal/binding/generator/api/BindingGenerator.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/BindingGeneratorImpl.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/yang/types/BaseYangTypes.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/yang/types/TypeProviderImpl.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/yang/types/UnionDependencySort.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/AugmentRleativeXPathTest.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/AugmentedTypeTest.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GenEnumResolvingTest.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GenTypesSubSetTest.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesTest.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/UnionTypeDefTest.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/abstract-topology@2013-02-08.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/augment-abstract-topology@2013-05-03.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/iana-if-type@2012-06-05.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/ietf-inet-types@2010-09-24.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/ietf-interfaces@2012-11-15.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/ietf-yang-types@2010-09-24.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/enum-test-models/abstract-topology@2013-02-08.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/enum-test-models/ietf-inet-types@2010-09-24.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/union-test-models/abstract-topology.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/union-test-models/ietf-inet-types@2010-09-24.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/BindingGeneratorUtil.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/Types.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/ClassCodeGenerator.java
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/Constants.java
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/EnumGenerator.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/GeneratorJavaFile.java
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/GeneratorUtil.java
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/InterfaceGenerator.java
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/ClassCodeGeneratorTest.java
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/GeneratorJavaFileTest.java
opendaylight/sal/yang-prototype/code-generator/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/controller/maven/sal/api/gen/plugin/CodeGeneratorImpl.java
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/java/org/opendaylight/controller/yang2sources/plugin/it/YangToSourcesPluginTestIT.java
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/GenerateTest2/pom.xml
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin/src/main/java/org/opendaylight/controller/yang2sources/plugin/YangToSourcesProcessor.java
opendaylight/sal/yang-prototype/code-generator/samples/maven-code-gen-sample/src/main/yang/controller-network.yang
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/impl/YangParserImpl.java
opendaylight/sal/yang-prototype/yang/yang-common/src/main/java/org/opendaylight/controller/yang/common/QName.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/ExtendedType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/SchemaContextUtil.java

index bed7989..a9859f7 100644 (file)
@@ -7,13 +7,47 @@
  */\r
 package org.opendaylight.controller.sal.binding.generator.api;\r
 \r
-import java.util.List;\r
-\r
 import org.opendaylight.controller.sal.binding.model.api.Type;\r
+import org.opendaylight.controller.yang.model.api.Module;\r
 import org.opendaylight.controller.yang.model.api.SchemaContext;\r
 \r
+import java.util.List;\r
+import java.util.Set;\r
+\r
+/**\r
+ *\r
+ *\r
+ */\r
 public interface BindingGenerator {\r
 \r
+    /**\r
+     * Generate Types from whole Schema Context.\r
+     * <br>\r
+     * The method will return List of All Generated Types that could be\r
+     * Generated from Schema Context.\r
+     *\r
+     *\r
+     * @param context Schema Context\r
+     * @return List of Generated Types\r
+     *\r
+     * @see SchemaContext\r
+     */\r
     public List<Type> generateTypes(final SchemaContext context);\r
 \r
+    /**\r
+     * Generate Types from Schema Context restricted by sub set of specified\r
+     * Modules. The Schema Context MUST contain all of the sub modules\r
+     * otherwise the there is no guarantee that result List of Generated\r
+     * Types will contain correct Generated Types.\r
+     *\r
+     * @param context Schema Context\r
+     * @param modules Sub Set of Modules\r
+     * @return List of Generated Types restricted by sub set of Modules\r
+     *\r
+     * @see Module\r
+     * @see SchemaContext\r
+     *\r
+     */\r
+    public List<Type> generateTypes(final SchemaContext context,\r
+                                    final Set<Module> modules);\r
 }\r
index a903ef1..65d4b48 100644 (file)
@@ -12,9 +12,7 @@ import org.opendaylight.controller.binding.generator.util.Types;
 import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTypeBuilderImpl;
 import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
 import org.opendaylight.controller.sal.binding.generator.spi.TypeProvider;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
-import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.*;
 import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
 import org.opendaylight.controller.sal.binding.yang.types.TypeProviderImpl;
 import org.opendaylight.controller.yang.common.QName;
@@ -30,7 +28,7 @@ import static org.opendaylight.controller.binding.generator.util.BindingGenerato
 import static org.opendaylight.controller.yang.model.util.SchemaContextUtil.findDataSchemaNode;
 import static org.opendaylight.controller.yang.model.util.SchemaContextUtil.findParentModule;
 
-public class BindingGeneratorImpl implements BindingGenerator {
+public final class BindingGeneratorImpl implements BindingGenerator {
 
     private Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders;
     private TypeProvider typeProvider;
@@ -43,69 +41,177 @@ public class BindingGeneratorImpl implements BindingGenerator {
     @Override
     public List<Type> generateTypes(final SchemaContext context) {
         if (context == null) {
-            throw new IllegalArgumentException("Schema Context reference cannot be NULL");
+            throw new IllegalArgumentException("Schema Context reference " +
+                    "cannot be NULL!");
         }
         if (context.getModules() == null) {
-            throw new IllegalStateException("Schema Context does not contain defined modules!");
+            throw new IllegalStateException("Schema Context does not contain " +
+                    "defined modules!");
         }
 
-        final List<Type> genTypes = new ArrayList<>();
+        final List<Type> generatedTypes = new ArrayList<>();
         schemaContext = context;
         typeProvider = new TypeProviderImpl(context);
         final Set<Module> modules = context.getModules();
         genTypeBuilders = new HashMap<>();
         for (final Module module : modules) {
-            final DataNodeIterator moduleIterator = new DataNodeIterator(
-                    module);
-
-            final List<AugmentationSchema> sortedAugmentations = provideSortedAugmentations(module);
-            final List<ContainerSchemaNode> schemaContainers = moduleIterator
-                    .allContainers();
-            final List<ListSchemaNode> schemaLists = moduleIterator
-                    .allLists();
-
-            final String basePackageName = moduleNamespaceToPackageName(module);
-            if ((schemaContainers != null)
-                    && !schemaContainers.isEmpty()) {
-                for (final ContainerSchemaNode container : schemaContainers) {
-                    genTypes.add(containerToGenType(basePackageName,
-                            container));
-                }
-            }
-            if ((schemaLists != null) && !schemaLists.isEmpty()) {
-                for (final ListSchemaNode list : schemaLists) {
-                    genTypes.addAll(listToGenType(basePackageName, list));
-                }
+            generatedTypes.add(moduleToDataType(module));
+            generatedTypes.addAll(allTypeDefinitionsToGenTypes(module));
+            generatedTypes.addAll(allContainersToGenTypes(module));
+            generatedTypes.addAll(allListsToGenTypes(module));
+            generatedTypes.addAll(allAugmentsToGenTypes(module));
+            generatedTypes.addAll(allRPCMethodsToGenType(module));
+            generatedTypes.addAll(allNotifycationsToGenType(module));
+        }
+        return generatedTypes;
+    }
+
+    @Override
+    public List<Type> generateTypes(final SchemaContext context,
+                                    final Set<Module> modules) {
+        if (context == null) {
+            throw new IllegalArgumentException("Schema Context reference " +
+                    "cannot be NULL!");
+        }
+        if (context.getModules() == null) {
+            throw new IllegalStateException("Schema Context does not contain " +
+                    "defined modules!");
+        }
+        if (modules == null) {
+            throw new IllegalArgumentException("Sef of Modules cannot be " +
+                    "NULL!");
+        }
+
+        final List<Type> filteredGenTypes = new ArrayList<>();
+        schemaContext = context;
+        typeProvider = new TypeProviderImpl(context);
+        final Set<Module> contextModules = context.getModules();
+        genTypeBuilders = new HashMap<>();
+        for (final Module contextModule : contextModules) {
+            final List<Type> generatedTypes = new ArrayList<>();
+
+            generatedTypes.add(moduleToDataType(contextModule));
+            generatedTypes.addAll(allTypeDefinitionsToGenTypes(contextModule));
+            generatedTypes.addAll(allContainersToGenTypes(contextModule));
+            generatedTypes.addAll(allListsToGenTypes(contextModule));
+            generatedTypes.addAll(allAugmentsToGenTypes(contextModule));
+            generatedTypes.addAll(allRPCMethodsToGenType(contextModule));
+            generatedTypes.addAll(allNotifycationsToGenType(contextModule));
+
+            if (modules.contains(contextModule)) {
+                filteredGenTypes.addAll(generatedTypes);
             }
+        }
+        return filteredGenTypes;
+    }
+
+    private List<Type> allTypeDefinitionsToGenTypes(final Module module) {
+        if (module == null) {
+            throw new IllegalArgumentException("Module reference cannot be NULL!");
+        }
+        if (module.getName() == null) {
+            throw new IllegalArgumentException("Module name cannot be NULL!");
+        }
+        if (module.getTypeDefinitions() == null) {
+            throw new IllegalArgumentException("Type Definitions for module " +
+                    module.getName() + " cannot be NULL!");
+        }
 
-            if ((sortedAugmentations != null)
-                    && !sortedAugmentations.isEmpty()) {
-                for (final AugmentationSchema augment : sortedAugmentations) {
-                    genTypes.addAll(augmentationToGenTypes(basePackageName, augment));
+        final Set<TypeDefinition<?>> typeDefinitions = module
+                .getTypeDefinitions();
+        final List<Type> generatedTypes = new ArrayList<>();
+        for (final TypeDefinition<?> typedef : typeDefinitions) {
+            if (typedef != null) {
+                final Type type = ((TypeProviderImpl)typeProvider)
+                        .generatedTypeForExtendedDefinitionType(typedef);
+                if ((type != null) && !generatedTypes.contains(type)) {
+                    generatedTypes.add(type);
                 }
             }
+        }
+        return generatedTypes;
+    }
 
-            final GeneratedType genDataType = moduleToDataType(basePackageName, module);
-            final List<GeneratedType> genRpcType = rpcMethodsToGenType(basePackageName, module);
-            final List<Type> genNotifyType = notifycationsToGenType(basePackageName, module);
+    private List<Type> allContainersToGenTypes(final Module module) {
+        if (module == null) {
+            throw new IllegalArgumentException("Module reference cannot be NULL!");
+        }
 
-            if (genDataType != null) {
-                genTypes.add(genDataType);
-            }
-            if (genRpcType != null) {
-                genTypes.addAll(genRpcType);
-            }
-            if (genNotifyType != null) {
-                genTypes.addAll(genNotifyType);
+        if (module.getName() == null) {
+            throw new IllegalArgumentException("Module name cannot be NULL!");
+        }
+
+        if (module.getChildNodes() == null) {
+            throw new IllegalArgumentException("Reference to Set of Child " +
+                    "Nodes in module " + module.getName() + " cannot be " +
+                    "NULL!");
+        }
+
+        final List<Type> generatedTypes = new ArrayList<>();
+        final DataNodeIterator it = new DataNodeIterator(
+                module);
+        final List<ContainerSchemaNode> schemaContainers = it.allContainers();
+        final String basePackageName = moduleNamespaceToPackageName(module);
+        for (final ContainerSchemaNode container : schemaContainers) {
+            generatedTypes.add(containerToGenType(basePackageName,
+                    container));
+        }
+        return generatedTypes;
+    }
+
+    private List<Type> allListsToGenTypes(final Module module) {
+        if (module == null) {
+            throw new IllegalArgumentException("Module reference cannot be NULL!");
+        }
+
+        if (module.getName() == null) {
+            throw new IllegalArgumentException("Module name cannot be NULL!");
+        }
+
+        if (module.getChildNodes() == null) {
+            throw new IllegalArgumentException("Reference to Set of Child " +
+                    "Nodes in module " + module.getName() + " cannot be " +
+                    "NULL!");
+        }
+
+        final List<Type> generatedTypes = new ArrayList<>();
+        final DataNodeIterator it = new DataNodeIterator(
+                module);
+        final List<ListSchemaNode> schemaLists = it.allLists();
+        final String basePackageName = moduleNamespaceToPackageName(module);
+        if (schemaLists != null) {
+            for (final ListSchemaNode list : schemaLists) {
+                generatedTypes.addAll(listToGenType(basePackageName, list));
             }
         }
-        genTypes.addAll(((TypeProviderImpl) typeProvider)
-                .getGeneratedTypeDefs());
+        return generatedTypes;
+    }
 
-        return genTypes;
+    private List<Type> allAugmentsToGenTypes(final Module module) {
+        if (module == null) {
+            throw new IllegalArgumentException("Module reference cannot be NULL!");
+        }
+
+        if (module.getName() == null) {
+            throw new IllegalArgumentException("Module name cannot be NULL!");
+        }
+
+        if (module.getChildNodes() == null) {
+            throw new IllegalArgumentException("Reference to Set of " +
+                    "Augmentation Definitions in module " + module.getName()
+                    + " cannot be NULL!");
+        }
+
+        final List<Type> generatedTypes = new ArrayList<>();
+        final String basePackageName = moduleNamespaceToPackageName(module);
+        final List<AugmentationSchema> augmentations = resolveAugmentations(module);
+        for (final AugmentationSchema augment : augmentations) {
+            generatedTypes.addAll(augmentationToGenTypes(basePackageName, augment));
+        }
+        return generatedTypes;
     }
 
-    private List<AugmentationSchema> provideSortedAugmentations(final Module module) {
+    private List<AugmentationSchema> resolveAugmentations(final Module module) {
         if (module == null) {
             throw new IllegalArgumentException("Module reference cannot be NULL!");
         }
@@ -142,7 +248,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
         return sortedAugmentations;
     }
 
-    private GeneratedType moduleToDataType(final String basePackageName, final Module module) {
+    private GeneratedType moduleToDataType(final Module module) {
         if (module == null) {
             throw new IllegalArgumentException("Module reference cannot be NULL!");
         }
@@ -150,6 +256,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
         final GeneratedTypeBuilder moduleDataTypeBuilder = moduleTypeBuilder(
                 module, "Data");
 
+        final String basePackageName = moduleNamespaceToPackageName(module);
         if (moduleDataTypeBuilder != null) {
             final Set<DataSchemaNode> dataNodes = module.getChildNodes();
             resolveDataSchemaNodes(basePackageName, moduleDataTypeBuilder, dataNodes);
@@ -157,17 +264,91 @@ public class BindingGeneratorImpl implements BindingGenerator {
         return moduleDataTypeBuilder.toInstance();
     }
 
-    private boolean isDerivedFromEnumerationType(
-            final TypeDefinition<?> typeDefinition) {
-        if (typeDefinition != null) {
-            if (typeDefinition.getBaseType() instanceof EnumTypeDefinition) {
-                return true;
-            } else if (typeDefinition.getBaseType() instanceof ExtendedType) {
-                return isDerivedFromEnumerationType(typeDefinition
-                        .getBaseType());
+    private List<GeneratedType> allRPCMethodsToGenType(final Module module) {
+        if (module == null) {
+            throw new IllegalArgumentException("Module reference cannot be NULL!");
+        }
+
+        if (module.getName() == null) {
+            throw new IllegalArgumentException("Module name cannot be NULL!");
+        }
+
+        if (module.getChildNodes() == null) {
+            throw new IllegalArgumentException("Reference to Set of " +
+                    "RPC Method Definitions in module " + module.getName()
+                    + " cannot be NULL!");
+        }
+
+        final String basePackageName = moduleNamespaceToPackageName(module);
+        final Set<RpcDefinition> rpcDefinitions = module.getRpcs();
+        final List<GeneratedType> genRPCTypes = new ArrayList<>();
+
+        for (final RpcDefinition rpc : rpcDefinitions) {
+            if (rpc != null) {
+                final List<DataNodeIterator> rpcInOut = new ArrayList<>();
+                rpcInOut.add(new DataNodeIterator(rpc.getInput()));
+                rpcInOut.add(new DataNodeIterator(rpc.getOutput()));
+
+                for (DataNodeIterator it : rpcInOut) {
+                    List<ContainerSchemaNode> nContainers = it.allContainers();
+                    if ((nContainers != null) && !nContainers.isEmpty()) {
+                        for (final ContainerSchemaNode container : nContainers) {
+                            genRPCTypes.add(containerToGenType(basePackageName, container));
+                        }
+                    }
+                }
             }
         }
-        return false;
+        return genRPCTypes;
+    }
+
+    private List<Type> allNotifycationsToGenType(final Module module) {
+        if (module == null) {
+            throw new IllegalArgumentException("Module reference cannot be NULL!");
+        }
+
+        if (module.getName() == null) {
+            throw new IllegalArgumentException("Module name cannot be NULL!");
+        }
+
+        if (module.getChildNodes() == null) {
+            throw new IllegalArgumentException("Reference to Set of " +
+                    "Notification Definitions in module " + module.getName()
+                    + " cannot be NULL!");
+        }
+
+        final String basePackageName = moduleNamespaceToPackageName(module);
+        final List<Type> genNotifyTypes = new ArrayList<>();
+        final Set<NotificationDefinition> notifications = module
+                .getNotifications();
+
+        for (final NotificationDefinition notification : notifications) {
+            if (notification != null) {
+                final List<DataNodeIterator> notifyChildren = new ArrayList<>();
+
+                for (DataSchemaNode childNode : notification.getChildNodes()) {
+                    if (childNode instanceof DataNodeContainer) {
+                        notifyChildren.add(new DataNodeIterator((DataNodeContainer) childNode));
+                    }
+                }
+
+                for (DataNodeIterator it : notifyChildren) {
+                    List<ContainerSchemaNode> nContainers = it.allContainers();
+                    List<ListSchemaNode> nLists = it.allLists();
+                    if ((nContainers != null) && !nContainers.isEmpty()) {
+                        for (final ContainerSchemaNode container : nContainers) {
+                            genNotifyTypes.add(containerToGenType(basePackageName, container));
+                        }
+                    }
+                    if ((nLists != null) && !nLists.isEmpty()) {
+                        for (final ListSchemaNode list : nLists) {
+                            genNotifyTypes.addAll(listToGenType(basePackageName, list));
+                        }
+                    }
+                }
+            }
+        }
+        return genNotifyTypes;
     }
 
     private EnumTypeDefinition enumTypeDefFromExtendedType(
@@ -182,7 +363,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
         return null;
     }
 
-    private EnumBuilder resolveEnumFromTypeDefinition(
+    private EnumBuilder resolveInnerEnumFromTypeDefinition(
             final EnumTypeDefinition enumTypeDef, final String enumName,
             final GeneratedTypeBuilder typeBuilder) {
         if ((enumTypeDef != null) && (typeBuilder != null)
@@ -230,75 +411,6 @@ public class BindingGeneratorImpl implements BindingGenerator {
 
     }
 
-    private List<GeneratedType> rpcMethodsToGenType(final String basePackageName, final Module module) {
-        if (module == null) {
-            throw new IllegalArgumentException("Module reference cannot be NULL!");
-        }
-
-        final Set<RpcDefinition> rpcDefinitions = module.getRpcs();
-        final List<GeneratedType> rpcTypes = new ArrayList<>();
-
-        if ((rpcDefinitions != null) && !rpcDefinitions.isEmpty()) {
-            for (final RpcDefinition rpc : rpcDefinitions) {
-                if (rpc != null) {
-                    final List<DataNodeIterator> rpcInOut = new ArrayList<>();
-                    rpcInOut.add(new DataNodeIterator(rpc.getInput()));
-                    rpcInOut.add(new DataNodeIterator(rpc.getOutput()));
-
-                    for (DataNodeIterator it : rpcInOut) {
-                        List<ContainerSchemaNode> nContainers = it.allContainers();
-                        if ((nContainers != null) && !nContainers.isEmpty()) {
-                            for (final ContainerSchemaNode container : nContainers) {
-                                rpcTypes.add(containerToGenType(basePackageName, container));
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        return rpcTypes;
-    }
-
-    private List<Type> notifycationsToGenType(final String basePackageName, final Module module) {
-        if (module == null) {
-            throw new IllegalArgumentException("Module reference cannot be NULL!");
-        }
-        final List<Type> notificationTypes = new ArrayList<>();
-        final Set<NotificationDefinition> notifications = module
-                .getNotifications();
-
-        if ((notifications != null) && !notifications.isEmpty()) {
-            for (final NotificationDefinition notification : notifications) {
-                if (notification != null) {
-                    final List<DataNodeIterator> notifyChildren = new ArrayList<>();
-
-                    for (DataSchemaNode childNode : notification.getChildNodes()) {
-                        if (childNode instanceof DataNodeContainer) {
-                            notifyChildren.add(new DataNodeIterator((DataNodeContainer) childNode));
-                        }
-                    }
-
-                    for (DataNodeIterator it : notifyChildren) {
-                        List<ContainerSchemaNode> nContainers = it.allContainers();
-                        List<ListSchemaNode> nLists = it.allLists();
-                        if ((nContainers != null) && !nContainers.isEmpty()) {
-                            for (final ContainerSchemaNode container : nContainers) {
-                                notificationTypes.add(containerToGenType(basePackageName, container));
-                            }
-                        }
-                        if ((nLists != null) && !nLists.isEmpty()) {
-                            for (final ListSchemaNode list : nLists) {
-
-                                notificationTypes.addAll(listToGenType(basePackageName, list));
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        return notificationTypes;
-    }
-
     private List<Type> augmentationToGenTypes(final String augmentPackageName,
                                               final AugmentationSchema augSchema) {
         if (augmentPackageName == null) {
@@ -404,8 +516,6 @@ public class BindingGeneratorImpl implements BindingGenerator {
             }
             if ((augLists != null) && !augLists.isEmpty()) {
                 for (final ListSchemaNode list : augLists) {
-//                    final String listPackageName = packageNameForAugmentedType(
-//                            augBasePackageName, list.getPath());
                     genTypes.addAll(listToGenType(augBasePackageName, list));
                 }
             }
@@ -507,27 +617,22 @@ public class BindingGeneratorImpl implements BindingGenerator {
                 final TypeDefinition<?> typeDef = leaf.getType();
 
                 Type returnType = null;
-                if (!(typeDef instanceof EnumTypeDefinition)
-                        && !isDerivedFromEnumerationType(typeDef)) {
+                if (!(typeDef instanceof EnumTypeDefinition)) {
                     returnType = typeProvider
                             .javaTypeForSchemaDefinitionType(typeDef);
                 } else {
-                    if (isImported(leaf.getPath(), typeDef.getPath())) {
-                        // TODO: resolving of imported enums as references to
-                        // GeneratedTypeData interface
-                    } else {
-                        final EnumTypeDefinition enumTypeDef = enumTypeDefFromExtendedType(typeDef);
-                        final EnumBuilder enumBuilder = resolveEnumFromTypeDefinition(
-                                enumTypeDef, leafName, typeBuilder);
-
-                        if (enumBuilder != null) {
-                            returnType = new ReferencedTypeImpl(
-                                    enumBuilder.getPackageName(),
-                                    enumBuilder.getName());
-                        }
+                    final EnumTypeDefinition enumTypeDef = enumTypeDefFromExtendedType(typeDef);
+                    final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(
+                            enumTypeDef, leafName, typeBuilder);
+
+                    if (enumBuilder != null) {
+                        returnType = new ReferencedTypeImpl(
+                                enumBuilder.getPackageName(),
+                                enumBuilder.getName());
                     }
+                    ((TypeProviderImpl)typeProvider).putReferencedType(leaf
+                            .getPath(), returnType);
                 }
-
                 if (returnType != null) {
                     constructGetter(typeBuilder, leafName, leafDesc, returnType);
                     if (!leaf.isConfiguration()) {
@@ -540,26 +645,6 @@ public class BindingGeneratorImpl implements BindingGenerator {
         return false;
     }
 
-    private boolean isImported(final SchemaPath leafPath,
-                               final SchemaPath typeDefPath) {
-        if ((leafPath != null) && (leafPath.getPath() != null)
-                && (typeDefPath != null) && (typeDefPath.getPath() != null)) {
-
-            final QName leafPathQName = leafPath.getPath().get(0);
-            final QName typePathQName = typeDefPath.getPath().get(0);
-
-            if ((leafPathQName != null)
-                    && (leafPathQName.getNamespace() != null)
-                    && (typePathQName != null)
-                    && (typePathQName.getNamespace() != null)) {
-
-                return !leafPathQName.getNamespace().equals(
-                        typePathQName.getNamespace());
-            }
-        }
-        return false;
-    }
-
     private boolean resolveLeafSchemaNodeAsProperty(
             final GeneratedTOBuilder toBuilder, final LeafSchemaNode leaf,
             boolean isReadOnly) {
@@ -767,23 +852,6 @@ public class BindingGeneratorImpl implements BindingGenerator {
             addSchemaNodeToListBuilders(basePackageName, schemaNode, typeBuilder,
                     genTOBuilder, listKeys);
         }
-
-//        if (list.isAugmenting()) {
-//            for (final DataSchemaNode schemaNode : schemaNodes) {
-//                if (schemaNode.isAugmenting()) {
-//                    addSchemaNodeToListBuilders(basePackageName, schemaNode, typeBuilder,
-//                            genTOBuilder, listKeys);
-//                }
-//            }
-//        } else {
-//            for (final DataSchemaNode schemaNode : schemaNodes) {
-//                if (schemaNode.isAugmenting()) {
-//                    continue;
-//                }
-//                addSchemaNodeToListBuilders(basePackageName, schemaNode, typeBuilder,
-//                        genTOBuilder, listKeys);
-//            }
-//        }
         return typeBuildersToGenTypes(typeBuilder, genTOBuilder);
     }
 
@@ -818,7 +886,6 @@ public class BindingGeneratorImpl implements BindingGenerator {
         } else if (schemaNode instanceof ListSchemaNode) {
             resolveListSchemaNode(basePackageName, typeBuilder, (ListSchemaNode) schemaNode);
         }
-
     }
 
     private List<Type> typeBuildersToGenTypes(
@@ -906,7 +973,6 @@ public class BindingGeneratorImpl implements BindingGenerator {
         if (listKeys.size() > 0) {
             genTOBuilder = resolveListKey(packageName, list);
         }
-
         return genTOBuilder;
     }
 }
index 374ad8b..fca2477 100644 (file)
@@ -16,7 +16,7 @@ import org.opendaylight.controller.sal.binding.generator.spi.TypeProvider;
 import org.opendaylight.controller.sal.binding.model.api.Type;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 
-public class BaseYangTypes {
+public final class BaseYangTypes {
 
     private static Map<String, Type> typeMap = new HashMap<String, Type>();
 
index 0618efc..b3739ec 100644 (file)
@@ -7,15 +7,7 @@
  */
 package org.opendaylight.controller.sal.binding.yang.types;
 
-import static org.opendaylight.controller.yang.model.util.SchemaContextUtil.*;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.opendaylight.controller.binding.generator.util.BindingGeneratorUtil;
+import org.opendaylight.controller.binding.generator.util.ReferencedTypeImpl;
 import org.opendaylight.controller.binding.generator.util.Types;
 import org.opendaylight.controller.binding.generator.util.generated.type.builder.EnumerationBuilderImpl;
 import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
@@ -27,13 +19,7 @@ import org.opendaylight.controller.sal.binding.model.api.type.builder.EnumBuilde
 import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedPropertyBuilder;
 import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTOBuilder;
 import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder;
-import org.opendaylight.controller.yang.model.api.DataSchemaNode;
-import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
-import org.opendaylight.controller.yang.model.api.Module;
-import org.opendaylight.controller.yang.model.api.RevisionAwareXPath;
-import org.opendaylight.controller.yang.model.api.SchemaContext;
-import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.*;
 import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition;
 import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition.EnumPair;
 import org.opendaylight.controller.yang.model.api.type.IdentityrefTypeDefinition;
@@ -41,11 +27,19 @@ import org.opendaylight.controller.yang.model.api.type.LeafrefTypeDefinition;
 import org.opendaylight.controller.yang.model.api.type.UnionTypeDefinition;
 import org.opendaylight.controller.yang.model.util.ExtendedType;
 
-public class TypeProviderImpl implements TypeProvider {
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.opendaylight.controller.binding.generator.util.BindingGeneratorUtil.*;
+import static org.opendaylight.controller.yang.model.util.SchemaContextUtil.*;
+
+public final class TypeProviderImpl implements TypeProvider {
 
     private final SchemaContext schemaContext;
-    private Map<String, Map<String, GeneratedTransferObject>> genTypeDefsContextMap;
-    private final List<GeneratedTransferObject> allTypeDefinitions;
+    private Map<String, Map<String, Type>> genTypeDefsContextMap;
+    private final Map<SchemaPath, Type> referencedTypes;
 
     public TypeProviderImpl(final SchemaContext schemaContext) {
         if (schemaContext == null) {
@@ -53,12 +47,23 @@ public class TypeProviderImpl implements TypeProvider {
         }
 
         this.schemaContext = schemaContext;
-        this.genTypeDefsContextMap = new HashMap<String, Map<String, GeneratedTransferObject>>();
-        allTypeDefinitions = resolveTypeDefsFromContext();
+        this.genTypeDefsContextMap = new HashMap<>();
+        this.referencedTypes = new HashMap<>();
+        resolveTypeDefsFromContext();
     }
 
-    public List<GeneratedTransferObject> getGeneratedTypeDefs() {
-        return allTypeDefinitions;
+    public void putReferencedType(final SchemaPath refTypePath,
+                                  final Type refType) {
+        if (refTypePath == null) {
+            throw new IllegalArgumentException("Path reference of " +
+                    "Enumeration Type Definition cannot be NULL!");
+        }
+
+        if (refType == null) {
+            throw new IllegalArgumentException("Reference to Enumeration " +
+                    "Type cannot be NULL!");
+        }
+        referencedTypes.put(refTypePath, refType);
     }
 
     /*
@@ -78,45 +83,93 @@ public class TypeProviderImpl implements TypeProvider {
     public Type javaTypeForSchemaDefinitionType(
             final TypeDefinition<?> typeDefinition) {
         Type returnType = null;
-        if (typeDefinition != null) {
-            final String typedefName = typeDefinition.getQName().getLocalName();
-            if (typeDefinition instanceof ExtendedType) {
-                final TypeDefinition<?> baseTypeDef = baseTypeDefForExtendedType(typeDefinition);
-
-                if (baseTypeDef instanceof LeafrefTypeDefinition) {
-                    final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) baseTypeDef;
-                    returnType = provideTypeForLeafref(leafref);
-                } else if (baseTypeDef instanceof IdentityrefTypeDefinition) {
-
-                } else if (baseTypeDef instanceof EnumTypeDefinition) {
-                    final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) baseTypeDef;
-                    returnType = resolveEnumFromTypeDefinition(enumTypeDef,
-                            typedefName);
-                } else {
+        if (typeDefinition == null) {
+            throw new IllegalArgumentException("Type Definition cannot be " +
+                    "NULL!");
+        }
 
-                    final Module module = resolveModuleFromTypePath(schemaContext, typeDefinition);
+        if (typeDefinition.getQName() == null) {
+            throw new IllegalArgumentException("Type Definition cannot have " +
+                    "non specified QName (QName cannot be NULL!)");
+        }
 
-                    if (module != null) {
-                        final Map<String, GeneratedTransferObject> genTOs = genTypeDefsContextMap
-                                .get(module.getName());
-                        if (genTOs != null) {
-                            returnType = genTOs.get(typedefName);
-                        }
+        if (typeDefinition.getQName().getLocalName() == null) {
+            throw new IllegalArgumentException("Type Definitions Local Name " +
+                    "cannot be NULL!");
+        }
+        final String typedefName = typeDefinition.getQName().getLocalName();
+        if (typeDefinition instanceof ExtendedType) {
+            final TypeDefinition<?> baseTypeDef = baseTypeDefForExtendedType(typeDefinition);
+
+            if (baseTypeDef instanceof LeafrefTypeDefinition) {
+                final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) baseTypeDef;
+                returnType = provideTypeForLeafref(leafref);
+            } else if (baseTypeDef instanceof IdentityrefTypeDefinition) {
+
+            } else if (baseTypeDef instanceof EnumTypeDefinition) {
+                final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) baseTypeDef;
+                returnType = resolveEnumFromTypeDefinition(enumTypeDef,
+                        typedefName);
+            } else {
+                final Module module = findParentModuleForTypeDefinition(schemaContext,
+                        typeDefinition);
+                if (module != null) {
+                    final Map<String, Type> genTOs = genTypeDefsContextMap
+                            .get(module.getName());
+                    if (genTOs != null) {
+                        returnType = genTOs.get(typedefName);
+                    }
+                    if (returnType == null) {
+                        returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER
+                                .javaTypeForSchemaDefinitionType(baseTypeDef);
                     }
                 }
+            }
+        } else {
+            if (typeDefinition instanceof LeafrefTypeDefinition) {
+                final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) typeDefinition;
+                returnType = provideTypeForLeafref(leafref);
+            } else if (typeDefinition instanceof IdentityrefTypeDefinition) {
+
             } else {
-                if (typeDefinition instanceof LeafrefTypeDefinition) {
-                    final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) typeDefinition;
-                    returnType = provideTypeForLeafref(leafref);
-                } else if (typeDefinition instanceof EnumTypeDefinition) {
-                    final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) typeDefinition;
-                    returnType = resolveEnumFromTypeDefinition(enumTypeDef,
-                            typedefName);
-                } else if (typeDefinition instanceof IdentityrefTypeDefinition) {
+                returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER
+                        .javaTypeForSchemaDefinitionType(typeDefinition);
+            }
+        }
+        return returnType;
+    }
 
-                } else {
-                    returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER
-                            .javaTypeForSchemaDefinitionType(typeDefinition);
+    public Type generatedTypeForExtendedDefinitionType(
+            final TypeDefinition<?> typeDefinition) {
+        Type returnType = null;
+        if (typeDefinition == null) {
+            throw new IllegalArgumentException("Type Definition cannot be " +
+                    "NULL!");
+        }
+        if (typeDefinition.getQName() == null) {
+            throw new IllegalArgumentException("Type Definition cannot have " +
+                    "non specified QName (QName cannot be NULL!)");
+        }
+        if (typeDefinition.getQName() == null) {
+            throw new IllegalArgumentException("Type Definitions Local Name " +
+                    "cannot be NULL!");
+        }
+
+        final String typedefName = typeDefinition.getQName().getLocalName();
+        if (typeDefinition instanceof ExtendedType) {
+            final TypeDefinition<?> baseTypeDef = baseTypeDefForExtendedType(typeDefinition);
+
+            if (!(baseTypeDef instanceof LeafrefTypeDefinition)
+                    && !(baseTypeDef instanceof IdentityrefTypeDefinition)) {
+                final Module module = findParentModuleForTypeDefinition(schemaContext,
+                        typeDefinition);
+
+                if (module != null) {
+                    final Map<String, Type> genTOs = genTypeDefsContextMap
+                            .get(module.getName());
+                    if (genTOs != null) {
+                        returnType = genTOs.get(typedefName);
+                    }
                 }
             }
         }
@@ -125,56 +178,55 @@ public class TypeProviderImpl implements TypeProvider {
 
     private TypeDefinition<?> baseTypeDefForExtendedType(
             final TypeDefinition<?> extendTypeDef) {
-        if (extendTypeDef != null) {
-            final TypeDefinition<?> baseTypeDef = extendTypeDef.getBaseType();
-            if (baseTypeDef instanceof ExtendedType) {
-                return baseTypeDefForExtendedType(baseTypeDef);
-            } else {
-                return baseTypeDef;
-            }
+        if (extendTypeDef == null) {
+            throw new IllegalArgumentException("Type Definiition reference " +
+                    "cannot be NULL!");
         }
-        return null;
+        final TypeDefinition<?> baseTypeDef = extendTypeDef.getBaseType();
+        if (baseTypeDef instanceof ExtendedType) {
+            return baseTypeDefForExtendedType(baseTypeDef);
+        } else {
+            return baseTypeDef;
+        }
+
     }
 
-    public Type baseTypeForExtendedType(final TypeDefinition<?> typeDefinition) {
+    public Type provideTypeForLeafref(final LeafrefTypeDefinition leafrefType) {
         Type returnType = null;
-        if (typeDefinition != null) {
-            final TypeDefinition<?> baseTypeDefinition = baseTypeDefForExtendedType(typeDefinition);
+        if (leafrefType == null) {
+            throw new IllegalArgumentException("Leafref Type Definition " +
+                    "reference cannot be NULL!");
+        }
 
-            if (baseTypeDefinition instanceof EnumTypeDefinition) {
-                final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) typeDefinition;
-                final String enumName = enumTypeDef.getQName().getLocalName();
-                return resolveEnumFromTypeDefinition(enumTypeDef, enumName);
-            } else {
-                returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER
-                        .javaTypeForSchemaDefinitionType(typeDefinition);
-            }
+        if (leafrefType.getPathStatement() == null) {
+            throw new IllegalArgumentException("The Path Statement for " +
+                    "Leafref Type Definition cannot be NULL!");
         }
-        return returnType;
-    }
 
-    public Type provideTypeForLeafref(final LeafrefTypeDefinition leafrefType) {
-        Type returnType = null;
-        if ((leafrefType != null) && (leafrefType.getPathStatement() != null)
-                && (leafrefType.getPath() != null)) {
+        final RevisionAwareXPath xpath = leafrefType.getPathStatement();
+        final String strXPath = xpath.toString();
 
-            final RevisionAwareXPath xpath = leafrefType.getPathStatement();
-            final String strXPath = xpath.toString();
+        if (strXPath != null) {
+            if (strXPath.matches(".*//[.* | .*//].*")) {
+                returnType = Types.typeForClass(Object.class);
+            } else {
+                final Module module = findParentModuleForTypeDefinition(schemaContext, leafrefType);
+                if (module != null) {
+                    final DataSchemaNode dataNode;
+                    if (xpath.isAbsolute()) {
+                        dataNode = findDataSchemaNode(schemaContext, module,
+                                xpath);
+                    } else {
+                        dataNode = findDataSchemaNodeForRelativeXPath(schemaContext,
+                                module, leafrefType, xpath);
+                    }
 
-            if (strXPath != null) {
-                if (strXPath.matches(".*//[.* | .*//].*")) {
-                    returnType = Types.typeForClass(Object.class);
-                } else {
-                    final Module module = resolveModuleFromTypePath(schemaContext, leafrefType);
-                    if (module != null) {
-                        final DataSchemaNode dataNode;
-                        if (xpath.isAbsolute()) {
-                            dataNode = findDataSchemaNode(schemaContext,
-                                    module, xpath);
-                        } else {
-                            dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module,
-                                            leafrefType, xpath);
-                        }
+                    if (leafContainsEnumDefinition(dataNode)) {
+                        returnType = referencedTypes.get(dataNode.getPath());
+                    } else if (leafListContainsEnumDefinition(dataNode)) {
+                        returnType = Types.listTypeFor(referencedTypes.get(
+                                dataNode.getPath()));
+                    } else {
                         returnType = resolveTypeFromDataSchemaNode(dataNode);
                     }
                 }
@@ -183,83 +235,112 @@ public class TypeProviderImpl implements TypeProvider {
         return returnType;
     }
 
-    private EnumBuilder resolveEnumFromTypeDefinition(
-            final EnumTypeDefinition enumTypeDef, final String enumName,
-            final GeneratedTypeBuilder typeBuilder) {
-        if ((enumTypeDef != null) && (typeBuilder != null)
-                && (enumTypeDef.getQName() != null)
-                && (enumTypeDef.getQName().getLocalName() != null)) {
-
-            final String enumerationName = BindingGeneratorUtil
-                    .parseToClassName(enumName);
-            final EnumBuilder enumBuilder = typeBuilder
-                    .addEnumeration(enumerationName);
-
-            if (enumBuilder != null) {
-                final List<EnumPair> enums = enumTypeDef.getValues();
-                if (enums != null) {
-                    int listIndex = 0;
-                    for (final EnumPair enumPair : enums) {
-                        if (enumPair != null) {
-                            final String enumPairName = BindingGeneratorUtil
-                                    .parseToClassName(enumPair.getName());
-                            Integer enumPairValue = enumPair.getValue();
-
-                            if (enumPairValue == null) {
-                                enumPairValue = listIndex;
-                            }
-                            enumBuilder.addValue(enumPairName, enumPairValue);
-                            listIndex++;
-                        }
-                    }
-                }
-                return enumBuilder;
+    private boolean leafContainsEnumDefinition(final DataSchemaNode dataNode) {
+        if (dataNode instanceof LeafSchemaNode) {
+            final LeafSchemaNode leaf = (LeafSchemaNode) dataNode;
+            if (leaf.getType() instanceof EnumTypeDefinition) {
+                return true;
             }
         }
-        return null;
+        return false;
+    }
+
+    private boolean leafListContainsEnumDefinition(
+            final DataSchemaNode dataNode) {
+        if (dataNode instanceof LeafListSchemaNode) {
+            final LeafListSchemaNode leafList = (LeafListSchemaNode) dataNode;
+            if (leafList.getType() instanceof EnumTypeDefinition) {
+                return true;
+            }
+        }
+        return false;
     }
 
     private Enumeration resolveEnumFromTypeDefinition(
             final EnumTypeDefinition enumTypeDef, final String enumName) {
-        if ((enumTypeDef != null) && (enumTypeDef.getQName() != null)
-                && (enumTypeDef.getQName().getLocalName() != null)) {
-
-            final String enumerationName = BindingGeneratorUtil
-                    .parseToClassName(enumName);
-
-            Module module = resolveModuleFromTypePath(schemaContext, enumTypeDef);
-
-            final String basePackageName = BindingGeneratorUtil
-                    .moduleNamespaceToPackageName(module);
-            final String packageName = BindingGeneratorUtil
-                    .packageNameForGeneratedType(basePackageName,
-                            enumTypeDef.getPath());
-
-            final EnumBuilder enumBuilder = new EnumerationBuilderImpl(
-                    packageName, enumerationName);
-
-            if (enumBuilder != null) {
-                final List<EnumPair> enums = enumTypeDef.getValues();
-                if (enums != null) {
-                    int listIndex = 0;
-                    for (final EnumPair enumPair : enums) {
-                        if (enumPair != null) {
-                            final String enumPairName = BindingGeneratorUtil
-                                    .parseToClassName(enumPair.getName());
-                            Integer enumPairValue = enumPair.getValue();
-
-                            if (enumPairValue == null) {
-                                enumPairValue = listIndex;
-                            }
-                            enumBuilder.addValue(enumPairName, enumPairValue);
-                            listIndex++;
+        if (enumTypeDef == null) {
+            throw new IllegalArgumentException("EnumTypeDefinition reference " +
+                    "cannot be NULL!");
+        }
+        if (enumTypeDef.getValues() == null) {
+            throw new IllegalArgumentException("EnumTypeDefinition MUST " +
+                    "contain at least ONE value definition!");
+        }
+        if (enumTypeDef.getQName() == null) {
+            throw new IllegalArgumentException("EnumTypeDefinition MUST " +
+                    "contain NON-NULL QName!");
+        }
+        if (enumTypeDef.getQName().getLocalName() == null) {
+            throw new IllegalArgumentException("Local Name in " +
+                    "EnumTypeDefinition QName cannot be NULL!");
+        }
+
+        final String enumerationName = parseToClassName(enumName);
+
+        Module module = findParentModuleForTypeDefinition(schemaContext, enumTypeDef);
+        final String basePackageName = moduleNamespaceToPackageName(module);
+
+        final EnumBuilder enumBuilder = new EnumerationBuilderImpl(
+                basePackageName, enumerationName);
+        updateEnumPairsFromEnumTypeDef(enumTypeDef, enumBuilder);
+        return enumBuilder.toInstance(null);
+    }
+
+    private EnumBuilder resolveInnerEnumFromTypeDefinition(
+            final EnumTypeDefinition enumTypeDef, final String enumName,
+            final GeneratedTypeBuilder typeBuilder) {
+        if (enumTypeDef == null) {
+            throw new IllegalArgumentException("EnumTypeDefinition reference " +
+                    "cannot be NULL!");
+        }
+        if (enumTypeDef.getValues() == null) {
+            throw new IllegalArgumentException("EnumTypeDefinition MUST " +
+                    "contain at least ONE value definition!");
+        }
+        if (enumTypeDef.getQName() == null) {
+            throw new IllegalArgumentException("EnumTypeDefinition MUST " +
+                    "contain NON-NULL QName!");
+        }
+        if (enumTypeDef.getQName().getLocalName() == null) {
+            throw new IllegalArgumentException("Local Name in " +
+                    "EnumTypeDefinition QName cannot be NULL!");
+        }
+        if (typeBuilder == null) {
+            throw new IllegalArgumentException("Generated Type Builder " +
+                    "reference cannot be NULL!");
+        }
+
+        final String enumerationName = parseToClassName(enumName);
+        final EnumBuilder enumBuilder = typeBuilder
+                .addEnumeration(enumerationName);
+
+        updateEnumPairsFromEnumTypeDef(enumTypeDef, enumBuilder);
+
+        return enumBuilder;
+    }
+
+    private void updateEnumPairsFromEnumTypeDef(
+            final EnumTypeDefinition enumTypeDef,
+            final EnumBuilder enumBuilder) {
+        if (enumBuilder != null) {
+            final List<EnumPair> enums = enumTypeDef.getValues();
+            if (enums != null) {
+                int listIndex = 0;
+                for (final EnumPair enumPair : enums) {
+                    if (enumPair != null) {
+                        final String enumPairName = parseToClassName(enumPair
+                                .getName());
+                        Integer enumPairValue = enumPair.getValue();
+
+                        if (enumPairValue == null) {
+                            enumPairValue = listIndex;
                         }
+                        enumBuilder.addValue(enumPairName, enumPairValue);
+                        listIndex++;
                     }
                 }
-                return enumBuilder.toInstance(null);
             }
         }
-        return null;
     }
 
     private Type resolveTypeFromDataSchemaNode(final DataSchemaNode dataNode) {
@@ -276,129 +357,185 @@ public class TypeProviderImpl implements TypeProvider {
         return returnType;
     }
 
-    private List<GeneratedTransferObject> resolveTypeDefsFromContext() {
-        final List<GeneratedTransferObject> genTypeDefs = new ArrayList<GeneratedTransferObject>();
+    private void resolveTypeDefsFromContext() {
         final Set<Module> modules = schemaContext.getModules();
-        if (modules != null) {
-            for (final Module module : modules) {
-                if (module != null) {
-                    final String moduleName = module.getName();
-                    final String basePackageName = BindingGeneratorUtil
-                            .moduleNamespaceToPackageName(module);
-
-                    final Set<TypeDefinition<?>> typeDefinitions = module
-                            .getTypeDefinitions();
-
-                    if ((typeDefinitions != null) && (basePackageName != null)) {
-                        for (final TypeDefinition<?> typedef : typeDefinitions) {
-                            final GeneratedTransferObject genTransObj = toGeneratedTransferObject(
-                                    basePackageName, moduleName, typedef);
-                            if (genTransObj != null) {
-                                genTypeDefs.add(genTransObj);
-                            }
-                        }
-                        // for (final TypeDefinition<?> typedef :
-                        // typeDefinitions) {
-                        // addUnionGeneratedTypeDefinition(basePackageName,
-                        // module.getName(), typedef);
-                        // }
-                    }
+        if (modules == null) {
+            throw new IllegalArgumentException("Sef of Modules cannot be " +
+                    "NULL!");
+        }
+        for (final Module module : modules) {
+            if (module == null) {
+                continue;
+            }
+            final String moduleName = module.getName();
+            final String basePackageName = moduleNamespaceToPackageName(module);
+
+            final Set<TypeDefinition<?>> typeDefinitions = module
+                    .getTypeDefinitions();
+
+            final Map<String, Type> typeMap = new HashMap<>();
+            genTypeDefsContextMap.put(moduleName, typeMap);
+
+            if ((typeDefinitions != null) && (basePackageName != null)) {
+                for (final TypeDefinition<?> typedef : typeDefinitions) {
+                    typedefToGeneratedType(basePackageName, moduleName, typedef);
+                }
+                final List<ExtendedType> extUnions = UnionDependencySort
+                        .sort(typeDefinitions);
+                for (final ExtendedType extUnionType : extUnions) {
+                    addUnionGeneratedTypeDefinition(basePackageName, extUnionType);
                 }
             }
         }
-        return genTypeDefs;
     }
 
-    private GeneratedTransferObject toGeneratedTransferObject(
-            final String basePackageName, final String moduleName,
-            final TypeDefinition<?> typedef) {
+    private Type typedefToGeneratedType(final String basePackageName,
+                                        final String moduleName, final TypeDefinition<?> typedef) {
         if ((basePackageName != null) && (moduleName != null)
                 && (typedef != null) && (typedef.getQName() != null)) {
-            final GeneratedTOBuilder genTOBuilder = typedefToTransferObject(
-                    basePackageName, typedef);
 
-            final String typedefName = typedef.getQName().getLocalName();
-            final String propertyName = BindingGeneratorUtil
-                    .parseToValidParamName(typedefName);
 
+            final String typedefName = typedef.getQName().getLocalName();
             final TypeDefinition<?> baseTypeDefinition = baseTypeDefForExtendedType(typedef);
             if (!(baseTypeDefinition instanceof LeafrefTypeDefinition)
                     && !(baseTypeDefinition instanceof IdentityrefTypeDefinition)) {
-                Type returnType = null;
+                Type returnType;
                 if (baseTypeDefinition instanceof EnumTypeDefinition) {
                     final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) baseTypeDefinition;
                     returnType = resolveEnumFromTypeDefinition(enumTypeDef,
                             typedefName);
+
                 } else {
-                    returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER
+                    final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER
                             .javaTypeForSchemaDefinitionType(baseTypeDefinition);
-                }
 
+                    returnType = wrapJavaTypeIntoTO(basePackageName, typedef,
+                            javaType);
+                }
                 if (returnType != null) {
-                    final GeneratedPropertyBuilder genPropBuilder = genTOBuilder
-                            .addProperty(propertyName);
-
-                    genPropBuilder.addReturnType(returnType);
-                    genTOBuilder.addEqualsIdentity(genPropBuilder);
-                    genTOBuilder.addHashIdentity(genPropBuilder);
-                    genTOBuilder.addToStringProperty(genPropBuilder);
-
-                    Map<String, GeneratedTransferObject> transferObjectsMap = genTypeDefsContextMap
-                            .get(moduleName);
-                    if (transferObjectsMap == null) {
-                        transferObjectsMap = new HashMap<String, GeneratedTransferObject>();
-                        genTypeDefsContextMap.put(moduleName,
-                                transferObjectsMap);
-                    }
-
-                    final GeneratedTransferObject transferObject = genTOBuilder
-                            .toInstance();
-                    if (transferObject != null) {
-                        transferObjectsMap.put(typedefName, transferObject);
-                        return transferObject;
+                    final Map<String, Type> typeMap = genTypeDefsContextMap.get
+                            (moduleName);
+                    if (typeMap != null) {
+                        typeMap.put(typedefName, returnType);
                     }
+                    return returnType;
                 }
             }
         }
         return null;
     }
 
+    private GeneratedTransferObject wrapJavaTypeIntoTO(
+            final String basePackageName, final TypeDefinition<?> typedef,
+            final Type javaType) {
+        if (javaType != null) {
+            final String typedefName = typedef.getQName().getLocalName();
+            final String propertyName = parseToValidParamName(typedefName);
+
+            final GeneratedTOBuilder genTOBuilder = typedefToTransferObject(
+                    basePackageName, typedef);
+
+            final GeneratedPropertyBuilder genPropBuilder = genTOBuilder
+                    .addProperty(propertyName);
+
+            genPropBuilder.addReturnType(javaType);
+            genTOBuilder.addEqualsIdentity(genPropBuilder);
+            genTOBuilder.addHashIdentity(genPropBuilder);
+            genTOBuilder.addToStringProperty(genPropBuilder);
+            return genTOBuilder.toInstance();
+        }
+        return null;
+    }
+
     private void addUnionGeneratedTypeDefinition(final String basePackageName,
-            final String moduleName, final TypeDefinition<?> typedef) {
-        if ((basePackageName != null) && (moduleName != null)
-                && (typedef != null) && (typedef.getQName() != null)) {
-            final TypeDefinition<?> baseTypeDefinition = baseTypeDefForExtendedType(typedef);
+                                                 final TypeDefinition<?> typedef) {
+        if (basePackageName == null) {
+            throw new IllegalArgumentException("Base Package Name cannot be " +
+                    "NULL!");
+        }
+        if (typedef == null) {
+            throw new IllegalArgumentException("Type Definition cannot be " +
+                    "NULL!");
+        }
+        if (typedef.getQName() == null) {
+            throw new IllegalArgumentException("Type Definition cannot have " +
+                    "non specified QName (QName cannot be NULL!)");
+        }
 
-            if ((baseTypeDefinition != null)
-                    && (baseTypeDefinition instanceof UnionTypeDefinition)) {
-                final UnionTypeDefinition unionTypeDef = (UnionTypeDefinition) baseTypeDefinition;
-
-                final List<TypeDefinition<?>> unionTypes = unionTypeDef
-                        .getTypes();
-                final Map<String, GeneratedTransferObject> genTOsMap = genTypeDefsContextMap
-                        .get(moduleName);
-                final GeneratedTOBuilder unionGenTransObject = typedefToTransferObject(
-                        basePackageName, typedef);
-                if ((unionTypes != null) && (genTOsMap != null)
-                        && (unionGenTransObject != null)) {
-                    for (final TypeDefinition<?> unionType : unionTypes) {
-                        final String typeName = unionType.getQName()
-                                .getLocalName();
-                        final GeneratedTransferObject genTransferObject = genTOsMap
-                                .get(typeName);
-
-                        if (genTransferObject != null) {
-                            unionGenTransObject
-                                    .addProperty(
-                                            BindingGeneratorUtil
-                                                    .parseToValidParamName(genTransferObject
-                                                            .getName()))
-                                    .addReturnType(genTransferObject);
+        final TypeDefinition<?> baseTypeDefinition = typedef.getBaseType();
+        if ((baseTypeDefinition != null)
+                && (baseTypeDefinition instanceof UnionTypeDefinition)) {
+            final UnionTypeDefinition unionTypeDef = (UnionTypeDefinition) baseTypeDefinition;
+            final List<TypeDefinition<?>> unionTypes = unionTypeDef
+                    .getTypes();
+            final Module parentModule = findParentModuleForTypeDefinition(schemaContext,
+                    typedef);
+
+            Map<String, Type> genTOsMap = null;
+            if (parentModule != null && parentModule.getName() != null) {
+                genTOsMap = genTypeDefsContextMap.get(parentModule.getName());
+            }
+
+            final GeneratedTOBuilder unionGenTransObject = typedefToTransferObject(
+                    basePackageName, typedef);
+            if ((unionTypes != null) && (unionGenTransObject != null)) {
+                for (final TypeDefinition<?> unionType : unionTypes) {
+                    final String typeName = unionType.getQName()
+                            .getLocalName();
+                    if (unionType instanceof ExtendedType) {
+                        final Module unionTypeModule = findParentModuleForTypeDefinition(schemaContext,
+                                unionType);
+                        if (unionTypeModule != null && unionTypeModule.getName() != null) {
+                            final Map<String, Type> innerGenTOs = genTypeDefsContextMap
+                                    .get(unionTypeModule.getName());
+
+                            final GeneratedTransferObject genTransferObject =
+                                    (GeneratedTransferObject) innerGenTOs.get(typeName);
+                            if (genTransferObject != null) {
+                                updateUnionTypeAsProperty(unionGenTransObject,
+                                        genTransferObject,
+                                        genTransferObject.getName());
+                            }
+                        }
+                    } else if (unionType instanceof EnumTypeDefinition) {
+                        final EnumBuilder
+                                enumBuilder = resolveInnerEnumFromTypeDefinition(
+                                (EnumTypeDefinition) unionType, typeName,
+                                unionGenTransObject);
+                        final Type enumRefType = new ReferencedTypeImpl(
+                                enumBuilder.getPackageName(),
+                                enumBuilder.getName());
+                        updateUnionTypeAsProperty(unionGenTransObject,
+                                enumRefType, typeName);
+                    } else {
+                        final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER
+                                .javaTypeForSchemaDefinitionType(unionType);
+                        if (javaType != null) {
+                            updateUnionTypeAsProperty(unionGenTransObject,
+                                    javaType, typeName);
                         }
                     }
-                    genTOsMap.put(unionTypeDef.getQName().getLocalName(),
-                            unionGenTransObject.toInstance());
                 }
+                genTOsMap.put(typedef.getQName().getLocalName(),
+                        unionGenTransObject.toInstance());
+            }
+        }
+    }
+
+    private void updateUnionTypeAsProperty(
+            final GeneratedTOBuilder unionGenTransObject, final Type type,
+            final String propertyName) {
+        if (unionGenTransObject != null && type != null) {
+            final GeneratedPropertyBuilder propBuilder =
+                    unionGenTransObject.addProperty(parseToValidParamName(
+                            propertyName));
+            propBuilder.addReturnType(type);
+            propBuilder.setReadOnly(false);
+
+            if (!(type instanceof Enumeration)) {
+                unionGenTransObject.addEqualsIdentity(propBuilder);
+                unionGenTransObject.addHashIdentity(propBuilder);
+                unionGenTransObject.addToStringProperty(propBuilder);
             }
         }
     }
@@ -406,14 +543,13 @@ public class TypeProviderImpl implements TypeProvider {
     private GeneratedTOBuilder typedefToTransferObject(
             final String basePackageName, final TypeDefinition<?> typedef) {
 
-        final String packageName = BindingGeneratorUtil
-                .packageNameForGeneratedType(basePackageName, typedef.getPath());
+        final String packageName = packageNameForGeneratedType(basePackageName,
+                typedef.getPath());
         final String typeDefTOName = typedef.getQName().getLocalName();
 
         if ((packageName != null) && (typedef != null)
                 && (typeDefTOName != null)) {
-            final String genTOName = BindingGeneratorUtil
-                    .parseToClassName(typeDefTOName);
+            final String genTOName = parseToClassName(typeDefTOName);
             final GeneratedTOBuilder newType = new GeneratedTOBuilderImpl(
                     packageName, genTOName);
 
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/yang/types/UnionDependencySort.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/yang/types/UnionDependencySort.java
new file mode 100644 (file)
index 0000000..d19ac3f
--- /dev/null
@@ -0,0 +1,161 @@
+/*
+ * 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.controller.sal.binding.yang.types;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.type.UnionTypeDefinition;
+import org.opendaylight.controller.yang.model.util.ExtendedType;
+import org.opendaylight.controller.yang.parser.util.TopologicalSort;
+import org.opendaylight.controller.yang.parser.util.TopologicalSort.Node;
+import org.opendaylight.controller.yang.parser.util.TopologicalSort.NodeImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class UnionDependencySort {
+    private static final Logger logger = LoggerFactory
+            .getLogger(UnionDependencySort.class);
+
+    public static List<ExtendedType> sort(
+            final Set<TypeDefinition<?>> typeDefinitions) {
+        if (typeDefinitions == null) {
+            logger.error("Set of Type Definitions cannot be NULL!");
+            throw new IllegalArgumentException("Set of Type Definitions " +
+                    "cannot be NULL!");
+        }
+
+        final Set<ExtendedType> extUnionTypes =
+                unionsFromTypeDefinitions(typeDefinitions);
+
+        final Set<Node> unsorted = unionTypesToUnionNodes(extUnionTypes);
+
+        final List<Node> sortedNodes = TopologicalSort.sort(unsorted);
+        return Lists.transform(sortedNodes, new Function<Node, ExtendedType>() {
+            @Override
+            public ExtendedType apply(Node input) {
+                return ((UnionNode) input).getUnionType();
+            }
+        });
+    }
+
+    private static Set<ExtendedType> unionsFromTypeDefinitions(
+            final Set<TypeDefinition<?>> typeDefinitions) {
+        final Set<ExtendedType> unions = Sets.newHashSet();
+
+        for (final TypeDefinition<?> typedef : typeDefinitions) {
+            if ((typedef != null) && (typedef.getBaseType() != null)) {
+                if (typedef instanceof ExtendedType
+                        && typedef.getBaseType() instanceof UnionTypeDefinition) {
+                    unions.add((ExtendedType) typedef);
+                }
+            }
+        }
+        return unions;
+    }
+
+    private static Set<Node> unionTypesToUnionNodes(
+            final Set<ExtendedType> extUnionTypes) {
+        final Map<ExtendedType, Node> nodeMap = Maps.newHashMap();
+        final Set<Node> resultNodes = Sets.newHashSet();
+
+        for (final ExtendedType unionType : extUnionTypes) {
+            final Node node = new UnionNode(unionType);
+            nodeMap.put(unionType, node);
+            resultNodes.add(node);
+        }
+
+        for (final Node node : resultNodes) {
+            final UnionNode unionNode = (UnionNode) node;
+            final ExtendedType extUnionType = unionNode.getUnionType();
+
+            final UnionTypeDefinition unionType = (UnionTypeDefinition)
+                    extUnionType.getBaseType();
+
+            final List<TypeDefinition<?>> innerTypes = unionType.getTypes();
+            for (final TypeDefinition<?> typedef : innerTypes) {
+                if (extUnionTypes.contains(typedef)) {
+                    final Node toNode = nodeMap.get(typedef);
+                    unionNode.addEdge(toNode);
+                }
+            }
+        }
+
+        return resultNodes;
+    }
+
+    private static UnionNode unionTypeToUnionNode(
+            final ExtendedType extUnionType,
+            final Set<ExtendedType> extUnionTypes) {
+        final UnionNode node = new UnionNode(extUnionType);
+
+        if (extUnionType.getBaseType() instanceof UnionTypeDefinition) {
+            final UnionTypeDefinition unionType = (UnionTypeDefinition)
+                    extUnionType.getBaseType();
+
+            final List<TypeDefinition<?>> innerTypes = unionType.getTypes();
+            for (final TypeDefinition<?> typedef : innerTypes) {
+                if ((typedef != null) && (typedef instanceof ExtendedType)
+                        && (typedef.getBaseType() instanceof UnionTypeDefinition)) {
+                    if (extUnionTypes.contains(typedef)) {
+                        node.addEdge(new UnionNode((ExtendedType) typedef));
+                    }
+                }
+            }
+        }
+
+        return node;
+    }
+
+    @VisibleForTesting
+    static final class UnionNode extends NodeImpl {
+        private final ExtendedType unionType;
+
+        UnionNode(ExtendedType unionType) {
+            this.unionType = unionType;
+        }
+
+        ExtendedType getUnionType() {
+            return unionType;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (!(o instanceof UnionNode)) {
+                return false;
+            }
+            UnionNode unionNode = (UnionNode) o;
+            if (!unionType.equals(unionNode.unionType)) {
+                return false;
+            }
+            return true;
+        }
+
+        @Override
+        public int hashCode() {
+            return unionType.hashCode();
+        }
+
+        @Override
+        public String toString() {
+            return "UnionNode{" +
+                    "unionType=" + unionType +
+                    '}';
+        }
+    }
+}
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/AugmentRleativeXPathTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/AugmentRleativeXPathTest.java
new file mode 100644 (file)
index 0000000..185d95b
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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.controller.sal.binding.generator.impl;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
+import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
+import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+public class AugmentRleativeXPathTest {
+
+    private final static List<File> augmentModels = new ArrayList<>();
+    private final static String augmentFolderPath = AugmentedTypeTest.class
+            .getResource("/augment-relative-xpath-models").getPath();
+
+    @BeforeClass
+    public static void loadTestResources() {
+        final File augFolder = new File(augmentFolderPath);
+
+        for (final File fileEntry : augFolder.listFiles()) {
+            if (fileEntry.isFile()) {
+                augmentModels.add(fileEntry);
+            }
+        }
+    }
+
+    @Test
+    public void AugmentationWithRelativeXPathTest() {
+        final YangModelParser parser = new YangParserImpl();
+        final Set<Module> modules = parser.parseYangModels(augmentModels);
+        final SchemaContext context = parser.resolveSchemaContext(modules);
+
+        assertNotNull("context is null", context);
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();
+        final List<Type> genTypes = bindingGen.generateTypes(context);
+
+        assertNotNull("genTypes is null", genTypes);
+        assertFalse("genTypes is empty", genTypes.isEmpty());
+    }
+}
index 448f610..0fc4e43 100644 (file)
@@ -7,26 +7,22 @@
  */
 package org.opendaylight.controller.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.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
-import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
-import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.*;
 import org.opendaylight.controller.yang.model.api.Module;
 import org.opendaylight.controller.yang.model.api.SchemaContext;
 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
 import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.*;
+
 public class AugmentedTypeTest {
 
     private final static List<File> augmentModels = new ArrayList<>();
@@ -63,16 +59,16 @@ public class AugmentedTypeTest {
         GeneratedTransferObject gtTunnelKey = null;
         GeneratedType gtNetworkLink2 = null;
 
-        for(final Type type : genTypes) {
-            if(type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {
+        for (final Type type : genTypes) {
+            if (type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {
                 gtInterfaceKey = (GeneratedTransferObject) type;
-            } else if(type.getName().equals("Interface") && type.getPackageName().contains("augment._abstract.topology")) {
+            } else if (type.getName().equals("Interface") && type.getPackageName().contains("augment._abstract.topology")) {
                 gtInterface = (GeneratedType) type;
-            } else if(type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {
+            } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {
                 gtTunnel = (GeneratedType) type;
-            } else if(type.getName().equals("TunnelKey") && type.getPackageName().contains("augment._abstract.topology")) {
+            } else if (type.getName().equals("TunnelKey") && type.getPackageName().contains("augment._abstract.topology")) {
                 gtTunnelKey = (GeneratedTransferObject) type;
-            } else if(type.getName().equals("NetworkLink2") && type.getPackageName().contains("augment._abstract.topology")) {
+            } else if (type.getName().equals("NetworkLink2") && type.getPackageName().contains("augment._abstract.topology")) {
                 gtNetworkLink2 = (GeneratedType) type;
             }
         }
@@ -90,8 +86,10 @@ public class AugmentedTypeTest {
         }
         assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);
         assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType());
-        assertFalse("getIfcKeyMethod.getReturnType() should not be Void", getIfcKeyMethod.getReturnType().equals("java.lang.Void"));
-        assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey", getIfcKeyMethod.getReturnType().getName().equals("InterfaceKey"));
+        assertFalse("getIfcKeyMethod.getReturnType() should not be Void",
+                getIfcKeyMethod.getReturnType().equals("java.lang.Void"));
+        assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey",
+                getIfcKeyMethod.getReturnType().getName().equals("InterfaceKey"));
 
         MethodSignature getHigherLayerIfMethod = null;
         for (final MethodSignature method : gtInterfaceMethods) {
@@ -101,9 +99,12 @@ public class AugmentedTypeTest {
             }
         }
         assertNotNull("getHigherLayerIfMethod is null", getHigherLayerIfMethod);
-        assertNotNull("getHigherLayerIfMethod.getReturnType() is null", getHigherLayerIfMethod.getReturnType());
-        assertFalse("getHigherLayerIfMethod.getReturnType() should not be Void", getHigherLayerIfMethod.getReturnType().equals("java.lang.Void"));
-        assertTrue("getHigherLayerIfMethod.getReturnType().getName() must be List", getHigherLayerIfMethod.getReturnType().getName().equals("List"));
+        assertNotNull("getHigherLayerIfMethod.getReturnType() is null",
+                getHigherLayerIfMethod.getReturnType());
+        assertFalse("getHigherLayerIfMethod.getReturnType() should not be Void",
+                getHigherLayerIfMethod.getReturnType().equals("java.lang.Void"));
+        assertTrue("getHigherLayerIfMethod.getReturnType().getName() must be List",
+                getHigherLayerIfMethod.getReturnType().getName().equals("List"));
 
         // 'InterfaceKey'
         assertNotNull("gtInterfaceKey is null", gtInterfaceKey);
@@ -118,8 +119,10 @@ public class AugmentedTypeTest {
         }
         assertNotNull("gtInterfaceId is null", gtInterfaceId);
         assertNotNull("gtInterfaceId.getReturnType() is null", gtInterfaceId.getReturnType());
-        assertFalse("gtInterfaceId.getReturnType() should not be Void", gtInterfaceId.getReturnType().equals("java.lang.Void"));
-        assertTrue("gtInterfaceId.getReturnType().getName() must be String", gtInterfaceId.getReturnType().getName().equals("String"));
+        assertFalse("gtInterfaceId.getReturnType() should not be Void",
+                gtInterfaceId.getReturnType().equals("java.lang.Void"));
+        assertTrue("gtInterfaceId.getReturnType().getName() must be String",
+                gtInterfaceId.getReturnType().getName().equals("String"));
 
         // 'Tunnel'
         assertNotNull("gtTunnel is null", gtTunnel);
@@ -133,9 +136,12 @@ public class AugmentedTypeTest {
             }
         }
         assertNotNull("getTunnelKeyMethod is null", getTunnelKeyMethod);
-        assertNotNull("getTunnelKeyMethod.getReturnType()", getTunnelKeyMethod.getReturnType());
-        assertFalse("getTunnelKeyMethod.getReturnType() should not be Void", getTunnelKeyMethod.getReturnType().equals("java.lang.Void"));
-        assertTrue("getTunnelKeyMethod.getReturnType().getName() must be TunnelKey", getTunnelKeyMethod.getReturnType().getName().equals("TunnelKey"));
+        assertNotNull("getTunnelKeyMethod.getReturnType()",
+                getTunnelKeyMethod.getReturnType());
+        assertFalse("getTunnelKeyMethod.getReturnType() should not be Void",
+                getTunnelKeyMethod.getReturnType().equals("java.lang.Void"));
+        assertTrue("getTunnelKeyMethod.getReturnType().getName() must be TunnelKey",
+                getTunnelKeyMethod.getReturnType().getName().equals("TunnelKey"));
 
         // 'TunnelKey'
         assertNotNull("gtTunnelKey is null", gtTunnelKey);
@@ -149,9 +155,12 @@ public class AugmentedTypeTest {
             }
         }
         assertNotNull("gtTunnelId is null", gtTunnelId);
-        assertNotNull("gtTunnelId.getReturnType() is null", gtTunnelId.getReturnType());
-        assertFalse("gtTunnelId.getReturnType() should not be Void", gtTunnelId.getReturnType().equals("java.lang.Void"));
-        assertTrue("gtTunnelId.getReturnType().getName() must be Integer", gtTunnelId.getReturnType().getName().equals("Integer"));
+        assertNotNull("gtTunnelId.getReturnType() is null",
+                gtTunnelId.getReturnType());
+        assertFalse("gtTunnelId.getReturnType() should not be Void",
+                gtTunnelId.getReturnType().equals("java.lang.Void"));
+        assertTrue("gtTunnelId.getReturnType().getName() must be Integer",
+                gtTunnelId.getReturnType().getName().equals("Integer"));
 
         // 'NetworkLink2'
         assertNotNull("gtNetworkLink2 is null", gtNetworkLink2);
@@ -160,21 +169,18 @@ public class AugmentedTypeTest {
         assertNotNull("networkLink2Methods is null", networkLink2Methods);
 
 //        FIXME: in some cases getIfcMethod is null which causes test fail. fix ASAP
-//        MethodSignature getIfcMethod = null;
-//        for (MethodSignature method : networkLink2Methods) {
-//            if (method.getName().equals("getInterface")) {
-//                getIfcMethod = method;
-//                break;
-//            }
-//        }
+//      MethodSignature getIfcMethod = null;
+//      for (MethodSignature method : networkLink2Methods) {
+//          if (method.getName().equals("getInterface")) {
+//              getIfcMethod = method;
+//              break;
+//          }
+//      }
 //
-//        assertNotNull("getIfcMethod is null", getIfcMethod);
-//        assertNotNull("getIfcMethod.getReturnType() is null",
-//                getIfcMethod.getReturnType());
-//        assertFalse("getIfcMethod.getReturnType() should not be Void",
-//                getIfcMethod.getReturnType().equals("java.lang.Void"));
-//        assertTrue("getIfcMethod.getReturnType().getName() must be String",
-//                getIfcMethod.getReturnType().getName().equals("String"));
+//      assertNotNull("getIfcMethod is null", getIfcMethod);
+//      assertNotNull("getIfcMethod.getReturnType() is null", getIfcMethod.getReturnType());
+//      assertFalse("getIfcMethod.getReturnType() should not be Void", getIfcMethod.getReturnType().equals("java.lang.Void"));
+//      assertTrue("getIfcMethod.getReturnType().getName() must be String", getIfcMethod.getReturnType().getName().equals("String"));
     }
 
     @Test
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GenEnumResolvingTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GenEnumResolvingTest.java
new file mode 100644 (file)
index 0000000..6a0e114
--- /dev/null
@@ -0,0 +1,213 @@
+/*
+ * 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.controller.sal.binding.generator.impl;
+
+import org.junit.Test;
+import org.opendaylight.controller.binding.generator.util.ReferencedTypeImpl;
+import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
+import org.opendaylight.controller.sal.binding.model.api.Enumeration;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
+import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
+import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
+import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class GenEnumResolvingTest {
+
+    private SchemaContext resolveSchemaContextFromFiles(
+            final String... yangFiles) {
+        final YangModelParser parser = new YangParserImpl();
+
+        final List<File> inputFiles = new ArrayList<File>();
+        for (int i = 0; i < yangFiles.length; ++i) {
+            inputFiles.add(new File(yangFiles[i]));
+        }
+
+        final Set<Module> 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<Type> genTypes = bindingGen.generateTypes(context);
+        assertTrue(genTypes != null);
+
+        assertEquals("Expected count of all Generated Types from yang models " +
+                "is 22", 22, 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<Enumeration> enums = genInterface.getEnumDefintions();
+        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<MethodSignature> methods = genInterface
+                .getMethodDefinitions();
+
+        assertNotNull("Generated Interface cannot contain NULL reference for " +
+                "Method Signature Definitions!", methods);
+
+        assertEquals("Expected count of method signature definitions is 26",
+                26, 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<Type> genTypes = bindingGen.generateTypes(context);
+        assertTrue(genTypes != null);
+        assertEquals(2, 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<Type> 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<MethodSignature> methods = genInterface.getMethodDefinitions();
+        assertNotNull("Generated Type Interface cannot contain NULL reference" +
+                " to Enumeration types!", methods);
+        assertEquals("Generated Type Interface MUST contain 7 Methods ",
+                7, 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/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GenTypesSubSetTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GenTypesSubSetTest.java
new file mode 100644 (file)
index 0000000..c6d9a28
--- /dev/null
@@ -0,0 +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.controller.sal.binding.generator.impl;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
+import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
+import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
+
+import java.io.File;
+import java.util.*;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+public class GenTypesSubSetTest {
+
+    private final static List<File> 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<Module> modules = parser.parseYangModels(yangModels);
+        final SchemaContext context = parser.resolveSchemaContext(modules);
+
+        final Set<Module> 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<Type> 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<Module> modules = parser.parseYangModels(yangModels);
+        final SchemaContext context = parser.resolveSchemaContext(modules);
+
+        final Set<Module> 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<Type> 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!", 25, genTypes.size());
+    }
+}
index 66c293e..0010733 100644 (file)
@@ -42,53 +42,6 @@ public class GeneratedTypesTest {
         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<Type> genTypes = bindingGen.generateTypes(context);
-        assertTrue(genTypes != null);
-    }
-
-    @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<Type> genTypes = bindingGen.generateTypes(context);
-        assertTrue(genTypes != null);
-        assertEquals(2, genTypes.size());
-
-        final Type type = genTypes.get(1);
-        assertTrue(type instanceof GeneratedTransferObject);
-
-        final GeneratedTransferObject genTransObj = (GeneratedTransferObject) type;
-        final List<GeneratedProperty> properties = genTransObj.getProperties();
-        assertNotNull(properties);
-        assertEquals(1, properties.size());
-
-        GeneratedProperty property = properties.get(0);
-        assertNotNull(property);
-        assertNotNull(property.getReturnType());
-
-        assertTrue(property.getReturnType() instanceof Enumeration);
-        final Enumeration enumer = (Enumeration) property.getReturnType();
-        assertEquals(272, enumer.getValues().size());
-    }
-
     @Test
     public void testMultipleModulesResolving() {
         final String topologyPath = getClass().getResource(
@@ -103,7 +56,7 @@ public class GeneratedTypesTest {
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
         assertTrue(genTypes != null);
-        assertEquals(24, genTypes.size());
+        assertEquals(27, genTypes.size());
     }
 
     @Test
@@ -140,7 +93,7 @@ public class GeneratedTypesTest {
         final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
-        assertEquals(50, genTypes.size());
+        assertEquals(53, genTypes.size());
         assertTrue(genTypes != null);
 
         GeneratedTransferObject gtIfcKey = null;
@@ -310,8 +263,8 @@ public class GeneratedTypesTest {
         assertTrue(genTypes != null);
         assertEquals(3, genTypes.size());
 
-        final GeneratedType simpleContainer = (GeneratedType) genTypes.get(0);
-        final GeneratedType nestedContainer = (GeneratedType) genTypes.get(1);
+        final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
+        final GeneratedType nestedContainer = (GeneratedType) genTypes.get(2);
 
         assertEquals("SimpleContainer", simpleContainer.getName());
         assertEquals("NestedContainer", nestedContainer.getName());
@@ -388,8 +341,8 @@ public class GeneratedTypesTest {
         assertTrue(genTypes != null);
         assertEquals(3, genTypes.size());
 
-        final GeneratedType simpleContainer = (GeneratedType) genTypes.get(0);
-        final GeneratedType nestedContainer = (GeneratedType) genTypes.get(1);
+        final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
+        final GeneratedType nestedContainer = (GeneratedType) genTypes.get(2);
 
         assertEquals("SimpleContainer", simpleContainer.getName());
         assertEquals("NestedContainer", nestedContainer.getName());
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/UnionTypeDefTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/UnionTypeDefTest.java
new file mode 100644 (file)
index 0000000..31092b0
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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.controller.sal.binding.generator.impl;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
+import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
+import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+public class UnionTypeDefTest {
+    private final static List<File> yangModels = new ArrayList<>();
+    private final static String yangModelsFolder = AugmentedTypeTest.class
+            .getResource("/union-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 unionTypeResolvingTest() {
+        final YangModelParser parser = new YangParserImpl();
+        final Set<Module> modules = parser.parseYangModels(yangModels);
+        final SchemaContext context = parser.resolveSchemaContext(modules);
+
+        assertNotNull("context is null", context);
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();
+        final List<Type> genTypes = bindingGen.generateTypes(context);
+
+        assertNotNull("genTypes is null", genTypes);
+        assertFalse("genTypes is empty", genTypes.isEmpty());
+    }
+}
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/abstract-topology@2013-02-08.yang b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/abstract-topology@2013-02-08.yang
new file mode 100644 (file)
index 0000000..d80a3e9
--- /dev/null
@@ -0,0 +1,101 @@
+module abstract-topology {
+    yang-version 1;
+    namespace "urn:model:abstract:topology";
+    prefix "tp";
+
+    import ietf-inet-types { 
+        prefix "inet"; 
+        revision-date 2010-09-24;
+    }
+
+    organization "OPEN DAYLIGHT";
+    contact "http://www.opendaylight.org/";
+
+    description
+        "This module contains the definitions of elements that creates network 
+    topology i.e. definition of network nodes and links. This module is not designed 
+    to be used solely for network representation. This module SHOULD be used as base 
+    module in defining the network topology.";
+
+    revision "2013-02-08" {
+        reference "http://www.opendaylight.org/";
+    }
+    
+    typedef node-id-ref {
+        type leafref {
+            path "/tp:topology/tp:network-nodes/tp:network-node/tp:node-id";
+        }
+        description "This type is used for leafs that reference network node instance.";
+    }
+
+    typedef link-id-ref {
+        type leafref {
+            path "/tp:topology/tp:network-links/tp:network-link/tp:link-id";
+        }
+        description "This type is used for leafs that reference network link instance.";
+    }
+
+    container 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.";
+
+        leaf topology-id {
+            type inet:uri;
+            description "It is presumed that datastore will contain many topologies. 
+            To distinguish between topologies it is vital to have
+            UNIQUE topology identifier.";
+        }
+
+        container network-nodes {
+            list network-node {
+                key "node-id";
+
+                leaf node-id {
+                    type inet:uri;
+                    description "The Topology identifier of network-node.";
+                }
+
+                container attributes {
+                    description "Aditional attributes that can Network Node contains.";
+                }
+                description "The list of network nodes defined for topology.";
+            }
+        }
+        
+        container network-links {
+            list network-link {
+                key "link-id";
+
+                leaf link-id {
+                    type inet:uri;
+                    description "";
+                }
+
+                container source-node {
+                    leaf id {
+                        type node-id-ref;
+                        description "Source node identifier.";
+                    }
+                }
+
+                container destination-node {
+                    leaf id {
+                        type node-id-ref;
+                        description "Destination node identifier.";
+                    }
+                }
+
+                container attributes {
+                    description "Aditional attributes that can Network Link contains.";
+                }
+                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.";
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/augment-abstract-topology@2013-05-03.yang b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/augment-abstract-topology@2013-05-03.yang
new file mode 100644 (file)
index 0000000..051b2d9
--- /dev/null
@@ -0,0 +1,69 @@
+module augment-abstract-topology {
+    yang-version 1;
+    namespace "urn:model:augment:abstract:topology";
+    prefix "atp";
+
+    import ietf-inet-types { 
+        prefix "inet";
+        revision-date 2010-09-24;
+    }
+
+    import ietf-interfaces {
+        prefix "if";
+        revision-date 2012-11-15;
+    }
+
+    import abstract-topology {
+        prefix "at";
+        revision-date 2013-02-08;
+    }
+
+    organization "OPEN DAYLIGHT";
+    contact "http://www.opendaylight.org/";
+
+    revision "2013-05-03" {
+        reference "http://www.opendaylight.org/";
+    }
+
+    augment "at:topology" {
+        container interfaces {
+            list interface {
+                key "interface-id";
+
+                leaf interface-id {
+                    type leafref {
+                        path "/if:interfaces/if:interface/if:name";
+                    }
+                }
+
+                leaf-list higher-layer-if {
+                    type leafref {
+                        path "/if:interfaces/if:interface/if:higher-layer-if";
+                    }
+                }
+            }
+        }
+    }
+
+    augment "at:topology/at:network-links/at:network-link" {
+        container tunnels {
+            list tunnel {
+                key "tunnel-id";
+
+                leaf tunnel-id {
+                    type leafref {
+                        path "../../../link-id";
+                    }
+                }
+            }
+        }
+    }
+
+    augment "at:topology/at:network-links/at:network-link" {
+        leaf interface {
+            type leafref {
+                path "../../../atp:interfaces/atp:interface/atp:interface-id";
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/iana-if-type@2012-06-05.yang b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/iana-if-type@2012-06-05.yang
new file mode 100644 (file)
index 0000000..a7fa137
--- /dev/null
@@ -0,0 +1,1516 @@
+module iana-if-type {
+  namespace "urn:ietf:params:xml:ns:yang:iana-if-type";
+  prefix ianaift;
+
+  organization "IANA";
+  contact
+    "        Internet Assigned Numbers Authority
+
+     Postal: ICANN
+             4676 Admiralty Way, Suite 330
+             Marina del Rey, CA 90292
+
+     Tel:    +1 310 823 9358
+     E-Mail: iana&iana.org";
+  description
+    "This YANG module defines the iana-if-type typedef, which
+     contains YANG definitions for IANA-registered interface types.
+
+     This YANG module is maintained by IANA, and reflects the
+     'ifType definitions' registry.
+
+     The latest revision of this YANG module can be obtained from
+     the IANA web site.
+
+     Copyright (c) 2011 IETF Trust and the persons identified as
+     authors of the code.  All rights reserved.
+
+     Redistribution and use in source and binary forms, with or
+     without modification, is permitted pursuant to, and subject
+     to the license terms contained in, the Simplified BSD License
+     set forth in Section 4.c of the IETF Trust's Legal Provisions
+     Relating to IETF Documents
+     (http://trustee.ietf.org/license-info).
+
+     This version of this YANG module is part of RFC XXXX; see
+     the RFC itself for full legal notices.";
+  // RFC Ed.: replace XXXX with actual RFC number and remove this
+  // note.
+
+  // RFC Ed.: update the date below with the date of RFC publication
+  // and remove this note.
+  revision 2012-06-05 {
+    description
+      "Initial revision.";
+    reference
+      "RFC XXXX: TITLE";
+  }
+
+  typedef iana-if-type {
+    type enumeration {
+      enum "other" {
+        value 1;
+        description
+          "None of the following";
+      }
+      enum "regular1822" {
+        value 2;
+      }
+      enum "hdh1822" {
+        value 3;
+      }
+      enum "ddnX25" {
+        value 4;
+      }
+      enum "rfc877x25" {
+        value 5;
+        reference
+          "RFC 1382 - SNMP MIB Extension for the X.25 Packet Layer";
+      }
+      enum "ethernetCsmacd" {
+        value 6;
+        description
+          "For all ethernet-like interfaces, regardless of speed,
+           as per RFC3635.";
+        reference
+          "RFC 3635 - Definitions of Managed Objects for the
+                      Ethernet-like Interface Types.";
+      }
+      enum "iso88023Csmacd" {
+        value 7;
+        status deprecated;
+        description
+          "Deprecated via RFC3635.
+           Use ethernetCsmacd(6) instead.";
+        reference
+          "RFC 3635 - Definitions of Managed Objects for the
+                      Ethernet-like Interface Types.";
+      }
+      enum "iso88024TokenBus" {
+        value 8;
+      }
+      enum "iso88025TokenRing" {
+        value 9;
+      }
+      enum "iso88026Man" {
+        value 10;
+      }
+      enum "starLan" {
+        value 11;
+        status deprecated;
+        description
+          "Deprecated via RFC3635.
+           Use ethernetCsmacd(6) instead.";
+        reference
+          "RFC 3635 - Definitions of Managed Objects for the
+                      Ethernet-like Interface Types.";
+      }
+      enum "proteon10Mbit" {
+        value 12;
+      }
+      enum "proteon80Mbit" {
+        value 13;
+      }
+      enum "hyperchannel" {
+        value 14;
+      }
+      enum "fddi" {
+        value 15;
+        reference
+          "RFC 1512 - FDDI Management Information Base";
+      }
+      enum "lapb" {
+        value 16;
+        reference
+          "RFC 1381 - SNMP MIB Extension for X.25 LAPB";
+      }
+      enum "sdlc" {
+        value 17;
+      }
+      enum "ds1" {
+        value 18;
+        description
+          "DS1-MIB";
+        reference
+          "RFC 4805 - Definitions of Managed Objects for the
+                      DS1, J1, E1, DS2, and E2 Interface Types";
+      }
+      enum "e1" {
+        value 19;
+        status obsolete;
+        description
+          "Obsolete see DS1-MIB";
+        reference
+          "RFC 4805 - Definitions of Managed Objects for the
+                      DS1, J1, E1, DS2, and E2 Interface Types";
+      }
+      enum "basicISDN" {
+        value 20;
+        description
+          "see also RFC2127";
+      }
+      enum "primaryISDN" {
+        value 21;
+      }
+      enum "propPointToPointSerial" {
+        value 22;
+        description
+          "proprietary serial";
+      }
+      enum "ppp" {
+        value 23;
+      }
+      enum "softwareLoopback" {
+        value 24;
+      }
+      enum "eon" {
+        value 25;
+        description
+          "CLNP over IP";
+      }
+      enum "ethernet3Mbit" {
+        value 26;
+      }
+      enum "nsip" {
+        value 27;
+        description
+          "XNS over IP";
+      }
+      enum "slip" {
+        value 28;
+        description
+          "generic SLIP";
+      }
+      enum "ultra" {
+        value 29;
+        description
+          "ULTRA technologies";
+      }
+      enum "ds3" {
+        value 30;
+        description
+          "DS3-MIB";
+        reference
+          "RFC 3896 - Definitions of Managed Objects for the
+                      DS3/E3 Interface Type";
+      }
+      enum "sip" {
+        value 31;
+        description
+          "SMDS, coffee";
+        reference
+          "RFC 1694 - Definitions of Managed Objects for SMDS
+                      Interfaces using SMIv2";
+      }
+      enum "frameRelay" {
+        value 32;
+        description
+          "DTE only.";
+        reference
+          "RFC 2115 - Management Information Base for Frame Relay
+                      DTEs Using SMIv2";
+      }
+      enum "rs232" {
+        value 33;
+        reference
+          "RFC 1659 - Definitions of Managed Objects for RS-232-like
+                      Hardware Devices using SMIv2";
+      }
+      enum "para" {
+        value 34;
+        description
+          "parallel-port";
+        reference
+          "RFC 1660 - Definitions of Managed Objects for
+                      Parallel-printer-like Hardware Devices using
+                      SMIv2";
+      }
+      enum "arcnet" {
+        value 35;
+        description
+          "arcnet";
+      }
+      enum "arcnetPlus" {
+        value 36;
+        description
+          "arcnet plus";
+      }
+      enum "atm" {
+        value 37;
+        description
+          "ATM cells";
+      }
+      enum "miox25" {
+        value 38;
+        reference
+          "RFC 1461 - SNMP MIB extension for Multiprotocol
+                      Interconnect over X.25";
+      }
+      enum "sonet" {
+        value 39;
+        description
+          "SONET or SDH";
+      }
+      enum "x25ple" {
+        value 40;
+        reference
+          "RFC 2127 - ISDN Management Information Base using SMIv2";
+      }
+      enum "iso88022llc" {
+        value 41;
+      }
+      enum "localTalk" {
+        value 42;
+      }
+      enum "smdsDxi" {
+        value 43;
+      }
+      enum "frameRelayService" {
+        value 44;
+        description
+          "FRNETSERV-MIB";
+        reference
+          "RFC 2954 - Definitions of Managed Objects for Frame
+                      Relay Service";
+      }
+      enum "v35" {
+        value 45;
+      }
+      enum "hssi" {
+        value 46;
+      }
+      enum "hippi" {
+        value 47;
+      }
+      enum "modem" {
+        value 48;
+        description
+          "Generic modem";
+      }
+      enum "aal5" {
+        value 49;
+        description
+          "AAL5 over ATM";
+      }
+      enum "sonetPath" {
+        value 50;
+      }
+      enum "sonetVT" {
+        value 51;
+      }
+      enum "smdsIcip" {
+        value 52;
+        description
+          "SMDS InterCarrier Interface";
+      }
+      enum "propVirtual" {
+        value 53;
+        description
+          "proprietary virtual/internal";
+        reference
+          "RFC 2863 - The Interfaces Group MIB";
+      }
+      enum "propMultiplexor" {
+        value 54;
+        description
+          "proprietary multiplexing";
+        reference
+          "RFC 2863 - The Interfaces Group MIB";
+      }
+      enum "ieee80212" {
+        value 55;
+        description
+          "100BaseVG";
+      }
+      enum "fibreChannel" {
+        value 56;
+        description
+          "Fibre Channel";
+      }
+      enum "hippiInterface" {
+        value 57;
+        description
+          "HIPPI interfaces";
+      }
+      enum "frameRelayInterconnect" {
+        value 58;
+        status obsolete;
+        description
+          "Obsolete use either
+           frameRelay(32) or frameRelayService(44).";
+      }
+      enum "aflane8023" {
+        value 59;
+        description
+          "ATM Emulated LAN for 802.3";
+      }
+      enum "aflane8025" {
+        value 60;
+        description
+          "ATM Emulated LAN for 802.5";
+      }
+      enum "cctEmul" {
+        value 61;
+        description
+         "ATM Emulated circuit";
+      }
+      enum "fastEther" {
+        value 62;
+        status deprecated;
+        description
+          "Obsoleted via RFC3635.
+          ethernetCsmacd(6) should be used instead";
+        reference
+          "RFC 3635 - Definitions of Managed Objects for the
+                      Ethernet-like Interface Types.";
+      }
+      enum "isdn" {
+        value 63;
+        description
+          "ISDN and X.25";
+        reference
+          "RFC 1356 - Multiprotocol Interconnect on X.25 and ISDN
+                      in the Packet Mode";
+      }
+      enum "v11" {
+        value 64;
+        description
+         "CCITT V.11/X.21";
+      }
+      enum "v36" {
+        value 65;
+        description
+          "CCITT V.36";
+      }
+      enum "g703at64k" {
+        value 66;
+        description
+          "CCITT G703 at 64Kbps";
+      }
+      enum "g703at2mb" {
+        value 67;
+        status obsolete;
+        description
+          "Obsolete see DS1-MIB";
+      }
+      enum "qllc" {
+        value 68;
+        description
+          "SNA QLLC";
+      }
+      enum "fastEtherFX" {
+        value 69;
+        status deprecated;
+        description
+          "Obsoleted via RFC3635
+          ethernetCsmacd(6) should be used instead";
+        reference
+          "RFC 3635 - Definitions of Managed Objects for the
+                      Ethernet-like Interface Types.";
+      }
+      enum "channel" {
+        value 70;
+        description
+          "channel";
+      }
+      enum "ieee80211" {
+        value 71;
+        description
+          "radio spread spectrum";
+      }
+      enum "ibm370parChan" {
+        value 72;
+        description
+          "IBM System 360/370 OEMI Channel";
+      }
+      enum "escon" {
+        value 73;
+        description
+          "IBM Enterprise Systems Connection";
+      }
+      enum "dlsw" {
+        value 74;
+        description
+          "Data Link Switching";
+      }
+      enum "isdns" {
+        value 75;
+        description
+          "ISDN S/T interface";
+      }
+      enum "isdnu" {
+        value 76;
+        description
+          "ISDN U interface";
+      }
+      enum "lapd" {
+        value 77;
+        description
+          "Link Access Protocol D";
+      }
+      enum "ipSwitch" {
+        value 78;
+        description
+          "IP Switching Objects";
+      }
+      enum "rsrb" {
+        value 79;
+        description
+          "Remote Source Route Bridging";
+      }
+      enum "atmLogical" {
+        value 80;
+        description
+          "ATM Logical Port";
+        reference
+          "RFC 3606 - Definitions of Supplemental Managed Objects
+                      for ATM Interface";
+      }
+      enum "ds0" {
+        value 81;
+        description
+          "Digital Signal Level 0";
+        reference
+          "RFC 2494 - Definitions of Managed Objects for the DS0
+                      and DS0 Bundle Interface Type";
+      }
+      enum "ds0Bundle" {
+        value 82;
+        description
+          "group of ds0s on the same ds1";
+        reference
+          "RFC 2494 - Definitions of Managed Objects for the DS0
+                      and DS0 Bundle Interface Type";
+      }
+      enum "bsc" {
+        value 83;
+        description
+          "Bisynchronous Protocol";
+      }
+      enum "async" {
+        value 84;
+        description
+          "Asynchronous Protocol";
+      }
+      enum "cnr" {
+        value 85;
+        description
+          "Combat Net Radio";
+      }
+      enum "iso88025Dtr" {
+        value 86;
+        description
+          "ISO 802.5r DTR";
+      }
+      enum "eplrs" {
+        value 87;
+        description
+          "Ext Pos Loc Report Sys";
+      }
+      enum "arap" {
+        value 88;
+        description
+          "Appletalk Remote Access Protocol";
+      }
+      enum "propCnls" {
+        value 89;
+        description
+          "Proprietary Connectionless Protocol";
+      }
+      enum "hostPad" {
+        value 90;
+        description
+          "CCITT-ITU X.29 PAD Protocol";
+      }
+      enum "termPad" {
+        value 91;
+        description
+          "CCITT-ITU X.3 PAD Facility";
+      }
+      enum "frameRelayMPI" {
+        value 92;
+        description
+          "Multiproto Interconnect over FR";
+      }
+      enum "x213" {
+        value 93;
+        description
+          "CCITT-ITU X213";
+      }
+      enum "adsl" {
+        value 94;
+        description
+          "Asymmetric Digital Subscriber Loop";
+      }
+      enum "radsl" {
+        value 95;
+        description
+          "Rate-Adapt. Digital Subscriber Loop";
+      }
+      enum "sdsl" {
+        value 96;
+        description
+          "Symmetric Digital Subscriber Loop";
+      }
+      enum "vdsl" {
+        value 97;
+        description
+          "Very H-Speed Digital Subscrib. Loop";
+      }
+      enum "iso88025CRFPInt" {
+        value 98;
+        description
+          "ISO 802.5 CRFP";
+      }
+      enum "myrinet" {
+        value 99;
+        description
+          "Myricom Myrinet";
+      }
+      enum "voiceEM" {
+        value 100;
+        description
+          "voice recEive and transMit";
+      }
+      enum "voiceFXO" {
+        value 101;
+        description
+          "voice Foreign Exchange Office";
+      }
+      enum "voiceFXS" {
+        value 102;
+        description
+          "voice Foreign Exchange Station";
+      }
+      enum "voiceEncap" {
+        value 103;
+        description
+          "voice encapsulation";
+      }
+      enum "voiceOverIp" {
+        value 104;
+        description
+          "voice over IP encapsulation";
+      }
+      enum "atmDxi" {
+        value 105;
+        description
+          "ATM DXI";
+      }
+      enum "atmFuni" {
+        value 106;
+        description
+          "ATM FUNI";
+      }
+      enum "atmIma" {
+        value 107;
+        description
+          "ATM IMA";
+      }
+      enum "pppMultilinkBundle" {
+        value 108;
+        description
+          "PPP Multilink Bundle";
+      }
+      enum "ipOverCdlc" {
+        value 109;
+        description
+          "IBM ipOverCdlc";
+      }
+      enum "ipOverClaw" {
+        value 110;
+        description
+          "IBM Common Link Access to Workstn";
+      }
+      enum "stackToStack" {
+        value 111;
+        description
+          "IBM stackToStack";
+      }
+      enum "virtualIpAddress" {
+        value 112;
+        description
+          "IBM VIPA";
+      }
+      enum "mpc" {
+        value 113;
+        description
+          "IBM multi-protocol channel support";
+      }
+      enum "ipOverAtm" {
+        value 114;
+        description
+          "IBM ipOverAtm";
+        reference
+          "RFC 2320 - Definitions of Managed Objects for Classical IP
+                      and ARP Over ATM Using SMIv2 (IPOA-MIB)";
+      }
+      enum "iso88025Fiber" {
+        value 115;
+        description
+          "ISO 802.5j Fiber Token Ring";
+      }
+      enum "tdlc" {
+        value 116;
+        description
+          "IBM twinaxial data link control";
+      }
+      enum "gigabitEthernet" {
+        value 117;
+        status deprecated;
+        description
+          "Obsoleted via RFC3635
+           ethernetCsmacd(6) should be used instead";
+        reference
+          "RFC 3635 - Definitions of Managed Objects for the
+                      Ethernet-like Interface Types.";
+      }
+      enum "hdlc" {
+        value 118;
+        description
+          "HDLC";
+      }
+      enum "lapf" {
+        value 119;
+        description
+          "LAP F";
+      }
+      enum "v37" {
+        value 120;
+        description
+          "V.37";
+      }
+      enum "x25mlp" {
+        value 121;
+        description
+          "Multi-Link Protocol";
+      }
+      enum "x25huntGroup" {
+        value 122;
+        description
+          "X25 Hunt Group";
+      }
+      enum "transpHdlc" {
+        value 123;
+        description
+          "Transp HDLC";
+      }
+      enum "interleave" {
+        value 124;
+        description
+          "Interleave channel";
+      }
+      enum "fast" {
+        value 125;
+        description
+          "Fast channel";
+      }
+      enum "ip" {
+        value 126;
+        description
+          "IP (for APPN HPR in IP networks)";
+      }
+      enum "docsCableMaclayer" {
+        value 127;
+        description
+          "CATV Mac Layer";
+      }
+      enum "docsCableDownstream" {
+        value 128;
+        description
+          "CATV Downstream interface";
+      }
+      enum "docsCableUpstream" {
+        value 129;
+        description
+          "CATV Upstream interface";
+      }
+      enum "a12MppSwitch" {
+        value 130;
+        description
+          "Avalon Parallel Processor";
+      }
+      enum "tunnel" {
+        value 131;
+        description
+          "Encapsulation interface";
+      }
+      enum "coffee" {
+        value 132;
+        description
+          "coffee pot";
+        reference
+          "RFC 2325 - Coffee MIB";
+      }
+      enum "ces" {
+        value 133;
+        description
+          "Circuit Emulation Service";
+      }
+      enum "atmSubInterface" {
+        value 134;
+        description
+          "ATM Sub Interface";
+      }
+      enum "l2vlan" {
+        value 135;
+        description
+          "Layer 2 Virtual LAN using 802.1Q";
+      }
+      enum "l3ipvlan" {
+        value 136;
+        description
+          "Layer 3 Virtual LAN using IP";
+      }
+      enum "l3ipxvlan" {
+        value 137;
+        description
+          "Layer 3 Virtual LAN using IPX";
+      }
+      enum "digitalPowerline" {
+        value 138;
+        description
+          "IP over Power Lines";
+      }
+      enum "mediaMailOverIp" {
+        value 139;
+        description
+          "Multimedia Mail over IP";
+      }
+      enum "dtm" {
+        value 140;
+        description
+          "Dynamic syncronous Transfer Mode";
+      }
+      enum "dcn" {
+        value 141;
+        description
+          "Data Communications Network";
+      }
+      enum "ipForward" {
+        value 142;
+        description
+          "IP Forwarding Interface";
+      }
+      enum "msdsl" {
+        value 143;
+        description
+          "Multi-rate Symmetric DSL";
+      }
+      enum "ieee1394" {
+        value 144;
+        description
+          "IEEE1394 High Performance Serial Bus";
+      }
+      enum "if-gsn" {
+        value 145;
+        description
+          "HIPPI-6400";
+      }
+      enum "dvbRccMacLayer" {
+        value 146;
+        description
+          "DVB-RCC MAC Layer";
+      }
+      enum "dvbRccDownstream" {
+        value 147;
+        description
+          "DVB-RCC Downstream Channel";
+      }
+      enum "dvbRccUpstream" {
+        value 148;
+        description
+          "DVB-RCC Upstream Channel";
+      }
+      enum "atmVirtual" {
+        value 149;
+        description
+          "ATM Virtual Interface";
+      }
+      enum "mplsTunnel" {
+        value 150;
+        description
+          "MPLS Tunnel Virtual Interface";
+      }
+      enum "srp" {
+        value 151;
+        description
+          "Spatial Reuse Protocol       ";
+      }
+      enum "voiceOverAtm" {
+        value 152;
+        description
+          "Voice Over ATM";
+      }
+      enum "voiceOverFrameRelay" {
+        value 153;
+        description
+          "Voice Over Frame Relay";
+      }
+      enum "idsl" {
+        value 154;
+        description
+          "Digital Subscriber Loop over ISDN";
+      }
+      enum "compositeLink" {
+        value 155;
+        description
+          "Avici Composite Link Interface";
+      }
+      enum "ss7SigLink" {
+        value 156;
+        description
+          "SS7 Signaling Link";
+      }
+      enum "propWirelessP2P" {
+        value 157;
+        description
+          "Prop. P2P wireless interface";
+      }
+      enum "frForward" {
+        value 158;
+        description
+          "Frame Forward Interface";
+      }
+      enum "rfc1483" {
+        value 159;
+        description
+          "Multiprotocol over ATM AAL5";
+        reference
+          "RFC 1483 - Multiprotocol Encapsulation over ATM
+                      Adaptation Layer 5";
+      }
+      enum "usb" {
+        value 160;
+        description
+          "USB Interface";
+      }
+      enum "ieee8023adLag" {
+        value 161;
+        description
+          "IEEE 802.3ad Link Aggregate";
+      }
+      enum "bgppolicyaccounting" {
+        value 162;
+        description
+          "BGP Policy Accounting";
+      }
+      enum "frf16MfrBundle" {
+        value 163;
+        description
+          "FRF .16 Multilink Frame Relay";
+      }
+      enum "h323Gatekeeper" {
+        value 164;
+        description
+          "H323 Gatekeeper";
+      }
+      enum "h323Proxy" {
+        value 165;
+        description
+          "H323 Voice and Video Proxy";
+      }
+      enum "mpls" {
+        value 166;
+        description
+          "MPLS";
+      }
+      enum "mfSigLink" {
+        value 167;
+        description
+          "Multi-frequency signaling link";
+      }
+      enum "hdsl2" {
+        value 168;
+        description
+          "High Bit-Rate DSL - 2nd generation";
+      }
+      enum "shdsl" {
+        value 169;
+        description
+          "Multirate HDSL2";
+      }
+      enum "ds1FDL" {
+        value 170;
+        description
+          "Facility Data Link 4Kbps on a DS1";
+      }
+      enum "pos" {
+        value 171;
+        description
+          "Packet over SONET/SDH Interface";
+      }
+      enum "dvbAsiIn" {
+        value 172;
+        description
+          "DVB-ASI Input";
+      }
+      enum "dvbAsiOut" {
+        value 173;
+        description
+          "DVB-ASI Output";
+      }
+      enum "plc" {
+        value 174;
+        description
+          "Power Line Communtications";
+      }
+      enum "nfas" {
+        value 175;
+        description
+          "Non Facility Associated Signaling";
+      }
+      enum "tr008" {
+        value 176;
+        description
+          "TR008";
+      }
+      enum "gr303RDT" {
+        value 177;
+        description
+          "Remote Digital Terminal";
+      }
+      enum "gr303IDT" {
+        value 178;
+        description
+          "Integrated Digital Terminal";
+      }
+      enum "isup" {
+        value 179;
+        description
+          "ISUP";
+      }
+      enum "propDocsWirelessMaclayer" {
+        value 180;
+        description
+          "Cisco proprietary Maclayer";
+      }
+      enum "propDocsWirelessDownstream" {
+        value 181;
+        description
+          "Cisco proprietary Downstream";
+      }
+      enum "propDocsWirelessUpstream" {
+        value 182;
+        description
+          "Cisco proprietary Upstream";
+      }
+      enum "hiperlan2" {
+        value 183;
+        description
+          "HIPERLAN Type 2 Radio Interface";
+      }
+      enum "propBWAp2Mp" {
+        value 184;
+        description
+          "PropBroadbandWirelessAccesspt2multipt use of this value
+           for IEEE 802.16 WMAN interfaces as per IEEE Std 802.16f
+           is deprecated and ieee80216WMAN(237) should be used
+           instead.";
+      }
+      enum "sonetOverheadChannel" {
+        value 185;
+        description
+          "SONET Overhead Channel";
+      }
+      enum "digitalWrapperOverheadChannel" {
+        value 186;
+        description
+          "Digital Wrapper";
+      }
+      enum "aal2" {
+        value 187;
+        description
+          "ATM adaptation layer 2";
+      }
+      enum "radioMAC" {
+        value 188;
+        description
+          "MAC layer over radio links";
+      }
+      enum "atmRadio" {
+        value 189;
+        description
+          "ATM over radio links";
+      }
+      enum "imt" {
+        value 190;
+        description
+          "Inter Machine Trunks";
+      }
+      enum "mvl" {
+        value 191;
+        description
+          "Multiple Virtual Lines DSL";
+      }
+      enum "reachDSL" {
+        value 192;
+        description
+          "Long Reach DSL";
+      }
+      enum "frDlciEndPt" {
+        value 193;
+        description
+          "Frame Relay DLCI End Point";
+      }
+      enum "atmVciEndPt" {
+        value 194;
+        description
+          "ATM VCI End Point";
+      }
+      enum "opticalChannel" {
+        value 195;
+        description
+          "Optical Channel";
+      }
+      enum "opticalTransport" {
+        value 196;
+        description
+          "Optical Transport";
+      }
+      enum "propAtm" {
+        value 197;
+        description
+          "Proprietary ATM";
+      }
+      enum "voiceOverCable" {
+        value 198;
+        description
+          "Voice Over Cable Interface";
+      }
+      enum "infiniband" {
+        value 199;
+        description
+          "Infiniband";
+      }
+      enum "teLink" {
+        value 200;
+        description
+          "TE Link";
+      }
+      enum "q2931" {
+        value 201;
+        description
+          "Q.2931";
+      }
+      enum "virtualTg" {
+        value 202;
+        description
+          "Virtual Trunk Group";
+      }
+      enum "sipTg" {
+        value 203;
+        description
+          "SIP Trunk Group";
+      }
+      enum "sipSig" {
+        value 204;
+        description
+          "SIP Signaling";
+      }
+      enum "docsCableUpstreamChannel" {
+        value 205;
+        description
+          "CATV Upstream Channel";
+      }
+      enum "econet" {
+        value 206;
+        description
+          "Acorn Econet";
+      }
+      enum "pon155" {
+        value 207;
+        description
+          "FSAN 155Mb Symetrical PON interface";
+      }
+      enum "pon622" {
+        value 208;
+        description
+          "FSAN622Mb Symetrical PON interface";
+      }
+      enum "bridge" {
+        value 209;
+        description
+          "Transparent bridge interface";
+      }
+      enum "linegroup" {
+        value 210;
+        description
+          "Interface common to multiple lines";
+      }
+      enum "voiceEMFGD" {
+        value 211;
+        description
+          "voice E&M Feature Group D";
+      }
+      enum "voiceFGDEANA" {
+        value 212;
+        description
+          "voice FGD Exchange Access North American";
+      }
+      enum "voiceDID" {
+        value 213;
+        description
+          "voice Direct Inward Dialing";
+      }
+      enum "mpegTransport" {
+        value 214;
+        description
+          "MPEG transport interface";
+      }
+      enum "sixToFour" {
+        value 215;
+        status deprecated;
+        description
+          "6to4 interface (DEPRECATED)";
+        reference
+          "RFC 4087 - IP Tunnel MIB";
+      }
+      enum "gtp" {
+        value 216;
+        description
+          "GTP (GPRS Tunneling Protocol)";
+      }
+      enum "pdnEtherLoop1" {
+        value 217;
+        description
+          "Paradyne EtherLoop 1";
+      }
+      enum "pdnEtherLoop2" {
+        value 218;
+        description
+          "Paradyne EtherLoop 2";
+      }
+      enum "opticalChannelGroup" {
+        value 219;
+        description
+          "Optical Channel Group";
+      }
+      enum "homepna" {
+        value 220;
+        description
+          "HomePNA ITU-T G.989";
+      }
+      enum "gfp" {
+        value 221;
+        description
+          "Generic Framing Procedure (GFP)";
+      }
+      enum "ciscoISLvlan" {
+        value 222;
+        description
+          "Layer 2 Virtual LAN using Cisco ISL";
+      }
+      enum "actelisMetaLOOP" {
+        value 223;
+        description
+          "Acteleis proprietary MetaLOOP High Speed Link";
+      }
+      enum "fcipLink" {
+        value 224;
+        description
+          "FCIP Link";
+      }
+      enum "rpr" {
+        value 225;
+        description
+          "Resilient Packet Ring Interface Type";
+      }
+      enum "qam" {
+        value 226;
+        description
+          "RF Qam Interface";
+      }
+      enum "lmp" {
+        value 227;
+        description
+          "Link Management Protocol";
+        reference
+          "RFC 4327 - Link Management Protocol (LMP) Management
+                      Information Base (MIB)";
+      }
+      enum "cblVectaStar" {
+        value 228;
+        description
+          "Cambridge Broadband Networks Limited VectaStar";
+      }
+      enum "docsCableMCmtsDownstream" {
+        value 229;
+        description
+          "CATV Modular CMTS Downstream Interface";
+      }
+      enum "adsl2" {
+        value 230;
+        status deprecated;
+        description
+          "Asymmetric Digital Subscriber Loop Version 2
+           (DEPRECATED/OBSOLETED - please use adsl2plus(238)
+           instead)";
+        reference
+          "RFC 4706 - Definitions of Managed Objects for Asymmetric
+                      Digital Subscriber Line 2 (ADSL2)";
+      }
+      enum "macSecControlledIF" {
+        value 231;
+        description
+          "MACSecControlled";
+      }
+      enum "macSecUncontrolledIF" {
+        value 232;
+        description
+          "MACSecUncontrolled";
+      }
+      enum "aviciOpticalEther" {
+        value 233;
+        description
+         "Avici Optical Ethernet Aggregate";
+      }
+      enum "atmbond" {
+        value 234;
+        description
+          "atmbond";
+      }
+      enum "voiceFGDOS" {
+        value 235;
+        description
+          "voice FGD Operator Services";
+      }
+      enum "mocaVersion1" {
+        value 236;
+        description
+          "MultiMedia over Coax Alliance (MoCA) Interface
+           as documented in information provided privately to IANA";
+      }
+      enum "ieee80216WMAN" {
+        value 237;
+        description
+          "IEEE 802.16 WMAN interface";
+      }
+      enum "adsl2plus" {
+        value 238;
+        description
+          "Asymmetric Digital Subscriber Loop Version 2,
+           Version 2 Plus and all variants";
+      }
+      enum "dvbRcsMacLayer" {
+        value 239;
+        description
+          "DVB-RCS MAC Layer";
+        reference
+          "RFC 5728 - The SatLabs Group DVB-RCS MIB";
+      }
+      enum "dvbTdm" {
+        value 240;
+        description
+          "DVB Satellite TDM";
+        reference
+          "RFC 5728 - The SatLabs Group DVB-RCS MIB";
+      }
+      enum "dvbRcsTdma" {
+        value 241;
+        description
+          "DVB-RCS TDMA";
+        reference
+          "RFC 5728 - The SatLabs Group DVB-RCS MIB";
+      }
+      enum "x86Laps" {
+        value 242;
+        description
+          "LAPS based on ITU-T X.86/Y.1323";
+      }
+      enum "wwanPP" {
+        value 243;
+        description
+          "3GPP WWAN";
+      }
+      enum "wwanPP2" {
+        value 244;
+        description
+          "3GPP2 WWAN";
+      }
+      enum "voiceEBS" {
+        value 245;
+        description
+          "voice P-phone EBS physical interface";
+      }
+      enum "ifPwType" {
+        value 246;
+        description
+          "Pseudowire interface type";
+        reference
+          "RFC 5601 - Pseudowire (PW) Management Information Base";
+      }
+      enum "ilan" {
+        value 247;
+        description
+          "Internal LAN on a bridge per IEEE 802.1ap";
+      }
+      enum "pip" {
+        value 248;
+        description
+          "Provider Instance Port on a bridge per IEEE 802.1ah PBB";
+      }
+      enum "aluELP" {
+        value 249;
+        description
+          "Alcatel-Lucent Ethernet Link Protection";
+      }
+      enum "gpon" {
+        value 250;
+        description
+          "Gigabit-capable passive optical networks (G-PON) as per
+           ITU-T G.948";
+      }
+      enum "vdsl2" {
+        value 251;
+        description
+          "Very high speed digital subscriber line Version 2
+           (as per ITU-T Recommendation G.993.2)";
+        reference
+          "RFC 5650 - Definitions of Managed Objects for Very High
+                      Speed Digital Subscriber Line 2 (VDSL2)";
+      }
+      enum "capwapDot11Profile" {
+        value 252;
+        description
+          "WLAN Profile Interface";
+        reference
+          "RFC 5834 - Control and Provisioning of Wireless Access
+                      Points (CAPWAP) Protocol Binding MIB for
+                      IEEE 802.11";
+      }
+      enum "capwapDot11Bss" {
+        value 253;
+        description
+          "WLAN BSS Interface";
+        reference
+          "RFC 5834 - Control and Provisioning of Wireless Access
+                      Points (CAPWAP) Protocol Binding MIB for
+                      IEEE 802.11";
+      }
+      enum "capwapWtpVirtualRadio" {
+        value 254;
+        description
+          "WTP Virtual Radio Interface";
+        reference
+          "RFC 5833 - Control and Provisioning of Wireless Access
+                      Points (CAPWAP) Protocol Base MIB";
+      }
+      enum "bits" {
+        value 255;
+        description
+          "bitsport";
+      }
+      enum "docsCableUpstreamRfPort" {
+        value 256;
+        description
+          "DOCSIS CATV Upstream RF Port";
+      }
+      enum "cableDownstreamRfPort" {
+        value 257;
+        description
+          "CATV downstream RF port";
+      }
+      enum "vmwareVirtualNic" {
+        value 258;
+        description
+          "VMware Virtual Network Interface";
+      }
+      enum "ieee802154" {
+        value 259;
+        description
+          "IEEE 802.15.4 WPAN interface";
+        reference
+          "IEEE 802.15.4-2006";
+      }
+      enum "otnOdu" {
+        value 260;
+        description
+          "OTN Optical Data Unit";
+      }
+      enum "otnOtu" {
+        value 261;
+        description
+          "OTN Optical channel Transport Unit";
+      }
+      enum "ifVfiType" {
+        value 262;
+        description
+          "VPLS Forwarding Instance Interface Type";
+      }
+      enum "g9981" {
+        value 263;
+        description
+          "G.998.1 bonded interface";
+      }
+      enum "g9982" {
+        value 264;
+        description
+          "G.998.2 bonded interface";
+      }
+      enum "g9983" {
+        value 265;
+        description
+          "G.998.3 bonded interface";
+      }
+      enum "aluEpon" {
+        value 266;
+        description
+          "Ethernet Passive Optical Networks (E-PON)";
+      }
+      enum "aluEponOnu" {
+        value 267;
+        description
+          "EPON Optical Network Unit";
+      }
+      enum "aluEponPhysicalUni" {
+        value 268;
+        description
+          "EPON physical User to Network interface";
+      }
+      enum "aluEponLogicalLink" {
+        value 269;
+        description
+          "The emulation of a point-to-point link over the EPON
+           layer";
+      }
+      enum "aluGponOnu" {
+        value 270;
+        description
+          "GPON Optical Network Unit";
+        reference
+          "ITU-T G.984.2";
+      }
+      enum "aluGponPhysicalUni" {
+        value 271;
+        description
+          "GPON physical User to Network interface";
+        reference
+          "ITU-T G.984.2";
+      }
+      enum "vmwareNicTeam" {
+        value 272;
+        description
+          "VMware NIC Team";
+      }
+    }
+    description
+      "This data type is used as the syntax of the 'type'
+       leaf in the 'interface' list in the YANG module
+       ietf-interface.
+
+       The definition of this typedef with the
+       addition of newly assigned values is published
+       periodically by the IANA, in either the Assigned
+       Numbers RFC, or some derivative of it specific to
+       Internet Network Management number assignments.  (The
+       latest arrangements can be obtained by contacting the
+       IANA.)
+
+       Requests for new values should be made to IANA via
+       email (iana&iana.org).";
+    reference
+      "ifType definitions registry.
+       <http://www.iana.org/assignments/smi-numbers>";
+  }
+}
\ No newline at end of file
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/ietf-inet-types@2010-09-24.yang b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/ietf-inet-types@2010-09-24.yang
new file mode 100644 (file)
index 0000000..de20feb
--- /dev/null
@@ -0,0 +1,418 @@
+ module ietf-inet-types {
+
+   namespace "urn:ietf:params:xml:ns:yang:ietf-inet-types";
+   prefix "inet";
+
+   organization
+    "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+
+   contact
+    "WG Web:   <http://tools.ietf.org/wg/netmod/>
+     WG List:  <mailto:netmod@ietf.org>
+
+     WG Chair: David Partain
+               <mailto:david.partain@ericsson.com>
+
+     WG Chair: David Kessens
+               <mailto:david.kessens@nsn.com>
+
+     Editor:   Juergen Schoenwaelder
+               <mailto:j.schoenwaelder@jacobs-university.de>";
+
+   description
+    "This module contains a collection of generally useful derived
+     YANG data types for Internet addresses and related things.
+
+     Copyright (c) 2010 IETF Trust and the persons identified as
+     authors of the code.  All rights reserved.
+
+     Redistribution and use in source and binary forms, with or without
+     modification, is permitted pursuant to, and subject to the license
+     terms contained in, the Simplified BSD License set forth in Section
+     4.c of the IETF Trust's Legal Provisions Relating to IETF Documents
+     (http://trustee.ietf.org/license-info).
+
+     This version of this YANG module is part of RFC 6021; see
+     the RFC itself for full legal notices.";
+
+   revision 2010-09-24 {
+     description
+      "Initial revision.";
+     reference
+      "RFC 6021: Common YANG Data Types";
+   }
+
+   /*** collection of protocol field related types ***/
+
+   typedef ip-version {
+     type enumeration {
+       enum unknown {
+         value "0";
+         description
+          "An unknown or unspecified version of the Internet protocol.";
+       }
+       enum ipv4 {
+         value "1";
+         description
+          "The IPv4 protocol as defined in RFC 791.";
+       }
+       enum ipv6 {
+         value "2";
+         description
+          "The IPv6 protocol as defined in RFC 2460.";
+       }
+     }
+     description
+      "This value represents the version of the IP protocol.
+
+       In the value set and its semantics, this type is equivalent
+       to the InetVersion textual convention of the SMIv2.";
+     reference
+      "RFC  791: Internet Protocol
+       RFC 2460: Internet Protocol, Version 6 (IPv6) Specification
+       RFC 4001: Textual Conventions for Internet Network Addresses";
+   }
+
+   typedef dscp {
+     type uint8 {
+       range "0..63";
+     }
+     description
+      "The dscp type represents a Differentiated Services Code-Point
+       that may be used for marking packets in a traffic stream.
+
+       In the value set and its semantics, this type is equivalent
+       to the Dscp textual convention of the SMIv2.";
+     reference
+      "RFC 3289: Management Information Base for the Differentiated
+                 Services Architecture
+       RFC 2474: Definition of the Differentiated Services Field
+                 (DS Field) in the IPv4 and IPv6 Headers
+       RFC 2780: IANA Allocation Guidelines For Values In
+                 the Internet Protocol and Related Headers";
+   }
+
+   typedef ipv6-flow-label {
+     type uint32 {
+       range "0..1048575";
+     }
+     description
+      "The flow-label type represents flow identifier or Flow Label
+       in an IPv6 packet header that may be used to discriminate
+       traffic flows.
+
+       In the value set and its semantics, this type is equivalent
+       to the IPv6FlowLabel textual convention of the SMIv2.";
+     reference
+      "RFC 3595: Textual Conventions for IPv6 Flow Label
+       RFC 2460: Internet Protocol, Version 6 (IPv6) Specification";
+   }
+
+   typedef port-number {
+     type uint16 {
+       range "0..65535";
+     }
+     description
+      "The port-number type represents a 16-bit port number of an
+       Internet transport layer protocol such as UDP, TCP, DCCP, or
+       SCTP.  Port numbers are assigned by IANA.  A current list of
+       all assignments is available from <http://www.iana.org/>.
+
+       Note that the port number value zero is reserved by IANA.  In
+       situations where the value zero does not make sense, it can
+       be excluded by subtyping the port-number type.
+
+       In the value set and its semantics, this type is equivalent
+       to the InetPortNumber textual convention of the SMIv2.";
+     reference
+      "RFC  768: User Datagram Protocol
+       RFC  793: Transmission Control Protocol
+       RFC 4960: Stream Control Transmission Protocol
+       RFC 4340: Datagram Congestion Control Protocol (DCCP)
+       RFC 4001: Textual Conventions for Internet Network Addresses";
+   }
+
+   /*** collection of autonomous system related types ***/
+
+   typedef as-number {
+     type uint32;
+     description
+      "The as-number type represents autonomous system numbers
+       which identify an Autonomous System (AS).  An AS is a set
+       of routers under a single technical administration, using
+       an interior gateway protocol and common metrics to route
+       packets within the AS, and using an exterior gateway
+       protocol to route packets to other ASs'.  IANA maintains
+       the AS number space and has delegated large parts to the
+       regional registries.
+
+       Autonomous system numbers were originally limited to 16
+       bits.  BGP extensions have enlarged the autonomous system
+       number space to 32 bits.  This type therefore uses an uint32
+       base type without a range restriction in order to support
+       a larger autonomous system number space.
+
+       In the value set and its semantics, this type is equivalent
+       to the InetAutonomousSystemNumber textual convention of
+       the SMIv2.";
+     reference
+      "RFC 1930: Guidelines for creation, selection, and registration
+                 of an Autonomous System (AS)
+       RFC 4271: A Border Gateway Protocol 4 (BGP-4)
+       RFC 4893: BGP Support for Four-octet AS Number Space
+       RFC 4001: Textual Conventions for Internet Network Addresses";
+   }
+
+   /*** collection of IP address and hostname related types ***/
+
+   typedef ip-address {
+     type union {
+       type inet:ipv4-address;
+       type inet:ipv6-address;
+     }
+     description
+      "The ip-address type represents an IP address and is IP
+       version neutral.  The format of the textual representations
+       implies the IP version.";
+   }
+
+   typedef ipv4-address {
+     type string {
+       pattern
+         '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
+       +  '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
+       + '(%[\p{N}\p{L}]+)?';
+     }
+     description
+       "The ipv4-address type represents an IPv4 address in
+        dotted-quad notation.  The IPv4 address may include a zone
+        index, separated by a % sign.
+
+        The zone index is used to disambiguate identical address
+        values.  For link-local addresses, the zone index will
+        typically be the interface index number or the name of an
+        interface.  If the zone index is not present, the default
+        zone of the device will be used.
+
+        The canonical format for the zone index is the numerical
+        format";
+   }
+
+   typedef ipv6-address {
+     type string {
+       pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}'
+             + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|'
+             + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
+             + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
+             + '(%[\p{N}\p{L}]+)?';
+       pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
+             + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
+             + '(%.+)?';
+     }
+     description
+      "The ipv6-address type represents an IPv6 address in full,
+       mixed, shortened, and shortened-mixed notation.  The IPv6
+       address may include a zone index, separated by a % sign.
+
+       The zone index is used to disambiguate identical address
+       values.  For link-local addresses, the zone index will
+       typically be the interface index number or the name of an
+       interface.  If the zone index is not present, the default
+       zone of the device will be used.
+
+       The canonical format of IPv6 addresses uses the compressed
+       format described in RFC 4291, Section 2.2, item 2 with the
+       following additional rules: the :: substitution must be
+       applied to the longest sequence of all-zero 16-bit chunks
+       in an IPv6 address.  If there is a tie, the first sequence
+       of all-zero 16-bit chunks is replaced by ::.  Single
+       all-zero 16-bit chunks are not compressed.  The canonical
+       format uses lowercase characters and leading zeros are
+       not allowed.  The canonical format for the zone index is
+       the numerical format as described in RFC 4007, Section
+       11.2.";
+     reference
+      "RFC 4291: IP Version 6 Addressing Architecture
+       RFC 4007: IPv6 Scoped Address Architecture
+       RFC 5952: A Recommendation for IPv6 Address Text Representation";
+   }
+
+   typedef ip-prefix {
+     type union {
+       type inet:ipv4-prefix;
+       type inet:ipv6-prefix;
+     }
+     description
+      "The ip-prefix type represents an IP prefix and is IP
+       version neutral.  The format of the textual representations
+       implies the IP version.";
+   }
+
+   typedef ipv4-prefix {
+     type string {
+       pattern
+          '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
+        +  '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
+        + '/(([0-9])|([1-2][0-9])|(3[0-2]))';
+     }
+     description
+      "The ipv4-prefix type represents an IPv4 address prefix.
+       The prefix length is given by the number following the
+       slash character and must be less than or equal to 32.
+
+       A prefix length value of n corresponds to an IP address
+       mask that has n contiguous 1-bits from the most
+       significant bit (MSB) and all other bits set to 0.
+
+       The canonical format of an IPv4 prefix has all bits of
+       the IPv4 address set to zero that are not part of the
+       IPv4 prefix.";
+   }
+
+   typedef ipv6-prefix {
+     type string {
+       pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}'
+             + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|'
+             + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
+             + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
+             + '(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))';
+       pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
+             + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
+             + '(/.+)';
+     }
+     description
+      "The ipv6-prefix type represents an IPv6 address prefix.
+       The prefix length is given by the number following the
+       slash character and must be less than or equal 128.
+
+       A prefix length value of n corresponds to an IP address
+       mask that has n contiguous 1-bits from the most
+       significant bit (MSB) and all other bits set to 0.
+
+       The IPv6 address should have all bits that do not belong
+       to the prefix set to zero.
+
+       The canonical format of an IPv6 prefix has all bits of
+       the IPv6 address set to zero that are not part of the
+       IPv6 prefix.  Furthermore, IPv6 address is represented
+       in the compressed format described in RFC 4291, Section
+       2.2, item 2 with the following additional rules: the ::
+       substitution must be applied to the longest sequence of
+       all-zero 16-bit chunks in an IPv6 address.  If there is
+       a tie, the first sequence of all-zero 16-bit chunks is
+       replaced by ::.  Single all-zero 16-bit chunks are not
+       compressed.  The canonical format uses lowercase
+       characters and leading zeros are not allowed.";
+     reference
+      "RFC 4291: IP Version 6 Addressing Architecture";
+   }
+
+   /*** collection of domain name and URI types ***/
+
+   typedef domain-name {
+     type string {
+       pattern '((([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.)*'
+            +  '([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.?)'
+            +  '|\.';
+       length "1..253";
+     }
+     description
+      "The domain-name type represents a DNS domain name.  The
+       name SHOULD be fully qualified whenever possible.
+
+       Internet domain names are only loosely specified.  Section
+       3.5 of RFC 1034 recommends a syntax (modified in Section
+       2.1 of RFC 1123).  The pattern above is intended to allow
+       for current practice in domain name use, and some possible
+       future expansion.  It is designed to hold various types of
+       domain names, including names used for A or AAAA records
+       (host names) and other records, such as SRV records.  Note
+       that Internet host names have a stricter syntax (described
+       in RFC 952) than the DNS recommendations in RFCs 1034 and
+       1123, and that systems that want to store host names in
+       schema nodes using the domain-name type are recommended to
+       adhere to this stricter standard to ensure interoperability.
+
+       The encoding of DNS names in the DNS protocol is limited
+       to 255 characters.  Since the encoding consists of labels
+       prefixed by a length bytes and there is a trailing NULL
+       byte, only 253 characters can appear in the textual dotted
+       notation.
+
+       The description clause of schema nodes using the domain-name
+       type MUST describe when and how these names are resolved to
+       IP addresses.  Note that the resolution of a domain-name value
+       may require to query multiple DNS records (e.g., A for IPv4
+       and AAAA for IPv6).  The order of the resolution process and
+       which DNS record takes precedence can either be defined
+       explicitely or it may depend on the configuration of the
+       resolver.
+
+       Domain-name values use the US-ASCII encoding.  Their canonical
+       format uses lowercase US-ASCII characters.  Internationalized
+       domain names MUST be encoded in punycode as described in RFC
+       3492";
+     reference
+      "RFC  952: DoD Internet Host Table Specification
+       RFC 1034: Domain Names - Concepts and Facilities
+       RFC 1123: Requirements for Internet Hosts -- Application
+                 and Support
+       RFC 2782: A DNS RR for specifying the location of services
+                 (DNS SRV)
+       RFC 3492: Punycode: A Bootstring encoding of Unicode for
+                 Internationalized Domain Names in Applications
+                 (IDNA)
+       RFC 5891: Internationalizing Domain Names in Applications
+                 (IDNA): Protocol";
+   }
+
+   typedef host {
+     type union {
+       type inet:ip-address;
+       type inet:domain-name;
+     }
+     description
+      "The host type represents either an IP address or a DNS
+       domain name.";
+   }
+
+   typedef uri {
+     type string;
+     description
+      "The uri type represents a Uniform Resource Identifier
+       (URI) as defined by STD 66.
+
+       Objects using the uri type MUST be in US-ASCII encoding,
+       and MUST be normalized as described by RFC 3986 Sections
+       6.2.1, 6.2.2.1, and 6.2.2.2.  All unnecessary
+       percent-encoding is removed, and all case-insensitive
+       characters are set to lowercase except for hexadecimal
+       digits, which are normalized to uppercase as described in
+       Section 6.2.2.1.
+
+       The purpose of this normalization is to help provide
+       unique URIs.  Note that this normalization is not
+       sufficient to provide uniqueness.  Two URIs that are
+       textually distinct after this normalization may still be
+       equivalent.
+
+       Objects using the uri type may restrict the schemes that
+       they permit.  For example, 'data:' and 'urn:' schemes
+       might not be appropriate.
+
+       A zero-length URI is not a valid URI.  This can be used to
+       express 'URI absent' where required.
+
+       In the value set and its semantics, this type is equivalent
+       to the Uri SMIv2 textual convention defined in RFC 5017.";
+     reference
+      "RFC 3986: Uniform Resource Identifier (URI): Generic Syntax
+       RFC 3305: Report from the Joint W3C/IETF URI Planning Interest
+                 Group: Uniform Resource Identifiers (URIs), URLs,
+                 and Uniform Resource Names (URNs): Clarifications
+                 and Recommendations
+       RFC 5017: MIB Textual Conventions for Uniform Resource
+                 Identifiers (URIs)";
+   }
+
+ }
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/ietf-interfaces@2012-11-15.yang b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/ietf-interfaces@2012-11-15.yang
new file mode 100644 (file)
index 0000000..b9117d0
--- /dev/null
@@ -0,0 +1,565 @@
+module ietf-interfaces {
+
+  namespace "urn:ietf:params:xml:ns:yang:ietf-interfaces";
+  prefix if;
+
+  import ietf-yang-types {
+    prefix yang;
+  }
+  import iana-if-type {
+    prefix ianaift;
+  }
+
+  organization
+    "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+
+  contact
+    "WG Web:   <http://tools.ietf.org/wg/netmod/>
+     WG List:  <mailto:netmod@ietf.org>
+
+     WG Chair: David Kessens
+               <mailto:david.kessens@nsn.com>
+
+     WG Chair: Juergen Schoenwaelder
+               <mailto:j.schoenwaelder@jacobs-university.de>
+
+     Editor:   Martin Bjorklund
+               <mailto:mbj@tail-f.com>";
+
+  description
+    "This module contains a collection of YANG definitions for
+     managing network interfaces.
+
+     Copyright (c) 2012 IETF Trust and the persons identified as
+     authors of the code.  All rights reserved.
+
+     Redistribution and use in source and binary forms, with or
+     without modification, is permitted pursuant to, and subject
+     to the license terms contained in, the Simplified BSD License
+     set forth in Section 4.c of the IETF Trust's Legal Provisions
+     Relating to IETF Documents
+     (http://trustee.ietf.org/license-info).
+
+     This version of this YANG module is part of RFC XXXX; see
+     the RFC itself for full legal notices.";
+
+  // RFC Ed.: replace XXXX with actual RFC number and remove this
+  // note.
+
+  // RFC Ed.: update the date below with the date of RFC publication
+  // and remove this note.
+  revision 2012-11-15 {
+    description
+      "Initial revision.";
+    reference
+      "RFC XXXX: A YANG Data Model for Interface Management";
+  }
+
+  /* Typedefs */
+
+  typedef interface-ref {
+    type leafref {
+      path "/if:interfaces/if:interface/if:name";
+    }
+    description
+      "This type is used by data models that need to reference
+       interfaces.";
+  }
+
+  /* Features */
+
+  feature arbitrary-names {
+    description
+      "This feature indicates that the server allows interfaces to
+       be named arbitrarily.";
+  }
+
+  feature if-mib {
+    description
+      "This feature indicates that the server implements IF-MIB.";
+    reference
+      "RFC 2863: The Interfaces Group MIB";
+  }
+
+  /* Data nodes */
+
+  container interfaces {
+    description
+      "Interface parameters.";
+
+    list interface {
+      key "name";
+      unique "type location";
+
+      description
+        "The list of interfaces on the device.";
+
+      leaf name {
+        type string;
+        description
+          "The name of the interface.
+
+           A device MAY restrict the allowed values for this leaf,
+           possibly depending on the type and location.
+
+           If the device allows arbitrarily named interfaces, the
+           feature 'arbitrary-names' is advertised.
+
+           This leaf MAY be mapped to ifName by an implementation.
+           Such an implementation MAY restrict the allowed values for
+           this leaf so that it matches the restrictions of ifName.
+           If a NETCONF server that implements this restriction is
+           sent a value that doesn't match the restriction, it MUST
+           reply with an rpc-error with the error-tag
+           'invalid-value'.";
+        reference
+          "RFC 2863: The Interfaces Group MIB - ifName";
+      }
+
+      leaf description {
+        type string;
+        description
+          "A textual description of the interface.
+
+           This leaf MAY be mapped to ifAlias by an implementation.
+           Such an implementation MAY restrict the allowed values for
+           this leaf so that it matches the restrictions of ifAlias.
+           If a NETCONF server that implements this restriction is
+           sent a value that doesn't match the restriction, it MUST
+           reply with an rpc-error with the error-tag
+           'invalid-value'.";
+        reference
+          "RFC 2863: The Interfaces Group MIB - ifAlias";
+      }
+
+      leaf type {
+        type ianaift:iana-if-type;
+        mandatory true;
+        description
+          "The type of the interface.
+
+           When an interface entry is created, a server MAY
+           initialize the type leaf with a valid value, e.g., if it
+           is possible to derive the type from the name of the
+           interface.";
+        reference
+          "RFC 2863: The Interfaces Group MIB - ifType";
+      }
+
+      leaf location {
+        type string;
+        description
+          "The device-specific location of the interface of a
+           particular type.  The format of the location string
+           depends on the interface type and the device.
+
+           If the interface's type represents a physical interface,
+           this leaf MUST be set.
+
+           When an interface entry is created, a server MAY
+           initialize the location leaf with a valid value, e.g., if
+           it is possible to derive the location from the name of
+           the interface.";
+      }
+
+      leaf enabled {
+        type boolean;
+        default "true";
+        description
+          "The desired state of the interface.
+
+           This leaf contains the configured, desired state of the
+           interface.  Systems that implement the IF-MIB use the
+           value of this leaf to set IF-MIB.ifAdminStatus to 'up' or
+           'down' after an ifEntry has been initialized, as described
+           in RFC 2863.";
+        reference
+          "RFC 2863: The Interfaces Group MIB - ifAdminStatus";
+      }
+
+      leaf oper-status {
+        type enumeration {
+          enum up {
+            value 1;
+            description
+              "Ready to pass packets.";
+          }
+          enum down {
+            value 2;
+            description
+              "The interface does not pass any packets.";
+          }
+          enum testing {
+            value 3;
+            description
+              "In some test mode.  No operational packets can
+               be passed.";
+          }
+          enum unknown {
+            value 4;
+            description
+              "Status cannot be determined for some reason.";
+          }
+          enum dormant {
+            value 5;
+            description
+              "Waiting for some external event.";
+          }
+          enum not-present {
+            value 6;
+            description
+              "Some component is missing.";
+          }
+          enum lower-layer-down {
+            value 7;
+            description
+              "Down due to state of lower-layer interface(s).";
+          }
+        }
+        config false;
+        description
+          "The current operational state of the interface.
+
+           If 'enabled' is 'false' then 'oper-status'
+           should be 'down'.  If 'enabled' is changed to 'true'
+           then 'oper-status' should change to 'up' if the interface
+           is ready to transmit and receive network traffic; it
+           should change to 'dormant' if the interface is waiting for
+           external actions (such as a serial line waiting for an
+           incoming connection); it should remain in the 'down' state
+           if and only if there is a fault that prevents it from
+           going to the 'up' state; it should remain in the
+           'not-present' state if the interface has missing
+           (typically, hardware) components.";
+        reference
+          "RFC 2863: The Interfaces Group MIB - ifOperStatus";
+      }
+
+      leaf last-change {
+        type yang:date-and-time;
+        config false;
+        description
+          "The time the interface entered its current operational
+           state.  If the current state was entered prior to the
+           last re-initialization of the local network management
+           subsystem, then this node is not present.";
+        reference
+          "RFC 2863: The Interfaces Group MIB - ifLastChange";
+      }
+
+      leaf if-index {
+        if-feature if-mib;
+        type int32 {
+          range "1..2147483647";
+        }
+        config false;
+        description
+          "The ifIndex value for the ifEntry represented by this
+           interface.
+
+           Media-specific modules must specify how the type is
+           mapped to entries in the ifTable.";
+        reference
+          "RFC 2863: The Interfaces Group MIB - ifIndex";
+      }
+
+      leaf link-up-down-trap-enable {
+        if-feature if-mib;
+        type enumeration {
+          enum enabled {
+            value 1;
+          }
+          enum disabled {
+            value 2;
+          }
+        }
+        description
+          "Indicates whether linkUp/linkDown SNMP notifications
+           should be generated for this interface.
+           If this node is not configured, the value 'enabled' is
+           operationally used by the server for interfaces which do
+           not operate on top of any other interface (i.e., there are
+           no 'lower-layer-if' entries), and 'disabled' otherwise.";
+        reference
+          "RFC 2863: The Interfaces Group MIB -
+                     ifLinkUpDownTrapEnable";
+      }
+
+      leaf phys-address {
+        type yang:phys-address;
+        config false;
+        description
+          "The interface's address at its protocol sub-layer.  For
+          example, for an 802.x interface, this object normally
+          contains a MAC address.  The interface's media-specific
+          modules must define the bit and byte ordering and the
+          format of the value of this object.  For interfaces that do
+          not have such an address (e.g., a serial line), this node
+          is not present.";
+        reference
+          "RFC 2863: The Interfaces Group MIB - ifPhysAddress";
+      }
+
+      leaf-list higher-layer-if {
+        type interface-ref;
+        config false;
+        description
+          "A list of references to interfaces layered on top of this
+           interface.";
+        reference
+          "RFC 2863: The Interfaces Group MIB - ifStackTable";
+      }
+
+      leaf-list lower-layer-if {
+        type interface-ref;
+        config false;
+        description
+          "A list of references to interfaces layered underneath this
+           interface.";
+        reference
+          "RFC 2863: The Interfaces Group MIB - ifStackTable";
+      }
+
+      leaf speed {
+        type yang:gauge64;
+        units "bits / second";
+        config false;
+        description
+            "An estimate of the interface's current bandwidth in bits
+             per second.  For interfaces which do not vary in
+             bandwidth or for those where no accurate estimation can
+             be made, this node should contain the nominal bandwidth.
+             For interfaces that has no concept of bandwidth, this
+             node is not present.";
+        reference
+          "RFC 2863: The Interfaces Group MIB -
+                     ifSpeed, ifHighSpeed";
+      }
+
+      container statistics {
+        config false;
+        description
+          "A collection of interface-related statistics objects.";
+
+        leaf discontinuity-time {
+          type yang:date-and-time;
+          description
+            "The time on the most recent occasion at which any one or
+             more of this interface's counters suffered a
+             discontinuity.  If no such discontinuities have occurred
+             since the last re-initialization of the local management
+             subsystem, then this node contains the time the local
+             management subsystem re-initialized itself.";
+        }
+
+        leaf in-octets {
+          type yang:counter64;
+          description
+            "The total number of octets received on the interface,
+             including framing characters.
+
+             Discontinuities in the value of this counter can occur
+             at re-initialization of the management system, and at
+             other times as indicated by the value of
+             'discontinuity-time'.";
+          reference
+            "RFC 2863: The Interfaces Group MIB - ifHCInOctets";
+        }
+        leaf in-unicast-pkts {
+          type yang:counter64;
+          description
+            "The number of packets, delivered by this sub-layer to a
+             higher (sub-)layer, which were not addressed to a
+             multicast or broadcast address at this sub-layer.
+
+             Discontinuities in the value of this counter can occur
+             at re-initialization of the management system, and at
+             other times as indicated by the value of
+             'discontinuity-time'.";
+          reference
+            "RFC 2863: The Interfaces Group MIB - ifHCInUcastPkts";
+        }
+        leaf in-broadcast-pkts {
+          type yang:counter64;
+          description
+            "The number of packets, delivered by this sub-layer to a
+             higher (sub-)layer, which were addressed to a broadcast
+             address at this sub-layer.
+
+             Discontinuities in the value of this counter can occur
+             at re-initialization of the management system, and at
+             other times as indicated by the value of
+             'discontinuity-time'.";
+          reference
+            "RFC 2863: The Interfaces Group MIB -
+                       ifHCInBroadcastPkts";
+        }
+        leaf in-multicast-pkts {
+          type yang:counter64;
+          description
+            "The number of packets, delivered by this sub-layer to a
+             higher (sub-)layer, which were addressed to a multicast
+             address at this sub-layer.  For a MAC layer protocol,
+             this includes both Group and Functional addresses.
+
+             Discontinuities in the value of this counter can occur
+             at re-initialization of the management system, and at
+             other times as indicated by the value of
+             'discontinuity-time'.";
+          reference
+            "RFC 2863: The Interfaces Group MIB -
+                       ifHCInMulticastPkts";
+        }
+        leaf in-discards {
+          type yang:counter32;
+          description
+            "The number of inbound packets which were chosen to be
+             discarded even though no errors had been detected to
+             prevent their being deliverable to a higher-layer
+             protocol.  One possible reason for discarding such a
+             packet could be to free up buffer space.
+
+             Discontinuities in the value of this counter can occur
+             at re-initialization of the management system, and at
+             other times as indicated by the value of
+             'discontinuity-time'.";
+          reference
+            "RFC 2863: The Interfaces Group MIB - ifInDiscards";
+        }
+        leaf in-errors {
+          type yang:counter32;
+          description
+            "For packet-oriented interfaces, the number of inbound
+             packets that contained errors preventing them from being
+             deliverable to a higher-layer protocol.  For character-
+             oriented or fixed-length interfaces, the number of
+             inbound transmission units that contained errors
+             preventing them from being deliverable to a higher-layer
+             protocol.
+
+             Discontinuities in the value of this counter can occur
+             at re-initialization of the management system, and at
+             other times as indicated by the value of
+             'discontinuity-time'.";
+          reference
+            "RFC 2863: The Interfaces Group MIB - ifInErrors";
+        }
+        leaf in-unknown-protos {
+          type yang:counter32;
+          description
+            "For packet-oriented interfaces, the number of packets
+             received via the interface which were discarded because
+             of an unknown or unsupported protocol.  For
+             character-oriented or fixed-length interfaces that
+             support protocol multiplexing the number of transmission
+             units received via the interface which were discarded
+             because of an unknown or unsupported protocol.  For any
+             interface that does not support protocol multiplexing,
+             this counter is not present.
+
+             Discontinuities in the value of this counter can occur
+             at re-initialization of the management system, and at
+             other times as indicated by the value of
+             'discontinuity-time'.";
+          reference
+            "RFC 2863: The Interfaces Group MIB - ifInUnknownProtos";
+        }
+
+        leaf out-octets {
+          type yang:counter64;
+          description
+            "The total number of octets transmitted out of the
+             interface, including framing characters.
+
+             Discontinuities in the value of this counter can occur
+             at re-initialization of the management system, and at
+             other times as indicated by the value of
+             'discontinuity-time'.";
+          reference
+            "RFC 2863: The Interfaces Group MIB - ifHCOutOctets";
+        }
+        leaf out-unicast-pkts {
+          type yang:counter64;
+          description
+            "The total number of packets that higher-level protocols
+             requested be transmitted, and which were not addressed
+             to a multicast or broadcast address at this sub-layer,
+             including those that were discarded or not sent.
+
+             Discontinuities in the value of this counter can occur
+             at re-initialization of the management system, and at
+             other times as indicated by the value of
+             'discontinuity-time'.";
+          reference
+            "RFC 2863: The Interfaces Group MIB - ifHCOutUcastPkts";
+        }
+        leaf out-broadcast-pkts {
+          type yang:counter64;
+          description
+            "The total number of packets that higher-level protocols
+             requested be transmitted, and which were addressed to a
+             broadcast address at this sub-layer, including those
+             that were discarded or not sent.
+
+             Discontinuities in the value of this counter can occur
+             at re-initialization of the management system, and at
+             other times as indicated by the value of
+             'discontinuity-time'.";
+          reference
+            "RFC 2863: The Interfaces Group MIB -
+                       ifHCOutBroadcastPkts";
+        }
+        leaf out-multicast-pkts {
+          type yang:counter64;
+          description
+            "The total number of packets that higher-level protocols
+             requested be transmitted, and which were addressed to a
+             multicast address at this sub-layer, including those
+             that were discarded or not sent.  For a MAC layer
+             protocol, this includes both Group and Functional
+             addresses.
+
+             Discontinuities in the value of this counter can occur
+             at re-initialization of the management system, and at
+             other times as indicated by the value of
+             'discontinuity-time'.";
+          reference
+            "RFC 2863: The Interfaces Group MIB -
+                       ifHCOutMulticastPkts";
+        }
+        leaf out-discards {
+          type yang:counter32;
+          description
+            "The number of outbound packets which were chosen to be
+             discarded even though no errors had been detected to
+             prevent their being transmitted.  One possible reason
+             for discarding such a packet could be to free up buffer
+             space.
+
+             Discontinuities in the value of this counter can occur
+             at re-initialization of the management system, and at
+             other times as indicated by the value of
+             'discontinuity-time'.";
+          reference
+            "RFC 2863: The Interfaces Group MIB - ifOutDiscards";
+        }
+        leaf out-errors {
+          type yang:counter32;
+          description
+            "For packet-oriented interfaces, the number of outbound
+             packets that could not be transmitted because of errors.
+             For character-oriented or fixed-length interfaces, the
+             number of outbound transmission units that could not be
+             transmitted because of errors.
+
+             Discontinuities in the value of this counter can occur
+             at re-initialization of the management system, and at
+             other times as indicated by the value of
+             'discontinuity-time'.";
+          reference
+            "RFC 2863: The Interfaces Group MIB - ifOutErrors";
+        }
+      }
+    }
+  }
+}
\ No newline at end of file
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/ietf-yang-types@2010-09-24.yang b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/ietf-yang-types@2010-09-24.yang
new file mode 100644 (file)
index 0000000..e9d88ab
--- /dev/null
@@ -0,0 +1,396 @@
+ module ietf-yang-types {
+
+   namespace "urn:ietf:params:xml:ns:yang:ietf-yang-types";
+   prefix "yang";
+
+   organization
+    "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+
+   contact
+    "WG Web:   <http://tools.ietf.org/wg/netmod/>
+     WG List:  <mailto:netmod@ietf.org>
+
+     WG Chair: David Partain
+               <mailto:david.partain@ericsson.com>
+
+     WG Chair: David Kessens
+               <mailto:david.kessens@nsn.com>
+
+     Editor:   Juergen Schoenwaelder
+               <mailto:j.schoenwaelder@jacobs-university.de>";
+
+   description
+    "This module contains a collection of generally useful derived
+     YANG data types.
+
+     Copyright (c) 2010 IETF Trust and the persons identified as
+     authors of the code.  All rights reserved.
+
+     Redistribution and use in source and binary forms, with or without
+     modification, is permitted pursuant to, and subject to the license
+     terms contained in, the Simplified BSD License set forth in Section
+     4.c of the IETF Trust's Legal Provisions Relating to IETF Documents
+     (http://trustee.ietf.org/license-info).
+
+     This version of this YANG module is part of RFC 6021; see
+     the RFC itself for full legal notices.";
+
+   revision 2010-09-24 {
+     description
+      "Initial revision.";
+     reference
+      "RFC 6021: Common YANG Data Types";
+   }
+
+   /*** collection of counter and gauge types ***/
+
+   typedef counter32 {
+     type uint32;
+     description
+      "The counter32 type represents a non-negative integer
+       that monotonically increases until it reaches a
+       maximum value of 2^32-1 (4294967295 decimal), when it
+       wraps around and starts increasing again from zero.
+
+       Counters have no defined 'initial' value, and thus, a
+       single value of a counter has (in general) no information
+       content.  Discontinuities in the monotonically increasing
+       value normally occur at re-initialization of the
+       management system, and at other times as specified in the
+       description of a schema node using this type.  If such
+       other times can occur, for example, the creation of
+       a schema node of type counter32 at times other than
+       re-initialization, then a corresponding schema node
+       should be defined, with an appropriate type, to indicate
+       the last discontinuity.
+
+       The counter32 type should not be used for configuration
+       schema nodes.  A default statement SHOULD NOT be used in
+       combination with the type counter32.
+
+       In the value set and its semantics, this type is equivalent
+       to the Counter32 type of the SMIv2.";
+     reference
+      "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+   }
+
+   typedef zero-based-counter32 {
+     type yang:counter32;
+     default "0";
+     description
+      "The zero-based-counter32 type represents a counter32
+       that has the defined 'initial' value zero.
+
+       A schema node of this type will be set to zero (0) on creation
+       and will thereafter increase monotonically until it reaches
+       a maximum value of 2^32-1 (4294967295 decimal), when it
+       wraps around and starts increasing again from zero.
+
+       Provided that an application discovers a new schema node
+       of this type within the minimum time to wrap, it can use the
+       'initial' value as a delta.  It is important for a management
+       station to be aware of this minimum time and the actual time
+       between polls, and to discard data if the actual time is too
+       long or there is no defined minimum time.
+
+       In the value set and its semantics, this type is equivalent
+       to the ZeroBasedCounter32 textual convention of the SMIv2.";
+     reference
+       "RFC 4502: Remote Network Monitoring Management Information
+                  Base Version 2";
+   }
+
+   typedef counter64 {
+     type uint64;
+     description
+      "The counter64 type represents a non-negative integer
+       that monotonically increases until it reaches a
+       maximum value of 2^64-1 (18446744073709551615 decimal),
+       when it wraps around and starts increasing again from zero.
+
+       Counters have no defined 'initial' value, and thus, a
+       single value of a counter has (in general) no information
+       content.  Discontinuities in the monotonically increasing
+       value normally occur at re-initialization of the
+       management system, and at other times as specified in the
+       description of a schema node using this type.  If such
+       other times can occur, for example, the creation of
+       a schema node of type counter64 at times other than
+       re-initialization, then a corresponding schema node
+       should be defined, with an appropriate type, to indicate
+       the last discontinuity.
+
+       The counter64 type should not be used for configuration
+       schema nodes.  A default statement SHOULD NOT be used in
+       combination with the type counter64.
+
+       In the value set and its semantics, this type is equivalent
+       to the Counter64 type of the SMIv2.";
+     reference
+      "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+   }
+
+   typedef zero-based-counter64 {
+     type yang:counter64;
+     default "0";
+     description
+      "The zero-based-counter64 type represents a counter64 that
+       has the defined 'initial' value zero.
+
+       A schema node of this type will be set to zero (0) on creation
+       and will thereafter increase monotonically until it reaches
+       a maximum value of 2^64-1 (18446744073709551615 decimal),
+       when it wraps around and starts increasing again from zero.
+
+       Provided that an application discovers a new schema node
+       of this type within the minimum time to wrap, it can use the
+       'initial' value as a delta.  It is important for a management
+       station to be aware of this minimum time and the actual time
+       between polls, and to discard data if the actual time is too
+       long or there is no defined minimum time.
+
+       In the value set and its semantics, this type is equivalent
+       to the ZeroBasedCounter64 textual convention of the SMIv2.";
+     reference
+      "RFC 2856: Textual Conventions for Additional High Capacity
+                 Data Types";
+   }
+
+   typedef gauge32 {
+     type uint32;
+     description
+      "The gauge32 type represents a non-negative integer, which
+       may increase or decrease, but shall never exceed a maximum
+       value, nor fall below a minimum value.  The maximum value
+       cannot be greater than 2^32-1 (4294967295 decimal), and
+       the minimum value cannot be smaller than 0.  The value of
+       a gauge32 has its maximum value whenever the information
+       being modeled is greater than or equal to its maximum
+       value, and has its minimum value whenever the information
+       being modeled is smaller than or equal to its minimum value.
+       If the information being modeled subsequently decreases
+       below (increases above) the maximum (minimum) value, the
+       gauge32 also decreases (increases).
+
+       In the value set and its semantics, this type is equivalent
+       to the Gauge32 type of the SMIv2.";
+     reference
+      "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+   }
+
+   typedef gauge64 {
+     type uint64;
+     description
+      "The gauge64 type represents a non-negative integer, which
+       may increase or decrease, but shall never exceed a maximum
+       value, nor fall below a minimum value.  The maximum value
+       cannot be greater than 2^64-1 (18446744073709551615), and
+       the minimum value cannot be smaller than 0.  The value of
+       a gauge64 has its maximum value whenever the information
+       being modeled is greater than or equal to its maximum
+       value, and has its minimum value whenever the information
+       being modeled is smaller than or equal to its minimum value.
+       If the information being modeled subsequently decreases
+       below (increases above) the maximum (minimum) value, the
+       gauge64 also decreases (increases).
+
+       In the value set and its semantics, this type is equivalent
+       to the CounterBasedGauge64 SMIv2 textual convention defined
+       in RFC 2856";
+     reference
+      "RFC 2856: Textual Conventions for Additional High Capacity
+                 Data Types";
+   }
+
+   /*** collection of identifier related types ***/
+
+   typedef object-identifier {
+     type string {
+       pattern '(([0-1](\.[1-3]?[0-9]))|(2\.(0|([1-9]\d*))))'
+             + '(\.(0|([1-9]\d*)))*';
+     }
+     description
+      "The object-identifier type represents administratively
+       assigned names in a registration-hierarchical-name tree.
+
+       Values of this type are denoted as a sequence of numerical
+       non-negative sub-identifier values.  Each sub-identifier
+       value MUST NOT exceed 2^32-1 (4294967295).  Sub-identifiers
+       are separated by single dots and without any intermediate
+       whitespace.
+
+       The ASN.1 standard restricts the value space of the first
+       sub-identifier to 0, 1, or 2.  Furthermore, the value space
+       of the second sub-identifier is restricted to the range
+       0 to 39 if the first sub-identifier is 0 or 1.  Finally,
+       the ASN.1 standard requires that an object identifier
+       has always at least two sub-identifier.  The pattern
+       captures these restrictions.
+
+       Although the number of sub-identifiers is not limited,
+       module designers should realize that there may be
+       implementations that stick with the SMIv2 limit of 128
+       sub-identifiers.
+
+       This type is a superset of the SMIv2 OBJECT IDENTIFIER type
+       since it is not restricted to 128 sub-identifiers.  Hence,
+       this type SHOULD NOT be used to represent the SMIv2 OBJECT
+       IDENTIFIER type, the object-identifier-128 type SHOULD be
+       used instead.";
+     reference
+      "ISO9834-1: Information technology -- Open Systems
+       Interconnection -- Procedures for the operation of OSI
+       Registration Authorities: General procedures and top
+       arcs of the ASN.1 Object Identifier tree";
+   }
+
+
+
+
+   typedef object-identifier-128 {
+     type object-identifier {
+       pattern '\d*(\.\d*){1,127}';
+     }
+     description
+      "This type represents object-identifiers restricted to 128
+       sub-identifiers.
+
+       In the value set and its semantics, this type is equivalent
+       to the OBJECT IDENTIFIER type of the SMIv2.";
+     reference
+      "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+   }
+
+   /*** collection of date and time related types ***/
+
+   typedef date-and-time {
+     type string {
+       pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?'
+             + '(Z|[\+\-]\d{2}:\d{2})';
+     }
+     description
+      "The date-and-time type is a profile of the ISO 8601
+       standard for representation of dates and times using the
+       Gregorian calendar.  The profile is defined by the
+       date-time production in Section 5.6 of RFC 3339.
+
+       The date-and-time type is compatible with the dateTime XML
+       schema type with the following notable exceptions:
+
+       (a) The date-and-time type does not allow negative years.
+
+       (b) The date-and-time time-offset -00:00 indicates an unknown
+           time zone (see RFC 3339) while -00:00 and +00:00 and Z all
+           represent the same time zone in dateTime.
+
+       (c) The canonical format (see below) of data-and-time values
+           differs from the canonical format used by the dateTime XML
+           schema type, which requires all times to be in UTC using the
+           time-offset 'Z'.
+
+       This type is not equivalent to the DateAndTime textual
+       convention of the SMIv2 since RFC 3339 uses a different
+       separator between full-date and full-time and provides
+       higher resolution of time-secfrac.
+
+       The canonical format for date-and-time values with a known time
+       zone uses a numeric time zone offset that is calculated using
+       the device's configured known offset to UTC time.  A change of
+       the device's offset to UTC time will cause date-and-time values
+       to change accordingly.  Such changes might happen periodically
+       in case a server follows automatically daylight saving time
+       (DST) time zone offset changes.  The canonical format for
+       date-and-time values with an unknown time zone (usually referring
+       to the notion of local time) uses the time-offset -00:00.";
+     reference
+      "RFC 3339: Date and Time on the Internet: Timestamps
+       RFC 2579: Textual Conventions for SMIv2
+       XSD-TYPES: XML Schema Part 2: Datatypes Second Edition";
+   }
+
+   typedef timeticks {
+     type uint32;
+     description
+      "The timeticks type represents a non-negative integer that
+       represents the time, modulo 2^32 (4294967296 decimal), in
+       hundredths of a second between two epochs.  When a schema
+       node is defined that uses this type, the description of
+       the schema node identifies both of the reference epochs.
+
+       In the value set and its semantics, this type is equivalent
+       to the TimeTicks type of the SMIv2.";
+     reference
+      "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+   }
+
+   typedef timestamp {
+     type yang:timeticks;
+     description
+      "The timestamp type represents the value of an associated
+       timeticks schema node at which a specific occurrence happened.
+       The specific occurrence must be defined in the description
+       of any schema node defined using this type.  When the specific
+       occurrence occurred prior to the last time the associated
+       timeticks attribute was zero, then the timestamp value is
+       zero.  Note that this requires all timestamp values to be
+       reset to zero when the value of the associated timeticks
+       attribute reaches 497+ days and wraps around to zero.
+
+       The associated timeticks schema node must be specified
+       in the description of any schema node using this type.
+
+       In the value set and its semantics, this type is equivalent
+       to the TimeStamp textual convention of the SMIv2.";
+     reference
+      "RFC 2579: Textual Conventions for SMIv2";
+   }
+
+   /*** collection of generic address types ***/
+
+   typedef phys-address {
+     type string {
+       pattern '([0-9a-fA-F]{2}(:[0-9a-fA-F]{2})*)?';
+     }
+     description
+      "Represents media- or physical-level addresses represented
+       as a sequence octets, each octet represented by two hexadecimal
+       numbers.  Octets are separated by colons.  The canonical
+       representation uses lowercase characters.
+
+       In the value set and its semantics, this type is equivalent
+       to the PhysAddress textual convention of the SMIv2.";
+     reference
+      "RFC 2579: Textual Conventions for SMIv2";
+   }
+
+   typedef mac-address {
+     type string {
+       pattern '[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}';
+     }
+     description
+      "The mac-address type represents an IEEE 802 MAC address.
+       The canonical representation uses lowercase characters.
+
+       In the value set and its semantics, this type is equivalent
+       to the MacAddress textual convention of the SMIv2.";
+     reference
+      "IEEE 802: IEEE Standard for Local and Metropolitan Area
+                 Networks: Overview and Architecture
+       RFC 2579: Textual Conventions for SMIv2";
+   }
+
+   /*** collection of XML specific types ***/
+
+   typedef xpath1.0 {
+     type string;
+     description
+      "This type represents an XPATH 1.0 expression.
+
+       When a schema node is defined that uses this type, the
+       description of the schema node MUST specify the XPath
+       context in which the XPath expression is evaluated.";
+     reference
+      "XPATH: XML Path Language (XPath) Version 1.0";
+   }
+
+ }
\ No newline at end of file
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/enum-test-models/abstract-topology@2013-02-08.yang b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/enum-test-models/abstract-topology@2013-02-08.yang
new file mode 100644 (file)
index 0000000..d4a7341
--- /dev/null
@@ -0,0 +1,153 @@
+module abstract-topology {
+    yang-version 1;
+    namespace "urn:model:abstract:topology";
+    prefix "tp";
+
+    import ietf-inet-types {
+        prefix "inet";
+        revision-date 2010-09-24;
+    }
+
+    import ietf-interfaces {
+        prefix "if";
+        revision-date 2012-11-15;
+    }
+
+    organization "OPEN DAYLIGHT";
+    contact "http://www.opendaylight.org/";
+
+    description
+        "This module contains the definitions of elements that creates network 
+    topology i.e. definition of network nodes and links. This module is not designed to be used solely for network representation. This module SHOULD be used as base module in defining the network topology.";
+
+    revision "2013-02-08" {
+        reference "~~~ WILL BE DEFINED LATER";
+    }
+    
+    revision "2013-01-01" {
+        reference "~~~ WILL BE DEFINED LATER";
+    }
+    
+    typedef node-id-ref {
+        type leafref {
+            path "/tp:topology/tp:network-nodes/tp:network-node/tp:node-id";
+        }
+        description "This type is used for leafs that reference network node instance.";
+    }
+
+    typedef link-id-ref {
+        type leafref {
+            path "/tp:topology/tp:network-links/tp:network-link/tp:link-id";
+        }
+        description "This type is used for leafs that reference network link instance.";
+    }
+
+    typedef interface-id-ref {
+        type leafref {
+            path "/tp:topology/tp:interfaces/tp:interface/tp:interface-id";
+        }
+    }
+
+    container 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.";
+
+        leaf topology-id {
+            type inet:uri;
+            description "It is presumed that datastore will contain many topologies. To distinguish between topologies it is vital to have
+            UNIQUE topology identifier.";
+        }
+
+        container network-nodes {
+            list network-node {
+                key "node-id";
+
+                leaf node-id {
+                    type inet:uri;
+                    description "The Topology identifier of network-node.";
+                }
+
+                container attributes {
+                    description "Aditional attributes that can Network Node contains.";
+                }
+                description "The list of network nodes defined for topology.";
+            }
+        }
+
+        container interfaces {
+            list interface {
+                key "interface-id";
+
+                leaf interface-id {
+                    type leafref {
+                        path "/if:interfaces/if:interface/if:name";
+                    }
+                }
+
+                leaf-list higher-layer-if {
+                    type leafref {
+                        path "/if:interfaces/if:interface/if:higher-layer-if";
+                    }
+                }
+
+                leaf oper-status {
+                    type leafref {
+                        path "/if:interfaces/if:interface/if:oper-status";
+                    }
+                }
+
+                leaf link-up-down-trap-enable {
+                    type leafref {
+                        path "/if:interfaces/if:interface/if:link-up-down-trap-enable";
+                    }
+                }
+            }
+        }
+        
+        container network-links {
+            list network-link {
+                key "link-id";
+
+                leaf link-id {
+                    type inet:uri;
+                    description "";
+                }
+
+                container source-node {
+                    leaf id {
+                        type node-id-ref;
+                        description "Source node identifier.";
+                    }
+                }
+
+                container destination-node {
+                    leaf id {
+                        type node-id-ref;
+                        description "Destination node identifier.";
+                    }
+                }
+
+                container tunnels {
+                    list tunnel {
+                        key "tunnel-id";
+
+                        leaf tunnel-id {
+                            type leafref {
+                                path "../../../link-id";
+                            }
+                        }
+                    }
+                }
+
+                leaf interface {
+                    type interface-id-ref;
+                }
+
+                container attributes {
+                    description "Aditional attributes that can Network Link contains.";
+                }
+                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.";
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/enum-test-models/ietf-inet-types@2010-09-24.yang b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/enum-test-models/ietf-inet-types@2010-09-24.yang
new file mode 100644 (file)
index 0000000..6a6c748
--- /dev/null
@@ -0,0 +1,418 @@
+ module ietf-inet-types {
+
+   namespace "urn:ietf:params:xml:ns:yang:ietf-inet-types";
+   prefix "inet";
+
+   organization
+    "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+
+   contact
+    "WG Web:   <http://tools.ietf.org/wg/netmod/>
+     WG List:  <mailto:netmod@ietf.org>
+
+     WG Chair: David Partain
+               <mailto:david.partain@ericsson.com>
+
+     WG Chair: David Kessens
+               <mailto:david.kessens@nsn.com>
+
+     Editor:   Juergen Schoenwaelder
+               <mailto:j.schoenwaelder@jacobs-university.de>";
+
+   description
+    "This module contains a collection of generally useful derived
+     YANG data types for Internet addresses and related things.
+
+     Copyright (c) 2010 IETF Trust and the persons identified as
+     authors of the code.  All rights reserved.
+
+     Redistribution and use in source and binary forms, with or without
+     modification, is permitted pursuant to, and subject to the license
+     terms contained in, the Simplified BSD License set forth in Section
+     4.c of the IETF Trust's Legal Provisions Relating to IETF Documents
+     (http://trustee.ietf.org/license-info).
+
+     This version of this YANG module is part of RFC 6021; see
+     the RFC itself for full legal notices.";
+
+   revision 2010-09-24 {
+     description
+      "Initial revision.";
+     reference
+      "RFC 6021: Common YANG Data Types";
+   }
+
+   /*** collection of protocol field related types ***/
+
+   typedef ip-version {
+     type enumeration {
+       enum unknown {
+         value "0";
+         description
+          "An unknown or unspecified version of the Internet protocol.";
+       }
+       enum ipv4 {
+         value "1";
+         description
+          "The IPv4 protocol as defined in RFC 791.";
+       }
+       enum ipv6 {
+         value "2";
+         description
+          "The IPv6 protocol as defined in RFC 2460.";
+       }
+     }
+     description
+      "This value represents the version of the IP protocol.
+
+       In the value set and its semantics, this type is equivalent
+       to the InetVersion textual convention of the SMIv2.";
+     reference
+      "RFC  791: Internet Protocol
+       RFC 2460: Internet Protocol, Version 6 (IPv6) Specification
+       RFC 4001: Textual Conventions for Internet Network Addresses";
+   }
+
+   typedef dscp {
+     type uint8 {
+       range "0..63";
+     }
+     description
+      "The dscp type represents a Differentiated Services Code-Point
+       that may be used for marking packets in a traffic stream.
+
+       In the value set and its semantics, this type is equivalent
+       to the Dscp textual convention of the SMIv2.";
+     reference
+      "RFC 3289: Management Information Base for the Differentiated
+                 Services Architecture
+       RFC 2474: Definition of the Differentiated Services Field
+                 (DS Field) in the IPv4 and IPv6 Headers
+       RFC 2780: IANA Allocation Guidelines For Values In
+                 the Internet Protocol and Related Headers";
+   }
+
+   typedef ipv6-flow-label {
+     type uint32 {
+       range "0..1048575";
+     }
+     description
+      "The flow-label type represents flow identifier or Flow Label
+       in an IPv6 packet header that may be used to discriminate
+       traffic flows.
+
+       In the value set and its semantics, this type is equivalent
+       to the IPv6FlowLabel textual convention of the SMIv2.";
+     reference
+      "RFC 3595: Textual Conventions for IPv6 Flow Label
+       RFC 2460: Internet Protocol, Version 6 (IPv6) Specification";
+   }
+
+   typedef port-number {
+     type uint16 {
+       range "0..65535";
+     }
+     description
+      "The port-number type represents a 16-bit port number of an
+       Internet transport layer protocol such as UDP, TCP, DCCP, or
+       SCTP.  Port numbers are assigned by IANA.  A current list of
+       all assignments is available from <http://www.iana.org/>.
+
+       Note that the port number value zero is reserved by IANA.  In
+       situations where the value zero does not make sense, it can
+       be excluded by subtyping the port-number type.
+
+       In the value set and its semantics, this type is equivalent
+       to the InetPortNumber textual convention of the SMIv2.";
+     reference
+      "RFC  768: User Datagram Protocol
+       RFC  793: Transmission Control Protocol
+       RFC 4960: Stream Control Transmission Protocol
+       RFC 4340: Datagram Congestion Control Protocol (DCCP)
+       RFC 4001: Textual Conventions for Internet Network Addresses";
+   }
+
+   /*** collection of autonomous system related types ***/
+
+   typedef as-number {
+     type uint32;
+     description
+      "The as-number type represents autonomous system numbers
+       which identify an Autonomous System (AS).  An AS is a set
+       of routers under a single technical administration, using
+       an interior gateway protocol and common metrics to route
+       packets within the AS, and using an exterior gateway
+       protocol to route packets to other ASs'.  IANA maintains
+       the AS number space and has delegated large parts to the
+       regional registries.
+
+       Autonomous system numbers were originally limited to 16
+       bits.  BGP extensions have enlarged the autonomous system
+       number space to 32 bits.  This type therefore uses an uint32
+       base type without a range restriction in order to support
+       a larger autonomous system number space.
+
+       In the value set and its semantics, this type is equivalent
+       to the InetAutonomousSystemNumber textual convention of
+       the SMIv2.";
+     reference
+      "RFC 1930: Guidelines for creation, selection, and registration
+                 of an Autonomous System (AS)
+       RFC 4271: A Border Gateway Protocol 4 (BGP-4)
+       RFC 4893: BGP Support for Four-octet AS Number Space
+       RFC 4001: Textual Conventions for Internet Network Addresses";
+   }
+
+   /*** collection of IP address and hostname related types ***/
+
+   typedef ip-address {
+     type union {
+       type inet:ipv4-address;
+       type inet:ipv6-address;
+     }
+     description
+      "The ip-address type represents an IP address and is IP
+       version neutral.  The format of the textual representations
+       implies the IP version.";
+   }
+
+   typedef ipv4-address {
+     type string {
+       pattern
+         '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
+       +  '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
+       + '(%[\p{N}\p{L}]+)?';
+     }
+     description
+       "The ipv4-address type represents an IPv4 address in
+        dotted-quad notation.  The IPv4 address may include a zone
+        index, separated by a % sign.
+
+        The zone index is used to disambiguate identical address
+        values.  For link-local addresses, the zone index will
+        typically be the interface index number or the name of an
+        interface.  If the zone index is not present, the default
+        zone of the device will be used.
+
+        The canonical format for the zone index is the numerical
+        format";
+   }
+
+   typedef ipv6-address {
+     type string {
+       pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}'
+             + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|'
+             + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
+             + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
+             + '(%[\p{N}\p{L}]+)?';
+       pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
+             + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
+             + '(%.+)?';
+     }
+     description
+      "The ipv6-address type represents an IPv6 address in full,
+       mixed, shortened, and shortened-mixed notation.  The IPv6
+       address may include a zone index, separated by a % sign.
+
+       The zone index is used to disambiguate identical address
+       values.  For link-local addresses, the zone index will
+       typically be the interface index number or the name of an
+       interface.  If the zone index is not present, the default
+       zone of the device will be used.
+
+       The canonical format of IPv6 addresses uses the compressed
+       format described in RFC 4291, Section 2.2, item 2 with the
+       following additional rules: the :: substitution must be
+       applied to the longest sequence of all-zero 16-bit chunks
+       in an IPv6 address.  If there is a tie, the first sequence
+       of all-zero 16-bit chunks is replaced by ::.  Single
+       all-zero 16-bit chunks are not compressed.  The canonical
+       format uses lowercase characters and leading zeros are
+       not allowed.  The canonical format for the zone index is
+       the numerical format as described in RFC 4007, Section
+       11.2.";
+     reference
+      "RFC 4291: IP Version 6 Addressing Architecture
+       RFC 4007: IPv6 Scoped Address Architecture
+       RFC 5952: A Recommendation for IPv6 Address Text Representation";
+   }
+
+   typedef ip-prefix {
+     type union {
+       type inet:ipv4-prefix;
+       type inet:ipv6-prefix;
+     }
+     description
+      "The ip-prefix type represents an IP prefix and is IP
+       version neutral.  The format of the textual representations
+       implies the IP version.";
+   }
+
+   typedef ipv4-prefix {
+     type string {
+       pattern
+          '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
+        +  '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
+        + '/(([0-9])|([1-2][0-9])|(3[0-2]))';
+     }
+     description
+      "The ipv4-prefix type represents an IPv4 address prefix.
+       The prefix length is given by the number following the
+       slash character and must be less than or equal to 32.
+
+       A prefix length value of n corresponds to an IP address
+       mask that has n contiguous 1-bits from the most
+       significant bit (MSB) and all other bits set to 0.
+
+       The canonical format of an IPv4 prefix has all bits of
+       the IPv4 address set to zero that are not part of the
+       IPv4 prefix.";
+   }
+
+   typedef ipv6-prefix {
+     type string {
+       pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}'
+             + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|'
+             + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
+             + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
+             + '(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))';
+       pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
+             + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
+             + '(/.+)';
+     }
+     description
+      "The ipv6-prefix type represents an IPv6 address prefix.
+       The prefix length is given by the number following the
+       slash character and must be less than or equal 128.
+
+       A prefix length value of n corresponds to an IP address
+       mask that has n contiguous 1-bits from the most
+       significant bit (MSB) and all other bits set to 0.
+
+       The IPv6 address should have all bits that do not belong
+       to the prefix set to zero.
+
+       The canonical format of an IPv6 prefix has all bits of
+       the IPv6 address set to zero that are not part of the
+       IPv6 prefix.  Furthermore, IPv6 address is represented
+       in the compressed format described in RFC 4291, Section
+       2.2, item 2 with the following additional rules: the ::
+       substitution must be applied to the longest sequence of
+       all-zero 16-bit chunks in an IPv6 address.  If there is
+       a tie, the first sequence of all-zero 16-bit chunks is
+       replaced by ::.  Single all-zero 16-bit chunks are not
+       compressed.  The canonical format uses lowercase
+       characters and leading zeros are not allowed.";
+     reference
+      "RFC 4291: IP Version 6 Addressing Architecture";
+   }
+
+   /*** collection of domain name and URI types ***/
+
+   typedef domain-name {
+     type string {
+       pattern '((([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.)*'
+            +  '([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.?)'
+            +  '|\.';
+       length "1..253";
+     }
+     description
+      "The domain-name type represents a DNS domain name.  The
+       name SHOULD be fully qualified whenever possible.
+
+       Internet domain names are only loosely specified.  Section
+       3.5 of RFC 1034 recommends a syntax (modified in Section
+       2.1 of RFC 1123).  The pattern above is intended to allow
+       for current practice in domain name use, and some possible
+       future expansion.  It is designed to hold various types of
+       domain names, including names used for A or AAAA records
+       (host names) and other records, such as SRV records.  Note
+       that Internet host names have a stricter syntax (described
+       in RFC 952) than the DNS recommendations in RFCs 1034 and
+       1123, and that systems that want to store host names in
+       schema nodes using the domain-name type are recommended to
+       adhere to this stricter standard to ensure interoperability.
+
+       The encoding of DNS names in the DNS protocol is limited
+       to 255 characters.  Since the encoding consists of labels
+       prefixed by a length bytes and there is a trailing NULL
+       byte, only 253 characters can appear in the textual dotted
+       notation.
+
+       The description clause of schema nodes using the domain-name
+       type MUST describe when and how these names are resolved to
+       IP addresses.  Note that the resolution of a domain-name value
+       may require to query multiple DNS records (e.g., A for IPv4
+       and AAAA for IPv6).  The order of the resolution process and
+       which DNS record takes precedence can either be defined
+       explicitely or it may depend on the configuration of the
+       resolver.
+
+       Domain-name values use the US-ASCII encoding.  Their canonical
+       format uses lowercase US-ASCII characters.  Internationalized
+       domain names MUST be encoded in punycode as described in RFC
+       3492";
+     reference
+      "RFC  952: DoD Internet Host Table Specification
+       RFC 1034: Domain Names - Concepts and Facilities
+       RFC 1123: Requirements for Internet Hosts -- Application
+                 and Support
+       RFC 2782: A DNS RR for specifying the location of services
+                 (DNS SRV)
+       RFC 3492: Punycode: A Bootstring encoding of Unicode for
+                 Internationalized Domain Names in Applications
+                 (IDNA)
+       RFC 5891: Internationalizing Domain Names in Applications
+                 (IDNA): Protocol";
+   }
+
+   typedef host {
+     type union {
+       type inet:ip-address;
+       type inet:domain-name;
+     }
+     description
+      "The host type represents either an IP address or a DNS
+       domain name.";
+   }
+
+   typedef uri {
+     type string;
+     description
+      "The uri type represents a Uniform Resource Identifier
+       (URI) as defined by STD 66.
+
+       Objects using the uri type MUST be in US-ASCII encoding,
+       and MUST be normalized as described by RFC 3986 Sections
+       6.2.1, 6.2.2.1, and 6.2.2.2.  All unnecessary
+       percent-encoding is removed, and all case-insensitive
+       characters are set to lowercase except for hexadecimal
+       digits, which are normalized to uppercase as described in
+       Section 6.2.2.1.
+
+       The purpose of this normalization is to help provide
+       unique URIs.  Note that this normalization is not
+       sufficient to provide uniqueness.  Two URIs that are
+       textually distinct after this normalization may still be
+       equivalent.
+
+       Objects using the uri type may restrict the schemes that
+       they permit.  For example, 'data:' and 'urn:' schemes
+       might not be appropriate.
+
+       A zero-length URI is not a valid URI.  This can be used to
+       express 'URI absent' where required.
+
+       In the value set and its semantics, this type is equivalent
+       to the Uri SMIv2 textual convention defined in RFC 5017.";
+     reference
+      "RFC 3986: Uniform Resource Identifier (URI): Generic Syntax
+       RFC 3305: Report from the Joint W3C/IETF URI Planning Interest
+                 Group: Uniform Resource Identifiers (URIs), URLs,
+                 and Uniform Resource Names (URNs): Clarifications
+                 and Recommendations
+       RFC 5017: MIB Textual Conventions for Uniform Resource
+                 Identifiers (URIs)";
+   }
+
+ }
\ No newline at end of file
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/union-test-models/abstract-topology.yang b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/union-test-models/abstract-topology.yang
new file mode 100644 (file)
index 0000000..a4b589b
--- /dev/null
@@ -0,0 +1,120 @@
+module abstract-topology {
+    yang-version 1;
+    namespace "urn:model:abstract:topology";
+    prefix "tp";
+
+    import ietf-inet-types { 
+        prefix "inet"; 
+        revision-date 2010-09-24;
+    }
+
+    organization "OPEN DAYLIGHT";
+    contact "http://www.opendaylight.org/";
+
+    description
+        "This module contains the definitions of elements that creates network 
+    topology i.e. definition of network nodes and links. This module is not designed to be used solely for network representation. This module SHOULD be used as base module in defining the network topology.";
+
+    revision "2013-02-08" {
+        reference "~~~ WILL BE DEFINED LATER";
+    }
+    
+    revision "2013-01-01" {
+        reference "~~~ WILL BE DEFINED LATER";
+    }
+
+    typedef union-enum {
+        type union {
+            type int32;
+            type enumeration {
+                enum "unbounded";
+            }
+        }
+    }
+
+    typedef link-address {
+        type union {
+            type inet:ip-address;
+            type string;
+        }
+    }
+
+    typedef node-id-ref {
+        type leafref {
+            path "/tp:topology/tp:network-nodes/tp:network-node/tp:node-id";
+        }
+        description "This type is used for leafs that reference network node instance.";
+    }
+
+    typedef link-id-ref {
+        type leafref {
+            path "/tp:topology/tp:network-links/tp:network-link/tp:link-id";
+        }
+        description "This type is used for leafs that reference network link instance.";
+    }
+
+    container 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.";
+
+        leaf topology-id {
+            type inet:uri;
+            description "It is presumed that datastore will contain many topologies. To distinguish between topologies it is vital to have
+            UNIQUE topology identifier.";
+        }
+
+        container network-nodes {
+            list network-node {
+                key "node-id";
+
+                leaf node-id {
+                    type inet:uri;
+                    description "The Topology identifier of network-node.";
+                }
+
+                leaf bounding {
+                    type union-enum;
+                }
+
+                container attributes {
+                    description "Aditional attributes that can Network Node contains.";
+                }
+                description "The list of network nodes defined for topology.";
+            }
+        }
+        
+        container network-links {
+            list network-link {
+                key "link-id";
+
+                leaf link-id {
+                    type inet:uri;
+                    description "";
+                }
+
+                leaf link-address {
+                    type link-address;
+                }
+
+                container source-node {
+                    leaf id {
+                        type node-id-ref;
+                        description "Source node identifier.";
+                    }
+                }
+
+                container destination-node {
+                    leaf id {
+                        type node-id-ref;
+                        description "Destination node identifier.";
+                    }
+                }
+
+                container attributes {
+                    description "Aditional attributes that can Network Link contains.";
+                }
+                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.";
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/union-test-models/ietf-inet-types@2010-09-24.yang b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/union-test-models/ietf-inet-types@2010-09-24.yang
new file mode 100644 (file)
index 0000000..6a6c748
--- /dev/null
@@ -0,0 +1,418 @@
+ module ietf-inet-types {
+
+   namespace "urn:ietf:params:xml:ns:yang:ietf-inet-types";
+   prefix "inet";
+
+   organization
+    "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+
+   contact
+    "WG Web:   <http://tools.ietf.org/wg/netmod/>
+     WG List:  <mailto:netmod@ietf.org>
+
+     WG Chair: David Partain
+               <mailto:david.partain@ericsson.com>
+
+     WG Chair: David Kessens
+               <mailto:david.kessens@nsn.com>
+
+     Editor:   Juergen Schoenwaelder
+               <mailto:j.schoenwaelder@jacobs-university.de>";
+
+   description
+    "This module contains a collection of generally useful derived
+     YANG data types for Internet addresses and related things.
+
+     Copyright (c) 2010 IETF Trust and the persons identified as
+     authors of the code.  All rights reserved.
+
+     Redistribution and use in source and binary forms, with or without
+     modification, is permitted pursuant to, and subject to the license
+     terms contained in, the Simplified BSD License set forth in Section
+     4.c of the IETF Trust's Legal Provisions Relating to IETF Documents
+     (http://trustee.ietf.org/license-info).
+
+     This version of this YANG module is part of RFC 6021; see
+     the RFC itself for full legal notices.";
+
+   revision 2010-09-24 {
+     description
+      "Initial revision.";
+     reference
+      "RFC 6021: Common YANG Data Types";
+   }
+
+   /*** collection of protocol field related types ***/
+
+   typedef ip-version {
+     type enumeration {
+       enum unknown {
+         value "0";
+         description
+          "An unknown or unspecified version of the Internet protocol.";
+       }
+       enum ipv4 {
+         value "1";
+         description
+          "The IPv4 protocol as defined in RFC 791.";
+       }
+       enum ipv6 {
+         value "2";
+         description
+          "The IPv6 protocol as defined in RFC 2460.";
+       }
+     }
+     description
+      "This value represents the version of the IP protocol.
+
+       In the value set and its semantics, this type is equivalent
+       to the InetVersion textual convention of the SMIv2.";
+     reference
+      "RFC  791: Internet Protocol
+       RFC 2460: Internet Protocol, Version 6 (IPv6) Specification
+       RFC 4001: Textual Conventions for Internet Network Addresses";
+   }
+
+   typedef dscp {
+     type uint8 {
+       range "0..63";
+     }
+     description
+      "The dscp type represents a Differentiated Services Code-Point
+       that may be used for marking packets in a traffic stream.
+
+       In the value set and its semantics, this type is equivalent
+       to the Dscp textual convention of the SMIv2.";
+     reference
+      "RFC 3289: Management Information Base for the Differentiated
+                 Services Architecture
+       RFC 2474: Definition of the Differentiated Services Field
+                 (DS Field) in the IPv4 and IPv6 Headers
+       RFC 2780: IANA Allocation Guidelines For Values In
+                 the Internet Protocol and Related Headers";
+   }
+
+   typedef ipv6-flow-label {
+     type uint32 {
+       range "0..1048575";
+     }
+     description
+      "The flow-label type represents flow identifier or Flow Label
+       in an IPv6 packet header that may be used to discriminate
+       traffic flows.
+
+       In the value set and its semantics, this type is equivalent
+       to the IPv6FlowLabel textual convention of the SMIv2.";
+     reference
+      "RFC 3595: Textual Conventions for IPv6 Flow Label
+       RFC 2460: Internet Protocol, Version 6 (IPv6) Specification";
+   }
+
+   typedef port-number {
+     type uint16 {
+       range "0..65535";
+     }
+     description
+      "The port-number type represents a 16-bit port number of an
+       Internet transport layer protocol such as UDP, TCP, DCCP, or
+       SCTP.  Port numbers are assigned by IANA.  A current list of
+       all assignments is available from <http://www.iana.org/>.
+
+       Note that the port number value zero is reserved by IANA.  In
+       situations where the value zero does not make sense, it can
+       be excluded by subtyping the port-number type.
+
+       In the value set and its semantics, this type is equivalent
+       to the InetPortNumber textual convention of the SMIv2.";
+     reference
+      "RFC  768: User Datagram Protocol
+       RFC  793: Transmission Control Protocol
+       RFC 4960: Stream Control Transmission Protocol
+       RFC 4340: Datagram Congestion Control Protocol (DCCP)
+       RFC 4001: Textual Conventions for Internet Network Addresses";
+   }
+
+   /*** collection of autonomous system related types ***/
+
+   typedef as-number {
+     type uint32;
+     description
+      "The as-number type represents autonomous system numbers
+       which identify an Autonomous System (AS).  An AS is a set
+       of routers under a single technical administration, using
+       an interior gateway protocol and common metrics to route
+       packets within the AS, and using an exterior gateway
+       protocol to route packets to other ASs'.  IANA maintains
+       the AS number space and has delegated large parts to the
+       regional registries.
+
+       Autonomous system numbers were originally limited to 16
+       bits.  BGP extensions have enlarged the autonomous system
+       number space to 32 bits.  This type therefore uses an uint32
+       base type without a range restriction in order to support
+       a larger autonomous system number space.
+
+       In the value set and its semantics, this type is equivalent
+       to the InetAutonomousSystemNumber textual convention of
+       the SMIv2.";
+     reference
+      "RFC 1930: Guidelines for creation, selection, and registration
+                 of an Autonomous System (AS)
+       RFC 4271: A Border Gateway Protocol 4 (BGP-4)
+       RFC 4893: BGP Support for Four-octet AS Number Space
+       RFC 4001: Textual Conventions for Internet Network Addresses";
+   }
+
+   /*** collection of IP address and hostname related types ***/
+
+   typedef ip-address {
+     type union {
+       type inet:ipv4-address;
+       type inet:ipv6-address;
+     }
+     description
+      "The ip-address type represents an IP address and is IP
+       version neutral.  The format of the textual representations
+       implies the IP version.";
+   }
+
+   typedef ipv4-address {
+     type string {
+       pattern
+         '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
+       +  '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
+       + '(%[\p{N}\p{L}]+)?';
+     }
+     description
+       "The ipv4-address type represents an IPv4 address in
+        dotted-quad notation.  The IPv4 address may include a zone
+        index, separated by a % sign.
+
+        The zone index is used to disambiguate identical address
+        values.  For link-local addresses, the zone index will
+        typically be the interface index number or the name of an
+        interface.  If the zone index is not present, the default
+        zone of the device will be used.
+
+        The canonical format for the zone index is the numerical
+        format";
+   }
+
+   typedef ipv6-address {
+     type string {
+       pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}'
+             + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|'
+             + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
+             + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
+             + '(%[\p{N}\p{L}]+)?';
+       pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
+             + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
+             + '(%.+)?';
+     }
+     description
+      "The ipv6-address type represents an IPv6 address in full,
+       mixed, shortened, and shortened-mixed notation.  The IPv6
+       address may include a zone index, separated by a % sign.
+
+       The zone index is used to disambiguate identical address
+       values.  For link-local addresses, the zone index will
+       typically be the interface index number or the name of an
+       interface.  If the zone index is not present, the default
+       zone of the device will be used.
+
+       The canonical format of IPv6 addresses uses the compressed
+       format described in RFC 4291, Section 2.2, item 2 with the
+       following additional rules: the :: substitution must be
+       applied to the longest sequence of all-zero 16-bit chunks
+       in an IPv6 address.  If there is a tie, the first sequence
+       of all-zero 16-bit chunks is replaced by ::.  Single
+       all-zero 16-bit chunks are not compressed.  The canonical
+       format uses lowercase characters and leading zeros are
+       not allowed.  The canonical format for the zone index is
+       the numerical format as described in RFC 4007, Section
+       11.2.";
+     reference
+      "RFC 4291: IP Version 6 Addressing Architecture
+       RFC 4007: IPv6 Scoped Address Architecture
+       RFC 5952: A Recommendation for IPv6 Address Text Representation";
+   }
+
+   typedef ip-prefix {
+     type union {
+       type inet:ipv4-prefix;
+       type inet:ipv6-prefix;
+     }
+     description
+      "The ip-prefix type represents an IP prefix and is IP
+       version neutral.  The format of the textual representations
+       implies the IP version.";
+   }
+
+   typedef ipv4-prefix {
+     type string {
+       pattern
+          '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
+        +  '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
+        + '/(([0-9])|([1-2][0-9])|(3[0-2]))';
+     }
+     description
+      "The ipv4-prefix type represents an IPv4 address prefix.
+       The prefix length is given by the number following the
+       slash character and must be less than or equal to 32.
+
+       A prefix length value of n corresponds to an IP address
+       mask that has n contiguous 1-bits from the most
+       significant bit (MSB) and all other bits set to 0.
+
+       The canonical format of an IPv4 prefix has all bits of
+       the IPv4 address set to zero that are not part of the
+       IPv4 prefix.";
+   }
+
+   typedef ipv6-prefix {
+     type string {
+       pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}'
+             + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|'
+             + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
+             + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
+             + '(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))';
+       pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
+             + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
+             + '(/.+)';
+     }
+     description
+      "The ipv6-prefix type represents an IPv6 address prefix.
+       The prefix length is given by the number following the
+       slash character and must be less than or equal 128.
+
+       A prefix length value of n corresponds to an IP address
+       mask that has n contiguous 1-bits from the most
+       significant bit (MSB) and all other bits set to 0.
+
+       The IPv6 address should have all bits that do not belong
+       to the prefix set to zero.
+
+       The canonical format of an IPv6 prefix has all bits of
+       the IPv6 address set to zero that are not part of the
+       IPv6 prefix.  Furthermore, IPv6 address is represented
+       in the compressed format described in RFC 4291, Section
+       2.2, item 2 with the following additional rules: the ::
+       substitution must be applied to the longest sequence of
+       all-zero 16-bit chunks in an IPv6 address.  If there is
+       a tie, the first sequence of all-zero 16-bit chunks is
+       replaced by ::.  Single all-zero 16-bit chunks are not
+       compressed.  The canonical format uses lowercase
+       characters and leading zeros are not allowed.";
+     reference
+      "RFC 4291: IP Version 6 Addressing Architecture";
+   }
+
+   /*** collection of domain name and URI types ***/
+
+   typedef domain-name {
+     type string {
+       pattern '((([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.)*'
+            +  '([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.?)'
+            +  '|\.';
+       length "1..253";
+     }
+     description
+      "The domain-name type represents a DNS domain name.  The
+       name SHOULD be fully qualified whenever possible.
+
+       Internet domain names are only loosely specified.  Section
+       3.5 of RFC 1034 recommends a syntax (modified in Section
+       2.1 of RFC 1123).  The pattern above is intended to allow
+       for current practice in domain name use, and some possible
+       future expansion.  It is designed to hold various types of
+       domain names, including names used for A or AAAA records
+       (host names) and other records, such as SRV records.  Note
+       that Internet host names have a stricter syntax (described
+       in RFC 952) than the DNS recommendations in RFCs 1034 and
+       1123, and that systems that want to store host names in
+       schema nodes using the domain-name type are recommended to
+       adhere to this stricter standard to ensure interoperability.
+
+       The encoding of DNS names in the DNS protocol is limited
+       to 255 characters.  Since the encoding consists of labels
+       prefixed by a length bytes and there is a trailing NULL
+       byte, only 253 characters can appear in the textual dotted
+       notation.
+
+       The description clause of schema nodes using the domain-name
+       type MUST describe when and how these names are resolved to
+       IP addresses.  Note that the resolution of a domain-name value
+       may require to query multiple DNS records (e.g., A for IPv4
+       and AAAA for IPv6).  The order of the resolution process and
+       which DNS record takes precedence can either be defined
+       explicitely or it may depend on the configuration of the
+       resolver.
+
+       Domain-name values use the US-ASCII encoding.  Their canonical
+       format uses lowercase US-ASCII characters.  Internationalized
+       domain names MUST be encoded in punycode as described in RFC
+       3492";
+     reference
+      "RFC  952: DoD Internet Host Table Specification
+       RFC 1034: Domain Names - Concepts and Facilities
+       RFC 1123: Requirements for Internet Hosts -- Application
+                 and Support
+       RFC 2782: A DNS RR for specifying the location of services
+                 (DNS SRV)
+       RFC 3492: Punycode: A Bootstring encoding of Unicode for
+                 Internationalized Domain Names in Applications
+                 (IDNA)
+       RFC 5891: Internationalizing Domain Names in Applications
+                 (IDNA): Protocol";
+   }
+
+   typedef host {
+     type union {
+       type inet:ip-address;
+       type inet:domain-name;
+     }
+     description
+      "The host type represents either an IP address or a DNS
+       domain name.";
+   }
+
+   typedef uri {
+     type string;
+     description
+      "The uri type represents a Uniform Resource Identifier
+       (URI) as defined by STD 66.
+
+       Objects using the uri type MUST be in US-ASCII encoding,
+       and MUST be normalized as described by RFC 3986 Sections
+       6.2.1, 6.2.2.1, and 6.2.2.2.  All unnecessary
+       percent-encoding is removed, and all case-insensitive
+       characters are set to lowercase except for hexadecimal
+       digits, which are normalized to uppercase as described in
+       Section 6.2.2.1.
+
+       The purpose of this normalization is to help provide
+       unique URIs.  Note that this normalization is not
+       sufficient to provide uniqueness.  Two URIs that are
+       textually distinct after this normalization may still be
+       equivalent.
+
+       Objects using the uri type may restrict the schemes that
+       they permit.  For example, 'data:' and 'urn:' schemes
+       might not be appropriate.
+
+       A zero-length URI is not a valid URI.  This can be used to
+       express 'URI absent' where required.
+
+       In the value set and its semantics, this type is equivalent
+       to the Uri SMIv2 textual convention defined in RFC 5017.";
+     reference
+      "RFC 3986: Uniform Resource Identifier (URI): Generic Syntax
+       RFC 3305: Report from the Joint W3C/IETF URI Planning Interest
+                 Group: Uniform Resource Identifiers (URIs), URLs,
+                 and Uniform Resource Names (URNs): Clarifications
+                 and Recommendations
+       RFC 5017: MIB Textual Conventions for Uniform Resource
+                 Identifiers (URIs)";
+   }
+
+ }
\ No newline at end of file
index 1fb8622..ef65a0e 100644 (file)
@@ -3,11 +3,14 @@ package org.opendaylight.controller.binding.generator.util;
 import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
 import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTOBuilder;
 import org.opendaylight.controller.yang.common.QName;
-import org.opendaylight.controller.yang.model.api.*;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.SchemaNode;
+import org.opendaylight.controller.yang.model.api.SchemaPath;
+import org.opendaylight.controller.yang.model.api.TypeDefinition;
 
 import java.util.*;
 
-public class BindingGeneratorUtil {
+public final class BindingGeneratorUtil {
 
     private static final String[] SET_VALUES = new String[]{"abstract",
             "assert", "boolean", "break", "byte", "case", "catch", "char",
@@ -19,7 +22,8 @@ public class BindingGeneratorUtil {
             "super", "switch", "synchronized", "this", "throw", "throws",
             "transient", "true", "try", "void", "volatile", "while"};
 
-    private BindingGeneratorUtil() {}
+    private BindingGeneratorUtil() {
+    }
 
     public static final Set<String> JAVA_RESERVED_WORDS = new HashSet<String>(
             Arrays.asList(SET_VALUES));
@@ -110,22 +114,43 @@ public class BindingGeneratorUtil {
 
     public static String packageNameForGeneratedType(
             final String basePackageName, final SchemaPath schemaPath) {
+        if (basePackageName == null) {
+            throw new IllegalArgumentException("Base Package Name cannot be " +
+                    "NULL!");
+        }
+        if (schemaPath == null) {
+            throw new IllegalArgumentException("Schema Path cannot be NULL!");
+        }
+
         final StringBuilder builder = new StringBuilder();
         builder.append(basePackageName);
-        if ((schemaPath != null) && (schemaPath.getPath() != null)) {
-            final List<QName> pathToNode = schemaPath.getPath();
-            final int traversalSteps = (pathToNode.size() - 1);
-            for (int i = 0; i < traversalSteps; ++i) {
-                builder.append(".");
-                String nodeLocalName = pathToNode.get(i).getLocalName();
-
-                nodeLocalName = nodeLocalName.replace(":", ".");
-                nodeLocalName = nodeLocalName.replace("-", ".");
-                builder.append(nodeLocalName);
-            }
-            return validateJavaPackage(builder.toString());
+        final List<QName> pathToNode = schemaPath.getPath();
+        final int traversalSteps = (pathToNode.size() - 1);
+        for (int i = 0; i < traversalSteps; ++i) {
+            builder.append(".");
+            String nodeLocalName = pathToNode.get(i).getLocalName();
+
+            nodeLocalName = nodeLocalName.replace(":", ".");
+            nodeLocalName = nodeLocalName.replace("-", ".");
+            builder.append(nodeLocalName);
         }
-        return null;
+        return validateJavaPackage(builder.toString());
+    }
+
+    public static String packageNameForTypeDefinition(
+            final String basePackageName, final TypeDefinition<?> typeDefinition) {
+        if (basePackageName == null) {
+            throw new IllegalArgumentException("Base Package Name cannot be " +
+                    "NULL!");
+        }
+        if (typeDefinition == null) {
+            throw new IllegalArgumentException("Type Definition reference " +
+                    "cannot be NULL!");
+        }
+
+        final StringBuilder builder = new StringBuilder();
+        builder.append(basePackageName);
+        return validateJavaPackage(builder.toString());
     }
 
     public static String parseToClassName(String token) {
index 87bb47c..2966246 100644 (file)
@@ -18,7 +18,7 @@ import org.opendaylight.controller.yang.binding.Augmentable;
 import org.opendaylight.controller.yang.binding.Augmentation;\r
 import org.opendaylight.controller.yang.binding.DataObject;\r
 \r
-public class Types {\r
+public final class Types {\r
     private static final Type SET_TYPE = typeForClass(Set.class);\r
     private static final Type LIST_TYPE = typeForClass(List.class);\r
     private static final Type MAP_TYPE = typeForClass(Map.class);\r
index 01d9bbf..558fb43 100644 (file)
@@ -101,7 +101,8 @@ public final class GeneratedTOBuilderImpl implements GeneratedTOBuilder {
     
     @Override
     public EnumBuilder addEnumeration(String name) {
-        final EnumBuilder builder = new EnumerationBuilderImpl(packageName,
+        final String innerPackageName = packageName + "." + this.name;
+        final EnumBuilder builder = new EnumerationBuilderImpl(innerPackageName,
                 name);
         enumerations.add(builder);
         return builder;
index 942174f..0dcaa71 100644 (file)
@@ -17,11 +17,12 @@ import java.util.List;
 import java.util.Map;
 
 import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;
+import org.opendaylight.controller.sal.binding.model.api.Enumeration;
 import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
 import org.opendaylight.controller.sal.binding.model.api.Type;
 
-public class ClassCodeGenerator implements CodeGenerator {
+public final class ClassCodeGenerator implements CodeGenerator {
 
     private Map<String, LinkedHashMap<String, Integer>> imports;
 
@@ -29,11 +30,12 @@ public class ClassCodeGenerator implements CodeGenerator {
     public Writer generate(Type type) throws IOException {
         final Writer writer = new StringWriter();
         if (type instanceof GeneratedTransferObject) {
-            GeneratedTransferObject genTO = (GeneratedTransferObject) type;
+            GeneratedTransferObject genTO = (GeneratedTransferObject) type;            
             imports = GeneratorUtil.createImports(genTO);
-
+            
             final String currentPkg = genTO.getPackageName();
             final List<GeneratedProperty> fields = genTO.getProperties();
+            final List<Enumeration> enums = genTO.getEnumDefintions();
 
             writer.write(GeneratorUtil.createPackageDeclaration(currentPkg));
             writer.write(NL);
@@ -48,6 +50,14 @@ public class ClassCodeGenerator implements CodeGenerator {
                     imports));
             writer.write(NL);
             writer.write(NL);
+            
+            if (enums != null) {           
+                       EnumGenerator enumGenerator = new EnumGenerator();
+               for ( Enumeration e : enums ) {                         
+                       writer.write(enumGenerator.generateInnerEnumeration(e, TAB).toString());
+                       writer.write(NL);
+               }
+            }
 
             if (fields != null) {
                 for (GeneratedProperty field : fields) {
index fbbd54e..bd94c20 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.controller.sal.java.api.generator;
 
-public class Constants {
+final class Constants {
 
     public static final String IFC = "interface";
     public static final String CLASS = "class";
@@ -32,4 +32,9 @@ public class Constants {
     public static final String FINAL = "final";
     public static final String EXTENDS = "extends";
     public static final String IMPLEMENTS = "implements";
+    
+    public static final String ENUMERATION_NAME = "value";
+    public static final String ENUMERATION_TYPE = "int";       
+    
+    private Constants() {}
 }
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/EnumGenerator.java b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/EnumGenerator.java
new file mode 100644 (file)
index 0000000..33d2917
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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.controller.sal.java.api.generator;
+
+import static org.opendaylight.controller.sal.java.api.generator.Constants.*;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;
+import org.opendaylight.controller.sal.binding.model.api.Enumeration;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+
+public class EnumGenerator implements CodeGenerator {
+
+       @Override
+       public Writer generate(Type type) throws IOException {
+               final Writer writer = new StringWriter();
+
+               if (type instanceof Enumeration) {
+                       Enumeration enums = (Enumeration) type;
+                       writer.write(GeneratorUtil.createPackageDeclaration(enums
+                                       .getPackageName()));
+                       writer.write(NL + NL);
+                       writer.write(GeneratorUtil.createEnum(enums, ""));
+               }
+
+               return writer;
+       }
+
+       public Writer generateInnerEnumeration(Type type, String indent) throws IOException {
+               final Writer writer = new StringWriter();
+
+               if (type instanceof Enumeration) {
+                       Enumeration enums = (Enumeration) type;
+                       writer.write(GeneratorUtil.createEnum(enums, indent));
+               }
+
+               return writer;
+       }
+
+}
index a0db8c7..ab103b4 100644 (file)
@@ -18,35 +18,45 @@ import java.util.List;
 import java.util.Set;
 
 import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;
+import org.opendaylight.controller.sal.binding.model.api.Enumeration;
 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
 import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
 import org.opendaylight.controller.sal.binding.model.api.Type;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class GeneratorJavaFile {
+public final class GeneratorJavaFile {
 
     private static final Logger log = LoggerFactory
             .getLogger(GeneratorJavaFile.class);
     private final CodeGenerator interfaceGenerator;
     private final ClassCodeGenerator classGenerator;
+    private final EnumGenerator enumGenerator;
+    
     private final Set<GeneratedType> genTypes;
     private final Set<GeneratedTransferObject> genTransferObjects;
+    private final Set<Enumeration> enumerations; 
 
     public GeneratorJavaFile(final CodeGenerator codeGenerator,
             final Set<GeneratedType> types) {
         this.interfaceGenerator = codeGenerator;
         this.genTypes = types;
         this.genTransferObjects = new HashSet<>();
-        classGenerator = new ClassCodeGenerator();
+        this.enumerations = new HashSet<>();
+        this.classGenerator = new ClassCodeGenerator();
+        this.enumGenerator = new EnumGenerator();
     }
 
     public GeneratorJavaFile(final Set<GeneratedType> types,
-            final Set<GeneratedTransferObject> genTransferObjects) {
+            final Set<GeneratedTransferObject> genTransferObjects,
+            final Set<Enumeration> enumerations) {
         this.interfaceGenerator = new InterfaceGenerator();
         this.classGenerator = new ClassCodeGenerator();
+        this.enumGenerator = new EnumGenerator();
+        
         this.genTypes = types;
         this.genTransferObjects = genTransferObjects;
+        this.enumerations = enumerations;
     }
 
     public List<File> generateToFile(final File parentDirectory) throws IOException {
@@ -67,6 +77,16 @@ public class GeneratorJavaFile {
                 result.add(genFile);
             }
         }
+        
+        for (Enumeration enumeration : enumerations) {
+            final File genFile = generateTypeToJavaFile(parentDirectory,
+                    enumeration, enumGenerator);
+
+            if (genFile != null) {
+                result.add(genFile);
+            }
+        }
+        
         return result;
     }
 
index b85e2b0..a059c13 100644 (file)
@@ -27,646 +27,663 @@ import org.opendaylight.controller.sal.binding.model.api.MethodSignature.Paramet
 import org.opendaylight.controller.sal.binding.model.api.ParameterizedType;
 import org.opendaylight.controller.sal.binding.model.api.Type;
 
-public class GeneratorUtil {
-
-    private GeneratorUtil() {
-    }
-
-    public static String createIfcDeclaration(final GeneratedType genType,
-            final String indent,
-            final Map<String, LinkedHashMap<String, Integer>> availableImports) {
-        return createFileDeclaration(IFC, genType, indent, availableImports);
-    }
-
-    public static String createClassDeclaration(
-            final GeneratedTransferObject genTransferObject,
-            final String indent,
-            final Map<String, LinkedHashMap<String, Integer>> availableImports) {
-        return createFileDeclaration(CLASS, genTransferObject, indent,
-                availableImports);
-    }
-
-    public static String createPackageDeclaration(final String packageName) {
-        return PKG + GAP + packageName + SC;
-    }
-
-    private static String createFileDeclaration(final String type,
-            final GeneratedType genType, final String indent,
-            final Map<String, LinkedHashMap<String, Integer>> availableImports) {
-        final StringBuilder builder = new StringBuilder();
-        final String currentPkg = genType.getPackageName();
-
-        createComment(builder, genType.getComment(), indent);
-
-        if (!genType.getAnnotations().isEmpty()) {
-            final List<AnnotationType> annotations = genType.getAnnotations();
-            appendAnnotations(builder, annotations);
-            builder.append(NL);
-        }
-        builder.append(PUBLIC + GAP + type + GAP + genType.getName() + GAP);
-
-        if (genType instanceof GeneratedTransferObject) {
-            GeneratedTransferObject genTO = (GeneratedTransferObject) genType;
-
-            if (genTO.getExtends() != null) {
-                builder.append(EXTENDS + GAP);
-                builder.append(genTO.getExtends() + GAP);
-            }
-        }
-
-        final List<Type> genImplements = genType.getImplements();
-        if (!genImplements.isEmpty()) {
-            if (genType instanceof GeneratedTransferObject) {
-                builder.append(IMPLEMENTS + GAP);
-            } else {
-                builder.append(EXTENDS + GAP);
-            }
-            builder.append(getExplicitType(genImplements.get(0),
-                    availableImports, currentPkg));
-
-            for (int i = 1; i < genImplements.size(); ++i) {
-                builder.append(", ");
-                builder.append(getExplicitType(genImplements.get(i),
-                        availableImports, currentPkg));
-            }
-        }
-
-        builder.append(GAP + LCB);
-        return builder.toString();
-    }
-
-    private static StringBuilder appendAnnotations(final StringBuilder builder,
-            final List<AnnotationType> annotations) {
-        if ((builder != null) && (annotations != null)) {
-            for (final AnnotationType annotation : annotations) {
-                builder.append("@");
-                builder.append(annotation.getPackageName());
-                builder.append(".");
-                builder.append(annotation.getName());
-
-                if (annotation.containsParameters()) {
-                    builder.append("(");
-                    final List<AnnotationType.Parameter> parameters = annotation
-                            .getParameters();
-                    appendAnnotationParams(builder, parameters);
-                    builder.append(")");
-                }
-            }
-        }
-        return builder;
-    }
-
-    private static StringBuilder appendAnnotationParams(
-            final StringBuilder builder,
-            final List<AnnotationType.Parameter> parameters) {
-        if (parameters != null) {
-            int i = 0;
-            for (final AnnotationType.Parameter param : parameters) {
-                if (param == null) {
-                    continue;
-                }
-                if (i > 0) {
-                    builder.append(", ");
-                }
-                final String paramName = param.getName();
-                if (param.getValue() != null) {
-                    builder.append(paramName);
-                    builder.append(" = ");
-                    builder.append(param.getValue());
-                } else {
-                    builder.append(paramName);
-                    builder.append(" = {");
-                    final List<String> values = param.getValues();
-                    builder.append(values.get(0));
-                    for (int j = 1; j < values.size(); ++j) {
-                        builder.append(", ");
-                        builder.append(values.get(j));
-                    }
-                    builder.append("}");
-                }
-                i++;
-            }
-        }
-        return builder;
-    }
-
-    public static String createConstant(final Constant constant,
-            final String indent,
-            final Map<String, LinkedHashMap<String, Integer>> availableImports,
-            final String currentPkg) {
-        final StringBuilder builder = new StringBuilder();
-        builder.append(indent + PUBLIC + GAP + STATIC + GAP + FINAL + GAP);
-        builder.append(getExplicitType(constant.getType(), availableImports,
-                currentPkg) + GAP + constant.getName());
-        builder.append(GAP + "=" + GAP);
-        builder.append(constant.getValue() + SC);
-        return builder.toString();
-    }
-
-    public static String createField(final GeneratedProperty property,
-            final String indent,
-            Map<String, LinkedHashMap<String, Integer>> availableImports,
-            final String currentPkg) {
-        final StringBuilder builder = new StringBuilder();
-        builder.append(indent);
-        if (!property.getAnnotations().isEmpty()) {
-            final List<AnnotationType> annotations = property.getAnnotations();
-            appendAnnotations(builder, annotations);
-            builder.append(NL);
-        }
-        builder.append(indent + PRIVATE + GAP);
-        builder.append(getExplicitType(property.getReturnType(),
-                availableImports, currentPkg) + GAP + property.getName());
-        builder.append(SC);
-        return builder.toString();
-    }
-
-    /**
-     * Create method declaration in interface.
-     *
-     * @param method
-     * @param indent
-     * @return
-     */
-    public static String createMethodDeclaration(final MethodSignature method,
-            final String indent,
-            Map<String, LinkedHashMap<String, Integer>> availableImports,
-            final String currentPkg) {
-        final StringBuilder builder = new StringBuilder();
-
-        if (method == null) {
-            throw new IllegalArgumentException(
-                    "Method Signature parameter MUST be specified and cannot be NULL!");
-        }
-
-        final String comment = method.getComment();
-        final String name = method.getName();
-        if (name == null) {
-            throw new IllegalStateException("Method Name cannot be NULL!");
-        }
-
-        final Type type = method.getReturnType();
-        if (type == null) {
-            throw new IllegalStateException(
-                    "Method Return type cannot be NULL!");
-        }
-
-        final List<Parameter> parameters = method.getParameters();
-
-        createComment(builder, comment, indent);
-        builder.append(NL);
-        builder.append(indent);
-
-        if (!method.getAnnotations().isEmpty()) {
-            final List<AnnotationType> annotations = method.getAnnotations();
-            appendAnnotations(builder, annotations);
-            builder.append(NL);
-        }
-
-        builder.append(indent
-                + getExplicitType(type, availableImports, currentPkg) + GAP
-                + name);
-        builder.append(LB);
-        for (int i = 0; i < parameters.size(); i++) {
-            Parameter p = parameters.get(i);
-            String separator = COMMA;
-            if (i + 1 == parameters.size()) {
-                separator = "";
-            }
-            builder.append(getExplicitType(p.getType(), availableImports,
-                    currentPkg) + GAP + p.getName() + separator);
-        }
-        builder.append(RB);
-        builder.append(SC);
-
-        return builder.toString();
-    }
-
-    public static String createConstructor(
-            GeneratedTransferObject genTransferObject, final String indent,
-            Map<String, LinkedHashMap<String, Integer>> availableImports) {
-        final StringBuilder builder = new StringBuilder();
-
-        final String currentPkg = genTransferObject.getPackageName();
-        final List<GeneratedProperty> properties = genTransferObject
-                .getProperties();
-        final List<GeneratedProperty> ctorParams = new ArrayList<GeneratedProperty>();
-        for (final GeneratedProperty property : properties) {
-            if (property.isReadOnly()) {
-                ctorParams.add(property);
-            }
-        }
-
-        builder.append(indent);
-        builder.append(PUBLIC);
-        builder.append(GAP);
-        builder.append(genTransferObject.getName());
-        builder.append(LB);
-
-        if (!ctorParams.isEmpty()) {
-            builder.append(getExplicitType(ctorParams.get(0).getReturnType(),
-                    availableImports, currentPkg));
-            builder.append(" ");
-            builder.append(ctorParams.get(0).getName());
-            for (int i = 1; i < ctorParams.size(); ++i) {
-                final GeneratedProperty param = ctorParams.get(i);
-                builder.append(", ");
-                builder.append(getExplicitType(param.getReturnType(),
-                        availableImports, currentPkg));
-                builder.append(GAP);
-                builder.append(param.getName());
-            }
-        }
-        builder.append(RB + GAP + LCB + NL + indent + TAB + "super();" + NL);
-        if (!ctorParams.isEmpty()) {
-            for (final GeneratedProperty property : ctorParams) {
-                builder.append(indent);
-                builder.append(TAB);
-                builder.append("this.");
-                builder.append(property.getName());
-                builder.append(" = ");
-                builder.append(property.getName());
-                builder.append(SC);
-                builder.append(NL);
-            }
-        }
-        builder.append(indent);
-        builder.append(RCB);
-        return builder.toString();
-    }
-
-    public static String createGetter(final GeneratedProperty property,
-            final String indent,
-            Map<String, LinkedHashMap<String, Integer>> availableImports,
-            final String currentPkg) {
-        final StringBuilder builder = new StringBuilder();
-
-        final Type type = property.getReturnType();
-        final String varName = property.getName();
-        final char first = Character.toUpperCase(varName.charAt(0));
-        final String methodName = "get" + first + varName.substring(1);
-
-        builder.append(indent + PUBLIC + GAP
-                + getExplicitType(type, availableImports, currentPkg) + GAP
-                + methodName);
-        builder.append(LB + RB + LCB + NL);
-
-        String currentIndent = indent + TAB;
-
-        builder.append(currentIndent + "return " + varName + SC + NL);
-
-        builder.append(indent + RCB);
-        return builder.toString();
-    }
-
-    public static String createSetter(final GeneratedProperty property,
-            final String indent,
-            Map<String, LinkedHashMap<String, Integer>> availableImports,
-            String currentPkg) {
-        final StringBuilder builder = new StringBuilder();
-
-        final Type type = property.getReturnType();
-        final String varName = property.getName();
-        final char first = Character.toUpperCase(varName.charAt(0));
-        final String methodName = "set" + first + varName.substring(1);
-
-        builder.append(indent + PUBLIC + GAP + "void" + GAP + methodName);
-        builder.append(LB + getExplicitType(type, availableImports, currentPkg)
-                + GAP + varName + RB + LCB + NL);
-        String currentIndent = indent + TAB;
-        builder.append(currentIndent + "this." + varName + " = " + varName + SC
-                + NL);
-        builder.append(indent + RCB);
-        return builder.toString();
-    }
-
-    public static String createHashCode(
-            final List<GeneratedProperty> properties, final String indent) {
-        StringBuilder builder = new StringBuilder();
-        builder.append(indent + "public int hashCode() {" + NL);
-        builder.append(indent + TAB + "final int prime = 31;" + NL);
-        builder.append(indent + TAB + "int result = 1;" + NL);
-
-        for (GeneratedProperty property : properties) {
-            String fieldName = property.getName();
-            builder.append(indent + TAB + "result = prime * result + (("
-                    + fieldName + " == null) ? 0 : " + fieldName
-                    + ".hashCode());" + NL);
-        }
-
-        builder.append(indent + TAB + "return result;" + NL);
-        builder.append(indent + RCB + NL);
-        return builder.toString();
-    }
-
-    public static String createEquals(final GeneratedTransferObject type,
-            final List<GeneratedProperty> properties, final String indent) {
-        StringBuilder builder = new StringBuilder();
-        final String indent1 = indent + TAB;
-        final String indent2 = indent1 + TAB;
-        final String indent3 = indent2 + TAB;
-
-        builder.append(indent + "public boolean equals(Object obj) {" + NL);
-        builder.append(indent1 + "if (this == obj) {" + NL);
-        builder.append(indent2 + "return true;" + NL);
-        builder.append(indent1 + "}" + NL);
-        builder.append(indent1 + "if (obj == null) {" + NL);
-        builder.append(indent2 + "return false;" + NL);
-        builder.append(indent1 + "}" + NL);
-        builder.append(indent1 + "if (getClass() != obj.getClass()) {" + NL);
-        builder.append(indent2 + "return false;" + NL);
-        builder.append(indent1 + "}" + NL);
-
-        String typeStr = type.getName();
-        builder.append(indent1 + typeStr + " other = (" + typeStr + ") obj;"
-                + NL);
-
-        for (GeneratedProperty property : properties) {
-            String fieldName = property.getName();
-            builder.append(indent1 + "if (" + fieldName + " == null) {" + NL);
-            builder.append(indent2 + "if (other." + fieldName + " != null) {"
-                    + NL);
-            builder.append(indent3 + "return false;" + NL);
-            builder.append(indent2 + "}" + NL);
-            builder.append(indent1 + "} else if (!" + fieldName
-                    + ".equals(other." + fieldName + ")) {" + NL);
-            builder.append(indent2 + "return false;" + NL);
-            builder.append(indent1 + "}" + NL);
-        }
-
-        builder.append(indent1 + "return true;" + NL);
-
-        builder.append(indent + RCB + NL);
-        return builder.toString();
-    }
-
-    public static String createToString(final GeneratedTransferObject type,
-            final List<GeneratedProperty> properties, final String indent) {
-        StringBuilder builder = new StringBuilder();
-        builder.append(indent);
-        builder.append("public String toString() {");
-        builder.append(NL);
-        builder.append(indent);
-        builder.append(TAB);
-        builder.append("StringBuilder builder = new StringBuilder();");
-        builder.append(NL);
-        builder.append(indent);
-        builder.append(TAB);
-        builder.append("builder.append(\"");
-        builder.append(type.getName());
-        builder.append(" [");
-
-        boolean first = true;
-        for (GeneratedProperty property : properties) {
-            if (first) {
-                builder.append(property.getName());
-                builder.append("=\");");
-                builder.append(NL);
-                builder.append(indent);
-                builder.append(TAB);
-                builder.append("builder.append(");
-                builder.append(property.getName());
-                builder.append(");");
-                first = false;
-            } else {
-                builder.append(NL);
-                builder.append(indent);
-                builder.append(TAB);
-                builder.append("builder.append(\", ");
-                builder.append(property.getName());
-                builder.append("=\");");
-                builder.append(NL);
-                builder.append(indent);
-                builder.append(TAB);
-                builder.append("builder.append(\", ");
-                builder.append(property.getName());
-                builder.append(");");
-            }
-        }
-        builder.append(NL);
-        builder.append(indent);
-        builder.append(TAB);
-        builder.append("builder.append(\"]\");");
-        builder.append(NL);
-        builder.append(indent);
-        builder.append(TAB);
-        builder.append("return builder.toString();");
-
-        builder.append(NL);
-        builder.append(indent);
-        builder.append(RCB);
-        builder.append(NL);
-        return builder.toString();
-    }
-
-    public static String createEnum(final Enumeration enumeration,
-            final String indent) {
-        final StringBuilder builder = new StringBuilder(indent + ENUM + GAP
-                + enumeration.getName() + GAP + LCB + NL);
-
-        String separator = COMMA;
-        final List<Pair> values = enumeration.getValues();
-        builder.append(indent + TAB);
-        for (int i = 0; i < values.size(); i++) {
-            if (i + 1 == values.size()) {
-                separator = SC;
-            }
-            builder.append(values.get(i).getName() + separator);
-        }
-        builder.append(NL);
-        builder.append(indent + RCB);
-        return builder.toString();
-    }
-
-    private static String getExplicitType(final Type type,
-            Map<String, LinkedHashMap<String, Integer>> availableImports,
-            final String currentPkg) {
-        if (type == null) {
-            throw new IllegalArgumentException(
-                    "Type parameter MUST be specified and cannot be NULL!");
-        }
-        String packageName = type.getPackageName();
-
-        LinkedHashMap<String, Integer> imports = availableImports.get(type
-                .getName());
-
-        if ((imports != null && packageName
-                .equals(findMaxValue(imports).get(0)))
-                || packageName.equals(currentPkg)) {
-            final StringBuilder builder = new StringBuilder(type.getName());
-            if (type instanceof ParameterizedType) {
-                ParameterizedType pType = (ParameterizedType) type;
-                Type[] pTypes = pType.getActualTypeArguments();
-                builder.append("<");
-                builder.append(getParameters(pTypes, availableImports,
-                        currentPkg));
-                builder.append(">");
-            }
-            if (builder.toString().equals("Void")) {
-                return "void";
-            }
-         &