Search in sources :

Example 21 with AclInterface

use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface in project netvirt by opendaylight.

the class AclInstanceRecoveryHandler method recoverService.

@Override
public void recoverService(String entityId) {
    LOG.info("Recover ACL instance {}", entityId);
    Uuid aclId = new Uuid(entityId);
    Collection<AclInterface> aclInterfaces = aclDataUtil.getInterfaceList(aclId);
    for (AclInterface aclInterface : aclInterfaces) {
        String aclInterfaceId = aclInterface.getInterfaceId();
        Optional<Interface> interfaceOptional = AclServiceUtils.getInterface(dataBroker, aclInterfaceId);
        if (interfaceOptional.isPresent()) {
            Interface interfaceBefore = interfaceOptional.get();
            LOG.debug("Starting Recovery of acl Instance {} for interface {}", entityId, interfaceBefore.getName());
            InterfaceAcl interfaceAclBefore = interfaceBefore.getAugmentation(InterfaceAcl.class);
            List<Uuid> sgList = new ArrayList<>(interfaceAclBefore.getSecurityGroups());
            sgList.remove(aclId);
            InterfaceAcl interfaceAclAfter = new InterfaceAclBuilder(interfaceAclBefore).setSecurityGroups(sgList).build();
            Interface interfaceAfter = new InterfaceBuilder(interfaceBefore).addAugmentation(InterfaceAcl.class, interfaceAclAfter).build();
            aclInterfaceListener.update(null, interfaceBefore, interfaceAfter);
            aclInterfaceListener.update(null, interfaceAfter, interfaceBefore);
        } else {
            LOG.error("Interfaces not present for aclInterface {} ", aclInterfaceId);
        }
    }
}
Also used : AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) InterfaceAclBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAclBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList) InterfaceBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder) InterfaceAcl(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl) AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface) ServiceRecoveryInterface(org.opendaylight.genius.srm.ServiceRecoveryInterface)

Example 22 with AclInterface

use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface in project netvirt by opendaylight.

the class AbstractAclServiceImpl method programAclForExistingTrafficTable.

private void programAclForExistingTrafficTable(AclInterface port, Ace ace, int addOrRemove, String flowName, List<MatchInfoBase> matches, Integer priority) {
    AceIp acl = (AceIp) ace.getMatches().getAceType();
    final String newFlowName = flowName + this.directionString + "_" + port.getDpId() + "_" + port.getLPortTag() + "_" + ((acl.getAceIpVersion() instanceof AceIpv4) ? "_IPv4" : "_IPv6") + "_FlowAfterRuleDeleted";
    final List<MatchInfoBase> newMatches = matches.stream().filter(obj -> !(obj instanceof NxMatchCtState || obj instanceof MatchMetadata)).collect(Collectors.toList());
    newMatches.add(AclServiceUtils.buildLPortTagMatch(port.getLPortTag(), serviceMode));
    newMatches.add(new NxMatchCtState(AclConstants.TRACKED_RPL_CT_STATE, AclConstants.TRACKED_RPL_CT_STATE_MASK));
    List<InstructionInfo> instructions = AclServiceUtils.createCtMarkInstructionForNewState(getAclFilterCumDispatcherTable(), port.getElanId());
    // Reversing the flow add/delete operation for this table.
    int operation = (addOrRemove == NwConstants.ADD_FLOW) ? NwConstants.DEL_FLOW : NwConstants.ADD_FLOW;
    syncFlow(port.getDpId(), getAclForExistingTrafficTable(), newFlowName, priority, "ACL", 0, AclServiceUtils.getHardTimoutForApplyStatefulChangeOnExistingTraffic(ace, aclServiceUtils), AclConstants.COOKIE_ACL_BASE, newMatches, instructions, operation);
}
Also used : 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) MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) 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) NxMatchCtState(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchCtState) 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) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase)

Example 23 with AclInterface

use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface in project netvirt by opendaylight.

the class AbstractAclServiceImpl method programRemoteAclTable.

private void programRemoteAclTable(String aclName, Set<Uuid> remoteAclIds, Set<BigInteger> dpns, int addOrRemove) {
    for (Uuid remoteAclId : remoteAclIds) {
        Collection<AclInterface> remoteAclInterfaces = aclDataUtil.getInterfaceList(remoteAclId);
        if (remoteAclInterfaces == null || remoteAclInterfaces.isEmpty()) {
            continue;
        }
        Set<AllowedAddressPairs> aaps = remoteAclInterfaces.stream().map(port -> port.getAllowedAddressPairs()).flatMap(List::stream).filter(aap -> AclServiceUtils.isNotIpAllNetwork(aap)).collect(Collectors.toSet());
        Integer aclTag = aclServiceUtils.getAclTag(remoteAclId);
        if (addOrRemove == NwConstants.ADD_FLOW) {
            for (BigInteger dpn : dpns) {
                for (AllowedAddressPairs aap : aaps) {
                    programRemoteAclTableFlow(dpn, aclTag, aap, addOrRemove);
                }
            }
        } else if (addOrRemove == NwConstants.DEL_FLOW) {
            Set<BigInteger> remoteAclDpns = new HashSet<>();
            Map<String, Set<AclInterface>> mapAclWithPortSet = aclDataUtil.getRemoteAclInterfaces(remoteAclId, this.direction);
            if (mapAclWithPortSet != null) {
                Map<String, Set<AclInterface>> copyOfMapAclWithPortSet = new HashMap<>(mapAclWithPortSet);
                copyOfMapAclWithPortSet.remove(aclName);
                remoteAclDpns = collectDpns(copyOfMapAclWithPortSet);
            }
            Set<BigInteger> dpnsToOperate = new HashSet<>(dpns);
            dpnsToOperate.removeAll(remoteAclDpns);
            LOG.debug("Deleting flows in Remote ACL table for remoteAclId={}, direction={}, dpnsToOperate={}, " + "remoteAclDpns={}, dpns={}", remoteAclId.getValue(), directionString, dpnsToOperate, remoteAclDpns, dpns);
            for (BigInteger dpn : dpnsToOperate) {
                for (AllowedAddressPairs aap : aaps) {
                    programRemoteAclTableFlow(dpn, aclTag, aap, addOrRemove);
                }
            }
        }
    }
}
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) SortedSet(java.util.SortedSet) Set(java.util.Set) HashSet(java.util.HashSet) BigInteger(java.math.BigInteger) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) AllowedAddressPairs(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs) BigInteger(java.math.BigInteger) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 24 with AclInterface

use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface in project netvirt by opendaylight.

the class AclInterfaceCacheImpl method addOrUpdate.

@Override
public AclInterface addOrUpdate(@Nonnull String interfaceId, BiConsumer<AclInterface, AclInterface.Builder> updateFunction) {
    while (true) {
        // First try to update the existing instance in the cache if one exists.
        AclInterface aclInterface = cache.computeIfPresent(interfaceId, (key, prevAclInterface) -> {
            Builder builder = AclInterface.builder(prevAclInterface);
            updateFunction.accept(prevAclInterface, builder);
            return builder.build();
        });
        if (aclInterface == null) {
            // No existing instance so try to put a new one.
            Builder builder = AclInterface.builder();
            builder.interfaceId(interfaceId);
            updateFunction.accept(null, builder);
            aclInterface = builder.build();
            if (cache.putIfAbsent(interfaceId, aclInterface) == null) {
                // The new instance was added.
                return aclInterface;
            }
        // The new instance wasn't added - some one else beat us to it. Loop back up and try again.
        } else {
            return aclInterface;
        }
    }
}
Also used : AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) Builder(org.opendaylight.netvirt.aclservice.api.utils.AclInterface.Builder)

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