Search in sources :

Example 76 with Group

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

the class DistributedGroupStore method updateGroupEntryStatsInternal.

/**
 * Updates the stats of an existing group entry.
 *
 * @param group the new stats
 * @param existing the existing group
 */
private void updateGroupEntryStatsInternal(Group group, StoredGroupEntry 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("updateGroupEntryStatsInternal: No matching bucket {}" + " to update stats for group {}", bucket, group.id());
        }
    }
    existing.setLife(group.life());
    existing.setPackets(group.packets());
    existing.setBytes(group.bytes());
    existing.setReferenceCount(group.referenceCount());
    existing.setFailedRetryCount(0);
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) GroupOperation(org.onosproject.net.group.GroupOperation) DriverService(org.onosproject.net.driver.DriverService) ALLOW_EXTRANEOUS_GROUPS(org.onosproject.store.OsgiPropertyConstants.ALLOW_EXTRANEOUS_GROUPS) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) StorageService(org.onosproject.store.service.StorageService) FluentIterable(com.google.common.collect.FluentIterable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) Tools.get(org.onlab.util.Tools.get) ImmutableSet(com.google.common.collect.ImmutableSet) 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) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) Versioned(org.onosproject.store.service.Versioned) List(java.util.List) GroupStoreDelegate(org.onosproject.net.group.GroupStoreDelegate) GARBAGE_COLLECT(org.onosproject.store.OsgiPropertyConstants.GARBAGE_COLLECT) GroupBuckets(org.onosproject.net.group.GroupBuckets) Type(org.onosproject.net.group.GroupEvent.Type) Entry(java.util.Map.Entry) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) GARBAGE_COLLECT_THRESH_DEFAULT(org.onosproject.store.OsgiPropertyConstants.GARBAGE_COLLECT_THRESH_DEFAULT) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) Dictionary(java.util.Dictionary) Iterables(com.google.common.collect.Iterables) ComponentContext(org.osgi.service.component.ComponentContext) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) KryoNamespace(org.onlab.util.KryoNamespace) GroupKey(org.onosproject.net.group.GroupKey) Group(org.onosproject.net.group.Group) MapEventListener(org.onosproject.store.service.MapEventListener) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) GroupStore(org.onosproject.net.group.GroupStore) Component(org.osgi.service.component.annotations.Component) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupState(org.onosproject.net.group.Group.GroupState) ALLOW_EXTRANEOUS_GROUPS_DEFAULT(org.onosproject.store.OsgiPropertyConstants.ALLOW_EXTRANEOUS_GROUPS_DEFAULT) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Activate(org.osgi.service.component.annotations.Activate) ExecutorService(java.util.concurrent.ExecutorService) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) Logger(org.slf4j.Logger) Properties(java.util.Properties) Iterator(java.util.Iterator) GARBAGE_COLLECT_DEFAULT(org.onosproject.store.OsgiPropertyConstants.GARBAGE_COLLECT_DEFAULT) Topic(org.onosproject.store.service.Topic) MastershipRole(org.onosproject.net.MastershipRole) GARBAGE_COLLECT_THRESH(org.onosproject.store.OsgiPropertyConstants.GARBAGE_COLLECT_THRESH) Status(org.onosproject.store.service.DistributedPrimitive.Status) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Consumer(java.util.function.Consumer) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp) GroupId(org.onosproject.core.GroupId) MapEvent(org.onosproject.store.service.MapEvent) AbstractStore(org.onosproject.store.AbstractStore) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) GroupBucket(org.onosproject.net.group.GroupBucket) StoredGroupBucketEntry(org.onosproject.net.group.StoredGroupBucketEntry)

Example 77 with Group

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

the class DistributedGroupStore method getFreeGroupIdValue.

private int getFreeGroupIdValue(DeviceId deviceId) {
    int freeId = groupIdGen.incrementAndGet();
    while (true) {
        Group existing = getGroup(deviceId, new GroupId(freeId));
        if (existing == null) {
            existing = (extraneousGroupEntriesById.get(deviceId) != null) ? extraneousGroupEntriesById.get(deviceId).get(new GroupId(freeId)) : null;
        }
        if (existing != null) {
            freeId = groupIdGen.incrementAndGet();
        } else {
            break;
        }
    }
    log.debug("getFreeGroupIdValue: Next Free ID is {}", freeId);
    return freeId;
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) GroupId(org.onosproject.core.GroupId)

Example 78 with Group

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

the class DistributedGroupStore method deviceInitialAuditCompleted.

@Override
public void deviceInitialAuditCompleted(DeviceId deviceId, boolean completed) {
    synchronized (deviceAuditStatus) {
        if (completed) {
            log.debug("AUDIT completed for device {}", deviceId);
            deviceAuditStatus.put(deviceId, true);
            // Execute all pending group requests
            List<StoredGroupEntry> pendingGroupRequests = getPendingGroupKeyTable().values().stream().filter(g -> g.deviceId().equals(deviceId)).collect(Collectors.toList());
            if (log.isDebugEnabled()) {
                List<String> pendingIds = pendingGroupRequests.stream().map(GroupDescription::givenGroupId).map(id -> id != null ? "0x" + Integer.toHexString(id) : "N/A").collect(Collectors.toList());
                log.debug("processing pending group add requests for device {}: {}", deviceId, pendingIds);
            }
            NodeId master;
            for (Group group : pendingGroupRequests) {
                // Mastership change can occur during this iteration
                if (!shouldHandle(deviceId)) {
                    log.warn("Tried to process pending groups while the node was not the master" + " or the device {} was not available", deviceId);
                    return;
                }
                GroupDescription tmp = new DefaultGroupDescription(group.deviceId(), group.type(), group.buckets(), group.appCookie(), group.givenGroupId(), group.appId());
                storeGroupDescriptionInternal(tmp);
                getPendingGroupKeyTable().remove(new GroupStoreKeyMapKey(deviceId, group.appCookie()));
            }
        } else {
            Boolean audited = deviceAuditStatus.get(deviceId);
            if (audited != null && audited) {
                log.debug("Clearing AUDIT status for device {}", deviceId);
                deviceAuditStatus.put(deviceId, false);
            }
        }
    }
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) GroupOperation(org.onosproject.net.group.GroupOperation) DriverService(org.onosproject.net.driver.DriverService) ALLOW_EXTRANEOUS_GROUPS(org.onosproject.store.OsgiPropertyConstants.ALLOW_EXTRANEOUS_GROUPS) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) StorageService(org.onosproject.store.service.StorageService) FluentIterable(com.google.common.collect.FluentIterable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) Tools.get(org.onlab.util.Tools.get) ImmutableSet(com.google.common.collect.ImmutableSet) 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) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) Versioned(org.onosproject.store.service.Versioned) List(java.util.List) GroupStoreDelegate(org.onosproject.net.group.GroupStoreDelegate) GARBAGE_COLLECT(org.onosproject.store.OsgiPropertyConstants.GARBAGE_COLLECT) GroupBuckets(org.onosproject.net.group.GroupBuckets) Type(org.onosproject.net.group.GroupEvent.Type) Entry(java.util.Map.Entry) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) GARBAGE_COLLECT_THRESH_DEFAULT(org.onosproject.store.OsgiPropertyConstants.GARBAGE_COLLECT_THRESH_DEFAULT) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) Dictionary(java.util.Dictionary) Iterables(com.google.common.collect.Iterables) ComponentContext(org.osgi.service.component.ComponentContext) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) KryoNamespace(org.onlab.util.KryoNamespace) GroupKey(org.onosproject.net.group.GroupKey) Group(org.onosproject.net.group.Group) MapEventListener(org.onosproject.store.service.MapEventListener) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) GroupStore(org.onosproject.net.group.GroupStore) Component(org.osgi.service.component.annotations.Component) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupState(org.onosproject.net.group.Group.GroupState) ALLOW_EXTRANEOUS_GROUPS_DEFAULT(org.onosproject.store.OsgiPropertyConstants.ALLOW_EXTRANEOUS_GROUPS_DEFAULT) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Activate(org.osgi.service.component.annotations.Activate) ExecutorService(java.util.concurrent.ExecutorService) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) Logger(org.slf4j.Logger) Properties(java.util.Properties) Iterator(java.util.Iterator) GARBAGE_COLLECT_DEFAULT(org.onosproject.store.OsgiPropertyConstants.GARBAGE_COLLECT_DEFAULT) Topic(org.onosproject.store.service.Topic) MastershipRole(org.onosproject.net.MastershipRole) GARBAGE_COLLECT_THRESH(org.onosproject.store.OsgiPropertyConstants.GARBAGE_COLLECT_THRESH) Status(org.onosproject.store.service.DistributedPrimitive.Status) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Consumer(java.util.function.Consumer) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp) GroupId(org.onosproject.core.GroupId) MapEvent(org.onosproject.store.service.MapEvent) AbstractStore(org.onosproject.store.AbstractStore) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) NodeId(org.onosproject.cluster.NodeId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry)

Example 79 with Group

use of org.onosproject.net.group.Group 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 80 with Group

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

the class GroupManagerTest method fallbackPoll.

@Test
public void fallbackPoll() {
    // Test Group creation before AUDIT process
    testGroupCreationBeforeAudit(FOO_DID);
    programmableTestCleanUp();
    // Test audit with extraneous and missing groups
    testAuditWithExtraneousMissingGroups(FOO_DID);
    // Test audit with confirmed groups
    Group createdGroup = testAuditWithConfirmedGroups(FOO_DID);
    GroupDriverProvider fallback = (GroupDriverProvider) mgr.defaultProvider();
    fallback.init(mgr.deviceService, fallback.groupProviderService, mgr.mastershipService, 1);
    TestTools.assertAfter(2000, () -> {
        Group e = mgr.getGroups(FOO_DID).iterator().next();
        assertEquals("incorrect group", createdGroup, e);
    });
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) Test(org.junit.Test)

Aggregations

Group (org.onosproject.net.group.Group)120 DefaultGroup (org.onosproject.net.group.DefaultGroup)57 GroupKey (org.onosproject.net.group.GroupKey)56 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)45 GroupBucket (org.onosproject.net.group.GroupBucket)44 GroupBuckets (org.onosproject.net.group.GroupBuckets)42 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)38 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)38 NextGroup (org.onosproject.net.behaviour.NextGroup)37 ArrayList (java.util.ArrayList)36 GroupDescription (org.onosproject.net.group.GroupDescription)36 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)30 PortNumber (org.onosproject.net.PortNumber)27 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)26 DeviceId (org.onosproject.net.DeviceId)24 TrafficSelector (org.onosproject.net.flow.TrafficSelector)24 GroupId (org.onosproject.core.GroupId)23 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)21 FlowRule (org.onosproject.net.flow.FlowRule)20 Instruction (org.onosproject.net.flow.instructions.Instruction)20