use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface in project netvirt by opendaylight.
the class AclServiceUtils method deleteAclPortsLookup.
public List<ListenableFuture<Void>> deleteAclPortsLookup(AclInterface port, List<Uuid> aclList, List<AllowedAddressPairs> allowedAddresses) {
String portId = port.getInterfaceId();
LOG.trace("Deleting AclPortsLookup for port={}, acls={}, AAPs={}", portId, aclList, allowedAddresses);
if (aclList == null || allowedAddresses == null || allowedAddresses.isEmpty()) {
LOG.warn("aclList or allowedAddresses is null. port={}, acls={}, AAPs={}", portId, aclList, allowedAddresses);
return Collections.emptyList();
}
List<ListenableFuture<Void>> futures = new ArrayList<>();
for (Uuid aclId : aclList) {
String aclName = aclId.getValue();
synchronized (aclName.intern()) {
futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
for (AllowedAddressPairs aap : allowedAddresses) {
InstanceIdentifier<PortIds> path = AclServiceUtils.getPortIdsPathInAclPortsLookup(aclName, aap.getIpAddress(), portId);
tx.delete(LogicalDatastoreType.OPERATIONAL, path);
}
cleanUpStaleEntriesInAclPortsLookup(aclName, tx);
}));
}
}
return futures;
}
use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface in project netvirt by opendaylight.
the class AclDataUtilTest method testAclInterfaces.
@Test
public void testAclInterfaces() {
assertTrue(aclDataUtil.getInterfaceList(ACL1).isEmpty());
aclDataUtil.removeAclInterfaceMap(Arrays.asList(ACL1), PORT1);
final BigInteger dpId = new BigInteger("123");
assertFalse(aclDataUtil.doesDpnHaveAclInterface(dpId));
aclDataUtil.addAclInterfaceMap(Arrays.asList(ACL1, ACL2), PORT1);
assertAclInterfaces(ACL1, PORT1);
assertAclInterfaces(ACL2, PORT1);
aclDataUtil.addAclInterfaceMap(Arrays.asList(ACL1), PORT2);
assertAclInterfaces(ACL1, PORT1, PORT2);
assertAclInterfaces(ACL2, PORT1);
assertFalse(aclDataUtil.doesDpnHaveAclInterface(dpId));
aclDataUtil.addAclInterfaceMap(Arrays.asList(ACL1), PORT2);
assertAclInterfaces(ACL1, PORT1, PORT2);
aclDataUtil.addOrUpdateAclInterfaceMap(Arrays.asList(ACL1), PORT3);
assertAclInterfaces(ACL1, PORT1, PORT2, PORT3);
AclInterface updatedPort2 = AclInterface.builder().interfaceId(PORT2.getInterfaceId()).dpId(dpId).build();
aclDataUtil.addOrUpdateAclInterfaceMap(Arrays.asList(ACL1), updatedPort2);
assertAclInterfaces(ACL1, PORT1, updatedPort2, PORT3);
assertTrue(aclDataUtil.doesDpnHaveAclInterface(dpId));
aclDataUtil.removeAclInterfaceMap(Arrays.asList(ACL1, ACL2), PORT1);
assertAclInterfaces(ACL1, updatedPort2, PORT3);
assertAclInterfaces(ACL2);
aclDataUtil.removeAclInterfaceMap(Arrays.asList(ACL1, ACL2), updatedPort2);
assertAclInterfaces(ACL1, PORT3);
assertAclInterfaces(ACL2);
assertFalse(aclDataUtil.doesDpnHaveAclInterface(dpId));
aclDataUtil.addOrUpdateAclInterfaceMap(Arrays.asList(ACL2), PORT2);
assertAclInterfaces(ACL2, PORT2);
aclDataUtil.addOrUpdateAclInterfaceMap(Arrays.asList(ACL3), PORT1);
assertAclInterfaces(ACL3, PORT1);
}
use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface in project netvirt by opendaylight.
the class EgressAclServiceImpl method programL2BroadcastAllowRule.
/**
* Programs Non-IP broadcast rules.
*
* @param port the Acl Interface port
* @param addOrRemove whether to delete or add flow
*/
private void programL2BroadcastAllowRule(AclInterface port, int addOrRemove) {
BigInteger dpId = port.getDpId();
int lportTag = port.getLPortTag();
List<AllowedAddressPairs> allowedAddresses = port.getAllowedAddressPairs();
Set<MacAddress> macs = allowedAddresses.stream().map(aap -> aap.getMacAddress()).collect(Collectors.toSet());
for (MacAddress mac : macs) {
List<MatchInfoBase> matches = new ArrayList<>();
matches.add(new MatchEthernetSource(mac));
matches.add(AclServiceUtils.buildLPortTagMatch(lportTag, serviceMode));
List<InstructionInfo> instructions = getDispatcherTableResubmitInstructions();
String flowName = "Egress_L2Broadcast_" + dpId + "_" + lportTag + "_" + mac.getValue();
syncFlow(dpId, getAclAntiSpoofingTable(), flowName, AclConstants.PROTO_L2BROADCAST_TRAFFIC_MATCH_PRIORITY, "ACL", 0, 0, AclConstants.COOKIE_ACL_BASE, matches, instructions, addOrRemove);
}
}
use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface in project netvirt by opendaylight.
the class AclEventListener method updateAclCaches.
private void updateAclCaches(Acl aclBefore, Acl aclAfter, Collection<AclInterface> aclInterfaces, Class<? extends DirectionBase> direction) {
Uuid aclId = new Uuid(aclAfter.getAclName());
Set<Uuid> remoteAclsBefore = AclServiceUtils.getRemoteAclIdsByDirection(aclBefore, direction);
Set<Uuid> remoteAclsAfter = AclServiceUtils.getRemoteAclIdsByDirection(aclAfter, direction);
Set<Uuid> remoteAclsDeleted = new HashSet<>(remoteAclsBefore);
remoteAclsDeleted.removeAll(remoteAclsAfter);
for (Uuid remoteAcl : remoteAclsDeleted) {
aclDataUtil.removeRemoteAclId(remoteAcl, aclId, direction);
}
Set<Uuid> remoteAclsAdded = new HashSet<>(remoteAclsAfter);
remoteAclsAdded.removeAll(remoteAclsBefore);
for (Uuid remoteAcl : remoteAclsAdded) {
aclDataUtil.addRemoteAclId(remoteAcl, aclId, direction);
}
if (remoteAclsDeleted.isEmpty() && remoteAclsAdded.isEmpty()) {
return;
}
if (aclInterfaces != null) {
for (AclInterface aclInterface : aclInterfaces) {
AclInterface aclInterfaceInCache = aclInterfaceCache.addOrUpdate(aclInterface.getInterfaceId(), (prevAclInterface, builder) -> {
SortedSet<Integer> remoteAclTags = aclServiceUtils.getRemoteAclTags(aclInterface.getSecurityGroups(), direction);
if (DirectionEgress.class.equals(direction)) {
builder.egressRemoteAclTags(remoteAclTags);
} else {
builder.ingressRemoteAclTags(remoteAclTags);
}
});
aclDataUtil.addOrUpdateAclInterfaceMap(aclInterface.getSecurityGroups(), aclInterfaceInCache);
}
}
}
use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface in project netvirt by opendaylight.
the class AclInterfaceListener method remove.
@Override
public void remove(InstanceIdentifier<Interface> key, Interface port) {
LOG.trace("Received AclInterface remove event, port={}", port);
String interfaceId = port.getName();
AclInterface aclInterface = aclInterfaceCache.remove(interfaceId);
if (AclServiceUtils.isOfInterest(aclInterface)) {
if (aclClusterUtil.isEntityOwner()) {
LOG.debug("On remove event, notify ACL unbind/remove for interface: {}", interfaceId);
aclServiceManager.notify(aclInterface, null, Action.UNBIND);
if (aclInterface.getDpId() != null) {
aclServiceManager.notify(aclInterface, null, Action.REMOVE);
}
AclServiceUtils.deleteSubnetIpPrefixes(dataBroker, interfaceId);
}
}
}
Aggregations