Thursday, February 9, 2012

Creating a hub in Floodlight

I'm interested in learning more about OpenFlow, and thought I'd go through the OpenFlow tutorial. Just to make things interesting I'm going to port it over from Beacon to Floodlight. First step for me is to remove the default forwarding behavior and just make the controller and switch act as a simple hub.

First we'll comment out the calls to initForwarding() and forwarding.startup() in Controller.java as well as references to the forwarding global variable:

protected void init() {
    topology = new TopologyImpl();
    deviceManager = new DeviceManagerImpl();
    counterStore = new CounterStore();
    pktinProcTime = new PktinProcessingTime();
    routingEngine = new RoutingImpl();
    flowCacheManager = new FlowCache();
    initStorageSource();

    topology.setFloodlightProvider(this);
    topology.setStorageSource(storageSource);

    deviceManager.setFloodlightProvider(this);
    deviceManager.setStorageSource(storageSource);
    deviceManager.setTopology(topology);

    initMessageFilterManager();
    initStaticFlowPusher();
    //initForwarding();


    // call this explicitly because it does setup
    this.setStorageSource(storageSource);        

    HashSet<ITopologyAware> topologyAware = new HashSet<ITopologyAware>();
    topologyAware.add(deviceManager);
    topologyAware.add(routingEngine);
    topology.setTopologyAware(topologyAware);
    topology.setRoutingEngine(routingEngine);

    HashSet<IDeviceManagerAware> dmAware = 
        new HashSet<IDeviceManagerAware>();
    //dmAware.add(forwarding);

protected void startupComponents() {
    // now, do our own init
    try {
        log.debug("Doing controller internal setup");
        this.startUp();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    log.debug("Starting topology service");
    topology.startUp();
    log.debug("Starting deviceManager service");
    deviceManager.startUp();
    // no need to do storageSource.startUp()
    log.debug("Starting counterStore service");
    counterStore.startUp();
    log.debug("Starting routingEngine service");
    routingEngine.startUp();
    //log.debug("Starting forwarding service");
    //forwarding.startUp(); 

protected void debugserver_start() {
    Map<String, Object> locals = new HashMap<String, Object>();
    locals.put("controller", this);
    locals.put("deviceManager", this.deviceManager);
    locals.put("topology", this.topology);
    locals.put("routingEngine", this.routingEngine);
    //locals.put("forwarding", this.forwarding);

Now we import the hub class:

import net.floodlightcontroller.hub.Hub; 

Then create a hub global variable:

protected Hub hub;

In the init() method we create our hub instance and set the floodlightprovider

hub = new Hub();
hub.setFloodlightProvider(this);

Then tell the hub to startup in the startupComponents() method

hub.startup();

After these changes I started up the controller and data gets forwarded out all ports just like a hub should!

No comments:

Post a Comment