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.Node;
27 import org.opendaylight.controller.sal.flowprogrammer.Flow;
28 import org.opendaylight.controller.sal.match.Match;
29 import org.opendaylight.controller.sal.match.MatchType;
30 import org.opendaylight.controller.sal.utils.NodeCreator;
31 import org.opendaylight.controller.sal.utils.Status;
32 import org.opendaylight.controller.sal.utils.StatusCode;
33 import org.ops4j.pax.exam.Option;
34 import org.ops4j.pax.exam.junit.Configuration;
35 import org.ops4j.pax.exam.junit.PaxExam;
36 import org.ops4j.pax.exam.util.PathUtils;
37 import org.osgi.framework.Bundle;
38 import org.osgi.framework.BundleContext;
39 import org.osgi.framework.ServiceReference;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
43 @RunWith(PaxExam.class)
44 public class ForwardingRulesManagerIT {
45 private Logger log = LoggerFactory.getLogger(ForwardingRulesManagerIT.class);
46 // get the OSGI bundle context
48 private BundleContext bc;
50 private IForwardingRulesManager manager = null;
52 // Configure the OSGi container
54 public Option[] config() {
57 systemProperty("logback.configurationFile").value(
58 "file:" + PathUtils.getBaseDir()
59 + "/src/test/resources/logback.xml"),
60 // To start OSGi console for inspection remotely
61 systemProperty("osgi.console").value("2401"),
62 // Set the systemPackages (used by clustering)
63 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
64 // List framework bundles
65 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console",
66 "1.0.0.v20120522-1841"),
67 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util",
68 "1.0.400.v20120522-2049"),
69 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services",
70 "3.3.100.v20120522-1822"),
71 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds",
72 "1.4.0.v20120522-1841"),
73 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command",
74 "0.8.0.v201108120515"),
75 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime",
76 "0.8.0.v201108120515"),
77 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell",
78 "0.8.0.v201110170705"),
79 // List logger bundles
80 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
81 mavenBundle("org.slf4j", "log4j-over-slf4j")
82 .versionAsInProject(),
83 mavenBundle("ch.qos.logback", "logback-core")
84 .versionAsInProject(),
85 mavenBundle("ch.qos.logback", "logback-classic")
86 .versionAsInProject(),
87 // List all the bundles on which the test case depends
88 mavenBundle("org.opendaylight.controller", "sal")
89 .versionAsInProject(),
90 mavenBundle("org.opendaylight.controller", "sal.implementation")
91 .versionAsInProject(),
93 mavenBundle("org.opendaylight.controller",
94 "protocol_plugins.stub").versionAsInProject(),
96 mavenBundle("org.opendaylight.controller", "containermanager")
97 .versionAsInProject(),
98 mavenBundle("org.opendaylight.controller",
99 "containermanager.implementation").versionAsInProject(),
101 mavenBundle("org.opendaylight.controller",
102 "forwardingrulesmanager").versionAsInProject(),
104 mavenBundle("org.opendaylight.controller",
105 "forwardingrulesmanager.implementation")
106 .versionAsInProject(),
108 mavenBundle("org.opendaylight.controller",
109 "clustering.services").versionAsInProject(),
110 mavenBundle("org.opendaylight.controller", "clustering.stub")
111 .versionAsInProject(),
112 mavenBundle("org.opendaylight.controller", "switchmanager")
113 .versionAsInProject(),
114 mavenBundle("org.opendaylight.controller", "statisticsmanager").versionAsInProject(),
115 mavenBundle("org.opendaylight.controller",
116 "switchmanager.implementation").versionAsInProject(),
117 mavenBundle("org.opendaylight.controller", "configuration")
118 .versionAsInProject(),
119 mavenBundle("org.opendaylight.controller",
120 "configuration.implementation").versionAsInProject(),
121 mavenBundle("org.opendaylight.controller", "hosttracker")
122 .versionAsInProject(),
123 mavenBundle("org.opendaylight.controller",
124 "hosttracker.implementation").versionAsInProject(),
126 // needed by hosttracker
127 mavenBundle("org.opendaylight.controller", "topologymanager")
128 .versionAsInProject(),
130 mavenBundle("org.jboss.spec.javax.transaction",
131 "jboss-transaction-api_1.1_spec").versionAsInProject(),
132 mavenBundle("org.apache.commons", "commons-lang3")
133 .versionAsInProject(),
134 mavenBundle("org.apache.felix",
135 "org.apache.felix.dependencymanager")
136 .versionAsInProject(), junitBundles());
139 private String stateToString(int state) {
143 case Bundle.INSTALLED:
145 case Bundle.RESOLVED:
147 case Bundle.UNINSTALLED:
148 return "UNINSTALLED";
150 return "Not CONVERTED";
155 public void areWeReady() {
157 boolean debugit = false;
158 Bundle b[] = bc.getBundles();
159 for (Bundle element : b) {
160 int state = element.getState();
161 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
162 log.debug("Bundle:" + element.getSymbolicName() + " state:"
163 + stateToString(state));
168 log.debug("Do some debugging because some bundle is "
172 // Assert if true, if false we are good to go!
173 assertFalse(debugit);
175 ServiceReference r = bc.getServiceReference(IForwardingRulesManager.class.getName());
177 this.manager = (IForwardingRulesManager) bc.getService(r);
179 // If StatisticsManager is null, cannot run tests.
180 assertNotNull(this.manager);
185 public void testFlowEntries() {
186 Flow flow = new Flow();
188 Match match = new Match();
190 match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
191 } catch (UnknownHostException e) {
193 flow.setMatch(match);
194 Action action = new Drop();
196 List<Action> actions = new ArrayList<Action>();
198 flow.setActions(actions);
200 Node node = NodeCreator.createOFNode(1L);
201 FlowEntry fe = new FlowEntry("g1", "f1", flow, node);
203 Status stat = manager.installFlowEntry(fe);
205 // OF plugin is not there in integration testing mode
206 Assert.assertTrue(stat.getCode() == StatusCode.NOSERVICE);