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