Skip to content
Snippets Groups Projects
Commit 7ec00431 authored by Ryan Izard's avatar Ryan Izard
Browse files

Merge pull request #597 from rizard/master

Patch Forwarding's pushRoute and pushPacket
parents f7e211bc f54eec09
No related branches found
No related tags found
No related merge requests found
...@@ -234,8 +234,8 @@ public class Forwarding extends ForwardingBase implements IFloodlightModule { ...@@ -234,8 +234,8 @@ public class Forwarding extends ForwardingBase implements IFloodlightModule {
Match m = createMatchFromPacket(sw, inPort, cntx); Match m = createMatchFromPacket(sw, inPort, cntx);
log.debug("Cretaing flow rules on the route, match rule: {}", m); log.debug("Cretaing flow rules on the route, match rule: {}", m);
pushRoute(route, m, pi, sw.getId(), cookie, pushRoute(route, m, pi, sw.getId(), cookie,
cntx, requestFlowRemovedNotifn, false, cntx, requestFlowRemovedNotifn,
OFFlowModCommand.ADD); OFFlowModCommand.ADD);
} else { } else {
log.error("Could not compute route between {} and {}. Dropping packet", srcDevice, dstDevice); log.error("Could not compute route between {} and {}. Dropping packet", srcDevice, dstDevice);
......
...@@ -71,9 +71,7 @@ import org.slf4j.LoggerFactory; ...@@ -71,9 +71,7 @@ import org.slf4j.LoggerFactory;
* decision. * decision.
*/ */
public abstract class ForwardingBase implements IOFMessageListener { public abstract class ForwardingBase implements IOFMessageListener {
protected static Logger log = LoggerFactory.getLogger(ForwardingBase.class);
protected static Logger log =
LoggerFactory.getLogger(ForwardingBase.class);
protected static int OFMESSAGE_DAMPER_CAPACITY = 10000; // TODO: find sweet spot protected static int OFMESSAGE_DAMPER_CAPACITY = 10000; // TODO: find sweet spot
protected static int OFMESSAGE_DAMPER_TIMEOUT = 250; // ms protected static int OFMESSAGE_DAMPER_TIMEOUT = 250; // ms
...@@ -128,27 +126,16 @@ public abstract class ForwardingBase implements IOFMessageListener { ...@@ -128,27 +126,16 @@ public abstract class ForwardingBase implements IOFMessageListener {
} }
}; };
/**
* init data structures
*
*/
protected void init() { protected void init() {
messageDamper = new OFMessageDamper(OFMESSAGE_DAMPER_CAPACITY, messageDamper = new OFMessageDamper(OFMESSAGE_DAMPER_CAPACITY,
EnumSet.of(OFType.FLOW_MOD), EnumSet.of(OFType.FLOW_MOD),
OFMESSAGE_DAMPER_TIMEOUT); OFMESSAGE_DAMPER_TIMEOUT);
} }
/**
* Adds a listener for devicemanager and registers for PacketIns.
*/
protected void startUp() { protected void startUp() {
floodlightProviderService.addOFMessageListener(OFType.PACKET_IN, this); floodlightProviderService.addOFMessageListener(OFType.PACKET_IN, this);
} }
/**
* Returns the application name "forwarding".
*/
@Override @Override
public String getName() { public String getName() {
return "forwarding"; return "forwarding";
...@@ -192,20 +179,17 @@ public abstract class ForwardingBase implements IOFMessageListener { ...@@ -192,20 +179,17 @@ public abstract class ForwardingBase implements IOFMessageListener {
* @param dstSwPort Destination switch port for final hop * @param dstSwPort Destination switch port for final hop
* @param cookie The cookie to set in each flow_mod * @param cookie The cookie to set in each flow_mod
* @param cntx The floodlight context * @param cntx The floodlight context
* @param reqeustFlowRemovedNotifn if set to true then the switch would * @param requestFlowRemovedNotification if set to true then the switch would
* send a flow mod removal notification when the flow mod expires * send a flow mod removal notification when the flow mod expires
* @param doFlush if set to true then the flow mod would be immediately
* written to the switch
* @param flowModCommand flow mod. command to use, e.g. OFFlowMod.OFPFC_ADD, * @param flowModCommand flow mod. command to use, e.g. OFFlowMod.OFPFC_ADD,
* OFFlowMod.OFPFC_MODIFY etc. * OFFlowMod.OFPFC_MODIFY etc.
* @return srcSwitchIncluded True if the source switch is included in this route * @return true if a packet out was sent on the first-hop switch of this route
*/ */
public boolean pushRoute(Route route, Match match, OFPacketIn pi, public boolean pushRoute(Route route, Match match, OFPacketIn pi,
DatapathId pinSwitch, U64 cookie, FloodlightContext cntx, DatapathId pinSwitch, U64 cookie, FloodlightContext cntx,
boolean reqeustFlowRemovedNotifn, boolean doFlush, boolean requestFlowRemovedNotification, OFFlowModCommand flowModCommand) {
OFFlowModCommand flowModCommand) {
boolean srcSwitchIncluded = false; boolean packetOutSent = false;
List<NodePortTuple> switchPortList = route.getPath(); List<NodePortTuple> switchPortList = route.getPath();
...@@ -218,7 +202,7 @@ public abstract class ForwardingBase implements IOFMessageListener { ...@@ -218,7 +202,7 @@ public abstract class ForwardingBase implements IOFMessageListener {
if (log.isWarnEnabled()) { if (log.isWarnEnabled()) {
log.warn("Unable to push route, switch at DPID {} " + "not available", switchDPID); log.warn("Unable to push route, switch at DPID {} " + "not available", switchDPID);
} }
return srcSwitchIncluded; return packetOutSent;
} }
// need to build flow mod based on what type it is. Cannot set command later // need to build flow mod based on what type it is. Cannot set command later
...@@ -255,14 +239,13 @@ public abstract class ForwardingBase implements IOFMessageListener { ...@@ -255,14 +239,13 @@ public abstract class ForwardingBase implements IOFMessageListener {
aob.setMaxLen(Integer.MAX_VALUE); aob.setMaxLen(Integer.MAX_VALUE);
actions.add(aob.build()); actions.add(aob.build());
if(FLOWMOD_DEFAULT_SET_SEND_FLOW_REM_FLAG) { if (FLOWMOD_DEFAULT_SET_SEND_FLOW_REM_FLAG || requestFlowRemovedNotification) {
Set<OFFlowModFlags> flags = new HashSet<>(); Set<OFFlowModFlags> flags = new HashSet<>();
flags.add(OFFlowModFlags.SEND_FLOW_REM); flags.add(OFFlowModFlags.SEND_FLOW_REM);
fmb.setFlags(flags); fmb.setFlags(flags);
} }
// compile fmb.setMatch(mb.build())
fmb.setMatch(mb.build()) // was match w/o modifying input port
.setActions(actions) .setActions(actions)
.setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT) .setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT)
.setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT) .setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT)
...@@ -281,55 +264,35 @@ public abstract class ForwardingBase implements IOFMessageListener { ...@@ -281,55 +264,35 @@ public abstract class ForwardingBase implements IOFMessageListener {
outPort }); outPort });
} }
messageDamper.write(sw, fmb.build()); messageDamper.write(sw, fmb.build());
if (doFlush) {
sw.flush();
}
// Push the packet out the source switch /* Push the packet out the first hop switch */
if (sw.getId().equals(pinSwitch)) { if (sw.getId().equals(pinSwitch) &&
// TODO: Instead of doing a packetOut here we could also !fmb.getCommand().equals(OFFlowModCommand.DELETE) &&
// send a flowMod with bufferId set.... !fmb.getCommand().equals(OFFlowModCommand.DELETE_STRICT)) {
pushPacket(sw, pi, false, outPort, cntx); /* Use the buffered packet at the switch, if there's one stored */
srcSwitchIncluded = true; pushPacket(sw, pi, outPort, true, cntx);
packetOutSent = true;
} }
} catch (IOException e) { } catch (IOException e) {
log.error("Failure writing flow mod", e); log.error("Failure writing flow mod", e);
} }
} }
return srcSwitchIncluded; return packetOutSent;
} }
/**
* Pushes a packet-out to a switch. If bufferId != BUFFER_ID_NONE we
* assume that the packetOut switch is the same as the packetIn switch
* and we will use the bufferId. In this case the packet can be null
* Caller needs to make sure that inPort and outPort differs
* @param packet packet data to send.
* @param sw switch from which packet-out is sent
* @param bufferId bufferId
* @param inPort input port
* @param outPort output port
* @param cntx context of the packet
* @param flush force to flush the packet.
*/
/** /**
* Pushes a packet-out to a switch. The assumption here is that * Pushes a packet-out to a switch. The assumption here is that
* the packet-in was also generated from the same switch. Thus, if the input * the packet-in was also generated from the same switch. Thus, if the input
* port of the packet-in and the outport are the same, the function will not * port of the packet-in and the outport are the same, the function will not
* push the packet-out. * push the packet-out.
* @param sw switch that generated the packet-in, and from which packet-out is sent * @param sw switch that generated the packet-in, and from which packet-out is sent
* @param pi packet-in * @param pi packet-in
* @param useBufferId if true, use the bufferId from the packet in and * @param outport output port
* do not add the packetIn's payload. If false set bufferId to * @param useBufferedPacket use the packet buffered at the switch, if possible
* BUFFER_ID_NONE and use the packetIn's payload * @param cntx context of the packet
* @param outport output port
* @param cntx context of the packet
*/ */
protected void pushPacket(IOFSwitch sw, OFPacketIn pi, boolean useBufferId, protected void pushPacket(IOFSwitch sw, OFPacketIn pi, OFPort outport, boolean useBufferedPacket, FloodlightContext cntx) {
OFPort outport, FloodlightContext cntx) {
if (pi == null) { if (pi == null) {
return; return;
} }
...@@ -353,18 +316,18 @@ public abstract class ForwardingBase implements IOFMessageListener { ...@@ -353,18 +316,18 @@ public abstract class ForwardingBase implements IOFMessageListener {
} }
OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut(); OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
// set actions
List<OFAction> actions = new ArrayList<OFAction>(); List<OFAction> actions = new ArrayList<OFAction>();
actions.add(sw.getOFFactory().actions().output(outport, Integer.MAX_VALUE)); actions.add(sw.getOFFactory().actions().output(outport, Integer.MAX_VALUE));
pob.setActions(actions); pob.setActions(actions);
if (useBufferId) { /* Use packet in buffer if there is a buffer ID set */
pob.setBufferId(pi.getBufferId()); if (useBufferedPacket) {
pob.setBufferId(pi.getBufferId()); /* will be NO_BUFFER if there isn't one */
} else { } else {
pob.setBufferId(OFBufferId.NO_BUFFER); pob.setBufferId(OFBufferId.NO_BUFFER);
} }
if (pob.getBufferId() == OFBufferId.NO_BUFFER) { if (pob.getBufferId().equals(OFBufferId.NO_BUFFER)) {
byte[] packetData = pi.getData(); byte[] packetData = pi.getData();
pob.setData(packetData); pob.setData(packetData);
} }
...@@ -378,7 +341,6 @@ public abstract class ForwardingBase implements IOFMessageListener { ...@@ -378,7 +341,6 @@ public abstract class ForwardingBase implements IOFMessageListener {
} }
} }
/** /**
* Write packetout message to sw with output actions to one or more * Write packetout message to sw with output actions to one or more
* output ports with inPort/outPorts passed in. * output ports with inPort/outPorts passed in.
...@@ -476,7 +438,7 @@ public abstract class ForwardingBase implements IOFMessageListener { ...@@ -476,7 +438,7 @@ public abstract class ForwardingBase implements IOFMessageListener {
log.debug("write drop flow-mod sw={} match={} flow-mod={}", log.debug("write drop flow-mod sw={} match={} flow-mod={}",
new Object[] { sw, mb.build(), fmb.build() }); new Object[] { sw, mb.build(), fmb.build() });
// TODO: can't use the message damper sine this method is static // TODO: can't use the message damper since this method is static
sw.write(fmb.build()); sw.write(fmb.build());
return true; return true;
...@@ -491,5 +453,4 @@ public abstract class ForwardingBase implements IOFMessageListener { ...@@ -491,5 +453,4 @@ public abstract class ForwardingBase implements IOFMessageListener {
public boolean isCallbackOrderingPostreq(OFType type, String name) { public boolean isCallbackOrderingPostreq(OFType type, String name) {
return false; return false;
} }
}
} \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment