BUG 2302 : odl-clustering-test-app should not be part of the odl-restconf-all feature set
[controller.git] / opendaylight / northbound / integrationtest / src / test / java / org / opendaylight / controller / northbound / integrationtest / NorthboundIT.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.northbound.integrationtest;
9
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertNotNull;
12 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
13 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
14 import static org.ops4j.pax.exam.CoreOptions.options;
15 import static org.ops4j.pax.exam.CoreOptions.systemPackages;
16 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
17
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.HashMap;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Set;
25 import javax.inject.Inject;
26
27 import org.apache.commons.codec.binary.Base64;
28 import org.codehaus.jettison.json.JSONArray;
29 import org.codehaus.jettison.json.JSONException;
30 import org.codehaus.jettison.json.JSONObject;
31 import org.codehaus.jettison.json.JSONTokener;
32 import org.junit.Assert;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.opendaylight.controller.commons.httpclient.HTTPClient;
37 import org.opendaylight.controller.commons.httpclient.HTTPRequest;
38 import org.opendaylight.controller.commons.httpclient.HTTPResponse;
39 import org.opendaylight.controller.hosttracker.IfIptoHost;
40 import org.opendaylight.controller.sal.core.Bandwidth;
41 import org.opendaylight.controller.sal.core.ConstructionException;
42 import org.opendaylight.controller.sal.core.Edge;
43 import org.opendaylight.controller.sal.core.Latency;
44 import org.opendaylight.controller.sal.core.Node;
45 import org.opendaylight.controller.sal.core.NodeConnector;
46 import org.opendaylight.controller.sal.core.Property;
47 import org.opendaylight.controller.sal.core.State;
48 import org.opendaylight.controller.sal.core.UpdateType;
49 import org.opendaylight.controller.sal.topology.IListenTopoUpdates;
50 import org.opendaylight.controller.sal.topology.TopoEdgeUpdate;
51 import org.opendaylight.controller.switchmanager.IInventoryListener;
52 import org.opendaylight.controller.usermanager.IUserManager;
53 import org.ops4j.pax.exam.Configuration;
54 import org.ops4j.pax.exam.Option;
55 import org.ops4j.pax.exam.junit.PaxExam;
56 import org.ops4j.pax.exam.util.PathUtils;
57 import org.osgi.framework.Bundle;
58 import org.osgi.framework.BundleContext;
59 import org.osgi.framework.ServiceReference;
60 import org.slf4j.Logger;
61 import org.slf4j.LoggerFactory;
62
63 @RunWith(PaxExam.class)
64 public class NorthboundIT {
65     private final Logger log = LoggerFactory.getLogger(NorthboundIT.class);
66     // get the OSGI bundle context
67     @Inject
68     private BundleContext bc;
69     private IUserManager userManager = null;
70     private IInventoryListener invtoryListener = null;
71     private IListenTopoUpdates topoUpdates = null;
72     private static final String baseUrlPrefix = "http://127.0.0.1:8080/controller/nb/v2/";
73     private final Boolean debugMsg = false;
74
75     private String stateToString(int state) {
76         switch (state) {
77         case Bundle.ACTIVE:
78             return "ACTIVE";
79         case Bundle.INSTALLED:
80             return "INSTALLED";
81         case Bundle.RESOLVED:
82             return "RESOLVED";
83         case Bundle.UNINSTALLED:
84             return "UNINSTALLED";
85         default:
86             return "Not CONVERTED";
87         }
88     }
89
90     @Before
91     public void areWeReady() {
92         assertNotNull(bc);
93         boolean debugit = false;
94         Bundle b[] = bc.getBundles();
95         for (Bundle element : b) {
96             int state = element.getState();
97             if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
98                 log.debug("Bundle:" + element.getSymbolicName() + " state:" + stateToString(state));
99                 debugit = true;
100             }
101         }
102         if (debugit) {
103             log.debug("Do some debugging because some bundle is " + "unresolved");
104         }
105         // Assert if true, if false we are good to go!
106         assertFalse(debugit);
107
108         ServiceReference r = bc.getServiceReference(IUserManager.class.getName());
109         if (r != null) {
110             this.userManager = (IUserManager) bc.getService(r);
111         }
112         // If UserManager is null, cannot login to run tests.
113         assertNotNull(this.userManager);
114
115         r = bc.getServiceReference(IfIptoHost.class.getName());
116         if (r != null) {
117             this.invtoryListener = (IInventoryListener) bc.getService(r);
118         }
119
120         // If inventoryListener is null, cannot run hosttracker tests.
121         assertNotNull(this.invtoryListener);
122
123         r = bc.getServiceReference(IListenTopoUpdates.class.getName());
124         if (r != null) {
125             this.topoUpdates = (IListenTopoUpdates) bc.getService(r);
126         }
127
128         // If topologyManager is null, cannot run topology North tests.
129         assertNotNull(this.topoUpdates);
130
131     }
132
133     // static variable to pass response code from getJsonResult()
134     private static Integer httpResponseCode = null;
135
136     private String getJsonResult(String restUrl) {
137         return getJsonResult(restUrl, "GET", null);
138     }
139
140     private String getJsonResult(String restUrl, String method) {
141         return getJsonResult(restUrl, method, null);
142     }
143
144     private String getJsonResult(String restUrl, String method, String body) {
145         // initialize response code to indicate error
146         httpResponseCode = 400;
147
148         if (debugMsg) {
149             System.out.println("HTTP method: " + method + " url: " + restUrl.toString());
150             if (body != null) {
151                 System.out.println("body: " + body);
152             }
153         }
154
155         try {
156             this.userManager.getAuthorizationList();
157             this.userManager.authenticate("admin", "admin");
158             HTTPRequest request = new HTTPRequest();
159
160             request.setUri(restUrl);
161             request.setMethod(method);
162             request.setTimeout(0);  // HostTracker doesn't respond
163                                     // within default timeout during
164                                     // IT so setting an indefinite
165                                     // timeout till the issue is
166                                     // sorted out
167
168             Map<String, List<String>> headers = new HashMap<String, List<String>>();
169             String authString = "admin:admin";
170             byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
171             String authStringEnc = new String(authEncBytes);
172             List<String> header = new ArrayList<String>();
173             header.add("Basic "+authStringEnc);
174             headers.put("Authorization", header);
175             header = new ArrayList<String>();
176             header.add("application/json");
177             headers.put("Accept", header);
178             request.setHeaders(headers);
179             request.setContentType("application/json");
180             if (body != null) {
181                 request.setEntity(body);
182             }
183
184             HTTPResponse response = HTTPClient.sendRequest(request);
185
186             // Response code for success should be 2xx
187             httpResponseCode = response.getStatus();
188             if (httpResponseCode > 299) {
189                 return httpResponseCode.toString();
190             }
191
192             if (debugMsg) {
193                 System.out.println("HTTP response code: " + response.getStatus());
194                 System.out.println("HTTP response message: " + response.getEntity());
195             }
196             return response.getEntity();
197         } catch (Exception e) {
198             if (debugMsg) {
199                 e.printStackTrace();
200             }
201             return null;
202         }
203     }
204
205     private void testNodeProperties(JSONObject node, Integer nodeId, String nodeType, Integer timestamp,
206             String timestampName, Integer actionsValue, Integer capabilitiesValue, Integer tablesValue,
207             Integer buffersValue) throws JSONException {
208
209         JSONObject nodeInfo = node.getJSONObject("node");
210         Assert.assertEquals(nodeId, (Integer) nodeInfo.getInt("id"));
211         Assert.assertEquals(nodeType, nodeInfo.getString("type"));
212
213         JSONObject properties = node.getJSONObject("properties");
214
215         if (timestamp == null || timestampName == null) {
216             Assert.assertFalse(properties.has("timeStamp"));
217         } else {
218             Assert.assertEquals(timestamp, (Integer) properties.getJSONObject("timeStamp").getInt("value"));
219             Assert.assertEquals(timestampName, properties.getJSONObject("timeStamp").getString("name"));
220         }
221         if (actionsValue == null) {
222             Assert.assertFalse(properties.has("actions"));
223         } else {
224             Assert.assertEquals(actionsValue, (Integer) properties.getJSONObject("actions").getInt("value"));
225         }
226         if (capabilitiesValue == null) {
227             Assert.assertFalse(properties.has("capabilities"));
228         } else {
229             Assert.assertEquals(capabilitiesValue,
230                     (Integer) properties.getJSONObject("capabilities").getInt("value"));
231         }
232         if (tablesValue == null) {
233             Assert.assertFalse(properties.has("tables"));
234         } else {
235             Assert.assertEquals(tablesValue, (Integer) properties.getJSONObject("tables").getInt("value"));
236         }
237         if (buffersValue == null) {
238             Assert.assertFalse(properties.has("buffers"));
239         } else {
240             Assert.assertEquals(buffersValue, (Integer) properties.getJSONObject("buffers").getInt("value"));
241         }
242     }
243
244     private void testNodeConnectorProperties(JSONObject nodeConnectorProperties, Integer ncId, String ncType,
245             Integer nodeId, String nodeType, Integer state, Integer capabilities, Integer bandwidth)
246             throws JSONException {
247
248         JSONObject nodeConnector = nodeConnectorProperties.getJSONObject("nodeconnector");
249         JSONObject node = nodeConnector.getJSONObject("node");
250         JSONObject properties = nodeConnectorProperties.getJSONObject("properties");
251
252         Assert.assertEquals(ncId, (Integer) nodeConnector.getInt("id"));
253         Assert.assertEquals(ncType, nodeConnector.getString("type"));
254         Assert.assertEquals(nodeId, (Integer) node.getInt("id"));
255         Assert.assertEquals(nodeType, node.getString("type"));
256         if (state == null) {
257             Assert.assertFalse(properties.has("state"));
258         } else {
259             Assert.assertEquals(state, (Integer) properties.getJSONObject("state").getInt("value"));
260         }
261         if (capabilities == null) {
262             Assert.assertFalse(properties.has("capabilities"));
263         } else {
264             Assert.assertEquals(capabilities,
265                     (Integer) properties.getJSONObject("capabilities").getInt("value"));
266         }
267         if (bandwidth == null) {
268             Assert.assertFalse(properties.has("bandwidth"));
269         } else {
270             Assert.assertEquals(bandwidth, (Integer) properties.getJSONObject("bandwidth").getInt("value"));
271         }
272     }
273
274     @Test
275     public void testSubnetsNorthbound() throws JSONException, ConstructionException {
276         System.out.println("Starting Subnets JAXB client.");
277         String baseURL = baseUrlPrefix + "subnetservice/";
278
279         String name1 = "testSubnet1";
280         String subnet1 = "1.1.1.1/24";
281
282         String name2 = "testSubnet2";
283         String subnet2 = "2.2.2.2/24";
284
285         String name3 = "testSubnet3";
286         String subnet3 = "3.3.3.3/24";
287
288         /*
289          * Create the node connector string list for the two subnets as:
290          * portList2 = {"OF|1@OF|00:00:00:00:00:00:00:02", "OF|2@OF|00:00:00:00:00:00:00:02", "OF|3@OF|00:00:00:00:00:00:00:02", "OF|4@OF|00:00:00:00:00:00:00:02"};
291          * portList3 = {"OF|1@OF|00:00:00:00:00:00:00:03", "OF|2@OF|00:00:00:00:00:00:00:03", "OF|3@OF|00:00:00:00:00:00:00:03"};
292          */
293         Node node2 = new Node(Node.NodeIDType.OPENFLOW, 2L);
294         List<String> portList2 = new ArrayList<String>();
295         NodeConnector nc21 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)1, node2);
296         NodeConnector nc22 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)2, node2);
297         NodeConnector nc23 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)3, node2);
298         NodeConnector nc24 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)3, node2);
299         portList2.add(nc21.toString());
300         portList2.add(nc22.toString());
301         portList2.add(nc23.toString());
302         portList2.add(nc24.toString());
303
304         List<String> portList3 = new ArrayList<String>();
305         Node node3 = new Node(Node.NodeIDType.OPENFLOW, 3L);
306         NodeConnector nc31 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)1, node3);
307         NodeConnector nc32 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)2, node3);
308         NodeConnector nc33 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)3, node3);
309         portList3.add(nc31.toString());
310         portList3.add(nc32.toString());
311         portList3.add(nc33.toString());
312
313         // Test GET subnets in default container
314         String result = getJsonResult(baseURL + "default/subnets");
315         JSONTokener jt = new JSONTokener(result);
316         JSONObject json = new JSONObject(jt);
317         JSONArray subnetConfigs = json.getJSONArray("subnetConfig");
318         Assert.assertEquals(subnetConfigs.length(), 1); // should only get the default subnet
319
320         // Test GET subnet1 expecting 404
321         result = getJsonResult(baseURL + "default/subnet/" + name1);
322         Assert.assertEquals(404, httpResponseCode.intValue());
323
324         // Test POST subnet1
325         JSONObject jo = new JSONObject().put("name", name1).put("subnet", subnet1);
326         // execute HTTP request and verify response code
327         result = getJsonResult(baseURL + "default/subnet/" + name1, "PUT", jo.toString());
328         Assert.assertTrue(httpResponseCode == 201);
329
330         // Test GET subnet1
331         result = getJsonResult(baseURL + "default/subnet/" + name1);
332         jt = new JSONTokener(result);
333         json = new JSONObject(jt);
334         Assert.assertEquals(200, httpResponseCode.intValue());
335         Assert.assertEquals(name1, json.getString("name"));
336         Assert.assertEquals(subnet1, json.getString("subnet"));
337
338         // Test PUT subnet2
339         JSONObject jo2 = new JSONObject().put("name", name2).put("subnet", subnet2).put("nodeConnectors", portList2);
340         // execute HTTP request and verify response code
341         result = getJsonResult(baseURL + "default/subnet/" + name2, "PUT", jo2.toString());
342         Assert.assertEquals(201, httpResponseCode.intValue());
343         // Test PUT subnet3
344         JSONObject jo3 = new JSONObject().put("name", name3).put("subnet", subnet3);
345         // execute HTTP request and verify response code
346         result = getJsonResult(baseURL + "default/subnet/" + name3, "PUT", jo3.toString());
347         Assert.assertEquals(201, httpResponseCode.intValue());
348         // Test POST subnet3 (modify port list: add)
349         JSONObject jo3New = new JSONObject().put("name", name3).put("subnet", subnet3).put("nodeConnectors", portList3);
350         // execute HTTP request and verify response code
351         result = getJsonResult(baseURL + "default/subnet/" + name3, "POST", jo3New.toString());
352         Assert.assertEquals(200, httpResponseCode.intValue());
353
354         // Test GET all subnets in default container
355         result = getJsonResult(baseURL + "default/subnets");
356         jt = new JSONTokener(result);
357         json = new JSONObject(jt);
358         JSONArray subnetConfigArray = json.getJSONArray("subnetConfig");
359         JSONObject subnetConfig;
360         Assert.assertEquals(3, subnetConfigArray.length());
361         for (int i = 0; i < subnetConfigArray.length(); i++) {
362             subnetConfig = subnetConfigArray.getJSONObject(i);
363             if (subnetConfig.getString("name").equals(name1)) {
364                 Assert.assertEquals(subnet1, subnetConfig.getString("subnet"));
365             } else if (subnetConfig.getString("name").equals(name2)) {
366                 Assert.assertEquals(subnet2, subnetConfig.getString("subnet"));
367                 JSONArray portListGet = subnetConfig.getJSONArray("nodeConnectors");
368                 Assert.assertEquals(portList2.get(0), portListGet.get(0));
369                 Assert.assertEquals(portList2.get(1), portListGet.get(1));
370                 Assert.assertEquals(portList2.get(2), portListGet.get(2));
371                 Assert.assertEquals(portList2.get(3), portListGet.get(3));
372             } else if (subnetConfig.getString("name").equals(name3)) {
373                 Assert.assertEquals(subnet3, subnetConfig.getString("subnet"));
374                 JSONArray portListGet = subnetConfig.getJSONArray("nodeConnectors");
375                 Assert.assertEquals(portList3.get(0), portListGet.get(0));
376                 Assert.assertEquals(portList3.get(1), portListGet.get(1));
377                 Assert.assertEquals(portList3.get(2), portListGet.get(2));
378             } else {
379                 // Unexpected config name
380                 Assert.assertTrue(false);
381             }
382         }
383
384         // Test POST subnet2 (modify port list: remove one port only)
385         List<String> newPortList2 = new ArrayList<String>(portList2);
386         newPortList2.remove(3);
387         JSONObject jo2New = new JSONObject().put("name", name2).put("subnet", subnet2).put("nodeConnectors", newPortList2);
388         // execute HTTP request and verify response code
389         result = getJsonResult(baseURL + "default/subnet/" + name2, "POST", jo2New.toString());
390         Assert.assertEquals(200, httpResponseCode.intValue());
391
392         // Test GET subnet2: verify contains only the first three ports
393         result = getJsonResult(baseURL + "default/subnet/" + name2);
394         jt = new JSONTokener(result);
395         subnetConfig = new JSONObject(jt);
396         Assert.assertEquals(200, httpResponseCode.intValue());
397         JSONArray portListGet2 = subnetConfig.getJSONArray("nodeConnectors");
398         Assert.assertEquals(portList2.get(0), portListGet2.get(0));
399         Assert.assertEquals(portList2.get(1), portListGet2.get(1));
400         Assert.assertEquals(portList2.get(2), portListGet2.get(2));
401         Assert.assertTrue(portListGet2.length() == 3);
402
403         // Test DELETE subnet1
404         result = getJsonResult(baseURL + "default/subnet/" + name1, "DELETE");
405         Assert.assertEquals(204, httpResponseCode.intValue());
406
407         // Test GET deleted subnet1
408         result = getJsonResult(baseURL + "default/subnet/" + name1);
409         Assert.assertEquals(404, httpResponseCode.intValue());
410
411         // TEST PUT bad subnet, expect 400, validate JSON exception mapper
412         JSONObject joBad = new JSONObject().put("foo", "bar");
413         result = getJsonResult(baseURL + "default/subnet/foo", "PUT", joBad.toString());
414         Assert.assertEquals(400, httpResponseCode.intValue());
415   }
416
417     @Test
418     public void testStaticRoutingNorthbound() throws JSONException {
419         System.out.println("Starting StaticRouting JAXB client.");
420         String baseURL = baseUrlPrefix + "staticroute/";
421
422         String name1 = "testRoute1";
423         String prefix1 = "192.168.1.1/24";
424         String nextHop1 = "0.0.0.0";
425         String name2 = "testRoute2";
426         String prefix2 = "192.168.1.1/16";
427         String nextHop2 = "1.1.1.1";
428
429         // Test GET static routes in default container, expecting no results
430         String result = getJsonResult(baseURL + "default/routes");
431         JSONTokener jt = new JSONTokener(result);
432         JSONObject json = new JSONObject(jt);
433         JSONArray staticRoutes = json.getJSONArray("staticRoute");
434         Assert.assertEquals(staticRoutes.length(), 0);
435
436         // Test insert static route
437         String requestBody = "{\"name\":\"" + name1 + "\", \"prefix\":\"" + prefix1 + "\", \"nextHop\":\"" + nextHop1
438                 + "\"}";
439         result = getJsonResult(baseURL + "default/route/" + name1, "PUT", requestBody);
440         Assert.assertEquals(201, httpResponseCode.intValue());
441
442         requestBody = "{\"name\":\"" + name2 + "\", \"prefix\":\"" + prefix2 + "\", \"nextHop\":\"" + nextHop2 + "\"}";
443         result = getJsonResult(baseURL + "default/route/" + name2, "PUT", requestBody);
444         Assert.assertEquals(201, httpResponseCode.intValue());
445
446         // Test Get all static routes
447         result = getJsonResult(baseURL + "default/routes");
448         jt = new JSONTokener(result);
449         json = new JSONObject(jt);
450         JSONArray staticRouteArray = json.getJSONArray("staticRoute");
451         Assert.assertEquals(2, staticRouteArray.length());
452         JSONObject route;
453         for (int i = 0; i < staticRoutes.length(); i++) {
454             route = staticRoutes.getJSONObject(i);
455             if (route.getString("name").equals(name1)) {
456                 Assert.assertEquals(prefix1, route.getString("prefix"));
457                 Assert.assertEquals(nextHop1, route.getString("nextHop"));
458             } else if (route.getString("name").equals(name2)) {
459                 Assert.assertEquals(prefix2, route.getString("prefix"));
460                 Assert.assertEquals(nextHop2, route.getString("nextHop"));
461             } else {
462                 // static route has unknown name
463                 Assert.assertTrue(false);
464             }
465         }
466
467         // Test get specific static route
468         result = getJsonResult(baseURL + "default/route/" + name1);
469         jt = new JSONTokener(result);
470         json = new JSONObject(jt);
471
472         Assert.assertEquals(name1, json.getString("name"));
473         Assert.assertEquals(prefix1, json.getString("prefix"));
474         Assert.assertEquals(nextHop1, json.getString("nextHop"));
475
476         result = getJsonResult(baseURL + "default/route/" + name2);
477         jt = new JSONTokener(result);
478         json = new JSONObject(jt);
479
480         Assert.assertEquals(name2, json.getString("name"));
481         Assert.assertEquals(prefix2, json.getString("prefix"));
482         Assert.assertEquals(nextHop2, json.getString("nextHop"));
483
484         // Test delete static route
485         result = getJsonResult(baseURL + "default/route/" + name1, "DELETE");
486         Assert.assertEquals(204, httpResponseCode.intValue());
487
488         result = getJsonResult(baseURL + "default/routes");
489         jt = new JSONTokener(result);
490         json = new JSONObject(jt);
491
492         staticRouteArray = json.getJSONArray("staticRoute");
493         JSONObject singleStaticRoute = staticRouteArray.getJSONObject(0);
494         Assert.assertEquals(name2, singleStaticRoute.getString("name"));
495
496     }
497
498     @Test
499     public void testSwitchManager() throws JSONException {
500         System.out.println("Starting SwitchManager JAXB client.");
501         String baseURL = baseUrlPrefix + "switchmanager/default/";
502
503         // define Node/NodeConnector attributes for test
504         int nodeId_1 = 51966;
505         int nodeId_2 = 3366;
506         int nodeId_3 = 4477;
507         int nodeConnectorId_1 = 51966;
508         int nodeConnectorId_2 = 12;
509         int nodeConnectorId_3 = 34;
510         String nodeType = "STUB";
511         String ncType = "STUB";
512         int timestamp_1 = 100000;
513         String timestampName_1 = "connectedSince";
514         int actionsValue_1 = 2;
515         int capabilitiesValue_1 = 3;
516         int tablesValue_1 = 1;
517         int buffersValue_1 = 1;
518         int ncState = 1;
519         int ncCapabilities = 1;
520         int ncBandwidth = 1000000000;
521
522         // Test GET all nodes
523
524         String result = getJsonResult(baseURL + "nodes");
525         JSONTokener jt = new JSONTokener(result);
526         JSONObject json = new JSONObject(jt);
527
528         // Test for first node
529         JSONObject node = getJsonInstance(json, "nodeProperties", nodeId_1);
530         Assert.assertNotNull(node);
531         testNodeProperties(node, nodeId_1, nodeType, timestamp_1, timestampName_1, actionsValue_1, capabilitiesValue_1,
532                 tablesValue_1, buffersValue_1);
533
534         // Test 2nd node, properties of 2nd node same as first node
535         node = getJsonInstance(json, "nodeProperties", nodeId_2);
536         Assert.assertNotNull(node);
537         testNodeProperties(node, nodeId_2, nodeType, timestamp_1, timestampName_1, actionsValue_1, capabilitiesValue_1,
538                 tablesValue_1, buffersValue_1);
539
540         // Test 3rd node, properties of 3rd node same as first node
541         node = getJsonInstance(json, "nodeProperties", nodeId_3);
542         Assert.assertNotNull(node);
543         testNodeProperties(node, nodeId_3, nodeType, timestamp_1, timestampName_1, actionsValue_1, capabilitiesValue_1,
544                 tablesValue_1, buffersValue_1);
545
546         // Test GET nodeConnectors of a node
547         // Test first node
548         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1);
549         jt = new JSONTokener(result);
550         json = new JSONObject(jt);
551         JSONArray nodeConnectorPropertiesArray = json.getJSONArray("nodeConnectorProperties");
552         JSONObject nodeConnectorProperties = nodeConnectorPropertiesArray.getJSONObject(0);
553
554         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_1, ncType, nodeId_1, nodeType, ncState,
555                 ncCapabilities, ncBandwidth);
556
557         // Test second node
558         result = getJsonResult(baseURL + "node/STUB/" + nodeId_2);
559         jt = new JSONTokener(result);
560         json = new JSONObject(jt);
561
562         nodeConnectorPropertiesArray = json.getJSONArray("nodeConnectorProperties");
563         nodeConnectorProperties = nodeConnectorPropertiesArray.getJSONObject(0);
564
565
566         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_2, ncType, nodeId_2, nodeType, ncState,
567                 ncCapabilities, ncBandwidth);
568
569         // Test third node
570         result = getJsonResult(baseURL + "node/STUB/" + nodeId_3);
571         jt = new JSONTokener(result);
572         json = new JSONObject(jt);
573
574         nodeConnectorPropertiesArray = json.getJSONArray("nodeConnectorProperties");
575         nodeConnectorProperties = nodeConnectorPropertiesArray.getJSONObject(0);
576         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_3, ncType, nodeId_3, nodeType, ncState,
577                 ncCapabilities, ncBandwidth);
578
579         // Test add property to node
580         // Add Tier and Description property to node1
581         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1 + "/property/tier/1001", "PUT");
582         Assert.assertEquals(201, httpResponseCode.intValue());
583         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1 + "/property/description/node1", "PUT");
584         Assert.assertEquals(201, httpResponseCode.intValue());
585
586         // Test for first node
587         result = getJsonResult(baseURL + "nodes");
588         jt = new JSONTokener(result);
589         json = new JSONObject(jt);
590         node = getJsonInstance(json, "nodeProperties", nodeId_1);
591         Assert.assertNotNull(node);
592         Assert.assertEquals(1001, node.getJSONObject("properties").getJSONObject("tier").getInt("value"));
593         Assert.assertEquals("node1", node.getJSONObject("properties").getJSONObject("description").getString("value"));
594
595         // Test delete nodeConnector property
596         // Delete state property of nodeconnector1
597         result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_1 + "/STUB/" + nodeConnectorId_1
598                 + "/property/state", "DELETE");
599         Assert.assertEquals(204, httpResponseCode.intValue());
600
601         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1);
602         jt = new JSONTokener(result);
603         json = new JSONObject(jt);
604         nodeConnectorPropertiesArray = json.getJSONArray("nodeConnectorProperties");
605         nodeConnectorProperties = nodeConnectorPropertiesArray.getJSONObject(0);
606
607         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_1, ncType, nodeId_1, nodeType, null,
608                 ncCapabilities, ncBandwidth);
609
610         // Delete capabilities property of nodeconnector2
611         result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_2 + "/STUB/" + nodeConnectorId_2
612                 + "/property/capabilities", "DELETE");
613         Assert.assertEquals(204, httpResponseCode.intValue());
614
615         result = getJsonResult(baseURL + "node/STUB/" + nodeId_2);
616         jt = new JSONTokener(result);
617         json = new JSONObject(jt);
618         nodeConnectorPropertiesArray = json.getJSONArray("nodeConnectorProperties");
619         nodeConnectorProperties = nodeConnectorPropertiesArray.getJSONObject(0);
620
621         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_2, ncType, nodeId_2, nodeType, ncState,
622                 null, ncBandwidth);
623
624         // Test PUT nodeConnector property
625         int newBandwidth = 1001;
626
627         // Add Name/Bandwidth property to nodeConnector1
628         result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_1 + "/STUB/" + nodeConnectorId_1
629                 + "/property/bandwidth/" + newBandwidth, "PUT");
630         Assert.assertEquals(201, httpResponseCode.intValue());
631
632         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1);
633         jt = new JSONTokener(result);
634         json = new JSONObject(jt);
635         nodeConnectorPropertiesArray = json.getJSONArray("nodeConnectorProperties");
636         nodeConnectorProperties = nodeConnectorPropertiesArray.getJSONObject(0);
637
638         // Check for new bandwidth value, state value removed from previous
639         // test
640         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_1, ncType, nodeId_1, nodeType, null,
641                 ncCapabilities, newBandwidth);
642
643     }
644
645     @Test
646     public void testStatistics() throws JSONException {
647         final String actionTypes[] = { "DROP", "LOOPBACK", "FLOOD", "FLOOD_ALL", "CONTROLLER", "SW_PATH", "HW_PATH", "OUTPUT",
648                 "SET_DL_SRC", "SET_DL_DST", "SET_DL_TYPE", "SET_VLAN_ID", "SET_VLAN_PCP", "SET_VLAN_CFI", "POP_VLAN", "PUSH_VLAN",
649                 "SET_NW_SRC", "SET_NW_DST", "SET_NW_TOS", "SET_TP_SRC", "SET_TP_DST" };
650         System.out.println("Starting Statistics JAXB client.");
651
652         String baseURL = baseUrlPrefix + "statistics/default/";
653
654         String result = getJsonResult(baseURL + "flow");
655         JSONTokener jt = new JSONTokener(result);
656         JSONObject json = new JSONObject(jt);
657         JSONObject flowStatistics = getJsonInstance(json, "flowStatistics", 0xCAFE);
658         JSONObject node = flowStatistics.getJSONObject("node");
659         // test that node was returned properly
660         Assert.assertTrue(node.getInt("id") == 0xCAFE);
661         Assert.assertEquals(node.getString("type"), "STUB");
662
663         // test that flow statistics results are correct
664         JSONArray flowStats = flowStatistics.getJSONArray("flowStatistic");
665         for (int i = 0; i < flowStats.length(); i++) {
666
667             JSONObject flowStat = flowStats.getJSONObject(i);
668             testFlowStat(flowStat, actionTypes[i], i);
669
670         }
671
672         // for /controller/nb/v2/statistics/default/port
673         result = getJsonResult(baseURL + "port");
674         jt = new JSONTokener(result);
675         json = new JSONObject(jt);
676         JSONObject portStatistics = getJsonInstance(json, "portStatistics", 0xCAFE);
677         JSONObject node2 = portStatistics.getJSONObject("node");
678         // test that node was returned properly
679         Assert.assertTrue(node2.getInt("id") == 0xCAFE);
680         Assert.assertEquals(node2.getString("type"), "STUB");
681
682         // test that port statistic results are correct
683         JSONArray portStatArray = portStatistics.getJSONArray("portStatistic");
684         JSONObject portStat = portStatArray.getJSONObject(0);
685         Assert.assertTrue(portStat.getInt("receivePackets") == 250);
686         Assert.assertTrue(portStat.getInt("transmitPackets") == 500);
687         Assert.assertTrue(portStat.getInt("receiveBytes") == 1000);
688         Assert.assertTrue(portStat.getInt("transmitBytes") == 5000);
689         Assert.assertTrue(portStat.getInt("receiveDrops") == 2);
690         Assert.assertTrue(portStat.getInt("transmitDrops") == 50);
691         Assert.assertTrue(portStat.getInt("receiveErrors") == 3);
692         Assert.assertTrue(portStat.getInt("transmitErrors") == 10);
693         Assert.assertTrue(portStat.getInt("receiveFrameError") == 5);
694         Assert.assertTrue(portStat.getInt("receiveOverRunError") == 6);
695         Assert.assertTrue(portStat.getInt("receiveCrcError") == 1);
696         Assert.assertTrue(portStat.getInt("collisionCount") == 4);
697
698         // test for getting one specific node's stats
699         result = getJsonResult(baseURL + "flow/node/STUB/51966");
700         jt = new JSONTokener(result);
701         json = new JSONObject(jt);
702         node = json.getJSONObject("node");
703         // test that node was returned properly
704         Assert.assertTrue(node.getInt("id") == 0xCAFE);
705         Assert.assertEquals(node.getString("type"), "STUB");
706
707         // test that flow statistics results are correct
708         flowStats = json.getJSONArray("flowStatistic");
709         for (int i = 0; i < flowStats.length(); i++) {
710             JSONObject flowStat = flowStats.getJSONObject(i);
711             testFlowStat(flowStat, actionTypes[i], i);
712         }
713
714         result = getJsonResult(baseURL + "port/node/STUB/51966");
715         jt = new JSONTokener(result);
716         json = new JSONObject(jt);
717         node2 = json.getJSONObject("node");
718         // test that node was returned properly
719         Assert.assertTrue(node2.getInt("id") == 0xCAFE);
720         Assert.assertEquals(node2.getString("type"), "STUB");
721
722         // test that port statistic results are correct
723         portStatArray = json.getJSONArray("portStatistic");
724         portStat = portStatArray.getJSONObject(0);
725
726         Assert.assertTrue(portStat.getInt("receivePackets") == 250);
727         Assert.assertTrue(portStat.getInt("transmitPackets") == 500);
728         Assert.assertTrue(portStat.getInt("receiveBytes") == 1000);
729         Assert.assertTrue(portStat.getInt("transmitBytes") == 5000);
730         Assert.assertTrue(portStat.getInt("receiveDrops") == 2);
731         Assert.assertTrue(portStat.getInt("transmitDrops") == 50);
732         Assert.assertTrue(portStat.getInt("receiveErrors") == 3);
733         Assert.assertTrue(portStat.getInt("transmitErrors") == 10);
734         Assert.assertTrue(portStat.getInt("receiveFrameError") == 5);
735         Assert.assertTrue(portStat.getInt("receiveOverRunError") == 6);
736         Assert.assertTrue(portStat.getInt("receiveCrcError") == 1);
737         Assert.assertTrue(portStat.getInt("collisionCount") == 4);
738     }
739
740     private void testFlowStat(JSONObject flowStat, String actionType, int actIndex) throws JSONException {
741         Assert.assertTrue(flowStat.getInt("tableId") == 1);
742         Assert.assertTrue(flowStat.getInt("durationSeconds") == 40);
743         Assert.assertTrue(flowStat.getInt("durationNanoseconds") == 400);
744         Assert.assertTrue(flowStat.getInt("packetCount") == 200);
745         Assert.assertTrue(flowStat.getInt("byteCount") == 100);
746
747         // test that flow information is correct
748         JSONObject flow = flowStat.getJSONObject("flow");
749         Assert.assertTrue(flow.getInt("priority") == (3500 + actIndex));
750         Assert.assertTrue(flow.getInt("idleTimeout") == 1000);
751         Assert.assertTrue(flow.getInt("hardTimeout") == 2000);
752         Assert.assertTrue(flow.getInt("id") == 12345);
753
754         JSONArray matches = (flow.getJSONObject("match").getJSONArray("matchField"));
755         Assert.assertEquals(matches.length(), 1);
756         JSONObject match = matches.getJSONObject(0);
757         Assert.assertTrue(match.getString("type").equals("NW_DST"));
758         Assert.assertTrue(match.getString("value").equals("1.1.1.1"));
759
760         JSONArray actionsArray = flow.getJSONArray("actions");
761         Assert.assertEquals(actionsArray.length(), 1);
762         JSONObject act = actionsArray.getJSONObject(0);
763         Assert.assertTrue(act.getString("type").equals(actionType));
764
765         if (act.getString("type").equals("OUTPUT")) {
766             JSONObject port = act.getJSONObject("port");
767             JSONObject port_node = port.getJSONObject("node");
768             Assert.assertTrue(port.getInt("id") == 51966);
769             Assert.assertTrue(port.getString("type").equals("STUB"));
770             Assert.assertTrue(port_node.getInt("id") == 51966);
771             Assert.assertTrue(port_node.getString("type").equals("STUB"));
772         }
773
774         if (act.getString("type").equals("SET_DL_SRC")) {
775             byte srcMatch[] = { (byte) 5, (byte) 4, (byte) 3, (byte) 2, (byte) 1 };
776             String src = act.getString("address");
777             byte srcBytes[] = new byte[5];
778             srcBytes[0] = Byte.parseByte(src.substring(0, 2));
779             srcBytes[1] = Byte.parseByte(src.substring(2, 4));
780             srcBytes[2] = Byte.parseByte(src.substring(4, 6));
781             srcBytes[3] = Byte.parseByte(src.substring(6, 8));
782             srcBytes[4] = Byte.parseByte(src.substring(8, 10));
783             Assert.assertTrue(Arrays.equals(srcBytes, srcMatch));
784         }
785
786         if (act.getString("type").equals("SET_DL_DST")) {
787             byte dstMatch[] = { (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5 };
788             String dst = act.getString("address");
789             byte dstBytes[] = new byte[5];
790             dstBytes[0] = Byte.parseByte(dst.substring(0, 2));
791             dstBytes[1] = Byte.parseByte(dst.substring(2, 4));
792             dstBytes[2] = Byte.parseByte(dst.substring(4, 6));
793             dstBytes[3] = Byte.parseByte(dst.substring(6, 8));
794             dstBytes[4] = Byte.parseByte(dst.substring(8, 10));
795             Assert.assertTrue(Arrays.equals(dstBytes, dstMatch));
796         }
797         if (act.getString("type").equals("SET_DL_TYPE")) {
798             Assert.assertTrue(act.getInt("dlType") == 10);
799         }
800         if (act.getString("type").equals("SET_VLAN_ID")) {
801             Assert.assertTrue(act.getInt("vlanId") == 2);
802         }
803         if (act.getString("type").equals("SET_VLAN_PCP")) {
804             Assert.assertTrue(act.getInt("pcp") == 3);
805         }
806         if (act.getString("type").equals("SET_VLAN_CFI")) {
807             Assert.assertTrue(act.getInt("cfi") == 1);
808         }
809
810         if (act.getString("type").equals("SET_NW_SRC")) {
811             Assert.assertTrue(act.getString("address").equals("2.2.2.2"));
812         }
813         if (act.getString("type").equals("SET_NW_DST")) {
814             Assert.assertTrue(act.getString("address").equals("1.1.1.1"));
815         }
816
817         if (act.getString("type").equals("PUSH_VLAN")) {
818             int head = act.getInt("VlanHeader");
819             // parsing vlan header
820             int id = head & 0xfff;
821             int cfi = (head >> 12) & 0x1;
822             int pcp = (head >> 13) & 0x7;
823             int tag = (head >> 16) & 0xffff;
824             Assert.assertTrue(id == 1234);
825             Assert.assertTrue(cfi == 1);
826             Assert.assertTrue(pcp == 1);
827             Assert.assertTrue(tag == 0x8100);
828         }
829         if (act.getString("type").equals("SET_NW_TOS")) {
830             Assert.assertTrue(act.getInt("tos") == 16);
831         }
832         if (act.getString("type").equals("SET_TP_SRC")) {
833             Assert.assertTrue(act.getInt("port") == 4201);
834         }
835         if (act.getString("type").equals("SET_TP_DST")) {
836             Assert.assertTrue(act.getInt("port") == 8080);
837         }
838     }
839
840     @Test
841     public void testFlowProgrammer() throws JSONException {
842         System.out.println("Starting FlowProgrammer JAXB client.");
843         String baseURL = baseUrlPrefix + "flowprogrammer/default/";
844         // Attempt to get a flow that doesn't exit. Should return 404
845         // status.
846         String result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test1", "GET");
847         Assert.assertTrue(result.equals("404"));
848
849         // test add flow1
850         String fc = "{\"name\":\"test1\", \"node\":{\"id\":\"51966\",\"type\":\"STUB\"}, \"actions\":[\"DROP\"]}";
851         result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test1", "PUT", fc);
852         Assert.assertTrue(httpResponseCode == 201);
853
854         // test get returns flow that was added.
855         result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test1", "GET");
856         // check that result came out fine.
857         Assert.assertTrue(httpResponseCode == 200);
858         JSONTokener jt = new JSONTokener(result);
859         JSONObject json = new JSONObject(jt);
860         Assert.assertEquals(json.getString("name"), "test1");
861         JSONArray actionsArray = json.getJSONArray("actions");
862         Assert.assertEquals(actionsArray.getString(0), "DROP");
863         Assert.assertEquals(json.getString("installInHw"), "true");
864         JSONObject node = json.getJSONObject("node");
865         Assert.assertEquals(node.getString("type"), "STUB");
866         Assert.assertEquals(node.getString("id"), "51966");
867         // test adding same flow again succeeds with a change in any field ..return Success
868         // code
869         fc = "{\"name\":\"test1\", \"node\":{\"id\":\"51966\",\"type\":\"STUB\"}, \"actions\":[\"LOOPBACK\"]}";
870         result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test1", "PUT", fc);
871         Assert.assertTrue(result.contains("Success"));
872
873         fc = "{\"name\":\"test2\", \"node\":{\"id\":\"51966\",\"type\":\"STUB\"}, \"actions\":[\"DROP\"]}";
874         result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test2", "PUT", fc);
875         // test should return 409 for error due to same flow being added.
876         Assert.assertTrue(result.equals("409"));
877
878         // add second flow that's different
879         fc = "{\"name\":\"test2\", \"nwSrc\":\"1.1.1.1\", \"node\":{\"id\":\"51966\",\"type\":\"STUB\"}, \"actions\":[\"DROP\"]}";
880         result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test2", "PUT", fc);
881         Assert.assertTrue(httpResponseCode == 201);
882
883         // check that request returns both flows given node.
884         result = getJsonResult(baseURL + "node/STUB/51966/", "GET");
885         jt = new JSONTokener(result);
886         json = new JSONObject(jt);
887         Assert.assertTrue(json.get("flowConfig") instanceof JSONArray);
888         JSONArray ja = json.getJSONArray("flowConfig");
889         Integer count = ja.length();
890         Assert.assertTrue(count == 2);
891
892         // check that request returns both flows given just container.
893         result = getJsonResult(baseURL);
894         jt = new JSONTokener(result);
895         json = new JSONObject(jt);
896         Assert.assertTrue(json.get("flowConfig") instanceof JSONArray);
897         ja = json.getJSONArray("flowConfig");
898         count = ja.length();
899         Assert.assertTrue(count == 2);
900
901         // delete a flow, check that it's no longer in list.
902         result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test2", "DELETE");
903         Assert.assertTrue(httpResponseCode == 204);
904
905         result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test2", "GET");
906         Assert.assertTrue(result.equals("404"));
907     }
908
909     // method to extract a JSONObject with specified node ID from a JSONObject
910     // that may contain an array of JSONObjects
911     // This is specifically written for statistics manager northbound REST
912     // interface
913     // array_name should be either "flowStatistics" or "portStatistics"
914     private JSONObject getJsonInstance(JSONObject json, String array_name, Integer nodeId) throws JSONException {
915         JSONObject result = null;
916         if (json.get(array_name) instanceof JSONArray) {
917             JSONArray json_array = json.getJSONArray(array_name);
918             for (int i = 0; i < json_array.length(); i++) {
919                 result = json_array.getJSONObject(i);
920                 Integer nid = result.getJSONObject("node").getInt("id");
921                 if (nid.equals(nodeId)) {
922                     break;
923                 }
924             }
925         } else {
926             result = json.getJSONObject(array_name);
927             Integer nid = result.getJSONObject("node").getInt("id");
928             if (!nid.equals(nodeId)) {
929                 result = null;
930             }
931         }
932         return result;
933     }
934
935     // a class to construct query parameter for HTTP request
936     private class QueryParameter {
937         StringBuilder queryString = null;
938
939         // constructor
940         QueryParameter(String key, String value) {
941             queryString = new StringBuilder();
942             queryString.append("?").append(key).append("=").append(value);
943         }
944
945         // method to add more query parameter
946         QueryParameter add(String key, String value) {
947             this.queryString.append("&").append(key).append("=").append(value);
948             return this;
949         }
950
951         // method to get the query parameter string
952         String getString() {
953             return this.queryString.toString();
954         }
955
956     }
957
958     @Test
959     public void testHostTracker() throws JSONException {
960
961         System.out.println("Starting HostTracker JAXB client.");
962
963         // setup 2 host models for @POST method
964         // 1st host
965         String networkAddress_1 = "192.168.0.8";
966         String dataLayerAddress_1 = "11:22:33:44:55:66";
967         String nodeType_1 = "STUB";
968         Integer nodeId_1 = 3366;
969         String nodeConnectorType_1 = "STUB";
970         Integer nodeConnectorId_1 = 12;
971         String vlan_1 = "";
972
973         // 2nd host
974         String networkAddress_2 = "10.1.1.1";
975         String dataLayerAddress_2 = "1A:2B:3C:4D:5E:6F";
976         String nodeType_2 = "STUB";
977         Integer nodeId_2 = 4477;
978         String nodeConnectorType_2 = "STUB";
979         Integer nodeConnectorId_2 = 34;
980         String vlan_2 = "123";
981
982         String baseURL = baseUrlPrefix + "hosttracker/default";
983
984         // test PUT method: addHost()
985         JSONObject fc_json = new JSONObject();
986         fc_json.put("dataLayerAddress", dataLayerAddress_1);
987         fc_json.put("nodeType", nodeType_1);
988         fc_json.put("nodeId", nodeId_1);
989         fc_json.put("nodeConnectorType", nodeType_1);
990         fc_json.put("nodeConnectorId", nodeConnectorId_1.toString());
991         fc_json.put("vlan", vlan_1);
992         fc_json.put("staticHost", "true");
993         fc_json.put("networkAddress", networkAddress_1);
994
995         String result = getJsonResult(baseURL + "/address/" + networkAddress_1, "PUT", fc_json.toString());
996         Assert.assertTrue(httpResponseCode == 201);
997
998         fc_json = new JSONObject();
999         fc_json.put("dataLayerAddress", dataLayerAddress_2);
1000         fc_json.put("nodeType", nodeType_2);
1001         fc_json.put("nodeId", nodeId_2);
1002         fc_json.put("nodeConnectorType", nodeType_2);
1003         fc_json.put("nodeConnectorId", nodeConnectorId_2.toString());
1004         fc_json.put("vlan", vlan_2);
1005         fc_json.put("staticHost", "true");
1006         fc_json.put("networkAddress", networkAddress_2);
1007
1008         result = getJsonResult(baseURL + "/address/" + networkAddress_2 , "PUT", fc_json.toString());
1009         Assert.assertTrue(httpResponseCode == 201);
1010
1011         // define variables for decoding returned strings
1012         String networkAddress;
1013         JSONObject host_jo;
1014
1015         // the two hosts should be in inactive host DB
1016         // test GET method: getInactiveHosts()
1017         result = getJsonResult(baseURL + "/hosts/inactive", "GET");
1018         Assert.assertTrue(httpResponseCode == 200);
1019
1020         JSONTokener jt = new JSONTokener(result);
1021         JSONObject json = new JSONObject(jt);
1022         // there should be at least two hosts in the DB
1023         Assert.assertTrue(json.get("hostConfig") instanceof JSONArray);
1024         JSONArray ja = json.getJSONArray("hostConfig");
1025         Integer count = ja.length();
1026         Assert.assertTrue(count == 2);
1027
1028         for (int i = 0; i < count; i++) {
1029             host_jo = ja.getJSONObject(i);
1030             networkAddress = host_jo.getString("networkAddress");
1031             if (networkAddress.equalsIgnoreCase(networkAddress_1)) {
1032                 Assert.assertTrue(host_jo.getString("dataLayerAddress").equalsIgnoreCase(dataLayerAddress_1));
1033                 Assert.assertTrue(host_jo.getString("nodeConnectorType").equalsIgnoreCase(nodeConnectorType_1));
1034                 Assert.assertTrue(host_jo.getInt("nodeConnectorId") == nodeConnectorId_1);
1035                 Assert.assertTrue(host_jo.getString("nodeType").equalsIgnoreCase(nodeType_1));
1036                 Assert.assertTrue(host_jo.getInt("nodeId") == nodeId_1);
1037                 Assert.assertTrue(host_jo.getString("vlan").equals("0"));
1038                 Assert.assertTrue(host_jo.getBoolean("staticHost"));
1039             } else if (networkAddress.equalsIgnoreCase(networkAddress_2)) {
1040                 Assert.assertTrue(host_jo.getString("dataLayerAddress").equalsIgnoreCase(dataLayerAddress_2));
1041                 Assert.assertTrue(host_jo.getString("nodeConnectorType").equalsIgnoreCase(nodeConnectorType_2));
1042                 Assert.assertTrue(host_jo.getInt("nodeConnectorId") == nodeConnectorId_2);
1043                 Assert.assertTrue(host_jo.getString("nodeType").equalsIgnoreCase(nodeType_2));
1044                 Assert.assertTrue(host_jo.getInt("nodeId") == nodeId_2);
1045                 Assert.assertTrue(host_jo.getString("vlan").equalsIgnoreCase(vlan_2));
1046                 Assert.assertTrue(host_jo.getBoolean("staticHost"));
1047             } else {
1048                 Assert.assertTrue(false);
1049             }
1050         }
1051
1052         // test GET method: getActiveHosts() - no host expected
1053         result = getJsonResult(baseURL + "/hosts/active", "GET");
1054         Assert.assertTrue(httpResponseCode == 200);
1055
1056         jt = new JSONTokener(result);
1057         json = new JSONObject(jt);
1058         Assert.assertFalse(hostInJson(json, networkAddress_1));
1059         Assert.assertFalse(hostInJson(json, networkAddress_2));
1060
1061         // put the 1st host into active host DB
1062         Node nd;
1063         NodeConnector ndc;
1064         try {
1065             nd = new Node(nodeType_1, nodeId_1);
1066             ndc = new NodeConnector(nodeConnectorType_1, nodeConnectorId_1, nd);
1067             this.invtoryListener.notifyNodeConnector(ndc, UpdateType.ADDED, null);
1068         } catch (ConstructionException e) {
1069             ndc = null;
1070             nd = null;
1071         }
1072
1073         // verify the host shows up in active host DB
1074
1075         result = getJsonResult(baseURL + "/hosts/active", "GET");
1076         Assert.assertTrue(httpResponseCode == 200);
1077
1078         jt = new JSONTokener(result);
1079         json = new JSONObject(jt);
1080
1081         Assert.assertTrue(hostInJson(json, networkAddress_1));
1082
1083         // test GET method for getHostDetails()
1084
1085         result = getJsonResult(baseURL + "/address/" + networkAddress_1, "GET");
1086         Assert.assertTrue(httpResponseCode == 200);
1087
1088         jt = new JSONTokener(result);
1089         json = new JSONObject(jt);
1090
1091         Assert.assertFalse(json.length() == 0);
1092
1093         Assert.assertTrue(json.getString("dataLayerAddress").equalsIgnoreCase(dataLayerAddress_1));
1094         Assert.assertTrue(json.getString("nodeConnectorType").equalsIgnoreCase(nodeConnectorType_1));
1095         Assert.assertTrue(json.getInt("nodeConnectorId") == nodeConnectorId_1);
1096         Assert.assertTrue(json.getString("nodeType").equalsIgnoreCase(nodeType_1));
1097         Assert.assertTrue(json.getInt("nodeId") == nodeId_1);
1098         Assert.assertTrue(json.getString("vlan").equals("0"));
1099         Assert.assertTrue(json.getBoolean("staticHost"));
1100
1101         // test DELETE method for deleteFlow()
1102
1103         result = getJsonResult(baseURL + "/address/" + networkAddress_1, "DELETE");
1104         Assert.assertTrue(httpResponseCode == 204);
1105
1106         // verify host_1 removed from active host DB
1107         // test GET method: getActiveHosts() - no host expected
1108
1109         result = getJsonResult(baseURL + "/hosts/active", "GET");
1110         Assert.assertTrue(httpResponseCode == 200);
1111
1112         jt = new JSONTokener(result);
1113         json = new JSONObject(jt);
1114
1115         Assert.assertFalse(hostInJson(json, networkAddress_1));
1116
1117     }
1118
1119     private Boolean hostInJson(JSONObject json, String hostIp) throws JSONException {
1120         // input JSONObject may be empty
1121         if (json.length() == 0) {
1122             return false;
1123         }
1124         if (json.get("hostConfig") instanceof JSONArray) {
1125             JSONArray ja = json.getJSONArray("hostConfig");
1126             for (int i = 0; i < ja.length(); i++) {
1127                 String na = ja.getJSONObject(i).getString("networkAddress");
1128                 if (na.equalsIgnoreCase(hostIp)) {
1129                     return true;
1130                 }
1131             }
1132             return false;
1133         } else {
1134             JSONObject ja = json.getJSONObject("hostConfig");
1135             String na = ja.getString("networkAddress");
1136             return na.equalsIgnoreCase(hostIp);
1137         }
1138     }
1139
1140     @Test
1141     public void testTopology() throws JSONException, ConstructionException {
1142         System.out.println("Starting Topology JAXB client.");
1143         String baseURL = baseUrlPrefix + "topology/default";
1144
1145         // === test GET method for getTopology()
1146         short state_1 = State.EDGE_UP, state_2 = State.EDGE_DOWN;
1147         long bw_1 = Bandwidth.BW10Gbps, bw_2 = Bandwidth.BW100Mbps;
1148         long lat_1 = Latency.LATENCY100ns, lat_2 = Latency.LATENCY1ms;
1149         String nodeType = "STUB";
1150         String nodeConnType = "STUB";
1151         int headNC1_nodeId = 1, headNC1_nodeConnId = 11;
1152         int tailNC1_nodeId = 2, tailNC1_nodeConnId = 22;
1153         int headNC2_nodeId = 2, headNC2_nodeConnId = 21;
1154         int tailNC2_nodeId = 1, tailNC2_nodeConnId = 12;
1155
1156         List<TopoEdgeUpdate> topoedgeupdateList = new ArrayList<TopoEdgeUpdate>();
1157         NodeConnector headnc1 = new NodeConnector(nodeConnType, headNC1_nodeConnId, new Node(nodeType, headNC1_nodeId));
1158         NodeConnector tailnc1 = new NodeConnector(nodeConnType, tailNC1_nodeConnId, new Node(nodeType, tailNC1_nodeId));
1159         Edge e1 = new Edge(tailnc1, headnc1);
1160         Set<Property> props_1 = new HashSet<Property>();
1161         props_1.add(new State(state_1));
1162         props_1.add(new Bandwidth(bw_1));
1163         props_1.add(new Latency(lat_1));
1164         TopoEdgeUpdate teu1 = new TopoEdgeUpdate(e1, props_1, UpdateType.ADDED);
1165         topoedgeupdateList.add(teu1);
1166
1167         NodeConnector headnc2 = new NodeConnector(nodeConnType, headNC2_nodeConnId, new Node(nodeType, headNC2_nodeId));
1168         NodeConnector tailnc2 = new NodeConnector(nodeConnType, tailNC2_nodeConnId, new Node(nodeType, tailNC2_nodeId));
1169         Edge e2 = new Edge(tailnc2, headnc2);
1170         Set<Property> props_2 = new HashSet<Property>();
1171         props_2.add(new State(state_2));
1172         props_2.add(new Bandwidth(bw_2));
1173         props_2.add(new Latency(lat_2));
1174
1175         TopoEdgeUpdate teu2 = new TopoEdgeUpdate(e2, props_2, UpdateType.ADDED);
1176         topoedgeupdateList.add(teu2);
1177
1178         topoUpdates.edgeUpdate(topoedgeupdateList);
1179
1180         // HTTP request
1181         String result = getJsonResult(baseURL, "GET");
1182         Assert.assertTrue(httpResponseCode == 200);
1183         if (debugMsg) {
1184             System.out.println("Get Topology: " + result);
1185         }
1186
1187         // returned data must be an array of edges
1188         JSONTokener jt = new JSONTokener(result);
1189         JSONObject json = new JSONObject(jt);
1190         Assert.assertTrue(json.get("edgeProperties") instanceof JSONArray);
1191         JSONArray ja = json.getJSONArray("edgeProperties");
1192
1193         for (int i = 0; i < ja.length(); i++) {
1194             JSONObject edgeProp = ja.getJSONObject(i);
1195             JSONObject edge = edgeProp.getJSONObject("edge");
1196             JSONObject tailNC = edge.getJSONObject("tailNodeConnector");
1197             JSONObject tailNode = tailNC.getJSONObject("node");
1198
1199             JSONObject headNC = edge.getJSONObject("headNodeConnector");
1200             JSONObject headNode = headNC.getJSONObject("node");
1201             JSONObject Props = edgeProp.getJSONObject("properties");
1202             JSONObject bandw = Props.getJSONObject("bandwidth");
1203             JSONObject stt = Props.getJSONObject("state");
1204             JSONObject ltc = Props.getJSONObject("latency");
1205
1206             if (headNC.getInt("id") == headNC1_nodeConnId) {
1207                 Assert.assertEquals(headNode.getString("type"), nodeType);
1208                 Assert.assertEquals(headNode.getLong("id"), headNC1_nodeId);
1209                 Assert.assertEquals(headNC.getString("type"), nodeConnType);
1210                 Assert.assertEquals(tailNode.getString("type"),nodeType);
1211                 Assert.assertEquals(tailNode.getString("type"), nodeConnType);
1212                 Assert.assertEquals(tailNC.getLong("id"), tailNC1_nodeConnId);
1213                 Assert.assertEquals(bandw.getLong("value"), bw_1);
1214                 Assert.assertTrue((short) stt.getInt("value") == state_1);
1215                 Assert.assertEquals(ltc.getLong("value"), lat_1);
1216             } else if (headNC.getInt("id") == headNC2_nodeConnId) {
1217                 Assert.assertEquals(headNode.getString("type"),nodeType);
1218                 Assert.assertEquals(headNode.getLong("id"), headNC2_nodeId);
1219                 Assert.assertEquals(headNC.getString("type"), nodeConnType);
1220                 Assert.assertEquals(tailNode.getString("type"), nodeType);
1221                 Assert.assertTrue(tailNode.getInt("id") == tailNC2_nodeId);
1222                 Assert.assertEquals(tailNC.getString("type"), nodeConnType);
1223                 Assert.assertEquals(tailNC.getLong("id"), tailNC2_nodeConnId);
1224                 Assert.assertEquals(bandw.getLong("value"), bw_2);
1225                 Assert.assertTrue((short) stt.getInt("value") == state_2);
1226                 Assert.assertEquals(ltc.getLong("value"), lat_2);
1227             }
1228         }
1229
1230         // === test POST method for addUserLink()
1231         // define 2 sample nodeConnectors for user link configuration tests
1232         String nodeType_1 = "STUB";
1233         Integer nodeId_1 = 3366;
1234         String nodeConnectorType_1 = "STUB";
1235         Integer nodeConnectorId_1 = 12;
1236         String nodeType_2 = "STUB";
1237         Integer nodeId_2 = 4477;
1238         String nodeConnectorType_2 = "STUB";
1239         Integer nodeConnectorId_2 = 34;
1240
1241         JSONObject jo = new JSONObject()
1242                 .put("name", "userLink_1")
1243                 .put("srcNodeConnector",
1244                         nodeConnectorType_1 + "|" + nodeConnectorId_1 + "@" + nodeType_1 + "|" + nodeId_1)
1245                 .put("dstNodeConnector",
1246                         nodeConnectorType_2 + "|" + nodeConnectorId_2 + "@" + nodeType_2 + "|" + nodeId_2);
1247         // execute HTTP request and verify response code
1248         result = getJsonResult(baseURL + "/userLink/userLink_1", "PUT", jo.toString());
1249         Assert.assertTrue(httpResponseCode == 201);
1250
1251         // === test GET method for getUserLinks()
1252         result = getJsonResult(baseURL + "/userLinks", "GET");
1253         Assert.assertTrue(httpResponseCode == 200);
1254         if (debugMsg) {
1255             System.out.println("result:" + result);
1256         }
1257
1258         jt = new JSONTokener(result);
1259         json = new JSONObject(jt);
1260
1261         // should have at least one object returned
1262         Assert.assertFalse(json.length() == 0);
1263         JSONObject userlink = new JSONObject();
1264
1265         if (json.get("userLinks") instanceof JSONArray) {
1266             ja = json.getJSONArray("userLinks");
1267             int i;
1268             for (i = 0; i < ja.length(); i++) {
1269                 userlink = ja.getJSONObject(i);
1270                 if (userlink.getString("name").equalsIgnoreCase("userLink_1")) {
1271                     break;
1272                 }
1273             }
1274             Assert.assertFalse(i == ja.length());
1275         } else {
1276             userlink = json.getJSONObject("userLinks");
1277             Assert.assertTrue(userlink.getString("name").equalsIgnoreCase("userLink_1"));
1278         }
1279
1280         String[] level_1, level_2;
1281         level_1 = userlink.getString("srcNodeConnector").split("\\@");
1282         level_2 = level_1[0].split("\\|");
1283         Assert.assertTrue(level_2[0].equalsIgnoreCase(nodeConnectorType_1));
1284         Assert.assertTrue(Integer.parseInt(level_2[1]) == nodeConnectorId_1);
1285         level_2 = level_1[1].split("\\|");
1286         Assert.assertTrue(level_2[0].equalsIgnoreCase(nodeType_1));
1287         Assert.assertTrue(Integer.parseInt(level_2[1]) == nodeId_1);
1288         level_1 = userlink.getString("dstNodeConnector").split("\\@");
1289         level_2 = level_1[0].split("\\|");
1290         Assert.assertTrue(level_2[0].equalsIgnoreCase(nodeConnectorType_2));
1291         Assert.assertTrue(Integer.parseInt(level_2[1]) == nodeConnectorId_2);
1292         level_2 = level_1[1].split("\\|");
1293         Assert.assertTrue(level_2[0].equalsIgnoreCase(nodeType_2));
1294         Assert.assertTrue(Integer.parseInt(level_2[1]) == nodeId_2);
1295
1296         // === test DELETE method for deleteUserLink()
1297         String userName = "userLink_1";
1298         result = getJsonResult(baseURL + "/userLink/" + userName, "DELETE");
1299         Assert.assertTrue(httpResponseCode == 204);
1300
1301         // execute another getUserLinks() request to verify that userLink_1 is
1302         // removed
1303         result = getJsonResult(baseURL + "/userLinks", "GET");
1304         Assert.assertTrue(httpResponseCode == 200);
1305         if (debugMsg) {
1306             System.out.println("result:" + result);
1307         }
1308         jt = new JSONTokener(result);
1309         json = new JSONObject(jt);
1310
1311         if (json.length() != 0) {
1312             if (json.get("userLinks") instanceof JSONArray) {
1313                 ja = json.getJSONArray("userLinks");
1314                 for (int i = 0; i < ja.length(); i++) {
1315                     userlink = ja.getJSONObject(i);
1316                     Assert.assertFalse(userlink.getString("name").equalsIgnoreCase("userLink_1"));
1317                 }
1318             } else {
1319                 userlink = json.getJSONObject("userLinks");
1320                 Assert.assertFalse(userlink.getString("name").equalsIgnoreCase("userLink_1"));
1321             }
1322         }
1323     }
1324     // Configure the OSGi container
1325     @Configuration
1326     public Option[] config() {
1327         return options(
1328                 //
1329                 systemProperty("logback.configurationFile").value(
1330                         "file:" + PathUtils.getBaseDir() + "/src/test/resources/logback.xml"),
1331                 // To start OSGi console for inspection remotely
1332                 systemProperty("osgi.console").value("2401"),
1333                 systemProperty("org.eclipse.gemini.web.tomcat.config.path").value(
1334                         PathUtils.getBaseDir() + "/src/test/resources/tomcat-server.xml"),
1335
1336                 // setting default level. Jersey bundles will need to be started
1337                 // earlier.
1338                 systemProperty("osgi.bundles.defaultStartLevel").value("4"),
1339
1340                 // Set the systemPackages (used by clustering)
1341                 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
1342                 mavenBundle("org.slf4j", "jcl-over-slf4j").versionAsInProject(),
1343                 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
1344                 mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(),
1345                 mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(),
1346                 mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(),
1347                 mavenBundle("org.apache.commons", "commons-lang3").versionAsInProject(),
1348                 mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager").versionAsInProject(),
1349
1350                 // the plugin stub to get data for the tests
1351                 mavenBundle("org.opendaylight.controller", "protocol_plugins.stub").versionAsInProject(),
1352
1353                 // List all the opendaylight modules
1354                 mavenBundle("org.opendaylight.controller", "configuration").versionAsInProject(),
1355                 mavenBundle("org.opendaylight.controller", "configuration.implementation").versionAsInProject(),
1356                 mavenBundle("org.opendaylight.controller", "containermanager").versionAsInProject(),
1357                 mavenBundle("org.opendaylight.controller", "containermanager.it.implementation").versionAsInProject(),
1358                 mavenBundle("org.opendaylight.controller", "clustering.services").versionAsInProject(),
1359                 mavenBundle("org.opendaylight.controller", "clustering.services-implementation").versionAsInProject(),
1360                 mavenBundle("org.opendaylight.controller", "security").versionAsInProject().noStart(),
1361                 mavenBundle("org.opendaylight.controller", "sal").versionAsInProject(),
1362                 mavenBundle("org.opendaylight.controller", "sal.implementation").versionAsInProject(),
1363                 mavenBundle("org.opendaylight.controller", "sal.connection").versionAsInProject(),
1364                 mavenBundle("org.opendaylight.controller", "sal.connection.implementation").versionAsInProject(),
1365                 mavenBundle("org.opendaylight.controller", "switchmanager").versionAsInProject(),
1366                 mavenBundle("org.opendaylight.controller", "connectionmanager").versionAsInProject(),
1367                 mavenBundle("org.opendaylight.controller", "connectionmanager.implementation").versionAsInProject(),
1368                 mavenBundle("org.opendaylight.controller", "switchmanager.implementation").versionAsInProject(),
1369                 mavenBundle("org.opendaylight.controller", "forwardingrulesmanager").versionAsInProject(),
1370                 mavenBundle("org.opendaylight.controller",
1371                             "forwardingrulesmanager.implementation").versionAsInProject(),
1372                 mavenBundle("org.opendaylight.controller", "statisticsmanager").versionAsInProject(),
1373                 mavenBundle("org.opendaylight.controller", "statisticsmanager.implementation").versionAsInProject(),
1374                 mavenBundle("org.opendaylight.controller", "arphandler").versionAsInProject(),
1375                 mavenBundle("org.opendaylight.controller", "hosttracker").versionAsInProject(),
1376                 mavenBundle("org.opendaylight.controller", "hosttracker.implementation").versionAsInProject(),
1377                 mavenBundle("org.opendaylight.controller", "arphandler").versionAsInProject(),
1378                 mavenBundle("org.opendaylight.controller", "routing.dijkstra_implementation").versionAsInProject(),
1379                 mavenBundle("org.opendaylight.controller", "topologymanager").versionAsInProject(),
1380                 mavenBundle("org.opendaylight.controller", "usermanager").versionAsInProject(),
1381                 mavenBundle("org.opendaylight.controller", "usermanager.implementation").versionAsInProject(),
1382                 mavenBundle("org.opendaylight.controller", "logging.bridge").versionAsInProject(),
1383 //                mavenBundle("org.opendaylight.controller", "clustering.test").versionAsInProject(),
1384                 mavenBundle("org.opendaylight.controller", "forwarding.staticrouting").versionAsInProject(),
1385                 mavenBundle("org.opendaylight.controller", "bundlescanner").versionAsInProject(),
1386                 mavenBundle("org.opendaylight.controller", "bundlescanner.implementation").versionAsInProject(),
1387                 mavenBundle("org.opendaylight.controller", "commons.httpclient").versionAsInProject(),
1388
1389                 // Northbound bundles
1390                 mavenBundle("org.opendaylight.controller", "commons.northbound").versionAsInProject(),
1391                 mavenBundle("org.opendaylight.controller", "forwarding.staticrouting.northbound").versionAsInProject(),
1392                 mavenBundle("org.opendaylight.controller", "statistics.northbound").versionAsInProject(),
1393                 mavenBundle("org.opendaylight.controller", "topology.northbound").versionAsInProject(),
1394                 mavenBundle("org.opendaylight.controller", "hosttracker.northbound").versionAsInProject(),
1395                 mavenBundle("org.opendaylight.controller", "switchmanager.northbound").versionAsInProject(),
1396                 mavenBundle("org.opendaylight.controller", "flowprogrammer.northbound").versionAsInProject(),
1397                 mavenBundle("org.opendaylight.controller", "subnets.northbound").versionAsInProject(),
1398
1399                 mavenBundle("com.fasterxml.jackson.core", "jackson-annotations").versionAsInProject(),
1400                 mavenBundle("com.fasterxml.jackson.core", "jackson-core").versionAsInProject(),
1401                 mavenBundle("com.fasterxml.jackson.core", "jackson-databind").versionAsInProject(),
1402                 mavenBundle("com.fasterxml.jackson.jaxrs", "jackson-jaxrs-json-provider").versionAsInProject(),
1403                 mavenBundle("com.fasterxml.jackson.jaxrs", "jackson-jaxrs-base").versionAsInProject(),
1404                 mavenBundle("com.fasterxml.jackson.module", "jackson-module-jaxb-annotations").versionAsInProject(),
1405
1406                 mavenBundle("org.codehaus.jettison", "jettison").versionAsInProject(),
1407
1408                 mavenBundle("commons-io", "commons-io").versionAsInProject(),
1409
1410                 mavenBundle("commons-fileupload", "commons-fileupload").versionAsInProject(),
1411
1412                 mavenBundle("equinoxSDK381", "javax.servlet").versionAsInProject(),
1413                 mavenBundle("equinoxSDK381", "javax.servlet.jsp").versionAsInProject(),
1414                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds").versionAsInProject(),
1415                 mavenBundle("orbit", "javax.xml.rpc").versionAsInProject(),
1416                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util").versionAsInProject(),
1417                 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services").versionAsInProject(),
1418                 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command").versionAsInProject(),
1419                 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime").versionAsInProject(),
1420                 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell").versionAsInProject(),
1421                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.cm").versionAsInProject(),
1422                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console").versionAsInProject(),
1423                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.launcher").versionAsInProject(),
1424
1425                 mavenBundle("geminiweb", "org.eclipse.gemini.web.core").versionAsInProject(),
1426                 mavenBundle("geminiweb", "org.eclipse.gemini.web.extender").versionAsInProject(),
1427                 mavenBundle("geminiweb", "org.eclipse.gemini.web.tomcat").versionAsInProject(),
1428                 mavenBundle("geminiweb", "org.eclipse.virgo.kernel.equinox.extensions").versionAsInProject().noStart(),
1429                 mavenBundle("geminiweb", "org.eclipse.virgo.util.common").versionAsInProject(),
1430                 mavenBundle("geminiweb", "org.eclipse.virgo.util.io").versionAsInProject(),
1431                 mavenBundle("geminiweb", "org.eclipse.virgo.util.math").versionAsInProject(),
1432                 mavenBundle("geminiweb", "org.eclipse.virgo.util.osgi").versionAsInProject(),
1433                 mavenBundle("geminiweb", "org.eclipse.virgo.util.osgi.manifest").versionAsInProject(),
1434                 mavenBundle("geminiweb", "org.eclipse.virgo.util.parser.manifest").versionAsInProject(),
1435
1436                 mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager").versionAsInProject(),
1437                 mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager.shell").versionAsInProject(),
1438
1439                 mavenBundle("com.google.code.gson", "gson").versionAsInProject(),
1440                 mavenBundle("org.jboss.spec.javax.transaction", "jboss-transaction-api_1.1_spec").versionAsInProject(),
1441                 mavenBundle("org.apache.felix", "org.apache.felix.fileinstall").versionAsInProject(),
1442                 mavenBundle("org.apache.commons", "commons-lang3").versionAsInProject(),
1443                 mavenBundle("commons-codec", "commons-codec").versionAsInProject(),
1444                 mavenBundle("virgomirror", "org.eclipse.jdt.core.compiler.batch").versionAsInProject(),
1445                 mavenBundle("eclipselink", "javax.persistence").versionAsInProject(),
1446                 mavenBundle("eclipselink", "javax.resource").versionAsInProject(),
1447
1448                 mavenBundle("orbit", "javax.activation").versionAsInProject(),
1449                 mavenBundle("orbit", "javax.annotation").versionAsInProject(),
1450                 mavenBundle("orbit", "javax.ejb").versionAsInProject(),
1451                 mavenBundle("orbit", "javax.el").versionAsInProject(),
1452                 mavenBundle("orbit", "javax.mail.glassfish").versionAsInProject(),
1453                 mavenBundle("orbit", "javax.xml.rpc").versionAsInProject(),
1454                 mavenBundle("orbit", "org.apache.catalina").versionAsInProject(),
1455                 // these are bundle fragments that can't be started on its own
1456                 mavenBundle("orbit", "org.apache.catalina.ha").versionAsInProject().noStart(),
1457                 mavenBundle("orbit", "org.apache.catalina.tribes").versionAsInProject().noStart(),
1458                 mavenBundle("orbit", "org.apache.coyote").versionAsInProject().noStart(),
1459                 mavenBundle("orbit", "org.apache.jasper").versionAsInProject().noStart(),
1460
1461                 mavenBundle("orbit", "org.apache.el").versionAsInProject(),
1462                 mavenBundle("orbit", "org.apache.juli.extras").versionAsInProject(),
1463                 mavenBundle("orbit", "org.apache.tomcat.api").versionAsInProject(),
1464                 mavenBundle("orbit", "org.apache.tomcat.util").versionAsInProject().noStart(),
1465                 mavenBundle("orbit", "javax.servlet.jsp.jstl").versionAsInProject(),
1466                 mavenBundle("orbit", "javax.servlet.jsp.jstl.impl").versionAsInProject(),
1467
1468                 mavenBundle("org.ops4j.pax.exam", "pax-exam-container-native").versionAsInProject(),
1469                 mavenBundle("org.ops4j.pax.exam", "pax-exam-junit4").versionAsInProject(),
1470                 mavenBundle("org.ops4j.pax.exam", "pax-exam-link-mvn").versionAsInProject(),
1471                 mavenBundle("org.ops4j.pax.url", "pax-url-aether").versionAsInProject(),
1472
1473                 mavenBundle("org.ow2.asm", "asm-all").versionAsInProject(),
1474
1475                 mavenBundle("org.springframework", "org.springframework.asm").versionAsInProject(),
1476                 mavenBundle("org.springframework", "org.springframework.aop").versionAsInProject(),
1477                 mavenBundle("org.springframework", "org.springframework.context").versionAsInProject(),
1478                 mavenBundle("org.springframework", "org.springframework.context.support").versionAsInProject(),
1479                 mavenBundle("org.springframework", "org.springframework.core").versionAsInProject(),
1480                 mavenBundle("org.springframework", "org.springframework.beans").versionAsInProject(),
1481                 mavenBundle("org.springframework", "org.springframework.expression").versionAsInProject(),
1482                 mavenBundle("org.springframework", "org.springframework.web").versionAsInProject(),
1483
1484                 mavenBundle("org.aopalliance", "com.springsource.org.aopalliance").versionAsInProject(),
1485                 mavenBundle("org.springframework", "org.springframework.web.servlet").versionAsInProject(),
1486                 mavenBundle("org.springframework.security", "spring-security-config").versionAsInProject(),
1487                 mavenBundle("org.springframework.security", "spring-security-core").versionAsInProject(),
1488                 mavenBundle("org.springframework.security", "spring-security-web").versionAsInProject(),
1489                 mavenBundle("org.springframework.security", "spring-security-taglibs").versionAsInProject(),
1490                 mavenBundle("org.springframework", "org.springframework.transaction").versionAsInProject(),
1491
1492                 mavenBundle("org.ow2.chameleon.management", "chameleon-mbeans").versionAsInProject(),
1493                 mavenBundle("org.opendaylight.controller.thirdparty", "net.sf.jung2").versionAsInProject(),
1494                 mavenBundle("org.opendaylight.controller.thirdparty", "com.sun.jersey.jersey-servlet")
1495                 .versionAsInProject(),
1496                 mavenBundle("org.opendaylight.controller.thirdparty", "org.apache.catalina.filters.CorsFilter")
1497                 .versionAsInProject().noStart(),
1498
1499                 // Jersey needs to be started before the northbound application
1500                 // bundles, using a lower start level
1501                 mavenBundle("com.sun.jersey", "jersey-client").versionAsInProject(),
1502                 mavenBundle("com.sun.jersey", "jersey-server").versionAsInProject().startLevel(2),
1503                 mavenBundle("com.sun.jersey", "jersey-core").versionAsInProject().startLevel(2),
1504                 junitBundles());
1505     }
1506
1507 }