added integration test: OFPlugin-OFLibrary-SimpleClient 50/2050/1
authorMichal Rehak <mirehak@cisco.com>
Mon, 21 Oct 2013 14:19:13 +0000 (16:19 +0200)
committerMichal Rehak <mirehak@cisco.com>
Mon, 21 Oct 2013 14:19:13 +0000 (16:19 +0200)
Change-Id: I36e8b5d83d80e973a2c4cd20f2e7f362f7201fa4
Signed-off-by: Michal Rehak <mirehak@cisco.com>
openflowplugin-it/pom.xml [new file with mode: 0644]
openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/OFPluginToLibraryTest.java [new file with mode: 0644]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImpl.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java

diff --git a/openflowplugin-it/pom.xml b/openflowplugin-it/pom.xml
new file mode 100644 (file)
index 0000000..16f852c
--- /dev/null
@@ -0,0 +1,145 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.opendaylight.openflowplugin</groupId>
+        <artifactId>commons.openflowplugin</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+        <relativePath>../commons</relativePath>
+    </parent>
+
+    <artifactId>openflowplugin-it</artifactId>
+
+    <properties>
+        <exam.version>3.0.0</exam.version>
+    </properties>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.ops4j.pax.exam</groupId>
+                <artifactId>maven-paxexam-plugin</artifactId>
+                <version>1.2.4</version>
+                <executions>
+                    <execution>
+                        <id>generate-config</id>
+                        <goals>
+                            <goal>generate-depends-file</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+        <pluginManagement>
+            <plugins>
+                <!--This plugin's configuration is used to store Eclipse m2e settings
+                    only. It has no influence on the Maven build itself. -->
+                <plugin>
+                    <groupId>org.eclipse.m2e</groupId>
+                    <artifactId>lifecycle-mapping</artifactId>
+                    <version>1.0.0</version>
+                    <configuration>
+                        <lifecycleMappingMetadata>
+                            <pluginExecutions>
+                                <pluginExecution>
+                                    <pluginExecutionFilter>
+                                        <groupId>
+                                            org.ops4j.pax.exam
+                                        </groupId>
+                                        <artifactId>
+                                            maven-paxexam-plugin
+                                        </artifactId>
+                                        <versionRange>
+                                            [1.2.4,)
+                                        </versionRange>
+                                        <goals>
+                                            <goal>
+                                                generate-depends-file
+                                            </goal>
+                                        </goals>
+                                    </pluginExecutionFilter>
+                                    <action>
+                                        <ignore></ignore>
+                                    </action>
+                                </pluginExecution>
+                            </pluginExecutions>
+                        </lifecycleMappingMetadata>
+                    </configuration>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.opendaylight.openflowplugin</groupId>
+            <artifactId>openflowplugin</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.openflowjava</groupId>
+            <artifactId>openflow-protocol-impl</artifactId>
+            <version>0.1-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.openflowjava</groupId>
+            <artifactId>simple-client</artifactId>
+            <version>0.1-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.javassist</groupId>
+            <artifactId>javassist</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools.thirdparty</groupId>
+            <artifactId>xtend-lib-osgi</artifactId>
+            <version>2.4.3</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-container-native</artifactId>
+            <version>${exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-junit4</artifactId>
+            <version>${exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-link-mvn</artifactId>
+            <version>${exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>equinoxSDK381</groupId>
+            <artifactId>org.eclipse.osgi</artifactId>
+            <version>3.8.1.v20120830-144521</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>log4j-over-slf4j</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/OFPluginToLibraryTest.java b/openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/OFPluginToLibraryTest.java
new file mode 100644 (file)
index 0000000..96e50e8
--- /dev/null
@@ -0,0 +1,125 @@
+package org.opendaylight.openflowplugin.openflow.md.it;
+
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import javax.inject.Inject;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioFactory;
+import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
+import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
+import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author mirehak
+ */
+@RunWith(PaxExam.class)
+public class OFPluginToLibraryTest {
+
+    private static final Logger LOG = LoggerFactory
+            .getLogger(OFPluginToLibraryTest.class);
+
+    /** base controller package */
+    public static final String ODL = "org.opendaylight.controller";
+    /** controller.model package */
+    public static final String ODL_MODEL = "org.opendaylight.controller.model";
+    /** yangtools package */
+    public static final String YANG = "org.opendaylight.yangtools";
+    /** yangtools.model package */
+    public static final String YANG_MODEL = "org.opendaylight.yangtools.model";
+    /** OFPlugin package */
+    public static final String OFPLUGIN = "org.opendaylight.openflowplugin";
+    /** OFLibrary package */
+    public static final String OFLIBRARY = "org.opendaylight.openflowjava";
+    /** netty.io package */
+    public static final String NETTY = "io.netty";
+
+    @Inject
+    SwitchConnectionProvider switchConnectionProvider;
+
+    @Inject
+    BundleContext ctx;
+
+    /**
+     * test basic integration with OFLib running the handshake
+     * @throws Exception
+     */
+    @Test
+    public void handshake() throws Exception {
+        LOG.debug("handshake integration test");
+        LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
+
+        SimpleClient switchSim = new SimpleClient("localhost", 6653);
+        switchSim.setSecuredClient(false);
+        ScenarioHandler scenario = new ScenarioHandler(ScenarioFactory.createHandshakeScenario());
+        switchSim.setScenarioHandler(scenario);
+        switchSim.start();
+        switchSim.getScenarioDone().get();
+    }
+
+
+    /**
+     * @return bundle options
+     */
+    @Configuration
+    public Option[] config() {
+        return options(
+                systemProperty("osgi.console").value("2401"),
+                mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
+                mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(),
+                mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(),
+                mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(),
+                mavenBundle("org.opendaylight.yangtools.thirdparty", "xtend-lib-osgi").versionAsInProject(),
+                mavenBundle("com.google.guava", "guava").versionAsInProject(),
+                mavenBundle("org.javassist", "javassist").versionAsInProject(),
+                mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager").versionAsInProject(),
+                mavenBundle("org.apache.commons", "commons-lang3").versionAsInProject(),
+
+                mavenBundle(ODL, "sal").versionAsInProject(),
+                mavenBundle(ODL, "sal.connection").versionAsInProject(),
+                mavenBundle(ODL, "sal-binding-api").versionAsInProject(),
+                mavenBundle(ODL, "sal-common").versionAsInProject(),
+                mavenBundle(ODL, "sal-common-api").versionAsInProject(),
+                mavenBundle(ODL, "sal-common-util").versionAsInProject(),
+
+                mavenBundle("org.opendaylight.controller.thirdparty", "org.openflow.openflowj").versionAsInProject(),
+                mavenBundle(ODL_MODEL, "model-flow-base").versionAsInProject(),
+                mavenBundle(ODL_MODEL, "model-inventory").versionAsInProject(),
+                mavenBundle(ODL_MODEL, "model-flow-service").versionAsInProject(),
+                mavenBundle(ODL_MODEL, "model-flow-statistics").versionAsInProject(),
+
+                mavenBundle(OFLIBRARY, "openflow-protocol-impl").versionAsInProject(),
+                mavenBundle(OFLIBRARY, "openflow-protocol-api").versionAsInProject(),
+                mavenBundle(OFLIBRARY, "openflow-protocol-spi").versionAsInProject(),
+
+                mavenBundle(NETTY, "netty-handler").versionAsInProject(),
+                mavenBundle(NETTY, "netty-buffer").versionAsInProject(),
+                mavenBundle(NETTY, "netty-common").versionAsInProject(),
+                mavenBundle(NETTY, "netty-transport").versionAsInProject(),
+                mavenBundle(NETTY, "netty-codec").versionAsInProject(),
+
+                mavenBundle(YANG_MODEL, "ietf-inet-types").versionAsInProject(),
+                mavenBundle(YANG_MODEL, "ietf-yang-types").versionAsInProject(),
+                mavenBundle(YANG_MODEL, "yang-ext").versionAsInProject(),
+                mavenBundle(YANG_MODEL, "opendaylight-l2-types").versionAsInProject(),
+
+                mavenBundle(YANG, "concepts").versionAsInProject(),
+                mavenBundle(YANG, "yang-binding").versionAsInProject(),
+                mavenBundle(YANG, "yang-common").versionAsInProject(),
+
+                mavenBundle(OFLIBRARY, "simple-client").versionAsInProject().start(),
+                mavenBundle(OFPLUGIN, "openflowplugin").versionAsInProject(),
+                junitBundles());
+    }
+
+}
index a25aec23e2cd20e3573142a7cb02ee8018c479d4..902eb0e8a69a2e0c7afb9af7715d6e01c0a33b79 100644 (file)
@@ -19,7 +19,6 @@ import org.opendaylight.openflowplugin.openflow.core.IMessageListener;
 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionManager;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder;
@@ -36,7 +35,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEvent;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener;
@@ -124,6 +122,7 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
         checkState(CONDUCTOR_STATE.HANDSHAKING);
 
         Short remoteVersion = hello.getVersion();
+        long xid = hello.getXid();
         short proposedVersion;
         try {
             proposedVersion = proposeVersion(remoteVersion);
@@ -132,7 +131,8 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
             throw e;
         }
         HelloInputBuilder helloBuilder = new HelloInputBuilder();
-        helloBuilder.setVersion(proposedVersion).setXid(hello.getXid());
+        xid++;
+        helloBuilder.setVersion(proposedVersion).setXid(xid);
         LOG.debug("sending helloReply");
         connectionAdapter.hello(helloBuilder.build());
 
@@ -145,7 +145,8 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
 
             // request features
             GetFeaturesInputBuilder featuresBuilder = new GetFeaturesInputBuilder();
-            featuresBuilder.setVersion(version).setXid(hello.getXid());
+            xid++;
+            featuresBuilder.setVersion(version).setXid(xid);
             Future<RpcResult<GetFeaturesOutput>> featuresFuture = connectionAdapter
                     .getFeatures(featuresBuilder.build());
             LOG.debug("waiting for features");
index 7f79b5ed99a503d098af4450c61f14463222f0f9..fa8395bae3907ef383e928c6a7ec36eacb150032 100644 (file)
@@ -110,9 +110,9 @@ public class ConnectionConductorImplTest {
         eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
                 EventFactory.DEFAULT_VERSION, new HelloMessageBuilder()));
         eventPlan.add(0,
-                EventFactory.createDefaultWaitForRpcEvent(42, "helloReply"));
+                EventFactory.createDefaultWaitForRpcEvent(43, "helloReply"));
         eventPlan.add(0,
-                EventFactory.createDefaultWaitForRpcEvent(42, "getFeatures"));
+                EventFactory.createDefaultWaitForRpcEvent(44, "getFeatures"));
         GetFeaturesOutputBuilder getFeaturesOutputBuilder = new GetFeaturesOutputBuilder();
         getFeaturesOutputBuilder.setDatapathId(new BigInteger("102030405060"));
         getFeaturesOutputBuilder.setAuxiliaryId((short) 0);
@@ -121,7 +121,7 @@ public class ConnectionConductorImplTest {
         getFeaturesOutputBuilder.setTables((short) 2);
         getFeaturesOutputBuilder.setCapabilities(84L);
 
-        eventPlan.add(0, EventFactory.createDefaultRpcResponseEvent(42,
+        eventPlan.add(0, EventFactory.createDefaultRpcResponseEvent(44,
                 EventFactory.DEFAULT_VERSION, getFeaturesOutputBuilder));
 
         execute(true);
@@ -140,17 +140,17 @@ public class ConnectionConductorImplTest {
         eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
                 (short) 0x05, new HelloMessageBuilder()));
         eventPlan.add(0,
-                EventFactory.createDefaultWaitForRpcEvent(42, "helloReply"));
-        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
+                EventFactory.createDefaultWaitForRpcEvent(43, "helloReply"));
+        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(43L,
                 (short) 0x03, new HelloMessageBuilder()));
         eventPlan.add(0,
-                EventFactory.createDefaultWaitForRpcEvent(42, "helloReply"));
-        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
+                EventFactory.createDefaultWaitForRpcEvent(44, "helloReply"));
+        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(44L,
                 (short) 0x01, new HelloMessageBuilder()));
         eventPlan.add(0,
-                EventFactory.createDefaultWaitForRpcEvent(42, "helloReply"));
+                EventFactory.createDefaultWaitForRpcEvent(45, "helloReply"));
         eventPlan.add(0,
-                EventFactory.createDefaultWaitForRpcEvent(42, "getFeatures"));
+                EventFactory.createDefaultWaitForRpcEvent(46, "getFeatures"));
         GetFeaturesOutputBuilder getFeaturesOutputBuilder = new GetFeaturesOutputBuilder();
         getFeaturesOutputBuilder.setDatapathId(new BigInteger("102030405060"));
         getFeaturesOutputBuilder.setAuxiliaryId((short) 0);
@@ -159,7 +159,7 @@ public class ConnectionConductorImplTest {
         getFeaturesOutputBuilder.setTables((short) 2);
         getFeaturesOutputBuilder.setCapabilities(84L);
 
-        eventPlan.add(0, EventFactory.createDefaultRpcResponseEvent(42,
+        eventPlan.add(0, EventFactory.createDefaultRpcResponseEvent(46,
                 EventFactory.DEFAULT_VERSION, getFeaturesOutputBuilder));
 
         executeNow();