Search in sources :

Example 11 with StoredGroupEntry

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

the class SimpleGroupStore method purgeGroupEntry.

@Override
public void purgeGroupEntry(DeviceId deviceId) {
    Set<Map.Entry<GroupId, StoredGroupEntry>> entryPendingRemove = groupEntriesById.get(deviceId).entrySet();
    groupEntriesById.remove(deviceId);
    groupEntriesByKey.remove(deviceId);
    entryPendingRemove.forEach(entry -> {
        notifyDelegate(new 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)

Example 12 with StoredGroupEntry

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

the class SimpleGroupStore 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;
    }
    GroupId id = null;
    if (groupDesc.givenGroupId() == null) {
        // Get a new group identifier
        id = new GroupId(getFreeGroupIdValue(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(groupDesc.deviceId());
    keyTable.put(groupDesc.appCookie(), group);
    ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(groupDesc.deviceId());
    idTable.put(id, group);
    notifyDelegate(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 13 with StoredGroupEntry

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

the class SimpleGroupStore method deviceInitialAuditCompleted.

@Override
public void deviceInitialAuditCompleted(DeviceId deviceId, boolean completed) {
    synchronized (deviceAuditStatus) {
        if (completed) {
            log.debug("deviceInitialAuditCompleted: AUDIT " + "completed for device {}", deviceId);
            deviceAuditStatus.put(deviceId, true);
            // Execute all pending group requests
            ConcurrentMap<GroupKey, StoredGroupEntry> pendingGroupRequests = getPendingGroupKeyTable(deviceId);
            for (Group group : pendingGroupRequests.values()) {
                GroupDescription tmp = new DefaultGroupDescription(group.deviceId(), group.type(), group.buckets(), group.appCookie(), group.givenGroupId(), group.appId());
                storeGroupDescriptionInternal(tmp);
            }
            getPendingGroupKeyTable(deviceId).clear();
        } else {
            if (deviceAuditStatus.getOrDefault(deviceId, false)) {
                log.debug("deviceInitialAuditCompleted: Clearing AUDIT " + "status for device {}", deviceId);
                deviceAuditStatus.put(deviceId, false);
            }
        }
    }
}
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) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry)

Example 14 with StoredGroupEntry

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

the class SimpleGroupStore 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 = (groupEntriesById.get(group.deviceId()) != null) ? groupEntriesById.get(group.deviceId()).get(group.id()) : null;
    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() == GroupState.PENDING_ADD) {
                existing.setState(GroupState.ADDED);
                event = new GroupEvent(Type.GROUP_ADDED, existing);
            } else {
                if (existing.state() == GroupState.PENDING_UPDATE) {
                    existing.setState(GroupState.ADDED);
                }
                event = new GroupEvent(Type.GROUP_UPDATED, existing);
            }
        }
    }
    if (event != null) {
        notifyDelegate(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) GroupStore(org.onosproject.net.group.GroupStore) 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) GroupState(org.onosproject.net.group.Group.GroupState) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) 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) GroupEvent(org.onosproject.net.group.GroupEvent) Collectors(java.util.stream.Collectors) 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) Type(org.onosproject.net.group.GroupEvent.Type) AbstractStore(org.onosproject.store.AbstractStore) 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 15 with StoredGroupEntry

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

the class SimpleGroupStore method groupMissing.

private void groupMissing(Group 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_UPDATE:
            log.debug("Group {} is in store but not on device {}", group, group.deviceId());
            StoredGroupEntry existing = (groupEntriesById.get(group.deviceId()) != null) ? groupEntriesById.get(group.deviceId()).get(group.id()) : null;
            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(new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, group));
            break;
        default:
            log.debug("Group {} has not been installed.", group);
            break;
    }
}
Also used : StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent)

Aggregations

StoredGroupEntry (org.onosproject.net.group.StoredGroupEntry)38 GroupEvent (org.onosproject.net.group.GroupEvent)26 DefaultGroup (org.onosproject.net.group.DefaultGroup)19 GroupKey (org.onosproject.net.group.GroupKey)18 GroupId (org.onosproject.core.GroupId)15 Group (org.onosproject.net.group.Group)13 GroupBucket (org.onosproject.net.group.GroupBucket)11 GroupBuckets (org.onosproject.net.group.GroupBuckets)11 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)10 GroupDescription (org.onosproject.net.group.GroupDescription)10 ArrayList (java.util.ArrayList)8 StoredGroupBucketEntry (org.onosproject.net.group.StoredGroupBucketEntry)8 DeviceId (org.onosproject.net.DeviceId)6 Activate (org.osgi.service.component.annotations.Activate)6 FluentIterable (com.google.common.collect.FluentIterable)5 Sets (com.google.common.collect.Sets)5 Collection (java.util.Collection)5 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 List (java.util.List)5