X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=elanmanager%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetvirt%2Felan%2Futils%2FElanItmUtils.java;h=0334efcf7ee0a4abad9c72a8ab7c11ab3cac41f1;hb=cf1ea9172b94fc17e45391b62bf4ca24ac5c5fe0;hp=f4aeb825860b124bc155227f28f69b8679c44f18;hpb=cf8a16020e2beb992e12e84387d2060a0d17c81f;p=netvirt.git diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanItmUtils.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanItmUtils.java index f4aeb82586..0334efcf7e 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanItmUtils.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanItmUtils.java @@ -7,14 +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; @@ -27,6 +29,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpc import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEgressActionsForInterfaceInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEgressActionsForInterfaceOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetEgressActionsForTunnelInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetEgressActionsForTunnelInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetEgressActionsForTunnelOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetExternalTunnelInterfaceNameInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetExternalTunnelInterfaceNameInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetExternalTunnelInterfaceNameOutput; @@ -36,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; @@ -46,13 +52,15 @@ public class ElanItmUtils { private final DataBroker broker; private final ItmRpcService itmRpcService; private final OdlInterfaceRpcService interfaceManagerRpcService; + private final IInterfaceManager interfaceManager; @Inject - public ElanItmUtils(DataBroker broker, ItmRpcService itmRpcService, - OdlInterfaceRpcService interfaceManagerRpcService) { + public ElanItmUtils(final DataBroker broker, final ItmRpcService itmRpcService, + final OdlInterfaceRpcService interfaceManagerRpcService, final IInterfaceManager interfaceManager) { this.broker = broker; this.itmRpcService = itmRpcService; this.interfaceManagerRpcService = interfaceManagerRpcService; + this.interfaceManager = interfaceManager; } /** @@ -69,7 +77,7 @@ public class ElanItmUtils { * Vni to be stamped on the VxLAN Header. * @return the external itm egress action */ - public List getExternalTunnelItmEgressAction(BigInteger srcDpnId, NodeId torNode, long vni) { + public List getExternalTunnelItmEgressAction(Uint64 srcDpnId, NodeId torNode, long vni) { List result = Collections.emptyList(); GetExternalTunnelInterfaceNameInput input = new GetExternalTunnelInterfaceNameInputBuilder() @@ -83,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 getExternalTunnelItmEgressAction(BigInteger srcDpnId, String nexthopIP, long vni) { + public List getExternalTunnelItmEgressAction(Uint64 srcDpnId, String nexthopIP, long vni) { List result = Collections.emptyList(); GetExternalTunnelInterfaceNameInput input = new GetExternalTunnelInterfaceNameInputBuilder() @@ -107,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; @@ -131,7 +139,7 @@ public class ElanItmUtils { * Tunnel key to be sent on the VxLAN header. * @return the internal itm egress action */ - public List getInternalTunnelItmEgressAction(BigInteger sourceDpnId, BigInteger destinationDpnId, long + public List getInternalTunnelItmEgressAction(Uint64 sourceDpnId, Uint64 destinationDpnId, long tunnelKey) { List result = Collections.emptyList(); LOG.trace("In getInternalItmEgressAction Action source {}, destination {}, serviceTag/Vni {}", sourceDpnId, @@ -145,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; } @@ -166,11 +174,10 @@ public class ElanItmUtils { * the tunnel key * @return the list */ - public List buildTunnelItmEgressActions(String tunnelIfaceName, Long tunnelKey) { + public List buildTunnelItmEgressActions(String tunnelIfaceName, Long tunnelKey, boolean ineternal) { if (tunnelIfaceName != null && !tunnelIfaceName.isEmpty()) { - return buildItmEgressActions(tunnelIfaceName, tunnelKey); + return buildItmEgressActions(tunnelIfaceName, tunnelKey, ineternal); } - return Collections.emptyList(); } @@ -183,7 +190,7 @@ public class ElanItmUtils { * @return the external port itm egress actions */ public List getExternalPortItmEgressAction(String interfaceName) { - return buildItmEgressActions(interfaceName, null); + return buildItmEgressActions(interfaceName, null, false); } /** @@ -198,26 +205,30 @@ public class ElanItmUtils { * @return the list */ @SuppressWarnings("checkstyle:IllegalCatch") - public List buildItmEgressActions(String interfaceName, Long tunnelKey) { - List result = Collections.emptyList(); + public List buildItmEgressActions(String interfaceName, @Nullable Long tunnelKey, boolean internal) { try { - GetEgressActionsForInterfaceInput getEgressActInput = new GetEgressActionsForInterfaceInputBuilder() - .setIntfName(interfaceName).setTunnelKey(tunnelKey).build(); - - Future> egressActionsOutputFuture = interfaceManagerRpcService - .getEgressActionsForInterface(getEgressActInput); - if (egressActionsOutputFuture.get().isSuccessful()) { - GetEgressActionsForInterfaceOutput egressActionsOutput = egressActionsOutputFuture.get().getResult(); - result = egressActionsOutput.getAction(); + if (internal && interfaceManager.isItmDirectTunnelsEnabled()) { + GetEgressActionsForTunnelInput getEgressActInputItm = new GetEgressActionsForTunnelInputBuilder() + .setIntfName(interfaceName).setTunnelKey(tunnelKey).build(); + Future> egressActionsOutputItm = + itmRpcService.getEgressActionsForTunnel(getEgressActInputItm); + if (egressActionsOutputItm.get().isSuccessful()) { + return new ArrayList(egressActionsOutputItm.get().getResult().getAction().values()); + } + } else { + GetEgressActionsForInterfaceInput getEgressActInput = new GetEgressActionsForInterfaceInputBuilder() + .setIntfName(interfaceName).setTunnelKey(tunnelKey).build(); + Future> egressActionsOutputFuture = + interfaceManagerRpcService.getEgressActionsForInterface(getEgressActInput); + if (egressActionsOutputFuture.get().isSuccessful()) { + return new ArrayList(egressActionsOutputFuture.get().getResult().getAction().values()); + } } } catch (Exception e) { - LOG.error("Error in RPC call getEgressActionsForInterface {}", e); + LOG.error("Error in RPC call getEgressActionsForInterface", e); } - - if (result == null || result.isEmpty()) { - LOG.warn("Could not build Egress actions for interface {} and tunnelId {}", interfaceName, tunnelKey); - } - return result; + LOG.warn("Could not build Egress actions for interface {} and tunnelId {}", interfaceName, tunnelKey); + return Collections.emptyList(); } /** @@ -229,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); }