Merge "Fix exception in HostTracker when non-OF node is removed."
[controller.git] / opendaylight / forwardingrulesmanager / integrationtest / src / test / java / org / opendaylight / controller / forwardingrulesmanager / internal / FRMIntegrationTest.java
1 package org.opendaylight.controller.forwardingrulesmanager.internal;
2
3 import java.net.InetAddress;
4 import java.net.UnknownHostException;
5 import java.util.ArrayList;
6 import java.util.List;
7 import java.util.Map;
8
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;
14
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.*;
39
40 import org.ops4j.pax.exam.Option;
41 import org.ops4j.pax.exam.util.PathUtils;
42
43 @RunWith(PaxExam.class)
44 public class FRMIntegrationTest {
45     private Logger log = LoggerFactory.getLogger(FRMIntegrationTest.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", "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",
86                         "0.5.0-SNAPSHOT"),
87                 mavenBundle("org.opendaylight.controller",
88                         "sal.implementation", "0.4.0-SNAPSHOT"),
89
90                 mavenBundle("org.opendaylight.controller",
91                         "protocol_plugins.stub", "0.4.0-SNAPSHOT"),
92                
93                 mavenBundle("org.opendaylight.controller", "containermanager",
94                         "0.4.0-SNAPSHOT"),
95                 mavenBundle("org.opendaylight.controller",
96                         "containermanager.implementation", "0.4.0-SNAPSHOT"),
97
98                 mavenBundle("org.opendaylight.controller",
99                         "forwardingrulesmanager", "0.4.0-SNAPSHOT"),
100
101                 mavenBundle("org.opendaylight.controller",
102                         "forwardingrulesmanager.implementation",
103                         "0.4.0-SNAPSHOT"),
104
105                 mavenBundle("org.opendaylight.controller",
106                         "clustering.services", "0.4.0-SNAPSHOT"),
107                 mavenBundle("org.opendaylight.controller", "clustering.stub",
108                         "0.4.0-SNAPSHOT"),
109                 mavenBundle("org.opendaylight.controller", "switchmanager",
110                         "0.4.0-SNAPSHOT"),
111                 mavenBundle("org.opendaylight.controller", "switchmanager.implementation",
112                                 "0.4.0-SNAPSHOT"),
113                 mavenBundle("org.opendaylight.controller", "configuration",
114                         "0.4.0-SNAPSHOT"),
115
116                 mavenBundle("org.opendaylight.controller",
117                         "configuration.implementation", "0.4.0-SNAPSHOT"),
118                 mavenBundle("org.opendaylight.controller", "hosttracker",
119                         "0.4.0-SNAPSHOT"),
120                 mavenBundle("org.opendaylight.controller", "hosttracker.implementation",
121                                 "0.4.0-SNAPSHOT"),
122
123                 // needed by hosttracker
124                 mavenBundle("org.opendaylight.controller", "topologymanager",
125                         "0.4.0-SNAPSHOT"),
126
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"),
132                 junitBundles());
133     }
134
135     private String stateToString(int state) {
136         switch (state) {
137         case Bundle.ACTIVE:
138             return "ACTIVE";
139         case Bundle.INSTALLED:
140             return "INSTALLED";
141         case Bundle.RESOLVED:
142             return "RESOLVED";
143         case Bundle.UNINSTALLED:
144             return "UNINSTALLED";
145         default:
146             return "Not CONVERTED";
147         }
148     }
149
150     @Before
151     public void areWeReady() {
152         assertNotNull(bc);
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));
160                 debugit = true;
161             }
162         }
163         if (debugit) {
164             log.debug("Do some debugging because some bundle is "
165                     + "unresolved");
166         }
167
168         // Assert if true, if false we are good to go!
169         assertFalse(debugit);
170
171         ServiceReference r = bc
172                 .getServiceReference(IForwardingRulesManager.class.getName());
173         if (r != null) {
174             this.manager = (IForwardingRulesManager) bc.getService(r);
175         }
176         // If StatisticsManager is null, cannot run tests.
177         assertNotNull(this.manager);
178
179     }
180
181     @Test
182     public void testFlowEntries() {
183         Flow flow = new Flow();
184
185         Match match = new Match();
186         try {
187             match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
188         } catch (UnknownHostException e) {
189         }
190         flow.setMatch(match);
191         Action action = new Drop();
192
193         List<Action> actions = new ArrayList<Action>();
194         actions.add(action);
195         flow.setActions(actions);
196
197         Node node = NodeCreator.createOFNode(1L);
198         FlowEntry fe = new FlowEntry("g1", "f1", flow, node);
199
200         Status stat = manager.installFlowEntry(null);
201         Assert.assertTrue(stat.getCode().equals(StatusCode.NOTACCEPTABLE));
202     }
203
204 }