intervalTime);
List<OFStatistics> portStats;
List<OFStatistics> flowStats;
List<OFPhysicalPort> portStatus;
SwitchDevice swd = null;
String[] datapathIdStringElements = datapathIdStrings.split(",");
try {
while (statThread != null) {
calendar = Calendar.getInstance();
logger.trace("getting flows from switches");
//check if conn is null if it is, reset connection
if(conn == null){
conn = DriverManager.getConnection(databaseDriver, dbUsername,
dbPassword);
}
for (String datapathIdString : datapathIdStringElements) {
try {
swd = flowscaleController
.getSwitchDevices()
.get(HexString
.toLong(datapathIdString));
if (swd == null) {
logger.info("switch {} does not exist, is it connected?",
datapathIdString);
continue;
}
logger.info(
"Getting flows from switch {} with ID {}",
swd.getSwitchName(), datapathIdString);
try {
portStats = flowscaleController
.getSwitchStatisticsFromInterface(
datapathIdString,
"port");
flowStats = flowscaleController
.getSwitchStatisticsFromInterface(
datapathIdString,
"flow");
portStatus = swd.getPortStates();
if (flowStats != null
&& portStats != null) {
String flowStatsJSON = JSONConverter
.toStat(flowStats,
"flow")
.toJSONString();
String portStatsJSON = JSONConverter
.toStat(portStats,
"port")
.toJSONString();
String portStatusJSON = JSONConverter
.toPortStatus(
portStatus)
.toJSONString();
// initialize or set hashmaps
HashMap<Long, Long> tempPortStatTransmitted;
HashMap<Long, Long> tempPortStatReceived;
HashMap<String, Long> tempFlowStat;
long datapathId = HexString
.toLong(datapathIdString);
if (tempPortStatTransmittedHashMap
.get(datapathId) == null) {
tempPortStatTransmitted = new HashMap<Long, Long>();
tempPortStatTransmittedHashMap
.put(datapathId,
tempPortStatTransmitted);
} else {
tempPortStatTransmitted = tempPortStatTransmittedHashMap
.get(datapathId);
}
if (tempPortStatReceivedHashMap
.get(datapathId) == null) {
tempPortStatReceived = new HashMap<Long, Long>();
tempPortStatReceivedHashMap
.put(datapathId,
tempPortStatReceived);
} else {
tempPortStatReceived = tempPortStatReceivedHashMap
.get(datapathId);
}
if (tempFlowStatHashMap
.get(datapathId) == null) {
tempFlowStat = new HashMap<String, Long>();
tempFlowStatHashMap.put(
datapathId,
tempFlowStat);
} else {
tempFlowStat = tempFlowStatHashMap
.get(datapathId);
}
storeSwitchDetails(
HexString
.toLong(datapathIdString),
portStatsJSON,
flowStatsJSON,
portStatusJSON,
tempPortStatTransmitted,
tempPortStatReceived,
tempFlowStat);
} else {
logger.error(
"Switch {} returned a null result possibility because the switch is not connected to the controller",
datapathIdString);
}
} catch (NoSwitchException e1) {
// TODO Auto-generated catch block
logger.error(
"Switch {} with ID {} is not connected aborting",
swd.getSwitchName(),datapathIdString);
} catch (IOException e1) {
logger.error("IOException {}", e1);
} catch (InterruptedException e1) {
logger.error(