use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface in project netvirt by opendaylight.
the class AclInterfaceStateListener method add.
@Override
protected void add(InstanceIdentifier<Interface> key, Interface added) {
if (!L2vlan.class.equals(added.getType())) {
return;
}
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface;
iface = interfaceManager.getInterfaceInfoFromConfigDataStore(added.getName());
if (iface == null) {
LOG.error("No interface with name {} available in interfaceConfig, servicing interfaceState ADD" + "for ACL failed", added.getName());
return;
}
InterfaceAcl aclInPort = iface.getAugmentation(InterfaceAcl.class);
if (aclInPort == null) {
LOG.trace("Interface {} is not an ACL Interface, ignoring ADD interfaceState event", added.getName());
return;
}
AclInterface aclInterface = aclInterfaceCache.addOrUpdate(added.getName(), (prevAclInterface, builder) -> {
builder.dpId(AclServiceUtils.getDpIdFromIterfaceState(added)).lPortTag(added.getIfIndex()).isMarkedForDelete(false);
if (AclServiceUtils.isOfInterest(prevAclInterface)) {
if (prevAclInterface.getSubnetIpPrefixes() == null) {
// For upgrades
List<IpPrefixOrAddress> subnetIpPrefixes = AclServiceUtils.getSubnetIpPrefixes(dataBroker, added.getName());
builder.subnetIpPrefixes(subnetIpPrefixes);
}
SortedSet<Integer> ingressRemoteAclTags = aclServiceUtils.getRemoteAclTags(aclInPort.getSecurityGroups(), DirectionIngress.class);
SortedSet<Integer> egressRemoteAclTags = aclServiceUtils.getRemoteAclTags(aclInPort.getSecurityGroups(), DirectionEgress.class);
builder.ingressRemoteAclTags(ingressRemoteAclTags).egressRemoteAclTags(egressRemoteAclTags);
}
});
if (AclServiceUtils.isOfInterest(aclInterface)) {
List<Uuid> aclList = aclInterface.getSecurityGroups();
if (aclList != null) {
aclDataUtil.addAclInterfaceMap(aclList, aclInterface);
}
if (aclInterface.getElanId() == null) {
LOG.debug("On Add event, skip ADD since ElanId is not updated");
return;
}
if (aclClusterUtil.isEntityOwner()) {
LOG.debug("On add event, notify ACL service manager to add ACL for interface: {}", aclInterface);
aclServiceManger.notify(aclInterface, null, Action.BIND);
if (aclList != null) {
aclServiceUtils.addAclPortsLookup(aclInterface, aclList, aclInterface.getAllowedAddressPairs());
}
aclServiceManger.notify(aclInterface, null, Action.ADD);
}
}
}
use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface in project netvirt by opendaylight.
the class AclDataUtil method getRemoteAclInterfaces.
/**
* Gets the set of ACL interfaces per ACL (in a map) which has specified
* remote ACL ID.
*
* @param remoteAclId the remote acl id
* @param direction the direction
* @return the set of ACL interfaces per ACL (in a map) which has specified
* remote ACL ID.
*/
public Map<String, Set<AclInterface>> getRemoteAclInterfaces(Uuid remoteAclId, Class<? extends DirectionBase> direction) {
Collection<Uuid> remoteAclList = getRemoteAcl(remoteAclId, direction);
if (remoteAclList == null) {
return null;
}
Map<String, Set<AclInterface>> mapOfAclWithInterfaces = new HashMap<>();
for (Uuid acl : remoteAclList) {
Set<AclInterface> interfaceSet = new HashSet<>();
Collection<AclInterface> interfaces = getInterfaceList(acl);
if (interfaces != null && !interfaces.isEmpty()) {
interfaceSet.addAll(interfaces);
mapOfAclWithInterfaces.put(acl.getValue(), interfaceSet);
}
}
return mapOfAclWithInterfaces;
}
use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface in project netvirt by opendaylight.
the class DisplayAclDataCaches method getAclInterfaceCache.
protected void getAclInterfaceCache() {
if (all == null && key == null) {
printAclInterfaceCacheHelp();
return;
}
if (all == null && key != null) {
AclInterface aclInterface = aclInterfaceCache.get(key);
if (aclInterface == null) {
session.getConsole().println("No data found");
return;
}
session.getConsole().println(ACL_INT_HEAD);
session.getConsole().println(String.format(ACL_INT_TAB_FOR, key, aclInterface.isPortSecurityEnabled(), aclInterface.getInterfaceId(), aclInterface.getLPortTag(), aclInterface.getDpId(), aclInterface.getElanId(), aclInterface.getSecurityGroups(), aclInterface.getAllowedAddressPairs(), aclInterface.getSubnetIpPrefixes(), aclInterface.isMarkedForDelete()));
} else if (key == null) {
if (!validateAll()) {
printAclInterfaceCacheHelp();
return;
}
Collection<Entry<String, AclInterface>> entries = aclInterfaceCache.entries();
if (entries.isEmpty()) {
session.getConsole().println("No data found");
} else {
session.getConsole().println(ACL_INT_HEAD);
for (Map.Entry<String, AclInterface> entry : entries) {
AclInterface aclInterface = entry.getValue();
session.getConsole().println(String.format(ACL_INT_TAB_FOR, entry.getKey(), aclInterface.isPortSecurityEnabled(), aclInterface.getInterfaceId(), aclInterface.getLPortTag(), aclInterface.getDpId(), aclInterface.getElanId(), aclInterface.getSecurityGroups(), aclInterface.getAllowedAddressPairs(), aclInterface.getSubnetIpPrefixes(), aclInterface.isMarkedForDelete()));
}
}
}
}
use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface in project netvirt by opendaylight.
the class AbstractAclServiceImpl method isFirstPortInDpnWithRemoteAclId.
private boolean isFirstPortInDpnWithRemoteAclId(AclInterface port, Uuid remoteAclId) {
String portId = port.getInterfaceId();
BigInteger dpId = port.getDpId();
Map<String, Set<AclInterface>> remoteAclInterfacesMap = aclDataUtil.getRemoteAclInterfaces(remoteAclId, direction);
if (remoteAclInterfacesMap != null) {
for (Set<AclInterface> interfaceSet : remoteAclInterfacesMap.values()) {
for (AclInterface aclInterface : interfaceSet) {
if (portId.equals(aclInterface.getInterfaceId())) {
continue;
}
if (dpId.equals(aclInterface.getDpId())) {
return false;
}
}
}
}
return true;
}
use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface in project netvirt by opendaylight.
the class AbstractAclServiceImpl method handleRemoteAclUpdate.
protected void handleRemoteAclUpdate(Acl aclBefore, Acl aclAfter, Collection<AclInterface> portsBefore) {
String aclName = aclAfter.getAclName();
Collection<AclInterface> interfaceList = aclDataUtil.getInterfaceList(new Uuid(aclName));
if (interfaceList == null || interfaceList.isEmpty()) {
LOG.trace("handleRemoteAclUpdate: No interfaces found with ACL={}", aclName);
return;
}
Set<Uuid> remoteAclsBefore = AclServiceUtils.getRemoteAclIdsByDirection(aclBefore, this.direction);
Set<Uuid> remoteAclsAfter = AclServiceUtils.getRemoteAclIdsByDirection(aclAfter, this.direction);
Set<Uuid> remoteAclsAdded = new HashSet<>(remoteAclsAfter);
remoteAclsAdded.removeAll(remoteAclsBefore);
Set<Uuid> remoteAclsDeleted = new HashSet<>(remoteAclsBefore);
remoteAclsDeleted.removeAll(remoteAclsAfter);
if (!remoteAclsAdded.isEmpty() || !remoteAclsDeleted.isEmpty()) {
// ports
for (AclInterface portBefore : portsBefore) {
programAclDispatcherTable(portBefore, NwConstants.DEL_FLOW);
}
for (AclInterface port : interfaceList) {
programAclDispatcherTable(port, NwConstants.ADD_FLOW);
}
}
Set<BigInteger> dpns = interfaceList.stream().map(port -> port.getDpId()).collect(Collectors.toSet());
programRemoteAclTable(aclName, remoteAclsDeleted, dpns, NwConstants.DEL_FLOW);
programRemoteAclTable(aclName, remoteAclsAdded, dpns, NwConstants.ADD_FLOW);
}
Aggregations