Merge "Moved parsing of unknown nodes from implementation to abstract classes."
[controller.git] / opendaylight / forwardingrulesmanager / integrationtest / src / test / java / org / opendaylight / controller / forwardingrulesmanager / internal / ForwardingRulesManagerIT.java
1 package org.opendaylight.controller.forwardingrulesmanager.internal;
2
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;
10
11 import java.net.InetAddress;
12 import java.net.UnknownHostException;
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import javax.inject.Inject;
17
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;
42
43 @RunWith(PaxExam.class)
44 public class ForwardingRulesManagerIT {
45     private Logger log = LoggerFactory.getLogger(ForwardingRulesManagerIT.class);
46     // get the OSGI bundle context
47     @Inject
48     private BundleContext bc;
49
50     private IForwardingRulesManager manager = null;
51
52     // Configure the OSGi container
53     @Configuration
54     public Option[] config() {
55         return options(
56                 //
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(),
92
93                 mavenBundle("org.opendaylight.controller",
94                         "protocol_plugins.stub").versionAsInProject(),
95
96                 mavenBundle("org.opendaylight.controller", "containermanager")
97                         .versionAsInProject(),
98                 mavenBundle("org.opendaylight.controller",
99                         "containermanager.implementation").versionAsInProject(),
100
101                 mavenBundle("org.opendaylight.controller",
102                         "forwardingrulesmanager").versionAsInProject(),
103
104                 mavenBundle("org.opendaylight.controller",
105                         "forwardingrulesmanager.implementation")
106                         .versionAsInProject(),
107
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",
115                         "switchmanager.implementation").versionAsInProject(),
116                 mavenBundle("org.opendaylight.controller", "configuration")
117                         .versionAsInProject(),
118
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(),
125
126                 // needed by hosttracker
127                 mavenBundle("org.opendaylight.controller", "topologymanager")
128                         .versionAsInProject(),
129
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());
137     }
138
139     private String stateToString(int state) {
140         switch (state) {
141         case Bundle.ACTIVE:
142             return "ACTIVE";
143         case Bundle.INSTALLED:
144             return "INSTALLED";
145         case Bundle.RESOLVED:
146             return "RESOLVED";
147         case Bundle.UNINSTALLED:
148             return "UNINSTALLED";
149         default:
150             return "Not CONVERTED";
151         }
152     }
153
154     @Before
155     public void areWeReady() {
156         assertNotNull(bc);
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));
164                 debugit = true;
165             }
166         }
167         if (debugit) {
168             log.debug("Do some debugging because some bundle is "
169                     + "unresolved");
170         }
171
172         // Assert if true, if false we are good to go!
173         assertFalse(debugit);
174
175         ServiceReference r = bc.getServiceReference(IForwardingRulesManager.class.getName());
176         if (r != null) {
177             this.manager = (IForwardingRulesManager) bc.getService(r);
178         }
179         // If StatisticsManager is null, cannot run tests.
180         assertNotNull(this.manager);
181
182     }
183
184     @Test
185     public void testFlowEntries() {
186         Flow flow = new Flow();
187
188         Match match = new Match();
189         try {
190             match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
191         } catch (UnknownHostException e) {
192         }
193         flow.setMatch(match);
194         Action action = new Drop();
195
196         List<Action> actions = new ArrayList<Action>();
197         actions.add(action);
198         flow.setActions(actions);
199
200         Node node = NodeCreator.createOFNode(1L);
201         FlowEntry fe = new FlowEntry("g1", "f1", flow, node);
202
203         Status stat = manager.installFlowEntry(fe);
204
205         // OF plugin is not there in integration testing mode
206         Assert.assertTrue(stat.getCode() == StatusCode.NOSERVICE);
207     }
208
209 }