use of org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION in project netvirt by opendaylight.
the class ElanInstanceEntityOwnershipListener method ownershipChanged.
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void ownershipChanged(EntityOwnershipChange ownershipChange) {
LOG.info("Entity Ownership changed for the entity: {}", ownershipChange);
if (!ownershipChange.getState().isOwner()) {
if (ft != null) {
ft.cancel(false);
ft = null;
}
return;
}
if (!ownershipChange.getState().wasOwner() && ownershipChange.getState().isOwner()) {
if (ft != null) {
ft.cancel(false);
ft = null;
}
ft = scheduler.getScheduledExecutorService().schedule(() -> {
try {
// check if i'm the owner
if (ownershipChange.getState().isOwner()) {
LOG.info("Elan Entity owner is: {}", ownershipChange);
txRunner.callWithNewReadOnlyTransactionAndClose(CONFIGURATION, tx -> {
l2GatewayConnectionListener.loadL2GwConnectionCache(tx);
});
InstanceIdentifier<ElanDpnInterfaces> elanDpnInterfacesInstanceIdentifier = InstanceIdentifier.builder(ElanDpnInterfaces.class).build();
txRunner.callWithNewReadOnlyTransactionAndClose(OPERATIONAL, tx -> {
Optional<ElanDpnInterfaces> optional = Optional.empty();
try {
optional = tx.read(elanDpnInterfacesInstanceIdentifier).get();
} catch (ExecutionException | InterruptedException e) {
LOG.error("Exception While reading ElanDpnInterfaces", e);
}
if (optional.isPresent() && optional.get().getElanDpnInterfacesList() != null) {
LOG.debug("Found elan dpn interfaces list");
optional.get().nonnullElanDpnInterfacesList().values().forEach(elanDpnInterfacesList -> {
List<DpnInterfaces> dpnInterfaces = new ArrayList<>(elanDpnInterfacesList.nonnullDpnInterfaces().values());
InstanceIdentifier<ElanDpnInterfacesList> parentIid = InstanceIdentifier.builder(ElanDpnInterfaces.class).child(ElanDpnInterfacesList.class, new ElanDpnInterfacesListKey(elanDpnInterfacesList.getElanInstanceName())).build();
for (DpnInterfaces dpnInterface : dpnInterfaces) {
LOG.debug("Found elan dpn interfaces");
elanDpnInterfaceClusteredListener.add(parentIid.child(DpnInterfaces.class, dpnInterface.key()), dpnInterface);
}
});
}
});
} else {
LOG.info("Not the owner for Elan entity {}", ownershipChange);
}
ft = null;
} catch (Exception e) {
LOG.error("Failed to read mdsal ", e);
}
}, ELAN_EOS_DELAY, TimeUnit.MINUTES);
}
}
use of org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnForSubnet.
@Nullable
private Subnetmap updateVpnForSubnet(Uuid oldVpnId, Uuid newVpnId, Uuid subnet, boolean isBeingAssociated) {
LOG.debug("Moving subnet {} from oldVpn {} to newVpn {} ", subnet.getValue(), oldVpnId.getValue(), newVpnId.getValue());
Uuid networkUuid = neutronvpnUtils.getSubnetmap(subnet).getNetworkId();
Network network = neutronvpnUtils.getNeutronNetwork(networkUuid);
boolean netIsExternal = NeutronvpnUtils.getIsExternal(network);
Uuid vpnExtUuid = netIsExternal ? neutronvpnUtils.getInternetvpnUuidBoundToSubnetRouter(subnet) : null;
Subnetmap sn = updateSubnetNode(subnet, null, newVpnId, vpnExtUuid);
if (sn == null) {
LOG.error("Updating subnet {} with newVpn {} failed", subnet.getValue(), newVpnId.getValue());
return sn;
}
/* vpnExtUuid will contain the value only on if the subnet is V6 and it is already been
* associated with internet BGP-VPN.
*/
if (vpnExtUuid != null) {
/* Update V6 Internet default route match with new VPN metadata.
* isBeingAssociated = true means oldVpnId is same as routerId
* isBeingAssociated = false means newVpnId is same as routerId
*/
if (isBeingAssociated) {
neutronvpnUtils.updateVpnInstanceWithFallback(oldVpnId, vpnExtUuid, true);
} else {
neutronvpnUtils.updateVpnInstanceWithFallback(newVpnId, vpnExtUuid, true);
}
}
// Update Router Interface first synchronously.
// CAUTION: Please DONOT make the router interface VPN Movement as an asynchronous commit again !
ListenableFuture<?> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> updateVpnInterface(newVpnId, oldVpnId, neutronvpnUtils.getNeutronPort(sn.getRouterInterfacePortId()), isBeingAssociated, true, tx, false));
Futures.addCallback(future, new FutureCallback<Object>() {
@Override
public void onSuccess(Object result) {
// Check for ports on this subnet and update association of
// corresponding vpn-interfaces to external vpn
List<Uuid> portList = sn.getPortList();
if (portList != null) {
for (Uuid port : portList) {
LOG.debug("Updating vpn-interface for port {} isBeingAssociated {}", port.getValue(), isBeingAssociated);
jobCoordinator.enqueueJob("PORT-" + port.getValue(), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> updateVpnInterface(newVpnId, oldVpnId, neutronvpnUtils.getNeutronPort(port), isBeingAssociated, false, tx, false))));
}
}
}
@Override
public void onFailure(Throwable throwable) {
LOG.error("Failed to update router interface {} in subnet {} from oldVpnId {} to newVpnId {}, " + "returning", sn.getRouterInterfacePortId().getValue(), subnet.getValue(), oldVpnId, newVpnId, throwable);
}
}, MoreExecutors.directExecutor());
return sn;
}
use of org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION in project netvirt by opendaylight.
the class NeutronvpnManager method deleteVpnInterface.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void deleteVpnInterface(String infName, @Nullable String vpnId, @Nullable TypedWriteTransaction<Configuration> wrtConfigTxn) {
if (wrtConfigTxn == null) {
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> deleteVpnInterface(infName, vpnId, tx)), LOG, "Error deleting VPN interface {} {}", infName, vpnId);
return;
}
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
Optional<VpnInterface> optionalVpnInterface;
try {
optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
} catch (ExecutionException | InterruptedException ex) {
LOG.error("Error during deletion of vpninterface {}", infName, ex);
return;
}
if (!optionalVpnInterface.isPresent()) {
LOG.warn("Deletion of vpninterface {}, optionalVpnInterface is not present()", infName);
return;
}
if (vpnId != null) {
VpnInterface vpnInterface = optionalVpnInterface.get();
Map<VpnInstanceNamesKey, VpnInstanceNames> keyVpnInstanceNamesMap = vpnInterface.getVpnInstanceNames();
if (keyVpnInstanceNamesMap != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId, new ArrayList<>(keyVpnInstanceNamesMap.values()))) {
VpnHelper.removeVpnInterfaceVpnInstanceNamesFromList(vpnId, new ArrayList<>(keyVpnInstanceNamesMap.values()));
if (!keyVpnInstanceNamesMap.isEmpty()) {
LOG.debug("Deleting vpn interface {} not immediately since vpnInstanceName " + "List not empty", infName);
return;
}
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get()).setVpnInstanceNames(keyVpnInstanceNamesMap);
wrtConfigTxn.put(vpnIfIdentifier, vpnIfBuilder.build());
}
}
LOG.debug("Deleting vpn interface {}", infName);
wrtConfigTxn.delete(vpnIfIdentifier);
}
use of org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION in project netvirt by opendaylight.
the class NeutronPortChangeListener method handleRouterInterfaceRemoved.
private void handleRouterInterfaceRemoved(Port routerPort) {
if (routerPort.getDeviceId() != null) {
Uuid routerId = new Uuid(routerPort.getDeviceId());
Uuid infNetworkId = routerPort.getNetworkId();
elanService.removeKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
Uuid vpnId = ObjectUtils.defaultIfNull(neutronvpnUtils.getVpnForRouter(routerId, true), routerId);
Map<FixedIpsKey, FixedIps> keyFixedIpsMap = routerPort.nonnullFixedIps();
boolean vpnInstanceInternetIpVersionRemoved = false;
Uuid vpnInstanceInternetUuid = null;
for (FixedIps portIP : keyFixedIpsMap.values()) {
// Internet VPN : flush InternetVPN first
Uuid subnetId = portIP.getSubnetId();
Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
if (sn != null && sn.getInternetVpnId() != null) {
if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, sn.getInternetVpnId())) {
vpnInstanceInternetIpVersionRemoved = true;
vpnInstanceInternetUuid = sn.getInternetVpnId();
}
nvpnManager.updateVpnInternetForSubnet(sn, sn.getInternetVpnId(), false);
}
}
/* Remove ping responder for router interfaces
* A router interface reference in a VPN will have to be removed before the host interface references
* for that subnet in the VPN are removed. This is to ensure that the FIB Entry of the router interface
* is not the last entry to be removed for that subnet in the VPN.
* If router interface FIB entry is the last to be removed for a subnet in a VPN , then all the host
* interface references in the vpn will already have been cleared, which will cause failures in
* cleanup of router interface flows*/
nvpnManager.deleteVpnInterface(routerPort.getUuid().getValue(), null, /* vpn-id */
null);
// update RouterInterfaces map
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
for (FixedIps portIP : keyFixedIpsMap.values()) {
Subnetmap sn = neutronvpnUtils.getSubnetmap(portIP.getSubnetId());
if (null == sn) {
LOG.error("Subnetmap for subnet {} not found", portIP.getSubnetId().getValue());
continue;
}
// router Port have either IPv4 or IPv6, never both
ipVersion = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
String ipValue = portIP.getIpAddress().stringValue();
neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, confTx);
// NOTE: Please donot change the order of calls to removeSubnetFromVpn and
// and updateSubnetNodeWithFixedIP
nvpnManager.removeSubnetFromVpn(vpnId, sn, sn.getInternetVpnId());
nvpnManager.updateSubnetNodeWithFixedIp(portIP.getSubnetId(), null, null, null, null, null);
}
nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
deleteElanInterface(routerPort.getUuid().getValue(), confTx);
deleteOfPortInterface(routerPort, confTx);
jobCoordinator.enqueueJob(routerId.toString(), () -> {
nvpnNatManager.handleSubnetsForExternalRouter(routerId);
return Collections.emptyList();
});
if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(ipVersion, routerId, false)) {
LOG.debug("vpnInstanceOpDataEntry is getting update with ip address family {} for VPN {}", ipVersion, vpnId.getValue());
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, false);
}
}), LOG, "Error handling interface removal");
if (vpnInstanceInternetIpVersionRemoved) {
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnInstanceInternetUuid.getValue(), IpVersionChoice.IPV6, false);
neutronvpnUtils.updateVpnInstanceWithFallback(routerId, vpnInstanceInternetUuid, false);
}
}
}
use of org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION in project netvirt by opendaylight.
the class NeutronPortChangeListener method handleRouterInterfaceAdded.
private void handleRouterInterfaceAdded(Port routerPort) {
if (routerPort.getDeviceId() != null) {
Uuid routerId = new Uuid(routerPort.getDeviceId());
Uuid infNetworkId = routerPort.getNetworkId();
Uuid existingVpnId = neutronvpnUtils.getVpnForNetwork(infNetworkId);
elanService.addKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
if (existingVpnId == null) {
Set<Uuid> listVpnIds = new HashSet<>();
Uuid vpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
if (vpnId == null) {
vpnId = routerId;
}
listVpnIds.add(vpnId);
Uuid internetVpnId = neutronvpnUtils.getInternetvpnUuidBoundToRouterId(routerId);
List<Subnetmap> subnetMapList = new ArrayList<>();
boolean portIsIpv6 = false;
for (FixedIps portIP : routerPort.nonnullFixedIps().values()) {
// and addSubnetToVpn here
if (internetVpnId != null && portIP.getIpAddress().getIpv6Address() != null) {
portIsIpv6 = true;
}
String ipValue = portIP.getIpAddress().stringValue();
Uuid subnetId = portIP.getSubnetId();
nvpnManager.updateSubnetNodeWithFixedIp(subnetId, routerId, routerPort.getUuid(), ipValue, routerPort.getMacAddress().getValue(), vpnId);
Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
subnetMapList.add(sn);
}
if (portIsIpv6) {
listVpnIds.add(internetVpnId);
if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(IpVersionChoice.IPV6, routerId, true)) {
neutronvpnUtils.updateVpnInstanceWithIpFamily(internetVpnId.getValue(), IpVersionChoice.IPV6, true);
neutronvpnUtils.updateVpnInstanceWithFallback(routerId, internetVpnId, true);
}
}
if (!subnetMapList.isEmpty()) {
nvpnManager.createVpnInterface(listVpnIds, routerPort, null);
}
IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
for (FixedIps portIP : routerPort.nonnullFixedIps().values()) {
String ipValue = portIP.getIpAddress().stringValue();
ipVersion = NeutronvpnUtils.getIpVersionFromString(ipValue);
if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV4)) {
nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId(), null);
} else {
nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId(), internetVpnId);
}
LOG.trace("NeutronPortChangeListener Add Subnet Gateway IP {} MAC {} Interface {} VPN {}", ipValue, routerPort.getMacAddress(), routerPort.getUuid().getValue(), vpnId.getValue());
}
if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(ipVersion, routerId, true)) {
LOG.debug("vpnInstanceOpDataEntry is getting update with ip address family {} for VPN {}", ipVersion, vpnId.getValue());
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, true);
}
nvpnManager.addToNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
jobCoordinator.enqueueJob(routerId.toString(), () -> {
nvpnNatManager.handleSubnetsForExternalRouter(routerId);
return Collections.emptyList();
});
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
String portInterfaceName = createOfPortInterface(routerPort, confTx);
createElanInterface(routerPort, portInterfaceName, confTx);
}), LOG, "Error creating ELAN interface for {}", routerPort);
} else {
LOG.error("Neutron network {} corresponding to router interface port {} for neutron router {}" + " already associated to VPN {}", infNetworkId.getValue(), routerPort.getUuid().getValue(), routerId.getValue(), existingVpnId.getValue());
}
}
}
Aggregations