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