1 package org.opendaylight.openflowplugin.openflow.md.it;
3 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
4 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
5 import static org.ops4j.pax.exam.CoreOptions.options;
6 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
8 import java.util.Stack;
9 import java.util.concurrent.TimeUnit;
11 import javax.inject.Inject;
13 import junit.framework.Assert;
15 import org.junit.After;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.opendaylight.controller.test.sal.binding.it.TestHelper;
19 import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent;
20 import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
21 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
22 import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent;
23 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
24 import org.ops4j.pax.exam.Configuration;
25 import org.ops4j.pax.exam.Option;
26 import org.ops4j.pax.exam.junit.PaxExam;
27 import org.osgi.framework.BundleContext;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
34 @RunWith(PaxExam.class)
35 public class OFPluginToLibraryTest {
37 private static final Logger LOG = LoggerFactory
38 .getLogger(OFPluginToLibraryTest.class);
40 /** base controller package */
41 public static final String ODL = "org.opendaylight.controller";
42 /** controller.model package */
43 public static final String ODL_MODEL = "org.opendaylight.controller.model";
44 /** yangtools package */
45 public static final String YANG = "org.opendaylight.yangtools";
46 /** yangtools.model package */
47 public static final String YANG_MODEL = "org.opendaylight.yangtools.model";
48 /** OFPlugin package */
49 public static final String OFPLUGIN = "org.opendaylight.openflowplugin";
50 /** OFLibrary package */
51 public static final String OFLIBRARY = "org.opendaylight.openflowjava";
52 /** netty.io package */
53 public static final String NETTY = "io.netty";
56 SwitchConnectionProvider switchConnectionProvider;
61 private SimpleClient switchSim;
67 public void tearDown() {
69 LOG.debug("tearing down simulator");
70 switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
71 } catch (Exception e) {
72 String msg = "waiting for scenario to finish failed: "+e.getMessage();
79 * test basic integration with OFLib running the handshake
83 public void handshakeOk1() throws Exception {
84 LOG.debug("handshake integration test");
85 LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
87 switchSim = new SimpleClient("localhost", 6653);
88 switchSim.setSecuredClient(false);
89 Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenarioVBM(
90 ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
92 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
93 switchSim.setScenarioHandler(scenario);
96 switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
97 } catch (Exception e) {
98 String msg = "waiting for scenario to finish failed: "+e.getMessage();
102 //TODO: dump errors of plugin
106 * test basic integration with OFLib running the handshake (with version bitmap)
110 public void handshakeOk2() throws Exception {
111 LOG.debug("handshake integration test");
112 LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
114 switchSim = new SimpleClient("localhost", 6653);
115 switchSim.setSecuredClient(false);
116 Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario(
117 (short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
119 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
120 switchSim.setScenarioHandler(scenario);
123 switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
124 } catch (Exception e) {
125 String msg = "waiting for scenario to finish failed: "+e.getMessage();
129 //TODO: dump errors of plugin
133 * test basic integration with OFLib running the handshake
137 public void handshakeFail1() throws Exception {
138 LOG.debug("handshake integration test");
139 LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
141 switchSim = new SimpleClient("localhost", 6653);
142 switchSim.setSecuredClient(false);
143 Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 1,
144 ScenarioFactory.VERSION_BITMAP_10_13);
146 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
147 switchSim.setScenarioHandler(scenario);
150 switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
151 } catch (Exception e) {
152 String msg = "waiting for scenario to finish failed: "+e.getMessage();
156 //TODO: dump errors of plugin
160 * test basic integration with OFLib running the handshake
164 public void handshakeFail2() throws Exception {
165 LOG.debug("handshake integration test");
166 LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
168 switchSim = new SimpleClient("localhost", 6653);
169 switchSim.setSecuredClient(false);
170 Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 1,
171 ScenarioFactory.VERSION_BITMAP_10_13);
172 handshakeScenario.setElementAt(new SleepEvent(5000), 0);
174 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
175 switchSim.setScenarioHandler(scenario);
178 //TODO: dump errors of plugin
182 * @return timeout for case of failure
184 private static long getFailSafeTimeout() {
190 * @return bundle options
193 public Option[] config() {
195 systemProperty("osgi.console").value("2401"),
196 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
197 mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(),
198 mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(),
199 mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(),
200 mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager").versionAsInProject(),
201 TestHelper.mdSalCoreBundles(), TestHelper.bindingAwareSalBundles(),
202 TestHelper.flowCapableModelBundles(), TestHelper.baseModelBundles(),
205 mavenBundle(ODL, "sal").versionAsInProject(),
206 mavenBundle(ODL, "sal.connection").versionAsInProject(),
207 mavenBundle(ODL, "sal-common").versionAsInProject(),
209 mavenBundle("org.opendaylight.controller.thirdparty", "org.openflow.openflowj").versionAsInProject(),
210 mavenBundle(ODL_MODEL, "model-flow-statistics").versionAsInProject(),
212 mavenBundle(OFLIBRARY, "openflow-protocol-impl").versionAsInProject(),
213 mavenBundle(OFLIBRARY, "openflow-protocol-api").versionAsInProject(),
214 mavenBundle(OFLIBRARY, "openflow-protocol-spi").versionAsInProject(),
216 mavenBundle(NETTY, "netty-handler").versionAsInProject(),
217 mavenBundle(NETTY, "netty-buffer").versionAsInProject(),
218 mavenBundle(NETTY, "netty-common").versionAsInProject(),
219 mavenBundle(NETTY, "netty-transport").versionAsInProject(),
220 mavenBundle(NETTY, "netty-codec").versionAsInProject(),
222 mavenBundle(OFLIBRARY, "simple-client").versionAsInProject().start(),
223 mavenBundle(OFPLUGIN, "openflowplugin").versionAsInProject(),