Search in sources :

Example 71 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project trellis-control by opennetworkinglab.

the class DefaultGroupHandler method removePortNextObjective.

/**
 * Removes simple next objective for a single port.
 *
 * @param deviceId device id that has the port to deal with
 * @param portNum the outgoing port on the device
 * @param vlanId vlan id associated with the port
 * @param popVlan true if POP_VLAN action is applied on the packets, false otherwise
 */
public void removePortNextObjective(DeviceId deviceId, PortNumber portNum, VlanId vlanId, boolean popVlan) {
    TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder();
    mbuilder.matchVlanId(vlanId);
    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
    tbuilder.immediate().setOutput(portNum);
    if (popVlan) {
        tbuilder.immediate().popVlan();
    }
    int portNextObjId = srManager.getPortNextObjectiveId(deviceId, portNum, tbuilder.build(), mbuilder.build(), false);
    PortNextObjectiveStoreKey key = new PortNextObjectiveStoreKey(deviceId, portNum, tbuilder.build(), mbuilder.build());
    if (portNextObjId != -1 && portNextObjStore.containsKey(key)) {
        NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(portNextObjId).withType(NextObjective.Type.SIMPLE).addTreatment(tbuilder.build()).fromApp(appId).withMeta(mbuilder.build());
        ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("removePortNextObjective removes NextObj {} on {}", portNextObjId, deviceId), (objective, error) -> {
            log.warn("removePortNextObjective failed to remove NextObj {} on {}: {}", portNextObjId, deviceId, error);
            srManager.invalidateNextObj(objective.id());
        });
        NextObjective nextObjective = nextObjBuilder.remove(context);
        log.info("**removePortNextObjective: Submitted " + "next objective {} in device {}", portNextObjId, deviceId);
        flowObjectiveService.next(deviceId, nextObjective);
        portNextObjStore.remove(key);
    }
}
Also used : PortNextObjectiveStoreKey(org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 72 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project trellis-control by opennetworkinglab.

the class DefaultGroupHandler method addToHashedNextObjective.

/**
 * Makes a call to the FlowObjective service to add buckets to
 * a hashed group. User must ensure that all the ports & labels are meant
 * same neighbor (ie. dstMac).
 *
 * @param portLabels a collection of port & label combinations to add
 *                   to the hash group identified by the nextId
 * @param dstMac destination mac address of next-hop
 * @param nextId id for next-objective to which buckets will be added
 */
private void addToHashedNextObjective(Collection<PortLabel> portLabels, MacAddress dstMac, Integer nextId) {
    // setup metadata to pass to nextObjective - indicate the vlan on egress
    // if needed by the switch pipeline. Since hashed next-hops are always to
    // other neighboring routers, there is no subnet assigned on those ports.
    TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder();
    metabuilder.matchVlanId(srManager.getDefaultInternalVlan());
    NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.HASHED).withMeta(metabuilder.build()).fromApp(appId);
    // Create the new buckets to be updated
    portLabels.forEach(pl -> {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
        tBuilder.setOutput(pl.port).setEthDst(dstMac).setEthSrc(nodeMacAddr);
        if (pl.popVlan) {
            tBuilder.popVlan();
        }
        if (pl.edgeLabel != DestinationSet.NO_EDGE_LABEL) {
            tBuilder.pushMpls().copyTtlOut().setMpls(MplsLabel.mplsLabel(pl.edgeLabel));
        }
        nextObjBuilder.addTreatment(tBuilder.build());
    });
    log.debug("addToHash in device {}: Adding Bucket with port/label {} " + "to nextId {}", deviceId, portLabels, nextId);
    ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("addToHash port/label {} addedTo " + "NextObj {} on {}", portLabels, nextId, deviceId), (objective, error) -> {
        log.warn("addToHash failed to add port/label {} to NextObj {} on {}: {}", portLabels, nextId, deviceId, error);
        srManager.invalidateNextObj(objective.id());
    });
    NextObjective nextObjective = nextObjBuilder.addToExisting(context);
    flowObjectiveService.next(deviceId, nextObjective);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) 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 73 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project trellis-control by opennetworkinglab.

the class DefaultGroupHandler method createBcastGroupFromVlan.

/**
 * Creates a single broadcast group from a given vlan id and list of ports.
 *
 * @param vlanId vlan id
 * @param ports list of ports in the subnet
 */
public void createBcastGroupFromVlan(VlanId vlanId, Collection<PortNumber> ports) {
    VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId);
    if (vlanNextObjStore.containsKey(key)) {
        log.debug("Broadcast group for device {} and subnet {} exists", deviceId, vlanId);
        return;
    }
    TrafficSelector metadata = DefaultTrafficSelector.builder().matchVlanId(vlanId).build();
    int nextId = flowObjectiveService.allocateNextId();
    NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.BROADCAST).fromApp(appId).withMeta(metadata);
    ports.forEach(port -> {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
        if (toPopVlan(port, vlanId)) {
            tBuilder.popVlan();
        }
        tBuilder.setOutput(port);
        nextObjBuilder.addTreatment(tBuilder.build());
    });
    ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("createBroadcastGroupFromVlan installed " + "NextObj {} on {}", nextId, deviceId), (objective, error) -> {
        log.warn("createBroadcastGroupFromVlan failed to install NextObj {} on {}: {}", nextId, deviceId, error);
        srManager.invalidateNextObj(objective.id());
    });
    NextObjective nextObj = nextObjBuilder.add(context);
    flowObjectiveService.next(deviceId, nextObj);
    log.debug("createBcastGroupFromVlan: Submitted next objective {} " + "for vlan: {} in device {}", nextId, vlanId, deviceId);
    vlanNextObjStore.put(key, nextId);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) MacVlanNextObjectiveStoreKey(org.onosproject.segmentrouting.storekey.MacVlanNextObjectiveStoreKey) VlanNextObjectiveStoreKey(org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 74 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project trellis-control by opennetworkinglab.

the class DefaultGroupHandler method removeGroup.

/**
 * Removes groups for the next objective ID given.
 *
 * @param objectiveId next objective ID to remove
 * @return true if succeeds, false otherwise
 */
public boolean removeGroup(int objectiveId) {
    for (Map.Entry<DestinationSetNextObjectiveStoreKey, NextNeighbors> e : dsNextObjStore.entrySet()) {
        if (e.getValue().nextId() != objectiveId) {
            continue;
        }
        // Right now it is just used in TunnelHandler
        // remember in future that PW transit groups could
        // be Indirect groups
        NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(objectiveId).withType(NextObjective.Type.HASHED).fromApp(appId);
        ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("RemoveGroup removes NextObj {} on {}", objectiveId, deviceId), (objective, error) -> {
            log.warn("RemoveGroup failed to remove NextObj {} on {}: {}", objectiveId, deviceId, error);
            srManager.invalidateNextObj(objective.id());
        });
        NextObjective nextObjective = nextObjBuilder.remove(context);
        log.info("**removeGroup: Submited " + "next objective {} in device {}", objectiveId, deviceId);
        flowObjectiveService.next(deviceId, nextObjective);
        dsNextObjStore.remove(e.getKey());
        return true;
    }
    return false;
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DestinationSetNextObjectiveStoreKey(org.onosproject.segmentrouting.storekey.DestinationSetNextObjectiveStoreKey) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap)

Example 75 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project trellis-control by opennetworkinglab.

the class DefaultGroupHandler method removeBcastGroupFromVlan.

/**
 * Removes a single broadcast group from a given vlan id.
 * The group should be empty.
 * @param deviceId device Id to remove the group
 * @param portNum port number related to the group
 * @param vlanId vlan id of the broadcast group to remove
 * @param popVlan true if the TrafficTreatment involves pop vlan tag action
 */
public void removeBcastGroupFromVlan(DeviceId deviceId, PortNumber portNum, VlanId vlanId, boolean popVlan) {
    VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId);
    if (!vlanNextObjStore.containsKey(key)) {
        log.debug("Broadcast group for device {} and subnet {} does not exist", deviceId, vlanId);
        return;
    }
    TrafficSelector metadata = DefaultTrafficSelector.builder().matchVlanId(vlanId).build();
    int nextId = vlanNextObjStore.get(key);
    NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.BROADCAST).fromApp(appId).withMeta(metadata);
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    if (popVlan) {
        tBuilder.popVlan();
    }
    tBuilder.setOutput(portNum);
    nextObjBuilder.addTreatment(tBuilder.build());
    ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("removeBroadcastGroupFromVlan removed " + "NextObj {} on {}", nextId, deviceId), (objective, error) -> {
        log.warn("removeBroadcastGroupFromVlan failed to remove NextObj {} on {}: {}", nextId, deviceId, error);
        srManager.invalidateNextObj(objective.id());
    });
    NextObjective nextObj = nextObjBuilder.remove(context);
    flowObjectiveService.next(deviceId, nextObj);
    log.debug("removeBcastGroupFromVlan: Submited next objective {} in device {}", nextId, deviceId);
    vlanNextObjStore.remove(key, nextId);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) MacVlanNextObjectiveStoreKey(org.onosproject.segmentrouting.storekey.MacVlanNextObjectiveStoreKey) VlanNextObjectiveStoreKey(org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

NextObjective (org.onosproject.net.flowobjective.NextObjective)83 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)57 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)56 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)55 TrafficSelector (org.onosproject.net.flow.TrafficSelector)51 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)47 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)36 Objective (org.onosproject.net.flowobjective.Objective)31 ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)30 DeviceId (org.onosproject.net.DeviceId)29 PortNumber (org.onosproject.net.PortNumber)24 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)24 DefaultObjectiveContext (org.onosproject.net.flowobjective.DefaultObjectiveContext)23 Set (java.util.Set)22 Test (org.junit.Test)22 List (java.util.List)21 Collectors (java.util.stream.Collectors)20 GroupBucket (org.onosproject.net.group.GroupBucket)19 GroupBuckets (org.onosproject.net.group.GroupBuckets)19 Lists (com.google.common.collect.Lists)18