diff --git a/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitch.java b/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitch.java index d9771468a7b981ad6a798d675e58f4c6bb0c58ef..08fe99305a26b9cae6c8b48e58e737f4229e332a 100644 --- a/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitch.java +++ b/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitch.java @@ -59,9 +59,7 @@ import org.openflow.protocol.OFMatch; import org.openflow.protocol.OFMessage; import org.openflow.protocol.OFPacketIn; import org.openflow.protocol.OFPacketOut; -import org.openflow.protocol.OFPhysicalPort; import org.openflow.protocol.OFPort; -import org.openflow.protocol.OFPortStatus; import org.openflow.protocol.OFType; import org.openflow.protocol.action.OFAction; import org.openflow.protocol.action.OFActionOutput; @@ -79,6 +77,7 @@ public class LearningSwitch protected ICounterStoreService counterStore; protected IRestApiService restApi; + // Stores the learned state for each switch protected Map<IOFSwitch, Map<MacVlanPair,Short>> macVlanToSwitchPortMap; // flow-mod - for use in the cookie @@ -107,14 +106,6 @@ public class LearningSwitch this.floodlightProvider = floodlightProvider; } - public ICounterStoreService getCounterStore() { - return counterStore; - } - - public void setCounterStore(ICounterStoreService counterStore) { - this.counterStore = counterStore; - } - @Override public String getName() { return "learningswitch"; @@ -200,6 +191,14 @@ public class LearningSwitch return macVlanToSwitchPortMap; } + /** + * Writes a OFFlowMod to a switch. + * @param sw The switch tow rite the flowmod to. + * @param command The FlowMod actions (add, delete, etc). + * @param bufferId The buffer ID if the switch has buffered the packet. + * @param match The OFMatch structure to write. + * @param outPort The switch port to output it to. + */ private void writeFlowMod(IOFSwitch sw, short command, int bufferId, OFMatch match, short outPort) { // from openflow 1.0 spec - need to set these on a struct ofp_flow_mod: @@ -262,6 +261,12 @@ public class LearningSwitch } } + /** + * Writes an OFPacketOut message to a switch. + * @param sw The switch to write the PacketOut to. + * @param packetInMessage The corresponding PacketIn. + * @param egressPort The switchport to output the PacketOut. + */ private void writePacketOutForPacketIn(IOFSwitch sw, OFPacketIn packetInMessage, short egressPort) { @@ -307,6 +312,15 @@ public class LearningSwitch } } + /** + * Processes a OFPacketIn message. If the switch has learned the MAC/VLAN to port mapping + * for the pair it will write a FlowMod for. If the mapping has not been learned the + * we will flood the packet. + * @param sw + * @param pi + * @param cntx + * @return + */ private Command processPacketInMessage(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) { // Read in packet data headers by using OFMatch OFMatch match = new OFMatch(); @@ -368,32 +382,14 @@ public class LearningSwitch } return Command.CONTINUE; } - - public void removedSwitch(IOFSwitch sw) { - // delete the switch structures - // they will get recreated on first packetin - log.info("clearing macVlanToPortMap for switch {}", sw); - clearLearnedTable(sw); - } - - private Command processPortStatusMessage(IOFSwitch sw, OFPortStatus portStatusMessage) { - // FIXME This is really just an optimization, speeding up removal of flow - // entries for a disabled port; think about whether it's really needed - OFPhysicalPort port = portStatusMessage.getDesc(); - log.info("received port status: " + portStatusMessage.getReason() + " for port " + port.getPortNumber()); - // LOOK! should be using the reason enums - but how? - if (portStatusMessage.getReason() == 1 || // DELETED - (portStatusMessage.getReason() == 2 && // MODIFIED and is now down - ((port.getConfig() & OFPhysicalPort.OFPortConfig.OFPPC_PORT_DOWN.getValue()) > 1 || - (port.getState() & OFPhysicalPort.OFPortState.OFPPS_LINK_DOWN.getValue()) > 1))) { - // then we should reset the switch data structures - // LOOK! we could be doing something more intelligent like - // extract out the macs just assigned to a port, but this is ok for now - this.removedSwitch(sw); - } - return Command.CONTINUE; - } + /** + * Processes a flow removed message. We will delete the learned MAC/VLAN mapping from + * the switch's table. + * @param sw The switch that sent the flow removed message. + * @param flowRemovedMessage The flow removed message. + * @return Whether to continue processing this message or stop. + */ private Command processFlowRemovedMessage(IOFSwitch sw, OFFlowRemoved flowRemovedMessage) { if (flowRemovedMessage.getCookie() != LearningSwitch.LEARNING_SWITCH_COOKIE) { return Command.CONTINUE; @@ -428,12 +424,13 @@ public class LearningSwitch return Command.CONTINUE; } + // IOFMessageListener + + @Override public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) { switch (msg.getType()) { case PACKET_IN: return this.processPacketInMessage(sw, (OFPacketIn) msg, cntx); - case PORT_STATUS: - return this.processPortStatusMessage(sw, (OFPortStatus) msg); case FLOW_REMOVED: return this.processFlowRemovedMessage(sw, (OFFlowRemoved) msg); case ERROR: @@ -446,7 +443,6 @@ public class LearningSwitch @Override public boolean isCallbackOrderingPrereq(OFType type, String name) { - // TODO - change this return false; } @@ -503,7 +499,6 @@ public class LearningSwitch @Override public void startUp(FloodlightModuleContext context) { floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this); - //floodlightProvider.addOFMessageListener(OFType.PORT_STATUS, this); floodlightProvider.addOFMessageListener(OFType.FLOW_REMOVED, this); floodlightProvider.addOFMessageListener(OFType.ERROR, this); restApi.addRestletRoutable(new LearningSwitchWebRoutable()); diff --git a/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java b/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java index 6e17a098bf2ec9b6fcf8a6bfa79dbce5b934a5ad..a0158bd5cdc1b62f2f2c554ee221d3fa0d30380c 100644 --- a/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java +++ b/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java @@ -95,11 +95,17 @@ public abstract class ForwardingBase implements } }; + /** + * Adds a listener for devicemanager and registers for PacketIns. + */ public void startUp() { deviceManager.addListener(this); floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this); } + /** + * Returns the application name "forwarding". + */ @Override public String getName() { return "forwarding"; @@ -128,9 +134,9 @@ public abstract class ForwardingBase implements case PACKET_IN: IRoutingDecision decision = null; if (cntx != null) - decision = - IRoutingDecision.rtStore.get(cntx, - IRoutingDecision.CONTEXT_DECISION); + decision = + IRoutingDecision.rtStore.get(cntx, + IRoutingDecision.CONTEXT_DECISION); return this.processPacketInMessage(sw, (OFPacketIn) msg, @@ -309,7 +315,7 @@ public abstract class ForwardingBase implements } /** - * This function will push 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 * port of the packet-in and the outport are the same, the function will not * push the packet-out. @@ -526,18 +532,14 @@ public abstract class ForwardingBase implements } /** - * @param floodlightProvider - * the floodlightProvider to set + * @param floodlightProvider the floodlightProvider to set */ - public - void - setFloodlightProvider(IFloodlightProviderService floodlightProvider) { + public void setFloodlightProvider(IFloodlightProviderService floodlightProvider) { this.floodlightProvider = floodlightProvider; } /** - * @param routingEngine - * the routingEngine to set + * @param routingEngine the routingEngine to set */ public void setRoutingEngine(IRoutingService routingEngine) { this.routingEngine = routingEngine; @@ -559,10 +561,6 @@ public abstract class ForwardingBase implements this.topology = topology; } - public ICounterStoreService getCounterStore() { - return counterStore; - } - public void setCounterStore(ICounterStoreService counterStore) { this.counterStore = counterStore; } diff --git a/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntries.java b/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntries.java index f39520f1e18f09c22687e32fbcb829244966df09..a7dc0eed39d47bfe8e9c2e2c63c361c58524aa0b 100644 --- a/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntries.java +++ b/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntries.java @@ -301,7 +301,7 @@ public class StaticFlowEntries { } /** - * Parses OFFlowMod actions from a database + * Parses OFFlowMod actions from strings. * @param flowMod The OFFlowMod to set the actions for * @param actionstr The string containing all the actions * @param log A logger to log for errors.