1 package org.opendaylight.controller.forwardingrulesmanager.internal;
3 import static junit.framework.Assert.fail;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertNotNull;
6 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
7 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
8 import static org.ops4j.pax.exam.CoreOptions.options;
9 import static org.ops4j.pax.exam.CoreOptions.systemPackages;
10 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
12 import java.net.InetAddress;
13 import java.net.UnknownHostException;
14 import java.util.ArrayList;
15 import java.util.List;
17 import javax.inject.Inject;
19 import org.junit.Assert;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
24 import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
25 import org.opendaylight.controller.sal.action.Action;
26 import org.opendaylight.controller.sal.action.Drop;
27 import org.opendaylight.controller.sal.core.ConstructionException;
28 import org.opendaylight.controller.sal.core.Node;
29 import org.opendaylight.controller.sal.flowprogrammer.Flow;
30 import org.opendaylight.controller.sal.match.Match;
31 import org.opendaylight.controller.sal.match.MatchType;
32 import org.opendaylight.controller.sal.utils.NodeCreator;
33 import org.opendaylight.controller.sal.utils.Status;
34 import org.opendaylight.controller.sal.utils.StatusCode;
35 import org.ops4j.pax.exam.Option;
36 import org.ops4j.pax.exam.junit.Configuration;
37 import org.ops4j.pax.exam.junit.PaxExam;
38 import org.ops4j.pax.exam.util.PathUtils;
39 import org.osgi.framework.Bundle;
40 import org.osgi.framework.BundleContext;
41 import org.osgi.framework.ServiceReference;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
45 @RunWith(PaxExam.class)
46 public class ForwardingRulesManagerIT {
47 private Logger log = LoggerFactory.getLogger(ForwardingRulesManagerIT.class);
48 // get the OSGI bundle context
50 private BundleContext bc;
52 private IForwardingRulesManager manager = null;
54 // Configure the OSGi container
56 public Option[] config() {
59 systemProperty("logback.configurationFile").value(
60 "file:" + PathUtils.getBaseDir()
61 + "/src/test/resources/logback.xml"),
62 // To start OSGi console for inspection remotely
63 systemProperty("osgi.console").value("2401"),
64 // Set the systemPackages (used by clustering)
65 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
66 // List framework bundles
67 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console").versionAsInProject(),
68 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util").versionAsInProject(),
69 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services").versionAsInProject(),
70 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds").versionAsInProject(),
71 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command").versionAsInProject(),
72 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime").versionAsInProject(),
73 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell").versionAsInProject(),
74 // List logger bundles
75 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
76 mavenBundle("org.slf4j", "log4j-over-slf4j")
77 .versionAsInProject(),
78 mavenBundle("ch.qos.logback", "logback-core")
79 .versionAsInProject(),
80 mavenBundle("ch.qos.logback", "logback-classic")
81 .versionAsInProject(),
82 // List all the bundles on which the test case depends
83 mavenBundle("org.opendaylight.controller", "sal")
84 .versionAsInProject(),
85 mavenBundle("org.opendaylight.controller", "sal.implementation")
86 .versionAsInProject(),
88 mavenBundle("org.opendaylight.controller",
89 "protocol_plugins.stub").versionAsInProject(),
91 mavenBundle("org.opendaylight.controller", "containermanager")
92 .versionAsInProject(),
93 mavenBundle("org.opendaylight.controller",
94 "containermanager.it.implementation").versionAsInProject(),
96 mavenBundle("org.opendaylight.controller",
97 "forwardingrulesmanager").versionAsInProject(),
99 mavenBundle("org.opendaylight.controller",
100 "forwardingrulesmanager.implementation")
101 .versionAsInProject(),
103 mavenBundle("org.opendaylight.controller",
104 "clustering.services").versionAsInProject(),
105 mavenBundle("org.opendaylight.controller", "clustering.stub")
106 .versionAsInProject(),
107 mavenBundle("org.opendaylight.controller", "switchmanager")
108 .versionAsInProject(),
109 mavenBundle("org.opendaylight.controller", "statisticsmanager").versionAsInProject(),
110 mavenBundle("org.opendaylight.controller",
111 "switchmanager.implementation").versionAsInProject(),
112 mavenBundle("org.opendaylight.controller", "configuration")
113 .versionAsInProject(),
114 mavenBundle("org.opendaylight.controller",
115 "configuration.implementation").versionAsInProject(),
116 mavenBundle("org.opendaylight.controller", "hosttracker")
117 .versionAsInProject(),
118 mavenBundle("org.opendaylight.controller",
119 "hosttracker.implementation").versionAsInProject(),
120 mavenBundle("org.opendaylight.controller",
121 "connectionmanager.implementation").versionAsInProject(),
122 mavenBundle("org.opendaylight.controller",
123 "connectionmanager").versionAsInProject(),
124 mavenBundle("org.opendaylight.controller",
125 "sal.connection").versionAsInProject(),
126 mavenBundle("org.opendaylight.controller",
127 "sal.connection.implementation").versionAsInProject(),
129 // needed by hosttracker
130 mavenBundle("org.opendaylight.controller", "topologymanager")
131 .versionAsInProject(),
133 mavenBundle("org.jboss.spec.javax.transaction",
134 "jboss-transaction-api_1.1_spec").versionAsInProject(),
135 mavenBundle("org.apache.commons", "commons-lang3")
136 .versionAsInProject(),
137 mavenBundle("org.apache.felix",
138 "org.apache.felix.dependencymanager")
139 .versionAsInProject(), junitBundles());
142 private String stateToString(int state) {
146 case Bundle.INSTALLED:
148 case Bundle.RESOLVED:
150 case Bundle.UNINSTALLED:
151 return "UNINSTALLED";
153 return "Not CONVERTED";
158 public void areWeReady() {
160 boolean debugit = false;
161 Bundle b[] = bc.getBundles();
162 for (Bundle element : b) {
163 int state = element.getState();
164 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
165 log.debug("Bundle:" + element.getSymbolicName() + " state:"
166 + stateToString(state));
171 log.debug("Do some debugging because some bundle is "
175 // Assert if true, if false we are good to go!
176 assertFalse(debugit);
178 ServiceReference r = bc.getServiceReference(IForwardingRulesManager.class.getName());
180 this.manager = (IForwardingRulesManager) bc.getService(r);
182 // If StatisticsManager is null, cannot run tests.
183 assertNotNull(this.manager);
188 public void testFlowEntries() {
189 Flow flow = new Flow();
191 Match match = new Match();
193 match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
194 } catch (UnknownHostException e) {
196 flow.setMatch(match);
197 Action action = new Drop();
199 List<Action> actions = new ArrayList<Action>();
201 flow.setActions(actions);
204 // Must use a node published by the stub protocol plugin else
205 // connection manager will not report it as a local node
206 node = new Node("STUB", 51966);
207 FlowEntry fe = new FlowEntry("g1", "f1", flow, node);
208 Status stat = manager.installFlowEntry(fe);
210 Assert.assertTrue(stat.getCode() == StatusCode.SUCCESS);
211 } catch (ConstructionException e) {
212 // Got a failure while allocating the node
213 fail("Failed while allocating the node " + e.getMessage());