use of org.onosproject.net.group.GroupBuckets in project onos by opennetworkinglab.
the class SimpleGroupStoreTest method testSetBuckets.
// Testing updateGroupDescription for SET operation from northbound
private void testSetBuckets(GroupKey currKey, GroupKey setKey) {
List<GroupBucket> toSetBuckets = new ArrayList<>();
short weight = 5;
PortNumber portNumber = PortNumber.portNumber(42);
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));
toSetBuckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build(), weight));
GroupBuckets toSetGroupBuckets = new GroupBuckets(toSetBuckets);
InternalGroupStoreDelegate updateGroupDescDelegate = new InternalGroupStoreDelegate(setKey, toSetGroupBuckets, GroupEvent.Type.GROUP_UPDATE_REQUESTED);
simpleGroupStore.setDelegate(updateGroupDescDelegate);
simpleGroupStore.updateGroupDescription(D1, currKey, UpdateType.SET, toSetGroupBuckets, setKey);
simpleGroupStore.unsetDelegate(updateGroupDescDelegate);
}
use of org.onosproject.net.group.GroupBuckets 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.GroupBuckets 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.GroupBuckets 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.GroupBuckets in project onos by opennetworkinglab.
the class KubevirtGroupRuleManager method setRule.
@Override
public void setRule(ApplicationId appId, DeviceId deviceId, int groupId, GroupDescription.Type type, List<GroupBucket> buckets, boolean install) {
Group group = groupService.getGroup(deviceId, getGroupKey(groupId));
if (install) {
if (group == null) {
GroupDescription groupDesc = new DefaultGroupDescription(deviceId, type, new GroupBuckets(buckets), getGroupKey(groupId), groupId, appId);
groupService.addGroup(groupDesc);
log.debug("Adding group table rule {}", groupId);
}
} else {
if (group != null) {
groupService.removeGroup(deviceId, getGroupKey(groupId), appId);
log.debug("Removing group table rule {}", groupId);
}
}
}
Aggregations