1 package org.opendaylight.controller.forwardingrulesmanager.internal;
3 import static org.junit.Assert.assertFalse;
4 import static org.junit.Assert.assertNotNull;
5 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
6 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
7 import static org.ops4j.pax.exam.CoreOptions.options;
8 import static org.ops4j.pax.exam.CoreOptions.systemPackages;
9 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
11 import java.net.InetAddress;
12 import java.net.UnknownHostException;
13 import java.util.ArrayList;
14 import java.util.List;
16 import javax.inject.Inject;
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
23 import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
24 import org.opendaylight.controller.sal.action.Action;
25 import org.opendaylight.controller.sal.action.Drop;
26 import org.opendaylight.controller.sal.core.ConstructionException;
27 import org.opendaylight.controller.sal.core.Node;
28 import org.opendaylight.controller.sal.flowprogrammer.Flow;
29 import org.opendaylight.controller.sal.match.Match;
30 import org.opendaylight.controller.sal.match.MatchType;
31 import org.opendaylight.controller.sal.utils.NodeCreator;
32 import org.opendaylight.controller.sal.utils.Status;
33 import org.opendaylight.controller.sal.utils.StatusCode;
34 import org.ops4j.pax.exam.Option;
35 import org.ops4j.pax.exam.junit.Configuration;
36 import org.ops4j.pax.exam.junit.PaxExam;
37 import org.ops4j.pax.exam.util.PathUtils;
38 import org.osgi.framework.Bundle;
39 import org.osgi.framework.BundleContext;
40 import org.osgi.framework.ServiceReference;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
44 @RunWith(PaxExam.class)
45 public class ForwardingRulesManagerIT {
46 private Logger log = LoggerFactory.getLogger(ForwardingRulesManagerIT.class);
47 // get the OSGI bundle context
49 private BundleContext bc;
51 private IForwardingRulesManager manager = null;
53 // Configure the OSGi container
55 public Option[] config() {
58 systemProperty("logback.configurationFile").value(
59 "file:" + PathUtils.getBaseDir()
60 + "/src/test/resources/logback.xml"),
61 // To start OSGi console for inspection remotely
62 systemProperty("osgi.console").value("2401"),
63 // Set the systemPackages (used by clustering)
64 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
65 // List framework bundles
66 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console",
67 "1.0.0.v20120522-1841"),
68 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util",
69 "1.0.400.v20120522-2049"),
70 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services",
71 "3.3.100.v20120522-1822"),
72 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds",
73 "1.4.0.v20120522-1841"),
74 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command",
75 "0.8.0.v201108120515"),
76 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime",
77 "0.8.0.v201108120515"),
78 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell",
79 "0.8.0.v201110170705"),
80 // List logger bundles
81 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
82 mavenBundle("org.slf4j", "log4j-over-slf4j")
83 .versionAsInProject(),
84 mavenBundle("ch.qos.logback", "logback-core")
85 .versionAsInProject(),
86 mavenBundle("ch.qos.logback", "logback-classic")
87 .versionAsInProject(),
88 // List all the bundles on which the test case depends
89 mavenBundle("org.opendaylight.controller", "sal")
90 .versionAsInProject(),
91 mavenBundle("org.opendaylight.controller", "sal.implementation")
92 .versionAsInProject(),
94 mavenBundle("org.opendaylight.controller",
95 "protocol_plugins.stub").versionAsInProject(),
97 mavenBundle("org.opendaylight.controller", "containermanager")
98 .versionAsInProject(),
99 mavenBundle("org.opendaylight.controller",
100 "containermanager.implementation").versionAsInProject(),
102 mavenBundle("org.opendaylight.controller",
103 "forwardingrulesmanager").versionAsInProject(),
105 mavenBundle("org.opendaylight.controller",
106 "forwardingrulesmanager.implementation")
107 .versionAsInProject(),
109 mavenBundle("org.opendaylight.controller",
110 "clustering.services").versionAsInProject(),
111 mavenBundle("org.opendaylight.controller", "clustering.stub")
112 .versionAsInProject(),
113 mavenBundle("org.opendaylight.controller", "switchmanager")
114 .versionAsInProject(),
115 mavenBundle("org.opendaylight.controller", "statisticsmanager").versionAsInProject(),
116 mavenBundle("org.opendaylight.controller",
117 "switchmanager.implementation").versionAsInProject(),
118 mavenBundle("org.opendaylight.controller", "configuration")
119 .versionAsInProject(),
120 mavenBundle("org.opendaylight.controller",
121 "configuration.implementation").versionAsInProject(),
122 mavenBundle("org.opendaylight.controller", "hosttracker")
123 .versionAsInProject(),
124 mavenBundle("org.opendaylight.controller",
125 "hosttracker.implementation").versionAsInProject(),
126 mavenBundle("org.opendaylight.controller",
127 "connectionmanager.implementation").versionAsInProject(),
128 mavenBundle("org.opendaylight.controller",
129 "connectionmanager").versionAsInProject(),
130 mavenBundle("org.opendaylight.controller",
131 "sal.connection").versionAsInProject(),
132 mavenBundle("org.opendaylight.controller",
133 "sal.connection.implementation").versionAsInProject(),
135 // needed by hosttracker
136 mavenBundle("org.opendaylight.controller", "topologymanager")
137 .versionAsInProject(),
139 mavenBundle("org.jboss.spec.javax.transaction",
140 "jboss-transaction-api_1.1_spec").versionAsInProject(),
141 mavenBundle("org.apache.commons", "commons-lang3")
142 .versionAsInProject(),
143 mavenBundle("org.apache.felix",
144 "org.apache.felix.dependencymanager")
145 .versionAsInProject(), junitBundles());
148 private String stateToString(int state) {
152 case Bundle.INSTALLED:
154 case Bundle.RESOLVED:
156 case Bundle.UNINSTALLED:
157 return "UNINSTALLED";
159 return "Not CONVERTED";
164 public void areWeReady() {
166 boolean debugit = false;
167 Bundle b[] = bc.getBundles();
168 for (Bundle element : b) {
169 int state = element.getState();
170 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
171 log.debug("Bundle:" + element.getSymbolicName() + " state:"
172 + stateToString(state));
177 log.debug("Do some debugging because some bundle is "
181 // Assert if true, if false we are good to go!
182 assertFalse(debugit);
184 ServiceReference r = bc.getServiceReference(IForwardingRulesManager.class.getName());
186 this.manager = (IForwardingRulesManager) bc.getService(r);
188 // If StatisticsManager is null, cannot run tests.
189 assertNotNull(this.manager);
194 public void testFlowEntries() {
195 Flow flow = new Flow();
197 Match match = new Match();
199 match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
200 } catch (UnknownHostException e) {
202 flow.setMatch(match);
203 Action action = new Drop();
205 List<Action> actions = new ArrayList<Action>();
207 flow.setActions(actions);
210 // Must use a node published by the stub protocol plugin else
211 // connection manager will not report it as a local node
212 node = new Node("STUB", 51966);
213 FlowEntry fe = new FlowEntry("g1", "f1", flow, node);
214 Status stat = manager.installFlowEntry(fe);
216 Assert.assertTrue(stat.getCode() == StatusCode.SUCCESS);
217 } catch (ConstructionException e) {
218 // Got a failure while allocating the node
219 Assert.assertTrue(false);