+ synchronized (intfName) {
+ // Read NextHops
+ InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
+ Optional<Adjacencies> adjacencies = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, path);
+
+ if (adjacencies.isPresent()) {
+ List<Adjacency> nextHops = adjacencies.get().getAdjacency();
+ List<Adjacency> value = new ArrayList<>();
+
+ // Get the rd of the vpn instance
+ String rd = getRouteDistinguisher(intf.getVpnInstanceName());
+
+ BigInteger dpnId = InterfaceUtils.getDpnForInterface(interfaceManager, intfName);
+ String nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(broker, dpnId);
+ if (nextHopIp == null){
+ LOG.error("NextHop for interface {} is null", intfName);
+ }
+
+ LOG.trace("NextHops are {}", nextHops);
+ for (Adjacency nextHop : nextHops) {
+ String prefix = VpnUtil.getIpPrefix(nextHop.getIpAddress());
+ long label = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil
+ .getNextHopLabelKey((rd == null) ? intf.getVpnInstanceName() : rd, prefix));
+ String adjNextHop = nextHop.getNextHopIp();
+ value.add(new AdjacencyBuilder(nextHop).setLabel(label).setNextHopIp((adjNextHop != null && !adjNextHop.isEmpty()) ? adjNextHop : nextHopIp)
+ .setIpAddress(prefix).setKey(new AdjacencyKey(prefix)).build());
+ if(nextHop.getMacAddress() != null && !nextHop.getMacAddress().isEmpty()) {
+ VpnUtil.syncUpdate(
+ broker,
+ LogicalDatastoreType.OPERATIONAL,
+ VpnUtil.getPrefixToInterfaceIdentifier(
+ VpnUtil.getVpnId(broker, intf.getVpnInstanceName()), prefix),
+ VpnUtil.getPrefixToInterface(dpnId, intf.getName(), prefix));
+ }
+ }
+
+ Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(value);
+ VpnInterface opInterface = VpnUtil.getVpnInterface(intfName, intf.getVpnInstanceName(), aug);
+ InstanceIdentifier<VpnInterface> interfaceId = VpnUtil.getVpnInterfaceIdentifier(intfName);
+ VpnUtil.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, interfaceId, opInterface);
+ for (Adjacency nextHop : aug.getAdjacency()) {
+ long label = nextHop.getLabel();
+ String adjNextHop = nextHop.getNextHopIp();
+ if (rd != null) {
+ addPrefixToBGP(rd, nextHop.getIpAddress(),
+ (adjNextHop != null && !adjNextHop.isEmpty()) ? adjNextHop : nextHopIp, label);
+ } else {
+ // ### add FIB route directly
+ addFibEntryToDS(intf.getVpnInstanceName(), nextHop.getIpAddress(),
+ (adjNextHop != null && !adjNextHop.isEmpty()) ? adjNextHop : nextHopIp, (int) label);
+ }
+ }