use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class SimpleGroupStore method updateGroupDescription.
/**
* Updates the existing group entry with the information
* from group description.
*
* @param deviceId the device ID
* @param oldAppCookie the current group key
* @param type update type
* @param newBuckets group buckets for updates
* @param newAppCookie optional new group key
*/
@Override
public void updateGroupDescription(DeviceId deviceId, GroupKey oldAppCookie, UpdateType type, GroupBuckets newBuckets, GroupKey newAppCookie) {
// Check if a group is existing with the provided key
Group oldGroup = getGroup(deviceId, oldAppCookie);
if (oldGroup == null) {
return;
}
List<GroupBucket> newBucketList = getUpdatedBucketList(oldGroup, type, newBuckets);
if (newBucketList != null) {
// Create a new group object from the old group
GroupBuckets updatedBuckets = new GroupBuckets(newBucketList);
GroupKey newCookie = (newAppCookie != null) ? newAppCookie : oldAppCookie;
GroupDescription updatedGroupDesc = new DefaultGroupDescription(oldGroup.deviceId(), oldGroup.type(), updatedBuckets, newCookie, oldGroup.givenGroupId(), oldGroup.appId());
StoredGroupEntry newGroup = new DefaultGroup(oldGroup.id(), updatedGroupDesc);
newGroup.setState(GroupState.PENDING_UPDATE);
newGroup.setLife(oldGroup.life());
newGroup.setPackets(oldGroup.packets());
newGroup.setBytes(oldGroup.bytes());
// Remove the old entry from maps and add new entry using new key
ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(oldGroup.deviceId());
ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(oldGroup.deviceId());
keyTable.remove(oldGroup.appCookie());
idTable.remove(oldGroup.id());
keyTable.put(newGroup.appCookie(), newGroup);
idTable.put(newGroup.id(), newGroup);
notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_REQUESTED, newGroup));
}
}
use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class SimpleGroupStoreTest method testUpdateGroupEntryFromSB.
// Testing addOrUpdateGroupEntry operation from southbound
private void testUpdateGroupEntryFromSB(GroupKey currKey) {
Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
int totalPkts = 0;
int totalBytes = 0;
List<GroupBucket> newBucketList = new ArrayList<>();
for (GroupBucket bucket : existingGroup.buckets().buckets()) {
StoredGroupBucketEntry newBucket = (StoredGroupBucketEntry) DefaultGroupBucket.createSelectGroupBucket(bucket.treatment());
newBucket.setPackets(10);
newBucket.setBytes(10 * 256 * 8);
totalPkts += 10;
totalBytes += 10 * 256 * 8;
newBucketList.add(newBucket);
}
GroupBuckets updatedBuckets = new GroupBuckets(newBucketList);
Group updatedGroup = new DefaultGroup(existingGroup.id(), existingGroup.deviceId(), existingGroup.type(), updatedBuckets);
((StoredGroupEntry) updatedGroup).setPackets(totalPkts);
((StoredGroupEntry) updatedGroup).setBytes(totalBytes);
InternalGroupStoreDelegate updateGroupEntryDelegate = new InternalGroupStoreDelegate(currKey, updatedBuckets, GroupEvent.Type.GROUP_UPDATED);
simpleGroupStore.setDelegate(updateGroupEntryDelegate);
simpleGroupStore.addOrUpdateGroupEntry(updatedGroup);
simpleGroupStore.unsetDelegate(updateGroupEntryDelegate);
}
use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class SimpleGroupStoreTest method testStoreAndGetGroup.
// Testing storeGroup operation
private void testStoreAndGetGroup(GroupKey key) {
PortNumber[] ports = { PortNumber.portNumber(31), PortNumber.portNumber(32) };
List<PortNumber> outPorts = new ArrayList<>();
outPorts.addAll(Arrays.asList(ports));
List<GroupBucket> buckets = new ArrayList<>();
for (PortNumber portNumber : outPorts) {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
tBuilder.setOutput(portNumber).setEthDst(MacAddress.valueOf("00:00:00:00:00:02")).setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")).pushMpls().setMpls(MplsLabel.mplsLabel(106));
buckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
}
GroupBuckets groupBuckets = new GroupBuckets(buckets);
GroupDescription groupDesc = new DefaultGroupDescription(D1, Group.Type.SELECT, groupBuckets, key, null, appId);
InternalGroupStoreDelegate checkStoreGroupDelegate = new InternalGroupStoreDelegate(key, groupBuckets, GroupEvent.Type.GROUP_ADD_REQUESTED);
simpleGroupStore.setDelegate(checkStoreGroupDelegate);
// Testing storeGroup operation
simpleGroupStore.storeGroupDescription(groupDesc);
// Testing getGroupCount operation
assertEquals(1, simpleGroupStore.getGroupCount(D1));
// Testing getGroup operation
Group createdGroup = simpleGroupStore.getGroup(D1, key);
checkStoreGroupDelegate.verifyGroupId(createdGroup.id());
// Testing getGroups operation
Iterable<Group> createdGroups = simpleGroupStore.getGroups(D1);
int groupCount = 0;
for (Group group : createdGroups) {
checkStoreGroupDelegate.verifyGroupId(group.id());
groupCount++;
}
assertEquals(1, groupCount);
simpleGroupStore.unsetDelegate(checkStoreGroupDelegate);
}
use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class SimpleGroupStoreTest method testRemoveBuckets.
// Testing updateGroupDescription for REMOVE operation from northbound
private void testRemoveBuckets(GroupKey currKey, GroupKey removeKey) {
Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
List<GroupBucket> buckets = new ArrayList<>();
buckets.addAll(existingGroup.buckets().buckets());
List<GroupBucket> toRemoveBuckets = new ArrayList<>();
// There should be 4 buckets in the current group
toRemoveBuckets.add(buckets.remove(0));
toRemoveBuckets.add(buckets.remove(1));
GroupBuckets toRemoveGroupBuckets = new GroupBuckets(toRemoveBuckets);
GroupBuckets remainingGroupBuckets = new GroupBuckets(buckets);
InternalGroupStoreDelegate removeGroupDescDelegate = new InternalGroupStoreDelegate(removeKey, remainingGroupBuckets, GroupEvent.Type.GROUP_UPDATE_REQUESTED);
simpleGroupStore.setDelegate(removeGroupDescDelegate);
simpleGroupStore.updateGroupDescription(D1, currKey, UpdateType.REMOVE, toRemoveGroupBuckets, removeKey);
simpleGroupStore.unsetDelegate(removeGroupDescDelegate);
}
use of org.onosproject.net.group.GroupBucket in project onos by opennetworkinglab.
the class GroupCodecTest method codecEncodeTest.
@Test
public void codecEncodeTest() {
GroupBucket bucket1 = DefaultGroupBucket.createAllGroupBucket(DefaultTrafficTreatment.emptyTreatment());
GroupBucket bucket2 = DefaultGroupBucket.createAllGroupBucket(DefaultTrafficTreatment.emptyTreatment());
GroupBucket bucket3 = DefaultGroupBucket.createIndirectGroupBucket(DefaultTrafficTreatment.emptyTreatment());
GroupBuckets allBuckets = new GroupBuckets(ImmutableList.of(bucket1, bucket2));
GroupBuckets indirectBuckets = new GroupBuckets(ImmutableList.of(bucket3));
DefaultGroup group = new DefaultGroup(new GroupId(1), NetTestTools.did("d1"), ALL, allBuckets);
DefaultGroup group1 = new DefaultGroup(new GroupId(2), NetTestTools.did("d2"), INDIRECT, indirectBuckets);
MockCodecContext context = new MockCodecContext();
GroupCodec codec = new GroupCodec();
ObjectNode groupJson = codec.encode(group, context);
ObjectNode groupJsonIndirect = codec.encode(group1, context);
assertThat(groupJson, matchesGroup(group));
assertThat(groupJsonIndirect, matchesGroup(group1));
}
Aggregations