import com.google.common.util.concurrent.ListenableFuture;
import java.math.BigInteger;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.AccessListEntries;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace;
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;
-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;
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;
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;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeIngress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionIngress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.SecurityRuleAttr;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
* Bind service.
*
- * @param interfaceName the interface name
+ * @param aclInterface the acl interface
*/
@Override
- protected void bindService(String interfaceName) {
- int flowPriority = AclConstants.INGRESS_ACL_DEFAULT_FLOW_PRIORITY;
-
- int instructionKey = 0;
- List<Instruction> instructions = new ArrayList<>();
- Long elanTag = AclServiceUtils.getElanIdFromInterface(interfaceName, dataBroker);
- instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(MetaDataUtil.getElanTagMetadata(elanTag),
- MetaDataUtil.METADATA_MASK_SERVICE, ++instructionKey));
- instructions.add(MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.EGRESS_ACL_TABLE, ++instructionKey));
- BoundServices serviceInfo = AclServiceUtils.getBoundServices(
- String.format("%s.%s.%s", "acl", "ingressacl", interfaceName),
- ServiceIndex.getIndex(NwConstants.EGRESS_ACL_SERVICE_NAME, NwConstants.EGRESS_ACL_SERVICE_INDEX),
- flowPriority, AclConstants.COOKIE_ACL_BASE, instructions);
- InstanceIdentifier<BoundServices> path = AclServiceUtils.buildServiceId(interfaceName,
- ServiceIndex.getIndex(NwConstants.EGRESS_ACL_SERVICE_NAME,
- NwConstants.EGRESS_ACL_SERVICE_INDEX), ServiceModeEgress.class);
-
+ public void bindService(AclInterface aclInterface) {
+ String interfaceName = aclInterface.getInterfaceId();
DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
dataStoreCoordinator.enqueueJob(interfaceName,
() -> {
+ int instructionKey = 0;
+ List<Instruction> instructions = new ArrayList<>();
+ Long vpnId = aclInterface.getVpnId();
+ if (vpnId != null) {
+ instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(MetaDataUtil.getVpnIdMetadata(vpnId),
+ MetaDataUtil.METADATA_MASK_VRFID, ++instructionKey));
+ LOG.debug("Binding ACL service for interface {} with vpnId {}", interfaceName, vpnId);
+ } else {
+ Long elanTag = aclInterface.getElanId();
+ instructions.add(
+ MDSALUtil.buildAndGetWriteMetadaInstruction(MetaDataUtil.getElanTagMetadata(elanTag),
+ MetaDataUtil.METADATA_MASK_SERVICE, ++instructionKey));
+ LOG.debug("Binding ACL service for interface {} with ElanTag {}", interfaceName, elanTag);
+ }
+ instructions.add(
+ MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.EGRESS_ACL_TABLE, ++instructionKey));
+ int flowPriority = AclConstants.INGRESS_ACL_DEFAULT_FLOW_PRIORITY;
+ short serviceIndex = ServiceIndex.getIndex(NwConstants.EGRESS_ACL_SERVICE_NAME,
+ NwConstants.EGRESS_ACL_SERVICE_INDEX);
+ BoundServices serviceInfo = AclServiceUtils.getBoundServices(
+ String.format("%s.%s.%s", "acl", "ingressacl", interfaceName), serviceIndex, flowPriority,
+ AclConstants.COOKIE_ACL_BASE, instructions);
+ InstanceIdentifier<BoundServices> path = AclServiceUtils.buildServiceId(interfaceName,
+ ServiceIndex.getIndex(NwConstants.EGRESS_ACL_SERVICE_NAME,
+ NwConstants.EGRESS_ACL_SERVICE_INDEX), ServiceModeEgress.class);
+
WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
- writeTxn.put(LogicalDatastoreType.CONFIGURATION, path, serviceInfo, true);
+ writeTxn.put(LogicalDatastoreType.CONFIGURATION, path, serviceInfo,
+ WriteTransaction.CREATE_MISSING_PARENTS);
- List<ListenableFuture<Void>> futures = new ArrayList<>();
- futures.add(writeTxn.submit());
- return futures;
+ return Collections.singletonList(writeTxn.submit());
});
}
/**
* Unbind service.
*
- * @param interfaceName the interface name
+ * @param aclInterface the acl interface
*/
@Override
- protected void unbindService(String interfaceName) {
+ protected void unbindService(AclInterface aclInterface) {
+ String interfaceName = aclInterface.getInterfaceId();
InstanceIdentifier<BoundServices> path = AclServiceUtils.buildServiceId(interfaceName,
ServiceIndex.getIndex(NwConstants.EGRESS_ACL_SERVICE_NAME, NwConstants.EGRESS_ACL_SERVICE_INDEX),
ServiceModeEgress.class);
DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
+ LOG.debug("UnBinding ACL service for interface {}", interfaceName);
dataStoreCoordinator.enqueueJob(interfaceName,
() -> {
WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
List<AllowedAddressPairs> allowedAddresses, int lportTag, String portId, Action action, int addOrRemove);
@Override
- protected void programGeneralFixedRules(BigInteger dpid, String dhcpMacAddress,
- List<AllowedAddressPairs> allowedAddresses, int lportTag, Action action, int addOrRemove) {
+ protected void programGeneralFixedRules(AclInterface port, String dhcpMacAddress,
+ List<AllowedAddressPairs> allowedAddresses, Action action, int addOrRemove) {
LOG.info("programFixedRules : {} default rules.", action == Action.ADD ? "adding" : "removing");
+ BigInteger dpid = port.getDpId();
+ int lportTag = port.getLPortTag();
if (action == Action.ADD || action == Action.REMOVE) {
ingressAclDhcpAllowServerTraffic(dpid, dhcpMacAddress, lportTag, addOrRemove,
AclConstants.PROTO_PREFIX_MATCH_PRIORITY);
ingressAclIcmpv6AllowedTraffic(dpid, lportTag, addOrRemove);
programArpRule(dpid, lportTag, addOrRemove);
+ programIpv4BroadcastRule(port, addOrRemove);
}
}
}
@Override
- protected boolean programAclRules(List<Uuid> aclUuidList, BigInteger dpId, int lportTag, int addOrRemove, String
- portId) {
+ protected boolean programAclRules(AclInterface port, List<Uuid> aclUuidList,int addOrRemove) {
+ BigInteger dpId = port.getDpId();
+ LOG.debug("Applying custom rules on DpId {}, lportTag {}", dpId, port.getLPortTag());
if (aclUuidList == null || dpId == null) {
LOG.warn("one of the ingress acl parameters can not be null. sg {}, dpId {}",
aclUuidList, dpId);
AccessListEntries accessListEntries = acl.getAccessListEntries();
List<Ace> aceList = accessListEntries.getAce();
for (Ace ace : aceList) {
- programAceRule(dpId, lportTag, addOrRemove, acl.getAclName(), ace, portId, null);
+ programAceRule(port, addOrRemove, acl.getAclName(), ace, null);
}
}
return true;
}
@Override
- protected void programAceRule(BigInteger dpId, int lportTag, int addOrRemove, String aclName, Ace ace,
- String portId, List<AllowedAddressPairs> syncAllowedAddresses) {
+ protected void programAceRule(AclInterface port, int addOrRemove, String aclName, Ace ace,
+ List<AllowedAddressPairs> syncAllowedAddresses) {
SecurityRuleAttr aceAttr = AclServiceUtils.getAccesssListAttributes(ace);
if (!aceAttr.getDirection().equals(DirectionIngress.class)) {
return;
Map<String, List<MatchInfoBase>> flowMap = null;
if (aceType instanceof AceIp) {
flowMap = AclServiceOFFlowBuilder.programIpFlow(matches);
- if (aceAttr.getRemoteGroupId() != null) {
- flowMap = aclServiceUtils.getFlowForRemoteAcl(aceAttr.getRemoteGroupId(), portId, flowMap, true);
- } else if (syncAllowedAddresses != null) {
+ if (syncAllowedAddresses != null) {
flowMap = AclServiceUtils.getFlowForAllowedAddresses(syncAllowedAddresses, flowMap, true);
+ } else if (aceAttr.getRemoteGroupId() != null) {
+ flowMap = aclServiceUtils.getFlowForRemoteAcl(port, aceAttr.getRemoteGroupId(), port.getInterfaceId(),
+ flowMap, true);
}
}
+ int lportTag = port.getLPortTag();
if (null == flowMap) {
LOG.error("Failed to apply ACL {} lportTag {}", ace.getKey(), lportTag);
return;
}
for (String flowName : flowMap.keySet()) {
- syncSpecificAclFlow(dpId, lportTag, addOrRemove, ace, portId, flowMap, flowName);
+ syncSpecificAclFlow(port.getDpId(), lportTag, addOrRemove, ace, port.getInterfaceId(), flowMap, flowName);
}
}
@Override
- protected void writeCurrentAclForRemoteAcls(Uuid acl, int addOrRemove, Long elanTag, AllowedAddressPairs ip,
- BigInteger aclId) {
+ protected void updateRemoteAclTableForPort(AclInterface port, Uuid acl, int addOrRemove,
+ AllowedAddressPairs ip, BigInteger aclId, BigInteger dpId) {
+ Long elanTag = port.getElanId();
+ Long vpnId = port.getVpnId();
List<MatchInfoBase> flowMatches = new ArrayList<>();
- flowMatches.addAll(AclServiceUtils.buildIpAndElanSrcMatch(elanTag, ip, dataBroker));
+ flowMatches.addAll(AclServiceUtils.buildIpAndSrcServiceMatch(elanTag, ip, dataBroker, vpnId));
List<InstructionInfo> instructions = new ArrayList<>();
instructions.add(writeMetatdata);
instructions.add(new InstructionGotoTable(getIngressAclFilterTable()));
- String flowNameAdded = "Acl_Filter_Ingress_" + new String(ip.getIpAddress().getValue()) + "_" + elanTag;
- LOG.warn((addOrRemove == 0 ? "ADD" : "REMOVE") + flowNameAdded);
+ Long serviceTag = vpnId != null ? vpnId : elanTag;
+ String flowNameAdded = "Acl_Filter_Ingress_" + new String(ip.getIpAddress().getValue()) + "_" + serviceTag;
- Map<String, Set<AclInterface>> mapAclWithPortSet = aclDataUtil.getAllRemoteAclInterfaces();
- Set<BigInteger> dpns = collectDpns(mapAclWithPortSet);
- for (BigInteger dpId : dpns) {
- LOG.debug("writing rule for ip {} and rlanId {} in ingress acl remote table {}", getIpPrefixOrAddress(ip),
- elanTag, getIngressAclRemoteAclTable());
- syncFlow(dpId, getIngressAclRemoteAclTable(), flowNameAdded, AclConstants.NO_PRIORITY, "ACL", 0, 0,
- AclConstants.COOKIE_ACL_BASE, flowMatches, instructions, addOrRemove);
- }
+ syncFlow(dpId, getIngressAclRemoteAclTable(), flowNameAdded, AclConstants.NO_PRIORITY, "ACL", 0, 0,
+ AclConstants.COOKIE_ACL_BASE, flowMatches, instructions, addOrRemove);
}
protected short getIngressAclFilterTable() {
return NwConstants.EGRESS_ACL_REMOTE_ACL_TABLE;
}
- @Override
- protected void writeRemoteAclForCurrentAclForInterface(BigInteger dpId, int addOrRemove, AclInterface inter,
- BigInteger aclId, Long elanTag) {
- for (AllowedAddressPairs ip : inter.getAllowedAddressPairs()) {
- if (!AclServiceUtils.isNotIpv4AllNetwork(ip)) {
- continue;
- }
- List<MatchInfoBase> flowMatches = new ArrayList<>();
- flowMatches.addAll(AclServiceUtils.buildIpAndElanSrcMatch(elanTag, ip, dataBroker));
-
- List<InstructionInfo> instructions = new ArrayList<>();
-
- InstructionWriteMetadata writeMetatdata =
- new InstructionWriteMetadata(AclServiceUtils.getAclIdMetadata(aclId),
- MetaDataUtil.METADATA_MASK_REMOTE_ACL_ID);
- instructions.add(writeMetatdata);
- instructions.add(new InstructionGotoTable(getIngressAclFilterTable()));
-
- String flowNameAdded =
- "Acl_Filter_Ingress_" + new String(ip.getIpAddress().getValue()) + "_" + elanTag;
-
- LOG.debug("writing rule for ip {} and elanId {} in ingress acl remote table {}",
- getIpPrefixOrAddress(ip), elanTag, getIngressAclRemoteAclTable());
- syncFlow(dpId, getIngressAclRemoteAclTable(), flowNameAdded, AclConstants.NO_PRIORITY, "ACL", 0,
- 0, AclConstants.COOKIE_ACL_BASE, flowMatches, instructions, addOrRemove);
- }
- }
-
protected abstract String syncSpecificAclFlow(BigInteger dpId, int lportTag, int addOrRemove, Ace ace,
String portId, Map<String, List<MatchInfoBase>> flowMap, String flowName);
List<MatchInfoBase> matches = new ArrayList<>();
matches.add(MatchEthernetType.ARP);
matches.add(buildLPortTagMatch(lportTag));
-
List<InstructionInfo> instructions = getDispatcherTableResubmitInstructions(new ArrayList<>());
+ LOG.debug(addOrRemove == NwConstants.DEL_FLOW ? "Deleting " : "Adding " + "ARP Rule on DPID {}, "
+ + "lportTag {}", dpId, lportTag);
String flowName = "Ingress_ARP_" + dpId + "_" + lportTag;
syncFlow(dpId, NwConstants.EGRESS_ACL_TABLE, flowName,
AclConstants.PROTO_ARP_TRAFFIC_MATCH_PRIORITY, "ACL", 0, 0,
AclConstants.COOKIE_ACL_BASE, matches, instructions, addOrRemove);
}
- protected MatchInfoBase buildLPortTagMatch(int lportTag) {
- return AclServiceUtils.buildLPortTagMatch(lportTag, ServiceModeIngress.class);
+
+ /**
+ * Programs broadcast rules.
+ *
+ * @param port the Acl Interface port
+ * @param addOrRemove whether to delete or add flow
+ */
+ @Override
+ protected void programBroadcastRules(AclInterface port, int addOrRemove) {
+ programIpv4BroadcastRule(port, addOrRemove);
}
- protected int getIngressSpecificAclFlowPriority(BigInteger dpId, int addOrRemove, String flowName,
- PacketHandling packetHandling) {
- int priority;
- if (addOrRemove == NwConstants.DEL_FLOW) {
- priority = aclServiceUtils.releaseAndRemoveFlowPriorityFromCache(dpId, NwConstants.EGRESS_ACL_FILTER_TABLE,
- flowName, packetHandling);
+ /**
+ * Programs IPv4 broadcast rules.
+ *
+ * @param port the Acl Interface port
+ * @param addOrRemove whether to delete or add flow
+ */
+ private void programIpv4BroadcastRule(AclInterface port, int addOrRemove) {
+ BigInteger dpId = port.getDpId();
+ int lportTag = port.getLPortTag();
+ MatchInfoBase lportMatchInfo = buildLPortTagMatch(lportTag);
+ List<IpPrefixOrAddress> cidrs = port.getSubnetIpPrefixes();
+ if (cidrs != null) {
+ List<String> broadcastAddresses = AclServiceUtils.getIpBroadcastAddresses(cidrs);
+ for (String broadcastAddress : broadcastAddresses) {
+ List<MatchInfoBase> matches =
+ AclServiceUtils.buildBroadcastIpV4Matches(broadcastAddress);
+ matches.add(lportMatchInfo);
+ List<InstructionInfo> instructions = new ArrayList<>();
+ instructions.add(new InstructionGotoTable(NwConstants.EGRESS_ACL_REMOTE_ACL_TABLE));
+ String flowName = "Ingress_v4_Broadcast_" + dpId + "_" + lportTag + "_" + broadcastAddress + "_Permit";
+ syncFlow(dpId, NwConstants.EGRESS_ACL_TABLE, flowName,
+ AclConstants.PROTO_MATCH_PRIORITY, "ACL", 0, 0, AclConstants.COOKIE_ACL_BASE, matches,
+ instructions, addOrRemove);
+ }
} else {
- priority = aclServiceUtils.allocateAndSaveFlowPriorityInCache(dpId, NwConstants.EGRESS_ACL_FILTER_TABLE,
- flowName, packetHandling);
+ LOG.error("IP Broadcast CIDRs are missing for port {}", port.getInterfaceId());
}
- return priority;
+ }
+
+ protected MatchInfoBase buildLPortTagMatch(int lportTag) {
+ return AclServiceUtils.buildLPortTagMatch(lportTag, ServiceModeIngress.class);
}
}