Skip to content
Snippets Groups Projects
Commit d7f6fa62 authored by Alex Reimers's avatar Alex Reimers
Browse files

Modify LearningSwitch and Hub to be proper loadable IFloodlightModules.

parent 27b94445
No related branches found
No related tags found
No related merge requests found
...@@ -18,12 +18,19 @@ ...@@ -18,12 +18,19 @@
package net.floodlightcontroller.hub; package net.floodlightcontroller.hub;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map;
import net.floodlightcontroller.core.FloodlightContext; import net.floodlightcontroller.core.FloodlightContext;
import net.floodlightcontroller.core.IFloodlightProviderService; import net.floodlightcontroller.core.IFloodlightProviderService;
import net.floodlightcontroller.core.IOFMessageListener; import net.floodlightcontroller.core.IOFMessageListener;
import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.IOFSwitch;
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.module.FloodlightModuleException;
import net.floodlightcontroller.core.module.IFloodlightModule;
import net.floodlightcontroller.core.module.IFloodlightService;
import org.openflow.protocol.OFMessage; import org.openflow.protocol.OFMessage;
import org.openflow.protocol.OFPacketIn; import org.openflow.protocol.OFPacketIn;
...@@ -40,7 +47,7 @@ import org.slf4j.LoggerFactory; ...@@ -40,7 +47,7 @@ import org.slf4j.LoggerFactory;
* *
* @author David Erickson (daviderickson@cs.stanford.edu) - 04/04/10 * @author David Erickson (daviderickson@cs.stanford.edu) - 04/04/10
*/ */
public class Hub implements IOFMessageListener { public class Hub implements IFloodlightModule, IOFMessageListener {
protected static Logger log = LoggerFactory.getLogger(Hub.class); protected static Logger log = LoggerFactory.getLogger(Hub.class);
protected IFloodlightProviderService floodlightProvider; protected IFloodlightProviderService floodlightProvider;
...@@ -52,14 +59,6 @@ public class Hub implements IOFMessageListener { ...@@ -52,14 +59,6 @@ public class Hub implements IOFMessageListener {
this.floodlightProvider = floodlightProvider; this.floodlightProvider = floodlightProvider;
} }
public void startUp() {
floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this);
}
public void shutDown() {
floodlightProvider.removeOFMessageListener(OFType.PACKET_IN, this);
}
@Override @Override
public String getName() { public String getName() {
return Hub.class.getPackage().getName(); return Hub.class.getPackage().getName();
...@@ -112,4 +111,40 @@ public class Hub implements IOFMessageListener { ...@@ -112,4 +111,40 @@ public class Hub implements IOFMessageListener {
public boolean isCallbackOrderingPostreq(OFType type, String name) { public boolean isCallbackOrderingPostreq(OFType type, String name) {
return false; return false;
} }
// IFloodlightModule
@Override
public Collection<Class<? extends IFloodlightService>> getModuleServices() {
// We don't provide any services, return null
return null;
}
@Override
public Map<Class<? extends IFloodlightService>, IFloodlightService>
getServiceImpls() {
// We don't provide any services, return null
return null;
}
@Override
public Collection<Class<? extends IFloodlightService>>
getModuleDependencies() {
Collection<Class<? extends IFloodlightService>> l =
new ArrayList<Class<? extends IFloodlightService>>();
l.add(IFloodlightProviderService.class);
return l;
}
@Override
public void init(FloodlightModuleContext context)
throws FloodlightModuleException {
floodlightProvider =
context.getServiceImpl(IFloodlightProviderService.class);
}
@Override
public void startUp(FloodlightModuleContext context) {
floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this);
}
} }
...@@ -32,12 +32,18 @@ package net.floodlightcontroller.learningswitch; ...@@ -32,12 +32,18 @@ package net.floodlightcontroller.learningswitch;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import net.floodlightcontroller.core.FloodlightContext; import net.floodlightcontroller.core.FloodlightContext;
import net.floodlightcontroller.core.IFloodlightProviderService; import net.floodlightcontroller.core.IFloodlightProviderService;
import net.floodlightcontroller.core.IOFMessageListener; import net.floodlightcontroller.core.IOFMessageListener;
import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.IOFSwitch;
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.module.FloodlightModuleException;
import net.floodlightcontroller.core.module.IFloodlightModule;
import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.counter.CounterStore; import net.floodlightcontroller.counter.CounterStore;
import net.floodlightcontroller.counter.CounterValue; import net.floodlightcontroller.counter.CounterValue;
import net.floodlightcontroller.counter.ICounter; import net.floodlightcontroller.counter.ICounter;
...@@ -61,7 +67,7 @@ import org.openflow.util.HexString; ...@@ -61,7 +67,7 @@ import org.openflow.util.HexString;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class LearningSwitch implements IOFMessageListener { public class LearningSwitch implements IFloodlightModule, IOFMessageListener {
protected static Logger log = LoggerFactory.getLogger(LearningSwitch.class); protected static Logger log = LoggerFactory.getLogger(LearningSwitch.class);
protected IFloodlightProviderService floodlightProvider; protected IFloodlightProviderService floodlightProvider;
protected ICounterStoreService counterStore; protected ICounterStoreService counterStore;
...@@ -96,22 +102,6 @@ public class LearningSwitch implements IOFMessageListener { ...@@ -96,22 +102,6 @@ public class LearningSwitch implements IOFMessageListener {
public void setCounterStore(ICounterStoreService counterStore) { public void setCounterStore(ICounterStoreService counterStore) {
this.counterStore = counterStore; this.counterStore = counterStore;
} }
public void startUp() {
log.trace("Starting");
floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this);
//floodlightProvider.addOFMessageListener(OFType.PORT_STATUS, this);
floodlightProvider.addOFMessageListener(OFType.FLOW_REMOVED, this);
floodlightProvider.addOFMessageListener(OFType.ERROR, this);
}
public void shutDown() {
log.trace("Stopping");
floodlightProvider.removeOFMessageListener(OFType.PACKET_IN, this);
//floodlightProvider.removeOFMessageListener(OFType.PORT_STATUS, this);
floodlightProvider.removeOFMessageListener(OFType.FLOW_REMOVED, this);
floodlightProvider.removeOFMessageListener(OFType.ERROR, this);
}
@Override @Override
public String getName() { public String getName() {
...@@ -202,7 +192,10 @@ public class LearningSwitch implements IOFMessageListener { ...@@ -202,7 +192,10 @@ public class LearningSwitch implements IOFMessageListener {
flowMod.setActions(Arrays.asList((OFAction) new OFActionOutput(outPort, (short) 0xffff))); flowMod.setActions(Arrays.asList((OFAction) new OFActionOutput(outPort, (short) 0xffff)));
flowMod.setLength((short) (OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH)); flowMod.setLength((short) (OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH));
log.trace("{} {} flow mod {}", new Object[]{ sw, (command == OFFlowMod.OFPFC_DELETE) ? "deleting" : "adding", flowMod }); if (log.isTraceEnabled()) {
log.trace("{} {} flow mod {}",
new Object[]{ sw, (command == OFFlowMod.OFPFC_DELETE) ? "deleting" : "adding", flowMod });
}
updateCounterStore(sw, flowMod); updateCounterStore(sw, flowMod);
...@@ -328,7 +321,6 @@ public class LearningSwitch implements IOFMessageListener { ...@@ -328,7 +321,6 @@ public class LearningSwitch implements IOFMessageListener {
private Command processPortStatusMessage(IOFSwitch sw, OFPortStatus portStatusMessage) { private Command processPortStatusMessage(IOFSwitch sw, OFPortStatus portStatusMessage) {
// FIXME This is really just an optimization, speeding up removal of flow // FIXME This is really just an optimization, speeding up removal of flow
// entries for a disabled port; think about whether it's really needed // entries for a disabled port; think about whether it's really needed
log.info("learning switch got a port_status");
OFPhysicalPort port = portStatusMessage.getDesc(); OFPhysicalPort port = portStatusMessage.getDesc();
log.info("received port status: " + portStatusMessage.getReason() + " for port " + port.getPortNumber()); log.info("received port status: " + portStatusMessage.getReason() + " for port " + port.getPortNumber());
// LOOK! should be using the reason enums - but how? // LOOK! should be using the reason enums - but how?
...@@ -348,7 +340,9 @@ public class LearningSwitch implements IOFMessageListener { ...@@ -348,7 +340,9 @@ public class LearningSwitch implements IOFMessageListener {
if (flowRemovedMessage.getCookie() != LearningSwitch.LEARNING_SWITCH_COOKIE) { if (flowRemovedMessage.getCookie() != LearningSwitch.LEARNING_SWITCH_COOKIE) {
return Command.CONTINUE; return Command.CONTINUE;
} }
log.trace("{} flow entry removed {}", sw, flowRemovedMessage); if (log.isTraceEnabled()) {
log.trace("{} flow entry removed {}", sw, flowRemovedMessage);
}
OFMatch match = flowRemovedMessage.getMatch(); OFMatch match = flowRemovedMessage.getMatch();
// When a flow entry expires, it means the device with the matching source // When a flow entry expires, it means the device with the matching source
// MAC address and VLAN either stopped sending packets or moved to a different // MAC address and VLAN either stopped sending packets or moved to a different
...@@ -394,12 +388,54 @@ public class LearningSwitch implements IOFMessageListener { ...@@ -394,12 +388,54 @@ public class LearningSwitch implements IOFMessageListener {
@Override @Override
public boolean isCallbackOrderingPrereq(OFType type, String name) { public boolean isCallbackOrderingPrereq(OFType type, String name) {
return (type == OFType.PACKET_IN && // TODO - change this
(name.equals("devicemanager") || name.equals("forwarding"))); return false;
} }
@Override @Override
public boolean isCallbackOrderingPostreq(OFType type, String name) { public boolean isCallbackOrderingPostreq(OFType type, String name) {
return false; return false;
} }
// IFloodlightModule
@Override
public Collection<Class<? extends IFloodlightService>> getModuleServices() {
// We don't provide any services, return null
return null;
}
@Override
public Map<Class<? extends IFloodlightService>, IFloodlightService>
getServiceImpls() {
// We don't provide any services, return null
return null;
}
@Override
public Collection<Class<? extends IFloodlightService>>
getModuleDependencies() {
Collection<Class<? extends IFloodlightService>> l =
new ArrayList<Class<? extends IFloodlightService>>();
l.add(IFloodlightProviderService.class);
l.add(ICounterStoreService.class);
return l;
}
@Override
public void init(FloodlightModuleContext context)
throws FloodlightModuleException {
floodlightProvider =
context.getServiceImpl(IFloodlightProviderService.class);
counterStore =
context.getServiceImpl(ICounterStoreService.class);
}
@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);
}
} }
...@@ -7,4 +7,6 @@ net.floodlightcontroller.forwarding.Forwarding ...@@ -7,4 +7,6 @@ net.floodlightcontroller.forwarding.Forwarding
net.floodlightcontroller.core.OFMessageFilterManager net.floodlightcontroller.core.OFMessageFilterManager
net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher
net.floodlightcontroller.perfmon.PktInProcessingTime net.floodlightcontroller.perfmon.PktInProcessingTime
net.floodlightcontroller.restserver.RestApiServer net.floodlightcontroller.restserver.RestApiServer
\ No newline at end of file net.floodlightcontroller.learningswitch.LearningSwitch
net.floodlightcontroller.hub.Hub
\ 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