2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.openflow.md.it;
10 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
11 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
12 import static org.ops4j.pax.exam.CoreOptions.options;
13 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
15 import java.util.Stack;
16 import java.util.concurrent.TimeUnit;
18 import javax.inject.Inject;
20 import junit.framework.Assert;
22 import org.junit.After;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.opendaylight.controller.test.sal.binding.it.TestHelper;
26 import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent;
27 import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
28 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
29 import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent;
30 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
31 import org.ops4j.pax.exam.Configuration;
32 import org.ops4j.pax.exam.Option;
33 import org.ops4j.pax.exam.junit.PaxExam;
34 import org.osgi.framework.BundleContext;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 //@RunWith(PaxExam.class)
39 public class OFPluginToLibraryTest {
41 private static final Logger LOG = LoggerFactory
42 .getLogger(OFPluginToLibraryTest.class);
44 /** base controller package */
45 public static final String ODL = "org.opendaylight.controller";
46 /** controller.model package */
47 public static final String ODL_MODEL = "org.opendaylight.controller.model";
48 /** yangtools package */
49 public static final String YANG = "org.opendaylight.yangtools";
50 /** yangtools.model package */
51 public static final String YANG_MODEL = "org.opendaylight.yangtools.model";
52 /** OFPlugin package */
53 public static final String OFPLUGIN = "org.opendaylight.openflowplugin";
54 /** OFLibrary package */
55 public static final String OFLIBRARY = "org.opendaylight.openflowjava";
56 /** netty.io package */
57 public static final String NETTY = "io.netty";
60 SwitchConnectionProvider switchConnectionProvider;
65 private SimpleClient switchSim;
71 public void tearDown() {
73 LOG.debug("tearing down simulator");
74 switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
75 } catch (Exception e) {
76 String msg = "waiting for scenario to finish failed: "+e.getMessage();
83 * test basic integration with OFLib running the handshake
87 public void handshakeOk1() throws Exception {
88 LOG.debug("handshake integration test");
89 LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
91 switchSim = new SimpleClient("localhost", 6653);
92 switchSim.setSecuredClient(false);
93 Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenarioVBM(
94 ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
96 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
97 switchSim.setScenarioHandler(scenario);
100 switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
101 } catch (Exception e) {
102 String msg = "waiting for scenario to finish failed: "+e.getMessage();
106 //TODO: dump errors of plugin
110 * test basic integration with OFLib running the handshake (with version bitmap)
114 public void handshakeOk2() throws Exception {
115 LOG.debug("handshake integration test");
116 LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
118 switchSim = new SimpleClient("localhost", 6653);
119 switchSim.setSecuredClient(false);
120 Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario(
121 (short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
123 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
124 switchSim.setScenarioHandler(scenario);
127 switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
128 } catch (Exception e) {
129 String msg = "waiting for scenario to finish failed: "+e.getMessage();
133 //TODO: dump errors of plugin
137 * test basic integration with OFLib running the handshake
141 public void handshakeFail1() throws Exception {
142 LOG.debug("handshake integration test");
143 LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
145 switchSim = new SimpleClient("localhost", 6653);
146 switchSim.setSecuredClient(false);
147 Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 1,
148 ScenarioFactory.VERSION_BITMAP_10_13);
150 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
151 switchSim.setScenarioHandler(scenario);
154 switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
155 } catch (Exception e) {
156 String msg = "waiting for scenario to finish failed: "+e.getMessage();
160 //TODO: dump errors of plugin
164 * test basic integration with OFLib running the handshake
168 public void handshakeFail2() throws Exception {
169 LOG.debug("handshake integration test");
170 LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
172 switchSim = new SimpleClient("localhost", 6653);
173 switchSim.setSecuredClient(false);
174 Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 1,
175 ScenarioFactory.VERSION_BITMAP_10_13);
176 handshakeScenario.setElementAt(new SleepEvent(5000), 0);
178 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
179 switchSim.setScenarioHandler(scenario);
182 //TODO: dump errors of plugin
186 * @return timeout for case of failure
188 private static long getFailSafeTimeout() {
194 * @return bundle options
197 public Option[] config() {
199 systemProperty("osgi.console").value("2401"),
200 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
201 mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(),
202 mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(),
203 mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(),
204 mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager").versionAsInProject(),
205 TestHelper.mdSalCoreBundles(), TestHelper.bindingAwareSalBundles(),
206 TestHelper.flowCapableModelBundles(), TestHelper.baseModelBundles(),
209 mavenBundle(ODL, "sal").versionAsInProject(),
210 mavenBundle(ODL, "sal.connection").versionAsInProject(),
211 mavenBundle(ODL, "sal-common").versionAsInProject(),
213 mavenBundle(ODL_MODEL, "model-flow-statistics").versionAsInProject(),
215 mavenBundle(OFLIBRARY, "openflow-protocol-impl").versionAsInProject(),
216 mavenBundle(OFLIBRARY, "openflow-protocol-api").versionAsInProject(),
217 mavenBundle(OFLIBRARY, "openflow-protocol-spi").versionAsInProject(),
219 mavenBundle(NETTY, "netty-handler").versionAsInProject(),
220 mavenBundle(NETTY, "netty-buffer").versionAsInProject(),
221 mavenBundle(NETTY, "netty-common").versionAsInProject(),
222 mavenBundle(NETTY, "netty-transport").versionAsInProject(),
223 mavenBundle(NETTY, "netty-codec").versionAsInProject(),
225 mavenBundle(OFLIBRARY, "simple-client").versionAsInProject().start(),
226 mavenBundle(OFPLUGIN, "openflowplugin").versionAsInProject(),