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").versionAsInProject(),
67 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util").versionAsInProject(),
68 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services").versionAsInProject(),
69 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds").versionAsInProject(),
70 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command").versionAsInProject(),
71 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime").versionAsInProject(),
72 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell").versionAsInProject(),
73 // List logger bundles
74 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
75 mavenBundle("org.slf4j", "log4j-over-slf4j")
76 .versionAsInProject(),
77 mavenBundle("ch.qos.logback", "logback-core")
78 .versionAsInProject(),
79 mavenBundle("ch.qos.logback", "logback-classic")
80 .versionAsInProject(),
81 // List all the bundles on which the test case depends
82 mavenBundle("org.opendaylight.controller", "sal")
83 .versionAsInProject(),
84 mavenBundle("org.opendaylight.controller", "sal.implementation")
85 .versionAsInProject(),
87 mavenBundle("org.opendaylight.controller",
88 "protocol_plugins.stub").versionAsInProject(),
90 mavenBundle("org.opendaylight.controller", "containermanager")
91 .versionAsInProject(),
92 mavenBundle("org.opendaylight.controller",
93 "containermanager.implementation").versionAsInProject(),
95 mavenBundle("org.opendaylight.controller",
96 "forwardingrulesmanager").versionAsInProject(),
98 mavenBundle("org.opendaylight.controller",
99 "forwardingrulesmanager.implementation")
100 .versionAsInProject(),
102 mavenBundle("org.opendaylight.controller",
103 "clustering.services").versionAsInProject(),
104 mavenBundle("org.opendaylight.controller", "clustering.stub")
105 .versionAsInProject(),
106 mavenBundle("org.opendaylight.controller", "switchmanager")
107 .versionAsInProject(),
108 mavenBundle("org.opendaylight.controller", "statisticsmanager").versionAsInProject(),
109 mavenBundle("org.opendaylight.controller",
110 "switchmanager.implementation").versionAsInProject(),
111 mavenBundle("org.opendaylight.controller", "configuration")
112 .versionAsInProject(),
113 mavenBundle("org.opendaylight.controller",
114 "configuration.implementation").versionAsInProject(),
115 mavenBundle("org.opendaylight.controller", "hosttracker")
116 .versionAsInProject(),
117 mavenBundle("org.opendaylight.controller",
118 "hosttracker.implementation").versionAsInProject(),
119 mavenBundle("org.opendaylight.controller",
120 "connectionmanager.implementation").versionAsInProject(),
121 mavenBundle("org.opendaylight.controller",
122 "connectionmanager").versionAsInProject(),
123 mavenBundle("org.opendaylight.controller",
124 "sal.connection").versionAsInProject(),
125 mavenBundle("org.opendaylight.controller",
126 "sal.connection.implementation").versionAsInProject(),
128 // needed by hosttracker
129 mavenBundle("org.opendaylight.controller", "topologymanager")
130 .versionAsInProject(),
132 mavenBundle("org.jboss.spec.javax.transaction",
133 "jboss-transaction-api_1.1_spec").versionAsInProject(),
134 mavenBundle("org.apache.commons", "commons-lang3")
135 .versionAsInProject(),
136 mavenBundle("org.apache.felix",
137 "org.apache.felix.dependencymanager")
138 .versionAsInProject(), junitBundles());
141 private String stateToString(int state) {
145 case Bundle.INSTALLED:
147 case Bundle.RESOLVED:
149 case Bundle.UNINSTALLED:
150 return "UNINSTALLED";
152 return "Not CONVERTED";
157 public void areWeReady() {
159 boolean debugit = false;
160 Bundle b[] = bc.getBundles();
161 for (Bundle element : b) {
162 int state = element.getState();
163 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
164 log.debug("Bundle:" + element.getSymbolicName() + " state:"
165 + stateToString(state));
170 log.debug("Do some debugging because some bundle is "
174 // Assert if true, if false we are good to go!
175 assertFalse(debugit);
177 ServiceReference r = bc.getServiceReference(IForwardingRulesManager.class.getName());
179 this.manager = (IForwardingRulesManager) bc.getService(r);
181 // If StatisticsManager is null, cannot run tests.
182 assertNotNull(this.manager);
187 public void testFlowEntries() {
188 Flow flow = new Flow();
190 Match match = new Match();
192 match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
193 } catch (UnknownHostException e) {
195 flow.setMatch(match);
196 Action action = new Drop();
198 List<Action> actions = new ArrayList<Action>();
200 flow.setActions(actions);
203 // Must use a node published by the stub protocol plugin else
204 // connection manager will not report it as a local node
205 node = new Node("STUB", 51966);
206 FlowEntry fe = new FlowEntry("g1", "f1", flow, node);
207 Status stat = manager.installFlowEntry(fe);
209 Assert.assertTrue(stat.getCode() == StatusCode.SUCCESS);
210 } catch (ConstructionException e) {
211 // Got a failure while allocating the node
212 Assert.assertTrue(false);