- Preconditions.checkNotNull(availableDcGws, "There are no dc-gws present");
- int noOfDcGws = availableDcGws.size();
- if (noOfDcGws == 1) {
- LOG.trace("There are no enough DC GateWays {} present to program LB group", availableDcGws);
- return;
- }
- // TODO : Place the logic to construct all possible DC-GW combination here.
- String groupIdKey = FibUtil.getGreLbGroupKey(availableDcGws);
- Long groupId = createNextHopPointer(groupIdKey);
- List<Bucket> listBucket = new ArrayList<>();
- for (int index = 0; index < noOfDcGws; index++) {
- if (isTunnelUp(availableDcGws.get(index), dpnId, tunnelType)) {
- listBucket.add(buildBucketForDcGwLbGroup(availableDcGws.get(index), dpnId, index, tunnelType));
- }
+ jobCoordinator.enqueueJob(getJobKey(dpnId), () -> {
+ List<ListenableFuture<Void>> futures = new ArrayList<>();
+ futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operationalTx -> {
+ synchronized (getDcGateWaySyncKey(destinationIp)) {
+ FibUtil.addL3vpnDcGateWay(destinationIp, operationalTx);
+ }
+ futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, configTx -> {
+ List<String> availableDcGws = getDcGwIps();
+ Preconditions.checkNotNull(availableDcGws, "There are no dc-gws present");
+ int noOfDcGws = availableDcGws.size();
+ if (noOfDcGws == 1) {
+ LOG.trace("There are no enough DC GateWays {} present to program LB group", availableDcGws);
+ return;
+ }
+ if (availableDcGws.contains(destinationIp)) {
+ availableDcGws.remove(destinationIp);
+ }
+ availableDcGws.forEach(dcGwIp -> {
+ List<String> dcGws = Arrays.asList(dcGwIp, destinationIp);
+ Collections.sort(dcGws);
+ String groupIdKey = FibUtil.getGreLbGroupKey(dcGws);
+ Long groupId = createNextHopPointer(groupIdKey);
+ List<Bucket> listBucket = new ArrayList<>();
+ for (int index = 0; index < dcGws.size(); index++) {
+ if (isTunnelUp(dcGws.get(index), dpnId, tunnelType)) {
+ listBucket.add(buildBucketForDcGwLbGroup(dcGws.get(index),
+ dpnId, index, tunnelType, true));
+ }
+ }
+ Group group = MDSALUtil.buildGroup(groupId, groupIdKey, GroupTypes.GroupSelect,
+ MDSALUtil.buildBucketLists(listBucket));
+ mdsalApiManager.addGroup(configTx, dpnId, group);
+ FibUtil.updateLbGroupInfo(dpnId, groupIdKey, groupId.toString(), operationalTx);
+ LOG.trace("LB group {} towards DC-GW installed on dpn {}. Group - {}",
+ groupIdKey, dpnId, group);
+ });
+ }));
+ }));
+ return futures;
+ }, RETRY_COUNT);
+ }
+
+ private String getJobKey(BigInteger dpnId) {
+ return new StringBuilder().append(NEXTHOPMANAGER_JOB_KEY_PREFIX).append(dpnId).toString();
+ }
+
+ private String getDcGateWaySyncKey(String destinationIp) {
+ String mutex = new StringBuilder().append("L3vpncDcGateWay").append(destinationIp).toString();
+ return mutex.intern();
+ }
+
+ private List<String> getDcGwIps() {
+ InstanceIdentifier<DcGatewayIpList> dcGatewayIpListid =
+ InstanceIdentifier.builder(DcGatewayIpList.class).build();
+ DcGatewayIpList dcGatewayIpListConfig =
+ MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, dcGatewayIpListid).orNull();
+ if (dcGatewayIpListConfig == null) {
+ return Collections.emptyList();