MatchInfo redesign
[netvirt.git] / vpnservice / aclservice / impl / src / main / java / org / opendaylight / netvirt / aclservice / StatelessEgressAclServiceImpl.java
index 5fb36a9fc7d7e56e135f1beae1d1cc1594fe6288..db7dc3eacd6dd9d4f866beb2ad0ffaf65d072bcd 100644 (file)
@@ -15,14 +15,14 @@ import java.util.Map;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.genius.mdsalutil.ActionInfo;
 import org.opendaylight.genius.mdsalutil.InstructionInfo;
-import org.opendaylight.genius.mdsalutil.MatchFieldType;
-import org.opendaylight.genius.mdsalutil.MatchInfo;
 import org.opendaylight.genius.mdsalutil.MatchInfoBase;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.genius.mdsalutil.NxMatchFieldType;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
+import org.opendaylight.genius.mdsalutil.matches.MatchTcpFlags;
 import org.opendaylight.netvirt.aclservice.api.AclServiceManager.Action;
 import org.opendaylight.netvirt.aclservice.utils.AclConstants;
+import org.opendaylight.netvirt.aclservice.utils.AclDataUtil;
 import org.opendaylight.netvirt.aclservice.utils.AclServiceOFFlowBuilder;
 import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace;
@@ -46,9 +46,9 @@ public class StatelessEgressAclServiceImpl extends AbstractEgressAclServiceImpl
 
     private static final Logger LOG = LoggerFactory.getLogger(StatelessEgressAclServiceImpl.class);
 
-    public StatelessEgressAclServiceImpl(DataBroker dataBroker,
-            IMdsalApiManager mdsalManager) {
-        super(dataBroker, mdsalManager);
+    public StatelessEgressAclServiceImpl(DataBroker dataBroker, IMdsalApiManager mdsalManager, AclDataUtil aclDataUtil,
+            AclServiceUtils aclServiceUtils) {
+        super(dataBroker, mdsalManager, aclDataUtil, aclServiceUtils);
     }
 
     @Override
@@ -57,15 +57,15 @@ public class StatelessEgressAclServiceImpl extends AbstractEgressAclServiceImpl
     }
 
     @Override
-    protected String syncSpecificAclFlow(BigInteger dpId, int lportTag, int addOrRemove, Ace ace, String portId,
-            Map<String, List<MatchInfoBase>> flowMap, String flowName) {
+    protected String syncSpecificAclFlow(BigInteger dpId, int lportTag, int addOrRemove, int priority, Ace ace,
+            String portId, Map<String, List<MatchInfoBase>> flowMap, String flowName) {
         // Not in use here. programAceRule function is overridden.
         return null;
     }
 
     @Override
-    protected void programAceRule(BigInteger dpId, int lportTag, int addOrRemove, Ace ace, String portId,
-            List<AllowedAddressPairs> syncAllowedAddresses) {
+    protected void programAceRule(BigInteger dpId, int lportTag, int addOrRemove, String aclName, Ace ace,
+            String portId, List<AllowedAddressPairs> syncAllowedAddresses) {
         SecurityRuleAttr aceAttr = AclServiceUtils.getAccesssListAttributes(ace);
         if (!aceAttr.getDirection().equals(DirectionEgress.class)) {
             return;
@@ -86,22 +86,25 @@ public class StatelessEgressAclServiceImpl extends AbstractEgressAclServiceImpl
         for (Map.Entry<String, List<MatchInfoBase>> flow : flowMap.entrySet()) {
             String flowName = flow.getKey();
             List<MatchInfoBase> flowMatches = flow.getValue();
-            boolean hasTcpDstMatch = AclServiceUtils.containsMatchFieldType(flowMatches,
-                    NxMatchFieldType.nx_tcp_dst_with_mask);
-            if (hasTcpDstMatch || protocol == null) {
+            boolean hasTcpMatch = AclServiceUtils.containsMatchFieldType(flowMatches,
+                    NxMatchFieldType.nx_tcp_dst_with_mask) || AclServiceUtils.containsMatchFieldType(flowMatches,
+                            NxMatchFieldType.nx_tcp_src_with_mask);
+            if (hasTcpMatch || protocol == null) {
                 flowName += "Egress" + lportTag + ace.getKey().getRuleName();
                 flowMatches.add(AclServiceUtils.buildLPortTagMatch(lportTag));
 
-                programAllowSynRules(dpId, flowName, flowMatches, addOrRemove);
+                programAllowSynRules(dpId, flowName, flowMatches, addOrRemove, protocol);
             }
         }
     }
 
     private void programAllowSynRules(BigInteger dpId, String origFlowName,
-            List<MatchInfoBase> origFlowMatches, int addFlow) {
+            List<MatchInfoBase> origFlowMatches, int addFlow, Short protocol) {
         List<MatchInfoBase> flowMatches = new ArrayList<>();
         flowMatches.addAll(origFlowMatches);
-        flowMatches.add(new MatchInfo(MatchFieldType.tcp_flags, new long[] { AclConstants.TCP_FLAG_SYN }));
+        if (new Short((short) NwConstants.IP_PROT_TCP).equals(protocol)) {
+            flowMatches.add(MatchTcpFlags.SYN);
+        }
 
         List<ActionInfo> actionsInfos = new ArrayList<>();
         List<InstructionInfo> instructions = getDispatcherTableResubmitInstructions(actionsInfos);