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.spi.reactors.ExamReactorStrategy;
44 import org.ops4j.pax.exam.spi.reactors.PerClass;
45 import org.ops4j.pax.exam.util.Filter;
46 import org.osgi.framework.BundleContext;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
51 * Exercise inventory listener ({@link OpendaylightInventoryListener#onNodeUpdated(NodeUpdated)})
53 @RunWith(PaxExam.class)
54 @ExamReactorStrategy(PerClass.class)
55 public class SalIntegrationTest {
57 static final Logger LOG = LoggerFactory.getLogger(SalIntegrationTest.class);
59 private final ArrayBlockingQueue<Runnable> SCENARIO_POOL_QUEUE = new ArrayBlockingQueue<>(1);
60 private ThreadPoolLoggingExecutor scenarioPool;
61 private SimpleClient switchSim;
62 private Runnable finalCheck;
64 @Inject @Filter(timeout=60*000)
67 @Inject @Filter(timeout=60*1000)
68 BindingAwareBroker broker;
70 @Inject @Filter(timeout=60*1000)
71 OpenflowPluginProvider openflowPluginProvider;
74 * @return timeout for case of failure
76 static long getFailSafeTimeout() {
82 * @throws InterruptedException
85 public void setUp() throws InterruptedException {
86 switchSim = new SimpleClient("localhost", 6653);
87 scenarioPool = new ThreadPoolLoggingExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, SCENARIO_POOL_QUEUE, "scenario");
94 public void tearDown() {
95 SimulatorAssistant.waitForSwitchSimulatorOn(switchSim);
96 SimulatorAssistant.tearDownSwitchSimulatorAfterScenario(switchSim, scenarioPool, getFailSafeTimeout());
98 if (finalCheck != null) {
99 LOG.info("starting final check");
105 * test basic integration with OFLib running the handshake
110 public void handshakeAndNodeUpdate() throws Exception {
112 final TestInventoryListener listener = new TestInventoryListener();
113 BindingAwareConsumer openflowConsumer = new BindingAwareConsumer() {
116 public void onSessionInitialized(ConsumerContext session) {
117 session.getSALService(NotificationService.class).registerNotificationListener(listener);
120 ConsumerContext consumerReg = broker.registerConsumer(openflowConsumer, ctx);
121 assertNotNull(consumerReg);
123 LOG.debug("handshake integration test");
124 LOG.debug("openflowPluginProvider: " + openflowPluginProvider);
126 switchSim.setSecuredClient(false);
127 ScenarioHandler scenario = new ScenarioHandler(ScenarioFactory.createHandshakeScenarioVBM(
128 ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13, true));
129 switchSim.setScenarioHandler(scenario);
130 scenarioPool.execute(switchSim);
132 finalCheck = new Runnable() {
135 assertEquals(1, listener.nodeUpdated.size());
136 assertNotNull(listener.nodeUpdated.get(0));
142 * @return bundle options
145 public Option[] config() {
147 systemProperty("osgi.console").value("2401"),
148 systemProperty("osgi.bundles.defaultStartLevel").value("4"),
149 systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
151 OFPaxOptionsAssistant.osgiConsoleBundles(),
152 OFPaxOptionsAssistant.loggingBudles(),
153 OFPaxOptionsAssistant.ofPluginBundles());
156 private static class TestInventoryListener implements OpendaylightInventoryListener {
158 List<NodeUpdated> nodeUpdated = new ArrayList<>();
159 List<NodeRemoved> nodeRemoved = new ArrayList<>();
160 List<NodeConnectorUpdated> nodeConnectorUpdated = new ArrayList<>();
161 List<NodeConnectorRemoved> nodeConnectorRemoved = new ArrayList<>();
166 protected TestInventoryListener() {
171 public void onNodeUpdated(NodeUpdated notification) {
172 nodeUpdated.add(notification);
176 public void onNodeRemoved(NodeRemoved notification) {
177 nodeRemoved.add(notification);
181 public void onNodeConnectorUpdated(NodeConnectorUpdated notification) {
182 nodeConnectorUpdated.add(notification);
186 public void onNodeConnectorRemoved(NodeConnectorRemoved notification) {
187 nodeConnectorRemoved.add(notification);