use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface 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.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class NatInterfaceStateChangeListener method update.
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
LOG.trace("update : Operation Interface update event - Old: {}, New: {}", original, update);
if (!L2vlan.class.equals(update.getType())) {
LOG.debug("update : Interface {} is not Vlan Interface.Ignoring", update.getName());
return;
}
Uint64 intfDpnId = Uint64.ZERO;
String interfaceName = update.getName();
try {
intfDpnId = NatUtil.getDpIdFromInterface(update);
} catch (Exception e) {
LOG.error("update : Exception occured while retriving dpnid for interface {}", update.getName(), e);
InstanceIdentifier<VpnInterface> id = NatUtil.getVpnInterfaceIdentifier(interfaceName);
Optional<VpnInterface> cfgVpnInterface = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (!cfgVpnInterface.isPresent()) {
LOG.warn("update : Interface {} is not a VPN Interface, ignoring.", interfaceName);
return;
}
for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().nonnullVpnInstanceNames().values()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = NatUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
Optional<VpnInterfaceOpDataEntry> optVpnInterface = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, idOper);
if (optVpnInterface.isPresent()) {
intfDpnId = optVpnInterface.get().getDpnId();
break;
}
}
}
if (Uint64.ZERO.equals(intfDpnId)) {
LOG.warn("remove : Could not retrieve dpnid for interface {} ", interfaceName);
return;
}
RouterInterface routerInterface = NatUtil.getConfiguredRouterInterface(dataBroker, interfaceName);
if (routerInterface != null) {
this.southboundEventHandlers.handleUpdate(original, update, intfDpnId, routerInterface);
} else {
LOG.info("update : Router-Interface Mapping not found for Interface : {}", interfaceName);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class NatInterfaceStateChangeListener method remove.
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
LOG.trace("remove : Interface {} removed event received", intrf);
if (!L2vlan.class.equals(intrf.getType())) {
LOG.debug("remove : Interface {} is not Vlan Interface.Ignoring", intrf.getName());
return;
}
String interfaceName = intrf.getName();
Uint64 intfDpnId = Uint64.ZERO;
try {
intfDpnId = NatUtil.getDpIdFromInterface(intrf);
} catch (Exception e) {
LOG.error("remove : Exception occured while retriving dpnid for interface {}", intrf.getName(), e);
InstanceIdentifier<VpnInterface> id = NatUtil.getVpnInterfaceIdentifier(interfaceName);
Optional<VpnInterface> cfgVpnInterface = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (!cfgVpnInterface.isPresent()) {
LOG.warn("remove : Interface {} is not a VPN Interface, ignoring.", interfaceName);
return;
}
for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().nonnullVpnInstanceNames().values()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = NatUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
Optional<VpnInterfaceOpDataEntry> optVpnInterface = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, idOper);
if (optVpnInterface.isPresent()) {
intfDpnId = optVpnInterface.get().getDpnId();
break;
}
}
}
if (Uint64.ZERO.equals(intfDpnId)) {
LOG.warn("remove : Could not retrieve dpnid for interface {} ", interfaceName);
return;
}
RouterInterface routerInterface = NatUtil.getConfiguredRouterInterface(dataBroker, interfaceName);
if (routerInterface != null) {
this.southboundEventHandlers.handleRemove(intrf.getName(), intfDpnId, routerInterface);
} else {
LOG.info("remove : Router-Interface Mapping not found for Interface : {}", interfaceName);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class NeutronvpnManager method writeVpnInterfaceToDs.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void writeVpnInterfaceToDs(@NonNull Collection<Uuid> vpnIdList, String infName, @Nullable Adjacencies adjacencies, Uuid networkUuid, Boolean isRouterInterface, TypedWriteTransaction<Configuration> wrtConfigTxn) {
if (vpnIdList.isEmpty() || infName == null) {
LOG.error("vpnid is empty or interface({}) is null", infName);
return;
}
if (wrtConfigTxn == null) {
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> writeVpnInterfaceToDs(vpnIdList, infName, adjacencies, networkUuid, isRouterInterface, tx)), LOG, "Error writing VPN interface");
return;
}
List<VpnInstanceNames> vpnIdListStruct = new ArrayList<>();
for (Uuid vpnId : vpnIdList) {
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
vpnIdListStruct.add(vpnInstance);
}
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
VpnInterfaceBuilder vpnb = new VpnInterfaceBuilder().withKey(new VpnInterfaceKey(infName)).setName(infName).setVpnInstanceNames(vpnIdListStruct).setRouterInterface(isRouterInterface);
LOG.info("Network Id is {}", networkUuid);
if (networkUuid != null) {
Network portNetwork = neutronvpnUtils.getNeutronNetwork(networkUuid);
ProviderTypes providerType = NeutronvpnUtils.getProviderNetworkType(portNetwork);
NetworkAttributes.NetworkType networkType = providerType != null ? NetworkAttributes.NetworkType.valueOf(providerType.getName()) : null;
String segmentationId = NeutronvpnUtils.getSegmentationIdFromNeutronNetwork(portNetwork);
vpnb.setNetworkId(networkUuid).setNetworkType(networkType).setSegmentationId(segmentationId != null ? Long.parseLong(segmentationId) : 0L);
}
if (adjacencies != null) {
vpnb.addAugmentation(adjacencies);
}
VpnInterface vpnIf = vpnb.build();
try {
LOG.info("Creating vpn interface {}", vpnIf);
wrtConfigTxn.put(vpnIfIdentifier, vpnIf);
} catch (Exception ex) {
LOG.error("Creation of vpninterface {} failed", infName, ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface 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