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