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.Stack;
14 import java.util.concurrent.TimeUnit;
16 import javax.inject.Inject;
18 import org.junit.After;
19 import org.junit.Assert;
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.sal.OpenflowPluginProvider;
29 import org.ops4j.pax.exam.Configuration;
30 import org.ops4j.pax.exam.Option;
31 import org.ops4j.pax.exam.junit.PaxExam;
32 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
33 import org.ops4j.pax.exam.spi.reactors.PerClass;
34 import org.ops4j.pax.exam.util.Filter;
35 import org.osgi.framework.BundleContext;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 * covers basic handshake scenarios
42 @RunWith(PaxExam.class)
43 @ExamReactorStrategy(PerClass.class)
44 public class OFPluginToLibraryTest {
46 private static final Logger LOG = LoggerFactory
47 .getLogger(OFPluginToLibraryTest.class);
49 @Inject @Filter(timeout=20000)
50 OpenflowPluginProvider openflowPluginProvider;
55 private SimpleClient switchSim;
59 * @throws InterruptedException
62 public void setUp() throws InterruptedException {
63 LOG.debug("openflowPluginProvider: "+openflowPluginProvider);
64 //FIXME: plugin should provide service exposing startup result via future
72 public void tearDown() {
74 LOG.debug("tearing down simulator");
75 switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
76 } catch (Exception e) {
77 String msg = "waiting for scenario to finish failed: "+e.getMessage();
82 //TODO: dump errors of plugin (by exploiting ErrorHandler)
85 LOG.debug("checking if simulator succeeded to connect to controller");
86 boolean simulatorWasOnline = switchSim.getIsOnlineFuture().get(100, TimeUnit.MILLISECONDS);
87 Assert.assertTrue("simulator failed to connect to controller", simulatorWasOnline);
88 } catch (Exception e) {
89 String message = "simulator probably failed to connect to controller";
90 LOG.error(message, e);
96 * test basic integration with OFLib running the handshake
100 public void handshakeOk1() throws Exception {
101 LOG.debug("handshakeOk1 integration test");
103 switchSim = createSimpleClient();
104 switchSim.setSecuredClient(false);
105 Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenarioVBM(
106 ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
108 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
109 switchSim.setScenarioHandler(scenario);
114 * test basic integration with OFLib running the handshake (with version bitmap)
118 public void handshakeOk2() throws Exception {
119 LOG.debug("handshakeOk2 integration test");
121 switchSim = createSimpleClient();
122 switchSim.setSecuredClient(false);
123 Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario(
124 (short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
126 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
127 switchSim.setScenarioHandler(scenario);
132 * test basic integration with OFLib running the handshake:
133 * creating auxiliary connection without primary connection -- FAIL
137 public void handshakeFail1() throws Exception {
138 LOG.debug("handshakeFail1 integration test");
140 switchSim = createSimpleClient();
141 switchSim.setSecuredClient(false);
142 Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 1,
143 ScenarioFactory.VERSION_BITMAP_10_13);
145 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
146 switchSim.setScenarioHandler(scenario);
151 * test basic integration with OFLib running the handshake
152 * adding 5s wait as first event of switch -- FAIL
156 public void handshakeFail2() throws Exception {
157 LOG.debug("handshakeFail2 integration test");
158 LOG.debug("openflowPluginProvider: "+openflowPluginProvider);
160 switchSim = createSimpleClient();
161 switchSim.setSecuredClient(false);
162 Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 0,
163 ScenarioFactory.VERSION_BITMAP_10_13);
164 handshakeScenario.setElementAt(new SleepEvent(5000), 0);
166 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
167 switchSim.setScenarioHandler(scenario);
172 * test with MLX running OF10 and OFP running OF13/OF10
174 * MLX issues an OFPT_ERROR on the version compatability MLX issues a second
175 * HELLO after the second OFP HELLO
180 public void handshakeOkNoVBM_OF10_TwoHello() throws Exception {
181 LOG.debug("handshakeOkMLX10 integration test");
182 LOG.debug("openflowPluginProvider: " + openflowPluginProvider);
184 switchSim = createSimpleClient();
185 switchSim.setSecuredClient(false);
186 Stack<ClientEvent> handshakeScenario = ScenarioFactory
187 .createHandshakeScenarioNoVBM_OF10_TwoHello();
188 // handshakeScenario.setElementAt(new SleepEvent(5000),
192 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
193 switchSim.setScenarioHandler(scenario);
198 * test with Mininet running OF10 and OFP running OF13/OF10
200 * Mininet issues an OFPT_ERROR on the version compatability Mininet doesn't
201 * issue a second HELLO
206 public void handshakeOkNoVBM_OF10_SingleHello() throws Exception {
207 LOG.debug("handshakeOkMLX10 integration test");
208 LOG.debug("openflowPluginProvider: " + openflowPluginProvider);
210 switchSim = createSimpleClient();
211 switchSim.setSecuredClient(false);
212 Stack<ClientEvent> handshakeScenario = ScenarioFactory
213 .createHandshakeScenarioNOVBM_OF10_OneHello();
215 ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
216 switchSim.setScenarioHandler(scenario);
223 private static SimpleClient createSimpleClient() {
224 return new SimpleClient("localhost", 6653);
228 * @return timeout for case of failure
230 private static long getFailSafeTimeout() {
236 * @return bundle options
239 public Option[] config() {
240 LOG.info("configuring...");
242 systemProperty("osgi.console").value("2401"),
243 systemProperty("osgi.bundles.defaultStartLevel").value("4"),
244 systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
246 OFPaxOptionsAssistant.osgiConsoleBundles(),
247 OFPaxOptionsAssistant.loggingBudles(),
249 TestHelper.junitAndMockitoBundles(),
250 TestHelper.mdSalCoreBundles(),
251 TestHelper.configMinumumBundles(),
252 TestHelper.baseModelBundles(),
253 TestHelper.flowCapableModelBundles(),
255 OFPaxOptionsAssistant.ofPluginBundles());