Search in sources :

Example 11 with GroupOperation

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));
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) GroupOperation(org.onosproject.net.group.GroupOperation)

Example 12 with GroupOperation

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);
}
Also used : GroupOperations(org.onosproject.net.group.GroupOperations) Dpid(org.onosproject.openflow.controller.Dpid) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupOperation(org.onosproject.net.group.GroupOperation) GroupId(org.onosproject.core.GroupId) Test(org.junit.Test)

Example 13 with GroupOperation

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));
    }
}
Also used : GroupOperations(org.onosproject.net.group.GroupOperations) GroupOperation(org.onosproject.net.group.GroupOperation)

Example 14 with GroupOperation

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();
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) GroupEvent(org.onosproject.net.group.GroupEvent) GroupOperation(org.onosproject.net.group.GroupOperation) Test(org.junit.Test)

Example 15 with GroupOperation

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);
    }
}
Also used : OFGroupMod(org.projectfloodlight.openflow.protocol.OFGroupMod) Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) AtomicLong(java.util.concurrent.atomic.AtomicLong) GroupOperation(org.onosproject.net.group.GroupOperation) GroupId(org.onosproject.core.GroupId)

Aggregations

GroupOperation (org.onosproject.net.group.GroupOperation)18 DefaultGroup (org.onosproject.net.group.DefaultGroup)13 Group (org.onosproject.net.group.Group)13 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)12 GroupKey (org.onosproject.net.group.GroupKey)12 PortNumber (org.onosproject.net.PortNumber)10 GroupId (org.onosproject.core.GroupId)8 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)8 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)8 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)8 GroupBucket (org.onosproject.net.group.GroupBucket)8 GroupBuckets (org.onosproject.net.group.GroupBuckets)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 VirtualGroupProviderService (org.onosproject.incubator.net.virtual.provider.VirtualGroupProviderService)5 GroupOperations (org.onosproject.net.group.GroupOperations)3 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)2 GroupDescription (org.onosproject.net.group.GroupDescription)2 GroupEvent (org.onosproject.net.group.GroupEvent)2 Dpid (org.onosproject.openflow.controller.Dpid)2