2 * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.aclservice;
10 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
12 import com.google.common.collect.Lists;
13 import java.math.BigInteger;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.HashMap;
18 import java.util.HashSet;
19 import java.util.List;
21 import java.util.Map.Entry;
23 import java.util.SortedSet;
24 import java.util.stream.Collectors;
25 import javax.annotation.Nullable;
26 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
27 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
28 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
29 import org.opendaylight.genius.mdsalutil.ActionInfo;
30 import org.opendaylight.genius.mdsalutil.FlowEntity;
31 import org.opendaylight.genius.mdsalutil.InstructionInfo;
32 import org.opendaylight.genius.mdsalutil.MDSALUtil;
33 import org.opendaylight.genius.mdsalutil.MatchInfoBase;
34 import org.opendaylight.genius.mdsalutil.NwConstants;
35 import org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack;
36 import org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack.NxCtAction;
37 import org.opendaylight.genius.mdsalutil.actions.ActionNxCtClear;
38 import org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit;
39 import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
40 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
41 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType;
42 import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
43 import org.opendaylight.genius.mdsalutil.nxmatches.NxMatchCtState;
44 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
45 import org.opendaylight.netvirt.aclservice.api.AclInterfaceCache;
46 import org.opendaylight.netvirt.aclservice.api.AclServiceListener;
47 import org.opendaylight.netvirt.aclservice.api.AclServiceManager.Action;
48 import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
49 import org.opendaylight.netvirt.aclservice.utils.AclConntrackClassifierType;
50 import org.opendaylight.netvirt.aclservice.utils.AclConstants;
51 import org.opendaylight.netvirt.aclservice.utils.AclDataUtil;
52 import org.opendaylight.netvirt.aclservice.utils.AclServiceOFFlowBuilder;
53 import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
54 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl;
55 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.AccessListEntries;
56 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace;
57 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches;
58 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIp;
59 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv4;
60 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeBase;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeEgress;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionBase;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionEgress;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionIngress;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.SecurityRuleAttr;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo;
69 import org.slf4j.Logger;
70 import org.slf4j.LoggerFactory;
72 public abstract class AbstractAclServiceImpl implements AclServiceListener {
74 private static final Logger LOG = LoggerFactory.getLogger(AbstractAclServiceImpl.class);
76 protected final IMdsalApiManager mdsalManager;
77 protected final ManagedNewTransactionRunner txRunner;
78 protected final Class<? extends ServiceModeBase> serviceMode;
79 protected final AclDataUtil aclDataUtil;
80 protected final AclServiceUtils aclServiceUtils;
81 protected final JobCoordinator jobCoordinator;
82 protected final AclInterfaceCache aclInterfaceCache;
84 protected final Class<? extends DirectionBase> direction;
85 protected final String directionString;
88 * Initialize the member variables.
90 * @param serviceMode the service mode
91 * @param dataBroker the data broker instance.
92 * @param mdsalManager the mdsal manager instance.
93 * @param aclDataUtil the acl data util.
94 * @param aclServiceUtils the acl service util.
95 * @param jobCoordinator the job coordinator
96 * @param aclInterfaceCache the acl interface cache
98 public AbstractAclServiceImpl(Class<? extends ServiceModeBase> serviceMode, DataBroker dataBroker,
99 IMdsalApiManager mdsalManager, AclDataUtil aclDataUtil, AclServiceUtils aclServiceUtils,
100 JobCoordinator jobCoordinator, AclInterfaceCache aclInterfaceCache) {
101 this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
102 this.mdsalManager = mdsalManager;
103 this.serviceMode = serviceMode;
104 this.aclDataUtil = aclDataUtil;
105 this.aclServiceUtils = aclServiceUtils;
106 this.jobCoordinator = jobCoordinator;
107 this.aclInterfaceCache = aclInterfaceCache;
110 this.serviceMode.equals(ServiceModeEgress.class) ? DirectionIngress.class : DirectionEgress.class;
111 this.directionString = this.direction.equals(DirectionEgress.class) ? "Egress" : "Ingress";
115 public boolean applyAcl(AclInterface port) {
117 LOG.error("port cannot be null");
120 if (port.getSecurityGroups() == null) {
121 LOG.info("Port {} without SGs", port.getInterfaceId());
124 BigInteger dpId = port.getDpId();
125 if (dpId == null || port.getLPortTag() == null) {
126 LOG.error("Unable to find DpId from ACL interface with id {}", port.getInterfaceId());
129 LOG.debug("Applying ACL on port {} with DpId {}", port, dpId);
130 List<FlowEntity> flowEntries = new ArrayList<>();
131 programAcl(flowEntries, port, Action.ADD, NwConstants.ADD_FLOW);
132 updateRemoteAclFilterTable(flowEntries, port, NwConstants.ADD_FLOW);
133 programFlows(AclConstants.ACL_JOB_KEY_PREFIX + port.getInterfaceId(), flowEntries, NwConstants.ADD_FLOW);
138 public boolean bindAcl(AclInterface port) {
139 if (port == null || port.getSecurityGroups() == null) {
140 LOG.error("Port and port security groups cannot be null for binding ACL service, port={}", port);
148 public boolean unbindAcl(AclInterface port) {
150 LOG.error("Port cannot be null for unbinding ACL service");
153 if (port.getDpId() != null) {
160 public boolean updateAcl(AclInterface portBefore, AclInterface portAfter) {
161 // this check is to avoid situations of port update coming before interface state is up
162 if (portAfter.getDpId() == null || portAfter.getLPortTag() == null) {
163 LOG.debug("Unable to find DpId from ACL interface with id {} and lport {}", portAfter.getInterfaceId(),
164 portAfter.getLPortTag());
167 boolean result = true;
168 boolean isPortSecurityEnable = portAfter.isPortSecurityEnabled();
169 boolean isPortSecurityEnableBefore = portBefore.isPortSecurityEnabled();
170 // if port security is changed, apply/remove Acls
171 if (isPortSecurityEnableBefore != isPortSecurityEnable) {
172 LOG.debug("On ACL update, Port security is {} for {}", isPortSecurityEnable ? "Enabled" :
173 "Disabled", portAfter.getInterfaceId());
174 if (isPortSecurityEnable) {
175 result = applyAcl(portAfter);
177 result = removeAcl(portBefore);
179 } else if (isPortSecurityEnable) {
180 // Acls has been updated, find added/removed Acls and act accordingly.
181 processInterfaceUpdate(portBefore, portAfter);
182 LOG.debug("On ACL update, ACL has been updated for {}", portAfter.getInterfaceId());
188 private void processInterfaceUpdate(AclInterface portBefore, AclInterface portAfter) {
189 List<FlowEntity> addFlowEntries = new ArrayList<>();
190 List<FlowEntity> deleteFlowEntries = new ArrayList<>();
191 List<AllowedAddressPairs> addedAaps = AclServiceUtils
192 .getUpdatedAllowedAddressPairs(portAfter.getAllowedAddressPairs(), portBefore.getAllowedAddressPairs());
193 List<AllowedAddressPairs> deletedAaps = AclServiceUtils
194 .getUpdatedAllowedAddressPairs(portBefore.getAllowedAddressPairs(), portAfter.getAllowedAddressPairs());
195 if (deletedAaps != null && !deletedAaps.isEmpty()) {
196 programAclWithAllowedAddress(deleteFlowEntries, portBefore, deletedAaps, Action.UPDATE,
197 NwConstants.DEL_FLOW);
198 updateRemoteAclFilterTable(deleteFlowEntries, portBefore, portBefore.getSecurityGroups(), deletedAaps,
199 NwConstants.DEL_FLOW);
201 if (addedAaps != null && !addedAaps.isEmpty()) {
202 programAclWithAllowedAddress(addFlowEntries, portAfter, addedAaps, Action.UPDATE, NwConstants.ADD_FLOW);
203 updateRemoteAclFilterTable(addFlowEntries, portAfter, portAfter.getSecurityGroups(), addedAaps,
204 NwConstants.ADD_FLOW);
206 if (portAfter.getSubnetInfo() != null && portBefore.getSubnetInfo() == null) {
207 programBroadcastRules(addFlowEntries, portAfter, NwConstants.ADD_FLOW);
209 handleSubnetChange(portBefore, portAfter, addFlowEntries, deleteFlowEntries);
211 List<Uuid> addedAcls = AclServiceUtils.getUpdatedAclList(portAfter.getSecurityGroups(),
212 portBefore.getSecurityGroups());
213 List<Uuid> deletedAcls = AclServiceUtils.getUpdatedAclList(portBefore.getSecurityGroups(),
214 portAfter.getSecurityGroups());
215 if (!deletedAcls.isEmpty() || !addedAcls.isEmpty()) {
216 handleAclChange(deleteFlowEntries, portBefore, deletedAcls, NwConstants.DEL_FLOW);
217 handleAclChange(addFlowEntries, portAfter, addedAcls, NwConstants.ADD_FLOW);
220 programFlows(AclConstants.ACL_JOB_KEY_PREFIX + portAfter.getInterfaceId(), deleteFlowEntries,
221 NwConstants.DEL_FLOW);
222 programFlows(AclConstants.ACL_JOB_KEY_PREFIX + portAfter.getInterfaceId(), addFlowEntries,
223 NwConstants.ADD_FLOW);
226 private void handleSubnetChange(AclInterface portBefore, AclInterface portAfter,
227 List<FlowEntity> addFlowEntries, List<FlowEntity> deleteFlowEntries) {
228 List<SubnetInfo> deletedSubnets =
229 AclServiceUtils.getSubnetDiff(portBefore.getSubnetInfo(), portAfter.getSubnetInfo());
230 List<SubnetInfo> addedSubnets =
231 AclServiceUtils.getSubnetDiff(portAfter.getSubnetInfo(), portBefore.getSubnetInfo());
233 if (deletedSubnets != null && !deletedSubnets.isEmpty()) {
234 programIcmpv6RARule(deleteFlowEntries, portAfter, deletedSubnets, NwConstants.DEL_FLOW);
235 programSubnetBroadcastRules(deleteFlowEntries, portAfter, deletedSubnets, NwConstants.DEL_FLOW);
237 if (addedSubnets != null && !addedSubnets.isEmpty()) {
238 programIcmpv6RARule(addFlowEntries, portAfter, addedSubnets, NwConstants.ADD_FLOW);
239 programSubnetBroadcastRules(addFlowEntries, portAfter, addedSubnets, NwConstants.ADD_FLOW);
243 private void handleAclChange(List<FlowEntity> flowEntries, AclInterface port, List<Uuid> aclList,
245 int operationForAclRules = (addOrRemove == NwConstants.DEL_FLOW) ? NwConstants.MOD_FLOW : addOrRemove;
246 programAclRules(flowEntries, port, aclList, operationForAclRules);
247 updateRemoteAclFilterTable(flowEntries, port, aclList, port.getAllowedAddressPairs(), addOrRemove);
248 programAclDispatcherTable(flowEntries, port, addOrRemove);
251 protected SortedSet<Integer> getRemoteAclTags(AclInterface port) {
252 return this.direction == DirectionIngress.class ? port.getIngressRemoteAclTags()
253 : port.getEgressRemoteAclTags();
256 protected void programAclDispatcherTable(List<FlowEntity> flowEntries, AclInterface port, int addOrRemove) {
257 SortedSet<Integer> remoteAclTags = getRemoteAclTags(port);
258 if (remoteAclTags.isEmpty()) {
259 LOG.debug("No {} rules with remote group id for port={}", this.directionString, port.getInterfaceId());
262 Integer firstRemoteAclTag = remoteAclTags.first();
263 Integer lastRemoteAclTag = remoteAclTags.last();
265 programFirstRemoteAclEntryInDispatcherTable(flowEntries, port, firstRemoteAclTag, addOrRemove);
266 programLastRemoteAclEntryInDispatcherTable(flowEntries, port, lastRemoteAclTag, addOrRemove);
268 Integer previousRemoteAclTag = firstRemoteAclTag;
269 for (Integer remoteAclTag : remoteAclTags) {
270 if (remoteAclTag.equals(firstRemoteAclTag)) {
273 List<MatchInfoBase> matches = new ArrayList<>();
274 matches.addAll(AclServiceUtils.buildMatchesForLPortTagAndRemoteAclTag(port.getLPortTag(),
275 previousRemoteAclTag, serviceMode));
276 String flowId = this.directionString + "_ACL_Dispatcher_" + port.getDpId() + "_" + port.getLPortTag() + "_"
279 List<InstructionInfo> instructions =
280 AclServiceOFFlowBuilder.getGotoInstructionInfo(getAclRuleBasedFilterTable());
281 instructions.add(AclServiceUtils.getWriteMetadataForRemoteAclTag(remoteAclTag));
282 addFlowEntryToList(flowEntries, port.getDpId(), getAclFilterCumDispatcherTable(), flowId,
283 AclConstants.ACE_GOTO_NEXT_REMOTE_ACL_PRIORITY, 0, 0, AclConstants.COOKIE_ACL_BASE, matches,
284 instructions, addOrRemove);
286 previousRemoteAclTag = remoteAclTag;
290 protected void programFirstRemoteAclEntryInDispatcherTable(List<FlowEntity> flowEntries, AclInterface port,
291 Integer firstRemoteAclTag, int addOrRemove) {
292 List<MatchInfoBase> matches = new ArrayList<>();
293 matches.add(AclServiceUtils.buildLPortTagMatch(port.getLPortTag(), serviceMode));
294 String flowId = this.directionString + "_ACL_Dispatcher_First_" + port.getDpId() + "_" + port.getLPortTag()
295 + "_" + firstRemoteAclTag;
297 List<InstructionInfo> instructions =
298 AclServiceOFFlowBuilder.getGotoInstructionInfo(getAclRuleBasedFilterTable());
299 instructions.add(AclServiceUtils.getWriteMetadataForRemoteAclTag(firstRemoteAclTag));
300 addFlowEntryToList(flowEntries, port.getDpId(), getAclFilterCumDispatcherTable(), flowId,
301 AclConstants.ACE_FIRST_REMOTE_ACL_PRIORITY, 0, 0, AclConstants.COOKIE_ACL_BASE, matches, instructions,
305 protected void programLastRemoteAclEntryInDispatcherTable(List<FlowEntity> flowEntries, AclInterface port,
306 Integer lastRemoteAclTag, int addOrRemove) {
307 List<MatchInfoBase> matches = new ArrayList<>();
308 matches.addAll(AclServiceUtils.buildMatchesForLPortTagAndRemoteAclTag(port.getLPortTag(), lastRemoteAclTag,
310 String flowId = this.directionString + "_ACL_Dispatcher_Last_" + port.getDpId() + "_" + port.getLPortTag() + "_"
313 List<InstructionInfo> instructions = AclServiceOFFlowBuilder.getDropInstructionInfo();
314 addFlowEntryToList(flowEntries, port.getDpId(), getAclFilterCumDispatcherTable(), flowId,
315 AclConstants.ACE_LAST_REMOTE_ACL_PRIORITY, 0, 0, AclServiceUtils.getDropFlowCookie(port.getLPortTag()),
316 matches, instructions, addOrRemove);
319 private void programAcl(List<FlowEntity> flowEntries, AclInterface port, Action action, int addOrRemove) {
320 programAclWithAllowedAddress(flowEntries, port, port.getAllowedAddressPairs(), action, addOrRemove);
323 private void programAclWithAllowedAddress(List<FlowEntity> flowEntries, AclInterface port,
324 List<AllowedAddressPairs> allowedAddresses, Action action, int addOrRemove) {
325 BigInteger dpId = port.getDpId();
326 int lportTag = port.getLPortTag();
327 LOG.debug("Applying ACL Allowed Address on DpId {}, lportTag {}, Action {}", dpId, lportTag, action);
328 String portId = port.getInterfaceId();
329 programAntiSpoofingRules(flowEntries, port, allowedAddresses, action, addOrRemove);
330 programAclPortSpecificFixedRules(flowEntries, dpId, allowedAddresses, lportTag, portId, action, addOrRemove);
331 if (action == Action.ADD || action == Action.REMOVE) {
332 programAclRules(flowEntries, port, port.getSecurityGroups(), addOrRemove);
333 programAclDispatcherTable(flowEntries, port, addOrRemove);
338 * Programs the acl custom rules.
340 * @param flowEntries the flow entries
341 * @param port acl interface
342 * @param aclUuidList the list of acl uuid to be applied
343 * @param addOrRemove whether to delete or add flow
344 * @return program succeeded
346 protected boolean programAclRules(List<FlowEntity> flowEntries, AclInterface port, List<Uuid> aclUuidList,
348 BigInteger dpId = port.getDpId();
349 LOG.debug("Applying custom rules on DpId {}, lportTag {}", dpId, port.getLPortTag());
350 if (aclUuidList == null || dpId == null) {
351 LOG.warn("{} ACL parameters can not be null. dpId={}, aclUuidList={}", this.directionString, dpId,
355 for (Uuid aclUuid : aclUuidList) {
356 Acl acl = this.aclDataUtil.getAcl(aclUuid.getValue());
358 LOG.warn("The ACL {} not found in cache", aclUuid.getValue());
361 AccessListEntries accessListEntries = acl.getAccessListEntries();
362 if (accessListEntries != null && accessListEntries.getAce() != null) {
363 for (Ace ace: accessListEntries.getAce()) {
364 programAceRule(flowEntries, port, aclUuid.getValue(), ace, addOrRemove);
372 * Programs the ace specific rule.
374 * @param flowEntries flow entries
375 * @param port acl interface
376 * @param aclName the acl name
377 * @param ace rule to be program
378 * @param addOrRemove whether to delete or add flow
380 protected void programAceRule(List<FlowEntity> flowEntries, AclInterface port, String aclName, Ace ace,
382 SecurityRuleAttr aceAttr = AclServiceUtils.getAccessListAttributes(ace);
383 if (addOrRemove == NwConstants.ADD_FLOW && aceAttr.isDeleted()) {
384 LOG.trace("Ignoring {} rule which is already deleted", ace.getRuleName());
387 if (!isValidDirection(aceAttr.getDirection())) {
388 LOG.trace("Ignoring {} direction while processing for {} ACE Rule {}", aceAttr.getDirection(),
389 this.directionString, ace.getRuleName());
392 LOG.debug("Program {} ACE rule for dpId={}, lportTag={}, addOrRemove={}, ace={}, portId={}",
393 this.directionString, port.getDpId(), port.getLPortTag(), addOrRemove, ace.getRuleName(),
394 port.getInterfaceId());
396 Matches matches = ace.getMatches();
397 if (matches != null && matches.getAceType() instanceof AceIp) {
398 Map<String, List<MatchInfoBase>> flowMap = AclServiceOFFlowBuilder.programIpFlow(matches);
399 if (!AclServiceUtils.doesAceHaveRemoteGroupId(aceAttr)) {
400 // programming for ACE which doesn't have any remote group Id
401 programForAceNotHavingRemoteAclId(flowEntries, port, aclName, ace, flowMap, addOrRemove);
403 Uuid remoteAclId = aceAttr.getRemoteGroupId();
404 // programming for ACE which have remote group Id
405 programAceSpecificFlows(flowEntries, port, aclName, ace, flowMap, remoteAclId, addOrRemove);
410 protected void programForAceNotHavingRemoteAclId(List<FlowEntity> flowEntries, AclInterface port, String aclName,
411 Ace ace, @Nullable Map<String, List<MatchInfoBase>> flowMap, int addOrRemove) {
412 if (null == flowMap) {
415 MatchInfoBase lportTagMatch = AclServiceUtils.buildLPortTagMatch(port.getLPortTag(), serviceMode);
416 List<InstructionInfo> instructions = AclServiceOFFlowBuilder.getGotoInstructionInfo(getAclCommitterTable());
417 Integer flowPriority = this.aclServiceUtils.getAceFlowPriority(aclName);
419 for (Entry<String, List<MatchInfoBase>> entry : flowMap.entrySet()) {
420 String flowName = entry.getKey();
421 List<MatchInfoBase> matches = entry.getValue();
422 matches.add(lportTagMatch);
423 String flowId = flowName + this.directionString + "_" + port.getDpId() + "_" + port.getLPortTag() + "_"
424 + ace.key().getRuleName();
426 int operation = addOrRemove == NwConstants.MOD_FLOW ? NwConstants.DEL_FLOW : addOrRemove;
427 addFlowEntryToList(flowEntries, port.getDpId(), getAclFilterCumDispatcherTable(), flowId, flowPriority,
428 0, 0, AclConstants.COOKIE_ACL_BASE, matches, instructions, operation);
430 if (addOrRemove != NwConstants.DEL_FLOW) {
431 programAclForExistingTrafficTable(port, ace, addOrRemove, flowName, matches, flowPriority);
436 protected void programAceSpecificFlows(List<FlowEntity> flowEntries, AclInterface port, String aclName, Ace ace,
437 @Nullable Map<String, List<MatchInfoBase>> flowMap, Uuid remoteAclId, int addOrRemove) {
438 if (null == flowMap) {
441 Integer remoteAclTag = this.aclServiceUtils.getAclTag(remoteAclId);
442 if (remoteAclTag == null || remoteAclTag == AclConstants.INVALID_ACL_TAG) {
443 LOG.error("remoteAclTag={} is null or invalid for remoteAclId={}", remoteAclTag, remoteAclId);
446 List<MatchInfoBase> lportAndAclMatches =
447 AclServiceUtils.buildMatchesForLPortTagAndRemoteAclTag(port.getLPortTag(), remoteAclTag, serviceMode);
448 List<InstructionInfo> instructions = AclServiceOFFlowBuilder.getGotoInstructionInfo(getAclRemoteAclTable());
449 Integer flowPriority = this.aclServiceUtils.getAceFlowPriority(aclName);
451 for (Entry<String, List<MatchInfoBase>> entry : flowMap.entrySet()) {
452 String flowName = entry.getKey();
453 List<MatchInfoBase> matches = entry.getValue();
454 matches.addAll(lportAndAclMatches);
455 String flowId = flowName + this.directionString + "_" + port.getDpId() + "_" + port.getLPortTag() + "_"
456 + ace.key().getRuleName();
458 int operation = addOrRemove == NwConstants.MOD_FLOW ? NwConstants.DEL_FLOW : addOrRemove;
459 addFlowEntryToList(flowEntries, port.getDpId(), getAclRuleBasedFilterTable(), flowId, flowPriority, 0, 0,
460 AclConstants.COOKIE_ACL_BASE, matches, instructions, operation);
462 if (addOrRemove != NwConstants.DEL_FLOW) {
463 programAclForExistingTrafficTable(port, ace, addOrRemove, flowName, matches, flowPriority);
468 private void programAclForExistingTrafficTable(AclInterface port, Ace ace, int addOrRemove, String flowName,
469 List<MatchInfoBase> matches, Integer priority) {
470 AceIp acl = (AceIp) ace.getMatches().getAceType();
471 final String newFlowName = flowName + this.directionString + "_" + port.getDpId() + "_" + port.getLPortTag()
472 + "_" + ((acl.getAceIpVersion() instanceof AceIpv4) ? "_IPv4" : "_IPv6") + "_FlowAfterRuleDeleted";
474 final List<MatchInfoBase> newMatches =
475 matches.stream().filter(obj -> !(obj instanceof NxMatchCtState || obj instanceof MatchMetadata))
476 .collect(Collectors.toList());
477 newMatches.add(AclServiceUtils.buildLPortTagMatch(port.getLPortTag(), serviceMode));
478 newMatches.add(new NxMatchCtState(AclConstants.TRACKED_RPL_CT_STATE, AclConstants.TRACKED_RPL_CT_STATE_MASK));
480 List<InstructionInfo> instructions =
481 AclServiceUtils.createCtMarkInstructionForNewState(getAclFilterCumDispatcherTable(), port.getElanId());
482 // Reversing the flow add/delete operation for this table.
483 List<FlowEntity> flowEntries = new ArrayList<>();
484 int operation = (addOrRemove == NwConstants.ADD_FLOW) ? NwConstants.DEL_FLOW : NwConstants.ADD_FLOW;
485 addFlowEntryToList(flowEntries, port.getDpId(), getAclForExistingTrafficTable(), newFlowName, priority, 0,
486 AclServiceUtils.getHardTimoutForApplyStatefulChangeOnExistingTraffic(ace, aclServiceUtils),
487 AclConstants.COOKIE_ACL_BASE, newMatches, instructions, operation);
488 programFlows(AclConstants.ACL_JOB_KEY_PREFIX + port.getInterfaceId(), flowEntries, operation);
492 public boolean removeAcl(AclInterface port) {
493 if (port.getDpId() == null) {
494 LOG.warn("Unable to find DP Id from ACL interface with id {}", port.getInterfaceId());
497 List<FlowEntity> flowEntries = new ArrayList<>();
498 programAcl(flowEntries, port, Action.REMOVE, NwConstants.DEL_FLOW);
499 updateRemoteAclFilterTable(flowEntries, port, NwConstants.DEL_FLOW);
500 programFlows(AclConstants.ACL_JOB_KEY_PREFIX + port.getInterfaceId(), flowEntries, NwConstants.DEL_FLOW);
505 public boolean applyAce(AclInterface port, String aclName, Ace ace) {
506 if (!port.isPortSecurityEnabled() || port.getDpId() == null) {
509 List<FlowEntity> flowEntries = new ArrayList<>();
510 programAceRule(flowEntries, port, aclName, ace, NwConstants.ADD_FLOW);
511 programFlows(AclConstants.ACL_JOB_KEY_PREFIX + port.getInterfaceId(), flowEntries, NwConstants.ADD_FLOW);
516 public boolean removeAce(AclInterface port, String aclName, Ace ace) {
517 if (!port.isPortSecurityEnabled() || port.getDpId() == null) {
520 List<FlowEntity> flowEntries = new ArrayList<>();
521 programAceRule(flowEntries, port, aclName, ace, NwConstants.MOD_FLOW);
522 programFlows(AclConstants.ACL_JOB_KEY_PREFIX + port.getInterfaceId(), flowEntries, NwConstants.DEL_FLOW);
527 public void updateRemoteAcl(Acl aclBefore, Acl aclAfter, Collection<AclInterface> portsBefore) {
528 handleRemoteAclUpdate(aclBefore, aclAfter, portsBefore);
534 * @param aclInterface the acl interface
536 public abstract void bindService(AclInterface aclInterface);
541 * @param aclInterface the acl interface
543 protected abstract void unbindService(AclInterface aclInterface);
546 * Programs the anti-spoofing rules.
548 * @param flowEntries the flow entries
549 * @param port the acl interface
550 * @param allowedAddresses the allowed addresses
551 * @param action add/modify/remove action
552 * @param addOrRemove addorRemove
554 protected abstract void programAntiSpoofingRules(List<FlowEntity> flowEntries, AclInterface port,
555 List<AllowedAddressPairs> allowedAddresses, Action action, int addOrRemove);
558 * Programs broadcast rules.
560 * @param flowEntries the flow entries
561 * @param port the Acl Interface port
562 * @param addOrRemove whether to delete or add flow
564 protected abstract void programBroadcastRules(List<FlowEntity> flowEntries, AclInterface port, int addOrRemove);
567 * Programs broadcast rules.
569 * @param flowEntries the flow entries
570 * @param port the Acl Interface port
571 * @param subnetInfoList the port subnet info list
572 * @param addOrRemove whether to delete or add flow
574 protected abstract void programSubnetBroadcastRules(List<FlowEntity> flowEntries, AclInterface port,
575 List<SubnetInfo> subnetInfoList, int addOrRemove);
577 protected abstract void programIcmpv6RARule(List<FlowEntity> flowEntries, AclInterface port,
578 List<SubnetInfo> subnets, int addOrRemove);
598 * the list of matches to be writted
599 * @param instructions
600 * the list of instruction to be written.
602 * add or remove the entries.
604 protected void addFlowEntryToList(List<FlowEntity> flowEntries, BigInteger dpId, short tableId, String flowId,
605 int priority, int idleTimeOut, int hardTimeOut, BigInteger cookie, List<? extends MatchInfoBase> matches,
606 List<InstructionInfo> instructions, int addOrRemove) {
607 List<InstructionInfo> instructionInfos = null;
608 if (addOrRemove == NwConstants.ADD_FLOW) {
609 instructionInfos = instructions;
611 FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, tableId, flowId, priority,
612 flowId, idleTimeOut, hardTimeOut, cookie, matches, instructionInfos);
613 LOG.trace("Adding flow to list: DpnId {}, flowId {}", dpId, flowId);
614 flowEntries.add(flowEntity);
617 protected void programFlows(String jobName, List<FlowEntity> flowEntries, int addOrRemove) {
618 List<List<FlowEntity>> flowEntityParts = Lists.partition(flowEntries, AclConstants.FLOWS_PER_TRANSACTION);
619 for (List<FlowEntity> part : flowEntityParts) {
620 jobCoordinator.enqueueJob(jobName,
621 () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
623 if (addOrRemove == NwConstants.ADD_FLOW) {
624 for (FlowEntity flowEntity: part) {
625 mdsalManager.addFlow(tx, flowEntity);
628 for (FlowEntity flowEntity: part) {
629 mdsalManager.removeFlow(tx, flowEntity);
632 })), AclConstants.JOB_MAX_RETRIES);
636 protected List<InstructionInfo> getDispatcherTableResubmitInstructions() {
637 return getDispatcherTableResubmitInstructions(new ArrayList<>());
641 * Gets the dispatcher table resubmit instructions based on ingress/egress service mode w.r.t switch.
643 * @param actionsInfos
645 * @return the instructions for dispatcher table resubmit
647 protected List<InstructionInfo> getDispatcherTableResubmitInstructions(List<ActionInfo> actionsInfos) {
648 short dispatcherTableId = NwConstants.LPORT_DISPATCHER_TABLE;
649 if (ServiceModeEgress.class.equals(this.serviceMode)) {
650 dispatcherTableId = NwConstants.EGRESS_LPORT_DISPATCHER_TABLE;
653 List<InstructionInfo> instructions = new ArrayList<>();
654 actionsInfos.add(new ActionNxResubmit(dispatcherTableId));
655 instructions.add(new InstructionApplyActions(actionsInfos));
659 protected void handleRemoteAclUpdate(Acl aclBefore, Acl aclAfter, Collection<AclInterface> portsBefore) {
660 String aclName = aclAfter.getAclName();
661 Collection<AclInterface> interfaceList = aclDataUtil.getInterfaceList(new Uuid(aclName));
662 if (interfaceList.isEmpty()) {
663 LOG.trace("handleRemoteAclUpdate: No interfaces found with ACL={}", aclName);
666 Set<Uuid> remoteAclsBefore = AclServiceUtils.getRemoteAclIdsByDirection(aclBefore, this.direction);
667 Set<Uuid> remoteAclsAfter = AclServiceUtils.getRemoteAclIdsByDirection(aclAfter, this.direction);
669 Set<Uuid> remoteAclsAdded = new HashSet<>(remoteAclsAfter);
670 remoteAclsAdded.removeAll(remoteAclsBefore);
672 Set<Uuid> remoteAclsDeleted = new HashSet<>(remoteAclsBefore);
673 remoteAclsDeleted.removeAll(remoteAclsAfter);
675 List<FlowEntity> addFlowEntries = new ArrayList<>();
676 List<FlowEntity> deleteFlowEntries = new ArrayList<>();
677 if (!remoteAclsAdded.isEmpty() || !remoteAclsDeleted.isEmpty()) {
678 // delete and add flows in ACL dispatcher table for all applicable
680 for (AclInterface portBefore : portsBefore) {
681 programAclDispatcherTable(deleteFlowEntries, portBefore, NwConstants.DEL_FLOW);
683 for (AclInterface port : interfaceList) {
684 programAclDispatcherTable(addFlowEntries, port, NwConstants.ADD_FLOW);
687 Set<BigInteger> dpns = interfaceList.stream().map(AclInterface::getDpId).collect(Collectors.toSet());
689 programRemoteAclTable(deleteFlowEntries, aclName, remoteAclsDeleted, dpns, NwConstants.DEL_FLOW);
690 programRemoteAclTable(addFlowEntries, aclName, remoteAclsAdded, dpns, NwConstants.ADD_FLOW);
692 programFlows(aclName, deleteFlowEntries, NwConstants.DEL_FLOW);
693 programFlows(aclName, addFlowEntries, NwConstants.ADD_FLOW);
696 private void programRemoteAclTable(List<FlowEntity> flowEntries, String aclName, Set<Uuid> remoteAclIds,
697 Set<BigInteger> dpns, int addOrRemove) {
698 for (Uuid remoteAclId : remoteAclIds) {
699 Collection<AclInterface> remoteAclInterfaces = aclDataUtil.getInterfaceList(remoteAclId);
700 if (remoteAclInterfaces.isEmpty()) {
703 Set<AllowedAddressPairs> aaps =
704 remoteAclInterfaces.stream().map(AclInterface::getAllowedAddressPairs).flatMap(List::stream)
705 .filter(AclServiceUtils::isNotIpAllNetwork).collect(Collectors.toSet());
707 Integer aclTag = aclServiceUtils.getAclTag(remoteAclId);
708 if (addOrRemove == NwConstants.ADD_FLOW) {
709 for (BigInteger dpn : dpns) {
710 for (AllowedAddressPairs aap : aaps) {
711 programRemoteAclTableFlow(flowEntries, dpn, aclTag, aap, addOrRemove);
714 } else if (addOrRemove == NwConstants.DEL_FLOW) {
715 Set<BigInteger> remoteAclDpns = new HashSet<>();
716 Map<String, Set<AclInterface>> mapAclWithPortSet =
717 aclDataUtil.getRemoteAclInterfaces(remoteAclId, this.direction);
718 if (mapAclWithPortSet != null) {
719 Map<String, Set<AclInterface>> copyOfMapAclWithPortSet = new HashMap<>(mapAclWithPortSet);
720 copyOfMapAclWithPortSet.remove(aclName);
721 remoteAclDpns = collectDpns(copyOfMapAclWithPortSet);
723 Set<BigInteger> dpnsToOperate = new HashSet<>(dpns);
724 dpnsToOperate.removeAll(remoteAclDpns);
726 "Deleting flows in Remote ACL table for remoteAclId={}, direction={}, dpnsToOperate={}, "
727 + "remoteAclDpns={}, dpns={}",
728 remoteAclId.getValue(), directionString, dpnsToOperate, remoteAclDpns, dpns);
730 for (BigInteger dpn : dpnsToOperate) {
731 for (AllowedAddressPairs aap : aaps) {
732 programRemoteAclTableFlow(flowEntries, dpn, aclTag, aap, addOrRemove);
739 private void updateRemoteAclFilterTable(List<FlowEntity> flowEntries, AclInterface port, int addOrRemove) {
740 updateRemoteAclFilterTable(flowEntries, port, port.getSecurityGroups(), port.getAllowedAddressPairs(),
744 private void updateRemoteAclFilterTable(List<FlowEntity> flowEntries, AclInterface port, List<Uuid> aclList,
745 List<AllowedAddressPairs> aaps, int addOrRemove) {
746 if (aclList == null) {
747 LOG.debug("Port {} without SGs", port.getInterfaceId());
750 String portId = port.getInterfaceId();
751 LOG.trace("updateRemoteAclFilterTable for portId={}, aclList={}, aaps={}, addOrRemove={}", portId, aclList,
753 for (Uuid aclId : aclList) {
754 if (aclDataUtil.getRemoteAcl(aclId, this.direction) != null) {
755 Integer aclTag = aclServiceUtils.getAclTag(aclId);
756 if (addOrRemove == NwConstants.ADD_FLOW) {
757 syncRemoteAclTable(flowEntries, portId, aclId, aclTag, aaps, addOrRemove);
759 else if (addOrRemove == NwConstants.DEL_FLOW) {
760 jobCoordinator.enqueueJob(aclId.getValue().intern(), () -> {
761 List<FlowEntity> remoteTableFlowEntries = new ArrayList<>();
762 syncRemoteAclTable(remoteTableFlowEntries, portId, aclId, aclTag, aaps, addOrRemove);
763 programFlows(AclConstants.ACL_JOB_KEY_PREFIX + aclId.getValue(),
764 remoteTableFlowEntries, NwConstants.DEL_FLOW);
765 return Collections.emptyList();
770 Set<Uuid> remoteAclIds = aclServiceUtils.getRemoteAclIdsByDirection(aclList, direction);
771 for (Uuid remoteAclId : remoteAclIds) {
772 syncRemoteAclTableFromOtherDpns(flowEntries, port, remoteAclId, addOrRemove);
776 private void syncRemoteAclTable(List<FlowEntity> flowEntries, String portId, Uuid acl, Integer aclTag,
777 List<AllowedAddressPairs> aaps, int addOrRemove) {
778 Map<String, Set<AclInterface>> mapAclWithPortSet = aclDataUtil.getRemoteAclInterfaces(acl, this.direction);
779 Set<BigInteger> dpns = collectDpns(mapAclWithPortSet);
780 for (AllowedAddressPairs aap : aaps) {
781 if (!AclServiceUtils.isNotIpAllNetwork(aap)) {
784 if (aclServiceUtils.skipDeleteInCaseOfOverlappingIP(portId, acl, aap.getIpAddress(),
786 LOG.debug("Skipping delete of IP={} in remote ACL table for remoteAclId={}, portId={}",
787 aap.getIpAddress(), portId, acl.getValue());
790 for (BigInteger dpId : dpns) {
791 programRemoteAclTableFlow(flowEntries, dpId, aclTag, aap, addOrRemove);
796 private void syncRemoteAclTableFromOtherDpns(List<FlowEntity> flowEntries, AclInterface port, Uuid remoteAclId,
798 Collection<AclInterface> aclInterfaces = aclDataUtil.getInterfaceList(remoteAclId);
800 if (!aclInterfaces.isEmpty() && isFirstPortInDpnWithRemoteAclId(port, remoteAclId)) {
801 Integer aclTag = aclServiceUtils.getAclTag(remoteAclId);
802 for (AclInterface aclInterface : aclInterfaces) {
803 if (port.getInterfaceId().equals(aclInterface.getInterfaceId())) {
806 for (AllowedAddressPairs aap : aclInterface.getAllowedAddressPairs()) {
807 if (AclServiceUtils.isNotIpAllNetwork(aap)) {
808 programRemoteAclTableFlow(flowEntries, port.getDpId(), aclTag, aap, addOrRemove);
815 private boolean isFirstPortInDpnWithRemoteAclId(AclInterface port, Uuid remoteAclId) {
816 String portId = port.getInterfaceId();
817 BigInteger dpId = port.getDpId();
818 Map<String, Set<AclInterface>> remoteAclInterfacesMap =
819 aclDataUtil.getRemoteAclInterfaces(remoteAclId, direction);
820 if (remoteAclInterfacesMap != null) {
821 for (Set<AclInterface> interfaceSet : remoteAclInterfacesMap.values()) {
822 for (AclInterface aclInterface : interfaceSet) {
823 if (portId.equals(aclInterface.getInterfaceId())) {
826 if (dpId.equals(aclInterface.getDpId())) {
835 protected abstract void programRemoteAclTableFlow(List<FlowEntity> flowEntries, BigInteger dpId, Integer aclTag,
836 AllowedAddressPairs aap, int addOrRemove);
838 protected Set<BigInteger> collectDpns(@Nullable Map<String, Set<AclInterface>> mapAclWithPortSet) {
839 Set<BigInteger> dpns = new HashSet<>();
840 if (mapAclWithPortSet == null) {
843 for (Set<AclInterface> innerSet : mapAclWithPortSet.values()) {
844 if (innerSet == null) {
847 for (AclInterface inter : innerSet) {
848 dpns.add(inter.getDpId());
855 * Programs the port specific fixed rules.
857 * @param flowEntries the flow entries
858 * @param dpId the dp id
859 * @param allowedAddresses the allowed addresses
860 * @param lportTag the lport tag
861 * @param portId the portId
862 * @param action the action
863 * @param write whether to add or remove the flow.
865 protected void programAclPortSpecificFixedRules(List<FlowEntity> flowEntries, BigInteger dpId,
866 List<AllowedAddressPairs> allowedAddresses, int lportTag, String portId, Action action, int write) {
867 programGotoClassifierTableRules(flowEntries, dpId, allowedAddresses, lportTag, write);
868 if (action == Action.ADD || action == Action.REMOVE) {
869 programConntrackRecircRules(flowEntries, dpId, allowedAddresses, lportTag, portId, write);
870 programPortSpecificDropRules(flowEntries, dpId, lportTag, write);
871 programAclCommitRules(flowEntries, dpId, lportTag, portId, write);
873 LOG.info("programAclPortSpecificFixedRules: flows for dpId={}, lportId={}, action={}, write={}", dpId, lportTag,
877 protected abstract void programGotoClassifierTableRules(List<FlowEntity> flowEntries, BigInteger dpId,
878 List<AllowedAddressPairs> aaps, int lportTag, int addOrRemove);
881 * Adds the rule to send the packet to the netfilter to check whether it is a known packet.
883 * @param flowEntries the flow entries
884 * @param dpId the dpId
885 * @param aaps the allowed address pairs
886 * @param lportTag the lport tag
887 * @param portId the portId
888 * @param addOrRemove whether to add or remove the flow
890 protected void programConntrackRecircRules(List<FlowEntity> flowEntries, BigInteger dpId,
891 List<AllowedAddressPairs> aaps, int lportTag, String portId, int addOrRemove) {
892 if (AclServiceUtils.doesIpv4AddressExists(aaps)) {
893 programConntrackRecircRule(flowEntries, dpId, lportTag, portId, MatchEthernetType.IPV4, addOrRemove);
895 if (AclServiceUtils.doesIpv6AddressExists(aaps)) {
896 programConntrackRecircRule(flowEntries, dpId, lportTag, portId, MatchEthernetType.IPV6, addOrRemove);
900 protected void programConntrackRecircRule(List<FlowEntity> flowEntries, BigInteger dpId, int lportTag,
901 String portId, MatchEthernetType matchEtherType, int addOrRemove) {
902 List<MatchInfoBase> matches = new ArrayList<>();
903 matches.add(matchEtherType);
904 matches.add(AclServiceUtils.buildLPortTagMatch(lportTag, serviceMode));
906 List<InstructionInfo> instructions = new ArrayList<>();
907 if (addOrRemove == NwConstants.ADD_FLOW) {
908 Long elanTag = getElanIdFromAclInterface(portId);
909 if (elanTag == null) {
910 LOG.error("ElanId not found for portId={}; Context: dpId={}, lportTag={}, addOrRemove={},", portId,
911 dpId, lportTag, addOrRemove);
914 List<ActionInfo> actionsInfos = new ArrayList<>();
915 actionsInfos.add(new ActionNxConntrack(2, 0, 0, elanTag.intValue(), getAclForExistingTrafficTable()));
916 instructions.add(new InstructionApplyActions(actionsInfos));
920 this.directionString + "_Fixed_Conntrk_" + dpId + "_" + lportTag + "_" + matchEtherType + "_Recirc";
921 addFlowEntryToList(flowEntries, dpId, getAclConntrackSenderTable(), flowName,
922 AclConstants.ACL_DEFAULT_PRIORITY, 0, 0, AclConstants.COOKIE_ACL_BASE, matches, instructions,
927 * Adds the rules to drop the unknown/invalid packets .
929 * @param flowEntries the flow entries
930 * @param dpId the dpId
931 * @param lportTag the lport tag
932 * @param addOrRemove whether to add or remove the flow
934 protected void programPortSpecificDropRules(List<FlowEntity> flowEntries, BigInteger dpId, int lportTag,
936 LOG.debug("Programming Drop Rules: DpId={}, lportTag={}, addOrRemove={}", dpId, lportTag, addOrRemove);
937 programConntrackInvalidDropRule(flowEntries, dpId, lportTag, addOrRemove);
938 programAclRuleMissDropRule(flowEntries, dpId, lportTag, addOrRemove);
942 * Adds the rule to drop the conntrack invalid packets .
944 * @param flowEntries the flow entries
945 * @param dpId the dpId
946 * @param lportTag the lport tag
947 * @param addOrRemove whether to add or remove the flow
949 protected void programConntrackInvalidDropRule(List<FlowEntity> flowEntries, BigInteger dpId, int lportTag,
951 List<MatchInfoBase> matches = AclServiceOFFlowBuilder.addLPortTagMatches(lportTag,
952 AclConstants.TRACKED_INV_CT_STATE, AclConstants.TRACKED_INV_CT_STATE_MASK, serviceMode);
953 List<InstructionInfo> instructions = AclServiceOFFlowBuilder.getDropInstructionInfo();
955 String flowId = this.directionString + "_Fixed_Conntrk_Drop" + dpId + "_" + lportTag + "_Tracked_Invalid";
956 addFlowEntryToList(flowEntries, dpId, getAclFilterCumDispatcherTable(), flowId,
957 AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY, 0, 0, AclServiceUtils.getDropFlowCookie(lportTag),
958 matches, instructions, addOrRemove);
962 * Program ACL rule miss drop rule for a port.
964 * @param flowEntries the flow entries
965 * @param dpId the dp id
966 * @param lportTag the lport tag
967 * @param addOrRemove the add or remove
969 protected void programAclRuleMissDropRule(List<FlowEntity> flowEntries, BigInteger dpId, int lportTag,
971 List<MatchInfoBase> matches = new ArrayList<>();
972 matches.add(AclServiceUtils.buildLPortTagMatch(lportTag, serviceMode));
973 List<InstructionInfo> instructions = AclServiceOFFlowBuilder.getDropInstructionInfo();
975 String flowId = this.directionString + "_Fixed_Acl_Rule_Miss_Drop_" + dpId + "_" + lportTag;
976 addFlowEntryToList(flowEntries, dpId, getAclFilterCumDispatcherTable(), flowId,
977 AclConstants.ACL_PORT_SPECIFIC_DROP_PRIORITY, 0, 0, AclServiceUtils.getDropFlowCookie(lportTag),
978 matches, instructions, addOrRemove);
982 * Program acl commit rules.
984 * @param flowEntries the flow entries
985 * @param dpId the dp id
986 * @param lportTag the lport tag
987 * @param portId the port id
988 * @param addOrRemove the add or remove
990 protected void programAclCommitRules(List<FlowEntity> flowEntries, BigInteger dpId, int lportTag, String portId,
992 programAclCommitRuleForConntrack(flowEntries, dpId, lportTag, portId, MatchEthernetType.IPV4, addOrRemove);
993 programAclCommitRuleForConntrack(flowEntries, dpId, lportTag, portId, MatchEthernetType.IPV6, addOrRemove);
994 programAclCommitRuleForNonConntrack(flowEntries, dpId, lportTag, addOrRemove);
998 * Program acl commit rule for conntrack.
1000 * @param flowEntries the flow entries
1001 * @param dpId the dp id
1002 * @param lportTag the lport tag
1003 * @param portId the port id
1004 * @param matchEtherType the match ether type
1005 * @param addOrRemove the add or remove
1007 protected void programAclCommitRuleForConntrack(List<FlowEntity> flowEntries, BigInteger dpId, int lportTag,
1008 String portId, MatchEthernetType matchEtherType, int addOrRemove) {
1009 List<MatchInfoBase> matches = new ArrayList<>();
1010 matches.add(matchEtherType);
1011 matches.addAll(AclServiceUtils.buildMatchesForLPortTagAndConntrackClassifierType(lportTag,
1012 AclConntrackClassifierType.CONNTRACK_SUPPORTED, serviceMode));
1014 List<ActionInfo> actionsInfos = new ArrayList<>();
1015 if (addOrRemove == NwConstants.ADD_FLOW) {
1016 Long elanId = getElanIdFromAclInterface(portId);
1017 if (elanId == null) {
1018 LOG.error("ElanId not found for portId={}; Context: dpId={}, lportTag={}, addOrRemove={}", portId, dpId,
1019 lportTag, addOrRemove);
1022 List<NxCtAction> ctActionsList =
1023 Lists.newArrayList(new ActionNxConntrack.NxCtMark(AclConstants.CT_MARK_EST_STATE));
1024 actionsInfos.add(new ActionNxConntrack(2, 1, 0, elanId.intValue(), (short) 255, ctActionsList));
1025 actionsInfos.add(new ActionNxCtClear());
1027 List<InstructionInfo> instructions = getDispatcherTableResubmitInstructions(actionsInfos);
1029 String flowName = directionString + "_Acl_Commit_Conntrack_" + dpId + "_" + lportTag + "_" + matchEtherType;
1030 // Flow for conntrack traffic to commit and resubmit to dispatcher
1031 addFlowEntryToList(flowEntries, dpId, getAclCommitterTable(), flowName, AclConstants.ACL_DEFAULT_PRIORITY,
1032 0, 0, AclConstants.COOKIE_ACL_BASE, matches, instructions, addOrRemove);
1036 * Program acl commit rule for non conntrack.
1038 * @param flowEntries the flow entries
1039 * @param dpId the dp id
1040 * @param lportTag the lport tag
1041 * @param addOrRemove the add or remove
1043 protected void programAclCommitRuleForNonConntrack(List<FlowEntity> flowEntries, BigInteger dpId, int lportTag,
1045 List<MatchInfoBase> matches = new ArrayList<>();
1046 matches.addAll(AclServiceUtils.buildMatchesForLPortTagAndConntrackClassifierType(lportTag,
1047 AclConntrackClassifierType.NON_CONNTRACK_SUPPORTED, serviceMode));
1049 List<InstructionInfo> instructions = getDispatcherTableResubmitInstructions();
1050 String flowName = this.directionString + "_Acl_Commit_Non_Conntrack_" + dpId + "_" + lportTag;
1051 // Flow for non-conntrack traffic to resubmit to dispatcher
1052 addFlowEntryToList(flowEntries, dpId, getAclCommitterTable(), flowName, AclConstants.ACL_DEFAULT_PRIORITY,
1053 0, 0, AclConstants.COOKIE_ACL_BASE, matches, instructions, addOrRemove);
1057 protected Long getElanIdFromAclInterface(String elanInterfaceName) {
1058 AclInterface aclInterface = aclInterfaceCache.get(elanInterfaceName);
1059 if (null != aclInterface) {
1060 return aclInterface.getElanId();
1065 protected abstract boolean isValidDirection(Class<? extends DirectionBase> direction);
1067 protected abstract short getAclConntrackSenderTable();
1069 protected abstract short getAclForExistingTrafficTable();
1071 protected abstract short getAclFilterCumDispatcherTable();
1073 protected abstract short getAclRuleBasedFilterTable();
1075 protected abstract short getAclRemoteAclTable();
1077 protected abstract short getAclCommitterTable();