Search in sources :

Example 16 with LinkCollectionIntent

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

the class HostToHostIntentCompilerTest method testSingleLongPathCompilation.

/**
 * Tests a pair of hosts with 8 hops between them.
 */
@Test
public void testSingleLongPathCompilation() {
    HostToHostIntent intent = makeIntent(HOST_ONE, HOST_TWO);
    assertThat(intent, is(notNullValue()));
    String[] hops = { HOST_ONE, S1, S2, S3, S4, S5, S6, S7, S8, HOST_TWO };
    HostToHostIntentCompiler compiler = makeCompiler(hops);
    assertThat(compiler, is(notNullValue()));
    List<Intent> result = compiler.compile(intent, null);
    assertThat(result, is(Matchers.notNullValue()));
    assertThat(result, hasSize(2));
    Intent forwardIntent = result.get(0);
    assertThat(forwardIntent instanceof LinkCollectionIntent, is(true));
    Intent reverseIntent = result.get(1);
    assertThat(reverseIntent instanceof LinkCollectionIntent, is(true));
    LinkCollectionIntent forwardLCIntent = (LinkCollectionIntent) forwardIntent;
    Set<Link> links = forwardLCIntent.links();
    assertThat(links, hasSize(7));
    Set<FilteredConnectPoint> ingressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S1, PORT_1)));
    assertThat(forwardLCIntent.filteredIngressPoints(), is(ingressPoints));
    assertThat(links, linksHasPath(S1, S2));
    assertThat(links, linksHasPath(S2, S3));
    assertThat(links, linksHasPath(S3, S4));
    assertThat(links, linksHasPath(S4, S5));
    assertThat(links, linksHasPath(S5, S6));
    assertThat(links, linksHasPath(S6, S7));
    assertThat(links, linksHasPath(S7, S8));
    Set<FilteredConnectPoint> egressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S8, PORT_2)));
    assertThat(forwardLCIntent.filteredEgressPoints(), is(egressPoints));
    LinkCollectionIntent reverseLCIntent = (LinkCollectionIntent) reverseIntent;
    links = reverseLCIntent.links();
    assertThat(reverseLCIntent.links(), hasSize(7));
    ingressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S8, PORT_2)));
    assertThat(reverseLCIntent.filteredIngressPoints(), is(ingressPoints));
    assertThat(links, linksHasPath(S2, S1));
    assertThat(links, linksHasPath(S3, S2));
    assertThat(links, linksHasPath(S4, S3));
    assertThat(links, linksHasPath(S5, S4));
    assertThat(links, linksHasPath(S6, S5));
    assertThat(links, linksHasPath(S7, S6));
    assertThat(links, linksHasPath(S8, S7));
    egressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S1, PORT_1)));
    assertThat(reverseLCIntent.filteredEgressPoints(), is(egressPoints));
    assertThat("key is inherited", result.stream().map(Intent::key).collect(Collectors.toList()), everyItem(is(intent.key())));
}
Also used : HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) Intent(org.onosproject.net.intent.Intent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) Link(org.onosproject.net.Link) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 17 with LinkCollectionIntent

use of org.onosproject.net.intent.LinkCollectionIntent 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 18 with LinkCollectionIntent

use of org.onosproject.net.intent.LinkCollectionIntent 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 19 with LinkCollectionIntent

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

the class LinkCollectionCompiler method manageMpIntent.

/**
 * Manages the Intents with multiple ingress points creating properly
 * the selector builder and the treatment builder.
 *
 * @param selectorBuilder the selector builder to update
 * @param treatmentBuilder the treatment builder to update
 * @param intent the intent to compile
 * @param inPort the input port of the current device
 * @param deviceId the current device
 * @param outPorts the output ports of this device
 */
private void manageMpIntent(TrafficSelector.Builder selectorBuilder, TrafficTreatment.Builder treatmentBuilder, LinkCollectionIntent intent, PortNumber inPort, DeviceId deviceId, Set<PortNumber> outPorts) {
    /*
         * Sanity check
         */
    if (intent.filteredEgressPoints().size() != 1) {
        throw new IntentCompilationException(WRONG_EGRESS);
    }
    /*
         * We try to understand if the device is one of the ingress points.
         */
    Optional<FilteredConnectPoint> filteredIngressPoint = getFilteredConnectPointFromIntent(deviceId, inPort, intent);
    /*
         * We retrieve from the Intent the unique egress points.
         */
    Optional<FilteredConnectPoint> filteredEgressPoint = intent.filteredEgressPoints().stream().findFirst();
    /*
         * We check if the device is the ingress device
         */
    if (filteredIngressPoint.isPresent()) {
        /*
             * We are at ingress, so basically what we have to do is this:
             * apply a set of operations (treatment, FEP) in order to have
             * a transition from the initial state to the final state.
             *
             * We initialize the treatment with the Intent treatment
             */
        intent.treatment().allInstructions().stream().filter(inst -> inst.type() != Instruction.Type.NOACTION).forEach(treatmentBuilder::add);
        /*
             * We build the final selector, adding the selector
             * of the FIP to the Intent selector and potentially
             * overriding its matches.
             */
        filteredIngressPoint.get().trafficSelector().criteria().forEach(selectorBuilder::add);
        /*
             * We define the transition FIP->FEP, basically
             * the set of the operations we need for reaching
             * the final state.
             */
        TrafficTreatment forwardingTreatment = forwardingTreatment(filteredIngressPoint.get().trafficSelector(), filteredEgressPoint.get().trafficSelector(), getEthType(intent.selector()));
        /*
             * We add to the treatment the actions necessary for the
             * transition, potentially overriding the treatment of the
             * Intent. The Intent treatment has always a low priority
             * in respect of the FEP.
             */
        forwardingTreatment.allInstructions().stream().filter(inst -> inst.type() != Instruction.Type.NOACTION).forEach(treatmentBuilder::add);
    } else {
        /*
             * We are in the core or in the egress switch.
             * The packets are in their final state. We need
             * to match against this final state.
             *
             * we derive the final state defined by the intent
             * treatment.
             */
        updateBuilder(selectorBuilder, intent.treatment());
        /*
             * We derive the final state defined by the unique
             * FEP. We merge the two states.
             */
        filteredEgressPoint.get().trafficSelector().criteria().forEach(selectorBuilder::add);
    }
    /*
         * Finally we set the output action.
         */
    outPorts.forEach(treatmentBuilder::setOutput);
}
Also used : PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) ModIPv6FlowLabelInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) Map(java.util.Map) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Ip4Address(org.onlab.packet.Ip4Address) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Set(java.util.Set) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) EthType(org.onlab.packet.EthType) ModTransportPortInstruction(org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) ModTunnelIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) IpPrefix(org.onlab.packet.IpPrefix) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) Identifier(org.onlab.util.Identifier) L4ModificationInstruction(org.onosproject.net.flow.instructions.L4ModificationInstruction) LabelAllocator(org.onosproject.net.resource.impl.LabelAllocator) ModMplsLabelInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction) DomainConstraint(org.onosproject.net.intent.constraint.DomainConstraint) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) ModIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction) ModArpIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) ModVlanPcpInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction) Type(org.onosproject.net.flow.criteria.Criterion.Type) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) DomainService(org.onosproject.net.domain.DomainService) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) DomainPointToPointIntent(org.onosproject.net.domain.DomainPointToPointIntent) Intent(org.onosproject.net.intent.Intent) LOCAL(org.onosproject.net.domain.DomainId.LOCAL) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ModMplsBosInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsBosInstruction) Logger(org.slf4j.Logger) MplsLabel(org.onlab.packet.MplsLabel) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) ModArpEthInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) Maps(com.google.common.collect.Maps) SetMultimap(com.google.common.collect.SetMultimap) DomainId(org.onosproject.net.domain.DomainId) L1ModificationInstruction(org.onosproject.net.flow.instructions.L1ModificationInstruction) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) ModArpOpInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 20 with LinkCollectionIntent

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

the class LinkCollectionCompiler method getDomainIntents.

/**
 * Creates the domain intents that the {@link LinkCollectionIntent} contains.
 *
 * @param intent        the link collection intent
 * @param domainService the domain service
 * @return the resulting list of domain intents
 */
protected List<Intent> getDomainIntents(LinkCollectionIntent intent, DomainService domainService) {
    ImmutableList.Builder<Intent> intentList = ImmutableList.builder();
    // TODO: support multi point to multi point
    if (intent.filteredIngressPoints().size() != 1 || intent.filteredEgressPoints().size() != 1) {
        log.warn("Multiple ingress or egress ports not supported!");
        return intentList.build();
    }
    ImmutableList.Builder<Link> domainLinks = ImmutableList.builder();
    // get the initial ingress connection point
    FilteredConnectPoint ingress = intent.filteredIngressPoints().iterator().next();
    FilteredConnectPoint egress;
    DeviceId currentDevice = ingress.connectPoint().deviceId();
    // the current domain (or LOCAL)
    DomainId currentDomain = domainService.getDomain(currentDevice);
    // if we entered a domain store the domain ingress
    FilteredConnectPoint domainIngress = LOCAL.equals(currentDomain) ? null : ingress;
    // this is necessary because a set is not sorted by default
    for (int i = 0; i < intent.links().size(); i++) {
        // find the next link
        List<Link> nextLinks = getEgressLinks(intent.links(), currentDevice);
        // no matching link exists
        if (nextLinks.isEmpty()) {
            throw new IntentCompilationException("No matching link starting at " + ingress.connectPoint().deviceId());
        }
        // get the first link
        Link nextLink = nextLinks.get(0);
        ingress = new FilteredConnectPoint(nextLink.src());
        egress = new FilteredConnectPoint(nextLink.dst());
        // query the domain for the domain of the link's destination
        DomainId dstDomain = domainService.getDomain(egress.connectPoint().deviceId());
        if (!currentDomain.equals(dstDomain)) {
            // we are leaving the current domain or LOCAL
            log.debug("Domain transition from {} to {}.", currentDomain, dstDomain);
            if (!LOCAL.equals(currentDomain)) {
                // add the domain intent to the intent list
                intentList.add(createDomainP2PIntent(intent, domainIngress, ingress, domainLinks.build()));
                // TODO: might end up with an unused builder
                // reset domain links builder
                domainLinks = ImmutableList.builder();
            }
            // update current domain (might be LOCAL)
            currentDomain = dstDomain;
            // update the domain's ingress
            domainIngress = LOCAL.equals(currentDomain) ? null : egress;
        } else {
            if (!LOCAL.equals(currentDomain)) {
                // we are staying in the same domain, store the traversed link
                domainLinks.add(nextLink);
                log.debug("{} belongs to the same domain.", egress.connectPoint().deviceId());
            }
        }
        currentDevice = egress.connectPoint().deviceId();
    }
    // get the egress point
    egress = intent.filteredEgressPoints().iterator().next();
    // still inside a domain?
    if (!LOCAL.equals(currentDomain) && currentDomain.equals(domainService.getDomain(egress.connectPoint().deviceId()))) {
        // add intent
        intentList.add(createDomainP2PIntent(intent, domainIngress, egress, domainLinks.build()));
    }
    return intentList.build();
}
Also used : DomainId(org.onosproject.net.domain.DomainId) ImmutableList(com.google.common.collect.ImmutableList) DeviceId(org.onosproject.net.DeviceId) DomainPointToPointIntent(org.onosproject.net.domain.DomainPointToPointIntent) Intent(org.onosproject.net.intent.Intent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) DomainConstraint(org.onosproject.net.intent.constraint.DomainConstraint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Aggregations

LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)39 Intent (org.onosproject.net.intent.Intent)37 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)35 ConnectPoint (org.onosproject.net.ConnectPoint)29 Test (org.junit.Test)27 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)20 Link (org.onosproject.net.Link)16 TrafficSelector (org.onosproject.net.flow.TrafficSelector)15 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)12 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)11 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)11 FlowObjectiveIntent (org.onosproject.net.intent.FlowObjectiveIntent)10 ImmutableList (com.google.common.collect.ImmutableList)9 DeviceId (org.onosproject.net.DeviceId)9 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)9 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)9 NextObjective (org.onosproject.net.flowobjective.NextObjective)9 Objective (org.onosproject.net.flowobjective.Objective)9 Set (java.util.Set)8 SinglePointToMultiPointIntent (org.onosproject.net.intent.SinglePointToMultiPointIntent)8