use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.group.buckets.bucket.action.action.NxActionRegLoadNodesNodeGroupBucketsBucketActionsCase in project netvirt by opendaylight.
the class ElanUtils method syncUpdateGroup.
public void syncUpdateGroup(Uint64 dpnId, Group newGroup, long delayTime, TypedWriteTransaction<Datastore.Configuration> confTx) {
Node nodeDpn = buildDpnNode(dpnId);
long groupIdInfo = newGroup.getGroupId().getValue().longValue();
GroupKey groupKey = new GroupKey(new GroupId(groupIdInfo));
InstanceIdentifier<Group> groupInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeDpn.key()).augmentation(FlowCapableNode.class).child(Group.class, groupKey).build();
LOG.trace("Performing merge operation for remote BC group for node {} with group {}", nodeDpn, newGroup);
Optional<Group> existingGroupOpt = ElanUtils.read(broker, LogicalDatastoreType.CONFIGURATION, groupInstanceId);
if (!existingGroupOpt.isPresent()) {
LOG.debug("Group {} doesn't exist. Performing syncInstall", groupIdInfo);
mdsalManager.addGroup(confTx, dpnId, newGroup);
return;
}
Buckets existingGroup = existingGroupOpt.get().getBuckets();
if (existingGroup == null) {
LOG.debug("Bucket doesn't exist for group {}. Performing syncInstall", groupIdInfo);
mdsalManager.addGroup(confTx, dpnId, newGroup);
return;
}
if (newGroup.getBuckets() == null) {
LOG.debug("Buckets are not sent for group {}. Skipping merge operation", groupIdInfo);
return;
}
List<Bucket> newBuckets = new ArrayList<>(newGroup.getBuckets().nonnullBucket().values());
List<Bucket> existingBuckets = new ArrayList<>(existingGroup.nonnullBucket().values());
LOG.debug("New Buckets {} and Existing Buckets {}", newBuckets, existingBuckets);
List<Bucket> combinedBuckets = new ArrayList<>(existingBuckets);
Map<String, Bucket> ncBucketMap = new HashMap<>();
Map<String, Bucket> reg6ActionBucketMap = new HashMap<>();
// Add all buckets in the new group to a map with node connector/reg6 value as key
newBuckets.forEach(bucket -> {
List<Action> actionList = new ArrayList<>(bucket.getAction().values());
if (actionList != null && !actionList.isEmpty()) {
actionList.forEach(action -> {
if (action.getAction() instanceof OutputActionCase) {
OutputActionCase outputAction = (OutputActionCase) action.getAction();
String nc = outputAction.getOutputAction().getOutputNodeConnector().getValue();
ncBucketMap.put(nc, bucket);
}
if (action.getAction() instanceof NxActionRegLoadNodesNodeTableFlowApplyActionsCase) {
NxActionRegLoadNodesNodeTableFlowApplyActionsCase regLoad = (NxActionRegLoadNodesNodeTableFlowApplyActionsCase) action.getAction();
String regValue = regLoad.getNxRegLoad().getValue().toString();
reg6ActionBucketMap.put(regValue, bucket);
}
});
}
});
// Replace existing bucket if action has same node connector/reg6 value as stored in map
// First, remove buckets with same nc id/reg6 value as in hashmap from combinedBuckets
// Next, add all the buckets in hashmap to combined buckets
existingBuckets.forEach(existingBucket -> {
List<Action> actionList = new ArrayList<>(existingBucket.getAction().values());
if (actionList != null && !actionList.isEmpty()) {
actionList.forEach(action -> {
if (action.getAction() instanceof OutputActionCase) {
OutputActionCase outputAction = (OutputActionCase) action.getAction();
String nc = outputAction.getOutputAction().getOutputNodeConnector().getValue();
Bucket storedBucket = ncBucketMap.get(nc);
if (storedBucket != null) {
combinedBuckets.remove(existingBucket);
}
}
if (action.getAction() instanceof NxActionRegLoadNodesNodeGroupBucketsBucketActionsCase) {
NxActionRegLoadNodesNodeGroupBucketsBucketActionsCase regLoad = (NxActionRegLoadNodesNodeGroupBucketsBucketActionsCase) action.getAction();
String regValue = regLoad.getNxRegLoad().getValue().toString();
Bucket storedBucket = reg6ActionBucketMap.get(regValue);
if (storedBucket != null) {
combinedBuckets.remove(existingBucket);
}
}
});
}
});
AtomicLong bucketIdValue = new AtomicLong(-1);
// Change the bucket id of existing buckets
List<Bucket> bucketsToBeAdded = new ArrayList<>();
bucketsToBeAdded.addAll(combinedBuckets.stream().map(bucket -> {
BucketId bucketId = new BucketId(bucketIdValue.incrementAndGet());
return new BucketBuilder(bucket).withKey(new BucketKey(bucketId)).setBucketId(bucketId).build();
}).collect(Collectors.toList()));
// Change the bucket id of remaining to be added to the combined buckets
bucketsToBeAdded.addAll(ncBucketMap.values().stream().map(bucket -> {
BucketId bucketId = new BucketId(bucketIdValue.incrementAndGet());
return new BucketBuilder(bucket).withKey(new BucketKey(bucketId)).setBucketId(bucketId).build();
}).collect(Collectors.toList()));
bucketsToBeAdded.addAll(reg6ActionBucketMap.values().stream().map(bucket -> {
BucketId bucketId = new BucketId(bucketIdValue.incrementAndGet());
return new BucketBuilder(bucket).withKey(new BucketKey(bucketId)).setBucketId(bucketId).build();
}).collect(Collectors.toList()));
Group group = MDSALUtil.buildGroup(newGroup.getGroupId().getValue().longValue(), newGroup.getGroupName(), GroupTypes.GroupAll, MDSALUtil.buildBucketLists(bucketsToBeAdded));
mdsalManager.addGroup(confTx, dpnId, group);
LOG.trace("Installed remote BC group for node {} with group {}", nodeDpn.key().getId().getValue(), group);
}
Aggregations