+ private void delIntfFromDpnToVpnList(long vpnId, BigInteger dpnId, String intfName, String rd) {
+ InstanceIdentifier<VpnToDpnList> id = FibUtil.getVpnToDpnListIdentifier(rd, dpnId);
+ Optional<VpnToDpnList> dpnInVpn = FibUtil.read(broker, LogicalDatastoreType.OPERATIONAL, id);
+ if (dpnInVpn.isPresent()) {
+ List<org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data
+ .vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces> vpnInterfaces = dpnInVpn.get().getVpnInterfaces();
+ org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces
+ currVpnInterface = new org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfacesBuilder().setInterfaceName(intfName).build();
+
+ if (vpnInterfaces.remove(currVpnInterface)) {
+ if (vpnInterfaces.isEmpty()) {
+ LOG.trace("Last vpn interface {} on dpn {} for vpn {}. Clean up fib in dpn", intfName, dpnId, rd);
+ FibUtil.delete(broker, LogicalDatastoreType.OPERATIONAL, id);
+ cleanUpDpnForVpn(dpnId, vpnId, rd);
+ } else {
+ LOG.trace("Delete vpn interface {} from dpn {} to vpn {} list.", intfName, dpnId, rd);
+ FibUtil.delete(broker, LogicalDatastoreType.OPERATIONAL, id.child(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data
+ .vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces.class,
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfacesKey(intfName)));
+ }
+ }
+ }
+ }
+
+ private void cleanUpOpDataForFib(Long vpnId, String rd, final VrfEntry vrfEntry) {
+ /* Get interface info from prefix to interface mapping;
+ Use the interface info to get the corresponding vpn interface op DS entry,
+ remove the adjacency corresponding to this fib entry.
+ If adjacency removed is the last adjacency, clean up the following:
+ - vpn interface from dpntovpn list, dpn if last vpn interface on dpn
+ - prefix to interface entry
+ - vpn interface op DS
+ */
+ Prefixes prefixInfo = getPrefixToInterface(vpnId, vrfEntry.getDestPrefix());
+ Extraroute extraRoute = null;
+ if (prefixInfo == null) {
+ extraRoute = getVpnToExtraroute(rd, vrfEntry.getDestPrefix());
+ if(extraRoute != null) {
+ prefixInfo = getPrefixToInterface(vpnId, extraRoute.getNexthopIp() + "/32");
+ //clean up the vpn to extra route entry in DS
+ FibUtil.delete(broker, LogicalDatastoreType.OPERATIONAL, FibUtil.getVpnToExtrarouteIdentifier(rd, vrfEntry.getDestPrefix()));
+ }
+ }
+ if (prefixInfo == null) {
+ LOG.debug("Cleanup VPN Data Failed as unable to find prefix Info for " + vrfEntry.getDestPrefix());
+ return; //Don't have any info for this prefix (shouldn't happen); need to return
+ }
+ String ifName = prefixInfo.getVpnInterfaceName();
+ Optional<Adjacencies> optAdjacencies = FibUtil.read(broker, LogicalDatastoreType.OPERATIONAL, FibUtil.getAdjListPath(ifName));
+ int numAdj = 0;
+ if (optAdjacencies.isPresent()) {
+ numAdj = optAdjacencies.get().getAdjacency().size();
+ }
+ LOG.trace("cleanUpOpDataForFib: remove adjacency for prefix: {} {}", vpnId, vrfEntry.getDestPrefix());
+ //remove adjacency corr to prefix
+ if (numAdj > 1) {
+ FibUtil.delete(broker, LogicalDatastoreType.OPERATIONAL,
+ FibUtil.getAdjacencyIdentifier(ifName, vrfEntry.getDestPrefix()));
+ }
+
+ if ((numAdj - 1) == 0) { //there are no adjacencies left for this vpn interface, clean up
+ //clean up the vpn interface from DpnToVpn list
+ LOG.trace("Clean up vpn interface {} from dpn {} to vpn {} list.", ifName, prefixInfo.getDpnId(), rd);
+ FibUtil.delete(broker, LogicalDatastoreType.OPERATIONAL,
+ FibUtil.getVpnInterfaceIdentifier(ifName));
+ }
+ }
+