use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionBase 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.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionBase 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.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionBase in project netvirt by opendaylight.
the class PolicyServiceUtil method getAcePolicyClassifier.
public Optional<String> getAcePolicyClassifier(Ace ace) {
Actions actions = ace.getActions();
SetPolicyClassifier setPolicyClassifier = actions.getAugmentation(SetPolicyClassifier.class);
if (setPolicyClassifier == null) {
LOG.warn("No valid policy action found for ACE rule {}", ace.getRuleName());
return Optional.absent();
}
Class<? extends DirectionBase> direction;
try {
direction = setPolicyClassifier.getDirection();
} catch (IllegalArgumentException e) {
LOG.warn("Failed to parse policy classifier direction");
return Optional.absent();
}
if (direction == null || !direction.isAssignableFrom(DirectionEgress.class)) {
LOG.trace("Ignoring non egress policy ACE rule {}", ace.getRuleName());
return Optional.absent();
}
return Optional.of(setPolicyClassifier.getPolicyClassifier());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionBase in project netvirt by opendaylight.
the class DisplayAclDataCaches method getRemoteAclIdMap.
protected void getRemoteAclIdMap(Class<? extends DirectionBase> direction) {
if (all == null && uuidStr == null) {
printRemoteAclIdMapHelp();
} else if (all == null) {
Uuid uuidRef;
try {
uuidRef = Uuid.getDefaultInstance(uuidStr);
} catch (IllegalArgumentException e) {
session.getConsole().println("Invalid uuid" + e.getMessage());
log.error("Invalid uuid", e);
return;
}
Collection<Uuid> remoteUuidLst = aclDataCache.getRemoteAcl(uuidRef, direction);
if (remoteUuidLst == null || remoteUuidLst.isEmpty()) {
session.getConsole().println("UUID not matched");
} else {
session.getConsole().println(REM_ID_HEAD);
session.getConsole().print(String.format(KEY_TAB, uuidRef.getValue()));
boolean first = true;
for (Uuid uuid : remoteUuidLst) {
if (first) {
session.getConsole().println(String.format(REM_ID_TAB, uuid.getValue()));
first = false;
} else {
session.getConsole().println(String.format(REM_ID_TAB_FOR, "", uuid.getValue()));
}
}
}
} else if (uuidStr == null) {
if (!validateAll()) {
printRemoteAclIdMapHelp();
return;
}
Map<Uuid, Collection<Uuid>> map = DirectionEgress.class.equals(direction) ? aclDataCache.getEgressRemoteAclIdMap() : aclDataCache.getIngressRemoteAclIdMap();
if (map.isEmpty()) {
session.getConsole().println("No data found");
} else {
session.getConsole().println(REM_ID_HEAD);
for (Entry<Uuid, Collection<Uuid>> entry : map.entrySet()) {
session.getConsole().print(String.format(KEY_TAB, entry.getKey().getValue()));
if (entry.getValue() == null || entry.getValue().isEmpty()) {
session.getConsole().println(String.format(REM_ID_TAB, ""));
} else {
boolean first = true;
for (Uuid uuid : entry.getValue()) {
if (first) {
session.getConsole().println(String.format(REM_ID_TAB, uuid.getValue()));
first = false;
} else {
session.getConsole().println(String.format(REM_ID_TAB_FOR, "", uuid.getValue()));
}
}
}
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionBase in project netvirt by opendaylight.
the class AclServiceUtils method getRemoteAclTags.
public SortedSet<Integer> getRemoteAclTags(List<Uuid> aclIds, Class<? extends DirectionBase> direction) {
SortedSet<Integer> remoteAclTags = new TreeSet<>();
Set<Uuid> remoteAclIds = getRemoteAclIdsByDirection(aclIds, direction);
for (Uuid remoteAclId : remoteAclIds) {
Integer remoteAclTag = getAclTag(remoteAclId);
if (remoteAclTag != null && remoteAclTag != AclConstants.INVALID_ACL_TAG) {
remoteAclTags.add(remoteAclTag);
}
}
return remoteAclTags;
}
Aggregations