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.TimeUnit;
19 import javax.inject.Inject;
21 import org.junit.Assert;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
26 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
27 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
28 import org.opendaylight.controller.sal.binding.api.NotificationService;
29 import org.opendaylight.controller.test.sal.binding.it.TestHelper;
30 import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
31 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
32 import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.OpendaylightInventoryListener;
38 import org.ops4j.pax.exam.Configuration;
39 import org.ops4j.pax.exam.Option;
40 import org.ops4j.pax.exam.junit.PaxExam;
41 import org.ops4j.pax.exam.util.Filter;
42 import org.osgi.framework.BundleContext;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
47 * Exercise inventory listener ({@link OpendaylightInventoryListener#onNodeUpdated(NodeUpdated)})
49 @RunWith(PaxExam.class)
50 public class SalIntegrationTest {
52 private static final Logger LOG = LoggerFactory.getLogger(SalIntegrationTest.class);
58 BindingAwareBroker broker;
61 @Filter(timeout=20*1000)
62 OpenflowPluginProvider openflowPluginProvider;
65 * @return timeout for case of failure
67 private static long getFailSafeTimeout() {
73 * @throws InterruptedException
76 public void setUp() throws InterruptedException {
77 //FIXME: plugin should provide service exposing startup result via future
82 * test basic integration with OFLib running the handshake
87 public void handshakeAndNodeUpdate() throws Exception {
89 final TestInventoryListener listener = new TestInventoryListener();
90 BindingAwareConsumer openflowConsumer = new BindingAwareConsumer() {
93 public void onSessionInitialized(ConsumerContext session) {
94 session.getSALService(NotificationService.class).registerNotificationListener(listener);
97 ConsumerContext consumerReg = broker.registerConsumer(openflowConsumer, ctx);
98 assertNotNull(consumerReg);
100 LOG.debug("handshake integration test");
101 LOG.debug("openflowPluginProvider: " + openflowPluginProvider);
103 SimpleClient switchSim = new SimpleClient("localhost", 6653);
104 switchSim.setSecuredClient(false);
105 ScenarioHandler scenario = new ScenarioHandler(ScenarioFactory.createHandshakeScenarioVBM(
106 ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13));
107 switchSim.setScenarioHandler(scenario);
111 LOG.debug("tearing down simulator");
112 switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
113 } catch (Exception e) {
114 String msg = "waiting for scenario to finish failed: "+e.getMessage();
120 LOG.debug("checking if simulator succeeded to connect to controller");
121 boolean simulatorWasOnline = switchSim.getIsOnlineFuture().get(100, TimeUnit.MILLISECONDS);
122 Assert.assertTrue("simulator failed to connect to controller", simulatorWasOnline);
123 } catch (Exception e) {
124 String message = "simulator probably failed to connect to controller";
125 LOG.error(message, e);
126 Assert.fail(message);
130 assertEquals(1, listener.nodeUpdated.size());
131 assertNotNull(listener.nodeUpdated.get(0));
135 * @return bundle options
138 public Option[] config() {
139 return options(systemProperty("osgi.console").value("2401"),
140 OFPaxOptionsAssistant.osgiConsoleBundles(),
141 OFPaxOptionsAssistant.loggingBudles(),
143 TestHelper.junitAndMockitoBundles(),
144 TestHelper.mdSalCoreBundles(),
145 TestHelper.configMinumumBundles(),
146 TestHelper.baseModelBundles(),
147 TestHelper.flowCapableModelBundles(),
148 OFPaxOptionsAssistant.ofLibraryBundles(),
149 OFPaxOptionsAssistant.ofPluginBundles()
153 private static class TestInventoryListener implements OpendaylightInventoryListener {
155 List<NodeUpdated> nodeUpdated = new ArrayList<>();
156 List<NodeRemoved> nodeRemoved = new ArrayList<>();
157 List<NodeConnectorUpdated> nodeConnectorUpdated = new ArrayList<>();
158 List<NodeConnectorRemoved> nodeConnectorRemoved = new ArrayList<>();
163 protected TestInventoryListener() {
168 public void onNodeUpdated(NodeUpdated notification) {
169 nodeUpdated.add(notification);
173 public void onNodeRemoved(NodeRemoved notification) {
174 nodeRemoved.add(notification);
178 public void onNodeConnectorUpdated(NodeConnectorUpdated notification) {
179 nodeConnectorUpdated.add(notification);
183 public void onNodeConnectorRemoved(NodeConnectorRemoved notification) {
184 nodeConnectorRemoved.add(notification);