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());
}
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());
}
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);
}
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);
}
Aggregations