+ JSONArray flowStats = flowStatistics.getJSONArray("flowStat");
+ for (int i = 0; i < flowStats.length(); i++) {
+
+ JSONObject flowStat = flowStats.getJSONObject(i);
+ testFlowStat(flowStat, actionTypes[i]);
+
+ }
+
+ // for /controller/nb/v2/statistics/default/portstats
+ result = getJsonResult(baseURL + "portstats");
+ jt = new JSONTokener(result);
+ json = new JSONObject(jt);
+ JSONObject portStatistics = json.getJSONObject("portStatistics");
+ JSONObject node2 = portStatistics.getJSONObject("node");
+ // test that node was returned properly
+ Assert.assertTrue(node2.getInt("@id") == 0xCAFE);
+ Assert.assertTrue(node2.getString("@type").equals("STUB"));
+
+ // test that port statistic results are correct
+ JSONObject portStat = portStatistics.getJSONObject("portStat");
+ Assert.assertTrue(portStat.getInt("receivePackets") == 250);
+ Assert.assertTrue(portStat.getInt("transmitPackets") == 500);
+ Assert.assertTrue(portStat.getInt("receiveBytes") == 1000);
+ Assert.assertTrue(portStat.getInt("transmitBytes") == 5000);
+ Assert.assertTrue(portStat.getInt("receiveDrops") == 2);
+ Assert.assertTrue(portStat.getInt("transmitDrops") == 50);
+ Assert.assertTrue(portStat.getInt("receiveErrors") == 3);
+ Assert.assertTrue(portStat.getInt("transmitErrors") == 10);
+ Assert.assertTrue(portStat.getInt("receiveFrameError") == 5);
+ Assert.assertTrue(portStat.getInt("receiveOverRunError") == 6);
+ Assert.assertTrue(portStat.getInt("receiveCrcError") == 1);
+ Assert.assertTrue(portStat.getInt("collisionCount") == 4);
+
+ // test for getting one specific node's stats
+ result = getJsonResult(baseURL + "flowstats/STUB/51966");
+ jt = new JSONTokener(result);
+ json = new JSONObject(jt);
+ node = json.getJSONObject("node");
+ // test that node was returned properly
+ Assert.assertTrue(node.getInt("@id") == 0xCAFE);
+ Assert.assertTrue(node.getString("@type").equals("STUB"));
+
+ // test that flow statistics results are correct
+ flowStats = json.getJSONArray("flowStat");
+ for (int i = 0; i < flowStats.length(); i++) {
+ JSONObject flowStat = flowStats.getJSONObject(i);
+ testFlowStat(flowStat, actionTypes[i]);
+ }
+
+ result = getJsonResult(baseURL + "portstats/STUB/51966");
+ jt = new JSONTokener(result);
+ json = new JSONObject(jt);
+ node2 = json.getJSONObject("node");
+ // test that node was returned properly
+ Assert.assertTrue(node2.getInt("@id") == 0xCAFE);
+ Assert.assertTrue(node2.getString("@type").equals("STUB"));
+
+ // test that port statistic results are correct
+ portStat = json.getJSONObject("portStat");
+ Assert.assertTrue(portStat.getInt("receivePackets") == 250);
+ Assert.assertTrue(portStat.getInt("transmitPackets") == 500);
+ Assert.assertTrue(portStat.getInt("receiveBytes") == 1000);
+ Assert.assertTrue(portStat.getInt("transmitBytes") == 5000);
+ Assert.assertTrue(portStat.getInt("receiveDrops") == 2);
+ Assert.assertTrue(portStat.getInt("transmitDrops") == 50);
+ Assert.assertTrue(portStat.getInt("receiveErrors") == 3);
+ Assert.assertTrue(portStat.getInt("transmitErrors") == 10);
+ Assert.assertTrue(portStat.getInt("receiveFrameError") == 5);
+ Assert.assertTrue(portStat.getInt("receiveOverRunError") == 6);
+ Assert.assertTrue(portStat.getInt("receiveCrcError") == 1);
+ Assert.assertTrue(portStat.getInt("collisionCount") == 4);
+
+ } catch (Exception e) {
+ // Got an unexpected exception
+ Assert.assertTrue(false);
+
+ }
+ }
+
+ private void testFlowStat(JSONObject flowStat, String actionType) {
+ try {