X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=vpnmanager%2Fvpnmanager-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2FVpnInterfaceManager.java;h=469b0e33a6c6c9f84d035cc78ba647acd77c359e;hb=2718ef3baf8e42e48743fbae515c152aa017e51f;hp=61ff3b818d97630a3ab68ce16407f862fdb95834;hpb=531867226c199d987d941aae9f8412e266a408d1;p=vpnservice.git diff --git a/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnInterfaceManager.java b/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnInterfaceManager.java index 61ff3b81..469b0e33 100644 --- a/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnInterfaceManager.java +++ b/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnInterfaceManager.java @@ -16,8 +16,21 @@ import com.google.common.util.concurrent.JdkFutureAdapters; import org.opendaylight.controller.md.sal.binding.api.*; import org.opendaylight.vpnservice.mdsalutil.*; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.NeutronRouterDpns; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.NeutronvpnService; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.PrefixToInterface; import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.adjacency.list.AdjacencyKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.neutron.router.dpns.RouterDpnList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.neutron.router.dpns.RouterDpnListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.neutron.router.dpns.RouterDpnListKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesListKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry; import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList; import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListBuilder; @@ -46,6 +59,7 @@ import java.util.concurrent.*; import com.google.common.base.Optional; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.NeutronvpnService; import org.opendaylight.bgpmanager.api.IBgpManager; import org.opendaylight.fibmanager.api.IFibManager; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.OdlInterfaceRpcService; @@ -85,6 +99,8 @@ public class VpnInterfaceManager extends AbstractDataChangeListener identifier, VpnInterface intf) { + private void processVpnInterfaceAdjacencies(BigInteger dpnId, final InstanceIdentifier identifier, VpnInterface intf) { String intfName = intf.getName(); synchronized (intfName) { @@ -263,7 +292,6 @@ public class VpnInterfaceManager extends AbstractDataChangeListener matches = new ArrayList(); BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(lPortTag, ++sIndex, BigInteger.valueOf(vpnId)); BigInteger metadataMask = MetaDataUtil.getMetaDataMaskForLPortDispatcher(MetaDataUtil.METADATA_MASK_SERVICE_INDEX, @@ -324,10 +362,9 @@ public class VpnInterfaceManager extends AbstractDataChangeListener instructions = new ArrayList(); List actionsInfos = new ArrayList(); actionsInfos.add(new ActionInfo(ActionType.punt_to_controller, new String[] {})); - instructions.add(new InstructionInfo(InstructionType.write_actions, actionsInfos)); + instructions.add(new InstructionInfo(InstructionType.apply_actions, actionsInfos)); // Install the flow entry in L3_INTERFACE_TABLE - BigInteger dpId = InterfaceUtils.getDpnForInterface(interfaceManager, vpnInterfaceName); String flowRef = VpnUtil.getFlowRef(dpId, NwConstants.L3_INTERFACE_TABLE, NwConstants.ETHTYPE_ARP, lPortTag, replyOrRequest.getArpOperation()); FlowEntity flowEntity; @@ -446,13 +483,13 @@ public class VpnInterfaceManager extends AbstractDataChangeListener adjacencies = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, path); String rd = VpnUtil.getVpnRd(broker, intf.getVpnInstanceName()); + LOG.trace("removeAdjacenciesFromVpn: For interface {} RD recovered for vpn {} as rd {}", intf.getName(), + intf.getVpnInstanceName(), rd); if (adjacencies.isPresent()) { List nextHops = adjacencies.get().getAdjacency(); if (!nextHops.isEmpty()) { LOG.trace("NextHops are " + nextHops); for (Adjacency nextHop : nextHops) { - VpnUtil.releaseId(idManager, VpnConstants.VPN_IDPOOL_NAME, + // Commenting the release of ID here as it will be released by FIB + /* VpnUtil.releaseId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(rd, nextHop.getIpAddress())); - /*VpnUtil.delete(broker, LogicalDatastoreType.OPERATIONAL, + VpnUtil.delete(broker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier( VpnUtil.getVpnId(broker, intf.getVpnInstanceName()), nextHop.getIpAddress()), @@ -513,7 +553,8 @@ public class VpnInterfaceManager extends AbstractDataChangeListener identifier, - VpnInterface original, VpnInterface update) { - LOG.trace("Update VPN Interface {} , original {}, update {}", - identifier, original, update); - String vpnName = original.getVpnInstanceName(); - - boolean vpnNameChanged = false; - String rd = getRouteDistinguisher(vpnName); - String newRd = rd; - String newVpnName = update.getVpnInstanceName(); - if(!vpnName.equals(newVpnName)) { - //VPN for this interface got changed. - //Remove the interface from old VPN and add it to new VPN - newRd = getRouteDistinguisher(newVpnName); - if(newRd.equals("")) { - LOG.warn("VPN Instance {} not found. Update operation aborted", newVpnName); - return; - } - vpnNameChanged = true; - LOG.debug("New VPN Name for the interface {} is {}", newVpnName, original.getName()); + protected void update(InstanceIdentifier identifier, VpnInterface original, VpnInterface update) { + if (LOG.isTraceEnabled()) { + LOG.trace("Updating VPN Interface : key " + identifier + ", original value=" + original + ", update " + + "value=" + update); } - + String oldVpnName = original.getVpnInstanceName(); + String newVpnName = update.getVpnInstanceName(); List oldAdjs = original.getAugmentation(Adjacencies.class).getAdjacency(); List newAdjs = update.getAugmentation(Adjacencies.class).getAdjacency(); - if(vpnNameChanged && newAdjs != null && !newAdjs.isEmpty()) { - long label = VpnConstants.INVALID_ID; - InstanceIdentifier path = identifier.augmentation(Adjacencies.class); - Optional adjacencies = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, path); - if (adjacencies.isPresent()) { - List nextHops = adjacencies.get().getAdjacency(); - for(Adjacency nextHop : nextHops) { - label = nextHop.getLabel(); - if(label == VpnConstants.INVALID_ID) { - //Generate label using ID Manager - label = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, - VpnUtil.getNextHopLabelKey(newRd, nextHop.getIpAddress())); - } - if (rd != null) { - removePrefixFromBGP(rd, nextHop.getIpAddress()); - } else { - removeFibEntryFromDS(vpnName, nextHop.getIpAddress()); - } - //updatePrefixToBGP(newRd, nextHop, nextHopIp, label); - } - processVpnInterfaceAdjacencies(identifier, update); - VpnUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, identifier, update); - } - } else if (oldAdjs != newAdjs) { - //handle both addition and removal of adjacencies - //currently, new adjacency may be an extra route + if (oldAdjs == null) { + oldAdjs = new ArrayList<>(); + } + if (newAdjs == null) { + newAdjs = new ArrayList<>(); + } + //handles switching between + if (!oldVpnName.equals(newVpnName)) { + remove(identifier, original); + add(identifier, update); + } + //handle both addition and removal of adjacencies + //currently, new adjacency may be an extra route + if (!oldAdjs.equals(newAdjs)) { for (Adjacency adj : newAdjs) { if (oldAdjs.contains(adj)) { oldAdjs.remove(adj); @@ -593,15 +609,10 @@ public class VpnInterfaceManager extends AbstractDataChangeListener identifier, VpnInterface del) { final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class); String interfaceName = key.getName(); - - //increment the vpn interface count in Vpn Instance Op Data - Long ifCnt = 0L; - String rd = getRouteDistinguisher(del.getVpnInstanceName()); - if(rd.isEmpty()) rd = del.getVpnInstanceName(); - VpnInstanceOpDataEntry vpnInstOp = VpnUtil.getVpnInstanceOpData(broker, rd); - if(vpnInstOp != null && vpnInstOp.getVpnInterfaceCount() != null) { - ifCnt = vpnInstOp.getVpnInterfaceCount(); + String vpnName = del.getVpnInstanceName(); + + LOG.trace("VpnInterfaceOpListener removed: interface name {} vpnName {}", interfaceName, vpnName); + //decrement the vpn interface count in Vpn Instance Op Data + InstanceIdentifier + id = VpnUtil.getVpnInstanceToVpnIdIdentifier(vpnName); + Optional vpnInstance + = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, id); + + if (vpnInstance.isPresent()) { + String rd = null; + rd = vpnInstance.get().getVrfId(); + //String rd = getRouteDistinguisher(del.getVpnInstanceName()); + + VpnInstanceOpDataEntry vpnInstOp = VpnUtil.getVpnInstanceOpData(broker, rd); + LOG.trace("VpnInterfaceOpListener removed: interface name {} rd {} vpnName {} in Vpn Op Instance {}", + interfaceName, rd, vpnName, vpnInstOp); + + if (vpnInstOp != null) { + // Vpn Interface removed => No more adjacencies from it. + // Hence clean up interface from vpn-dpn-interface list. + Adjacency adjacency = del.getAugmentation(Adjacencies.class).getAdjacency().get(0); + Optional prefixToInterface = Optional.absent(); + prefixToInterface = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, + VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), + VpnUtil.getIpPrefix(adjacency.getIpAddress()))); + if (!prefixToInterface.isPresent()) { + prefixToInterface = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, + VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), + VpnUtil.getIpPrefix(adjacency.getNextHopIp()))); + } + if (prefixToInterface.isPresent()) { + VpnUtil.delete(broker, LogicalDatastoreType.OPERATIONAL, + VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), + prefixToInterface.get().getIpAddress()), + VpnUtil.DEFAULT_CALLBACK); + updateDpnDbs(prefixToInterface.get().getDpnId(), del.getVpnInstanceName(), interfaceName, false); + } + Long ifCnt = 0L; + ifCnt = vpnInstOp.getVpnInterfaceCount(); + LOG.trace("VpnInterfaceOpListener removed: interface name {} rd {} vpnName {} Intf count {}", + interfaceName, rd, vpnName, ifCnt); + if ((ifCnt != null) && (ifCnt > 0)) { + VpnUtil.asyncUpdate(broker, LogicalDatastoreType.OPERATIONAL, + VpnUtil.getVpnInstanceOpDataIdentifier(rd), + VpnUtil.updateIntfCntInVpnInstOpData(ifCnt - 1, rd), VpnUtil.DEFAULT_CALLBACK); + } + } + } else { + LOG.error("rd not retrievable as vpninstancetovpnid for vpn {} is absent, trying rd as ", vpnName, vpnName); } - - LOG.trace("VpnInterfaceOpListener remove: interface name {} rd {} interface count in Vpn Op Instance {}", interfaceName, rd, ifCnt); - - VpnUtil.asyncUpdate(broker, LogicalDatastoreType.OPERATIONAL, - VpnUtil.getVpnInstanceOpDataIdentifier(rd), - VpnUtil.updateIntfCntInVpnInstOpData(ifCnt - 1, rd), VpnUtil.DEFAULT_CALLBACK); - - //TODO: Clean up the DPN List in Vpn Instance Op if ifCnt is zero - notifyTaskIfRequired(interfaceName); } @@ -843,7 +889,7 @@ public class VpnInterfaceManager extends AbstractDataChangeListener idBuilder = InstanceIdentifier.builder(VpnInstances.class); InstanceIdentifier vpnInstancesId = idBuilder.build(); Optional vpnInstances = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, vpnInstancesId); @@ -870,46 +917,147 @@ public class VpnInterfaceManager extends AbstractDataChangeListener vpnInstIter = vpnInstanceList.iterator(); while (vpnInstIter.hasNext()) { VpnInstance vpnInstance = vpnInstIter.next(); - VpnAfConfig vpnConfig = vpnInstance.getIpv4Family(); - String rd = vpnConfig.getRouteDistinguisher(); - - InstanceIdentifier id = VpnUtil.getVpnToDpnListIdentifier(rd, dpnId); - Optional dpnInVpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, id); - if (dpnInVpn.isPresent()) { - if (action == UpdateRouteAction.ADVERTISE_ROUTE) { - fibManager.populateFibOnNewDpn(dpnId, VpnUtil - .getVpnId(broker, vpnInstance.getVpnInstanceName()), rd); + try { + VpnAfConfig vpnConfig = vpnInstance.getIpv4Family(); + String rd = vpnConfig.getRouteDistinguisher(); + if (rd == null || rd.isEmpty()) { + rd = vpnInstance.getVpnInstanceName(); } - List vpnInterfaces = dpnInVpn.get().getVpnInterfaces(); - for(org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data - .vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces vpnInterface : vpnInterfaces) { - InstanceIdentifier vpnIntfId = VpnUtil.getVpnInterfaceIdentifier(vpnInterface.getInterfaceName()); - InstanceIdentifier path = vpnIntfId.augmentation(Adjacencies.class); - Optional adjacencies = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, path); - - if (adjacencies.isPresent()) { - List adjacencyList = adjacencies.get().getAdjacency(); - Iterator adjacencyIterator = adjacencyList.iterator(); - - while (adjacencyIterator.hasNext()) { - Adjacency adjacency = adjacencyIterator.next(); - try { - if(action == UpdateRouteAction.ADVERTISE_ROUTE) - bgpManager.addPrefix(rd, adjacency.getIpAddress(), adjacency.getNextHopIp(), adjacency.getLabel().intValue()); - else if(action == UpdateRouteAction.WITHDRAW_ROUTE) - bgpManager.deletePrefix(rd, adjacency.getIpAddress()); - } catch (Exception e) { - LOG.error("Exception when updating prefix {} in vrf {} to BGP", adjacency.getIpAddress(), rd); + InstanceIdentifier id = + VpnUtil.getVpnToDpnListIdentifier(rd, dpnId); + Optional dpnInVpn = + VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, id); + if (dpnInVpn.isPresent()) { + // if (action == UpdateRouteAction.ADVERTISE_ROUTE) { + // fibManager.populateFibOnNewDpn(dpnId, VpnUtil + // .getVpnId(broker, vpnInstance.getVpnInstanceName()), rd); + // } + List + vpnInterfaces = dpnInVpn.get().getVpnInterfaces(); + for (org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data + .vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces vpnInterface : vpnInterfaces) { + InstanceIdentifier vpnIntfId = + VpnUtil.getVpnInterfaceIdentifier(vpnInterface.getInterfaceName()); + InstanceIdentifier path = + vpnIntfId.augmentation(Adjacencies.class); + Optional adjacencies = + VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, path); + + if (adjacencies.isPresent()) { + List adjacencyList = adjacencies.get().getAdjacency(); + Iterator adjacencyIterator = adjacencyList.iterator(); + + while (adjacencyIterator.hasNext()) { + Adjacency adjacency = adjacencyIterator.next(); + try { + if (action == UpdateRouteAction.ADVERTISE_ROUTE) + bgpManager.addPrefix(rd, adjacency.getIpAddress(), + adjacency.getNextHopIp(), + adjacency.getLabel().intValue()); + else if (action == UpdateRouteAction.WITHDRAW_ROUTE) + bgpManager.deletePrefix(rd, adjacency.getIpAddress()); + } catch (Exception e) { + LOG.error("Exception when updating prefix {} in vrf {} to BGP", + adjacency.getIpAddress(), rd); + } } } - } + } + // if (action == UpdateRouteAction.WITHDRAW_ROUTE) { + // fibManager.cleanUpDpnForVpn(dpnId, VpnUtil.getVpnId(broker, vpnInstance.getVpnInstanceName()), rd); + // } } - if (action == UpdateRouteAction.WITHDRAW_ROUTE) { - fibManager.cleanUpDpnForVpn(dpnId, VpnUtil - .getVpnId(broker, vpnInstance.getVpnInstanceName()), rd); - } + } catch (Exception e) { + LOG.error("updatePrefixesForDPN {} in vpn {} failed", dpnId, vpnInstance.getVpnInstanceName(), e); + } + } + } + } + + InstanceIdentifier getRouterDpnId(String routerName, BigInteger dpnId) { + return InstanceIdentifier.builder(NeutronRouterDpns.class) + .child(RouterDpnList.class, new RouterDpnListKey(routerName)) + .child(DpnVpninterfacesList.class, new DpnVpninterfacesListKey(dpnId)).build(); + } + + InstanceIdentifier getRouterId(String routerName) { + return InstanceIdentifier.builder(NeutronRouterDpns.class) + .child(RouterDpnList.class, new RouterDpnListKey(routerName)).build(); + } + + protected void addToNeutronRouterDpnsMap(String routerName, String vpnInterfaceName) { + BigInteger dpId = InterfaceUtils.getDpnForInterface(interfaceManager, vpnInterfaceName); + if(dpId.equals(BigInteger.ZERO)) { + LOG.warn("Could not retrieve dp id for interface {} to handle router {} association model", vpnInterfaceName, routerName); + return; + } + InstanceIdentifier routerDpnListIdentifier = getRouterDpnId(routerName, dpId); + + Optional optionalRouterDpnList = VpnUtil.read(broker, LogicalDatastoreType + .CONFIGURATION, routerDpnListIdentifier); + RouterInterfaces routerInterface = new RouterInterfacesBuilder().setKey(new RouterInterfacesKey(vpnInterfaceName)).setInterface(vpnInterfaceName).build(); + if (optionalRouterDpnList.isPresent()) { + MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, routerDpnListIdentifier.child( + RouterInterfaces.class, new RouterInterfacesKey(vpnInterfaceName)), routerInterface); + } else { + MDSALUtil.syncUpdate(broker, LogicalDatastoreType.CONFIGURATION, + getRouterId(routerName), + new RouterDpnListBuilder().setRouterId(routerName).build()); + //VpnToDpnListBuilder vpnToDpnList = new VpnToDpnListBuilder().setDpnId(dpnId); + DpnVpninterfacesListBuilder dpnVpnList = new DpnVpninterfacesListBuilder().setDpnId(dpId); + List routerInterfaces = new ArrayList<>(); + routerInterfaces.add(routerInterface); + MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, routerDpnListIdentifier, + dpnVpnList.setRouterInterfaces(routerInterfaces).build()); + } + } + + protected void removeFromNeutronRouterDpnsMap(String routerName, String vpnInterfaceName) { + BigInteger dpId = InterfaceUtils.getDpnForInterface(interfaceManager, vpnInterfaceName); + if(dpId.equals(BigInteger.ZERO)) { + LOG.warn("Could not retrieve dp id for interface {} to handle router {} dissociation model", vpnInterfaceName, routerName); + return; + } + InstanceIdentifier routerDpnListIdentifier = getRouterDpnId(routerName, dpId); + Optional optionalRouterDpnList = VpnUtil.read(broker, LogicalDatastoreType + .CONFIGURATION, routerDpnListIdentifier); + if (optionalRouterDpnList.isPresent()) { + List routerInterfaces = optionalRouterDpnList.get().getRouterInterfaces(); + RouterInterfaces routerInterface = new RouterInterfacesBuilder().setKey(new RouterInterfacesKey(vpnInterfaceName)).setInterface(vpnInterfaceName).build(); + + if (routerInterfaces != null && routerInterfaces.remove(routerInterface)) { + if (routerInterfaces.isEmpty()) { + MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, routerDpnListIdentifier); + } else { + MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, routerDpnListIdentifier.child( + RouterInterfaces.class, + new RouterInterfacesKey(vpnInterfaceName))); + } + } + } + } + + protected void removeFromNeutronRouterDpnsMap(String routerName, String vpnInterfaceName,BigInteger dpId) { + if(dpId.equals(BigInteger.ZERO)) { + LOG.warn("Could not retrieve dp id for interface {} to handle router {} dissociation model", vpnInterfaceName, routerName); + return; + } + InstanceIdentifier routerDpnListIdentifier = getRouterDpnId(routerName, dpId); + Optional optionalRouterDpnList = VpnUtil.read(broker, LogicalDatastoreType + .CONFIGURATION, routerDpnListIdentifier); + if (optionalRouterDpnList.isPresent()) { + List routerInterfaces = optionalRouterDpnList.get().getRouterInterfaces(); + RouterInterfaces routerInterface = new RouterInterfacesBuilder().setKey(new RouterInterfacesKey(vpnInterfaceName)).setInterface(vpnInterfaceName).build(); + + if (routerInterfaces != null && routerInterfaces.remove(routerInterface)) { + if (routerInterfaces.isEmpty()) { + MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, routerDpnListIdentifier); + } else { + MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, routerDpnListIdentifier.child( + RouterInterfaces.class, + new RouterInterfacesKey(vpnInterfaceName))); } } }