Split Ingress and Egress ACL Programming 56/10756/1
authorDave Tucker <djt@redhat.com>
Thu, 4 Sep 2014 09:18:05 +0000 (10:18 +0100)
committerDave Tucker <djt@redhat.com>
Thu, 4 Sep 2014 09:18:05 +0000 (10:18 +0100)
Change-Id: I7ccb0f7cfced6410efa95cc82dd6e51e8739fbe9
Signed-off-by: Dave Tucker <djt@redhat.com>
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/OF13Provider.java
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/services/EgressAclService.java
openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/services/IngressAclService.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/api/Constants.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/api/EgressAclProvider.java [new file with mode: 0644]
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/api/IngressAclProvider.java

index ae68d15fb7cf1ec20e5f2aa2ebcad7ca32545e58..b63e82949a137c6988141ee272e7c59671689c76 100644 (file)
@@ -20,6 +20,7 @@ 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.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.L3ForwardingProvider;
@@ -169,6 +170,7 @@ public class Activator extends ComponentActivatorAbstractBase {
             c.add(createServiceDependency().setService(OvsdbConnectionService.class).setRequired(true));
             c.add(createServiceDependency().setService(MdsalConsumer.class).setRequired(true));
             c.add(createServiceDependency().setService(IngressAclProvider.class).setRequired(true));
+            c.add(createServiceDependency().setService(EgressAclProvider.class).setRequired(true));
         }
 
         if (imp.equals(PipelineOrchestratorImpl.class)) {
@@ -178,10 +180,10 @@ public class Activator extends ComponentActivatorAbstractBase {
                            .setCallbacks("registerService", "unregisterService"));
         }
 
-        if (AbstractServiceInstance.class.isAssignableFrom((Class)imp)) {
+        if (AbstractServiceInstance.class.isAssignableFrom((Class) imp)) {
             c.add(createServiceDependency()
-                    .setService(PipelineOrchestrator.class)
-                    .setRequired(true));
+                          .setService(PipelineOrchestrator.class)
+                          .setRequired(true));
             c.add(createServiceDependency().setService(MdsalConsumer.class).setRequired(true));
         }
 
@@ -253,6 +255,14 @@ public class Activator extends ComponentActivatorAbstractBase {
             c.setInterface(AbstractServiceInstance.class.getName(), properties);
         }
 
+        if (imp.equals(EgressAclService.class)) {
+            Properties properties = new Properties();
+            properties.put(AbstractServiceInstance.SERVICE_PROPERTY, Service.EGRESS_ACL);
+            properties.put(Constants.PROVIDER_NAME_PROPERTY, OF13Provider.NAME);
+            c.setInterface(new String[]{AbstractServiceInstance.class.getName(),
+                                        EgressAclProvider.class.getName()}, properties);
+        }
+
         if (imp.equals(OutboundNatService.class)) {
             Properties properties = new Properties();
             properties.put(AbstractServiceInstance.SERVICE_PROPERTY, Service.OUTBOUND_NAT);
index 6248a95abb94130149b489a28abd6a97b562020b..b46bf3c58f7a356b5fc228eabe441aae54c94861 100644 (file)
@@ -33,6 +33,7 @@ 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.Constants;
+import org.opendaylight.ovsdb.openstack.netvirt.api.EgressAclProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.IngressAclProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.SecurityServicesManager;
@@ -121,6 +122,7 @@ public class OF13Provider implements NetworkingProvider {
     private volatile MdsalConsumer mdsalConsumer;
     private volatile SecurityServicesManager securityServicesManager;
     private volatile IngressAclProvider ingressAclProvider;
+    private volatile EgressAclProvider egressAclProvider;
 
     public static final String NAME = "OF13Provider";
 
@@ -838,6 +840,8 @@ public class OF13Provider implements NetworkingProvider {
                         "to be installed on DPID: {}", networkType, securityGroupInPort, dpid);
                 ingressAclProvider.programPortSecurityACL(node, dpid, segmentationId, attachedMac, localPort,
                         securityGroupInPort);
+                egressAclProvider.programPortSecurityACL(node, dpid, segmentationId, attachedMac, localPort,
+                                                         securityGroupInPort);
             }
             else if (networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_GRE) ||
                        networkType.equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VXLAN)) {
index 2c0b3c4dd51b0214afaea6f5f1ac4485818d8f56..ceaf38037717e1668ccb73cc6104418452f8c289 100644 (file)
@@ -9,10 +9,40 @@
  */
 package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services;
 
+import org.opendaylight.controller.networkconfig.neutron.NeutronSecurityGroup;
+import org.opendaylight.controller.networkconfig.neutron.NeutronSecurityRule;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
+import org.opendaylight.ovsdb.openstack.netvirt.api.EgressAclProvider;
 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.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.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 com.google.common.collect.Lists;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.math.BigInteger;
+import java.util.List;
+
+public class EgressAclService extends AbstractServiceInstance implements EgressAclProvider {
+
+    static final Logger logger = LoggerFactory.getLogger(EgressAclService.class);
 
-public class EgressAclService extends AbstractServiceInstance {
     public EgressAclService() {
         super(Service.EGRESS_ACL);
     }
@@ -21,8 +51,427 @@ public class EgressAclService extends AbstractServiceInstance {
         super(service);
     }
 
+
     @Override
     public boolean isBridgeInPipeline (String nodeId) {
         return true;
     }
-}
\ No newline at end of file
+
+    @Override
+    public void programPortSecurityACL(Node node, Long dpid, String segmentationId, String attachedMac, long localPort,
+                                       NeutronSecurityGroup securityGroup) {
+
+        logger.trace("programLocalBridgeRulesWithSec neutronSecurityGroup: {} ", securityGroup);
+        List<NeutronSecurityRule> portSecurityList = securityGroup.getSecurityRules();
+        /* Iterate over the Port Security Rules in the Port Security Group bound to the port*/
+        for (NeutronSecurityRule portSecurityRule : portSecurityList) {
+            /**
+             * Neutron Port Security ACL "egress" and "IPv4"
+             *
+             * Check that the base conditions for flow based Port Security are true:
+             * Port Security Rule Direction ("egress") and Protocol ("IPv4")
+             * Neutron defines the direction "ingress" as the vSwitch to the VM as defined in:
+             * http://docs.openstack.org/api/openstack-network/2.0/content/security_groups.html
+             *
+             */
+            if (portSecurityRule.getSecurityRuleEthertype().equalsIgnoreCase("IPv4") &&
+                portSecurityRule.getSecurityRuleDirection().equalsIgnoreCase("egress")) {
+                logger.debug("Egress IPV4 ACL  Port Security Rule: {} ", portSecurityRule);
+                // ToDo: Implement Port Range
+
+                /**
+                 * TCP Proto (True), TCP Port Minimum (True), TCP Port Max (True), IP Prefix (True)
+                 */
+                if (String.valueOf(portSecurityRule.getSecurityRuleProtocol()).equalsIgnoreCase("tcp") &&
+                    !String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
+                    !String.valueOf(portSecurityRule.getSecurityRulePortMax()).equalsIgnoreCase("null") &&
+                    (!String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix()).equalsIgnoreCase("null") &&
+                     !String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix())
+                             .equalsIgnoreCase("0.0.0.0/0"))) {
+                    logger.debug(
+                            "Rule #1 egress PortSec Rule Matches -> TCP Protocol: {}, TCP Port Min: {}, TCP Port Max: {}, IP Prefix: {}",
+                            portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
+                            portSecurityRule.getSecurityRulePortMax(),
+                            portSecurityRule.getSecurityRuleRemoteIpPrefix());
+                    egressACLDefaultTcpDrop(dpid, segmentationId, attachedMac,
+                                            Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY_DROP,
+                                            true);
+                    egressACLTcpPortWithPrefix(dpid, segmentationId,
+                                               attachedMac, true, portSecurityRule.getSecurityRulePortMin(),
+                                               portSecurityRule.getSecurityRuleRemoteIpPrefix(),
+                                               Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY);
+                    continue;
+                }
+                /**
+                 * TCP Proto (True), TCP Port Minimum (True), TCP Port Max (False), IP Prefix (True)
+                 */
+                if (String.valueOf(portSecurityRule.getSecurityRuleProtocol()).equalsIgnoreCase("tcp") &&
+                    !String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
+                    String.valueOf(portSecurityRule.getSecurityRulePortMax()).equalsIgnoreCase("null") &&
+                    (!String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix()).equalsIgnoreCase("null") &&
+                     !String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix())
+                             .equalsIgnoreCase("0.0.0.0/0"))) {
+                    logger.debug(
+                            "Rule #2 egress PortSec Rule Matches -> TCP Protocol: {}, TCP Port Min: {}, TCP Port Max: {}, IP Prefix: {}",
+                            portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
+                            portSecurityRule.getSecurityRulePortMax(),
+                            portSecurityRule.getSecurityRuleRemoteIpPrefix());
+                    egressACLDefaultTcpDrop(dpid, segmentationId, attachedMac,
+                                            Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY_DROP,
+                                            true);
+                    egressACLTcpPortWithPrefix(dpid, segmentationId,
+                                               attachedMac, true, portSecurityRule.getSecurityRulePortMin(),
+                                               portSecurityRule.getSecurityRuleRemoteIpPrefix(),
+                                               Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY);
+                    continue;
+                }
+                /**
+                 * TCP Proto (True), TCP Port Minimum (False), TCP Port Max (False), IP Prefix (True)
+                 */
+                if (String.valueOf(portSecurityRule.getSecurityRuleProtocol()).equalsIgnoreCase("tcp") &&
+                    String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
+                    String.valueOf(portSecurityRule.getSecurityRulePortMax()).equalsIgnoreCase("null") &&
+                    !String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix()).equalsIgnoreCase("null")) {
+                    logger.debug(
+                            "Rule #3 egress PortSec Rule Matches -> TCP Protocol: {}, TCP Port Min: {}, TCP Port Max: {}, IP Prefix: {}",
+                            portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
+                            portSecurityRule.getSecurityRulePortMax(),
+                            portSecurityRule.getSecurityRuleRemoteIpPrefix());
+                    egressACLDefaultTcpDrop(dpid, segmentationId, attachedMac, Constants.PROTO_PREFIX_MATCH_PRIORITY_DROP,
+                                            true);
+                    egressACLPermitAllProto(dpid, segmentationId, attachedMac, true,
+                                            portSecurityRule.getSecurityRuleRemoteIpPrefix(), Constants.PROTO_PREFIX_MATCH_PRIORITY);
+                    continue;
+                }
+                /**
+                 * TCP Proto (False), TCP Port Minimum (False), TCP Port Max (False), IP Prefix (True)
+                 */
+                if (String.valueOf(portSecurityRule.getSecurityRuleProtocol()).equalsIgnoreCase("null") &&
+                    String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
+                    String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
+                    (!String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix()).equalsIgnoreCase("null") &&
+                     !String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix())
+                             .equalsIgnoreCase("0.0.0.0/0"))) {
+                    logger.debug(
+                            "Rule #4 egress PortSec Rule Matches -> TCP Protocol: {}, TCP Port Min: {}, TCP Port Max: {}, IP Prefix: {}",
+                            portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
+                            portSecurityRule.getSecurityRulePortMax(),
+                            portSecurityRule.getSecurityRuleRemoteIpPrefix());
+                    egressACLDefaultTcpDrop(dpid, segmentationId, attachedMac, Constants.PREFIX_MATCH_PRIORITY_DROP, true);
+                    egressACLPermitAllProto(dpid, segmentationId, attachedMac, true,
+                                            portSecurityRule.getSecurityRuleRemoteIpPrefix(), Constants.PREFIX_MATCH_PRIORITY);
+                    continue;
+                }
+                /**
+                 * TCP Proto (True), TCP Port Minimum (True), TCP Port Max (True), IP Prefix (False)
+                 */
+                if (String.valueOf(portSecurityRule.getSecurityRuleProtocol()).equalsIgnoreCase("tcp") &&
+                    !String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
+                    !String.valueOf(portSecurityRule.getSecurityRulePortMax()).equalsIgnoreCase("null") &&
+                    String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix()).equalsIgnoreCase("null")) {
+                    logger.debug(
+                            "Rule #5 egress PortSec Rule Matches -> TCP Protocol: {}, TCP Port Min: {}, TCP Port Max: {}, IP Prefix: {}",
+                            portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
+                            portSecurityRule.getSecurityRulePortMax(),
+                            portSecurityRule.getSecurityRuleRemoteIpPrefix());
+                    egressACLDefaultTcpDrop(dpid, segmentationId, attachedMac, Constants.PROTO_PORT_MATCH_PRIORITY_DROP,
+                                            true);
+                    egressACLTcpSyn(dpid, segmentationId,
+                                    attachedMac, true, portSecurityRule.getSecurityRulePortMin(),
+                                    Constants.PROTO_PORT_MATCH_PRIORITY);
+                    continue;
+                }
+                /**
+                 * TCP Proto (True), TCP Port Minimum (True), TCP Port Max (False), IP Prefix (False)
+                 */
+                if (String.valueOf(portSecurityRule.getSecurityRuleProtocol()).equalsIgnoreCase("tcp") &&
+                    !String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
+                    String.valueOf(portSecurityRule.getSecurityRulePortMax()).equalsIgnoreCase("null") &&
+                    String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix()).equalsIgnoreCase("null")) {
+                    logger.debug(
+                            "Rule #6 egress PortSec Rule Matches -> TCP Protocol: {}, TCP Port Min: {}, TCP Port Max: {}, IP Prefix: {}",
+                            portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
+                            portSecurityRule.getSecurityRulePortMax(),
+                            portSecurityRule.getSecurityRuleRemoteIpPrefix());
+                    egressACLDefaultTcpDrop(dpid, segmentationId, attachedMac,
+                                            Constants.PROTO_PORT_MATCH_PRIORITY_DROP, true);
+                    egressACLTcpSyn(dpid, segmentationId, attachedMac, true,
+                                    portSecurityRule.getSecurityRulePortMin(), Constants.PROTO_PORT_MATCH_PRIORITY);
+                    continue;
+                }
+                /**
+                 * TCP Proto (True), TCP Port Minimum (False), TCP Port Max (False), IP Prefix (False or 0.0.0.0/0)
+                 */
+                if (String.valueOf(portSecurityRule.getSecurityRuleProtocol()).equalsIgnoreCase("tcp") &&
+                    String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
+                    String.valueOf(portSecurityRule.getSecurityRulePortMax()).equalsIgnoreCase("null") &&
+                    ((String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix()).equalsIgnoreCase("null")) ||
+                     String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix())
+                             .equalsIgnoreCase("0.0.0.0/0"))) {
+                    logger.debug(
+                            "Rule #7 egress PortSec Rule Matches -> TCP Protocol: {}, TCP Port Min: {}, TCP Port Max: {}, IP Prefix: {}",
+                            portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
+                            portSecurityRule.getSecurityRulePortMax(),
+                            portSecurityRule.getSecurityRuleRemoteIpPrefix());
+                    // No need to drop until UDP/ICMP are implemented
+                    // egressACLDefaultTcpDrop(dpid, segmentationId, attachedMac, PROTO_MATCH_PRIORITY_DROP, true);
+                    egressAllowProto(dpid, segmentationId, attachedMac, true,
+                                     portSecurityRule.getSecurityRuleProtocol(), Constants.PROTO_MATCH_PRIORITY);
+                    continue;
+                }
+                logger.debug("ACL Match combination not found for rule: {}", portSecurityRule);
+            }
+        }
+    }
+
+    public void egressACLDefaultTcpDrop(Long dpidLong, String segmentationId, String attachedMac,
+                                        int priority, boolean write) {
+
+        String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpidLong;
+        MatchBuilder matchBuilder = new MatchBuilder();
+        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        flowBuilder.setMatch(MatchUtils.createSmacTcpPortWithFlagMatch(matchBuilder,
+                                                                       attachedMac, Constants.TCP_SYN, segmentationId).build());
+        logger.debug("MatchBuilder contains: {}", flowBuilder.getMatch());
+
+        String flowId = "TCP_Syn_Egress_Default_Drop_" + attachedMac;
+        flowBuilder.setId(new FlowId(flowId));
+        FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setStrict(false);
+        flowBuilder.setPriority(priority);
+        flowBuilder.setBarrier(true);
+        flowBuilder.setTableId(this.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();
+            List<Instruction> instructions = Lists.newArrayList();
+
+            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);
+
+            logger.debug("Instructions contain: {}", ib.getInstruction());
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+
+    public void egressACLTcpPortWithPrefix(Long dpidLong, String segmentationId, String attachedMac, boolean write,
+                                           Integer securityRulePortMin, String securityRuleIpPrefix, Integer protoPortPrefixMatchPriority) {
+
+        String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpidLong;
+        PortNumber tcpPort = new PortNumber(securityRulePortMin);
+        MatchBuilder matchBuilder = new MatchBuilder();
+        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+        FlowBuilder flowBuilder = new FlowBuilder();
+        Ipv4Prefix srcIpPrefix = new Ipv4Prefix(securityRuleIpPrefix);
+
+        flowBuilder.setMatch(MatchUtils
+                                     .createSmacTcpSynDstIpPrefixTcpPort(matchBuilder, new MacAddress(attachedMac),
+                                                                         tcpPort, Constants.TCP_SYN, segmentationId, srcIpPrefix).build());
+
+        logger.debug(" MatchBuilder contains:  {}", flowBuilder.getMatch());
+        String flowId = "UcastEgress_" + segmentationId + "_" + attachedMac +
+                        securityRulePortMin + securityRuleIpPrefix;
+        // Add Flow Attributes
+        flowBuilder.setId(new FlowId(flowId));
+        FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setStrict(false);
+        flowBuilder.setPriority(protoPortPrefixMatchPriority);
+        flowBuilder.setBarrier(true);
+        flowBuilder.setTableId(this.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();
+            List<Instruction> instructionsList = Lists.newArrayList();
+
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructionsList.add(ib.build());
+            isb.setInstruction(instructionsList);
+
+            logger.debug("Instructions contain: {}", ib.getInstruction());
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+
+
+
+    public void egressAllowProto(Long dpidLong, String segmentationId, String attachedMac, boolean write,
+                                 String securityRuleProtcol, Integer protoMatchPriority) {
+
+        String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpidLong;
+        MatchBuilder matchBuilder = new MatchBuilder();
+        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        flowBuilder.setMatch(MatchUtils
+                                     .createDmacIpTcpSynMatch(matchBuilder, new MacAddress(attachedMac), null, null).build());
+        flowBuilder.setMatch(MatchUtils
+                                     .createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
+
+        logger.debug("MatchBuilder contains:  {}", flowBuilder.getMatch());
+        String flowId = "EgressAllProto_" + segmentationId + "_" +
+                        attachedMac + "_AllowEgressTCPSyn_" + securityRuleProtcol;
+        // Add Flow Attributes
+        flowBuilder.setId(new FlowId(flowId));
+        FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setStrict(false);
+        flowBuilder.setPriority(protoMatchPriority);
+        flowBuilder.setBarrier(true);
+        flowBuilder.setTableId(this.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();
+            List<Instruction> instructionsList = Lists.newArrayList();
+
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructionsList.add(ib.build());
+            isb.setInstruction(instructionsList);
+
+            logger.debug("Instructions contain: {}", ib.getInstruction());
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+
+    public void egressACLPermitAllProto(Long dpidLong, String segmentationId, String attachedMac,
+                                        boolean write, String securityRuleIpPrefix, Integer protoPortMatchPriority) {
+
+        String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpidLong;
+        Ipv4Prefix srcIpPrefix = new Ipv4Prefix(securityRuleIpPrefix);
+        MatchBuilder matchBuilder = new MatchBuilder();
+        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId))
+                                     .build());
+        if (securityRuleIpPrefix != null) {
+            flowBuilder.setMatch(MatchUtils
+                                         .createSmacIpTcpSynMatch(matchBuilder, new MacAddress(attachedMac), null, srcIpPrefix)
+                                         .build());
+        } else {
+            flowBuilder.setMatch(MatchUtils
+                                         .createSmacIpTcpSynMatch(matchBuilder, new MacAddress(attachedMac), null, null)
+                                         .build());
+        }
+        logger.debug("MatchBuilder contains: {}", flowBuilder.getMatch());
+        String flowId = "Egress_Proto_ACL" + segmentationId + "_" +
+                        attachedMac + "_Permit_" + securityRuleIpPrefix;
+        // Add Flow Attributes
+        flowBuilder.setId(new FlowId(flowId));
+        FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setStrict(false);
+        flowBuilder.setPriority(protoPortMatchPriority);
+        flowBuilder.setBarrier(true);
+        flowBuilder.setTableId(this.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();
+            List<Instruction> instructionsList = Lists.newArrayList();
+
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructionsList.add(ib.build());
+            isb.setInstruction(instructionsList);
+
+            logger.debug("Instructions contain: {}", ib.getInstruction());
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+
+
+    public void egressACLTcpSyn(Long dpidLong, String segmentationId, String attachedMac, boolean write,
+                                Integer securityRulePortMin, Integer protoPortMatchPriority) {
+
+        String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpidLong;
+        PortNumber tcpPort = new PortNumber(securityRulePortMin);
+        MatchBuilder matchBuilder = new MatchBuilder();
+        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+        FlowBuilder flowBuilder = new FlowBuilder();
+
+        flowBuilder.setMatch(MatchUtils.createSmacTcpSyn(matchBuilder, attachedMac, tcpPort,
+                                                         Constants.TCP_SYN, segmentationId).build());
+
+        logger.debug("MatchBuilder contains: {}", flowBuilder.getMatch());
+        String flowId = "Ucast_this.getTable()" + segmentationId + "_" + attachedMac + securityRulePortMin;
+        // Add Flow Attributes
+        flowBuilder.setId(new FlowId(flowId));
+        FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setStrict(false);
+        flowBuilder.setPriority(protoPortMatchPriority);
+        flowBuilder.setBarrier(true);
+        flowBuilder.setTableId(this.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();
+            List<Instruction> instructionsList = Lists.newArrayList();
+
+            ib = this.getMutablePipelineInstructionBuilder();
+            ib.setOrder(0);
+            ib.setKey(new InstructionKey(0));
+            instructionsList.add(ib.build());
+            isb.setInstruction(instructionsList);
+
+            logger.debug("Instructions contain: {}", ib.getInstruction());
+            // Add InstructionsBuilder to FlowBuilder
+            flowBuilder.setInstructions(isb.build());
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+}
index b8ceb95207c018eeaf2a2aa4cbc9fba070d52228..ad2e37a9f474a992b85cbb074670bebebf1e2864 100644 (file)
@@ -15,6 +15,7 @@ import java.util.List;
 import org.opendaylight.controller.networkconfig.neutron.NeutronSecurityGroup;
 import org.opendaylight.controller.networkconfig.neutron.NeutronSecurityRule;
 import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
 import org.opendaylight.ovsdb.openstack.netvirt.api.IngressAclProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
@@ -40,27 +41,6 @@ import com.google.common.collect.Lists;
 public class IngressAclService extends AbstractServiceInstance implements IngressAclProvider {
 
     static final Logger logger = LoggerFactory.getLogger(IngressAclService.class);
-    public static final Integer PROTO_MATCH_PRIORITY_DROP = 36006;
-    public static final Integer PROTO_PORT_MATCH_PRIORITY_DROP = 36005;
-    public static final Integer PREFIX_MATCH_PRIORITY_DROP = 36004;
-    public static final Integer PROTO_PREFIX_MATCH_PRIORITY_DROP = 36003;
-    public static final Integer PREFIX_PORT_MATCH_PRIORITY_DROP = 36002;
-    public static final Integer PROTO_PORT_PREFIX_MATCH_PRIORITY_DROP = 36001;
-
-    public static final Integer PROTO_MATCH_PRIORITY = 61010;
-    public static final Integer PREFIX_MATCH_PRIORITY = 61009;
-    public static final Integer PROTO_PREFIX_MATCH_PRIORITY = 61008;
-    public static final Integer PROTO_PORT_MATCH_PRIORITY = 61007;
-    public static final Integer PROTO_PORT_PREFIX_MATCH_PRIORITY = 61007;
-
-    public static final int TCP_SYN = 0x002;
-    public static final short INGRESS_ACL = 40; // Flows Destined to the VM Port go here
-    // TODO: break out egress to the egress table and create a parent for both ingress/egress
-    public static final short EGRESS_ACL = 100; // Flows Sourced from the VM Port go here
-    public static final short OUTBOUND_SNAT = 110; // Ingress ACL table drains traffic to this table
-
-    private static final String OPENFLOW = "openflow:";
-    private static Long groupId = 1L;
 
     public IngressAclService() {
         super(Service.INGRESS_ACL);
@@ -109,11 +89,11 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                             portSecurityRule.getSecurityRulePortMax(),
                             portSecurityRule.getSecurityRuleRemoteIpPrefix());
                     ingressACLDefaultTcpDrop(dpid, segmentationId, attachedMac,
-                            PROTO_PORT_PREFIX_MATCH_PRIORITY_DROP,
+                            Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY_DROP,
                             true);
                     ingressACLTcpPortWithPrefix(dpid, segmentationId,
                             attachedMac, true, portSecurityRule.getSecurityRulePortMin(),
-                            portSecurityRule.getSecurityRuleRemoteIpPrefix(), PROTO_PORT_PREFIX_MATCH_PRIORITY);
+                            portSecurityRule.getSecurityRuleRemoteIpPrefix(), Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY);
                     continue;
                 }
                 /**
@@ -130,11 +110,11 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                             portSecurityRule.getSecurityRulePortMax(),
                             portSecurityRule.getSecurityRuleRemoteIpPrefix());
                     ingressACLDefaultTcpDrop(dpid, segmentationId, attachedMac,
-                            PROTO_PORT_PREFIX_MATCH_PRIORITY_DROP,
+                                             Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY_DROP,
                             true);
                     ingressACLTcpPortWithPrefix(dpid, segmentationId,
                             attachedMac, true, portSecurityRule.getSecurityRulePortMin(),
-                            portSecurityRule.getSecurityRuleRemoteIpPrefix(), PROTO_PORT_PREFIX_MATCH_PRIORITY);
+                            portSecurityRule.getSecurityRuleRemoteIpPrefix(), Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY);
                     continue;
                 }
                 /**
@@ -148,10 +128,10 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                             portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
                             portSecurityRule.getSecurityRulePortMax(),
                             portSecurityRule.getSecurityRuleRemoteIpPrefix());
-                    ingressACLDefaultTcpDrop(dpid, segmentationId, attachedMac, PROTO_PREFIX_MATCH_PRIORITY_DROP,
+                    ingressACLDefaultTcpDrop(dpid, segmentationId, attachedMac, Constants.PROTO_PREFIX_MATCH_PRIORITY_DROP,
                             true);
                     ingressACLPermitAllProto(dpid, segmentationId, attachedMac, true,
-                            portSecurityRule.getSecurityRuleRemoteIpPrefix(), PROTO_PREFIX_MATCH_PRIORITY);
+                            portSecurityRule.getSecurityRuleRemoteIpPrefix(), Constants.PROTO_PREFIX_MATCH_PRIORITY);
                     continue;
                 }
                 /**
@@ -167,9 +147,9 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                             portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
                             portSecurityRule.getSecurityRulePortMax(),
                             portSecurityRule.getSecurityRuleRemoteIpPrefix());
-                    ingressACLDefaultTcpDrop(dpid, segmentationId, attachedMac, PREFIX_MATCH_PRIORITY_DROP, true);
+                    ingressACLDefaultTcpDrop(dpid, segmentationId, attachedMac, Constants.PREFIX_MATCH_PRIORITY_DROP, true);
                     ingressACLPermitAllProto(dpid, segmentationId, attachedMac, true,
-                            portSecurityRule.getSecurityRuleRemoteIpPrefix(), PREFIX_MATCH_PRIORITY);
+                            portSecurityRule.getSecurityRuleRemoteIpPrefix(), Constants.PREFIX_MATCH_PRIORITY);
                     continue;
                 }
                 /**
@@ -183,11 +163,11 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                             portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
                             portSecurityRule.getSecurityRulePortMax(),
                             portSecurityRule.getSecurityRuleRemoteIpPrefix());
-                    ingressACLDefaultTcpDrop(dpid, segmentationId, attachedMac, PROTO_PORT_MATCH_PRIORITY_DROP,
+                    ingressACLDefaultTcpDrop(dpid, segmentationId, attachedMac, Constants.PROTO_PORT_MATCH_PRIORITY_DROP,
                             true);
                     ingressACLTcpSyn(dpid, segmentationId,
                             attachedMac, true, portSecurityRule.getSecurityRulePortMin(),
-                            PREFIX_PORT_MATCH_PRIORITY_DROP);
+                            Constants.PREFIX_PORT_MATCH_PRIORITY_DROP);
                     continue;
                 }
                 /**
@@ -202,9 +182,9 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                             portSecurityRule.getSecurityRulePortMax(),
                             portSecurityRule.getSecurityRuleRemoteIpPrefix());
                     ingressACLDefaultTcpDrop(dpid, segmentationId, attachedMac,
-                            PROTO_PORT_MATCH_PRIORITY_DROP, true);
+                                             Constants.PROTO_PORT_MATCH_PRIORITY_DROP, true);
                     ingressACLTcpSyn(dpid, segmentationId, attachedMac, true,
-                            portSecurityRule.getSecurityRulePortMin(), PROTO_PORT_MATCH_PRIORITY);
+                            portSecurityRule.getSecurityRulePortMin(), Constants.PROTO_PORT_MATCH_PRIORITY);
                     continue;
                 }
                 /**
@@ -223,173 +203,25 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                     // No need to drop until UDP/ICMP are implemented
                     // ingressACLDefaultTcpDrop(dpid, segmentationId, attachedMac, PROTO_MATCH_PRIORITY_DROP, true);
                     handleIngressAllowProto(dpid, segmentationId, attachedMac, true,
-                            portSecurityRule.getSecurityRuleProtocol(), PROTO_MATCH_PRIORITY);
+                            portSecurityRule.getSecurityRuleProtocol(), Constants.PROTO_MATCH_PRIORITY);
                     continue;
                 }
                 logger.debug("Ingress ACL Match combination not found for rule: {}", portSecurityRule);
             }
-
-            /**
-             * Neutron Port Security ACL "egress" and "IPv4"
-             *
-             * Check that the base conditions for flow based Port Security are true:
-             * Port Security Rule Direction ("egress") and Protocol ("IPv4")
-             * Neutron defines the direction "ingress" as the vSwitch to the VM as defined in:
-             * http://docs.openstack.org/api/openstack-network/2.0/content/security_groups.html
-             *
-             */
-            if (portSecurityRule.getSecurityRuleEthertype().equalsIgnoreCase("IPv4") &&
-                    portSecurityRule.getSecurityRuleDirection().equalsIgnoreCase("egress")) {
-                logger.debug("Egress IPV4 ACL  Port Security Rule: {} ", portSecurityRule);
-                // TODO Move to EgressAclService and Implement Port Range
-
-                /**
-                 * TCP Proto (True), TCP Port Minimum (True), TCP Port Max (True), IP Prefix (True)
-                 */
-                if (String.valueOf(portSecurityRule.getSecurityRuleProtocol()).equalsIgnoreCase("tcp") &&
-                        !String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
-                        !String.valueOf(portSecurityRule.getSecurityRulePortMax()).equalsIgnoreCase("null") &&
-                        (!String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix()).equalsIgnoreCase("null") &&
-                                !String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix())
-                                        .equalsIgnoreCase("0.0.0.0/0"))) {
-                    logger.debug("Rule #1 egress PortSec Rule Matches -> TCP Protocol: {}, TCP Port Min: {}, TCP Port Max: {}, IP Prefix: {}",
-                            portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
-                            portSecurityRule.getSecurityRulePortMax(),
-                            portSecurityRule.getSecurityRuleRemoteIpPrefix());
-                    egressACLDefaultTcpDrop(dpid, segmentationId, attachedMac,
-                            PROTO_PORT_PREFIX_MATCH_PRIORITY_DROP,
-                            true);
-                    egressACLTcpPortWithPrefix(dpid, segmentationId,
-                            attachedMac, true, portSecurityRule.getSecurityRulePortMin(),
-                            portSecurityRule.getSecurityRuleRemoteIpPrefix(), PROTO_PORT_PREFIX_MATCH_PRIORITY);
-                    continue;
-                }
-                /**
-                 * TCP Proto (True), TCP Port Minimum (True), TCP Port Max (False), IP Prefix (True)
-                 */
-                if (String.valueOf(portSecurityRule.getSecurityRuleProtocol()).equalsIgnoreCase("tcp") &&
-                        !String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
-                        String.valueOf(portSecurityRule.getSecurityRulePortMax()).equalsIgnoreCase("null") &&
-                        (!String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix()).equalsIgnoreCase("null") &&
-                                !String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix())
-                                        .equalsIgnoreCase("0.0.0.0/0"))) {
-                    logger.debug("Rule #2 egress PortSec Rule Matches -> TCP Protocol: {}, TCP Port Min: {}, TCP Port Max: {}, IP Prefix: {}",
-                            portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
-                            portSecurityRule.getSecurityRulePortMax(),
-                            portSecurityRule.getSecurityRuleRemoteIpPrefix());
-                    egressACLDefaultTcpDrop(dpid, segmentationId, attachedMac,
-                            PROTO_PORT_PREFIX_MATCH_PRIORITY_DROP,
-                            true);
-                    egressACLTcpPortWithPrefix(dpid, segmentationId,
-                            attachedMac, true, portSecurityRule.getSecurityRulePortMin(),
-                            portSecurityRule.getSecurityRuleRemoteIpPrefix(), PROTO_PORT_PREFIX_MATCH_PRIORITY);
-                    continue;
-                }
-                /**
-                 * TCP Proto (True), TCP Port Minimum (False), TCP Port Max (False), IP Prefix (True)
-                 */
-                if (String.valueOf(portSecurityRule.getSecurityRuleProtocol()).equalsIgnoreCase("tcp") &&
-                        String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
-                        String.valueOf(portSecurityRule.getSecurityRulePortMax()).equalsIgnoreCase("null") &&
-                        !String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix()).equalsIgnoreCase("null")) {
-                    logger.debug("Rule #3 egress PortSec Rule Matches -> TCP Protocol: {}, TCP Port Min: {}, TCP Port Max: {}, IP Prefix: {}",
-                            portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
-                            portSecurityRule.getSecurityRulePortMax(),
-                            portSecurityRule.getSecurityRuleRemoteIpPrefix());
-                    egressACLDefaultTcpDrop(dpid, segmentationId, attachedMac, PROTO_PREFIX_MATCH_PRIORITY_DROP,
-                            true);
-                    egressACLPermitAllProto(dpid, segmentationId, attachedMac, true,
-                            portSecurityRule.getSecurityRuleRemoteIpPrefix(), PROTO_PREFIX_MATCH_PRIORITY);
-                    continue;
-                }
-                /**
-                 * TCP Proto (False), TCP Port Minimum (False), TCP Port Max (False), IP Prefix (True)
-                 */
-                if (String.valueOf(portSecurityRule.getSecurityRuleProtocol()).equalsIgnoreCase("null") &&
-                        String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
-                        String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
-                        (!String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix()).equalsIgnoreCase("null") &&
-                                !String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix())
-                                        .equalsIgnoreCase("0.0.0.0/0"))) {
-                    logger.debug("Rule #4 egress PortSec Rule Matches -> TCP Protocol: {}, TCP Port Min: {}, TCP Port Max: {}, IP Prefix: {}",
-                            portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
-                            portSecurityRule.getSecurityRulePortMax(),
-                            portSecurityRule.getSecurityRuleRemoteIpPrefix());
-                    egressACLDefaultTcpDrop(dpid, segmentationId, attachedMac, PREFIX_MATCH_PRIORITY_DROP, true);
-                    egressACLPermitAllProto(dpid, segmentationId, attachedMac, true,
-                            portSecurityRule.getSecurityRuleRemoteIpPrefix(), PREFIX_MATCH_PRIORITY);
-                    continue;
-                }
-                /**
-                 * TCP Proto (True), TCP Port Minimum (True), TCP Port Max (True), IP Prefix (False)
-                 */
-                if (String.valueOf(portSecurityRule.getSecurityRuleProtocol()).equalsIgnoreCase("tcp") &&
-                        !String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
-                        !String.valueOf(portSecurityRule.getSecurityRulePortMax()).equalsIgnoreCase("null") &&
-                        String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix()).equalsIgnoreCase("null")) {
-                    logger.debug("Rule #5 egress PortSec Rule Matches -> TCP Protocol: {}, TCP Port Min: {}, TCP Port Max: {}, IP Prefix: {}",
-                            portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
-                            portSecurityRule.getSecurityRulePortMax(),
-                            portSecurityRule.getSecurityRuleRemoteIpPrefix());
-                    egressACLDefaultTcpDrop(dpid, segmentationId, attachedMac, PROTO_PORT_MATCH_PRIORITY_DROP,
-                            true);
-                    egressACLTcpSyn(dpid, segmentationId,
-                            attachedMac, true, portSecurityRule.getSecurityRulePortMin(), PROTO_PORT_MATCH_PRIORITY);
-                    continue;
-                }
-                /**
-                 * TCP Proto (True), TCP Port Minimum (True), TCP Port Max (False), IP Prefix (False)
-                 */
-                if (String.valueOf(portSecurityRule.getSecurityRuleProtocol()).equalsIgnoreCase("tcp") &&
-                        !String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
-                        String.valueOf(portSecurityRule.getSecurityRulePortMax()).equalsIgnoreCase("null") &&
-                        String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix()).equalsIgnoreCase("null")) {
-                    logger.debug("Rule #6 egress PortSec Rule Matches -> TCP Protocol: {}, TCP Port Min: {}, TCP Port Max: {}, IP Prefix: {}",
-                            portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
-                            portSecurityRule.getSecurityRulePortMax(),
-                            portSecurityRule.getSecurityRuleRemoteIpPrefix());
-                    egressACLDefaultTcpDrop(dpid, segmentationId, attachedMac,
-                            PROTO_PORT_MATCH_PRIORITY_DROP, true);
-                    egressACLTcpSyn(dpid, segmentationId, attachedMac, true,
-                            portSecurityRule.getSecurityRulePortMin(), PROTO_PORT_MATCH_PRIORITY);
-                    continue;
-                }
-                /**
-                 * TCP Proto (True), TCP Port Minimum (False), TCP Port Max (False), IP Prefix (False or 0.0.0.0/0)
-                 */
-                if (String.valueOf(portSecurityRule.getSecurityRuleProtocol()).equalsIgnoreCase("tcp") &&
-                        String.valueOf(portSecurityRule.getSecurityRulePortMin()).equalsIgnoreCase("null") &&
-                        String.valueOf(portSecurityRule.getSecurityRulePortMax()).equalsIgnoreCase("null") &&
-                        ((String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix()).equalsIgnoreCase("null")) ||
-                                String.valueOf(portSecurityRule.getSecurityRuleRemoteIpPrefix())
-                                        .equalsIgnoreCase("0.0.0.0/0"))) {
-                    logger.debug("Rule #7 egress PortSec Rule Matches -> TCP Protocol: {}, TCP Port Min: {}, TCP Port Max: {}, IP Prefix: {}",
-                            portSecurityRule.getSecurityRuleProtocol(), portSecurityRule.getSecurityRulePortMin(),
-                            portSecurityRule.getSecurityRulePortMax(),
-                            portSecurityRule.getSecurityRuleRemoteIpPrefix());
-                    // No need to drop until UDP/ICMP are implemented
-                    // egressACLDefaultTcpDrop(dpid, segmentationId, attachedMac, PROTO_MATCH_PRIORITY_DROP, true);
-                    egressAllowProto(dpid, segmentationId, attachedMac, true,
-                            portSecurityRule.getSecurityRuleProtocol(), PROTO_MATCH_PRIORITY);
-                    continue;
-                }
-                logger.debug("ACL Match combination not found for rule: {}", portSecurityRule);
-
-            }
         }
     }
 
     public void ingressACLTcpSyn(Long dpidLong, String segmentationId, String attachedMac, boolean write,
             Integer securityRulePortMin, Integer protoPortMatchPriority) {
 
-        String nodeName = OPENFLOW + dpidLong;
+        String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpidLong;
         PortNumber tcpPort = new PortNumber(securityRulePortMin);
         MatchBuilder matchBuilder = new MatchBuilder();
         NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
         FlowBuilder flowBuilder = new FlowBuilder();
 
         flowBuilder.setMatch(MatchUtils.createDmacTcpSynMatch(matchBuilder, attachedMac, tcpPort,
-                TCP_SYN, segmentationId).build());
+                                                              Constants.TCP_SYN, segmentationId).build());
 
         logger.debug("ingressACLTcpSyn MatchBuilder contains:  {}", flowBuilder.getMatch());
         String flowId = "UcastOut_ACL2" + segmentationId + "_" + attachedMac + securityRulePortMin;
@@ -399,7 +231,7 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
         flowBuilder.setStrict(false);
         flowBuilder.setPriority(protoPortMatchPriority);
         flowBuilder.setBarrier(true);
-        flowBuilder.setTableId(INGRESS_ACL);
+        flowBuilder.setTableId(this.getTable());
         flowBuilder.setKey(key);
         flowBuilder.setFlowName(flowId);
         flowBuilder.setHardTimeout(0);
@@ -422,7 +254,7 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
             flowBuilder.setInstructions(isb.build());
             writeFlow(flowBuilder, nodeBuilder);
         } else {
-            // removeFlow(flowBuilder, nodeBuilder);
+            removeFlow(flowBuilder, nodeBuilder);
         }
     }
 
@@ -430,7 +262,7 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
             boolean write, Integer securityRulePortMin, String securityRuleIpPrefix,
             Integer protoPortPrefixMatchPriority) {
 
-        String nodeName = OPENFLOW + dpidLong;
+        String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpidLong;
         PortNumber tcpPort = new PortNumber(securityRulePortMin);
 
         MatchBuilder matchBuilder = new MatchBuilder();
@@ -440,7 +272,7 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
 
         flowBuilder.setMatch(MatchUtils
                 .createDmacTcpSynDstIpPrefixTcpPort(matchBuilder, new MacAddress(attachedMac),
-                        tcpPort, TCP_SYN, segmentationId, srcIpPrefix).build());
+                        tcpPort, Constants.TCP_SYN, segmentationId, srcIpPrefix).build());
 
         logger.debug(" MatchBuilder contains:  {}", flowBuilder.getMatch());
         String flowId = "UcastOut2_" + segmentationId + "_" + attachedMac +
@@ -451,7 +283,7 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
         flowBuilder.setStrict(false);
         flowBuilder.setPriority(protoPortPrefixMatchPriority);
         flowBuilder.setBarrier(true);
-        flowBuilder.setTableId(INGRESS_ACL);
+        flowBuilder.setTableId(this.getTable());
         flowBuilder.setKey(key);
         flowBuilder.setFlowName(flowId);
         flowBuilder.setHardTimeout(0);
@@ -474,14 +306,14 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
             flowBuilder.setInstructions(isb.build());
             writeFlow(flowBuilder, nodeBuilder);
         } else {
-            // removeFlow(flowBuilder, nodeBuilder);
+            removeFlow(flowBuilder, nodeBuilder);
         }
     }
 
     public void handleIngressAllowProto(Long dpidLong, String segmentationId, String attachedMac, boolean write,
             String securityRuleProtcol, Integer protoMatchPriority) {
 
-        String nodeName = OPENFLOW + dpidLong;
+        String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpidLong;
 
         MatchBuilder matchBuilder = new MatchBuilder();
         NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
@@ -501,7 +333,7 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
         flowBuilder.setStrict(false);
         flowBuilder.setPriority(protoMatchPriority);
         flowBuilder.setBarrier(true);
-        flowBuilder.setTableId(INGRESS_ACL);
+        flowBuilder.setTableId(this.getTable());
         flowBuilder.setKey(key);
         flowBuilder.setFlowName(flowId);
         flowBuilder.setHardTimeout(0);
@@ -524,7 +356,7 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
             flowBuilder.setInstructions(isb.build());
             writeFlow(flowBuilder, nodeBuilder);
         } else {
-            // removeFlow(flowBuilder, nodeBuilder);
+            removeFlow(flowBuilder, nodeBuilder);
         }
     }
 
@@ -532,13 +364,13 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
     public void ingressACLDefaultTcpDrop(Long dpidLong, String segmentationId, String attachedMac,
             int priority, boolean write) {
 
-        String nodeName = OPENFLOW + dpidLong;
+        String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpidLong;
         MatchBuilder matchBuilder = new MatchBuilder();
         NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
         FlowBuilder flowBuilder = new FlowBuilder();
 
         flowBuilder.setMatch(MatchUtils.createDmacTcpPortWithFlagMatch(matchBuilder,
-                attachedMac, TCP_SYN, segmentationId).build());
+                attachedMac, Constants.TCP_SYN, segmentationId).build());
 
         logger.debug("MatchBuilder contains: {}", flowBuilder.getMatch());
         String flowId = "PortSec_TCP_Syn_Default_Drop_" + attachedMac;
@@ -547,7 +379,7 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
         flowBuilder.setStrict(false);
         flowBuilder.setPriority(priority);
         flowBuilder.setBarrier(true);
-        flowBuilder.setTableId(INGRESS_ACL);
+        flowBuilder.setTableId(this.getTable());
         flowBuilder.setKey(key);
         flowBuilder.setFlowName(flowId);
         flowBuilder.setHardTimeout(0);
@@ -574,14 +406,14 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
             flowBuilder.setInstructions(isb.build());
             writeFlow(flowBuilder, nodeBuilder);
         } else {
-            // removeFlow(flowBuilder, nodeBuilder);
+            removeFlow(flowBuilder, nodeBuilder);
         }
     }
 
     public void ingressACLPermitAllProto(Long dpidLong, String segmentationId, String attachedMac,
             boolean write, String securityRuleIpPrefix, Integer protoPortMatchPriority) {
 
-        String nodeName = OPENFLOW + dpidLong;
+        String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpidLong;
         Ipv4Prefix srcIpPrefix = new Ipv4Prefix(securityRuleIpPrefix);
         MatchBuilder matchBuilder = new MatchBuilder();
         NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
@@ -608,7 +440,7 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
         flowBuilder.setStrict(false);
         flowBuilder.setPriority(protoPortMatchPriority);
         flowBuilder.setBarrier(true);
-        flowBuilder.setTableId(INGRESS_ACL);
+        flowBuilder.setTableId(this.getTable());
         flowBuilder.setKey(key);
         flowBuilder.setFlowName(flowId);
         flowBuilder.setHardTimeout(0);
@@ -631,260 +463,7 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
             flowBuilder.setInstructions(isb.build());
             writeFlow(flowBuilder, nodeBuilder);
         } else {
-            // // removeFlow(flowBuilder, nodeBuilder);
-        }
-    }
-
-    public void egressACLDefaultTcpDrop(Long dpidLong, String segmentationId, String attachedMac,
-            int priority, boolean write) {
-
-        String nodeName = OPENFLOW + dpidLong;
-        MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-        FlowBuilder flowBuilder = new FlowBuilder();
-
-        flowBuilder.setMatch(MatchUtils.createSmacTcpPortWithFlagMatch(matchBuilder,
-                attachedMac, TCP_SYN, segmentationId).build());
-        logger.debug("MatchBuilder contains: {}", flowBuilder.getMatch());
-
-        String flowId = "TCP_Syn_Egress_Default_Drop_" + attachedMac;
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setStrict(false);
-        flowBuilder.setPriority(priority);
-        flowBuilder.setBarrier(true);
-        flowBuilder.setTableId(EGRESS_ACL);
-        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();
-            List<Instruction> instructions = Lists.newArrayList();
-
-            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);
-
-            logger.debug("Instructions contain: {}", ib.getInstruction());
-            // Add InstructionsBuilder to FlowBuilder
-            flowBuilder.setInstructions(isb.build());
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            // TODO Add // removeFlow to AnstractServiceInstance
-            //// removeFlow(flowBuilder, nodeBuilder);
-        }
-    }
-
-    public void egressACLTcpPortWithPrefix(Long dpidLong, String segmentationId, String attachedMac, boolean write,
-            Integer securityRulePortMin, String securityRuleIpPrefix, Integer protoPortPrefixMatchPriority) {
-
-        String nodeName = OPENFLOW + dpidLong;
-        PortNumber tcpPort = new PortNumber(securityRulePortMin);
-        MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-        FlowBuilder flowBuilder = new FlowBuilder();
-        Ipv4Prefix srcIpPrefix = new Ipv4Prefix(securityRuleIpPrefix);
-
-        flowBuilder.setMatch(MatchUtils
-                .createSmacTcpSynDstIpPrefixTcpPort(matchBuilder, new MacAddress(attachedMac),
-                        tcpPort, TCP_SYN, segmentationId, srcIpPrefix).build());
-
-        logger.debug(" MatchBuilder contains:  {}", flowBuilder.getMatch());
-        String flowId = "UcastEgress_" + segmentationId + "_" + attachedMac +
-                securityRulePortMin + securityRuleIpPrefix;
-        // Add Flow Attributes
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setStrict(false);
-        flowBuilder.setPriority(protoPortPrefixMatchPriority);
-        flowBuilder.setBarrier(true);
-        flowBuilder.setTableId(EGRESS_ACL);
-        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();
-            List<Instruction> instructionsList = Lists.newArrayList();
-
-            InstructionUtils.createGotoTableInstructions(ib, OUTBOUND_SNAT);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructionsList.add(ib.build());
-            isb.setInstruction(instructionsList);
-
-            logger.debug("Instructions contain: {}", ib.getInstruction());
-            // Add InstructionsBuilder to FlowBuilder
-            flowBuilder.setInstructions(isb.build());
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            // TODO Add // removeFlow to AnstractServiceInstance
-            //// removeFlow(flowBuilder, nodeBuilder);
-        }
-    }
-
-
-
-    public void egressAllowProto(Long dpidLong, String segmentationId, String attachedMac, boolean write,
-            String securityRuleProtcol, Integer protoMatchPriority) {
-
-        String nodeName = OPENFLOW + dpidLong;
-        MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-        FlowBuilder flowBuilder = new FlowBuilder();
-
-        flowBuilder.setMatch(MatchUtils
-                .createDmacIpTcpSynMatch(matchBuilder, new MacAddress(attachedMac), null, null).build());
-        flowBuilder.setMatch(MatchUtils
-                .createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
-
-        logger.debug("MatchBuilder contains:  {}", flowBuilder.getMatch());
-        String flowId = "EgressAllProto_" + segmentationId + "_" +
-                attachedMac + "_AllowEgressTCPSyn_" + securityRuleProtcol;
-        // Add Flow Attributes
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setStrict(false);
-        flowBuilder.setPriority(protoMatchPriority);
-        flowBuilder.setBarrier(true);
-        flowBuilder.setTableId(EGRESS_ACL);
-        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();
-            List<Instruction> instructionsList = Lists.newArrayList();
-
-            InstructionUtils.createGotoTableInstructions(ib, OUTBOUND_SNAT);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructionsList.add(ib.build());
-            isb.setInstruction(instructionsList);
-
-            logger.debug("Instructions contain: {}", ib.getInstruction());
-            // Add InstructionsBuilder to FlowBuilder
-            flowBuilder.setInstructions(isb.build());
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            // removeFlow(flowBuilder, nodeBuilder);
-        }
-    }
-
-    public void egressACLPermitAllProto(Long dpidLong, String segmentationId, String attachedMac,
-            boolean write, String securityRuleIpPrefix, Integer protoPortMatchPriority) {
-
-        String nodeName = OPENFLOW + dpidLong;
-        Ipv4Prefix srcIpPrefix = new Ipv4Prefix(securityRuleIpPrefix);
-        MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-        FlowBuilder flowBuilder = new FlowBuilder();
-
-        flowBuilder.setMatch(MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId))
-                .build());
-        if (securityRuleIpPrefix != null) {
-            flowBuilder.setMatch(MatchUtils
-                    .createSmacIpTcpSynMatch(matchBuilder, new MacAddress(attachedMac), null, srcIpPrefix)
-                    .build());
-        } else {
-            flowBuilder.setMatch(MatchUtils
-                    .createSmacIpTcpSynMatch(matchBuilder, new MacAddress(attachedMac), null, null)
-                    .build());
-        }
-        logger.debug("MatchBuilder contains: {}", flowBuilder.getMatch());
-        String flowId = "Egress_Proto_ACL" + segmentationId + "_" +
-                attachedMac + "_Permit_" + securityRuleIpPrefix;
-        // Add Flow Attributes
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setStrict(false);
-        flowBuilder.setPriority(protoPortMatchPriority);
-        flowBuilder.setBarrier(true);
-        flowBuilder.setTableId(EGRESS_ACL);
-        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();
-            List<Instruction> instructionsList = Lists.newArrayList();
-
-            InstructionUtils.createGotoTableInstructions(ib, OUTBOUND_SNAT);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructionsList.add(ib.build());
-            isb.setInstruction(instructionsList);
-
-            logger.debug("Instructions contain: {}", ib.getInstruction());
-            // Add InstructionsBuilder to FlowBuilder
-            flowBuilder.setInstructions(isb.build());
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            // removeFlow(flowBuilder, nodeBuilder);
-        }
-    }
-
-
-    public void egressACLTcpSyn(Long dpidLong, String segmentationId, String attachedMac, boolean write,
-            Integer securityRulePortMin, Integer protoPortMatchPriority) {
-
-        String nodeName = OPENFLOW + dpidLong;
-        PortNumber tcpPort = new PortNumber(securityRulePortMin);
-        MatchBuilder matchBuilder = new MatchBuilder();
-        NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
-        FlowBuilder flowBuilder = new FlowBuilder();
-
-        flowBuilder.setMatch(MatchUtils.createSmacTcpSyn(matchBuilder, attachedMac, tcpPort,
-                TCP_SYN, segmentationId).build());
-
-        logger.debug("MatchBuilder contains: {}", flowBuilder.getMatch());
-        String flowId = "Ucast_Egress_ACL" + segmentationId + "_" + attachedMac + securityRulePortMin;
-        // Add Flow Attributes
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setStrict(false);
-        flowBuilder.setPriority(protoPortMatchPriority);
-        flowBuilder.setBarrier(true);
-        flowBuilder.setTableId(EGRESS_ACL);
-        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();
-            List<Instruction> instructionsList = Lists.newArrayList();
-
-            InstructionUtils.createGotoTableInstructions(ib, OUTBOUND_SNAT);
-            ib.setOrder(0);
-            ib.setKey(new InstructionKey(0));
-            instructionsList.add(ib.build());
-            isb.setInstruction(instructionsList);
-
-            logger.debug("Instructions contain: {}", ib.getInstruction());
-            // Add InstructionsBuilder to FlowBuilder
-            flowBuilder.setInstructions(isb.build());
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            // removeFlow(flowBuilder, nodeBuilder);
+            removeFlow(flowBuilder, nodeBuilder);
         }
     }
 }
index 537c7c7382a39071d594b3ca2a568d140abc447e..acf7a9b496ea226320dd2d6a5aaf354b57171845 100644 (file)
@@ -73,4 +73,27 @@ public final class Constants {
      * Ethertypes
      */
     public static final long ARP_ETHERTYPE = 0x0806L;
+
+
+    /*
+     * ACL
+     */
+    public static final Integer PROTO_MATCH_PRIORITY_DROP = 36006;
+    public static final Integer PROTO_PORT_MATCH_PRIORITY_DROP = 36005;
+    public static final Integer PREFIX_MATCH_PRIORITY_DROP = 36004;
+    public static final Integer PROTO_PREFIX_MATCH_PRIORITY_DROP = 36003;
+    public static final Integer PREFIX_PORT_MATCH_PRIORITY_DROP = 36002;
+    public static final Integer PROTO_PORT_PREFIX_MATCH_PRIORITY_DROP = 36001;
+
+    public static final Integer PROTO_MATCH_PRIORITY = 61010;
+    public static final Integer PREFIX_MATCH_PRIORITY = 61009;
+    public static final Integer PROTO_PREFIX_MATCH_PRIORITY = 61008;
+    public static final Integer PROTO_PORT_MATCH_PRIORITY = 61007;
+    public static final Integer PROTO_PORT_PREFIX_MATCH_PRIORITY = 61007;
+
+    public static final int TCP_SYN = 0x002;
+    public static final short INGRESS_ACL = 40; // Flows Destined to the VM Port go here
+    public static final short OUTBOUND_SNAT = 110; // Ingress ACL table drains traffic to this table
+
+    private static Long groupId = 1L;
 }
diff --git a/openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/api/EgressAclProvider.java b/openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/api/EgressAclProvider.java
new file mode 100644 (file)
index 0000000..fb037ee
--- /dev/null
@@ -0,0 +1,23 @@
+package org.opendaylight.ovsdb.openstack.netvirt.api;
+
+import org.opendaylight.controller.networkconfig.neutron.NeutronSecurityGroup;
+import org.opendaylight.controller.sal.core.Node;
+
+/**
+ *  This interface allows egress Port Security flows to be written to devices
+ */
+public interface EgressAclProvider {
+
+    /**
+     * Program port security ACL.
+     *
+     * @param node the node
+     * @param dpid the dpid
+     * @param segmentationId the segmentation id
+     * @param attachedMac the attached mac
+     * @param localPort the local port
+     * @param securityGroup the security group
+     */
+    public void programPortSecurityACL(Node node, Long dpid, String segmentationId, String attachedMac,
+                                       long localPort, NeutronSecurityGroup securityGroup);
+}
index f61cc1e0ee2d6f6584df7812106550d8cb39261c..1589294c1834e34fc48fd5432513ebed713a04f4 100644 (file)
@@ -13,7 +13,7 @@ import org.opendaylight.controller.networkconfig.neutron.NeutronSecurityGroup;
 import org.opendaylight.controller.sal.core.Node;
 
 /**
- *  This interface allows Port Security flows to be written to devices
+ *  This interface allows ingress Port Security flows to be written to devices
  */
 public interface IngressAclProvider {