Search in sources :

Example 26 with GroupEvent

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

the class DistributedGroupStore method storeGroupDescriptionInternal.

private void storeGroupDescriptionInternal(GroupDescription groupDesc) {
    // Check if a group is existing with the same key
    if (getGroup(groupDesc.deviceId(), groupDesc.appCookie()) != null) {
        return;
    }
    synchronized (deviceAuditStatus) {
        if (deviceAuditStatus.get(groupDesc.deviceId()) == null) {
            // Device group audit has not completed yet
            // Add this group description to pending group key table
            // Create a group entry object with Dummy Group ID
            log.debug("storeGroupDescriptionInternal: Device {} AUDIT pending...Queuing Group id {} ADD request", groupDesc.deviceId(), groupDesc.givenGroupId() != null ? "0x" + Integer.toHexString(groupDesc.givenGroupId()) : "N/A");
            StoredGroupEntry group = new DefaultGroup(dummyGroupId, groupDesc);
            group.setState(GroupState.WAITING_AUDIT_COMPLETE);
            Map<GroupStoreKeyMapKey, StoredGroupEntry> pendingKeyTable = getPendingGroupKeyTable();
            pendingKeyTable.put(new GroupStoreKeyMapKey(groupDesc.deviceId(), groupDesc.appCookie()), group);
            return;
        }
    }
    Group matchingExtraneousGroup = null;
    if (groupDesc.givenGroupId() != null) {
        // Check if there is a extraneous group existing with the same Id
        matchingExtraneousGroup = getMatchingExtraneousGroupbyId(groupDesc.deviceId(), groupDesc.givenGroupId());
        if (matchingExtraneousGroup != null) {
            log.debug("storeGroupDescriptionInternal: Matching extraneous group " + "found in Device {} for group id 0x{}", groupDesc.deviceId(), Integer.toHexString(groupDesc.givenGroupId()));
            // Check if the group buckets matches with user provided buckets
            if (matchingExtraneousGroup.buckets().equals(groupDesc.buckets())) {
                // Group is already existing with the same buckets and Id
                // Create a group entry object
                log.debug("storeGroupDescriptionInternal: Buckets also matching " + "in Device {} for group id 0x{}", groupDesc.deviceId(), Integer.toHexString(groupDesc.givenGroupId()));
                StoredGroupEntry group = new DefaultGroup(matchingExtraneousGroup.id(), groupDesc);
                // Insert the newly created group entry into key and id maps
                getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(groupDesc.deviceId(), groupDesc.appCookie()), group);
                // Ensure it also inserted into group id based table to
                // avoid any chances of duplication in group id generation
                getGroupIdTable(groupDesc.deviceId()).put(matchingExtraneousGroup.id(), group);
                addOrUpdateGroupEntry(matchingExtraneousGroup);
                removeExtraneousGroupEntry(matchingExtraneousGroup);
                return;
            } else {
                // Group buckets are not matching. Update group
                // with user provided buckets.
                log.debug("storeGroupDescriptionInternal: Buckets are not " + "matching in Device {} for group id 0x{}", groupDesc.deviceId(), Integer.toHexString(groupDesc.givenGroupId()));
                StoredGroupEntry modifiedGroup = new DefaultGroup(matchingExtraneousGroup.id(), groupDesc);
                modifiedGroup.setState(GroupState.PENDING_UPDATE);
                getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(groupDesc.deviceId(), groupDesc.appCookie()), modifiedGroup);
                // Ensure it also inserted into group id based table to
                // avoid any chances of duplication in group id generation
                getGroupIdTable(groupDesc.deviceId()).put(matchingExtraneousGroup.id(), modifiedGroup);
                removeExtraneousGroupEntry(matchingExtraneousGroup);
                log.debug("storeGroupDescriptionInternal: Triggering Group " + "UPDATE request for {} in device {}", matchingExtraneousGroup.id(), groupDesc.deviceId());
                notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_REQUESTED, modifiedGroup));
                return;
            }
        }
    } else {
        // Check if there is an extraneous group with user provided buckets
        matchingExtraneousGroup = getMatchingExtraneousGroupbyBuckets(groupDesc.deviceId(), groupDesc.buckets());
        if (matchingExtraneousGroup != null) {
            // Group is already existing with the same buckets.
            // So reuse this group.
            log.debug("storeGroupDescriptionInternal: Matching extraneous group found in Device {}", groupDesc.deviceId());
            // Create a group entry object
            StoredGroupEntry group = new DefaultGroup(matchingExtraneousGroup.id(), groupDesc);
            // Insert the newly created group entry into key and id maps
            getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(groupDesc.deviceId(), groupDesc.appCookie()), group);
            // Ensure it also inserted into group id based table to
            // avoid any chances of duplication in group id generation
            getGroupIdTable(groupDesc.deviceId()).put(matchingExtraneousGroup.id(), group);
            addOrUpdateGroupEntry(matchingExtraneousGroup);
            removeExtraneousGroupEntry(matchingExtraneousGroup);
            return;
        } else {
            // TODO: Check if there are any empty groups that can be used here
            log.debug("storeGroupDescriptionInternal: No matching extraneous groups found in Device {}", groupDesc.deviceId());
        }
    }
    GroupId id = null;
    if (groupDesc.givenGroupId() == null) {
        // Get a new group identifier
        id = new GroupId(getFreeGroupIdValue(groupDesc.deviceId()));
    } else {
        // we need to use the identifier passed in by caller, but check if
        // already used
        Group existing = getGroup(groupDesc.deviceId(), new GroupId(groupDesc.givenGroupId()));
        if (existing != null) {
            log.warn("Group already exists with the same id: 0x{} in dev:{} " + "but with different key: {} (request gkey: {})", Integer.toHexString(groupDesc.givenGroupId()), groupDesc.deviceId(), existing.appCookie(), groupDesc.appCookie());
            return;
        }
        id = new GroupId(groupDesc.givenGroupId());
    }
    // Create a group entry object
    StoredGroupEntry group = new DefaultGroup(id, groupDesc);
    // Insert the newly created group entry into key and id maps
    getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(groupDesc.deviceId(), groupDesc.appCookie()), group);
    // Ensure it also inserted into group id based table to
    // avoid any chances of duplication in group id generation
    getGroupIdTable(groupDesc.deviceId()).put(id, group);
    log.debug("storeGroupDescriptionInternal: Processing Group ADD request for Id {} in device {}", id, groupDesc.deviceId());
    notifyDelegate(new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, group));
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) DefaultGroup(org.onosproject.net.group.DefaultGroup) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent) GroupId(org.onosproject.core.GroupId)

Example 27 with GroupEvent

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

the class SimpleVirtualGroupStore method addOrUpdateGroupEntry.

@Override
public void addOrUpdateGroupEntry(NetworkId networkId, Group group) {
    // check if this new entry is an update to an existing entry
    StoredGroupEntry existing = null;
    if (groupEntriesById.get(networkId) != null && groupEntriesById.get(networkId).get(group.deviceId()) != null) {
        existing = groupEntriesById.get(networkId).get(group.deviceId()).get(group.id());
    }
    GroupEvent event = null;
    if (existing != null) {
        synchronized (existing) {
            for (GroupBucket bucket : group.buckets().buckets()) {
                Optional<GroupBucket> matchingBucket = existing.buckets().buckets().stream().filter((existingBucket) -> (existingBucket.equals(bucket))).findFirst();
                if (matchingBucket.isPresent()) {
                    ((StoredGroupBucketEntry) matchingBucket.get()).setPackets(bucket.packets());
                    ((StoredGroupBucketEntry) matchingBucket.get()).setBytes(bucket.bytes());
                } else {
                    log.warn("addOrUpdateGroupEntry: No matching " + "buckets to update stats");
                }
            }
            existing.setLife(group.life());
            existing.setPackets(group.packets());
            existing.setBytes(group.bytes());
            if (existing.state() == Group.GroupState.PENDING_ADD) {
                existing.setState(Group.GroupState.ADDED);
                event = new GroupEvent(GroupEvent.Type.GROUP_ADDED, existing);
            } else {
                if (existing.state() == Group.GroupState.PENDING_UPDATE) {
                    existing.setState(Group.GroupState.ADDED);
                }
                event = new GroupEvent(GroupEvent.Type.GROUP_UPDATED, existing);
            }
        }
    }
    if (event != null) {
        notifyDelegate(networkId, event);
    }
}
Also used : HashMap(java.util.HashMap) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) GroupOperation(org.onosproject.net.group.GroupOperation) GroupKey(org.onosproject.net.group.GroupKey) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Component(org.osgi.service.component.annotations.Component) FluentIterable(com.google.common.collect.FluentIterable) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Activate(org.osgi.service.component.annotations.Activate) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) StoredGroupBucketEntry(org.onosproject.net.group.StoredGroupBucketEntry) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) VirtualNetworkGroupStore(org.onosproject.incubator.net.virtual.VirtualNetworkGroupStore) GroupEvent(org.onosproject.net.group.GroupEvent) Sets(com.google.common.collect.Sets) List(java.util.List) GroupStoreDelegate(org.onosproject.net.group.GroupStoreDelegate) GroupId(org.onosproject.core.GroupId) GroupBuckets(org.onosproject.net.group.GroupBuckets) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) GroupBucket(org.onosproject.net.group.GroupBucket) StoredGroupBucketEntry(org.onosproject.net.group.StoredGroupBucketEntry) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent)

Example 28 with GroupEvent

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

the class SimpleVirtualGroupStore method updateGroupDescription.

@Override
public void updateGroupDescription(NetworkId networkId, DeviceId deviceId, GroupKey oldAppCookie, UpdateType type, GroupBuckets newBuckets, GroupKey newAppCookie) {
    // Check if a group is existing with the provided key
    Group oldGroup = getGroup(networkId, deviceId, oldAppCookie);
    if (oldGroup == null) {
        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);
        newGroup.setState(Group.GroupState.PENDING_UPDATE);
        newGroup.setLife(oldGroup.life());
        newGroup.setPackets(oldGroup.packets());
        newGroup.setBytes(oldGroup.bytes());
        // Remove the old entry from maps and add new entry using new key
        ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(networkId, oldGroup.deviceId());
        ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(networkId, oldGroup.deviceId());
        keyTable.remove(oldGroup.appCookie());
        idTable.remove(oldGroup.id());
        keyTable.put(newGroup.appCookie(), newGroup);
        idTable.put(newGroup.id(), newGroup);
        notifyDelegate(networkId, new GroupEvent(GroupEvent.Type.GROUP_UPDATE_REQUESTED, newGroup));
    }
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBuckets(org.onosproject.net.group.GroupBuckets) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent) GroupId(org.onosproject.core.GroupId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Example 29 with GroupEvent

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

the class SimpleVirtualGroupStore method groupMissing.

private void groupMissing(NetworkId networkId, Group group) {
    switch(group.state()) {
        case PENDING_DELETE:
            log.debug("Group {} delete confirmation from device {} " + "of virtaual network {}", group, group.deviceId(), networkId);
            removeGroupEntry(networkId, group);
            break;
        case ADDED:
        case PENDING_ADD:
        case PENDING_UPDATE:
            log.debug("Group {} is in store but not on device {}", group, group.deviceId());
            StoredGroupEntry existing = null;
            if (groupEntriesById.get(networkId) != null && groupEntriesById.get(networkId).get(group.deviceId()) != null) {
                existing = groupEntriesById.get(networkId).get(group.deviceId()).get(group.id());
            }
            if (existing == null) {
                break;
            }
            log.trace("groupMissing: group " + "entry {} in device {} moving " + "from {} to PENDING_ADD", existing.id(), existing.deviceId(), existing.state());
            existing.setState(Group.GroupState.PENDING_ADD);
            notifyDelegate(networkId, new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, group));
            break;
        default:
            log.debug("Virtual network {} : Group {} has not been installed.", networkId, group);
            break;
    }
}
Also used : StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent)

Example 30 with GroupEvent

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

the class SimpleVirtualGroupStore method deleteGroupDescription.

@Override
public void deleteGroupDescription(NetworkId networkId, DeviceId deviceId, GroupKey appCookie) {
    // Check if a group is existing with the provided key
    StoredGroupEntry existing = null;
    if (groupEntriesByKey.get(networkId) != null && groupEntriesByKey.get(networkId).get(deviceId) != null) {
        existing = groupEntriesByKey.get(networkId).get(deviceId).get(appCookie);
    }
    if (existing == null) {
        return;
    }
    synchronized (existing) {
        existing.setState(Group.GroupState.PENDING_DELETE);
    }
    notifyDelegate(networkId, new GroupEvent(GroupEvent.Type.GROUP_REMOVE_REQUESTED, existing));
}
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