use of org.onosproject.net.group.DefaultGroup 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.DefaultGroup in project onos by opennetworkinglab.
the class GroupManagerTest method createSouthboundGroupEntry.
private static Group createSouthboundGroupEntry(GroupId gId, List<PortNumber> ports, long referenceCount, DeviceId deviceId) {
List<PortNumber> outPorts = new ArrayList<>();
outPorts.addAll(ports);
List<GroupBucket> buckets = new ArrayList<>();
for (PortNumber portNumber : outPorts) {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
tBuilder.setOutput(portNumber).setEthDst(MacAddress.valueOf("00:00:00:00:00:02")).setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")).pushMpls().setMpls(MplsLabel.mplsLabel(106));
buckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
}
GroupBuckets groupBuckets = new GroupBuckets(buckets);
StoredGroupEntry group = new DefaultGroup(gId, deviceId, Group.Type.SELECT, groupBuckets);
group.setReferenceCount(referenceCount);
return group;
}
use of org.onosproject.net.group.DefaultGroup in project onos by opennetworkinglab.
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 PiReplicationGroupTranslatorImplTest method createGroup.
private static Group createGroup(List<GroupBucket> bucketList, GroupDescription.Type type) {
final GroupBuckets buckets = new GroupBuckets(bucketList);
final GroupDescription groupDesc = new DefaultGroupDescription(DEVICE_ID, type, buckets, GROUP_KEY, GROUP_ID.id(), APP_ID);
return new DefaultGroup(GROUP_ID, groupDesc);
}
use of org.onosproject.net.group.DefaultGroup in project onos by opennetworkinglab.
the class NullGroupProvider method groupModify.
private void groupModify(DeviceId deviceId, GroupOperation go) {
groupTables.get(deviceId).computeIfPresent(go.groupId(), (gid, group) -> {
DefaultGroup grp = new DefaultGroup(gid, deviceId, go.groupType(), go.buckets());
grp.setState(Group.GroupState.ADDED);
return grp;
});
}
Aggregations