use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel in project netvirt by opendaylight.
the class ExternalRoutersListener method getTunnelInterfaceName.
protected String getTunnelInterfaceName(BigInteger srcDpId, BigInteger dstDpId) {
Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
RpcResult<GetTunnelInterfaceNameOutput> rpcResult;
try {
Future<RpcResult<GetTunnelInterfaceNameOutput>> result = itmManager.getTunnelInterfaceName(new GetTunnelInterfaceNameInputBuilder().setSourceDpid(srcDpId).setDestinationDpid(dstDpId).setTunnelType(tunType).build());
rpcResult = result.get();
if (!rpcResult.isSuccessful()) {
tunType = TunnelTypeGre.class;
result = itmManager.getTunnelInterfaceName(new GetTunnelInterfaceNameInputBuilder().setSourceDpid(srcDpId).setDestinationDpid(dstDpId).setTunnelType(tunType).build());
rpcResult = result.get();
if (!rpcResult.isSuccessful()) {
LOG.warn("getTunnelInterfaceName : RPC Call to getTunnelInterfaceId returned with Errors {}", rpcResult.getErrors());
} else {
return rpcResult.getResult().getInterfaceName();
}
LOG.warn("getTunnelInterfaceName : RPC Call to getTunnelInterfaceId returned with Errors {}", rpcResult.getErrors());
} else {
return rpcResult.getResult().getInterfaceName();
}
} catch (InterruptedException | ExecutionException | NullPointerException e) {
LOG.error("getTunnelInterfaceName : Exception when getting tunnel interface Id for tunnel " + "between {} and {}", srcDpId, dstDpId, e);
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel in project netvirt by opendaylight.
the class NatTunnelInterfaceStateListener method handleTepDelForAllRtrs.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private boolean handleTepDelForAllRtrs(BigInteger srcDpnId, String tunnelType, String tunnelName, String srcTepIp, String destTepIp, WriteTransaction writeFlowInvTx) {
LOG.trace("handleTepDelForAllRtrs : TEP DEL ----- for EXTERNAL/HWVTEP ITM Tunnel,TYPE {},State is UP b/w SRC IP" + " : {} and DEST IP: {}", fibManager.getTransportTypeStr(tunnelType), srcTepIp, destTepIp);
// When tunnel EP is deleted on a DPN , VPN gets two deletion event.
// One for a DPN on which tunnel EP was deleted and another for other-end DPN.
// Handle only the DPN on which it was deleted , ignore other event.
// DPN on which TEP is deleted , endpoint IP will be null.
String endpointIpForDPN = null;
try {
endpointIpForDPN = NatUtil.getEndpointIpAddressForDPN(dataBroker, srcDpnId);
} catch (Exception e) {
/* this dpn does not have the VTEP */
LOG.error("handleTepDelForAllRtrs : DPN {} does not have the VTEP", srcDpnId);
endpointIpForDPN = null;
}
if (endpointIpForDPN != null) {
LOG.trace("handleTepDelForAllRtrs : Ignore TEP DELETE event received for DPN {} VTEP IP {} since its " + "the other end DPN w.r.t the delted TEP", srcDpnId, srcTepIp);
return false;
}
List<RoutersList> routersList = null;
InstanceIdentifier<DpnRoutersList> dpnRoutersListId = NatUtil.getDpnRoutersId(srcDpnId);
Optional<DpnRoutersList> optionalRouterDpnList = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, dpnRoutersListId);
if (optionalRouterDpnList.isPresent()) {
routersList = optionalRouterDpnList.get().getRoutersList();
} else {
LOG.warn("handleTepDelForAllRtrs : RouterDpnList is empty for DPN {}.Hence ignoring TEP DEL event " + "for the ITM TUNNEL TYPE {} b/w SRC IP {} and DST IP {} and TUNNEL NAME {} ", srcDpnId, tunnelType, srcTepIp, destTepIp, tunnelName);
return false;
}
if (routersList == null) {
LOG.error("handleTepDelForAllRtrs : DPN {} does not have the Routers presence", srcDpnId);
return false;
}
for (RoutersList router : routersList) {
String routerName = router.getRouter();
LOG.debug("handleTepDelForAllRtrs : TEP DEL : DNAT -> Withdrawing routes for router {} ", routerName);
long routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("handleTepDelForAllRtrs :Invalid ROUTER-ID {} returned for routerName {}", routerId, routerName);
return false;
}
Uuid externalNetworkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, externalNetworkId);
if (extNwProvType == null) {
return false;
}
hndlTepDelForDnatInEachRtr(router, routerId, srcDpnId, extNwProvType);
LOG.debug("handleTepDelForAllRtrs : TEP DEL : SNAT -> Withdrawing and Advertising routes for router {} ", router.getRouter());
hndlTepDelForSnatInEachRtr(router, routerId, srcDpnId, tunnelType, srcTepIp, destTepIp, tunnelName, extNwProvType, writeFlowInvTx);
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel in project netvirt by opendaylight.
the class NatTunnelInterfaceStateListener method hndlTepAddForAllRtrs.
private boolean hndlTepAddForAllRtrs(BigInteger srcDpnId, String tunnelType, String tunnelName, String srcTepIp, String destTepIp, WriteTransaction writeFlowInvTx) {
LOG.trace("hndlTepAddForAllRtrs: TEP ADD ----- for EXTERNAL/HWVTEP ITM Tunnel, TYPE {} ,State is UP b/w SRC IP" + " : {} and DEST IP: {}", fibManager.getTransportTypeStr(tunnelType), srcTepIp, destTepIp);
InstanceIdentifier<DpnRoutersList> dpnRoutersListId = NatUtil.getDpnRoutersId(srcDpnId);
Optional<DpnRoutersList> optionalRouterDpnList = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, dpnRoutersListId);
if (!optionalRouterDpnList.isPresent()) {
LOG.info("hndlTepAddForAllRtrs : RouterDpnList model is empty for DPN {}. Hence ignoring TEP add event " + "for the ITM TUNNEL TYPE {} b/w SRC IP {} and DST IP {} and TUNNEL NAME {} ", srcDpnId, tunnelType, srcTepIp, destTepIp, tunnelName);
return false;
}
List<RoutersList> routersList = optionalRouterDpnList.get().getRoutersList();
if (routersList == null) {
LOG.debug("hndlTepAddForAllRtrs : Ignoring TEP add for the DPN {} since no routers are associated" + " for the DPN having the TUNNEL TYPE {} b/w SRC IP {} and DST IP {} and" + "TUNNEL NAME {} ", srcDpnId, tunnelType, srcTepIp, destTepIp, tunnelName);
return false;
}
String nextHopIp = NatUtil.getEndpointIpAddressForDPN(dataBroker, srcDpnId);
for (RoutersList router : routersList) {
String routerName = router.getRouter();
long routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("hndlTepAddForAllRtrs :Invalid ROUTER-ID {} returned for routerName {}", routerId, routerName);
return false;
}
LOG.debug("hndlTepAddForAllRtrs : TEP ADD : DNAT -> Advertising routes for router {} ", routerName);
Uuid externalNetworkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, externalNetworkId);
if (extNwProvType == null) {
return false;
}
hndlTepAddForDnatInEachRtr(router, routerId, nextHopIp, srcDpnId, extNwProvType, writeFlowInvTx);
LOG.debug("hndlTepAddForAllRtrs : TEP ADD : SNAT -> Advertising routes for router {} ", routerName);
hndlTepAddForSnatInEachRtr(router, routerId, srcDpnId, tunnelType, srcTepIp, destTepIp, tunnelName, nextHopIp, extNwProvType, writeFlowInvTx);
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel in project netvirt by opendaylight.
the class NatTunnelInterfaceStateListener method hndlTepAddOnNaptSwitch.
private boolean hndlTepAddOnNaptSwitch(BigInteger srcDpnId, String tunnelType, String srcTepIp, String destTepIp, String tunnelName, long routerId, Optional<Routers> routerData, String nextHopIp, Uuid vpnName, ProviderTypes extNwProvType, WriteTransaction writeFlowInvTx) {
if (!routerData.isPresent()) {
LOG.warn("hndlTepAddOnNaptSwitch: routerData is not present");
return false;
}
Routers router = routerData.get();
String routerName = router.getRouterName();
LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Processing TEP add for the DPN {} having the router {} since " + "its THE NAPT switch for the TUNNEL TYPE {} b/w SRC IP {} and DST IP {} " + "and TUNNEL NAME {} ", srcDpnId, routerName, tunnelType, srcTepIp, destTepIp, tunnelName);
Uuid networkId = router.getNetworkId();
if (networkId == null) {
LOG.warn("hndlTepAddOnNaptSwitch : SNAT -> Ignoring TEP add since the router {} is not associated to the " + "external network", routerName);
return false;
}
LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Router {} is associated with Ext nw {}", routerId, networkId);
Long vpnId;
if (vpnName == null) {
LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Internal VPN associated to router {}", routerId);
vpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
if (vpnId == NatConstants.INVALID_ID) {
LOG.error("hndlTepAddOnNaptSwitch : Invalid External VPN-ID returned for routerName {}", routerName);
return false;
}
LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Retrieved External VPN-ID {} for router {}", vpnId, routerId);
} else {
LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Private BGP VPN associated to router {}", routerId);
vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
if (vpnId == null || vpnId == NatConstants.INVALID_ID) {
LOG.error("hndlTepAddOnNaptSwitch : Invalid vpnId returned for routerName {}", routerName);
return false;
}
LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Retrieved vpnId {} for router {}", vpnId, routerId);
}
/*1) Withdraw the old route to the external IP from the BGP which was having the
next hop as the old TEP IP.
2) Advertise to the BGP about the new route to the external IP having the
new TEP IP as the next hop.
3) Populate a new FIB entry with the next hop IP as the new TEP IP using the
FIB manager.
*/
// Withdraw the old route to the external IP from the BGP which was having the
// next hop as the old TEP IP.
final String externalVpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
if (externalVpnName == null) {
LOG.error("hndlTepAddOnNaptSwitch : SNAT -> No VPN associated with ext nw {} in router {}", networkId, routerId);
return false;
}
Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
LOG.debug("hndlTepAddOnNaptSwitch : Clearing the FIB entries but not the BGP routes");
for (String externalIp : externalIps) {
String rd = NatUtil.getVpnRd(dataBroker, externalVpnName);
LOG.debug("hndlTepAddOnNaptSwitch : Removing Fib entry rd {} prefix {}", rd, externalIp);
fibManager.removeFibEntry(rd, externalIp, null);
}
/*
Advertise to the BGP about the new route to the external IP having the
new TEP IP as the next hop.
Populate a new FIB entry with the next hop IP as the new TEP IP using the
FIB manager.
*/
String rd = NatUtil.getVpnRd(dataBroker, externalVpnName);
if (extNwProvType == null) {
return false;
}
String gwMacAddress = null;
long l3Vni = 0;
if (extNwProvType == ProviderTypes.VXLAN) {
// Get the External Gateway MAC Address which is Router gateway MAC address for SNAT
gwMacAddress = NatUtil.getExtGwMacAddFromRouterName(dataBroker, routerName);
if (gwMacAddress != null) {
LOG.debug("hndlTepAddOnNaptSwitch : External Gateway MAC address {} found for External Router ID {}", gwMacAddress, routerId);
} else {
LOG.error("hndlTepAddOnNaptSwitch : No External Gateway MAC address found for External Router ID {}", routerId);
return false;
}
// get l3Vni value for external VPN
l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
LOG.debug("hndlTepAddOnNaptSwitch : L3VNI value is not configured in Internet VPN {} and RD {} " + "Carve-out L3VNI value from OpenDaylight VXLAN VNI Pool and continue to installing " + "NAT flows", vpnName, rd);
l3Vni = NatOverVxlanUtil.getInternetVpnVni(idManager, externalVpnName, routerId).longValue();
}
}
for (final String externalIp : externalIps) {
long serviceId = 0;
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
if (extNwProvType == ProviderTypes.VXLAN) {
LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Advertise the route to the externalIp {} " + "having nextHopIp {}", externalIp, nextHopIp);
NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, externalVpnName, rd, externalIp, nextHopIp, l3Vni, tunnelName, gwMacAddress, writeFlowInvTx, RouteOrigin.STATIC, srcDpnId);
serviceId = l3Vni;
} else {
Long label = externalRouterListner.checkExternalIpLabel(routerId, externalIp);
if (label == null || label == NatConstants.INVALID_ID) {
LOG.error("hndlTepAddOnNaptSwitch : SNAT->Unable to advertise to the DC GW " + "since label is invalid");
return false;
}
LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Advertise the route to the externalIp {} " + "having nextHopIp {}", externalIp, nextHopIp);
long l3vni = 0;
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, externalVpnName, l3vni).longValue();
}
Uuid externalSubnetId = NatUtil.getExternalSubnetForRouterExternalIp(externalIp, router);
NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, externalVpnName, rd, externalSubnetId, fibExternalIp, nextHopIp, networkId.getValue(), null, /* mac-address */
label, l3vni, RouteOrigin.STATIC, srcDpnId);
serviceId = label;
}
LOG.debug("hndlTepAddOnNaptSwitch: SNAT -> Install custom FIB routes " + "(Table 21 -> Push MPLS label to Tunnel port");
List<Instruction> customInstructions = new ArrayList<>();
int customInstructionIndex = 0;
long externalSubnetVpnId = NatUtil.getExternalSubnetVpnIdForRouterExternalIp(dataBroker, externalIp, router);
if (externalSubnetVpnId != NatConstants.INVALID_ID) {
LOG.debug("hndlTepAddOnNaptSwitch : Will install custom FIB router with external subnet VPN ID {}", externalSubnetVpnId);
BigInteger subnetIdMetaData = MetaDataUtil.getVpnIdMetadata(externalSubnetVpnId);
customInstructions.add(new InstructionWriteMetadata(subnetIdMetaData, MetaDataUtil.METADATA_MASK_VRFID).buildInstruction(customInstructionIndex));
customInstructionIndex++;
}
customInstructions.add(new InstructionGotoTable(NwConstants.INBOUND_NAPT_TABLE).buildInstruction(customInstructionIndex));
CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(externalVpnName).setSourceDpid(srcDpnId).setInstruction(customInstructions).setIpAddress(fibExternalIp).setServiceId(serviceId).setInstruction(customInstructions).build();
Future<RpcResult<Void>> future = fibRpcService.createFibEntry(input);
ListenableFuture<RpcResult<Void>> listenableFuture = JdkFutureAdapters.listenInPoolThread(future);
Futures.addCallback(listenableFuture, new FutureCallback<RpcResult<Void>>() {
@Override
public void onFailure(@Nonnull Throwable error) {
LOG.error("hndlTepAddOnNaptSwitch : SNAT->Error in generate label or fib install process", error);
}
@Override
public void onSuccess(@Nonnull RpcResult<Void> result) {
if (result.isSuccessful()) {
LOG.info("hndlTepAddOnNaptSwitch : SNAT -> Successfully installed custom FIB routes " + "for prefix {}", externalIp);
} else {
LOG.error("hndlTepAddOnNaptSwitch : SNAT -> Error in rpc call to create custom Fib entries " + "for prefix {} in DPN {}, {}", externalIp, srcDpnId, result.getErrors());
}
}
}, MoreExecutors.directExecutor());
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel in project netvirt by opendaylight.
the class NatUtil method isFloatingIpPresentForDpn.
public static Boolean isFloatingIpPresentForDpn(DataBroker dataBroker, BigInteger dpnId, String rd, String vpnName, String externalIp, Boolean isMoreThanOneFipCheckOnDpn) {
InstanceIdentifier<VpnToDpnList> id = getVpnToDpnListIdentifier(rd, dpnId);
Optional<VpnToDpnList> dpnInVpn = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (dpnInVpn.isPresent()) {
LOG.debug("isFloatingIpPresentForDpn : vpn-to-dpn-list is not empty for vpnName {}, dpn id {}, " + "rd {} and floatingIp {}", vpnName, dpnId, rd, externalIp);
try {
List<IpAddresses> ipAddressList = dpnInVpn.get().getIpAddresses();
if (ipAddressList != null && !ipAddressList.isEmpty()) {
int floatingIpPresentCount = 0;
for (IpAddresses ipAddress : ipAddressList) {
if (!ipAddress.getIpAddress().equals(externalIp) && IpAddresses.IpAddressSource.FloatingIP.equals(ipAddress.getIpAddressSource())) {
floatingIpPresentCount++;
// Add tunnel table check
if (isMoreThanOneFipCheckOnDpn && floatingIpPresentCount > 1) {
return Boolean.TRUE;
}
// Remove tunnel table check
if (!isMoreThanOneFipCheckOnDpn) {
return Boolean.TRUE;
}
}
}
} else {
LOG.debug("isFloatingIpPresentForDpn : vpn-to-dpn-list does not contain any floating IP for DPN {}", dpnId);
return Boolean.FALSE;
}
} catch (NullPointerException e) {
LOG.error("isFloatingIpPresentForDpn: Exception occurred on getting external IP address from " + "vpn-to-dpn-list on Dpn {}", dpnId, e);
return Boolean.FALSE;
}
}
return Boolean.FALSE;
}
Aggregations