Program: 25440
Project: 25440
Buggy source:
/** 
 * handle messages from the switch and verify they should be a part of this slice if not just return
 * @param msg
 * @param cntx
 */
public void toController(OFMessage msg,FloodlightContext cntx){
  if (ofcch == null) {
    return;
  }
  log.debug("String_Node_Str" + msg.getType());
  int xid=msg.getXid();
switch (msg.getType()) {
case PACKET_IN:
    OFPacketIn pcktIn=(OFPacketIn)msg;
  OFMatch match=new OFMatch();
if (pcktIn.getPacketData().length <= 0) {
  log.debug("String_Node_Str");
  return;
}
match.loadFromPacket(pcktIn.getPacketData(),pcktIn.getInPort());
OFFlowMod flowMod=new OFFlowMod();
flowMod.setMatch(match);
List<OFFlowMod> allowed=this.mySlicer.allowedFlows(flowMod);
if (allowed.size() == 0) {
log.debug("String_Node_Str" + this.mySlicer.getSliceName());
return;
}
if (this.packetInRate.okToProcess()) {
this.mySlicer.addBufferId(pcktIn.getBufferId(),pcktIn.getPacketData());
if (this.mySlicer.getTagManagement()) {
log.debug("String_Node_Str");
Ethernet newPkt=new Ethernet();
byte[] pktData=pcktIn.getPacketData();
newPkt.deserialize(pktData,0,pktData.length);
newPkt.setEtherType(newPkt.getEtherType());
newPkt.setVlanID(Ethernet.VLAN_UNTAGGED);
byte[] newPktData=newPkt.serialize();
pcktIn.setPacketData(newPktData);
pcktIn.setTotalLength((short)newPktData.length);
}
break;
}
 else {
log.warn("String_Node_Str" + this.getSlicer().getSliceName() + "String_Node_Str"+ this.getSlicer().getSwitchName()+ "String_Node_Str");
this.setAdminStatus(false);
return;
}
case PORT_STATUS:
OFPortStatus portStatus=(OFPortStatus)msg;
OFPhysicalPort port=portStatus.getDesc();
if (!this.mySlicer.isPortPartOfSlice(port.getName())) {
log.debug("String_Node_Str" + this.getSlicer().getSwitchName() + "String_Node_Str"+ port.getName()+ "String_Node_Str"+ this.mySlicer.getSliceName());
return;
}
switch (OFPortReason.fromReasonCode(portStatus.getReason())) {
case OFPPR_ADD:
this.mySlicer.setPortId(port.getName(),port.getPortNumber());
break;
case OFPPR_MODIFY:
break;
case OFPPR_DELETE:
break;
}
break;
case ERROR:
if (xidMap.containsKey(xid)) {
msg.setXid(xidMap.get(xid));
xidMap.remove(xid);
OFError error=(OFError)msg;
OFMessage error_msg=null;
try {
error_msg=error.getOffendingMsg();
}
 catch (MessageParseException e) {
log.error("String_Node_Str");
break;
}
if (error_msg == null) {
break;
}
switch (error_msg.getType()) {
case FLOW_MOD:
OFFlowMod mod=(OFFlowMod)error_msg;
switch (mod.getCommand()) {
case OFFlowMod.OFPFC_ADD:
this.flowCount--;
break;
case OFFlowMod.OFPFC_DELETE:
this.flowCount++;
break;
case OFFlowMod.OFPFC_DELETE_STRICT:
this.flowCount++;
break;
default :
break;
}
break;
default :
break;
}
}
 else {
return;
}
break;
case FLOW_REMOVED:
OFFlowRemoved removedFlow=(OFFlowRemoved)msg;
OFFlowMod mod=new OFFlowMod();
mod.setMatch(removedFlow.getMatch());
List<OFFlowMod> flows=mySlicer.allowedFlows(mod);
if (flows.size() == 0) {
return;
}
if (mySlicer.getTagManagement()) {
removedFlow.getMatch().setDataLayerVirtualLan((short)0);
removedFlow.getMatch().getWildcardObj().wildcard(Wildcards.Flag.DL_VLAN);
msg=removedFlow;
}
this.flowCount--;
break;
case BARRIER_REPLY:
if (xidMap.containsKey(xid)) {
msg.setXid(xidMap.get(xid));
xidMap.removeToKey(xid);
}
 else {
return;
}
break;
case ECHO_REQUEST:
return;
default :
log.debug("String_Node_Str" + msg.getType());
break;
}
try {
ofcch.sendMessage(msg);
}
 catch (IOException e) {
e.printStackTrace();
}
}

Fixed version (ground truth):
/** 
 * handle messages from the switch and verify they should be a part of this slice if not just return
 * @param msg
 * @param cntx
 */
public void toController(OFMessage msg,FloodlightContext cntx){
  if (ofcch == null) {
    return;
  }
  log.debug("String_Node_Str" + msg.getType());
  int xid=msg.getXid();
switch (msg.getType()) {
case PACKET_IN:
    OFPacketIn pcktIn=(OFPacketIn)msg;
  OFMatch match=new OFMatch();
if (pcktIn.getPacketData().length <= 0) {
  log.debug("String_Node_Str");
  return;
}
match.loadFromPacket(pcktIn.getPacketData(),pcktIn.getInPort());
OFFlowMod flowMod=new OFFlowMod();
flowMod.setMatch(match);
List<OFFlowMod> allowed=this.mySlicer.allowedFlows(flowMod);
if (allowed.size() == 0) {
log.debug("String_Node_Str" + this.mySlicer.getSliceName());
return;
}
if (this.packetInRate.okToProcess()) {
this.mySlicer.addBufferId(pcktIn.getBufferId(),pcktIn.getPacketData());
if (this.mySlicer.getTagManagement()) {
log.debug("String_Node_Str");
Ethernet newPkt=new Ethernet();
byte[] pktData=pcktIn.getPacketData();
newPkt.deserialize(pktData,0,pktData.length);
newPkt.setEtherType(newPkt.getEtherType());
newPkt.setVlanID(Ethernet.VLAN_UNTAGGED);
byte[] newPktData=newPkt.serialize();
pcktIn.setPacketData(newPktData);
pcktIn.setTotalLength((short)newPktData.length);
}
break;
}
 else {
log.warn("String_Node_Str" + this.getSlicer().getSliceName() + "String_Node_Str"+ this.getSlicer().getSwitchName()+ "String_Node_Str");
this.setAdminStatus(false);
return;
}
case PORT_STATUS:
OFPortStatus portStatus=(OFPortStatus)msg;
OFPhysicalPort port=portStatus.getDesc();
if (!this.mySlicer.isPortPartOfSlice(port.getName())) {
log.debug("String_Node_Str" + this.getSlicer().getSwitchName() + "String_Node_Str"+ port.getName()+ "String_Node_Str"+ this.mySlicer.getSliceName());
return;
}
switch (OFPortReason.fromReasonCode(portStatus.getReason())) {
case OFPPR_ADD:
this.mySlicer.setPortId(port.getName(),port.getPortNumber());
break;
case OFPPR_MODIFY:
break;
case OFPPR_DELETE:
break;
}
break;
case ERROR:
if (xidMap.containsKey(xid)) {
msg.setXid(xidMap.get(xid));
xidMap.remove(xid);
OFError error=(OFError)msg;
OFMessage error_msg=null;
try {
error_msg=error.getOffendingMsg();
}
 catch (MessageParseException e) {
log.error("String_Node_Str");
break;
}
if (error_msg == null) {
break;
}
switch (error_msg.getType()) {
case FLOW_MOD:
OFFlowMod mod=(OFFlowMod)error_msg;
switch (mod.getCommand()) {
case OFFlowMod.OFPFC_ADD:
this.flowCount--;
break;
case OFFlowMod.OFPFC_DELETE:
this.flowCount++;
break;
case OFFlowMod.OFPFC_DELETE_STRICT:
this.flowCount++;
break;
default :
break;
}
break;
default :
break;
}
}
 else {
return;
}
break;
case FLOW_REMOVED:
OFFlowRemoved removedFlow=(OFFlowRemoved)msg;
OFFlowMod mod=new OFFlowMod();
mod.setMatch(removedFlow.getMatch());
List<OFFlowMod> flows=mySlicer.allowedFlows(mod);
if (flows.size() == 0) {
return;
}
if (mySlicer.getTagManagement()) {
removedFlow.getMatch().setDataLayerVirtualLan((short)0);
removedFlow.getMatch().setWildcards(removedFlow.getMatch().getWildcardObj().wildcard(Wildcards.Flag.DL_VLAN));
msg=removedFlow;
}
this.flowCount--;
break;
case BARRIER_REPLY:
if (xidMap.containsKey(xid)) {
msg.setXid(xidMap.get(xid));
xidMap.removeToKey(xid);
}
 else {
return;
}
break;
case ECHO_REQUEST:
return;
default :
log.debug("String_Node_Str" + msg.getType());
break;
}
try {
ofcch.sendMessage(msg);
}
 catch (IOException e) {
e.printStackTrace();
}
}