Search in sources :

Example 31 with GroupEvent

use of org.onosproject.net.group.GroupEvent in project onos by opennetworkinglab.

the class SimpleVirtualGroupStore method addOrUpdateExtraneousGroupEntry.

@Override
public void addOrUpdateExtraneousGroupEntry(NetworkId networkId, Group group) {
    ConcurrentMap<GroupId, Group> extraneousIdTable = getExtraneousGroupIdTable(networkId, group.deviceId());
    extraneousIdTable.put(group.id(), group);
    // Check the reference counter
    if (group.referenceCount() == 0) {
        notifyDelegate(networkId, new GroupEvent(GroupEvent.Type.GROUP_REMOVE_REQUESTED, group));
    }
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) GroupEvent(org.onosproject.net.group.GroupEvent) GroupId(org.onosproject.core.GroupId)

Example 32 with GroupEvent

use of org.onosproject.net.group.GroupEvent 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)

Aggregations

GroupEvent (org.onosproject.net.group.GroupEvent)32 StoredGroupEntry (org.onosproject.net.group.StoredGroupEntry)23 GroupId (org.onosproject.core.GroupId)13 DefaultGroup (org.onosproject.net.group.DefaultGroup)12 GroupKey (org.onosproject.net.group.GroupKey)11 Group (org.onosproject.net.group.Group)10 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)5 GroupBucket (org.onosproject.net.group.GroupBucket)5 GroupBuckets (org.onosproject.net.group.GroupBuckets)5 GroupDescription (org.onosproject.net.group.GroupDescription)5 ArrayList (java.util.ArrayList)4 GroupOperation (org.onosproject.net.group.GroupOperation)4 StoredGroupBucketEntry (org.onosproject.net.group.StoredGroupBucketEntry)4 FluentIterable (com.google.common.collect.FluentIterable)2 Sets (com.google.common.collect.Sets)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2