+/**
+ * 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.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 junit.framework.Assert;
-
import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opendaylight.controller.test.sal.binding.it.TestHelper;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.util.Filter;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * @author mirehak
+ * covers basic handshake scenarios
*/
@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.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
+ @Inject @Filter(timeout=5000)
SwitchConnectionProvider switchConnectionProvider;
-
+
@Inject
BundleContext ctx;
private SimpleClient switchSim;
+ /**
+ * test setup
+ * @throws InterruptedException
+ */
+ @Before
+ public void setUp() throws InterruptedException {
+ LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
+ //FIXME: plugin should provide service exposing startup result via future
+ Thread.sleep(5000);
+ }
+
/**
* test tear down
*/
LOG.error(msg, e);
Assert.fail(msg);
}
+
+ //TODO: dump errors of plugin (by exploiting ErrorHandler)
+
+ try {
+ LOG.debug("checking if simulator succeeded to connect to controller");
+ boolean simulatorWasOnline = switchSim.getIsOnlineFuture().get(100, TimeUnit.MILLISECONDS);
+ Assert.assertTrue("simulator failed to connect to controller", simulatorWasOnline);
+ } catch (Exception e) {
+ String message = "simulator probably failed to connect to controller";
+ LOG.error(message, e);
+ Assert.fail(message);
+ }
}
/**
*/
@Test
public void handshakeOk1() throws Exception {
- LOG.debug("handshake integration test");
- LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
+ LOG.debug("handshakeOk1 integration test");
- switchSim = new SimpleClient("localhost", 6653);
+ switchSim = createSimpleClient();
switchSim.setSecuredClient(false);
Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenarioVBM(
ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
switchSim.setScenarioHandler(scenario);
switchSim.start();
- try {
- switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
- } catch (Exception e) {
- String msg = "waiting for scenario to finish failed: "+e.getMessage();
- LOG.error(msg, e);
- Assert.fail(msg);
- }
- //TODO: dump errors of plugin
}
/**
*/
@Test
public void handshakeOk2() throws Exception {
- LOG.debug("handshake integration test");
- LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
+ LOG.debug("handshakeOk2 integration test");
- switchSim = new SimpleClient("localhost", 6653);
+ switchSim = createSimpleClient();
switchSim.setSecuredClient(false);
Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario(
(short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
switchSim.setScenarioHandler(scenario);
switchSim.start();
- try {
- switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
- } catch (Exception e) {
- String msg = "waiting for scenario to finish failed: "+e.getMessage();
- LOG.error(msg, e);
- Assert.fail(msg);
- }
- //TODO: dump errors of plugin
}
/**
- * test basic integration with OFLib running the handshake
+ * test basic integration with OFLib running the handshake:
+ * creating auxiliary connection without primary connection -- FAIL
* @throws Exception
*/
@Test
public void handshakeFail1() throws Exception {
- LOG.debug("handshake integration test");
- LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
+ LOG.debug("handshakeFail1 integration test");
- switchSim = new SimpleClient("localhost", 6653);
+ switchSim = createSimpleClient();
switchSim.setSecuredClient(false);
Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 1,
ScenarioFactory.VERSION_BITMAP_10_13);
ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
switchSim.setScenarioHandler(scenario);
switchSim.start();
- try {
- switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
- } catch (Exception e) {
- String msg = "waiting for scenario to finish failed: "+e.getMessage();
- LOG.error(msg, e);
- Assert.fail(msg);
- }
- //TODO: dump errors of plugin
}
/**
* test basic integration with OFLib running the handshake
+ * adding 5s wait as first event of switch -- FAIL
* @throws Exception
*/
@Test
public void handshakeFail2() throws Exception {
- LOG.debug("handshake integration test");
+ LOG.debug("handshakeFail2 integration test");
LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
- switchSim = new SimpleClient("localhost", 6653);
+ switchSim = createSimpleClient();
switchSim.setSecuredClient(false);
- Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 1,
+ Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 0,
ScenarioFactory.VERSION_BITMAP_10_13);
handshakeScenario.setElementAt(new SleepEvent(5000), 0);
ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
switchSim.setScenarioHandler(scenario);
switchSim.start();
- tearDown();
- //TODO: dump errors of plugin
+ }
+
+ /**
+ * @return
+ */
+ private static SimpleClient createSimpleClient() {
+ return new SimpleClient("localhost", 6653);
}
/**
*/
@Configuration
public Option[] config() {
+ LOG.info("configuring...");
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.apache.felix", "org.apache.felix.dependencymanager").versionAsInProject(),
- TestHelper.mdSalCoreBundles(), TestHelper.bindingAwareSalBundles(),
- TestHelper.flowCapableModelBundles(), TestHelper.baseModelBundles(),
-
-
- mavenBundle(ODL, "sal").versionAsInProject(),
- mavenBundle(ODL, "sal.connection").versionAsInProject(),
- mavenBundle(ODL, "sal-common").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(OFLIBRARY, "simple-client").versionAsInProject().start(),
- mavenBundle(OFPLUGIN, "openflowplugin").versionAsInProject(),
- junitBundles());
+ systemProperty("osgi.bundles.defaultStartLevel").value("4"),
+ systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
+
+ OFPaxOptionsAssistant.osgiConsoleBundles(),
+ OFPaxOptionsAssistant.loggingBudles(),
+
+ TestHelper.junitAndMockitoBundles(),
+ TestHelper.mdSalCoreBundles(),
+ TestHelper.configMinumumBundles(),
+ TestHelper.baseModelBundles(),
+ TestHelper.flowCapableModelBundles(),
+
+ OFPaxOptionsAssistant.ofPluginBundles());
}
}