5a2289378989615e421761fd18cbfcc0dee126f3
[netvirt.git] / vpnservice / aclservice / impl / src / main / java / org / opendaylight / netvirt / aclservice / AbstractEgressAclServiceImpl.java
1 /*
2  * Copyright (c) 2016 HPE, Inc. and others. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.aclservice;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.math.BigInteger;
12 import java.util.ArrayList;
13 import java.util.Collections;
14 import java.util.List;
15 import java.util.Map;
16 import java.util.Set;
17 import java.util.stream.Collectors;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator;
22 import org.opendaylight.genius.mdsalutil.ActionInfo;
23 import org.opendaylight.genius.mdsalutil.InstructionInfo;
24 import org.opendaylight.genius.mdsalutil.MDSALUtil;
25 import org.opendaylight.genius.mdsalutil.MatchInfoBase;
26 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
27 import org.opendaylight.genius.mdsalutil.NwConstants;
28 import org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable;
29 import org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata;
30 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
31 import org.opendaylight.genius.mdsalutil.matches.MatchArpSha;
32 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType;
33 import org.opendaylight.genius.utils.ServiceIndex;
34 import org.opendaylight.netvirt.aclservice.api.AclServiceManager.Action;
35 import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
36 import org.opendaylight.netvirt.aclservice.utils.AclConstants;
37 import org.opendaylight.netvirt.aclservice.utils.AclDataUtil;
38 import org.opendaylight.netvirt.aclservice.utils.AclServiceOFFlowBuilder;
39 import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.AccessListEntries;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace;
43 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;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.actions.PacketHandling;
45 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.AceType;
46 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;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeEgress;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeIngress;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionEgress;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.SecurityRuleAttr;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs;
56 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
57 import org.slf4j.Logger;
58 import org.slf4j.LoggerFactory;
59
60 /**
61  * Provides abstract implementation for egress (w.r.t VM) ACL service.
62  *
63  * <p>
64  * Note: Table names used are w.r.t switch. Hence, switch ingress is VM egress
65  * and vice versa.
66  */
67 public abstract class AbstractEgressAclServiceImpl extends AbstractAclServiceImpl {
68
69     private static final Logger LOG = LoggerFactory.getLogger(AbstractEgressAclServiceImpl.class);
70
71     /**
72      * Initialize the member variables.
73      *
74      * @param dataBroker the data broker instance.
75      * @param mdsalManager the mdsal manager instance.
76      * @param aclDataUtil
77      *            the acl data util.
78      * @param aclServiceUtils
79      *            the acl service util.
80      */
81     public AbstractEgressAclServiceImpl(DataBroker dataBroker, IMdsalApiManager mdsalManager, AclDataUtil aclDataUtil,
82             AclServiceUtils aclServiceUtils) {
83         // Service mode is w.rt. switch
84         super(ServiceModeIngress.class, dataBroker, mdsalManager, aclDataUtil, aclServiceUtils);
85     }
86
87     /**
88      * Bind service.
89      *
90      * @param interfaceName the interface name
91      */
92     @Override
93     public void bindService(String interfaceName, Long vpnId) {
94         int instructionKey = 0;
95         List<Instruction> instructions = new ArrayList<>();
96         if (vpnId != null) {
97             instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(MetaDataUtil.getVpnIdMetadata(vpnId),
98                     MetaDataUtil.METADATA_MASK_VRFID, ++instructionKey));
99         } else {
100             Long elanTag = AclServiceUtils.getElanIdFromInterface(interfaceName, dataBroker);
101             instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(MetaDataUtil.getElanTagMetadata(elanTag),
102                     MetaDataUtil.METADATA_MASK_SERVICE, ++instructionKey));
103         }
104         instructions.add(MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.INGRESS_ACL_TABLE, ++instructionKey));
105         short serviceIndex = ServiceIndex.getIndex(NwConstants.ACL_SERVICE_NAME, NwConstants.ACL_SERVICE_INDEX);
106         int flowPriority = AclConstants.EGRESS_ACL_DEFAULT_FLOW_PRIORITY;
107         BoundServices serviceInfo =
108                 AclServiceUtils.getBoundServices(String.format("%s.%s.%s", "acl", "egressacl", interfaceName),
109                 serviceIndex, flowPriority, AclConstants.COOKIE_ACL_BASE, instructions);
110         InstanceIdentifier<BoundServices> path =
111                 AclServiceUtils.buildServiceId(interfaceName, serviceIndex, ServiceModeIngress.class);
112
113         DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
114         dataStoreCoordinator.enqueueJob(interfaceName,
115             () -> {
116                 WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
117                 writeTxn.put(LogicalDatastoreType.CONFIGURATION, path, serviceInfo, true);
118
119                 List<ListenableFuture<Void>> futures = new ArrayList<>();
120                 futures.add(writeTxn.submit());
121                 return futures;
122             });
123     }
124
125     /**
126      * Unbind service.
127      *
128      * @param interfaceName the interface name
129      */
130     @Override
131     protected void unbindService(String interfaceName) {
132         InstanceIdentifier<BoundServices> path =
133                 AclServiceUtils.buildServiceId(interfaceName,
134                         ServiceIndex.getIndex(NwConstants.ACL_SERVICE_NAME, NwConstants.ACL_SERVICE_INDEX),
135                         ServiceModeIngress.class);
136
137         DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
138         dataStoreCoordinator.enqueueJob(interfaceName,
139             () -> {
140                 WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
141                 writeTxn.delete(LogicalDatastoreType.CONFIGURATION, path);
142
143                 List<ListenableFuture<Void>> futures = new ArrayList<>();
144                 futures.add(writeTxn.submit());
145                 return futures;
146             });
147     }
148
149     @Override
150     protected void programGeneralFixedRules(BigInteger dpid, String dhcpMacAddress,
151             List<AllowedAddressPairs> allowedAddresses, int lportTag, Action action, int addOrRemove) {
152         LOG.info("programFixedRules :  adding default rules.");
153
154         if (action == Action.ADD || action == Action.REMOVE) {
155             egressAclDhcpAllowClientTraffic(dpid, dhcpMacAddress, lportTag, addOrRemove);
156             egressAclDhcpv6AllowClientTraffic(dpid, dhcpMacAddress, lportTag, addOrRemove);
157             egressAclDhcpDropServerTraffic(dpid, dhcpMacAddress, lportTag, addOrRemove);
158             egressAclDhcpv6DropServerTraffic(dpid, dhcpMacAddress, lportTag, addOrRemove);
159             egressAclIcmpv6DropRouterAdvts(dpid, lportTag, addOrRemove);
160             egressAclIcmpv6AllowedList(dpid, lportTag, addOrRemove);
161
162             programArpRule(dpid, allowedAddresses, lportTag, addOrRemove);
163         }
164     }
165
166     @Override
167     protected void updateArpForAllowedAddressPairs(BigInteger dpId, int lportTag, List<AllowedAddressPairs> deletedAAP,
168             List<AllowedAddressPairs> addedAAP) {
169         Set<MacAddress> deletedAAPmacs =
170                 deletedAAP.stream().map(aap -> aap.getMacAddress()).collect(Collectors.toSet());
171         Set<MacAddress> addedAAPmacs = addedAAP.stream().map(aap -> aap.getMacAddress()).collect(Collectors.toSet());
172
173         // Remove common macs to avoid delete and add of ARP flows having same MAC.
174         deletedAAPmacs.removeAll(addedAAPmacs);
175
176         programArpRule(dpId, deletedAAPmacs, lportTag, NwConstants.DEL_FLOW);
177         programArpRule(dpId, addedAAPmacs, lportTag, NwConstants.ADD_FLOW);
178     }
179
180     @Override
181     protected boolean programAclRules(List<Uuid> aclUuidList, BigInteger dpId, int lportTag, int addOrRemove, String
182             portId) {
183         LOG.trace("Applying custom rules DpId {}, lportTag {}", dpId, lportTag);
184         if (aclUuidList == null || dpId == null) {
185             LOG.warn("one of the egress acl parameters can not be null. sg {}, dpId {}",
186                     aclUuidList, dpId);
187             return false;
188         }
189         for (Uuid sgUuid :aclUuidList) {
190             Acl acl = AclServiceUtils.getAcl(dataBroker, sgUuid.getValue());
191             if (null == acl) {
192                 LOG.warn("The ACL is empty");
193                 continue;
194             }
195             AccessListEntries accessListEntries = acl.getAccessListEntries();
196             List<Ace> aceList = accessListEntries.getAce();
197             for (Ace ace: aceList) {
198                 programAceRule(dpId, lportTag, addOrRemove, acl.getAclName(), ace, portId, null);
199             }
200         }
201         return true;
202     }
203
204     @Override
205     protected void programAceRule(BigInteger dpId, int lportTag, int addOrRemove, String aclName, Ace ace,
206             String portId, List<AllowedAddressPairs> syncAllowedAddresses) {
207         SecurityRuleAttr aceAttr = AclServiceUtils.getAccesssListAttributes(ace);
208         if (!aceAttr.getDirection().equals(DirectionEgress.class)) {
209             return;
210         }
211         Matches matches = ace.getMatches();
212         AceType aceType = matches.getAceType();
213         Map<String,List<MatchInfoBase>> flowMap = null;
214         if (aceType instanceof AceIp) {
215             flowMap = AclServiceOFFlowBuilder.programIpFlow(matches);
216             if (aceAttr.getRemoteGroupId() != null) {
217                 flowMap = aclServiceUtils.getFlowForRemoteAcl(aceAttr.getRemoteGroupId(), portId, flowMap, false);
218             } else if (syncAllowedAddresses != null) {
219                 flowMap = AclServiceUtils.getFlowForAllowedAddresses(syncAllowedAddresses, flowMap, false);
220             }
221         }
222         if (null == flowMap) {
223             LOG.error("Failed to apply ACL {} lportTag {}", ace.getKey(), lportTag);
224             return;
225         }
226         for (String flowName : flowMap.keySet()) {
227             syncSpecificAclFlow(dpId, lportTag, addOrRemove, ace, portId, flowMap, flowName);
228         }
229     }
230
231     @Override
232     protected void writeCurrentAclForRemoteAcls(Uuid acl, int addOrRemove, Long elanTag, AllowedAddressPairs ip,
233             BigInteger aclId, Long vpnId) {
234         List<MatchInfoBase> flowMatches = new ArrayList<>();
235         flowMatches.addAll(AclServiceUtils.buildIpAndDstServiceMatch(elanTag, ip, dataBroker, vpnId));
236
237         List<InstructionInfo> instructions = new ArrayList<>();
238
239         InstructionWriteMetadata writeMetatdata =
240                 new InstructionWriteMetadata(AclServiceUtils.getAclIdMetadata(aclId),
241                         MetaDataUtil.METADATA_MASK_REMOTE_ACL_ID);
242         instructions.add(writeMetatdata);
243         instructions.add(new InstructionGotoTable(getEgressAclFilterTable()));
244
245         Long serviceTag = vpnId != null ? vpnId : elanTag;
246         String flowNameAdded = "Acl_Filter_Egress_" + new String(ip.getIpAddress().getValue()) + "_" + serviceTag;
247
248         Map<String, Set<AclInterface>> mapAclWithPortSet = aclDataUtil.getAllRemoteAclInterfaces();
249         Set<BigInteger> dpns = collectDpns(mapAclWithPortSet);
250         for (BigInteger dpId : dpns) {
251             LOG.debug("writing rule for ip {} and rlanId {} in egress acl remote table {}", getIpPrefixOrAddress(ip),
252                     elanTag, getEgressAclRemoteAclTable());
253             syncFlow(dpId, getEgressAclRemoteAclTable(), flowNameAdded, AclConstants.NO_PRIORITY, "ACL", 0, 0,
254                     AclConstants.COOKIE_ACL_BASE, flowMatches, instructions, addOrRemove);
255         }
256     }
257
258     protected short getEgressAclFilterTable() {
259         return NwConstants.INGRESS_ACL_FILTER_TABLE;
260     }
261
262     protected short getEgressAclRemoteAclTable() {
263         return NwConstants.INGRESS_ACL_REMOTE_ACL_TABLE;
264     }
265
266     @Override
267     protected void writeRemoteAclForCurrentAclForInterface(BigInteger dpId, int addOrRemove, AclInterface inter,
268             BigInteger aclId, Long elanTag, Long vpnId) {
269         for (AllowedAddressPairs ip : inter.getAllowedAddressPairs()) {
270             if (!AclServiceUtils.isNotIpv4AllNetwork(ip)) {
271                 continue;
272             }
273             List<MatchInfoBase> flowMatches = new ArrayList<>();
274             flowMatches.addAll(AclServiceUtils.buildIpAndDstServiceMatch(elanTag, ip, dataBroker, vpnId));
275
276             List<InstructionInfo> instructions = new ArrayList<>();
277
278             InstructionWriteMetadata writeMetatdata =
279                     new InstructionWriteMetadata(AclServiceUtils.getAclIdMetadata(aclId),
280                             MetaDataUtil.METADATA_MASK_REMOTE_ACL_ID);
281             instructions.add(writeMetatdata);
282             instructions.add(new InstructionGotoTable(getEgressAclFilterTable()));
283
284             Long serviceTag = vpnId != null ? vpnId : elanTag;
285             String flowNameAdded =
286                     "Acl_Filter_Egress_" + new String(ip.getIpAddress().getValue()) + "_" + serviceTag;
287
288             LOG.debug("writing rule for ip {} and elanId {} in egress acl remote table {}",
289                     getIpPrefixOrAddress(ip), elanTag, getEgressAclRemoteAclTable());
290             syncFlow(dpId, getEgressAclRemoteAclTable(), flowNameAdded, AclConstants.NO_PRIORITY, "ACL", 0,
291                     0, AclConstants.COOKIE_ACL_BASE, flowMatches, instructions, addOrRemove);
292         }
293     }
294
295     protected abstract String syncSpecificAclFlow(BigInteger dpId, int lportTag, int addOrRemove, Ace ace,
296             String portId, Map<String, List<MatchInfoBase>> flowMap, String flowName);
297
298     /**
299      * Anti-spoofing rule to block the Ipv4 DHCP server traffic from the port.
300      *
301      * @param dpId the dpId
302      * @param dhcpMacAddress the Dhcp mac address
303      * @param lportTag the lport tag
304      * @param addOrRemove add/remove the flow.
305      */
306     protected void egressAclDhcpDropServerTraffic(BigInteger dpId, String dhcpMacAddress, int lportTag,
307             int addOrRemove) {
308         List<MatchInfoBase> matches = AclServiceUtils.buildDhcpMatches(AclConstants.DHCP_SERVER_PORT_IPV4,
309                 AclConstants.DHCP_CLIENT_PORT_IPV4, lportTag, ServiceModeEgress.class);
310
311         String flowName = "Egress_DHCP_Server_v4" + dpId + "_" + lportTag + "_" + dhcpMacAddress + "_Drop_";
312         syncFlow(dpId, NwConstants.INGRESS_ACL_TABLE, flowName,
313                 AclConstants.PROTO_DHCP_CLIENT_TRAFFIC_MATCH_PRIORITY, "ACL", 0,
314                 0, AclConstants.COOKIE_ACL_BASE, matches, Collections.emptyList(), addOrRemove);
315     }
316
317     /**
318      * Anti-spoofing rule to block the Ipv6 DHCP server traffic from the port.
319      *
320      * @param dpId the dpId
321      * @param dhcpMacAddress the Dhcp mac address
322      * @param lportTag the lport tag
323      * @param addOrRemove add/remove the flow.
324      */
325     protected void egressAclDhcpv6DropServerTraffic(BigInteger dpId, String dhcpMacAddress, int lportTag,
326             int addOrRemove) {
327         List<MatchInfoBase> matches = AclServiceUtils.buildDhcpV6Matches(AclConstants.DHCP_SERVER_PORT_IPV6,
328                 AclConstants.DHCP_CLIENT_PORT_IPV6, lportTag, ServiceModeEgress.class);
329
330         String flowName = "Egress_DHCP_Server_v6" + "_" + dpId + "_" + lportTag + "_" + dhcpMacAddress + "_Drop_";
331         syncFlow(dpId, NwConstants.INGRESS_ACL_TABLE, flowName,
332                 AclConstants.PROTO_DHCP_CLIENT_TRAFFIC_MATCH_PRIORITY, "ACL", 0,
333                 0, AclConstants.COOKIE_ACL_BASE, matches, Collections.emptyList(), addOrRemove);
334     }
335
336     /**
337      * Anti-spoofing rule to block the Ipv6 Router Advts from the VM port.
338      *
339      * @param dpId the dpId
340      * @param lportTag the lport tag
341      * @param addOrRemove add/remove the flow.
342      */
343     private void egressAclIcmpv6DropRouterAdvts(BigInteger dpId, int lportTag, int addOrRemove) {
344         List<MatchInfoBase> matches = AclServiceUtils.buildIcmpV6Matches(AclConstants.ICMPV6_TYPE_RA, 0, lportTag,
345                 ServiceModeEgress.class);
346
347         String flowName = "Egress_ICMPv6" + "_" + dpId + "_" + lportTag + "_" + AclConstants.ICMPV6_TYPE_RA + "_Drop_";
348         syncFlow(dpId, NwConstants.INGRESS_ACL_TABLE, flowName, AclConstants.PROTO_IPV6_DROP_PRIORITY, "ACL", 0,
349                 0, AclConstants.COOKIE_ACL_BASE, matches, Collections.emptyList(), addOrRemove);
350     }
351
352     /**
353      * Add rule to allow certain ICMPv6 traffic from VM ports.
354      *
355      * @param dpId the dpId
356      * @param lportTag the lport tag
357      * @param addOrRemove add/remove the flow.
358      */
359     private void egressAclIcmpv6AllowedList(BigInteger dpId, int lportTag, int addOrRemove) {
360         List<ActionInfo> actionsInfos = new ArrayList<>();
361         List<InstructionInfo> instructions = getDispatcherTableResubmitInstructions(actionsInfos);
362
363         for (Integer icmpv6Type: AclConstants.allowedIcmpv6NdList()) {
364             List<MatchInfoBase> matches = AclServiceUtils.buildIcmpV6Matches(icmpv6Type, 0, lportTag,
365                     ServiceModeEgress.class);
366             String flowName = "Egress_ICMPv6" + "_" + dpId + "_" + lportTag + "_" + icmpv6Type + "_Permit_";
367             syncFlow(dpId, NwConstants.INGRESS_ACL_TABLE, flowName, AclConstants.PROTO_IPV6_ALLOWED_PRIORITY,
368                     "ACL", 0, 0, AclConstants.COOKIE_ACL_BASE, matches, instructions, addOrRemove);
369         }
370     }
371
372     /**
373      * Add rule to ensure only DHCP server traffic from the specified mac is
374      * allowed.
375      *
376      * @param dpId the dpid
377      * @param dhcpMacAddress the DHCP server mac address
378      * @param lportTag the lport tag
379      * @param addOrRemove whether to add or remove the flow
380      */
381     private void egressAclDhcpAllowClientTraffic(BigInteger dpId, String dhcpMacAddress, int lportTag,
382             int addOrRemove) {
383         final List<MatchInfoBase> matches = AclServiceUtils.buildDhcpMatches(AclConstants.DHCP_CLIENT_PORT_IPV4,
384                 AclConstants.DHCP_SERVER_PORT_IPV4, lportTag, ServiceModeEgress.class);
385
386         List<ActionInfo> actionsInfos = new ArrayList<>();
387         List<InstructionInfo> instructions = getDispatcherTableResubmitInstructions(actionsInfos);
388
389         String flowName = "Egress_DHCP_Client_v4" + dpId + "_" + lportTag + "_" + dhcpMacAddress + "_Permit_";
390         syncFlow(dpId, NwConstants.INGRESS_ACL_TABLE, flowName, AclConstants.PROTO_DHCP_CLIENT_TRAFFIC_MATCH_PRIORITY,
391             "ACL", 0, 0, AclConstants.COOKIE_ACL_BASE, matches, instructions, addOrRemove);
392     }
393
394     /**
395      * Add rule to ensure only DHCPv6 server traffic from the specified mac is
396      * allowed.
397      *
398      * @param dpId the dpid
399      * @param dhcpMacAddress the DHCP server mac address
400      * @param lportTag the lport tag
401      * @param addOrRemove whether to add or remove the flow
402      */
403     private void egressAclDhcpv6AllowClientTraffic(BigInteger dpId, String dhcpMacAddress, int lportTag,
404             int addOrRemove) {
405         final List<MatchInfoBase> matches = AclServiceUtils.buildDhcpV6Matches(AclConstants.DHCP_CLIENT_PORT_IPV6,
406                 AclConstants.DHCP_SERVER_PORT_IPV6, lportTag, ServiceModeEgress.class);
407
408         List<ActionInfo> actionsInfos = new ArrayList<>();
409         List<InstructionInfo> instructions = getDispatcherTableResubmitInstructions(actionsInfos);
410
411         String flowName = "Egress_DHCP_Client_v6" + "_" + dpId + "_" + lportTag + "_" + dhcpMacAddress + "_Permit_";
412         syncFlow(dpId, NwConstants.INGRESS_ACL_TABLE, flowName, AclConstants.PROTO_DHCP_CLIENT_TRAFFIC_MATCH_PRIORITY,
413             "ACL", 0, 0, AclConstants.COOKIE_ACL_BASE, matches, instructions, addOrRemove);
414     }
415
416     /**
417      * Program arp rule.
418      *
419      * @param dpId the dp id
420      * @param allowedAddresses the allowed addresses
421      * @param lportTag the lport tag
422      * @param addOrRemove whether to add or remove the flow
423      */
424     protected void programArpRule(BigInteger dpId, List<AllowedAddressPairs> allowedAddresses, int lportTag,
425             int addOrRemove) {
426         // Collecting macs as a set to avoid duplicate
427         Set<MacAddress> macs = allowedAddresses.stream().map(aap -> aap.getMacAddress()).collect(Collectors.toSet());
428         programArpRule(dpId, macs, lportTag, addOrRemove);
429     }
430
431     /**
432      * Adds the rule to allow arp packets.
433      *
434      * @param dpId the dpId
435      * @param macs the set of MACs
436      * @param lportTag the lport tag
437      * @param addOrRemove whether to add or remove the flow
438      */
439     protected void programArpRule(BigInteger dpId, Set<MacAddress> macs, int lportTag, int addOrRemove) {
440         for (MacAddress mac : macs) {
441             List<MatchInfoBase> matches = new ArrayList<>();
442             matches.add(MatchEthernetType.ARP);
443             matches.add(new MatchArpSha(mac));
444             matches.add(buildLPortTagMatch(lportTag));
445
446             List<InstructionInfo> instructions = getDispatcherTableResubmitInstructions(new ArrayList<>());
447
448             String flowName = "Egress_ARP_" + dpId + "_" + lportTag + "_" + mac.getValue();
449             syncFlow(dpId, NwConstants.INGRESS_ACL_TABLE, flowName,
450                     AclConstants.PROTO_ARP_TRAFFIC_MATCH_PRIORITY, "ACL", 0, 0,
451                     AclConstants.COOKIE_ACL_BASE, matches, instructions, addOrRemove);
452         }
453     }
454
455     protected MatchInfoBase buildLPortTagMatch(int lportTag) {
456         return AclServiceUtils.buildLPortTagMatch(lportTag, ServiceModeEgress.class);
457     }
458
459     protected int getEgressSpecificAclFlowPriority(BigInteger dpId, int addOrRemove, String flowName,
460                                                  PacketHandling packetHandling) {
461         int priority;
462         if (addOrRemove == NwConstants.DEL_FLOW) {
463             priority = aclServiceUtils.releaseAndRemoveFlowPriorityFromCache(dpId, NwConstants.INGRESS_ACL_FILTER_TABLE,
464                     flowName, packetHandling);
465         } else {
466             priority = aclServiceUtils.allocateAndSaveFlowPriorityInCache(dpId, NwConstants.INGRESS_ACL_FILTER_TABLE,
467                     flowName, packetHandling);
468         }
469         return priority;
470     }
471 }