Java Code Examples for org.onosproject.net.flowobjective.NextObjective#type()

The following examples show how to use org.onosproject.net.flowobjective.NextObjective#type() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractHPPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Gets traffic treatment from a next objective.
 * Merge traffic treatments from next objective if the next objective is
 * BROADCAST type and contains multiple traffic treatments.
 * Returns first treatment from next objective if the next objective is
 * SIMPLE type and it contains only one treatment.
 *
 * @param nextObjective the next objective
 * @return the treatment from next objective; null if not supported
 */
private TrafficTreatment getTreatment(NextObjective nextObjective) {
    Collection<TrafficTreatment> treatments = nextObjective.next();
    switch (nextObjective.type()) {
        case SIMPLE:
            if (treatments.size() != 1) {
                log.error("Next Objectives of type SIMPLE should have only " +
                                "one traffic treatment. NexObjective: {}",
                        nextObjective.toString());
                return null;
            }
            return treatments.iterator().next();
        case BROADCAST:
            TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
            treatments.forEach(builder::addTreatment);
            return builder.build();
        default:
            log.error("Unsupported next objective type {}.", nextObjective.type());
            return null;
    }
}
 
Example 2
Source File: SoftRouterPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void next(NextObjective nextObjective) {
    switch (nextObjective.type()) {
        case SIMPLE:
            Collection<TrafficTreatment> treatments = nextObjective.next();
            if (treatments.size() != 1) {
                log.error("Next Objectives of type Simple should only have a "
                                  + "single Traffic Treatment. Next Objective Id:{}", nextObjective.id());
                fail(nextObjective, ObjectiveError.BADPARAMS);
                return;
            }
            processSimpleNextObjective(nextObjective);
            break;
        case HASHED:
        case BROADCAST:
        case FAILOVER:
            fail(nextObjective, ObjectiveError.UNSUPPORTED);
            log.warn("Unsupported next objective type {}", nextObjective.type());
            break;
        default:
            fail(nextObjective, ObjectiveError.UNKNOWN);
            log.warn("Unknown next objective type {}", nextObjective.type());
    }
}
 
Example 3
Source File: OfdpaGroupHandlerUtility.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * The purpose of this function is to verify if the hashed next
 * objective is supported by the current pipeline.
 *
 * @param nextObjective the hashed objective to verify
 * @return true if the hashed objective is supported. Otherwise false.
 */
public static boolean verifyHashedNextObjective(NextObjective nextObjective) {
    // if it is not hashed, there is something wrong;
    if (nextObjective.type() != HASHED) {
        return false;
    }
    // The case non supported is the MPLS-ECMP. For now, we try
    // to create a MPLS-ECMP for the transport of a VPWS. The
    // necessary info are contained in the meta selector. In particular
    // we are looking for the case of BoS==False;
    TrafficSelector metaSelector = nextObjective.meta();
    if (metaSelector != null && isNotMplsBos(metaSelector)) {
        return false;
    }

    return true;
}
 
Example 4
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * modifies group with next objective.
 *
 * @param nextObjective the NextObjective
 * @param nextGroup the NextGroup
*/
protected void modifyBucketFromGroup(NextObjective nextObjective, NextGroup nextGroup) {
    switch (nextObjective.type()) {
        case SIMPLE:
            Collection<TrafficTreatment> treatments = nextObjective.next();
            if (treatments.size() != 1) {
                log.error("Next Objectives of type Simple should only have a "
                                + "single Traffic Treatment. Next Objective Id:{}",
                        nextObjective.id());
                fail(nextObjective, ObjectiveError.BADPARAMS);
                return;
            }
            modifySimpleNextObjective(nextObjective, nextGroup);
            break;
        default:
            fail(nextObjective, ObjectiveError.UNKNOWN);
            log.warn("Unknown next objective type {}", nextObjective.type());
    }
}
 
Example 5
Source File: DefaultSingleTablePipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Gets traffic treatment from a next objective.
 * Merge traffic treatments from next objective if the next objective is
 * BROADCAST type and contains multiple traffic treatments.
 * Returns first treatment from next objective if the next objective is
 * SIMPLE type and it contains only one treatment.
 *
 * @param nextObjective the next objective
 * @return the treatment from next objective; null if not supported
 */
private TrafficTreatment getTreatment(NextObjective nextObjective) {
    Collection<TrafficTreatment> treatments = nextObjective.next();
    switch (nextObjective.type()) {
        case SIMPLE:
            if (treatments.size() != 1) {
                log.error("Next Objectives of type SIMPLE should have only " +
                                  "one traffic treatment. NexObjective: {}",
                          nextObjective.toString());
                return null;
            }
            return treatments.iterator().next();
        case BROADCAST:
            TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
            treatments.forEach(builder::addTreatment);
            return builder.build();
        default:
            log.error("Unsupported next objective type {}.", nextObjective.type());
            return null;
    }
}
 
Example 6
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a list of group chain by given NextObjective.
 *
 * @param nextObjective the NextObjective
 */
protected void addGroup(NextObjective nextObjective) {
    switch (nextObjective.type()) {
        case SIMPLE:
            Collection<TrafficTreatment> treatments = nextObjective.next();
            if (treatments.size() != 1) {
                log.error("Next Objectives of type Simple should only have a "
                                + "single Traffic Treatment. Next Objective Id:{}",
                        nextObjective.id());
                fail(nextObjective, ObjectiveError.BADPARAMS);
                return;
            }
            processSimpleNextObjective(nextObjective);
            break;
        case BROADCAST:
            processBroadcastNextObjective(nextObjective);
            break;
        case HASHED:
            if (!verifyHashedNextObjective(nextObjective)) {
                log.error("Next Objectives of type hashed not supported. Next Objective Id:{}",
                          nextObjective.id());
                fail(nextObjective, ObjectiveError.BADPARAMS);
                return;
            }
            if (isL2Hash(nextObjective)) {
                processL2HashedNextObjective(nextObjective);
                return;
            }
            processEcmpHashedNextObjective(nextObjective);
            break;
        case FAILOVER:
            fail(nextObjective, ObjectiveError.UNSUPPORTED);
            log.warn("Unsupported next objective type {}", nextObjective.type());
            break;
        default:
            fail(nextObjective, ObjectiveError.UNKNOWN);
            log.warn("Unknown next objective type {}", nextObjective.type());
    }
}
 
Example 7
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Removes buckets in the top level group of a possible group-chain. Does
 * not remove the groups in the group-chain pointed to by this bucket, as they
 * may be in use (referenced by other groups) elsewhere.
 *
 * @param nextObjective a next objective that contains information for the
 *                          buckets to be removed from the group
 * @param next the representation of the existing group-chains for this next
 *          objective, from which the top-level buckets to remove are determined
 */
protected void removeBucketFromGroup(NextObjective nextObjective, NextGroup next) {
    if (nextObjective.type() != NextObjective.Type.HASHED &&
            nextObjective.type() != NextObjective.Type.BROADCAST) {
        log.warn("RemoveBuckets not applied to nextType:{} in dev:{} for next:{}",
                nextObjective.type(), deviceId, nextObjective.id());
        fail(nextObjective, ObjectiveError.UNSUPPORTED);
        return;
    }
    List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data());
    List<Integer> indicesToRemove = Lists.newArrayList();
    for (TrafficTreatment treatment : nextObjective.next()) {
        // find the top-level bucket in the group-chain by matching the
        // outport and label from different groups in the chain
        PortNumber portToRemove = readOutPortFromTreatment(treatment);
        int labelToRemove = readLabelFromTreatment(treatment);
        if (portToRemove == null) {
            log.warn("treatment {} of next objective {} has no outport.. "
                    + "cannot remove bucket from group in dev: {}", treatment,
                    nextObjective.id(), deviceId);
            continue;
        }
        List<Integer> existing = existingPortAndLabel(allActiveKeys,
                                                      groupService, deviceId,
                                                      portToRemove, labelToRemove);
        indicesToRemove.addAll(existing);

    }

    List<Deque<GroupKey>> chainsToRemove = Lists.newArrayList();
    indicesToRemove.forEach(index -> chainsToRemove
                            .add(allActiveKeys.get(index)));
    if (chainsToRemove.isEmpty()) {
        log.warn("Could not find appropriate group-chain for removing bucket"
                + " for next id {} in dev:{}", nextObjective.id(), deviceId);
        fail(nextObjective, ObjectiveError.BADPARAMS);
        return;
    }
    removeBucket(chainsToRemove, nextObjective);
}
 
Example 8
Source File: AbstractCorsaPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void next(NextObjective nextObjective) {
    switch (nextObjective.type()) {
        case SIMPLE:
            Collection<TrafficTreatment> treatments = nextObjective.next();
            if (treatments.size() == 1) {
                TrafficTreatment treatment = treatments.iterator().next();
                CorsaTrafficTreatment corsaTreatment = processNextTreatment(treatment);
                final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
                if (corsaTreatment.type() == CorsaTrafficTreatmentType.GROUP) {
                    GroupBucket bucket = DefaultGroupBucket.createIndirectGroupBucket(corsaTreatment.treatment());
                    GroupBuckets buckets = new GroupBuckets(Collections.singletonList(bucket));
                    // group id == null, let group service determine group id
                    GroupDescription groupDescription = new DefaultGroupDescription(deviceId,
                                                                                    GroupDescription.Type.INDIRECT,
                                                                                    buckets,
                                                                                    key,
                                                                                    null,
                                                                                    nextObjective.appId());
                    groupService.addGroup(groupDescription);
                    pendingGroups.put(key, nextObjective);
                } else if (corsaTreatment.type() == CorsaTrafficTreatmentType.ACTIONS) {
                    pendingNext.put(nextObjective.id(), nextObjective);
                    flowObjectiveStore.putNextGroup(nextObjective.id(), new CorsaGroup(key));
                    nextObjective.context().ifPresent(context -> context.onSuccess(nextObjective));
                }
            }
            break;
        case HASHED:
        case BROADCAST:
        case FAILOVER:
            fail(nextObjective, ObjectiveError.UNSUPPORTED);
            log.warn("Unsupported next objective type {}", nextObjective.type());
            break;
        default:
            fail(nextObjective, ObjectiveError.UNKNOWN);
            log.warn("Unknown next objective type {}", nextObjective.type());
    }

}
 
Example 9
Source File: NextObjectiveTranslator.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectiveTranslation doTranslate(NextObjective obj)
        throws FabricPipelinerException {

    final ObjectiveTranslation.Builder resultBuilder =
            ObjectiveTranslation.builder();

    switch (obj.type()) {
        case SIMPLE:
            simpleNext(obj, resultBuilder, false);
            break;
        case HASHED:
            hashedNext(obj, resultBuilder);
            break;
        case BROADCAST:
            if (isXconnect(obj)) {
                xconnectNext(obj, resultBuilder);
            } else {
                multicastNext(obj, resultBuilder);
            }
            break;
        default:
            log.warn("Unsupported NextObjective type '{}'", obj);
            return ObjectiveTranslation.ofError(ObjectiveError.UNSUPPORTED);
    }

    if (!isGroupModifyOp(obj)) {
        // Generate next VLAN rules.
        nextVlan(obj, resultBuilder);
    }

    return resultBuilder.build();
}
 
Example 10
Source File: FabricPipeliner.java    From onos with Apache License 2.0 5 votes vote down vote up
private void putNextGroup(NextObjective obj) {
    final List<String> nextMappings = obj.nextTreatments().stream()
            .map(this::nextTreatmentToMappingString)
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
    final FabricNextGroup nextGroup = new FabricNextGroup(obj.type(), nextMappings);
    flowObjectiveStore.putNextGroup(obj.id(), nextGroup);
}
 
Example 11
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 *  Adds a bucket to the top level group of a group-chain, and creates the chain.
 *  Ensures that bucket being added is not a duplicate, by checking existing
 *  buckets for the same output port.
 *
 * @param nextObjective the bucket information for a next group
 * @param next the representation of the existing group-chain for this next objective
 */
protected void addBucketToGroup(NextObjective nextObjective, NextGroup next) {
    if (nextObjective.type() != NextObjective.Type.HASHED &&
            nextObjective.type() != NextObjective.Type.BROADCAST) {
        log.warn("AddBuckets not applied to nextType:{} in dev:{} for next:{}",
                 nextObjective.type(), deviceId, nextObjective.id());
        fail(nextObjective, ObjectiveError.UNSUPPORTED);
        return;
    }
    // first check to see if bucket being added is not a duplicate of an
    // existing bucket. If it is for an existing output port, then its a
    // duplicate.
    Set<TrafficTreatment> duplicateBuckets = Sets.newHashSet();
    List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data());
    Set<PortNumber> existingPorts = getExistingOutputPorts(allActiveKeys,
                                                           groupService,
                                                           deviceId);
    Set<TrafficTreatment> nonDuplicateBuckets = Sets.newHashSet();
    NextObjective objectiveToAdd;
    nextObjective.next().forEach(trafficTreatment -> {
        PortNumber portNumber = readOutPortFromTreatment(trafficTreatment);
        if (portNumber == null) {
            return;
        }
        if (existingPorts.contains(portNumber)) {
            // its possible that portnumbers are same but labels are different
            int label = readLabelFromTreatment(trafficTreatment);
            if (label == -1) {
                duplicateBuckets.add(trafficTreatment);
            } else {
                List<Integer> existing = existingPortAndLabel(allActiveKeys,
                                             groupService, deviceId,
                                             portNumber, label);
                if (!existing.isEmpty()) {
                    duplicateBuckets.add(trafficTreatment);
                } else {
                    nonDuplicateBuckets.add(trafficTreatment);
                }
            }
        } else {
            nonDuplicateBuckets.add(trafficTreatment);
        }
    });
    if (duplicateBuckets.isEmpty()) {
        // use the original objective
        objectiveToAdd = nextObjective;
    } else if (!nonDuplicateBuckets.isEmpty()) {
        // only use the non-duplicate buckets if there are any
        log.debug("Some buckets {} already exist in next id {}, duplicate "
                + "buckets will be ignored.", duplicateBuckets, nextObjective.id());
        // new next objective with non duplicate treatments
        NextObjective.Builder builder = DefaultNextObjective.builder()
                .withType(nextObjective.type())
                .withId(nextObjective.id())
                .withMeta(nextObjective.meta())
                .fromApp(nextObjective.appId());
        nonDuplicateBuckets.forEach(builder::addTreatment);
        ObjectiveContext context = nextObjective.context().orElse(null);
        objectiveToAdd = builder.addToExisting(context);
    } else {
        // buckets to add are already there - nothing to do
        log.debug("buckets already exist {} in next: {} ..ignoring bucket add",
                  duplicateBuckets, nextObjective.id());
        pass(nextObjective);
        return;
    }
    if (nextObjective.type() == NextObjective.Type.HASHED) {
        if (isL2Hash(nextObjective)) {
            addBucketToL2HashGroup(objectiveToAdd, allActiveKeys);
            return;
        }
        addBucketToEcmpHashGroup(objectiveToAdd, allActiveKeys);
    } else if (nextObjective.type() == NextObjective.Type.BROADCAST) {
        addBucketToBroadcastGroup(objectiveToAdd, allActiveKeys);
    }
}
 
Example 12
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Removes top-level buckets from a group that represents the given next objective.
 *
 * @param chainsToRemove a list of group bucket chains to remove
 * @param nextObjective the next objective that contains information for the
 *                  buckets to be removed from the group
 */
protected void removeBucket(List<Deque<GroupKey>> chainsToRemove,
                            NextObjective nextObjective) {
    List<GroupBucket> bucketsToRemove = Lists.newArrayList();
    //first group key is the one we want to modify
    GroupKey modGroupKey = chainsToRemove.get(0).peekFirst();
    Group modGroup = groupService.getGroup(deviceId, modGroupKey);
    if (modGroup == null) {
        log.warn("removeBucket(): Attempt to modify non-existent group {} for device {}", modGroupKey, deviceId);
        return;
    }
    for (Deque<GroupKey> foundChain : chainsToRemove) {
        //second group key is the one we wish to remove the reference to
        if (foundChain.size() < 2) {
            // additional check to make sure second group key exists in
            // the chain.
            log.warn("Can't find second group key from chain {}",
                     foundChain);
            continue;
        }
        GroupKey pointedGroupKey = foundChain.stream()
                                       .collect(Collectors.toList()).get(1);
        Group pointedGroup = groupService.getGroup(deviceId, pointedGroupKey);
        if (pointedGroup == null) {
            continue;
        }

        GroupBucket bucket;
        if (nextObjective.type() == NextObjective.Type.HASHED) {
            bucket = DefaultGroupBucket.createSelectGroupBucket(
                    DefaultTrafficTreatment.builder()
                            .group(pointedGroup.id())
                            .build());
        } else {
            bucket = DefaultGroupBucket.createAllGroupBucket(
                    DefaultTrafficTreatment.builder()
                            .group(pointedGroup.id())
                            .build());
        }
        bucketsToRemove.add(bucket);
    }

    GroupBuckets removeBuckets = new GroupBuckets(bucketsToRemove);
    List<String> pointedGroupIds; // for debug log
    pointedGroupIds = bucketsToRemove.stream()
            .map(GroupBucket::treatment)
            .map(TrafficTreatment::allInstructions)
            .flatMap(List::stream)
            .filter(inst -> inst instanceof Instructions.GroupInstruction)
            .map(inst -> (Instructions.GroupInstruction) inst)
            .map(Instructions.GroupInstruction::groupId)
            .map(GroupId::id)
            .map(Integer::toHexString)
            .map(id -> HEX_PREFIX + id)
            .collect(Collectors.toList());

    log.debug("Removing buckets from group id 0x{} pointing to group id(s) {} "
            + "for next id {} in device {}",
            Integer.toHexString(modGroup.id().id()),
            pointedGroupIds, nextObjective.id(), deviceId);
    addPendingUpdateNextObjective(modGroupKey, nextObjective);
    groupService.removeBucketsFromGroup(deviceId, modGroupKey,
                                        removeBuckets, modGroupKey,
                                        nextObjective.appId());
    // update store - synchronize access as there may be multiple threads
    // trying to remove buckets from the same group, each with its own
    // potentially stale copy of allActiveKeys
    synchronized (flowObjectiveStore) {
        // get a fresh copy of what the store holds
        NextGroup next = flowObjectiveStore.getNextGroup(nextObjective.id());
        List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data());
        allActiveKeys = Lists.newArrayList(allActiveKeys);
        // Note that since we got a new object, and ArrayDeque does not implement
        // Object.equals(), we have to check the deque elems one by one
        allActiveKeys
            .removeIf(active ->
                chainsToRemove.stream().anyMatch(remove ->
                    Arrays.equals(remove.toArray(new GroupKey[0]),
                                  active.toArray(new GroupKey[0]))));
        // If no buckets in the group, then retain an entry for the
        // top level group which still exists.
        if (allActiveKeys.isEmpty()) {
            ArrayDeque<GroupKey> top = new ArrayDeque<>();
            top.add(modGroupKey);
            allActiveKeys.add(top);
        }
        flowObjectiveStore.putNextGroup(nextObjective.id(),
                                        new OfdpaNextGroup(allActiveKeys,
                                                           nextObjective));
    }
}
 
Example 13
Source File: NokiaOltPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void next(NextObjective nextObjective) {
    if (nextObjective.type() != NextObjective.Type.BROADCAST) {
        log.error("OLT only supports broadcast groups.");
        fail(nextObjective, ObjectiveError.BADPARAMS);
    }

    if (nextObjective.next().size() != 1) {
        log.error("OLT only supports singleton broadcast groups.");
        fail(nextObjective, ObjectiveError.BADPARAMS);
    }

    TrafficTreatment treatment = nextObjective.next().stream().findFirst().get();


    GroupBucket bucket = DefaultGroupBucket.createAllGroupBucket(treatment);
    GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));


    pendingGroups.put(key, nextObjective);

    switch (nextObjective.op()) {
        case ADD:
            GroupDescription groupDesc =
                    new DefaultGroupDescription(deviceId,
                                                GroupDescription.Type.ALL,
                                                new GroupBuckets(Collections.singletonList(bucket)),
                                                key,
                                                null,
                                                nextObjective.appId());
            groupService.addGroup(groupDesc);
            break;
        case REMOVE:
            groupService.removeGroup(deviceId, key, nextObjective.appId());
            break;
        case ADD_TO_EXISTING:
            groupService.addBucketsToGroup(deviceId, key,
                                           new GroupBuckets(Collections.singletonList(bucket)),
                                           key, nextObjective.appId());
            break;
        case REMOVE_FROM_EXISTING:
            groupService.removeBucketsFromGroup(deviceId, key,
                                                new GroupBuckets(Collections.singletonList(bucket)),
                                                key, nextObjective.appId());
            break;
        default:
            log.warn("Unknown next objective operation: {}", nextObjective.op());
    }


}
 
Example 14
Source File: CentecV350Pipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void next(NextObjective nextObjective) {
    switch (nextObjective.type()) {
        case SIMPLE:
            Collection<TrafficTreatment> treatments = nextObjective.next();
            if (treatments.size() == 1) {
                TrafficTreatment treatment = treatments.iterator().next();

                // Since we do not support strip_vlan in PORT_VLAN table, we use mod_vlan
                // to modify the packet to desired vlan.
                // Note: if we use push_vlan here, the switch will add a second VLAN tag to the outgoing
                // packet, which is not what we want.
                TrafficTreatment.Builder treatmentWithoutPushVlan = DefaultTrafficTreatment.builder();
                VlanId modVlanId;
                for (Instruction ins : treatment.allInstructions()) {
                    if (ins.type() == Instruction.Type.L2MODIFICATION) {
                        L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
                        switch (l2ins.subtype()) {
                            case ETH_DST:
                                treatmentWithoutPushVlan.setEthDst(
                                        ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
                                break;
                            case ETH_SRC:
                                treatmentWithoutPushVlan.setEthSrc(
                                        ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
                                break;
                            case VLAN_ID:
                                modVlanId = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
                                treatmentWithoutPushVlan.setVlanId(modVlanId);
                                break;
                            default:
                                break;
                        }
                    } else if (ins.type() == Instruction.Type.OUTPUT) {
                        //long portNum = ((Instructions.OutputInstruction) ins).port().toLong();
                        treatmentWithoutPushVlan.add(ins);
                    } else {
                        // Ignore the vlan_pcp action since it's does matter much.
                        log.warn("Driver does not handle this type of TrafficTreatment"
                                + " instruction in nextObjectives:  {}", ins.type());
                    }
                }

                GroupBucket bucket =
                        DefaultGroupBucket.createIndirectGroupBucket(treatmentWithoutPushVlan.build());
                final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
                GroupDescription groupDescription
                        = new DefaultGroupDescription(deviceId,
                        GroupDescription.Type.INDIRECT,
                        new GroupBuckets(Collections
                                .singletonList(bucket)),
                        key,
                        null, // let group service determine group id
                        nextObjective.appId());
                groupService.addGroup(groupDescription);
                pendingGroups.put(key, nextObjective);
            }
            break;
        case HASHED:
        case BROADCAST:
        case FAILOVER:
            fail(nextObjective, ObjectiveError.UNSUPPORTED);
            log.warn("Unsupported next objective type {}", nextObjective.type());
            break;
        default:
            fail(nextObjective, ObjectiveError.UNKNOWN);
            log.warn("Unknown next objective type {}", nextObjective.type());
    }

}
 
Example 15
Source File: OltPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void next(NextObjective nextObjective) {
    if (nextObjective.type() != NextObjective.Type.BROADCAST) {
        log.error("OLT only supports broadcast groups.");
        fail(nextObjective, ObjectiveError.BADPARAMS);
        return;
    }

    if (nextObjective.next().size() != 1 && !nextObjective.op().equals(Objective.Operation.REMOVE)) {
        log.error("OLT only supports singleton broadcast groups.");
        fail(nextObjective, ObjectiveError.BADPARAMS);
        return;
    }

    Optional<TrafficTreatment> treatmentOpt = nextObjective.next().stream().findFirst();
    if (treatmentOpt.isEmpty() && !nextObjective.op().equals(Objective.Operation.REMOVE)) {
        log.error("Next objective {} does not have a treatment", nextObjective);
        fail(nextObjective, ObjectiveError.BADPARAMS);
        return;
    }

    GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));

    pendingGroups.put(key, nextObjective);
    log.trace("NextObjective Operation {}", nextObjective.op());
    switch (nextObjective.op()) {
        case ADD:
            GroupDescription groupDesc =
                    new DefaultGroupDescription(deviceId,
                                                GroupDescription.Type.ALL,
                                                new GroupBuckets(
                                                        Collections.singletonList(
                                                            buildBucket(treatmentOpt.get()))),
                                                key,
                                                null,
                                                nextObjective.appId());
            groupService.addGroup(groupDesc);
            break;
        case REMOVE:
            groupService.removeGroup(deviceId, key, nextObjective.appId());
            break;
        case ADD_TO_EXISTING:
            groupService.addBucketsToGroup(deviceId, key,
                                           new GroupBuckets(
                                                   Collections.singletonList(
                                                           buildBucket(treatmentOpt.get()))),
                                           key, nextObjective.appId());
            break;
        case REMOVE_FROM_EXISTING:
            groupService.removeBucketsFromGroup(deviceId, key,
                                                new GroupBuckets(
                                                        Collections.singletonList(
                                                            buildBucket(treatmentOpt.get()))),
                                                key, nextObjective.appId());
            break;
        default:
            log.warn("Unknown next objective operation: {}", nextObjective.op());
    }


}
 
Example 16
Source File: PicaPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void next(NextObjective nextObjective) {
    switch (nextObjective.type()) {
        case SIMPLE:
            Collection<TrafficTreatment> treatments = nextObjective.next();
            if (treatments.size() != 1) {
                log.error("Next Objectives of type Simple should only have a "
                        + "single Traffic Treatment. Next Objective Id:{}", nextObjective.id());
               fail(nextObjective, ObjectiveError.BADPARAMS);
               return;
            }
            TrafficTreatment treatment = treatments.iterator().next();
            TrafficTreatment.Builder filteredTreatment = DefaultTrafficTreatment.builder();
            VlanId modVlanId;
            for (Instruction ins : treatment.allInstructions()) {
                if (ins.type() == Instruction.Type.L2MODIFICATION) {
                    L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
                    switch (l2ins.subtype()) {
                        case ETH_DST:
                            filteredTreatment.setEthDst(
                                    ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
                            break;
                        case ETH_SRC:
                            filteredTreatment.setEthSrc(
                                    ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
                            break;
                        case VLAN_ID:
                            modVlanId = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
                            filteredTreatment.setVlanId(modVlanId);
                            break;
                        default:
                            break;
                    }
                } else if (ins.type() == Instruction.Type.OUTPUT) {
                    //long portNum = ((Instructions.OutputInstruction) ins).port().toLong();
                    filteredTreatment.add(ins);
                } else {
                    // Ignore the vlan_pcp action since it's does matter much.
                    log.warn("Driver does not handle this type of TrafficTreatment"
                            + " instruction in nextObjectives:  {}", ins.type());
                }
            }
            // store for future use
            flowObjectiveStore.putNextGroup(nextObjective.id(),
                                            new PicaGroup(filteredTreatment.build()));
            break;
        case HASHED:
        case BROADCAST:
        case FAILOVER:
            fail(nextObjective, ObjectiveError.UNSUPPORTED);
            log.warn("Unsupported next objective type {}", nextObjective.type());
            break;
        default:
            fail(nextObjective, ObjectiveError.UNKNOWN);
            log.warn("Unknown next objective type {}", nextObjective.type());
    }

}