.getSwitchDevices().get(
HexString.toLong(datapathIdString));
IOFSwitch sw = switchDevice.getOpenFlowSwitch();
List<OFPhysicalPort> switchPorts = switchDevice.getPortStates();
OFPhysicalPort updatedPort = null;
for (OFPhysicalPort ofPort : switchPorts) {
if (ofPort.getPortNumber() == Short
.parseShort(sensorIdString)) {
updatedPort = ofPort;
break;
}
}
updatedPort.setConfig(0);
OFPortMod portMod = new OFPortMod();
if (updateStatus.equals("down")) {
portMod.setConfig(OFPhysicalPort.OFPortConfig.OFPPC_PORT_DOWN
.getValue());
} else if (updateStatus.equals("up")) {
portMod.setConfig(0);
}
portMod.setMask(1);
portMod.setPortNumber(updatedPort.getPortNumber());
portMod.setHardwareAddress(updatedPort.getHardwareAddress());
portMod.setType(OFType.PORT_MOD);
sw.getOutputStream().write(portMod);
sw.getOutputStream().flush();
obj = new JSONObject();