Merge "Ensuring that SET_DL_* action with openflowj only uses OFP_ETH_ALEN bytes...
[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 java.net.InetAddress;
4 import java.net.UnknownHostException;
5 import java.util.ArrayList;
6 import java.util.List;
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;
12
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.*;
33
34 import org.ops4j.pax.exam.Option;
35 import org.ops4j.pax.exam.util.PathUtils;
36
37 @RunWith(PaxExam.class)
38 public class ForwardingRulesManagerIT {
39     private Logger log = LoggerFactory.getLogger(ForwardingRulesManagerIT.class);
40     // get the OSGI bundle context
41     @Inject
42     private BundleContext bc;
43
44     private IForwardingRulesManager manager = null;
45
46     // Configure the OSGi container
47     @Configuration
48     public Option[] config() {
49         return options(
50                 //
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(),
86
87                 mavenBundle("org.opendaylight.controller",
88                         "protocol_plugins.stub").versionAsInProject(),
89
90                 mavenBundle("org.opendaylight.controller", "containermanager")
91                         .versionAsInProject(),
92                 mavenBundle("org.opendaylight.controller",
93                         "containermanager.implementation").versionAsInProject(),
94
95                 mavenBundle("org.opendaylight.controller",
96                         "forwardingrulesmanager").versionAsInProject(),
97
98                 mavenBundle("org.opendaylight.controller",
99                         "forwardingrulesmanager.implementation")
100                         .versionAsInProject(),
101
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(),
112
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(),
119
120                 // needed by hosttracker
121                 mavenBundle("org.opendaylight.controller", "topologymanager")
122                         .versionAsInProject(),
123
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());
131     }
132
133     private String stateToString(int state) {
134         switch (state) {
135         case Bundle.ACTIVE:
136             return "ACTIVE";
137         case Bundle.INSTALLED:
138             return "INSTALLED";
139         case Bundle.RESOLVED:
140             return "RESOLVED";
141         case Bundle.UNINSTALLED:
142             return "UNINSTALLED";
143         default:
144             return "Not CONVERTED";
145         }
146     }
147
148     @Before
149     public void areWeReady() {
150         assertNotNull(bc);
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));
158                 debugit = true;
159             }
160         }
161         if (debugit) {
162             log.debug("Do some debugging because some bundle is "
163                     + "unresolved");
164         }
165
166         // Assert if true, if false we are good to go!
167         assertFalse(debugit);
168
169         ServiceReference r = bc
170                 .getServiceReference(IForwardingRulesManager.class.getName());
171         if (r != null) {
172             this.manager = (IForwardingRulesManager) bc.getService(r);
173         }
174         // If StatisticsManager is null, cannot run tests.
175         assertNotNull(this.manager);
176
177     }
178
179     @Test
180     public void testFlowEntries() {
181         Flow flow = new Flow();
182
183         Match match = new Match();
184         try {
185             match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
186         } catch (UnknownHostException e) {
187         }
188         flow.setMatch(match);
189         Action action = new Drop();
190
191         List<Action> actions = new ArrayList<Action>();
192         actions.add(action);
193         flow.setActions(actions);
194
195         Node node = NodeCreator.createOFNode(1L);
196         FlowEntry fe = new FlowEntry("g1", "f1", flow, node);
197
198         Status stat = manager.installFlowEntry(null);
199         Assert.assertTrue(stat.getCode().equals(StatusCode.NOTACCEPTABLE));
200     }
201
202 }