use of org.onosproject.net.group.DefaultGroup 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.DefaultGroup in project onos by opennetworkinglab.
the class NullGroupProvider method groupAdd.
private void groupAdd(DeviceId deviceId, GroupOperation go) {
GroupId gid = go.groupId();
DefaultGroup group = new DefaultGroup(gid, deviceId, go.groupType(), go.buckets());
group.setState(Group.GroupState.ADDED);
groupTables.get(deviceId).put(gid, group);
}
use of org.onosproject.net.group.DefaultGroup in project onos by opennetworkinglab.
the class P4RuntimeReplicationGroupProgrammable method addedGroup.
private Group addedGroup(Group original, long life) {
final DefaultGroup forgedGroup = new DefaultGroup(original.id(), original);
forgedGroup.setState(Group.GroupState.ADDED);
forgedGroup.setLife(life);
return forgedGroup;
}
use of org.onosproject.net.group.DefaultGroup in project fabric-tna by stratum.
the class FabricPipeliner method handleVerify.
private ObjectiveError handleVerify(NextObjective nextObjective) {
Map<GroupBucket, FlowRule> bucketsToFlows = getBucketToFlowMapping(nextObjective);
if (bucketsToFlows.isEmpty() && !nextObjective.nextTreatments().isEmpty()) {
log.warn("VERIFY failed due to translation error, bucketsToFlows is empty");
return ObjectiveError.BADPARAMS;
}
if (log.isTraceEnabled()) {
log.trace("Mapping bucketsToFlows {} has been generated ", bucketsToFlows);
}
GroupKey groupKey = nextTranslator.getGroupKey(nextObjective);
if (groupKey == null) {
log.warn("VERIFY failed due to translation error, unable to determine group key");
return ObjectiveError.BADPARAMS;
}
Group groupFromStore = groupService.getGroup(deviceId, groupKey);
if (groupFromStore == null) {
log.warn("VERIFY failed due to missing group in the store");
return ObjectiveError.GROUPMISSING;
}
// Looking for duplicate buckets - remove them by using a set and comparing size after/before
Set<GroupBucket> bucketsFromStore = Sets.newHashSet(groupFromStore.buckets().buckets());
if (groupFromStore.buckets().buckets().size() > bucketsFromStore.size()) {
log.warn("Duplicated buckets detected in device:{}, nextId:{}, before-size" + ":{} after-size:{} .. correcting", deviceId, nextObjective.id(), groupFromStore.buckets().buckets().size(), bucketsFromStore.size());
final GroupBuckets bucketToSet = new GroupBuckets(Lists.newArrayList(bucketsFromStore));
groupService.setBucketsForGroup(deviceId, groupKey, bucketToSet, groupKey, nextObjective.appId());
// Forge temporary the group to avoid race condition with the store
groupFromStore = new DefaultGroup(groupFromStore.id(), deviceId, groupFromStore.type(), bucketToSet);
}
// Looking for buckets missing in the group but defined in the next
Map<GroupBucket, FlowRule> toAdd = Maps.newHashMap();
for (Map.Entry<GroupBucket, FlowRule> entry : bucketsToFlows.entrySet()) {
if (!groupFromStore.buckets().buckets().contains(entry.getKey())) {
toAdd.put(entry.getKey(), entry.getValue());
}
}
// Looking for buckets missing in the next but defined in the group
// FIXME SDFAB-250 we cannot remove associated egress flows
List<GroupBucket> toRemove = Lists.newArrayList();
groupFromStore.buckets().buckets().forEach(bucket -> {
if (!bucketsToFlows.containsKey(bucket)) {
toRemove.add(bucket);
}
});
if (!toAdd.isEmpty() || !toRemove.isEmpty()) {
log.warn("Mismatch detected in device:{}, nextId:{}, groupFromTranslation-size:{} " + "groupFromStore-size:{} toAdd-size:{} toRemove-size: {} .. correcting", deviceId, nextObjective.id(), bucketsToFlows.size(), groupFromStore.buckets().buckets().size(), toAdd.size(), toRemove.size());
}
if (!toAdd.isEmpty()) {
if (log.isTraceEnabled()) {
log.trace("Adding missing buckets {} and flows {}", toAdd.keySet(), toAdd.values());
}
final FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
final FlowRule dummyFlow = getDummyFlow(nextObjective);
toAdd.values().stream().filter(flowRule -> !flowRule.equals(dummyFlow)).forEach(ops::add);
final GroupBuckets bucketsToAdd = new GroupBuckets(Lists.newArrayList(toAdd.keySet()));
groupService.addBucketsToGroup(deviceId, groupKey, bucketsToAdd, groupKey, nextObjective.appId());
flowRuleService.apply(ops.build());
}
if (!toRemove.isEmpty()) {
if (log.isTraceEnabled()) {
log.trace("Removing stale buckets {}", toRemove);
}
final GroupBuckets bucketsToRemove = new GroupBuckets(toRemove);
groupService.removeBucketsFromGroup(deviceId, groupKey, bucketsToRemove, groupKey, nextObjective.appId());
}
return null;
}
use of org.onosproject.net.group.DefaultGroup in project onos by opennetworkinglab.
the class DistributedGroupStore method storeGroupDescriptionInternal.
private void storeGroupDescriptionInternal(GroupDescription groupDesc) {
// Check if a group is existing with the same key
if (getGroup(groupDesc.deviceId(), groupDesc.appCookie()) != null) {
return;
}
synchronized (deviceAuditStatus) {
if (deviceAuditStatus.get(groupDesc.deviceId()) == null) {
// Device group audit has not completed yet
// Add this group description to pending group key table
// Create a group entry object with Dummy Group ID
log.debug("storeGroupDescriptionInternal: Device {} AUDIT pending...Queuing Group id {} ADD request", groupDesc.deviceId(), groupDesc.givenGroupId() != null ? "0x" + Integer.toHexString(groupDesc.givenGroupId()) : "N/A");
StoredGroupEntry group = new DefaultGroup(dummyGroupId, groupDesc);
group.setState(GroupState.WAITING_AUDIT_COMPLETE);
Map<GroupStoreKeyMapKey, StoredGroupEntry> pendingKeyTable = getPendingGroupKeyTable();
pendingKeyTable.put(new GroupStoreKeyMapKey(groupDesc.deviceId(), groupDesc.appCookie()), group);
return;
}
}
Group matchingExtraneousGroup = null;
if (groupDesc.givenGroupId() != null) {
// Check if there is a extraneous group existing with the same Id
matchingExtraneousGroup = getMatchingExtraneousGroupbyId(groupDesc.deviceId(), groupDesc.givenGroupId());
if (matchingExtraneousGroup != null) {
log.debug("storeGroupDescriptionInternal: Matching extraneous group " + "found in Device {} for group id 0x{}", groupDesc.deviceId(), Integer.toHexString(groupDesc.givenGroupId()));
// Check if the group buckets matches with user provided buckets
if (matchingExtraneousGroup.buckets().equals(groupDesc.buckets())) {
// Group is already existing with the same buckets and Id
// Create a group entry object
log.debug("storeGroupDescriptionInternal: Buckets also matching " + "in Device {} for group id 0x{}", groupDesc.deviceId(), Integer.toHexString(groupDesc.givenGroupId()));
StoredGroupEntry group = new DefaultGroup(matchingExtraneousGroup.id(), groupDesc);
// Insert the newly created group entry into key and id maps
getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(groupDesc.deviceId(), groupDesc.appCookie()), group);
// Ensure it also inserted into group id based table to
// avoid any chances of duplication in group id generation
getGroupIdTable(groupDesc.deviceId()).put(matchingExtraneousGroup.id(), group);
addOrUpdateGroupEntry(matchingExtraneousGroup);
removeExtraneousGroupEntry(matchingExtraneousGroup);
return;
} else {
// Group buckets are not matching. Update group
// with user provided buckets.
log.debug("storeGroupDescriptionInternal: Buckets are not " + "matching in Device {} for group id 0x{}", groupDesc.deviceId(), Integer.toHexString(groupDesc.givenGroupId()));
StoredGroupEntry modifiedGroup = new DefaultGroup(matchingExtraneousGroup.id(), groupDesc);
modifiedGroup.setState(GroupState.PENDING_UPDATE);
getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(groupDesc.deviceId(), groupDesc.appCookie()), modifiedGroup);
// Ensure it also inserted into group id based table to
// avoid any chances of duplication in group id generation
getGroupIdTable(groupDesc.deviceId()).put(matchingExtraneousGroup.id(), modifiedGroup);
removeExtraneousGroupEntry(matchingExtraneousGroup);
log.debug("storeGroupDescriptionInternal: Triggering Group " + "UPDATE request for {} in device {}", matchingExtraneousGroup.id(), groupDesc.deviceId());
notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_REQUESTED, modifiedGroup));
return;
}
}
} else {
// Check if there is an extraneous group with user provided buckets
matchingExtraneousGroup = getMatchingExtraneousGroupbyBuckets(groupDesc.deviceId(), groupDesc.buckets());
if (matchingExtraneousGroup != null) {
// Group is already existing with the same buckets.
// So reuse this group.
log.debug("storeGroupDescriptionInternal: Matching extraneous group found in Device {}", groupDesc.deviceId());
// Create a group entry object
StoredGroupEntry group = new DefaultGroup(matchingExtraneousGroup.id(), groupDesc);
// Insert the newly created group entry into key and id maps
getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(groupDesc.deviceId(), groupDesc.appCookie()), group);
// Ensure it also inserted into group id based table to
// avoid any chances of duplication in group id generation
getGroupIdTable(groupDesc.deviceId()).put(matchingExtraneousGroup.id(), group);
addOrUpdateGroupEntry(matchingExtraneousGroup);
removeExtraneousGroupEntry(matchingExtraneousGroup);
return;
} else {
// TODO: Check if there are any empty groups that can be used here
log.debug("storeGroupDescriptionInternal: No matching extraneous groups found in Device {}", groupDesc.deviceId());
}
}
GroupId id = null;
if (groupDesc.givenGroupId() == null) {
// Get a new group identifier
id = new GroupId(getFreeGroupIdValue(groupDesc.deviceId()));
} else {
// we need to use the identifier passed in by caller, but check if
// already used
Group existing = getGroup(groupDesc.deviceId(), new GroupId(groupDesc.givenGroupId()));
if (existing != null) {
log.warn("Group already exists with the same id: 0x{} in dev:{} " + "but with different key: {} (request gkey: {})", Integer.toHexString(groupDesc.givenGroupId()), groupDesc.deviceId(), existing.appCookie(), groupDesc.appCookie());
return;
}
id = new GroupId(groupDesc.givenGroupId());
}
// Create a group entry object
StoredGroupEntry group = new DefaultGroup(id, groupDesc);
// Insert the newly created group entry into key and id maps
getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(groupDesc.deviceId(), groupDesc.appCookie()), group);
// Ensure it also inserted into group id based table to
// avoid any chances of duplication in group id generation
getGroupIdTable(groupDesc.deviceId()).put(id, group);
log.debug("storeGroupDescriptionInternal: Processing Group ADD request for Id {} in device {}", id, groupDesc.deviceId());
notifyDelegate(new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, group));
}
Aggregations