use of org.onosproject.net.group.DefaultGroupKey in project onos by opennetworkinglab.
the class GroupManagerTest method testAddBuckets.
// Test group add bucket operations
private void testAddBuckets(DeviceId deviceId) {
GroupKey addKey = new DefaultGroupKey("group1AddBuckets".getBytes());
GroupKey prevKey = new DefaultGroupKey("group1BeforeAudit".getBytes());
Group createdGroup = groupService.getGroup(deviceId, prevKey);
List<GroupBucket> buckets = new ArrayList<>();
buckets.addAll(createdGroup.buckets().buckets());
PortNumber[] addPorts = { PortNumber.portNumber(51), PortNumber.portNumber(52) };
List<PortNumber> outPorts;
outPorts = new ArrayList<>();
outPorts.addAll(Arrays.asList(addPorts));
List<GroupBucket> addBuckets;
addBuckets = 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));
addBuckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
buckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
}
GroupBuckets groupAddBuckets = new GroupBuckets(addBuckets);
groupService.addBucketsToGroup(deviceId, prevKey, groupAddBuckets, addKey, appId);
GroupBuckets updatedBuckets = new GroupBuckets(buckets);
List<GroupOperation> expectedGroupOps = Collections.singletonList(GroupOperation.createModifyGroupOperation(createdGroup.id(), Group.Type.SELECT, updatedBuckets));
if (deviceId.equals(DID)) {
internalProvider.validate(deviceId, expectedGroupOps);
} else {
this.validate(deviceId, expectedGroupOps);
}
Group existingGroup = groupService.getGroup(deviceId, addKey);
List<Group> groupEntries = Collections.singletonList(existingGroup);
providerService.pushGroupMetrics(deviceId, groupEntries);
internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_UPDATED));
}
use of org.onosproject.net.group.DefaultGroupKey in project onos by opennetworkinglab.
the class GroupManagerTest method testRemoveBuckets.
// Test group remove bucket operations
private void testRemoveBuckets(DeviceId deviceId) {
GroupKey removeKey = new DefaultGroupKey("group1RemoveBuckets".getBytes());
GroupKey prevKey = new DefaultGroupKey("group1AddBuckets".getBytes());
Group createdGroup = groupService.getGroup(deviceId, prevKey);
List<GroupBucket> buckets = new ArrayList<>();
buckets.addAll(createdGroup.buckets().buckets());
PortNumber[] removePorts = { PortNumber.portNumber(31), PortNumber.portNumber(32) };
List<PortNumber> outPorts = new ArrayList<>();
outPorts.addAll(Arrays.asList(removePorts));
List<GroupBucket> removeBuckets = 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));
removeBuckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
buckets.remove(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
}
GroupBuckets groupRemoveBuckets = new GroupBuckets(removeBuckets);
groupService.removeBucketsFromGroup(deviceId, prevKey, groupRemoveBuckets, removeKey, appId);
GroupBuckets updatedBuckets = new GroupBuckets(buckets);
List<GroupOperation> expectedGroupOps = Collections.singletonList(GroupOperation.createModifyGroupOperation(createdGroup.id(), Group.Type.SELECT, updatedBuckets));
if (deviceId.equals(DID)) {
internalProvider.validate(deviceId, expectedGroupOps);
} else {
this.validate(deviceId, expectedGroupOps);
}
Group existingGroup = groupService.getGroup(deviceId, removeKey);
List<Group> groupEntries = Collections.singletonList(existingGroup);
providerService.pushGroupMetrics(deviceId, groupEntries);
internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_UPDATED));
}
use of org.onosproject.net.group.DefaultGroupKey in project onos by opennetworkinglab.
the class GroupManagerTest method testInitialAuditWithPendingGroupRequests.
// Test initial AUDIT process with pending group requests
private void testInitialAuditWithPendingGroupRequests(DeviceId deviceId) {
PortNumber[] ports1 = { PortNumber.portNumber(31), PortNumber.portNumber(32) };
PortNumber[] ports2 = { PortNumber.portNumber(41), PortNumber.portNumber(42) };
GroupId gId1 = new GroupId(1);
Group group1 = createSouthboundGroupEntry(gId1, Arrays.asList(ports1), 0, deviceId);
GroupId gId2 = new GroupId(2);
// Non zero reference count will make the group manager to queue
// the extraneous groups until reference count is zero.
Group group2 = createSouthboundGroupEntry(gId2, Arrays.asList(ports2), 2, deviceId);
List<Group> groupEntries = Arrays.asList(group1, group2);
providerService.pushGroupMetrics(deviceId, groupEntries);
// First group metrics would trigger the device audit completion
// post which all pending group requests are also executed.
GroupKey key = new DefaultGroupKey("group1BeforeAudit".getBytes());
Group createdGroup = groupService.getGroup(deviceId, key);
int createdGroupId = createdGroup.id().id();
assertNotEquals(gId1.id().intValue(), createdGroupId);
assertNotEquals(gId2.id().intValue(), createdGroupId);
List<GroupOperation> expectedGroupOps = Arrays.asList(GroupOperation.createDeleteGroupOperation(gId1, Group.Type.SELECT), GroupOperation.createAddGroupOperation(createdGroup.id(), Group.Type.SELECT, createdGroup.buckets()));
if (deviceId.equals(DID)) {
internalProvider.validate(deviceId, expectedGroupOps);
} else {
this.validate(deviceId, expectedGroupOps);
}
}
use of org.onosproject.net.group.DefaultGroupKey in project onos by opennetworkinglab.
the class DistributedGroupStoreTest method testPushGroupMetrics.
/**
* Tests pushing group metrics.
*/
@Test
public void testPushGroupMetrics() {
groupStore.deviceInitialAuditCompleted(deviceId1, true);
groupStore.deviceInitialAuditCompleted(deviceId2, true);
GroupDescription groupDescription3 = new DefaultGroupDescription(deviceId1, ALL, allGroupBuckets, new DefaultGroupKey("aaa".getBytes()), null, APP_ID);
groupStore.storeGroupDescription(groupDescription1);
groupStore.storeGroupDescription(groupDescription2);
groupStore.storeGroupDescription(groupDescription3);
Group group1 = groupStore.getGroup(deviceId1, groupId1);
assertThat(group1, instanceOf(DefaultGroup.class));
DefaultGroup defaultGroup1 = (DefaultGroup) group1;
defaultGroup1.setPackets(55L);
defaultGroup1.setBytes(66L);
groupStore.pushGroupMetrics(deviceId1, ImmutableList.of(group1));
// Make sure the group was updated.
Group requeryGroup1 = groupStore.getGroup(deviceId1, groupId1);
assertThat(requeryGroup1.packets(), is(55L));
assertThat(requeryGroup1.bytes(), is(66L));
}
use of org.onosproject.net.group.DefaultGroupKey in project onos by opennetworkinglab.
the class DistributedGroupStoreTest method testUpdateGroupDescription.
/**
* Tests updating of group descriptions.
*/
@Test
public void testUpdateGroupDescription() {
GroupBuckets buckets = new GroupBuckets(ImmutableList.of(allGroupBucket2));
groupStore.deviceInitialAuditCompleted(deviceId1, true);
groupStore.storeGroupDescription(groupDescription1);
GroupKey newKey = new DefaultGroupKey("123".getBytes());
groupStore.updateGroupDescription(deviceId1, groupKey1, ADD, buckets, newKey);
Group group1 = groupStore.getGroup(deviceId1, groupId1);
assertThat(group1.appCookie(), is(newKey));
assertThat(group1.buckets().buckets(), hasSize(2));
buckets = new GroupBuckets(ImmutableList.of(allGroupBucket, allGroupBucket2));
groupStore.updateGroupDescription(deviceId1, newKey, ADD, buckets, newKey);
group1 = groupStore.getGroup(deviceId1, groupId1);
assertThat(group1.appCookie(), is(newKey));
assertThat(group1.buckets().buckets(), hasSize(2));
for (GroupBucket bucket : group1.buckets().buckets()) {
assertTrue(bucket.treatment().equals(treatment) || bucket.treatment().equals(treatment2));
}
buckets = new GroupBuckets(ImmutableList.of(allGroupBucket2));
groupStore.updateGroupDescription(deviceId1, newKey, SET, buckets, newKey);
group1 = groupStore.getGroup(deviceId1, groupId1);
assertThat(group1.appCookie(), is(newKey));
assertThat(group1.buckets().buckets(), hasSize(1));
GroupBucket onlyBucket = group1.buckets().buckets().iterator().next();
assertEquals(treatment2, onlyBucket.treatment());
}
Aggregations