use of org.onosproject.net.group.Group 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.Group in project onos by opennetworkinglab.
the class SimpleGroupStore method pushGroupMetrics.
@Override
public void pushGroupMetrics(DeviceId deviceId, Collection<Group> groupEntries) {
boolean deviceInitialAuditStatus = deviceInitialAuditStatus(deviceId);
Set<Group> southboundGroupEntries = Sets.newHashSet(groupEntries);
Set<Group> storedGroupEntries = Sets.newHashSet(getGroups(deviceId));
Set<Group> extraneousStoredEntries = Sets.newHashSet(getExtraneousGroups(deviceId));
if (log.isTraceEnabled()) {
log.trace("pushGroupMetrics: Displaying all ({}) " + "southboundGroupEntries for device {}", southboundGroupEntries.size(), deviceId);
for (Group group : southboundGroupEntries) {
log.trace("Group {} in device {}", group, deviceId);
}
log.trace("Displaying all ({}) stored group entries for device {}", storedGroupEntries.size(), deviceId);
for (Group group : storedGroupEntries) {
log.trace("Stored Group {} for device {}", group, deviceId);
}
}
for (Iterator<Group> it2 = southboundGroupEntries.iterator(); it2.hasNext(); ) {
Group group = it2.next();
if (storedGroupEntries.remove(group)) {
// we both have the group, let's update some info then.
log.trace("Group AUDIT: group {} exists " + "in both planes for device {}", group.id(), deviceId);
groupAdded(group);
it2.remove();
}
}
for (Group group : southboundGroupEntries) {
if (getGroup(group.deviceId(), group.id()) != null) {
// in progress while we got a stale info from switch
if (!storedGroupEntries.remove(getGroup(group.deviceId(), group.id()))) {
log.warn("Group AUDIT: Inconsistent state:" + "Group exists in ID based table while " + "not present in key based table");
}
} else {
// there are groups in the switch that aren't in the store
log.trace("Group AUDIT: extraneous group {} exists " + "in data plane for device {}", group.id(), deviceId);
extraneousStoredEntries.remove(group);
extraneousGroup(group);
}
}
for (Group group : storedGroupEntries) {
// there are groups in the store that aren't in the switch
log.trace("Group AUDIT: group {} missing " + "in data plane for device {}", group.id(), deviceId);
groupMissing(group);
}
for (Group group : extraneousStoredEntries) {
// there are groups in the extraneous store that
// aren't in the switch
log.trace("Group AUDIT: clearing extransoeus group {} " + "from store for device {}", group.id(), deviceId);
removeExtraneousGroupEntry(group);
}
if (!deviceInitialAuditStatus) {
log.debug("Group AUDIT: Setting device {} initial " + "AUDIT completed", deviceId);
deviceInitialAuditCompleted(deviceId, true);
}
}
use of org.onosproject.net.group.Group in project onos by opennetworkinglab.
the class SimpleGroupStore method updateGroupDescription.
/**
* Updates the existing group entry with the information
* from group description.
*
* @param deviceId the device ID
* @param oldAppCookie the current group key
* @param type update type
* @param newBuckets group buckets for updates
* @param newAppCookie optional new group key
*/
@Override
public void updateGroupDescription(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) {
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);
newGroup.setState(GroupState.PENDING_UPDATE);
newGroup.setLife(oldGroup.life());
newGroup.setPackets(oldGroup.packets());
newGroup.setBytes(oldGroup.bytes());
// Remove the old entry from maps and add new entry using new key
ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(oldGroup.deviceId());
ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(oldGroup.deviceId());
keyTable.remove(oldGroup.appCookie());
idTable.remove(oldGroup.id());
keyTable.put(newGroup.appCookie(), newGroup);
idTable.put(newGroup.id(), newGroup);
notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_REQUESTED, newGroup));
}
}
use of org.onosproject.net.group.Group in project onos by opennetworkinglab.
the class SimpleGroupStoreTest method testRemoveGroupFromSB.
// Testing removeGroupEntry operation from southbound
private void testRemoveGroupFromSB(GroupKey currKey) {
Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
InternalGroupStoreDelegate removeGroupEntryDelegate = new InternalGroupStoreDelegate(currKey, existingGroup.buckets(), GroupEvent.Type.GROUP_REMOVED);
simpleGroupStore.setDelegate(removeGroupEntryDelegate);
simpleGroupStore.removeGroupEntry(existingGroup);
// Testing getGroup operation
existingGroup = simpleGroupStore.getGroup(D1, currKey);
assertEquals(null, existingGroup);
assertEquals(0, Iterables.size(simpleGroupStore.getGroups(D1)));
assertEquals(0, simpleGroupStore.getGroupCount(D1));
simpleGroupStore.unsetDelegate(removeGroupEntryDelegate);
}
use of org.onosproject.net.group.Group 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);
}
Aggregations