alshabib

clean packet context

......@@ -6,6 +6,7 @@ import org.onlab.packet.Ethernet;
import org.projectfloodlight.openflow.protocol.OFPacketIn;
import org.projectfloodlight.openflow.protocol.OFPacketOut;
import org.projectfloodlight.openflow.protocol.action.OFAction;
import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
import org.projectfloodlight.openflow.types.OFBufferId;
import org.projectfloodlight.openflow.types.OFPort;
......@@ -36,21 +37,26 @@ public final class DefaultPacketContext implements PacketContext {
}
@Override
public void build(OFPort outPort) {
public synchronized void build(OFPort outPort) {
if (isBuilt) {
return;
}
OFPacketOut.Builder builder = sw.factory().buildPacketOut();
OFAction act = buildOutput(outPort.getPortNumber());
pktout = builder.setXid(pktin.getXid())
.setBufferId(pktin.getBufferId())
.setActions(Collections.singletonList(act))
.build();
isBuilt = true;
}
@Override
public void build(Ethernet ethFrame, OFPort outPort) {
public synchronized void build(Ethernet ethFrame, OFPort outPort) {
if (isBuilt) {
return;
}
OFPacketOut.Builder builder = sw.factory().buildPacketOut();
OFAction act = sw.factory().actions()
.buildOutput()
.setPort(OFPort.of(outPort.getPortNumber()))
.build();
OFAction act = buildOutput(outPort.getPortNumber());
pktout = builder.setXid(pktin.getXid())
.setBufferId(OFBufferId.NO_BUFFER)
.setActions(Collections.singletonList(act))
......@@ -85,4 +91,12 @@ public final class DefaultPacketContext implements PacketContext {
return pktin.getData().clone();
}
private OFActionOutput buildOutput(Integer port) {
OFActionOutput act = sw.factory().actions()
.buildOutput()
.setPort(OFPort.of(port))
.build();
return act;
}
}
......