+ public synchronized void removeFibEntryFromDS(String rd, String prefix) {
+
+ LOG.debug("Removing fib entry with destination prefix {} from vrf table for rd {}", prefix, rd);
+
+ InstanceIdentifierBuilder<VrfEntry> idBuilder =
+ InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).child(VrfEntry.class, new VrfEntryKey(prefix));
+ InstanceIdentifier<VrfEntry> vrfEntryId = idBuilder.build();
+ VpnUtil.delete(broker, LogicalDatastoreType.OPERATIONAL, vrfEntryId, VpnUtil.DEFAULT_CALLBACK);
+
+ }
+
+ public synchronized void removeVrfFromDS(String rd) {
+ LOG.debug("Removing vrf table for rd {}", rd);
+
+ InstanceIdentifierBuilder<VrfTables> idBuilder =
+ InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd));
+ InstanceIdentifier<VrfTables> vrfTableId = idBuilder.build();
+
+ VpnUtil.delete(broker, LogicalDatastoreType.OPERATIONAL, vrfTableId, VpnUtil.DEFAULT_CALLBACK);
+
+ }
+
+ protected void addNewAdjToVpnInterface(InstanceIdentifier<VpnInterface> identifier, Adjacency adj) {
+
+ Optional<VpnInterface> optVpnInterface = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, identifier);
+
+ if (optVpnInterface.isPresent()) {
+ VpnInterface currVpnIntf = optVpnInterface.get();
+ String prefix = VpnUtil.getIpPrefix(adj.getIpAddress());
+ String rd = getRouteDistinguisher(currVpnIntf.getVpnInstanceName());
+ InstanceIdentifier<Adjacencies> adjPath = identifier.augmentation(Adjacencies.class);
+ Optional<Adjacencies> optAdjacencies = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, adjPath);
+ long label =
+ VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME,
+ VpnUtil.getNextHopLabelKey((rd != null) ? rd : currVpnIntf.getVpnInstanceName(), prefix));
+
+ List<Adjacency> adjacencies;
+ if (optAdjacencies.isPresent()) {
+ adjacencies = optAdjacencies.get().getAdjacency();
+ } else {
+ //This code will not be hit since VM adjacency will always be there
+ adjacencies = new ArrayList<>();
+ }
+
+ adjacencies.add(new AdjacencyBuilder(adj).setLabel(label).setNextHopIp(adj.getNextHopIp())
+ .setIpAddress(prefix).setKey(new AdjacencyKey(prefix)).build());
+
+ Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(adjacencies);
+ VpnInterface newVpnIntf = VpnUtil.getVpnInterface(currVpnIntf.getName(), currVpnIntf.getVpnInstanceName(), aug);
+
+ VpnUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, identifier, newVpnIntf);
+ addExtraRoute(adj.getIpAddress(), adj.getNextHopIp(), rd, currVpnIntf.getVpnInstanceName(), (int) label);
+
+ }
+
+ }
+
+ protected void delAdjFromVpnInterface(InstanceIdentifier<VpnInterface> identifier, Adjacency adj) {
+ Optional<VpnInterface> optVpnInterface = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, identifier);
+
+ if (optVpnInterface.isPresent()) {
+ VpnInterface currVpnIntf = optVpnInterface.get();
+
+ InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
+ Optional<Adjacencies> optAdjacencies = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, path);
+ if (optAdjacencies.isPresent()) {
+ List<Adjacency> adjacencies = optAdjacencies.get().getAdjacency();
+
+ if (!adjacencies.isEmpty()) {
+ String rd = getRouteDistinguisher(currVpnIntf.getVpnInstanceName());
+ LOG.trace("Adjacencies are " + adjacencies);
+ Iterator<Adjacency> adjIt = adjacencies.iterator();
+ while (adjIt.hasNext()) {
+ Adjacency adjElem = adjIt.next();
+ if (adjElem.getIpAddress().equals(adj.getIpAddress())) {
+ VpnUtil.releaseId(idManager, VpnConstants.VPN_IDPOOL_NAME,
+ VpnUtil.getNextHopLabelKey(rd, adj.getIpAddress()));
+ adjIt.remove();
+
+ Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(adjacencies);
+ VpnInterface newVpnIntf = VpnUtil.getVpnInterface(currVpnIntf.getName(), currVpnIntf.getVpnInstanceName(), aug);
+
+ VpnUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, identifier, newVpnIntf);
+
+ delExtraRoute(adj.getIpAddress(), rd, currVpnIntf.getVpnInstanceName());
+ break;
+ }
+
+ }
+ }
+ }
+ }
+
+ }
+
+ protected void addExtraRoute(String destination, String nextHop, String rd, String routerID, int label) {
+ if (rd != null) {
+ addPrefixToBGP(rd, destination, nextHop, label);
+ } else {
+ // ### add FIB route directly
+ addFibEntryToDS(routerID, destination, nextHop, label);
+ }