Search in sources :

Example 1 with GroupEvent

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

the class DistributedGroupStoreTest method testGroupOperationFailed.

/**
 * Tests group operation failed interface.
 */
@Test
public void testGroupOperationFailed() {
    TestDelegate delegate = new TestDelegate();
    groupStore.setDelegate(delegate);
    groupStore.deviceInitialAuditCompleted(deviceId1, true);
    groupStore.deviceInitialAuditCompleted(deviceId2, true);
    groupStore.storeGroupDescription(groupDescription1);
    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();
    GroupOperation opAdd = GroupOperation.createAddGroupOperation(groupId1, INDIRECT, indirectGroupBuckets);
    groupStore.groupOperationFailed(deviceId1, opAdd);
    List<GroupEvent> eventsAfterAddFailed = delegate.eventsSeen();
    assertThat(eventsAfterAddFailed, hasSize(2));
    assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADD_FAILED));
    assertThat(eventsAfterAddFailed.get(1).type(), is(GroupEvent.Type.GROUP_REMOVED));
    delegate.resetEvents();
    GroupOperation opModify = GroupOperation.createModifyGroupOperation(groupId2, INDIRECT, indirectGroupBuckets);
    groupStore.groupOperationFailed(deviceId2, opModify);
    List<GroupEvent> eventsAfterModifyFailed = delegate.eventsSeen();
    assertThat(eventsAfterModifyFailed, hasSize(1));
    assertThat(eventsAfterModifyFailed.get(0).type(), is(GroupEvent.Type.GROUP_UPDATE_FAILED));
    delegate.resetEvents();
    GroupOperation opDelete = GroupOperation.createDeleteGroupOperation(groupId2, INDIRECT);
    groupStore.groupOperationFailed(deviceId2, opDelete);
    List<GroupEvent> eventsAfterDeleteFailed = delegate.eventsSeen();
    assertThat(eventsAfterDeleteFailed, hasSize(1));
    assertThat(eventsAfterDeleteFailed.get(0).type(), is(GroupEvent.Type.GROUP_REMOVE_FAILED));
    delegate.resetEvents();
}
Also used : GroupEvent(org.onosproject.net.group.GroupEvent) GroupOperation(org.onosproject.net.group.GroupOperation) Test(org.junit.Test)

Example 2 with GroupEvent

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

the class DistributedGroupStore method removeGroupEntry.

/**
 * Removes the group entry from store.
 *
 * @param group group entry
 */
@Override
public void removeGroupEntry(Group group) {
    StoredGroupEntry existing = getStoredGroupEntry(group.deviceId(), group.id());
    if (existing != null) {
        log.debug("removeGroupEntry: removing group entry {} in device {}", group.id(), group.deviceId());
        // Removal from groupid based map will happen in the
        // map update listener
        getGroupStoreKeyMap().remove(new GroupStoreKeyMapKey(existing.deviceId(), existing.appCookie()));
        notifyDelegate(new GroupEvent(Type.GROUP_REMOVED, existing));
    } else {
        log.warn("removeGroupEntry for {} in device{} is " + "not existing in our maps", group.id(), group.deviceId());
    }
}
Also used : StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent)

Example 3 with GroupEvent

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

the class DistributedGroupStore method addOrUpdateGroupEntry.

/**
 * Stores a new group entry, or updates an existing entry.
 *
 * @param group group entry
 */
@Override
public void addOrUpdateGroupEntry(Group group) {
    // check if this new entry is an update to an existing entry
    StoredGroupEntry existing = getStoredGroupEntry(group.deviceId(), group.id());
    GroupEvent event = null;
    if (existing != null) {
        log.trace("addOrUpdateGroupEntry: updating group entry {} in device {}", group.id(), group.deviceId());
        // TODO is this really safe ?
        synchronized (existing) {
            // Update stats
            updateGroupEntryStatsInternal(group, existing);
            if ((existing.state() == GroupState.PENDING_ADD) || (existing.state() == GroupState.PENDING_ADD_RETRY)) {
                log.trace("addOrUpdateGroupEntry: group entry {} in device {} moving from {} to ADDED", existing.id(), existing.deviceId(), existing.state());
                existing.setState(GroupState.ADDED);
                existing.setIsGroupStateAddedFirstTime(true);
                event = new GroupEvent(Type.GROUP_ADDED, existing);
            } else {
                log.trace("addOrUpdateGroupEntry: group entry {} in device {} moving from {} to ADDED", existing.id(), existing.deviceId(), GroupState.PENDING_UPDATE);
                existing.setState(GroupState.ADDED);
                existing.setIsGroupStateAddedFirstTime(false);
                event = new GroupEvent(Type.GROUP_UPDATED, existing);
            }
            // Re-PUT map entries to trigger map update events
            getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(existing.deviceId(), existing.appCookie()), existing);
        }
    } else {
        log.warn("addOrUpdateGroupEntry: Group update {} " + "happening for a non-existing entry in the map", group);
    }
    // TODO if map is going to trigger event, is this one needed?
    if (event != null) {
        notifyDelegate(event);
    }
}
Also used : StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent)

Example 4 with GroupEvent

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

the class SimpleVirtualGroupStore method storeGroupDescriptionInternal.

private void storeGroupDescriptionInternal(NetworkId networkId, GroupDescription groupDesc) {
    // Check if a group is existing with the same key
    if (getGroup(networkId, groupDesc.deviceId(), groupDesc.appCookie()) != null) {
        return;
    }
    GroupId id = null;
    if (groupDesc.givenGroupId() == null) {
        // Get a new group identifier
        id = new GroupId(getFreeGroupIdValue(networkId, groupDesc.deviceId()));
    } else {
        id = new GroupId(groupDesc.givenGroupId());
    }
    // Create a group entry object
    StoredGroupEntry group = new DefaultGroup(id, groupDesc);
    // Insert the newly created group entry into concurrent key and id maps
    ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(networkId, groupDesc.deviceId());
    keyTable.put(groupDesc.appCookie(), group);
    ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(networkId, groupDesc.deviceId());
    idTable.put(id, group);
    notifyDelegate(networkId, new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, group));
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupKey(org.onosproject.net.group.GroupKey) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent) GroupId(org.onosproject.core.GroupId)

Example 5 with GroupEvent

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

the class SimpleVirtualGroupStore method purgeGroupEntry.

@Override
public void purgeGroupEntry(NetworkId networkId, DeviceId deviceId) {
    if (groupEntriesById.get(networkId) != null) {
        Set<Map.Entry<GroupId, StoredGroupEntry>> entryPendingRemove = groupEntriesById.get(networkId).get(deviceId).entrySet();
        groupEntriesById.get(networkId).remove(deviceId);
        groupEntriesByKey.get(networkId).remove(deviceId);
        entryPendingRemove.forEach(entry -> {
            notifyDelegate(networkId, new GroupEvent(GroupEvent.Type.GROUP_REMOVED, entry.getValue()));
        });
    }
}
Also used : StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) StoredGroupBucketEntry(org.onosproject.net.group.StoredGroupBucketEntry) GroupEvent(org.onosproject.net.group.GroupEvent)

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