Search in sources :

Example 6 with AclInterface

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);
        }
    }
}
Also used : AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) L2vlan(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan) IpPrefixOrAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress) InterfaceAcl(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 7 with AclInterface

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;
}
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 8 with AclInterface

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()));
            }
        }
    }
}
Also used : AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) Entry(java.util.Map.Entry) Collection(java.util.Collection)

Example 9 with AclInterface

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;
}
Also used : AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) SortedSet(java.util.SortedSet) Set(java.util.Set) HashSet(java.util.HashSet) BigInteger(java.math.BigInteger)

Example 10 with AclInterface

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);
}
Also used : AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) AceIpv4(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.ace.ip.ace.ip.version.AceIpv4) NxMatchCtState(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchCtState) Acl(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl) SortedSet(java.util.SortedSet) LoggerFactory(org.slf4j.LoggerFactory) AclServiceListener(org.opendaylight.netvirt.aclservice.api.AclServiceListener) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) AllowedAddressPairs(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs) Map(java.util.Map) BigInteger(java.math.BigInteger) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) DirectionIngress(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionIngress) MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) AclConstants(org.opendaylight.netvirt.aclservice.utils.AclConstants) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) AclDataUtil(org.opendaylight.netvirt.aclservice.utils.AclDataUtil) Collection(java.util.Collection) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) Set(java.util.Set) AclConntrackClassifierType(org.opendaylight.netvirt.aclservice.utils.AclConntrackClassifierType) Matches(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches) Collectors(java.util.stream.Collectors) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) List(java.util.List) NxCtAction(org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack.NxCtAction) Entry(java.util.Map.Entry) AceIp(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) DirectionEgress(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionEgress) HashMap(java.util.HashMap) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) ServiceModeBase(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeBase) AclServiceUtils(org.opendaylight.netvirt.aclservice.utils.AclServiceUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) AclInterfaceCache(org.opendaylight.netvirt.aclservice.api.AclInterfaceCache) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) SecurityRuleAttr(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.SecurityRuleAttr) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) AccessListEntries(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.AccessListEntries) AclServiceOFFlowBuilder(org.opendaylight.netvirt.aclservice.utils.AclServiceOFFlowBuilder) ServiceModeEgress(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeEgress) DirectionBase(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionBase) AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) Logger(org.slf4j.Logger) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) Ace(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace) ActionNxConntrack(org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) Action(org.opendaylight.netvirt.aclservice.api.AclServiceManager.Action) Collections(java.util.Collections) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) BigInteger(java.math.BigInteger) HashSet(java.util.HashSet)

Aggregations

AclInterface (org.opendaylight.netvirt.aclservice.api.utils.AclInterface)24 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)12 BigInteger (java.math.BigInteger)10 ArrayList (java.util.ArrayList)10 Set (java.util.Set)9 Collections (java.util.Collections)8 HashSet (java.util.HashSet)8 List (java.util.List)8 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)8 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)8 MDSALUtil (org.opendaylight.genius.mdsalutil.MDSALUtil)8 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)8 NwConstants (org.opendaylight.genius.mdsalutil.NwConstants)8 MatchEthernetType (org.opendaylight.genius.mdsalutil.matches.MatchEthernetType)8 DirectionBase (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionBase)8 AllowedAddressPairs (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 Collection (java.util.Collection)7 HashMap (java.util.HashMap)6