use of org.onosproject.net.group.GroupOperation in project onos by opennetworkinglab.
the class GroupManagerTest method testRemoveGroup.
// Test group remove operations
private void testRemoveGroup(DeviceId deviceId) {
GroupKey currKey = new DefaultGroupKey("group1RemoveBuckets".getBytes());
Group existingGroup = groupService.getGroup(deviceId, currKey);
groupService.removeGroup(deviceId, currKey, appId);
List<GroupOperation> expectedGroupOps = Collections.singletonList(GroupOperation.createDeleteGroupOperation(existingGroup.id(), Group.Type.SELECT));
if (deviceId.equals(DID)) {
internalProvider.validate(deviceId, expectedGroupOps);
} else {
this.validate(deviceId, expectedGroupOps);
}
List<Group> groupEntries = Collections.emptyList();
providerService.pushGroupMetrics(deviceId, groupEntries);
internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_REMOVED));
}
use of org.onosproject.net.group.GroupOperation in project onos by opennetworkinglab.
the class OpenFlowGroupProviderTest method addGroup.
@Test
public void addGroup() {
GroupId groupId = new GroupId(1);
List<GroupBucket> bucketList = Lists.newArrayList();
TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
builder.setOutput(PortNumber.portNumber(1));
GroupBucket bucket = DefaultGroupBucket.createSelectGroupBucket(builder.build());
bucketList.add(bucket);
GroupBuckets buckets = new GroupBuckets(bucketList);
List<GroupOperation> operationList = Lists.newArrayList();
GroupOperation operation = GroupOperation.createAddGroupOperation(groupId, GroupDescription.Type.SELECT, buckets);
operationList.add(operation);
GroupOperations operations = new GroupOperations(operationList);
provider.performGroupOperation(deviceId, operations);
final Dpid dpid = Dpid.dpid(deviceId.uri());
TestOpenFlowSwitch sw = (TestOpenFlowSwitch) controller.getSwitch(dpid);
assertNotNull("Switch should not be nul", sw);
assertNotNull("OFGroupMsg should not be null", sw.msg);
}
use of org.onosproject.net.group.GroupOperation in project onos by opennetworkinglab.
the class P4RuntimeGroupProgrammable method doPerformGroupOperation.
private void doPerformGroupOperation(DeviceId deviceId, GroupOperations groupOps) {
// TODO: fix GroupProgrammable API, passing the device ID is ambiguous
checkArgument(deviceId.equals(data().deviceId()), "passed deviceId must be the same assigned to this behavior");
final List<GroupOperation> actionGroups = Lists.newArrayList();
final List<GroupOperation> preGroups = Lists.newArrayList();
groupOps.operations().forEach(op -> {
switch(op.groupType()) {
case INDIRECT:
case SELECT:
actionGroups.add(op);
break;
case ALL:
case CLONE:
preGroups.add(op);
break;
case FAILOVER:
default:
log.warn("{} group type not supported [{}]", op.groupType(), op);
}
});
if (!actionGroups.isEmpty()) {
actionProgrammable().performGroupOperation(deviceId, new GroupOperations(actionGroups));
}
if (!preGroups.isEmpty()) {
replicationProgrammable().performGroupOperation(deviceId, new GroupOperations(preGroups));
}
}
use of org.onosproject.net.group.GroupOperation in project onos by opennetworkinglab.
the class DistributedGroupStoreTest method testGroupOperationFailedWithErrorCode.
/**
* Tests group operation failed interface, with error codes for failures.
*/
@Test
public void testGroupOperationFailedWithErrorCode() {
TestDelegate delegate = new TestDelegate();
groupStore.setDelegate(delegate);
groupStore.deviceInitialAuditCompleted(deviceId1, true);
groupStore.storeGroupDescription(groupDescription1);
groupStore.deviceInitialAuditCompleted(deviceId2, true);
groupStore.storeGroupDescription(groupDescription2);
List<GroupEvent> eventsAfterAdds = delegate.eventsSeen();
assertThat(eventsAfterAdds, hasSize(2));
eventsAfterAdds.forEach(event -> assertThat(event.type(), is(GroupEvent.Type.GROUP_ADD_REQUESTED)));
delegate.resetEvents();
// test group exists
GroupOperation opAdd = GroupOperation.createAddGroupOperation(groupId1, ALL, allGroupBuckets);
GroupOperation addFailedExists = GroupOperation.createFailedGroupOperation(opAdd, GroupMsgErrorCode.GROUP_EXISTS);
groupStore.groupOperationFailed(deviceId1, addFailedExists);
List<GroupEvent> eventsAfterAddFailed = delegate.eventsSeen();
assertThat(eventsAfterAddFailed, hasSize(2));
assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADDED));
assertThat(eventsAfterAddFailed.get(1).type(), is(GroupEvent.Type.GROUP_ADDED));
Group g1 = groupStore.getGroup(deviceId1, groupId1);
assertEquals(0, g1.failedRetryCount());
delegate.resetEvents();
// test invalid group
Group g2 = groupStore.getGroup(deviceId2, groupId2);
assertEquals(0, g2.failedRetryCount());
assertEquals(GroupState.PENDING_ADD, g2.state());
GroupOperation opAdd1 = GroupOperation.createAddGroupOperation(groupId2, INDIRECT, indirectGroupBuckets);
GroupOperation addFailedInvalid = GroupOperation.createFailedGroupOperation(opAdd1, GroupMsgErrorCode.INVALID_GROUP);
groupStore.groupOperationFailed(deviceId2, addFailedInvalid);
groupStore.pushGroupMetrics(deviceId2, ImmutableList.of());
List<GroupEvent> eventsAfterAddFailed1 = delegate.eventsSeen();
assertThat(eventsAfterAddFailed1, hasSize(1));
assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADD_REQUESTED));
g2 = groupStore.getGroup(deviceId2, groupId2);
assertEquals(1, g2.failedRetryCount());
assertEquals(GroupState.PENDING_ADD_RETRY, g2.state());
delegate.resetEvents();
groupStore.groupOperationFailed(deviceId2, addFailedInvalid);
groupStore.pushGroupMetrics(deviceId2, ImmutableList.of());
List<GroupEvent> eventsAfterAddFailed2 = delegate.eventsSeen();
assertThat(eventsAfterAddFailed2, hasSize(1));
assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADD_REQUESTED));
g2 = groupStore.getGroup(deviceId2, groupId2);
assertEquals(2, g2.failedRetryCount());
assertEquals(GroupState.PENDING_ADD_RETRY, g2.state());
delegate.resetEvents();
groupStore.groupOperationFailed(deviceId2, addFailedInvalid);
groupStore.pushGroupMetrics(deviceId2, ImmutableList.of());
List<GroupEvent> eventsAfterAddFailed3 = delegate.eventsSeen();
assertThat(eventsAfterAddFailed3, hasSize(2));
assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADD_FAILED));
assertThat(eventsAfterAddFailed.get(1).type(), is(GroupEvent.Type.GROUP_REMOVED));
g2 = groupStore.getGroup(deviceId2, groupId2);
assertEquals(null, g2);
delegate.resetEvents();
}
use of org.onosproject.net.group.GroupOperation in project onos by opennetworkinglab.
the class OpenFlowGroupProvider method performGroupOperation.
@Override
public void performGroupOperation(DeviceId deviceId, GroupOperations groupOps) {
final Dpid dpid = Dpid.dpid(deviceId.uri());
OpenFlowSwitch sw = controller.getSwitch(dpid);
for (GroupOperation groupOperation : groupOps.operations()) {
if (sw == null) {
log.error("SW {} is not found", dpid);
return;
}
switch(groupOperation.groupType()) {
case SELECT:
case INDIRECT:
case ALL:
case FAILOVER:
break;
case CLONE:
default:
log.warn("Group type {} not supported, ignoring operation [{}]", groupOperation.groupType(), groupOperation);
// Next groupOperation.
continue;
}
final Long groupModXid = XID_COUNTER.getAndIncrement();
GroupModBuilder builder = null;
if (driverService == null) {
builder = GroupModBuilder.builder(groupOperation.buckets(), groupOperation.groupId(), groupOperation.groupType(), sw.factory(), Optional.of(groupModXid));
} else {
builder = GroupModBuilder.builder(groupOperation.buckets(), groupOperation.groupId(), groupOperation.groupType(), sw.factory(), Optional.of(groupModXid), Optional.of(driverService));
}
OFGroupMod groupMod = null;
switch(groupOperation.opType()) {
case ADD:
groupMod = builder.buildGroupAdd();
break;
case MODIFY:
groupMod = builder.buildGroupMod();
break;
case DELETE:
groupMod = builder.buildGroupDel();
break;
default:
log.error("Unsupported Group operation");
return;
}
sw.sendMsg(groupMod);
GroupId groudId = new GroupId(groupMod.getGroup().getGroupNumber());
pendingGroupOperations.put(groudId, groupOperation);
pendingXidMaps.put(groudId, groupModXid);
}
}
Aggregations