Merge "Combine ovssfc patches."
authorMadhu Venugopal <mavenugo@gmail.com>
Fri, 5 Sep 2014 09:48:22 +0000 (09:48 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 5 Sep 2014 09:48:22 +0000 (09:48 +0000)
12 files changed:
integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/neutron/NeutronIT.java
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/Activator.java
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/AbstractServiceInstance.java
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/OF13Provider.java
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/services/ClassifierService.java
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/services/L2ForwardingService.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/Activator.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/api/ClassifierProvider.java [new file with mode: 0644]
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/api/ConfigurationService.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/api/L2ForwardingProvider.java [new file with mode: 0644]
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/ConfigurationServiceImpl.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/NeutronL3Adapter.java

index 4365809a614af623b6055869905768068d98d0cf..3ab171c945ea77d0945dc46dded19145c7db79c7 100644 (file)
@@ -228,6 +228,18 @@ public class NeutronIT extends OvsdbIntegrationTestBase {
         }
     }
 
+    @Test
+    public void testGetDefaultGatewayMacAddress() throws Exception {
+        // Thread.sleep(5000);
+        String defaultGatewayMacAddress = netVirtConfigurationService.getDefaultGatewayMacAddress(node);
+
+        if (defaultGatewayMacAddress != null) {
+            String[] splits = defaultGatewayMacAddress.split(":");
+            Assert.assertTrue("Unexpected mac format", splits.length == 6);
+        }
+        // log.info("testGetDefaultGatewayMacAddress got mac {}", defaultGatewayMacAddress);
+    }
+
     @After
     public void tearDown() throws InterruptedException {
         Thread.sleep(5000);
index b63e82949a137c6988141ee272e7c59671689c76..bdedccb8eb02cc43f353e28f274e189f2c4c9761 100644 (file)
@@ -19,11 +19,14 @@ import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
 import org.opendaylight.controller.switchmanager.ISwitchManager;
 import org.opendaylight.ovsdb.openstack.netvirt.api.ArpProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
+import org.opendaylight.ovsdb.openstack.netvirt.api.ClassifierProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
 import org.opendaylight.ovsdb.openstack.netvirt.api.EgressAclProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.InboundNatProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.IngressAclProvider;
+import org.opendaylight.ovsdb.openstack.netvirt.api.L2ForwardingProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.L3ForwardingProvider;
+import org.opendaylight.ovsdb.openstack.netvirt.api.LoadBalancerProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.OutboundNatProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.RoutingProvider;
@@ -169,8 +172,10 @@ public class Activator extends ComponentActivatorAbstractBase {
             c.add(createServiceDependency().setService(OvsdbConfigurationService.class).setRequired(true));
             c.add(createServiceDependency().setService(OvsdbConnectionService.class).setRequired(true));
             c.add(createServiceDependency().setService(MdsalConsumer.class).setRequired(true));
+            c.add(createServiceDependency().setService(ClassifierProvider.class).setRequired(true));
             c.add(createServiceDependency().setService(IngressAclProvider.class).setRequired(true));
             c.add(createServiceDependency().setService(EgressAclProvider.class).setRequired(true));
+            c.add(createServiceDependency().setService(L2ForwardingProvider.class).setRequired(true));
         }
 
         if (imp.equals(PipelineOrchestratorImpl.class)) {
@@ -191,7 +196,8 @@ public class Activator extends ComponentActivatorAbstractBase {
             Properties properties = new Properties();
             properties.put(AbstractServiceInstance.SERVICE_PROPERTY, Service.CLASSIFIER);
             properties.put(Constants.PROVIDER_NAME_PROPERTY, OF13Provider.NAME);
-            c.setInterface(AbstractServiceInstance.class.getName(), properties);
+            c.setInterface(new String[] {AbstractServiceInstance.class.getName(), ClassifierProvider.class.getName()},
+                           properties);
         }
 
         if (imp.equals(ArpResponderService.class)) {
@@ -222,7 +228,8 @@ public class Activator extends ComponentActivatorAbstractBase {
             Properties properties = new Properties();
             properties.put(AbstractServiceInstance.SERVICE_PROPERTY, Service.LOAD_BALANCER);
             properties.put(Constants.PROVIDER_NAME_PROPERTY, OF13Provider.NAME);
-            c.setInterface(AbstractServiceInstance.class.getName(), properties);
+            c.setInterface(new String[] {AbstractServiceInstance.class.getName(), LoadBalancerProvider.class.getName()},
+                           properties);
         }
 
         if (imp.equals(RoutingService.class)) {
@@ -252,7 +259,8 @@ public class Activator extends ComponentActivatorAbstractBase {
             Properties properties = new Properties();
             properties.put(AbstractServiceInstance.SERVICE_PROPERTY, Service.L2_FORWARDING);
             properties.put(Constants.PROVIDER_NAME_PROPERTY, OF13Provider.NAME);
-            c.setInterface(AbstractServiceInstance.class.getName(), properties);
+            c.setInterface(new String[] {AbstractServiceInstance.class.getName(), L2ForwardingProvider.class.getName()},
+                           properties);
         }
 
         if (imp.equals(EgressAclService.class)) {
index efc39c0a6666fb1085388740a0f2dc39c237f9d3..5c071454abac97cbae7f4ff2990a3f8ca03e185e 100644 (file)
@@ -16,6 +16,7 @@ import java.util.concurrent.LinkedBlockingDeque;
 
 import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
@@ -72,7 +73,7 @@ import com.google.common.util.concurrent.Futures;
 public abstract class AbstractServiceInstance implements OpendaylightInventoryListener, Runnable, TransactionChainListener {
     public static final String SERVICE_PROPERTY ="serviceProperty";
     private static final Logger logger = LoggerFactory.getLogger(AbstractServiceInstance.class);
-
+    public static final String OPENFLOW = "openflow:";
     // OSGi Services that we are dependent on.
     private volatile MdsalConsumer mdsalConsumer;
     private volatile PipelineOrchestrator orchestrator;
@@ -80,8 +81,6 @@ public abstract class AbstractServiceInstance implements OpendaylightInventoryLi
     // Concrete Service that this AbstractServiceInstance represent
     private Service service;
 
-    private BindingTransactionChain txChain;
-
     // Process Notification in its own thread
     Thread thread = null;
     private final BlockingQueue<String> queue = new LinkedBlockingDeque<>();
@@ -111,7 +110,6 @@ public abstract class AbstractServiceInstance implements OpendaylightInventoryLi
         if (notificationService != null) {
             notificationService.registerNotificationListener(this);
         }
-        this.txChain =  mdsalConsumer.getDataBroker().createTransactionChain(this);
 
         // Never block a Notification thread. Process the notification in its own Thread.
         thread = new Thread(this);
@@ -209,6 +207,37 @@ public abstract class AbstractServiceInstance implements OpendaylightInventoryLi
         }
     }
 
+    public Flow getFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
+        Preconditions.checkNotNull(mdsalConsumer);
+        if (mdsalConsumer == null) {
+            logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
+            return null;
+        }
+
+        DataBroker dataBroker = mdsalConsumer.getDataBroker();
+        if (dataBroker == null) {
+            logger.error("ERROR finding reference for DataBroker. Please check MD-SAL support on the Controller.");
+            return null;
+        }
+
+        InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
+                .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class,
+                new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
+
+        ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
+        try {
+            Optional<Flow> data = readTx.read(LogicalDatastoreType.CONFIGURATION, path1).get();
+            if (data.isPresent()) {
+                return data.get();
+            }
+        } catch (InterruptedException|ExecutionException e) {
+            logger.error(e.getMessage(), e);
+        }
+
+        logger.debug("Cannot find data for Flow " + flowBuilder.getFlowName());
+        return null;
+    }
+
     /**
      * Program Default Pipeline Flow.
      *
@@ -308,6 +337,7 @@ public abstract class AbstractServiceInstance implements OpendaylightInventoryLi
             InstanceIdentifierBuilder<Node> builder = ((InstanceIdentifier<Node>) ref.getValue()).builder();
             InstanceIdentifierBuilder<FlowCapableNode> augmentation = builder.augmentation(FlowCapableNode.class);
             final InstanceIdentifier<FlowCapableNode> path = augmentation.build();
+            BindingTransactionChain txChain = mdsalConsumer.getDataBroker().createTransactionChain(this);
             CheckedFuture readFuture = txChain.newReadWriteTransaction().read(LogicalDatastoreType.OPERATIONAL, path);
             Futures.addCallback(readFuture, new FutureCallback<Optional<? extends DataObject>>() {
                 @Override
index b46bf3c58f7a356b5fc228eabe441aae54c94861..843ae064655262945d48492f0481a5df7550ab07 100644 (file)
@@ -9,7 +9,6 @@
  */
 package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13;
 
-import java.math.BigInteger;
 import java.net.InetAddress;
 import java.util.List;
 import java.util.Map;
@@ -32,9 +31,11 @@ import org.opendaylight.ovsdb.lib.notation.Row;
 import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
 import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
+import org.opendaylight.ovsdb.openstack.netvirt.api.ClassifierProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
 import org.opendaylight.ovsdb.openstack.netvirt.api.EgressAclProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.IngressAclProvider;
+import org.opendaylight.ovsdb.openstack.netvirt.api.L2ForwardingProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.SecurityServicesManager;
 import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager;
@@ -45,14 +46,11 @@ import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
 import org.opendaylight.ovsdb.schema.openvswitch.Interface;
 import org.opendaylight.ovsdb.schema.openvswitch.Port;
 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.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.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.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.list.Action;
@@ -65,7 +63,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.ta
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
 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.Instructions;
 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;
@@ -90,8 +87,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
 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.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -123,6 +118,8 @@ public class OF13Provider implements NetworkingProvider {
     private volatile SecurityServicesManager securityServicesManager;
     private volatile IngressAclProvider ingressAclProvider;
     private volatile EgressAclProvider egressAclProvider;
+    private volatile ClassifierProvider classifierProvider;
+    private volatile L2ForwardingProvider l2ForwardingProvider;
 
     public static final String NAME = "OF13Provider";
 
@@ -303,14 +300,14 @@ public class OF13Provider implements NetworkingProvider {
             String portUUID = this.getPortUuid(node, portName, bridgeUUID);
             Status status = new Status(StatusCode.SUCCESS);
             if (portUUID != null) {
-               status = ovsdbConfigurationService
-                       .deleteRow(node, ovsdbConfigurationService.getTableName(node, Port.class), portUUID);
-               if (!status.isSuccess()) {
-                   logger.error("Failed to delete port {} in {} status : {}", portName, bridgeUUID,
-                                status);
-                   return status;
-               }
-               logger.debug("Port {} delete status : {}", portName, status);
+                status = ovsdbConfigurationService
+                        .deleteRow(node, ovsdbConfigurationService.getTableName(node, Port.class), portUUID);
+                if (!status.isSuccess()) {
+                    logger.error("Failed to delete port {} in {} status : {}", portName, bridgeUUID,
+                            status);
+                    return status;
+                }
+                logger.debug("Port {} delete status : {}", portName, status);
             }
             return status;
         } catch (Exception e) {
@@ -331,14 +328,14 @@ public class OF13Provider implements NetworkingProvider {
     }
 
     private void programLocalBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long localPort) {
-         /*
+        /*
          * Table(0) Rule #3
          * ----------------
          * Match: VM sMac and Local Ingress Port
          * Action:Action: Set Tunnel ID and GOTO Local Table (5)
          */
 
-         handleLocalInPort(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_1_ISOLATE_TENANT, segmentationId, localPort, attachedMac, true);
+        handleLocalInPort(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_1_ISOLATE_TENANT, segmentationId, localPort, attachedMac, true);
 
         /*
          * Table(0) Rule #4
@@ -347,51 +344,51 @@ public class OF13Provider implements NetworkingProvider {
          * Action: Drop w/ a low priority
          */
 
-         handleDropSrcIface(dpid, localPort, true);
-
-         /*
-          * Table(2) Rule #1
-          * ----------------
-          * Match: Match TunID and Destination DL/dMAC Addr
-          * Action: Output Port
-          * table=2,tun_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
-          */
-
-         handleLocalUcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, attachedMac, true);
-
-         /*
-          * Table(2) Rule #2
-          * ----------------
-          * Match: Tunnel ID and dMAC (::::FF:FF)
-          * table=2,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
-          * actions=output:2,3,4,5
-          */
-
-          handleLocalBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, true);
-
-          /*
-           * TODO : Optimize the following 2 writes to be restricted only for the very first port known in a segment.
-           */
-          /*
-           * Table(1) Rule #3
-           * ----------------
-           * Match:  Any remaining Ingress Local VM Packets
-           * Action: Drop w/ a low priority
-           * -------------------------------------------
-           * table=1,priority=8192,tun_id=0x5 actions=goto_table:2
-           */
-
-           handleTunnelMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, true);
-
-          /*
-           * Table(2) Rule #3
-           * ----------------
-           * Match: Any Remaining Flows w/a TunID
-           * Action: Drop w/ a low priority
-           * table=2,priority=8192,tun_id=0x5 actions=drop
-           */
-
-           handleLocalTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, true);
+        handleDropSrcIface(dpid, localPort, true);
+
+        /*
+         * Table(2) Rule #1
+         * ----------------
+         * Match: Match TunID and Destination DL/dMAC Addr
+         * Action: Output Port
+         * table=2,tun_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
+         */
+
+        handleLocalUcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, attachedMac, true);
+
+        /*
+         * Table(2) Rule #2
+         * ----------------
+         * Match: Tunnel ID and dMAC (::::FF:FF)
+         * table=2,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
+         * actions=output:2,3,4,5
+         */
+
+        handleLocalBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, true);
+
+        /*
+         * TODO : Optimize the following 2 writes to be restricted only for the very first port known in a segment.
+         */
+        /*
+         * Table(1) Rule #3
+         * ----------------
+         * Match:  Any remaining Ingress Local VM Packets
+         * Action: Drop w/ a low priority
+         * -------------------------------------------
+         * table=1,priority=8192,tun_id=0x5 actions=goto_table:2
+         */
+
+        handleTunnelMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, true);
+
+        /*
+         * Table(2) Rule #3
+         * ----------------
+         * Match: Any Remaining Flows w/a TunID
+         * Action: Drop w/ a low priority
+         * table=2,priority=8192,tun_id=0x5 actions=drop
+         */
+
+        handleLocalTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, true);
     }
 
     private void removeLocalBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long localPort) {
@@ -402,7 +399,7 @@ public class OF13Provider implements NetworkingProvider {
          * Action:Action: Set Tunnel ID and GOTO Local Table (5)
          */
 
-         handleLocalInPort(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_1_ISOLATE_TENANT, segmentationId, localPort, attachedMac, false);
+        handleLocalInPort(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_1_ISOLATE_TENANT, segmentationId, localPort, attachedMac, false);
 
         /*
          * Table(0) Rule #4
@@ -411,27 +408,27 @@ public class OF13Provider implements NetworkingProvider {
          * Action: Drop w/ a low priority
          */
 
-         handleDropSrcIface(dpid, localPort, false);
+        handleDropSrcIface(dpid, localPort, false);
 
-         /*
-          * Table(2) Rule #1
-          * ----------------
-          * Match: Match TunID and Destination DL/dMAC Addr
-          * Action: Output Port
-          * table=2,tun_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
-          */
+        /*
+         * Table(2) Rule #1
+         * ----------------
+         * Match: Match TunID and Destination DL/dMAC Addr
+         * Action: Output Port
+         * table=2,tun_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
+         */
 
-         handleLocalUcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, attachedMac, false);
+        handleLocalUcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, attachedMac, false);
 
-         /*
-          * Table(2) Rule #2
-          * ----------------
-          * Match: Tunnel ID and dMAC (::::FF:FF)
-          * table=2,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
-          * actions=output:2,3,4,5
-          */
+        /*
+         * Table(2) Rule #2
+         * ----------------
+         * Match: Tunnel ID and dMAC (::::FF:FF)
+         * table=2,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
+         * actions=output:2,3,4,5
+         */
 
-          handleLocalBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, false);
+        handleLocalBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, false);
     }
 
     private void programLocalIngressTunnelBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long tunnelOFPort, long localPort) {
@@ -442,19 +439,19 @@ public class OF13Provider implements NetworkingProvider {
          * Action: GOTO Local Table (20)
          */
 
-         handleTunnelIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, true);
+        handleTunnelIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, true);
 
-         /*
-          * Table(1) Rule #2
-          * ----------------
-          * Match: Match Tunnel ID and L2 ::::FF:FF Flooding
-          * Action: Flood to selected destination TEPs
-          * -------------------------------------------
-          * table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
-          * actions=output:10,output:11,goto_table:2
-          */
+        /*
+         * Table(1) Rule #2
+         * ----------------
+         * Match: Match Tunnel ID and L2 ::::FF:FF Flooding
+         * Action: Flood to selected destination TEPs
+         * -------------------------------------------
+         * table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
+         * actions=output:10,output:11,goto_table:2
+         */
 
-         handleTunnelFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, true);
+        handleTunnelFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, true);
 
     }
 
@@ -521,15 +518,15 @@ public class OF13Provider implements NetworkingProvider {
 
         handleTunnelIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, false);
 
-         /*
-          * Table(1) Rule #2
-          * ----------------
-          * Match: Match Tunnel ID and L2 ::::FF:FF Flooding
-          * Action: Flood to selected destination TEPs
-          * -------------------------------------------
-          * table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
-          * actions=output:10,output:11,goto_table:2
-          */
+        /*
+         * Table(1) Rule #2
+         * ----------------
+         * Match: Match Tunnel ID and L2 ::::FF:FF Flooding
+         * Action: Flood to selected destination TEPs
+         * -------------------------------------------
+         * table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
+         * actions=output:10,output:11,goto_table:2
+         */
 
         handleTunnelFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, false);
     }
@@ -578,21 +575,21 @@ public class OF13Provider implements NetworkingProvider {
         handleLocalVlanBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId,
                 localPort, true);
 
-         /*
-          * Table(2) Rule #3
-          * ----------------
-          * Match: Any Remaining Flows w/a VLAN ID
-          * Action: Drop w/ a low priority
-          * Example: table=2,priority=8192,vlan_id=0x5 actions=drop
-          */
+        /*
+         * Table(2) Rule #3
+         * ----------------
+         * Match: Any Remaining Flows w/a VLAN ID
+         * Action: Drop w/ a low priority
+         * Example: table=2,priority=8192,vlan_id=0x5 actions=drop
+         */
 
-          handleLocalVlanTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId,
-                                   true);
-   }
+        handleLocalVlanTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId,
+                true);
+    }
 
     private void removeLocalVlanRules(Node node, Long dpid,
-                                      String segmentationId, String attachedMac,
-                                      long localPort) {
+            String segmentationId, String attachedMac,
+            long localPort) {
         /*
          * Table(0) Rule #1
          * ----------------
@@ -635,18 +632,18 @@ public class OF13Provider implements NetworkingProvider {
 
         handleLocalVlanBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId,
                 localPort, false);
-   }
+    }
 
-   private void programLocalIngressVlanRules(Node node, Long dpid, String segmentationId, String attachedMac, long ethPort) {
-       /*
-        * Table(0) Rule #2
-        * ----------------
-        * Match: Ingress port = physical interface, Vlan ID
-        * Action: GOTO Local Table 2
-        */
+    private void programLocalIngressVlanRules(Node node, Long dpid, String segmentationId, String attachedMac, long ethPort) {
+        /*
+         * Table(0) Rule #2
+         * ----------------
+         * Match: Ingress port = physical interface, Vlan ID
+         * Action: GOTO Local Table 2
+         */
 
-       handleVlanIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD,
-                    segmentationId, ethPort, true);
+        handleVlanIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD,
+                segmentationId, ethPort, true);
 
         /*
          * Table(1) Rule #2
@@ -659,62 +656,62 @@ public class OF13Provider implements NetworkingProvider {
          */
 
         handleVlanFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
-                           segmentationId, ethPort, true);
-   }
-
-   private void programRemoteEgressVlanRules(Node node, Long dpid, String segmentationId, String attachedMac, long ethPort) {
-       /*
-        * Table(1) Rule #1
-        * ----------------
-        * Match: Destination MAC is local VM MAC and vlan id
-        * Action: go to table 2
-        * -------------------------------------------
-        * Example: table=1,vlan_id=0x5,dl_dst=00:00:00:00:00:08 \
-        * actions=goto_table:2
-        */
-
-       handleVlanOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
-                     segmentationId, ethPort, attachedMac, true);
-
-       /*
-        * Table(1) Rule #3
-        * ----------------
-        * Match:  VLAN ID
-        * Action: Go to table 2
-        * -------------------------------------------
-        * Example: table=1,priority=8192,vlan_id=0x5 actions=output:1,goto_table:2
-        */
-
-       handleVlanMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
-                      segmentationId, ethPort, true);
-   }
-
-   private void removeRemoteEgressVlanRules(Node node, Long dpid, String segmentationId, String attachedMac, long ethPort) {
-       /*
-        * Table(1) Rule #1
-        * ----------------
-        * Match: Destination MAC is local VM MAC and vlan id
-        * Action: go to table 2
-        * -------------------------------------------
-        * Example: table=1,vlan_id=0x5,dl_dst=00:00:00:00:00:08 \
-        * actions=goto_table:2
-        */
-
-       handleVlanOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
-                     segmentationId, ethPort, attachedMac, false);
-   }
-
-   private void removePerVlanRules(Node node, Long dpid, String segmentationId, long ethPort) {
-       /*
-        * Table(2) Rule #3
-        * ----------------
-        * Match: Any Remaining Flows w/a VLAN ID
-        * Action: Drop w/ a low priority
-        * Example: table=2,priority=8192,vlan_id=0x5 actions=drop
-        */
+                segmentationId, ethPort, true);
+    }
+
+    private void programRemoteEgressVlanRules(Node node, Long dpid, String segmentationId, String attachedMac, long ethPort) {
+        /*
+         * Table(1) Rule #1
+         * ----------------
+         * Match: Destination MAC is local VM MAC and vlan id
+         * Action: go to table 2
+         * -------------------------------------------
+         * Example: table=1,vlan_id=0x5,dl_dst=00:00:00:00:00:08 \
+         * actions=goto_table:2
+         */
+
+        handleVlanOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
+                segmentationId, ethPort, attachedMac, true);
+
+        /*
+         * Table(1) Rule #3
+         * ----------------
+         * Match:  VLAN ID
+         * Action: Go to table 2
+         * -------------------------------------------
+         * Example: table=1,priority=8192,vlan_id=0x5 actions=output:1,goto_table:2
+         */
+
+        handleVlanMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
+                segmentationId, ethPort, true);
+    }
+
+    private void removeRemoteEgressVlanRules(Node node, Long dpid, String segmentationId, String attachedMac, long ethPort) {
+        /*
+         * Table(1) Rule #1
+         * ----------------
+         * Match: Destination MAC is local VM MAC and vlan id
+         * Action: go to table 2
+         * -------------------------------------------
+         * Example: table=1,vlan_id=0x5,dl_dst=00:00:00:00:00:08 \
+         * actions=goto_table:2
+         */
+
+        handleVlanOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
+                segmentationId, ethPort, attachedMac, false);
+    }
+
+    private void removePerVlanRules(Node node, Long dpid, String segmentationId, long ethPort) {
+        /*
+         * Table(2) Rule #3
+         * ----------------
+         * Match: Any Remaining Flows w/a VLAN ID
+         * Action: Drop w/ a low priority
+         * Example: table=2,priority=8192,vlan_id=0x5 actions=drop
+         */
 
         handleLocalVlanTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId,
-                                 false);
+                false);
 
         /*
          * Table(0) Rule #2
@@ -724,33 +721,33 @@ public class OF13Provider implements NetworkingProvider {
          */
 
         handleVlanIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD,
-                     segmentationId, ethPort, false);
-
-         /*
-          * Table(1) Rule #2
-          * ----------------
-          * Match: Match VLAN ID and L2 ::::FF:FF Flooding
-          * Action: Flood to local and remote VLAN members
-          * -------------------------------------------
-          * Example: table=1,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
-          * actions=output:10 (eth port),goto_table:2
-          */
-
-         handleVlanFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
-                            segmentationId, ethPort, false);
-
-         /*
-          * Table(1) Rule #3
-          * ----------------
-          * Match:  VLAN ID
-          * Action: Go to table 2
-          * -------------------------------------------
-          * Example: table=1,priority=8192,vlan_id=0x5 actions=output:1,goto_table:2
-          */
-
-         handleVlanMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
-                        segmentationId, ethPort, false);
-   }
+                segmentationId, ethPort, false);
+
+        /*
+         * Table(1) Rule #2
+         * ----------------
+         * Match: Match VLAN ID and L2 ::::FF:FF Flooding
+         * Action: Flood to local and remote VLAN members
+         * -------------------------------------------
+         * Example: table=1,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
+         * actions=output:10 (eth port),goto_table:2
+         */
+
+        handleVlanFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
+                segmentationId, ethPort, false);
+
+        /*
+         * Table(1) Rule #3
+         * ----------------
+         * Match:  VLAN ID
+         * Action: Go to table 2
+         * -------------------------------------------
+         * Example: table=1,priority=8192,vlan_id=0x5 actions=output:1,goto_table:2
+         */
+
+        handleVlanMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD,
+                segmentationId, ethPort, false);
+    }
     private Long getDpid (Node node, String bridgeUuid) {
         Preconditions.checkNotNull(ovsdbConfigurationService);
         try {
@@ -841,10 +838,10 @@ public class OF13Provider implements NetworkingProvider {
                 ingressAclProvider.programPortSecurityACL(node, dpid, segmentationId, attachedMac, localPort,
                         securityGroupInPort);
                 egressAclProvider.programPortSecurityACL(node, dpid, segmentationId, attachedMac, localPort,
-                                                         securityGroupInPort);
+                        securityGroupInPort);
             }
             else if (networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE) ||
-                       networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)) {
+                    networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)) {
                 logger.debug("Program local bridge rules for interface {}", intf.getName());
                 programLocalBridgeRules(node, dpid, segmentationId, attachedMac, localPort);
             }
@@ -885,7 +882,7 @@ public class OF13Provider implements NetworkingProvider {
                 logger.debug("Remove local vlan rules for interface {}", intf.getName());
                 removeLocalVlanRules(node, dpid, segmentationId, attachedMac, localPort);
             } else if (networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE) ||
-                       networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)) {
+                    networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)) {
                 logger.debug("Remove local bridge rules for interface {}", intf.getName());
                 removeLocalBridgeRules(node, dpid, segmentationId, attachedMac, localPort);
             }
@@ -1074,7 +1071,7 @@ public class OF13Provider implements NetworkingProvider {
                             if (of_ports == null || of_ports.size() <= 0) {
                                 // Wait for the OVSDB update to sync up the Local cache.
                                 Thread.sleep(500);
-                                timeout--;
+                                        timeout--;
                             }
                         }
 
@@ -1102,7 +1099,7 @@ public class OF13Provider implements NetworkingProvider {
     }
 
     private void removeVlanRules (NeutronNetwork network, Node node,
-                      Interface intf, boolean isLastInstanceOnNode) {
+            Interface intf, boolean isLastInstanceOnNode) {
         Preconditions.checkNotNull(ovsdbConfigurationService);
         logger.debug("Remove vlan rules for interface {}", intf.getName());
 
@@ -1137,7 +1134,7 @@ public class OF13Provider implements NetworkingProvider {
                 for (Row row : intfs.values()) {
                     Interface ethIntf = ovsdbConfigurationService.getTypedRow(node, Interface.class, row);
                     if (ethIntf.getName().equalsIgnoreCase(bridgeConfigurationManager.getPhysicalInterfaceName(node,
-                                                                   network.getProviderPhysicalNetwork()))) {
+                            network.getProviderPhysicalNetwork()))) {
                         of_ports = ethIntf.getOpenFlowPortColumn().getData();
                         if (of_ports == null || of_ports.size() <= 0) {
                             logger.error("Could NOT Identify eth port {} on {}", ethIntf.getName(), node);
@@ -1174,7 +1171,7 @@ public class OF13Provider implements NetworkingProvider {
         if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
             this.programVlanRules(network, srcNode, intf);
         } else if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)
-                   || network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)){
+                || network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)){
             for (Node dstNode : nodes) {
                 InetAddress src = configurationService.getTunnelEndPoint(srcNode);
                 InetAddress dst = configurationService.getTunnelEndPoint(dstNode);
@@ -1229,7 +1226,7 @@ public class OF13Provider implements NetworkingProvider {
         logger.info("Delete intf " + intf.getName() + " isLastInstanceOnNode " + isLastInstanceOnNode);
         List<String> phyIfName = bridgeConfigurationManager.getAllPhysicalInterfaceNames(srcNode);
         if (intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)
-            || intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)) {
+                || intf.getTypeColumn().getData().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)) {
             /* Delete tunnel port */
             try {
                 Map<String, String> options = intf.getOptionsColumn().getData();
@@ -1248,19 +1245,19 @@ public class OF13Provider implements NetworkingProvider {
 
             if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
                 this.removeVlanRules(network, srcNode,
-                                 intf, isLastInstanceOnNode);
+                        intf, isLastInstanceOnNode);
             } else if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE)
-                   || network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)) {
+                    || network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)) {
 
                 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());
                     this.removeTunnelRules(tunnelType, network.getProviderSegmentationID(),
-                                           dst, srcNode, intf, true, isLastInstanceOnNode);
+                            dst, srcNode, intf, true, isLastInstanceOnNode);
                     logger.info("Remove tunnel rules for interface " + intf.getName() + " on dstNode " + dstNode.getNodeIDString());
                     this.removeTunnelRules(tunnelType, network.getProviderSegmentationID(),
-                                           src, dstNode, intf, false, isLastInstanceOnNode);
+                            src, dstNode, intf, false, isLastInstanceOnNode);
                 }
             }
         }
@@ -1294,68 +1291,29 @@ public class OF13Provider implements NetworkingProvider {
          * Action: Packet_In to Controller Reserved Port
          */
 
-         writeLLDPRule(dpid);
-         if (bridgeName.equals(configurationService.getExternalBridgeName())) {
-             writeNormalRule(dpid);
-         }
+        writeLLDPRule(dpid);
+        if (bridgeName.equals(configurationService.getExternalBridgeName())) {
+            writeNormalRule(dpid);
+        }
     }
 
     /*
-    * Create an LLDP Flow Rule to encapsulate into
-    * a packet_in that is sent to the controller
-    * for topology handling.
-    * Match: Ethertype 0x88CCL
-    * Action: Punt to Controller in a Packet_In msg
-    */
+     * Create an LLDP Flow Rule to encapsulate into
+     * a packet_in that is sent to the controller
+     * for topology handling.
+     * Match: Ethertype 0x88CCL
+     * Action: Punt to Controller in a Packet_In msg
+     */
 
     private void writeLLDPRule(Long dpidLong) {
-
-        String nodeName = OPENFLOW + dpidLong;
-        EtherType etherType = new EtherType(0x88CCL);
-
-        MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-        FlowBuilder flowBuilder = new FlowBuilder();
-
-        // Create Match(es) and Set them in the FlowBuilder Object
-        flowBuilder.setMatch(MatchUtils.createEtherTypeMatch(matchBuilder, etherType).build());
-
-        // Create the OF Actions and Instructions
-        InstructionBuilder ib = new InstructionBuilder();
-        InstructionsBuilder isb = new InstructionsBuilder();
-
-        // Instructions List Stores Individual Instructions
-        List<Instruction> instructions = Lists.newArrayList();
-
-        // Call the InstructionBuilder Methods Containing Actions
-        InstructionUtils.createSendToControllerInstructions(ib);
-        ib.setOrder(0);
-        ib.setKey(new InstructionKey(0));
-        instructions.add(ib.build());
-
-        // Add InstructionBuilder to the Instruction(s)Builder List
-        isb.setInstruction(instructions);
-
-        // 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((short) 0);
-        flowBuilder.setKey(key);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
-        writeFlow(flowBuilder, nodeBuilder);
+        classifierProvider.programLLDPPuntRule(dpidLong);
     }
 
     /*
-    * Create a NORMAL Table Miss Flow Rule
-    * Match: any
-    * Action: forward to NORMAL pipeline
-    */
+     * Create a NORMAL Table Miss Flow Rule
+     * Match: any
+     * Action: forward to NORMAL pipeline
+     */
 
     private void writeNormalRule(Long dpidLong) {
 
@@ -1406,58 +1364,9 @@ public class OF13Provider implements NetworkingProvider {
      */
 
     private void handleTunnelIn(Long dpidLong, Short writeTable,
-                                Short goToTableId, String segmentationId,
-                                Long ofPort, boolean write) {
-
-        String nodeName = OPENFLOW + dpidLong;
-
-        BigInteger tunnelId = new BigInteger(segmentationId);
-        MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-        FlowBuilder flowBuilder = new FlowBuilder();
-
-        // 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());
-
-        if (write) {
-            // Create the OF Actions and Instructions
-            InstructionBuilder ib = new InstructionBuilder();
-            InstructionsBuilder isb = new InstructionsBuilder();
-
-            // Instructions List Stores Individual Instructions
-            List<Instruction> instructions = Lists.newArrayList();
-
-            // Call the InstructionBuilder Methods Containing Actions
-            InstructionUtils.createGotoTableInstructions(ib, goToTableId);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructions.add(ib.build());
-
-            // Add InstructionBuilder to the Instruction(s)Builder List
-            isb.setInstruction(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(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
-
-        if (write) {
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            removeFlow(flowBuilder, nodeBuilder);
-        }
+            Short goToTableId, String segmentationId,
+            Long ofPort, boolean write) {
+        classifierProvider.programTunnelIn(dpidLong, segmentationId, ofPort, write);
     }
 
     /*
@@ -1468,124 +1377,22 @@ public class OF13Provider implements NetworkingProvider {
      */
 
     private void handleVlanIn(Long dpidLong, Short writeTable, Short goToTableId,
-                      String segmentationId,  Long ethPort, boolean write) {
-
-        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(
-                MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId)))
-                        .build())
-                .setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, ethPort)
-                        .build());
-
-        if (write) {
-            // Create the OF Actions and Instructions
-            InstructionBuilder ib = new InstructionBuilder();
-            InstructionsBuilder isb = new InstructionsBuilder();
-
-            // Instructions List Stores Individual Instructions
-            List<Instruction> instructions = Lists.newArrayList();
-
-            // Call the InstructionBuilder Methods Containing Actions
-            InstructionUtils.createGotoTableInstructions(ib, goToTableId);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructions.add(ib.build());
-
-            // Add InstructionBuilder to the Instruction(s)Builder List
-            isb.setInstruction(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(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
-        if (write) {
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            removeFlow(flowBuilder, nodeBuilder);
-        }
+            String segmentationId,  Long ethPort, boolean write) {
+        classifierProvider.programVlanIn(dpidLong, segmentationId, ethPort, write);
     }
 
-   /*
-    * (Table:0) Egress VM Traffic Towards TEP
-    * Match: Destination Ethernet Addr and OpenFlow InPort
-    * Instruction: Set TunnelID and GOTO Table Tunnel Table (n)
-    * table=0,in_port=2,dl_src=00:00:00:00:00:01 \
-    * actions=set_field:5->tun_id,goto_table=1"
-    */
+    /*
+     * (Table:0) Egress VM Traffic Towards TEP
+     * Match: Destination Ethernet Addr and OpenFlow InPort
+     * Instruction: Set TunnelID and GOTO Table Tunnel Table (n)
+     * table=0,in_port=2,dl_src=00:00:00:00:00:01 \
+     * actions=set_field:5->tun_id,goto_table=1"
+     */
 
     private void handleLocalInPort(Long dpidLong, Short writeTable, Short goToTableId,
-                           String segmentationId, Long inPort, String attachedMac,
-                           boolean write) {
-
-        String nodeName = OPENFLOW + dpidLong;
-
-        MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-        FlowBuilder flowBuilder = new FlowBuilder();
-
-        // 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(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
-
-        if (write) {
-            // Instantiate the Builders for the OF Actions and Instructions
-            InstructionBuilder ib = new InstructionBuilder();
-            InstructionsBuilder isb = new InstructionsBuilder();
-
-            // Instructions List Stores Individual Instructions
-            List<Instruction> instructions = Lists.newArrayList();
-
-            // GOTO Instructions Need to be added first to the List
-            InstructionUtils.createGotoTableInstructions(ib, goToTableId);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructions.add(ib.build());
-            // TODO Broken SetTunID
-            InstructionUtils.createSetTunnelIdInstructions(ib, new BigInteger(segmentationId));
-            ib.setOrder(1);
-            ib.setKey(new InstructionKey(1));
-            instructions.add(ib.build());
-
-            // Add InstructionBuilder to the Instruction(s)Builder List
-            isb.setInstruction(instructions);
-
-            // Add InstructionsBuilder to FlowBuilder
-            flowBuilder.setInstructions(isb.build());
-
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            removeFlow(flowBuilder, nodeBuilder);
-        }
+            String segmentationId, Long inPort, String attachedMac,
+            boolean write) {
+        classifierProvider.programLocalInPort(dpidLong, segmentationId, inPort, attachedMac, write);
     }
 
     /*
@@ -1596,63 +1403,12 @@ public class OF13Provider implements NetworkingProvider {
      * actions=push_vlan, set_field:5->vlan_id,goto_table=1"
      */
 
-     private void handleLocalInPortSetVlan(Long dpidLong, Short writeTable,
-                                  Short goToTableId, String segmentationId,
-                                  Long inPort, String attachedMac,
-                                  boolean write) {
-
-         String nodeName = OPENFLOW + dpidLong;
-
-         MatchBuilder matchBuilder = new MatchBuilder();
-         NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-         FlowBuilder flowBuilder = new FlowBuilder();
-
-         // Create the OF Match using MatchBuilder
-         flowBuilder.setMatch(MatchUtils.createEthSrcMatch(matchBuilder, new MacAddress(attachedMac)).build());
-         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(writeTable);
-         flowBuilder.setKey(key);
-         flowBuilder.setFlowName(flowId);
-         flowBuilder.setHardTimeout(0);
-         flowBuilder.setIdleTimeout(0);
-
-         if (write) {
-             // Instantiate the Builders for the OF Actions and Instructions
-             InstructionBuilder ib = new InstructionBuilder();
-             InstructionsBuilder isb = new InstructionsBuilder();
-
-             // Instructions List Stores Individual Instructions
-             List<Instruction> instructions = Lists.newArrayList();
-
-             // GOTO Instructions Need to be added first to the List
-             InstructionUtils.createGotoTableInstructions(ib, goToTableId);
-             ib.setOrder(0);
-             ib.setKey(new InstructionKey(0));
-             instructions.add(ib.build());
-             // Set VLAN ID Instruction
-             InstructionUtils.createSetVlanInstructions(ib, new VlanId(Integer.valueOf(segmentationId)));
-             ib.setOrder(1);
-             ib.setKey(new InstructionKey(1));
-             instructions.add(ib.build());
-
-             // Add InstructionBuilder to the Instruction(s)Builder List
-             isb.setInstruction(instructions);
-
-             // Add InstructionsBuilder to FlowBuilder
-             flowBuilder.setInstructions(isb.build());
-
-             writeFlow(flowBuilder, nodeBuilder);
-         } else {
-             removeFlow(flowBuilder, nodeBuilder);
-         }
-     }
+    private void handleLocalInPortSetVlan(Long dpidLong, Short writeTable,
+            Short goToTableId, String segmentationId,
+            Long inPort, String attachedMac,
+            boolean write) {
+        classifierProvider.programLocalInPortSetVlan(dpidLong, segmentationId, inPort, attachedMac, write);
+    }
 
     /*
      * (Table:0) Drop frames source from a VM that do not
@@ -1663,403 +1419,76 @@ public class OF13Provider implements NetworkingProvider {
      */
 
     private void handleDropSrcIface(Long dpidLong, Long inPort, boolean write) {
+        classifierProvider.programDropSrcIface(dpidLong, inPort, write);
+    }
 
-        String nodeName = OPENFLOW + dpidLong;
-
-        MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-        FlowBuilder flowBuilder = new FlowBuilder();
-
-        // Create the OF Match using MatchBuilder
-        flowBuilder.setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, inPort).build());
+    /*
+     * (Table:1) Egress Tunnel Traffic
+     * Match: Destination Ethernet Addr and Local InPort
+     * Instruction: Set TunnelID and GOTO Table Tunnel Table (n)
+     * table=1,tun_id=0x5,dl_dst=00:00:00:00:00:08 \
+     * actions=output:10,goto_table:2"
+     */
+    private void handleTunnelOut(Long dpidLong, Short writeTable,
+            Short goToTableId, String segmentationId,
+            Long OFPortOut, String attachedMac,
+            boolean write) {
+        l2ForwardingProvider.programTunnelOut(dpidLong, segmentationId, OFPortOut, attachedMac, write);
+    }
 
-        if (write) {
-            // Instantiate the Builders for the OF Actions and Instructions
-            InstructionBuilder ib = new InstructionBuilder();
-            InstructionsBuilder isb = new InstructionsBuilder();
+    /*
+     * (Table:1) Egress VLAN Traffic
+     * Match: Destination Ethernet Addr and VLAN id
+     * Instruction: GOTO Table Table 2
+     * table=1,vlan_id=0x5,dl_dst=00:00:00:00:00:08 \
+     * actions= goto_table:2"
+     */
 
-            // Instructions List Stores Individual Instructions
-            List<Instruction> instructions = Lists.newArrayList();
+    private void handleVlanOut(Long dpidLong, Short writeTable,
+            Short goToTableId, String segmentationId,
+            Long ethPort, String attachedMac, boolean write) {
+        l2ForwardingProvider.programVlanOut(dpidLong, segmentationId, ethPort, attachedMac, write);
+    }
 
-            // Call the InstructionBuilder Methods Containing Actions
-            InstructionUtils.createDropInstructions(ib);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructions.add(ib.build());
+    /*
+     * (Table:1) Egress Tunnel Traffic
+     * Match: Destination Ethernet Addr and Local InPort
+     * Instruction: Set TunnelID and GOTO Table Tunnel Table (n)
+     * table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
+     * actions=output:10,output:11,goto_table:2
+     */
 
-            // Add InstructionBuilder to the Instruction(s)Builder List
-            isb.setInstruction(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(TABLE_0_DEFAULT_INGRESS);
-        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:1) Egress Tunnel Traffic
-    * Match: Destination Ethernet Addr and Local InPort
-    * Instruction: Set TunnelID and GOTO Table Tunnel Table (n)
-    * table=1,tun_id=0x5,dl_dst=00:00:00:00:00:08 \
-    * actions=output:10,goto_table:2"
-    */
-    private void handleTunnelOut(Long dpidLong, Short writeTable,
-                         Short goToTableId, String segmentationId,
-                         Long OFPortOut, String attachedMac,
-                         boolean write) {
-
-        String nodeName = OPENFLOW + dpidLong;
-
-        MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-        FlowBuilder flowBuilder = new FlowBuilder();
-
-        // Create the OF Match using MatchBuilder
-        flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
-        flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
-
-        String flowId = "TunnelOut_"+segmentationId+"_"+OFPortOut+"_"+attachedMac;
-        // Add Flow Attributes
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setStrict(true);
-        flowBuilder.setBarrier(false);
-        flowBuilder.setTableId(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
-
-        if (write) {
-            // Instantiate the Builders for the OF Actions and Instructions
-            InstructionBuilder ib = new InstructionBuilder();
-            InstructionsBuilder isb = new InstructionsBuilder();
-
-            // Instructions List Stores Individual Instructions
-            List<Instruction> instructions = Lists.newArrayList();
-
-            // GOTO Instructions
-            InstructionUtils.createGotoTableInstructions(ib, goToTableId);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructions.add(ib.build());
-            // Set the Output Port/Iface
-            InstructionUtils.createOutputPortInstructions(ib, dpidLong, OFPortOut);
-            ib.setOrder(1);
-            ib.setKey(new InstructionKey(1));
-            instructions.add(ib.build());
-
-            // Add InstructionBuilder to the Instruction(s)Builder List
-            isb.setInstruction(instructions);
-
-            // Add InstructionsBuilder to FlowBuilder
-            flowBuilder.setInstructions(isb.build());
-
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            removeFlow(flowBuilder, nodeBuilder);
-        }
-    }
+    private void handleTunnelFloodOut(Long dpidLong, Short writeTable,
+            Short localTable, String segmentationId,
+            Long OFPortOut, boolean write) {
+        l2ForwardingProvider.programTunnelFloodOut(dpidLong, segmentationId, OFPortOut, write);
+    }
 
     /*
      * (Table:1) Egress VLAN Traffic
      * Match: Destination Ethernet Addr and VLAN id
-     * Instruction: GOTO Table Table 2
-     * table=1,vlan_id=0x5,dl_dst=00:00:00:00:00:08 \
-     * actions= goto_table:2"
+     * Instruction: GOTO table 2 and Output port eth interface
+     * Example: table=1,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
+     * actions=output:eth1,goto_table:2
      */
 
-     private void handleVlanOut(Long dpidLong, Short writeTable,
-                        Short goToTableId, String segmentationId,
-                        Long ethPort, String attachedMac, boolean write) {
-
-         String nodeName = OPENFLOW + dpidLong;
-
-         MatchBuilder matchBuilder = new MatchBuilder();
-         NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-         FlowBuilder flowBuilder = new FlowBuilder();
-
-         // Create the OF Match using MatchBuilder
-         flowBuilder.setMatch(
-                 MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
-         flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
-
-         String flowId = "VlanOut_"+segmentationId+"_"+ethPort+"_"+attachedMac;
-         // Add Flow Attributes
-         flowBuilder.setId(new FlowId(flowId));
-         FlowKey key = new FlowKey(new FlowId(flowId));
-         flowBuilder.setStrict(true);
-         flowBuilder.setBarrier(false);
-         flowBuilder.setTableId(writeTable);
-         flowBuilder.setKey(key);
-         flowBuilder.setFlowName(flowId);
-         flowBuilder.setHardTimeout(0);
-         flowBuilder.setIdleTimeout(0);
-
-         if (write) {
-             // Instantiate the Builders for the OF Actions and Instructions
-             InstructionBuilder ib = new InstructionBuilder();
-             InstructionsBuilder isb = new InstructionsBuilder();
-
-             // Instructions List Stores Individual Instructions
-             List<Instruction> instructions = Lists.newArrayList();
-
-             // GOTO Instructions
-             InstructionUtils.createGotoTableInstructions(ib, goToTableId);
-             ib.setOrder(0);
-             ib.setKey(new InstructionKey(0));
-             instructions.add(ib.build());
-
-             // Add InstructionBuilder to the Instruction(s)Builder List
-             isb.setInstruction(instructions);
-
-             // Add InstructionsBuilder to FlowBuilder
-             flowBuilder.setInstructions(isb.build());
-
-             writeFlow(flowBuilder, nodeBuilder);
-         } else {
-             removeFlow(flowBuilder, nodeBuilder);
-         }
-     }
-
-       /*
-    * (Table:1) Egress Tunnel Traffic
-    * Match: Destination Ethernet Addr and Local InPort
-    * Instruction: Set TunnelID and GOTO Table Tunnel Table (n)
-    * table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
-    * actions=output:10,output:11,goto_table:2
-    */
-
-    private void handleTunnelFloodOut(Long dpidLong, Short writeTable,
-                             Short localTable, String segmentationId,
-                             Long OFPortOut, boolean write) {
-
-        String nodeName = OPENFLOW + dpidLong;
-
-        MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-        FlowBuilder flowBuilder = new FlowBuilder();
-
-        // Create the OF Match using MatchBuilder
-        // Match TunnelID
-        flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
-        // Match DMAC
-
-        flowBuilder.setMatch(MatchUtils.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
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setBarrier(true);
-        flowBuilder.setTableId(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setPriority(16384);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
-
-        Flow flow = this.getFlow(flowBuilder, nodeBuilder);
-        // Instantiate the Builders for the OF Actions and Instructions
-        InstructionBuilder ib = new InstructionBuilder();
-        InstructionsBuilder isb = new InstructionsBuilder();
-        List<Instruction> instructions = Lists.newArrayList();
-        List<Instruction> existingInstructions = null;
-        if (flow != null) {
-            Instructions ins = flow.getInstructions();
-            if (ins != null) {
-                existingInstructions = ins.getInstruction();
-            }
-        }
-
-        if (write) {
-            // GOTO Instruction
-            InstructionUtils.createGotoTableInstructions(ib, localTable);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructions.add(ib.build());
-            // Set the Output Port/Iface
-            //createOutputGroupInstructions(nodeBuilder, ib, dpidLong, OFPortOut, existingInstructions);
-            createOutputPortInstructions(ib, dpidLong, OFPortOut, existingInstructions);
-            ib.setOrder(1);
-            ib.setKey(new InstructionKey(1));
-            instructions.add(ib.build());
-
-            // Add InstructionBuilder to the Instruction(s)Builder List
-            isb.setInstruction(instructions);
-
-            // Add InstructionsBuilder to FlowBuilder
-            flowBuilder.setInstructions(isb.build());
-
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            /* remove port from action list */
-            boolean flowRemove = InstructionUtils.removeOutputPortFromInstructions(ib, dpidLong,
-                    OFPortOut, existingInstructions);
-            if (flowRemove) {
-                /* if all port are removed, remove the flow too. */
-                removeFlow(flowBuilder, nodeBuilder);
-            } else {
-                /* Install instruction with new output port list*/
-                ib.setOrder(0);
-                ib.setKey(new InstructionKey(0));
-                instructions.add(ib.build());
-
-                // Add InstructionBuilder to the Instruction(s)Builder List
-                isb.setInstruction(instructions);
-
-                // Add InstructionsBuilder to FlowBuilder
-                flowBuilder.setInstructions(isb.build());
-            }
-        }
+    private void handleVlanFloodOut(Long dpidLong, Short writeTable,
+            Short localTable, String segmentationId,
+            Long ethPort, boolean write) {
+        l2ForwardingProvider.programVlanFloodOut(dpidLong, segmentationId, ethPort, write);
     }
 
     /*
-     * (Table:1) Egress VLAN Traffic
-     * Match: Destination Ethernet Addr and VLAN id
-     * Instruction: GOTO table 2 and Output port eth interface
-     * Example: table=1,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
-     * actions=output:eth1,goto_table:2
+     * (Table:1) Table Drain w/ Catch All
+     * Match: Tunnel ID
+     * Action: GOTO Local Table (10)
+     * table=2,priority=8192,tun_id=0x5 actions=drop
      */
 
-     private void handleVlanFloodOut(Long dpidLong, Short writeTable,
-                           Short localTable, String segmentationId,
-                           Long ethPort, boolean write) {
-
-         String nodeName = OPENFLOW + dpidLong;
-
-         MatchBuilder matchBuilder = new MatchBuilder();
-         NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-         FlowBuilder flowBuilder = new FlowBuilder();
-
-         // Create the OF Match using MatchBuilder
-         // Match Vlan ID
-         flowBuilder.setMatch(
-                 MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
-         // Match DMAC
-         flowBuilder.setMatch(MatchUtils.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
-         flowBuilder.setId(new FlowId(flowId));
-         FlowKey key = new FlowKey(new FlowId(flowId));
-         flowBuilder.setBarrier(true);
-         flowBuilder.setTableId(writeTable);
-         flowBuilder.setKey(key);
-         flowBuilder.setPriority(16384);
-         flowBuilder.setFlowName(flowId);
-         flowBuilder.setHardTimeout(0);
-         flowBuilder.setIdleTimeout(0);
-
-         //ToDo: Is there something to be done with result of the call to getFlow?
-
-         Flow flow = this.getFlow(flowBuilder, nodeBuilder);
-         // Instantiate the Builders for the OF Actions and Instructions
-         InstructionBuilder ib = new InstructionBuilder();
-         InstructionsBuilder isb = new InstructionsBuilder();
-         List<Instruction> instructions = Lists.newArrayList();
-
-         if (write) {
-             // GOTO Instruction
-             InstructionUtils.createGotoTableInstructions(ib, localTable);
-             ib.setOrder(0);
-             ib.setKey(new InstructionKey(0));
-             instructions.add(ib.build());
-             // Set the Output Port/Iface
-             InstructionUtils.createOutputPortInstructions(ib, dpidLong, ethPort);
-             ib.setOrder(1);
-             ib.setKey(new InstructionKey(1));
-             instructions.add(ib.build());
-
-             // Add InstructionBuilder to the Instruction(s)Builder List
-             isb.setInstruction(instructions);
-
-             // Add InstructionsBuilder to FlowBuilder
-             flowBuilder.setInstructions(isb.build());
-
-             writeFlow(flowBuilder, nodeBuilder);
-         } else {
-             removeFlow(flowBuilder, nodeBuilder);
-         }
-     }
-
-   /*
-    * (Table:1) Table Drain w/ Catch All
-    * Match: Tunnel ID
-    * Action: GOTO Local Table (10)
-    * table=2,priority=8192,tun_id=0x5 actions=drop
-    */
-
     private void handleTunnelMiss(Long dpidLong, Short writeTable,
-                          Short goToTableId, String segmentationId,
-                          boolean write) {
-
-        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(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
-
-        if (write) {
-            // Create the OF Actions and Instructions
-            InstructionBuilder ib = new InstructionBuilder();
-            InstructionsBuilder isb = new InstructionsBuilder();
-
-            // Instructions List Stores Individual Instructions
-            List<Instruction> instructions = Lists.newArrayList();
-
-            // Call the InstructionBuilder Methods Containing Actions
-            InstructionUtils.createGotoTableInstructions(ib, goToTableId);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructions.add(ib.build());
-
-            // Add InstructionBuilder to the Instruction(s)Builder List
-            isb.setInstruction(instructions);
-
-            // Add InstructionsBuilder to FlowBuilder
-            flowBuilder.setInstructions(isb.build());
-        }
-
-        String flowId = "TunnelMiss_"+segmentationId;
-        // Add Flow Attributes
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setStrict(true);
-        flowBuilder.setBarrier(false);
-        flowBuilder.setTableId(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setPriority(8192);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
-        if (write) {
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            removeFlow(flowBuilder, nodeBuilder);
-        }
+            Short goToTableId, String segmentationId,
+            boolean write) {
+        l2ForwardingProvider.programTunnelMiss(dpidLong, segmentationId, write);
     }
 
 
@@ -2070,64 +1499,11 @@ public class OF13Provider implements NetworkingProvider {
      * table=1,priority=8192,vlan_id=0x5 actions= output port:eth1
      */
 
-     private void handleVlanMiss(Long dpidLong, Short writeTable,
-                         Short goToTableId, String segmentationId,
-                         Long ethPort, boolean write) {
-
-         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(
-                 MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
-
-         if (write) {
-             // Create the OF Actions and Instructions
-             InstructionBuilder ib = new InstructionBuilder();
-             InstructionsBuilder isb = new InstructionsBuilder();
-
-             // Instructions List Stores Individual Instructions
-             List<Instruction> instructions = Lists.newArrayList();
-
-             // Call the InstructionBuilder Methods Containing Actions
-             //createGotoTableInstructions(ib, goToTableId);
-             //ib.setOrder(0);
-             //ib.setKey(new InstructionKey(0));
-             //instructions.add(ib.build());
-             // Set the Output Port/Iface
-             InstructionUtils.createOutputPortInstructions(ib, dpidLong, ethPort);
-             ib.setOrder(0);
-             ib.setKey(new InstructionKey(1));
-             instructions.add(ib.build());
-
-             // Add InstructionBuilder to the Instruction(s)Builder List
-             isb.setInstruction(instructions);
-
-             // Add InstructionsBuilder to FlowBuilder
-             flowBuilder.setInstructions(isb.build());
-         }
-
-         String flowId = "VlanMiss_"+segmentationId;
-         // Add Flow Attributes
-         flowBuilder.setId(new FlowId(flowId));
-         FlowKey key = new FlowKey(new FlowId(flowId));
-         flowBuilder.setStrict(true);
-         flowBuilder.setBarrier(false);
-         flowBuilder.setTableId(writeTable);
-         flowBuilder.setKey(key);
-         flowBuilder.setPriority(8192);
-         flowBuilder.setFlowName(flowId);
-         flowBuilder.setHardTimeout(0);
-         flowBuilder.setIdleTimeout(0);
-         if (write) {
-             writeFlow(flowBuilder, nodeBuilder);
-         } else {
-             removeFlow(flowBuilder, nodeBuilder);
-         }
-     }
+    private void handleVlanMiss(Long dpidLong, Short writeTable,
+            Short goToTableId, String segmentationId,
+            Long ethPort, boolean write) {
+        l2ForwardingProvider.programVlanMiss(dpidLong, segmentationId, ethPort, write);
+    }
 
     /*
      * (Table:1) Local Broadcast Flood
@@ -2137,54 +1513,9 @@ public class OF13Provider implements NetworkingProvider {
      */
 
     private void handleLocalUcastOut(Long dpidLong, Short writeTable,
-                             String segmentationId, Long localPort,
-                             String attachedMac, boolean write) {
-
-        String nodeName = OPENFLOW + dpidLong;
-
-        MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-        FlowBuilder flowBuilder = new FlowBuilder();
-
-        // Create the OF Match using MatchBuilder
-        flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
-        flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
-
-        String flowId = "UcastOut_"+segmentationId+"_"+localPort+"_"+attachedMac;
-        // Add Flow Attributes
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setStrict(true);
-        flowBuilder.setBarrier(false);
-        flowBuilder.setTableId(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
-
-        if (write) {
-            // Instantiate the Builders for the OF Actions and Instructions
-            InstructionBuilder ib = new InstructionBuilder();
-            InstructionsBuilder isb = new InstructionsBuilder();
-
-            // Instructions List Stores Individual Instructions
-            List<Instruction> instructions = Lists.newArrayList();
-
-            // Set the Output Port/Iface
-            InstructionUtils.createOutputPortInstructions(ib, dpidLong, localPort);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructions.add(ib.build());
-
-            // Add InstructionBuilder to the Instruction(s)Builder List
-            isb.setInstruction(instructions);
-
-            // Add InstructionsBuilder to FlowBuilder
-            flowBuilder.setInstructions(isb.build());
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            removeFlow(flowBuilder, nodeBuilder);
-        }
+            String segmentationId, Long localPort,
+            String attachedMac, boolean write) {
+        l2ForwardingProvider.programLocalUcastOut(dpidLong, segmentationId, localPort, attachedMac, write);
     }
 
     /*
@@ -2195,63 +1526,9 @@ public class OF13Provider implements NetworkingProvider {
      */
 
     private void handleLocalVlanUcastOut(Long dpidLong, Short writeTable,
-                                 String segmentationId, Long localPort,
-                                 String attachedMac, boolean write) {
-
-        String nodeName = OPENFLOW + dpidLong;
-
-        MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-        FlowBuilder flowBuilder = new FlowBuilder();
-
-        // Create the OF Match using MatchBuilder
-        flowBuilder.setMatch(
-                MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
-        flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
-
-        String flowId = "VlanUcastOut_"+segmentationId+"_"+localPort+"_"+attachedMac;
-        // Add Flow Attributes
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setStrict(true);
-        flowBuilder.setBarrier(false);
-        flowBuilder.setTableId(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
-
-        if (write) {
-            // Instantiate the Builders for the OF Actions and Instructions
-            InstructionBuilder ib = new InstructionBuilder();
-            InstructionsBuilder isb = new InstructionsBuilder();
-
-            // Instructions List Stores Individual Instructions
-            List<Instruction> instructions = Lists.newArrayList();
-            List<Instruction> instructions_tmp = Lists.newArrayList();
-
-            /* Strip vlan and store to tmp instruction space*/
-            InstructionUtils.createPopVlanInstructions(ib);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructions_tmp.add(ib.build());
-
-            // Set the Output Port/Iface
-            ib = new InstructionBuilder();
-            InstructionUtils.addOutputPortInstructions(ib, dpidLong, localPort, instructions_tmp);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructions.add(ib.build());
-
-            // Add InstructionBuilder to the Instruction(s)Builder List
-            isb.setInstruction(instructions);
-
-            // Add InstructionsBuilder to FlowBuilder
-            flowBuilder.setInstructions(isb.build());
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            removeFlow(flowBuilder, nodeBuilder);
-        }
+            String segmentationId, Long localPort,
+            String attachedMac, boolean write) {
+        l2ForwardingProvider.programLocalVlanUcastOut(dpidLong, segmentationId, localPort, attachedMac, write);
     }
 
     /*
@@ -2262,80 +1539,9 @@ public class OF13Provider implements NetworkingProvider {
      */
 
     private void handleLocalBcastOut(Long dpidLong, Short writeTable,
-                             String segmentationId, Long localPort,
-                             boolean write) {
-
-        String nodeName = OPENFLOW + dpidLong;
-
-        MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-        FlowBuilder flowBuilder = new FlowBuilder();
-
-        // Create the OF Match using MatchBuilder
-        flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
-        flowBuilder.setMatch(MatchUtils.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
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setStrict(true);
-        flowBuilder.setBarrier(false);
-        flowBuilder.setTableId(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setPriority(16384);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
-        Flow flow = this.getFlow(flowBuilder, nodeBuilder);
-        // Instantiate the Builders for the OF Actions and Instructions
-        InstructionBuilder ib = new InstructionBuilder();
-        InstructionsBuilder isb = new InstructionsBuilder();
-        List<Instruction> instructions = Lists.newArrayList();
-        List<Instruction> existingInstructions = null;
-        if (flow != null) {
-            Instructions ins = flow.getInstructions();
-            if (ins != null) {
-                existingInstructions = ins.getInstruction();
-            }
-        }
-
-        if (write) {
-            // Create output port list
-            createOutputPortInstructions(ib, dpidLong, localPort, existingInstructions);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructions.add(ib.build());
-
-            // Add InstructionBuilder to the Instruction(s)Builder List
-            isb.setInstruction(instructions);
-
-            // Add InstructionsBuilder to FlowBuilder
-            flowBuilder.setInstructions(isb.build());
-
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            boolean flowRemove = InstructionUtils.removeOutputPortFromInstructions(ib, dpidLong, localPort,
-                    existingInstructions);
-            if (flowRemove) {
-                /* if all ports are removed, remove flow */
-                removeFlow(flowBuilder, nodeBuilder);
-            } else {
-                /* Install instruction with new output port list*/
-                ib.setOrder(0);
-                ib.setKey(new InstructionKey(0));
-                instructions.add(ib.build());
-
-                // Add InstructionBuilder to the Instruction(s)Builder List
-                isb.setInstruction(instructions);
-
-                // Add InstructionsBuilder to FlowBuilder
-                flowBuilder.setInstructions(isb.build());
-
-                writeFlow(flowBuilder, nodeBuilder);
-            }
-        }
+            String segmentationId, Long localPort,
+            boolean write) {
+        l2ForwardingProvider.programLocalBcastOut(dpidLong, segmentationId, localPort, write);
     }
 
     /*
@@ -2346,110 +1552,9 @@ public class OF13Provider implements NetworkingProvider {
      */
 
     private void handleLocalVlanBcastOut(Long dpidLong, Short writeTable,
-                                 String segmentationId, Long localPort,
-                                 boolean write) {
-
-        String nodeName = OPENFLOW + dpidLong;
-
-        MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-        FlowBuilder flowBuilder = new FlowBuilder();
-
-        // Create the OF Match using MatchBuilder
-        flowBuilder.setMatch(
-                MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
-        flowBuilder.setMatch(MatchUtils.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
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setStrict(true);
-        flowBuilder.setBarrier(false);
-        flowBuilder.setTableId(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setPriority(16384);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
-        Flow flow = this.getFlow(flowBuilder, nodeBuilder);
-        // Instantiate the Builders for the OF Actions and Instructions
-        InstructionBuilder ib = new InstructionBuilder();
-        InstructionsBuilder isb = new InstructionsBuilder();
-        List<Instruction> instructions = Lists.newArrayList();
-        List<Instruction> existingInstructions = null;
-        boolean add_pop_vlan = true;
-        if (flow != null) {
-            Instructions ins = flow.getInstructions();
-            if (ins != null) {
-                existingInstructions = ins.getInstruction();
-            }
-        }
-
-        if (write) {
-            if (existingInstructions != null) {
-                /* Check if pop vlan is already the first action in action list */
-                List<Action> existingActions;
-                for (Instruction in : existingInstructions) {
-                    if (in.getInstruction() instanceof ApplyActionsCase) {
-                        existingActions = (((ApplyActionsCase)
-                                in.getInstruction()).getApplyActions().getAction());
-                        if (existingActions.get(0).getAction() instanceof PopVlanActionCase) {
-                            add_pop_vlan = false;
-                            break;
-                        }
-                    }
-                }
-            } else {
-                existingInstructions = Lists.newArrayList();
-            }
-
-            if (add_pop_vlan) {
-                /* pop vlan */
-                InstructionUtils.createPopVlanInstructions(ib);
-                ib.setOrder(0);
-                ib.setKey(new InstructionKey(0));
-                existingInstructions.add(ib.build());
-                ib = new InstructionBuilder();
-            }
-
-            // Create port list
-            //createOutputGroupInstructions(nodeBuilder, ib, dpidLong, localPort, existingInstructions);
-            createOutputPortInstructions(ib, dpidLong, localPort, existingInstructions);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructions.add(ib.build());
-
-            // Add InstructionBuilder to the Instruction(s)Builder List
-            isb.setInstruction(instructions);
-
-            // Add InstructionsBuilder to FlowBuilder
-            flowBuilder.setInstructions(isb.build());
-
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            //boolean flowRemove = removeOutputPortFromGroup(nodeBuilder, ib, dpidLong,
-            //                     localPort, existingInstructions);
-            boolean flowRemove = InstructionUtils.removeOutputPortFromInstructions(ib, dpidLong,
-                    localPort, existingInstructions);
-            if (flowRemove) {
-                /* if all ports are removed, remove flow */
-                removeFlow(flowBuilder, nodeBuilder);
-            } else {
-                /* Install instruction with new output port list*/
-                ib.setOrder(0);
-                ib.setKey(new InstructionKey(0));
-                instructions.add(ib.build());
-
-                // Add InstructionBuilder to the Instruction(s)Builder List
-                isb.setInstruction(instructions);
-
-                // Add InstructionsBuilder to FlowBuilder
-                flowBuilder.setInstructions(isb.build());
-                writeFlow(flowBuilder, nodeBuilder);
-            }
-        }
+            String segmentationId, Long localPort,
+            boolean write) {
+        l2ForwardingProvider.programLocalVlanBcastOut(dpidLong, segmentationId, localPort, write);
     }
 
     /*
@@ -2460,55 +1565,8 @@ public class OF13Provider implements NetworkingProvider {
      */
 
     private void handleLocalTableMiss(Long dpidLong, Short writeTable,
-                             String segmentationId, boolean write) {
-
-        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(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
-
-        if (write) {
-            // Create the OF Actions and Instructions
-            InstructionBuilder ib = new InstructionBuilder();
-            InstructionsBuilder isb = new InstructionsBuilder();
-
-            // Instructions List Stores Individual Instructions
-            List<Instruction> instructions = Lists.newArrayList();
-
-            // Call the InstructionBuilder Methods Containing Actions
-            InstructionUtils.createDropInstructions(ib);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructions.add(ib.build());
-
-            // Add InstructionBuilder to the Instruction(s)Builder List
-            isb.setInstruction(instructions);
-
-            // Add InstructionsBuilder to FlowBuilder
-            flowBuilder.setInstructions(isb.build());
-        }
-
-        String flowId = "LocalTableMiss_"+segmentationId;
-        // Add Flow Attributes
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setStrict(true);
-        flowBuilder.setBarrier(false);
-        flowBuilder.setTableId(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setPriority(8192);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
-        if (write) {
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            removeFlow(flowBuilder, nodeBuilder);
-        }
+            String segmentationId, boolean write) {
+        l2ForwardingProvider.programLocalTableMiss(dpidLong, segmentationId, write);
     }
 
     /*
@@ -2519,56 +1577,8 @@ public class OF13Provider implements NetworkingProvider {
      */
 
     private void handleLocalVlanTableMiss(Long dpidLong, Short writeTable,
-                                  String segmentationId, boolean write) {
-
-        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(
-                MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
-
-        if (write) {
-            // Create the OF Actions and Instructions
-            InstructionBuilder ib = new InstructionBuilder();
-            InstructionsBuilder isb = new InstructionsBuilder();
-
-            // Instructions List Stores Individual Instructions
-            List<Instruction> instructions = Lists.newArrayList();
-
-            // Call the InstructionBuilder Methods Containing Actions
-            InstructionUtils.createDropInstructions(ib);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructions.add(ib.build());
-
-            // Add InstructionBuilder to the Instruction(s)Builder List
-            isb.setInstruction(instructions);
-
-            // Add InstructionsBuilder to FlowBuilder
-            flowBuilder.setInstructions(isb.build());
-        }
-
-        String flowId = "LocalTableMiss_"+segmentationId;
-        // Add Flow Attributes
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setStrict(true);
-        flowBuilder.setBarrier(false);
-        flowBuilder.setTableId(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setPriority(8192);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
-        if (write) {
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            removeFlow(flowBuilder, nodeBuilder);
-        }
+            String segmentationId, boolean write) {
+        l2ForwardingProvider.programLocalVlanTableMiss(dpidLong, segmentationId, write);
     }
 
     private Group getGroup(GroupBuilder groupBuilder, NodeBuilder nodeBuilder) {
@@ -2586,7 +1596,7 @@ public class OF13Provider implements NetworkingProvider {
 
         InstanceIdentifier<Group> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
                 .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Group.class,
-                new GroupKey(groupBuilder.getGroupId())).build();
+                        new GroupKey(groupBuilder.getGroupId())).build();
         ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
         try {
             Optional<Group> data = readTx.read(LogicalDatastoreType.CONFIGURATION, path1).get();
@@ -2617,7 +1627,7 @@ public class OF13Provider implements NetworkingProvider {
         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
         InstanceIdentifier<Group> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
                 .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Group.class,
-                new GroupKey(groupBuilder.getGroupId())).build();
+                        new GroupKey(groupBuilder.getGroupId())).build();
         modification.put(LogicalDatastoreType.CONFIGURATION, path1, groupBuilder.build(), true /*createMissingParents*/);
 
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
@@ -2645,7 +1655,7 @@ public class OF13Provider implements NetworkingProvider {
         WriteTransaction modification = dataBroker.newWriteOnlyTransaction();
         InstanceIdentifier<Group> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
                 .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Group.class,
-                new GroupKey(groupBuilder.getGroupId())).build();
+                        new GroupKey(groupBuilder.getGroupId())).build();
         modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
 
@@ -2671,7 +1681,7 @@ public class OF13Provider implements NetworkingProvider {
 
         InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
                 .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class,
-                new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
+                        new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
 
         ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
         try {
@@ -2703,7 +1713,7 @@ public class OF13Provider implements NetworkingProvider {
         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
         InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
                 .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class,
-                new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
+                        new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
 
         //modification.put(LogicalDatastoreType.OPERATIONAL, path1, flowBuilder.build());
         modification.put(LogicalDatastoreType.CONFIGURATION, path1, flowBuilder.build(), true /*createMissingParents*/);
@@ -2734,9 +1744,9 @@ public class OF13Provider implements NetworkingProvider {
         WriteTransaction modification = dataBroker.newWriteOnlyTransaction();
         InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class)
                 .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
-                .rev130819.nodes.Node.class, nodeBuilder.getKey())
-                .augmentation(FlowCapableNode.class).child(Table.class,
-                new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
+                        .rev130819.nodes.Node.class, nodeBuilder.getKey())
+                        .augmentation(FlowCapableNode.class).child(Table.class,
+                                new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
         //modification.delete(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder));
         //modification.delete(LogicalDatastoreType.OPERATIONAL, path1);
         //modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder));
@@ -2751,62 +1761,6 @@ public class OF13Provider implements NetworkingProvider {
         }
     }
 
-    /**
-     * Create Output Port Group 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 InstructionBuilder createOutputPortInstructions(InstructionBuilder ib,
-                                                              Long dpidLong, Long port ,
-                                                              List<Instruction> instructions) {
-        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();
-        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());
-        boolean addNew = true;
-
-        /* Find the group action and get the group */
-        for (Action action : actionList) {
-            if (action.getAction() instanceof OutputActionCase) {
-                OutputActionCase opAction = (OutputActionCase)action.getAction();
-                /* If output port action already in the action list of one of the buckets, skip */
-                if (opAction.getOutputAction().getOutputNodeConnector().equals(new Uri(ncid))) {
-                    addNew = false;
-                    break;
-                }
-            }
-        }
-        if (addNew) {
-            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());
-        logger.debug("createOutputPortInstructions() : applyAction {}", aab.build());
-        return ib;
-    }
-
     /**
      * Create Output Port Group Instruction
      *
@@ -2816,9 +1770,9 @@ public class OF13Provider implements NetworkingProvider {
      * @return ib InstructionBuilder Map with instructions
      */
     protected InstructionBuilder createOutputGroupInstructions(NodeBuilder nodeBuilder,
-                                                               InstructionBuilder ib,
-                                                               Long dpidLong, Long port ,
-                                                               List<Instruction> instructions) {
+            InstructionBuilder ib,
+            Long dpidLong, Long port ,
+            List<Instruction> instructions) {
         NodeConnectorId ncid = new NodeConnectorId(OPENFLOW + dpidLong + ":" + port);
         logger.debug("createOutputGroupInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
 
@@ -2973,7 +1927,7 @@ public class OF13Provider implements NetworkingProvider {
      * @return ib InstructionBuilder Map with instructions
      */
     protected boolean removeOutputPortFromGroup(NodeBuilder nodeBuilder, InstructionBuilder ib,
-                                Long dpidLong, Long port , List<Instruction> instructions) {
+            Long dpidLong, Long port , List<Instruction> instructions) {
 
         NodeConnectorId ncid = new NodeConnectorId(OPENFLOW + dpidLong + ":" + port);
         logger.debug("removeOutputPortFromGroup() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
@@ -3114,7 +2068,7 @@ public class OF13Provider implements NetworkingProvider {
     }
 
     private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nodeBuilderToInstanceId(NodeBuilder
-                                                                                                                                             node) {
+            node) {
         return InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class,
                 node.getKey()).toInstance();
     }
index 16ce635bbca65713d381ca4158e769a20615d1d8..b3547a6028a2a3d40999669b6d04c2bf4b038e28 100644 (file)
@@ -9,10 +9,30 @@
  */
 package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services;
 
+import java.math.BigInteger;
+import java.util.List;
+
+import org.opendaylight.ovsdb.openstack.netvirt.api.ClassifierProvider;
 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.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;
+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.NodeBuilder;
+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 com.google.common.collect.Lists;
 
-public class ClassifierService extends AbstractServiceInstance {
+public class ClassifierService extends AbstractServiceInstance implements ClassifierProvider {
     public ClassifierService() {
         super(Service.CLASSIFIER);
     }
@@ -25,4 +45,367 @@ public class ClassifierService extends AbstractServiceInstance {
     public boolean isBridgeInPipeline (String nodeId) {
         return true;
     }
+
+    /*
+     * (Table:Classifier) Egress VM Traffic Towards TEP
+     * Match: Destination Ethernet Addr and OpenFlow InPort
+     * Instruction: Set TunnelID and GOTO Table Tunnel Table (n)
+     * 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);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        // 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);
+
+        if (write) {
+            // Instantiate the Builders for the OF Actions and Instructions
+            InstructionBuilder ib = new InstructionBuilder();
+            InstructionsBuilder isb = new InstructionsBuilder();
+
+            // Instructions List Stores Individual Instructions
+            List<Instruction> instructions = Lists.newArrayList();
+
+            // GOTO Instructions Need to be added first to the List
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+            // TODO Broken SetTunID
+            InstructionUtils.createSetTunnelIdInstructions(ib, new BigInteger(segmentationId));
+            ib.setOrder(1);
+            ib.setKey(new InstructionKey(1));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(instructions);
+
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+
+    /*
+     * (Table:Classifier) Egress VM Traffic Towards TEP
+     * Match: Source Ethernet Addr and OpenFlow InPort
+     * Instruction: Set VLANID and GOTO Table Egress (n)
+     * table=0,in_port=2,dl_src=00:00:00:00:00:01 \
+     * actions=push_vlan, set_field:5->vlan_id,goto_table=<Next-Table>"
+     */
+
+    @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);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        // Create the OF Match using MatchBuilder
+        flowBuilder.setMatch(MatchUtils.createEthSrcMatch(matchBuilder, new MacAddress(attachedMac)).build());
+        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);
+
+        if (write) {
+            // Instantiate the Builders for the OF Actions and Instructions
+            InstructionBuilder ib = new InstructionBuilder();
+            InstructionsBuilder isb = new InstructionsBuilder();
+
+            // Instructions List Stores Individual Instructions
+            List<Instruction> instructions = Lists.newArrayList();
+
+            // GOTO Instructions Need to be added first to the List
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+            // Set VLAN ID Instruction
+            InstructionUtils.createSetVlanInstructions(ib, new VlanId(Integer.valueOf(segmentationId)));
+            ib.setOrder(1);
+            ib.setKey(new InstructionKey(1));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(instructions);
+
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+
+    /*
+     * (Table:Classifier) Drop frames source from a VM that do not
+     * match the associated MAC address of the local VM.
+     * Match: Low priority anything not matching the VM SMAC
+     * 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);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        // Create the OF Match using MatchBuilder
+        flowBuilder.setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, inPort).build());
+
+        if (write) {
+            // Instantiate the Builders for the OF Actions and Instructions
+            InstructionBuilder ib = new InstructionBuilder();
+            InstructionsBuilder isb = new InstructionsBuilder();
+
+            // Instructions List Stores Individual Instructions
+            List<Instruction> instructions = Lists.newArrayList();
+
+            // Call the InstructionBuilder Methods Containing Actions
+            InstructionUtils.createDropInstructions(ib);
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(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);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        // 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());
+
+        if (write) {
+            // Create the OF Actions and Instructions
+            InstructionBuilder ib = new InstructionBuilder();
+            InstructionsBuilder isb = new InstructionsBuilder();
+
+            // Instructions List Stores Individual Instructions
+            List<Instruction> instructions = Lists.newArrayList();
+
+            // Call the InstructionBuilder Methods Containing Actions
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(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) Ingress VLAN Traffic
+     * Match: OpenFlow InPort and vlan ID
+     * Action: GOTO Local Table (20)
+     * table=0,vlan_id=0x5,in_port=10, actions=goto_table:2
+     */
+
+    @Override
+    public void programVlanIn(Long dpidLong, String segmentationId,  Long ethPort, boolean write) {
+
+        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(
+                MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId)))
+                .build())
+                .setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, ethPort)
+                        .build());
+
+        if (write) {
+            // Create the OF Actions and Instructions
+            InstructionBuilder ib = new InstructionBuilder();
+            InstructionsBuilder isb = new InstructionsBuilder();
+
+            // Instructions List Stores Individual Instructions
+            List<Instruction> instructions = Lists.newArrayList();
+
+            // Call the InstructionBuilder Methods Containing Actions
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(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);
+        }
+    }
+
+    /*
+     * Create an LLDP Flow Rule to encapsulate into
+     * a packet_in that is sent to the controller
+     * for topology handling.
+     * 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);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        // Create Match(es) and Set them in the FlowBuilder Object
+        flowBuilder.setMatch(MatchUtils.createEtherTypeMatch(matchBuilder, etherType).build());
+
+        // Create the OF Actions and Instructions
+        InstructionBuilder ib = new InstructionBuilder();
+        InstructionsBuilder isb = new InstructionsBuilder();
+
+        // Instructions List Stores Individual Instructions
+        List<Instruction> instructions = Lists.newArrayList();
+
+        // Call the InstructionBuilder Methods Containing Actions
+        InstructionUtils.createSendToControllerInstructions(ib);
+        ib.setOrder(0);
+        ib.setKey(new InstructionKey(0));
+        instructions.add(ib.build());
+
+        // Add InstructionBuilder to the Instruction(s)Builder List
+        isb.setInstruction(instructions);
+
+        // 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);
+    }
 }
\ No newline at end of file
index 0d2467c1fbf29cd9f9291d5dc7d367e0ed47314c..199055779da1baa34b10e3aefe3db07b6c79de3b 100644 (file)
@@ -9,10 +9,46 @@
  */
 package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services;
 
+import java.math.BigInteger;
+import java.util.List;
+
+import org.opendaylight.ovsdb.openstack.netvirt.api.L2ForwardingProvider;
 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.InstructionUtils;
+import org.opendaylight.ovsdb.utils.mdsal.openflow.MatchUtils;
+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.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.output.action._case.OutputActionBuilder;
+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.Flow;
+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.Instructions;
+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;
+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.apply.actions._case.ApplyActionsBuilder;
+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.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
 
-public class L2ForwardingService extends AbstractServiceInstance {
+public class L2ForwardingService extends AbstractServiceInstance implements L2ForwardingProvider {
+    private static final Logger logger = LoggerFactory.getLogger(L2ForwardingService.class);
     public L2ForwardingService() {
         super(Service.L2_FORWARDING);
     }
@@ -25,4 +61,920 @@ public class L2ForwardingService extends AbstractServiceInstance {
     public boolean isBridgeInPipeline (String nodeId) {
         return true;
     }
+
+    /*
+     * (Table:L2Forwarding) Local Broadcast Flood
+     * Match: Tunnel ID and dMAC
+     * Action: Output Port
+     * table=2,tun_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2 goto:<next-table>
+     */
+    @Override
+    public void programLocalUcastOut(Long dpidLong, String segmentationId,
+            Long localPort, String attachedMac, boolean write) {
+
+        String nodeName = OPENFLOW + dpidLong;
+
+        MatchBuilder matchBuilder = new MatchBuilder();
+        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        // Create the OF Match using MatchBuilder
+        flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
+        flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
+
+        String flowId = "UcastOut_"+segmentationId+"_"+localPort+"_"+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);
+
+        if (write) {
+            // Instantiate the Builders for the OF Actions and Instructions
+            InstructionBuilder ib = new InstructionBuilder();
+            InstructionsBuilder isb = new InstructionsBuilder();
+
+            // Instructions List Stores Individual Instructions
+            List<Instruction> instructions = Lists.newArrayList();
+
+            // GOTO Instructions Need to be added first to the List
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+
+            // Set the Output Port/Iface
+            InstructionUtils.createOutputPortInstructions(ib, dpidLong, localPort);
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(instructions);
+
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+    /*
+     * (Table:2) Local VLAN unicast
+     * Match: VLAN ID and dMAC
+     * Action: Output Port
+     * table=2,vlan_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
+     */
+
+    @Override
+    public void programLocalVlanUcastOut (Long dpidLong, String segmentationId, Long localPort, String attachedMac, boolean write) {
+
+        String nodeName = OPENFLOW + dpidLong;
+
+        MatchBuilder matchBuilder = new MatchBuilder();
+        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        // Create the OF Match using MatchBuilder
+        flowBuilder.setMatch(
+                MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
+        flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
+
+        String flowId = "VlanUcastOut_"+segmentationId+"_"+localPort+"_"+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);
+
+        if (write) {
+            // Instantiate the Builders for the OF Actions and Instructions
+            InstructionBuilder ib = new InstructionBuilder();
+            InstructionsBuilder isb = new InstructionsBuilder();
+
+            // Instructions List Stores Individual Instructions
+            List<Instruction> instructions = Lists.newArrayList();
+            List<Instruction> instructions_tmp = Lists.newArrayList();
+
+            // GOTO Instructions Need to be added first to the List
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+
+            /* Strip vlan and store to tmp instruction space*/
+            InstructionUtils.createPopVlanInstructions(ib);
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions_tmp.add(ib.build());
+
+            // Set the Output Port/Iface
+            ib = new InstructionBuilder();
+            InstructionUtils.addOutputPortInstructions(ib, dpidLong, localPort, instructions_tmp);
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(instructions);
+
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+
+    /*
+     * (Table:2) Local Broadcast Flood
+     * Match: Tunnel ID and dMAC (::::FF:FF)
+     * table=2,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
+     * actions=output:2,3,4,5
+     */
+
+    @Override
+    public void programLocalBcastOut(Long dpidLong, String segmentationId, Long localPort, boolean write) {
+
+        String nodeName = OPENFLOW + dpidLong;
+
+        MatchBuilder matchBuilder = new MatchBuilder();
+        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        // Create the OF Match using MatchBuilder
+        flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
+        flowBuilder.setMatch(MatchUtils.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
+        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.setPriority(16384);
+        flowBuilder.setFlowName(flowId);
+        flowBuilder.setHardTimeout(0);
+        flowBuilder.setIdleTimeout(0);
+        Flow flow = this.getFlow(flowBuilder, nodeBuilder);
+        // Instantiate the Builders for the OF Actions and Instructions
+        InstructionBuilder ib = new InstructionBuilder();
+        InstructionsBuilder isb = new InstructionsBuilder();
+        List<Instruction> instructions = Lists.newArrayList();
+        List<Instruction> existingInstructions = null;
+        if (flow != null) {
+            Instructions ins = flow.getInstructions();
+            if (ins != null) {
+                existingInstructions = ins.getInstruction();
+            }
+        }
+
+        if (write) {
+            // Create output port list
+            createOutputPortInstructions(ib, dpidLong, localPort, existingInstructions);
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(instructions);
+
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            boolean flowRemove = InstructionUtils.removeOutputPortFromInstructions(ib, dpidLong, localPort,
+                    existingInstructions);
+            if (flowRemove) {
+                /* if all ports are removed, remove flow */
+                removeFlow(flowBuilder, nodeBuilder);
+            } else {
+                /* Install instruction with new output port list*/
+                ib.setOrder(0);
+                ib.setKey(new InstructionKey(0));
+                instructions.add(ib.build());
+
+                // Add InstructionBuilder to the Instruction(s)Builder List
+                isb.setInstruction(instructions);
+
+                // Add InstructionsBuilder to FlowBuilder
+                flowBuilder.setInstructions(isb.build());
+
+                writeFlow(flowBuilder, nodeBuilder);
+            }
+        }
+    }
+
+    /*
+     * (Table:2) Local VLAN Broadcast Flood
+     * Match: vlan ID and dMAC (::::FF:FF)
+     * table=2,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
+     * actions=strip_vlan, output:2,3,4,5
+     */
+
+    @Override
+    public void programLocalVlanBcastOut(Long dpidLong,
+            String segmentationId, Long localPort,
+            boolean write) {
+
+        String nodeName = OPENFLOW + dpidLong;
+
+        MatchBuilder matchBuilder = new MatchBuilder();
+        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        // Create the OF Match using MatchBuilder
+        flowBuilder.setMatch(
+                MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
+        flowBuilder.setMatch(MatchUtils.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
+        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.setPriority(16384);
+        flowBuilder.setFlowName(flowId);
+        flowBuilder.setHardTimeout(0);
+        flowBuilder.setIdleTimeout(0);
+        Flow flow = this.getFlow(flowBuilder, nodeBuilder);
+        // Instantiate the Builders for the OF Actions and Instructions
+        InstructionBuilder ib = new InstructionBuilder();
+        InstructionsBuilder isb = new InstructionsBuilder();
+        List<Instruction> instructions = Lists.newArrayList();
+        List<Instruction> existingInstructions = null;
+        boolean add_pop_vlan = true;
+        if (flow != null) {
+            Instructions ins = flow.getInstructions();
+            if (ins != null) {
+                existingInstructions = ins.getInstruction();
+            }
+        }
+
+        if (write) {
+            if (existingInstructions != null) {
+                /* Check if pop vlan is already the first action in action list */
+                List<Action> existingActions;
+                for (Instruction in : existingInstructions) {
+                    if (in.getInstruction() instanceof ApplyActionsCase) {
+                        existingActions = (((ApplyActionsCase)
+                                in.getInstruction()).getApplyActions().getAction());
+                        if (existingActions.get(0).getAction() instanceof PopVlanActionCase) {
+                            add_pop_vlan = false;
+                            break;
+                        }
+                    }
+                }
+            } else {
+                existingInstructions = Lists.newArrayList();
+            }
+
+            if (add_pop_vlan) {
+                /* pop vlan */
+                InstructionUtils.createPopVlanInstructions(ib);
+                ib.setOrder(0);
+                ib.setKey(new InstructionKey(0));
+                existingInstructions.add(ib.build());
+                ib = new InstructionBuilder();
+            }
+
+            // Create port list
+            //createOutputGroupInstructions(nodeBuilder, ib, dpidLong, localPort, existingInstructions);
+            createOutputPortInstructions(ib, dpidLong, localPort, existingInstructions);
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(instructions);
+
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            //boolean flowRemove = removeOutputPortFromGroup(nodeBuilder, ib, dpidLong,
+            //                     localPort, existingInstructions);
+            boolean flowRemove = InstructionUtils.removeOutputPortFromInstructions(ib, dpidLong,
+                    localPort, existingInstructions);
+            if (flowRemove) {
+                /* if all ports are removed, remove flow */
+                removeFlow(flowBuilder, nodeBuilder);
+            } else {
+                /* Install instruction with new output port list*/
+                ib.setOrder(0);
+                ib.setKey(new InstructionKey(0));
+                instructions.add(ib.build());
+
+                // Add InstructionBuilder to the Instruction(s)Builder List
+                isb.setInstruction(instructions);
+
+                // Add InstructionsBuilder to FlowBuilder
+                flowBuilder.setInstructions(isb.build());
+                writeFlow(flowBuilder, nodeBuilder);
+            }
+        }
+    }
+
+    /*
+     * (Table:1) Local Table Miss
+     * Match: Any Remaining Flows w/a TunID
+     * Action: Drop w/ a low priority
+     * table=2,priority=8192,tun_id=0x5 actions=drop
+     */
+
+    @Override
+    public void programLocalTableMiss(Long dpidLong, String segmentationId, boolean write) {
+
+        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(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
+
+        if (write) {
+            // Create the OF Actions and Instructions
+            InstructionBuilder ib = new InstructionBuilder();
+            InstructionsBuilder isb = new InstructionsBuilder();
+
+            // Instructions List Stores Individual Instructions
+            List<Instruction> instructions = Lists.newArrayList();
+
+            // Call the InstructionBuilder Methods Containing Actions
+            InstructionUtils.createDropInstructions(ib);
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(instructions);
+
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+        }
+
+        String flowId = "LocalTableMiss_"+segmentationId;
+        // 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.setPriority(8192);
+        flowBuilder.setFlowName(flowId);
+        flowBuilder.setHardTimeout(0);
+        flowBuilder.setIdleTimeout(0);
+        if (write) {
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+
+    /*
+     * (Table:1) Local Table Miss
+     * Match: Any Remaining Flows w/a VLAN ID
+     * Action: Drop w/ a low priority
+     * table=2,priority=8192,vlan_id=0x5 actions=drop
+     */
+
+    @Override
+    public void programLocalVlanTableMiss(Long dpidLong, String segmentationId, boolean write) {
+
+        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(
+                MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
+
+        if (write) {
+            // Create the OF Actions and Instructions
+            InstructionBuilder ib = new InstructionBuilder();
+            InstructionsBuilder isb = new InstructionsBuilder();
+
+            // Instructions List Stores Individual Instructions
+            List<Instruction> instructions = Lists.newArrayList();
+
+            // Call the InstructionBuilder Methods Containing Actions
+            InstructionUtils.createDropInstructions(ib);
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(instructions);
+
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+        }
+
+        String flowId = "LocalTableMiss_"+segmentationId;
+        // 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.setPriority(8192);
+        flowBuilder.setFlowName(flowId);
+        flowBuilder.setHardTimeout(0);
+        flowBuilder.setIdleTimeout(0);
+        if (write) {
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+
+
+    /*
+     * (Table:1) Egress Tunnel Traffic
+     * Match: Destination Ethernet Addr and Local InPort
+     * Instruction: Set TunnelID and GOTO Table Tunnel Table (n)
+     * table=1,tun_id=0x5,dl_dst=00:00:00:00:00:08 \
+     * actions=output:10,goto_table:2"
+     */
+    // TODO : Check on the reason why the original handleTunnelOut was chaining the traffic to table 2
+    @Override
+    public void programTunnelOut(Long dpidLong, String segmentationId, Long OFPortOut, String attachedMac, boolean write) {
+
+        String nodeName = OPENFLOW + dpidLong;
+
+        MatchBuilder matchBuilder = new MatchBuilder();
+        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        // Create the OF Match using MatchBuilder
+        flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
+        flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
+
+        String flowId = "TunnelOut_"+segmentationId+"_"+OFPortOut+"_"+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);
+
+        if (write) {
+            // Instantiate the Builders for the OF Actions and Instructions
+            InstructionBuilder ib = new InstructionBuilder();
+            InstructionsBuilder isb = new InstructionsBuilder();
+
+            // Instructions List Stores Individual Instructions
+            List<Instruction> instructions = Lists.newArrayList();
+
+            // GOTO Instructions
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+            // Set the Output Port/Iface
+            InstructionUtils.createOutputPortInstructions(ib, dpidLong, OFPortOut);
+            ib.setOrder(1);
+            ib.setKey(new InstructionKey(1));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(instructions);
+
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+
+    /*
+     * (Table:1) Egress VLAN Traffic
+     * Match: Destination Ethernet Addr and VLAN id
+     * Instruction: GOTO Table Table 2
+     * table=1,vlan_id=0x5,dl_dst=00:00:00:00:00:08 \
+     * actions= goto_table:2"
+     */
+    // TODO : Check on the reason why the original handleTunnelOut was chaining the traffic to table 2
+    @Override
+    public void programVlanOut(Long dpidLong, String segmentationId, Long ethPort, String attachedMac, boolean write) {
+
+        String nodeName = OPENFLOW + dpidLong;
+
+        MatchBuilder matchBuilder = new MatchBuilder();
+        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        // Create the OF Match using MatchBuilder
+        flowBuilder.setMatch(
+                MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
+        flowBuilder.setMatch(MatchUtils.createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
+
+        String flowId = "VlanOut_"+segmentationId+"_"+ethPort+"_"+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);
+
+        if (write) {
+            // Instantiate the Builders for the OF Actions and Instructions
+            InstructionBuilder ib = new InstructionBuilder();
+            InstructionsBuilder isb = new InstructionsBuilder();
+
+            // Instructions List Stores Individual Instructions
+            List<Instruction> instructions = Lists.newArrayList();
+
+            // GOTO Instructions
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(instructions);
+
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+
+    /*
+     * (Table:1) Egress Tunnel Traffic
+     * Match: Destination Ethernet Addr and Local InPort
+     * Instruction: Set TunnelID and GOTO Table Tunnel Table (n)
+     * table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
+     * actions=output:10,output:11,goto_table:2
+     */
+    @Override
+    public void programTunnelFloodOut(Long dpidLong, String segmentationId, Long OFPortOut, boolean write) {
+
+        String nodeName = OPENFLOW + dpidLong;
+
+        MatchBuilder matchBuilder = new MatchBuilder();
+        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        // Create the OF Match using MatchBuilder
+        // Match TunnelID
+        flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
+        // Match DMAC
+
+        flowBuilder.setMatch(MatchUtils.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
+        flowBuilder.setId(new FlowId(flowId));
+        FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setBarrier(true);
+        flowBuilder.setTableId(getTable());
+        flowBuilder.setKey(key);
+        flowBuilder.setPriority(16384);
+        flowBuilder.setFlowName(flowId);
+        flowBuilder.setHardTimeout(0);
+        flowBuilder.setIdleTimeout(0);
+
+        Flow flow = this.getFlow(flowBuilder, nodeBuilder);
+        // Instantiate the Builders for the OF Actions and Instructions
+        InstructionBuilder ib = new InstructionBuilder();
+        InstructionsBuilder isb = new InstructionsBuilder();
+        List<Instruction> instructions = Lists.newArrayList();
+        List<Instruction> existingInstructions = null;
+        if (flow != null) {
+            Instructions ins = flow.getInstructions();
+            if (ins != null) {
+                existingInstructions = ins.getInstruction();
+            }
+        }
+
+        if (write) {
+            // GOTO Instruction
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+            // Set the Output Port/Iface
+            //createOutputGroupInstructions(nodeBuilder, ib, dpidLong, OFPortOut, existingInstructions);
+            createOutputPortInstructions(ib, dpidLong, OFPortOut, existingInstructions);
+            ib.setOrder(1);
+            ib.setKey(new InstructionKey(1));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(instructions);
+
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            /* remove port from action list */
+            boolean flowRemove = InstructionUtils.removeOutputPortFromInstructions(ib, dpidLong,
+                    OFPortOut, existingInstructions);
+            if (flowRemove) {
+                /* if all port are removed, remove the flow too. */
+                removeFlow(flowBuilder, nodeBuilder);
+            } else {
+                /* Install instruction with new output port list*/
+                ib.setOrder(0);
+                ib.setKey(new InstructionKey(0));
+                instructions.add(ib.build());
+
+                // Add InstructionBuilder to the Instruction(s)Builder List
+                isb.setInstruction(instructions);
+
+                // Add InstructionsBuilder to FlowBuilder
+                flowBuilder.setInstructions(isb.build());
+            }
+        }
+    }
+
+    /*
+     * (Table:1) Egress VLAN Traffic
+     * Match: Destination Ethernet Addr and VLAN id
+     * Instruction: GOTO table 2 and Output port eth interface
+     * Example: table=1,priority=16384,vlan_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
+     * actions=output:eth1,goto_table:2
+     */
+
+    @Override
+    public void programVlanFloodOut(Long dpidLong, String segmentationId, Long ethPort, boolean write) {
+
+        String nodeName = OPENFLOW + dpidLong;
+
+        MatchBuilder matchBuilder = new MatchBuilder();
+        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        // Create the OF Match using MatchBuilder
+        // Match Vlan ID
+        flowBuilder.setMatch(
+                MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
+        // Match DMAC
+        flowBuilder.setMatch(MatchUtils.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
+        flowBuilder.setId(new FlowId(flowId));
+        FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setBarrier(true);
+        flowBuilder.setTableId(getTable());
+        flowBuilder.setKey(key);
+        flowBuilder.setPriority(16384);
+        flowBuilder.setFlowName(flowId);
+        flowBuilder.setHardTimeout(0);
+        flowBuilder.setIdleTimeout(0);
+
+        //ToDo: Is there something to be done with result of the call to getFlow?
+
+        Flow flow = this.getFlow(flowBuilder, nodeBuilder);
+        // Instantiate the Builders for the OF Actions and Instructions
+        InstructionBuilder ib = new InstructionBuilder();
+        InstructionsBuilder isb = new InstructionsBuilder();
+        List<Instruction> instructions = Lists.newArrayList();
+
+        if (write) {
+            // GOTO Instruction
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+            // Set the Output Port/Iface
+            InstructionUtils.createOutputPortInstructions(ib, dpidLong, ethPort);
+            ib.setOrder(1);
+            ib.setKey(new InstructionKey(1));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(instructions);
+
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+
+    /*
+     * (Table:1) Table Drain w/ Catch All
+     * Match: Tunnel ID
+     * Action: GOTO Local Table (10)
+     * table=2,priority=8192,tun_id=0x5 actions=drop
+     */
+    @Override
+    public void programTunnelMiss(Long dpidLong, String segmentationId, boolean write) {
+
+        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(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
+
+        if (write) {
+            // Create the OF Actions and Instructions
+            InstructionBuilder ib = new InstructionBuilder();
+            InstructionsBuilder isb = new InstructionsBuilder();
+
+            // Instructions List Stores Individual Instructions
+            List<Instruction> instructions = Lists.newArrayList();
+
+            // Call the InstructionBuilder Methods Containing Actions
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(instructions);
+
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+        }
+
+        String flowId = "TunnelMiss_"+segmentationId;
+        // 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.setPriority(8192);
+        flowBuilder.setFlowName(flowId);
+        flowBuilder.setHardTimeout(0);
+        flowBuilder.setIdleTimeout(0);
+        if (write) {
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+
+    /*
+     * (Table:1) Table Drain w/ Catch All
+     * Match: Vlan ID
+     * Action: Output port eth interface
+     * table=1,priority=8192,vlan_id=0x5 actions= output port:eth1
+     */
+
+    @Override
+    public void programVlanMiss(Long dpidLong, String segmentationId, Long ethPort, boolean write) {
+
+        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(
+                MatchUtils.createVlanIdMatch(matchBuilder, new VlanId(Integer.valueOf(segmentationId))).build());
+
+        if (write) {
+            // Create the OF Actions and Instructions
+            InstructionBuilder ib = new InstructionBuilder();
+            InstructionsBuilder isb = new InstructionsBuilder();
+
+            // Instructions List Stores Individual Instructions
+            List<Instruction> instructions = Lists.newArrayList();
+
+            // Call the InstructionBuilder Methods Containing Actions
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructions.add(ib.build());
+
+            // Set the Output Port/Iface
+            InstructionUtils.createOutputPortInstructions(ib, dpidLong, ethPort);
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(1));
+            instructions.add(ib.build());
+
+            // Add InstructionBuilder to the Instruction(s)Builder List
+            isb.setInstruction(instructions);
+
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+        }
+
+        String flowId = "VlanMiss_"+segmentationId;
+        // 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.setPriority(8192);
+        flowBuilder.setFlowName(flowId);
+        flowBuilder.setHardTimeout(0);
+        flowBuilder.setIdleTimeout(0);
+        if (write) {
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+
+    /**
+     * Create Output Port Group 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 InstructionBuilder createOutputPortInstructions(InstructionBuilder ib,
+            Long dpidLong, Long port ,
+            List<Instruction> instructions) {
+        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();
+        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());
+                boolean addNew = true;
+
+                /* Find the group action and get the group */
+                for (Action action : actionList) {
+                    if (action.getAction() instanceof OutputActionCase) {
+                        OutputActionCase opAction = (OutputActionCase)action.getAction();
+                        /* If output port action already in the action list of one of the buckets, skip */
+                        if (opAction.getOutputAction().getOutputNodeConnector().equals(new Uri(ncid))) {
+                            addNew = false;
+                            break;
+                        }
+                    }
+                }
+                if (addNew) {
+                    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());
+                logger.debug("createOutputPortInstructions() : applyAction {}", aab.build());
+                return ib;
+    }
 }
\ No newline at end of file
index 5e38d1507743d191ebb373d13c45a803ea535b5a..347631f4294f4d1ace315e592cfdfb31a0fe1fe8 100644 (file)
@@ -10,6 +10,9 @@
 
 package org.opendaylight.ovsdb.openstack.netvirt;
 
+import java.util.Properties;
+
+import org.apache.felix.dm.Component;
 import org.opendaylight.controller.networkconfig.neutron.INeutronFirewallAware;
 import org.opendaylight.controller.networkconfig.neutron.INeutronFirewallPolicyAware;
 import org.opendaylight.controller.networkconfig.neutron.INeutronFirewallRuleAware;
@@ -17,6 +20,7 @@ import org.opendaylight.controller.networkconfig.neutron.INeutronFloatingIPAware
 import org.opendaylight.controller.networkconfig.neutron.INeutronLoadBalancerAware;
 import org.opendaylight.controller.networkconfig.neutron.INeutronLoadBalancerCRUD;
 import org.opendaylight.controller.networkconfig.neutron.INeutronLoadBalancerPoolCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronLoadBalancerPoolMemberAware;
 import org.opendaylight.controller.networkconfig.neutron.INeutronLoadBalancerPoolMemberCRUD;
 import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkAware;
 import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
@@ -25,8 +29,8 @@ import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;
 import org.opendaylight.controller.networkconfig.neutron.INeutronRouterAware;
 import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityGroupAware;
 import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityRuleAware;
-import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;
 import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetAware;
+import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;
 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
 import org.opendaylight.controller.switchmanager.IInventoryListener;
 import org.opendaylight.controller.switchmanager.ISwitchManager;
@@ -57,9 +61,6 @@ import org.opendaylight.ovsdb.openstack.netvirt.impl.VlanConfigurationCacheImpl;
 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
 import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
 import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryListener;
-import org.apache.felix.dm.Component;
-
-import java.util.Properties;
 
 /**
  * OSGi bundle activator for the OVSDB Neutron Interface.
@@ -264,7 +265,7 @@ public class Activator extends ComponentActivatorAbstractBase {
             Properties lbaasPoolMemberHandlerProperties = new Properties();
             lbaasPoolMemberHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
                     AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER_POOL_MEMBER);
-            c.setInterface(new String[] {INeutronLoadBalancerAware.class.getName()},
+            c.setInterface(new String[] {INeutronLoadBalancerPoolMemberAware.class.getName()},
                                          lbaasPoolMemberHandlerProperties);
             c.add(createServiceDependency().setService(EventDispatcher.class).setRequired(true));
             c.add(createServiceDependency().setService(INeutronPortCRUD.class).setRequired(true));
@@ -336,7 +337,6 @@ public class Activator extends ComponentActivatorAbstractBase {
              * Either that, or we should do service lookup at runtime based on getProvider().getName()
              * This is a shortcut as for now there will only be one implementation of these classes.
              */
-            c.add(createServiceDependency().setService(MultiTenantAwareRouter.class).setRequired(false));
             c.add(createServiceDependency().setService(ArpProvider.class).setRequired(false));
             c.add(createServiceDependency().setService(InboundNatProvider.class).setRequired(false));
             c.add(createServiceDependency().setService(OutboundNatProvider.class).setRequired(false));
diff --git a/openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/api/ClassifierProvider.java b/openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/api/ClassifierProvider.java
new file mode 100644 (file)
index 0000000..d85f64a
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2014 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.api;
+
+
+/**
+ *  This interface allows Classifier flows to be written to devices
+ */
+public interface ClassifierProvider {
+    public void programLocalInPort(Long dpidLong, String segmentationId, Long inPort, String attachedMac, boolean write);
+    public void programLocalInPortSetVlan(Long dpidLong, String segmentationId, Long inPort, String attachedMac, boolean write);
+    public void programDropSrcIface(Long dpidLong, Long inPort, boolean write);
+    public void programTunnelIn(Long dpidLong, String segmentationId, Long ofPort, boolean write);
+    public void programVlanIn(Long dpidLong, String segmentationId, Long ethPort, boolean write);
+    public void programLLDPPuntRule(Long dpidLong);
+}
index d479742be043f1ccb7d3ef13b248e372d6e2cca1..ff946e57f7aeaea4948e423a55c4648effacc3d6 100644 (file)
@@ -117,4 +117,12 @@ public interface ConfigurationService {
      * @return the OpenFlow version to use
      */
     public String getOpenflowVersion(Node node);
+
+    /**
+     * Returns the MacAddress to be used for the default gateway by the {@link L3ForwardingProvider}
+     * There is no default.
+     * @param node the node to query
+     * @return the MacAddress to use for the default gateway; or null if none is configured.
+     */
+    public String getDefaultGatewayMacAddress(Node node);
 }
\ No newline at end of file
diff --git a/openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/api/L2ForwardingProvider.java b/openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/api/L2ForwardingProvider.java
new file mode 100644 (file)
index 0000000..caf00ea
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2014 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.api;
+
+/**
+ *  This interface allows L2Forwarding flows to be written to devices
+ */
+public interface L2ForwardingProvider {
+    public void programLocalUcastOut(Long dpidLong, String segmentationId, Long localPort, String attachedMac, boolean write);
+    public void programLocalVlanUcastOut(Long dpidLong, String segmentationId, Long localPort, String attachedMac, boolean write);
+    public void programLocalBcastOut(Long dpidLong, String segmentationId, Long localPort, boolean write);
+    public void programLocalVlanBcastOut(Long dpidLong, String segmentationId, Long localPort, boolean write);
+    public void programLocalTableMiss(Long dpidLong, String segmentationId, boolean write);
+    public void programLocalVlanTableMiss(Long dpidLong, String segmentationId, boolean write);
+    public void programTunnelOut(Long dpidLong, String segmentationId, Long OFPortOut, String attachedMac, boolean write);
+    public void programVlanOut(Long dpidLong, String segmentationId, Long ethPort, String attachedMac, boolean write);
+    public void programTunnelFloodOut(Long dpidLong, String segmentationId, Long OFPortOut, boolean write);
+    public void programVlanFloodOut(Long dpidLong, String segmentationId, Long ethPort, boolean write);
+    public void programTunnelMiss(Long dpidLong, String segmentationId, boolean write);
+    public void programVlanMiss(Long dpidLong, String segmentationId, Long ethPort, boolean write);
+}
index f9031388dd7d4233055fb4538468a34f26e92853..329cd5647d7042d530157f76dcea3aa7fe029d7e 100644 (file)
@@ -207,4 +207,11 @@ public class ConfigurationServiceImpl implements org.opendaylight.ovsdb.openstac
 
         return Constants.OPENFLOW13;
     }
+
+    @Override
+    public String getDefaultGatewayMacAddress(Node node) {
+        final String l3gatewayForNode =
+            node != null ? System.getProperty("ovsdb.l3gateway.mac." + node.getNodeIDString()) : null;
+        return l3gatewayForNode != null ? l3gatewayForNode : System.getProperty("ovsdb.l3gateway.mac");
+    }
 }
index 79bace8594ab90322a2362606fe27db7c1f29450..f11ae09af60d74373bf2623f9f38b787b4f91df2 100644 (file)
@@ -47,6 +47,7 @@ import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -85,8 +86,10 @@ public class NeutronL3Adapter {
     private Set<String> outboundIpRewriteExclusionCache;
     private Set<String> routerInterfacesCache;
     private Set<String> staticArpEntryCache;
+    private Set<String> l3ForwardingCache;
     private Set<String> defaultRouteCache;
-    private Map<String, String> networkId2MacCache;
+    private Map<String, String> networkId2RouterMacCache;
+    private Map<String, NeutronRouter_Interface> routerInterfaceCache;
 
     void init() {
         this.inboundIpRewriteCache = new HashSet<>();
@@ -95,8 +98,10 @@ public class NeutronL3Adapter {
         this.outboundIpRewriteExclusionCache = new HashSet<>();
         this.routerInterfacesCache = new HashSet<>();
         this.staticArpEntryCache = new HashSet<>();
+        this.l3ForwardingCache = new HashSet<>();
         this.defaultRouteCache = new HashSet<>();
-        this.networkId2MacCache = new HashMap();
+        this.networkId2RouterMacCache = new HashMap<>();
+        this.routerInterfaceCache = new HashMap<>();
     }
 
     //
@@ -105,20 +110,21 @@ public class NeutronL3Adapter {
 
     public void handleNeutronSubnetEvent(final NeutronSubnet subnet, Action action) {
         logger.debug("Neutron subnet {} event : {}", action, subnet.toString());
-
-        // TODO
     }
 
     public void handleNeutronPortEvent(final NeutronPort neutronPort, Action action) {
         logger.debug("Neutron port {} event : {}", action, neutronPort.toString());
 
-        // TODO
+        final boolean isAdd = action == Action.ADD;
+        final boolean isDelete = action == Action.DELETE;
+
+        if (isAdd || isDelete) {
+            updateL3ForNeutronPort(neutronPort, null /*neutronRouterInterfaceFilter*/, isDelete);
+        }
     }
 
     public void handleNeutronRouterEvent(final NeutronRouter neutronRouter, Action action) {
         logger.debug("Neutron router {} event : {}", action, neutronRouter.toString());
-
-        // TODO
     }
 
     public void handleNeutronRouterInterfaceEvent(final NeutronRouter neutronRouter,
@@ -130,7 +136,28 @@ public class NeutronL3Adapter {
                      action,
                      neutronRouterInterface.getSubnetUUID());
 
-        this.programFlowsForNeutronRouterInterface(neutronRouterInterface, action == Action.DELETE);
+        final boolean isAdd = action == Action.ADD;
+        final boolean isDelete = action == Action.DELETE;
+
+        // add 'before'
+        if (isAdd) {
+            routerInterfaceCache.put(neutronRouterInterface.getID(), neutronRouterInterface);
+        }
+        this.programFlowsForNeutronRouterInterface(neutronRouterInterface, isDelete, null /*nodeFilter*/);
+
+        // As neutron router interface is added/removed, we need to iterate through all the neutron ports and
+        // see if they are affected by l3
+        //
+        if (isAdd || isDelete) {
+            for (NeutronPort neutronPort : neutronPortCache.getAllPorts()) {
+                updateL3ForNeutronPort(neutronPort, neutronRouterInterface, isDelete);
+            }
+        }
+
+        // delete 'after'
+        if (isDelete) {
+            routerInterfaceCache.remove(neutronRouterInterface.getID());
+        }
     }
 
     public void handleNeutronFloatingIPEvent(final NeutronFloatingIP neutronFloatingIP,
@@ -140,13 +167,11 @@ public class NeutronL3Adapter {
                      neutronFloatingIP.getFloatingIPAddress(),
                      neutronFloatingIP.getFloatingNetworkUUID());
 
-        this.programFlowsForFloatingIP(neutronFloatingIP, action == Action.DELETE);
+        programFlowsForFloatingIP(neutronFloatingIP, action == Action.DELETE);
     }
 
     public void handleNeutronNetworkEvent(final NeutronNetwork neutronNetwork, Action action) {
         logger.debug("neutronNetwork {}: network: {}", action, neutronNetwork);
-
-        // TODO
     }
 
     //
@@ -155,16 +180,123 @@ public class NeutronL3Adapter {
     public void handleInterfaceEvent(final Node node, final Interface intf, final NeutronNetwork neutronNetwork,
                                      Action action) {
         logger.debug("southbound interface {} node:{} interface:{}, neutronNetwork:{}",
-                     action, node, intf, neutronNetwork);
-
-        // TODO
+                     action, node, intf.getName(), neutronNetwork);
     }
 
     //
     // Internal helpers
     //
+    private void updateL3ForNeutronPort(final NeutronPort neutronPort,
+                                        final NeutronRouter_Interface neutronRouterInterfaceFilter,
+                                        final boolean isDelete) {
+
+        final String networkUUID = neutronPort.getNetworkUUID();
+        final String routerMacAddress = networkId2RouterMacCache.get(networkUUID);
+
+        // If there is no router interface handling the networkUUID, we are done
+        if (routerMacAddress == null || routerMacAddress.isEmpty()) {
+            return;
+        }
+
+        // If this is the neutron port for the router interface itself, ignore it as well
+        if (routerMacAddress.equalsIgnoreCase(neutronPort.getMacAddress())) {
+            return;
+        }
+
+        final NeutronNetwork neutronNetwork = neutronNetworkCache.getNetwork(networkUUID);
+        final String providerSegmentationId = neutronNetwork != null ?
+                                              neutronNetwork.getProviderSegmentationID() : null;
+        final String tenantMac = neutronPort.getMacAddress();
+
+        if (providerSegmentationId == null || providerSegmentationId.isEmpty() ||
+            tenantMac == null || tenantMac.isEmpty()) {
+            return;  // done: go no further w/out all the info needed...
+        }
+
+        final Action action = isDelete ? Action.DELETE : Action.ADD;
+        List<Node> nodes = connectionService.getNodes();
+        for (Node node : nodes) {
+            final Long dpid = getDpid(node);
+            final Action actionForNode =
+                    tenantNetworkManager.isTenantNetworkPresentInNode(node, providerSegmentationId) ?
+                    action : Action.DELETE;
+            for (Neutron_IPs neutronIP : neutronPort.getFixedIPs()) {
+                final String tenantIpStr = neutronIP.getIpAddress();
+                if (tenantIpStr.isEmpty()) {
+                    continue;
+                }
+                // If router interface was provided, make sure subnetId matches
+                if (neutronRouterInterfaceFilter != null &&
+                    !neutronRouterInterfaceFilter.getSubnetUUID().equalsIgnoreCase(neutronIP.getSubnetUUID())) {
+                    continue;
+                }
+
+                // Configure L3 fwd
+                programL3ForwardingStage1(node, dpid, providerSegmentationId, tenantMac, tenantIpStr, actionForNode);
+
+                // Configure distributed ARP responder
+                programStaticArpStage1(node, dpid, providerSegmentationId, tenantMac, tenantIpStr, actionForNode);
+            }
+        }
+    }
+
+    private void programL3ForwardingStage1(Node node, Long dpid, String providerSegmentationId,
+                                           String macAddress, String ipStr,
+                                           Action actionForNode) {
+        // Based on the local cache, figure out whether programming needs to occur. To do this, we
+        // will look at desired action for node.
+        //
+        final String cacheKey = node.toString() + ":" + providerSegmentationId + ":" + ipStr;
+        final Boolean isProgrammed = l3ForwardingCache.contains(cacheKey);
+
+        if (actionForNode == Action.DELETE && isProgrammed == Boolean.FALSE)
+            return;
+        if (actionForNode == Action.ADD && isProgrammed == Boolean.TRUE)
+            return;
+
+        Status status = this.programL3ForwardingStage2(node, dpid, providerSegmentationId,
+                                                       macAddress, ipStr, actionForNode);
+        if (status.isSuccess()) {
+            // Update cache
+            if (actionForNode == Action.ADD) {
+                l3ForwardingCache.add(cacheKey);
+            } else {
+                l3ForwardingCache.remove(cacheKey);
+            }
+        }
+    }
+
+    private Status programL3ForwardingStage2(Node node, Long dpid, String providerSegmentationId,
+                                             String macAddress,
+                                             String address,
+                                             Action actionForNode) {
+        Status status;
+        try {
+            InetAddress inetAddress = InetAddress.getByName(address);
+            status = l3ForwardingProvider == null ?
+                     new Status(StatusCode.SUCCESS) :
+                     l3ForwardingProvider.programForwardingTableEntry(node, dpid, providerSegmentationId,
+                                                                      inetAddress, macAddress, actionForNode);
+        } catch (UnknownHostException e) {
+            status = new Status(StatusCode.BADREQUEST);
+        }
+
+        if (status.isSuccess()) {
+            logger.debug("ProgramL3Forwarding {} for mac:{} addr:{} node:{} action:{}",
+                         l3ForwardingProvider == null ? "skipped" : "programmed",
+                         macAddress, address, node, actionForNode);
+        } else {
+            logger.error("ProgramL3Forwarding failed for mac:{} addr:{} node:{} action:{} status:{}",
+                         macAddress, address, node, actionForNode, status);
+        }
+        return status;
+    }
+
+    // --
+
     private void programFlowsForNeutronRouterInterface(final NeutronRouter_Interface neutronRouterInterface,
-                                                       Boolean isDelete) {
+                                                       Boolean isDelete,
+                                                       Node nodeFilter) {
         Preconditions.checkNotNull(neutronRouterInterface);
 
         final NeutronPort neutronPort = neutronPortCache.getPort(neutronRouterInterface.getPortUUID());
@@ -192,13 +324,17 @@ public class NeutronL3Adapter {
         // Keep cache for finding router's mac from network uuid
         //
         if (isDelete) {
-            networkId2MacCache.remove(neutronNetwork.getNetworkUUID());
+            networkId2RouterMacCache.remove(neutronNetwork.getNetworkUUID());
         } else {
-            networkId2MacCache.put(neutronNetwork.getNetworkUUID(), macAddress);
+            networkId2RouterMacCache.put(neutronNetwork.getNetworkUUID(), macAddress);
         }
 
         List<Node> nodes = connectionService.getNodes();
         for (Node node : nodes) {
+            if (nodeFilter != null && !(nodeFilter.getID().equals(node.getID()))) {
+                continue;
+            }
+
             final Long dpid = getDpid(node);
             final Action actionForNode =
                     tenantNetworkManager.isTenantNetworkPresentInNode(node, providerSegmentationId) ?
@@ -227,7 +363,7 @@ public class NeutronL3Adapter {
             if (gatewayIp != null && !gatewayIp.isEmpty()) {
                 final Action actionForNodeDefaultRoute =
                         isExternal ? actionForNode : Action.DELETE;
-                final String defaultGatewayMacAddress = "00:01:02:03:04:05";  // FIXME!
+                final String defaultGatewayMacAddress = configurationService.getDefaultGatewayMacAddress(node);
                 programDefaultRouteStage1(node, dpid, providerSegmentationId, defaultGatewayMacAddress, gatewayIp,
                                           actionForNodeDefaultRoute);
             }
@@ -459,15 +595,21 @@ public class NeutronL3Adapter {
         Preconditions.checkNotNull(neutronFloatingIP);
 
         final String networkUUID = neutronFloatingIP.getFloatingNetworkUUID();
+        final String routerMacAddress = networkId2RouterMacCache.get(networkUUID);
+
+        // If there is no router interface handling the networkUUID, we are done
+        if (routerMacAddress == null || routerMacAddress.isEmpty()) {
+            return;
+        }
+
         final NeutronNetwork neutronNetwork = neutronNetworkCache.getNetwork(networkUUID);
         final String providerSegmentationId = neutronNetwork != null ?
                                               neutronNetwork.getProviderSegmentationID() : null;
-        final String routerMacAddress = networkId2MacCache.get(networkUUID);
         final String fixedIPAddress = neutronFloatingIP.getFixedIPAddress();
         final String floatingIpAddress = neutronFloatingIP.getFloatingIPAddress();
 
         if (providerSegmentationId == null || providerSegmentationId.isEmpty() ||
-            routerMacAddress == null || routerMacAddress.isEmpty() ||
+            // routerMacAddress == null || routerMacAddress.isEmpty() ||
             fixedIPAddress == null || fixedIPAddress.isEmpty() ||
             floatingIpAddress == null || floatingIpAddress.isEmpty()) {
             return;  // done: go no further w/out all the info needed...
@@ -615,8 +757,9 @@ public class NeutronL3Adapter {
     private String getInternalBridgeUUID (Node node, String bridgeName) {
         Preconditions.checkNotNull(ovsdbConfigurationService);
         try {
-            Map<String, Row>
-                    bridgeTable = ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Bridge.class));
+            Map<String, Row> bridgeTable =
+                    ovsdbConfigurationService.getRows(node,
+                                                      ovsdbConfigurationService.getTableName(node, Bridge.class));
             if (bridgeTable == null) return null;
             for (String key : bridgeTable.keySet()) {
                 Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeTable.get(key));
@@ -628,24 +771,18 @@ public class NeutronL3Adapter {
         return null;
     }
 
-}
+    private NeutronRouter_Interface getNeutronRouterInterface(String subnetUUID) {
+        Iterator it = routerInterfaceCache.entrySet().iterator();
+        while (it.hasNext()) {
+            Map.Entry pairs = (Map.Entry)it.next();
+            NeutronRouter_Interface routerInterface = (NeutronRouter_Interface) pairs.getValue();
+            if (routerInterface.getSubnetUUID().equalsIgnoreCase(subnetUUID)) {
+                return routerInterface;
+            }
+        }
+        return null;
+    }
 
-/*
-JUNK
+}
 
-        // NeutronPort neutronPort = neutronPortCache.getPort(neutronRouterInterface.getPortUUID());
-        NeutronSubnet subnet = neutronSubnetCache.getSubnet(neutronRouterInterface.getSubnetUUID());
-        NeutronNetwork neutronNetwork = neutronNetworkCache.getNetwork(subnet.getNetworkUUID());
-        String providerSegmentationId = neutronNetwork.getProviderSegmentationID();
-        Boolean isExternal = neutronNetwork.getRouterExternal();
-        String cidr = subnet.getCidr();
 
-        List<Node> nodes = connectionService.getNodes();
-        for (Node node : nodes) {
-            if (tenantNetworkManager.isTenantNetworkPresentInNode(node, providerSegmentationId)) {
-                Long dpid = getDpid(node);
-                Status status = multiTenantRouterForwardingProvider
-                        .programIpRewriteExclusion(node, dpid, providerSegmentationId, cidr, action);
-            }
-        }
-*/