Search in sources :

Example 1 with DefaultNextTreatment

use of org.onosproject.net.flowobjective.DefaultNextTreatment in project onos by opennetworkinglab.

the class NextObjectiveTranslator method selectGroup.

private int selectGroup(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
    final PiTableId hashedTableId = FabricConstants.FABRIC_INGRESS_NEXT_HASHED;
    final List<DefaultNextTreatment> defaultNextTreatments = defaultNextTreatments(obj.nextTreatments(), true);
    final List<TrafficTreatment> piTreatments = Lists.newArrayList();
    for (DefaultNextTreatment t : defaultNextTreatments) {
        // Map treatment to PI...
        piTreatments.add(mapTreatmentToPiIfNeeded(t.treatment(), hashedTableId));
        // ...and handle egress if necessary.
        handleEgress(obj, t.treatment(), resultBuilder, false);
    }
    final List<GroupBucket> bucketList = piTreatments.stream().map(DefaultGroupBucket::createSelectGroupBucket).collect(Collectors.toList());
    final int groupId = obj.id();
    final PiGroupKey groupKey = (PiGroupKey) getGroupKey(obj);
    resultBuilder.addGroup(new DefaultGroupDescription(deviceId, GroupDescription.Type.SELECT, new GroupBuckets(bucketList), groupKey, groupId, obj.appId()));
    return groupId;
}
Also used : DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) PiTableId(org.onosproject.net.pi.model.PiTableId) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Example 2 with DefaultNextTreatment

use of org.onosproject.net.flowobjective.DefaultNextTreatment in project onos by opennetworkinglab.

the class NextObjectiveTranslator method allGroup.

private int allGroup(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
    final Collection<DefaultNextTreatment> defaultNextTreatments = defaultNextTreatments(obj.nextTreatments(), true);
    // multicast entries is based solely on the output port.
    for (DefaultNextTreatment t : defaultNextTreatments) {
        handleEgress(obj, t.treatment(), resultBuilder, true);
    }
    // FIXME: this implementation supports only the case in which each
    // switch interface is associated with only one VLAN, otherwise we would
    // need to support replicating multiple times the same packet for the
    // same port while setting different VLAN IDs. Hence, collect in a set.
    final Set<PortNumber> outPorts = defaultNextTreatments.stream().map(DefaultNextTreatment::treatment).map(FabricUtils::outputPort).filter(Objects::nonNull).collect(Collectors.toSet());
    if (outPorts.size() != defaultNextTreatments.size()) {
        throw new FabricPipelinerException(format("Found BROADCAST NextObjective with %d treatments but " + "found only %d distinct OUTPUT port numbers, cannot " + "translate to ALL groups", defaultNextTreatments.size(), outPorts.size()), ObjectiveError.UNSUPPORTED);
    }
    final List<GroupBucket> bucketList = outPorts.stream().map(p -> DefaultTrafficTreatment.builder().setOutput(p).build()).map(DefaultGroupBucket::createAllGroupBucket).collect(Collectors.toList());
    final int groupId = obj.id();
    // Use DefaultGroupKey instead of PiGroupKey as we don't have any
    // action profile to apply to the groups of ALL type.
    final GroupKey groupKey = getGroupKey(obj);
    resultBuilder.addGroup(new DefaultGroupDescription(deviceId, GroupDescription.Type.ALL, new GroupBuckets(bucketList), groupKey, groupId, obj.appId()));
    return groupId;
}
Also used : DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) FabricUtils(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils) PortNumber(org.onosproject.net.PortNumber) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Example 3 with DefaultNextTreatment

use of org.onosproject.net.flowobjective.DefaultNextTreatment in project onos by opennetworkinglab.

the class NextObjectiveTranslator method simpleNext.

private void simpleNext(NextObjective obj, ObjectiveTranslation.Builder resultBuilder, boolean forceSimple) throws FabricPipelinerException {
    if (capabilities.hasHashedTable()) {
        // Use hashed table when possible.
        hashedNext(obj, resultBuilder);
        return;
    }
    if (obj.nextTreatments().isEmpty()) {
        // Do nothing.
        return;
    } else if (!forceSimple && obj.nextTreatments().size() != 1) {
        throw new FabricPipelinerException(format("SIMPLE NextObjective should contain only 1 treatment, found %d", obj.nextTreatments().size()), ObjectiveError.BADPARAMS);
    }
    final TrafficSelector selector = nextIdSelector(obj.id());
    final List<DefaultNextTreatment> treatments = defaultNextTreatments(obj.nextTreatments(), true);
    if (forceSimple && treatments.size() > 1) {
        log.warn("Forcing SIMPLE behavior for NextObjective with {} treatments {}", treatments.size(), obj);
    }
    // If not forcing, we are essentially extracting the only available treatment.
    final TrafficTreatment treatment = defaultNextTreatments(obj.nextTreatments(), true).get(0).treatment();
    resultBuilder.addFlowRule(flowRule(obj, FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE, selector, treatment));
    handleEgress(obj, treatment, resultBuilder, false);
}
Also used : DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) 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 4 with DefaultNextTreatment

use of org.onosproject.net.flowobjective.DefaultNextTreatment in project onos by opennetworkinglab.

the class NextObjectiveTranslator method indirectGroup.

private int indirectGroup(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
    if (isGroupModifyOp(obj)) {
        throw new FabricPipelinerException("Simple next objective does not support" + "*_TO_EXISTING operations");
    }
    final PiTableId hashedTableId = FabricConstants.FABRIC_INGRESS_NEXT_HASHED;
    final List<DefaultNextTreatment> defaultNextTreatments = defaultNextTreatments(obj.nextTreatments(), true);
    if (defaultNextTreatments.size() != 1) {
        throw new FabricPipelinerException("Simple next objective must have a single" + " treatment");
    }
    final TrafficTreatment piTreatment;
    final DefaultNextTreatment defaultNextTreatment = defaultNextTreatments.get(0);
    piTreatment = mapTreatmentToPiIfNeeded(defaultNextTreatment.treatment(), hashedTableId);
    handleEgress(obj, defaultNextTreatment.treatment(), resultBuilder, false);
    final GroupBucket groupBucket = DefaultGroupBucket.createIndirectGroupBucket(piTreatment);
    final int groupId = obj.id();
    final PiGroupKey groupKey = (PiGroupKey) getGroupKey(obj);
    resultBuilder.addGroup(new DefaultGroupDescription(deviceId, GroupDescription.Type.INDIRECT, new GroupBuckets(Collections.singletonList(groupBucket)), groupKey, groupId, obj.appId()));
    return groupId;
}
Also used : DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) PiTableId(org.onosproject.net.pi.model.PiTableId) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Example 5 with DefaultNextTreatment

use of org.onosproject.net.flowobjective.DefaultNextTreatment in project onos by opennetworkinglab.

the class Ofdpa2GroupHandler method prepareL2InterfaceGroup.

private List<GroupInfo> prepareL2InterfaceGroup(NextObjective nextObj, VlanId assignedVlan) {
    ImmutableList.Builder<GroupInfo> groupInfoBuilder = ImmutableList.builder();
    // break up broadcast next objective to multiple groups
    Collection<TrafficTreatment> buckets = nextObj.nextTreatments().stream().filter(nt -> nt.type() == NextTreatment.Type.TREATMENT).map(nt -> ((DefaultNextTreatment) nt).treatment()).collect(Collectors.toSet());
    // Each treatment is converted to an L2 interface group
    for (TrafficTreatment treatment : buckets) {
        TrafficTreatment.Builder newTreatment = DefaultTrafficTreatment.builder();
        PortNumber portNum = null;
        VlanId egressVlan = null;
        // ensure that the only allowed treatments are pop-vlan and output
        for (Instruction ins : treatment.allInstructions()) {
            if (ins.type() == Instruction.Type.L2MODIFICATION) {
                L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
                switch(l2ins.subtype()) {
                    case VLAN_POP:
                        newTreatment.add(l2ins);
                        break;
                    case VLAN_ID:
                        egressVlan = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
                        break;
                    default:
                        log.debug("action {} not permitted for broadcast nextObj", l2ins.subtype());
                        break;
                }
            } else if (ins.type() == Instruction.Type.OUTPUT) {
                portNum = ((Instructions.OutputInstruction) ins).port();
                newTreatment.add(ins);
            } else {
                log.debug("TrafficTreatment of type {} not permitted in " + " broadcast nextObjective", ins.type());
            }
        }
        if (portNum == null) {
            log.debug("Can't find output port for the bucket {}.", treatment);
            continue;
        }
        // assemble info for l2 interface group
        VlanId l2InterfaceGroupVlan = (egressVlan != null && !assignedVlan.equals(egressVlan)) ? egressVlan : assignedVlan;
        int l2gk = l2InterfaceGroupKey(deviceId, l2InterfaceGroupVlan, portNum.toLong());
        final GroupKey l2InterfaceGroupKey = new DefaultGroupKey(appKryo.serialize(l2gk));
        int l2InterfaceGroupId = L2_INTERFACE_TYPE | ((l2InterfaceGroupVlan.toShort() & THREE_NIBBLE_MASK) << PORT_LEN) | ((int) portNum.toLong() & FOUR_NIBBLE_MASK);
        GroupBucket l2InterfaceGroupBucket = DefaultGroupBucket.createIndirectGroupBucket(newTreatment.build());
        GroupDescription l2InterfaceGroupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.INDIRECT, new GroupBuckets(Collections.singletonList(l2InterfaceGroupBucket)), l2InterfaceGroupKey, l2InterfaceGroupId, nextObj.appId());
        log.debug("Trying L2-Interface: device:{} gid:{} gkey:{} nextid:{}", deviceId, Integer.toHexString(l2InterfaceGroupId), l2InterfaceGroupKey, nextObj.id());
        groupInfoBuilder.add(new GroupInfo(l2InterfaceGroupDescription, l2InterfaceGroupDescription));
    }
    return groupInfoBuilder.build();
}
Also used : Arrays(java.util.Arrays) TUNNEL_ID(org.onosproject.net.flow.criteria.Criterion.Type.TUNNEL_ID) AtomicCounter(org.onosproject.store.service.AtomicCounter) OfdpaPipelineUtility(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility) PortNumber(org.onosproject.net.PortNumber) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Operation(org.onosproject.net.flowobjective.Objective.Operation) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) ServiceDirectory(org.onlab.osgi.ServiceDirectory) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) INDIRECT(org.onosproject.net.group.GroupDescription.Type.INDIRECT) StorageService(org.onosproject.store.service.StorageService) GroupListener(org.onosproject.net.group.GroupListener) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) IN_PORT(org.onosproject.net.flow.criteria.Criterion.Type.IN_PORT) SELECT(org.onosproject.net.group.GroupDescription.Type.SELECT) ALL(org.onosproject.net.group.GroupDescription.Type.ALL) PipelinerContext(org.onosproject.net.behaviour.PipelinerContext) VLAN_VID(org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) FlowObjectiveStore(org.onosproject.net.flowobjective.FlowObjectiveStore) GroupEvent(org.onosproject.net.group.GroupEvent) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) L2_MULTICAST_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_MULTICAST_TYPE) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) GroupBuckets(org.onosproject.net.group.GroupBuckets) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) DeviceId(org.onosproject.net.DeviceId) Ofdpa2Pipeline(org.onosproject.driver.pipeline.ofdpa.Ofdpa2Pipeline) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) IpPrefix(org.onlab.packet.IpPrefix) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) OfdpaSetAllowVlanTranslation(org.onosproject.driver.extensions.OfdpaSetAllowVlanTranslation) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) OfdpaSetVlanVid(org.onosproject.driver.extensions.OfdpaSetVlanVid) DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) GroupBucket(org.onosproject.net.group.GroupBucket) NextGroup(org.onosproject.net.behaviour.NextGroup) GroupKey(org.onosproject.net.group.GroupKey) Deque(java.util.Deque) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) OfdpaGroupHandlerUtility.l2MulticastGroupKey(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) OfdpaGroupHandlerUtility(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) RemovalNotification(com.google.common.cache.RemovalNotification) Ofdpa3AllowVlanTranslationType(org.onosproject.driver.extensions.Ofdpa3AllowVlanTranslationType) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) MplsLabel(org.onlab.packet.MplsLabel) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) GroupService(org.onosproject.net.group.GroupService) GroupInstruction(org.onosproject.net.flow.instructions.Instructions.GroupInstruction) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) IdNextTreatment(org.onosproject.net.flowobjective.IdNextTreatment) TimeUnit(java.util.concurrent.TimeUnit) RemovalCause(com.google.common.cache.RemovalCause) GroupId(org.onosproject.core.GroupId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) Cache(com.google.common.cache.Cache) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) ImmutableList(com.google.common.collect.ImmutableList) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) OfdpaGroupHandlerUtility.l2MulticastGroupKey(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) GroupInstruction(org.onosproject.net.flow.instructions.Instructions.GroupInstruction) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) PortNumber(org.onosproject.net.PortNumber) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) VlanId(org.onlab.packet.VlanId)

Aggregations

DefaultNextTreatment (org.onosproject.net.flowobjective.DefaultNextTreatment)11 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)9 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)8 TrafficSelector (org.onosproject.net.flow.TrafficSelector)7 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)7 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)7 GroupBucket (org.onosproject.net.group.GroupBucket)7 GroupBuckets (org.onosproject.net.group.GroupBuckets)7 PortNumber (org.onosproject.net.PortNumber)6 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)5 GroupKey (org.onosproject.net.group.GroupKey)5 Lists (com.google.common.collect.Lists)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 List (java.util.List)4 Objects (java.util.Objects)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 MplsLabel (org.onlab.packet.MplsLabel)4 NextTreatment (org.onosproject.net.flowobjective.NextTreatment)4