if(!updateSwitch)
sw = new Switch(dpid);
List<Port> ports = new ArrayList<Port>();
Map<String, Future<Object>> stats;
JSONObject descriptionObj = null, aggregateObj = null, portObj = null, featuresObj = null;
try {
stats = (Map<String, Future<Object>>) futureStats.get(dpid).get(5L, TimeUnit.SECONDS);
// Don't bother if we are updating this switch, since description is static
if(!updateSwitch)
descriptionObj = (JSONObject)stats.get("description").get(5L, TimeUnit.SECONDS);
aggregateObj = (JSONObject)stats.get("aggregate").get(5L, TimeUnit.SECONDS);
portObj = (JSONObject)stats.get("port").get(5L, TimeUnit.SECONDS);
featuresObj = (JSONObject)stats.get("features").get(5L, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TimeoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Description stats
if(!updateSwitch && descriptionObj != null){
descriptionObj = descriptionObj.getJSONArray(dpid).getJSONObject(0);
sw.setManufacturerDescription(descriptionObj.getString("manufacturerDescription"));
sw.setHardwareDescription(descriptionObj.getString("hardwareDescription"));
sw.setSoftwareDescription(descriptionObj.getString("softwareDescription"));
sw.setSerialNumber(descriptionObj.getString("serialNumber"));
sw.setDatapathDescription(descriptionObj.getString("datapathDescription"));
}
// Aggregate stats, ignore
if(aggregateObj != null){
aggregateObj = aggregateObj.getJSONArray(dpid).getJSONObject(0);
sw.setPacketCount(String.valueOf(aggregateObj.getInt("packetCount")));
sw.setByteCount(String.valueOf(aggregateObj.getInt("byteCount")));
sw.setFlowCount(String.valueOf(aggregateObj.getInt("flowCount")));
}
// Flow Stats
sw.setFlows(FlowJSON.getFlows(dpid));
// Port and Features stats
JSONArray json = portObj.getJSONArray(sw.getDpid());
JSONObject objtwo = featuresObj.getJSONObject(sw.getDpid());
JSONArray jsontwo = objtwo.getJSONArray("ports");
for(int i = 0; i < json.length(); i++)
{
obj = (JSONObject)json.get(i);
Port port = new Port(String.valueOf(obj.getInt("portNumber")));
port.setReceivePackets(FormatLong.formatPackets(obj.getLong("receivePackets"), false, false));