Search in sources :

Example 6 with FlowRuleIntent

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

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

the class PathIntentCompiler method compile.

@Override
public List<Intent> compile(PathIntent intent, List<Intent> installable) {
    List<FlowRule> rules = new LinkedList<>();
    List<DeviceId> devices = new LinkedList<>();
    compile(this, intent, rules, devices);
    return ImmutableList.of(new FlowRuleIntent(appId, intent.key(), rules, intent.resources(), intent.type(), intent.resourceGroup()));
}
Also used : DeviceId(org.onosproject.net.DeviceId) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) LinkedList(java.util.LinkedList) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 8 with FlowRuleIntent

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

the class PointToPointIntentCompiler method setPathsToRemove.

/**
 * Sets instance variables erasePrimary and eraseBackup. If erasePrimary,
 * the primary path is no longer viable and related intents will be deleted.
 * If eraseBackup, the backup path is no longer viable and related intents
 * will be deleted.
 *
 * @param intent  intent whose resources are found to be disabled/inactive:
 *                if intent is part of primary path, primary path set for removal;
 *                if intent is part of backup path, backup path set for removal;
 *                if bad intent is of type failover, the ingress point is down,
 *                and both paths are rendered inactive.
 * @return        true if both primary and backup paths are to be removed
 */
private boolean setPathsToRemove(Intent intent) {
    if (intent instanceof FlowRuleIntent) {
        FlowRuleIntent frIntent = (FlowRuleIntent) intent;
        PathIntent.ProtectionType type = frIntent.type();
        if (type == PathIntent.ProtectionType.PRIMARY || type == PathIntent.ProtectionType.FAILOVER) {
            erasePrimary = true;
        }
        if (type == PathIntent.ProtectionType.BACKUP || type == PathIntent.ProtectionType.FAILOVER) {
            eraseBackup = true;
        }
    }
    return erasePrimary && eraseBackup;
}
Also used : PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 9 with FlowRuleIntent

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

the class PointToPointIntentCompiler method createProtectedIntent.

// FIXME: Compatibility with EncapsulationConstraint
private List<Intent> createProtectedIntent(ConnectPoint ingressPoint, ConnectPoint egressPoint, PointToPointIntent intent, List<Intent> installable) {
    log.trace("createProtectedIntent");
    DisjointPath path = getDisjointPath(intent, ingressPoint.deviceId(), egressPoint.deviceId());
    List<Intent> reusableIntents = null;
    if (installable != null) {
        reusableIntents = filterInvalidSubIntents(installable, intent);
        if (reusableIntents.size() == installable.size()) {
            // all old paths are still viable
            return installable;
        }
    }
    List<Intent> intentList = new ArrayList<>();
    // primary path intent
    List<Link> links = new ArrayList<>();
    links.addAll(path.links());
    links.add(createEdgeLink(egressPoint, false));
    // backup path intent
    List<Link> backupLinks = new ArrayList<>();
    backupLinks.addAll(path.backup().links());
    backupLinks.add(createEdgeLink(egressPoint, false));
    /*
         * One of the old paths is still entirely intact. This old path has
         * already been made primary, so we must add a backup path intent
         * and modify the failover group treatment accordingly.
         */
    if (reusableIntents != null && reusableIntents.size() > 1) {
        /*
             * Ensures that the egress port on source device is different than
             * that of existing path so that failover group will be useful
             * (would not be useful if both output ports in group bucket were
             * the same). Does not necessarily ensure that the new backup path
             * is entirely disjoint from the old path.
             */
        PortNumber primaryPort = getPrimaryPort(intent);
        if (primaryPort != null && !links.get(0).src().port().equals(primaryPort)) {
            reusableIntents.add(createPathIntent(new DefaultPath(PID, links, path.weight(), path.annotations()), intent, PathIntent.ProtectionType.BACKUP));
            updateFailoverGroup(intent, links);
            return reusableIntents;
        } else {
            reusableIntents.add(createPathIntent(new DefaultPath(PID, backupLinks, path.backup().weight(), path.backup().annotations()), intent, PathIntent.ProtectionType.BACKUP));
            updateFailoverGroup(intent, backupLinks);
            return reusableIntents;
        }
    }
    intentList.add(createPathIntent(new DefaultPath(PID, links, path.weight(), path.annotations()), intent, PathIntent.ProtectionType.PRIMARY));
    intentList.add(createPathIntent(new DefaultPath(PID, backupLinks, path.backup().weight(), path.backup().annotations()), intent, PathIntent.ProtectionType.BACKUP));
    // add contents appropriately.
    if (groupService.getGroup(ingressPoint.deviceId(), makeGroupKey(intent.id())) == null) {
        // manufactured fast failover flow rule intent
        createFailoverTreatmentGroup(path.links(), path.backup().links(), intent);
        FlowRuleIntent frIntent = new FlowRuleIntent(intent.appId(), intent.key(), createFailoverFlowRules(intent), asList(ingressPoint.deviceId()), PathIntent.ProtectionType.FAILOVER, intent.resourceGroup());
        intentList.add(frIntent);
    } else {
        updateFailoverGroup(intent, links);
        updateFailoverGroup(intent, backupLinks);
    }
    return intentList;
}
Also used : ArrayList(java.util.ArrayList) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) DefaultPath(org.onosproject.net.DefaultPath) PortNumber(org.onosproject.net.PortNumber) DisjointPath(org.onosproject.net.DisjointPath) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) Link(org.onosproject.net.Link) EdgeLink(org.onosproject.net.EdgeLink) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 10 with FlowRuleIntent

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

the class LinkCollectionOptimizationTest method testOptimizationCoLocatedPointsTrivialForSp.

/**
 * We test the proper optimization of sp2mp with trivial selector,
 * trivial treatment, vlan encapsulation and co-located
 * ingress/egress points.
 */
@Test
public void testOptimizationCoLocatedPointsTrivialForSp() {
    intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc).constraints(constraintsForVlan).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11), new FilteredConnectPoint(d2p10), new FilteredConnectPoint(d3p10))).build();
    sut.activate();
    /*
         * We use the FIRST_FIT to simplify tests.
         */
    LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
    List<Intent> compiled = sut.compile(intent, Collections.emptyList());
    assertThat(compiled, hasSize(1));
    Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
    assertThat(rules, hasSize(3));
    Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS1, hasSize(1));
    FlowRule ruleS1 = rulesS1.iterator().next();
    assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(selector).matchInPort(d1p10.port()).build()));
    assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().pushVlan().setVlanId(VlanId.vlanId(LABEL)).setOutput(d1p0.port()).popVlan().setOutput(d1p11.port()).build()));
    Collection<FlowRule> rulesS2 = rules.stream().filter(rule -> rule.deviceId().equals(d2p0.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS2, hasSize(1));
    FlowRule ruleS2 = rulesS2.iterator().next();
    assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p0.port()).matchVlanId(VlanId.vlanId(LABEL)).build()));
    assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId(LABEL)).setOutput(d2p1.port()).popVlan().setOutput(d2p10.port()).build()));
    Collection<FlowRule> rulesS3 = rules.stream().filter(rule -> rule.deviceId().equals(d3p1.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS3, hasSize(1));
    FlowRule ruleS3 = rulesS3.iterator().next();
    assertThat(ruleS3.selector(), is(DefaultTrafficSelector.builder().matchInPort(d3p0.port()).matchVlanId(VlanId.vlanId(LABEL)).build()));
    assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().popVlan().setOutput(d3p10.port()).build()));
    sut.deactivate();
}
Also used : MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) APP_ID(org.onosproject.net.NetTestTools.APP_ID) CoreService(org.onosproject.core.CoreService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Ethernet(org.onlab.packet.Ethernet) DomainService(org.onosproject.net.domain.DomainService) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) Is.is(org.hamcrest.core.Is.is) Intent(org.onosproject.net.intent.Intent) Matchers.hasSize(org.hamcrest.Matchers.hasSize) LOCAL(org.onosproject.net.domain.DomainId.LOCAL) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MockResourceService(org.onosproject.net.resource.MockResourceService) Before(org.junit.Before) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) ImmutableSet(com.google.common.collect.ImmutableSet) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) IPV4(org.onlab.packet.EthType.EtherType.IPV4) VLAN_VID(org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) EasyMock(org.easymock.EasyMock) Collectors(java.util.stream.Collectors) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) MPLS_LABEL(org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Intent(org.onosproject.net.intent.Intent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) FlowRule(org.onosproject.net.flow.FlowRule) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test)

Aggregations

FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)111 Intent (org.onosproject.net.intent.Intent)103 FlowRule (org.onosproject.net.flow.FlowRule)91 Test (org.junit.Test)89 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)67 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)67 List (java.util.List)58 DeviceId (org.onosproject.net.DeviceId)58 Collection (java.util.Collection)57 Collectors (java.util.stream.Collectors)55 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)55 VlanId (org.onlab.packet.VlanId)54 Before (org.junit.Before)52 Collections (java.util.Collections)51 CoreService (org.onosproject.core.CoreService)50 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)50 EasyMock (org.easymock.EasyMock)49 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)49 ComponentConfigAdapter (org.onosproject.cfg.ComponentConfigAdapter)49 IntentExtensionService (org.onosproject.net.intent.IntentExtensionService)49