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