codego123
codego123

Reputation: 301

Modify action in OpenFlow Controller

I am trying to build a simple topology in Mininet with a load balancer. I am using a switch in place of the Load Balancer. I need to modify the destination IP to one of the server's IPs in order to perform the job of a load balancer.

I am unable to modify the incoming to do the same. Can anyone please help me with the same? Or is there a better way to do this?

Thanks in advance!

Upvotes: 0

Views: 263

Answers (1)

Icaro Camelo
Icaro Camelo

Reputation: 382

You need to write an Openflow message containing a match and the desired action. A match will be useful to "detect" those packets that need to have the destination IP modified. The action must be a SET_FIELD action. Here is a simple example about how to do it using OpenDaylight controller (this case modify destination MAC Address):

public static Action createSetFieldDestinationMacAddress(int order, String macAddress) {

        Action action;
        ActionBuilder ab = new ActionBuilder();

        MacAddress address = MacAddress.getDefaultInstance(macAddress);
        EthernetDestination destination = new EthernetDestinationBuilder().setAddress(address).build();

        EthernetMatchBuilder builder = new EthernetMatchBuilder();
        builder.setEthernetDestination(destination);

        EthernetMatch ethernetMatch = builder.build();
        SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
        setFieldBuilder.setEthernetMatch(ethernetMatch);
        SetField setField = setFieldBuilder.build();
        org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action acction = new SetFieldCaseBuilder().
                setSetField(setField).build();
        ab.setOrder(order).setKey(new ActionKey(order)).setAction(acction);
        action = ab.build();
        return action;
    }

Upvotes: 0

Related Questions