+ protected Node buildDpnNode(Uint64 dpnId) {
+ org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId nodeId =
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819
+ .NodeId("openflow:" + dpnId);
+ Node nodeDpn = new NodeBuilder().setId(nodeId).withKey(new NodeKey(nodeId)).build();
+ return nodeDpn;
+ }
+
+ public void syncUpdateGroup(Uint64 dpnId, Group newGroup, long delayTime,
+ TypedWriteTransaction<Datastore.Configuration> confTx) {
+ Node nodeDpn = buildDpnNode(dpnId);
+ long groupIdInfo = newGroup.getGroupId().getValue().toJava();
+ 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<Bucket>(newGroup.getBuckets().getBucket().values());
+ List<Bucket> existingBuckets = new ArrayList<Bucket>(existingGroup.getBucket().values());
+ Set<Bucket> toMergeBucketsWithoutId = new LinkedHashSet<>();
+
+ existingBuckets.stream()
+ .map(TO_BUCKET_WITHOUT_ID)
+ .forEach(bucketWithoutId -> toMergeBucketsWithoutId.add(bucketWithoutId));
+
+ newBuckets.stream()
+ .map(TO_BUCKET_WITHOUT_ID)
+ .forEach(bucketWithoutId -> toMergeBucketsWithoutId.add(bucketWithoutId));
+
+ if (toMergeBucketsWithoutId.size() == existingBuckets.size()) {
+ //no new buckets got added
+ //size matched and no extra buckets in existing buckets , rewrite the group
+ LOG.debug("Buckets did not change group {}. Skipping merge operation", groupIdInfo);
+ return;
+ }
+ LOG.debug("Old group buckets size {} New group buckets size {} Dpn id {} Group id {} ",
+ existingBuckets.size(), toMergeBucketsWithoutId.size(), dpnId, groupIdInfo);
+ AtomicLong bucketIdValue = new AtomicLong(-1);
+ //Change the bucket id of existing buckets
+ List<Bucket> bucketsToBeAdded = toMergeBucketsWithoutId.stream()
+ .map(bucketWithoutId -> TO_BUCKET_WITH_ID.apply(bucketWithoutId, bucketIdValue))
+ .collect(Collectors.toList());
+
+ Group group = MDSALUtil.buildGroup(newGroup.getGroupId().getValue().toJava(), newGroup.getGroupName(),
+ GroupTypes.GroupAll, MDSALUtil.buildBucketLists(bucketsToBeAdded));
+ mdsalManager.addGroup(confTx, dpnId, group);
+ LOG.trace("Installed remote BC group for node {} with group {}", nodeDpn, group);
+ }
+
+ static InstanceIdentifier<Subnetmaps> buildSubnetMapsWildCardPath() {
+ return InstanceIdentifier.create(Subnetmaps.class);
+ }
+
+ public static InstanceIdentifier<Group> getGroupInstanceid(Uint64 dpnId, long groupId) {
+ return InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow:" + dpnId)))
+ .augmentation(FlowCapableNode.class).child(Group.class, new GroupKey(new GroupId(groupId))).build();
+ }
+
+ public static String getBcGroupUpdateKey(String elanName) {
+ return "bc.group.update." + elanName;
+ }
+}