use of org.opendaylight.mdsal.binding.api.DataBroker in project netvirt by opendaylight.
the class VpnServiceChainUtils method getAllVpnIfaceNames.
public static List<String> getAllVpnIfaceNames(DataBroker dataBroker, String vpnName) {
String vpnRd = getVpnRd(dataBroker, vpnName);
InstanceIdentifier<VpnInstanceOpDataEntry> vpnOpDataIid = InstanceIdentifier.builder(VpnInstanceOpData.class).child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(vpnRd)).build();
try {
VpnInstanceOpDataEntry vpnOpData = SingleTransactionDataBroker.syncRead(dataBroker, LogicalDatastoreType.OPERATIONAL, vpnOpDataIid);
if (vpnOpData == null) {
return Collections.emptyList();
}
List<VpnToDpnList> dpnToVpns = vpnOpData.getVpnToDpnList();
if (dpnToVpns == null) {
return Collections.emptyList();
}
return dpnToVpns.stream().filter(dpn -> dpn.getVpnInterfaces() != null).flatMap(dpn -> dpn.getVpnInterfaces().stream()).map(VpnInterfaces::getInterfaceName).collect(Collectors.toList());
} catch (InterruptedException | ExecutionException e) {
LOG.warn("getAllVpnInterfaces for vpn {}: Failure on read operation", vpnName, e);
return Collections.emptyList();
}
}
use of org.opendaylight.mdsal.binding.api.DataBroker in project netvirt by opendaylight.
the class L2GatewayListener method removeL2Device.
private void removeL2Device(Devices l2Device, L2gateway input) {
final String l2DeviceName = l2Device.getDeviceName();
L2GatewayDevice l2GwDevice = l2GatewayCache.get(l2DeviceName);
if (l2GwDevice != null) {
// Also, do not delete device from cache if it's connected
if (L2GatewayUtils.isLastL2GatewayBeingDeleted(l2GwDevice)) {
if (l2GwDevice.isConnected()) {
/*
l2GwDevice.removeL2GatewayId(input.getUuid());
// Delete ITM tunnels
final String hwvtepId = l2GwDevice.getHwvtepNodeId();
final Set<IpAddress> tunnelIps = l2GwDevice.getTunnelIps();
jobCoordinator.enqueueJob(hwvtepId, () -> {
if (entityOwnershipUtils.isEntityOwner(HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
HwvtepSouthboundConstants.ELAN_ENTITY_NAME)) {
LOG.info("Deleting ITM Tunnels for {} connected to cluster node owner", l2DeviceName);
for (IpAddress tunnelIp : tunnelIps) {
L2GatewayUtils.deleteItmTunnels(itmRpcService, hwvtepId, l2DeviceName, tunnelIp);
}
} else {
LOG.info("ITM Tunnels are not deleted on the cluster node as this is not owner for {}",
l2DeviceName);
}
return null;
});
*/
} else {
l2GatewayCache.remove(l2DeviceName);
}
l2GwDevice.removeL2GatewayId(input.getUuid());
// Delete itm tunnels
elanClusterUtils.runOnlyInOwnerNode(l2GwDevice.getDeviceName(), "handling delete of l2gwdevice delete itm tunnels ", () -> {
if (l2GwDevice.getHwvtepNodeId() == null) {
return Collections.emptyList();
}
// Cleaning up the config DS
NodeId nodeId = new NodeId(l2GwDevice.getHwvtepNodeId());
LOG.info("L2GatewayListener deleting the config nodes {} {}", nodeId, l2DeviceName);
NodeId psNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, l2DeviceName);
InstanceIdentifier<Node> psNodeIid = HwvtepSouthboundUtils.createInstanceIdentifier(psNodeId);
InstanceIdentifier<Node> globalIid = HwvtepSouthboundUtils.createInstanceIdentifier(nodeId);
List<ListenableFuture<?>> result = new ArrayList<>();
result.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
LOG.info("Deleting the zero day config for l2gw delete {}", psNodeIid);
l2gwZeroDayConfigUtil.deleteZeroDayConfig(tx, globalIid, l2GwDevice);
}));
LOG.info("L2GatewayListener Deleting itm tunnels for {}", l2GwDevice.getDeviceName());
for (final IpAddress tunnelIpAddr : l2GwDevice.getTunnelIps()) {
L2GatewayUtils.deleteItmTunnels(itmRpcService, l2GwDevice.getHwvtepNodeId(), l2DeviceName, tunnelIpAddr);
// result.add(ElanL2GatewayUtils.deleteItmTunnels(tunnelIpAddr, dataBroker));
LOG.info("L2GatewayListener Deleting itm tunnel {}", tunnelIpAddr);
}
return result;
});
} else {
l2GwDevice.removeL2GatewayId(input.getUuid());
LOG.info("ITM tunnels are not deleted for {} as this device has other L2gateway associations", l2DeviceName);
}
} else {
LOG.error("L2GatewayListener Unable to find L2 Gateway details for {}", l2DeviceName);
}
}
use of org.opendaylight.mdsal.binding.api.DataBroker in project netvirt by opendaylight.
the class NexthopManager method getDcGwIps.
private List<String> getDcGwIps() {
InstanceIdentifier<DcGatewayIpList> dcGatewayIpListid = InstanceIdentifier.builder(DcGatewayIpList.class).build();
DcGatewayIpList dcGatewayIpListConfig;
try {
dcGatewayIpListConfig = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, dcGatewayIpListid).orElse(null);
} catch (ExecutionException | InterruptedException e) {
LOG.error("getDcGwIps: Exception while reading DcGatewayIpList DS", e);
return Collections.emptyList();
}
if (dcGatewayIpListConfig == null) {
return Collections.emptyList();
}
return new ArrayList<DcGatewayIp>(dcGatewayIpListConfig.nonnullDcGatewayIp().values()).stream().filter(dcGwIp -> dcGwIp.getTunnnelType().equals(TunnelTypeMplsOverGre.class)).map(dcGwIp -> dcGwIp.getIpAddress().stringValue()).sorted().collect(toList());
}
use of org.opendaylight.mdsal.binding.api.DataBroker in project netvirt by opendaylight.
the class VrfEntryListener method cleanUpExternalRoutesOnDpn.
public void cleanUpExternalRoutesOnDpn(final Uint64 dpnId, final Uint32 vpnId, final String rd, final String localNextHopIp, final String remoteNextHopIp) {
LOG.trace("cleanUpExternalRoutesOnDpn : cleanup remote routes on dpn {} for vpn {}, rd {}, " + " localNexthopIp {} , remoteNexhtHopIp {}", dpnId, vpnId, rd, localNextHopIp, remoteNextHopIp);
InstanceIdentifier<VrfTables> id = buildVrfId(rd);
final VpnInstanceOpDataEntry vpnInstance = fibUtil.getVpnInstance(rd);
List<SubTransaction> txnObjects = new ArrayList<>();
final Optional<VrfTables> vrfTable;
try {
vrfTable = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
} catch (ExecutionException | InterruptedException e) {
LOG.error("getVrfEntry: Exception while reading VrfTable for the rd {} vpnId {}", rd, vpnId, e);
return;
}
if (vrfTable.isPresent()) {
jobCoordinator.enqueueJob(FibUtil.getJobKeyForVpnIdDpnId(vpnId, dpnId), () -> {
final ReentrantLock lock = lockFor(vpnInstance);
lock.lock();
try {
return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> vrfTable.get().nonnullVrfEntry().values().stream().filter(vrfEntry -> RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.BGP).forEach(bgpRouteVrfEntryHandler.getConsumerForDeletingRemoteFib(dpnId, vpnId, remoteNextHopIp, vrfTable, TransactionAdapter.toWriteTransaction(tx), txnObjects))));
} finally {
lock.unlock();
}
});
}
}
use of org.opendaylight.mdsal.binding.api.DataBroker 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);
}
}
Aggregations