use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class SimpleGroupStoreTest method testAddBuckets.
// Testing updateGroupDescription for ADD operation from northbound
private void testAddBuckets(GroupKey currKey, GroupKey addKey) {
Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
List<GroupBucket> buckets = new ArrayList<>();
buckets.addAll(existingGroup.buckets().buckets());
PortNumber[] newNeighborPorts = { PortNumber.portNumber(41), PortNumber.portNumber(42) };
List<PortNumber> newOutPorts = new ArrayList<>();
newOutPorts.addAll(Collections.singletonList(newNeighborPorts[0]));
List<GroupBucket> toAddBuckets = new ArrayList<>();
for (PortNumber portNumber : newOutPorts) {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
tBuilder.setOutput(portNumber).setEthDst(MacAddress.valueOf("00:00:00:00:00:03")).setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")).pushMpls().setMpls(MplsLabel.mplsLabel(106));
toAddBuckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
}
GroupBuckets toAddGroupBuckets = new GroupBuckets(toAddBuckets);
buckets.addAll(toAddBuckets);
GroupBuckets updatedGroupBuckets = new GroupBuckets(buckets);
InternalGroupStoreDelegate updateGroupDescDelegate = new InternalGroupStoreDelegate(addKey, updatedGroupBuckets, GroupEvent.Type.GROUP_UPDATE_REQUESTED);
simpleGroupStore.setDelegate(updateGroupDescDelegate);
simpleGroupStore.updateGroupDescription(D1, currKey, UpdateType.ADD, toAddGroupBuckets, addKey);
simpleGroupStore.unsetDelegate(updateGroupDescDelegate);
short weight = 5;
toAddBuckets = new ArrayList<>();
for (PortNumber portNumber : newOutPorts) {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
tBuilder.setOutput(portNumber).setEthDst(MacAddress.valueOf("00:00:00:00:00:03")).setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")).pushMpls().setMpls(MplsLabel.mplsLabel(106));
toAddBuckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build(), weight));
}
toAddGroupBuckets = new GroupBuckets(toAddBuckets);
buckets = new ArrayList<>();
buckets.addAll(existingGroup.buckets().buckets());
buckets.addAll(toAddBuckets);
updatedGroupBuckets = new GroupBuckets(buckets);
updateGroupDescDelegate = new InternalGroupStoreDelegate(addKey, updatedGroupBuckets, GroupEvent.Type.GROUP_UPDATE_REQUESTED);
simpleGroupStore.setDelegate(updateGroupDescDelegate);
simpleGroupStore.updateGroupDescription(D1, addKey, UpdateType.ADD, toAddGroupBuckets, addKey);
simpleGroupStore.unsetDelegate(updateGroupDescDelegate);
}
use of org.onosproject.net.group.GroupBucket 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.GroupBucket 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.GroupBucket in project onos by opennetworkinglab.
the class GroupsListCommand method printGroups.
private void printGroups(DeviceId deviceId, List<Group> groups) {
print("deviceId=%s, groupCount=%s", deviceId, groups.size());
if (countOnly) {
return;
}
for (Group group : groups) {
print(FORMAT, Integer.toHexString(group.id().id()), group.state(), group.type(), group.bytes(), group.packets(), group.appId().name(), group.referenceCount());
int i = 0;
for (GroupBucket bucket : group.buckets().buckets()) {
print(BUCKET_FORMAT, Integer.toHexString(group.id().id()), ++i, bucket.bytes(), bucket.packets(), bucket.weight(), bucket.treatment().allInstructions());
}
}
}
use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class KubevirtLbHandler method setBucketsToGroup.
private void setBucketsToGroup(KubevirtLoadBalancer loadBalancer, KubevirtNode gateway, boolean install) {
int groupId = loadBalancer.hashCode();
KubevirtNetwork network = networkService.network(loadBalancer.networkId());
Set<KubevirtPort> ports = portService.ports(loadBalancer.networkId());
List<GroupBucket> bkts = Lists.newArrayList();
loadBalancer.members().forEach(ip -> {
ports.stream().filter(port -> port.ipAddress().equals(ip) && port.macAddress() != null).findAny().ifPresent(port -> bkts.add(buildGroupBucket(port)));
});
groupRuleService.setBuckets(appId, gateway.intgBridge(), groupId, bkts, install);
}
Aggregations