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;
20 import javax.inject.Inject;
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
27 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
28 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
29 import org.opendaylight.controller.sal.binding.api.NotificationService;
30 import org.opendaylight.controller.test.sal.binding.it.TestHelper;
31 import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
32 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
33 import org.opendaylight.openflowplugin.openflow.md.core.ThreadPoolLoggingExecutor;
34 import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.OpendaylightInventoryListener;
40 import org.ops4j.pax.exam.Configuration;
41 import org.ops4j.pax.exam.Option;
42 import org.ops4j.pax.exam.junit.PaxExam;
43 import org.ops4j.pax.exam.util.Filter;
44 import org.osgi.framework.BundleContext;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
49 * Exercise inventory listener ({@link OpendaylightInventoryListener#onNodeUpdated(NodeUpdated)})
51 @RunWith(PaxExam.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;
65 @Filter(timeout=20*1000)
66 BindingAwareBroker broker;
69 @Filter(timeout=20*1000)
70 OpenflowPluginProvider openflowPluginProvider;
73 * @return timeout for case of failure
75 static long getFailSafeTimeout() {
81 * @throws InterruptedException
84 public void setUp() throws InterruptedException {
85 switchSim = new SimpleClient("localhost", 6653);
86 scenarioPool = new ThreadPoolLoggingExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, SCENARIO_POOL_QUEUE, "scenario");
93 public void tearDown() {
94 SimulatorAssistant.waitForSwitchSimulatorOn(switchSim);
95 SimulatorAssistant.tearDownSwitchSimulatorAfterScenario(switchSim, scenarioPool, getFailSafeTimeout());
97 if (finalCheck != null) {
98 LOG.info("starting final check");
104 * test basic integration with OFLib running the handshake
109 public void handshakeAndNodeUpdate() throws Exception {
111 final TestInventoryListener listener = new TestInventoryListener();
112 BindingAwareConsumer openflowConsumer = new BindingAwareConsumer() {
115 public void onSessionInitialized(ConsumerContext session) {
116 session.getSALService(NotificationService.class).registerNotificationListener(listener);
119 ConsumerContext consumerReg = broker.registerConsumer(openflowConsumer, ctx);
120 assertNotNull(consumerReg);
122 LOG.debug("handshake integration test");
123 LOG.debug("openflowPluginProvider: " + openflowPluginProvider);
125 switchSim.setSecuredClient(false);
126 ScenarioHandler scenario = new ScenarioHandler(ScenarioFactory.createHandshakeScenarioVBM(
127 ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13, true));
128 switchSim.setScenarioHandler(scenario);
129 scenarioPool.execute(switchSim);
131 finalCheck = new Runnable() {
134 assertEquals(1, listener.nodeUpdated.size());
135 assertNotNull(listener.nodeUpdated.get(0));
141 * @return bundle options
144 public Option[] config() {
145 return options(systemProperty("osgi.console").value("2401"),
146 OFPaxOptionsAssistant.osgiConsoleBundles(),
147 OFPaxOptionsAssistant.loggingBudles(),
149 TestHelper.junitAndMockitoBundles(),
150 TestHelper.mdSalCoreBundles(),
151 TestHelper.configMinumumBundles(),
152 TestHelper.baseModelBundles(),
153 OFPaxOptionsAssistant.ofLibraryBundles(),
154 OFPaxOptionsAssistant.ofPluginBundles()
158 private static class TestInventoryListener implements OpendaylightInventoryListener {
160 List<NodeUpdated> nodeUpdated = new ArrayList<>();
161 List<NodeRemoved> nodeRemoved = new ArrayList<>();
162 List<NodeConnectorUpdated> nodeConnectorUpdated = new ArrayList<>();
163 List<NodeConnectorRemoved> nodeConnectorRemoved = new ArrayList<>();
168 protected TestInventoryListener() {
173 public void onNodeUpdated(NodeUpdated notification) {
174 nodeUpdated.add(notification);
178 public void onNodeRemoved(NodeRemoved notification) {
179 nodeRemoved.add(notification);
183 public void onNodeConnectorUpdated(NodeConnectorUpdated notification) {
184 nodeConnectorUpdated.add(notification);
188 public void onNodeConnectorRemoved(NodeConnectorRemoved notification) {
189 nodeConnectorRemoved.add(notification);