Search in sources :

Example 16 with Acl

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl in project netvirt by opendaylight.

the class AbstractAclServiceImpl method syncRemoteAclTable.

private void syncRemoteAclTable(String portId, Uuid acl, Integer aclTag, List<AllowedAddressPairs> aaps, int addOrRemove) {
    Map<String, Set<AclInterface>> mapAclWithPortSet = aclDataUtil.getRemoteAclInterfaces(acl, this.direction);
    Set<BigInteger> dpns = collectDpns(mapAclWithPortSet);
    for (AllowedAddressPairs aap : aaps) {
        if (!AclServiceUtils.isNotIpAllNetwork(aap)) {
            continue;
        }
        if (aclServiceUtils.skipDeleteInCaseOfOverlappingIP(portId, acl, aap.getIpAddress(), addOrRemove)) {
            LOG.debug("Skipping delete of IP={} in remote ACL table for remoteAclId={}, portId={}", aap.getIpAddress(), portId, acl.getValue());
            continue;
        }
        for (BigInteger dpId : dpns) {
            programRemoteAclTableFlow(dpId, aclTag, aap, addOrRemove);
        }
    }
}
Also used : SortedSet(java.util.SortedSet) Set(java.util.Set) HashSet(java.util.HashSet) BigInteger(java.math.BigInteger) AllowedAddressPairs(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs)

Example 17 with Acl

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl in project netvirt by opendaylight.

the class AbstractAclServiceImpl method programAclRules.

/**
 * Programs the acl custom rules.
 *
 * @param port acl interface
 * @param aclUuidList the list of acl uuid to be applied
 * @param addOrRemove whether to delete or add flow
 * @return program succeeded
 */
protected boolean programAclRules(AclInterface port, List<Uuid> aclUuidList, int addOrRemove) {
    BigInteger dpId = port.getDpId();
    LOG.debug("Applying custom rules on DpId {}, lportTag {}", dpId, port.getLPortTag());
    if (aclUuidList == null || dpId == null) {
        LOG.warn("{} ACL parameters can not be null. dpId={}, aclUuidList={}", this.directionString, dpId, aclUuidList);
        return false;
    }
    for (Uuid aclUuid : aclUuidList) {
        Acl acl = this.aclDataUtil.getAcl(aclUuid.getValue());
        if (null == acl) {
            LOG.warn("The ACL {} not found in cache", aclUuid.getValue());
            continue;
        }
        AccessListEntries accessListEntries = acl.getAccessListEntries();
        List<Ace> aceList = accessListEntries.getAce();
        for (Ace ace : aceList) {
            programAceRule(port, aclUuid.getValue(), ace, addOrRemove);
        }
    }
    return true;
}
Also used : Ace(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) BigInteger(java.math.BigInteger) Acl(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl) AccessListEntries(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.AccessListEntries)

Example 18 with Acl

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl 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)

Example 19 with Acl

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl in project netvirt by opendaylight.

the class PolicyServiceUtil method updateAclRuleForPolicyClassifier.

public void updateAclRuleForPolicyClassifier(String policyClassifier, String aclName, String ruleName, boolean isAdded) {
    coordinator.enqueueJob(policyClassifier, () -> {
        InstanceIdentifier<AceRule> identifier = getPolicyClassifierAceIdentifier(policyClassifier, aclName, ruleName);
        WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
        if (isAdded) {
            tx.merge(LogicalDatastoreType.OPERATIONAL, identifier, new AceRuleBuilder().setRuleName(ruleName).build(), true);
            LOG.info("Add ACL {} rule {} to policy classifier {}", aclName, ruleName, policyClassifier);
        } else {
            tx.delete(LogicalDatastoreType.OPERATIONAL, identifier);
            LOG.info("Remove ACL {} rule {} from policy classifier {}", aclName, ruleName, policyClassifier);
        }
        return Collections.singletonList(tx.submit());
    });
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) AceRule(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.policy.profiles.policy.profile.policy.acl.rule.AceRule) AceRuleBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.policy.profiles.policy.profile.policy.acl.rule.AceRuleBuilder)

Example 20 with Acl

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl in project netvirt by opendaylight.

the class FlowClassifierTranslator method buildAcl.

public static Acl buildAcl(SfcFlowClassifier flowClassifier, String sfpName) {
    LOG.info("OpenStack Networking SFC pushed Flow classifier : {}", flowClassifier);
    AclBuilder aclBuilder = new AclBuilder();
    AceBuilder aceBuilder = new AceBuilder();
    ActionsBuilder actionsBuilder = new ActionsBuilder();
    RedirectToSfcBuilder redirectToSfcBuilder = new RedirectToSfcBuilder();
    NeutronPortsBuilder neutronPortsBuilder = new NeutronPortsBuilder();
    AceIpBuilder aceIpBuilder = new AceIpBuilder();
    DestinationPortRangeBuilder destinationPortRange = new DestinationPortRangeBuilder();
    SourcePortRangeBuilder sourcePortRangeBuilder = new SourcePortRangeBuilder();
    if (flowClassifier.getUuid() != null) {
        if (flowClassifier.getName() != null) {
            aclBuilder.setAclName(flowClassifier.getUuid().getValue() + "_" + flowClassifier.getName());
        } else {
            aclBuilder.setAclName(flowClassifier.getUuid().getValue());
        }
    }
    if (flowClassifier.getEthertype() != null) {
        IpPrefix sourceIp = null;
        IpPrefix destinationIp = null;
        if (flowClassifier.getSourceIpPrefix() != null) {
            sourceIp = flowClassifier.getSourceIpPrefix();
        }
        if (flowClassifier.getDestinationIpPrefix() != null) {
            destinationIp = flowClassifier.getDestinationIpPrefix();
        }
        if (flowClassifier.getEthertype() == EthertypeV4.class) {
            AceIpv4Builder aceIpv4Builder = new AceIpv4Builder();
            if (sourceIp != null && sourceIp.getIpv4Prefix() != null) {
                aceIpv4Builder.setSourceIpv4Network(sourceIp.getIpv4Prefix());
            }
            if (destinationIp != null && destinationIp.getIpv4Prefix() != null) {
                aceIpv4Builder.setDestinationIpv4Network(destinationIp.getIpv4Prefix());
            }
            aceIpBuilder.setAceIpVersion(aceIpv4Builder.build());
            aclBuilder.setAclType(Ipv4Acl.class);
        }
        if (flowClassifier.getEthertype() == EthertypeV6.class) {
            AceIpv6Builder aceIpv6Builder = new AceIpv6Builder();
            if (sourceIp != null && sourceIp.getIpv6Prefix() != null) {
                aceIpv6Builder.setSourceIpv6Network(sourceIp.getIpv6Prefix());
            }
            if (sourceIp != null && destinationIp.getIpv6Prefix() != null) {
                aceIpv6Builder.setDestinationIpv6Network(destinationIp.getIpv6Prefix());
            }
            aceIpBuilder.setAceIpVersion(aceIpv6Builder.build());
            aclBuilder.setAclType(Ipv6Acl.class);
        }
    }
    if (flowClassifier.getProtocol() != null) {
        if (flowClassifier.getProtocol() == ProtocolTcp.class) {
            aceIpBuilder.setProtocol(PROTO_TCP);
        }
        if (flowClassifier.getProtocol() == ProtocolUdp.class) {
            aceIpBuilder.setProtocol(PROTO_UDP);
        }
    }
    if (flowClassifier.getSourcePortRangeMin() != null) {
        sourcePortRangeBuilder.setLowerPort(new PortNumber(flowClassifier.getSourcePortRangeMin()));
        // set source port range only if lower port is specified as it is a mandatory parameter in acl model
        aceIpBuilder.setSourcePortRange(sourcePortRangeBuilder.build());
    }
    if (flowClassifier.getSourcePortRangeMax() != null) {
        sourcePortRangeBuilder.setUpperPort(new PortNumber(flowClassifier.getSourcePortRangeMax()));
    }
    if (flowClassifier.getDestinationPortRangeMin() != null) {
        destinationPortRange.setLowerPort(new PortNumber(flowClassifier.getDestinationPortRangeMin()));
        // set destination port range only if lower port is specified as it is a mandatory parameter in acl model
        aceIpBuilder.setDestinationPortRange(destinationPortRange.build());
    }
    if (flowClassifier.getDestinationPortRangeMax() != null) {
        destinationPortRange.setUpperPort(new PortNumber(flowClassifier.getDestinationPortRangeMax()));
    }
    if (flowClassifier.getLogicalSourcePort() != null) {
        neutronPortsBuilder.setSourcePortUuid(flowClassifier.getLogicalSourcePort().getValue());
    }
    if (flowClassifier.getLogicalDestinationPort() != null) {
        neutronPortsBuilder.setDestinationPortUuid(flowClassifier.getLogicalDestinationPort().getValue());
    }
    // currently not supported.
    // if (flowClassifier.getL7Parameter() != null) {
    // }
    MatchesBuilder matchesBuilder = new MatchesBuilder();
    matchesBuilder.setAceType(aceIpBuilder.build());
    matchesBuilder.addAugmentation(NeutronPorts.class, neutronPortsBuilder.build());
    // Set redirect-to-rsp action if rsp name is provided
    if (sfpName != null) {
        redirectToSfcBuilder.setSfpName(sfpName);
        actionsBuilder.addAugmentation(RedirectToSfc.class, redirectToSfcBuilder.build());
        aceBuilder.setActions(actionsBuilder.build());
    }
    aceBuilder.setMatches(matchesBuilder.build());
    // OpenStack networking-sfc don't pass action information
    // with flow classifier. It need to be determined using the
    // Port Chain data and then flow calssifier need to be updated
    // with the actions.
    aceBuilder.setRuleName(aclBuilder.getAclName() + RULE);
    aceBuilder.setKey(new AceKey(aceBuilder.getRuleName()));
    ArrayList<Ace> aceList = new ArrayList<>();
    aceList.add(aceBuilder.build());
    AccessListEntriesBuilder accessListEntriesBuilder = new AccessListEntriesBuilder();
    accessListEntriesBuilder.setAce(aceList);
    aclBuilder.setAccessListEntries(accessListEntriesBuilder.build());
    aclBuilder.setKey(new AclKey(aclBuilder.getAclName(), aclBuilder.getAclType()));
    LOG.info("Translated ACL Flow classfier : {}", aclBuilder.toString());
    return aclBuilder.build();
}
Also used : AceIpv6Builder(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.AceIpv6Builder) Ace(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace) NeutronPortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.sfc.acl.rev150105.NeutronPortsBuilder) AclKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.AclKey) ArrayList(java.util.ArrayList) AclBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.AclBuilder) MatchesBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder) IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) AceKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.AceKey) AccessListEntriesBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.AccessListEntriesBuilder) ActionsBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.ActionsBuilder) AceBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.AceBuilder) DestinationPortRangeBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.DestinationPortRangeBuilder) AceIpBuilder(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.AceIpBuilder) RedirectToSfcBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.sfc.acl.rev150105.RedirectToSfcBuilder) AceIpv4Builder(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.AceIpv4Builder) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) SourcePortRangeBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.SourcePortRangeBuilder)

Aggregations

ArrayList (java.util.ArrayList)27 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)19 AclInterface (org.opendaylight.netvirt.aclservice.api.utils.AclInterface)16 BigInteger (java.math.BigInteger)15 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)15 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)13 AllowedAddressPairs (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs)13 List (java.util.List)12 IpPrefixOrAddress (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress)10 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 Ace (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace)9 Set (java.util.Set)8 Acl (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl)8 Collections (java.util.Collections)7 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)7 MDSALUtil (org.opendaylight.genius.mdsalutil.MDSALUtil)7 NwConstants (org.opendaylight.genius.mdsalutil.NwConstants)7 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)7 MatchEthernetType (org.opendaylight.genius.mdsalutil.matches.MatchEthernetType)7