Skip to content

OpenFlow Java library API Cookbook

Dmitry-Orekhov edited this page Aug 26, 2013 · 23 revisions

OpenFlow Java library API Cookbook

(work in progress)

Launch a controller

The controller infrastructure is started the next way:

import org.flowforwarding.of.controller.Controller;
/*................*/
Controller.launch (SessionHandler.class); // This launches a controller listening tcp port 6633
Controller.launch (SessionHandler.class, configuration); // This launches a controller listening given tcp port 

Configuration

It's a POJO containing some configuration information as tcp port number etc.

import org.flowforwarding.of.controller.Configuration
/*................*/
Configuration config1 = new Configuration();     // tcp port 6633 by default
Configuration config2 = new Configuration(6633);

Session handlers

You have to implement your session handler to interact with Controller. You may manage of incoming messages handling or send messages you want. Session handlers extend the class OFSessionHandler:

import org.flowforwarding.of.controller.SwitchState.SwitchRef;
import org.flowforwarding.of.controller.session.OFSessionHandler;

public class SimpleHandler extends OFSessionHandler {

   /*
    * User-defined Switch event handlers
    */
   @Override
   protected void handshaked(SwitchRef swRef) {
      super.handshaked(swRef);
      /*You have to implement your own logic here*/
   }

/*.................................................*/   
   @Override
   protected void connected(SwitchRef swRef) {
      super.connected(swRef);
      /*You have to implement your own logic here*/
   }

/*.................................................*/   
   @Override
   protected void packetIn(SwitchRef swRef) {
      super.connected(swRef);
      /*You have to implement your own logic here*/
   }
}

Clone this wiki locally