Search in sources :

Example 21 with GroupEvent

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

the class DistributedGroupStore method deleteGroupDescriptionInternal.

private void deleteGroupDescriptionInternal(DeviceId deviceId, GroupKey appCookie) {
    // Check if a group is existing with the provided key
    StoredGroupEntry existing = getStoredGroupEntry(deviceId, appCookie);
    if (existing == null) {
        return;
    }
    log.debug("deleteGroupDescriptionInternal: group entry {} in device {} moving from {} to PENDING_DELETE", existing.id(), existing.deviceId(), existing.state());
    // TODO is this really safe ?
    synchronized (existing) {
        existing.setState(GroupState.PENDING_DELETE);
        getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(existing.deviceId(), existing.appCookie()), existing);
    }
    log.debug("deleteGroupDescriptionInternal: in device {} issuing GROUP_REMOVE_REQUESTED for {}", deviceId, existing.id());
    notifyDelegate(new GroupEvent(Type.GROUP_REMOVE_REQUESTED, existing));
}
Also used : StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent)

Example 22 with GroupEvent

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

the class DistributedGroupStore method updateGroupDescriptionInternal.

private void updateGroupDescriptionInternal(DeviceId deviceId, GroupKey oldAppCookie, UpdateType type, GroupBuckets newBuckets, GroupKey newAppCookie) {
    // Check if a group is existing with the provided key
    Group oldGroup = getGroup(deviceId, oldAppCookie);
    if (oldGroup == null) {
        log.warn("updateGroupDescriptionInternal: Group not found...strange. " + "GroupKey:{} DeviceId:{} newGroupKey:{}", oldAppCookie, deviceId, newAppCookie);
        return;
    }
    List<GroupBucket> newBucketList = getUpdatedBucketList(oldGroup, type, newBuckets);
    if (newBucketList != null) {
        // Create a new group object from the old group
        GroupBuckets updatedBuckets = new GroupBuckets(newBucketList);
        GroupKey newCookie = (newAppCookie != null) ? newAppCookie : oldAppCookie;
        GroupDescription updatedGroupDesc = new DefaultGroupDescription(oldGroup.deviceId(), oldGroup.type(), updatedBuckets, newCookie, oldGroup.givenGroupId(), oldGroup.appId());
        StoredGroupEntry newGroup = new DefaultGroup(oldGroup.id(), updatedGroupDesc);
        log.debug("updateGroupDescriptionInternal: group entry {} in device {} moving from {} to PENDING_UPDATE", oldGroup.id(), oldGroup.deviceId(), oldGroup.state());
        newGroup.setState(GroupState.PENDING_UPDATE);
        newGroup.setLife(oldGroup.life());
        newGroup.setPackets(oldGroup.packets());
        newGroup.setBytes(oldGroup.bytes());
        // Update the group entry in groupkey based map.
        // Update to groupid based map will happen in the
        // groupkey based map update listener
        log.debug("updateGroupDescriptionInternal with type {}: Group {} updated with buckets", type, newGroup.id());
        getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(newGroup.deviceId(), newGroup.appCookie()), newGroup);
        notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_REQUESTED, newGroup));
    } else {
        log.warn("updateGroupDescriptionInternal with type {}: Group {} No " + "change in the buckets in update", type, oldGroup.id());
    }
}
Also used : DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent)

Example 23 with GroupEvent

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

the class DistributedGroupStore method pushGroupMetrics.

@Override
public void pushGroupMetrics(DeviceId deviceId, Collection<Group> groupEntries) {
    boolean deviceInitialAuditStatus = deviceInitialAuditStatus(deviceId);
    Set<Group> southboundGroupEntries = Sets.newHashSet(groupEntries);
    Set<StoredGroupEntry> storedGroupEntries = Sets.newHashSet(getStoredGroups(deviceId));
    Set<Group> extraneousStoredEntries = Sets.newHashSet(getExtraneousGroups(deviceId));
    NodeId master;
    if (log.isTraceEnabled()) {
        log.trace("pushGroupMetrics: Displaying all ({}) southboundGroupEntries for device {}", southboundGroupEntries.size(), deviceId);
        for (Group group : southboundGroupEntries) {
            log.trace("Group {} in device {}", group, deviceId);
        }
        log.trace("Displaying all ({}) stored group entries for device {}", storedGroupEntries.size(), deviceId);
        for (StoredGroupEntry group : storedGroupEntries) {
            log.trace("Stored Group {} for device {}", group, deviceId);
        }
    }
    garbageCollect(deviceId, southboundGroupEntries, storedGroupEntries);
    // update stats
    for (Iterator<Group> it2 = southboundGroupEntries.iterator(); it2.hasNext(); ) {
        // Mastership change can occur during this iteration
        if (!shouldHandle(deviceId)) {
            log.warn("Tried to update the group stats while the node was not the master" + " or the device {} was not available", deviceId);
            return;
        }
        Group group = it2.next();
        if (storedGroupEntries.remove(group)) {
            // we both have the group, let's update some info then.
            log.trace("Group AUDIT: group {} exists in both planes for device {}", group.id(), deviceId);
            groupAdded(group);
            it2.remove();
        }
    }
    // extraneous groups in the dataplane
    for (Group group : southboundGroupEntries) {
        if (getGroup(group.deviceId(), group.id()) != null) {
            // in progress while we got a stale info from switch
            if (!storedGroupEntries.remove(getGroup(group.deviceId(), group.id()))) {
                log.warn("Group AUDIT: Inconsistent state:" + "Group exists in ID based table while " + "not present in key based table");
            }
        } else {
            // Mastership change can occur during this iteration
            if (!shouldHandle(deviceId)) {
                log.warn("Tried to process extraneous groups while the node was not the master" + " or the device {} was not available", deviceId);
                return;
            }
            // there are groups in the switch that aren't in the store
            log.debug("Group AUDIT: extraneous group {} exists in data plane for device {}", group.id(), deviceId);
            extraneousStoredEntries.remove(group);
            if (allowExtraneousGroups) {
                extraneousGroup(group);
            } else {
                notifyDelegate(new GroupEvent(Type.GROUP_REMOVE_REQUESTED, group));
            }
        }
    }
    // missing groups in the dataplane
    for (StoredGroupEntry group : storedGroupEntries) {
        // Mastership change can occur during this iteration
        if (!shouldHandle(deviceId)) {
            log.warn("Tried to process missing groups while the node was not the master" + " or the device {} was not available", deviceId);
            return;
        }
        // there are groups in the store that aren't in the switch
        log.debug("Group AUDIT: group {} missing in data plane for device {}", group.id(), deviceId);
        groupMissing(group);
    }
    // extraneous groups in the store
    for (Group group : extraneousStoredEntries) {
        // Mastership change can occur during this iteration
        if (!shouldHandle(deviceId)) {
            log.warn("Tried to process node extraneous groups while the node was not the master" + " or the device {} was not available", deviceId);
            return;
        }
        // there are groups in the extraneous store that
        // aren't in the switch
        log.debug("Group AUDIT: clearing extraneous group {} from store for device {}", group.id(), deviceId);
        removeExtraneousGroupEntry(group);
    }
    if (!deviceInitialAuditStatus) {
        log.info("Group AUDIT: Setting device {} initial AUDIT completed", deviceId);
        deviceInitialAuditCompleted(deviceId, true);
    }
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) NodeId(org.onosproject.cluster.NodeId) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent)

Example 24 with GroupEvent

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

the class DistributedGroupStore method groupMissing.

private void groupMissing(StoredGroupEntry group) {
    switch(group.state()) {
        case PENDING_DELETE:
            log.debug("Group {} delete confirmation from device {}", group, group.deviceId());
            removeGroupEntry(group);
            break;
        case ADDED:
        case PENDING_ADD:
        case PENDING_ADD_RETRY:
        case PENDING_UPDATE:
            log.debug("groupMissing: group entry {} in device {} moving from {} to PENDING_ADD_RETRY", group.id(), group.deviceId(), group.state());
            group.setState(Group.GroupState.PENDING_ADD_RETRY);
            // Re-PUT map entries to trigger map update events
            getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(group.deviceId(), group.appCookie()), group);
            notifyDelegate(new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, group));
            break;
        default:
            log.debug("Group {} has not been installed.", group);
            break;
    }
}
Also used : GroupEvent(org.onosproject.net.group.GroupEvent)

Example 25 with GroupEvent

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

the class DistributedGroupStore method groupOperationFailed.

@Override
public void groupOperationFailed(DeviceId deviceId, GroupOperation operation) {
    StoredGroupEntry existing = getStoredGroupEntry(deviceId, operation.groupId());
    if (existing == null) {
        log.warn("No group entry with ID {} found ", operation.groupId());
        return;
    }
    log.warn("groupOperationFailed: group operation {} failed in state {} " + "for group {} in device {} with code {}", operation.opType(), existing.state(), existing.id(), existing.deviceId(), operation.failureCode());
    if (operation.failureCode() == GroupOperation.GroupMsgErrorCode.GROUP_EXISTS) {
        if (operation.buckets().equals(existing.buckets())) {
            if (existing.state() == GroupState.PENDING_ADD || existing.state() == GroupState.PENDING_ADD_RETRY) {
                log.info("GROUP_EXISTS: GroupID and Buckets match for group in pending " + "add state - moving to ADDED for group {} in device {}", existing.id(), deviceId);
                addOrUpdateGroupEntry(existing);
                return;
            } else {
                log.warn("GROUP_EXISTS: GroupId and Buckets match but existing" + "group in state: {}", existing.state());
            }
        } else {
            log.warn("GROUP EXISTS: Group ID matched but buckets did not. " + "Operation: {} Existing: {}", operation.buckets(), existing.buckets());
        }
    }
    if (operation.failureCode() == GroupOperation.GroupMsgErrorCode.INVALID_GROUP) {
        existing.incrFailedRetryCount();
        if (existing.failedRetryCount() < MAX_FAILED_ATTEMPTS) {
            log.warn("Group {} programming failed {} of {} times in dev {}, " + "retrying ..", existing.id(), existing.failedRetryCount(), MAX_FAILED_ATTEMPTS, deviceId);
            return;
        }
        log.warn("Group {} programming failed {} of {} times in dev {}, " + "removing group from store", existing.id(), existing.failedRetryCount(), MAX_FAILED_ATTEMPTS, deviceId);
    // fall through to case
    }
    switch(operation.opType()) {
        case ADD:
            if (existing.state() == GroupState.PENDING_ADD || existing.state() == GroupState.PENDING_ADD_RETRY) {
                notifyDelegate(new GroupEvent(Type.GROUP_ADD_FAILED, existing));
                log.warn("groupOperationFailed: cleaning up " + "group {} from store in device {}....", existing.id(), existing.deviceId());
                // Removal from groupid based map will happen in the
                // map update listener
                getGroupStoreKeyMap().remove(new GroupStoreKeyMapKey(existing.deviceId(), existing.appCookie()));
            }
            break;
        case MODIFY:
            notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_FAILED, existing));
            break;
        case DELETE:
            notifyDelegate(new GroupEvent(Type.GROUP_REMOVE_FAILED, existing));
            break;
        default:
            log.warn("Unknown group operation type {}", operation.opType());
    }
}
Also used : StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) 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