alshabib

pkt glitch FIXED... ovs was not sending a bufferid

Change-Id: Id6fedf7c6ed8fbcfefb7308b0ee442e614e5e3af
1 package org.onlab.onos.fwd; 1 package org.onlab.onos.fwd;
2 2
3 +import static org.slf4j.LoggerFactory.getLogger;
4 +
5 +import java.util.Set;
6 +
3 import org.apache.felix.scr.annotations.Activate; 7 import org.apache.felix.scr.annotations.Activate;
4 import org.apache.felix.scr.annotations.Component; 8 import org.apache.felix.scr.annotations.Component;
5 import org.apache.felix.scr.annotations.Deactivate; 9 import org.apache.felix.scr.annotations.Deactivate;
...@@ -27,10 +31,6 @@ import org.onlab.onos.net.topology.TopologyService; ...@@ -27,10 +31,6 @@ import org.onlab.onos.net.topology.TopologyService;
27 import org.onlab.packet.Ethernet; 31 import org.onlab.packet.Ethernet;
28 import org.slf4j.Logger; 32 import org.slf4j.Logger;
29 33
30 -import java.util.Set;
31 -
32 -import static org.slf4j.LoggerFactory.getLogger;
33 -
34 /** 34 /**
35 * Sample reactive forwarding application. 35 * Sample reactive forwarding application.
36 */ 36 */
...@@ -101,8 +101,8 @@ public class ReactiveForwarding { ...@@ -101,8 +101,8 @@ public class ReactiveForwarding {
101 // Otherwise, get a set of paths that lead from here to the 101 // Otherwise, get a set of paths that lead from here to the
102 // destination edge switch. 102 // destination edge switch.
103 Set<Path> paths = topologyService.getPaths(topologyService.currentTopology(), 103 Set<Path> paths = topologyService.getPaths(topologyService.currentTopology(),
104 - pkt.receivedFrom().deviceId(), 104 + pkt.receivedFrom().deviceId(),
105 - dst.location().deviceId()); 105 + dst.location().deviceId());
106 if (paths.isEmpty()) { 106 if (paths.isEmpty()) {
107 // If there are no paths, flood and bail. 107 // If there are no paths, flood and bail.
108 flood(context); 108 flood(context);
...@@ -114,8 +114,8 @@ public class ReactiveForwarding { ...@@ -114,8 +114,8 @@ public class ReactiveForwarding {
114 Path path = pickForwardPath(paths, pkt.receivedFrom().port()); 114 Path path = pickForwardPath(paths, pkt.receivedFrom().port());
115 if (path == null) { 115 if (path == null) {
116 log.warn("Doh... don't know where to go... {} -> {} received on {}", 116 log.warn("Doh... don't know where to go... {} -> {} received on {}",
117 - ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), 117 + ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(),
118 - pkt.receivedFrom().port()); 118 + pkt.receivedFrom());
119 flood(context); 119 flood(context);
120 return; 120 return;
121 } 121 }
...@@ -139,7 +139,7 @@ public class ReactiveForwarding { ...@@ -139,7 +139,7 @@ public class ReactiveForwarding {
139 // Floods the specified packet if permissible. 139 // Floods the specified packet if permissible.
140 private void flood(PacketContext context) { 140 private void flood(PacketContext context) {
141 if (topologyService.isBroadcastPoint(topologyService.currentTopology(), 141 if (topologyService.isBroadcastPoint(topologyService.currentTopology(),
142 - context.inPacket().receivedFrom())) { 142 + context.inPacket().receivedFrom())) {
143 packetOut(context, PortNumber.FLOOD); 143 packetOut(context, PortNumber.FLOOD);
144 } else { 144 } else {
145 context.block(); 145 context.block();
...@@ -161,15 +161,15 @@ public class ReactiveForwarding { ...@@ -161,15 +161,15 @@ public class ReactiveForwarding {
161 Ethernet inPkt = context.inPacket().parsed(); 161 Ethernet inPkt = context.inPacket().parsed();
162 TrafficSelector.Builder builder = new DefaultTrafficSelector.Builder(); 162 TrafficSelector.Builder builder = new DefaultTrafficSelector.Builder();
163 builder.add(Criteria.matchEthType(inPkt.getEtherType())) 163 builder.add(Criteria.matchEthType(inPkt.getEtherType()))
164 - .add(Criteria.matchEthSrc(inPkt.getSourceMAC())) 164 + .add(Criteria.matchEthSrc(inPkt.getSourceMAC()))
165 - .add(Criteria.matchEthDst(inPkt.getDestinationMAC())) 165 + .add(Criteria.matchEthDst(inPkt.getDestinationMAC()))
166 - .add(Criteria.matchInPort(context.inPacket().receivedFrom().port())); 166 + .add(Criteria.matchInPort(context.inPacket().receivedFrom().port()));
167 167
168 TrafficTreatment.Builder treat = new DefaultTrafficTreatment.Builder(); 168 TrafficTreatment.Builder treat = new DefaultTrafficTreatment.Builder();
169 treat.add(Instructions.createOutput(portNumber)); 169 treat.add(Instructions.createOutput(portNumber));
170 170
171 FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(), 171 FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(),
172 - builder.build(), treat.build(), 0); 172 + builder.build(), treat.build(), 0);
173 173
174 flowRuleService.applyFlowRules(f); 174 flowRuleService.applyFlowRules(f);
175 } 175 }
......
...@@ -25,9 +25,12 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext ...@@ -25,9 +25,12 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext
25 private final OFPacketIn pktin; 25 private final OFPacketIn pktin;
26 private OFPacketOut pktout = null; 26 private OFPacketOut pktout = null;
27 27
28 + private final boolean isBuffered;
29 +
28 private DefaultOpenFlowPacketContext(OpenFlowSwitch s, OFPacketIn pkt) { 30 private DefaultOpenFlowPacketContext(OpenFlowSwitch s, OFPacketIn pkt) {
29 this.sw = s; 31 this.sw = s;
30 this.pktin = pkt; 32 this.pktin = pkt;
33 + this.isBuffered = pktin.getBufferId() != OFBufferId.NO_BUFFER;
31 } 34 }
32 35
33 @Override 36 @Override
...@@ -117,4 +120,9 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext ...@@ -117,4 +120,9 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext
117 return !free.get(); 120 return !free.get();
118 } 121 }
119 122
123 + @Override
124 + public boolean isBuffered() {
125 + return isBuffered;
126 + }
127 +
120 } 128 }
......
...@@ -67,4 +67,10 @@ public interface OpenFlowPacketContext { ...@@ -67,4 +67,10 @@ public interface OpenFlowPacketContext {
67 * @return the port 67 * @return the port
68 */ 68 */
69 public Integer inPort(); 69 public Integer inPort();
70 +
71 + /**
72 + * Indicates that this packet is buffered at the switch.
73 + * @return buffer indication
74 + */
75 + boolean isBuffered();
70 } 76 }
......
...@@ -225,5 +225,10 @@ public class OpenFlowHostProviderTest { ...@@ -225,5 +225,10 @@ public class OpenFlowHostProviderTest {
225 return false; 225 return false;
226 } 226 }
227 227
228 + @Override
229 + public boolean isBuffered() {
230 + return false;
231 + }
232 +
228 } 233 }
229 } 234 }
......
...@@ -32,18 +32,19 @@ public class OpenFlowCorePacketContext extends DefaultPacketContext { ...@@ -32,18 +32,19 @@ public class OpenFlowCorePacketContext extends DefaultPacketContext {
32 public void send() { 32 public void send() {
33 if (!this.block()) { 33 if (!this.block()) {
34 if (outPacket() == null) { 34 if (outPacket() == null) {
35 - sendBufferedPacket(); 35 + sendPacket(null);
36 } else { 36 } else {
37 Ethernet eth = new Ethernet(); 37 Ethernet eth = new Ethernet();
38 eth.deserialize(outPacket().data().array(), 0, 38 eth.deserialize(outPacket().data().array(), 0,
39 outPacket().data().array().length); 39 outPacket().data().array().length);
40 - ofPktCtx.build(eth, OFPort.FLOOD); 40 + sendPacket(eth);
41 +
41 } 42 }
42 43
43 } 44 }
44 } 45 }
45 46
46 - private void sendBufferedPacket() { 47 + private void sendPacket(Ethernet eth) {
47 List<Instruction> ins = treatmentBuilder().build().instructions(); 48 List<Instruction> ins = treatmentBuilder().build().instructions();
48 OFPort p = null; 49 OFPort p = null;
49 //TODO: support arbitrary list of treatments must be supported in ofPacketContext 50 //TODO: support arbitrary list of treatments must be supported in ofPacketContext
...@@ -53,10 +54,13 @@ public class OpenFlowCorePacketContext extends DefaultPacketContext { ...@@ -53,10 +54,13 @@ public class OpenFlowCorePacketContext extends DefaultPacketContext {
53 break; //for now... 54 break; //for now...
54 } 55 }
55 } 56 }
56 - ofPktCtx.build(p); 57 + if (eth == null) {
58 + ofPktCtx.build(p);
59 + } else {
60 + ofPktCtx.build(eth, p);
61 + }
57 ofPktCtx.send(); 62 ofPktCtx.send();
58 } 63 }
59 -
60 private OFPort buildPort(PortNumber port) { 64 private OFPort buildPort(PortNumber port) {
61 return OFPort.of((int) port.toLong()); 65 return OFPort.of((int) port.toLong());
62 } 66 }
......
1 package org.onlab.onos.provider.of.packet.impl; 1 package org.onlab.onos.provider.of.packet.impl;
2 2
3 +import static org.onlab.onos.openflow.controller.RoleState.SLAVE;
3 import static org.slf4j.LoggerFactory.getLogger; 4 import static org.slf4j.LoggerFactory.getLogger;
4 5
5 import java.nio.ByteBuffer; 6 import java.nio.ByteBuffer;
...@@ -16,6 +17,7 @@ import org.onlab.onos.net.PortNumber; ...@@ -16,6 +17,7 @@ import org.onlab.onos.net.PortNumber;
16 import org.onlab.onos.net.flow.instructions.Instruction; 17 import org.onlab.onos.net.flow.instructions.Instruction;
17 import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction; 18 import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction;
18 import org.onlab.onos.net.packet.DefaultInboundPacket; 19 import org.onlab.onos.net.packet.DefaultInboundPacket;
20 +import org.onlab.onos.net.packet.DefaultOutboundPacket;
19 import org.onlab.onos.net.packet.OutboundPacket; 21 import org.onlab.onos.net.packet.OutboundPacket;
20 import org.onlab.onos.net.packet.PacketProvider; 22 import org.onlab.onos.net.packet.PacketProvider;
21 import org.onlab.onos.net.packet.PacketProviderRegistry; 23 import org.onlab.onos.net.packet.PacketProviderRegistry;
...@@ -36,8 +38,6 @@ import org.projectfloodlight.openflow.types.OFBufferId; ...@@ -36,8 +38,6 @@ import org.projectfloodlight.openflow.types.OFBufferId;
36 import org.projectfloodlight.openflow.types.OFPort; 38 import org.projectfloodlight.openflow.types.OFPort;
37 import org.slf4j.Logger; 39 import org.slf4j.Logger;
38 40
39 -import static org.onlab.onos.openflow.controller.RoleState.*;
40 -
41 41
42 /** 42 /**
43 * Provider which uses an OpenFlow controller to detect network 43 * Provider which uses an OpenFlow controller to detect network
...@@ -152,9 +152,15 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr ...@@ -152,9 +152,15 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr
152 new ConnectPoint(id, PortNumber.portNumber(pktCtx.inPort())), 152 new ConnectPoint(id, PortNumber.portNumber(pktCtx.inPort())),
153 pktCtx.parsed(), ByteBuffer.wrap(pktCtx.unparsed())); 153 pktCtx.parsed(), ByteBuffer.wrap(pktCtx.unparsed()));
154 154
155 + DefaultOutboundPacket outPkt = null;
156 + if (!pktCtx.isBuffered()) {
157 + outPkt = new DefaultOutboundPacket(id, null,
158 + ByteBuffer.wrap(pktCtx.unparsed()));
159 + }
160 +
155 OpenFlowCorePacketContext corePktCtx = 161 OpenFlowCorePacketContext corePktCtx =
156 new OpenFlowCorePacketContext(System.currentTimeMillis(), 162 new OpenFlowCorePacketContext(System.currentTimeMillis(),
157 - inPkt, null, pktCtx.isHandled(), pktCtx); 163 + inPkt, outPkt, pktCtx.isHandled(), pktCtx);
158 providerService.processPacket(corePktCtx); 164 providerService.processPacket(corePktCtx);
159 } 165 }
160 166
......