Cleanup ivpnLink unused code + small modifications 81/49881/9
authorMiguel Perez <francisco.miguel.perez@ericsson.com>
Fri, 30 Dec 2016 18:59:06 +0000 (19:59 +0100)
committerVivekanandan Narasimhan <n.vivekanandan@ericsson.com>
Tue, 21 Feb 2017 17:12:25 +0000 (17:12 +0000)
 + This is the 1st change to cleanup/refactor InterVpnLink code

 + 3 new utility methods in InterVpnLinkDataComposite
 + add.getName() replaced by IvpnLinkName in InterVpnLinkListener

Change-Id: Icf7e29d9f77f53cc3d06620f60e8fab7efd464da
Signed-off-by: Miguel Perez <francisco.miguel.perez@ericsson.com>
vpnservice/vpnmanager/vpnmanager-api/src/main/java/org/opendaylight/netvirt/vpnmanager/api/intervpnlink/IVpnLinkService.java [changed mode: 0644->0755]
vpnservice/vpnmanager/vpnmanager-api/src/main/java/org/opendaylight/netvirt/vpnmanager/api/intervpnlink/InterVpnLinkDataComposite.java
vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnInterfaceManager.java
vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnRpcServiceImpl.java
vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/intervpnlink/InterVpnLinkListener.java
vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/intervpnlink/InterVpnLinkNodeAddTask.java
vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/intervpnlink/InterVpnLinkUtil.java

old mode 100644 (file)
new mode 100755 (executable)
index bda312a..1b2449e
@@ -13,7 +13,7 @@ import org.opendaylight.netvirt.fibmanager.api.RouteOrigin;
 public interface IVpnLinkService {
 
     /**
-     * Leaks a route belonging to a L3VPN to other L3VPN if the neccessary
+     * Leaks a route belonging to a L3VPN to other L3VPN if the necessary
      * circumstances are met, like there is an InterVpnLink linking both L3VPNs
      * and the corresponding leaking flag is active (bgp/static/connected).
      *
index 7fa72186843080738d3c307808658d1792514d31..41fc096d35e4bb7f84a63d045139165d80add2c1 100755 (executable)
@@ -134,6 +134,12 @@ public class InterVpnLinkDataComposite {
         return Optional.of(this.interVpnLinkCfg.getFirstEndpoint().getIpAddress().getValue());
     }
 
+    public Optional<Long> getFirstEndpointLportTag() {
+        return ( !isComplete() || this.interVpnLinkState.getFirstEndpointState().getLportTag() == null )
+                   ? Optional.absent()
+                   : Optional.of(this.interVpnLinkState.getFirstEndpointState().getLportTag());
+    }
+
     public List<BigInteger> getFirstEndpointDpns() {
         return (!isComplete() || this.interVpnLinkState.getFirstEndpointState().getDpId() == null)
                    ? Collections.emptyList()
@@ -154,18 +160,18 @@ public class InterVpnLinkDataComposite {
         return Optional.of(this.interVpnLinkCfg.getSecondEndpoint().getIpAddress().getValue());
     }
 
+    public Optional<Long> getSecondEndpointLportTag() {
+        return (!isComplete() || this.interVpnLinkState.getSecondEndpointState().getLportTag() == null )
+            ? Optional.absent()
+            : Optional.of(this.interVpnLinkState.getSecondEndpointState().getLportTag());
+    }
+
     public List<BigInteger> getSecondEndpointDpns() {
         return (!isComplete() || this.interVpnLinkState.getSecondEndpointState().getDpId() == null)
                     ? Collections.emptyList()
                     : this.interVpnLinkState.getSecondEndpointState().getDpId();
     }
 
-    public String getOtherVpnName(String thisVpnName) {
-        Optional<String> optOtherVpnName = isFirstEndpointVpnName(thisVpnName) ? getSecondEndpointVpnUuid()
-                                                                               : getFirstEndpointVpnUuid();
-        return optOtherVpnName.orNull();
-    }
-
     public Optional<Long> getEndpointLportTagByIpAddr(String endpointIp) {
         if (!isComplete()) {
             return Optional.absent();
@@ -185,6 +191,17 @@ public class InterVpnLinkDataComposite {
                                                : Optional.of(interVpnLinkState.getFirstEndpointState().getLportTag());
     }
 
+    public String getOtherVpnName(String vpnName) {
+        if ( !isFirstEndpointVpnName(vpnName) && !isSecondEndpointVpnName(vpnName)) {
+            LOG.debug("VPN {} does not participate in InterVpnLink {}", vpnName, getInterVpnLinkName());
+            return null;
+        }
+
+        Optional<String> optOtherVpnName = isFirstEndpointVpnName(vpnName) ? getSecondEndpointVpnUuid()
+                                                                           : getFirstEndpointVpnUuid();
+        return optOtherVpnName.orNull();
+    }
+
     public String getOtherEndpoint(String vpnUuid) {
         if (!isFirstEndpointVpnName(vpnUuid) && !isSecondEndpointVpnName(vpnUuid)) {
             LOG.debug("VPN {} does not participate in InterVpnLink {}", vpnUuid, getInterVpnLinkName());
index c7005c8a872c96ae2713b2c6b048fc31cbcc7f74..a45442b0974db4715ce8c66ce7854e1ad196e20a 100755 (executable)
@@ -48,6 +48,8 @@ import org.opendaylight.netvirt.bgpmanager.api.IBgpManager;
 import org.opendaylight.netvirt.fibmanager.api.IFibManager;
 import org.opendaylight.netvirt.fibmanager.api.RouteOrigin;
 import org.opendaylight.netvirt.vpnmanager.api.IVpnManager;
+import org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkCache;
+import org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite;
 import org.opendaylight.netvirt.vpnmanager.arp.responder.ArpResponderUtil;
 import org.opendaylight.netvirt.vpnmanager.intervpnlink.InterVpnLinkUtil;
 import org.opendaylight.netvirt.vpnmanager.populator.input.L3vpnInput;
@@ -103,7 +105,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpntargets.VpnTarget;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
 import org.opendaylight.yangtools.yang.common.RpcError;
@@ -1713,30 +1714,27 @@ public class VpnInterfaceManager extends AsyncDataTreeChangeListenerBase<VpnInte
         // TODO: This is a limitation to be stated in docs. When configuring static route to go to
         // another VPN, there can only be one nexthop or, at least, the nexthop to the interVpnLink should be in
         // first place.
-        Optional<InterVpnLink> optInterVpnLink = InterVpnLinkUtil.getInterVpnLinkByEndpointIp(dataBroker, nextHop);
-        if (optInterVpnLink.isPresent()) {
-            InterVpnLink interVpnLink = optInterVpnLink.get();
+        Optional<InterVpnLinkDataComposite> optVpnLink = InterVpnLinkCache.getInterVpnLinkByEndpoint(nextHop);
+        if ( optVpnLink.isPresent() && optVpnLink.get().isActive()) {
+            InterVpnLinkDataComposite interVpnLink = optVpnLink.get();
             // If the nexthop is the endpoint of Vpn2, then prefix must be advertised to Vpn1 in DC-GW, with nexthops
             // pointing to the DPNs where Vpn1 is instantiated. LFIB in these DPNS must have a flow entry, with lower
             // priority, where if Label matches then sets the lportTag of the Vpn2 endpoint and goes to LportDispatcher
             // This is like leaking one of the Vpn2 routes towards Vpn1
-            boolean nexthopIsVpn2 = interVpnLink.getSecondEndpoint().getIpAddress().getValue().equals(nextHop);
-            String srcVpnUuid = nexthopIsVpn2 ? interVpnLink.getSecondEndpoint().getVpnUuid().getValue()
-                : interVpnLink.getFirstEndpoint().getVpnUuid().getValue();
-            String dstVpnUuid = nexthopIsVpn2 ? interVpnLink.getFirstEndpoint().getVpnUuid().getValue()
-                : interVpnLink.getSecondEndpoint().getVpnUuid().getValue();
+            boolean nexthopIsVpn2 = interVpnLink.getSecondEndpointVpnUuid().get().equals(nextHop);
+            String srcVpnUuid = nexthopIsVpn2 ? interVpnLink.getSecondEndpointVpnUuid().get()
+                                              : interVpnLink.getFirstEndpointVpnUuid().get();
+            String dstVpnUuid = interVpnLink.getOtherVpnName(srcVpnUuid);
             String dstVpnRd = VpnUtil.getVpnRd(dataBroker, dstVpnUuid);
             long newLabel = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME,
-                VpnUtil.getNextHopLabelKey(dstVpnRd, destination));
+                                                VpnUtil.getNextHopLabelKey(dstVpnRd, destination));
             if (newLabel == 0) {
-                LOG.error(
-                    "Unable to fetch label from Id Manager. Bailing out of adding intervpnlink route for destination "
-                        + "{}",
-                    destination);
+                LOG.error("Unable to fetch label from Id Manager. Bailing out of adding intervpnlink route "
+                          + "for destination {}", destination);
                 return;
             }
-            InterVpnLinkUtil.leakRoute(dataBroker, bgpManager, interVpnLink, srcVpnUuid, dstVpnUuid, destination,
-                newLabel);
+            InterVpnLinkUtil.leakRoute(dataBroker, bgpManager, interVpnLink.getInterVpnLinkConfig(),
+                                       srcVpnUuid, dstVpnUuid, destination, newLabel);
         } else {
             if (rd != null) {
                 addPrefixToBGP(rd, VpnUtil.getPrimaryRd(dataBroker, vpnName), destination, nextHopIpList,
index 6137f42360aee7871e38ae75edb06bae8393c215..c7aad16bd4bd58d70e6c55b2e8d5d49c27be1266 100644 (file)
@@ -29,7 +29,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.G
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveStaticRouteInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveVpnLabelInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.VpnRpcService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -222,9 +221,9 @@ public class VpnRpcServiceImpl implements VpnRpcService {
             return result;
         }
 
-        Optional<InterVpnLink> optVpnLink = InterVpnLinkUtil.getInterVpnLinkByEndpointIp(dataBroker, nexthop);
-        if (optVpnLink.isPresent()) {
-            fibManager.removeOrUpdateFibEntry(dataBroker, vpnRd, destination, nexthop, null);
+        Optional<InterVpnLinkDataComposite> optVpnLink = InterVpnLinkCache.getInterVpnLinkByEndpoint(nexthop);
+        if ( optVpnLink.isPresent() ) {
+            fibManager.removeOrUpdateFibEntry(dataBroker,  vpnRd, destination, nexthop, null);
             bgpManager.withdrawPrefix(vpnRd, destination);
         } else {
             vpnInterfaceMgr.delExtraRoute(destination, nexthop, vpnRd, null /*routerId*/, null /*intfName*/, null);
index 2c15fed6d5ae58413aedc656390e4f689ddae52a..00fe4fcc8264be1014c7b895199af1dbbdae3a10 100755 (executable)
@@ -130,14 +130,14 @@ public class InterVpnLinkListener extends AsyncDataTreeChangeListenerBase<InterV
     @Override
     protected void add(InstanceIdentifier<InterVpnLink> identifier, InterVpnLink add) {
 
-
+        String ivpnLinkName = add.getName();
         LOG.debug("Reacting to IVpnLink {} creation. Vpn1=[name={}  EndpointIp={}]  Vpn2=[name={} endpointIP={}]",
-                  add.getName(), add.getFirstEndpoint().getVpnUuid(), add.getFirstEndpoint().getIpAddress(),
+                  ivpnLinkName, add.getFirstEndpoint().getVpnUuid(), add.getFirstEndpoint().getIpAddress(),
                   add.getSecondEndpoint().getVpnUuid(), add.getSecondEndpoint().getIpAddress());
 
         // Create VpnLink state
-        InstanceIdentifier<InterVpnLinkState> vpnLinkStateIid = InterVpnLinkUtil.getInterVpnLinkStateIid(add.getName());
-        InterVpnLinkState vpnLinkState = new InterVpnLinkStateBuilder().setInterVpnLinkName(add.getName()).build();
+        InstanceIdentifier<InterVpnLinkState> vpnLinkStateIid = InterVpnLinkUtil.getInterVpnLinkStateIid(ivpnLinkName);
+        InterVpnLinkState vpnLinkState = new InterVpnLinkStateBuilder().setInterVpnLinkName(ivpnLinkName).build();
         MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnLinkStateIid, vpnLinkState);
 
         InterVpnLinkKey key = add.getKey();
@@ -147,28 +147,28 @@ public class InterVpnLinkListener extends AsyncDataTreeChangeListenerBase<InterV
         String vpn2Name = vpn2Uuid.getValue();
         // First VPN
         if (VpnUtil.getVpnInstance(this.dataBroker, vpn1Name) == null) {
-            String errMsg = "InterVpnLink " + add.getName() + " creation error: could not find 1st endpoint Vpn "
-                + vpn1Name;
+            String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: could not find 1st endpoint Vpn "
+                            + vpn1Name;
             setInError(vpnLinkStateIid, vpnLinkState, errMsg);
             return;
         }
         if (!checkVpnAvailability(key, vpn1Uuid)) {
-            String errMsg = "InterVpnLink " + add.getName() + " creation error: Vpn " + vpn1Name
-                + " is already associated to an inter-vpn-link ";
+            String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Vpn " + vpn1Name
+                            + " is already associated to an inter-vpn-link ";
             setInError(vpnLinkStateIid, vpnLinkState, errMsg);
             return;
         }
 
         // Second VPN
         if (VpnUtil.getVpnInstance(this.dataBroker, vpn2Name) == null) {
-            String errMsg = "InterVpnLink " + add.getName() + " creation error: could not find 2nd endpoint Vpn "
-                + vpn2Name;
+            String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: could not find 2nd endpoint Vpn "
+                             + vpn2Name;
             setInError(vpnLinkStateIid, vpnLinkState, errMsg);
             return;
         }
         if (!checkVpnAvailability(key, vpn2Uuid)) {
-            String errMsg = "InterVpnLink " + add.getName() + " creation error: Vpn " + vpn2Name
-                + " is already associated with an inter-vpn-link";
+            String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Vpn " + vpn2Name
+                            + " is already associated with an inter-vpn-link";
             setInError(vpnLinkStateIid, vpnLinkState, errMsg);
             return;
         }
@@ -183,9 +183,8 @@ public class InterVpnLinkListener extends AsyncDataTreeChangeListenerBase<InterV
                                                     VpnConstants.PER_VPN_INSTANCE_MAX_WAIT_TIME_IN_MILLISECONDS);
             if (!vpn1Ready) {
                 String errMsg =
-                    "InterVpnLink " + add.getName() + " creation error: Operational Data for VPN " + vpn1Name
-                        + " not ready after " + VpnConstants.PER_INTERFACE_MAX_WAIT_TIME_IN_MILLISECONDS
-                        + " milliseconds";
+                    "InterVpnLink " + ivpnLinkName + " creation error: Operational Data for VPN " + vpn1Name
+                    + " not ready after " + VpnConstants.PER_INTERFACE_MAX_WAIT_TIME_IN_MILLISECONDS + " milliseconds";
                 setInError(vpnLinkStateIid, vpnLinkState, errMsg);
                 return;
             }
@@ -197,9 +196,8 @@ public class InterVpnLinkListener extends AsyncDataTreeChangeListenerBase<InterV
                                                     VpnConstants.PER_VPN_INSTANCE_MAX_WAIT_TIME_IN_MILLISECONDS);
             if (!vpn1Ready) {
                 String errMsg =
-                    "InterVpnLink " + add.getName() + " creation error: Operational Data for VPN " + vpn2Name
-                        + " not ready after " + VpnConstants.PER_INTERFACE_MAX_WAIT_TIME_IN_MILLISECONDS
-                        + " milliseconds";
+                    "InterVpnLink " + ivpnLinkName + " creation error: Operational Data for VPN " + vpn2Name
+                    + " not ready after " + VpnConstants.PER_INTERFACE_MAX_WAIT_TIME_IN_MILLISECONDS + " milliseconds";
                 setInError(vpnLinkStateIid, vpnLinkState, errMsg);
                 return;
             }
@@ -218,14 +216,14 @@ public class InterVpnLinkListener extends AsyncDataTreeChangeListenerBase<InterV
                 new SecondEndpointStateBuilder().setVpnUuid(vpn2Uuid).setDpId(secondDpnList)
                     .setLportTag(secondVpnLportTag).build();
 
-            InterVpnLinkUtil.updateInterVpnLinkState(dataBroker, add.getName(), InterVpnLinkState.State.Active,
-                firstEndPointState, secondEndPointState);
+            InterVpnLinkUtil.updateInterVpnLinkState(dataBroker, ivpnLinkName, InterVpnLinkState.State.Active,
+                                                     firstEndPointState, secondEndPointState);
 
             // Note that in the DPN of the firstEndpoint we install the lportTag of the secondEndpoint and viceversa
-            InterVpnLinkUtil.installLPortDispatcherTableFlow(dataBroker, mdsalManager, add, firstDpnList,
-                vpn2Uuid, secondVpnLportTag);
-            InterVpnLinkUtil.installLPortDispatcherTableFlow(dataBroker, mdsalManager, add, secondDpnList,
-                vpn1Uuid, firstVpnLportTag);
+            InterVpnLinkUtil.installLPortDispatcherTableFlow(dataBroker, mdsalManager, ivpnLinkName, firstDpnList,
+                                                             vpn2Name, secondVpnLportTag);
+            InterVpnLinkUtil.installLPortDispatcherTableFlow(dataBroker, mdsalManager, ivpnLinkName, secondDpnList,
+                                                             vpn1Name, firstVpnLportTag);
             // Update the VPN -> DPNs Map.
             // Note: when a set of DPNs is calculated for Vpn1, these DPNs are added to the VpnToDpn map of Vpn2. Why?
             // because we do the handover from Vpn1 to Vpn2 in those DPNs, so in those DPNs we must know how to reach
@@ -251,8 +249,8 @@ public class InterVpnLinkListener extends AsyncDataTreeChangeListenerBase<InterV
             SecondEndpointState secondEndPointState =
                 new SecondEndpointStateBuilder().setVpnUuid(vpn2Uuid).setLportTag(secondVpnLportTag)
                                                 .setDpId(Collections.emptyList()).build();
-            InterVpnLinkUtil.updateInterVpnLinkState(dataBroker, add.getName(), InterVpnLinkState.State.Error,
-                firstEndPointState, secondEndPointState);
+            InterVpnLinkUtil.updateInterVpnLinkState(dataBroker, ivpnLinkName, InterVpnLinkState.State.Error,
+                                                     firstEndPointState, secondEndPointState);
         }
     }
 
index b013644110b8d2895b74a69908278dbfa7cca0b9..6ae794e08da77edd17dbcb771a92550d5f9afd31 100755 (executable)
@@ -21,14 +21,16 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.netvirt.vpnmanager.VpnFootprintService;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkCache;
+import org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkStateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.FirstEndpointState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.FirstEndpointStateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.SecondEndpointState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.SecondEndpointStateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A task that, when a Node comes UP, checks if there are any InterVpnLink that
@@ -37,6 +39,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.
  * created.
  */
 public class InterVpnLinkNodeAddTask implements Callable<List<ListenableFuture<Void>>> {
+    private static final Logger LOG = LoggerFactory.getLogger(InterVpnLinkNodeAddTask.class);
     private static final String NBR_OF_DPNS_PROPERTY_NAME = "vpnservice.intervpnlink.number.dpns";
 
     private final DataBroker broker;
@@ -115,27 +118,44 @@ public class InterVpnLinkNodeAddTask implements Callable<List<ListenableFuture<V
     }
 
     private void installLPortDispatcherTable(InterVpnLinkState interVpnLinkState, List<BigInteger> firstDpnList,
-        List<BigInteger> secondDpnList) {
-        Optional<InterVpnLink> vpnLink =
-            InterVpnLinkUtil.getInterVpnLinkByName(broker, interVpnLinkState.getKey().getInterVpnLinkName());
-        if (vpnLink.isPresent()) {
-            Uuid firstEndpointVpnUuid = vpnLink.get().getFirstEndpoint().getVpnUuid();
-            Uuid secondEndpointVpnUuid = vpnLink.get().getSecondEndpoint().getVpnUuid();
-            // Note that in the DPN of the firstEndpoint we install the lportTag of the secondEndpoint and viceversa
-            InterVpnLinkUtil.installLPortDispatcherTableFlow(broker, mdsalManager, vpnLink.get(), firstDpnList,
-                secondEndpointVpnUuid,
-                interVpnLinkState.getSecondEndpointState().getLportTag());
-            InterVpnLinkUtil.installLPortDispatcherTableFlow(broker, mdsalManager, vpnLink.get(), secondDpnList,
-                firstEndpointVpnUuid,
-                interVpnLinkState.getFirstEndpointState().getLportTag());
-            // Update the VPN -> DPNs Map.
-            // Note: when a set of DPNs is calculated for Vpn1, these DPNs are added to the VpnToDpn map of Vpn2. Why?
-            // because we do the handover from Vpn1 to Vpn2 in those DPNs, so in those DPNs we must know how to reach
-            // to Vpn2 targets. If new Vpn2 targets are added later, the Fib will be maintained in these DPNs even if
-            // Vpn2 is not physically present there.
-            InterVpnLinkUtil.updateVpnFootprint(vpnFootprintService, secondEndpointVpnUuid.getValue(), firstDpnList);
-            InterVpnLinkUtil.updateVpnFootprint(vpnFootprintService, firstEndpointVpnUuid.getValue(), secondDpnList);
+                                             List<BigInteger> secondDpnList) {
+        String ivpnLinkName = interVpnLinkState.getKey().getInterVpnLinkName();
+        Optional<InterVpnLinkDataComposite> optVpnLink = InterVpnLinkCache.getInterVpnLinkByName(ivpnLinkName);
+        if (!optVpnLink.isPresent()) {
+            LOG.warn("installLPortDispatcherTable: Could not find interVpnLink {}", ivpnLinkName);
+            return;
         }
+
+        InterVpnLinkDataComposite vpnLink = optVpnLink.get();
+        Optional<Long> opt1stEndpointLportTag = vpnLink.getFirstEndpointLportTag();
+        if (!opt1stEndpointLportTag.isPresent()) {
+            LOG.warn("installLPortDispatcherTable: Could not find LPortTag for 1stEnpoint in InterVpnLink {}",
+                     ivpnLinkName);
+            return;
+        }
+
+        Optional<Long> opt2ndEndpointLportTag = vpnLink.getSecondEndpointLportTag();
+        if (!opt2ndEndpointLportTag.isPresent()) {
+            LOG.warn("installLPortDispatcherTable: Could not find LPortTag for 2ndEnpoint in InterVpnLink {}",
+                     ivpnLinkName);
+            return;
+        }
+
+        String firstEndpointVpnUuid = vpnLink.getFirstEndpointVpnUuid().get();
+        String secondEndpointVpnUuid = vpnLink.getSecondEndpointVpnUuid().get();
+        // Note that in the DPN of the firstEndpoint we install the lportTag of the secondEndpoint and viceversa
+
+        InterVpnLinkUtil.installLPortDispatcherTableFlow(broker, mdsalManager, ivpnLinkName, firstDpnList,
+                                                         secondEndpointVpnUuid, opt2ndEndpointLportTag.get());
+        InterVpnLinkUtil.installLPortDispatcherTableFlow(broker, mdsalManager, ivpnLinkName, secondDpnList,
+                                                         firstEndpointVpnUuid, opt1stEndpointLportTag.get());
+        // Update the VPN -> DPNs Map.
+        // Note: when a set of DPNs is calculated for Vpn1, these DPNs are added to the VpnToDpn map of Vpn2. Why?
+        // because we do the handover from Vpn1 to Vpn2 in those DPNs, so in those DPNs we must know how to reach
+        // to Vpn2 targets. If new Vpn2 targets are added later, the Fib will be maintained in these DPNs even if
+        // Vpn2 is not physically present there.
+        InterVpnLinkUtil.updateVpnFootprint(vpnFootprintService, secondEndpointVpnUuid, firstDpnList);
+        InterVpnLinkUtil.updateVpnFootprint(vpnFootprintService, firstEndpointVpnUuid, secondDpnList);
     }
 
 }
index 37dd36ca83791992b7ee090520426bc1f99521ab..f143ebd045fbf0fa27ae865cf783898ec60685c6 100755 (executable)
@@ -33,7 +33,6 @@ import org.opendaylight.netvirt.vpnmanager.VpnUtil;
 import org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkCache;
 import org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite;
 import org.opendaylight.netvirt.vpnmanager.utilities.InterfaceUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries;
@@ -160,9 +159,9 @@ public class InterVpnLinkUtil {
         if (optOldVpnLinkState.isPresent()) {
             InterVpnLinkState newVpnLinkState =
                 new InterVpnLinkStateBuilder(optOldVpnLinkState.get()).setState(state)
-                    .setFirstEndpointState(newFirstEndpointState)
-                    .setSecondEndpointState(newSecondEndpointState)
-                    .build();
+                            .setFirstEndpointState(newFirstEndpointState)
+                            .setSecondEndpointState(newSecondEndpointState)
+                            .build();
             VpnUtil.syncUpdate(broker, LogicalDatastoreType.CONFIGURATION,
                 InterVpnLinkUtil.getInterVpnLinkStateIid(vpnLinkName), newVpnLinkState);
             InterVpnLinkCache.addInterVpnLinkStateToCaches(newVpnLinkState);
@@ -187,21 +186,24 @@ public class InterVpnLinkUtil {
      *
      * @param broker dataBroker service reference
      * @param mdsalManager MDSAL API accessor
-     * @param interVpnLink Object that holds the needed information about both endpoints of the InterVpnLink.
+     * @param interVpnLinkName Name of the InterVpnLink.
      * @param dpnList The list of DPNs where this flow must be installed
      * @param vpnUuidOtherEndpoint UUID of the other endpoint of the InterVpnLink
      * @param lportTagOfOtherEndpoint Dataplane identifier of the other endpoint of the InterVpnLink
      * @return the list of Futures for each and every flow that has been installed
      */
     public static List<ListenableFuture<Void>> installLPortDispatcherTableFlow(DataBroker broker,
-        IMdsalApiManager mdsalManager, InterVpnLink interVpnLink, List<BigInteger> dpnList, Uuid vpnUuidOtherEndpoint,
-        Long lportTagOfOtherEndpoint) {
+                                                                               IMdsalApiManager mdsalManager,
+                                                                               String interVpnLinkName,
+                                                                               List<BigInteger> dpnList,
+                                                                               String vpnUuidOtherEndpoint,
+                                                                               Long lportTagOfOtherEndpoint) {
         List<ListenableFuture<Void>> result = new ArrayList<>();
-        long vpnId = VpnUtil.getVpnId(broker, vpnUuidOtherEndpoint.getValue());
-        for (BigInteger dpnId : dpnList) {
+        long vpnId = VpnUtil.getVpnId(broker, vpnUuidOtherEndpoint);
+        for ( BigInteger dpnId : dpnList ) {
             // insert into LPortDispatcher table
-            Flow lportDispatcherFlow = buildLPortDispatcherFlow(interVpnLink.getName(), vpnId,
-                lportTagOfOtherEndpoint.intValue());
+            Flow lportDispatcherFlow = buildLPortDispatcherFlow(interVpnLinkName, vpnId,
+                                                                lportTagOfOtherEndpoint.intValue());
             result.add(mdsalManager.installFlow(dpnId, lportDispatcherFlow));
         }
 
@@ -529,8 +531,5 @@ public class InterVpnLinkUtil {
             vpnRd, destination, label, nexthopList);
         bgpManager.advertisePrefix(vpnRd, null /*macAddress*/, destination, nexthopList,
                 VrfEntry.EncapType.Mplsgre, label, 0 /*l3vni*/, null /*gatewayMacAddress*/);
-
-        // TODO: Leak if static-routes-leaking flag is active
-
     }
 }