1 package org.opendaylight.controller.forwardingrulesmanager.internal;
3 import java.net.InetAddress;
4 import java.net.UnknownHostException;
5 import java.util.ArrayList;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9 import org.osgi.framework.ServiceReference;
10 import org.osgi.framework.Bundle;
11 import javax.inject.Inject;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.junit.Before;
16 import org.junit.runner.RunWith;
17 import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
18 import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
19 import org.opendaylight.controller.sal.action.Action;
20 import org.opendaylight.controller.sal.action.Drop;
21 import org.opendaylight.controller.sal.core.Node;
22 import org.opendaylight.controller.sal.flowprogrammer.Flow;
23 import org.opendaylight.controller.sal.match.Match;
24 import org.opendaylight.controller.sal.match.MatchType;
25 import org.opendaylight.controller.sal.utils.NodeCreator;
26 import org.opendaylight.controller.sal.utils.Status;
27 import org.opendaylight.controller.sal.utils.StatusCode;
28 import org.ops4j.pax.exam.junit.PaxExam;
29 import org.osgi.framework.BundleContext;
30 import static org.junit.Assert.*;
31 import org.ops4j.pax.exam.junit.Configuration;
32 import static org.ops4j.pax.exam.CoreOptions.*;
34 import org.ops4j.pax.exam.Option;
35 import org.ops4j.pax.exam.util.PathUtils;
37 @RunWith(PaxExam.class)
38 public class ForwardingRulesManagerIT {
39 private Logger log = LoggerFactory.getLogger(ForwardingRulesManagerIT.class);
40 // get the OSGI bundle context
42 private BundleContext bc;
44 private IForwardingRulesManager manager = null;
46 // Configure the OSGi container
48 public Option[] config() {
51 systemProperty("logback.configurationFile").value(
52 "file:" + PathUtils.getBaseDir()
53 + "/src/test/resources/logback.xml"),
54 // To start OSGi console for inspection remotely
55 systemProperty("osgi.console").value("2401"),
56 // Set the systemPackages (used by clustering)
57 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
58 // List framework bundles
59 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console",
60 "1.0.0.v20120522-1841"),
61 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util",
62 "1.0.400.v20120522-2049"),
63 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services",
64 "3.3.100.v20120522-1822"),
65 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds",
66 "1.4.0.v20120522-1841"),
67 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command",
68 "0.8.0.v201108120515"),
69 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime",
70 "0.8.0.v201108120515"),
71 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell",
72 "0.8.0.v201110170705"),
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",
109 "switchmanager.implementation").versionAsInProject(),
110 mavenBundle("org.opendaylight.controller", "configuration")
111 .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(),
120 // needed by hosttracker
121 mavenBundle("org.opendaylight.controller", "topologymanager")
122 .versionAsInProject(),
124 mavenBundle("org.jboss.spec.javax.transaction",
125 "jboss-transaction-api_1.1_spec").versionAsInProject(),
126 mavenBundle("org.apache.commons", "commons-lang3")
127 .versionAsInProject(),
128 mavenBundle("org.apache.felix",
129 "org.apache.felix.dependencymanager")
130 .versionAsInProject(), junitBundles());
133 private String stateToString(int state) {
137 case Bundle.INSTALLED:
139 case Bundle.RESOLVED:
141 case Bundle.UNINSTALLED:
142 return "UNINSTALLED";
144 return "Not CONVERTED";
149 public void areWeReady() {
151 boolean debugit = false;
152 Bundle b[] = bc.getBundles();
153 for (Bundle element : b) {
154 int state = element.getState();
155 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
156 log.debug("Bundle:" + element.getSymbolicName() + " state:"
157 + stateToString(state));
162 log.debug("Do some debugging because some bundle is "
166 // Assert if true, if false we are good to go!
167 assertFalse(debugit);
169 ServiceReference r = bc
170 .getServiceReference(IForwardingRulesManager.class.getName());
172 this.manager = (IForwardingRulesManager) bc.getService(r);
174 // If StatisticsManager is null, cannot run tests.
175 assertNotNull(this.manager);
180 public void testFlowEntries() {
181 Flow flow = new Flow();
183 Match match = new Match();
185 match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
186 } catch (UnknownHostException e) {
188 flow.setMatch(match);
189 Action action = new Drop();
191 List<Action> actions = new ArrayList<Action>();
193 flow.setActions(actions);
195 Node node = NodeCreator.createOFNode(1L);
196 FlowEntry fe = new FlowEntry("g1", "f1", flow, node);
198 Status stat = manager.installFlowEntry(null);
199 Assert.assertTrue(stat.getCode().equals(StatusCode.NOTACCEPTABLE));