Search in sources :

Example 1 with DirectionBase

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);
        }
    }
}
Also used : AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) HashSet(java.util.HashSet)

Example 2 with DirectionBase

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;
}
Also used : AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 3 with DirectionBase

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());
}
Also used : Actions(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Actions) SetPolicyClassifier(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.SetPolicyClassifier)

Example 4 with DirectionBase

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()));
                        }
                    }
                }
            }
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Collection(java.util.Collection) DirectionEgress(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionEgress)

Example 5 with DirectionBase

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;
}
Also used : BigInteger(java.math.BigInteger) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) TreeSet(java.util.TreeSet)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)6 HashSet (java.util.HashSet)4 AclInterface (org.opendaylight.netvirt.aclservice.api.utils.AclInterface)2 BigInteger (java.math.BigInteger)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Ipv4Acl (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.Ipv4Acl)1 Acl (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl)1 AccessListEntries (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.AccessListEntries)1 Ace (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace)1 Actions (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Actions)1 NetvirtAcl (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.types.rev170711.NetvirtAcl)1 DirectionEgress (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionEgress)1 InterfaceAcl (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl)1 SecurityRuleAttr (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.SecurityRuleAttr)1 SetPolicyClassifier (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.SetPolicyClassifier)1