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.options;
11 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
13 import java.util.Deque;
14 import java.util.concurrent.ArrayBlockingQueue;
15 import java.util.concurrent.TimeUnit;
17 import javax.inject.Inject;
19 import org.junit.After;
20 import org.junit.Assert;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.opendaylight.controller.test.sal.binding.it.TestHelper;
25 import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent;
26 import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
27 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
28 import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent;
29 import org.opendaylight.openflowplugin.openflow.md.core.ThreadPoolLoggingExecutor;
30 import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
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.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
35 import org.ops4j.pax.exam.spi.reactors.PerClass;
36 import org.ops4j.pax.exam.util.Filter;
37 import org.osgi.framework.BundleContext;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * covers basic handshake scenarios
44 @RunWith(PaxExam.class)
45 @ExamReactorStrategy(PerClass.class)
46 public class OFPluginToLibraryTest {
48 private static final Logger LOG = LoggerFactory
49 .getLogger(OFPluginToLibraryTest.class);
51 private static final ArrayBlockingQueue<Runnable> SCENARIO_POOL_QUEUE = new ArrayBlockingQueue<>(1);
53 @Inject @Filter(timeout=20000)
54 OpenflowPluginProvider openflowPluginProvider;
59 private SimpleClient switchSim;
60 private ThreadPoolLoggingExecutor scenarioPool;
64 * @throws InterruptedException
67 public void setUp() throws InterruptedException {
68 LOG.debug("openflowPluginProvider: "+openflowPluginProvider);
69 scenarioPool = new ThreadPoolLoggingExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, SCENARIO_POOL_QUEUE, "scenario");
70 //FIXME: plugin should provide service exposing startup result via future
78 public void tearDown() {
80 LOG.debug("tearing down simulator");
81 switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
82 } catch (Exception e) {
83 String msg = "waiting for scenario to finish failed: "+e.getMessage();
87 scenarioPool.shutdownNow();
88 SCENARIO_POOL_QUEUE.clear();
92 LOG.debug("checking if simulator succeeded to connect to controller");
93 boolean simulatorWasOnline = switchSim.getIsOnlineFuture().get(100, TimeUnit.MILLISECONDS);
94 Assert.assertTrue("simulator failed to connect to controller", simulatorWasOnline);
95 } catch (Exception e) {
96 String message = "simulator probably failed to connect to controller";
97 LOG.error(message, e);
103 * test basic integration with OFLib running the handshake
107 public void handshakeOk1() throws Exception {
108 LOG.debug("handshakeOk1 integration test");
110 switchSim = createSimpleClient();
111 switchSim.setSecuredClient(false);
112 Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenarioVBM(
113 ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13, true);
115 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
116 switchSim.setScenarioHandler(scenario);
117 scenarioPool.execute(switchSim);
121 * test basic integration with OFLib running the handshake (with version bitmap)
125 public void handshakeOk2() throws Exception {
126 LOG.debug("handshakeOk2 integration test");
128 switchSim = createSimpleClient();
129 switchSim.setSecuredClient(false);
130 Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario(
131 (short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
133 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
134 switchSim.setScenarioHandler(scenario);
135 scenarioPool.execute(switchSim);
139 * test basic integration with OFLib running the handshake:
140 * creating auxiliary connection without primary connection -- FAIL
144 public void handshakeFail1() throws Exception {
145 LOG.debug("handshakeFail1 integration test");
147 switchSim = createSimpleClient();
148 switchSim.setSecuredClient(false);
149 Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 1,
150 ScenarioFactory.VERSION_BITMAP_10_13);
152 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
153 switchSim.setScenarioHandler(scenario);
154 scenarioPool.execute(switchSim);
158 * test basic integration with OFLib running the handshake
159 * adding 5s wait as first event of switch -- FAIL
163 public void handshakeFail2() throws Exception {
164 LOG.debug("handshakeFail2 integration test");
165 LOG.debug("openflowPluginProvider: "+openflowPluginProvider);
167 switchSim = createSimpleClient();
168 switchSim.setSecuredClient(false);
169 Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 0,
170 ScenarioFactory.VERSION_BITMAP_10_13);
171 handshakeScenario.addFirst(new SleepEvent(5000));
172 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
173 switchSim.setScenarioHandler(scenario);
174 scenarioPool.execute(switchSim);
178 * test with MLX running OF10 and OFP running OF13/OF10
180 * MLX issues an OFPT_ERROR on the version compatability MLX issues a second
181 * HELLO after the second OFP HELLO
186 public void handshakeOkNoVBM_OF10_TwoHello() throws Exception {
187 LOG.debug("handshakeOkMLX10 integration test");
188 LOG.debug("openflowPluginProvider: " + openflowPluginProvider);
190 switchSim = createSimpleClient();
191 switchSim.setSecuredClient(false);
192 Deque<ClientEvent> handshakeScenario = ScenarioFactory
193 .createHandshakeScenarioNoVBM_OF10_TwoHello();
194 // handshakeScenario.setElementAt(new SleepEvent(5000),
198 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
199 switchSim.setScenarioHandler(scenario);
200 scenarioPool.execute(switchSim);
204 * test with Mininet running OF10 and OFP running OF13/OF10
206 * Mininet issues an OFPT_ERROR on the version compatability Mininet doesn't
207 * issue a second HELLO
212 public void handshakeOkNoVBM_OF10_SingleHello() throws Exception {
213 LOG.debug("handshakeOkMLX10 integration test");
214 LOG.debug("openflowPluginProvider: " + openflowPluginProvider);
216 switchSim = createSimpleClient();
217 switchSim.setSecuredClient(false);
218 Deque<ClientEvent> handshakeScenario = ScenarioFactory
219 .createHandshakeScenarioNOVBM_OF10_OneHello();
221 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
222 switchSim.setScenarioHandler(scenario);
223 scenarioPool.execute(switchSim);
229 private static SimpleClient createSimpleClient() {
230 return new SimpleClient("localhost", 6653);
234 * @return timeout for case of failure
236 private static long getFailSafeTimeout() {
242 * @return bundle options
245 public Option[] config() {
246 LOG.info("configuring...");
248 systemProperty("osgi.console").value("2401"),
249 systemProperty("osgi.bundles.defaultStartLevel").value("4"),
250 systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
252 OFPaxOptionsAssistant.osgiConsoleBundles(),
253 OFPaxOptionsAssistant.loggingBudles(),
255 TestHelper.junitAndMockitoBundles(),
256 TestHelper.mdSalCoreBundles(),
257 TestHelper.configMinumumBundles(),
258 TestHelper.baseModelBundles(),
259 TestHelper.flowCapableModelBundles(),
261 OFPaxOptionsAssistant.ofPluginBundles());