Stanford OpenFlow Forums: Question about Declarative routing - Stanford OpenFlow Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Question about Declarative routing Rate Topic: -----

#1 User is offline   beyounn 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 21-October 11

Posted 22 October 2011 - 02:45 PM

David,
In your ppt (https://openflow.sta...e=1314745611000), you have mentioned about declarative routing, could you give some more info on it? What is it? And how to use it?

At the moment, I'm looking for a way to push some flow rules to my switch. And these rules will work like a simple static route (if ip.dst==x/y then set mac/ip to m/i then send packet out from port p), is there a way to do it without changing source code?
Thanks
Yi
0

#2 User is offline   David Erickson 

  • Developer
  • Group: Administrators
  • Posts: 653
  • Joined: 28-June 11

Posted 22 October 2011 - 07:32 PM

View Postbeyounn, on 22 October 2011 - 02:45 PM, said:

David,
In your ppt (https://openflow.sta...e=1314745611000), you have mentioned about declarative routing, could you give some more info on it? What is it? And how to use it?

At the moment, I'm looking for a way to push some flow rules to my switch. And these rules will work like a simple static route (if ip.dst==x/y then set mac/ip to m/i then send packet out from port p), is there a way to do it without changing source code?
Thanks
Yi


Hi Yi,
I have a couple modules in development at the moment for another project, the first is a static routing class that you can programatically extend to insert static flows at switch connect time, how you populate this is up to you. The second is a RoutingEngine implementation that takes a JSON document containing routes, so when a packet comes in matching a particular set of traffic this engine receives it and returns the route specified in the document. If either of these sound like something you are looking for I could get you an early copy of the code to play with if you'd like.

-David
0

#3 User is offline   beyounn 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 21-October 11

Posted 24 October 2011 - 09:02 AM

View PostDavid Erickson, on 22 October 2011 - 07:32 PM, said:

Hi Yi,
I have a couple modules in development at the moment for another project, the first is a static routing class that you can programatically extend to insert static flows at switch connect time, how you populate this is up to you. The second is a RoutingEngine implementation that takes a JSON document containing routes, so when a packet comes in matching a particular set of traffic this engine receives it and returns the route specified in the document. If either of these sound like something you are looking for I could get you an early copy of the code to play with if you'd like.

-David


David,
These are exactly what we need. It would be very helpful, if you can give us some early code to try out.
Thank you very much
Yi
0

#4 User is offline   David Erickson 

  • Developer
  • Group: Administrators
  • Posts: 653
  • Joined: 28-June 11

Posted 26 October 2011 - 10:43 AM

View Postbeyounn, on 24 October 2011 - 09:02 AM, said:

David,
These are exactly what we need. It would be very helpful, if you can give us some early code to try out.
Thank you very much
Yi


Here is a rough (un committed) version of a basic StaticFlowManager class for you, you'll need to add in the code to load the flows you want to push out statically to switches at start time.

package net.beaconcontroller.core.internal;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.beaconcontroller.core.IBeaconProvider;
import net.beaconcontroller.core.IOFSwitch;
import net.beaconcontroller.core.IOFSwitchListener;

import org.openflow.protocol.OFFlowMod;
import org.openflow.protocol.OFMatch;
import org.openflow.protocol.OFMessage;
import org.openflow.protocol.action.OFAction;
import org.openflow.protocol.action.OFActionEnqueue;
import org.openflow.protocol.action.OFActionOutput;
import org.openflow.util.HexString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author David Erickson (daviderickson@cs.stanford.edu)
 */
public class StaticFlowManager implements IOFSwitchListener {
    protected static Logger log = LoggerFactory.getLogger(StaticFlowManager.class);

    protected IBeaconProvider beaconProvider;
    protected Map<Long, List<OFFlowMod>> switchToFlowsMap;

    public StaticFlowManager() {
        switchToFlowsMap = new HashMap<Long, List<OFFlowMod>>();
    }

    public void startUp() {
        generateFlows();
        beaconProvider.addOFSwitchListener(this);
    }

    public void shutDown() {
        beaconProvider.removeOFSwitchListener(this);
    }

    @Override
    public void addedSwitch(IOFSwitch sw) {
        List<OFFlowMod> flowMods = switchToFlowsMap.get(sw.getId());
        if (flowMods != null) {
        List<OFMessage> messages = new ArrayList<OFMessage>(flowMods);
            try {
                sw.getOutputStream().write(messages);
            } catch (IOException e) {
                log.error(
                        "Failure writing static flows to switch "
                                + HexString.toHexString(sw.getId()), e);
            }
        }
    }

    @Override
    public void removedSwitch(IOFSwitch sw) {
    }

    @Override
    public String getName() {
        return "staticflowmanager";
    }

    protected void generateFlows() {
      // Load and create your flows here, calling addFlow(..) for each
    }

    protected void addFlow(Long switchId, OFFlowMod flowMod) {
        log.trace("Switch {} Flow {}", HexString.toHexString(switchId), flowMod);
        List<OFFlowMod> flows = switchToFlowsMap.get(switchId);
        if (flows == null) {
            flows = new ArrayList<OFFlowMod>();
            switchToFlowsMap.put(switchId, flows);
        }
        flows.add(flowMod);
    }

    /**
     * @param beaconProvider the beaconProvider to set
     */
    public void setBeaconProvider(IBeaconProvider beaconProvider) {
        this.beaconProvider = beaconProvider;
    }
}


Also I put this inside the core package and then added the following to META-INF/spring/context.xml to load it:

<bean id="staticFlowManager" class="net.beaconcontroller.core.internal.StaticFlowManager"
    init-method="startUp" destroy-method="shutDown">
<property name="beaconProvider" ref="controller"/>
</bean>


My declarative routing engine is actually very intertwined with other library code I'm using so sharing at this point would be hard, but in a nut shell this is what I did. Created a new class that extended AllPairsShortestPathRoutingEngineImpl, for this example I'll refer to this new class as XRoutingEngineImpl. Inside XRoutingEngineImpl just override the getRoute method, then within that method determine if the route request is one that you want to service with a pre-declared route using the match or switch ids, and if so return your pre-declared route, otherwise delegate to the APSP engine via super.getRoute(...). Then depending on where you put this class, if you put it in the routing.apsp bundle you'll need to edit the META-INF/spring/context.xml file and change the class for the routingEngine bean to the new class. The instructions would vary if you put it elsewhere.

Hope that helps!

-David
0

#5 User is offline   beyounn 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 21-October 11

Posted 26 October 2011 - 09:25 PM

Thanks David,

I'm trying to integrate your code with Web UI. But somehow I can not make my staticrouting menu entry to show up in the Web page.
What I did is to create a new project called net.beaconcontroller.staticrouting. In the project, I have StaticRouting class that basically have your code with a packetin implementation. I also added an interface called IStaticRouting to interface with the webui code. The implementation for the interface is in put into a file called StaticRoutingImpl.java and it will call addFlow method to add new routing records so that we can query it later when either a packetin happen or a new switch is added. So the basic code without WebUI worked. And I can see the flow_mode command on my switch with the right content.

Then I created another new project called net.beaconcontroller.staticrouting.web with a class called StaticRoutingWeb. It is basically a copy of the DeviceManagerWebManageAble.java with name changes (And the overview method is empty). I also created following files in my porject's WEB-INF/sping/servlet

springmvc-staticrouting-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

  <context:component-scan base-package="net.beaconcontroller.staticrouting.web"/>
</beans>



springmvc-staticrouting-osgi.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:osgi="http://www.springframework.org/schema/osgi"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-2.0-m1.xsd">

  <!-- import -->
  <osgi:reference id="staticrouting" cardinality="1..1"
    interface="net.beaconcontroller.staticrouting.IStaticRouting">
  </osgi:reference>
</beans>


I created new debug configure with both new projects enabled. I did not see any error message on the console, but the WebUI did not change either. Is there a way to debug this?
Thanks
Yi
0

#6 User is offline   beyounn 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 21-October 11

Posted 26 October 2011 - 11:16 PM

Ok, found the answer, you have mentioned this in your UI doc

When creating a web bundle or a fragment attaching to one it is critical that the Output folder is set to WEB-INF/classes as this is where Servlet containers look for classes



Yi
0

#7 User is offline   David Erickson 

  • Developer
  • Group: Administrators
  • Posts: 653
  • Joined: 28-June 11

Posted 27 October 2011 - 08:04 AM

View Postbeyounn, on 26 October 2011 - 11:16 PM, said:

Ok, found the answer, you have mentioned this in your UI doc

When creating a web bundle or a fragment attaching to one it is critical that the Output folder is set to WEB-INF/classes as this is where Servlet containers look for classes



Yi


Great! Glad you got it working.
1

#8 User is offline   Fidel Rosell 

  • Member
  • PipPip
  • Group: Members
  • Posts: 11
  • Joined: 05-February 14
  • LocationMiami

Posted 09 December 2014 - 06:34 PM

Hi David. I am getting lost trying to configure Static Flows in a Fat tree topology. Do you think that you could help me on this one. I meant like you did on LearningSwitchTutorial, where I can follow some steps in order to accomplish the creation of the static flows. Thank you David and I am sorry if I ask too much but I have been learning Java.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users