Merge "Parents pom distribution"
[controller.git] / opendaylight / northbound / integrationtest / src / test / java / org / opendaylight / controller / northbound / integrationtest / NorthboundIT.java
1 package org.opendaylight.controller.northbound.integrationtest;
2
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5 import org.osgi.framework.ServiceReference;
6 import org.osgi.framework.Bundle;
7 import javax.inject.Inject;
8
9 import org.junit.Assert;
10 import org.junit.Test;
11 import org.junit.Before;
12 import org.junit.runner.RunWith;
13 import org.ops4j.pax.exam.junit.PaxExam;
14 import org.osgi.framework.BundleContext;
15 import static org.junit.Assert.*;
16 import org.ops4j.pax.exam.junit.Configuration;
17 import static org.ops4j.pax.exam.CoreOptions.*;
18 import org.ops4j.pax.exam.Option;
19 import org.ops4j.pax.exam.util.PathUtils;
20 import java.io.BufferedReader;
21 import java.io.InputStream;
22 import java.io.InputStreamReader;
23 import java.io.OutputStreamWriter;
24 import java.net.HttpURLConnection;
25 import java.net.URL;
26 import java.nio.charset.Charset;
27 import java.util.Arrays;
28
29 import org.apache.commons.codec.binary.Base64;
30
31 import org.codehaus.jettison.json.JSONArray;
32 import org.codehaus.jettison.json.JSONException;
33 import org.codehaus.jettison.json.JSONObject;
34 import org.codehaus.jettison.json.JSONTokener;
35
36 import org.opendaylight.controller.hosttracker.IfIptoHost;
37 import org.opendaylight.controller.sal.core.ConstructionException;
38 import org.opendaylight.controller.sal.core.Node;
39 import org.opendaylight.controller.sal.core.NodeConnector;
40 import org.opendaylight.controller.sal.core.UpdateType;
41 import org.opendaylight.controller.switchmanager.IInventoryListener;
42 import org.opendaylight.controller.usermanager.IUserManager;
43
44 @RunWith(PaxExam.class)
45 public class NorthboundIT {
46     private Logger log = LoggerFactory.getLogger(NorthboundIT.class);
47     // get the OSGI bundle context
48     @Inject
49     private BundleContext bc;
50     private IUserManager users = null;
51     private IInventoryListener invtoryListener = null;
52
53     private String stateToString(int state) {
54         switch (state) {
55         case Bundle.ACTIVE:
56             return "ACTIVE";
57         case Bundle.INSTALLED:
58             return "INSTALLED";
59         case Bundle.RESOLVED:
60             return "RESOLVED";
61         case Bundle.UNINSTALLED:
62             return "UNINSTALLED";
63         default:
64             return "Not CONVERTED";
65         }
66     }
67
68     @Before
69     public void areWeReady() {
70         assertNotNull(bc);
71         boolean debugit = false;
72         Bundle b[] = bc.getBundles();
73         for (int i = 0; i < b.length; i++) {
74             int state = b[i].getState();
75             if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
76                 log.debug("Bundle:" + b[i].getSymbolicName() + " state:"
77                         + stateToString(state));
78                 debugit = true;
79             }
80         }
81         if (debugit) {
82             log.debug("Do some debugging because some bundle is "
83                     + "unresolved");
84         }
85         // Assert if true, if false we are good to go!
86         assertFalse(debugit);
87
88         ServiceReference r = bc.getServiceReference(IUserManager.class
89                 .getName());
90         if (r != null) {
91             this.users = (IUserManager) bc.getService(r);
92         }
93         // If UserManager is null, cannot login to run tests.
94         assertNotNull(this.users);
95
96         r = bc.getServiceReference(IfIptoHost.class.getName());
97         if (r != null) {
98             this.invtoryListener = (IInventoryListener) bc.getService(r);
99         }
100
101         // If inventoryListener is null, cannot run hosttracker tests.
102         assertNotNull(this.invtoryListener);
103
104     }
105
106     // static variable to pass response code from getJsonResult()
107     private static Integer httpResponseCode = null;
108
109     private String getJsonResult(String restUrl) {
110         return getJsonResult(restUrl, "GET", null);
111     }
112
113     private String getJsonResult(String restUrl, String method) {
114         return getJsonResult(restUrl, method, null);
115     }
116
117     private String getJsonResult(String restUrl, String method, String body) {
118         // initialize response code to indicate error
119         httpResponseCode = 400;
120
121         try {
122             URL url = new URL(restUrl);
123             this.users.getAuthorizationList();
124             this.users.authenticate("admin", "admin");
125             String authString = "admin:admin";
126             byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
127             String authStringEnc = new String(authEncBytes);
128
129             HttpURLConnection connection = (HttpURLConnection) url
130                     .openConnection();
131             connection.setRequestMethod(method);
132             connection.setRequestProperty("Authorization", "Basic "
133                     + authStringEnc);
134             connection.setRequestProperty("Content-Type", "application/json");
135             connection.setRequestProperty("Accept", "application/json");
136
137             if (body != null) {
138                 connection.setDoOutput(true);
139                 OutputStreamWriter wr = new OutputStreamWriter(
140                         connection.getOutputStream());
141                 wr.write(body);
142                 wr.flush();
143             }
144             connection.connect();
145             connection.getContentType();
146
147             // Response code for success should be 2xx
148             httpResponseCode = connection.getResponseCode();
149             if (httpResponseCode > 299)
150                 return httpResponseCode.toString();
151
152             InputStream is = connection.getInputStream();
153             BufferedReader rd = new BufferedReader(new InputStreamReader(is,
154                     Charset.forName("UTF-8")));
155             StringBuilder sb = new StringBuilder();
156             int cp;
157             while ((cp = rd.read()) != -1) {
158                 sb.append((char) cp);
159             }
160             is.close();
161             connection.disconnect();
162             return sb.toString();
163         } catch (Exception e) {
164             return null;
165         }
166     }
167
168     private void testNodeProperties(JSONObject node, Integer nodeId,
169             String nodeType, Integer timestamp, String timestampName,
170             Integer actionsValue, Integer capabilitiesValue,
171             Integer tablesValue, Integer buffersValue) throws JSONException {
172
173         JSONObject nodeInfo = node.getJSONObject("node");
174         Assert.assertEquals(nodeId, (Integer) nodeInfo.getInt("@id"));
175         Assert.assertEquals(nodeType, nodeInfo.getString("@type"));
176
177         JSONObject properties = node.getJSONObject("properties");
178
179         if (timestamp == null || timestampName == null) {
180             Assert.assertFalse(properties.has("timeStamp"));
181         } else {
182             Assert.assertEquals(
183                     timestamp,
184                     (Integer) properties.getJSONObject("timeStamp").getInt(
185                             "timestamp"));
186             Assert.assertEquals(
187                     timestampName,
188                     properties.getJSONObject("timeStamp").getString(
189                             "timestampName"));
190         }
191         if (actionsValue == null) {
192             Assert.assertFalse(properties.has("actions"));
193         } else {
194             Assert.assertEquals(actionsValue, (Integer) properties
195                     .getJSONObject("actions").getInt("actionsValue"));
196         }
197         if (capabilitiesValue == null) {
198             Assert.assertFalse(properties.has("capabilities"));
199         } else {
200             Assert.assertEquals(capabilitiesValue, (Integer) properties
201                     .getJSONObject("capabilities").getInt("capabilitiesValue"));
202         }
203         if (tablesValue == null) {
204             Assert.assertFalse(properties.has("tables"));
205         } else {
206             Assert.assertEquals(tablesValue, (Integer) properties
207                     .getJSONObject("tables").getInt("tablesValue"));
208         }
209         if (buffersValue == null) {
210             Assert.assertFalse(properties.has("buffers"));
211         } else {
212             Assert.assertEquals(buffersValue, (Integer) properties
213                     .getJSONObject("buffers").getInt("buffersValue"));
214         }
215     }
216
217     private void testNodeConnectorProperties(
218             JSONObject nodeConnectorProperties, Integer ncId, String ncType,
219             Integer nodeId, String nodeType, Integer state,
220             Integer capabilities, Integer bandwidth) throws JSONException {
221
222         JSONObject nodeConnector = nodeConnectorProperties
223                 .getJSONObject("nodeconnector");
224         JSONObject node = nodeConnector.getJSONObject("node");
225         JSONObject properties = nodeConnectorProperties
226                 .getJSONObject("properties");
227
228         Assert.assertEquals(ncId, (Integer) nodeConnector.getInt("@id"));
229         Assert.assertEquals(ncType, nodeConnector.getString("@type"));
230         Assert.assertEquals(nodeId, (Integer) node.getInt("@id"));
231         Assert.assertEquals(nodeType, node.getString("@type"));
232         if (state == null) {
233             Assert.assertFalse(properties.has("state"));
234         } else {
235             Assert.assertEquals(
236                     state,
237                     (Integer) properties.getJSONObject("state").getInt(
238                             "stateValue"));
239         }
240         if (capabilities == null) {
241             Assert.assertFalse(properties.has("capabilities"));
242         } else {
243             Assert.assertEquals(capabilities, (Integer) properties
244                     .getJSONObject("capabilities").getInt("capabilitiesValue"));
245         }
246         if (bandwidth == null) {
247             Assert.assertFalse(properties.has("bandwidth"));
248         } else {
249             Assert.assertEquals(
250                     bandwidth,
251                     (Integer) properties.getJSONObject("bandwidth").getInt(
252                             "bandwidthValue"));
253         }
254
255     }
256
257     @Test
258     public void testSubnetsNorthbound() throws JSONException {
259         String baseURL = "http://127.0.0.1:8080/controller/nb/v2/subnet/";
260
261         String name1 = "testSubnet1";
262         String subnet1 = "1.1.1.1/24";
263         String name2 = "testSubnet2";
264         String subnet2 = "2.2.2.2/24";
265
266         // Test GET subnets in default container
267         String result = getJsonResult(baseURL + "default");
268         JSONTokener jt = new JSONTokener(result);
269         JSONObject json = new JSONObject(jt);
270         Assert.assertEquals("{}", result);
271
272         // Test GET subnet1 expecting 404
273         result = getJsonResult(baseURL + "default/" + name1);
274         Assert.assertEquals(404, httpResponseCode.intValue());
275
276         // Test POST subnet1
277         String queryParameter = new QueryParameter("subnetName", name1).add(
278                 "subnet", subnet1).getString();
279         result = getJsonResult(baseURL + "default/" + name1 + queryParameter,
280                 "POST");
281         Assert.assertEquals(201, httpResponseCode.intValue());
282
283         // Test GET subnet1
284         result = getJsonResult(baseURL + "default/" + name1);
285         jt = new JSONTokener(result);
286         json = new JSONObject(jt);
287         Assert.assertEquals(200, httpResponseCode.intValue());
288         Assert.assertEquals(name1, json.getString("@name"));
289         Assert.assertEquals(subnet1, json.getString("@subnet"));
290
291         // Test POST subnet2
292         queryParameter = new QueryParameter("subnetName", name2).add("subnet",
293                 subnet2).getString();
294         result = getJsonResult(baseURL + "default/" + name2 + queryParameter,
295                 "POST");
296         Assert.assertEquals(201, httpResponseCode.intValue());
297
298         // Test GET all subnets in default container
299         result = getJsonResult(baseURL + "default");
300         jt = new JSONTokener(result);
301         json = new JSONObject(jt);
302         JSONArray subnetConfigArray = json.getJSONArray("subnetConfig");
303         JSONObject subnetConfig;
304         Assert.assertEquals(2, subnetConfigArray.length());
305         for (int i = 0; i < subnetConfigArray.length(); i++) {
306             subnetConfig = subnetConfigArray.getJSONObject(i);
307             if (subnetConfig.getString("@name").equals(name1)) {
308                 Assert.assertEquals(subnet1, subnetConfig.getString("@subnet"));
309             } else if (subnetConfig.getString("@name").equals(name2)) {
310                 Assert.assertEquals(subnet2, subnetConfig.getString("@subnet"));
311             } else {
312                 // Unexpected config name
313                 Assert.assertTrue(false);
314             }
315         }
316
317         // Test DELETE subnet1
318         result = getJsonResult(baseURL + "default/" + name1, "DELETE");
319         Assert.assertEquals(200, httpResponseCode.intValue());
320
321         // Test GET deleted subnet1
322         result = getJsonResult(baseURL + "default/" + name1);
323         Assert.assertEquals(404, httpResponseCode.intValue());
324
325     }
326
327     @Test
328     public void testStaticRoutingNorthbound() throws JSONException {
329         String baseURL = "http://127.0.0.1:8080/controller/nb/v2/staticroute/";
330
331         String name1 = "testRoute1";
332         String prefix1 = "192.168.1.1/24";
333         String nextHop1 = "0.0.0.0";
334         String name2 = "testRoute2";
335         String prefix2 = "192.168.1.1/16";
336         String nextHop2 = "1.1.1.1";
337
338         // Test GET static routes in default container, expecting no results
339         String result = getJsonResult(baseURL + "default");
340         JSONTokener jt = new JSONTokener(result);
341         JSONObject json = new JSONObject(jt);
342         Assert.assertEquals("{}", result);
343
344         // Test insert static route
345         String requestBody = "{\"name\":\"" + name1 + "\", \"prefix\":\""
346                 + prefix1 + "\", \"nextHop\":\"" + nextHop1 + "\"}";
347         result = getJsonResult(baseURL + "default/" + name1, "POST",
348                 requestBody);
349         Assert.assertEquals(201, httpResponseCode.intValue());
350
351         requestBody = "{\"name\":\"" + name2 + "\", \"prefix\":\"" + prefix2
352                 + "\", \"nextHop\":\"" + nextHop2 + "\"}";
353         result = getJsonResult(baseURL + "default/" + name2, "POST",
354                 requestBody);
355         Assert.assertEquals(201, httpResponseCode.intValue());
356
357         // Test Get all static routes
358         result = getJsonResult(baseURL + "default");
359         jt = new JSONTokener(result);
360         json = new JSONObject(jt);
361         JSONArray staticRoutes = json.getJSONArray("staticRoute");
362         Assert.assertEquals(2, staticRoutes.length());
363         JSONObject route;
364         for (int i = 0; i < staticRoutes.length(); i++) {
365             route = staticRoutes.getJSONObject(i);
366             if (route.getString("name").equals(name1)) {
367                 Assert.assertEquals(prefix1, route.getString("prefix"));
368                 Assert.assertEquals(nextHop1, route.getString("nextHop"));
369             } else if (route.getString("name").equals(name2)) {
370                 Assert.assertEquals(prefix2, route.getString("prefix"));
371                 Assert.assertEquals(nextHop2, route.getString("nextHop"));
372             } else {
373                 // static route has unknown name
374                 Assert.assertTrue(false);
375             }
376         }
377
378         // Test get specific static route
379         result = getJsonResult(baseURL + "default/" + name1);
380         jt = new JSONTokener(result);
381         json = new JSONObject(jt);
382
383         Assert.assertEquals(name1, json.getString("name"));
384         Assert.assertEquals(prefix1, json.getString("prefix"));
385         Assert.assertEquals(nextHop1, json.getString("nextHop"));
386
387         result = getJsonResult(baseURL + "default/" + name2);
388         jt = new JSONTokener(result);
389         json = new JSONObject(jt);
390
391         Assert.assertEquals(name2, json.getString("name"));
392         Assert.assertEquals(prefix2, json.getString("prefix"));
393         Assert.assertEquals(nextHop2, json.getString("nextHop"));
394
395         // Test delete static route
396         result = getJsonResult(baseURL + "default/" + name1, "DELETE");
397         Assert.assertEquals(200, httpResponseCode.intValue());
398
399         result = getJsonResult(baseURL + "default");
400         jt = new JSONTokener(result);
401         json = new JSONObject(jt);
402         JSONObject singleStaticRoute = json.getJSONObject("staticRoute");
403         Assert.assertEquals(name2, singleStaticRoute.getString("name"));
404
405     }
406
407     @Test
408     public void testSwitchManager() throws JSONException {
409         String baseURL = "http://127.0.0.1:8080/controller/nb/v2/switch/default/";
410
411         // define Node/NodeConnector attributes for test
412         int nodeId_1 = 51966;
413         int nodeId_2 = 3366;
414         int nodeId_3 = 4477;
415         int nodeConnectorId_1 = 51966;
416         int nodeConnectorId_2 = 12;
417         int nodeConnectorId_3 = 34;
418         String nodeType = "STUB";
419         String ncType = "STUB";
420         int timestamp_1 = 100000;
421         String timestampName_1 = "connectedSince";
422         int actionsValue_1 = 2;
423         int capabilitiesValue_1 = 3;
424         int tablesValue_1 = 1;
425         int buffersValue_1 = 1;
426         int ncState = 1;
427         int ncCapabilities = 1;
428         int ncBandwidth = 1000000000;
429
430         // Test GET all nodes
431
432         String result = getJsonResult(baseURL + "nodes");
433         JSONTokener jt = new JSONTokener(result);
434         JSONObject json = new JSONObject(jt);
435
436         // Test for first node
437         JSONObject node = getJsonInstance(json, "nodeProperties", nodeId_1);
438         Assert.assertNotNull(node);
439         testNodeProperties(node, nodeId_1, nodeType, timestamp_1,
440                 timestampName_1, actionsValue_1, capabilitiesValue_1,
441                 tablesValue_1, buffersValue_1);
442
443         // Test 2nd node, properties of 2nd node same as first node
444         node = getJsonInstance(json, "nodeProperties", nodeId_2);
445         Assert.assertNotNull(node);
446         testNodeProperties(node, nodeId_2, nodeType, timestamp_1,
447                 timestampName_1, actionsValue_1, capabilitiesValue_1,
448                 tablesValue_1, buffersValue_1);
449
450         // Test 3rd node, properties of 3rd node same as first node
451         node = getJsonInstance(json, "nodeProperties", nodeId_3);
452         Assert.assertNotNull(node);
453         testNodeProperties(node, nodeId_3, nodeType, timestamp_1,
454                 timestampName_1, actionsValue_1, capabilitiesValue_1,
455                 tablesValue_1, buffersValue_1);
456
457         // Test GET nodeConnectors of a node
458         // Test first node
459         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1);
460         jt = new JSONTokener(result);
461         json = new JSONObject(jt);
462         JSONObject nodeConnectorProperties = json
463                 .getJSONObject("nodeConnectorProperties");
464
465         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_1,
466                 ncType, nodeId_1, nodeType, ncState, ncCapabilities,
467                 ncBandwidth);
468
469         // Test second node
470         result = getJsonResult(baseURL + "node/STUB/" + nodeId_2);
471         jt = new JSONTokener(result);
472         json = new JSONObject(jt);
473         nodeConnectorProperties = json.getJSONObject("nodeConnectorProperties");
474
475         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_2,
476                 ncType, nodeId_2, nodeType, ncState, ncCapabilities,
477                 ncBandwidth);
478
479         // Test third node
480         result = getJsonResult(baseURL + "node/STUB/" + nodeId_3);
481         jt = new JSONTokener(result);
482         json = new JSONObject(jt);
483
484         nodeConnectorProperties = json.getJSONObject("nodeConnectorProperties");
485         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_3,
486                 ncType, nodeId_3, nodeType, ncState, ncCapabilities,
487                 ncBandwidth);
488
489         // Test delete node property
490         // Delete timestamp property from node1
491         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1
492                 + "/property/timeStamp", "DELETE");
493         Assert.assertEquals(200, httpResponseCode.intValue());
494
495         // Check node1
496         result = getJsonResult(baseURL + "nodes");
497         jt = new JSONTokener(result);
498         json = new JSONObject(jt);
499         node = getJsonInstance(json, "nodeProperties", nodeId_1);
500         Assert.assertNotNull(node);
501         testNodeProperties(node, nodeId_1, nodeType, null, null,
502                 actionsValue_1, capabilitiesValue_1, tablesValue_1,
503                 buffersValue_1);
504
505         // Delete actions property from node2
506         result = getJsonResult(baseURL + "node/STUB/" + nodeId_2
507                 + "/property/actions", "DELETE");
508         Assert.assertEquals(200, httpResponseCode.intValue());
509
510         // Check node2
511         result = getJsonResult(baseURL + "nodes");
512         jt = new JSONTokener(result);
513         json = new JSONObject(jt);
514         node = getJsonInstance(json, "nodeProperties", nodeId_2);
515         Assert.assertNotNull(node);
516         testNodeProperties(node, nodeId_2, nodeType, timestamp_1,
517                 timestampName_1, null, capabilitiesValue_1, tablesValue_1,
518                 buffersValue_1);
519
520         // Test add property to node
521         // Add Tier and Bandwidth property to node1
522         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1
523                 + "/property/tier/1001", "PUT");
524         Assert.assertEquals(201, httpResponseCode.intValue());
525         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1
526                 + "/property/bandwidth/1002", "PUT");
527         Assert.assertEquals(201, httpResponseCode.intValue());
528
529         // Test for first node
530         result = getJsonResult(baseURL + "nodes");
531         jt = new JSONTokener(result);
532         json = new JSONObject(jt);
533         node = getJsonInstance(json, "nodeProperties", nodeId_1);
534         Assert.assertNotNull(node);
535         Assert.assertEquals(1001, node.getJSONObject("properties")
536                 .getJSONObject("tier").getInt("tierValue"));
537         Assert.assertEquals(1002, node.getJSONObject("properties")
538                 .getJSONObject("bandwidth").getInt("bandwidthValue"));
539
540         // Test delete nodeConnector property
541         // Delete state property of nodeconnector1
542         result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_1
543                 + "/STUB/" + nodeConnectorId_1 + "/property/state", "DELETE");
544         Assert.assertEquals(200, httpResponseCode.intValue());
545
546         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1);
547         jt = new JSONTokener(result);
548         json = new JSONObject(jt);
549         nodeConnectorProperties = json.getJSONObject("nodeConnectorProperties");
550
551         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_1,
552                 ncType, nodeId_1, nodeType, null, ncCapabilities, ncBandwidth);
553
554         // Delete capabilities property of nodeconnector2
555         result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_2
556                 + "/STUB/" + nodeConnectorId_2 + "/property/capabilities",
557                 "DELETE");
558         Assert.assertEquals(200, httpResponseCode.intValue());
559
560         result = getJsonResult(baseURL + "node/STUB/" + nodeId_2);
561         jt = new JSONTokener(result);
562         json = new JSONObject(jt);
563         nodeConnectorProperties = json.getJSONObject("nodeConnectorProperties");
564
565         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_2,
566                 ncType, nodeId_2, nodeType, ncState, null, ncBandwidth);
567
568         // Test PUT nodeConnector property
569         int newBandwidth = 1001;
570
571         // Add Name/Bandwidth property to nodeConnector1
572         result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_1
573                 + "/STUB/" + nodeConnectorId_1 + "/property/bandwidth/"
574                 + newBandwidth, "PUT");
575         Assert.assertEquals(201, httpResponseCode.intValue());
576
577         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1);
578         jt = new JSONTokener(result);
579         json = new JSONObject(jt);
580         nodeConnectorProperties = json.getJSONObject("nodeConnectorProperties");
581
582         // Check for new bandwidth value, state value removed from previous
583         // test
584         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_1,
585                 ncType, nodeId_1, nodeType, null, ncCapabilities, newBandwidth);
586
587     }
588
589     @Test
590     public void testStatistics() throws JSONException {
591         String actionTypes[] = { "drop", "loopback", "flood", "floodAll",
592                 "controller", "swPath", "hwPath", "output", "setDlSrc",
593                 "setDlDst", "setDlType", "setVlanId", "setVlanPcp",
594                 "setVlanCfi", "popVlan", "pushVlan", "setNwSrc", "setNwDst",
595                 "setNwTos", "setTpSrc", "setTpDst" };
596         System.out.println("Starting Statistics JAXB client.");
597
598         String baseURL = "http://127.0.0.1:8080/controller/nb/v2/statistics/default/";
599
600         String result = getJsonResult(baseURL + "flowstats");
601         JSONTokener jt = new JSONTokener(result);
602         JSONObject json = new JSONObject(jt);
603         JSONObject flowStatistics = getJsonInstance(json, "flowStatistics",
604                 0xCAFE);
605         JSONObject node = flowStatistics.getJSONObject("node");
606         // test that node was returned properly
607         Assert.assertTrue(node.getInt("@id") == 0xCAFE);
608         Assert.assertTrue(node.getString("@type").equals("STUB"));
609
610         // test that flow statistics results are correct
611         JSONArray flowStats = flowStatistics.getJSONArray("flowStat");
612         for (int i = 0; i < flowStats.length(); i++) {
613
614             JSONObject flowStat = flowStats.getJSONObject(i);
615             testFlowStat(flowStat, actionTypes[i]);
616
617         }
618
619         // for /controller/nb/v2/statistics/default/portstats
620         result = getJsonResult(baseURL + "portstats");
621         jt = new JSONTokener(result);
622         json = new JSONObject(jt);
623         JSONObject portStatistics = getJsonInstance(json, "portStatistics",
624                 0xCAFE);
625         JSONObject node2 = portStatistics.getJSONObject("node");
626         // test that node was returned properly
627         Assert.assertTrue(node2.getInt("@id") == 0xCAFE);
628         Assert.assertTrue(node2.getString("@type").equals("STUB"));
629
630         // test that port statistic results are correct
631         JSONObject portStat = portStatistics.getJSONObject("portStat");
632         Assert.assertTrue(portStat.getInt("receivePackets") == 250);
633         Assert.assertTrue(portStat.getInt("transmitPackets") == 500);
634         Assert.assertTrue(portStat.getInt("receiveBytes") == 1000);
635         Assert.assertTrue(portStat.getInt("transmitBytes") == 5000);
636         Assert.assertTrue(portStat.getInt("receiveDrops") == 2);
637         Assert.assertTrue(portStat.getInt("transmitDrops") == 50);
638         Assert.assertTrue(portStat.getInt("receiveErrors") == 3);
639         Assert.assertTrue(portStat.getInt("transmitErrors") == 10);
640         Assert.assertTrue(portStat.getInt("receiveFrameError") == 5);
641         Assert.assertTrue(portStat.getInt("receiveOverRunError") == 6);
642         Assert.assertTrue(portStat.getInt("receiveCrcError") == 1);
643         Assert.assertTrue(portStat.getInt("collisionCount") == 4);
644
645         // test for getting one specific node's stats
646         result = getJsonResult(baseURL + "flowstats/STUB/51966");
647         jt = new JSONTokener(result);
648         json = new JSONObject(jt);
649         node = json.getJSONObject("node");
650         // test that node was returned properly
651         Assert.assertTrue(node.getInt("@id") == 0xCAFE);
652         Assert.assertTrue(node.getString("@type").equals("STUB"));
653
654         // test that flow statistics results are correct
655         flowStats = json.getJSONArray("flowStat");
656         for (int i = 0; i < flowStats.length(); i++) {
657             JSONObject flowStat = flowStats.getJSONObject(i);
658             testFlowStat(flowStat, actionTypes[i]);
659         }
660
661         result = getJsonResult(baseURL + "portstats/STUB/51966");
662         jt = new JSONTokener(result);
663         json = new JSONObject(jt);
664         node2 = json.getJSONObject("node");
665         // test that node was returned properly
666         Assert.assertTrue(node2.getInt("@id") == 0xCAFE);
667         Assert.assertTrue(node2.getString("@type").equals("STUB"));
668
669         // test that port statistic results are correct
670         portStat = json.getJSONObject("portStat");
671         Assert.assertTrue(portStat.getInt("receivePackets") == 250);
672         Assert.assertTrue(portStat.getInt("transmitPackets") == 500);
673         Assert.assertTrue(portStat.getInt("receiveBytes") == 1000);
674         Assert.assertTrue(portStat.getInt("transmitBytes") == 5000);
675         Assert.assertTrue(portStat.getInt("receiveDrops") == 2);
676         Assert.assertTrue(portStat.getInt("transmitDrops") == 50);
677         Assert.assertTrue(portStat.getInt("receiveErrors") == 3);
678         Assert.assertTrue(portStat.getInt("transmitErrors") == 10);
679         Assert.assertTrue(portStat.getInt("receiveFrameError") == 5);
680         Assert.assertTrue(portStat.getInt("receiveOverRunError") == 6);
681         Assert.assertTrue(portStat.getInt("receiveCrcError") == 1);
682         Assert.assertTrue(portStat.getInt("collisionCount") == 4);
683     }
684
685     private void testFlowStat(JSONObject flowStat, String actionType)
686             throws JSONException {
687         Assert.assertTrue(flowStat.getInt("tableId") == 1);
688         Assert.assertTrue(flowStat.getInt("durationSeconds") == 40);
689         Assert.assertTrue(flowStat.getInt("durationNanoseconds") == 400);
690         Assert.assertTrue(flowStat.getInt("packetCount") == 200);
691         Assert.assertTrue(flowStat.getInt("byteCount") == 100);
692
693         // test that flow information is correct
694         JSONObject flow = flowStat.getJSONObject("flow");
695         Assert.assertTrue(flow.getInt("priority") == 3500);
696         Assert.assertTrue(flow.getInt("idleTimeout") == 1000);
697         Assert.assertTrue(flow.getInt("hardTimeout") == 2000);
698         Assert.assertTrue(flow.getInt("id") == 12345);
699
700         JSONObject match = (flow.getJSONObject("match")
701                 .getJSONObject("matchField"));
702         Assert.assertTrue(match.getString("type").equals("NW_DST"));
703         Assert.assertTrue(match.getString("value").equals("1.1.1.1"));
704
705         JSONObject act = flow.getJSONObject("actions");
706         Assert.assertTrue(act.getString("@type").equals(actionType));
707
708         if (act.getString("@type").equals("output")) {
709             JSONObject port = act.getJSONObject("port");
710             JSONObject port_node = port.getJSONObject("node");
711             Assert.assertTrue(port.getInt("@id") == 51966);
712             Assert.assertTrue(port.getString("@type").equals("STUB"));
713             Assert.assertTrue(port_node.getInt("@id") == 51966);
714             Assert.assertTrue(port_node.getString("@type").equals("STUB"));
715         }
716
717         if (act.getString("@type").equals("setDlSrc")) {
718             byte srcMatch[] = { (byte) 5, (byte) 4, (byte) 3, (byte) 2,
719                     (byte) 1 };
720             String src = act.getString("address");
721             byte srcBytes[] = new byte[5];
722             srcBytes[0] = Byte.parseByte(src.substring(0, 2));
723             srcBytes[1] = Byte.parseByte(src.substring(2, 4));
724             srcBytes[2] = Byte.parseByte(src.substring(4, 6));
725             srcBytes[3] = Byte.parseByte(src.substring(6, 8));
726             srcBytes[4] = Byte.parseByte(src.substring(8, 10));
727             Assert.assertTrue(Arrays.equals(srcBytes, srcMatch));
728         }
729
730         if (act.getString("@type").equals("setDlDst")) {
731             byte dstMatch[] = { (byte) 1, (byte) 2, (byte) 3, (byte) 4,
732                     (byte) 5 };
733             String dst = act.getString("address");
734             byte dstBytes[] = new byte[5];
735             dstBytes[0] = Byte.parseByte(dst.substring(0, 2));
736             dstBytes[1] = Byte.parseByte(dst.substring(2, 4));
737             dstBytes[2] = Byte.parseByte(dst.substring(4, 6));
738             dstBytes[3] = Byte.parseByte(dst.substring(6, 8));
739             dstBytes[4] = Byte.parseByte(dst.substring(8, 10));
740             Assert.assertTrue(Arrays.equals(dstBytes, dstMatch));
741         }
742         if (act.getString("@type").equals("setDlType"))
743             Assert.assertTrue(act.getInt("dlType") == 10);
744         if (act.getString("@type").equals("setVlanId"))
745             Assert.assertTrue(act.getInt("vlanId") == 2);
746         if (act.getString("@type").equals("setVlanPcp"))
747             Assert.assertTrue(act.getInt("pcp") == 3);
748         if (act.getString("@type").equals("setVlanCfi"))
749             Assert.assertTrue(act.getInt("cfi") == 1);
750
751         if (act.getString("@type").equals("setNwSrc"))
752             Assert.assertTrue(act.getString("address").equals("2.2.2.2"));
753         if (act.getString("@type").equals("setNwDst"))
754             Assert.assertTrue(act.getString("address").equals("1.1.1.1"));
755
756         if (act.getString("@type").equals("pushVlan")) {
757             int head = act.getInt("VlanHeader");
758             // parsing vlan header
759             int id = head & 0xfff;
760             int cfi = (head >> 12) & 0x1;
761             int pcp = (head >> 13) & 0x7;
762             int tag = (head >> 16) & 0xffff;
763             Assert.assertTrue(id == 1234);
764             Assert.assertTrue(cfi == 1);
765             Assert.assertTrue(pcp == 1);
766             Assert.assertTrue(tag == 0x8100);
767         }
768         if (act.getString("@type").equals("setNwTos"))
769             Assert.assertTrue(act.getInt("tos") == 16);
770         if (act.getString("@type").equals("setTpSrc"))
771             Assert.assertTrue(act.getInt("port") == 4201);
772         if (act.getString("@type").equals("setTpDst"))
773             Assert.assertTrue(act.getInt("port") == 8080);
774     }
775
776     @Test
777     public void testFlowProgrammer() throws JSONException {
778         String baseURL = "http://127.0.0.1:8080/controller/nb/v2/flow/default/";
779         // Attempt to get a flow that doesn't exit. Should return 404
780         // status.
781         String result = getJsonResult(baseURL + "STUB/51966/test1", "GET");
782         Assert.assertTrue(result.equals("404"));
783
784         // test add flow1
785         String fc = "{\"dynamic\":\"false\", \"name\":\"test1\", \"node\":{\"@id\":\"51966\",\"@type\":\"STUB\"}, \"actions\":[\"DROP\"]}";
786         result = getJsonResult(baseURL + "STUB/51966/test1", "POST", fc);
787         Assert.assertTrue(httpResponseCode == 201);
788
789         // test get returns flow that was added.
790         result = getJsonResult(baseURL + "STUB/51966/test1", "GET");
791         // check that result came out fine.
792         Assert.assertTrue(httpResponseCode == 200);
793         JSONTokener jt = new JSONTokener(result);
794         JSONObject json = new JSONObject(jt);
795         Assert.assertTrue(json.getString("name").equals("test1"));
796         Assert.assertTrue(json.getString("actions").equals("DROP"));
797         Assert.assertTrue(json.getString("installInHw").equals("true"));
798         JSONObject node = json.getJSONObject("node");
799         Assert.assertTrue(node.getString("@type").equals("STUB"));
800         Assert.assertTrue(node.getString("@id").equals("51966"));
801         // test adding same flow again fails due to repeat name..return 409
802         // code
803         result = getJsonResult(baseURL + "STUB/51966/test1", "POST", fc);
804         Assert.assertTrue(result.equals("409"));
805
806         fc = "{\"dynamic\":\"false\", \"name\":\"test2\", \"node\":{\"@id\":\"51966\",\"@type\":\"STUB\"}, \"actions\":[\"DROP\"]}";
807         result = getJsonResult(baseURL + "STUB/51966/test2", "POST", fc);
808         // test should return 500 for error due to same flow being added.
809         Assert.assertTrue(result.equals("500"));
810
811         // add second flow that's different
812         fc = "{\"dynamic\":\"false\", \"name\":\"test2\", \"nwSrc\":\"1.1.1.1\", \"node\":{\"@id\":\"51966\",\"@type\":\"STUB\"}, \"actions\":[\"DROP\"]}";
813         result = getJsonResult(baseURL + "STUB/51966/test2", "POST", fc);
814         Assert.assertTrue(httpResponseCode == 201);
815
816         // check that request returns both flows given node.
817         result = getJsonResult(baseURL + "STUB/51966/", "GET");
818         jt = new JSONTokener(result);
819         json = new JSONObject(jt);
820         Assert.assertTrue(json.get("flowConfig") instanceof JSONArray);
821         JSONArray ja = json.getJSONArray("flowConfig");
822         Integer count = ja.length();
823         Assert.assertTrue(count == 2);
824
825         // check that request returns both flows given just container.
826         result = getJsonResult(baseURL);
827         jt = new JSONTokener(result);
828         json = new JSONObject(jt);
829         Assert.assertTrue(json.get("flowConfig") instanceof JSONArray);
830         ja = json.getJSONArray("flowConfig");
831         count = ja.length();
832         Assert.assertTrue(count == 2);
833
834         // delete a flow, check that it's no longer in list.
835         result = getJsonResult(baseURL + "STUB/51966/test2", "DELETE");
836         Assert.assertTrue(httpResponseCode == 200);
837
838         result = getJsonResult(baseURL + "STUB/51966/test2", "GET");
839         Assert.assertTrue(result.equals("404"));
840     }
841
842     // method to extract a JSONObject with specified node ID from a JSONObject
843     // that may contain an array of JSONObjects
844     // This is specifically written for statistics manager northbound REST
845     // interface
846     // array_name should be either "flowStatistics" or "portStatistics"
847     private JSONObject getJsonInstance(JSONObject json, String array_name,
848             Integer nodeId) throws JSONException {
849         JSONObject result = null;
850         if (json.get(array_name) instanceof JSONArray) {
851             JSONArray json_array = json.getJSONArray(array_name);
852             for (int i = 0; i < json_array.length(); i++) {
853                 result = json_array.getJSONObject(i);
854                 Integer nid = result.getJSONObject("node").getInt("@id");
855                 if (nid.equals(nodeId))
856                     break;
857             }
858         } else {
859             result = json.getJSONObject(array_name);
860             Integer nid = result.getJSONObject("node").getInt("@id");
861             if (!nid.equals(nodeId))
862                 result = null;
863         }
864         return result;
865     }
866
867     // a class to construct query parameter for HTTP request
868     private class QueryParameter {
869         StringBuilder queryString = null;
870
871         // constructor
872         QueryParameter(String key, String value) {
873             queryString = new StringBuilder();
874             queryString.append("?").append(key).append("=").append(value);
875         }
876
877         // method to add more query parameter
878         QueryParameter add(String key, String value) {
879             this.queryString.append("&").append(key).append("=").append(value);
880             return this;
881         }
882
883         // method to get the query parameter string
884         String getString() {
885             return this.queryString.toString();
886         }
887
888     }
889
890     @Test
891     public void testHostTracker() throws JSONException {
892
893         System.out.println("Starting HostTracker JAXB client.");
894
895         // setup 2 host models for @POST method
896         // 1st host
897         String networkAddress_1 = "192.168.0.8";
898         String dataLayerAddress_1 = "11:22:33:44:55:66";
899         String nodeType_1 = "STUB";
900         Integer nodeId_1 = 3366;
901         String nodeConnectorType_1 = "STUB";
902         Integer nodeConnectorId_1 = 12;
903         String vlan_1 = "4";
904
905         // 2nd host
906         String networkAddress_2 = "10.1.1.1";
907         String dataLayerAddress_2 = "1A:2B:3C:4D:5E:6F";
908         String nodeType_2 = "STUB";
909         Integer nodeId_2 = 4477;
910         String nodeConnectorType_2 = "STUB";
911         Integer nodeConnectorId_2 = 34;
912         String vlan_2 = "0";
913
914         String baseURL = "http://127.0.0.1:8080/controller/nb/v2/host/default";
915
916         // test POST method: addHost()
917         String queryParameter = new QueryParameter("dataLayerAddress",
918                 dataLayerAddress_1).add("nodeType", nodeType_1)
919                 .add("nodeId", nodeId_1.toString())
920                 .add("nodeConnectorType", nodeConnectorType_1)
921                 .add("nodeConnectorId", nodeConnectorId_1.toString())
922                 .add("vlan", vlan_1).getString();
923
924         String result = getJsonResult(baseURL + "/" + networkAddress_1
925                 + queryParameter, "POST");
926         Assert.assertTrue(httpResponseCode.intValue() == (Integer) 201);
927
928         // vlan is not passed through query parameter but should be
929         // defaulted to "0"
930         queryParameter = new QueryParameter("dataLayerAddress",
931                 dataLayerAddress_2).add("nodeType", nodeType_2)
932                 .add("nodeId", nodeId_2.toString())
933                 .add("nodeConnectorType", nodeConnectorType_2)
934                 .add("nodeConnectorId", nodeConnectorId_2.toString())
935                 .getString();
936
937         result = getJsonResult(baseURL + "/" + networkAddress_2
938                 + queryParameter, "POST");
939         Assert.assertTrue(httpResponseCode.intValue() == (Integer) 201);
940
941         // define variables for decoding returned strings
942         String networkAddress;
943         JSONObject host_jo, dl_jo, nc_jo, node_jo;
944
945         // the two hosts should be in inactive host DB
946         // test GET method: getInactiveHosts()
947         result = getJsonResult(baseURL + "/inactive", "GET");
948         Assert.assertTrue(httpResponseCode.intValue() == (Integer) 200);
949
950         JSONTokener jt = new JSONTokener(result);
951         JSONObject json = new JSONObject(jt);
952         // there should be at least two hosts in the DB
953         Assert.assertTrue(json.get("host") instanceof JSONArray);
954         JSONArray ja = json.getJSONArray("host");
955         Integer count = ja.length();
956         Assert.assertTrue(count == 2);
957
958         for (int i = 0; i < count; i++) {
959             host_jo = ja.getJSONObject(i);
960             dl_jo = host_jo.getJSONObject("dataLayerAddress");
961             nc_jo = host_jo.getJSONObject("nodeConnector");
962             node_jo = nc_jo.getJSONObject("node");
963
964             networkAddress = host_jo.getString("networkAddress");
965             if (networkAddress.equalsIgnoreCase(networkAddress_1)) {
966                 Assert.assertTrue(dl_jo.getString("macAddress")
967                         .equalsIgnoreCase(dataLayerAddress_1));
968                 Assert.assertTrue(nc_jo.getString("@type").equalsIgnoreCase(
969                         nodeConnectorType_1));
970                 Assert.assertTrue(Integer.parseInt(nc_jo.getString("@id")) == nodeConnectorId_1);
971                 Assert.assertTrue(node_jo.getString("@type").equalsIgnoreCase(
972                         nodeType_1));
973                 Assert.assertTrue(Integer.parseInt(node_jo.getString("@id")) == nodeId_1);
974                 Assert.assertTrue(host_jo.getString("vlan").equalsIgnoreCase(
975                         vlan_1));
976             } else if (networkAddress.equalsIgnoreCase(networkAddress_2)) {
977                 Assert.assertTrue(dl_jo.getString("macAddress")
978                         .equalsIgnoreCase(dataLayerAddress_2));
979                 Assert.assertTrue(nc_jo.getString("@type").equalsIgnoreCase(
980                         nodeConnectorType_2));
981                 Assert.assertTrue(Integer.parseInt(nc_jo.getString("@id")) == nodeConnectorId_2);
982                 Assert.assertTrue(node_jo.getString("@type").equalsIgnoreCase(
983                         nodeType_2));
984                 Assert.assertTrue(Integer.parseInt(node_jo.getString("@id")) == nodeId_2);
985                 Assert.assertTrue(host_jo.getString("vlan").equalsIgnoreCase(
986                         vlan_2));
987             } else {
988                 Assert.assertTrue(false);
989             }
990         }
991
992         // test GET method: getActiveHosts() - no host expected
993         result = getJsonResult(baseURL, "GET");
994         Assert.assertTrue(httpResponseCode.intValue() == (Integer) 200);
995
996         jt = new JSONTokener(result);
997         json = new JSONObject(jt);
998         Assert.assertFalse(hostInJson(json, networkAddress_1));
999         Assert.assertFalse(hostInJson(json, networkAddress_2));
1000
1001         // put the 1st host into active host DB
1002         Node nd;
1003         NodeConnector ndc;
1004         try {
1005             nd = new Node(nodeType_1, nodeId_1);
1006             ndc = new NodeConnector(nodeConnectorType_1, nodeConnectorId_1, nd);
1007             this.invtoryListener.notifyNodeConnector(ndc, UpdateType.ADDED,
1008                     null);
1009         } catch (ConstructionException e) {
1010             ndc = null;
1011             nd = null;
1012         }
1013
1014         // verify the host shows up in active host DB
1015
1016         result = getJsonResult(baseURL, "GET");
1017         Assert.assertTrue(httpResponseCode.intValue() == (Integer) 200);
1018
1019         jt = new JSONTokener(result);
1020         json = new JSONObject(jt);
1021
1022         Assert.assertTrue(hostInJson(json, networkAddress_1));
1023
1024         // test GET method for getHostDetails()
1025
1026         result = getJsonResult(baseURL + "/" + networkAddress_1, "GET");
1027         Assert.assertTrue(httpResponseCode.intValue() == (Integer) 200);
1028
1029         jt = new JSONTokener(result);
1030         json = new JSONObject(jt);
1031
1032         Assert.assertFalse(json.length() == 0);
1033
1034         dl_jo = json.getJSONObject("dataLayerAddress");
1035         nc_jo = json.getJSONObject("nodeConnector");
1036         node_jo = nc_jo.getJSONObject("node");
1037
1038         Assert.assertTrue(json.getString("networkAddress").equalsIgnoreCase(
1039                 networkAddress_1));
1040         Assert.assertTrue(dl_jo.getString("macAddress").equalsIgnoreCase(
1041                 dataLayerAddress_1));
1042         Assert.assertTrue(nc_jo.getString("@type").equalsIgnoreCase(
1043                 nodeConnectorType_1));
1044         Assert.assertTrue(Integer.parseInt(nc_jo.getString("@id")) == nodeConnectorId_1);
1045         Assert.assertTrue(node_jo.getString("@type").equalsIgnoreCase(
1046                 nodeType_1));
1047         Assert.assertTrue(Integer.parseInt(node_jo.getString("@id")) == nodeId_1);
1048         Assert.assertTrue(json.getString("vlan").equalsIgnoreCase(vlan_1));
1049
1050         // test DELETE method for deleteFlow()
1051
1052         result = getJsonResult(baseURL + "/" + networkAddress_1, "DELETE");
1053         Assert.assertTrue(httpResponseCode.intValue() == (Integer) 200);
1054
1055         // verify host_1 removed from active host DB
1056         // test GET method: getActiveHosts() - no host expected
1057
1058         result = getJsonResult(baseURL, "GET");
1059         Assert.assertTrue(httpResponseCode.intValue() == (Integer) 200);
1060
1061         jt = new JSONTokener(result);
1062         json = new JSONObject(jt);
1063
1064         Assert.assertFalse(hostInJson(json, networkAddress_1));
1065
1066     }
1067
1068     private Boolean hostInJson(JSONObject json, String hostIp)
1069             throws JSONException {
1070         // input JSONObject may be empty
1071         if (json.length() == 0) {
1072             return false;
1073         }
1074         if (json.get("host") instanceof JSONArray) {
1075             JSONArray ja = json.getJSONArray("host");
1076             for (int i = 0; i < ja.length(); i++) {
1077                 String na = ja.getJSONObject(i).getString("networkAddress");
1078                 if (na.equalsIgnoreCase(hostIp))
1079                     return true;
1080             }
1081             return false;
1082         } else {
1083             String na = json.getJSONObject("host").getString("networkAddress");
1084             return (na.equalsIgnoreCase(hostIp)) ? true : false;
1085         }
1086     }
1087
1088     // Configure the OSGi container
1089     @Configuration
1090     public Option[] config() {
1091         return options(
1092                 //
1093                 systemProperty("logback.configurationFile").value(
1094                         "file:" + PathUtils.getBaseDir()
1095                                 + "/src/test/resources/logback.xml"),
1096                 // To start OSGi console for inspection remotely
1097                 systemProperty("osgi.console").value("2401"),
1098                 systemProperty("org.eclipse.gemini.web.tomcat.config.path")
1099                         .value(PathUtils.getBaseDir()
1100                                 + "/src/test/resources/tomcat-server.xml"),
1101
1102                 // setting default level. Jersey bundles will need to be started
1103                 // earlier.
1104                 systemProperty("osgi.bundles.defaultStartLevel").value("4"),
1105
1106                 // Set the systemPackages (used by clustering)
1107                 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
1108                 mavenBundle("javax.servlet", "servlet-api", "2.5"),
1109
1110                 mavenBundle("org.slf4j", "jcl-over-slf4j", "1.7.2"),
1111                 mavenBundle("org.slf4j", "slf4j-api", "1.7.2"),
1112                 mavenBundle("org.slf4j", "log4j-over-slf4j", "1.7.2"),
1113                 mavenBundle("ch.qos.logback", "logback-core", "1.0.9"),
1114                 mavenBundle("ch.qos.logback", "logback-classic", "1.0.9"),
1115                 mavenBundle("org.apache.commons", "commons-lang3", "3.1"),
1116                 mavenBundle("org.apache.felix",
1117                         "org.apache.felix.dependencymanager", "3.1.0"),
1118
1119                 // the plugin stub to get data for the tests
1120                 mavenBundle("org.opendaylight.controller",
1121                         "protocol_plugins.stub", "0.4.0-SNAPSHOT"),
1122
1123                 // List all the opendaylight modules
1124                 mavenBundle("org.opendaylight.controller", "security",
1125                         "0.4.0-SNAPSHOT").noStart(),
1126                 mavenBundle("org.opendaylight.controller", "sal",
1127                         "0.5.0-SNAPSHOT"),
1128                 mavenBundle("org.opendaylight.controller",
1129                         "sal.implementation", "0.4.0-SNAPSHOT"),
1130                 mavenBundle("org.opendaylight.controller", "statisticsmanager",
1131                         "0.4.0-SNAPSHOT"),
1132                 mavenBundle("org.opendaylight.controller",
1133                         "statisticsmanager.implementation", "0.4.0-SNAPSHOT"),
1134                 mavenBundle("org.opendaylight.controller", "containermanager",
1135                         "0.4.0-SNAPSHOT"),
1136                 mavenBundle("org.opendaylight.controller",
1137                         "containermanager.implementation", "0.4.0-SNAPSHOT"),
1138                 mavenBundle("org.opendaylight.controller",
1139                         "forwardingrulesmanager", "0.4.0-SNAPSHOT"),
1140                 mavenBundle("org.opendaylight.controller",
1141                         "forwardingrulesmanager.implementation",
1142                         "0.4.0-SNAPSHOT"),
1143                 mavenBundle("org.opendaylight.controller", "arphandler",
1144                         "0.4.0-SNAPSHOT"),
1145                 mavenBundle("org.opendaylight.controller",
1146                         "clustering.services", "0.4.0-SNAPSHOT"),
1147                 mavenBundle("org.opendaylight.controller",
1148                         "clustering.services-implementation", "0.4.0-SNAPSHOT"),
1149                 mavenBundle("org.opendaylight.controller", "switchmanager",
1150                         "0.4.0-SNAPSHOT"),
1151                 mavenBundle("org.opendaylight.controller",
1152                         "switchmanager.implementation", "0.4.0-SNAPSHOT"),
1153                 mavenBundle("org.opendaylight.controller", "configuration",
1154                         "0.4.0-SNAPSHOT"),
1155                 mavenBundle("org.opendaylight.controller",
1156                         "configuration.implementation", "0.4.0-SNAPSHOT"),
1157                 mavenBundle("org.opendaylight.controller", "hosttracker",
1158                         "0.4.0-SNAPSHOT"),
1159                 mavenBundle("org.opendaylight.controller",
1160                         "hosttracker.implementation", "0.4.0-SNAPSHOT"),
1161                 mavenBundle("org.opendaylight.controller", "arphandler",
1162                         "0.4.0-SNAPSHOT"),
1163                 mavenBundle("org.opendaylight.controller",
1164                         "routing.dijkstra_implementation", "0.4.0-SNAPSHOT"),
1165                 mavenBundle("org.opendaylight.controller", "topologymanager",
1166                         "0.4.0-SNAPSHOT"),
1167
1168                 mavenBundle("org.opendaylight.controller", "usermanager",
1169                         "0.4.0-SNAPSHOT"),
1170                 mavenBundle("org.opendaylight.controller",
1171                         "usermanager.implementation", "0.4.0-SNAPSHOT"),
1172                 mavenBundle("org.opendaylight.controller", "logging.bridge",
1173                         "0.4.0-SNAPSHOT"),
1174                 mavenBundle("org.opendaylight.controller", "clustering.test",
1175                         "0.4.0-SNAPSHOT"),
1176
1177                 mavenBundle("org.opendaylight.controller",
1178                         "forwarding.staticrouting", "0.4.0-SNAPSHOT"),
1179
1180                 // Northbound bundles
1181                 mavenBundle("org.opendaylight.controller",
1182                         "commons.northbound", "0.4.0-SNAPSHOT"),
1183                 mavenBundle("org.opendaylight.controller",
1184                         "forwarding.staticrouting.northbound", "0.4.0-SNAPSHOT"),
1185                 mavenBundle("org.opendaylight.controller",
1186                         "statistics.northbound", "0.4.0-SNAPSHOT"),
1187                 mavenBundle("org.opendaylight.controller",
1188                         "topology.northbound", "0.4.0-SNAPSHOT"),
1189                 mavenBundle("org.opendaylight.controller",
1190                         "hosttracker.northbound", "0.4.0-SNAPSHOT"),
1191                 mavenBundle("org.opendaylight.controller",
1192                         "switchmanager.northbound", "0.4.0-SNAPSHOT"),
1193                 mavenBundle("org.opendaylight.controller",
1194                         "flowprogrammer.northbound", "0.4.0-SNAPSHOT"),
1195                 mavenBundle("org.opendaylight.controller",
1196                         "subnets.northbound", "0.4.0-SNAPSHOT"),
1197
1198                 mavenBundle("org.codehaus.jackson", "jackson-mapper-asl",
1199                         "1.9.8"),
1200                 mavenBundle("org.codehaus.jackson", "jackson-core-asl", "1.9.8"),
1201                 mavenBundle("org.codehaus.jackson", "jackson-jaxrs", "1.9.8"),
1202                 mavenBundle("org.codehaus.jettison", "jettison", "1.3.3"),
1203
1204                 mavenBundle("commons-io", "commons-io", "2.3"),
1205
1206                 mavenBundle("commons-fileupload", "commons-fileupload", "1.2.2"),
1207
1208                 mavenBundle("equinoxSDK381", "javax.servlet",
1209                         "3.0.0.v201112011016"),
1210                 mavenBundle("equinoxSDK381", "javax.servlet.jsp",
1211                         "2.2.0.v201112011158"),
1212                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds",
1213                         "1.4.0.v20120522-1841"),
1214                 mavenBundle("orbit", "javax.xml.rpc", "1.1.0.v201005080400"),
1215                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util",
1216                         "1.0.400.v20120522-2049"),
1217                 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services",
1218                         "3.3.100.v20120522-1822"),
1219                 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command",
1220                         "0.8.0.v201108120515"),
1221                 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime",
1222                         "0.8.0.v201108120515"),
1223                 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell",
1224                         "0.8.0.v201110170705"),
1225                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.cm",
1226                         "1.0.400.v20120522-1841"),
1227                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console",
1228                         "1.0.0.v20120522-1841"),
1229                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.launcher",
1230                         "1.3.0.v20120522-1813"),
1231
1232                 mavenBundle("geminiweb", "org.eclipse.gemini.web.core",
1233                         "2.2.0.RELEASE"),
1234                 mavenBundle("geminiweb", "org.eclipse.gemini.web.extender",
1235                         "2.2.0.RELEASE"),
1236                 mavenBundle("geminiweb", "org.eclipse.gemini.web.tomcat",
1237                         "2.2.0.RELEASE"),
1238                 mavenBundle("geminiweb",
1239                         "org.eclipse.virgo.kernel.equinox.extensions",
1240                         "3.6.0.RELEASE").noStart(),
1241                 mavenBundle("geminiweb", "org.eclipse.virgo.util.common",
1242                         "3.6.0.RELEASE"),
1243                 mavenBundle("geminiweb", "org.eclipse.virgo.util.io",
1244                         "3.6.0.RELEASE"),
1245                 mavenBundle("geminiweb", "org.eclipse.virgo.util.math",
1246                         "3.6.0.RELEASE"),
1247                 mavenBundle("geminiweb", "org.eclipse.virgo.util.osgi",
1248                         "3.6.0.RELEASE"),
1249                 mavenBundle("geminiweb",
1250                         "org.eclipse.virgo.util.osgi.manifest", "3.6.0.RELEASE"),
1251                 mavenBundle("geminiweb",
1252                         "org.eclipse.virgo.util.parser.manifest",
1253                         "3.6.0.RELEASE"),
1254
1255                 mavenBundle("org.apache.felix",
1256                         "org.apache.felix.dependencymanager", "3.1.0"),
1257                 mavenBundle("org.apache.felix",
1258                         "org.apache.felix.dependencymanager.shell", "3.0.1"),
1259
1260                 mavenBundle("com.google.code.gson", "gson", "2.1"),
1261                 mavenBundle("org.jboss.spec.javax.transaction",
1262                         "jboss-transaction-api_1.1_spec", "1.0.1.Final"),
1263                 mavenBundle("org.apache.felix", "org.apache.felix.fileinstall",
1264                         "3.1.6"),
1265                 mavenBundle("org.apache.commons", "commons-lang3", "3.1"),
1266                 mavenBundle("commons-codec", "commons-codec"),
1267                 mavenBundle("virgomirror",
1268                         "org.eclipse.jdt.core.compiler.batch",
1269                         "3.8.0.I20120518-2145"),
1270                 mavenBundle("eclipselink", "javax.persistence",
1271                         "2.0.4.v201112161009"),
1272
1273                 mavenBundle("orbit", "javax.activation", "1.1.0.v201211130549"),
1274                 mavenBundle("orbit", "javax.annotation", "1.1.0.v201209060031"),
1275                 mavenBundle("orbit", "javax.ejb", "3.1.1.v201204261316"),
1276                 mavenBundle("orbit", "javax.el", "2.2.0.v201108011116"),
1277                 mavenBundle("orbit", "javax.mail.glassfish",
1278                         "1.4.1.v201108011116"),
1279                 mavenBundle("orbit", "javax.xml.rpc", "1.1.0.v201005080400"),
1280                 mavenBundle("orbit", "org.apache.catalina",
1281                         "7.0.32.v201211201336"),
1282                 // these are bundle fragments that can't be started on its own
1283                 mavenBundle("orbit", "org.apache.catalina.ha",
1284                         "7.0.32.v201211201952").noStart(),
1285                 mavenBundle("orbit", "org.apache.catalina.tribes",
1286                         "7.0.32.v201211201952").noStart(),
1287                 mavenBundle("orbit", "org.apache.coyote",
1288                         "7.0.32.v201211201952").noStart(),
1289                 mavenBundle("orbit", "org.apache.jasper",
1290                         "7.0.32.v201211201952").noStart(),
1291
1292                 mavenBundle("orbit", "org.apache.el", "7.0.32.v201211081135"),
1293                 mavenBundle("orbit", "org.apache.juli.extras",
1294                         "7.0.32.v201211081135"),
1295                 mavenBundle("orbit", "org.apache.tomcat.api",
1296                         "7.0.32.v201211081135"),
1297                 mavenBundle("orbit", "org.apache.tomcat.util",
1298                         "7.0.32.v201211201952").noStart(),
1299                 mavenBundle("orbit", "javax.servlet.jsp.jstl",
1300                         "1.2.0.v201105211821"),
1301                 mavenBundle("orbit", "javax.servlet.jsp.jstl.impl",
1302                         "1.2.0.v201210211230"),
1303
1304                 mavenBundle("org.ops4j.pax.exam", "pax-exam-container-native"),
1305                 mavenBundle("org.ops4j.pax.exam", "pax-exam-junit4"),
1306                 mavenBundle("org.ops4j.pax.exam", "pax-exam-link-mvn"),
1307                 mavenBundle("org.ops4j.pax.url", "pax-url-aether"),
1308
1309                 mavenBundle("org.springframework", "org.springframework.asm",
1310                         "3.1.3.RELEASE"),
1311                 mavenBundle("org.springframework", "org.springframework.aop",
1312                         "3.1.3.RELEASE"),
1313                 mavenBundle("org.springframework",
1314                         "org.springframework.context", "3.1.3.RELEASE"),
1315                 mavenBundle("org.springframework",
1316                         "org.springframework.context.support", "3.1.3.RELEASE"),
1317                 mavenBundle("org.springframework", "org.springframework.core",
1318                         "3.1.3.RELEASE"),
1319                 mavenBundle("org.springframework", "org.springframework.beans",
1320                         "3.1.3.RELEASE"),
1321                 mavenBundle("org.springframework",
1322                         "org.springframework.expression", "3.1.3.RELEASE"),
1323                 mavenBundle("org.springframework", "org.springframework.web",
1324                         "3.1.3.RELEASE"),
1325
1326                 mavenBundle("org.aopalliance",
1327                         "com.springsource.org.aopalliance", "1.0.0"),
1328                 mavenBundle("org.springframework",
1329                         "org.springframework.web.servlet", "3.1.3.RELEASE"),
1330                 mavenBundle("org.springframework.security",
1331                         "spring-security-config", "3.1.3.RELEASE"),
1332                 mavenBundle("org.springframework.security",
1333                         "spring-security-core", "3.1.3.RELEASE"),
1334                 mavenBundle("org.springframework.security",
1335                         "spring-security-web", "3.1.3.RELEASE"),
1336                 mavenBundle("org.springframework.security",
1337                         "spring-security-taglibs", "3.1.3.RELEASE"),
1338                 mavenBundle("org.springframework",
1339                         "org.springframework.transaction", "3.1.3.RELEASE"),
1340
1341                 mavenBundle("org.ow2.chameleon.management", "chameleon-mbeans",
1342                         "1.0.0"),
1343                 mavenBundle("org.opendaylight.controller.thirdparty",
1344                         "net.sf.jung2", "2.0.1-SNAPSHOT"),
1345                 mavenBundle("org.opendaylight.controller.thirdparty",
1346                         "com.sun.jersey.jersey-servlet", "1.17-SNAPSHOT"),
1347
1348                 // Jersey needs to be started before the northbound application
1349                 // bundles, using a lower start level
1350                 mavenBundle("com.sun.jersey", "jersey-client", "1.17"),
1351                 mavenBundle("com.sun.jersey", "jersey-server", "1.17")
1352                         .startLevel(2),
1353                 mavenBundle("com.sun.jersey", "jersey-core", "1.17")
1354                         .startLevel(2),
1355                 mavenBundle("com.sun.jersey", "jersey-json", "1.17")
1356                         .startLevel(2), junitBundles());
1357     }
1358 }