Search in sources :

Example 1 with PathIntent

use of org.onosproject.net.intent.PathIntent in project onos by opennetworkinglab.

the class PathCompiler method compile.

/**
 * Compiles an intent down to flows.
 *
 * @param creator how to create the flows
 * @param intent intent to process
 * @param flows list of generated flows
 * @param devices list of devices that correspond to the flows
 */
public void compile(PathCompilerCreateFlow<T> creator, PathIntent intent, List<T> flows, List<DeviceId> devices) {
    // Note: right now recompile is not considered
    // TODO: implement recompile behavior
    List<Link> links = intent.path().links();
    Optional<EncapsulationConstraint> encapConstraint = intent.constraints().stream().filter(constraint -> constraint instanceof EncapsulationConstraint).map(x -> (EncapsulationConstraint) x).findAny();
    // if no encapsulation or is involved only a single switch use the default behaviour
    if (!encapConstraint.isPresent() || links.size() == 2) {
        for (int i = 0; i < links.size() - 1; i++) {
            ConnectPoint ingress = links.get(i).dst();
            ConnectPoint egress = links.get(i + 1).src();
            creator.createFlow(intent.selector(), intent.treatment(), ingress, egress, intent.priority(), isLast(links, i), flows, devices);
        }
        return;
    }
    encapConstraint.map(EncapsulationConstraint::encapType).map(type -> {
        switch(type) {
            case VLAN:
                manageVlanEncap(creator, flows, devices, intent);
                break;
            case MPLS:
                manageMplsEncap(creator, flows, devices, intent);
                break;
            default:
        }
        return 0;
    });
}
Also used : EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) Identifier(org.onlab.util.Identifier) LabelAllocator(org.onosproject.net.resource.impl.LabelAllocator) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) Link(org.onosproject.net.Link) ResourceService(org.onosproject.net.resource.ResourceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Map(java.util.Map) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) LinkKey.linkKey(org.onosproject.net.LinkKey.linkKey) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) LinkKey(org.onosproject.net.LinkKey) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MplsLabel(org.onlab.packet.MplsLabel) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Sets(com.google.common.collect.Sets) EthType(org.onlab.packet.EthType) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint)

Example 2 with PathIntent

use of org.onosproject.net.intent.PathIntent in project onos by opennetworkinglab.

the class TrafficMonitorBase method createTrafficLinks.

protected void createTrafficLinks(Highlights highlights, TrafficLinkMap linkMap, Set<Intent> intents, LinkHighlight.Flavor flavor, boolean showTraffic) {
    for (Intent intent : intents) {
        List<Intent> installables = services.intent().getInstallableIntents(intent.key());
        Iterable<Link> links = null;
        if (installables != null) {
            for (Intent installable : installables) {
                if (installable instanceof PathIntent) {
                    links = ((PathIntent) installable).path().links();
                } else if (installable instanceof FlowRuleIntent) {
                    Collection<Link> l = new ArrayList<>();
                    l.addAll(linkResources(installable));
                    // Add cross connect links
                    if (intent instanceof OpticalConnectivityIntent) {
                        OpticalConnectivityIntent ocIntent = (OpticalConnectivityIntent) intent;
                        LinkService linkService = services.link();
                        DeviceService deviceService = services.device();
                        l.addAll(linkService.getDeviceIngressLinks(ocIntent.getSrc().deviceId()).stream().filter(i -> deviceService.getDevice(i.src().deviceId()).type() == Device.Type.SWITCH).collect(Collectors.toList()));
                        l.addAll(linkService.getDeviceEgressLinks(ocIntent.getDst().deviceId()).stream().filter(e -> deviceService.getDevice(e.dst().deviceId()).type() == Device.Type.SWITCH).collect(Collectors.toList()));
                    }
                    links = l;
                } else if (installable instanceof FlowObjectiveIntent) {
                    links = linkResources(installable);
                } else if (installable instanceof LinkCollectionIntent) {
                    links = ((LinkCollectionIntent) installable).links();
                } else if (installable instanceof OpticalPathIntent) {
                    links = ((OpticalPathIntent) installable).path().links();
                }
                if (links == null) {
                    links = Lists.newArrayList();
                }
                links = addEdgeLinksIfNeeded(intent, Lists.newArrayList(links));
                boolean isOptical = intent instanceof OpticalConnectivityIntent;
                processLinks(linkMap, links, flavor, isOptical, showTraffic);
                updateHighlights(highlights, links);
            }
        }
    }
}
Also used : Mode(org.onosproject.ui.impl.TrafficMonitorBase.Mode) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) ElementId(org.onosproject.net.ElementId) Highlights(org.onosproject.ui.topo.Highlights) Timer(java.util.Timer) Link(org.onosproject.net.Link) DefaultEdgeLink(org.onosproject.net.DefaultEdgeLink) PACKETS(org.onosproject.net.statistic.PortStatisticsService.MetricType.PACKETS) ServicesBundle(org.onosproject.ui.impl.topo.util.ServicesBundle) TimerTask(java.util.TimerTask) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Device(org.onosproject.net.Device) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) TrafficLink(org.onosproject.ui.impl.topo.util.TrafficLink) OpticalPathIntent(org.onosproject.net.intent.OpticalPathIntent) LinkHighlight(org.onosproject.ui.topo.LinkHighlight) Collection(java.util.Collection) Set(java.util.Set) BYTES(org.onosproject.net.statistic.PortStatisticsService.MetricType.BYTES) IntentSelection(org.onosproject.ui.impl.topo.util.IntentSelection) Collectors(java.util.stream.Collectors) List(java.util.List) LinkService(org.onosproject.net.link.LinkService) DeviceId(org.onosproject.net.DeviceId) TopoologyTrafficMessageHandlerAbstract(org.onosproject.ui.impl.topo.TopoologyTrafficMessageHandlerAbstract) AbstractTopoMonitor(org.onosproject.ui.topo.AbstractTopoMonitor) DeviceHighlight(org.onosproject.ui.topo.DeviceHighlight) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Host(org.onosproject.net.Host) TrafficLinkMap(org.onosproject.ui.impl.topo.util.TrafficLinkMap) UiExtensionService(org.onosproject.ui.UiExtensionService) MetricType(org.onosproject.net.statistic.PortStatisticsService.MetricType) Load(org.onosproject.net.statistic.Load) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) UiTopoHighlighterFactory(org.onosproject.ui.UiTopoHighlighterFactory) HostHighlight(org.onosproject.ui.topo.HostHighlight) NodeHighlight(org.onosproject.ui.topo.NodeHighlight) Intent(org.onosproject.net.intent.Intent) UiTopoHighlighter(org.onosproject.ui.UiTopoHighlighter) HostId(org.onosproject.net.HostId) PathIntent(org.onosproject.net.intent.PathIntent) Logger(org.slf4j.Logger) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) DefaultEdgeLink.createEdgeLinks(org.onosproject.net.DefaultEdgeLink.createEdgeLinks) TopoIntentFilter(org.onosproject.ui.impl.topo.util.TopoIntentFilter) NodeSelection(org.onosproject.ui.topo.NodeSelection) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) Collections(java.util.Collections) TopoUtils(org.onosproject.ui.topo.TopoUtils) OpticalPathIntent(org.onosproject.net.intent.OpticalPathIntent) PathIntent(org.onosproject.net.intent.PathIntent) OpticalPathIntent(org.onosproject.net.intent.OpticalPathIntent) DeviceService(org.onosproject.net.device.DeviceService) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) OpticalPathIntent(org.onosproject.net.intent.OpticalPathIntent) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Collection(java.util.Collection) LinkService(org.onosproject.net.link.LinkService) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) Link(org.onosproject.net.Link) DefaultEdgeLink(org.onosproject.net.DefaultEdgeLink) TrafficLink(org.onosproject.ui.impl.topo.util.TrafficLink) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 3 with PathIntent

use of org.onosproject.net.intent.PathIntent in project onos by opennetworkinglab.

the class TopoIntentFilter method isIntentRelevant.

// Indicates whether the specified intent involves all of the given edge points.
private boolean isIntentRelevant(OpticalConnectivityIntent opticalIntent, Iterable<Intent> intents) {
    Link ccSrc = getFirstLink(opticalIntent.getSrc(), false);
    Link ccDst = getFirstLink(opticalIntent.getDst(), true);
    if (ccSrc == null || ccDst == null) {
        return false;
    }
    for (Intent intent : intents) {
        List<Intent> installables = intentService.getInstallableIntents(intent.key());
        for (Intent installable : installables) {
            if (installable instanceof PathIntent) {
                List<Link> links = ((PathIntent) installable).path().links();
                if (links.size() == 3) {
                    Link tunnel = links.get(1);
                    if (Objects.equals(tunnel.src(), ccSrc.src()) && Objects.equals(tunnel.dst(), ccDst.dst())) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : PathIntent(org.onosproject.net.intent.PathIntent) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) Link(org.onosproject.net.Link)

Example 4 with PathIntent

use of org.onosproject.net.intent.PathIntent in project onos by opennetworkinglab.

the class IntentsListCommand method detailsFormat.

/**
 * Returns detailed information text about a specific intent.
 *
 * @param intent to print
 * @param state of intent
 * @return detailed information or "" if {@code state} was null
 */
private StringBuilder detailsFormat(Intent intent, IntentState state) {
    StringBuilder builder = new StringBuilder();
    if (state == null) {
        return builder;
    }
    if (!intent.resources().isEmpty()) {
        builder.append('\n').append(format(RESOURCES, intent.resources()));
    }
    if (intent instanceof ConnectivityIntent) {
        ConnectivityIntent ci = (ConnectivityIntent) intent;
        if (!ci.selector().criteria().isEmpty()) {
            builder.append('\n').append(format(COMMON_SELECTOR, formatSelector(ci.selector())));
        }
        if (!ci.treatment().allInstructions().isEmpty()) {
            builder.append('\n').append(format(TREATMENT, ci.treatment().allInstructions()));
        }
        if (ci.constraints() != null && !ci.constraints().isEmpty()) {
            builder.append('\n').append(format(CONSTRAINTS, ci.constraints()));
        }
    }
    if (intent instanceof HostToHostIntent) {
        HostToHostIntent pi = (HostToHostIntent) intent;
        builder.append('\n').append(format(SRC + HOST, pi.one()));
        builder.append('\n').append(format(DST + HOST, pi.two()));
    } else if (intent instanceof PointToPointIntent) {
        PointToPointIntent pi = (PointToPointIntent) intent;
        builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
        builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
    } else if (intent instanceof MultiPointToSinglePointIntent) {
        MultiPointToSinglePointIntent pi = (MultiPointToSinglePointIntent) intent;
        builder.append('\n').append(formatFilteredCps(pi.filteredIngressPoints(), INGRESS));
        builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
    } else if (intent instanceof SinglePointToMultiPointIntent) {
        SinglePointToMultiPointIntent pi = (SinglePointToMultiPointIntent) intent;
        builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
        builder.append('\n').append(formatFilteredCps(pi.filteredEgressPoints(), EGRESS));
    } else if (intent instanceof PathIntent) {
        PathIntent pi = (PathIntent) intent;
        builder.append(format("path=%s, cost=%f", pi.path().links(), pi.path().cost()));
    } else if (intent instanceof LinkCollectionIntent) {
        LinkCollectionIntent li = (LinkCollectionIntent) intent;
        builder.append('\n').append(format("links=%s", li.links()));
        builder.append('\n').append(format(CP, li.egressPoints()));
    } else if (intent instanceof OpticalCircuitIntent) {
        OpticalCircuitIntent ci = (OpticalCircuitIntent) intent;
        builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
        builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
        builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
    } else if (intent instanceof OpticalConnectivityIntent) {
        OpticalConnectivityIntent ci = (OpticalConnectivityIntent) intent;
        builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
        builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
        builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
        builder.append('\n').append(format("ochSignal=%s", ci.ochSignal()));
    } else if (intent instanceof OpticalOduIntent) {
        OpticalOduIntent ci = (OpticalOduIntent) intent;
        builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
        builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
        builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
    }
    List<Intent> installable = service.getInstallableIntents(intent.key()).stream().filter(i -> contentFilter.filter(i)).collect(Collectors.toList());
    if (showInstallable && installable != null && !installable.isEmpty()) {
        builder.append('\n').append(format(INSTALLABLE, installable));
    }
    return builder;
}
Also used : StringFilter(org.onlab.util.StringFilter) StringUtils(org.apache.commons.lang.StringUtils) Tools(org.onlab.util.Tools) IntentState(org.onosproject.net.intent.IntentState) HashMap(java.util.HashMap) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) IntentService(org.onosproject.net.intent.IntentService) Map(java.util.Map) Intent(org.onosproject.net.intent.Intent) JsonNode(com.fasterxml.jackson.databind.JsonNode) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) Criterion(org.onosproject.net.flow.criteria.Criterion) NodeId(org.onosproject.cluster.NodeId) PathIntent(org.onosproject.net.intent.PathIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) WordUtils.uncapitalize(org.apache.commons.lang3.text.WordUtils.uncapitalize) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) Key(org.onosproject.net.intent.Key) List(java.util.List) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) Service(org.apache.karaf.shell.api.action.lifecycle.Service) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) OpticalOduIntent(org.onosproject.net.intent.OpticalOduIntent) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) Option(org.apache.karaf.shell.api.action.Option) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) PathIntent(org.onosproject.net.intent.PathIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) OpticalOduIntent(org.onosproject.net.intent.OpticalOduIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) OpticalOduIntent(org.onosproject.net.intent.OpticalOduIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent)

Example 5 with PathIntent

use of org.onosproject.net.intent.PathIntent in project onos by opennetworkinglab.

the class PathCompiler method manageVlanEncap.

/**
 * Creates the flow rules for the path intent using VLAN
 * encapsulation.
 *
 * @param creator the flowrules creator
 * @param flows the list of flows to fill
 * @param devices the devices on the path
 * @param intent the PathIntent to compile
 */
private void manageVlanEncap(PathCompilerCreateFlow<T> creator, List<T> flows, List<DeviceId> devices, PathIntent intent) {
    Set<Link> linksSet = Sets.newConcurrentHashSet();
    for (int i = 1; i <= intent.path().links().size() - 2; i++) {
        linksSet.add(intent.path().links().get(i));
    }
    Map<LinkKey, Identifier<?>> vlanIds = labelAllocator.assignLabelToLinks(linksSet, intent.key(), EncapsulationType.VLAN);
    Iterator<Link> links = intent.path().links().iterator();
    Link srcLink = links.next();
    Link link = links.next();
    // Ingress traffic
    VlanId vlanId = (VlanId) vlanIds.get(linkKey(link));
    if (vlanId == null) {
        throw new IntentCompilationException(ERROR_VLAN + link);
    }
    VlanId prevVlanId = vlanId;
    Optional<VlanIdCriterion> vlanCriterion = intent.selector().criteria().stream().filter(criterion -> criterion.type() == Criterion.Type.VLAN_VID).map(criterion -> (VlanIdCriterion) criterion).findAny();
    // Push VLAN if selector does not include VLAN
    TrafficTreatment.Builder treatBuilder = DefaultTrafficTreatment.builder();
    if (!vlanCriterion.isPresent()) {
        treatBuilder.pushVlan();
    }
    // Tag the traffic with the new encapsulation VLAN
    treatBuilder.setVlanId(vlanId);
    creator.createFlow(intent.selector(), treatBuilder.build(), srcLink.dst(), link.src(), intent.priority(), true, flows, devices);
    ConnectPoint prev = link.dst();
    while (links.hasNext()) {
        link = links.next();
        if (links.hasNext()) {
            // Transit traffic
            VlanId egressVlanId = (VlanId) vlanIds.get(linkKey(link));
            if (egressVlanId == null) {
                throw new IntentCompilationException(ERROR_VLAN + link);
            }
            TrafficSelector transitSelector = DefaultTrafficSelector.builder().matchInPort(prev.port()).matchVlanId(prevVlanId).build();
            TrafficTreatment.Builder transitTreat = DefaultTrafficTreatment.builder();
            // Set the new vlanId only if the previous one is different
            if (!prevVlanId.equals(egressVlanId)) {
                transitTreat.setVlanId(egressVlanId);
            }
            creator.createFlow(transitSelector, transitTreat.build(), prev, link.src(), intent.priority(), true, flows, devices);
            /* For the next hop we have to remember
                 * the previous egress VLAN id and the egress
                 * node
                 */
            prevVlanId = egressVlanId;
            prev = link.dst();
        } else {
            // Egress traffic
            TrafficSelector egressSelector = DefaultTrafficSelector.builder().matchInPort(prev.port()).matchVlanId(prevVlanId).build();
            TrafficTreatment.Builder egressTreat = DefaultTrafficTreatment.builder(intent.treatment());
            Optional<L2ModificationInstruction.ModVlanIdInstruction> modVlanIdInstruction = intent.treatment().allInstructions().stream().filter(instruction -> instruction instanceof L2ModificationInstruction.ModVlanIdInstruction).map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x).findAny();
            Optional<L2ModificationInstruction.ModVlanHeaderInstruction> popVlanInstruction = intent.treatment().allInstructions().stream().filter(instruction -> instruction instanceof L2ModificationInstruction.ModVlanHeaderInstruction).map(x -> (L2ModificationInstruction.ModVlanHeaderInstruction) x).findAny();
            if (!modVlanIdInstruction.isPresent() && !popVlanInstruction.isPresent()) {
                if (vlanCriterion.isPresent()) {
                    egressTreat.setVlanId(vlanCriterion.get().vlanId());
                } else {
                    egressTreat.popVlan();
                }
            }
            creator.createFlow(egressSelector, egressTreat.build(), prev, link.src(), intent.priority(), true, flows, devices);
        }
    }
}
Also used : MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) Identifier(org.onlab.util.Identifier) LabelAllocator(org.onosproject.net.resource.impl.LabelAllocator) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) Link(org.onosproject.net.Link) ResourceService(org.onosproject.net.resource.ResourceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Map(java.util.Map) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) LinkKey.linkKey(org.onosproject.net.LinkKey.linkKey) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) LinkKey(org.onosproject.net.LinkKey) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MplsLabel(org.onlab.packet.MplsLabel) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Sets(com.google.common.collect.Sets) EthType(org.onlab.packet.EthType) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) LinkKey(org.onosproject.net.LinkKey) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Identifier(org.onlab.util.Identifier) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) Link(org.onosproject.net.Link) VlanId(org.onlab.packet.VlanId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Aggregations

PathIntent (org.onosproject.net.intent.PathIntent)6 List (java.util.List)5 Set (java.util.Set)5 Link (org.onosproject.net.Link)5 Sets (com.google.common.collect.Sets)4 Map (java.util.Map)4 ConnectPoint (org.onosproject.net.ConnectPoint)4 DeviceId (org.onosproject.net.DeviceId)4 Logger (org.slf4j.Logger)4 Iterator (java.util.Iterator)3 Optional (java.util.Optional)3 EthType (org.onlab.packet.EthType)3 Ethernet (org.onlab.packet.Ethernet)3 MplsLabel (org.onlab.packet.MplsLabel)3 VlanId (org.onlab.packet.VlanId)3 Identifier (org.onlab.util.Identifier)3 EncapsulationType (org.onosproject.net.EncapsulationType)3 LinkKey (org.onosproject.net.LinkKey)3 TrafficSelector (org.onosproject.net.flow.TrafficSelector)3 Criterion (org.onosproject.net.flow.criteria.Criterion)3