1 package org.opendaylight.openflowplugin.openflow.md.it;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.baseModelBundles;
6 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.bindingAwareSalBundles;
7 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.configMinumumBundles;
8 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.flowCapableModelBundles;
9 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.mdSalCoreBundles;
10 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
11 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
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.Test;
22 import org.junit.runner.RunWith;
23 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
24 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
25 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
26 import org.opendaylight.controller.sal.binding.api.NotificationService;
27 import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
28 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
29 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.OpendaylightInventoryListener;
35 import org.ops4j.pax.exam.Configuration;
36 import org.ops4j.pax.exam.Option;
37 import org.ops4j.pax.exam.junit.PaxExam;
38 import org.osgi.framework.BundleContext;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
45 //@RunWith(PaxExam.class)
46 public class SalIntegrationTest {
48 private static final Logger LOG = LoggerFactory.getLogger(SalIntegrationTest.class);
50 /** base controller package */
51 public static final String ODL = "org.opendaylight.controller";
52 /** controller.model package */
53 public static final String ODL_MODEL = "org.opendaylight.controller.model";
54 /** yangtools package */
55 public static final String YANG = "org.opendaylight.yangtools";
56 /** yangtools.model package */
57 public static final String YANG_MODEL = "org.opendaylight.yangtools.model";
58 /** OFPlugin package */
59 public static final String OFPLUGIN = "org.opendaylight.openflowplugin";
60 /** OFLibrary package */
61 public static final String OFLIBRARY = "org.opendaylight.openflowjava";
62 /** netty.io package */
63 public static final String NETTY = "io.netty";
66 SwitchConnectionProvider switchConnectionProvider;
72 BindingAwareBroker broker;
75 * @return timeout for case of failure
77 private static long getFailSafeTimeout() {
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("switchConnectionProvider: " + switchConnectionProvider);
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);
110 switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
112 assertEquals(1, listener.nodeUpdated.size());
113 assertNotNull(listener.nodeUpdated.get(0));
118 * @return bundle options
121 public Option[] config() {
122 return options(systemProperty("osgi.console").value("2401"),
123 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
124 mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(),
125 mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(),
126 mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(),
128 mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager").versionAsInProject(),
130 mavenBundle(OFLIBRARY, "openflow-protocol-impl").versionAsInProject(),
131 mavenBundle(OFLIBRARY, "openflow-protocol-api").versionAsInProject(),
132 mavenBundle(OFLIBRARY, "openflow-protocol-spi").versionAsInProject(),
134 mavenBundle(ODL, "sal").versionAsInProject(),
135 mavenBundle(ODL, "sal.connection").versionAsInProject(),
136 mdSalCoreBundles(), baseModelBundles(), flowCapableModelBundles(),
137 configMinumumBundles(),
139 bindingAwareSalBundles(),
141 mavenBundle(NETTY, "netty-handler").versionAsInProject(),
142 mavenBundle(NETTY, "netty-buffer").versionAsInProject(),
143 mavenBundle(NETTY, "netty-common").versionAsInProject(),
144 mavenBundle(NETTY, "netty-transport").versionAsInProject(),
145 mavenBundle(NETTY, "netty-codec").versionAsInProject(),
147 mavenBundle(OFLIBRARY, "simple-client").versionAsInProject().start(),
148 mavenBundle(OFPLUGIN, "openflowplugin").versionAsInProject(), junitBundles(),
149 mavenBundle("org.opendaylight.controller.thirdparty", "org.openflow.openflowj").versionAsInProject()
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);