Search in sources :

Example 1 with StoredGroupBucketEntry

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

the class OpenFlowGroupProvider method buildGroupMetrics.

private Collection<Group> buildGroupMetrics(DeviceId deviceId, OFGroupStatsReply groupStatsReply, OFGroupDescStatsReply groupDescStatsReply) {
    Map<Integer, Group> groups = Maps.newHashMap();
    Dpid dpid = Dpid.dpid(deviceId.uri());
    for (OFGroupDescStatsEntry entry : groupDescStatsReply.getEntries()) {
        int id = entry.getGroup().getGroupNumber();
        GroupId groupId = new GroupId(id);
        GroupDescription.Type type = getGroupType(entry.getGroupType());
        GroupBuckets buckets = new GroupBucketEntryBuilder(dpid, entry.getBuckets(), entry.getGroupType(), driverService).build();
        DefaultGroup group = new DefaultGroup(groupId, deviceId, type, buckets);
        groups.put(id, group);
    }
    if (groupStatsReply == null) {
        return groups.values();
    }
    for (OFGroupStatsEntry entry : groupStatsReply.getEntries()) {
        int groupId = entry.getGroup().getGroupNumber();
        DefaultGroup group = (DefaultGroup) groups.get(groupId);
        if (group != null) {
            group.setBytes(entry.getByteCount().getValue());
            group.setLife(entry.getDurationSec());
            group.setPackets(entry.getPacketCount().getValue());
            group.setReferenceCount(entry.getRefCount());
            int bucketIndex = 0;
            for (OFBucketCounter bucketStats : entry.getBucketStats()) {
                ((StoredGroupBucketEntry) group.buckets().buckets().get(bucketIndex)).setPackets(bucketStats.getPacketCount().getValue());
                ((StoredGroupBucketEntry) group.buckets().buckets().get(bucketIndex)).setBytes(entry.getBucketStats().get(bucketIndex).getByteCount().getValue());
                bucketIndex++;
            }
        }
    }
    return groups.values();
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) Dpid(org.onosproject.openflow.controller.Dpid) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupId(org.onosproject.core.GroupId) GroupDescription(org.onosproject.net.group.GroupDescription) OFGroupStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupStatsEntry) OFBucketCounter(org.projectfloodlight.openflow.protocol.OFBucketCounter) StoredGroupBucketEntry(org.onosproject.net.group.StoredGroupBucketEntry)

Example 2 with StoredGroupBucketEntry

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

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

the class SimpleGroupStoreTest method testUpdateGroupEntryFromSB.

// Testing addOrUpdateGroupEntry operation from southbound
private void testUpdateGroupEntryFromSB(GroupKey currKey) {
    Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
    int totalPkts = 0;
    int totalBytes = 0;
    List<GroupBucket> newBucketList = new ArrayList<>();
    for (GroupBucket bucket : existingGroup.buckets().buckets()) {
        StoredGroupBucketEntry newBucket = (StoredGroupBucketEntry) DefaultGroupBucket.createSelectGroupBucket(bucket.treatment());
        newBucket.setPackets(10);
        newBucket.setBytes(10 * 256 * 8);
        totalPkts += 10;
        totalBytes += 10 * 256 * 8;
        newBucketList.add(newBucket);
    }
    GroupBuckets updatedBuckets = new GroupBuckets(newBucketList);
    Group updatedGroup = new DefaultGroup(existingGroup.id(), existingGroup.deviceId(), existingGroup.type(), updatedBuckets);
    ((StoredGroupEntry) updatedGroup).setPackets(totalPkts);
    ((StoredGroupEntry) updatedGroup).setBytes(totalBytes);
    InternalGroupStoreDelegate updateGroupEntryDelegate = new InternalGroupStoreDelegate(currKey, updatedBuckets, GroupEvent.Type.GROUP_UPDATED);
    simpleGroupStore.setDelegate(updateGroupEntryDelegate);
    simpleGroupStore.addOrUpdateGroupEntry(updatedGroup);
    simpleGroupStore.unsetDelegate(updateGroupEntryDelegate);
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) StoredGroupBucketEntry(org.onosproject.net.group.StoredGroupBucketEntry) GroupBuckets(org.onosproject.net.group.GroupBuckets) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry)

Example 4 with StoredGroupBucketEntry

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

use of org.onosproject.net.group.StoredGroupBucketEntry 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)

Aggregations

DefaultGroup (org.onosproject.net.group.DefaultGroup)5 Group (org.onosproject.net.group.Group)5 GroupBuckets (org.onosproject.net.group.GroupBuckets)5 StoredGroupBucketEntry (org.onosproject.net.group.StoredGroupBucketEntry)5 ArrayList (java.util.ArrayList)4 GroupId (org.onosproject.core.GroupId)4 GroupBucket (org.onosproject.net.group.GroupBucket)4 GroupDescription (org.onosproject.net.group.GroupDescription)4 StoredGroupEntry (org.onosproject.net.group.StoredGroupEntry)4 FluentIterable (com.google.common.collect.FluentIterable)3 Sets (com.google.common.collect.Sets)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Set (java.util.Set)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3