use of org.onosproject.net.group.GroupBuckets 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.GroupBuckets 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.GroupBuckets 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.GroupBuckets 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));
}
use of org.onosproject.net.group.GroupBuckets in project onos by opennetworkinglab.
the class GroupBucketEntryBuilder method build.
/**
* Builds a GroupBuckets.
*
* @return GroupBuckets object, a list of GroupBuckets
*/
public GroupBuckets build() {
List<GroupBucket> bucketList = Lists.newArrayList();
for (OFBucket bucket : ofBuckets) {
TrafficTreatment treatment = buildTreatment(bucket.getActions());
// TODO: Use GroupBucketEntry
GroupBucket groupBucket = null;
switch(type) {
case INDIRECT:
groupBucket = DefaultGroupBucket.createIndirectGroupBucket(treatment);
break;
case SELECT:
groupBucket = DefaultGroupBucket.createSelectGroupBucket(treatment, (short) bucket.getWeight());
break;
case FF:
PortNumber port = PortNumber.portNumber(bucket.getWatchPort().getPortNumber());
GroupId groupId = new GroupId(bucket.getWatchGroup().getGroupNumber());
groupBucket = DefaultGroupBucket.createFailoverGroupBucket(treatment, port, groupId);
break;
case ALL:
groupBucket = DefaultGroupBucket.createAllGroupBucket(treatment);
break;
default:
log.error("Unsupported Group type : {}", type);
}
if (groupBucket != null) {
bucketList.add(groupBucket);
}
}
return new GroupBuckets(bucketList);
}
Aggregations