1 package org.opendaylight.controller.forwardingrulesmanager.internal;
3 import java.net.InetAddress;
4 import java.net.UnknownHostException;
5 import java.util.ArrayList;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
11 import org.osgi.framework.ServiceReference;
12 import org.osgi.framework.Bundle;
13 import javax.inject.Inject;
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.junit.Before;
18 import org.junit.runner.RunWith;
19 import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
20 import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
21 import org.opendaylight.controller.sal.action.Action;
22 import org.opendaylight.controller.sal.action.Drop;
23 import org.opendaylight.controller.sal.core.Node;
24 import org.opendaylight.controller.sal.core.NodeConnector;
25 import org.opendaylight.controller.sal.flowprogrammer.Flow;
26 import org.opendaylight.controller.sal.match.Match;
27 import org.opendaylight.controller.sal.match.MatchType;
28 import org.opendaylight.controller.sal.reader.FlowOnNode;
29 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
30 import org.opendaylight.controller.sal.reader.NodeDescription;
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.junit.PaxExam;
35 import org.osgi.framework.BundleContext;
36 import static org.junit.Assert.*;
37 import org.ops4j.pax.exam.junit.Configuration;
38 import static org.ops4j.pax.exam.CoreOptions.*;
40 import org.ops4j.pax.exam.Option;
41 import org.ops4j.pax.exam.util.PathUtils;
43 @RunWith(PaxExam.class)
44 public class FRMIntegrationTest {
45 private Logger log = LoggerFactory.getLogger(FRMIntegrationTest.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", "1.7.2"),
81 mavenBundle("org.slf4j", "log4j-over-slf4j", "1.7.2"),
82 mavenBundle("ch.qos.logback", "logback-core", "1.0.9"),
83 mavenBundle("ch.qos.logback", "logback-classic", "1.0.9"),
84 // List all the bundles on which the test case depends
85 mavenBundle("org.opendaylight.controller", "sal",
87 mavenBundle("org.opendaylight.controller",
88 "sal.implementation", "0.4.0-SNAPSHOT"),
90 mavenBundle("org.opendaylight.controller",
91 "protocol_plugins.stub", "0.4.0-SNAPSHOT"),
93 mavenBundle("org.opendaylight.controller", "containermanager",
95 mavenBundle("org.opendaylight.controller",
96 "containermanager.implementation", "0.4.0-SNAPSHOT"),
98 mavenBundle("org.opendaylight.controller",
99 "forwardingrulesmanager", "0.4.0-SNAPSHOT"),
101 mavenBundle("org.opendaylight.controller",
102 "forwardingrulesmanager.implementation",
105 mavenBundle("org.opendaylight.controller",
106 "clustering.services", "0.4.0-SNAPSHOT"),
107 mavenBundle("org.opendaylight.controller", "clustering.stub",
109 mavenBundle("org.opendaylight.controller", "switchmanager",
111 mavenBundle("org.opendaylight.controller", "switchmanager.implementation",
113 mavenBundle("org.opendaylight.controller", "configuration",
116 mavenBundle("org.opendaylight.controller",
117 "configuration.implementation", "0.4.0-SNAPSHOT"),
118 mavenBundle("org.opendaylight.controller", "hosttracker",
120 mavenBundle("org.opendaylight.controller", "hosttracker.implementation",
123 // needed by hosttracker
124 mavenBundle("org.opendaylight.controller", "topologymanager",
127 mavenBundle("org.jboss.spec.javax.transaction",
128 "jboss-transaction-api_1.1_spec", "1.0.1.Final"),
129 mavenBundle("org.apache.commons", "commons-lang3", "3.1"),
130 mavenBundle("org.apache.felix",
131 "org.apache.felix.dependencymanager", "3.1.0"),
135 private String stateToString(int state) {
139 case Bundle.INSTALLED:
141 case Bundle.RESOLVED:
143 case Bundle.UNINSTALLED:
144 return "UNINSTALLED";
146 return "Not CONVERTED";
151 public void areWeReady() {
153 boolean debugit = false;
154 Bundle b[] = bc.getBundles();
155 for (int i = 0; i < b.length; i++) {
156 int state = b[i].getState();
157 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
158 log.debug("Bundle:" + b[i].getSymbolicName() + " state:"
159 + stateToString(state));
164 log.debug("Do some debugging because some bundle is "
168 // Assert if true, if false we are good to go!
169 assertFalse(debugit);
171 ServiceReference r = bc
172 .getServiceReference(IForwardingRulesManager.class.getName());
174 this.manager = (IForwardingRulesManager) bc.getService(r);
176 // If StatisticsManager is null, cannot run tests.
177 assertNotNull(this.manager);
182 public void testFlowEntries() {
183 Flow flow = new Flow();
185 Match match = new Match();
187 match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
188 } catch (UnknownHostException e) {
190 flow.setMatch(match);
191 Action action = new Drop();
193 List<Action> actions = new ArrayList<Action>();
195 flow.setActions(actions);
197 Node node = NodeCreator.createOFNode(1L);
198 FlowEntry fe = new FlowEntry("g1", "f1", flow, node);
200 Status stat = manager.installFlowEntry(null);
201 Assert.assertTrue(stat.getCode().equals(StatusCode.NOTACCEPTABLE));