MRI version bumpup for Aluminium
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / utils / ElanItmUtils.java
index 791f3209a07c2f8da8075de9a918c3d1e5fb8bbb..0334efcf7ee0a4abad9c72a8ab7c11ab3cac41f1 100644 (file)
@@ -7,15 +7,16 @@
  */
 package org.opendaylight.netvirt.elan.utils;
 
-import java.math.BigInteger;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
+import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
@@ -40,6 +41,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.G
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.Uint64;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -75,7 +77,7 @@ public class ElanItmUtils {
      *            Vni to be stamped on the VxLAN Header.
      * @return the external itm egress action
      */
-    public List<Action> getExternalTunnelItmEgressAction(BigInteger srcDpnId, NodeId torNode, long vni) {
+    public List<Action> getExternalTunnelItmEgressAction(Uint64 srcDpnId, NodeId torNode, long vni) {
         List<Action> result = Collections.emptyList();
 
         GetExternalTunnelInterfaceNameInput input = new GetExternalTunnelInterfaceNameInputBuilder()
@@ -89,17 +91,17 @@ public class ElanItmUtils {
                 String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
                 LOG.debug("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
 
-                result = buildTunnelItmEgressActions(tunnelIfaceName, vni);
+                result = buildTunnelItmEgressActions(tunnelIfaceName, vni, false);
             }
 
         } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Error in RPC call getTunnelInterfaceName {}", e);
+            LOG.error("Error in RPC call getTunnelInterfaceName", e);
         }
 
         return result;
     }
 
-    public List<Action> getExternalTunnelItmEgressAction(BigInteger srcDpnId, String nexthopIP, long vni) {
+    public List<Action> getExternalTunnelItmEgressAction(Uint64 srcDpnId, String nexthopIP, long vni) {
         List<Action> result = Collections.emptyList();
 
         GetExternalTunnelInterfaceNameInput input = new GetExternalTunnelInterfaceNameInputBuilder()
@@ -113,11 +115,11 @@ public class ElanItmUtils {
                 String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
                 LOG.debug("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
 
-                result = buildTunnelItmEgressActions(tunnelIfaceName, vni);
+                result = buildTunnelItmEgressActions(tunnelIfaceName, vni, false);
             }
 
         } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Error in RPC call getTunnelInterfaceName {}", e);
+            LOG.error("Error in RPC call getTunnelInterfaceName", e);
         }
 
         return result;
@@ -137,7 +139,7 @@ public class ElanItmUtils {
      *            Tunnel key to be sent on the VxLAN header.
      * @return the internal itm egress action
      */
-    public List<Action> getInternalTunnelItmEgressAction(BigInteger sourceDpnId, BigInteger destinationDpnId, long
+    public List<Action> getInternalTunnelItmEgressAction(Uint64 sourceDpnId, Uint64 destinationDpnId, long
             tunnelKey) {
         List<Action> result = Collections.emptyList();
         LOG.trace("In getInternalItmEgressAction Action source {}, destination {}, serviceTag/Vni {}", sourceDpnId,
@@ -151,13 +153,13 @@ public class ElanItmUtils {
                 GetTunnelInterfaceNameOutput tunnelInterfaceNameOutput = output.get().getResult();
                 String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
                 LOG.info("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
-                result = buildTunnelItmEgressActions(tunnelIfaceName, tunnelKey);
+                result = buildTunnelItmEgressActions(tunnelIfaceName, tunnelKey, true);
             } else {
                 LOG.trace("Tunnel interface doesn't exist between srcDpId {} dstDpId {}", sourceDpnId,
                         destinationDpnId);
             }
         } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Error in RPC call getTunnelInterfaceName {}", e);
+            LOG.error("Error in RPC call getTunnelInterfaceName", e);
         }
         return result;
     }
@@ -172,11 +174,10 @@ public class ElanItmUtils {
      *            the tunnel key
      * @return the list
      */
-    public List<Action> buildTunnelItmEgressActions(String tunnelIfaceName, Long tunnelKey) {
+    public List<Action> buildTunnelItmEgressActions(String tunnelIfaceName, Long tunnelKey, boolean ineternal) {
         if (tunnelIfaceName != null && !tunnelIfaceName.isEmpty()) {
-            return buildItmEgressActions(tunnelIfaceName, tunnelKey);
+            return buildItmEgressActions(tunnelIfaceName, tunnelKey, ineternal);
         }
-
         return Collections.emptyList();
     }
 
@@ -189,7 +190,7 @@ public class ElanItmUtils {
      * @return the external port itm egress actions
      */
     public List<Action> getExternalPortItmEgressAction(String interfaceName) {
-        return buildItmEgressActions(interfaceName, null);
+        return buildItmEgressActions(interfaceName, null, false);
     }
 
     /**
@@ -204,26 +205,27 @@ public class ElanItmUtils {
      * @return the list
      */
     @SuppressWarnings("checkstyle:IllegalCatch")
-    public List<Action> buildItmEgressActions(String interfaceName, Long tunnelKey) {
+    public List<Action> buildItmEgressActions(String interfaceName, @Nullable Long tunnelKey, boolean internal) {
         try {
-            GetEgressActionsForInterfaceInput getEgressActInput = new GetEgressActionsForInterfaceInputBuilder()
-                    .setIntfName(interfaceName).setTunnelKey(tunnelKey).build();
-
-            Future<RpcResult<GetEgressActionsForInterfaceOutput>> egressActionsOutputFuture = interfaceManagerRpcService
-                    .getEgressActionsForInterface(getEgressActInput);
-
-            GetEgressActionsForTunnelInput getEgressActInputItm = new GetEgressActionsForTunnelInputBuilder()
-                    .setIntfName(interfaceName).setTunnelKey(tunnelKey).build();
-
-            Future<RpcResult<GetEgressActionsForTunnelOutput>> egressActionsOutputItm =
-                    itmRpcService.getEgressActionsForTunnel(getEgressActInputItm);
-            if (egressActionsOutputFuture.get().isSuccessful() && !interfaceManager.isItmDirectTunnelsEnabled()) {
-                return egressActionsOutputFuture.get().getResult().getAction();
-            } else if (egressActionsOutputItm.get().isSuccessful() && interfaceManager.isItmDirectTunnelsEnabled()) {
-                return egressActionsOutputItm.get().getResult().getAction();
+            if (internal && interfaceManager.isItmDirectTunnelsEnabled()) {
+                GetEgressActionsForTunnelInput getEgressActInputItm = new GetEgressActionsForTunnelInputBuilder()
+                        .setIntfName(interfaceName).setTunnelKey(tunnelKey).build();
+                Future<RpcResult<GetEgressActionsForTunnelOutput>> egressActionsOutputItm =
+                        itmRpcService.getEgressActionsForTunnel(getEgressActInputItm);
+                if (egressActionsOutputItm.get().isSuccessful()) {
+                    return new ArrayList<Action>(egressActionsOutputItm.get().getResult().getAction().values());
+                }
+            } else {
+                GetEgressActionsForInterfaceInput getEgressActInput = new GetEgressActionsForInterfaceInputBuilder()
+                        .setIntfName(interfaceName).setTunnelKey(tunnelKey).build();
+                Future<RpcResult<GetEgressActionsForInterfaceOutput>> egressActionsOutputFuture =
+                        interfaceManagerRpcService.getEgressActionsForInterface(getEgressActInput);
+                if (egressActionsOutputFuture.get().isSuccessful()) {
+                    return new ArrayList<Action>(egressActionsOutputFuture.get().getResult().getAction().values());
+                }
             }
         } catch (Exception e) {
-            LOG.error("Error in RPC call getEgressActionsForInterface {}", e);
+            LOG.error("Error in RPC call getEgressActionsForInterface", e);
         }
         LOG.warn("Could not build Egress actions for interface {} and tunnelId {}", interfaceName, tunnelKey);
         return Collections.emptyList();
@@ -238,16 +240,16 @@ public class ElanItmUtils {
      *            the dst hw vtep node id
      * @return the dpn tep ip
      */
-    public IpAddress getSourceDpnTepIp(BigInteger srcDpnId,
+    public IpAddress getSourceDpnTepIp(Uint64 srcDpnId,
             org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId dstHwVtepNodeId) {
         IpAddress dpnTepIp = null;
-        String tunnelInterfaceName = getExternalTunnelInterfaceName(String.valueOf(srcDpnId),
+        String tunnelInterfaceName = getExternalTunnelInterfaceName(srcDpnId.toString(),
                 dstHwVtepNodeId.getValue());
         if (tunnelInterfaceName != null) {
             Interface tunnelInterface =
                     ElanL2GatewayUtils.getInterfaceFromConfigDS(new InterfaceKey(tunnelInterfaceName), broker);
             if (tunnelInterface != null) {
-                dpnTepIp = tunnelInterface.getAugmentation(IfTunnel.class).getTunnelSource();
+                dpnTepIp = tunnelInterface.augmentation(IfTunnel.class).getTunnelSource();
             } else {
                 LOG.warn("Tunnel interface not found for tunnelInterfaceName {}", tunnelInterfaceName);
             }