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.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.ops4j.pax.exam.CoreOptions.options;
13 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
15 import java.util.ArrayList;
16 import java.util.List;
17 import java.util.concurrent.ArrayBlockingQueue;
18 import java.util.concurrent.TimeUnit;
19 import javax.inject.Inject;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
25 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
26 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
27 import org.opendaylight.controller.sal.binding.api.NotificationService;
28 import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
29 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
30 import org.opendaylight.openflowplugin.openflow.md.core.ThreadPoolLoggingExecutor;
31 import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.OpendaylightInventoryListener;
37 import org.ops4j.pax.exam.Configuration;
38 import org.ops4j.pax.exam.Option;
39 import org.ops4j.pax.exam.junit.PaxExam;
40 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
41 import org.ops4j.pax.exam.spi.reactors.PerClass;
42 import org.ops4j.pax.exam.util.Filter;
43 import org.osgi.framework.BundleContext;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 * Exercise inventory listener ({@link OpendaylightInventoryListener#onNodeUpdated(NodeUpdated)})
50 @RunWith(PaxExam.class)
51 @ExamReactorStrategy(PerClass.class)
52 public class SalIntegrationTest {
54 static final Logger LOG = LoggerFactory.getLogger(SalIntegrationTest.class);
56 private final ArrayBlockingQueue<Runnable> SCENARIO_POOL_QUEUE = new ArrayBlockingQueue<>(1);
57 private ThreadPoolLoggingExecutor scenarioPool;
58 private SimpleClient switchSim;
59 private Runnable finalCheck;
61 @Inject @Filter(timeout=60*000)
64 @Inject @Filter(timeout=60*1000)
65 BindingAwareBroker broker;
67 @Inject @Filter(timeout=60*1000)
68 OpenflowPluginProvider openflowPluginProvider;
71 * @return timeout for case of failure
73 static long getFailSafeTimeout() {
79 * @throws InterruptedException
82 public void setUp() throws InterruptedException {
83 switchSim = new SimpleClient("localhost", 6653);
84 scenarioPool = new ThreadPoolLoggingExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, SCENARIO_POOL_QUEUE, "scenario");
92 public void tearDown() {
93 SimulatorAssistant.waitForSwitchSimulatorOn(switchSim);
94 SimulatorAssistant.tearDownSwitchSimulatorAfterScenario(switchSim, scenarioPool, getFailSafeTimeout());
96 if (finalCheck != null) {
97 LOG.info("starting final check");
103 * test basic integration with OFLib running the handshake
108 public void handshakeAndNodeUpdate() throws Exception {
110 final TestInventoryListener listener = new TestInventoryListener();
111 BindingAwareConsumer openflowConsumer = new BindingAwareConsumer() {
114 public void onSessionInitialized(ConsumerContext session) {
115 session.getSALService(NotificationService.class).registerNotificationListener(listener);
118 ConsumerContext consumerReg = broker.registerConsumer(openflowConsumer, ctx);
119 assertNotNull(consumerReg);
121 LOG.debug("handshake integration test");
122 LOG.debug("openflowPluginProvider: " + openflowPluginProvider);
124 switchSim.setSecuredClient(false);
125 ScenarioHandler scenario = new ScenarioHandler(ScenarioFactory.createHandshakeScenarioVBM(
126 ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13, true));
127 switchSim.setScenarioHandler(scenario);
128 scenarioPool.execute(switchSim);
130 finalCheck = new Runnable() {
133 assertEquals(1, listener.nodeUpdated.size());
134 assertNotNull(listener.nodeUpdated.get(0));
140 * @return bundle options
143 public Option[] config() {
145 systemProperty("osgi.console").value("2401"),
146 systemProperty("osgi.bundles.defaultStartLevel").value("4"),
147 systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
149 OFPaxOptionsAssistant.osgiConsoleBundles(),
150 OFPaxOptionsAssistant.loggingBudles(),
151 OFPaxOptionsAssistant.ofPluginBundles());
154 private static class TestInventoryListener implements OpendaylightInventoryListener {
156 List<NodeUpdated> nodeUpdated = new ArrayList<>();
157 List<NodeRemoved> nodeRemoved = new ArrayList<>();
158 List<NodeConnectorUpdated> nodeConnectorUpdated = new ArrayList<>();
159 List<NodeConnectorRemoved> nodeConnectorRemoved = new ArrayList<>();
164 protected TestInventoryListener() {
169 public void onNodeUpdated(NodeUpdated notification) {
170 nodeUpdated.add(notification);
174 public void onNodeRemoved(NodeRemoved notification) {
175 nodeRemoved.add(notification);
179 public void onNodeConnectorUpdated(NodeConnectorUpdated notification) {
180 nodeConnectorUpdated.add(notification);
184 public void onNodeConnectorRemoved(NodeConnectorRemoved notification) {
185 nodeConnectorRemoved.add(notification);