Use initFlowBuilder for L3ForwardingService
authorSam Hague <shague@redhat.com>
Mon, 21 Dec 2015 23:40:47 +0000 (18:40 -0500)
committerSam Hague <shague@redhat.com>
Mon, 21 Dec 2015 23:40:47 +0000 (18:40 -0500)
Change-Id: Ibc4b611c30e21e63ad3b3412712b0e787faaeda4
Signed-off-by: Sam Hague <shague@redhat.com>
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/services/L3ForwardingService.java

index 919fe6746e01051777d95835aea18bb65ef8fffe..f8a8c26a64d5343750d0e0bcd4a18ea30056bb9e 100644 (file)
@@ -14,20 +14,17 @@ import java.net.InetAddress;
 import java.util.List;
 
 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
-import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
 import org.opendaylight.ovsdb.openstack.netvirt.api.L3ForwardingProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.Status;
 import org.opendaylight.ovsdb.openstack.netvirt.api.StatusCode;
 import org.opendaylight.ovsdb.openstack.netvirt.providers.ConfigInterface;
 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
-import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.OF13Provider;
 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
+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.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.list.Instruction;
@@ -55,15 +52,14 @@ public class L3ForwardingService extends AbstractServiceInstance implements L3Fo
     @Override
     public Status programForwardingTableEntry(Long dpid, String segmentationId, InetAddress ipAddress,
                                               String macAddress, Action action) {
-        String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpid;
+        NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpid);
+        FlowBuilder flowBuilder = new FlowBuilder();
+        String flowName = "L3Forwarding_" + segmentationId + "_" + ipAddress.getHostAddress();
+        FlowUtils.initFlowBuilder(flowBuilder, flowName, getTable()).setPriority(1024);
 
         MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = OF13Provider.createNodeBuilder(nodeName);
-
-        // Instructions List Stores Individual Instructions
-        InstructionsBuilder isb = new InstructionsBuilder();
-        List<Instruction> instructions = Lists.newArrayList();
-        InstructionBuilder ib = new InstructionBuilder();
+        MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId));
+        MatchUtils.createDstL3IPv4Match(matchBuilder, MatchUtils.iPv4PrefixFromIPv4Address(ipAddress.getHostAddress()));
 
         if (ipAddress instanceof Inet6Address) {
             // WORKAROUND: For now ipv6 is not supported
@@ -72,38 +68,28 @@ public class L3ForwardingService extends AbstractServiceInstance implements L3Fo
                       dpid, segmentationId, ipAddress, macAddress, action);
             return new Status(StatusCode.NOTIMPLEMENTED);
         }
+        flowBuilder.setMatch(matchBuilder.build());
 
-        MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId));
-        MatchUtils.createDstL3IPv4Match(matchBuilder, MatchUtils.iPv4PrefixFromIPv4Address(ipAddress.getHostAddress()));
+        if (action.equals(Action.ADD)) {
+            // Instructions List Stores Individual Instructions
+            InstructionsBuilder isb = new InstructionsBuilder();
+            List<Instruction> instructions = Lists.newArrayList();
+            InstructionBuilder ib = new InstructionBuilder();
 
-        // Set Dest Mac address
-        InstructionUtils.createDlDstInstructions(ib, new MacAddress(macAddress));
-        ib.setOrder(0);
-        ib.setKey(new InstructionKey(0));
-        instructions.add(ib.build());
+            // Set Dest Mac address
+            InstructionUtils.createDlDstInstructions(ib, new MacAddress(macAddress));
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
 
-        // Goto Next Table
-        ib = getMutablePipelineInstructionBuilder();
-        ib.setOrder(1);
-        ib.setKey(new InstructionKey(1));
-        instructions.add(ib.build());
+            // Goto Next Table
+            ib = getMutablePipelineInstructionBuilder();
+            ib.setOrder(1);
+            ib.setKey(new InstructionKey(1));
+            instructions.add(ib.build());
 
-        FlowBuilder flowBuilder = new FlowBuilder();
-        flowBuilder.setMatch(matchBuilder.build());
-        flowBuilder.setInstructions(isb.setInstruction(instructions).build());
-
-        String flowId = "L3Forwarding_" + segmentationId + "_" + ipAddress.getHostAddress();
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setBarrier(true);
-        flowBuilder.setTableId(this.getTable());
-        flowBuilder.setKey(key);
-        flowBuilder.setPriority(1024);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
+            flowBuilder.setInstructions(isb.setInstruction(instructions).build());
 
-        if (action.equals(Action.ADD)) {
             writeFlow(flowBuilder, nodeBuilder);
         } else {
             removeFlow(flowBuilder, nodeBuilder);