Search in sources :

Example 36 with TrafficSelector

use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.

the class LinkCollectionIntentFlowObjectiveCompiler method buildFilteringObjective.

private FilteringObjective buildFilteringObjective(LinkCollectionIntent intent, TrafficSelector selector, DeviceId deviceId, PortNumber inPort) {
    FilteringObjective.Builder builder = DefaultFilteringObjective.builder();
    builder.fromApp(appId).permit().makePermanent().withPriority(intent.priority());
    Criterion inPortCriterion = selector.getCriterion(Criterion.Type.IN_PORT);
    if (inPortCriterion != null) {
        builder.withKey(inPortCriterion);
    }
    FilteredConnectPoint ingressPoint = intent.filteredIngressPoints().stream().filter(fcp -> fcp.connectPoint().equals(new ConnectPoint(deviceId, inPort))).filter(fcp -> selector.criteria().containsAll(fcp.trafficSelector().criteria())).findFirst().orElse(null);
    AtomicBoolean emptyCondition = new AtomicBoolean(true);
    if (ingressPoint != null) {
        // ingress point, use criterion of it
        ingressPoint.trafficSelector().criteria().forEach(criterion -> {
            builder.addCondition(criterion);
            emptyCondition.set(false);
        });
        if (emptyCondition.get()) {
            return null;
        }
        return builder.add();
    }
    Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);
    if (encapConstraint.isPresent() && !encapConstraint.get().encapType().equals(EncapsulationType.NONE)) {
        // encapsulation enabled, use encapsulation label and tag.
        EncapsulationConstraint encap = encapConstraint.get();
        switch(encap.encapType()) {
            case VLAN:
                builder.addCondition(selector.getCriterion(Criterion.Type.VLAN_VID));
                emptyCondition.set(false);
                break;
            case MPLS:
                builder.addCondition(selector.getCriterion(Criterion.Type.MPLS_LABEL));
                emptyCondition.set(false);
                break;
            default:
                log.warn("No filtering rule found because of unknown encapsulation type.");
                break;
        }
    } else {
        // encapsulation not enabled, check if the treatment applied to the ingress or not
        if (intent.applyTreatmentOnEgress()) {
            // filtering criterion will be changed on egress point, use
            // criterion of ingress point
            ingressPoint = intent.filteredIngressPoints().stream().findFirst().orElse(null);
            if (ingressPoint == null) {
                log.warn("No filtering rule found because no ingress point in the Intent");
            } else {
                ingressPoint.trafficSelector().criteria().stream().filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT)).forEach(criterion -> {
                    builder.addCondition(criterion);
                    emptyCondition.set(false);
                });
            }
        } else {
            // filtering criterion will be changed on ingress point, use
            // criterion of egress point
            FilteredConnectPoint egressPoint = intent.filteredEgressPoints().stream().findFirst().orElse(null);
            if (egressPoint == null) {
                log.warn("No filtering rule found because no egress point in the Intent");
            } else {
                egressPoint.trafficSelector().criteria().stream().filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT)).forEach(criterion -> {
                    builder.addCondition(criterion);
                    emptyCondition.set(false);
                });
            }
        }
    }
    if (emptyCondition.get()) {
        return null;
    }
    return builder.add();
}
Also used : CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) ResourceService(org.onosproject.net.resource.ResourceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) HashMultimap(com.google.common.collect.HashMultimap) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) Deactivate(org.osgi.service.component.annotations.Deactivate) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Set(java.util.Set) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Sets(com.google.common.collect.Sets) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) IntentCompiler(org.onosproject.net.intent.IntentCompiler) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) Identifier(org.onlab.util.Identifier) LabelAllocator(org.onosproject.net.resource.impl.LabelAllocator) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) ArrayList(java.util.ArrayList) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) DomainService(org.onosproject.net.domain.DomainService) Intent(org.onosproject.net.intent.Intent) LOCAL(org.onosproject.net.domain.DomainId.LOCAL) Activate(org.osgi.service.component.annotations.Activate) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) Instruction(org.onosproject.net.flow.instructions.Instruction) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) SetMultimap(com.google.common.collect.SetMultimap) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) Reference(org.osgi.service.component.annotations.Reference) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 37 with TrafficSelector

use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.

the class PointToPointIntentCompiler method createFailoverFlowRules.

/**
 * Manufactures flow rule with treatment that is defined by failover
 * group and traffic selector determined by ingress port of the intent.
 *
 * @param intent intent which is being compiled (for appId)
 * @return       a list of a singular flow rule with fast failover
 *               outport traffic treatment
 */
private List<FlowRule> createFailoverFlowRules(PointToPointIntent intent) {
    List<FlowRule> flowRules = new ArrayList<>();
    ConnectPoint ingress = intent.filteredIngressPoint().connectPoint();
    DeviceId deviceId = ingress.deviceId();
    // flow rule with failover traffic treatment
    TrafficSelector trafficSelector = DefaultTrafficSelector.builder(intent.selector()).matchInPort(ingress.port()).build();
    FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
    flowRules.add(flowRuleBuilder.withSelector(trafficSelector).withTreatment(buildFailoverTreatment(deviceId, makeGroupKey(intent.id()))).fromApp(intent.appId()).makePermanent().forDevice(deviceId).withPriority(PRIORITY).build());
    return flowRules;
}
Also used : DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 38 with TrafficSelector

use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.

the class HostToHostIntentCompiler method createLinkCollectionIntent.

private Intent createLinkCollectionIntent(Path path, Host src, Host dst, HostToHostIntent intent) {
    // Try to allocate bandwidth
    List<ConnectPoint> pathCPs = path.links().stream().flatMap(l -> Stream.of(l.src(), l.dst())).collect(Collectors.toList());
    allocateBandwidth(intent, pathCPs);
    Link ingressLink = path.links().get(0);
    Link egressLink = path.links().get(path.links().size() - 1);
    FilteredConnectPoint ingressPoint = getFilteredPointFromLink(ingressLink);
    FilteredConnectPoint egressPoint = getFilteredPointFromLink(egressLink);
    TrafficSelector selector = builder(intent.selector()).matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
    /*
         * The path contains also the edge links, these are not necessary
         * for the LinkCollectionIntent.
         */
    Set<Link> coreLinks = path.links().stream().filter(link -> !link.type().equals(EDGE)).collect(Collectors.toSet());
    return LinkCollectionIntent.builder().key(intent.key()).appId(intent.appId()).selector(selector).treatment(intent.treatment()).links(coreLinks).filteredIngressPoints(ImmutableSet.of(ingressPoint)).filteredEgressPoints(ImmutableSet.of(egressPoint)).applyTreatmentOnEgress(true).constraints(intent.constraints()).priority(intent.priority()).resourceGroup(intent.resourceGroup()).build();
}
Also used : Arrays(java.util.Arrays) Host(org.onosproject.net.Host) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) Link(org.onosproject.net.Link) HostService(org.onosproject.net.host.HostService) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) DefaultPath(org.onosproject.net.DefaultPath) Intent(org.onosproject.net.intent.Intent) Activate(org.osgi.service.component.annotations.Activate) DefaultLink(org.onosproject.net.DefaultLink) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) DefaultTrafficSelector.builder(org.onosproject.net.flow.DefaultTrafficSelector.builder) Collectors(java.util.stream.Collectors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) EDGE(org.onosproject.net.Link.Type.EDGE) Path(org.onosproject.net.Path) Reference(org.osgi.service.component.annotations.Reference) DeviceId(org.onosproject.net.DeviceId) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 39 with TrafficSelector

use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.

the class FlowObjectiveCompositionUtil method composeSequential.

public static ForwardingObjective composeSequential(ForwardingObjective fo1, ForwardingObjective fo2, int priorityMultiplier) {
    TrafficSelector revertTrafficSelector = revertTreatmentSelector(fo1.treatment(), fo2.selector());
    if (revertTrafficSelector == null) {
        return null;
    }
    TrafficSelector trafficSelector = intersectTrafficSelector(fo1.selector(), revertTrafficSelector);
    if (trafficSelector == null) {
        return null;
    }
    TrafficTreatment trafficTreatment = unionTrafficTreatment(fo1.treatment(), fo2.treatment());
    return DefaultForwardingObjective.builder().fromApp(fo1.appId()).makePermanent().withFlag(ForwardingObjective.Flag.VERSATILE).withPriority(fo1.priority() * priorityMultiplier + fo2.priority()).withSelector(trafficSelector).withTreatment(trafficTreatment).add();
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 40 with TrafficSelector

use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.

the class FlowObjectiveCompositionUtil method intersectTrafficSelector.

public static TrafficSelector intersectTrafficSelector(TrafficSelector ts1, TrafficSelector ts2) {
    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
    Set<Criterion.Type> ts1IntersectTs2 = getTypeSet(ts1);
    ts1IntersectTs2.retainAll(getTypeSet(ts2));
    for (Criterion.Type type : ts1IntersectTs2) {
        Criterion criterion = intersectCriterion(ts1.getCriterion(type), ts2.getCriterion(type));
        if (criterion == null) {
            return null;
        } else {
            selectorBuilder.add(criterion);
        }
    }
    Set<Criterion.Type> ts1MinusTs2 = getTypeSet(ts1);
    ts1MinusTs2.removeAll(getTypeSet(ts2));
    for (Criterion.Type type : ts1MinusTs2) {
        selectorBuilder.add(ts1.getCriterion(type));
    }
    Set<Criterion.Type> ts2MinusTs1 = getTypeSet(ts2);
    ts2MinusTs1.removeAll(getTypeSet(ts1));
    for (Criterion.Type type : ts2MinusTs1) {
        selectorBuilder.add(ts2.getCriterion(type));
    }
    return selectorBuilder.build();
}
Also used : MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) VlanPcpCriterion(org.onosproject.net.flow.criteria.VlanPcpCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) OduSignalIdCriterion(org.onosproject.net.flow.criteria.OduSignalIdCriterion) IPv6FlowLabelCriterion(org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector)

Aggregations

TrafficSelector (org.onosproject.net.flow.TrafficSelector)396 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)354 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)249 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)235 FlowRule (org.onosproject.net.flow.FlowRule)94 Test (org.junit.Test)85 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)84 PiAction (org.onosproject.net.pi.runtime.PiAction)54 ConnectPoint (org.onosproject.net.ConnectPoint)51 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)48 DeviceId (org.onosproject.net.DeviceId)43 PortNumber (org.onosproject.net.PortNumber)43 List (java.util.List)42 NextObjective (org.onosproject.net.flowobjective.NextObjective)41 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)39 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)38 Instruction (org.onosproject.net.flow.instructions.Instruction)37 Criterion (org.onosproject.net.flow.criteria.Criterion)36 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)36 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)35