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.Before;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.opendaylight.controller.test.sal.binding.it.TestHelper;
24 import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent;
25 import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
26 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
27 import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent;
28 import org.opendaylight.openflowplugin.openflow.md.core.ThreadPoolLoggingExecutor;
29 import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
30 import org.ops4j.pax.exam.Configuration;
31 import org.ops4j.pax.exam.Option;
32 import org.ops4j.pax.exam.junit.PaxExam;
33 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
34 import org.ops4j.pax.exam.spi.reactors.PerClass;
35 import org.ops4j.pax.exam.util.Filter;
36 import org.osgi.framework.BundleContext;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
41 * covers basic handshake scenarios
43 @RunWith(PaxExam.class)
44 @ExamReactorStrategy(PerClass.class)
45 public class OFPluginToLibraryTest {
47 private static final Logger LOG = LoggerFactory
48 .getLogger(OFPluginToLibraryTest.class);
50 private final ArrayBlockingQueue<Runnable> SCENARIO_POOL_QUEUE = new ArrayBlockingQueue<>(1);
52 @Inject @Filter(timeout=60000)
53 OpenflowPluginProvider openflowPluginProvider;
55 @Inject @Filter(timeout=60000)
58 private SimpleClient switchSim;
59 private ThreadPoolLoggingExecutor scenarioPool;
63 * @throws InterruptedException
66 public void setUp() throws InterruptedException {
67 LOG.debug("openflowPluginProvider: "+openflowPluginProvider);
68 switchSim = createSimpleClient();
69 scenarioPool = new ThreadPoolLoggingExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, SCENARIO_POOL_QUEUE, "scenario");
76 public void tearDown() {
77 SimulatorAssistant.waitForSwitchSimulatorOn(switchSim);
78 SimulatorAssistant.tearDownSwitchSimulatorAfterScenario(switchSim, scenarioPool, getFailSafeTimeout());
82 * test basic integration with OFLib running the handshake
86 public void handshakeOk1() throws Exception {
87 LOG.debug("handshakeOk1 integration test");
89 switchSim.setSecuredClient(false);
90 Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenarioVBM(
91 ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13, true);
93 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
94 switchSim.setScenarioHandler(scenario);
95 scenarioPool.execute(switchSim);
99 * test basic integration with OFLib running the handshake (with version bitmap)
103 public void handshakeOk2() throws Exception {
104 LOG.debug("handshakeOk2 integration test");
106 switchSim = createSimpleClient();
107 switchSim.setSecuredClient(false);
108 Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario(
109 (short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
111 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
112 switchSim.setScenarioHandler(scenario);
113 scenarioPool.execute(switchSim);
117 * test basic integration with OFLib running the handshake:
118 * creating auxiliary connection without primary connection -- FAIL
122 public void handshakeFail1() throws Exception {
123 LOG.debug("handshakeFail1 integration test");
125 switchSim = createSimpleClient();
126 switchSim.setSecuredClient(false);
127 Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 1,
128 ScenarioFactory.VERSION_BITMAP_10_13);
130 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
131 switchSim.setScenarioHandler(scenario);
132 scenarioPool.execute(switchSim);
136 * test basic integration with OFLib running the handshake
137 * adding 5s wait as first event of switch -- FAIL
141 public void handshakeFail2() throws Exception {
142 LOG.debug("handshakeFail2 integration test");
143 LOG.debug("openflowPluginProvider: "+openflowPluginProvider);
145 switchSim = createSimpleClient();
146 switchSim.setSecuredClient(false);
147 Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 0,
148 ScenarioFactory.VERSION_BITMAP_10_13);
149 handshakeScenario.addFirst(new SleepEvent(5000));
150 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
151 switchSim.setScenarioHandler(scenario);
152 scenarioPool.execute(switchSim);
156 * test with MLX running OF10 and OFP running OF13/OF10
158 * MLX issues an OFPT_ERROR on the version compatability MLX issues a second
159 * HELLO after the second OFP HELLO
164 public void handshakeOkNoVBM_OF10_TwoHello() throws Exception {
165 LOG.debug("handshakeOkMLX10 integration test");
166 LOG.debug("openflowPluginProvider: " + openflowPluginProvider);
168 switchSim = createSimpleClient();
169 switchSim.setSecuredClient(false);
170 Deque<ClientEvent> handshakeScenario = ScenarioFactory
171 .createHandshakeScenarioNoVBM_OF10_TwoHello();
172 // handshakeScenario.setElementAt(new SleepEvent(5000),
176 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
177 switchSim.setScenarioHandler(scenario);
178 scenarioPool.execute(switchSim);
182 * test with Mininet running OF10 and OFP running OF13/OF10
184 * Mininet issues an OFPT_ERROR on the version compatability Mininet doesn't
185 * issue a second HELLO
190 public void handshakeOkNoVBM_OF10_SingleHello() throws Exception {
191 LOG.debug("handshakeOkMLX10 integration test");
192 LOG.debug("openflowPluginProvider: " + openflowPluginProvider);
194 switchSim = createSimpleClient();
195 switchSim.setSecuredClient(false);
196 Deque<ClientEvent> handshakeScenario = ScenarioFactory
197 .createHandshakeScenarioNOVBM_OF10_OneHello();
199 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
200 switchSim.setScenarioHandler(scenario);
201 scenarioPool.execute(switchSim);
207 private static SimpleClient createSimpleClient() {
208 return new SimpleClient("localhost", 6653);
212 * @return timeout for case of failure
214 private static long getFailSafeTimeout() {
220 * @return bundle options
223 public Option[] config() {
224 LOG.info("configuring...");
226 systemProperty("osgi.console").value("2401"),
227 systemProperty("osgi.bundles.defaultStartLevel").value("4"),
228 systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
230 OFPaxOptionsAssistant.osgiConsoleBundles(),
231 OFPaxOptionsAssistant.loggingBudles(),
232 OFPaxOptionsAssistant.ofPluginBundles());