use of org.opendaylight.mdsal.binding.api.DataBroker 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.api.DataBroker 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.api.DataBroker 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();
}
}
}
use of org.opendaylight.mdsal.binding.api.DataBroker in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnInterfaceWithAdjacencies.
private void updateVpnInterfaceWithAdjacencies(Uuid vpnId, String infName, Adjacencies adjacencies, TypedWriteTransaction<Configuration> wrtConfigTxn) {
if (vpnId == null || infName == null) {
LOG.error("vpn id or interface is null");
return;
}
if (wrtConfigTxn == null) {
LOG.error("updateVpnInterfaceWithAdjancies called with wrtConfigTxn as null");
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
updateVpnInterfaceWithAdjacencies(vpnId, infName, adjacencies, tx);
}), LOG, "Error updating VPN interface with adjacencies");
return;
}
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
try (AcquireResult lock = tryInterfaceLock(infName)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(infName);
}
try {
Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get());
LOG.debug("Updating vpn interface {} with new adjacencies", infName);
if (adjacencies == null) {
return;
}
vpnIfBuilder.addAugmentation(adjacencies);
if (optionalVpnInterface.get().getVpnInstanceNames() != null) {
List<VpnInstanceNames> listVpnInstances = new ArrayList<>(optionalVpnInterface.get().getVpnInstanceNames().values());
if (listVpnInstances.isEmpty() || !VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId.getValue(), listVpnInstances)) {
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
listVpnInstances.add(vpnInstance);
vpnIfBuilder.setVpnInstanceNames(listVpnInstances);
}
} else {
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
List<VpnInstanceNames> listVpnInstances = new ArrayList<>();
listVpnInstances.add(vpnInstance);
vpnIfBuilder.setVpnInstanceNames(listVpnInstances);
}
LOG.info("Updating vpn interface {} with new adjacencies", infName);
wrtConfigTxn.put(vpnIfIdentifier, vpnIfBuilder.build());
}
} catch (IllegalStateException | ExecutionException | InterruptedException ex) {
// FIXME: why are we catching IllegalStateException here?
LOG.error("Update of vpninterface {} failed", infName, ex);
}
}
}
Aggregations