use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes in project netvirt by opendaylight.
the class ExternalRoutersListener method handleEnableSnat.
public void handleEnableSnat(Routers routers, long routerId, BigInteger primarySwitchId, long bgpVpnId, WriteTransaction writeFlowInvTx) {
String routerName = routers.getRouterName();
LOG.info("handleEnableSnat : Handling SNAT for router {}", routerName);
naptManager.initialiseExternalCounter(routers, routerId);
subnetRegisterMapping(routers, routerId);
LOG.debug("handleEnableSnat:About to create and install outbound miss entry in Primary Switch {} for router {}", primarySwitchId, routerName);
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, routers.getNetworkId());
if (extNwProvType == null) {
LOG.error("handleEnableSnat : External Network Provider Type missing");
return;
}
if (bgpVpnId != NatConstants.INVALID_ID) {
installFlowsWithUpdatedVpnId(primarySwitchId, routerName, bgpVpnId, routerId, false, writeFlowInvTx, extNwProvType);
} else {
// write metadata and punt
installOutboundMissEntry(routerName, routerId, primarySwitchId, writeFlowInvTx);
// Now install entries in SNAT tables to point to Primary for each router
List<BigInteger> switches = naptSwitchSelector.getDpnsForVpn(routerName);
for (BigInteger dpnId : switches) {
// Handle switches and NAPT switches separately
if (!dpnId.equals(primarySwitchId)) {
LOG.debug("handleEnableSnat : Handle Ordinary switch");
handleSwitches(dpnId, routerName, routerId, primarySwitchId);
} else {
LOG.debug("handleEnableSnat : Handle NAPT switch");
handlePrimaryNaptSwitch(dpnId, routerName, routerId, writeFlowInvTx);
}
}
}
Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
if (externalIps.isEmpty()) {
LOG.error("handleEnableSnat : Internal External mapping not found for router {}", routerName);
return;
} else {
for (String externalIpAddrPrefix : externalIps) {
LOG.debug("handleEnableSnat : Calling handleSnatReverseTraffic for primarySwitchId {}, " + "routerName {} and externalIpAddPrefix {}", primarySwitchId, routerName, externalIpAddrPrefix);
handleSnatReverseTraffic(primarySwitchId, routers, routerId, routerName, externalIpAddrPrefix, writeFlowInvTx);
}
}
LOG.debug("handleEnableSnat : Exit");
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes in project netvirt by opendaylight.
the class ExternalRoutersListener method delFibTsAndReverseTraffic.
protected void delFibTsAndReverseTraffic(final BigInteger dpnId, long routerId, String extIp, final String vpnName, Uuid extNetworkId, long tempLabel, String gwMacAddress, boolean switchOver, WriteTransaction removeFlowInvTx) {
LOG.debug("delFibTsAndReverseTraffic : Removing fib entry for externalIp {} in routerId {}", extIp, routerId);
String routerName = NatUtil.getRouterName(dataBroker, routerId);
if (routerName == null) {
LOG.error("delFibTsAndReverseTraffic : Could not retrieve Router Name from Router ID {} ", routerId);
return;
}
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNetworkId);
if (extNwProvType == null) {
LOG.error("delFibTsAndReverseTraffic : External Network Provider Type Missing");
return;
}
/* Remove the flow table19->44 and table36->44 entries for SNAT reverse traffic flow if the
* external network provided type is VxLAN
*/
if (extNwProvType == ProviderTypes.VXLAN) {
evpnSnatFlowProgrammer.evpnDelFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName, gwMacAddress, removeFlowInvTx);
return;
}
if (tempLabel < 0) {
LOG.error("delFibTsAndReverseTraffic : Label not found for externalIp {} with router id {}", extIp, routerId);
return;
}
final long label = tempLabel;
final String externalIp = NatUtil.validateAndAddNetworkMask(extIp);
RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setIpAddress(externalIp).setServiceId(label).setIpAddressSource(RemoveFibEntryInput.IpAddressSource.ExternalFixedIP).build();
Future<RpcResult<Void>> future = fibService.removeFibEntry(input);
removeTunnelTableEntry(dpnId, label, removeFlowInvTx);
removeLFibTableEntry(dpnId, label, removeFlowInvTx);
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
// Remove the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId, removeFlowInvTx);
}
if (!switchOver) {
ListenableFuture<RpcResult<Void>> labelFuture = Futures.transformAsync(JdkFutureAdapters.listenInPoolThread(future), (AsyncFunction<RpcResult<Void>, RpcResult<Void>>) result -> {
if (result.isSuccessful()) {
NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId, removeFlowInvTx);
RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder().setVpnName(vpnName).setIpPrefix(externalIp).build();
Future<RpcResult<Void>> labelFuture1 = vpnService.removeVpnLabel(labelInput);
return JdkFutureAdapters.listenInPoolThread(labelFuture1);
} else {
String errMsg = String.format("RPC call to remove custom FIB entries on dpn %s for " + "prefix %s Failed - %s", dpnId, externalIp, result.getErrors());
LOG.error(errMsg);
return Futures.immediateFailedFuture(new RuntimeException(errMsg));
}
});
Futures.addCallback(labelFuture, new FutureCallback<RpcResult<Void>>() {
@Override
public void onFailure(@Nonnull Throwable error) {
LOG.error("delFibTsAndReverseTraffic : Error in removing the label:{} or custom fib entries" + "got external ip {}", label, extIp, error);
}
@Override
public void onSuccess(@Nonnull RpcResult<Void> result) {
if (result.isSuccessful()) {
LOG.debug("delFibTsAndReverseTraffic : Successfully removed the label for the prefix {} " + "from VPN {}", externalIp, vpnName);
} else {
LOG.error("delFibTsAndReverseTraffic : Error in removing the label for prefix {} " + " from VPN {}, {}", externalIp, vpnName, result.getErrors());
}
}
}, MoreExecutors.directExecutor());
} else {
LOG.debug("delFibTsAndReverseTraffic: switch-over is happened on DpnId {}. No need to release allocated " + "label {} for external fixed ip {} for router {}", dpnId, label, externalIp, routerId);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes in project netvirt by opendaylight.
the class FlatVlanConntrackBasedSnatService method handleSnatAllSwitch.
@Override
public boolean handleSnatAllSwitch(Routers routers, BigInteger primarySwitchId, int addOrRemove) {
ProviderTypes extNwProviderType = NatUtil.getProviderTypefromNetworkId(dataBroker, routers.getNetworkId());
LOG.debug("FlatVlanConntrackBasedSnatService: handleSnatAllSwitch ProviderTypes {}", extNwProviderType);
if (extNwProviderType == ProviderTypes.VXLAN || extNwProviderType == ProviderTypes.GRE) {
return false;
}
return super.handleSnatAllSwitch(routers, primarySwitchId, addOrRemove);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes in project netvirt by opendaylight.
the class NatEvpnUtil method getExtNwProvTypeFromRouterName.
static ProviderTypes getExtNwProvTypeFromRouterName(DataBroker dataBroker, String routerName, Uuid externalNetworkId) {
ProviderTypes extNwProviderType = null;
if (externalNetworkId == null) {
LOG.error("getExtNwProvTypeFromRouterName : external network UUID is not available for router {}", routerName);
return extNwProviderType;
}
extNwProviderType = NatUtil.getProviderTypefromNetworkId(dataBroker, externalNetworkId);
if (extNwProviderType == null) {
LOG.error("getExtNwProvTypeFromRouterName : Could not retrieve provider type for external network {}", externalNetworkId);
return extNwProviderType;
}
return extNwProviderType;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes in project netvirt by opendaylight.
the class VpnFloatingIpHandler method cleanupFibEntries.
@Override
public void cleanupFibEntries(final BigInteger dpnId, final String vpnName, final String externalIp, final long label, WriteTransaction removeFlowInvTx, ProviderTypes provType) {
// Remove Prefix from BGP
String rd = NatUtil.getVpnRd(dataBroker, vpnName);
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
NatUtil.removePrefixFromBGP(bgpManager, fibManager, rd, fibExternalIp, vpnName, LOG);
// Remove custom FIB routes
// Future<RpcResult<java.lang.Void>> removeFibEntry(RemoveFibEntryInput input);
RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setIpAddress(fibExternalIp).setServiceId(label).setIpAddressSource(RemoveFibEntryInput.IpAddressSource.FloatingIP).build();
Future<RpcResult<Void>> future = fibService.removeFibEntry(input);
ListenableFuture<RpcResult<Void>> labelFuture = Futures.transformAsync(JdkFutureAdapters.listenInPoolThread(future), (AsyncFunction<RpcResult<Void>, RpcResult<Void>>) result -> {
if (result.isSuccessful()) {
Boolean removeTunnelFlow = Boolean.TRUE;
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanService, provType)) {
if (NatUtil.isFloatingIpPresentForDpn(dataBroker, dpnId, rd, vpnName, externalIp, false)) {
removeTunnelFlow = Boolean.FALSE;
}
}
if (removeTunnelFlow) {
removeTunnelTableEntry(dpnId, label, removeFlowInvTx);
}
removeLFibTableEntry(dpnId, label, removeFlowInvTx);
RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder().setVpnName(vpnName).setIpPrefix(externalIp).build();
Future<RpcResult<Void>> labelFuture1 = vpnService.removeVpnLabel(labelInput);
return JdkFutureAdapters.listenInPoolThread(labelFuture1);
} else {
String errMsg = String.format("onRemoveFloatingIp :RPC call to remove custom FIB entries " + "on dpn %s for prefix %s Failed - %s", dpnId, externalIp, result.getErrors());
LOG.error(errMsg);
return Futures.immediateFailedFuture(new RuntimeException(errMsg));
}
}, MoreExecutors.directExecutor());
Futures.addCallback(labelFuture, new FutureCallback<RpcResult<Void>>() {
@Override
public void onFailure(@Nonnull Throwable error) {
LOG.error("onRemoveFloatingIp : Error in removing the label or custom fib entries", error);
}
@Override
public void onSuccess(@Nonnull RpcResult<Void> result) {
if (result.isSuccessful()) {
LOG.debug("onRemoveFloatingIp : Successfully removed the label for the prefix {} from VPN {}", externalIp, vpnName);
} else {
LOG.error("onRemoveFloatingIp : Error in removing the label for prefix {} from VPN {}, {}", externalIp, vpnName, result.getErrors());
}
}
}, MoreExecutors.directExecutor());
}
Aggregations