alshabib

clean packet context

...@@ -6,6 +6,7 @@ import org.onlab.packet.Ethernet; ...@@ -6,6 +6,7 @@ import org.onlab.packet.Ethernet;
6 import org.projectfloodlight.openflow.protocol.OFPacketIn; 6 import org.projectfloodlight.openflow.protocol.OFPacketIn;
7 import org.projectfloodlight.openflow.protocol.OFPacketOut; 7 import org.projectfloodlight.openflow.protocol.OFPacketOut;
8 import org.projectfloodlight.openflow.protocol.action.OFAction; 8 import org.projectfloodlight.openflow.protocol.action.OFAction;
9 +import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
9 import org.projectfloodlight.openflow.types.OFBufferId; 10 import org.projectfloodlight.openflow.types.OFBufferId;
10 import org.projectfloodlight.openflow.types.OFPort; 11 import org.projectfloodlight.openflow.types.OFPort;
11 12
...@@ -36,21 +37,26 @@ public final class DefaultPacketContext implements PacketContext { ...@@ -36,21 +37,26 @@ public final class DefaultPacketContext implements PacketContext {
36 } 37 }
37 38
38 @Override 39 @Override
39 - public void build(OFPort outPort) { 40 + public synchronized void build(OFPort outPort) {
41 + if (isBuilt) {
42 + return;
43 + }
44 + OFPacketOut.Builder builder = sw.factory().buildPacketOut();
45 + OFAction act = buildOutput(outPort.getPortNumber());
46 + pktout = builder.setXid(pktin.getXid())
47 + .setBufferId(pktin.getBufferId())
48 + .setActions(Collections.singletonList(act))
49 + .build();
40 isBuilt = true; 50 isBuilt = true;
41 -
42 } 51 }
43 52
44 @Override 53 @Override
45 - public void build(Ethernet ethFrame, OFPort outPort) { 54 + public synchronized void build(Ethernet ethFrame, OFPort outPort) {
46 if (isBuilt) { 55 if (isBuilt) {
47 return; 56 return;
48 } 57 }
49 OFPacketOut.Builder builder = sw.factory().buildPacketOut(); 58 OFPacketOut.Builder builder = sw.factory().buildPacketOut();
50 - OFAction act = sw.factory().actions() 59 + OFAction act = buildOutput(outPort.getPortNumber());
51 - .buildOutput()
52 - .setPort(OFPort.of(outPort.getPortNumber()))
53 - .build();
54 pktout = builder.setXid(pktin.getXid()) 60 pktout = builder.setXid(pktin.getXid())
55 .setBufferId(OFBufferId.NO_BUFFER) 61 .setBufferId(OFBufferId.NO_BUFFER)
56 .setActions(Collections.singletonList(act)) 62 .setActions(Collections.singletonList(act))
...@@ -85,4 +91,12 @@ public final class DefaultPacketContext implements PacketContext { ...@@ -85,4 +91,12 @@ public final class DefaultPacketContext implements PacketContext {
85 return pktin.getData().clone(); 91 return pktin.getData().clone();
86 } 92 }
87 93
94 + private OFActionOutput buildOutput(Integer port) {
95 + OFActionOutput act = sw.factory().actions()
96 + .buildOutput()
97 + .setPort(OFPort.of(port))
98 + .build();
99 + return act;
100 + }
101 +
88 } 102 }
......