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();
}
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);
}
}
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);
}
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);
}
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);
}
}
Aggregations