Bug 7922 - Use counter to keep track of duplicate flow entries 16/52816/8
authorVinh Nguyen <vinh.nguyen@hcl.com>
Sun, 5 Mar 2017 03:49:54 +0000 (19:49 -0800)
committerSam Hague <shague@redhat.com>
Sat, 8 Apr 2017 16:41:55 +0000 (16:41 +0000)
Problem: Single flow entry associated with two more security rules
incorrectly deleted when one of the security rule is deleted.

Fix: Use counter to keeps track of duplicate security rules
in a particular VM. The counter is maintained in the flow cookie.
When writing a security flow, the flow counter is incremented
if the flow already exists, otherwise the flow cookie is set to '1'.
When removing a security flow, if the counter value is '1',
the flow is removed from the node, otherwise the flow counter is
decremented.

This changeset also:
- reversed some previous partial fixes for the same problem.
- refactor common Acl Service to AbstractAclService
- reformat/clean up code

Change-Id: Idfec36fa47c88db76a8382f8fcbc65c4100e9e6e
Signed-off-by: Vinh Nguyen <vinh.nguyen@hcl.com>
15 files changed:
openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/AbstractServiceInstance.java
openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/AbstractAclService.java [new file with mode: 0644]
openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/EgressAclLearnServiceUtil.java
openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/EgressAclService.java
openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/IngressAclLearnServiceUtil.java
openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/IngressAclService.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/PortSecurityHandler.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/api/Constants.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/api/EgressAclProvider.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/api/IngressAclProvider.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/api/SecurityServicesManager.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/impl/SecurityGroupCacheManagerImpl.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/impl/SecurityServicesImpl.java
openstack/net-virt/src/test/java/org/opendaylight/netvirt/openstack/netvirt/impl/SecurityGroupCacheManagerImplTest.java
openstack/net-virt/src/test/java/org/opendaylight/netvirt/openstack/netvirt/impl/SecurityServicesImplTest.java

index c88722486bc175a3154181612bf58275cb4f56ea..233cc329dab667c619eac5429b08d7b20c4f265e 100644 (file)
@@ -59,7 +59,7 @@ public abstract class AbstractServiceInstance {
     public static final String SERVICE_PROPERTY ="serviceProperty";
     private static final Logger LOG = LoggerFactory.getLogger(AbstractServiceInstance.class);
     public static final String OPENFLOW = "openflow:";
-    private DataBroker dataBroker = null;
+    protected DataBroker dataBroker = null;
     // OSGi Services that we are dependent on.
     private volatile PipelineOrchestrator orchestrator;
     private volatile Southbound southbound;
@@ -117,7 +117,7 @@ public abstract class AbstractServiceInstance {
         return builder;
     }
 
-    private static InstanceIdentifier<Flow> createFlowPath(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
+    protected static InstanceIdentifier<Flow> createFlowPath(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
         return InstanceIdentifier.builder(Nodes.class)
                 .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class,
                         nodeBuilder.getKey())
@@ -173,6 +173,8 @@ public abstract class AbstractServiceInstance {
 
     protected void removeFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
         if (NetvirtProvidersProvider.isMasterProviderInstance()) {
+            LOG.debug("removeFlow: flowBuilder: {}, nodeBuilder: {}",
+                    flowBuilder.build(), nodeBuilder.build());
             WriteTransaction modification = dataBroker.newWriteOnlyTransaction();
             modification.delete(LogicalDatastoreType.CONFIGURATION, createFlowPath(flowBuilder, nodeBuilder));
 
diff --git a/openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/AbstractAclService.java b/openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/AbstractAclService.java
new file mode 100644 (file)
index 0000000..f080ac8
--- /dev/null
@@ -0,0 +1,270 @@
+/*
+ * Copyright (c) 2017 NEC Corporation and others. All rights reserved.
+ *
+ * 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.netvirt.openstack.netvirt.providers.openflow13.services;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.netvirt.openstack.netvirt.api.SecurityGroupCacheManger;
+import org.opendaylight.netvirt.openstack.netvirt.api.SecurityServicesManager;
+import org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
+import org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.Service;
+import org.opendaylight.netvirt.openstack.netvirt.translator.NeutronSecurityGroup;
+import org.opendaylight.netvirt.openstack.netvirt.translator.NeutronSecurityRule;
+import org.opendaylight.netvirt.openstack.netvirt.translator.crud.INeutronSecurityRuleCRUD;
+import org.opendaylight.netvirt.utils.mdsal.openflow.ActionUtils;
+import org.opendaylight.netvirt.utils.mdsal.openflow.InstructionUtils;
+import org.opendaylight.netvirt.utils.mdsal.openflow.MatchUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
+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.types.rev131026.FlowCookie;
+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.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+import java.math.BigInteger;
+import java.util.ArrayList;
+
+import java.util.List;
+
+/**
+ * Provide functionalities for programing pipeline flows associated with Security rules
+ */
+public class AbstractAclService extends AbstractServiceInstance {
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractAclService.class);
+    protected volatile SecurityServicesManager securityServicesManager;
+    protected volatile SecurityGroupCacheManger securityGroupCacheManger;
+    protected volatile INeutronSecurityRuleCRUD neutronSecurityRule;
+    protected static final int PORT_RANGE_MIN = 1;
+    protected static final int PORT_RANGE_MAX = 65535;
+    protected static final NeutronSecurityRule TCP_SECURITY_GROUP_RULE_IPv4_ANY = new NeutronSecurityRule();
+    protected static final NeutronSecurityRule UDP_SECURITY_GROUP_RULE_IPv4_ANY = new NeutronSecurityRule();
+    protected static final NeutronSecurityRule ICMP_SECURITY_GROUP_RULE_IPv4_ANY = new NeutronSecurityRule();
+
+    static {
+        TCP_SECURITY_GROUP_RULE_IPv4_ANY.setSecurityRuleProtocol(MatchUtils.TCP);
+        TCP_SECURITY_GROUP_RULE_IPv4_ANY.setSecurityRuleEthertype(NeutronSecurityRule.ETHERTYPE_IPV4);
+        TCP_SECURITY_GROUP_RULE_IPv4_ANY.setSecurityRulePortMin(null);
+        TCP_SECURITY_GROUP_RULE_IPv4_ANY.setSecurityRulePortMax(null);
+        UDP_SECURITY_GROUP_RULE_IPv4_ANY.setSecurityRuleProtocol(MatchUtils.UDP);
+        UDP_SECURITY_GROUP_RULE_IPv4_ANY.setSecurityRuleEthertype(NeutronSecurityRule.ETHERTYPE_IPV4);
+        UDP_SECURITY_GROUP_RULE_IPv4_ANY.setSecurityRulePortMin(null);
+        UDP_SECURITY_GROUP_RULE_IPv4_ANY.setSecurityRulePortMax(null);
+        ICMP_SECURITY_GROUP_RULE_IPv4_ANY.setSecurityRuleProtocol(MatchUtils.ICMP);
+        ICMP_SECURITY_GROUP_RULE_IPv4_ANY.setSecurityRuleEthertype(NeutronSecurityRule.ETHERTYPE_IPV4);
+        ICMP_SECURITY_GROUP_RULE_IPv4_ANY.setSecurityRulePortMin(null);
+        ICMP_SECURITY_GROUP_RULE_IPv4_ANY.setSecurityRulePortMax(null);
+    }
+
+    protected AbstractAclService(Service service) {
+        super(service);
+    }
+
+    /**
+     * Add or remove flow to the node.
+     *
+     * @param flowBuilder the flow builder
+     * @param nodeBuilder the node builder
+     * @param write       whether it is a write
+     */
+    protected void syncFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder,
+                            boolean write) {
+        if (write) {
+            writeFlow(flowBuilder, nodeBuilder);
+        } else {
+            removeFlow(flowBuilder, nodeBuilder);
+        }
+    }
+
+    /**
+     * Add or remove security group related flow to the node.
+     *
+     * @param flowBuilder the flow builder
+     * @param nodeBuilder the node builder
+     * @param write       whether it is a write
+     */
+    protected void syncSecurityRuleFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder, boolean write) {
+        LOG.trace("syncSecurityRuleFlow {} {}", flowBuilder.build(), write);
+        if (securityServicesManager.isConntrackEnabled()) {
+            syncFlow(flowBuilder, nodeBuilder, write);
+        } else {
+            if (write) {
+                writeSecurityRuleFlow(flowBuilder, nodeBuilder);
+            } else {
+                removeSecurityRuleFlow(flowBuilder, nodeBuilder);
+            }
+        }
+    }
+
+    /**
+     * Add security related flow to the node.
+     *
+     * The flow cookie contains the counter which keeps track of duplicate security rules in a particular VM.
+     * When writing a security related flow, the flow counter is incremented if the flow already exists,
+     * otherwise the flow is added to the node with counter value is '1'
+     * When removing a security related flow, if the counter value is '1', the flow is removed from the node,
+     * otherwise the flow counter is decremented
+     *
+     * @param flowBuilder the flow builder
+     * @param nodeBuilder the node builder
+     */
+    protected void writeSecurityRuleFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
+        ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
+        InstanceIdentifier<Flow> flowInstanceIdentifier = createFlowPath(flowBuilder, nodeBuilder);
+        CheckedFuture<Optional<Flow>, ReadFailedException> readFlowFuture =
+                readTx.read(LogicalDatastoreType.CONFIGURATION, flowInstanceIdentifier);
+        Futures.addCallback(readFlowFuture, new FutureCallback<Optional<Flow>>() {
+            @Override
+            public void onSuccess(@Nullable Optional<Flow> optionalFlow) {
+                if (optionalFlow != null) {
+                    if (optionalFlow.isPresent()) {
+                        Flow flow = optionalFlow.get();
+                        if (flow.getCookie() == null) {
+                            flowBuilder.setCookie(new FlowCookie(BigInteger.ONE));
+                        } else {
+                            flowBuilder.setCookie(new FlowCookie(flow.getCookie().getValue().add(BigInteger.ONE)));
+                        }
+                    } else {
+                        flowBuilder.setCookie(new FlowCookie(BigInteger.ONE));
+                    }
+                    writeFlow(flowBuilder, nodeBuilder);
+                }
+            }
+            @Override
+            public void onFailure(Throwable throwable) {
+                LOG.warn("Read Config/DS for Flow failed! " + flowInstanceIdentifier, throwable);
+            }
+        });
+    }
+
+    /**
+     * Remove security related flow from the node.
+     *
+     * The flow cookie contains the counter which keeps track of duplicate security rules in a particular VM.
+     * If the flow counter value stored in the flow cookie is '1', which indicates the flow is only associated with
+     * single security rule, it is removed from the node.
+     * Otherwise the flow counter is decremented.
+     *
+     * @param flowBuilder the flow builder
+     * @param nodeBuilder the node builder
+     */
+    protected void removeSecurityRuleFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
+        ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
+        InstanceIdentifier<Flow> flowInstanceIdentifier = createFlowPath(flowBuilder, nodeBuilder);
+        CheckedFuture<Optional<Flow>, ReadFailedException> readFlowFuture =
+                readTx.read(LogicalDatastoreType.CONFIGURATION, flowInstanceIdentifier);
+        Futures.addCallback(readFlowFuture, new FutureCallback<Optional<Flow>>() {
+            @Override
+            public void onSuccess(@Nullable Optional<Flow> optionalFlow) {
+                if (optionalFlow != null && optionalFlow.isPresent()) {
+                    Flow flow = optionalFlow.get();
+                    if (flow.getCookie() != null) {
+                        FlowCookie flowCookie = flow.getCookie();
+                        BigInteger cookie = flowCookie.getValue();
+                        int compareValue = cookie.compareTo(BigInteger.ONE);
+                        if (compareValue == 0) {
+                            removeFlow(flowBuilder, nodeBuilder);
+                        } else if (compareValue == 1) {
+                            flowBuilder.setCookie(new FlowCookie(cookie.subtract(BigInteger.ONE)));
+                            writeFlow(flowBuilder, nodeBuilder);
+                        }
+                    } else {
+                        removeFlow(flowBuilder, nodeBuilder);
+                    }
+                }
+            }
+            @Override
+            public void onFailure(Throwable throwable) {
+                LOG.warn("Read Config/DS for Flow failed! " + flowInstanceIdentifier, throwable);
+            }
+
+        });
+    }
+
+    protected FlowBuilder addInstructionWithConntrackCommit(FlowBuilder flowBuilder, boolean isDrop) {
+        InstructionBuilder instructionBuilder = null;
+        if (securityServicesManager.isConntrackEnabled()) {
+            Action conntrackAction = ActionUtils.nxConntrackAction(1, 0L, 0, (short) 0xff);
+            instructionBuilder = InstructionUtils
+                    .createInstructionBuilder(ActionUtils.conntrackActionBuilder(conntrackAction), 1, false);
+        }
+        return addPipelineInstruction(flowBuilder, instructionBuilder, isDrop);
+    }
+
+    protected FlowBuilder addPipelineInstruction(FlowBuilder flowBuilder, InstructionBuilder instructionBuilder,
+                                                 boolean isDrop) {
+        InstructionBuilder pipeLineIndstructionBuilder = createPipleLineInstructionBuilder(isDrop);
+        List<Instruction> instructionsList = Lists.newArrayList();
+        instructionsList.add(pipeLineIndstructionBuilder.build());
+        if (null != instructionBuilder) {
+            instructionsList.add(instructionBuilder.build());
+        }
+        InstructionsBuilder isb = new InstructionsBuilder();
+        isb.setInstruction(instructionsList);
+        flowBuilder.setInstructions(isb.build());
+        return flowBuilder;
+    }
+
+    protected InstructionBuilder createPipleLineInstructionBuilder(boolean drop) {
+        InstructionBuilder ib = this.getMutablePipelineInstructionBuilder();
+        if (drop) {
+            InstructionUtils.createDropInstructions(ib);
+        }
+        ib.setOrder(0);
+        List<Instruction> instructionsList = Lists.newArrayList();
+        ib.setKey(new InstructionKey(0));
+        instructionsList.add(ib.build());
+        return ib;
+    }
+
+    protected List<NeutronSecurityRule> getSecurityRulesforGroup(NeutronSecurityGroup securityGroup) {
+        List<NeutronSecurityRule> securityRules = new ArrayList<>();
+        List<NeutronSecurityRule> rules = neutronSecurityRule.getAllNeutronSecurityRules();
+        for (NeutronSecurityRule securityRule : rules) {
+            if (securityGroup.getID().equals(securityRule.getSecurityRuleGroupID())) {
+                securityRules.add(securityRule);
+            }
+        }
+        return securityRules;
+    }
+
+    protected void addConntrackMatch(MatchBuilder matchBuilder, int state, int mask) {
+        if (securityServicesManager.isConntrackEnabled()) {
+            MatchUtils.addCtState(matchBuilder, state, mask);
+        }
+
+    }
+
+    protected FlowBuilder addInstructionWithConntrackRecirc(FlowBuilder flowBuilder) {
+        InstructionBuilder instructionBuilder = null;
+        if (securityServicesManager.isConntrackEnabled()) {
+            Action conntrackAction = ActionUtils.nxConntrackAction(0, 0L, 0, (short) 0x0);
+            instructionBuilder = InstructionUtils
+                    .createInstructionBuilder(ActionUtils.conntrackActionBuilder(conntrackAction), 1, false);
+            List<Instruction> instructionsList = Lists.newArrayList();
+            instructionsList.add(instructionBuilder.build());
+            InstructionsBuilder isb = new InstructionsBuilder();
+            isb.setInstruction(instructionsList);
+            flowBuilder.setInstructions(isb.build());
+        }
+        return flowBuilder;
+    }
+}
index 14e945fca3a555ae2db162175c234f950976d775..fdc3008cbc9455d9dd9dcb5f5dc4c1d267d75cc5 100644 (file)
@@ -12,23 +12,15 @@ import java.math.BigInteger;
 import java.util.List;
 import java.util.ArrayList;
 
-import org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
 import org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.Service;
-import org.opendaylight.netvirt.openstack.netvirt.providers.ConfigInterface;
-import org.opendaylight.netvirt.openstack.netvirt.api.L2ForwardingLearnProvider;
 import org.opendaylight.netvirt.openstack.netvirt.api.LearnConstants;
 import org.opendaylight.netvirt.openstack.netvirt.api.LearnConstants.LearnFlowModsType;
 import org.opendaylight.netvirt.openstack.netvirt.providers.NetvirtProvidersProvider;
-import org.opendaylight.netvirt.utils.mdsal.openflow.ActionUtils;
-import org.opendaylight.netvirt.utils.mdsal.openflow.FlowUtils;
-import org.opendaylight.netvirt.utils.mdsal.openflow.MatchUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
 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.tables.table.FlowBuilder;
 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.ApplyActions;
@@ -36,13 +28,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instru
 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.InstructionKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.add.group.input.buckets.bucket.action.action.NxActionResubmitRpcAddGroupCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.resubmit.grouping.NxResubmitBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxRegCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.FlowModAddMatchFromFieldCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.FlowModAddMatchFromValueCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.FlowModCopyFieldIntoFieldCaseBuilder;
@@ -57,14 +44,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ni
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.learn.grouping.NxLearnBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.learn.grouping.nx.learn.FlowMods;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.learn.grouping.nx.learn.FlowModsBuilder;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Lists;
 
 public class EgressAclLearnServiceUtil {
+    private static final short LEARN_TABLE_ID = Service.ACL_LEARN_SERVICE.getTable();
+    private static final short RESUBMIT_TABLE_ID = Service.LOAD_BALANCER.getTable();
 
     /*
      * (Table:EgressAclLearnService) EgressACL Learning
@@ -74,7 +59,7 @@ public class EgressAclLearnServiceUtil {
      * fin_hard_timeout=0,priority=61010, cookie=0x6900000,eth_type=0x800,nw_proto=6, NXM_OF_IP_SRC[]=NXM_OF_IP_DST[],NXM_OF_IP_DST[]=NXM_OF_IP_SRC[],
      * NXM_OF_TCP_SRC[]=NXM_OF_TCP_DST[],NXM_OF_TCP_DST[]=NXM_OF_TCP_SRC[],load:0x1->NXM_NX_REG6[0..7]),resubmit(,50)"
      */
-    public static FlowBuilder programEgressAclLearnRuleForTcp(FlowBuilder flowBuilder, InstructionBuilder instructionBuilder, short learnTableId, short resubmitId) {
+    public static FlowBuilder programEgressAclLearnRuleForTcp(FlowBuilder flowBuilder) {
         List<Action> listAction = new ArrayList<>();
 
         // Create learn action
@@ -95,7 +80,7 @@ public class EgressAclLearnServiceUtil {
             LearnConstants.LEARN_PRIORITY,
             "0",
             LearnConstants.DELETE_LEARNED_FLAG_VALUE,
-            String.valueOf(learnTableId),
+            String.valueOf(LEARN_TABLE_ID),
             String.valueOf(NetvirtProvidersProvider.getSecurityGroupTcpFinIdleTimeout()),
             String.valueOf(NetvirtProvidersProvider.getSecurityGroupTcpFinHardTimeout())
         };
@@ -142,16 +127,14 @@ public class EgressAclLearnServiceUtil {
         listAction.add(buildAction(0, header, flowMod));
         ActionBuilder ab = new ActionBuilder();
         ab = new ActionBuilder();
-        ab.setAction(createResubmitActions(resubmitId));
+        ab.setAction(createResubmitActions());
         ab.setKey(new ActionKey(1));
         listAction.add(ab.build());
         ApplyActions applyActions = new ApplyActionsBuilder().setAction(listAction).build();
         ApplyActionsCase applyActionsCase = new ApplyActionsCaseBuilder().setApplyActions(applyActions).build();
         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
         List<Instruction> instructions = Lists.newArrayList();
-        if(instructionBuilder == null) {
-            instructionBuilder = new InstructionBuilder();
-        }
+        InstructionBuilder instructionBuilder = new InstructionBuilder();
         instructionBuilder.setInstruction(applyActionsCase);
         instructionBuilder.setOrder(0);
         instructionBuilder.setKey(new InstructionKey(0));
@@ -173,7 +156,7 @@ public class EgressAclLearnServiceUtil {
      * fin_hard_timeout=0,priority=61010, cookie=0x6900000,eth_type=0x800,nw_proto=6, NXM_OF_IP_SRC[]=NXM_OF_IP_DST[],NXM_OF_IP_DST[]=NXM_OF_IP_SRC[],
      * NXM_OF_UDP_SRC[]=NXM_OF_UDP_DST[],NXM_OF_UDP_DST[]=NXM_OF_UDP_SRC[],load:0x1->NXM_NX_REG6[0..7]),resubmit(,50)"
      */
-    public static FlowBuilder programEgressAclLearnRuleForUdp(FlowBuilder flowBuilder, InstructionBuilder instructionBuilder,short learnTableId, short resubmitId) {
+    public static FlowBuilder programEgressAclLearnRuleForUdp(FlowBuilder flowBuilder) {
         List<Action> listAction = new ArrayList<>();
         // Create learn action
         /*
@@ -192,7 +175,7 @@ public class EgressAclLearnServiceUtil {
             LearnConstants.LEARN_PRIORITY,
             "0",
             LearnConstants.DELETE_LEARNED_FLAG_VALUE,
-            String.valueOf(learnTableId),
+            String.valueOf(LEARN_TABLE_ID),
             "0",
             "0"
         };
@@ -239,16 +222,14 @@ public class EgressAclLearnServiceUtil {
         listAction.add(buildAction(0, header, flowMod));
         ActionBuilder ab = new ActionBuilder();
         ab = new ActionBuilder();
-        ab.setAction(createResubmitActions(resubmitId));
+        ab.setAction(createResubmitActions());
         ab.setKey(new ActionKey(1));
         listAction.add(ab.build());
         ApplyActions applyActions = new ApplyActionsBuilder().setAction(listAction).build();
         ApplyActionsCase applyActionsCase = new ApplyActionsCaseBuilder().setApplyActions(applyActions).build();
         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
         List<Instruction> instructions = Lists.newArrayList();
-        if(instructionBuilder == null) {
-        instructionBuilder = new InstructionBuilder();
-        }
+        InstructionBuilder instructionBuilder = new InstructionBuilder();
         instructionBuilder.setInstruction(applyActionsCase);
         instructionBuilder.setOrder(0);
         instructionBuilder.setKey(new InstructionKey(0));
@@ -270,7 +251,8 @@ public class EgressAclLearnServiceUtil {
      * fin_hard_timeout=0,priority=61010, cookie=0x6900000,eth_type=0x800,nw_proto=6, NXM_OF_IP_SRC[]=NXM_OF_IP_DST[],NXM_OF_IP_DST[]=NXM_OF_IP_SRC[],
      * NXM_OF_UDP_SRC[]=NXM_OF_UDP_DST[],NXM_OF_UDP_DST[]=NXM_OF_UDP_SRC[],load:0x1->NXM_NX_REG6[0..7]),resubmit(,50)"
      */
-    public static FlowBuilder programEgressAclLearnRuleForIcmp(FlowBuilder flowBuilder, InstructionBuilder instructionBuilder, String icmpType, String icmpCode,short learnTableId, short resubmitId) {
+    public static FlowBuilder programEgressAclLearnRuleForIcmp(FlowBuilder flowBuilder,
+                                                               String icmpType, String icmpCode) {
         List<Action> listAction = new ArrayList<>();
 
         String[] header = new String[] {
@@ -279,7 +261,7 @@ public class EgressAclLearnServiceUtil {
             LearnConstants.LEARN_PRIORITY,
             "0",
             LearnConstants.DELETE_LEARNED_FLAG_VALUE,
-            String.valueOf(learnTableId),
+            String.valueOf(LEARN_TABLE_ID),
             "0",
             "0"
         };
@@ -321,90 +303,7 @@ public class EgressAclLearnServiceUtil {
         listAction.add(buildAction(0, header, flowMod));
         ActionBuilder ab = new ActionBuilder();
         ab = new ActionBuilder();
-        ab.setAction(createResubmitActions(resubmitId));
-        ab.setKey(new ActionKey(1));
-        listAction.add(ab.build());
-        ApplyActions applyActions = new ApplyActionsBuilder().setAction(listAction).build();
-        ApplyActionsCase applyActionsCase = new ApplyActionsCaseBuilder().setApplyActions(applyActions).build();
-        InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
-        List<Instruction> instructions = Lists.newArrayList();
-
-        if(instructionBuilder == null) {
-            instructionBuilder = new InstructionBuilder();
-        }
-        instructionBuilder.setInstruction(applyActionsCase);
-        instructionBuilder.setOrder(0);
-        instructionBuilder.setKey(new InstructionKey(0));
-        instructions.add(instructionBuilder.build());
-        // Add InstructionBuilder to the Instruction(s)Builder List
-        instructionsBuilder.setInstruction(instructions);
-
-        // Add InstructionsBuilder to FlowBuilder
-        flowBuilder.setInstructions(instructionsBuilder.build());
-
-        return flowBuilder;
-
-    }
-
-    /*
-     * (Table:EgressAclLearnService) EgressACL Learning
-     * Match: reg6 = LearnConstants.NxmOfFieldType.NXM_NX_REG6
-     * Action: learn and resubmit to next table
-     * "table=40,dl_src=fa:16:3e:d3:bb:8a,priority=61003,icmp,dl_src=fa:16:3e:55:71:d1,actions=learn(table=39,idle_timeout=300,fin_idle_timeout=0,
-     * fin_hard_timeout=0,priority=61010, cookie=0x6900000,eth_type=0x800,nw_proto=6, NXM_OF_IP_SRC[]=NXM_OF_IP_DST[],NXM_OF_IP_DST[]=NXM_OF_IP_SRC[],
-     * NXM_OF_ICMP_TYPE=NXM_OF_ICMP_TYPE,NXM_OF_ICMP_CODE=NXM_OF_ICMP_CODE,load:0x1->NXM_NX_REG6[0..7]),resubmit(,50)"
-     */
-    public static FlowBuilder programEgressAclLearnRuleForIcmpAll(FlowBuilder flowBuilder, InstructionBuilder instructionBuilder, short learnTableId, short resubmitId) {
-        List<Action> listAction = new ArrayList<>();
-
-        String[] header = new String[] {
-            String.valueOf(NetvirtProvidersProvider.getSecurityGroupDefaultIdleTimeout()),
-            String.valueOf(NetvirtProvidersProvider.getSecurityGroupDefaultHardTimeout()),
-            LearnConstants.LEARN_PRIORITY,
-            "0",
-            LearnConstants.DELETE_LEARNED_FLAG_VALUE,
-            String.valueOf(learnTableId),
-            "0",
-            "0"
-        };
-
-        String[][] flowMod = new String[7][];
-        //eth_type=0x800
-        flowMod[0] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_VALUE.name(),
-                Integer.toString(LearnConstants.ETHTYPE_IPV4),
-                LearnConstants.NxmOfFieldType.NXM_OF_ETH_TYPE.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_ETH_TYPE.getFlowModHeaderLen() };
-        //nw_proto=1
-        flowMod[1] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_VALUE.name(),
-                Integer.toString(LearnConstants.IP_PROT_ICMP),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_PROTO.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_PROTO.getFlowModHeaderLen() };
-        //NXM_OF_IP_SRC[]=NXM_OF_IP_DST[]
-        flowMod[2] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_DST.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_SRC.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_DST.getFlowModHeaderLen()};
-        // NXM_OF_IP_DST[]=NXM_OF_IP_SRC[]
-        flowMod[3] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_SRC.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_DST.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_SRC.getFlowModHeaderLen()};
-         //NXM_OF_ICMP_TYPE=NXM_OF_ICMP_TYPE
-        flowMod[4] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
-                LearnConstants.NxmOfFieldType.NXM_OF_ICMP_TYPE.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_ICMP_TYPE.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_ICMP_TYPE.getFlowModHeaderLen()};
-        // NXM_OF_ICMP_CODE=NXM_OF_ICMP_CODE
-        flowMod[5] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
-                LearnConstants.NxmOfFieldType.NXM_OF_ICMP_CODE.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_ICMP_CODE.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_ICMP_CODE.getFlowModHeaderLen()};
-        flowMod[6] = new String[] {
-                LearnConstants.LearnFlowModsType.COPY_FROM_VALUE.name(), LearnConstants.LEARN_MATCH_REG_VALUE,
-                LearnConstants.NxmOfFieldType.NXM_NX_REG6.getHexType(), "8" };
-        listAction.add(buildAction(0, header, flowMod));
-        ActionBuilder ab = new ActionBuilder();
-        ab.setAction(createResubmitActions(resubmitId));
+        ab.setAction(createResubmitActions());
         ab.setKey(new ActionKey(1));
         listAction.add(ab.build());
         ApplyActions applyActions = new ApplyActionsBuilder().setAction(listAction).build();
@@ -412,9 +311,7 @@ public class EgressAclLearnServiceUtil {
         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
         List<Instruction> instructions = Lists.newArrayList();
 
-        if(instructionBuilder == null) {
-            instructionBuilder = new InstructionBuilder();
-        }
+        InstructionBuilder instructionBuilder = new InstructionBuilder();
         instructionBuilder.setInstruction(applyActionsCase);
         instructionBuilder.setOrder(0);
         instructionBuilder.setKey(new InstructionKey(0));
@@ -426,7 +323,6 @@ public class EgressAclLearnServiceUtil {
         flowBuilder.setInstructions(instructionsBuilder.build());
 
         return flowBuilder;
-
     }
 
     /*
@@ -520,10 +416,10 @@ public class EgressAclLearnServiceUtil {
         return abExt.build();
     }
 
-    private static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action createResubmitActions(short tableId) {
+    private static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action createResubmitActions() {
 
         NxResubmitBuilder gttb = new NxResubmitBuilder();
-        gttb.setTable(tableId);
+        gttb.setTable(RESUBMIT_TABLE_ID);
 
         // Wrap our Apply Action in an InstructionBuilder
         return (new NxActionResubmitRpcAddGroupCaseBuilder().setNxResubmit(gttb.build())).build();
index 369834de5cec02b8ee2c5627fc38333e436b08bf..2f3443fe687248588f179bd3583004d877efa7e0 100644 (file)
@@ -8,12 +8,10 @@
 
 package org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.services;
 
-import java.math.BigInteger;
 import java.net.Inet4Address;
 import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.HashMap;
 import java.util.Map;
@@ -24,7 +22,6 @@ import org.opendaylight.netvirt.openstack.netvirt.api.LearnConstants;
 import org.opendaylight.netvirt.openstack.netvirt.api.SecurityGroupCacheManger;
 import org.opendaylight.netvirt.openstack.netvirt.api.SecurityServicesManager;
 import org.opendaylight.netvirt.openstack.netvirt.providers.ConfigInterface;
-import org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
 import org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.Service;
 import org.opendaylight.netvirt.openstack.netvirt.translator.NeutronSecurityGroup;
 import org.opendaylight.netvirt.openstack.netvirt.translator.NeutronSecurityRule;
@@ -40,37 +37,22 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
-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.model.match.types.rev131026.match.Icmpv4MatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.collect.Lists;
-
-public class EgressAclService extends AbstractServiceInstance implements EgressAclProvider, ConfigInterface {
+public class EgressAclService extends AbstractAclService implements EgressAclProvider, ConfigInterface {
 
     private static final Logger LOG = LoggerFactory.getLogger(EgressAclService.class);
-    private volatile SecurityServicesManager securityServicesManager;
-    private volatile SecurityGroupCacheManger securityGroupCacheManger;
-    private volatile INeutronSecurityRuleCRUD neutronSecurityRule;
     private static final int DHCP_SOURCE_PORT = 67;
     private static final int DHCP_DESTINATION_PORT = 68;
     private static final int DHCPV6_SOURCE_PORT = 547;
     private static final int DHCPV6_DESTINATION_PORT = 546;
-    private static final String HOST_MASK = "/32";
-    private static final String V6_HOST_MASK = "/128";
-    private static final int PORT_RANGE_MIN = 1;
-    private static final int PORT_RANGE_MAX = 65535;
 
     public EgressAclService() {
         super(Service.EGRESS_ACL);
@@ -82,7 +64,7 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
 
     @Override
     public void programPortSecurityGroup(Long dpid, String segmentationId, String attachedMac, long localPort,
-                                       NeutronSecurityGroup securityGroup, String portUuid, NodeId nodeId, boolean write) {
+                                         NeutronSecurityGroup securityGroup, String portUuid, NodeId nodeId, boolean write) {
 
         LOG.trace("programPortSecurityGroup: neutronSecurityGroup: {} ", securityGroup);
         if (securityGroup == null ) {
@@ -120,11 +102,11 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
                     List<Neutron_IPs> remoteSrcAddressList = secGroupRemoteIPMap.get(remoteSgUuid);
                     if (remoteSrcAddressList == null) {
                         remoteSrcAddressList = securityServicesManager
-                                .getVmListForSecurityGroup(portUuid,remoteSgUuid);
+                                .getVmListForSecurityGroup(portUuid, remoteSgUuid);
                         secGroupRemoteIPMap.put(remoteSgUuid, remoteSrcAddressList);
                     }
                     for (Neutron_IPs vmIp :remoteSrcAddressList ) {
-                        programPortSecurityRule(dpid, segmentationId, attachedMac, portSecurityRule, securityGroup, vmIp, write);
+                        programPortSecurityRule(dpid, segmentationId, attachedMac, portSecurityRule, vmIp, write);
                     }
                     if (write) {
                         securityGroupCacheManger.addToCache(remoteSgUuid, portUuid, nodeId);
@@ -133,15 +115,15 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
                                                                  portUuid, nodeId);
                     }
                 } else {
-                    programPortSecurityRule(dpid, segmentationId, attachedMac, portSecurityRule, securityGroup, null, write);
+                    programPortSecurityRule(dpid, segmentationId, attachedMac, portSecurityRule, null, write);
                 }
             }
         }
     }
 
     @Override
-    public void programPortSecurityRule(Long dpid, String segmentationId, String attachedMac, NeutronSecurityRule portSecurityRule,
-                                        NeutronSecurityGroup securityGroup, Neutron_IPs vmIp, boolean write) {
+    public void programPortSecurityRule(Long dpid, String segmentationId, String attachedMac,
+                                        NeutronSecurityRule portSecurityRule, Neutron_IPs vmIp, boolean write) {
         String securityRuleEtherType = portSecurityRule.getSecurityRuleEthertype();
         boolean isIpv6 = NeutronSecurityRule.ETHERTYPE_IPV6.equals(securityRuleEtherType);
         if (!isIpv6 && !NeutronSecurityRule.ETHERTYPE_IPV4.equals(securityRuleEtherType)) {
@@ -150,7 +132,6 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
             return;
         }
 
-
         String ipaddress = null;
         if (null != vmIp) {
             ipaddress = vmIp.getIpAddress();
@@ -166,57 +147,37 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
                 return;
             }
         }
-        if (null == portSecurityRule.getSecurityRuleProtocol() && securityGroup.getSecurityGroupName().equals("default")) {
-            /* TODO Rework on the priority values */
-            egressAclIp(dpid, isIpv6, segmentationId, attachedMac,
-                portSecurityRule, ipaddress,
-                write, Constants.PROTO_PORT_MATCH_PRIORITY - 1, false);
-            if(!isIpv6) {
-                portSecurityRule.setSecurityRuleProtocol(MatchUtils.TCP);
-                portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
-                portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
-                egressAclTcp(dpid, segmentationId, attachedMac,
-                        portSecurityRule,ipaddress, write,
-                        Constants.PROTO_PORT_MATCH_PRIORITY, false);
-                portSecurityRule.setSecurityRuleProtocol(MatchUtils.UDP);
-                egressAclUdp(dpid, segmentationId, attachedMac,
-                        portSecurityRule, ipaddress, write,
-                        Constants.PROTO_PORT_MATCH_PRIORITY, false);
-                portSecurityRule.setSecurityRuleProtocol(MatchUtils.ICMP);
-                portSecurityRule.setSecurityRulePortMin(null);
-                portSecurityRule.setSecurityRulePortMax(null);
-                egressAclIcmp(dpid, segmentationId, attachedMac,
-                        portSecurityRule, ipaddress,write,
-                        Constants.PROTO_PORT_MATCH_PRIORITY, false);
-                portSecurityRule.setSecurityRuleProtocol(null);
+        if (null == portSecurityRule.getSecurityRuleProtocol()
+                || portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.ANY_PROTOCOL)) {
+            egressAclIp(dpid, isIpv6, segmentationId, attachedMac, portSecurityRule, ipaddress, write);
+            if (NeutronSecurityRule.ETHERTYPE_IPV4.equals(portSecurityRule.getSecurityRuleEthertype())) {
+                egressAclTcp(dpid, segmentationId, attachedMac, TCP_SECURITY_GROUP_RULE_IPv4_ANY, ipaddress, write);
+                egressAclUdp(dpid, segmentationId, attachedMac, UDP_SECURITY_GROUP_RULE_IPv4_ANY, ipaddress, write);
+                egressAclIcmp(dpid, segmentationId, attachedMac, ICMP_SECURITY_GROUP_RULE_IPv4_ANY, ipaddress, write);
             }
         } else {
-            switch (portSecurityRule.getSecurityRuleProtocol() == null ? "" : portSecurityRule.getSecurityRuleProtocol()) {
+            switch (portSecurityRule.getSecurityRuleProtocol()) {
                 case MatchUtils.TCP:
+                case MatchUtils.TCP_PROTOCOL:
                     LOG.debug("programPortSecurityRule: Rule matching TCP", portSecurityRule);
-                    egressAclTcp(dpid, segmentationId, attachedMac,
-                        portSecurityRule,ipaddress, write,
-                        Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+                    egressAclTcp(dpid, segmentationId, attachedMac, portSecurityRule, ipaddress, write);
                     break;
                 case MatchUtils.UDP:
+                case MatchUtils.UDP_PROTOCOL:
                     LOG.debug("programPortSecurityRule: Rule matching UDP", portSecurityRule);
-                    egressAclUdp(dpid, segmentationId, attachedMac,
-                        portSecurityRule, ipaddress, write,
-                        Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+                    egressAclUdp(dpid, segmentationId, attachedMac, portSecurityRule, ipaddress, write);
                     break;
                 case MatchUtils.ICMP:
                 case MatchUtils.ICMPV6:
+                case MatchUtils.ICMP_PROTOCOL:
                     LOG.debug("programPortSecurityRule: Rule matching ICMP", portSecurityRule);
-                    egressAclIcmp(dpid, segmentationId, attachedMac,
-                        portSecurityRule, ipaddress,write,
-                        Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+                    egressAclIcmp(dpid, segmentationId, attachedMac, portSecurityRule, ipaddress, write);
                     break;
                 default:
                     LOG.info("programPortSecurityAcl: Protocol is not TCP/UDP/ICMP but other "
                             + "protocol = ", portSecurityRule.getSecurityRuleProtocol());
                     egressOtherProtocolAclHandler(dpid, segmentationId, attachedMac,
-                        portSecurityRule, ipaddress, write,
-                        Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, isIpv6);
+                        portSecurityRule, ipaddress, write, isIpv6);
                     break;
             }
         }
@@ -224,83 +185,41 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
 
     private void egressOtherProtocolAclHandler(Long dpidLong, String segmentationId, String srcMac,
                                                NeutronSecurityRule portSecurityRule, String dstAddress,
-                                               boolean write, Integer priority, boolean isIpv6) {
-        if(null == portSecurityRule.getSecurityRuleProtocol() || portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.ANY_PROTOCOL)) {
-            egressAclIp(dpidLong, isIpv6, segmentationId, srcMac,
-                    portSecurityRule, dstAddress,
-                    write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY - 1, true);
-            if(!isIpv6) {
-                portSecurityRule.setSecurityRuleProtocol(MatchUtils.TCP);
-                portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
-                portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
-                egressAclTcp(dpidLong, segmentationId, srcMac,
-                        portSecurityRule,dstAddress, write,
-                        Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, true);
-                portSecurityRule.setSecurityRuleProtocol(MatchUtils.UDP);
-                egressAclUdp(dpidLong, segmentationId, srcMac,
-                        portSecurityRule, dstAddress, write,
-                        Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, true);
-                portSecurityRule.setSecurityRulePortMin(null);
-                portSecurityRule.setSecurityRulePortMax(null);
-                portSecurityRule.setSecurityRuleProtocol(MatchUtils.ICMP);
-                egressAclIcmp(dpidLong, segmentationId, srcMac,
-                        portSecurityRule, dstAddress,write,
-                        Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, true);
-                portSecurityRule.setSecurityRuleProtocol(null);
-            }
-        } else {
-            if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.TCP_PROTOCOL)) {
-                portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
-                portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
-                egressAclTcp(dpidLong, segmentationId, srcMac,
-                        portSecurityRule,dstAddress, write,
-                        Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
-            } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.UDP_PROTOCOL)) {
-                portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
-                portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
-                egressAclUdp(dpidLong, segmentationId, srcMac,
-                        portSecurityRule, dstAddress, write,
-                        Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
-            } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.ICMP_PROTOCOL)) {
-                egressAclIcmp(dpidLong, segmentationId, srcMac,
-                        portSecurityRule, dstAddress,write,
-                        Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+                                               boolean write, boolean isIpv6) {
+        MatchBuilder matchBuilder = new MatchBuilder();
+        String flowId = "Egress_Other_" + segmentationId + "_" + srcMac + "_";
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, srcMac, null, MatchUtils.ETHERTYPE_IPV4);
+        short proto = 0;
+        try {
+            Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol());
+            proto = protocol.shortValue();
+            flowId = flowId + proto;
+        } catch (NumberFormatException e) {
+            LOG.error("Protocol value conversion failure", e);
+        }
+        matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, srcMac, null);
+        if (null != dstAddress) {
+            flowId = flowId + "_" + dstAddress;
+            matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
+                    MatchUtils.iPv4PrefixFromIPv4Address(dstAddress));
+        } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
+            flowId = flowId + "_" + portSecurityRule.getSecurityRuleRemoteIpPrefix();
+            if (isIpv6) {
+                matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder, null,
+                        new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
             } else {
-                MatchBuilder matchBuilder = new MatchBuilder();
-                String flowId = "Egress_Other_" + segmentationId + "_" + srcMac + "_";
-                matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,srcMac,null,MatchUtils.ETHERTYPE_IPV4);
-                short proto = 0;
-                try {
-                    Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol());
-                    proto = protocol.shortValue();
-                    flowId = flowId + proto;
-                } catch (NumberFormatException e) {
-                    LOG.error("Protocol vlaue conversion failure", e);
-                }
-                matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, srcMac, null);
-                if (null != dstAddress) {
-                    flowId = flowId + dstAddress;
+                if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
                     matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
-                                                                 MatchUtils.iPv4PrefixFromIPv4Address(dstAddress));
-                } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
-                    flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
-                    if(isIpv6) {
-                        matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,null,
-                                new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
-                    } else {
-                        if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
-                            matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
-                                new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
-                        }
-                    }
+                            new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
                 }
-                flowId = flowId + "_Permit";
-                NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, priority, matchBuilder, getTable());
-                addInstructionWithConntrackCommit(flowBuilder, false);
-                syncFlow(flowBuilder ,nodeBuilder, write);
             }
         }
+        flowId = flowId + "_Permit";
+        NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
+        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(
+                flowId, Constants.PROTO_OTHER_MATCH_PRIORITY, matchBuilder, getTable());
+        addInstructionWithConntrackCommit(flowBuilder, false);
+        syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
     }
 
     @Override
@@ -315,19 +234,20 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
         if (securityServicesManager.isConntrackEnabled()) {
             programEgressAclFixedConntrackRule(dpid, segmentationId, localPort, attachedMac, write);
         } else {
-            egressVMDrop(dpid, segmentationId, attachedMac, write,Constants.PROTO_TCP_SYN_MATCH_PRIORITY_DROP);
-            egressVMRegex(dpid, segmentationId, attachedMac, write,Constants.PROTO_REG6_MATCH_PRIORITY);
+            egressVMDrop(dpid, segmentationId, attachedMac, write, Constants.PROTO_PORT_DROP_PRIORITY);
+            egressVMRegex(dpid, segmentationId, attachedMac, write, Constants.PROTO_REG6_MATCH_PRIORITY);
         }
         egressAclDhcpDropServerTrafficfromVm(dpid, localPort, write,
                                              Constants.PROTO_DHCP_CLIENT_SPOOF_MATCH_PRIORITY_DROP);
         egressAclDhcpv6DropServerTrafficfromVm(dpid, localPort, write,
                                                Constants.PROTO_DHCP_CLIENT_SPOOF_MATCH_PRIORITY_DROP);
     }
+
     private void egressVMRegex(Long dpidLong, String segmentationId, String srcMac,
             boolean write, Integer priority) {
         String flowName = "Egress_Regx_" + segmentationId + "_" + srcMac;
         MatchBuilder matchBuilder = new MatchBuilder();
-        matchBuilder = MatchUtils.createV4EtherMatchWithoutType(matchBuilder,srcMac,null);
+        matchBuilder = MatchUtils.createV4EtherMatchWithoutType(matchBuilder, srcMac, null);
         MatchUtils.addNxRegMatch(matchBuilder,
                 new MatchUtils.RegMatch(ClassifierService.REG_FIELD_6, ClassifierService.REG_VALUE_FROM_LOCAL));
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
@@ -336,34 +256,11 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
         syncFlow(flowBuilder, nodeBuilder, write);
     }
 
-    private void addTcpSynFlagMatchIpv4Drop(Long dpidLong, String segmentationId, String srcMac,
-                                  boolean write, Integer priority) {
-        String flowName = "Egress_TCP_Ipv4_" + segmentationId + "_" + srcMac + "_DROP";
-        MatchBuilder matchBuilder = new MatchBuilder();
-        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,srcMac,null,MatchUtils.ETHERTYPE_IPV4);
-        matchBuilder = MatchUtils.addTcpSynMatch(matchBuilder);
-        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
-        addPipelineInstruction(flowBuilder, null, true);
-        NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder, nodeBuilder, write);
-    }
     private void egressVMDrop(Long dpidLong, String segmentationId, String srcMac,
             boolean write, Integer priority) {
         String flowName = "Egress_Drop_" + segmentationId + "_" + srcMac + "_DROP";
         MatchBuilder matchBuilder = new MatchBuilder();
-        matchBuilder = MatchUtils.createV4EtherMatchWithoutType(matchBuilder,srcMac,null);
-        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
-        addPipelineInstruction(flowBuilder, null, true);
-        NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder, nodeBuilder, write);
-    }
-
-    private void addTcpSynFlagMatchIpv6Drop(Long dpidLong, String segmentationId, String srcMac,
-                                        boolean write, Integer priority) {
-        String flowName = "Egress_TCP_Ipv6_" + segmentationId + "_" + srcMac + "_DROP";
-        MatchBuilder matchBuilder = new MatchBuilder();
-        matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder,srcMac,null);
-        matchBuilder = MatchUtils.addTcpSynMatch(matchBuilder);
+        matchBuilder = MatchUtils.createV4EtherMatchWithoutType(matchBuilder, srcMac, null);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, true);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
@@ -373,19 +270,19 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
     private void programArpRule(Long dpid, String segmentationId, long localPort, String attachedMac, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowId = "Egress_ARP_" + segmentationId + "_" + localPort + "_";
-        MatchUtils.createV4EtherMatchWithType(matchBuilder,null,null,MatchUtils.ETHERTYPE_ARP);
+        MatchUtils.createV4EtherMatchWithType(matchBuilder, null, null, MatchUtils.ETHERTYPE_ARP);
         MatchUtils.addArpMacMatch(matchBuilder, attachedMac, null);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, Constants.PROTO_MATCH_PRIORITY,
                                                               matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpid);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     private void programEgressAclFixedConntrackRule(Long dpid,
                                              String segmentationId, long localPort, String attachMac, boolean write) {
         try {
-            programConntrackUntrackRule(dpid, segmentationId, localPort,attachMac,
+            programConntrackUntrackRule(dpid, segmentationId, localPort, attachMac,
                                         Constants.CT_STATE_UNTRACKED_PRIORITY, write );
             programConntrackTrackedPlusEstRule(dpid, segmentationId, localPort,
                                                Constants.CT_STATE_TRACKED_EXIST_PRIORITY, write );
@@ -405,39 +302,39 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
                                              long localPort, String attachMac, Integer priority, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowName = "Egress_Fixed_Conntrk_Untrk_" + segmentationId + "_" + localPort + "_";
-        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, attachMac, null,MatchUtils.ETHERTYPE_IPV4);
-        matchBuilder = MatchUtils.addCtState(matchBuilder,MatchUtils.UNTRACKED_CT_STATE,
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, attachMac, null, MatchUtils.ETHERTYPE_IPV4);
+        matchBuilder = MatchUtils.addCtState(matchBuilder, MatchUtils.UNTRACKED_CT_STATE,
                                              MatchUtils.UNTRACKED_CT_STATE_MASK);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addInstructionWithConntrackRecirc(flowBuilder);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     private void programConntrackTrackedPlusEstRule(Long dpidLong, String segmentationId,
-                                                    long localPort,Integer priority, boolean write) {
+                                                    long localPort, Integer priority, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowName = "Egress_Fixed_Conntrk_TrkEst_" + segmentationId + "_" + localPort + "_";
         matchBuilder = MatchUtils.createInPortMatch(matchBuilder, dpidLong, localPort);
-        matchBuilder = MatchUtils.addCtState(matchBuilder,MatchUtils.TRACKED_EST_CT_STATE,
+        matchBuilder = MatchUtils.addCtState(matchBuilder, MatchUtils.TRACKED_EST_CT_STATE,
                                              MatchUtils.TRACKED_CT_STATE_MASK);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     private void programConntrackTrackedPlusRelRule(Long dpidLong, String segmentationId,
-                                                    long localPort,Integer priority, boolean write) {
+                                                    long localPort, Integer priority, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowName = "Egress_Fixed_Conntrk_TrkRel_" + segmentationId + "_" + localPort + "_";
         matchBuilder = MatchUtils.createInPortMatch(matchBuilder, dpidLong, localPort);
-        matchBuilder = MatchUtils.addCtState(matchBuilder,MatchUtils.TRACKED_REL_CT_STATE,
+        matchBuilder = MatchUtils.addCtState(matchBuilder, MatchUtils.TRACKED_REL_CT_STATE,
                                              MatchUtils.TRACKED_CT_STATE_MASK);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     private void programConntrackNewDropRule(Long dpidLong, String segmentationId,
@@ -446,12 +343,12 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
 
         String flowName = "Egress_Fixed_Conntrk_NewDrop_" + segmentationId + "_" + localPort + "_";
         matchBuilder = MatchUtils.createInPortMatch(matchBuilder, dpidLong, localPort);
-        matchBuilder = MatchUtils.addCtState(matchBuilder,MatchUtils.TRACKED_NEW_CT_STATE,
+        matchBuilder = MatchUtils.addCtState(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,
                                              MatchUtils.TRACKED_NEW_CT_STATE_MASK);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, true);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     private void programConntrackInvDropRule(Long dpidLong, String segmentationId,
@@ -459,12 +356,12 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowName = "Egress_Fixed_Conntrk_InvDrop_" + segmentationId + "_" + localPort + "_";
         matchBuilder = MatchUtils.createInPortMatch(matchBuilder, dpidLong, localPort);
-        matchBuilder = MatchUtils.addCtState(matchBuilder,MatchUtils.TRACKED_INV_CT_STATE,
+        matchBuilder = MatchUtils.addCtState(matchBuilder, MatchUtils.TRACKED_INV_CT_STATE,
                                              MatchUtils.TRACKED_INV_CT_STATE_MASK);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, true);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     /**
@@ -474,43 +371,35 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
      * @param segmentationId the segementation id
      * @param srcMac the src mac address
      * @param write add or remove
-     * @param isRegMatchReq add Reg MAtch or not
-     * @param protoPortMatchPriority the protocol match priority.
      */
     private void egressAclIp(Long dpidLong, boolean isIpv6, String segmentationId, String srcMac,
-                             NeutronSecurityRule portSecurityRule, String srcAddress,
-                               boolean write, Integer protoPortMatchPriority, boolean isRegMatchReq ) {
+                             NeutronSecurityRule portSecurityRule, String srcAddress, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowId = "Egress_IP" + segmentationId + "_" + srcMac + "_Permit_";
         if (isIpv6) {
-            matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder,srcMac,null);
+            matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder, srcMac, null);
         } else {
-            matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,srcMac,null,MatchUtils.ETHERTYPE_IPV4);
-        }
-        if (isRegMatchReq) {
-            flowId = flowId + "_regEx_";
-            MatchUtils.addNxRegMatch(matchBuilder,
-                    new MatchUtils.RegMatch(ClassifierService.REG_FIELD_6, ClassifierService.REG_VALUE_FROM_LOCAL_0));
+            matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, srcMac, null, MatchUtils.ETHERTYPE_IPV4);
         }
         if (null != srcAddress) {
             flowId = flowId + srcAddress;
             if (isIpv6) {
                 matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,
-                        MatchUtils.iPv6PrefixFromIPv6Address(srcAddress),null);
+                        MatchUtils.iPv6PrefixFromIPv6Address(srcAddress), null);
             } else {
                 matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
-                        MatchUtils.iPv4PrefixFromIPv4Address(srcAddress),null);
+                        MatchUtils.iPv4PrefixFromIPv4Address(srcAddress), null);
             }
         } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
             flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
             if (isIpv6) {
-                matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,null,
+                matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder, null,
                         new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
             } else {
                 // Fix: Bug 6473
                 // IP match removed if CIDR created as 0.0.0.0/0 in openstack security rule
                 if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
-                    matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,null,
+                    matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
                             new Ipv4Prefix(portSecurityRule
                                            .getSecurityRuleRemoteIpPrefix()));
                  }
@@ -522,11 +411,12 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
                 flowId = flowId + "Ipv4";
             }
         }
-        addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority, matchBuilder, getTable());
+        addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(
+                flowId, Constants.PROTO_IP_PORT_MATCH_PRIORITY, matchBuilder, getTable());
         addInstructionWithConntrackCommit(flowBuilder, false);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
     }
 
     /**
@@ -539,25 +429,18 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
      * @param portSecurityRule the security rule in the SG
      * @param dstAddress the destination IP address
      * @param write add or delete
-     * @param isRegMatchReq add Reg MAtch or not
-     * @param protoPortMatchPriority the protocol match priroty
      */
     private void egressAclTcp(Long dpidLong, String segmentationId, String srcMac,
-                              NeutronSecurityRule portSecurityRule, String dstAddress,
-                              boolean write, Integer protoPortMatchPriority, boolean isRegMatchReq) {
+                              NeutronSecurityRule portSecurityRule, String dstAddress, boolean write) {
+        LOG.debug("egressAclTcp: portSecurityRule {} ", portSecurityRule);
         boolean portRange = false;
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowId = "Egress_TCP_" + segmentationId + "_" + srcMac + "_";
         boolean isIpv6 = NeutronSecurityRule.ETHERTYPE_IPV6.equals(portSecurityRule.getSecurityRuleEthertype());
         if (isIpv6) {
-            matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder,srcMac,null);
+            matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder, srcMac, null);
         } else {
-            matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,srcMac,null,MatchUtils.ETHERTYPE_IPV4);
-        }
-        if (isRegMatchReq) {
-            flowId = flowId + "_regEx_";
-            MatchUtils.addNxRegMatch(matchBuilder,
-                    new MatchUtils.RegMatch(ClassifierService.REG_FIELD_6, ClassifierService.REG_VALUE_FROM_LOCAL_0));
+            matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, srcMac, null, MatchUtils.ETHERTYPE_IPV4);
         }
 
         /* Custom TCP Match */
@@ -583,22 +466,22 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
         if (null != dstAddress) {
             flowId = flowId + dstAddress;
             if (isIpv6) {
-                matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,null,
+                matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder, null,
                         MatchUtils.iPv6PrefixFromIPv6Address(dstAddress));
             } else {
-                matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,null,
+                matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
                         MatchUtils.iPv4PrefixFromIPv4Address(dstAddress));
             }
         } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
             flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
             if (isIpv6) {
-                matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,null,
+                matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder, null,
                         new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
             } else {
                 // Fix: Bug 6473
                 // IP match removed if CIDR created as 0.0.0.0/0 in openstack security rule
                 if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
-                    matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,null,
+                    matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
                             new Ipv4Prefix(portSecurityRule
                                            .getSecurityRuleRemoteIpPrefix()));
                  }
@@ -610,43 +493,34 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
                     .getLayer4MaskForRange(portSecurityRule.getSecurityRulePortMin(),
                                            portSecurityRule.getSecurityRulePortMax());
             for (Integer port: portMaskMap.keySet()) {
-                String rangeflowId = flowId + port + "_" + portMaskMap.get(port) + "_";
+                String rangeflowId = flowId + port + "_" + portMaskMap.get(port);
                 rangeflowId = rangeflowId + "_Permit";
                 MatchUtils.addLayer4MatchWithMask(matchBuilder, MatchUtils.TCP_SHORT,
                                                   0, port, portMaskMap.get(port));
-                addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(rangeflowId, protoPortMatchPriority,
-                                                                      matchBuilder, getTable());
+                addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(
+                        rangeflowId, Constants.PROTO_PORT_MATCH_PRIORITY, matchBuilder, getTable());
                 addInstructionWithLearnConntrackCommit(portSecurityRule, flowBuilder, null, null);
-                syncFlow(flowBuilder ,nodeBuilder, write);
+                syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
             }
         } else {
             flowId = flowId + "_Permit";
-            addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-            FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority,
+            addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+            FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, Constants.PROTO_PORT_MATCH_PRIORITY,
                                                                   matchBuilder, getTable());
             addInstructionWithLearnConntrackCommit(portSecurityRule, flowBuilder, null, null);
-            syncFlow(flowBuilder ,nodeBuilder, write);
-        }
-    }
-
-    private void addTcpSynMatch(MatchBuilder matchBuilder) {
-        if (!securityServicesManager.isConntrackEnabled()) {
-            MatchUtils.createTcpProtoSynMatch(matchBuilder);
+            syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
         }
     }
 
     private void egressAclIcmp(Long dpidLong, String segmentationId, String srcMac,
-            NeutronSecurityRule portSecurityRule, String dstAddress,
-            boolean write, Integer protoPortMatchPriority, boolean isRegMatchReq) {
+            NeutronSecurityRule portSecurityRule, String dstAddress, boolean write) {
 
         boolean isIpv6 = NeutronSecurityRule.ETHERTYPE_IPV6.equals(portSecurityRule.getSecurityRuleEthertype());
         if (isIpv6) {
-            egressAclIcmpV6(dpidLong, segmentationId, srcMac, portSecurityRule, dstAddress, write,
-                            protoPortMatchPriority, isRegMatchReq);
+            egressAclIcmpV6(dpidLong, segmentationId, srcMac, portSecurityRule, dstAddress, write);
         } else {
-            egressAclIcmpV4(dpidLong, segmentationId, srcMac, portSecurityRule, dstAddress, write,
-                            protoPortMatchPriority, isRegMatchReq);
+            egressAclIcmpV4(dpidLong, segmentationId, srcMac, portSecurityRule, dstAddress, write);
         }
     }
 
@@ -660,17 +534,15 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
      * @param portSecurityRule the security rule in the SG
      * @param dstAddress the source IP address
      * @param write add or delete
-     * @param isRegMatchReq add Reg MAtch or not
-     * @param protoPortMatchPriority the protocol match priority
      */
     private void egressAclIcmpV4(Long dpidLong, String segmentationId, String srcMac,
-                                 NeutronSecurityRule portSecurityRule, String dstAddress,
-                                 boolean write, Integer protoPortMatchPriority, boolean isRegMatchReq) {
+                                 NeutronSecurityRule portSecurityRule, String dstAddress, boolean write) {
 
         MatchBuilder matchBuilder = new MatchBuilder();
         boolean isIcmpAll = false;
         String flowId = "Egress_ICMP_" + segmentationId + "_" + srcMac + "_";
-        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,srcMac,null,MatchUtils.ETHERTYPE_IPV4);
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, srcMac, null, MatchUtils.ETHERTYPE_IPV4);
+
         /*Custom ICMP Match */
         if (portSecurityRule.getSecurityRulePortMin() != null
                 && portSecurityRule.getSecurityRulePortMax() != null) {
@@ -681,91 +553,75 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
                     portSecurityRule.getSecurityRulePortMax().shortValue());
         } else {
             isIcmpAll = true;
-            /* All ICMP Match */ // We are getting from neutron NULL for both min and max
-            flowId = flowId + "all" + "_" ;
-            matchBuilder = MatchUtils.createICMPv4Match(matchBuilder, MatchUtils.ALL_ICMP, MatchUtils.ALL_ICMP);
-        }
-        if (isRegMatchReq) {
-            flowId = flowId + "_regEx_";
-            MatchUtils.addNxRegMatch(matchBuilder,
-                    new MatchUtils.RegMatch(ClassifierService.REG_FIELD_6, ClassifierService.REG_VALUE_FROM_LOCAL_0));
         }
+
         if (null != dstAddress) {
             flowId = flowId + dstAddress;
-            matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,null,
+            matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
                     MatchUtils.iPv4PrefixFromIPv4Address(dstAddress));
         } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
             flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
             if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
-                matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,null,
+                matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
                     new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
             }
         }
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        //matchBuilder = MatchUtils.createICMPv4Match(matchBuilder, portSecurityRule.getSecurityRulePortMin().shortValue(), portSecurityRule.getSecurityRulePortMax().shortValue());
         if(isIcmpAll)
         {
             Map<Integer, String> map = LearnConstants.ICMP_TYPE_MAP;
             for(Map.Entry<Integer, String> entry : map.entrySet()) {
-                Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
-                icmpv4match.setIcmpv4Type(entry.getKey().shortValue());
-                icmpv4match.setIcmpv4Code((short)0);
-                matchBuilder.setIcmpv4Match(icmpv4match.build());
-                String rangeflowId = flowId + "_" + entry.getKey() + "_" + entry.getValue();
-                addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(rangeflowId, protoPortMatchPriority, matchBuilder, getTable());
+                matchBuilder = MatchUtils.createICMPv4Match(matchBuilder, entry.getKey().shortValue(), (short)0);
+                String rangeflowId = flowId + entry.getKey() + "_" + entry.getValue() + "_";
+                rangeflowId = rangeflowId + "_Permit";
+                addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(
+                        rangeflowId, Constants.PROTO_PORT_MATCH_PRIORITY, matchBuilder, getTable());
                 addInstructionWithLearnConntrackCommit(portSecurityRule, flowBuilder, entry.getValue(), "0");
-                syncFlow(flowBuilder ,nodeBuilder, write);
+                syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
             }
-            addIcmpFlow(nodeBuilder, portSecurityRule, segmentationId, srcMac, protoPortMatchPriority - 1, dstAddress, write, isRegMatchReq);
+            addIcmpFlow(nodeBuilder, portSecurityRule, segmentationId, srcMac, dstAddress, write);
         } else {
             flowId = flowId + "_Permit";
-            addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-            FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority, matchBuilder, getTable());
+            addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+            FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(
+                    flowId, Constants.PROTO_PORT_MATCH_PRIORITY, matchBuilder, getTable());
              String icmpType = LearnConstants.ICMP_TYPE_MAP.get(portSecurityRule.getSecurityRulePortMin());
             if (icmpType == null){
                 icmpType = Integer.toString(portSecurityRule.getSecurityRulePortMin());
             }
             addInstructionWithLearnConntrackCommit(portSecurityRule, flowBuilder, icmpType,
                     Integer.toString(portSecurityRule.getSecurityRulePortMax()));
-            syncFlow(flowBuilder ,nodeBuilder, write);
+            syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
         }
     }
 
-    private void addIcmpFlow(NodeBuilder nodeBuilder, NeutronSecurityRule portSecurityRule, String segmentationId, String srcMac,
-            Integer protoPortMatchPriority, String dstAddress, boolean write, boolean isRegMatchReq) {
+    private void addIcmpFlow(NodeBuilder nodeBuilder, NeutronSecurityRule portSecurityRule, String segmentationId,
+                             String srcMac, String dstAddress, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
-        InstructionBuilder instructionBuilder = null;
-        short learnTableId=getTable(Service.ACL_LEARN_SERVICE);
-        short resubmitId=getTable(Service.LOAD_BALANCER);
         String flowId = "Ingress_ICMP_" + segmentationId + "_" + srcMac + "_";
-        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,srcMac,null,MatchUtils.ETHERTYPE_IPV4);
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, srcMac, null, MatchUtils.ETHERTYPE_IPV4);
         flowId = flowId + "all" + "_" ;
         matchBuilder = MatchUtils.createICMPv4Match(matchBuilder, MatchUtils.ALL_ICMP, MatchUtils.ALL_ICMP);
         if (null != dstAddress) {
             flowId = flowId + dstAddress;
-            matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,null,
+            matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
                     MatchUtils.iPv4PrefixFromIPv4Address(dstAddress));
         } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
             flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
             if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
-                matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,null,
+                matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
                     new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
             }
         }
-        if (isRegMatchReq) {
-            flowId = flowId + "_regEx_";
-            MatchUtils.addNxRegMatch(matchBuilder,
-                    new MatchUtils.RegMatch(ClassifierService.REG_FIELD_6, ClassifierService.REG_VALUE_FROM_LOCAL_0));
-        }
-        Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
-        matchBuilder.setIcmpv4Match(icmpv4match.build());
+        /* All ICMP Match */
+        matchBuilder = MatchUtils.createICMPv4Match(matchBuilder, MatchUtils.ALL_ICMP, MatchUtils.ALL_ICMP);
         String rangeflowId = flowId;
-        addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(rangeflowId, protoPortMatchPriority, matchBuilder, getTable());
+        addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(
+                rangeflowId, Constants.PROTO_PORT_ICMP_MATCH_PRIORITY, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
-        syncFlow(flowBuilder ,nodeBuilder, write);
-
+        syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
     }
 
     /**
@@ -778,16 +634,13 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
      * @param portSecurityRule the security rule in the SG
      * @param dstAddress the source IP address
      * @param write add or delete
-     * @param isRegMatchReq add Reg MAtch or not
-     * @param protoPortMatchPriority the protocol match priority
      */
     private void egressAclIcmpV6(Long dpidLong, String segmentationId, String srcMac,
-                                 NeutronSecurityRule portSecurityRule, String dstAddress,
-                                 boolean write, Integer protoPortMatchPriority, boolean isRegMatchReq) {
+                                 NeutronSecurityRule portSecurityRule, String dstAddress, boolean write) {
 
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowId = "Egress_ICMP_" + segmentationId + "_" + srcMac + "_";
-        matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder,srcMac,null);
+        matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder, srcMac, null);
 
         /*Custom ICMP Match */
         if (portSecurityRule.getSecurityRulePortMin() != null
@@ -802,26 +655,21 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
             flowId = flowId + "all" + "_" ;
             matchBuilder = MatchUtils.createICMPv6Match(matchBuilder, MatchUtils.ALL_ICMP, MatchUtils.ALL_ICMP);
         }
-        if (isRegMatchReq) {
-            flowId = flowId + "_regEx_";
-            MatchUtils.addNxRegMatch(matchBuilder,
-                    new MatchUtils.RegMatch(ClassifierService.REG_FIELD_6, ClassifierService.REG_VALUE_FROM_LOCAL_0));
-        }
         if (null != dstAddress) {
             flowId = flowId + dstAddress;
-            matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,null,
+            matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder, null,
                     MatchUtils.iPv6PrefixFromIPv6Address(dstAddress));
         } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
             flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
-            matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,null,
+            matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder, null,
                     new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
         }
         flowId = flowId + "_Permit";
-        addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+        addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority, matchBuilder, getTable());
+        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, Constants.PROTO_PORT_MATCH_PRIORITY, matchBuilder, getTable());
         addInstructionWithConntrackCommit(flowBuilder, false);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     /**
@@ -834,25 +682,18 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
      * @param portSecurityRule the security rule in the SG
      * @param dstAddress the source IP address
      * @param write add or delete
-     * @param isRegMatchReq add Reg MAtch or not
-     * @param protoPortMatchPriority the protocol match priroty
      */
     private void egressAclUdp(Long dpidLong, String segmentationId, String srcMac,
-                              NeutronSecurityRule portSecurityRule, String dstAddress,
-                              boolean write, Integer protoPortMatchPriority, boolean isRegMatchReq) {
+                              NeutronSecurityRule portSecurityRule, String dstAddress, boolean write) {
+        LOG.debug("egressAclTcp: egressAclUdp {} ", portSecurityRule);
         boolean portRange = false;
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowId = "Egress_UDP_" + segmentationId + "_" + srcMac + "_";
         boolean isIpv6 = NeutronSecurityRule.ETHERTYPE_IPV6.equals(portSecurityRule.getSecurityRuleEthertype());
         if (isIpv6) {
-            matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder,srcMac,null);
+            matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder, srcMac, null);
         } else {
-            matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,srcMac,null,MatchUtils.ETHERTYPE_IPV4);
-        }
-        if (isRegMatchReq) {
-            flowId = flowId + "_regEx_";
-            MatchUtils.addNxRegMatch(matchBuilder,
-                    new MatchUtils.RegMatch(ClassifierService.REG_FIELD_6, ClassifierService.REG_VALUE_FROM_LOCAL_0));
+            matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, srcMac, null, MatchUtils.ETHERTYPE_IPV4);
         }
 
         /* Custom UDP Match */
@@ -878,10 +719,10 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
         if (null != dstAddress) {
             flowId = flowId + dstAddress;
             if (isIpv6) {
-                matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,null,
+                matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder, null,
                         MatchUtils.iPv6PrefixFromIPv6Address(dstAddress));
             } else {
-                matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,null,
+                matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
                         MatchUtils.iPv4PrefixFromIPv4Address(dstAddress));
             }
         } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
@@ -908,19 +749,19 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
                 rangeflowId = rangeflowId + "_Permit";
                 MatchUtils.addLayer4MatchWithMask(matchBuilder, MatchUtils.UDP_SHORT,
                                                   0, port, portMaskMap.get(port));
-                addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(rangeflowId, protoPortMatchPriority,
+                addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(rangeflowId, Constants.PROTO_PORT_MATCH_PRIORITY,
                                                                       matchBuilder, getTable());
                 addInstructionWithLearnConntrackCommit(portSecurityRule, flowBuilder, null, null);
-                syncFlow(flowBuilder ,nodeBuilder, write);
+                syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
             }
         } else {
             flowId = flowId + "_Permit";
-            addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-            FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority,
+            addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+            FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, Constants.PROTO_PORT_MATCH_PRIORITY,
                                                                   matchBuilder, getTable());
             addInstructionWithLearnConntrackCommit(portSecurityRule, flowBuilder, null, null);
-            syncFlow(flowBuilder ,nodeBuilder, write);
+            syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
         }
     }
 
@@ -941,7 +782,7 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     /**
@@ -961,7 +802,7 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     /**
@@ -981,7 +822,7 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, true);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     /**
@@ -1002,7 +843,7 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, true);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     /**
@@ -1019,14 +860,14 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
                                                       String attachedMac, String srcIp,
                                                       Integer priority, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
-        MatchUtils.createSrcL3Ipv4MatchWithMac(matchBuilder, new Ipv4Prefix(srcIp),new MacAddress(attachedMac));
+        MatchUtils.createSrcL3Ipv4MatchWithMac(matchBuilder, new Ipv4Prefix(srcIp), new MacAddress(attachedMac));
         MatchUtils.createInPortMatch(matchBuilder, dpidLong, localPort);
         LOG.debug("egressAclAllowTrafficFromVmIpMacPair: MatchBuilder contains: {}", matchBuilder);
         String flowName = "Egress_Allow_VM_IP_MAC" + "_" + localPort + attachedMac + "_Permit_";
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     /**
@@ -1043,119 +884,37 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
                                                         String attachedMac, String srcIp,
                                                         Integer priority, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
-        MatchUtils.createSrcL3Ipv6MatchWithMac(matchBuilder, new Ipv6Prefix(srcIp),new MacAddress(attachedMac));
+        MatchUtils.createSrcL3Ipv6MatchWithMac(matchBuilder, new Ipv6Prefix(srcIp), new MacAddress(attachedMac));
         MatchUtils.createInPortMatch(matchBuilder, dpidLong, localPort);
         LOG.debug("egressAclAllowTrafficFromVmIpMacPair: MatchBuilder contains: {}", matchBuilder);
         String flowName = "Egress_Allow_VM_IPv6_MAC" + "_" + localPort + attachedMac + "_Permit_";
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
-    }
-
-    private void addConntrackMatch(MatchBuilder matchBuilder, int state, int mask) {
-        if (securityServicesManager.isConntrackEnabled()) {
-            MatchUtils.addCtState(matchBuilder, state, mask );
-        }
-
+        syncFlow(flowBuilder, nodeBuilder, write);
     }
 
-    private FlowBuilder addInstructionWithConntrackCommit( FlowBuilder flowBuilder , boolean isDrop) {
-        InstructionBuilder instructionBuilder = null;
-        if (securityServicesManager.isConntrackEnabled()) {
-            Action conntrackAction = ActionUtils.nxConntrackAction(1, 0L, 0, (short)0xff);
-            instructionBuilder = InstructionUtils
-                    .createInstructionBuilder(ActionUtils.conntrackActionBuilder(conntrackAction), 1, false);
-        }
-        return addPipelineInstruction(flowBuilder,instructionBuilder, isDrop);
-    }
     private FlowBuilder addInstructionWithLearnConntrackCommit(NeutronSecurityRule portSecurityRule, FlowBuilder flowBuilder, String icmpType, String icmpCode) {
         InstructionBuilder instructionBuilder = null;
-        short learnTableId=getTable(Service.ACL_LEARN_SERVICE);
-        short resubmitId=getTable(Service.LOAD_BALANCER);
         if (securityServicesManager.isConntrackEnabled()) {
             Action conntrackAction = ActionUtils.nxConntrackAction(1, 0L, 0, (short)0xff);
             instructionBuilder = InstructionUtils
                     .createInstructionBuilder(ActionUtils.conntrackActionBuilder(conntrackAction), 1, false);
-            return addPipelineInstruction(flowBuilder,instructionBuilder, false);
-        }
-        if (portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.TCP) || portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.TCP_PROTOCOL)) {
-            return EgressAclLearnServiceUtil.programEgressAclLearnRuleForTcp(flowBuilder,instructionBuilder,learnTableId,resubmitId);
-        } else if (portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.UDP)  || portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.UDP_PROTOCOL)) {
-            return EgressAclLearnServiceUtil.programEgressAclLearnRuleForUdp(flowBuilder,instructionBuilder,learnTableId,resubmitId);
-        } else if (portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.ICMP)  || portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.ICMP_PROTOCOL)) {
-            return EgressAclLearnServiceUtil.programEgressAclLearnRuleForIcmp(flowBuilder,instructionBuilder, icmpType, icmpCode,learnTableId,resubmitId);
-        }
-        return flowBuilder;
-    }
-
-    private FlowBuilder addInstructionWithConntrackRecirc( FlowBuilder flowBuilder) {
-        InstructionBuilder instructionBuilder = null;
-        if (securityServicesManager.isConntrackEnabled()) {
-            Action conntrackAction = ActionUtils.nxConntrackAction(0, 0L, 0, (short)0x0);
-
-            instructionBuilder = InstructionUtils
-                    .createInstructionBuilder(ActionUtils.conntrackActionBuilder(conntrackAction), 1, false);
-            List<Instruction> instructionsList = Lists.newArrayList();
-            instructionsList.add(instructionBuilder.build());
-            InstructionsBuilder isb = new InstructionsBuilder();
-            isb.setInstruction(instructionsList);
-            flowBuilder.setInstructions(isb.build());
-        }
-        return flowBuilder;
-    }
-
-    private FlowBuilder addPipelineInstruction( FlowBuilder flowBuilder ,
-                                                InstructionBuilder instructionBuilder,boolean isDrop) {
-        InstructionBuilder pipeLineIndstructionBuilder = createPipleLineInstructionBuilder(isDrop);
-        List<Instruction> instructionsList = Lists.newArrayList();
-        instructionsList.add(pipeLineIndstructionBuilder.build());
-        if (null != instructionBuilder) {
-            instructionsList.add(instructionBuilder.build());
+            return addPipelineInstruction(flowBuilder, instructionBuilder, false);
+        }
+        if (portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.TCP)
+                || portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.TCP_PROTOCOL)) {
+            return EgressAclLearnServiceUtil.programEgressAclLearnRuleForTcp(flowBuilder);
+        } else if (portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.UDP)
+                || portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.UDP_PROTOCOL)) {
+            return EgressAclLearnServiceUtil.programEgressAclLearnRuleForUdp(flowBuilder);
+        } else if (portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.ICMP)
+                || portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.ICMP_PROTOCOL)) {
+            return EgressAclLearnServiceUtil.programEgressAclLearnRuleForIcmp(flowBuilder, icmpType, icmpCode);
         }
-        InstructionsBuilder isb = new InstructionsBuilder();
-        isb.setInstruction(instructionsList);
-        flowBuilder.setInstructions(isb.build());
         return flowBuilder;
     }
 
-    private InstructionBuilder createPipleLineInstructionBuilder(boolean drop) {
-        InstructionBuilder ib = this.getMutablePipelineInstructionBuilder();
-        if (drop) {
-            InstructionUtils.createDropInstructions(ib);
-        }
-        ib.setOrder(0);
-        List<Instruction> instructionsList = Lists.newArrayList();
-        ib.setKey(new InstructionKey(0));
-        instructionsList.add(ib.build());
-        return ib;
-    }
-    /**
-     * Add or remove flow to the node.
-     * @param flowBuilder the flow builder
-     * @param nodeBuilder the node builder
-     * @param write whether it is a write
-     */
-    private void syncFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder,
-                          boolean write) {
-        if (write) {
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            removeFlow(flowBuilder, nodeBuilder);
-        }
-    }
-
-    private List<NeutronSecurityRule> getSecurityRulesforGroup(NeutronSecurityGroup securityGroup) {
-        List<NeutronSecurityRule> securityRules = new ArrayList<>();
-        List<NeutronSecurityRule> rules = neutronSecurityRule.getAllNeutronSecurityRules();
-        for (NeutronSecurityRule securityRule : rules) {
-            if (securityGroup.getID().equals(securityRule.getSecurityRuleGroupID())) {
-                securityRules.add(securityRule);
-            }
-        }
-        return securityRules;
-    }
-
     @Override
     public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
         super.setDependencies(bundleContext.getServiceReference(EgressAclProvider.class.getName()), this);
index ce9be052e789210c4fbf2f16dd2c358f66de99ce..b8b6ab9e14b3046ea057e045268f9885262eb3fd 100644 (file)
@@ -67,6 +67,8 @@ import org.slf4j.LoggerFactory;
 import com.google.common.collect.Lists;
 
 public class IngressAclLearnServiceUtil {
+    private static final short LEARN_TABLE_ID = Service.ACL_LEARN_SERVICE.getTable();
+    private static final short RESUBMIT_TABLE_ID = Service.OUTBOUND_NAT.getTable();
 
     /*
      * (Table:IngressAclLearnService) IngressAcl Learning
@@ -76,7 +78,7 @@ public class IngressAclLearnServiceUtil {
      * fin_hard_timeout=0,priority=61010, cookie=0x6900000,eth_type=0x800,nw_proto=6, NXM_OF_IP_SRC[]=NXM_OF_IP_DST[],NXM_OF_IP_DST[]=NXM_OF_IP_SRC[],
      * NXM_OF_TCP_SRC[]=NXM_OF_TCP_DST[],NXM_OF_TCP_DST[]=NXM_OF_TCP_SRC[],load:0x1->NXM_NX_REG6[0..7]),resubmit(,100)"
      */
-    public static FlowBuilder programIngressAclLearnRuleForTcp(FlowBuilder flowBuilder, InstructionBuilder instructionBuilder, short learnTableId, short resubmitTableId) {
+    public static FlowBuilder programIngressAclLearnRuleForTcp(FlowBuilder flowBuilder) {
         List<Action> listAction = new ArrayList<>();
 
         // Create learn action
@@ -96,7 +98,7 @@ public class IngressAclLearnServiceUtil {
             LearnConstants.LEARN_PRIORITY,
             "0",
             LearnConstants.DELETE_LEARNED_FLAG_VALUE,
-            String.valueOf(learnTableId),
+            String.valueOf(LEARN_TABLE_ID),
             String.valueOf(NetvirtProvidersProvider.getSecurityGroupTcpFinIdleTimeout()),
             String.valueOf(NetvirtProvidersProvider.getSecurityGroupTcpFinHardTimeout())
         };
@@ -143,16 +145,15 @@ public class IngressAclLearnServiceUtil {
         listAction.add(buildAction(0, header, flowMod));
         ActionBuilder ab = new ActionBuilder();
         ab = new ActionBuilder();
-        ab.setAction(createResubmitActions(resubmitTableId));
+        ab.setAction(createResubmitActions());
         ab.setKey(new ActionKey(1));
         listAction.add(ab.build());
         ApplyActions applyActions = new ApplyActionsBuilder().setAction(listAction).build();
         ApplyActionsCase applyActionsCase = new ApplyActionsCaseBuilder().setApplyActions(applyActions).build();
         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
         List<Instruction> instructions = Lists.newArrayList();
-        if(instructionBuilder == null) {
-            instructionBuilder = new InstructionBuilder();
-        }
+
+        InstructionBuilder instructionBuilder = new InstructionBuilder();
         instructionBuilder.setInstruction(applyActionsCase);
         instructionBuilder.setOrder(0);
         instructionBuilder.setKey(new InstructionKey(0));
@@ -173,7 +174,7 @@ public class IngressAclLearnServiceUtil {
      * fin_hard_timeout=0,priority=61010, cookie=0x6900000,eth_type=0x800,nw_proto=6, NXM_OF_IP_SRC[]=NXM_OF_IP_DST[],NXM_OF_IP_DST[]=NXM_OF_IP_SRC[],
      * NXM_OF_TCP_SRC[]=NXM_OF_TCP_DST[],NXM_OF_TCP_DST[]=NXM_OF_TCP_SRC[],load:0x1->NXM_NX_REG6[0..7]),resubmit(,100)"
      */
-    public static FlowBuilder programIngressAclLearnRuleForUdp(FlowBuilder flowBuilder, InstructionBuilder instructionBuilder, short learnTableId, short resubmitTableId) {
+    public static FlowBuilder programIngressAclLearnRuleForUdp(FlowBuilder flowBuilder) {
         List<Action> listAction = new ArrayList<>();
 
         // Create learn action
@@ -193,7 +194,7 @@ public class IngressAclLearnServiceUtil {
             LearnConstants.LEARN_PRIORITY,
             "0",
             LearnConstants.DELETE_LEARNED_FLAG_VALUE,
-            String.valueOf(learnTableId),
+            String.valueOf(LEARN_TABLE_ID),
             "0",
             "0"
         };
@@ -242,7 +243,7 @@ public class IngressAclLearnServiceUtil {
 
         ActionBuilder ab = new ActionBuilder();
         ab = new ActionBuilder();
-        ab.setAction(createResubmitActions(resubmitTableId));
+        ab.setAction(createResubmitActions());
         ab.setKey(new ActionKey(1));
         listAction.add(ab.build());
 
@@ -250,9 +251,8 @@ public class IngressAclLearnServiceUtil {
         ApplyActionsCase applyActionsCase = new ApplyActionsCaseBuilder().setApplyActions(applyActions).build();
         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
         List<Instruction> instructions = Lists.newArrayList();
-        if(instructionBuilder == null) {
-            instructionBuilder = new InstructionBuilder();
-        }
+
+        InstructionBuilder instructionBuilder = new InstructionBuilder();
         instructionBuilder.setInstruction(applyActionsCase);
         instructionBuilder.setOrder(0);
         instructionBuilder.setKey(new InstructionKey(0));
@@ -273,7 +273,7 @@ public class IngressAclLearnServiceUtil {
      * fin_hard_timeout=0,priority=61010, cookie=0x6900000,eth_type=0x800,nw_proto=6, NXM_OF_IP_SRC[]=NXM_OF_IP_DST[],NXM_OF_IP_DST[]=NXM_OF_IP_SRC[],
      * NXM_OF_TCP_SRC[]=NXM_OF_TCP_DST[],NXM_OF_TCP_DST[]=NXM_OF_TCP_SRC[],load:0x1->NXM_NX_REG6[0..7]),resubmit(,100)"
      */
-    public static FlowBuilder programIngressAclLearnRuleForIcmp(FlowBuilder flowBuilder, InstructionBuilder instructionBuilder, String icmpType, String icmpCode, short learnTableId, short resubmitTableId) {
+    public static FlowBuilder programIngressAclLearnRuleForIcmp(FlowBuilder flowBuilder, String icmpType, String icmpCode) {
         //, Integer icmpCode,Integer icmpType
         List<Action> listAction = new ArrayList<>();
 
@@ -283,7 +283,7 @@ public class IngressAclLearnServiceUtil {
             LearnConstants.LEARN_PRIORITY,
             "0",
             LearnConstants.DELETE_LEARNED_FLAG_VALUE,
-            String.valueOf(learnTableId),
+            String.valueOf(LEARN_TABLE_ID),
             "0",
             "0"
         };
@@ -323,7 +323,7 @@ public class IngressAclLearnServiceUtil {
         listAction.add(buildAction(0, header, flowMod));
         ActionBuilder ab = new ActionBuilder();
         ab = new ActionBuilder();
-        ab.setAction(createResubmitActions(resubmitTableId));
+        ab.setAction(createResubmitActions());
         ab.setKey(new ActionKey(1));
         listAction.add(ab.build());
         ApplyActions applyActions = new ApplyActionsBuilder().setAction(listAction).build();
@@ -331,9 +331,7 @@ public class IngressAclLearnServiceUtil {
         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
         List<Instruction> instructions = Lists.newArrayList();
 
-        if(instructionBuilder == null) {
-            instructionBuilder = new InstructionBuilder();
-        }
+        InstructionBuilder instructionBuilder = new InstructionBuilder();
         instructionBuilder.setInstruction(applyActionsCase);
         instructionBuilder.setOrder(0);
         instructionBuilder.setKey(new InstructionKey(0));
@@ -345,91 +343,6 @@ public class IngressAclLearnServiceUtil {
         flowBuilder.setInstructions(instructionsBuilder.build());
 
         return flowBuilder;
-
-    }
-
-    /*
-     * (Table:IngressAclLearnService) IngressAcl Learning
-     * Match: reg6 = LearnConstants.NxmOfFieldType.NXM_NX_REG6
-     * Action: learn and resubmit to next table
-     * "table=90,dl_src=fa:16:3e:d3:bb:8a,priority=61002,icmp,dl_dst=fa:16:3e:bb:79:c1 ,actions=learn(table=39,idle_timeout=300,fin_idle_timeout=0,
-     * fin_hard_timeout=0,priority=61010, cookie=0x6900000,eth_type=0x800,nw_proto=6, NXM_OF_IP_SRC[]=NXM_OF_IP_DST[],NXM_OF_IP_DST[]=NXM_OF_IP_SRC[],
-     * NXM_OF_ICMP_TYPE[]=NXM_OF_ICMP_TYPE[],NXM_OF_ICMP_CODE[]=NXM_OF_ICMP_CODE[],load:0x1->NXM_NX_REG6[0..7]),resubmit(,100)"
-     */
-    public static FlowBuilder programIngressAclLearnRuleForIcmpAll(FlowBuilder flowBuilder, InstructionBuilder instructionBuilder, short learnTableId, short resubmitTableId) {
-        //, Integer icmpCode,Integer icmpType
-        List<Action> listAction = new ArrayList<>();
-
-        String[] header = new String[] {
-            String.valueOf(NetvirtProvidersProvider.getSecurityGroupDefaultIdleTimeout()),
-            String.valueOf(NetvirtProvidersProvider.getSecurityGroupDefaultHardTimeout()),
-            LearnConstants.LEARN_PRIORITY,
-            "0",
-            LearnConstants.DELETE_LEARNED_FLAG_VALUE,
-            String.valueOf(learnTableId),
-            "0",
-            "0"
-        };
-
-        String[][] flowMod = new String[7][];
-        //eth_type=0x800
-        flowMod[0] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_VALUE.name(),
-                Integer.toString(LearnConstants.ETHTYPE_IPV4),
-                LearnConstants.NxmOfFieldType.NXM_OF_ETH_TYPE.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_ETH_TYPE.getFlowModHeaderLen() };
-        //nw_proto=1
-        flowMod[1] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_VALUE.name(),
-                Integer.toString(LearnConstants.IP_PROT_ICMP),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_PROTO.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_PROTO.getFlowModHeaderLen() };
-        //NXM_OF_IP_SRC[]=NXM_OF_IP_DST[]
-        flowMod[2] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_DST.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_SRC.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_DST.getFlowModHeaderLen()};
-        // NXM_OF_IP_DST[]=NXM_OF_IP_SRC[]
-        flowMod[3] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_SRC.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_DST.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_IP_SRC.getFlowModHeaderLen()};
-        //NXM_OF_ICMP_TYPE=NXM_OF_ICMP_TYPE
-        flowMod[4] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
-                LearnConstants.NxmOfFieldType.NXM_OF_ICMP_TYPE.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_ICMP_TYPE.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_ICMP_TYPE.getFlowModHeaderLen()};
-        // NXM_OF_ICMP_CODE=NXM_OF_ICMP_CODE
-        flowMod[5] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
-                LearnConstants.NxmOfFieldType.NXM_OF_ICMP_CODE.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_ICMP_CODE.getHexType(),
-                LearnConstants.NxmOfFieldType.NXM_OF_ICMP_CODE.getFlowModHeaderLen()};
-        flowMod[6] = new String[] {
-                LearnConstants.LearnFlowModsType.COPY_FROM_VALUE.name(), LearnConstants.LEARN_MATCH_REG_VALUE,
-                LearnConstants.NxmOfFieldType.NXM_NX_REG6.getHexType(), "8" };
-        listAction.add(buildAction(0, header, flowMod));
-        ActionBuilder ab = new ActionBuilder();
-        ab.setAction(createResubmitActions(resubmitTableId));
-        ab.setKey(new ActionKey(1));
-        listAction.add(ab.build());
-        ApplyActions applyActions = new ApplyActionsBuilder().setAction(listAction).build();
-        ApplyActionsCase applyActionsCase = new ApplyActionsCaseBuilder().setApplyActions(applyActions).build();
-        InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
-        List<Instruction> instructions = Lists.newArrayList();
-
-        if(instructionBuilder == null) {
-            instructionBuilder = new InstructionBuilder();
-        }
-        instructionBuilder.setInstruction(applyActionsCase);
-        instructionBuilder.setOrder(0);
-        instructionBuilder.setKey(new InstructionKey(0));
-        instructions.add(instructionBuilder.build());
-        // Add InstructionBuilder to the Instruction(s)Builder List
-        instructionsBuilder.setInstruction(instructions);
-
-        // Add InstructionsBuilder to FlowBuilder
-        flowBuilder.setInstructions(instructionsBuilder.build());
-
-        return flowBuilder;
-
     }
 
     /*
@@ -523,10 +436,10 @@ public class IngressAclLearnServiceUtil {
         return abExt.build();
     }
 
-    private static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action createResubmitActions(short tableId) {
+    private static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action createResubmitActions() {
 
         NxResubmitBuilder gttb = new NxResubmitBuilder();
-        gttb.setTable(tableId);
+        gttb.setTable(RESUBMIT_TABLE_ID);
 
         // Wrap our Apply Action in an InstructionBuilder
         return (new NxActionResubmitRpcAddGroupCaseBuilder().setNxResubmit(gttb.build())).build();
index f7c4d1176f27e0f8acb92002337727cd063736aa..5529e8a71ce6b63b890b111145f9fdc6000c8538 100644 (file)
@@ -8,12 +8,10 @@
 
 package org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.services;
 
-import java.math.BigInteger;
 import java.net.Inet4Address;
 import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.HashMap;
 import java.util.Map;
@@ -23,12 +21,10 @@ import org.opendaylight.netvirt.openstack.netvirt.api.IngressAclProvider;
 import org.opendaylight.netvirt.openstack.netvirt.api.SecurityGroupCacheManger;
 import org.opendaylight.netvirt.openstack.netvirt.api.SecurityServicesManager;
 import org.opendaylight.netvirt.openstack.netvirt.providers.ConfigInterface;
-import org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
 import org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.Service;
 import org.opendaylight.netvirt.openstack.netvirt.translator.NeutronSecurityGroup;
 import org.opendaylight.netvirt.openstack.netvirt.translator.NeutronSecurityRule;
 import org.opendaylight.netvirt.openstack.netvirt.translator.Neutron_IPs;
-import org.opendaylight.netvirt.openstack.netvirt.translator.crud.INeutronSecurityGroupCRUD;
 import org.opendaylight.netvirt.openstack.netvirt.translator.crud.INeutronSecurityRuleCRUD;
 import org.opendaylight.netvirt.utils.mdsal.openflow.ActionUtils;
 import org.opendaylight.netvirt.utils.mdsal.openflow.FlowUtils;
@@ -39,14 +35,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
-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.model.match.types.rev131026.match.Icmpv4MatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
 import org.opendaylight.netvirt.openstack.netvirt.api.LearnConstants;
@@ -55,15 +45,8 @@ import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.collect.Lists;
-
-public class IngressAclService extends AbstractServiceInstance implements IngressAclProvider, ConfigInterface {
+public class IngressAclService extends AbstractAclService implements IngressAclProvider, ConfigInterface {
     private static final Logger LOG = LoggerFactory.getLogger(IngressAclService.class);
-    private volatile SecurityServicesManager securityServicesManager;
-    private volatile SecurityGroupCacheManger securityGroupCacheManger;
-    private volatile INeutronSecurityRuleCRUD neutronSecurityRule;
-    private static final int PORT_RANGE_MIN = 1;
-    private static final int PORT_RANGE_MAX = 65535;
 
     public IngressAclService() {
         super(Service.INGRESS_ACL);
@@ -114,11 +97,11 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                     List<Neutron_IPs> remoteSrcAddressList = secGroupRemoteIPMap.get(remoteSgUuid);
                     if (remoteSrcAddressList == null) {
                         remoteSrcAddressList = securityServicesManager
-                                .getVmListForSecurityGroup(portUuid,remoteSgUuid);
+                                .getVmListForSecurityGroup(portUuid, remoteSgUuid);
                         secGroupRemoteIPMap.put(remoteSgUuid, remoteSrcAddressList);
                     }
                     for (Neutron_IPs vmIp :remoteSrcAddressList ) {
-                        programPortSecurityRule(dpid, segmentationId, attachedMac, portSecurityRule, securityGroup, vmIp, write);
+                        programPortSecurityRule(dpid, segmentationId, attachedMac, portSecurityRule, vmIp, write);
                     }
                     if (write) {
                         securityGroupCacheManger.addToCache(remoteSgUuid, portUuid, nodeId);
@@ -126,15 +109,15 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                         securityGroupCacheManger.removeFromCache(remoteSgUuid, portUuid, nodeId);
                     }
                 } else {
-                    programPortSecurityRule(dpid, segmentationId, attachedMac, portSecurityRule, securityGroup, null, write);
+                    programPortSecurityRule(dpid, segmentationId, attachedMac, portSecurityRule, null, write);
                 }
             }
         }
     }
 
     @Override
-    public void programPortSecurityRule(Long dpid, String segmentationId, String attachedMac, NeutronSecurityRule portSecurityRule,
-                                        NeutronSecurityGroup securityGroup, Neutron_IPs vmIp, boolean write) {
+    public void programPortSecurityRule(Long dpid, String segmentationId, String attachedMac,
+                                        NeutronSecurityRule portSecurityRule, Neutron_IPs vmIp, boolean write) {
         String securityRuleEtherType = portSecurityRule.getSecurityRuleEthertype();
         boolean isIpv6 = NeutronSecurityRule.ETHERTYPE_IPV6.equals(securityRuleEtherType);
         if (!isIpv6 && !NeutronSecurityRule.ETHERTYPE_IPV4.equals(securityRuleEtherType)) {
@@ -157,165 +140,115 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                 return;
             }
         }
-        if (null == portSecurityRule.getSecurityRuleProtocol() && securityGroup.getSecurityGroupName().equals("default")) {
-            ingressAclIp(dpid, isIpv6, segmentationId, attachedMac,
-                portSecurityRule, ipaddress,
-                write, Constants.PROTO_PORT_MATCH_PRIORITY - 1, false);
-            if(!isIpv6) {
-                portSecurityRule.setSecurityRuleProtocol(MatchUtils.TCP);
-                portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
-                portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
-                ingressAclTcp(dpid, segmentationId, attachedMac, portSecurityRule, ipaddress,
-                        write, Constants.PROTO_PORT_MATCH_PRIORITY, false);
-                portSecurityRule.setSecurityRuleProtocol(MatchUtils.UDP);
-                ingressAclUdp(dpid, segmentationId, attachedMac, portSecurityRule, ipaddress,
-                        write, Constants.PROTO_PORT_MATCH_PRIORITY, false);
-                portSecurityRule.setSecurityRuleProtocol(MatchUtils.ICMP);
-                portSecurityRule.setSecurityRulePortMin(null);
-                portSecurityRule.setSecurityRulePortMax(null);
-                ingressAclIcmp(dpid, segmentationId, attachedMac, portSecurityRule, ipaddress,
-                        write, Constants.PROTO_PORT_MATCH_PRIORITY, false);
-                portSecurityRule.setSecurityRuleProtocol(null);
+        if (null == portSecurityRule.getSecurityRuleProtocol()
+                || portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.ANY_PROTOCOL)) {
+            ingressAclIp(dpid, isIpv6, segmentationId, attachedMac, portSecurityRule, ipaddress, write);
+            if (NeutronSecurityRule.ETHERTYPE_IPV4.equals(portSecurityRule.getSecurityRuleEthertype())) {
+                ingressAclTcp(dpid, segmentationId, attachedMac, TCP_SECURITY_GROUP_RULE_IPv4_ANY, ipaddress, write);
+                ingressAclUdp(dpid, segmentationId, attachedMac, UDP_SECURITY_GROUP_RULE_IPv4_ANY, ipaddress, write);
+                ingressAclIcmp(dpid, segmentationId, attachedMac, ICMP_SECURITY_GROUP_RULE_IPv4_ANY, ipaddress, write);
             }
         } else {
-
-            switch (portSecurityRule.getSecurityRuleProtocol() == null ? "" : portSecurityRule.getSecurityRuleProtocol()) {
+            switch (portSecurityRule.getSecurityRuleProtocol()) {
                 case MatchUtils.TCP:
+                case MatchUtils.TCP_PROTOCOL:
                     LOG.debug("programPortSecurityRule: Rule matching TCP", portSecurityRule);
-                    ingressAclTcp(dpid, segmentationId, attachedMac, portSecurityRule, ipaddress,
-                        write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+                    ingressAclTcp(dpid, segmentationId, attachedMac, portSecurityRule, ipaddress, write);
                     break;
                 case MatchUtils.UDP:
+                case MatchUtils.UDP_PROTOCOL:
                     LOG.debug("programPortSecurityRule: Rule matching UDP", portSecurityRule);
-                    ingressAclUdp(dpid, segmentationId, attachedMac, portSecurityRule, ipaddress,
-                        write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+                    ingressAclUdp(dpid, segmentationId, attachedMac, portSecurityRule, ipaddress, write);
                     break;
                 case MatchUtils.ICMP:
                 case MatchUtils.ICMPV6:
+                case MatchUtils.ICMP_PROTOCOL:
                     LOG.debug("programPortSecurityRule: Rule matching ICMP", portSecurityRule);
-                    ingressAclIcmp(dpid, segmentationId, attachedMac, portSecurityRule, ipaddress,
-                        write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+                    ingressAclIcmp(dpid, segmentationId, attachedMac, portSecurityRule, ipaddress, write);
                     break;
                 default:
                     LOG.info("programPortSecurityAcl: Protocol is not TCP/UDP/ICMP but other "
                             + "protocol = ", portSecurityRule.getSecurityRuleProtocol());
                     ingressOtherProtocolAclHandler(dpid, segmentationId, attachedMac, portSecurityRule,
-                            ipaddress, write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, isIpv6);
+                            ipaddress, write, isIpv6);
                     break;
             }
         }
-
     }
 
     private void ingressOtherProtocolAclHandler(Long dpidLong, String segmentationId, String dstMac,
           NeutronSecurityRule portSecurityRule, String srcAddress,
-          boolean write, Integer protoPortMatchPriority, boolean isIpv6) {
-        if(null == portSecurityRule.getSecurityRuleProtocol() || portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.ANY_PROTOCOL)) {
-            ingressAclIp(dpidLong, isIpv6, segmentationId, dstMac,
-                    portSecurityRule, srcAddress,
-                    write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY - 1, true);
-            if(!isIpv6) {
-                portSecurityRule.setSecurityRuleProtocol(MatchUtils.TCP);
-                portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
-                portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
-                ingressAclTcp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
-                        write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, true);
-                portSecurityRule.setSecurityRuleProtocol(MatchUtils.UDP);
-                ingressAclUdp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
-                        write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, true);
-                portSecurityRule.setSecurityRuleProtocol(MatchUtils.ICMP);
-                portSecurityRule.setSecurityRulePortMin(null);
-                portSecurityRule.setSecurityRulePortMax(null);
-                ingressAclIcmp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
-                        write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, true);
-                portSecurityRule.setSecurityRuleProtocol(null);
-            }
-        } else {
-            if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.TCP_PROTOCOL)) {
-                portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
-                portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
-                ingressAclTcp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
-                        write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
-            } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.UDP_PROTOCOL)) {
-                portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
-                portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
-                ingressAclUdp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
-                        write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
-            } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.ICMP_PROTOCOL)) {
-                ingressAclIcmp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
-                        write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+          boolean write, boolean isIpv6) {
+
+        MatchBuilder matchBuilder = new MatchBuilder();
+        String flowId = "Ingress_Other_" + segmentationId + "_" + dstMac + "_";
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, null, dstMac, MatchUtils.ETHERTYPE_IPV4);
+        short proto = 0;
+        try {
+            Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol());
+            proto = protocol.shortValue();
+            flowId = flowId + proto;
+        } catch (NumberFormatException e) {
+            LOG.error("Protocol value conversion failure", e);
+        }
+        matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, null, dstMac);
+        if (null != srcAddress) {
+            flowId = flowId + srcAddress;
+            matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
+                    MatchUtils.iPv4PrefixFromIPv4Address(srcAddress), null);
+        } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
+            flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
+            if (isIpv6) {
+                matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder, null,
+                        new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
             } else {
-                MatchBuilder matchBuilder = new MatchBuilder();
-                String flowId = "Ingress_Other_" + segmentationId + "_" + dstMac + "_";
-                matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,null,dstMac,MatchUtils.ETHERTYPE_IPV4);
-                short proto = 0;
-                try {
-                    Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol());
-                    proto = protocol.shortValue();
-                    flowId = flowId + proto;
-                } catch (NumberFormatException e) {
-                    LOG.error("Protocol vlaue conversion failure", e);
-                }
-                matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, null, dstMac);
-                if (null != srcAddress) {
-                    flowId = flowId + srcAddress;
+                if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
                     matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
-                                                                MatchUtils.iPv4PrefixFromIPv4Address(srcAddress), null);
-                } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
-                    flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
-                    if(isIpv6) {
-                        matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,null,
-                                new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
-                    } else {
-                        if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
-                            matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
-                                    new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()),null);
-                        }
-                    }
+                            new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()), null);
                 }
-                flowId = flowId + "_Permit";
-                NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority,
-                                                                      matchBuilder, getTable());
-                addInstructionWithConntrackCommit(flowBuilder, false);
-                syncFlow(flowBuilder ,nodeBuilder, write);
             }
         }
+        flowId = flowId + "_Permit";
+        NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
+        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, Constants.PROTO_OTHER_MATCH_PRIORITY,
+                matchBuilder, getTable());
+        addInstructionWithConntrackCommit(flowBuilder, false);
+        syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
     }
 
     @Override
     public void programFixedSecurityGroup(Long dpid, String segmentationId, String dhcpMacAddress,
-                                        long localPort, String attachMac, boolean write) {
+                                          long localPort, String attachMac, boolean write) {
 
-        ingressAclDhcpAllowServerTraffic(dpid, segmentationId,dhcpMacAddress, attachMac,
-                                         write,Constants.PROTO_DHCP_SERVER_MATCH_PRIORITY);
-        ingressAclDhcpv6AllowServerTraffic(dpid, segmentationId,dhcpMacAddress, attachMac,
-                                           write,Constants.PROTO_DHCP_SERVER_MATCH_PRIORITY);
+        ingressAclDhcpAllowServerTraffic(dpid, segmentationId, dhcpMacAddress, attachMac,
+                                         write, Constants.PROTO_DHCP_SERVER_MATCH_PRIORITY);
+        ingressAclDhcpv6AllowServerTraffic(dpid, segmentationId, dhcpMacAddress, attachMac,
+                                           write, Constants.PROTO_DHCP_SERVER_MATCH_PRIORITY);
         if (securityServicesManager.isConntrackEnabled()) {
             programIngressAclFixedConntrackRule(dpid, segmentationId, attachMac, localPort, write);
         } else {
-            ingressVMDrop(dpid, segmentationId, attachMac, write,
-                    Constants.PROTO_TCP_SYN_MATCH_PRIORITY_DROP);
-            ingressVMRegex(dpid, segmentationId, attachMac, write,
-                    Constants.PROTO_REG6_MATCH_PRIORITY);
+            ingressVMDrop(dpid, segmentationId, attachMac, write, Constants.PROTO_PORT_DROP_PRIORITY);
+            ingressVMRegex(dpid, segmentationId, attachMac, write, Constants.PROTO_REG6_MATCH_PRIORITY);
         }
         programArpRule(dpid, segmentationId, localPort, attachMac, write);
     }
+
     private void ingressVMDrop(Long dpidLong, String segmentationId, String srcMac,
             boolean write, Integer priority) {
         String flowName = "Ingress_Drop_" + segmentationId + "_" + srcMac + "_DROP";
         MatchBuilder matchBuilder = new MatchBuilder();
-        matchBuilder = MatchUtils.createV4EtherMatchWithoutType(matchBuilder,null,srcMac);
+        matchBuilder = MatchUtils.createV4EtherMatchWithoutType(matchBuilder, null, srcMac);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, true);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
         syncFlow(flowBuilder, nodeBuilder, write);
     }
+
     private void ingressVMRegex(Long dpidLong, String segmentationId, String srcMac,
             boolean write, Integer priority) {
         String flowName = "Ingress_Regx_" + segmentationId + "_" + srcMac;
         MatchBuilder matchBuilder = new MatchBuilder();
-        matchBuilder = MatchUtils.createV4EtherMatchWithoutType(matchBuilder,null,srcMac);
+        matchBuilder = MatchUtils.createV4EtherMatchWithoutType(matchBuilder, null, srcMac);
         MatchUtils.addNxRegMatch(matchBuilder,
                 new MatchUtils.RegMatch(ClassifierService.REG_FIELD_6, ClassifierService.REG_VALUE_FROM_LOCAL));
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
@@ -324,40 +257,16 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
         syncFlow(flowBuilder, nodeBuilder, write);
     }
 
-    private void addTcpSynFlagMatchIpv4Drop(Long dpidLong, String segmentationId, String dstMac,
-                              boolean write, Integer priority) {
-        String flowId = "Ingress_TCP_Ipv4_" + segmentationId + "_" + dstMac + "_DROP";
-        MatchBuilder matchBuilder = new MatchBuilder();
-        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,null,dstMac,MatchUtils.ETHERTYPE_IPV4);
-        matchBuilder = MatchUtils.addTcpSynMatch(matchBuilder);
-        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, priority, matchBuilder, getTable());
-        addPipelineInstruction(flowBuilder, null, true);
-        NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder, nodeBuilder, write);
-    }
-
-    private void addTcpSynFlagMatchIpv6Drop(Long dpidLong, String segmentationId, String dstMac,
-                                            boolean write, Integer priority) {
-        String flowId = "Ingress_TCP_Ipv6_" + segmentationId + "_" + dstMac + "_DROP";
-        MatchBuilder matchBuilder = new MatchBuilder();
-        matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder,null,dstMac);
-        matchBuilder = MatchUtils.addTcpSynMatch(matchBuilder);
-        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, priority, matchBuilder, getTable());
-        addPipelineInstruction(flowBuilder, null, true);
-        NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder, nodeBuilder, write);
-    }
-
     private void programArpRule(Long dpid, String segmentationId, long localPort, String attachMac, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowId = "Ingress_ARP_" + segmentationId + "_" + localPort + "_";
-        MatchUtils.createV4EtherMatchWithType(matchBuilder,null,null,MatchUtils.ETHERTYPE_ARP);
+        MatchUtils.createV4EtherMatchWithType(matchBuilder, null, null, MatchUtils.ETHERTYPE_ARP);
         MatchUtils.addArpMacMatch(matchBuilder, null, attachMac);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, Constants.PROTO_MATCH_PRIORITY,
                                                               matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpid);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     private void programIngressAclFixedConntrackRule(Long dpid,
@@ -384,39 +293,39 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                                              long localPort, String attachMac, Integer priority, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowName = "Ingress_Fixed_Conntrk_Untrk_" + segmentationId + "_" + localPort + "_";
-        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,null,attachMac,MatchUtils.ETHERTYPE_IPV4);
-        matchBuilder = MatchUtils.addCtState(matchBuilder,MatchUtils.UNTRACKED_CT_STATE,
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, null, attachMac, MatchUtils.ETHERTYPE_IPV4);
+        matchBuilder = MatchUtils.addCtState(matchBuilder, MatchUtils.UNTRACKED_CT_STATE,
                                              MatchUtils.UNTRACKED_CT_STATE_MASK);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addInstructionWithConntrackRecirc(flowBuilder);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     private void programConntrackTrackedPlusEstRule(Long dpidLong, String segmentationId,
-                                                  long localPort, String attachMac,Integer priority, boolean write) {
+                                                  long localPort, String attachMac, Integer priority, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowName = "Ingress_Fixed_Conntrk_TrkEst_" + segmentationId + "_" + localPort + "_";
-        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,null,attachMac,MatchUtils.ETHERTYPE_IPV4);
-        matchBuilder = MatchUtils.addCtState(matchBuilder,MatchUtils.TRACKED_EST_CT_STATE,
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, null, attachMac, MatchUtils.ETHERTYPE_IPV4);
+        matchBuilder = MatchUtils.addCtState(matchBuilder, MatchUtils.TRACKED_EST_CT_STATE,
                                              MatchUtils.TRACKED_CT_STATE_MASK);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     private void programConntrackTrackedPlusRelRule(Long dpidLong, String segmentationId,
-                                                    long localPort, String attachMac,Integer priority, boolean write) {
+                                                    long localPort, String attachMac, Integer priority, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowName = "Ingress_Fixed_Conntrk_TrkRel_" + segmentationId + "_" + localPort + "_";
-        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,null,attachMac,MatchUtils.ETHERTYPE_IPV4);
-        matchBuilder = MatchUtils.addCtState(matchBuilder,MatchUtils.TRACKED_REL_CT_STATE,
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, null, attachMac, MatchUtils.ETHERTYPE_IPV4);
+        matchBuilder = MatchUtils.addCtState(matchBuilder, MatchUtils.TRACKED_REL_CT_STATE,
                                              MatchUtils.TRACKED_CT_STATE_MASK);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     private void programConntrackNewDropRule(Long dpidLong, String segmentationId,
@@ -424,26 +333,26 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
         MatchBuilder matchBuilder = new MatchBuilder();
 
         String flowName = "Ingress_Fixed_Conntrk_NewDrop_" + segmentationId + "_" + localPort + "_";
-        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,null,attachMac,0x0800L);
-        matchBuilder = MatchUtils.addCtState(matchBuilder,MatchUtils.TRACKED_NEW_CT_STATE,
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, null, attachMac, 0x0800L);
+        matchBuilder = MatchUtils.addCtState(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,
                                              MatchUtils.TRACKED_NEW_CT_STATE_MASK);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, true);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     private void programConntrackInvDropRule(Long dpidLong, String segmentationId,
                                              long localPort, String attachMac, Integer priority, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowName = "Ingress_Fixed_Conntrk_InvDrop_" + segmentationId + "_" + localPort + "_";
-        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,null,attachMac, MatchUtils.ETHERTYPE_IPV4);
-        matchBuilder = MatchUtils.addCtState(matchBuilder,MatchUtils.TRACKED_INV_CT_STATE,
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, null, attachMac, MatchUtils.ETHERTYPE_IPV4);
+        matchBuilder = MatchUtils.addCtState(matchBuilder, MatchUtils.TRACKED_INV_CT_STATE,
                                              MatchUtils.TRACKED_INV_CT_STATE_MASK);
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowName, priority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, true);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     /**
@@ -453,46 +362,38 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
      * @param segmentationId the segementation id
      * @param dstMac the destination mac address
      * @param write add or remove
-     * @param isRegMatchReq add Reg MAtch or not
-     * @param protoPortMatchPriority the protocol match priority.
      */
     private void ingressAclIp(Long dpidLong, boolean isIpv6, String segmentationId, String dstMac,
-                              NeutronSecurityRule portSecurityRule, String srcAddress,
-                              boolean write, Integer protoPortMatchPriority, boolean isRegMatchReq ) {
+                              NeutronSecurityRule portSecurityRule, String srcAddress, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowId = "Ingress_IP" + segmentationId + "_" + dstMac + "_Permit_";
         if (isIpv6) {
-            matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder,null,dstMac);
+            matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder, null, dstMac);
         } else {
-            matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,null,dstMac,MatchUtils.ETHERTYPE_IPV4);
-        }
-        if (isRegMatchReq) {
-            flowId = flowId + "_regEx_";
-            MatchUtils.addNxRegMatch(matchBuilder,
-                    new MatchUtils.RegMatch(ClassifierService.REG_FIELD_6, ClassifierService.REG_VALUE_FROM_LOCAL_0));
+            matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, null, dstMac, MatchUtils.ETHERTYPE_IPV4);
         }
         if (null != srcAddress) {
             flowId = flowId + srcAddress;
             if (isIpv6) {
                 matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,
-                        MatchUtils.iPv6PrefixFromIPv6Address(srcAddress),null);
+                        MatchUtils.iPv6PrefixFromIPv6Address(srcAddress), null);
             } else {
                 matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
-                        MatchUtils.iPv4PrefixFromIPv4Address(srcAddress),null);
+                        MatchUtils.iPv4PrefixFromIPv4Address(srcAddress), null);
             }
         } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
             flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
             if (isIpv6) {
                 matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,
                         new Ipv6Prefix(portSecurityRule
-                                       .getSecurityRuleRemoteIpPrefix()),null);
+                                       .getSecurityRuleRemoteIpPrefix()), null);
             } else {
                 // Fix: Bug 6473
                 // IP match removed if CIDR created as 0.0.0.0/0 in openstack security rule
                 if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
                     matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
                             new Ipv4Prefix(portSecurityRule
-                                       .getSecurityRuleRemoteIpPrefix()),null);
+                                       .getSecurityRuleRemoteIpPrefix()), null);
                 }
             }
         } else {
@@ -502,11 +403,12 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                 flowId = flowId + "Ipv4";
             }
         }
-        addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority, matchBuilder, getTable());
+        addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(
+                flowId, Constants.PROTO_IP_PORT_MATCH_PRIORITY, matchBuilder, getTable());
         addInstructionWithConntrackCommit(flowBuilder, false);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
     }
 
     /**
@@ -519,25 +421,17 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
      * @param portSecurityRule the security rule in the SG
      * @param srcAddress the destination IP address
      * @param write add or delete
-     * @param isRegMatchReq add Reg MAtch or not
-     * @param protoPortMatchPriority the protocol match priroty
      */
     private void ingressAclTcp(Long dpidLong, String segmentationId, String dstMac,
-                               NeutronSecurityRule portSecurityRule, String srcAddress, boolean write,
-                               Integer protoPortMatchPriority, boolean isRegMatchReq) {
+                               NeutronSecurityRule portSecurityRule, String srcAddress, boolean write) {
         boolean portRange = false;
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowId = "Ingress_TCP_" + segmentationId + "_" + dstMac + "_";
         boolean isIpv6 = NeutronSecurityRule.ETHERTYPE_IPV6.equals(portSecurityRule.getSecurityRuleEthertype());
         if (isIpv6) {
-            matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder,null,dstMac);
+            matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder, null, dstMac);
         } else {
-            matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,null,dstMac,MatchUtils.ETHERTYPE_IPV4);
-        }
-        if (isRegMatchReq) {
-            flowId = flowId + "_regEx_";
-            MatchUtils.addNxRegMatch(matchBuilder,
-                    new MatchUtils.RegMatch(ClassifierService.REG_FIELD_6, ClassifierService.REG_VALUE_FROM_LOCAL_0));
+            matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, null, dstMac, MatchUtils.ETHERTYPE_IPV4);
         }
 
         /* Custom TCP Match*/
@@ -564,24 +458,24 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
             flowId = flowId + srcAddress;
             if (isIpv6) {
                 matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,
-                        MatchUtils.iPv6PrefixFromIPv6Address(srcAddress),null);
+                        MatchUtils.iPv6PrefixFromIPv6Address(srcAddress), null);
             } else {
                 matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
-                        MatchUtils.iPv4PrefixFromIPv4Address(srcAddress),null);
+                        MatchUtils.iPv4PrefixFromIPv4Address(srcAddress), null);
             }
         } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
             flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
             if (isIpv6) {
                 matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,
                         new Ipv6Prefix(portSecurityRule
-                                       .getSecurityRuleRemoteIpPrefix()),null);
+                                       .getSecurityRuleRemoteIpPrefix()), null);
             } else {
                 // Fix: Bug 6473
                 // IP match removed if CIDR created as 0.0.0.0/0 in openstack security rule
                 if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
                     matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
                             new Ipv4Prefix(portSecurityRule
-                                       .getSecurityRuleRemoteIpPrefix()),null);
+                                       .getSecurityRuleRemoteIpPrefix()), null);
                 }
             }
         }
@@ -595,25 +489,19 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                 rangeflowId = rangeflowId + "_Permit";
                 MatchUtils.addLayer4MatchWithMask(matchBuilder, MatchUtils.TCP_SHORT,
                                                   0, port, portMaskMap.get(port));
-                addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(rangeflowId, protoPortMatchPriority,
+                addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(rangeflowId, Constants.PROTO_PORT_MATCH_PRIORITY,
                                                                       matchBuilder, getTable());
                 addInstructionWithLearnConntrackCommit(portSecurityRule, flowBuilder, null, null);
-                syncFlow(flowBuilder ,nodeBuilder, write);
+                syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
             }
         } else {
             flowId = flowId + "_Permit";
-            addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-            FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority,
+            addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+            FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, Constants.PROTO_PORT_MATCH_PRIORITY,
                                                                   matchBuilder, getTable());
             addInstructionWithLearnConntrackCommit(portSecurityRule, flowBuilder, null, null);
-            syncFlow(flowBuilder ,nodeBuilder, write);
-        }
-    }
-
-    private void addTcpSynMatch(MatchBuilder matchBuilder) {
-        if (!securityServicesManager.isConntrackEnabled()) {
-            MatchUtils.createTcpProtoSynMatch(matchBuilder);
+            syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
         }
     }
 
@@ -627,25 +515,18 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
      * @param portSecurityRule the security rule in the SG
      * @param srcAddress the destination IP address
      * @param write add or delete
-     * @param isRegMatchReq add Reg MAtch or not
-     * @param protoPortMatchPriority the protocol match priroty
      */
     private void ingressAclUdp(Long dpidLong, String segmentationId, String dstMac,
                                NeutronSecurityRule portSecurityRule, String srcAddress,
-                               boolean write, Integer protoPortMatchPriority, boolean isRegMatchReq ) {
+                               boolean write) {
         boolean portRange = false;
         boolean isIpv6 = NeutronSecurityRule.ETHERTYPE_IPV6.equals(portSecurityRule.getSecurityRuleEthertype());
         MatchBuilder matchBuilder = new MatchBuilder();
         String flowId = "Ingress_UDP_" + segmentationId + "_" + dstMac + "_";
         if (isIpv6)  {
-            matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder,null,dstMac);
+            matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder, null, dstMac);
         } else {
-            matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,null,dstMac,MatchUtils.ETHERTYPE_IPV4);
-        }
-        if (isRegMatchReq) {
-            flowId = flowId + "_regEx_";
-            MatchUtils.addNxRegMatch(matchBuilder,
-                    new MatchUtils.RegMatch(ClassifierService.REG_FIELD_6, ClassifierService.REG_VALUE_FROM_LOCAL_0));
+            matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, null, dstMac, MatchUtils.ETHERTYPE_IPV4);
         }
 
         /* Custom UDP Match */
@@ -681,12 +562,12 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
             if (isIpv6) {
                 matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,
                         new Ipv6Prefix(portSecurityRule
-                                       .getSecurityRuleRemoteIpPrefix()),null);
+                                       .getSecurityRuleRemoteIpPrefix()), null);
             } else {
                 if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
                 matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
                         new Ipv4Prefix(portSecurityRule
-                                       .getSecurityRuleRemoteIpPrefix()),null);
+                                       .getSecurityRuleRemoteIpPrefix()), null);
                 }
             }
         }
@@ -700,33 +581,31 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                 rangeflowId = rangeflowId + "_Permit";
                 MatchUtils.addLayer4MatchWithMask(matchBuilder, MatchUtils.UDP_SHORT,
                                                    0, port, portMaskMap.get(port));
-                addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(rangeflowId, protoPortMatchPriority,
-                                                                      matchBuilder, getTable());
+                addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(
+                        rangeflowId, Constants.PROTO_PORT_MATCH_PRIORITY, matchBuilder, getTable());
                 addInstructionWithLearnConntrackCommit(portSecurityRule, flowBuilder, null, null);
-                syncFlow(flowBuilder ,nodeBuilder, write);
+                syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
             }
         } else {
             flowId = flowId + "_Permit";
-            addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-            FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority,
-                                                                  matchBuilder, getTable());
+            addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+            FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(
+                    flowId, Constants.PROTO_PORT_MATCH_PRIORITY, matchBuilder, getTable());
             addInstructionWithLearnConntrackCommit(portSecurityRule, flowBuilder, null, null);
-            syncFlow(flowBuilder ,nodeBuilder, write);
+            syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
         }
     }
 
     private void ingressAclIcmp(Long dpidLong, String segmentationId, String dstMac,
             NeutronSecurityRule portSecurityRule, String srcAddress,
-            boolean write, Integer protoPortMatchPriority, boolean isRegMatchReq) {
+            boolean write) {
 
         boolean isIpv6 = NeutronSecurityRule.ETHERTYPE_IPV6.equals(portSecurityRule.getSecurityRuleEthertype());
         if (isIpv6) {
-            ingressAclIcmpV6(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
-                             write, protoPortMatchPriority, isRegMatchReq);
+            ingressAclIcmpV6(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress, write);
         } else {
-            ingressAclIcmpV4(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
-                             write, protoPortMatchPriority, isRegMatchReq);
+            ingressAclIcmpV4(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress, write);
         }
     }
 
@@ -740,17 +619,13 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
      * @param portSecurityRule the security rule in the SG
      * @param srcAddress the destination IP address
      * @param write add or delete
-     * @param isRegMatchReq add Reg MAtch or not
-     * @param protoPortMatchPriority the protocol match priority
      */
     private void ingressAclIcmpV4(Long dpidLong, String segmentationId, String dstMac,
-                                  NeutronSecurityRule portSecurityRule, String srcAddress,
-                                  boolean write, Integer protoPortMatchPriority, boolean isRegMatchReq) {
-
+                                  NeutronSecurityRule portSecurityRule, String srcAddress, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
         boolean isIcmpAll = false;
         String flowId = "Ingress_ICMP_" + segmentationId + "_" + dstMac + "_";
-        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,null,dstMac,MatchUtils.ETHERTYPE_IPV4);
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, null, dstMac, MatchUtils.ETHERTYPE_IPV4);
 
         /* Custom ICMP Match */
         if (portSecurityRule.getSecurityRulePortMin() != null
@@ -763,14 +638,7 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
         } else {
             isIcmpAll = true;
             /* All ICMP Match */
-            flowId = flowId + "all" + "_";
-            matchBuilder = MatchUtils.createICMPv4Match(matchBuilder,MatchUtils.ALL_ICMP, MatchUtils.ALL_ICMP);
-        }
-
-        if (isRegMatchReq) {
-            flowId = flowId + "_regEx_";
-            MatchUtils.addNxRegMatch(matchBuilder,
-                    new MatchUtils.RegMatch(ClassifierService.REG_FIELD_6, ClassifierService.REG_VALUE_FROM_LOCAL_0));
+            matchBuilder = MatchUtils.createICMPv4Match(matchBuilder, MatchUtils.ALL_ICMP, MatchUtils.ALL_ICMP);
         }
 
         if (null != srcAddress) {
@@ -781,7 +649,7 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
             flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
             if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
                 matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
-                                         new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()),null);
+                        new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()), null);
             }
         }
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
@@ -789,39 +657,36 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
         {
             Map<Integer, String> map = LearnConstants.ICMP_TYPE_MAP;
             for(Map.Entry<Integer, String> entry : map.entrySet()) {
-                Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
-                icmpv4match.setIcmpv4Type(entry.getKey().shortValue());
-                icmpv4match.setIcmpv4Code((short)0);
-                matchBuilder.setIcmpv4Match(icmpv4match.build());
-                String rangeflowId = flowId + "_" + entry.getKey() + "_" + entry.getValue();
-                addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(rangeflowId, protoPortMatchPriority, matchBuilder, getTable());
+                matchBuilder = MatchUtils.createICMPv4Match(matchBuilder, entry.getKey().shortValue(), (short)0);
+                String rangeflowId = flowId + entry.getKey() + "_" + entry.getValue() + "_" ;
+                rangeflowId = rangeflowId + "_Permit";
+                addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(
+                        rangeflowId, Constants.PROTO_PORT_MATCH_PRIORITY, matchBuilder, getTable());
                 addInstructionWithLearnConntrackCommit(portSecurityRule, flowBuilder, entry.getValue(), "0");
-                syncFlow(flowBuilder ,nodeBuilder, write);
+                syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
             }
-            addIcmpFlow(nodeBuilder, portSecurityRule, segmentationId, dstMac, protoPortMatchPriority - 1, srcAddress, write, isRegMatchReq);
+            addIcmpFlow(nodeBuilder, portSecurityRule, segmentationId, dstMac, srcAddress, write);
         } else {
             flowId = flowId + "_Permit";
-            addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-            FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority, matchBuilder, getTable());
+            addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+            FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(
+                    flowId, Constants.PROTO_PORT_MATCH_PRIORITY, matchBuilder, getTable());
              String icmpType = LearnConstants.ICMP_TYPE_MAP.get(portSecurityRule.getSecurityRulePortMin());
             if (icmpType == null){
                 icmpType = Integer.toString(portSecurityRule.getSecurityRulePortMin());
             }
             addInstructionWithLearnConntrackCommit(portSecurityRule, flowBuilder, icmpType,
                     Integer.toString(portSecurityRule.getSecurityRulePortMax()));
-            syncFlow(flowBuilder ,nodeBuilder, write);
+            syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
         }
     }
 
-    private void addIcmpFlow(NodeBuilder nodeBuilder, NeutronSecurityRule portSecurityRule, String segmentationId, String dstMac,
-            Integer protoPortMatchPriority, String srcAddress, boolean write, boolean isRegMatchReq) {
+    private void addIcmpFlow(NodeBuilder nodeBuilder, NeutronSecurityRule portSecurityRule, String segmentationId,
+                             String dstMac, String srcAddress, boolean write) {
         MatchBuilder matchBuilder = new MatchBuilder();
-        InstructionBuilder instructionBuilder = null;
-        short learnTableId=getTable(Service.ACL_LEARN_SERVICE);
-        short resubmitId=getTable(Service.OUTBOUND_NAT);
         String flowId = "Ingress_ICMP_" + segmentationId + "_" + dstMac + "_";
-        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,null,dstMac,MatchUtils.ETHERTYPE_IPV4);
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, null, dstMac, MatchUtils.ETHERTYPE_IPV4);
         if (null != srcAddress) {
             flowId = flowId + srcAddress;
             matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
@@ -830,24 +695,17 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
              flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
              if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
                  matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
-                                          new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()),null);
+                         new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()), null);
              }
         }
-        if (isRegMatchReq) {
-            flowId = flowId + "_regEx_";
-            MatchUtils.addNxRegMatch(matchBuilder,
-                    new MatchUtils.RegMatch(ClassifierService.REG_FIELD_6, ClassifierService.REG_VALUE_FROM_LOCAL_0));
-        }
         flowId = flowId + "all" + "_";
-        matchBuilder = MatchUtils.createICMPv4Match(matchBuilder,MatchUtils.ALL_ICMP, MatchUtils.ALL_ICMP);
-        Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
-        matchBuilder.setIcmpv4Match(icmpv4match.build());
+        matchBuilder = MatchUtils.createICMPv4Match(matchBuilder, MatchUtils.ALL_ICMP, MatchUtils.ALL_ICMP);
         String rangeflowId = flowId;
-        addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
-        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(rangeflowId, protoPortMatchPriority, matchBuilder, getTable());
+        addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(
+                rangeflowId, Constants.PROTO_PORT_ICMP_MATCH_PRIORITY, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
-        syncFlow(flowBuilder ,nodeBuilder, write);
-
+        syncSecurityRuleFlow(flowBuilder, nodeBuilder, write);
     }
 
     /**
@@ -860,16 +718,13 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
      * @param portSecurityRule the security rule in the SG
      * @param srcAddress the destination IP address
      * @param write add or delete
-     * @param isRegMatchReq add Reg MAtch or not
-     * @param protoPortMatchPriority the protocol match priority
      */
     private void ingressAclIcmpV6(Long dpidLong, String segmentationId, String dstMac,
-                                  NeutronSecurityRule portSecurityRule, String srcAddress,
-                                  boolean write, Integer protoPortMatchPriority, boolean isRegMatchReq) {
+                                  NeutronSecurityRule portSecurityRule, String srcAddress, boolean write) {
 
         MatchBuilder matchBuilder = new MatchBuilder();
-        String flowId = "Ingress_ICMP_" + segmentationId + "_" + dstMac + "_";
-        matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder,null,dstMac);
+        String flowId = "Ingress_ICMPv6_" + segmentationId + "_" + dstMac + "_";
+        matchBuilder = MatchUtils.createV6EtherMatchWithType(matchBuilder, null, dstMac);
 
         /* Custom ICMP Match */
         if (portSecurityRule.getSecurityRulePortMin() != null
@@ -882,12 +737,7 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
         } else {
             /* All ICMP Match */
             flowId = flowId + "all" + "_";
-            matchBuilder = MatchUtils.createICMPv6Match(matchBuilder,MatchUtils.ALL_ICMP, MatchUtils.ALL_ICMP);
-        }
-        if (isRegMatchReq) {
-            flowId = flowId + "_regEx_";
-            MatchUtils.addNxRegMatch(matchBuilder,
-                    new MatchUtils.RegMatch(ClassifierService.REG_FIELD_6, ClassifierService.REG_VALUE_FROM_LOCAL_0));
+            matchBuilder = MatchUtils.createICMPv6Match(matchBuilder, MatchUtils.ALL_ICMP, MatchUtils.ALL_ICMP);
         }
         if (null != srcAddress) {
             flowId = flowId + srcAddress;
@@ -897,14 +747,14 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
             flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
             matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,
                     new Ipv6Prefix(portSecurityRule
-                                   .getSecurityRuleRemoteIpPrefix()),null);
+                                   .getSecurityRuleRemoteIpPrefix()), null);
         }
-        addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE,MatchUtils.TRACKED_NEW_CT_STATE_MASK);
+        addConntrackMatch(matchBuilder, MatchUtils.TRACKED_NEW_CT_STATE, MatchUtils.TRACKED_NEW_CT_STATE_MASK);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
         flowId = flowId + "_Permit";
-        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority, matchBuilder, getTable());
+        FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, Constants.PROTO_PORT_MATCH_PRIORITY, matchBuilder, getTable());
         addInstructionWithConntrackCommit(flowBuilder, false);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     /**
@@ -921,14 +771,14 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                                                   String attachMac, boolean write, Integer protoPortMatchPriority) {
 
         MatchBuilder matchBuilder = new MatchBuilder();
-        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,dhcpMacAddress,attachMac,
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, dhcpMacAddress, attachMac,
                                                              MatchUtils.ETHERTYPE_IPV4);
         MatchUtils.addLayer4Match(matchBuilder, MatchUtils.UDP_SHORT, 67, 68);
         String flowId = "Ingress_DHCP_Server_" + segmentationId + "_" + attachMac + "_Permit";
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
+        syncFlow(flowBuildernodeBuilder, write);
     }
 
     /**
@@ -945,117 +795,37 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                                                     String attachMac, boolean write, Integer protoPortMatchPriority) {
 
         MatchBuilder matchBuilder = new MatchBuilder();
-        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,dhcpMacAddress,attachMac,
+        matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, dhcpMacAddress, attachMac,
                                                              MatchUtils.ETHERTYPE_IPV6);
         MatchUtils.addLayer4Match(matchBuilder, MatchUtils.UDP_SHORT, 547, 546);
         String flowId = "Ingress_DHCPv6_Server_" + segmentationId + "_" + attachMac + "_Permit";
         FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority, matchBuilder, getTable());
         addPipelineInstruction(flowBuilder, null, false);
         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-        syncFlow(flowBuilder ,nodeBuilder, write);
-    }
-
-    private void addConntrackMatch(MatchBuilder matchBuilder, int state, int mask) {
-        if (securityServicesManager.isConntrackEnabled()) {
-            MatchUtils.addCtState(matchBuilder, state, mask );
-        }
-    }
-    private FlowBuilder addInstructionWithLearnConntrackCommit(NeutronSecurityRule portSecurityRule, FlowBuilder flowBuilder , String icmpType, String icmpCode) {
-        InstructionBuilder instructionBuilder = null;
-        short learnTableId=getTable(Service.ACL_LEARN_SERVICE);
-        short resubmitTableId=getTable(Service.OUTBOUND_NAT);
-        if (securityServicesManager.isConntrackEnabled()) {
-            Action conntrackAction = ActionUtils.nxConntrackAction(1, 0L, 0, (short)0xff);
-            instructionBuilder = InstructionUtils
-                    .createInstructionBuilder(ActionUtils.conntrackActionBuilder(conntrackAction), 1, false);
-            return addPipelineInstruction(flowBuilder,instructionBuilder, false);
-        }
-        if (portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.TCP) || portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.TCP_PROTOCOL)) {
-            return IngressAclLearnServiceUtil.programIngressAclLearnRuleForTcp(flowBuilder,instructionBuilder,learnTableId,resubmitTableId);
-        } else if (portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.UDP) || portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.UDP_PROTOCOL)) {
-            return IngressAclLearnServiceUtil.programIngressAclLearnRuleForUdp(flowBuilder,instructionBuilder,learnTableId,resubmitTableId);
-        } else if (portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.ICMP) || portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.ICMP_PROTOCOL)) {
-            return IngressAclLearnServiceUtil.programIngressAclLearnRuleForIcmp(flowBuilder,instructionBuilder, icmpType, icmpCode,learnTableId,resubmitTableId);
-        }
-        return flowBuilder;
+        syncFlow(flowBuilder, nodeBuilder, write);
     }
 
-    private FlowBuilder addInstructionWithConntrackCommit( FlowBuilder flowBuilder , boolean isDrop) {
-        InstructionBuilder instructionBuilder = null;
+    private FlowBuilder addInstructionWithLearnConntrackCommit(NeutronSecurityRule portSecurityRule, FlowBuilder flowBuilder,
+                                                               String icmpType, String icmpCode) {
         if (securityServicesManager.isConntrackEnabled()) {
             Action conntrackAction = ActionUtils.nxConntrackAction(1, 0L, 0, (short)0xff);
-            instructionBuilder = InstructionUtils
+            InstructionBuilder instructionBuilder = InstructionUtils
                     .createInstructionBuilder(ActionUtils.conntrackActionBuilder(conntrackAction), 1, false);
+            return addPipelineInstruction(flowBuilder, instructionBuilder, false);
+        }
+        if (portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.TCP)
+                || portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.TCP_PROTOCOL)) {
+            return IngressAclLearnServiceUtil.programIngressAclLearnRuleForTcp(flowBuilder);
+        } else if (portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.UDP)
+                || portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.UDP_PROTOCOL)) {
+            return IngressAclLearnServiceUtil.programIngressAclLearnRuleForUdp(flowBuilder);
+        } else if (portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.ICMP)
+                || portSecurityRule.getSecurityRuleProtocol().equalsIgnoreCase(MatchUtils.ICMP_PROTOCOL)) {
+            return IngressAclLearnServiceUtil.programIngressAclLearnRuleForIcmp(flowBuilder, icmpType, icmpCode);
         }
-        return addPipelineInstruction(flowBuilder,instructionBuilder, isDrop);
-    }
-
-    private FlowBuilder addInstructionWithConntrackRecirc( FlowBuilder flowBuilder) {
-        InstructionBuilder instructionBuilder = null;
-        if (securityServicesManager.isConntrackEnabled()) {
-            Action conntrackAction = ActionUtils.nxConntrackAction(0, 0L, 0, (short)0x0);
-            instructionBuilder = InstructionUtils
-                    .createInstructionBuilder(ActionUtils.conntrackActionBuilder(conntrackAction), 1, false);
-            List<Instruction> instructionsList = Lists.newArrayList();
-            instructionsList.add(instructionBuilder.build());
-            InstructionsBuilder isb = new InstructionsBuilder();
-            isb.setInstruction(instructionsList);
-            flowBuilder.setInstructions(isb.build());
-        }
-        return flowBuilder;
-    }
-
-    private FlowBuilder addPipelineInstruction( FlowBuilder flowBuilder , InstructionBuilder instructionBuilder,
-                                                boolean isDrop) {
-        InstructionBuilder pipeLineIndstructionBuilder = createPipleLineInstructionBuilder(isDrop);
-        List<Instruction> instructionsList = Lists.newArrayList();
-        instructionsList.add(pipeLineIndstructionBuilder.build());
-        if (null != instructionBuilder) {
-            instructionsList.add(instructionBuilder.build());
-        }
-        InstructionsBuilder isb = new InstructionsBuilder();
-        isb.setInstruction(instructionsList);
-        flowBuilder.setInstructions(isb.build());
         return flowBuilder;
     }
 
-    private InstructionBuilder createPipleLineInstructionBuilder(boolean drop) {
-        InstructionBuilder ib = this.getMutablePipelineInstructionBuilder();
-        if (drop) {
-            InstructionUtils.createDropInstructions(ib);
-        }
-        ib.setOrder(0);
-        List<Instruction> instructionsList = Lists.newArrayList();
-        ib.setKey(new InstructionKey(0));
-        instructionsList.add(ib.build());
-        return ib;
-    }
-    /**
-     * Add or remove flow to the node.
-     * @param flowBuilder the flow builder
-     * @param nodeBuilder the node builder
-     * @param write whether it is a write
-     */
-    private void syncFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder,
-                          boolean write) {
-        if (write) {
-            writeFlow(flowBuilder, nodeBuilder);
-        } else {
-            removeFlow(flowBuilder, nodeBuilder);
-        }
-    }
-
-    private List<NeutronSecurityRule> getSecurityRulesforGroup(NeutronSecurityGroup securityGroup) {
-        List<NeutronSecurityRule> securityRules = new ArrayList<>();
-        List<NeutronSecurityRule> rules = neutronSecurityRule.getAllNeutronSecurityRules();
-        for (NeutronSecurityRule securityRule : rules) {
-            if (securityGroup.getID().equals(securityRule.getSecurityRuleGroupID())) {
-                securityRules.add(securityRule);
-            }
-        }
-        return securityRules;
-    }
-
     @Override
     public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
         super.setDependencies(bundleContext.getServiceReference(IngressAclProvider.class.getName()), this);
index 15826566b149b6fc4f0cf56d02b1b7214b6a5d8a..917b211914487cecc1bcf5aa7fe719ebb66ed880 100644 (file)
@@ -199,11 +199,11 @@ public class PortSecurityHandler extends AbstractHandler
                 }
             } else {
                 for (Neutron_IPs vmIp : vmIpList) {
-                    securityServicesManager.syncSecurityRule(port, securityRule, vmIp, nodeId, securityGroup, write);
+                    securityServicesManager.syncSecurityRule(port, securityRule, vmIp, nodeId, write);
                 }
             }
         } else {
-            securityServicesManager.syncSecurityRule(port, securityRule, null, nodeId, securityGroup, write);
+            securityServicesManager.syncSecurityRule(port, securityRule, null, nodeId, write);
         }
     }
 
index a69e712e8e995780c0a5da7476e4ee46a0acae8c..8773993a21ab8b9f6a4c8ac1b45117221cdf8be5 100644 (file)
@@ -86,15 +86,13 @@ public final class Constants {
 
     public static final Integer PROTO_DHCP_CLIENT_TRAFFIC_MATCH_PRIORITY = 61012;
     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 = 61004;
     public static final Integer PROTO_DHCP_SERVER_MATCH_PRIORITY = 61008;
-    public static final Integer PROTO_PORT_ICMP_MATCH_PRIORITY = 61003;
-    public static final Integer PROTO_TCP_SYN_MATCH_PRIORITY_DROP = 61002;
+    public static final Integer PROTO_PORT_MATCH_PRIORITY = 61007;
+    public static final Integer PROTO_IP_PORT_MATCH_PRIORITY = 61006;
     public static final Integer PROTO_REG6_MATCH_PRIORITY = 61005;
-    public static final Integer PROTO_VM_IP_MAC_MATCH_PRIORITY = 36001;
+    public static final Integer PROTO_OTHER_MATCH_PRIORITY = 61004;
+    public static final Integer PROTO_PORT_ICMP_MATCH_PRIORITY = 61003;
+    public static final Integer PROTO_PORT_DROP_PRIORITY = 61002;
     public static final Integer CT_STATE_UNTRACKED_PRIORITY = 62030;
     public static final Integer CT_STATE_TRACKED_EXIST_PRIORITY = 62020;
     public static final Integer CT_STATE_TRACKED_NEW_PRIORITY = 62010;
index ea858938f85af2a1a51675a0d91314882aac3416..f5cf05c7731b358cf2092493f392da907276ba84 100644 (file)
@@ -42,12 +42,11 @@ public interface EgressAclProvider {
      * @param segmentationId the segmentation id
      * @param attachedMac the attached mac
      * @param portSecurityRule the security rule
-     * @param securityGroup the security group
      * @param vmIp the ip of the remote vm if it has a remote security group.
      * @param write  is this flow write or delete
      */
-    void programPortSecurityRule(Long dpid, String segmentationId, String attachedMac, NeutronSecurityRule portSecurityRule,
-                                    NeutronSecurityGroup securityGroup, Neutron_IPs vmIp, boolean write);
+    void programPortSecurityRule(Long dpid, String segmentationId, String attachedMac,
+                                 NeutronSecurityRule portSecurityRule, Neutron_IPs vmIp, boolean write);
     /**
      *  Program fixed egress security group rules that will be associated with the VM port when a vm is spawned.
      *
index 021f930972a54afb1f749b961c38cbeac1ea7b13..c8af290db08247a448b2016050794e55cefd7aca 100644 (file)
@@ -14,48 +14,50 @@ import org.opendaylight.netvirt.openstack.netvirt.translator.Neutron_IPs;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 
 /**
- *  This interface allows ingress Port Security flows to be written to devices.
+ * This interface allows ingress Port Security flows to be written to devices.
  */
 public interface IngressAclProvider {
 
     /**
      * Program port security Group.
      *
-     * @param dpid the dpid
+     * @param dpid           the dpid
      * @param segmentationId the segmentation id
-     * @param attachedMac the attached mac
-     * @param localPort the local port
-     * @param securityGroup the security group
-     * @param portUuid the uuid of the port.
-     * @param nodeId the NodeId of the node.
-     * @param write  is this flow write or delete
+     * @param attachedMac    the attached mac
+     * @param localPort      the local port
+     * @param securityGroup  the security group
+     * @param portUuid       the uuid of the port.
+     * @param nodeId         the NodeId of the node.
+     * @param write          is this flow write or delete
      */
     void programPortSecurityGroup(Long dpid, String segmentationId, String attachedMac,
-                                       long localPort, NeutronSecurityGroup securityGroup,
-                                       String portUuid, NodeId nodeId, boolean write);
+                                  long localPort, NeutronSecurityGroup securityGroup,
+                                  String portUuid, NodeId nodeId, boolean write);
+
     /**
      * Program port security rule.
      *
-     * @param dpid the dpid
-     * @param segmentationId the segmentation id
-     * @param attachedMac the attached mac
+     * @param dpid             the dpid
+     * @param segmentationId   the segmentation id
+     * @param attachedMac      the attached mac
      * @param portSecurityRule the security rule
-     * @param securityGroup the security group
-     * @param vmIp the ip of the remote vm if it has a remote security group.
-     * @param write  is this flow write or delete
+     * @param vmIp             the ip of the remote vm if it has a remote security group.
+     * @param write            is this flow write or delete
      */
-    void programPortSecurityRule(Long dpid, String segmentationId, String attachedMac, NeutronSecurityRule portSecurityRule,
-                                     NeutronSecurityGroup securityGroup, Neutron_IPs vmIp, boolean write);
+    void programPortSecurityRule(Long dpid, String segmentationId, String attachedMac,
+                                 NeutronSecurityRule portSecurityRule, Neutron_IPs vmIp, boolean write);
+
     /**
      * Program fixed ingress ACL rules that will be associated with the VM port when a vm is spawned.
      * *
-     * @param dpid the dpid
+     *
+     * @param dpid           the dpid
      * @param segmentationId the segmentation id
-     * @param attachedMac the dhcp mac
-     * @param localPort the local port
-     * @param attachedMac2 the src mac
-     * @param write is this flow writing or deleting
+     * @param attachedMac    the dhcp mac
+     * @param localPort      the local port
+     * @param attachedMac2   the src mac
+     * @param write          is this flow writing or deleting
      */
     void programFixedSecurityGroup(Long dpid, String segmentationId, String attachedMac, long localPort,
-                                  String attachedMac2, boolean write);
+                                   String attachedMac2, boolean write);
 }
\ No newline at end of file
index 879f6e24c3e290c3ffc2c09b3132cff63ff029cc..c140ef5eed4e0263f838b3eef0dababfd307a7e2 100644 (file)
@@ -117,11 +117,10 @@ public interface SecurityServicesManager {
      * @param securityRule the security group associated with the port.
      * @param vmIp The list of remote vm ips.
      * @param nodeId the NodeId of the node.
-     * @param securityGroup the security group.
      * @param write whether to add/delete flow.
      */
     void syncSecurityRule(NeutronPort port, NeutronSecurityRule securityRule, Neutron_IPs vmIp, NodeId nodeId,
-            NeutronSecurityGroup securityGroup, boolean write);
+                          boolean write);
     /**
      * Is connection tracking enabled or not by the user (default is false).
      * @return whether connection tracking enabled.
index dd24bc29c72402b295db2f72de03711ec1584d52..4a7b15813d3c3a6709d79759519491df2da36fc4 100644 (file)
@@ -165,9 +165,9 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG
                     }
                     for (Neutron_IPs vmIp : currentPort.getFixedIPs()) {
                         if (write) {
-                            securityServicesManager.syncSecurityRule(cachedport, securityRule, vmIp, nodeId, securityGroup, true);
+                            securityServicesManager.syncSecurityRule(cachedport, securityRule, vmIp, nodeId, true);
                         } else {
-                            securityServicesManager.syncSecurityRule(cachedport, securityRule, vmIp, nodeId, securityGroup, false);
+                            securityServicesManager.syncSecurityRule(cachedport, securityRule, vmIp, nodeId, false);
                         }
                     }
                 }
index 3426d196a670f10cdc37a623c55d3c0af3618911..62af88d7d6ae5a8e4450431f9cfb4613fa802187 100644 (file)
@@ -498,11 +498,11 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
 
     @Override
     public void syncSecurityRule(NeutronPort port, NeutronSecurityRule securityRule, Neutron_IPs vmIp, NodeId nodeId,
-            NeutronSecurityGroup securityGroup, boolean write) {
+            boolean write) {
         LOG.trace("syncSecurityGroup:" + securityRule + " Write:" + write);
         if (null != port && null != port.getSecurityGroups()) {
             if (nodeId != null) {
-                syncSecurityRules(port, securityRule, vmIp, nodeId, port.getMacAddress(), securityGroup, write);
+                syncSecurityRules(port, securityRule, vmIp, nodeId, port.getMacAddress(), write);
             } else {
                 return;
             }
@@ -510,7 +510,7 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
     }
 
     private void syncSecurityRules(NeutronPort port, NeutronSecurityRule securityRule, Neutron_IPs vmIp, NodeId nodeId,
-            String attachedMac, NeutronSecurityGroup securityGroup, boolean write) {
+            String attachedMac, boolean write) {
         NeutronNetwork neutronNetwork = neutronL3Adapter.getNetworkFromCleanupCache(port.getNetworkUUID());
         if (null == neutronNetwork) {
             neutronNetwork = neutronNetworkCache.getNetwork(port.getNetworkUUID());
@@ -534,10 +534,10 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
         if (NeutronSecurityRule.ETHERTYPE_IPV4.equals(securityRule.getSecurityRuleEthertype())) {
             if (NeutronSecurityRule.DIRECTION_INGRESS.equals(securityRule.getSecurityRuleDirection())) {
                 ingressAclProvider.programPortSecurityRule(dpId, segmentationId, attachedMac,
-                        securityRule, securityGroup, vmIp, write);
+                        securityRule, vmIp, write);
             } else if (NeutronSecurityRule.DIRECTION_EGRESS.equals(securityRule.getSecurityRuleDirection())) {
                 egressAclProvider.programPortSecurityRule(dpId, segmentationId, attachedMac,
-                        securityRule, securityGroup, vmIp, write);
+                        securityRule, vmIp, write);
             }
         }
     }
index 6d80ef5ee84cbd31599b0e2d968f14261c34a8d9..f4b491746dbc0ab963904718dee7e38c74003134 100644 (file)
@@ -137,7 +137,7 @@ public class SecurityGroupCacheManagerImplTest {
     @Test
     public void testPortAddedWithNoRemoteSGInCache() {
         securityGroupCacheManagerImpl.portAdded(SECURITY_GROUP_ID_1, NEUTRON_PORT_ID_VM_1);
-        verify(securityServicesManager, times(0)).syncSecurityRule(any(NeutronPort.class), any(NeutronSecurityRule.class), any(Neutron_IPs.class), any(NodeId.class), any(NeutronSecurityGroup.class), anyBoolean());
+        verify(securityServicesManager, times(0)).syncSecurityRule(any(NeutronPort.class), any(NeutronSecurityRule.class), any(Neutron_IPs.class), any(NodeId.class), anyBoolean());
     }
 
     /**
@@ -147,7 +147,7 @@ public class SecurityGroupCacheManagerImplTest {
     public void testPortRemovedWithNoRemoteSGInCache() {
         securityGroupCacheManagerImpl.addToCache(SECURITY_GROUP_ID_1, NEUTRON_PORT_ID_VM_1, nodeId_1);
         securityGroupCacheManagerImpl.portRemoved(SECURITY_GROUP_ID_1, NEUTRON_PORT_ID_VM_1);
-        verify(securityServicesManager, times(0)).syncSecurityRule(any(NeutronPort.class), any(NeutronSecurityRule.class), any(Neutron_IPs.class), any(NodeId.class), any(NeutronSecurityGroup.class), anyBoolean());
+        verify(securityServicesManager, times(0)).syncSecurityRule(any(NeutronPort.class), any(NeutronSecurityRule.class), any(Neutron_IPs.class), any(NodeId.class), anyBoolean());
     }
 
     /**
@@ -160,8 +160,8 @@ public class SecurityGroupCacheManagerImplTest {
         securityGroupCacheManagerImpl.portAdded(SECURITY_GROUP_ID_1, NEUTRON_PORT_ID_VM_1);
         securityGroupCacheManagerImpl.addToCache(SECURITY_GROUP_ID_1, NEUTRON_PORT_ID_VM_2, nodeId_1);
         securityGroupCacheManagerImpl.portAdded(SECURITY_GROUP_ID_1, NEUTRON_PORT_ID_VM_2);
-        securityServicesManager.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_2, nodeId_1, neutronSecurityGroup_1, true);
-        verify(securityServicesManager, times(1)).syncSecurityRule(eq(neutronPort_Vm1), eq(neutronSecurityRule_1), eq(neutron_ip_2), eq(nodeId_1), eq(neutronSecurityGroup_1), eq(true));
+        securityServicesManager.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_2, nodeId_1, true);
+        verify(securityServicesManager, times(1)).syncSecurityRule(eq(neutronPort_Vm1), eq(neutronSecurityRule_1), eq(neutron_ip_2), eq(nodeId_1), eq(true));
     }
 
     /**
@@ -173,8 +173,8 @@ public class SecurityGroupCacheManagerImplTest {
         securityGroupCacheManagerImpl.addToCache(SECURITY_GROUP_ID_1, NEUTRON_PORT_ID_VM_1, nodeId_1);
         securityGroupCacheManagerImpl.addToCache(SECURITY_GROUP_ID_1, NEUTRON_PORT_ID_VM_2, nodeId_1);
         securityGroupCacheManagerImpl.portRemoved(SECURITY_GROUP_ID_1, NEUTRON_PORT_ID_VM_2);
-        securityServicesManager.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_2, nodeId_1, neutronSecurityGroup_1, false);
-        verify(securityServicesManager, times(1)).syncSecurityRule(eq(neutronPort_Vm1), eq(neutronSecurityRule_1), eq(neutron_ip_2), eq(nodeId_1), eq(neutronSecurityGroup_1), eq(false));
+        securityServicesManager.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_2, nodeId_1, false);
+        verify(securityServicesManager, times(1)).syncSecurityRule(eq(neutronPort_Vm1), eq(neutronSecurityRule_1), eq(neutron_ip_2), eq(nodeId_1), eq(false));
     }
 
     /**
@@ -186,8 +186,8 @@ public class SecurityGroupCacheManagerImplTest {
     public void testPortAddedWithCidrInCache() {
         securityGroupCacheManagerImpl.addToCache(SECURITY_GROUP_ID_2, NEUTRON_PORT_ID_VM_3, nodeId_1);
         securityGroupCacheManagerImpl.portAdded(SECURITY_GROUP_ID_2, NEUTRON_PORT_ID_VM_2);
-        securityServicesManager.syncSecurityRule(neutronPort_Vm3, neutronSecurityRule_3, neutron_ip_2, nodeId_1, neutronSecurityGroup_1, true);
-       verify(securityServicesManager, times(1)).syncSecurityRule(eq(neutronPort_Vm3), eq(neutronSecurityRule_3), eq(neutron_ip_2), eq(nodeId_1), eq(neutronSecurityGroup_1), eq(true));
+        securityServicesManager.syncSecurityRule(neutronPort_Vm3, neutronSecurityRule_3, neutron_ip_2, nodeId_1, true);
+       verify(securityServicesManager, times(1)).syncSecurityRule(eq(neutronPort_Vm3), eq(neutronSecurityRule_3), eq(neutron_ip_2), eq(nodeId_1), eq(true));
     }
 
     /**
@@ -199,8 +199,8 @@ public class SecurityGroupCacheManagerImplTest {
     public void testPortRemovedWithCidrInCache() {
         securityGroupCacheManagerImpl.addToCache(SECURITY_GROUP_ID_2, NEUTRON_PORT_ID_VM_3, nodeId_1);
         securityGroupCacheManagerImpl.portRemoved(SECURITY_GROUP_ID_2, NEUTRON_PORT_ID_VM_2);
-        securityServicesManager.syncSecurityRule(neutronPort_Vm3, neutronSecurityRule_3, neutron_ip_2, nodeId_1, neutronSecurityGroup_1, false);
-        verify(securityServicesManager, times(1)).syncSecurityRule(eq(neutronPort_Vm3), eq(neutronSecurityRule_3), eq(neutron_ip_2), eq(nodeId_1), eq(neutronSecurityGroup_1), eq(false));
+        securityServicesManager.syncSecurityRule(neutronPort_Vm3, neutronSecurityRule_3, neutron_ip_2, nodeId_1, false);
+        verify(securityServicesManager, times(1)).syncSecurityRule(eq(neutronPort_Vm3), eq(neutronSecurityRule_3), eq(neutron_ip_2), eq(nodeId_1), eq(false));
     }
 
     /**
@@ -211,6 +211,6 @@ public class SecurityGroupCacheManagerImplTest {
         securityGroupCacheManagerImpl.addToCache(SECURITY_GROUP_ID_2, NEUTRON_PORT_ID_VM_3, nodeId_1);
         securityGroupCacheManagerImpl.removeFromCache(SECURITY_GROUP_ID_2, NEUTRON_PORT_ID_VM_3, nodeId_1);
         securityGroupCacheManagerImpl.portRemoved(SECURITY_GROUP_ID_2, NEUTRON_PORT_ID_VM_2);
-        verify(securityServicesManager, times(0)).syncSecurityRule(any(NeutronPort.class), any(NeutronSecurityRule.class), any(Neutron_IPs.class),any(NodeId.class), any(NeutronSecurityGroup.class), anyBoolean());
+        verify(securityServicesManager, times(0)).syncSecurityRule(any(NeutronPort.class), any(NeutronSecurityRule.class), any(Neutron_IPs.class),any(NodeId.class), anyBoolean());
     }
 }
index a221d621bd3a211da63ada89a69ac9d16074484c..280da7550d8aa5ecb295bdd906aa0fd6338e2d44 100644 (file)
@@ -480,9 +480,8 @@ public class SecurityServicesImplTest {
         when(neutronSecurityRule_1.getSecurityRuleEthertype()).thenReturn(NeutronSecurityRule.ETHERTYPE_IPV4);
         when(nodeCacheManager.getNode(nodeId_1)).thenReturn(node);
         when(neutronPort_Vm1.getMacAddress()).thenReturn("attached-mac");
-        when(neutronSecurityGroup_1.getSecurityGroupName()).thenReturn(SECURITY_GROUP_ID_1);
-        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, neutronSecurityGroup_1, true);
-        verify(egressAclService, times(1)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutronSecurityGroup_1), eq(neutron_ip_1), eq(true));
+        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, true);
+        verify(egressAclService, times(1)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutron_ip_1), eq(true));
     }
 
     /**
@@ -494,9 +493,8 @@ public class SecurityServicesImplTest {
         securityRuleList.add(neutronSecurityRule_1);
         when(neutronSecurityRule_1.getSecurityRuleDirection()).thenReturn(NeutronSecurityRule.DIRECTION_INGRESS);
         when(neutronSecurityRule_1.getSecurityRuleEthertype()).thenReturn(NeutronSecurityRule.ETHERTYPE_IPV4);
-        when(neutronSecurityGroup_1.getSecurityGroupName()).thenReturn(SECURITY_GROUP_ID_1);
-        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, neutronSecurityGroup_1, true);
-        verify(ingressAclService, times(1)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutronSecurityGroup_1), eq(neutron_ip_1), eq(true));
+        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, true);
+        verify(ingressAclService, times(1)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutron_ip_1), eq(true));
     }
 
     /**
@@ -508,9 +506,8 @@ public class SecurityServicesImplTest {
         securityRuleList.add(neutronSecurityRule_1);
         when(neutronSecurityRule_1.getSecurityRuleDirection()).thenReturn(NeutronSecurityRule.DIRECTION_EGRESS);
         when(neutronSecurityRule_1.getSecurityRuleEthertype()).thenReturn(NeutronSecurityRule.ETHERTYPE_IPV4);
-        when(neutronSecurityGroup_1.getSecurityGroupName()).thenReturn(SECURITY_GROUP_ID_1);
-        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, neutronSecurityGroup_1, false);
-        verify(egressAclService, times(1)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutronSecurityGroup_1), eq(neutron_ip_1), eq(false));
+        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, false);
+        verify(egressAclService, times(1)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutron_ip_1), eq(false));
     }
 
     /**
@@ -522,9 +519,8 @@ public class SecurityServicesImplTest {
         securityRuleList.add(neutronSecurityRule_1);
         when(neutronSecurityRule_1.getSecurityRuleDirection()).thenReturn(NeutronSecurityRule.DIRECTION_INGRESS);
         when(neutronSecurityRule_1.getSecurityRuleEthertype()).thenReturn(NeutronSecurityRule.ETHERTYPE_IPV4);
-        when(neutronSecurityGroup_1.getSecurityGroupName()).thenReturn(SECURITY_GROUP_ID_1);
-        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, neutronSecurityGroup_1, false);
-        verify(ingressAclService, times(1)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutronSecurityGroup_1), eq(neutron_ip_1), eq(false));
+        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, false);
+        verify(ingressAclService, times(1)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutron_ip_1), eq(false));
     }
 
     /**
@@ -536,9 +532,8 @@ public class SecurityServicesImplTest {
         securityRuleList.add(neutronSecurityRule_1);
         when(neutronSecurityRule_1.getSecurityRuleDirection()).thenReturn(NeutronSecurityRule.DIRECTION_INGRESS);
         when(neutronSecurityRule_1.getSecurityRuleEthertype()).thenReturn(NeutronSecurityRule.ETHERTYPE_IPV4);
-        when(neutronSecurityGroup_1.getSecurityGroupName()).thenReturn(SECURITY_GROUP_ID_1);
-        securityServicesImpl.syncSecurityRule(null, neutronSecurityRule_1, neutron_ip_1, nodeId_1, neutronSecurityGroup_1, false);
-        verify(ingressAclService, times(0)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutronSecurityGroup_1), eq(neutron_ip_1), eq(false));
+        securityServicesImpl.syncSecurityRule(null, neutronSecurityRule_1, neutron_ip_1, nodeId_1, false);
+        verify(ingressAclService, times(0)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutron_ip_1), eq(false));
     }
 
     /**
@@ -551,9 +546,8 @@ public class SecurityServicesImplTest {
         when(neutronPort_Vm1.getSecurityGroups()).thenReturn(null);
         when(neutronSecurityRule_1.getSecurityRuleDirection()).thenReturn(NeutronSecurityRule.DIRECTION_INGRESS);
         when(neutronSecurityRule_1.getSecurityRuleEthertype()).thenReturn(NeutronSecurityRule.ETHERTYPE_IPV4);
-        when(neutronSecurityGroup_1.getSecurityGroupName()).thenReturn(SECURITY_GROUP_ID_1);
-        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, neutronSecurityGroup_1, false);
-        verify(ingressAclService, times(0)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutronSecurityGroup_1), eq(neutron_ip_1), eq(false));
+        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, false);
+        verify(ingressAclService, times(0)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutron_ip_1), eq(false));
     }
 
     /**
@@ -566,9 +560,8 @@ public class SecurityServicesImplTest {
         when(neutronSecurityRule_1.getSecurityRuleDirection()).thenReturn(NeutronSecurityRule.DIRECTION_INGRESS);
         when(neutronSecurityRule_1.getSecurityRuleEthertype()).thenReturn(NeutronSecurityRule.ETHERTYPE_IPV4);
         when(southbound.getInterfaceExternalIdsValue(any(OvsdbTerminationPointAugmentation.class),eq("attached-mac"))).thenReturn(null);
-        when(neutronSecurityGroup_1.getSecurityGroupName()).thenReturn(SECURITY_GROUP_ID_1);
-        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, neutronSecurityGroup_1, false);
-        verify(ingressAclService, times(1)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutronSecurityGroup_1), eq(neutron_ip_1), eq(false));
+        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, false);
+        verify(ingressAclService, times(1)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutron_ip_1), eq(false));
     }
 
 
@@ -581,9 +574,8 @@ public class SecurityServicesImplTest {
         securityRuleList.add(neutronSecurityRule_1);
         when(neutronSecurityRule_1.getSecurityRuleDirection()).thenReturn(NeutronSecurityRule.DIRECTION_INGRESS);
         when(neutronSecurityRule_1.getSecurityRuleEthertype()).thenReturn(NeutronSecurityRule.ETHERTYPE_IPV6);
-        when(neutronSecurityGroup_1.getSecurityGroupName()).thenReturn(SECURITY_GROUP_ID_1);
-        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, neutronSecurityGroup_1, false);
-        verify(ingressAclService, times(0)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutronSecurityGroup_1), eq(neutron_ip_1), eq(false));
+        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, false);
+        verify(ingressAclService, times(0)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutron_ip_1), eq(false));
     }
 
     /**
@@ -595,9 +587,8 @@ public class SecurityServicesImplTest {
         securityRuleList.add(neutronSecurityRule_1);
         when(neutronSecurityRule_1.getSecurityRuleDirection()).thenReturn("outgress");
         when(neutronSecurityRule_1.getSecurityRuleEthertype()).thenReturn(NeutronSecurityRule.ETHERTYPE_IPV4);
-        when(neutronSecurityGroup_1.getSecurityGroupName()).thenReturn(SECURITY_GROUP_ID_1);
-        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, neutronSecurityGroup_1, false);
-        verify(ingressAclService, times(0)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutronSecurityGroup_1), eq(neutron_ip_1), eq(false));
+        securityServicesImpl.syncSecurityRule(neutronPort_Vm1, neutronSecurityRule_1, neutron_ip_1, nodeId_1, false);
+        verify(ingressAclService, times(0)).programPortSecurityRule(eq(new Long(1)), eq("1000"), eq("attached-mac"), eq(neutronSecurityRule_1), eq(neutron_ip_1), eq(false));
     }
 
     @Test