import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager;
import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
+import org.opendaylight.ovsdb.openstack.netvirt.providers.mdsalopenflow13.OF13MdSalInstruction;
+import org.opendaylight.ovsdb.openstack.netvirt.providers.mdsalopenflow13.OF13MdSalMatch;
import org.opendaylight.ovsdb.plugin.api.StatusWithUuid;
import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
import org.opendaylight.ovsdb.schema.openvswitch.Interface;
import org.opendaylight.ovsdb.schema.openvswitch.Port;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtl;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import com.google.common.base.Preconditions;
private static final short TABLE_0_DEFAULT_INGRESS = 0;
private static final short TABLE_1_ISOLATE_TENANT = 10;
private static final short TABLE_2_LOCAL_FORWARD = 20;
+ private static final String OPENFLOW = "openflow:";
private static Long groupId = 1L;
private volatile org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService configurationService;
for (Node dstNode : nodes) {
InetAddress src = configurationService.getTunnelEndPoint(srcNode);
InetAddress dst = configurationService.getTunnelEndPoint(dstNode);
- logger.info("Remove tunnel rules for interface " + intf.getName() + " on srcNode" + srcNode.getNodeIDString());
+ logger.info("Remove tunnel rules for interface " + intf.getName() + " on srcNode " + srcNode.getNodeIDString());
this.removeTunnelRules(tunnelType, network.getProviderSegmentationID(),
dst, srcNode, intf, true, isLastInstanceOnNode);
- logger.info("Remove tunnel rules for interface " + intf.getName() + " on dstNode" + dstNode.getNodeIDString());
+ logger.info("Remove tunnel rules for interface " + intf.getName() + " on dstNode " + dstNode.getNodeIDString());
this.removeTunnelRules(tunnelType, network.getProviderSegmentationID(),
src, dstNode, intf, false, isLastInstanceOnNode);
}
private void writeLLDPRule(Long dpidLong) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
EtherType etherType = new EtherType(0x88CCL);
MatchBuilder matchBuilder = new MatchBuilder();
FlowBuilder flowBuilder = new FlowBuilder();
// Create Match(es) and Set them in the FlowBuilder Object
- flowBuilder.setMatch(createEtherTypeMatch(matchBuilder, etherType).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createEtherTypeMatch(matchBuilder, etherType).build());
// Create the OF Actions and Instructions
InstructionBuilder ib = new InstructionBuilder();
List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
- createSendToControllerInstructions(ib);
+ OF13MdSalInstruction.createSendToControllerInstructions(ib);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
private void writeNormalRule(Long dpidLong) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
- createNormalInstructions(ib);
+ OF13MdSalInstruction.createNormalInstructions(ib);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
Short goToTableId, String segmentationId,
Long ofPort, boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
BigInteger tunnelId = new BigInteger(segmentationId);
MatchBuilder matchBuilder = new MatchBuilder();
FlowBuilder flowBuilder = new FlowBuilder();
// Create Match(es) and Set them in the FlowBuilder Object
- flowBuilder.setMatch(createTunnelIDMatch(matchBuilder, tunnelId).build());
- flowBuilder.setMatch(createInPortMatch(matchBuilder, dpidLong, ofPort).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createTunnelIDMatch(matchBuilder, tunnelId).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createInPortMatch(matchBuilder, dpidLong, ofPort).build());
if (write) {
// Create the OF Actions and Instructions
List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
- createGotoTableInstructions(ib, goToTableId);
+ OF13MdSalInstruction.createGotoTableInstructions(ib, goToTableId);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
private void handleVlanIn(Long dpidLong, Short writeTable, Short goToTableId,
String segmentationId, Long ethPort, boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
FlowBuilder flowBuilder = new FlowBuilder();
// Create Match(es) and Set them in the FlowBuilder Object
- flowBuilder.setMatch(createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
- flowBuilder.setMatch(createInPortMatch(matchBuilder, dpidLong, ethPort).build());
+ flowBuilder.setMatch(
+ OF13MdSalMatch.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId)))
+ .build())
+ .setMatch(OF13MdSalMatch.createInPortMatch(matchBuilder, dpidLong, ethPort)
+ .build());
if (write) {
// Create the OF Actions and Instructions
List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
- createGotoTableInstructions(ib, goToTableId);
+ OF13MdSalInstruction.createGotoTableInstructions(ib, goToTableId);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
String segmentationId, Long inPort, String attachedMac,
boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
FlowBuilder flowBuilder = new FlowBuilder();
// Create the OF Match using MatchBuilder
- flowBuilder.setMatch(createEthSrcMatch(matchBuilder, new MacAddress(attachedMac)).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createEthSrcMatch(matchBuilder, new MacAddress(attachedMac)).build());
// TODO Broken In_Port Match
- flowBuilder.setMatch(createInPortMatch(matchBuilder, dpidLong, inPort).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createInPortMatch(matchBuilder, dpidLong, inPort).build());
String flowId = "LocalMac_"+segmentationId+"_"+inPort+"_"+attachedMac;
// Add Flow Attributes
// Instructions List Stores Individual Instructions
List<Instruction> instructions = Lists.newArrayList();
- // GOTO Instuctions Need to be added first to the List
- createGotoTableInstructions(ib, goToTableId);
+ // GOTO Instructions Need to be added first to the List
+ OF13MdSalInstruction.createGotoTableInstructions(ib, goToTableId);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
// TODO Broken SetTunID
- createSetTunnelIdInstructions(ib, new BigInteger(segmentationId));
+ OF13MdSalInstruction.createSetTunnelIdInstructions(ib, new BigInteger(segmentationId));
ib.setOrder(1);
ib.setKey(new InstructionKey(1));
instructions.add(ib.build());
Long inPort, String attachedMac,
boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
FlowBuilder flowBuilder = new FlowBuilder();
// Create the OF Match using MatchBuilder
- flowBuilder.setMatch(createEthSrcMatch(matchBuilder, new MacAddress(attachedMac)).build());
- // TODO Broken In_Port Match
- flowBuilder.setMatch(createInPortMatch(matchBuilder, dpidLong, inPort).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createEthSrcMatch(matchBuilder, new MacAddress(attachedMac)).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createInPortMatch(matchBuilder, dpidLong, inPort).build());
String flowId = "LocalMac_"+segmentationId+"_"+inPort+"_"+attachedMac;
// Add Flow Attributes
List<Instruction> instructions = Lists.newArrayList();
// GOTO Instructions Need to be added first to the List
- createGotoTableInstructions(ib, goToTableId);
+ OF13MdSalInstruction.createGotoTableInstructions(ib, goToTableId);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
// Set VLAN ID Instruction
- createSetVlanInstructions(ib, new VlanId(Integer.valueOf(segmentationId)));
+ OF13MdSalInstruction.createSetVlanInstructions(ib, new VlanId(Integer.valueOf(segmentationId)));
ib.setOrder(1);
ib.setKey(new InstructionKey(1));
instructions.add(ib.build());
private void handleDropSrcIface(Long dpidLong, Long inPort, boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
FlowBuilder flowBuilder = new FlowBuilder();
// Create the OF Match using MatchBuilder
- flowBuilder.setMatch(createInPortMatch(matchBuilder, dpidLong, inPort).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createInPortMatch(matchBuilder, dpidLong, inPort).build());
if (write) {
// Instantiate the Builders for the OF Actions and Instructions
List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
- createDropInstructions(ib);
+ OF13MdSalInstruction.createDropInstructions(ib);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
FlowKey key = new FlowKey(new FlowId(flowId));
flowBuilder.setStrict(true);
flowBuilder.setBarrier(false);
- flowBuilder.setTableId((short) 0);
+ flowBuilder.setTableId(TABLE_0_DEFAULT_INGRESS);
flowBuilder.setKey(key);
flowBuilder.setFlowName(flowId);
flowBuilder.setPriority(8192);
Long OFPortOut, String attachedMac,
boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
FlowBuilder flowBuilder = new FlowBuilder();
// Create the OF Match using MatchBuilder
- flowBuilder.setMatch(createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
- flowBuilder.setMatch(createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
String flowId = "TunnelOut_"+segmentationId+"_"+OFPortOut+"_"+attachedMac;
// Add Flow Attributes
// Instructions List Stores Individual Instructions
List<Instruction> instructions = Lists.newArrayList();
- // GOTO Instuctions
- createGotoTableInstructions(ib, goToTableId);
+ // GOTO Instructions
+ OF13MdSalInstruction.createGotoTableInstructions(ib, goToTableId);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
// Set the Output Port/Iface
- createOutputPortInstructions(ib, dpidLong, OFPortOut);
+ OF13MdSalInstruction.createOutputPortInstructions(ib, dpidLong, OFPortOut);
ib.setOrder(1);
ib.setKey(new InstructionKey(1));
instructions.add(ib.build());
Short goToTableId, String segmentationId,
Long ethPort, String attachedMac, boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
FlowBuilder flowBuilder = new FlowBuilder();
// Create the OF Match using MatchBuilder
- flowBuilder.setMatch(createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
- flowBuilder.setMatch(createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
+ flowBuilder.setMatch(
+ OF13MdSalMatch.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
String flowId = "VlanOut_"+segmentationId+"_"+ethPort+"_"+attachedMac;
// Add Flow Attributes
// Instructions List Stores Individual Instructions
List<Instruction> instructions = Lists.newArrayList();
- // GOTO Instuctions
- createGotoTableInstructions(ib, goToTableId);
+ // GOTO Instructions
+ OF13MdSalInstruction.createGotoTableInstructions(ib, goToTableId);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
Short localTable, String segmentationId,
Long OFPortOut, boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
// Create the OF Match using MatchBuilder
// Match TunnelID
- flowBuilder.setMatch(createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
// Match DMAC
- flowBuilder.setMatch(createDestEthMatch(matchBuilder, new MacAddress("01:00:00:00:00:00"), new MacAddress("01:00:00:00:00:00")).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createDestEthMatch(matchBuilder, new MacAddress("01:00:00:00:00:00"),
+ new MacAddress("01:00:00:00:00:00")).build());
String flowId = "TunnelFloodOut_"+segmentationId;
// Add Flow Attributes
if (write) {
// GOTO Instruction
- createGotoTableInstructions(ib, localTable);
+ OF13MdSalInstruction.createGotoTableInstructions(ib, localTable);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
writeFlow(flowBuilder, nodeBuilder);
} else {
/* remove port from action list */
- boolean flowRemove = removeOutputPortFromInstructions(ib, dpidLong,
- OFPortOut, existingInstructions);
+ boolean flowRemove = OF13MdSalInstruction.removeOutputPortFromInstructions(ib, dpidLong,
+ OFPortOut, existingInstructions);
if (flowRemove) {
/* if all port are removed, remove the flow too. */
removeFlow(flowBuilder, nodeBuilder);
Short localTable, String segmentationId,
Long ethPort, boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
// Create the OF Match using MatchBuilder
// Match Vlan ID
- flowBuilder.setMatch(createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
+ flowBuilder.setMatch(
+ OF13MdSalMatch.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
// Match DMAC
- flowBuilder.setMatch(createDestEthMatch(matchBuilder, new MacAddress("01:00:00:00:00:00"), new MacAddress("01:00:00:00:00:00")).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createDestEthMatch(matchBuilder, new MacAddress("01:00:00:00:00:00"),
+ new MacAddress("01:00:00:00:00:00")).build());
String flowId = "VlanFloodOut_"+segmentationId;
// Add Flow Attributes
List<Instruction> instructions = Lists.newArrayList();
if (write) {
- // GOTO Instuction
- createGotoTableInstructions(ib, localTable);
+ // GOTO Instruction
+ OF13MdSalInstruction.createGotoTableInstructions(ib, localTable);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
// Set the Output Port/Iface
- createOutputPortInstructions(ib, dpidLong, ethPort);
+ OF13MdSalInstruction.createOutputPortInstructions(ib, dpidLong, ethPort);
ib.setOrder(1);
ib.setKey(new InstructionKey(1));
instructions.add(ib.build());
Short goToTableId, String segmentationId,
boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
FlowBuilder flowBuilder = new FlowBuilder();
// Create Match(es) and Set them in the FlowBuilder Object
- flowBuilder.setMatch(createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
if (write) {
// Create the OF Actions and Instructions
List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
- createGotoTableInstructions(ib, goToTableId);
+ OF13MdSalInstruction.createGotoTableInstructions(ib, goToTableId);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
Short goToTableId, String segmentationId,
Long ethPort, boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
FlowBuilder flowBuilder = new FlowBuilder();
// Create Match(es) and Set them in the FlowBuilder Object
- flowBuilder.setMatch(createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
+ flowBuilder.setMatch(
+ OF13MdSalMatch.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
if (write) {
// Create the OF Actions and Instructions
//ib.setKey(new InstructionKey(0));
//instructions.add(ib.build());
// Set the Output Port/Iface
- createOutputPortInstructions(ib, dpidLong, ethPort);
+ OF13MdSalInstruction.createOutputPortInstructions(ib, dpidLong, ethPort);
ib.setOrder(0);
ib.setKey(new InstructionKey(1));
instructions.add(ib.build());
String segmentationId, Long localPort,
String attachedMac, boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
FlowBuilder flowBuilder = new FlowBuilder();
// Create the OF Match using MatchBuilder
- flowBuilder.setMatch(createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
- flowBuilder.setMatch(createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
String flowId = "UcastOut_"+segmentationId+"_"+localPort+"_"+attachedMac;
// Add Flow Attributes
List<Instruction> instructions = Lists.newArrayList();
// Set the Output Port/Iface
- createOutputPortInstructions(ib, dpidLong, localPort);
+ OF13MdSalInstruction.createOutputPortInstructions(ib, dpidLong, localPort);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
String segmentationId, Long localPort,
String attachedMac, boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
FlowBuilder flowBuilder = new FlowBuilder();
// Create the OF Match using MatchBuilder
- flowBuilder.setMatch(createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
- flowBuilder.setMatch(createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
+ flowBuilder.setMatch(
+ OF13MdSalMatch.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
String flowId = "VlanUcastOut_"+segmentationId+"_"+localPort+"_"+attachedMac;
// Add Flow Attributes
List<Instruction> instructions_tmp = Lists.newArrayList();
/* Strip vlan and store to tmp instruction space*/
- createPopVlanInstructions(ib);
+ OF13MdSalInstruction.createPopVlanInstructions(ib);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions_tmp.add(ib.build());
// Set the Output Port/Iface
ib = new InstructionBuilder();
- addOutputPortInstructions(ib, dpidLong, localPort, instructions_tmp);
+ OF13MdSalInstruction.addOutputPortInstructions(ib, dpidLong, localPort, instructions_tmp);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
String segmentationId, Long localPort,
boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
FlowBuilder flowBuilder = new FlowBuilder();
// Create the OF Match using MatchBuilder
- flowBuilder.setMatch(createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
- flowBuilder.setMatch(createDestEthMatch(matchBuilder, new MacAddress("01:00:00:00:00:00"), new MacAddress("01:00:00:00:00:00")).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createDestEthMatch(matchBuilder, new MacAddress("01:00:00:00:00:00"),
+ new MacAddress("01:00:00:00:00:00")).build());
String flowId = "BcastOut_"+segmentationId;
// Add Flow Attributes
writeFlow(flowBuilder, nodeBuilder);
} else {
- boolean flowRemove = removeOutputPortFromInstructions(ib, dpidLong, localPort,
- existingInstructions);
+ boolean flowRemove = OF13MdSalInstruction.removeOutputPortFromInstructions(ib, dpidLong, localPort,
+ existingInstructions);
if (flowRemove) {
/* if all ports are removed, remove flow */
removeFlow(flowBuilder, nodeBuilder);
String segmentationId, Long localPort,
boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
FlowBuilder flowBuilder = new FlowBuilder();
// Create the OF Match using MatchBuilder
- flowBuilder.setMatch(createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
- flowBuilder.setMatch(createDestEthMatch(matchBuilder, new MacAddress("01:00:00:00:00:00"), new MacAddress("01:00:00:00:00:00")).build());
+ flowBuilder.setMatch(
+ OF13MdSalMatch.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createDestEthMatch(matchBuilder, new MacAddress("01:00:00:00:00:00"),
+ new MacAddress("01:00:00:00:00:00")).build());
String flowId = "VlanBcastOut_"+segmentationId;
// Add Flow Attributes
if (add_pop_vlan) {
/* pop vlan */
- createPopVlanInstructions(ib);
+ OF13MdSalInstruction.createPopVlanInstructions(ib);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
existingInstructions.add(ib.build());
} else {
//boolean flowRemove = removeOutputPortFromGroup(nodeBuilder, ib, dpidLong,
// localPort, existingInstructions);
- boolean flowRemove = removeOutputPortFromInstructions(ib, dpidLong,
- localPort, existingInstructions);
+ boolean flowRemove = OF13MdSalInstruction.removeOutputPortFromInstructions(ib, dpidLong,
+ localPort, existingInstructions);
if (flowRemove) {
/* if all ports are removed, remove flow */
removeFlow(flowBuilder, nodeBuilder);
private void handleLocalTableMiss(Long dpidLong, Short writeTable,
String segmentationId, boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
FlowBuilder flowBuilder = new FlowBuilder();
// Create Match(es) and Set them in the FlowBuilder Object
- flowBuilder.setMatch(createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
+ flowBuilder.setMatch(OF13MdSalMatch.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
if (write) {
// Create the OF Actions and Instructions
List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
- createDropInstructions(ib);
+ OF13MdSalInstruction.createDropInstructions(ib);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
private void handleLocalVlanTableMiss(Long dpidLong, Short writeTable,
String segmentationId, boolean write) {
- String nodeName = "openflow:" + dpidLong;
+ String nodeName = OPENFLOW + dpidLong;
MatchBuilder matchBuilder = new MatchBuilder();
NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
FlowBuilder flowBuilder = new FlowBuilder();
// Create Match(es) and Set them in the FlowBuilder Object
- flowBuilder.setMatch(createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
+ flowBuilder.setMatch(
+ OF13MdSalMatch.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
if (write) {
// Create the OF Actions and Instructions
List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
- createDropInstructions(ib);
+ OF13MdSalInstruction.createDropInstructions(ib);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
}
}
- /**
- * Create Ingress Port Match dpidLong, inPort
- *
- * @param matchBuilder Map matchBuilder MatchBuilder Object without a match
- * @param dpidLong Long the datapath ID of a switch/node
- * @param inPort Long ingress port on a switch
- * @return matchBuilder Map MatchBuilder Object with a match
- */
- protected static MatchBuilder createInPortMatch(MatchBuilder matchBuilder, Long dpidLong, Long inPort) {
-
- NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + inPort);
- logger.debug("createInPortMatch() Node Connector ID is - Type=openflow: DPID={} inPort={} ", dpidLong, inPort);
- matchBuilder.setInPort(NodeConnectorId.getDefaultInstance(ncid.getValue()));
- matchBuilder.setInPort(ncid);
-
- return matchBuilder;
- }
-
- /**
- * Create EtherType Match
- *
- * @param matchBuilder Map matchBuilder MatchBuilder Object without a match
- * @param etherType Long EtherType
- * @return matchBuilder Map MatchBuilder Object with a match
- */
- protected static MatchBuilder createEtherTypeMatch(MatchBuilder matchBuilder, EtherType etherType) {
-
- EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
- EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
- ethTypeBuilder.setType(new EtherType(etherType));
- ethernetMatch.setEthernetType(ethTypeBuilder.build());
- matchBuilder.setEthernetMatch(ethernetMatch.build());
-
- return matchBuilder;
- }
-
- /**
- * Create Ethernet Source Match
- *
- * @param matchBuilder MatchBuilder Object without a match yet
- * @param sMacAddr String representing a source MAC
- * @return matchBuilder Map MatchBuilder Object with a match
- */
- protected static MatchBuilder createEthSrcMatch(MatchBuilder matchBuilder, MacAddress sMacAddr) {
-
- EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
- EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
- ethSourceBuilder.setAddress(new MacAddress(sMacAddr));
- ethernetMatch.setEthernetSource(ethSourceBuilder.build());
- matchBuilder.setEthernetMatch(ethernetMatch.build());
-
- return matchBuilder;
- }
-
- /**
- * Create Ethernet Destination Match
- *
- * @param matchBuilder MatchBuilder Object without a match yet
- * @param vlanId Integer representing a VLAN ID Integer representing a VLAN ID
- * @return matchBuilder Map MatchBuilder Object with a match
- */
-
- protected static MatchBuilder createVlanIdMatch(MatchBuilder matchBuilder, VlanId vlanId) {
- VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
- VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
- vlanIdBuilder.setVlanId(new VlanId(vlanId));
- vlanIdBuilder.setVlanIdPresent(true);
- vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
- matchBuilder.setVlanMatch(vlanMatchBuilder.build());
-
- return matchBuilder;
- }
-
- /**
- * Create Ethernet Destination Match
- *
- * @param matchBuilder MatchBuilder Object without a match yet
- * @param dMacAddr String representing a destination MAC
- * @return matchBuilder Map MatchBuilder Object with a match
- */
-
- protected static MatchBuilder createDestEthMatch(MatchBuilder matchBuilder, MacAddress dMacAddr, MacAddress mask) {
-
- EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
- EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
- ethDestinationBuilder.setAddress(new MacAddress(dMacAddr));
- if (mask != null) {
- ethDestinationBuilder.setMask(mask);
- }
- ethernetMatch.setEthernetDestination(ethDestinationBuilder.build());
- matchBuilder.setEthernetMatch(ethernetMatch.build());
-
- return matchBuilder;
- }
-
- /**
- * Tunnel ID Match Builder
- *
- * @param matchBuilder MatchBuilder Object without a match yet
- * @param tunnelId BigInteger representing a tunnel ID
- * @return matchBuilder Map MatchBuilder Object with a match
- */
- protected static MatchBuilder createTunnelIDMatch(MatchBuilder matchBuilder, BigInteger tunnelId) {
-
- TunnelBuilder tunnelBuilder = new TunnelBuilder();
- tunnelBuilder.setTunnelId(tunnelId);
- matchBuilder.setTunnel(tunnelBuilder.build());
-
- return matchBuilder;
- }
-
- /**
- * Match ICMP code and type
- *
- * @param matchBuilder MatchBuilder Object without a match yet
- * @param type short representing an ICMP type
- * @param code short representing an ICMP code
- * @return matchBuilder Map MatchBuilder Object with a match
- */
- protected static MatchBuilder createICMPv4Match(MatchBuilder matchBuilder, short type, short code) {
-
- EthernetMatchBuilder eth = new EthernetMatchBuilder();
- EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
- ethTypeBuilder.setType(new EtherType(0x0800L));
- eth.setEthernetType(ethTypeBuilder.build());
- matchBuilder.setEthernetMatch(eth.build());
-
- // Build the IPv4 Match requied per OVS Syntax
- IpMatchBuilder ipmatch = new IpMatchBuilder();
- ipmatch.setIpProtocol((short) 1);
- matchBuilder.setIpMatch(ipmatch.build());
-
- // Build the ICMPv4 Match
- Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
- icmpv4match.setIcmpv4Type(type);
- icmpv4match.setIcmpv4Code(code);
- matchBuilder.setIcmpv4Match(icmpv4match.build());
-
- return matchBuilder;
- }
-
- /**
- * @param matchBuilder MatchBuilder Object without a match yet
- * @param dstip String containing an IPv4 prefix
- * @return matchBuilder Map Object with a match
- */
- private static MatchBuilder createDstL3IPv4Match(MatchBuilder matchBuilder, Ipv4Prefix dstip) {
-
- EthernetMatchBuilder eth = new EthernetMatchBuilder();
- EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
- ethTypeBuilder.setType(new EtherType(0x0800L));
- eth.setEthernetType(ethTypeBuilder.build());
- matchBuilder.setEthernetMatch(eth.build());
-
- Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
- ipv4match.setIpv4Destination(dstip);
-
- matchBuilder.setLayer3Match(ipv4match.build());
-
- return matchBuilder;
-
- }
-
- /**
- * @param matchBuilder MatchBuilder Object without a match yet
- * @param srcip String containing an IPv4 prefix
- * @return matchBuilder Map Object with a match
- */
- private static MatchBuilder createSrcL3IPv4Match(MatchBuilder matchBuilder, Ipv4Prefix srcip) {
-
- EthernetMatchBuilder eth = new EthernetMatchBuilder();
- EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
- ethTypeBuilder.setType(new EtherType(0x0800L));
- eth.setEthernetType(ethTypeBuilder.build());
- matchBuilder.setEthernetMatch(eth.build());
-
- Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
- Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
- ipv4match.setIpv4Source(srcip);
- matchBuilder.setLayer3Match(ipv4match.build());
-
- return matchBuilder;
-
- }
-
- /**
- * Create Source TCP Port Match
- *
- * @param matchBuilder @param matchbuilder MatchBuilder Object without a match yet
- * @param tcpport Integer representing a source TCP port
- * @return matchBuilder Map MatchBuilder Object with a match
- */
- protected static MatchBuilder createSetSrcTcpMatch(MatchBuilder matchBuilder, PortNumber tcpport) {
-
- EthernetMatchBuilder ethType = new EthernetMatchBuilder();
- EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
- ethTypeBuilder.setType(new EtherType(0x0800L));
- ethType.setEthernetType(ethTypeBuilder.build());
- matchBuilder.setEthernetMatch(ethType.build());
-
- IpMatchBuilder ipmatch = new IpMatchBuilder();
- ipmatch.setIpProtocol((short) 6);
- matchBuilder.setIpMatch(ipmatch.build());
-
- TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
- tcpmatch.setTcpSourcePort(tcpport);
- matchBuilder.setLayer4Match(tcpmatch.build());
-
- return matchBuilder;
-
- }
-
- /**
- * Create Destination TCP Port Match
- *
- * @param matchBuilder MatchBuilder Object without a match yet
- * @param tcpport Integer representing a destination TCP port
- * @return matchBuilder Map MatchBuilder Object with a match
- */
- protected static MatchBuilder createSetDstTcpMatch(MatchBuilder matchBuilder, PortNumber tcpport) {
-
- EthernetMatchBuilder ethType = new EthernetMatchBuilder();
- EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
- ethTypeBuilder.setType(new EtherType(0x0800L));
- ethType.setEthernetType(ethTypeBuilder.build());
- matchBuilder.setEthernetMatch(ethType.build());
-
- IpMatchBuilder ipmatch = new IpMatchBuilder();
- ipmatch.setIpProtocol((short) 6);
- matchBuilder.setIpMatch(ipmatch.build());
-
- PortNumber dstport = new PortNumber(tcpport);
- TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
-
- tcpmatch.setTcpDestinationPort(tcpport);
- matchBuilder.setLayer4Match(tcpmatch.build());
-
- return matchBuilder;
- }
-
- /**
- * Create Send to Controller Reserved Port Instruction (packet_in)
- *
- * @param ib Map InstructionBuilder without any instructions
- * @return ib Map InstructionBuilder with instructions
- */
-
- protected static InstructionBuilder createSendToControllerInstructions(InstructionBuilder ib) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
-
- OutputActionBuilder output = new OutputActionBuilder();
- output.setMaxLength(0xffff);
- Uri value = new Uri("CONTROLLER");
- output.setOutputNodeConnector(value);
- ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
- ab.setOrder(0);
- ab.setKey(new ActionKey(0));
- actionList.add(ab.build());
-
- // Create an Apply Action
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
-
- // Wrap our Apply Action in an Instruction
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
- /**
- * Create NORMAL Reserved Port Instruction (packet_in)
- *
- * @param ib Map InstructionBuilder without any instructions
- * @return ib Map InstructionBuilder with instructions
- */
-
- protected static InstructionBuilder createNormalInstructions(InstructionBuilder ib) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
-
- OutputActionBuilder output = new OutputActionBuilder();
- Uri value = new Uri("NORMAL");
- output.setOutputNodeConnector(value);
- ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
- ab.setOrder(0);
- ab.setKey(new ActionKey(0));
- actionList.add(ab.build());
-
- // Create an Apply Action
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
-
- // Wrap our Apply Action in an Instruction
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
- /**
- * Create Output Port Instruction
- *
- * @param ib Map InstructionBuilder without any instructions
- * @param dpidLong Long the datapath ID of a switch/node
- * @param port Long representing a port on a switch/node
- * @return ib InstructionBuilder Map with instructions
- */
- protected static InstructionBuilder createOutputPortInstructions(InstructionBuilder ib, Long dpidLong, Long port) {
-
- NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
- logger.debug("createOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} inPort={} ", dpidLong, port);
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
- OutputActionBuilder oab = new OutputActionBuilder();
- oab.setOutputNodeConnector(ncid);
-
- ab.setAction(new OutputActionCaseBuilder().setOutputAction(oab.build()).build());
- ab.setOrder(0);
- ab.setKey(new ActionKey(0));
- actionList.add(ab.build());
-
- // Create an Apply Action
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
/**
* Create Output Port Group Instruction
*
protected InstructionBuilder createOutputPortInstructions(InstructionBuilder ib,
Long dpidLong, Long port ,
List<Instruction> instructions) {
- NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
+ NodeConnectorId ncid = new NodeConnectorId(OPENFLOW + dpidLong + ":" + port);
logger.debug("createOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
List<Action> actionList = Lists.newArrayList();
InstructionBuilder ib,
Long dpidLong, Long port ,
List<Instruction> instructions) {
- NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
+ NodeConnectorId ncid = new NodeConnectorId(OPENFLOW + dpidLong + ":" + port);
logger.debug("createOutputGroupInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
List<Action> actionList = Lists.newArrayList();
groupBuilder.setGroupType(GroupTypes.GroupAll);
groupBuilder.setGroupId(new GroupId(groupId));
groupBuilder.setKey(new GroupKey(new GroupId(groupId)));
- groupBuilder.setGroupName("Output port group" + groupId);
+ groupBuilder.setGroupName("Output port group " + groupId);
groupBuilder.setBarrier(false);
BucketsBuilder bucketBuilder = new BucketsBuilder();
/* Add new group action */
GroupActionBuilder groupActionB = new GroupActionBuilder();
groupActionB.setGroupId(groupId);
- groupActionB.setGroup("Output port group" + groupId);
+ groupActionB.setGroup("Output port group " + groupId);
ab = new ActionBuilder();
ab.setAction(new GroupActionCaseBuilder().setGroupAction(groupActionB.build()).build());
ab.setOrder(actionList.size());
return ib;
}
- /**
- * add Output Port action to Instruction action list.
- * This is use for flow with single output port actions.
- * Flow with mutiple output port actions should use createOutputPortInstructions() method.
- *
- * @param ib Map InstructionBuilder without any instructions
- * @param dpidLong Long the datapath ID of a switch/node
- * @param port Long representing a port on a switch/node
- * @return ib InstructionBuilder Map with instructions
- */
- protected static InstructionBuilder addOutputPortInstructions(InstructionBuilder ib,
- Long dpidLong, Long port ,
- List<Instruction> instructions) {
- NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
- logger.debug("addOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
-
- List<Action> existingActions;
- if (instructions != null) {
- for (Instruction in : instructions) {
- if (in.getInstruction() instanceof ApplyActionsCase) {
- existingActions = (((ApplyActionsCase) in.getInstruction()).getApplyActions().getAction());
- actionList.addAll(existingActions);
- }
- }
- }
-
- /* Create output action for this port*/
- OutputActionBuilder oab = new OutputActionBuilder();
- oab.setOutputNodeConnector(ncid);
- ab.setAction(new OutputActionCaseBuilder().setOutputAction(oab.build()).build());
- ab.setOrder(actionList.size());
- ab.setKey(new ActionKey(actionList.size()));
- actionList.add(ab.build());
-
- // Create an Apply Action
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
/**
* Remove Output Port from action list in group bucket
*
protected boolean removeOutputPortFromGroup(NodeBuilder nodeBuilder, InstructionBuilder ib,
Long dpidLong, Long port , List<Instruction> instructions) {
- NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
+ NodeConnectorId ncid = new NodeConnectorId(OPENFLOW + dpidLong + ":" + port);
logger.debug("removeOutputPortFromGroup() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
List<Action> actionList = Lists.newArrayList();
}
}
- /**
- * Remove Output Port from Instruction
- *
- * @param ib Map InstructionBuilder without any instructions
- * @param dpidLong Long the datapath ID of a switch/node
- * @param port Long representing a port on a switch/node
- * @return ib InstructionBuilder Map with instructions
- */
- protected static boolean removeOutputPortFromInstructions(InstructionBuilder ib,
- Long dpidLong, Long port , List<Instruction> instructions) {
-
- NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
- logger.debug("removeOutputPortFromInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab;
-
- List<Action> existingActions;
- if (instructions != null) {
- for (Instruction in : instructions) {
- if (in.getInstruction() instanceof ApplyActionsCase) {
- existingActions = (((ApplyActionsCase) in.getInstruction()).getApplyActions().getAction());
- actionList.addAll(existingActions);
- break;
- }
- }
- }
-
- int index = 0;
- boolean isPortDeleted = false;
- boolean removeFlow = true;
- for (Action action : actionList) {
- if (action.getAction() instanceof OutputActionCase) {
- OutputActionCase opAction = (OutputActionCase)action.getAction();
- if (opAction.getOutputAction().getOutputNodeConnector().equals(new Uri(ncid))) {
- /* Find the output port in action list and remove */
- index = actionList.indexOf(action);
- actionList.remove(action);
- isPortDeleted = true;
- break;
- }
- removeFlow = false;
- }
- }
-
- if (isPortDeleted) {
- for (int i = index; i< actionList.size(); i++) {
- Action action = actionList.get(i);
- if (action.getOrder() != i) {
- /* Shift the action order */
- ab = new ActionBuilder();
- ab.setAction(action.getAction());
- ab.setOrder(i);
- ab.setKey(new ActionKey(i));
- Action actionNewOrder = ab.build();
- actionList.remove(action);
- actionList.add(i, actionNewOrder);
- }
- if (action.getAction() instanceof OutputActionCase) {
- removeFlow = false;
- }
- }
- }
-
- /* Put new action list in Apply Action instruction */
- if (!removeFlow) {
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
- logger.debug("removeOutputPortFromInstructions() : applyAction {}", aab.build());
- return false;
- } else {
- /* if all output port are removed. Return true to indicate flow remove */
- return true;
- }
- }
-
- /**
- * Create Set Vlan ID Instruction - This includes push vlan action, and set field -> vlan vid action
- *
- * @param ib Map InstructionBuilder without any instructions
- * @param vlanId Integer representing a VLAN ID Integer representing a VLAN ID
- * @return ib Map InstructionBuilder with instructions
- */
- protected static InstructionBuilder createSetVlanInstructions(InstructionBuilder ib, VlanId vlanId) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
-
- /* First we push vlan header */
- PushVlanActionBuilder vlan = new PushVlanActionBuilder();
- vlan.setEthernetType(new Integer(0x8100));
- ab.setAction(new PushVlanActionCaseBuilder().setPushVlanAction(vlan.build()).build());
- ab.setOrder(0);
- actionList.add(ab.build());
-
- /* Then we set vlan id value as vlanId */
- SetVlanIdActionBuilder vl = new SetVlanIdActionBuilder();
- vl.setVlanId(vlanId);
- ab = new ActionBuilder();
- ab.setAction(new SetVlanIdActionCaseBuilder().setSetVlanIdAction(vl.build()).build());
- ab.setOrder(1);
- actionList.add(ab.build());
- // Create an Apply Action
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
-
- // Wrap our Apply Action in an Instruction
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
- /**
- * Create Pop Vlan Instruction - this remove vlan header
- *
- * @param ib Map InstructionBuilder without any instructions
- * @return ib Map InstructionBuilder with instructions
- */
- protected static InstructionBuilder createPopVlanInstructions(InstructionBuilder ib) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
-
- PopVlanActionBuilder popVlanActionBuilder = new PopVlanActionBuilder();
- ab.setAction(new PopVlanActionCaseBuilder().setPopVlanAction(popVlanActionBuilder.build()).build());
- ab.setOrder(0);
- actionList.add(ab.build());
-
- // Create an Apply Action
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
-
- // Wrap our Apply Action in an Instruction
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
- /**
- * Create Set IPv4 Source Instruction
- *
- * @param ib Map InstructionBuilder without any instructions
- * @param prefixsrc String containing an IPv4 prefix
- * @return ib Map InstructionBuilder with instructions
- */
- protected static InstructionBuilder createNwSrcInstructions(InstructionBuilder ib, Ipv4Prefix prefixsrc) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
-
- SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
- Ipv4Builder ipsrc = new Ipv4Builder();
- ipsrc.setIpv4Address(prefixsrc);
- setNwsrcActionBuilder.setAddress(ipsrc.build());
- ab.setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
- actionList.add(ab.build());
-
- // Create an Apply Action
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
-
- // Wrap our Apply Action in an Instruction
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
- /**
- * Create Set IPv4 Destination Instruction
- *
- * @param ib Map InstructionBuilder without any instructions
- * @param prefixdst String containing an IPv4 prefix
- * @return ib Map InstructionBuilder with instructions
- */
- protected static InstructionBuilder createNwDstInstructions(InstructionBuilder ib, Ipv4Prefix prefixdst) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
-
- SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
- Ipv4Builder ipdst = new Ipv4Builder();
- ipdst.setIpv4Address(prefixdst);
- setNwDstActionBuilder.setAddress(ipdst.build());
- ab.setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build());
- actionList.add(ab.build());
-
- // Create an Apply Action
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
-
- // Wrap our Apply Action in an Instruction
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
- /**
- * Create Drop Instruction
- *
- * @param ib Map InstructionBuilder without any instructions
- * @return ib Map InstructionBuilder with instructions
- */
- protected static InstructionBuilder createDropInstructions(InstructionBuilder ib) {
-
- DropActionBuilder dab = new DropActionBuilder();
- DropAction dropAction = dab.build();
- ActionBuilder ab = new ActionBuilder();
- ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
- ab.setOrder(0);
-
- // Add our drop action to a list
- List<Action> actionList = Lists.newArrayList();
- actionList.add(ab.build());
-
- // Create an Apply Action
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
-
- // Wrap our Apply Action in an Instruction
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
- /**
- * Create GOTO Table Instruction Builder
- *
- * @param ib Map InstructionBuilder without any instructions
- * @param tableId short representing a flow table ID short representing a flow table ID
- * @return ib Map InstructionBuilder with instructions
- */
- protected static InstructionBuilder createGotoTableInstructions(InstructionBuilder ib, short tableId) {
-
- GoToTableBuilder gttb = new GoToTableBuilder();
- gttb.setTableId(tableId);
-
- // Wrap our Apply Action in an InstructionBuilder
- ib.setInstruction(new GoToTableCaseBuilder().setGoToTable(gttb.build()).build());
-
- return ib;
- }
-
- /**
- * Create Set Tunnel ID Instruction Builder
- *
- * @param ib Map InstructionBuilder without any instructions
- * @param tunnelId BigInteger representing a tunnel ID
- * @return ib Map InstructionBuilder with instructions
- */
- protected static InstructionBuilder createSetTunnelIdInstructions(InstructionBuilder ib, BigInteger tunnelId) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
- SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
-
- // Build the Set Tunnel Field Action
- TunnelBuilder tunnel = new TunnelBuilder();
- tunnel.setTunnelId(tunnelId);
- setFieldBuilder.setTunnel(tunnel.build());
- ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
- ab.setOrder(0);
- actionList.add(ab.build());
-
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
-
- // Wrap the Apply Action in an InstructionBuilder and return
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
- /**
- * Create Set Source TCP Port Instruction
- *
- * @param ib Map InstructionBuilder without any instructions
- * @param tcpport Integer representing a source TCP port
- * @return ib Map InstructionBuilder with instructions
- */
- protected static InstructionBuilder createSetSrcTCPPort(InstructionBuilder ib, PortNumber tcpport) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
- SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
-
- // Build the Destination TCP Port
- PortNumber tcpsrcport = new PortNumber(tcpport);
- TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
- tcpmatch.setTcpSourcePort(tcpsrcport);
-
- setFieldBuilder.setLayer4Match(tcpmatch.build());
- ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
- ab.setKey(new ActionKey(1));
- actionList.add(ab.build());
-
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
- /**
- * Create Set Destination TCP Port Instruction
- *
- * @param ib Map InstructionBuilder without any instructions
- * @param tcpport Integer representing a source TCP port
- * @return ib Map InstructionBuilder with instructions
- */
- protected static InstructionBuilder createSetDstTCPPort(InstructionBuilder ib, PortNumber tcpport) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
- SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
-
- // Build the Destination TCP Port
- PortNumber tcpdstport = new PortNumber(tcpport);
- TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
- tcpmatch.setTcpDestinationPort(tcpdstport);
-
- setFieldBuilder.setLayer4Match(tcpmatch.build());
- ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
- ab.setKey(new ActionKey(1));
- actionList.add(ab.build());
-
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
- /**
- * Create Set Source UDP Port Instruction
- *
- * @param ib Map InstructionBuilder without any instructions
- * @param udpport Integer representing a source UDP port
- * @return ib Map InstructionBuilder with instructions
- */
- protected static InstructionBuilder createSetSrcUDPPort(InstructionBuilder ib, PortNumber udpport) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
- SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
-
- // Build the Destination TCP Port
- PortNumber udpsrcport = new PortNumber(udpport);
- UdpMatchBuilder udpmatch = new UdpMatchBuilder();
- udpmatch.setUdpSourcePort(udpsrcport);
-
- setFieldBuilder.setLayer4Match(udpmatch.build());
- ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
- ab.setKey(new ActionKey(1));
- actionList.add(ab.build());
-
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
- /**
- * Create Set Destination UDP Port Instruction
- *
- * @param ib Map InstructionBuilder without any instructions
- * @param udpport Integer representing a destination UDP port
- * @return ib Map InstructionBuilder with instructions
- */
- protected static InstructionBuilder createSetDstUDPPort(InstructionBuilder ib, PortNumber udpport) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
- SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
-
- // Build the Destination TCP Port
- PortNumber udpdstport = new PortNumber(udpport);
- UdpMatchBuilder udpmatch = new UdpMatchBuilder();
- udpmatch.setUdpDestinationPort(udpdstport);
-
- setFieldBuilder.setLayer4Match(udpmatch.build());
- ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
- ab.setKey(new ActionKey(1));
- actionList.add(ab.build());
-
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
- /**
- * Create Set ICMP Code Instruction
- *
- * @param ib Map InstructionBuilder without any instructions
- * @param code short repesenting an ICMP code
- * @return ib Map InstructionBuilder with instructions
- */
-
- private static InstructionBuilder createSetIcmpCodeInstruction(InstructionBuilder ib, short code) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
- SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
- Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
-
- // Build the ICMPv4 Code Match
- icmpv4match.setIcmpv4Code(code);
- setFieldBuilder.setIcmpv4Match(icmpv4match.build());
-
- ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
- ab.setKey(new ActionKey(0));
- actionList.add(ab.build());
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
-
- // Wrap our Apply Action in an Instruction
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
- /**
- * Create Set ICMP Code Instruction
- *
- * @param ib Map InstructionBuilder without any instructions
- * @return ib Map InstructionBuilder with instructions
- */
- private static InstructionBuilder createSetIcmpTypeInstruction(InstructionBuilder ib, short type) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
- SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
- Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
-
- // Build the ICMPv4 Code Match
- icmpv4match.setIcmpv4Code(type);
- setFieldBuilder.setIcmpv4Match(icmpv4match.build());
-
- ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
- ab.setKey(new ActionKey(1));
- actionList.add(ab.build());
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
-
- // Wrap our Apply Action in an Instruction
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
- /**
- * Create Decrement TTL Instruction
- *
- * @param ib Map InstructionBuilder without any instructions
- * @return ib Map InstructionBuilder with instructions
- */
- private static InstructionBuilder createDecNwTtlInstructions(InstructionBuilder ib) {
- DecNwTtlBuilder decNwTtlBuilder = new DecNwTtlBuilder();
- DecNwTtl decNwTtl = decNwTtlBuilder.build();
- ActionBuilder ab = new ActionBuilder();
- ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
-
- // Add our drop action to a list
- List<Action> actionList = Lists.newArrayList();
- actionList.add(ab.build());
-
- // Create an Apply Action
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
-
- // Wrap our Apply Action in an Instruction
- ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-
- return ib;
- }
-
- /**
- * Set Src Arp MAC
- */
- private static InstructionBuilder createSrcArpMacInstructions(InstructionBuilder ib, MacAddress macsrc) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
-
- SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
- ArpMatchBuilder arpmatch = new ArpMatchBuilder();
- ArpSourceHardwareAddressBuilder arpsrc = new ArpSourceHardwareAddressBuilder();
- arpsrc.setAddress(macsrc);
- arpmatch.setArpSourceHardwareAddress(arpsrc.build());
- setFieldBuilder.setLayer3Match(arpmatch.build());
- ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
- ab.setKey(new ActionKey(0));
- actionList.add(ab.build());
-
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
-
- return ib;
- }
-
- /**
- * Set Dst Arp MAC
- */
- private static InstructionBuilder createDstArpMacInstructions(InstructionBuilder ib, MacAddress macdst) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
- SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
-
- ArpMatchBuilder arpmatch = new ArpMatchBuilder();
- ArpTargetHardwareAddressBuilder arpdst = new ArpTargetHardwareAddressBuilder();
- arpdst.setAddress(macdst);
- setFieldBuilder.setLayer3Match(arpmatch.build());
- ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
- ab.setKey(new ActionKey(0));
- actionList.add(ab.build());
-
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
-
- return ib;
- }
-
- /**
- * Set Dst Arp IP
- */
- private static InstructionBuilder createDstArpIpInstructions(InstructionBuilder ib, Ipv4Prefix dstiparp) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
- SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
-
- ArpMatchBuilder arpmatch = new ArpMatchBuilder();
- arpmatch.setArpTargetTransportAddress(dstiparp);
- setFieldBuilder.setLayer3Match(arpmatch.build());
- ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
- ab.setKey(new ActionKey(0));
- actionList.add(ab.build());
-
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
-
- return ib;
- }
-
- /**
- * Set Src Arp IP
- */
- private static InstructionBuilder createSrcArpIpInstructions(InstructionBuilder ib, Ipv4Prefix srciparp) {
-
- List<Action> actionList = Lists.newArrayList();
- ActionBuilder ab = new ActionBuilder();
- SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
-
- ArpMatchBuilder arpmatch = new ArpMatchBuilder();
- arpmatch.setArpSourceTransportAddress(srciparp);
- setFieldBuilder.setLayer3Match(arpmatch.build());
- ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
- ab.setKey(new ActionKey(0));
- actionList.add(ab.build());
-
- ApplyActionsBuilder aab = new ApplyActionsBuilder();
- aab.setAction(actionList);
-
- return ib;
- }
-
@Override
public void initializeOFFlowRules(Node openflowNode) {
Preconditions.checkNotNull(connectionService);
--- /dev/null
+/*
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ */
+
+package org.opendaylight.ovsdb.openstack.netvirt.providers.mdsalopenflow13;
+
+import com.google.common.collect.Lists;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
+public class OF13MdSalInstruction {
+ private static final Logger logger = LoggerFactory.getLogger(OF13MdSalInstruction.class);
+ private static final int IPV4 = 0x8100;
+ private static final int MAX_LENGTH = 0xffff;
+
+ /**
+ * Create Send to Controller Reserved Port Instruction (packet_in)
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @return ib Map InstructionBuilder with instructions
+ */
+ public static InstructionBuilder createSendToControllerInstructions(InstructionBuilder ib) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+
+ OutputActionBuilder output = new OutputActionBuilder();
+ output.setMaxLength(MAX_LENGTH);
+ Uri value = new Uri("CONTROLLER");
+ output.setOutputNodeConnector(value);
+ ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
+ ab.setOrder(0);
+ ab.setKey(new ActionKey(0));
+ actionList.add(ab.build());
+
+ // Create an Apply Action
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ // Wrap our Apply Action in an Instruction
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Create NORMAL Reserved Port Instruction (packet_in)
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @return ib Map InstructionBuilder with instructions
+ */
+
+ public static InstructionBuilder createNormalInstructions(InstructionBuilder ib) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+
+ OutputActionBuilder output = new OutputActionBuilder();
+ Uri value = new Uri("NORMAL");
+ output.setOutputNodeConnector(value);
+ ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
+ ab.setOrder(0);
+ ab.setKey(new ActionKey(0));
+ actionList.add(ab.build());
+
+ // Create an Apply Action
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ // Wrap our Apply Action in an Instruction
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Create Output Port Instruction
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param dpidLong Long the datapath ID of a switch/node
+ * @param port Long representing a port on a switch/node
+ * @return ib InstructionBuilder Map with instructions
+ */
+ public static InstructionBuilder createOutputPortInstructions(InstructionBuilder ib, Long dpidLong, Long port) {
+
+ NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
+ logger.debug("createOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} inPort={} ",
+ dpidLong, port);
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+ OutputActionBuilder oab = new OutputActionBuilder();
+ oab.setOutputNodeConnector(ncid);
+
+ ab.setAction(new OutputActionCaseBuilder().setOutputAction(oab.build()).build());
+ ab.setOrder(0);
+ ab.setKey(new ActionKey(0));
+ actionList.add(ab.build());
+
+ // Create an Apply Action
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * add Output Port action to Instruction action list.
+ * This is use for flow with single output port actions.
+ * Flow with mutiple output port actions should use createOutputPortInstructions() method.
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param dpidLong Long the datapath ID of a switch/node
+ * @param port Long representing a port on a switch/node
+ * @return ib InstructionBuilder Map with instructions
+ */
+ public static InstructionBuilder addOutputPortInstructions(InstructionBuilder ib,
+ Long dpidLong, Long port,
+ List<Instruction> instructions) {
+ NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
+ logger.debug(
+ "addOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}",
+ dpidLong, port, instructions);
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+
+ List<Action> existingActions;
+ if (instructions != null) {
+ for (Instruction in : instructions) {
+ if (in.getInstruction() instanceof ApplyActionsCase) {
+ existingActions = (((ApplyActionsCase) in.getInstruction()).getApplyActions().getAction());
+ actionList.addAll(existingActions);
+ }
+ }
+ }
+
+ /* Create output action for this port*/
+ OutputActionBuilder oab = new OutputActionBuilder();
+ oab.setOutputNodeConnector(ncid);
+ ab.setAction(new OutputActionCaseBuilder().setOutputAction(oab.build()).build());
+ ab.setOrder(actionList.size());
+ ab.setKey(new ActionKey(actionList.size()));
+ actionList.add(ab.build());
+
+ // Create an Apply Action
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Remove Output Port from Instruction
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param dpidLong Long the datapath ID of a switch/node
+ * @param port Long representing a port on a switch/node
+ * @return ib InstructionBuilder Map with instructions
+ */
+ public static boolean removeOutputPortFromInstructions(InstructionBuilder ib,
+ Long dpidLong, Long port, List<Instruction> instructions) {
+
+ NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
+ logger.debug(
+ "removeOutputPortFromInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}",
+ dpidLong, port, instructions);
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab;
+
+ List<Action> existingActions;
+ if (instructions != null) {
+ for (Instruction in : instructions) {
+ if (in.getInstruction() instanceof ApplyActionsCase) {
+ existingActions = (((ApplyActionsCase) in.getInstruction()).getApplyActions().getAction());
+ actionList.addAll(existingActions);
+ break;
+ }
+ }
+ }
+
+ int index = 0;
+ boolean isPortDeleted = false;
+ boolean removeFlow = true;
+ for (Action action : actionList) {
+ if (action.getAction() instanceof OutputActionCase) {
+ OutputActionCase opAction = (OutputActionCase) action.getAction();
+ if (opAction.getOutputAction().getOutputNodeConnector().equals(new Uri(ncid))) {
+ /* Find the output port in action list and remove */
+ index = actionList.indexOf(action);
+ actionList.remove(action);
+ isPortDeleted = true;
+ break;
+ }
+ removeFlow = false;
+ }
+ }
+
+ if (isPortDeleted) {
+ for (int i = index; i < actionList.size(); i++) {
+ Action action = actionList.get(i);
+ if (action.getOrder() != i) {
+ /* Shift the action order */
+ ab = new ActionBuilder();
+ ab.setAction(action.getAction());
+ ab.setOrder(i);
+ ab.setKey(new ActionKey(i));
+ Action actionNewOrder = ab.build();
+ actionList.remove(action);
+ actionList.add(i, actionNewOrder);
+ }
+ if (action.getAction() instanceof OutputActionCase) {
+ removeFlow = false;
+ }
+ }
+ }
+
+ /* Put new action list in Apply Action instruction */
+ if (!removeFlow) {
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+ logger.debug("removeOutputPortFromInstructions() : applyAction {}", aab.build());
+ return false;
+ } else {
+ /* if all output port are removed. Return true to indicate flow remove */
+ return true;
+ }
+ }
+
+ /**
+ * Create Set Vlan ID Instruction - This includes push vlan action, and set field -> vlan vid action
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param vlanId Integer representing a VLAN ID Integer representing a VLAN ID
+ * @return ib Map InstructionBuilder with instructions
+ */
+ public static InstructionBuilder createSetVlanInstructions(InstructionBuilder ib, VlanId vlanId) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+
+ /* First we push vlan header */
+ PushVlanActionBuilder vlan = new PushVlanActionBuilder();
+ vlan.setEthernetType(IPV4);
+ ab.setAction(new PushVlanActionCaseBuilder().setPushVlanAction(vlan.build()).build());
+ ab.setOrder(0);
+ actionList.add(ab.build());
+
+ /* Then we set vlan id value as vlanId */
+ SetVlanIdActionBuilder vl = new SetVlanIdActionBuilder();
+ vl.setVlanId(vlanId);
+ ab = new ActionBuilder();
+ ab.setAction(new SetVlanIdActionCaseBuilder().setSetVlanIdAction(vl.build()).build());
+ ab.setOrder(1);
+ actionList.add(ab.build());
+ // Create an Apply Action
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ // Wrap our Apply Action in an Instruction
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Create Pop Vlan Instruction - this remove vlan header
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @return ib Map InstructionBuilder with instructions
+ */
+ public static InstructionBuilder createPopVlanInstructions(InstructionBuilder ib) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+
+ PopVlanActionBuilder popVlanActionBuilder = new PopVlanActionBuilder();
+ ab.setAction(new PopVlanActionCaseBuilder().setPopVlanAction(popVlanActionBuilder.build()).build());
+ ab.setOrder(0);
+ actionList.add(ab.build());
+
+ // Create an Apply Action
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ // Wrap our Apply Action in an Instruction
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Create Set IPv4 Source Instruction
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param prefixsrc String containing an IPv4 prefix
+ * @return ib Map InstructionBuilder with instructions
+ */
+ public static InstructionBuilder createNwSrcInstructions(InstructionBuilder ib, Ipv4Prefix prefixsrc) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+
+ SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
+ Ipv4Builder ipsrc = new Ipv4Builder();
+ ipsrc.setIpv4Address(prefixsrc);
+ setNwsrcActionBuilder.setAddress(ipsrc.build());
+ ab.setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
+ actionList.add(ab.build());
+
+ // Create an Apply Action
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ // Wrap our Apply Action in an Instruction
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Create Set IPv4 Destination Instruction
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param prefixdst String containing an IPv4 prefix
+ * @return ib Map InstructionBuilder with instructions
+ */
+ public static InstructionBuilder createNwDstInstructions(InstructionBuilder ib, Ipv4Prefix prefixdst) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+
+ SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
+ Ipv4Builder ipdst = new Ipv4Builder();
+ ipdst.setIpv4Address(prefixdst);
+ setNwDstActionBuilder.setAddress(ipdst.build());
+ ab.setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build());
+ actionList.add(ab.build());
+
+ // Create an Apply Action
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ // Wrap our Apply Action in an Instruction
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Create Drop Instruction
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @return ib Map InstructionBuilder with instructions
+ */
+ public static InstructionBuilder createDropInstructions(InstructionBuilder ib) {
+
+ DropActionBuilder dab = new DropActionBuilder();
+ DropAction dropAction = dab.build();
+ ActionBuilder ab = new ActionBuilder();
+ ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
+ ab.setOrder(0);
+
+ // Add our drop action to a list
+ List<Action> actionList = Lists.newArrayList();
+ actionList.add(ab.build());
+
+ // Create an Apply Action
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ // Wrap our Apply Action in an Instruction
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Create GOTO Table Instruction Builder
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param tableId short representing a flow table ID short representing a flow table ID
+ * @return ib Map InstructionBuilder with instructions
+ */
+ public static InstructionBuilder createGotoTableInstructions(InstructionBuilder ib, short tableId) {
+
+ GoToTableBuilder gttb = new GoToTableBuilder();
+ gttb.setTableId(tableId);
+
+ // Wrap our Apply Action in an InstructionBuilder
+ ib.setInstruction(new GoToTableCaseBuilder().setGoToTable(gttb.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Create Set Tunnel ID Instruction Builder
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param tunnelId BigInteger representing a tunnel ID
+ * @return ib Map InstructionBuilder with instructions
+ */
+ public static InstructionBuilder createSetTunnelIdInstructions(InstructionBuilder ib, BigInteger tunnelId) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+ SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
+
+ // Build the Set Tunnel Field Action
+ TunnelBuilder tunnel = new TunnelBuilder();
+ tunnel.setTunnelId(tunnelId);
+ setFieldBuilder.setTunnel(tunnel.build());
+ ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
+ ab.setOrder(0);
+ actionList.add(ab.build());
+
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ // Wrap the Apply Action in an InstructionBuilder and return
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Create Set Source TCP Port Instruction
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param tcpport Integer representing a source TCP port
+ * @return ib Map InstructionBuilder with instructions
+ */
+ public static InstructionBuilder createSetSrcTCPPort(InstructionBuilder ib, PortNumber tcpport) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+ SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
+
+ // Build the Destination TCP Port
+ PortNumber tcpsrcport = new PortNumber(tcpport);
+ TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
+ tcpmatch.setTcpSourcePort(tcpsrcport);
+
+ setFieldBuilder.setLayer4Match(tcpmatch.build());
+ ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
+ ab.setKey(new ActionKey(1));
+ actionList.add(ab.build());
+
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Create Set Destination TCP Port Instruction
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param tcpport Integer representing a source TCP port
+ * @return ib Map InstructionBuilder with instructions
+ */
+ public static InstructionBuilder createSetDstTCPPort(InstructionBuilder ib, PortNumber tcpport) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+ SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
+
+ // Build the Destination TCP Port
+ PortNumber tcpdstport = new PortNumber(tcpport);
+ TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
+ tcpmatch.setTcpDestinationPort(tcpdstport);
+
+ setFieldBuilder.setLayer4Match(tcpmatch.build());
+ ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
+ ab.setKey(new ActionKey(1));
+ actionList.add(ab.build());
+
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Create Set Source UDP Port Instruction
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param udpport Integer representing a source UDP port
+ * @return ib Map InstructionBuilder with instructions
+ */
+ public static InstructionBuilder createSetSrcUDPPort(InstructionBuilder ib, PortNumber udpport) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+ SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
+
+ // Build the Destination TCP Port
+ PortNumber udpsrcport = new PortNumber(udpport);
+ UdpMatchBuilder udpmatch = new UdpMatchBuilder();
+ udpmatch.setUdpSourcePort(udpsrcport);
+
+ setFieldBuilder.setLayer4Match(udpmatch.build());
+ ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
+ ab.setKey(new ActionKey(1));
+ actionList.add(ab.build());
+
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Create Set Destination UDP Port Instruction
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param udpport Integer representing a destination UDP port
+ * @return ib Map InstructionBuilder with instructions
+ */
+ public static InstructionBuilder createSetDstUDPPort(InstructionBuilder ib, PortNumber udpport) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+ SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
+
+ // Build the Destination TCP Port
+ PortNumber udpdstport = new PortNumber(udpport);
+ UdpMatchBuilder udpmatch = new UdpMatchBuilder();
+ udpmatch.setUdpDestinationPort(udpdstport);
+
+ setFieldBuilder.setLayer4Match(udpmatch.build());
+ ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
+ ab.setKey(new ActionKey(1));
+ actionList.add(ab.build());
+
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Create Set ICMP Code Instruction
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param code short repesenting an ICMP code
+ * @return ib Map InstructionBuilder with instructions
+ */
+
+ public static InstructionBuilder createSetIcmpCodeInstruction(InstructionBuilder ib, short code) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+ SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
+ Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
+
+ // Build the ICMPv4 Code Match
+ icmpv4match.setIcmpv4Code(code);
+ setFieldBuilder.setIcmpv4Match(icmpv4match.build());
+
+ ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
+ ab.setKey(new ActionKey(0));
+ actionList.add(ab.build());
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ // Wrap our Apply Action in an Instruction
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Create Set ICMP Code Instruction
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @return ib Map InstructionBuilder with instructions
+ */
+ public static InstructionBuilder createSetIcmpTypeInstruction(InstructionBuilder ib, short type) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+ SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
+ Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
+
+ // Build the ICMPv4 Code Match
+ icmpv4match.setIcmpv4Code(type);
+ setFieldBuilder.setIcmpv4Match(icmpv4match.build());
+
+ ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
+ ab.setKey(new ActionKey(1));
+ actionList.add(ab.build());
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ // Wrap our Apply Action in an Instruction
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Create Decrement TTL Instruction
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @return ib Map InstructionBuilder with instructions
+ */
+ public static InstructionBuilder createDecNwTtlInstructions(InstructionBuilder ib) {
+ DecNwTtlBuilder decNwTtlBuilder = new DecNwTtlBuilder();
+ DecNwTtl decNwTtl = decNwTtlBuilder.build();
+ ActionBuilder ab = new ActionBuilder();
+ ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
+
+ // Add our drop action to a list
+ List<Action> actionList = Lists.newArrayList();
+ actionList.add(ab.build());
+
+ // Create an Apply Action
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ // Wrap our Apply Action in an Instruction
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+ return ib;
+ }
+
+ /**
+ * Set ARP_SHA Instructions
+ * @param ib Map InstructionBuilder
+ * @param macsrc the macsrc
+ * @return instructionbuilder with new instructions
+ */
+ public static InstructionBuilder createSrcArpMacInstructions(InstructionBuilder ib, MacAddress macsrc) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+
+ SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
+ ArpMatchBuilder arpmatch = new ArpMatchBuilder();
+ ArpSourceHardwareAddressBuilder arpsrc = new ArpSourceHardwareAddressBuilder();
+ arpsrc.setAddress(macsrc);
+ arpmatch.setArpSourceHardwareAddress(arpsrc.build());
+ setFieldBuilder.setLayer3Match(arpmatch.build());
+ ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
+ ab.setKey(new ActionKey(0));
+ actionList.add(ab.build());
+
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ return ib;
+ }
+
+ /**
+ * Set ARP_THA Instructions
+ * @param ib Map InstructionBuilder
+ * @param macdst the macdst
+ * @return instructionbuilder with new attributes
+ */
+ public static InstructionBuilder createDstArpMacInstructions(InstructionBuilder ib, MacAddress macdst) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+ SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
+
+ ArpMatchBuilder arpmatch = new ArpMatchBuilder();
+ ArpTargetHardwareAddressBuilder arpdst = new ArpTargetHardwareAddressBuilder();
+ arpdst.setAddress(macdst);
+ setFieldBuilder.setLayer3Match(arpmatch.build());
+ ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
+ ab.setKey(new ActionKey(0));
+ actionList.add(ab.build());
+
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ return ib;
+ }
+
+ /**
+ * Set ARP_TPA Instructions
+ * @param ib Map InstructionBuilder
+ * @param dstiparp the dstiparp
+ * @return instructionbuilder with new attributes
+ */
+ public static InstructionBuilder createDstArpIpInstructions(InstructionBuilder ib, Ipv4Prefix dstiparp) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+ SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
+
+ ArpMatchBuilder arpmatch = new ArpMatchBuilder();
+ arpmatch.setArpTargetTransportAddress(dstiparp);
+ setFieldBuilder.setLayer3Match(arpmatch.build());
+ ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
+ ab.setKey(new ActionKey(0));
+ actionList.add(ab.build());
+
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ return ib;
+ }
+
+ /**
+ * Set ARP_SPA Instructions
+ * @param ib Map InstructionBuilder
+ * @param srciparp the srciparp
+ * @return instructionbuilder with new attributes
+ */
+ public static InstructionBuilder createSrcArpIpInstructions(InstructionBuilder ib, Ipv4Prefix srciparp) {
+
+ List<Action> actionList = Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+ SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
+
+ ArpMatchBuilder arpmatch = new ArpMatchBuilder();
+ arpmatch.setArpSourceTransportAddress(srciparp);
+ setFieldBuilder.setLayer3Match(arpmatch.build());
+ ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
+ ab.setKey(new ActionKey(0));
+ actionList.add(ab.build());
+
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ return ib;
+ }
+
+ public static InstructionBuilder createTunnelIpv4SrcInstructions(InstructionBuilder ib, Ipv4Prefix srcIp) {
+
+ List<Action> actionList = new ArrayList<Action>();
+ ActionBuilder ab = new ActionBuilder();
+
+ // Build the tunnel endpoint source IPv4 address
+ SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
+
+ // Add the new IPv4 object as the tunnel destination
+ TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = new TunnelIpv4MatchBuilder();
+ tunnelIpv4MatchBuilder.setTunnelIpv4Source(srcIp);
+ setFieldBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
+
+ // Add the IPv4 tunnel src to the set_field value
+ ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
+ ab.setOrder(0);
+ ab.setKey(new ActionKey(0));
+ actionList.add(ab.build());
+
+ // Resulting action is a per/flow src TEP (set_field:172.16.100.100->tun_src)
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ return ib;
+ }
+
+ public static InstructionBuilder createTunnelIpv4DstInstructions(InstructionBuilder ib, Ipv4Prefix srcIp) {
+
+ List<Action> actionList = new ArrayList<Action>();
+ ActionBuilder ab = new ActionBuilder();
+
+ // Build the tunnel endpoint dst IPv4 address
+ SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
+
+ // Add the new IPv4 object as the tunnel destination
+ TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = new TunnelIpv4MatchBuilder();
+ tunnelIpv4MatchBuilder.setTunnelIpv4Destination(srcIp);
+ setFieldBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
+
+ // Add the IPv4 tunnel src to the set_field value
+ ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
+ ab.setOrder(0);
+ ab.setKey(new ActionKey(0));
+ actionList.add(ab.build());
+
+ // Resulting action is a per/flow src TEP (set_field:172.16.100.100->tun_src)
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ return ib;
+ }
+}
\ No newline at end of file