use of org.opendaylight.mdsal.binding.util.Datastore.Configuration in project netvirt by opendaylight.
the class EvpnDnatFlowProgrammer method onRemoveFloatingIp.
public void onRemoveFloatingIp(final Uint64 dpnId, final String vpnName, final String externalIp, final String floatingIpInterface, final String floatingIpPortMacAddress, final Uint32 routerId) {
/*
* 1) Remove the flow INTERNAL_TUNNEL_TABLE (table=36)-> PDNAT_TABLE (table=25) (SNAT VM on DPN1 is
* responding back to FIP VM on DPN2) {SNAT to DNAT traffic on different Hypervisor}
*
* 2) Remove the flow L3_FIB_TABLE (table=21)-> PDNAT_TABLE (table=25) (FIP VM1 to FIP VM2
* Traffic on Same Hypervisor) {DNAT to DNAT on Same Hypervisor}
*
* 3) Remove the flow L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
* (DC-GW is responding back to FIP VM) {DNAT Reverse traffic})
*
*/
String rd = NatUtil.getVpnRd(dataBroker, vpnName);
if (rd == null) {
LOG.error("onRemoveFloatingIp : Could not retrieve RD value from VPN Name {} ", vpnName);
return;
}
Uint32 vpnId = NatUtil.getVpnId(dataBroker, vpnName);
if (vpnId == NatConstants.INVALID_ID) {
LOG.error("onRemoveFloatingIp : Invalid Vpn Id is found for Vpn Name {}", vpnName);
return;
}
Uint32 l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
LOG.debug("onRemoveFloatingIp : L3VNI value is not configured in Internet VPN {} and RD {} " + "Carve-out L3VNI value from OpenDaylight VXLAN VNI Pool and continue with installing " + "DNAT flows for FloatingIp {}", vpnName, rd, externalIp);
l3Vni = natOverVxlanUtil.getInternetVpnVni(vpnName, routerId);
}
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
// Remove Prefix from BGP
NatUtil.removePrefixFromBGP(bgpManager, fibManager, rd, fibExternalIp, vpnName);
// Remove custom FIB routes flow for L3_FIB_TABLE (table=21)-> PDNAT_TABLE (table=25)
RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setIpAddress(fibExternalIp).setServiceId(l3Vni).setIpAddressSource(RemoveFibEntryInput.IpAddressSource.FloatingIP).build();
ListenableFuture<RpcResult<RemoveFibEntryOutput>> futureVxlan = fibService.removeFibEntry(input);
final Uint32 finalL3Vni = l3Vni;
Futures.addCallback(futureVxlan, new FutureCallback<RpcResult<RemoveFibEntryOutput>>() {
@Override
public void onFailure(@NonNull Throwable error) {
LOG.error("onRemoveFloatingIp : Error {} in custom fib routes remove process for Floating " + "IP Prefix {} on DPN {}", error, externalIp, dpnId);
}
@Override
public void onSuccess(@NonNull RpcResult<RemoveFibEntryOutput> result) {
if (result.isSuccessful()) {
LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, innerConfTx -> {
LOG.info("onRemoveFloatingIp : Successfully removed custom FIB routes for Floating " + "IP Prefix {} on DPN {}", externalIp, dpnId);
/* check if any floating IP information is available in vpn-to-dpn-list for given dpn id.
* If exist any floating IP then do not remove
* INTERNAL_TUNNEL_TABLE (table=36) -> PDNAT_TABLE (table=25) flow entry.
*/
if (!NatUtil.isFloatingIpPresentForDpn(dataBroker, dpnId, rd, vpnName, externalIp, false)) {
// Remove the flow for INTERNAL_TUNNEL_TABLE (table=36)-> PDNAT_TABLE (table=25)
removeTunnelTableEntry(dpnId, finalL3Vni, innerConfTx);
}
// Remove the flow for L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
NatEvpnUtil.removeL3GwMacTableEntry(dpnId, vpnId, floatingIpPortMacAddress, mdsalManager, innerConfTx);
}), LOG, "Error removing flows");
} else {
LOG.error("onRemoveFloatingIp : Error {} in rpc call to remove custom Fib entries for Floating " + "IP Prefix {} on DPN {}", result.getErrors(), externalIp, dpnId);
}
}
}, MoreExecutors.directExecutor());
// Read the FIP vpn-interface details from Operational l3vpn:vpn-interfaces model and delete from Operational DS
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NatUtil.getVpnInterfaceIdentifier(floatingIpInterface);
Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
for (VpnInstanceNames vpnInstance : optionalVpnInterface.get().nonnullVpnInstanceNames().values()) {
if (!vpnName.equals(vpnInstance.getVpnName())) {
continue;
}
InstanceIdentifier<VpnInterfaceOpDataEntry> vpnOpIfIdentifier = NatUtil.getVpnInterfaceOpDataEntryIdentifier(floatingIpInterface, vpnName);
tx.delete(vpnOpIfIdentifier);
break;
}
}), LOG, "onRemoveFloatingIp : Could not remove vpnInterface {}, vpnName {} from Operational " + "odl-l3vpn:vpn-interface-op-data", floatingIpInterface, vpnName);
LOG.debug("onRemoveFloatingIp : Remove vpnInterface {} vpnName {} " + "to Operational odl-l3vpn:vpn-interface-op-data", floatingIpInterface, vpnName);
} else {
LOG.debug("onRemoveFloatingIp : No vpnInterface {} found " + "in Operational odl-l3vpn:vpn-interface-op-data", floatingIpInterface);
}
}
use of org.opendaylight.mdsal.binding.util.Datastore.Configuration in project netvirt by opendaylight.
the class FloatingIPListener method addOrDelDefaultFibRouteForDnat.
private void addOrDelDefaultFibRouteForDnat(Uint64 dpnId, String routerName, Uint32 routerId, @Nullable TypedReadWriteTransaction<Configuration> confTx, boolean create) throws ExecutionException, InterruptedException {
if (confTx == null) {
LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, newTx -> addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, newTx, create)), LOG, "Error handling default FIB route for DNAT");
return;
}
// Check if the router to bgp-vpn association is present
Uint32 associatedVpnId = NatConstants.INVALID_ID;
Uuid associatedVpn = NatUtil.getVpnForRouter(dataBroker, routerName);
if (associatedVpn != null) {
associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVpn.getValue());
}
if (create) {
if (associatedVpnId != NatConstants.INVALID_ID) {
LOG.debug("addOrDelDefaultFibRouteForDnat: Install NAT default route on DPN {} for the router {} with " + "vpn-id {}", dpnId, routerName, associatedVpnId);
defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, associatedVpnId, routerId, confTx);
} else {
LOG.debug("addOrDelDefaultFibRouteForDnat: Install NAT default route on DPN {} for the router {} with " + "vpn-id {}", dpnId, routerName, routerId);
defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, confTx);
}
} else {
if (associatedVpnId != NatConstants.INVALID_ID) {
LOG.debug("addOrDelDefaultFibRouteForDnat: Remove NAT default route on DPN {} for the router {} " + "with vpn-id {}", dpnId, routerName, associatedVpnId);
defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, associatedVpnId, routerId, confTx);
} else {
LOG.debug("addOrDelDefaultFibRouteForDnat: Remove NAT default route on DPN {} for the router {} " + "with vpn-id {}", dpnId, routerName, routerId);
defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, confTx);
}
}
}
use of org.opendaylight.mdsal.binding.util.Datastore.Configuration in project netvirt by opendaylight.
the class SnatCentralizedSwitchChangeListener method update.
@Override
public void update(InstanceIdentifier<RouterToNaptSwitch> key, RouterToNaptSwitch origRouterToNaptSwitch, RouterToNaptSwitch updatedRouterToNaptSwitch) {
LOG.debug("Updating old {} new {}", origRouterToNaptSwitch, updatedRouterToNaptSwitch);
if (natMode == NatMode.Controller) {
LOG.info("Do Not Processing this update() event for (routerName:designatedDpn) {}:{}" + "configured in Controller Mode", updatedRouterToNaptSwitch.getRouterName(), updatedRouterToNaptSwitch.getPrimarySwitchId());
return;
}
Uint64 origPrimarySwitchId = origRouterToNaptSwitch.getPrimarySwitchId();
Uint64 updatedPrimarySwitchId = updatedRouterToNaptSwitch.getPrimarySwitchId();
LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
Routers origRouter = NatUtil.getRoutersFromConfigDS(confTx, origRouterToNaptSwitch.getRouterName());
Routers updatedRouter = NatUtil.getRoutersFromConfigDS(confTx, updatedRouterToNaptSwitch.getRouterName());
if (!Objects.equals(origPrimarySwitchId, updatedPrimarySwitchId)) {
if (origRouter != null) {
try {
snatServiceManger.notify(confTx, origRouter, null, origPrimarySwitchId, null, SnatServiceManager.Action.CNT_ROUTER_ALL_SWITCH_DISBL);
if (origRouterToNaptSwitch.isEnableSnat()) {
snatServiceManger.notify(confTx, origRouter, null, origPrimarySwitchId, null, SnatServiceManager.Action.SNAT_ALL_SWITCH_DISBL);
}
} catch (ExecutionException | InterruptedException e) {
LOG.error("Exception while notifying snatManager for : {}", origRouter, e);
}
natDataUtil.removeFromRouterMap(origRouter);
}
if (updatedRouter != null) {
natDataUtil.updateRouterMap(updatedRouter);
try {
snatServiceManger.notify(confTx, updatedRouter, null, updatedPrimarySwitchId, null, SnatServiceManager.Action.CNT_ROUTER_ALL_SWITCH_ENBL);
if (updatedRouterToNaptSwitch.isEnableSnat()) {
snatServiceManger.notify(confTx, updatedRouter, null, updatedPrimarySwitchId, null, SnatServiceManager.Action.SNAT_ALL_SWITCH_ENBL);
}
} catch (ExecutionException | InterruptedException e) {
LOG.error("Exception while notifying snatManager for : {}", updatedRouter, e);
}
}
} else {
boolean origIsSnatEnabled = false;
boolean updatedIsSnatEnabled = false;
if (origRouterToNaptSwitch.isEnableSnat() != null) {
origIsSnatEnabled = origRouterToNaptSwitch.isEnableSnat();
}
if (updatedRouterToNaptSwitch.isEnableSnat() != null) {
updatedIsSnatEnabled = updatedRouterToNaptSwitch.isEnableSnat();
}
if (origIsSnatEnabled != updatedIsSnatEnabled) {
if (updatedRouterToNaptSwitch.isEnableSnat()) {
snatServiceManger.notify(confTx, updatedRouter, null, updatedPrimarySwitchId, null, SnatServiceManager.Action.SNAT_ALL_SWITCH_ENBL);
} else {
snatServiceManger.notify(confTx, origRouter, null, origPrimarySwitchId, null, SnatServiceManager.Action.SNAT_ALL_SWITCH_DISBL);
}
}
}
}), LOG, "Error handling SNAT centralized switch update");
}
use of org.opendaylight.mdsal.binding.util.Datastore.Configuration in project netvirt by opendaylight.
the class SnatCentralizedSwitchChangeListener method add.
@Override
public void add(InstanceIdentifier<RouterToNaptSwitch> key, RouterToNaptSwitch routerToNaptSwitch) {
LOG.debug("Adding {}", routerToNaptSwitch);
if (natMode == NatMode.Controller) {
LOG.info("Do Not Processing this add() event for (routerName:designatedDpn) {}:{}" + "configured in Controller Mode", routerToNaptSwitch.getRouterName(), routerToNaptSwitch.getPrimarySwitchId());
return;
}
Uint64 primarySwitchId = routerToNaptSwitch.getPrimarySwitchId();
String routerName = routerToNaptSwitch.getRouterName();
Routers router = NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
final boolean isEnableSnat;
if (routerToNaptSwitch.isEnableSnat() != null) {
isEnableSnat = routerToNaptSwitch.isEnableSnat();
} else {
isEnableSnat = false;
}
Uint32 vpnId = NatUtil.getVpnId(dataBroker, routerName);
if (vpnId == NatConstants.INVALID_ID) {
LOG.warn("VpnId not unavailable for router {} yet", routerName);
eventCallbacks.onAddOrUpdate(LogicalDatastoreType.CONFIGURATION, NatUtil.getVpnInstanceToVpnIdIdentifier(routerName), (unused, newVpnId) -> {
LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, innerConfTx -> handleAdd(innerConfTx, routerName, router, primarySwitchId, isEnableSnat)), LOG, "Error handling router addition");
return DataTreeEventCallbackRegistrar.NextAction.UNREGISTER;
}, Duration.ofSeconds(5), iid -> LOG.error("VpnId not found for router {}", routerName));
return;
}
LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> handleAdd(confTx, routerName, router, primarySwitchId, isEnableSnat)), LOG, "Error handling router addition");
}
use of org.opendaylight.mdsal.binding.util.Datastore.Configuration in project netvirt by opendaylight.
the class NatRouterInterfaceListener method remove.
@Override
public void remove(InstanceIdentifier<Interfaces> identifier, Interfaces interfaceInfo) {
LOG.trace("remove : Remove event - key: {}, value: {}", interfaceInfo.key(), interfaceInfo);
final String routerId = identifier.firstKeyOf(RouterInterfaces.class).getRouterId().getValue();
final String interfaceName = interfaceInfo.getInterfaceId();
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState = NatUtil.getInterfaceStateFromOperDS(dataBroker, interfaceName);
if (interfaceState != null) {
Uint64 dpId = NatUtil.getDpIdFromInterface(interfaceState);
if (dpId.equals(Uint64.ZERO)) {
LOG.warn("REMOVE : Could not retrieve DPN ID for interface {} to handle router {} dissociation model", interfaceName, routerId);
return;
}
final ReentrantLock lock = NatUtil.lockForNat(dpId);
lock.lock();
try {
if (NatUtil.isSnatEnabledForRouterId(dataBroker, routerId)) {
NatUtil.removeSnatEntriesForPort(dataBroker, naptManager, mdsalManager, neutronVpnService, interfaceName, routerId);
}
LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> {
// Delete the NeutronRouterDpnMap from the ODL:L3VPN operational model
NatUtil.removeFromNeutronRouterDpnsMap(routerId, interfaceName, dpId, operTx);
// Delete the DpnRouterMap from the ODL:L3VPN operational model
NatUtil.removeFromDpnRoutersMap(dataBroker, routerId, interfaceName, dpId, interfaceManager, operTx);
}), LOG, "Error handling NAT router interface removal");
// Delete the RouterInterfaces maintained in the ODL:L3VPN configuration model
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> confTx.delete(NatUtil.getRouterInterfaceId(interfaceName))), LOG, "Error handling NAT router interface removal");
} finally {
lock.unlock();
}
}
}
Aggregations