Software Defined Networking
1754270 Members
2931 Online
108813 Solutions
New Discussion

Creating a Java FlowMod for 1.3 DataPath

 
RGBD
Occasional Advisor

Creating a Java FlowMod for 1.3 DataPath

If I have an OF 1.0 action that looks something like this:

 

Action action = ActionFactory.createAction( ProtocolVersion.V_1_0, ActionType.OUTPUT, Port.NORMAL  );

 

I have tried to create an Instruction for 1.3 but only get this far:

 

Instruction instruction = Instruction.createInstruction(ProtocolVersion.V_1_3, ...

 

I've lost my way in JavaDocs.

 

Could someone provide and example of an OF 1.3 FlowMod or point me in the correct direction?

 

 

5 REPLIES 5
sdnindia
Trusted Contributor

Re: Creating a Java FlowMod for 1.3 DataPath

Hello RGBD,

 

The following listing shows an example of how to create a flowmod message:

Flowmod Message Example:

 

public class SampleFlowModMessageCreation {

private static final ProtocolVersion PV = ProtocolVersion.V_1_3;

private static final long COOKIE = 0x00002468;

private static final TableId TABLE_ID = TableId.valueOf(200);

 

private static final int FLOW_IDLE_TIMEOUT = 300;

private static final int FLOW_HARD_TIMEOUT = 600;

private static final int FLOW_PRIORITY = 50;

private static final BufferId BUFFER_ID = BufferId.NO_BUFFER;

private static final Set<FlowModFlag> FLAGS = EnumSet.of(FlowModFlag.SEND_FLOW_REM, FlowModFlag.CHECK_OVERLAP, FlowModFlag.NO_BYTE_COUNTS);

private static final MacAddress MAC =MacAddress.valueOf("00001e:000000");

private static final MacAddress MAC_MASK =MacAddress.valueOf("ffffff:000000");

private static final PortNumber SMTP_PORT = PortNumber.valueOf(25);

private static final MacAddress MAC_DEST = MacAddress.BROADCAST;

private static final IpAddress IP_DEST = IpAddress.LOOPBACK_IPv4;

private OfmFlowMod sampleFlowModCreation() {

// Create a 1.3 FlowMod ADD message...

OfmMutableFlowMod fm = (OfmMutableFlowMod) MessageFactory.create(PV, MessageType.FLOW_MOD, FlowModCommand.ADD);

// NOTE: outPort = ANY and outGroup = ANY by default so we don’t have

// to explicitly set them.

fm.cookie(COOKIE).tableId(TABLE_ID).priority(FLOW_PRIORITY).idleTimeout(FLOW_IDLE_TIMEOUT).hardTimeout(FLOW_HARD_TIMEOUT).bufferId(BUFFER_ID).flowModFlags(FLAGS).match(createMatch());

for (Instruction ins: createInstructions())

fm.addInstruction(ins);

return (OfmFlowMod) fm.toImmutable();

}

private Match

createMatch() {

// NOTE static imports of:

//

com.hp.of.lib.match.FieldFactory.createBasicField;

//

com.hp.of.lib.match.OxmBasicFieldType.*;

MutableMatch mm = MatchFactory.createMatch(PV).addField(createBasicField(PV, ETH_SRC, MAC, MAC_MASK)).addField(createBasicField(PV, ETH_TYPE, EthernetType.IPv4)).addField(createBasicField(PV, IP_PROTO, IpProtocol.TCP)).addField(createBasicField(PV, TCP_DST, SMTP_PORT));

return (Match) mm.toImmutable();

}

private static final long INS_META_MASK = 0xffff0000;

private static final long INS_META_DATA = 0x33ab0000;

private List<Instruction> createInstructions() {

// NOTE static imports of:

// com.hp.of.lib.instr.ActionFactory.createAction;

// com.hp.of.lib.instr.ActionFactory.createActionSetField;

// com.hp.of.lib.instr.InstructionFactory.createInstruction;

//

com.hp.of.lib.instr.InstructionFactory.createMutableInstruction;

List<Instruction> result = new ArrayList<Instruction>();

result.add(createInstruction(PV, InstructionType.WRITE_METADATA,INS_META_DATA, INS_META_MASK));

InstrMutableAction apply = createMutableInstruction(PV,InstructionType.APPLY_ACTIONS);

apply.addAction(createAction(PV, ActionType.DEC_NW_TTL)).addAction(createActionSetField(PV, ETH_DST, MAC_DEST)).addAction(createActionSetField(PV, IPV4_DST, IP_DEST));

result.add((Instruction) apply.toImmutable());

return result;

}

}

 

 

This is an example for  FlowMOD  message  in the SDN Programming guide. [page 27-29]

Please follow the example and let us know if you still face the issue.

 

Thanks,

HP SDN Team

sdnindia
Trusted Contributor

Re: Creating a Java FlowMod for 1.3 DataPath

Hi RGBD,

 

Doing a follow up to see if previous post helps you.

Please let us know if your problem is solved or you still have some problem.

 

Thanks,

HP SDN Team

Dast
Occasional Advisor

Re: Creating a Java FlowMod for 1.3 DataPath

Hi everyone! 

 

How do I send the FlowMod message? 

I tried it with the ControllerService.sendFlowMod method

 

MessageFuture sendFlowMod(OfmFlowMod flowMod,
                        DataPathId dpid)
                          throws OpenflowException

but I always get the follogwing error:

 

ERROR of-io-29-thread-6  hp.of.ctl   Unable to perform I/O java.lang.NoSuchMethodError: com.hp.of.ctl.ControllerService.sendFlowMod(Lcom/hp/of/lib/msg/OfmFlowMod;Lcom/hp/of/lib/dt/DataPathId;)Lcom/hp/of/lib/msg/MessageFuture;

 

The necessary jars are referenced in the projects pom.xml and the ControllerService seems to be bound as I can add a PacketListener. 


Does anybody have an idea where the problem is?

sdnindia
Trusted Contributor

Re: Creating a Java FlowMod for 1.3 DataPath

Hello Dast,

 

Below are the steps to send the FlowMod message-

 

 

// Construct OfmMutableFlowMod 

OfmMutableFlowMod mod = (OfmMutableFlowMod) MessageFactory .create(pv, MessageType.FLOW_MOD);

 

// Assemble the match fields

 

// Add the values to flow mod

 

//Convert to Immutable

OfmFlowMod flow = (OfmFlowMod)mod.toImmutable();

 

 

//Call the method

cs.sendFlowMod(flow, dpInfo.dpid());     // Here dpInfo is of type DataPathInfo and cs is of type ControllerService

 

Please let us know if this helps .

 

Thanks,

HP SDN Team

Yuanxiance
Occasional Contributor

Re: Creating a Java FlowMod for 1.3 DataPath

i have a problem. copy your above code, sdn-apidoc.2.0.0 API web page tell us the function "sendFlowMod" should have return "MessageFuture" type! But my code return null!!!!!!! what's the problem? please help me quickly,thks!!!