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;
16 import javax.inject.Inject;
17 import org.junit.After;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent;
22 import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
23 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
24 import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent;
25 import org.opendaylight.openflowplugin.openflow.md.core.ThreadPoolLoggingExecutor;
26 import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
27 import org.ops4j.pax.exam.Configuration;
28 import org.ops4j.pax.exam.Option;
29 import org.ops4j.pax.exam.junit.PaxExam;
30 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
31 import org.ops4j.pax.exam.spi.reactors.PerClass;
32 import org.ops4j.pax.exam.util.Filter;
33 import org.osgi.framework.BundleContext;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 * covers basic handshake scenarios
40 @RunWith(PaxExam.class)
41 @ExamReactorStrategy(PerClass.class)
42 public class OFPluginToLibraryTest {
44 private static final Logger LOG = LoggerFactory
45 .getLogger(OFPluginToLibraryTest.class);
47 private final ArrayBlockingQueue<Runnable> SCENARIO_POOL_QUEUE = new ArrayBlockingQueue<>(1);
49 @Inject @Filter(timeout=60000)
50 OpenflowPluginProvider openflowPluginProvider;
52 @Inject @Filter(timeout=60000)
55 private SimpleClient switchSim;
56 private ThreadPoolLoggingExecutor scenarioPool;
60 * @throws InterruptedException
63 public void setUp() throws InterruptedException {
64 LOG.debug("openflowPluginProvider: "+openflowPluginProvider);
65 switchSim = createSimpleClient();
66 scenarioPool = new ThreadPoolLoggingExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, SCENARIO_POOL_QUEUE, "scenario");
74 public void tearDown() {
75 SimulatorAssistant.waitForSwitchSimulatorOn(switchSim);
76 SimulatorAssistant.tearDownSwitchSimulatorAfterScenario(switchSim, scenarioPool, getFailSafeTimeout());
80 * test basic integration with OFLib running the handshake
84 public void handshakeOk1() throws Exception {
85 LOG.debug("handshakeOk1 integration test");
87 switchSim.setSecuredClient(false);
88 Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenarioVBM(
89 ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13, true);
91 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
92 switchSim.setScenarioHandler(scenario);
93 scenarioPool.execute(switchSim);
97 * test basic integration with OFLib running the handshake (with version bitmap)
101 public void handshakeOk2() throws Exception {
102 LOG.debug("handshakeOk2 integration test");
104 switchSim = createSimpleClient();
105 switchSim.setSecuredClient(false);
106 Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario(
107 (short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
109 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
110 switchSim.setScenarioHandler(scenario);
111 scenarioPool.execute(switchSim);
115 * test basic integration with OFLib running the handshake:
116 * creating auxiliary connection without primary connection -- FAIL
120 public void handshakeFail1() throws Exception {
121 LOG.debug("handshakeFail1 integration test");
123 switchSim = createSimpleClient();
124 switchSim.setSecuredClient(false);
125 Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 1,
126 ScenarioFactory.VERSION_BITMAP_10_13);
128 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
129 switchSim.setScenarioHandler(scenario);
130 scenarioPool.execute(switchSim);
134 * test basic integration with OFLib running the handshake
135 * adding 5s wait as first event of switch -- FAIL
139 public void handshakeFail2() throws Exception {
140 LOG.debug("handshakeFail2 integration test");
141 LOG.debug("openflowPluginProvider: "+openflowPluginProvider);
143 switchSim = createSimpleClient();
144 switchSim.setSecuredClient(false);
145 Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 0,
146 ScenarioFactory.VERSION_BITMAP_10_13);
147 handshakeScenario.addFirst(new SleepEvent(5000));
148 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
149 switchSim.setScenarioHandler(scenario);
150 scenarioPool.execute(switchSim);
154 * test with MLX running OF10 and OFP running OF13/OF10
156 * MLX issues an OFPT_ERROR on the version compatability MLX issues a second
157 * HELLO after the second OFP HELLO
162 public void handshakeOkNoVBM_OF10_TwoHello() throws Exception {
163 LOG.debug("handshakeOkMLX10 integration test");
164 LOG.debug("openflowPluginProvider: " + openflowPluginProvider);
166 switchSim = createSimpleClient();
167 switchSim.setSecuredClient(false);
168 Deque<ClientEvent> handshakeScenario = ScenarioFactory
169 .createHandshakeScenarioNoVBM_OF10_TwoHello();
170 // handshakeScenario.setElementAt(new SleepEvent(5000),
174 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
175 switchSim.setScenarioHandler(scenario);
176 scenarioPool.execute(switchSim);
180 * test with Mininet running OF10 and OFP running OF13/OF10
182 * Mininet issues an OFPT_ERROR on the version compatability Mininet doesn't
183 * issue a second HELLO
188 public void handshakeOkNoVBM_OF10_SingleHello() throws Exception {
189 LOG.debug("handshakeOkMLX10 integration test");
190 LOG.debug("openflowPluginProvider: " + openflowPluginProvider);
192 switchSim = createSimpleClient();
193 switchSim.setSecuredClient(false);
194 Deque<ClientEvent> handshakeScenario = ScenarioFactory
195 .createHandshakeScenarioNOVBM_OF10_OneHello();
197 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
198 switchSim.setScenarioHandler(scenario);
199 scenarioPool.execute(switchSim);
205 private static SimpleClient createSimpleClient() {
206 return new SimpleClient("localhost", 6653);
210 * @return timeout for case of failure
212 private static long getFailSafeTimeout() {
218 * @return bundle options
221 public Option[] config() {
222 LOG.info("configuring...");
224 systemProperty("osgi.console").value("2401"),
225 systemProperty("osgi.bundles.defaultStartLevel").value("4"),
226 systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
228 OFPaxOptionsAssistant.osgiConsoleBundles(),
229 OFPaxOptionsAssistant.loggingBudles(),
230 OFPaxOptionsAssistant.ofPluginBundles());