Search in sources :

Example 96 with GroupKey

use of org.onosproject.net.group.GroupKey in project onos by opennetworkinglab.

the class GroupsWebResource method updateGroupBuckets.

/**
 * Adds buckets to a group using the group service.
 *
 * @param deviceIdString device Id
 * @param appCookieString application cookie
 * @param stream JSON stream
 */
private void updateGroupBuckets(String deviceIdString, String appCookieString, InputStream stream) throws IOException {
    GroupService groupService = get(GroupService.class);
    DeviceId deviceId = DeviceId.deviceId(deviceIdString);
    final GroupKey groupKey = createKey(appCookieString);
    Group group = nullIsNotFound(groupService.getGroup(deviceId, groupKey), GROUP_NOT_FOUND);
    ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
    GroupBuckets buckets = null;
    List<GroupBucket> groupBucketList = new ArrayList<>();
    JsonNode bucketsJson = jsonTree.get("buckets");
    final JsonCodec<GroupBucket> groupBucketCodec = codec(GroupBucket.class);
    if (bucketsJson != null) {
        IntStream.range(0, bucketsJson.size()).forEach(i -> {
            ObjectNode bucketJson = (ObjectNode) bucketsJson.get(i);
            groupBucketList.add(groupBucketCodec.decode(bucketJson, this));
        });
        buckets = new GroupBuckets(groupBucketList);
    }
    groupService.addBucketsToGroup(deviceId, groupKey, buckets, groupKey, group.appId());
}
Also used : Group(org.onosproject.net.group.Group) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) ArrayList(java.util.ArrayList) GroupBucket(org.onosproject.net.group.GroupBucket) JsonNode(com.fasterxml.jackson.databind.JsonNode) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupService(org.onosproject.net.group.GroupService)

Example 97 with GroupKey

use of org.onosproject.net.group.GroupKey in project onos by opennetworkinglab.

the class GroupsWebResource method removeGroupBuckets.

/**
 * Removes buckets from a group using the group service.
 *
 * @param deviceIdString device Id
 * @param appCookieString application cookie
 * @param bucketIds comma separated list of bucket Ids to remove
 */
private void removeGroupBuckets(String deviceIdString, String appCookieString, String bucketIds) {
    DeviceId deviceId = DeviceId.deviceId(deviceIdString);
    final GroupKey groupKey = createKey(appCookieString);
    GroupService groupService = get(GroupService.class);
    Group group = nullIsNotFound(groupService.getGroup(deviceId, groupKey), GROUP_NOT_FOUND);
    List<GroupBucket> groupBucketList = new ArrayList<>();
    List<String> bucketsToRemove = ImmutableList.copyOf(bucketIds.split(","));
    bucketsToRemove.forEach(bucketIdToRemove -> {
        group.buckets().buckets().stream().filter(bucket -> Integer.toString(bucket.hashCode()).equals(bucketIdToRemove)).forEach(groupBucketList::add);
    });
    groupService.removeBucketsFromGroup(deviceId, groupKey, new GroupBuckets(groupBucketList), groupKey, group.appId());
}
Also used : IntStream(java.util.stream.IntStream) PathParam(javax.ws.rs.PathParam) AbstractWebResource(org.onosproject.rest.AbstractWebResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) DeviceService(org.onosproject.net.device.DeviceService) Path(javax.ws.rs.Path) GroupBucket(org.onosproject.net.group.GroupBucket) GroupKey(org.onosproject.net.group.GroupKey) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) MediaType(javax.ws.rs.core.MediaType) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) Consumes(javax.ws.rs.Consumes) JsonNode(com.fasterxml.jackson.databind.JsonNode) UriBuilder(javax.ws.rs.core.UriBuilder) DELETE(javax.ws.rs.DELETE) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) Tools.nullIsNotFound(org.onlab.util.Tools.nullIsNotFound) Device(org.onosproject.net.Device) GroupService(org.onosproject.net.group.GroupService) IOException(java.io.IOException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) HexString(org.onlab.util.HexString) Response(javax.ws.rs.core.Response) JsonCodec(org.onosproject.codec.JsonCodec) GroupBuckets(org.onosproject.net.group.GroupBuckets) UriInfo(javax.ws.rs.core.UriInfo) DeviceId(org.onosproject.net.DeviceId) Tools.readTreeFromStream(org.onlab.util.Tools.readTreeFromStream) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) InputStream(java.io.InputStream) Group(org.onosproject.net.group.Group) DeviceId(org.onosproject.net.DeviceId) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) ArrayList(java.util.ArrayList) GroupBucket(org.onosproject.net.group.GroupBucket) HexString(org.onlab.util.HexString) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupService(org.onosproject.net.group.GroupService)

Example 98 with GroupKey

use of org.onosproject.net.group.GroupKey in project TFG by mattinelorza.

the class Utils method buildReplicationGroup.

private static GroupDescription buildReplicationGroup(ApplicationId appId, DeviceId deviceId, int groupId, Collection<PortNumber> ports, boolean isClone) {
    checkNotNull(deviceId);
    checkNotNull(appId);
    checkArgument(!ports.isEmpty());
    final GroupKey groupKey = new DefaultGroupKey(ByteBuffer.allocate(4).putInt(groupId).array());
    final List<GroupBucket> bucketList = ports.stream().map(p -> DefaultTrafficTreatment.builder().setOutput(p).build()).map(t -> isClone ? createCloneGroupBucket(t) : createAllGroupBucket(t)).collect(Collectors.toList());
    return new DefaultGroupDescription(deviceId, isClone ? GroupDescription.Type.CLONE : GroupDescription.Type.ALL, new GroupBuckets(bucketList), groupKey, groupId, appId);
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) GroupBucket(org.onosproject.net.group.GroupBucket) GroupKey(org.onosproject.net.group.GroupKey) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) DefaultGroupBucket.createCloneGroupBucket(org.onosproject.net.group.DefaultGroupBucket.createCloneGroupBucket) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) ApplicationId(org.onosproject.core.ApplicationId) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) PiActionProfileId(org.onosproject.net.pi.model.PiActionProfileId) PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) Logger(org.slf4j.Logger) DefaultGroupBucket.createAllGroupBucket(org.onosproject.net.group.DefaultGroupBucket.createAllGroupBucket) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) Collectors(java.util.stream.Collectors) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) PiAction(org.onosproject.net.pi.runtime.PiAction) DEFAULT_FLOW_RULE_PRIORITY(org.onosproject.ngsdn.tutorial.AppConstants.DEFAULT_FLOW_RULE_PRIORITY) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) GroupBuckets(org.onosproject.net.group.GroupBuckets) DeviceId(org.onosproject.net.DeviceId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket.createCloneGroupBucket(org.onosproject.net.group.DefaultGroupBucket.createCloneGroupBucket) DefaultGroupBucket.createAllGroupBucket(org.onosproject.net.group.DefaultGroupBucket.createAllGroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Example 99 with GroupKey

use of org.onosproject.net.group.GroupKey in project TFG by mattinelorza.

the class Utils method buildSelectGroup.

public static GroupDescription buildSelectGroup(DeviceId deviceId, String tableId, String actionProfileId, int groupId, Collection<PiAction> actions, ApplicationId appId) {
    final GroupKey groupKey = new PiGroupKey(PiTableId.of(tableId), PiActionProfileId.of(actionProfileId), groupId);
    final List<GroupBucket> buckets = actions.stream().map(action -> DefaultTrafficTreatment.builder().piTableAction(action).build()).map(DefaultGroupBucket::createSelectGroupBucket).collect(Collectors.toList());
    return new DefaultGroupDescription(deviceId, GroupDescription.Type.SELECT, new GroupBuckets(buckets), groupKey, groupId, appId);
}
Also used : PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket.createCloneGroupBucket(org.onosproject.net.group.DefaultGroupBucket.createCloneGroupBucket) DefaultGroupBucket.createAllGroupBucket(org.onosproject.net.group.DefaultGroupBucket.createAllGroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Aggregations

GroupKey (org.onosproject.net.group.GroupKey)99 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)83 GroupBuckets (org.onosproject.net.group.GroupBuckets)59 GroupBucket (org.onosproject.net.group.GroupBucket)58 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)52 Group (org.onosproject.net.group.Group)50 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)48 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)48 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)47 GroupDescription (org.onosproject.net.group.GroupDescription)46 GroupId (org.onosproject.core.GroupId)31 ArrayList (java.util.ArrayList)29 PortNumber (org.onosproject.net.PortNumber)27 DefaultGroup (org.onosproject.net.group.DefaultGroup)27 NextGroup (org.onosproject.net.behaviour.NextGroup)24 OfdpaGroupHandlerUtility.l2MulticastGroupKey (org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey)21 ArrayDeque (java.util.ArrayDeque)20 Deque (java.util.Deque)19 TrafficSelector (org.onosproject.net.flow.TrafficSelector)18 Instruction (org.onosproject.net.flow.instructions.Instruction)18