Example of openflowjava extension for nx_action_resubmit 08/8808/5
authorMichal Polkorab <michal.polkorab@pantheon.sk>
Tue, 8 Jul 2014 16:21:11 +0000 (18:21 +0200)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Mon, 21 Jul 2014 09:41:53 +0000 (11:41 +0200)
 - configuration file is located in src/main/resources - use this file to load / register this bundle
 - configuration file is exemplary - it registers the NX_ACTION_RESUBMIT into ofjava 6633 and 6653 instances
 - change contains 2 yang files:
   - nx-resubmit-action.yang - shows how to augment existing structures
   - openflow-nx-resubmit-action.yang - shows how to configure custom bundle
 - unit tests test if the structure is (de)serialized correctly

Change-Id: I6ed7226dba83f36deb100de88e5408ae32c060b2
Signed-off-by: Michal Polkorab <michal.polkorab@pantheon.sk>
13 files changed:
openflow-nx-resubmit-action/pom.xml [new file with mode: 0644]
openflow-nx-resubmit-action/src/main/java/org/opendaylight/openflowjava/protocol/nx/NxResubmitActionRegistrator.java [new file with mode: 0644]
openflow-nx-resubmit-action/src/main/java/org/opendaylight/openflowjava/protocol/nx/deserialization/NxActionResubmitDeserializer.java [new file with mode: 0644]
openflow-nx-resubmit-action/src/main/java/org/opendaylight/openflowjava/protocol/nx/serialization/NxActionResubmitSerializer.java [new file with mode: 0644]
openflow-nx-resubmit-action/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/nx/resubmit/action/rev140709/NxResubmitActionRegistratorModule.java [new file with mode: 0644]
openflow-nx-resubmit-action/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/nx/resubmit/action/rev140709/NxResubmitActionRegistratorModuleFactory.java [new file with mode: 0644]
openflow-nx-resubmit-action/src/main/resources/43-openflow-nx-resubmit-config.xml [new file with mode: 0644]
openflow-nx-resubmit-action/src/main/resources/log4j.xml [new file with mode: 0644]
openflow-nx-resubmit-action/src/main/yang/nx-resubmit-action.yang [new file with mode: 0644]
openflow-nx-resubmit-action/src/main/yang/openflow-nx-resubmit-action.yang [new file with mode: 0644]
openflow-nx-resubmit-action/src/test/java/org/opendaylight/openflowjava/protocol/nx/deserialization/NxActionResubmitDeserializerTest.java [new file with mode: 0644]
openflow-nx-resubmit-action/src/test/java/org/opendaylight/openflowjava/protocol/nx/serialization/NxActionResubmitSerializerTest.java [new file with mode: 0644]
pom.xml

diff --git a/openflow-nx-resubmit-action/pom.xml b/openflow-nx-resubmit-action/pom.xml
new file mode 100644 (file)
index 0000000..1468d01
--- /dev/null
@@ -0,0 +1,112 @@
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.opendaylight.openflowjava</groupId>
+        <artifactId>openflow-protocol-parent</artifactId>
+        <version>0.5-SNAPSHOT</version>
+    </parent>
+    <groupId>org.opendaylight.openflowjava</groupId>
+    <artifactId>openflow-nx-resubmit-action</artifactId>
+    <version>0.5-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+    <name>Openflow Protocol Library - Nx Resubmit Action</name>
+    <url>http://maven.apache.org</url>
+    <scm>
+        <url>https://wiki.opendaylight.org/view/Openflow_Protocol_Library:Main</url>
+        <tag>HEAD</tag>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.opendaylight.yangtools</groupId>
+                <artifactId>yang-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>generate-sources</goal>
+                        </goals>
+                        <configuration>
+                            <codeGenerators>
+                                <generator>
+                                    <codeGeneratorClass>
+                                        org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+                                    </codeGeneratorClass>
+                                    <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
+                                    <additionalConfiguration>
+                                        <namespaceToPackage1>
+                                            urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang
+                                        </namespaceToPackage1>
+                                    </additionalConfiguration>
+                                </generator>
+                                <generator>
+                                    <codeGeneratorClass>
+                                        org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
+                                    </codeGeneratorClass>
+                                    <outputBaseDir>${salGeneratorPath}</outputBaseDir>
+                                </generator>
+                                <generator>
+                                    <codeGeneratorClass>org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
+                                    <outputBaseDir>${project.build.directory}/site/models</outputBaseDir>
+                                </generator>
+                            </codeGenerators>
+                            <inspectDependencies>true</inspectDependencies>
+                        </configuration>
+                    </execution>
+                </executions>
+                <dependencies>
+                    <dependency>
+                        <groupId>org.opendaylight.controller</groupId>
+                        <artifactId>yang-jmx-generator-plugin</artifactId>
+                        <version>${config.version}</version>
+                    </dependency>
+                    <dependency>
+                        <groupId>org.opendaylight.yangtools</groupId>
+                        <artifactId>maven-sal-api-gen-plugin</artifactId>
+                        <version>${yangtools.generator.version}</version>
+                        <type>jar</type>
+                    </dependency>
+                </dependencies>
+            </plugin>
+        </plugins>
+    </build>
+
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>openflow-protocol-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>openflow-protocol-spi</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools.model</groupId>
+            <artifactId>yang-ext</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.netty</groupId>
+            <artifactId>netty-buffer</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <version>${slf4j.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>config-api</artifactId>
+            <version>${config.version}</version>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/openflow-nx-resubmit-action/src/main/java/org/opendaylight/openflowjava/protocol/nx/NxResubmitActionRegistrator.java b/openflow-nx-resubmit-action/src/main/java/org/opendaylight/openflowjava/protocol/nx/NxResubmitActionRegistrator.java
new file mode 100644 (file)
index 0000000..4baf6d2
--- /dev/null
@@ -0,0 +1,87 @@
+/*\r
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.nx;\r
+\r
+import java.util.List;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterActionDeserializerKey;\r
+import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterActionSerializerKey;\r
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.nx.deserialization.NxActionResubmitDeserializer;\r
+import org.opendaylight.openflowjava.protocol.nx.serialization.NxActionResubmitSerializer;\r
+import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class NxResubmitActionRegistrator implements AutoCloseable {\r
+\r
+    /** Nicira experimenter ID */\r
+    public static final Long NICIRA_EXPERIMENTER_ID = 0x00002320L;\r
+    private List<SwitchConnectionProvider> providers;\r
+\r
+    /**\r
+     * @param providers providers that shall be filled with serializers\r
+     */\r
+    public void registerNxResubmitSerializer(List<SwitchConnectionProvider> providers) {\r
+        if (providers != null) {\r
+            this.providers = providers;\r
+            for (SwitchConnectionProvider provider : providers) {\r
+                /* In case of handling multiple actions, instructions and other structures which\r
+                 * are differentiated by vendor / experimenter subtype, vendor has to\r
+                 * switch / choose between these subtypes.\r
+                 * \r
+                 * This has to be done in this way because of experimenter headers, which\r
+                 * provide only vendor / experimenter ID. Subtype position may be different\r
+                 * for different vendors (or not present at all) - that's why vendor has to\r
+                 * handle it in his own implementations.\r
+                 */\r
+                provider.registerActionSerializer(new ExperimenterActionSerializerKey(\r
+                        EncodeConstants.OF13_VERSION_ID, NICIRA_EXPERIMENTER_ID),\r
+                        new NxActionResubmitSerializer());\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+     * @param providers providers that shall be filled with deserializers\r
+     */\r
+    public void registerNxResubmitDeserializer(List<SwitchConnectionProvider> providers) {\r
+        if (providers != null) {\r
+            this.providers = providers;\r
+            for (SwitchConnectionProvider provider : providers) {\r
+                /* In case of handling multiple actions, instructions and other structures which\r
+                 * are differentiated by vendor / experimenter subtype, vendor has to\r
+                 * switch / choose between these subtypes.\r
+                 * \r
+                 * This has to be done in this way because of experimenter headers, which\r
+                 * provide only vendor / experimenter ID. Subtype position may be different\r
+                 * for different vendors (or not present at all) - that's why vendor has to\r
+                 * handle it in his own implementations.\r
+                 */\r
+                provider.registerActionDeserializer(new ExperimenterActionDeserializerKey(\r
+                        EncodeConstants.OF13_VERSION_ID, NICIRA_EXPERIMENTER_ID),\r
+                        new NxActionResubmitDeserializer());\r
+            }\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public void close() throws Exception {\r
+        for (SwitchConnectionProvider provider : providers) {\r
+            // unregister serializer\r
+            provider.unregisterSerializer(new ExperimenterActionSerializerKey(\r
+                    EncodeConstants.OF13_VERSION_ID, NICIRA_EXPERIMENTER_ID));\r
+            // unregister deserializer\r
+            provider.unregisterDeserializer(new ExperimenterActionDeserializerKey(\r
+                    EncodeConstants.OF13_VERSION_ID, NICIRA_EXPERIMENTER_ID));\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-nx-resubmit-action/src/main/java/org/opendaylight/openflowjava/protocol/nx/deserialization/NxActionResubmitDeserializer.java b/openflow-nx-resubmit-action/src/main/java/org/opendaylight/openflowjava/protocol/nx/deserialization/NxActionResubmitDeserializer.java
new file mode 100644 (file)
index 0000000..f5d50f5
--- /dev/null
@@ -0,0 +1,61 @@
+/*\r
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.nx.deserialization;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;\r
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.nx.resubmit.action.rev130731.NxActionResubmitAugment;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.nx.resubmit.action.rev130731.NxActionResubmitAugmentBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class NxActionResubmitDeserializer implements OFDeserializer<Action>,\r
+        HeaderDeserializer<Action> {\r
+\r
+    @Override\r
+    public Action deserializeHeader(ByteBuf input) {\r
+        ActionBuilder builder = processHeader(input);\r
+        return builder.build();\r
+    }\r
+\r
+    @Override\r
+    public Action deserialize(ByteBuf input) {\r
+        ActionBuilder builder = processHeader(input);\r
+        NxActionResubmitAugmentBuilder nxBuilder = new NxActionResubmitAugmentBuilder();\r
+        nxBuilder.setSubtype(input.readUnsignedShort());\r
+        nxBuilder.setInPort(input.readUnsignedShort());\r
+        nxBuilder.setTable(input.readUnsignedByte());\r
+        input.skipBytes(3);\r
+        builder.addAugmentation(NxActionResubmitAugment.class, nxBuilder.build());\r
+        return builder.build();\r
+    }\r
+\r
+    private static ActionBuilder processHeader(ByteBuf input) {\r
+        ActionBuilder builder = new ActionBuilder();\r
+        input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
+        builder.setType(Experimenter.class);\r
+        input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
+        // ExperimenterIdAction augmentation is used for vendor / experimenter differentiation\r
+        ExperimenterIdActionBuilder expIdBuilder = new ExperimenterIdActionBuilder();\r
+        expIdBuilder.setExperimenter(new ExperimenterId(input.readUnsignedInt()));\r
+        builder.addAugmentation(ExperimenterIdAction.class, expIdBuilder.build());\r
+        return builder;\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-nx-resubmit-action/src/main/java/org/opendaylight/openflowjava/protocol/nx/serialization/NxActionResubmitSerializer.java b/openflow-nx-resubmit-action/src/main/java/org/opendaylight/openflowjava/protocol/nx/serialization/NxActionResubmitSerializer.java
new file mode 100644 (file)
index 0000000..a6a38c8
--- /dev/null
@@ -0,0 +1,51 @@
+/*\r
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.nx.serialization;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.nx.NxResubmitActionRegistrator;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.nx.resubmit.action.rev130731.NxActionResubmitAugment;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class NxActionResubmitSerializer implements OFSerializer<Action>,\r
+        HeaderSerializer<Action> {\r
+    private static final Logger LOGGER = LoggerFactory\r
+            .getLogger(NxActionResubmitSerializer.class);\r
+    private static final byte NX_ACTION_RESUBMIT_LENGTH = 16;\r
+\r
+    @Override\r
+    public void serialize(Action action, ByteBuf outBuffer) {\r
+        LOGGER.error("SERIALIZING NX ACTION");\r
+        outBuffer.writeShort(EncodeConstants.EXPERIMENTER_VALUE);\r
+        outBuffer.writeShort(NX_ACTION_RESUBMIT_LENGTH);\r
+        NxActionResubmitAugment expAction = action.getAugmentation(NxActionResubmitAugment.class);\r
+        outBuffer.writeInt(NxResubmitActionRegistrator.NICIRA_EXPERIMENTER_ID.intValue());\r
+        outBuffer.writeShort(expAction.getSubtype());\r
+        outBuffer.writeShort(expAction.getInPort());\r
+        outBuffer.writeByte(expAction.getTable());\r
+        outBuffer.writeZero(3);\r
+    }\r
+\r
+    @Override\r
+    public void serializeHeader(Action action, ByteBuf outBuffer) {\r
+        outBuffer.writeShort(EncodeConstants.EXPERIMENTER_VALUE);\r
+        outBuffer.writeShort(EncodeConstants.EXPERIMENTER_IDS_LENGTH);\r
+        outBuffer.writeInt(NxResubmitActionRegistrator.NICIRA_EXPERIMENTER_ID.intValue());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-nx-resubmit-action/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/nx/resubmit/action/rev140709/NxResubmitActionRegistratorModule.java b/openflow-nx-resubmit-action/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/nx/resubmit/action/rev140709/NxResubmitActionRegistratorModule.java
new file mode 100644 (file)
index 0000000..b2c8cd6
--- /dev/null
@@ -0,0 +1,27 @@
+package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.nx.resubmit.action.rev140709;
+
+import org.opendaylight.openflowjava.protocol.nx.NxResubmitActionRegistrator;
+
+public class NxResubmitActionRegistratorModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.nx.resubmit.action.rev140709.AbstractNxResubmitActionRegistratorModule {
+    public NxResubmitActionRegistratorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+        super(identifier, dependencyResolver);
+    }
+
+    public NxResubmitActionRegistratorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.nx.resubmit.action.rev140709.NxResubmitActionRegistratorModule oldModule, java.lang.AutoCloseable oldInstance) {
+        super(identifier, dependencyResolver, oldModule, oldInstance);
+    }
+
+    @Override
+    public void customValidation() {
+        // add custom validation form module attributes here.
+    }
+
+    @Override
+    public java.lang.AutoCloseable createInstance() {
+        NxResubmitActionRegistrator registrator =  new NxResubmitActionRegistrator();
+        registrator.registerNxResubmitSerializer(getOpenflowSwitchConnectionProviderDependency());
+        registrator.registerNxResubmitDeserializer(getOpenflowSwitchConnectionProviderDependency());
+        return registrator;
+    }
+
+}
diff --git a/openflow-nx-resubmit-action/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/nx/resubmit/action/rev140709/NxResubmitActionRegistratorModuleFactory.java b/openflow-nx-resubmit-action/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/nx/resubmit/action/rev140709/NxResubmitActionRegistratorModuleFactory.java
new file mode 100644 (file)
index 0000000..3885223
--- /dev/null
@@ -0,0 +1,13 @@
+/*
+* Generated file
+*
+* Generated from: yang module name: openflow-nx-resubmit-action yang module local name: openflow-nx-resubmit-action
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Wed Jul 09 18:42:22 CEST 2014
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.nx.resubmit.action.rev140709;
+public class NxResubmitActionRegistratorModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.nx.resubmit.action.rev140709.AbstractNxResubmitActionRegistratorModuleFactory {
+
+}
diff --git a/openflow-nx-resubmit-action/src/main/resources/43-openflow-nx-resubmit-config.xml b/openflow-nx-resubmit-action/src/main/resources/43-openflow-nx-resubmit-config.xml
new file mode 100644 (file)
index 0000000..df43aa0
--- /dev/null
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+Copyright (c) 2014 Pantheon Technologies s.r.o. 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
+-->
+<snapshot>
+  <required-capabilities>
+    <capability>urn:opendaylight:params:xml:ns:yang:openflow:nx:resubmit:action?module=openflow-nx-resubmit-action&amp;revision=2014-07-09</capability>
+  </required-capabilities>
+
+  <configuration>
+
+    <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+      <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
+        <module>
+          <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:openflow:nx:resubmit:action">prefix:openflow-nx-resubmit-action</type>
+          <name>openflow-nx-resubmit-action-bundle</name>
+          <openflow-switch-connection-provider>
+            <type xmlns:ofSwitch="urn:opendaylight:params:xml:ns:yang:openflow:switch:connection:provider">ofSwitch:openflow-switch-connection-provider</type>
+            <name>openflow-switch-connection-provider-legacy</name>
+          </openflow-switch-connection-provider>
+          <openflow-switch-connection-provider>
+            <type xmlns:ofSwitch="urn:opendaylight:params:xml:ns:yang:openflow:switch:connection:provider">ofSwitch:openflow-switch-connection-provider</type>
+            <name>openflow-switch-connection-provider-default</name>
+          </openflow-switch-connection-provider>
+        </module>
+      </modules>
+    </data>
+
+  </configuration>
+</snapshot>
diff --git a/openflow-nx-resubmit-action/src/main/resources/log4j.xml b/openflow-nx-resubmit-action/src/main/resources/log4j.xml
new file mode 100644 (file)
index 0000000..5077ef8
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">\r
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">\r
+\r
+    <appender name="console" class="org.apache.log4j.ConsoleAppender">\r
+        <layout class="org.apache.log4j.PatternLayout">\r
+            <param name="ConversionPattern" value="%-6p %d{HH:mm:ss.SSS} [%10.10t] %30.30c %x - %m%n" />\r
+        </layout>\r
+    </appender>\r
+\r
+    <logger name="org.opendaylight.openflowjava.protocol.nx" additivity="false">\r
+        <level value="DEBUG" />\r
+        <appender-ref ref="console" />\r
+    </logger>\r
+\r
+    <root>\r
+        <priority value="INFO" />\r
+        <appender-ref ref="console" />\r
+    </root>\r
+</log4j:configuration>\r
diff --git a/openflow-nx-resubmit-action/src/main/yang/nx-resubmit-action.yang b/openflow-nx-resubmit-action/src/main/yang/nx-resubmit-action.yang
new file mode 100644 (file)
index 0000000..5ab94cd
--- /dev/null
@@ -0,0 +1,34 @@
+/*\r
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
\r
+ module nx-resubmit-action {\r
+    namespace "urn:opendaylight:openflow:nx:resubmit:action";\r
+    prefix "nx-resubmit";\r
+\r
+    import openflow-types {prefix oft;}\r
+    import openflow-action {prefix ofaction;}\r
+    import yang-ext {prefix ext;}\r
+\r
+    revision "2013-07-31" {\r
+        description "OpenFlow 1.3 - action model";\r
+    }\r
+\r
+    augment "/ofaction:actions-container/ofaction:action" {\r
+         ext:augment-identifier "nx-action-resubmit-augment";\r
+         leaf subtype {\r
+             type uint16;\r
+         }\r
+         leaf in-port {\r
+             type uint16;\r
+         }\r
+         leaf table {\r
+             type uint8;\r
+         }\r
+     }\r
+\r
+}
\ No newline at end of file
diff --git a/openflow-nx-resubmit-action/src/main/yang/openflow-nx-resubmit-action.yang b/openflow-nx-resubmit-action/src/main/yang/openflow-nx-resubmit-action.yang
new file mode 100644 (file)
index 0000000..45caf93
--- /dev/null
@@ -0,0 +1,45 @@
+/*\r
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+module openflow-nx-resubmit-action {\r
+       yang-version 1;\r
+    namespace "urn:opendaylight:params:xml:ns:yang:openflow:nx:resubmit:action";\r
+    prefix "openflow-nx-resubmit-action";\r
+\r
+    import config {prefix config; revision-date 2013-04-05;}\r
+    import openflow-switch-connection-provider {prefix openflow-switch-connection-provider;revision-date 2014-03-28;}\r
+\r
+\r
+    description\r
+        "openflow library default exemplary package";\r
+\r
+    revision "2014-07-09" {\r
+        description\r
+            "Initial revision";\r
+    }\r
+\r
+    identity openflow-nx-resubmit-action {\r
+        base config:module-type;\r
+        config:java-name-prefix NxResubmitActionRegistrator;\r
+    }\r
+\r
+    augment "/config:modules/config:module/config:configuration" {\r
+        case openflow-nx-resubmit-action {\r
+            when "/config:modules/config:module/config:type = 'openflow-nx-resubmit-action'";\r
+\r
+            list openflow-switch-connection-provider {\r
+                uses config:service-ref {\r
+                    refine type {\r
+                        mandatory true;\r
+                        config:required-identity openflow-switch-connection-provider:openflow-switch-connection-provider;\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-nx-resubmit-action/src/test/java/org/opendaylight/openflowjava/protocol/nx/deserialization/NxActionResubmitDeserializerTest.java b/openflow-nx-resubmit-action/src/test/java/org/opendaylight/openflowjava/protocol/nx/deserialization/NxActionResubmitDeserializerTest.java
new file mode 100644 (file)
index 0000000..5fca9ce
--- /dev/null
@@ -0,0 +1,56 @@
+/*\r
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.nx.deserialization;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
+import org.opendaylight.openflowjava.protocol.nx.NxResubmitActionRegistrator;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.nx.resubmit.action.rev130731.NxActionResubmitAugment;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class NxActionResubmitDeserializerTest {\r
+\r
+    /**\r
+     * Test deserialization of NX_ACTION_RESUBMIT action\r
+     */\r
+    @Test\r
+    public void test() {\r
+        ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+        buffer.writeShort(EncodeConstants.EXPERIMENTER_VALUE);\r
+        buffer.writeShort(16);\r
+        buffer.writeInt(NxResubmitActionRegistrator.NICIRA_EXPERIMENTER_ID.intValue());\r
+        buffer.writeShort(1);\r
+        buffer.writeShort(42);\r
+        buffer.writeByte(5);\r
+        buffer.writeZero(3);\r
+\r
+        NxActionResubmitDeserializer deserializer = new NxActionResubmitDeserializer();\r
+        Action action = deserializer.deserialize(buffer);\r
+\r
+        Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight"\r
+                + ".openflow.common.action.rev130731.Experimenter", action.getType().getName());\r
+        ExperimenterIdAction expAction = action.getAugmentation(ExperimenterIdAction.class);\r
+        Assert.assertEquals("Wrong vendor id", NxResubmitActionRegistrator.NICIRA_EXPERIMENTER_ID.intValue(),\r
+                expAction.getExperimenter().getValue().intValue());\r
+        NxActionResubmitAugment nxResubmit = action.getAugmentation(NxActionResubmitAugment.class);\r
+        Assert.assertEquals("Wrong subtype", 1, nxResubmit.getSubtype().intValue());\r
+        Assert.assertEquals("Wrong in-port", 42, nxResubmit.getInPort().intValue());\r
+        Assert.assertEquals("Wrong table", 5, nxResubmit.getTable().intValue());\r
+        Assert.assertTrue("Unread data", buffer.readableBytes() == 0);\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-nx-resubmit-action/src/test/java/org/opendaylight/openflowjava/protocol/nx/serialization/NxActionResubmitSerializerTest.java b/openflow-nx-resubmit-action/src/test/java/org/opendaylight/openflowjava/protocol/nx/serialization/NxActionResubmitSerializerTest.java
new file mode 100644 (file)
index 0000000..59a0138
--- /dev/null
@@ -0,0 +1,86 @@
+/*\r
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.nx.serialization;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.nx.NxResubmitActionRegistrator;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.nx.resubmit.action.rev130731.NxActionResubmitAugment;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.nx.resubmit.action.rev130731.NxActionResubmitAugmentBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class NxActionResubmitSerializerTest {\r
+\r
+    /**\r
+     * Test serialization of NX_ACTION_RESUBMIT action\r
+     */\r
+    @Test\r
+    public void test() {\r
+        ActionBuilder builder = new ActionBuilder();\r
+        builder.setType(Experimenter.class);\r
+        ExperimenterIdActionBuilder expIdBuilder = new ExperimenterIdActionBuilder();\r
+        expIdBuilder.setExperimenter(new ExperimenterId(NxResubmitActionRegistrator.NICIRA_EXPERIMENTER_ID));\r
+        builder.addAugmentation(ExperimenterIdAction.class, expIdBuilder.build());\r
+        NxActionResubmitAugmentBuilder nxBuilder = new NxActionResubmitAugmentBuilder();\r
+        nxBuilder.setSubtype(1);\r
+        nxBuilder.setInPort(42);\r
+        nxBuilder.setTable((short) 5);\r
+        builder.addAugmentation(NxActionResubmitAugment.class, nxBuilder.build());\r
+        Action action = builder.build();\r
+\r
+        ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+        NxActionResubmitSerializer serializer = new NxActionResubmitSerializer();\r
+        serializer.serialize(action, buffer);\r
+\r
+        Assert.assertEquals("Wrong action type", 65535, buffer.readUnsignedShort());\r
+        Assert.assertEquals("Wrong length", 16, buffer.readUnsignedShort());\r
+        Assert.assertEquals("Wrong vendor id", NxResubmitActionRegistrator.NICIRA_EXPERIMENTER_ID.intValue(),\r
+                buffer.readUnsignedInt());\r
+        Assert.assertEquals("Wrong subtype", 1, buffer.readUnsignedShort());\r
+        Assert.assertEquals("Wrong in-port", 42, buffer.readUnsignedShort());\r
+        Assert.assertEquals("Wrong table", 5, buffer.readUnsignedByte());\r
+        buffer.skipBytes(3);\r
+        Assert.assertTrue("Unread data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test serialization of NX_ACTION_RESUBMIT action\r
+     */\r
+    @Test\r
+    public void testHeaderSerialization() {\r
+        ActionBuilder builder = new ActionBuilder();\r
+        builder.setType(Experimenter.class);\r
+        ExperimenterIdActionBuilder expIdBuilder = new ExperimenterIdActionBuilder();\r
+        expIdBuilder.setExperimenter(new ExperimenterId(NxResubmitActionRegistrator.NICIRA_EXPERIMENTER_ID));\r
+        builder.addAugmentation(ExperimenterIdAction.class, expIdBuilder.build());\r
+        Action action = builder.build();\r
+\r
+        ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+        NxActionResubmitSerializer serializer = new NxActionResubmitSerializer();\r
+        serializer.serializeHeader(action, buffer);\r
+\r
+        Assert.assertEquals("Wrong action type", 65535, buffer.readUnsignedShort());\r
+        Assert.assertEquals("Wrong length", 8, buffer.readUnsignedShort());\r
+        Assert.assertEquals("Wrong vendor id", NxResubmitActionRegistrator.NICIRA_EXPERIMENTER_ID.intValue(),\r
+                buffer.readUnsignedInt());\r
+        Assert.assertTrue("Unread data", buffer.readableBytes() == 0);\r
+    }\r
+}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 05862144ad642beae14dbdf9da94a93532640508..ab183759d1a6ce90eb7830a96d1f02569d244c39 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -13,6 +13,7 @@
         <module>openflow-protocol-it</module>
         <module>feature</module>
         <module>simple-client</module>
+        <module>openflow-nx-resubmit-action</module>
     </modules>
     <scm>
         <connection>scm:git:ssh://git.opendaylight.org:29418/openflowjava.git</connection>