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.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
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.osgi.framework.BundleContext;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
46 * Exercise inventory listener ({@link OpendaylightInventoryListener#onNodeUpdated(NodeUpdated)})
48 @RunWith(PaxExam.class)
49 public class SalIntegrationTest {
51 private static final Logger LOG = LoggerFactory.getLogger(SalIntegrationTest.class);
54 SwitchConnectionProvider switchConnectionProvider;
60 BindingAwareBroker broker;
63 * @return timeout for case of failure
65 private static long getFailSafeTimeout() {
71 * @throws InterruptedException
74 public void setUp() throws InterruptedException {
75 //FIXME: plugin should provide service exposing startup result via future
80 * test basic integration with OFLib running the handshake
85 public void handshakeAndNodeUpdate() throws Exception {
87 final TestInventoryListener listener = new TestInventoryListener();
88 BindingAwareConsumer openflowConsumer = new BindingAwareConsumer() {
91 public void onSessionInitialized(ConsumerContext session) {
92 session.getSALService(NotificationService.class).registerNotificationListener(listener);
95 ConsumerContext consumerReg = broker.registerConsumer(openflowConsumer, ctx);
96 assertNotNull(consumerReg);
98 LOG.debug("handshake integration test");
99 LOG.debug("switchConnectionProvider: " + switchConnectionProvider);
101 SimpleClient switchSim = new SimpleClient("localhost", 6653);
102 switchSim.setSecuredClient(false);
103 ScenarioHandler scenario = new ScenarioHandler(ScenarioFactory.createHandshakeScenarioVBM(
104 ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13));
105 switchSim.setScenarioHandler(scenario);
109 LOG.debug("tearing down simulator");
110 switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
111 } catch (Exception e) {
112 String msg = "waiting for scenario to finish failed: "+e.getMessage();
118 LOG.debug("checking if simulator succeeded to connect to controller");
119 boolean simulatorWasOnline = switchSim.getIsOnlineFuture().get(100, TimeUnit.MILLISECONDS);
120 Assert.assertTrue("simulator failed to connect to controller", simulatorWasOnline);
121 } catch (Exception e) {
122 String message = "simulator probably failed to connect to controller";
123 LOG.error(message, e);
124 Assert.fail(message);
128 assertEquals(1, listener.nodeUpdated.size());
129 assertNotNull(listener.nodeUpdated.get(0));
133 * @return bundle options
136 public Option[] config() {
137 return options(systemProperty("osgi.console").value("2401"),
138 OFPaxOptionsAssistant.osgiConsoleBundles(),
139 OFPaxOptionsAssistant.loggingBudles(),
141 TestHelper.junitAndMockitoBundles(),
142 TestHelper.mdSalCoreBundles(),
143 TestHelper.configMinumumBundles(),
144 TestHelper.baseModelBundles(),
145 TestHelper.flowCapableModelBundles(),
147 OFPaxOptionsAssistant.ofPluginBundles()
151 private static class TestInventoryListener implements OpendaylightInventoryListener {
153 List<NodeUpdated> nodeUpdated = new ArrayList<>();
154 List<NodeRemoved> nodeRemoved = new ArrayList<>();
155 List<NodeConnectorUpdated> nodeConnectorUpdated = new ArrayList<>();
156 List<NodeConnectorRemoved> nodeConnectorRemoved = new ArrayList<>();
161 protected TestInventoryListener() {
166 public void onNodeUpdated(NodeUpdated notification) {
167 nodeUpdated.add(notification);
171 public void onNodeRemoved(NodeRemoved notification) {
172 nodeRemoved.add(notification);
176 public void onNodeConnectorUpdated(NodeConnectorUpdated notification) {
177 nodeConnectorUpdated.add(notification);
181 public void onNodeConnectorRemoved(NodeConnectorRemoved notification) {
182 nodeConnectorRemoved.add(notification);