Removed old legacy code and moved parent pom.xml to root
[openflowplugin.git] / openflowplugin-it / src / test / java / org / opendaylight / openflowplugin / openflow / md / it / OFPluginToLibraryTest.java
1 package org.opendaylight.openflowplugin.openflow.md.it;
2
3 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
4 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
5 import static org.ops4j.pax.exam.CoreOptions.options;
6 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
7
8 import java.util.Stack;
9 import java.util.concurrent.TimeUnit;
10
11 import javax.inject.Inject;
12
13 import junit.framework.Assert;
14
15 import org.junit.After;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.opendaylight.controller.test.sal.binding.it.TestHelper;
19 import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent;
20 import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
21 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
22 import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent;
23 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
24 import org.ops4j.pax.exam.Configuration;
25 import org.ops4j.pax.exam.Option;
26 import org.ops4j.pax.exam.junit.PaxExam;
27 import org.osgi.framework.BundleContext;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * @author mirehak
33  */
34 @RunWith(PaxExam.class)
35 public class OFPluginToLibraryTest {
36
37     private static final Logger LOG = LoggerFactory
38             .getLogger(OFPluginToLibraryTest.class);
39
40     /** base controller package */
41     public static final String ODL = "org.opendaylight.controller";
42     /** controller.model package */
43     public static final String ODL_MODEL = "org.opendaylight.controller.model";
44     /** yangtools package */
45     public static final String YANG = "org.opendaylight.yangtools";
46     /** yangtools.model package */
47     public static final String YANG_MODEL = "org.opendaylight.yangtools.model";
48     /** OFPlugin package */
49     public static final String OFPLUGIN = "org.opendaylight.openflowplugin";
50     /** OFLibrary package */
51     public static final String OFLIBRARY = "org.opendaylight.openflowjava";
52     /** netty.io package */
53     public static final String NETTY = "io.netty";
54
55     @Inject
56     SwitchConnectionProvider switchConnectionProvider;
57
58     @Inject
59     BundleContext ctx;
60
61     private SimpleClient switchSim;
62
63     /**
64      * test tear down
65      */
66     @After
67     public void tearDown() {
68         try {
69             LOG.debug("tearing down simulator");
70             switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
71         } catch (Exception e) {
72             String msg = "waiting for scenario to finish failed: "+e.getMessage();
73             LOG.error(msg, e);
74             Assert.fail(msg);
75         }
76     }
77
78     /**
79      * test basic integration with OFLib running the handshake
80      * @throws Exception
81      */
82     @Test
83     public void handshakeOk1() throws Exception {
84         LOG.debug("handshake integration test");
85         LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
86
87         switchSim = new SimpleClient("localhost", 6653);
88         switchSim.setSecuredClient(false);
89         Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenarioVBM(
90                 ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
91
92         ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
93         switchSim.setScenarioHandler(scenario);
94         switchSim.start();
95         try {
96             switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
97         } catch (Exception e) {
98             String msg = "waiting for scenario to finish failed: "+e.getMessage();
99             LOG.error(msg, e);
100             Assert.fail(msg);
101         }
102         //TODO: dump errors of plugin
103     }
104
105     /**
106      * test basic integration with OFLib running the handshake (with version bitmap)
107      * @throws Exception
108      */
109     @Test
110     public void handshakeOk2() throws Exception {
111         LOG.debug("handshake integration test");
112         LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
113
114         switchSim = new SimpleClient("localhost", 6653);
115         switchSim.setSecuredClient(false);
116         Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario(
117                 (short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
118
119         ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
120         switchSim.setScenarioHandler(scenario);
121         switchSim.start();
122         try {
123             switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
124         } catch (Exception e) {
125             String msg = "waiting for scenario to finish failed: "+e.getMessage();
126             LOG.error(msg, e);
127             Assert.fail(msg);
128         }
129         //TODO: dump errors of plugin
130     }
131
132     /**
133      * test basic integration with OFLib running the handshake
134      * @throws Exception
135      */
136     @Test
137     public void handshakeFail1() throws Exception {
138         LOG.debug("handshake integration test");
139         LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
140
141         switchSim = new SimpleClient("localhost", 6653);
142         switchSim.setSecuredClient(false);
143         Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 1,
144                 ScenarioFactory.VERSION_BITMAP_10_13);
145
146         ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
147         switchSim.setScenarioHandler(scenario);
148         switchSim.start();
149         try {
150             switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
151         } catch (Exception e) {
152             String msg = "waiting for scenario to finish failed: "+e.getMessage();
153             LOG.error(msg, e);
154             Assert.fail(msg);
155         }
156         //TODO: dump errors of plugin
157     }
158
159     /**
160      * test basic integration with OFLib running the handshake
161      * @throws Exception
162      */
163     @Test
164     public void handshakeFail2() throws Exception {
165         LOG.debug("handshake integration test");
166         LOG.debug("switchConnectionProvider: "+switchConnectionProvider);
167
168         switchSim = new SimpleClient("localhost", 6653);
169         switchSim.setSecuredClient(false);
170         Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 1,
171                 ScenarioFactory.VERSION_BITMAP_10_13);
172         handshakeScenario.setElementAt(new SleepEvent(5000), 0);
173
174         ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
175         switchSim.setScenarioHandler(scenario);
176         switchSim.start();
177         tearDown();
178         //TODO: dump errors of plugin
179     }
180
181     /**
182      * @return timeout for case of failure
183      */
184     private static long getFailSafeTimeout() {
185         return 20000;
186     }
187
188
189     /**
190      * @return bundle options
191      */
192     @Configuration
193     public Option[] config() {
194         return options(
195                 systemProperty("osgi.console").value("2401"),
196                 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
197                 mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(),
198                 mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(),
199                 mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(),
200                 mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager").versionAsInProject(),
201                 TestHelper.mdSalCoreBundles(), TestHelper.bindingAwareSalBundles(),
202                 TestHelper.flowCapableModelBundles(), TestHelper.baseModelBundles(),
203
204
205                 mavenBundle(ODL, "sal").versionAsInProject(),
206                 mavenBundle(ODL, "sal.connection").versionAsInProject(),
207                 mavenBundle(ODL, "sal-common").versionAsInProject(),
208
209                 mavenBundle(ODL_MODEL, "model-flow-statistics").versionAsInProject(),
210
211                 mavenBundle(OFLIBRARY, "openflow-protocol-impl").versionAsInProject(),
212                 mavenBundle(OFLIBRARY, "openflow-protocol-api").versionAsInProject(),
213                 mavenBundle(OFLIBRARY, "openflow-protocol-spi").versionAsInProject(),
214
215                 mavenBundle(NETTY, "netty-handler").versionAsInProject(),
216                 mavenBundle(NETTY, "netty-buffer").versionAsInProject(),
217                 mavenBundle(NETTY, "netty-common").versionAsInProject(),
218                 mavenBundle(NETTY, "netty-transport").versionAsInProject(),
219                 mavenBundle(NETTY, "netty-codec").versionAsInProject(),
220
221                 mavenBundle(OFLIBRARY, "simple-client").versionAsInProject().start(),
222                 mavenBundle(OFPLUGIN, "openflowplugin").versionAsInProject(),
223                 junitBundles());
224     }
225
226 }