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