import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
import org.opendaylight.ovsdb.utils.mdsal.openflow.ActionUtils;
+import org.opendaylight.ovsdb.utils.mdsal.openflow.FlowUtils;
import org.opendaylight.ovsdb.utils.mdsal.openflow.InstructionUtils;
import org.opendaylight.ovsdb.utils.mdsal.openflow.MatchUtils;
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.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.flow.inventory.rev130819.FlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
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;
* table=0,in_port=2,dl_src=00:00:00:00:00:01 \
* actions=set_field:5->tun_id,goto_table=<next-table>"
*/
-
@Override
- public void programLocalInPort(Long dpidLong, String segmentationId, Long inPort, String attachedMac, boolean write) {
- String nodeName = OPENFLOW + dpidLong;
-
- MatchBuilder matchBuilder = new MatchBuilder();
- NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+ public void programLocalInPort(Long dpidLong, String segmentationId, Long inPort, String attachedMac,
+ boolean write) {
+ NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
FlowBuilder flowBuilder = new FlowBuilder();
+ String flowName = "LocalMac_" + segmentationId + "_" + inPort + "_" + attachedMac;
+ FlowUtils.initFlowBuilder(flowBuilder, flowName, getTable());
- // Create the OF Match using MatchBuilder
- flowBuilder.setMatch(MatchUtils.createEthSrcMatch(matchBuilder, new MacAddress(attachedMac)).build());
- // TODO Broken In_Port Match
- flowBuilder.setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, inPort).build());
-
- String flowId = "LocalMac_"+segmentationId+"_"+inPort+"_"+attachedMac;
- // Add Flow Attributes
- flowBuilder.setId(new FlowId(flowId));
- FlowKey key = new FlowKey(new FlowId(flowId));
- flowBuilder.setStrict(true);
- flowBuilder.setBarrier(false);
- flowBuilder.setTableId(getTable());
- flowBuilder.setKey(key);
- flowBuilder.setFlowName(flowId);
- flowBuilder.setHardTimeout(0);
- flowBuilder.setIdleTimeout(0);
+ MatchBuilder matchBuilder = new MatchBuilder();
+ MatchUtils.createEthSrcMatch(matchBuilder, new MacAddress(attachedMac));
+ MatchUtils.createInPortMatch(matchBuilder, dpidLong, inPort);
+ flowBuilder.setMatch(matchBuilder.build());
if (write) {
// Instantiate the Builders for the OF Actions and Instructions
// Instructions List Stores Individual Instructions
List<Instruction> instructions = Lists.newArrayList();
- // TODO Broken SetTunID
InstructionUtils.createSetTunnelIdInstructions(ib, new BigInteger(segmentationId));
ApplyActionsCase aac = (ApplyActionsCase) ib.getInstruction();
List<Action> actionList = aac.getApplyActions().getAction();
* actions=push_vlan, set_field:5->vlan_id,goto_table=<Next-Table>"
* table=0,in_port=1,vlan_tci=0x0000/0x1fff,dl_src=fa:16:3e:70:2f:c2 actions=push_vlan:0x8100,set_field:6097->vlan_vid,goto_table:20
*/
-
@Override
- public void programLocalInPortSetVlan(Long dpidLong, String segmentationId, Long inPort, String attachedMac, boolean write) {
-
- String nodeName = OPENFLOW + dpidLong;
-
- MatchBuilder matchBuilder = new MatchBuilder();
- NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+ public void programLocalInPortSetVlan(Long dpidLong, String segmentationId, Long inPort, String attachedMac,
+ boolean write) {
+ NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
FlowBuilder flowBuilder = new FlowBuilder();
+ String flowName = "LocalMac_" + segmentationId + "_" + inPort + "_" + attachedMac;
+ FlowUtils.initFlowBuilder(flowBuilder, flowName, getTable());
- // Create the OF Match using MatchBuilder
- flowBuilder.setMatch(MatchUtils.createEthSrcMatch(matchBuilder, new MacAddress(attachedMac)).build());
- flowBuilder.setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, inPort).build());
- /* openflowplugin requires a vlan match to add a vlan */
- flowBuilder.setMatch(MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(0), false).build());
-
- String flowId = "LocalMac_"+segmentationId+"_"+inPort+"_"+attachedMac;
- // Add Flow Attributes
- flowBuilder.setId(new FlowId(flowId));
- FlowKey key = new FlowKey(new FlowId(flowId));
- flowBuilder.setStrict(true);
- flowBuilder.setBarrier(false);
- flowBuilder.setTableId(getTable());
- flowBuilder.setKey(key);
- flowBuilder.setFlowName(flowId);
- flowBuilder.setHardTimeout(0);
- flowBuilder.setIdleTimeout(0);
+ MatchBuilder matchBuilder = new MatchBuilder();
+ MatchUtils.createEthSrcMatch(matchBuilder, new MacAddress(attachedMac));
+ MatchUtils.createInPortMatch(matchBuilder, dpidLong, inPort);
+ // openflowplugin requires a vlan match to add a vlan
+ MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(0), false);
+ flowBuilder.setMatch(matchBuilder.build());
if (write) {
// Instantiate the Builders for the OF Actions and Instructions
* Instruction: Drop
* table=0,priority=16384,in_port=1 actions=drop"
*/
-
@Override
public void programDropSrcIface(Long dpidLong, Long inPort, boolean write) {
-
- String nodeName = OPENFLOW + dpidLong;
-
- MatchBuilder matchBuilder = new MatchBuilder();
- NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+ NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
FlowBuilder flowBuilder = new FlowBuilder();
+ String flowName = "DropFilter_" + inPort;
+ FlowUtils.initFlowBuilder(flowBuilder, flowName, getTable()).setPriority(8192);
- // Create the OF Match using MatchBuilder
- flowBuilder.setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, inPort).build());
+ MatchBuilder matchBuilder = new MatchBuilder();
+ MatchUtils.createInPortMatch(matchBuilder, dpidLong, inPort);
+ flowBuilder.setMatch(matchBuilder.build());
if (write) {
// Instantiate the Builders for the OF Actions and Instructions
// Add InstructionsBuilder to FlowBuilder
flowBuilder.setInstructions(isb.build());
- }
- String flowId = "DropFilter_"+inPort;
- // Add Flow Attributes
- flowBuilder.setId(new FlowId(flowId));
- FlowKey key = new FlowKey(new FlowId(flowId));
- flowBuilder.setStrict(true);
- flowBuilder.setBarrier(false);
- flowBuilder.setTableId(getTable());
- flowBuilder.setKey(key);
- flowBuilder.setFlowName(flowId);
- flowBuilder.setPriority(8192);
- flowBuilder.setHardTimeout(0);
- flowBuilder.setIdleTimeout(0);
- if (write) {
writeFlow(flowBuilder, nodeBuilder);
} else {
removeFlow(flowBuilder, nodeBuilder);
}
}
+
/*
* (Table:0) Ingress Tunnel Traffic
* Match: OpenFlow InPort and Tunnel ID
* Action: GOTO Local Table (10)
* table=0,tun_id=0x5,in_port=10, actions=goto_table:2
*/
-
@Override
- public void programTunnelIn(Long dpidLong, String segmentationId,
- Long ofPort, boolean write) {
-
- String nodeName = OPENFLOW + dpidLong;
-
- BigInteger tunnelId = new BigInteger(segmentationId);
- MatchBuilder matchBuilder = new MatchBuilder();
- NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+ public void programTunnelIn(Long dpidLong, String segmentationId, Long ofPort, boolean write) {
+ NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
FlowBuilder flowBuilder = new FlowBuilder();
+ String flowName = "TunnelIn_" + segmentationId + "_" + ofPort;
+ FlowUtils.initFlowBuilder(flowBuilder, flowName, getTable());
- // Create Match(es) and Set them in the FlowBuilder Object
- flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, tunnelId).build());
- flowBuilder.setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, ofPort).build());
+ MatchBuilder matchBuilder = new MatchBuilder();
+ MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId));
+ MatchUtils.createInPortMatch(matchBuilder, dpidLong, ofPort);
+ flowBuilder.setMatch(matchBuilder.build());
if (write) {
// Create the OF Actions and Instructions
// Add InstructionsBuilder to FlowBuilder
flowBuilder.setInstructions(isb.build());
- }
-
- String flowId = "TunnelIn_"+segmentationId+"_"+ofPort;
- // Add Flow Attributes
- flowBuilder.setId(new FlowId(flowId));
- FlowKey key = new FlowKey(new FlowId(flowId));
- flowBuilder.setStrict(true);
- flowBuilder.setBarrier(false);
- flowBuilder.setTableId(getTable());
- flowBuilder.setKey(key);
- flowBuilder.setFlowName(flowId);
- flowBuilder.setHardTimeout(0);
- flowBuilder.setIdleTimeout(0);
- if (write) {
writeFlow(flowBuilder, nodeBuilder);
} else {
removeFlow(flowBuilder, nodeBuilder);
* table=0,vlan_id=0x5,in_port=10, actions=goto_table:2
* table=0,in_port=2,dl_vlan=2001 actions=goto_table:20
*/
-
@Override
public void programVlanIn(Long dpidLong, String segmentationId, Long ethPort, boolean write) {
-
- String nodeName = OPENFLOW + dpidLong;
-
- MatchBuilder matchBuilder = new MatchBuilder();
- NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+ NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
FlowBuilder flowBuilder = new FlowBuilder();
+ String flowName = "VlanIn_" + segmentationId + "_" + ethPort;
+ FlowUtils.initFlowBuilder(flowBuilder, flowName, getTable());
- // Create Match(es) and Set them in the FlowBuilder Object
- flowBuilder.setMatch(MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId)), true).build());
- flowBuilder.setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, ethPort).build());
+ MatchBuilder matchBuilder = new MatchBuilder();
+ MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId)), true);
+ MatchUtils.createInPortMatch(matchBuilder, dpidLong, ethPort);
+ flowBuilder.setMatch(matchBuilder.build());
if (write) {
// Create the OF Actions and Instructions
// Add InstructionsBuilder to FlowBuilder
flowBuilder.setInstructions(isb.build());
- }
- String flowId = "VlanIn_"+segmentationId+"_"+ethPort;
- // Add Flow Attributes
- flowBuilder.setId(new FlowId(flowId));
- FlowKey key = new FlowKey(new FlowId(flowId));
- flowBuilder.setStrict(true);
- flowBuilder.setBarrier(false);
- flowBuilder.setTableId(getTable());
- flowBuilder.setKey(key);
- flowBuilder.setFlowName(flowId);
- flowBuilder.setHardTimeout(0);
- flowBuilder.setIdleTimeout(0);
- if (write) {
writeFlow(flowBuilder, nodeBuilder);
} else {
removeFlow(flowBuilder, nodeBuilder);
* Match: Ethertype 0x88CCL
* Action: Punt to Controller in a Packet_In msg
*/
-
@Override
public void programLLDPPuntRule(Long dpidLong) {
-
- String nodeName = OPENFLOW + dpidLong;
- EtherType etherType = new EtherType(0x88CCL);
-
- MatchBuilder matchBuilder = new MatchBuilder();
- NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+ NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
FlowBuilder flowBuilder = new FlowBuilder();
+ String flowName = "LLDP";
+ FlowUtils.initFlowBuilder(flowBuilder, flowName, getTable());
- // Create Match(es) and Set them in the FlowBuilder Object
- flowBuilder.setMatch(MatchUtils.createEtherTypeMatch(matchBuilder, etherType).build());
+ MatchBuilder matchBuilder = new MatchBuilder();
+ MatchUtils.createEtherTypeMatch(matchBuilder, new EtherType(0x88CCL));
+ flowBuilder.setMatch(matchBuilder.build());
// Create the OF Actions and Instructions
InstructionBuilder ib = new InstructionBuilder();
List<Instruction> instructions = Lists.newArrayList();
// Call the InstructionBuilder Methods Containing Actions
- InstructionUtils.createSendToControllerInstructions(nodeName, ib);
+ InstructionUtils.createSendToControllerInstructions(FlowUtils.getNodeName(dpidLong), ib);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
// Add InstructionsBuilder to FlowBuilder
flowBuilder.setInstructions(isb.build());
- String flowId = "LLDP";
- flowBuilder.setId(new FlowId(flowId));
- FlowKey key = new FlowKey(new FlowId(flowId));
- flowBuilder.setBarrier(true);
- flowBuilder.setTableId(getTable());
- flowBuilder.setKey(key);
- flowBuilder.setFlowName(flowId);
- flowBuilder.setHardTimeout(0);
- flowBuilder.setIdleTimeout(0);
writeFlow(flowBuilder, nodeBuilder);
}