Search in sources :

Example 46 with Matches

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

the class ConfigurationClassifierImpl method getEntriesForSfpRedirect.

private Set<ClassifierRenderableEntry> getEntriesForSfpRedirect(String ruleName, String srcPort, String dstPort, String sfpName, Matches matches) {
    if (srcPort == null && dstPort == null) {
        LOG.warn("Ace {} ignored: no source or destination port to match against", ruleName);
        return Collections.emptySet();
    }
    if (Objects.equals(srcPort, dstPort)) {
        LOG.warn("Ace {} ignored: equal source and destination port not supported", ruleName);
        return Collections.emptySet();
    }
    List<RenderedServicePath> rsps = sfcProvider.readServicePathState(sfpName).orElse(Collections.emptyList()).stream().map(sfcProvider::getRenderedServicePath).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    // be missing. It will be handled on a later listener event.
    if (rsps.isEmpty()) {
        LOG.debug("Ace {} ignored: no RSPs for SFP {} yet available", ruleName, sfpName);
        return Collections.emptySet();
    }
    // An SFP will have two RSPs associated if symmetric, one otherwise.
    if (rsps.size() > 2) {
        LOG.warn("Ace {} ignored: more than two RSPs associated to SFP {} not supported", ruleName, sfpName);
        return Collections.emptySet();
    }
    RenderedServicePath forwardRsp = rsps.stream().filter(rsp -> !rsp.isReversePath()).findAny().orElse(null);
    RenderedServicePath reverseRsp = rsps.stream().filter(RenderedServicePath::isReversePath).filter(rsp -> forwardRsp != null && rsp.getSymmetricPathId().equals(forwardRsp.getPathId())).findAny().orElse(null);
    if (srcPort != null && forwardRsp == null) {
        LOG.debug("Ace {} ignored: no forward RSP yet available for SFP {} and source port {}", ruleName, sfpName, srcPort);
        return Collections.emptySet();
    }
    if (dstPort != null && reverseRsp == null) {
        LOG.debug("Ace {} ignored: no reverse RSP yet available for SFP {} and destination port {}", ruleName, sfpName, dstPort);
        return Collections.emptySet();
    }
    Set<ClassifierRenderableEntry> entries = new HashSet<>();
    if (srcPort != null) {
        entries.addAll(this.buildEntries(ruleName, Collections.singletonList(srcPort), matches, forwardRsp));
    }
    if (dstPort != null) {
        Matches invertedMatches = AclMatches.invertMatches(matches);
        entries.addAll(this.buildEntries(ruleName, Collections.singletonList(dstPort), invertedMatches, reverseRsp));
    }
    return entries;
}
Also used : Optional(java.util.Optional) 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) AclMatches(org.opendaylight.netvirt.sfc.classifier.utils.AclMatches) ClassifierRenderableEntry(org.opendaylight.netvirt.sfc.classifier.service.domain.api.ClassifierRenderableEntry) RenderedServicePath(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePath) HashSet(java.util.HashSet)

Example 47 with Matches

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

the class ConfigurationClassifierImpl method buildEntries.

private Set<ClassifierRenderableEntry> buildEntries(String ruleName, @NonNull List<String> interfaces, @NonNull Matches matches, @NonNull RenderedServicePath rsp) {
    String rspName = rsp.getName().getValue();
    Long nsp = rsp.getPathId();
    Short nsi = rsp.getStartingIndex();
    Short nsl = rsp.getRenderedServicePathHop() == null ? null : (short) rsp.getRenderedServicePathHop().size();
    if (nsp == null || nsi == null || nsl == null) {
        LOG.warn("Ace {} RSP {} ignored: no valid NSI or NSP or length", ruleName, rspName);
        return Collections.emptySet();
    }
    DpnIdType firstHopDpn = sfcProvider.getFirstHopIngressInterfaceFromRsp(rsp).flatMap(geniusProvider::getDpnIdFromInterfaceName).orElse(null);
    if (firstHopDpn == null) {
        LOG.warn("Ace {} RSP {} ignored: no valid first hop DPN", ruleName, rspName);
        return Collections.emptySet();
    }
    String lastHopInterface = sfcProvider.getLastHopEgressInterfaceFromRsp(rsp).orElse(null);
    if (lastHopInterface == null) {
        LOG.warn("Ace {} RSP {} ignored: has no valid last hop interface", ruleName, rspName);
        return Collections.emptySet();
    }
    DpnIdType lastHopDpn = geniusProvider.getDpnIdFromInterfaceName(lastHopInterface).orElse(null);
    if (lastHopDpn == null) {
        LOG.warn("Ace {} RSP {} ignored: has no valid last hop DPN", ruleName, rspName);
        return Collections.emptySet();
    }
    Map<NodeId, List<InterfaceKey>> nodeToInterfaces = new HashMap<>();
    for (String iface : interfaces) {
        geniusProvider.getNodeIdFromLogicalInterface(iface).ifPresent(nodeId -> nodeToInterfaces.computeIfAbsent(nodeId, key -> new ArrayList<>()).add(new InterfaceKey(iface)));
    }
    LOG.trace("Ace {} RSP {}: got classifier nodes and interfaces: {}", ruleName, rspName, nodeToInterfaces);
    String firstHopIp = geniusProvider.getIpFromDpnId(firstHopDpn).orElse(null);
    Set<ClassifierRenderableEntry> entries = new HashSet<>();
    nodeToInterfaces.forEach((nodeId, ifaces) -> {
        // Get node info
        DpnIdType nodeDpn = new DpnIdType(OpenFlow13Provider.getDpnIdFromNodeId(nodeId));
        String nodeIp = geniusProvider.getIpFromDpnId(nodeDpn).orElse(LOCAL_HOST_IP);
        if (firstHopIp == null && !nodeDpn.equals(firstHopDpn)) {
            LOG.warn("Ace {} RSP {} classifier {} ignored: no IP to reach first hop DPN {}", ruleName, rspName, nodeId, firstHopDpn);
            return;
        }
        // Add entries that are not based on ingress or egress interface
        entries.add(ClassifierEntry.buildNodeEntry(nodeId));
        entries.add(ClassifierEntry.buildPathEntry(nodeId, nsp, nsi, nsl, nodeDpn.equals(firstHopDpn) ? null : firstHopIp));
        // Add entries based on ingress interface
        ifaces.forEach(interfaceKey -> {
            entries.add(ClassifierEntry.buildIngressEntry(interfaceKey));
            entries.add(ClassifierEntry.buildMatchEntry(nodeId, geniusProvider.getNodeConnectorIdFromInterfaceName(interfaceKey.getName()).get(), matches, nsp, nsi));
        });
        // hand-off can happen through the dispatcher table
        if (nodeDpn.equals(lastHopDpn)) {
            entries.add(ClassifierEntry.buildIngressEntry(new InterfaceKey(lastHopInterface)));
        }
        // Egress services must bind to egress ports. Since we dont know before-hand what
        // the egress ports will be, we will bind on all switch ports. If the packet
        // doesnt have NSH, it will be returned to the the egress dispatcher table.
        List<Interfaces> interfaceUuidStrList = geniusProvider.getInterfacesFromNode(nodeId);
        interfaceUuidStrList.forEach(interfaceUuidStr -> {
            InterfaceKey interfaceKey = new InterfaceKey(interfaceUuidStr.getInterfaceName());
            Optional<String> remoteIp = geniusProvider.getRemoteIpAddress(interfaceUuidStr.getInterfaceName());
            entries.add(ClassifierEntry.buildEgressEntry(interfaceKey, remoteIp.orElse(nodeIp)));
        });
    });
    return entries;
}
Also used : HashMap(java.util.HashMap) DpnIdType(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.sfc.sff.logical.rev160620.DpnIdType) Interfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.get.dpn._interface.list.output.Interfaces) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) ClassifierRenderableEntry(org.opendaylight.netvirt.sfc.classifier.service.domain.api.ClassifierRenderableEntry) ArrayList(java.util.ArrayList) List(java.util.List) InterfaceKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey) HashSet(java.util.HashSet)

Example 48 with Matches

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

the class PolicyAceFlowProgrammer method getIngressInterfaceFlow.

private Optional<PolicyAceFlowWrapper> getIngressInterfaceFlow(IngressInterface ingressInterface) {
    String interfaceName = ingressInterface.getName();
    if (interfaceName == null) {
        LOG.error("Invalid ingress interface augmentation. missing interface name");
        return Optional.absent();
    }
    String flowName = "INGRESS_INTERFACE_" + interfaceName;
    int flowPriority = PolicyServiceConstants.POLICY_ACL_TRUNK_INTERFACE_FLOW_PRIOPITY;
    VlanId vlanId = ingressInterface.getVlanId();
    if (vlanId != null) {
        Optional<String> vlanMemberInterfaceOpt = policyServiceUtil.getVlanMemberInterface(interfaceName, vlanId);
        if (!vlanMemberInterfaceOpt.isPresent()) {
            LOG.debug("Vlan member {} missing for trunk {}", vlanId.getValue(), interfaceName);
            return Optional.of(new PolicyAceFlowWrapper(flowName, PolicyAceFlowWrapper.PARTIAL));
        }
        interfaceName = vlanMemberInterfaceOpt.get();
        flowPriority = PolicyServiceConstants.POLICY_ACL_VLAN_INTERFACE_FLOW_PRIOPITY;
    }
    List<MatchInfoBase> matches = policyFlowUtil.getIngressInterfaceMatches(interfaceName);
    if (matches == null || matches.isEmpty()) {
        LOG.debug("Failed to get ingress interface {} matches", interfaceName);
        return Optional.of(new PolicyAceFlowWrapper(flowName, PolicyAceFlowWrapper.PARTIAL));
    }
    BigInteger dpId = interfaceManager.getDpnForInterface(interfaceName);
    if (dpId == null) {
        dpId = BigInteger.ZERO;
    }
    return Optional.of(new PolicyAceFlowWrapper(flowName, matches, flowPriority, dpId));
}
Also used : BigInteger(java.math.BigInteger) VlanId(org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase)

Example 49 with Matches

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

the class PolicyAceFlowProgrammer method getPolicyAceFlowWrapper.

private Optional<PolicyAceFlowWrapper> getPolicyAceFlowWrapper(Matches matches) {
    IngressInterface ingressInterface = matches.getAugmentation(IngressInterface.class);
    if (ingressInterface != null) {
        Optional<PolicyAceFlowWrapper> interfaceFlowOpt = getIngressInterfaceFlow(ingressInterface);
        if (interfaceFlowOpt.isPresent()) {
            return interfaceFlowOpt;
        }
    }
    Service service = matches.getAugmentation(Service.class);
    if (service != null) {
        Optional<PolicyAceFlowWrapper> serviceFlowOpt = getPolicyServiceFlow(service);
        if (serviceFlowOpt.isPresent()) {
            return serviceFlowOpt;
        }
    }
    return Optional.absent();
}
Also used : IngressInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.IngressInterface) Service(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.Service)

Example 50 with Matches

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches in project controller by opendaylight.

the class EventSourceTopic method notifyExistingNodes.

private void notifyExistingNodes(final EventSourceTopology eventSourceTopology) {
    LOG.debug("Notify existing nodes");
    final Pattern nodeRegex = this.nodeIdPattern;
    final ReadOnlyTransaction tx = eventSourceTopology.getDataBroker().newReadOnlyTransaction();
    final ListenableFuture<Optional<Topology>> future = tx.read(LogicalDatastoreType.OPERATIONAL, EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH);
    Futures.addCallback(future, new FutureCallback<Optional<Topology>>() {

        @Override
        public void onSuccess(@Nonnull final Optional<Topology> data) {
            if (data.isPresent()) {
                final List<Node> nodes = data.get().getNode();
                if (nodes != null) {
                    for (final Node node : nodes) {
                        if (nodeRegex.matcher(node.getNodeId().getValue()).matches()) {
                            notifyNode(EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class, node.getKey()));
                        }
                    }
                }
            }
            tx.close();
        }

        @Override
        public void onFailure(final Throwable ex) {
            LOG.error("Can not notify existing nodes", ex);
            tx.close();
        }
    }, MoreExecutors.directExecutor());
}
Also used : NotificationPattern(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern) Pattern(java.util.regex.Pattern) Optional(com.google.common.base.Optional) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) List(java.util.List) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology)

Aggregations

ArrayList (java.util.ArrayList)66 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)31 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)30 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)28 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)22 BigInteger (java.math.BigInteger)21 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)21 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)20 Test (org.junit.Test)18 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)17 List (java.util.List)16 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)16 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)15 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)15 IpPrefixOrAddress (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress)13 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)12 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)10 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)10 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)8 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)8