X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=vpnmanager%2Fvpnmanager-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2FVpnInterfaceManager.java;fp=vpnmanager%2Fvpnmanager-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2FVpnInterfaceManager.java;h=e7e471747f1092c558a265aacc163a2318c294ad;hb=c71d51b15e07c98b18fcebe3a4d3adbb2ccc9f79;hp=66e24e132b8f94b01d231c7fcd268e734f8a904c;hpb=9c5a326cda49fd1ba17380c081e3dce70b9781a8;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 66e24e13..e7e47174 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 @@ -209,7 +209,6 @@ 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, true); - 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); @@ -601,15 +573,10 @@ public class VpnInterfaceManager extends AbstractDataChangeListener