use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class ExternalRoutersListener method remove.
@Override
public void remove(InstanceIdentifier<Routers> identifier, Routers router) {
if (natMode != NatMode.Controller) {
return;
}
LOG.trace("remove : Router delete method");
if (identifier == null || router == null) {
LOG.error("remove : returning without processing since routers is null");
return;
}
String routerName = router.getRouterName();
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + router.key(), () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
LOG.info("remove : Removing default NAT route from FIB on all dpns part of router {} ", routerName);
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("remove : Remove external router event - Invalid routerId for routerName {}", routerName);
return;
}
Uint32 bgpVpnId = NatConstants.INVALID_ID;
Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
if (bgpVpnUuid != null) {
bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
}
addOrDelDefFibRouteToSNAT(routerName, routerId, bgpVpnId, bgpVpnUuid, false, tx);
Uuid networkUuid = router.getNetworkId();
Uint64 primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
if (primarySwitchId == null || primarySwitchId.equals(Uint64.ZERO)) {
// No NAPT switch for external router, probably because the router is not attached to
// any
// internal networks
LOG.debug("No NAPT switch for router {}, check if router is attached to any internal " + "network", routerName);
return;
} else {
Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkUuid);
handleDisableSnat(router, networkUuid, externalIps, true, vpnName, primarySwitchId, routerId, tx);
}
if (NatUtil.releaseId(idManager, NatConstants.ODL_VNI_POOL_NAME, routerName) == NatConstants.INVALID_ID) {
LOG.error("remove: Unable to release VNI for router - {}", routerName);
}
})), NatConstants.NAT_DJC_MAX_RETRIES);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class ExternalNetworksChangeListener method disassociateExternalNetworkFromVPN.
private void disassociateExternalNetworkFromVPN(Networks network, String vpnName) {
if (network.getRouterIds() != null) {
for (Uuid routerId : network.getRouterIds()) {
InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerId.getValue());
Optional<RouterPorts> optRouterPorts = Optional.empty();
try {
optRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
} catch (ExecutionException | InterruptedException e) {
LOG.error("disassociateExternalNetworkFromVPN: Exception while reading RouterPorts DS for the " + "router {} network {} vpn {}", routerId, network.getId().getValue(), vpnName, e);
}
if (!optRouterPorts.isPresent()) {
LOG.debug("disassociateExternalNetworkFromVPN : Could not read Router Ports data object with id: {} " + "to handle disassociate ext nw {}", routerId, network.getId());
continue;
}
RouterPorts routerPorts = optRouterPorts.get();
for (Ports port : routerPorts.nonnullPorts().values()) {
String portName = port.getPortName();
Uint64 dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
if (dpnId.equals(Uint64.ZERO)) {
LOG.debug("disassociateExternalNetworkFromVPN : DPN not found for {}," + "skip handling of ext nw {} disassociation", portName, network.getId());
continue;
}
for (InternalToExternalPortMap intExtPortMap : port.nonnullInternalToExternalPortMap().values()) {
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + intExtPortMap.key(), () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> floatingIpListener.removeNATFlowEntries(dpnId, portName, vpnName, routerId.getValue(), intExtPortMap, tx))), NatConstants.NAT_DJC_MAX_RETRIES);
}
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class FloatingIPListener method createNATFlowEntries.
void createNATFlowEntries(Uint64 dpnId, String interfaceName, String routerName, Uuid externalNetworkId, InternalToExternalPortMap mapping, TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("createNATFlowEntries : Could not retrieve router id for {} to create NAT Flow entries", routerName);
return;
}
// Check if the router to vpn association is present
Uint32 associatedVpnId = NatUtil.getAssociatedVpn(dataBroker, routerName);
if (associatedVpnId == NatConstants.INVALID_ID) {
LOG.debug("createNATFlowEntries : Router {} is not assicated with any BGP VPN instance", routerName);
} else {
LOG.debug("createNATFlowEntries : Router {} is associated with VPN Instance with Id {}", routerName, associatedVpnId);
// routerId = associatedVpnId;
}
Uuid vpnUuid = getVpnUuid(externalNetworkId, mapping.getExternalId());
LOG.trace("createNATFlowEntries : vpnUuid {} for External Network {}", vpnUuid, externalNetworkId);
if (vpnUuid == null) {
LOG.error("createNATFlowEntries : No vpnUuid associated with Ext nw {}. Unable to create SNAT table entry" + " for fixed ip {}", externalNetworkId, mapping.getInternalIp());
return;
}
VpnInstance vpnInstance = NatUtil.getVpnIdToVpnInstance(dataBroker, vpnUuid.getValue());
if (vpnInstance == null || vpnInstance.getVpnId() == null) {
LOG.error("createNATFlowEntries: VpnInstance associated with Ext nw {}. Unable to create SNAT table entry" + " for fixed ip {}", externalNetworkId, mapping.getInternalIp());
return;
}
// Install the DNAT default FIB flow L3_FIB_TABLE (21) -> PSNAT_TABLE (26) if SNAT is disabled
boolean isSnatEnabled = NatUtil.isSnatEnabledForRouterId(dataBroker, routerName);
if (!isSnatEnabled) {
addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, confTx, true);
}
// Create the DNAT and SNAT table entries
Uint32 vpnId = vpnInstance.getVpnId();
String vrfId = vpnInstance.getVrfId();
createDNATTblEntry(dpnId, mapping, routerId, associatedVpnId, confTx);
createSNATTblEntry(dpnId, mapping, vpnId, routerId, associatedVpnId, externalNetworkId, confTx);
floatingIPHandler.onAddFloatingIp(dpnId, routerName, routerId, externalNetworkId, interfaceName, mapping, vrfId, confTx);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class FloatingIPListener method removeNATFlowEntries.
void removeNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping, InstanceIdentifier<RouterPorts> portIid, final String routerName, @Nullable Uint64 dpnId, TypedReadWriteTransaction<Configuration> removeFlowInvTx) throws ExecutionException, InterruptedException {
Uuid extNwId = getExtNetworkId(portIid, LogicalDatastoreType.OPERATIONAL);
if (extNwId == null) {
LOG.error("removeNATFlowEntries : External network associated with interface {} could not be retrieved", interfaceName);
return;
}
// For FLAT/VLAN Networks, get the DPN with provider_mappings for external network.
if (dpnId == null) {
dpnId = getAssociatedDpnWithExternalInterface(routerName, extNwId, NatUtil.getDpnForInterface(interfaceManager, interfaceName), interfaceName);
if (dpnId == null || dpnId.equals(Uint64.ZERO)) {
LOG.warn("removeNATFlowEntries: Abort processing Floating ip configuration. No DPN for port: {}", interfaceName);
return;
}
}
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("removeNATFlowEntries : Could not retrieve router id for {} to remove NAT Flow entries", routerName);
return;
}
String internalIp = mapping.getInternalIp();
String externalIp = mapping.getExternalIp();
// Delete the DNAT and SNAT table entries
removeDNATTblEntry(dpnId, internalIp, externalIp, routerId, removeFlowInvTx);
Uuid vpnUuid = getVpnUuid(extNwId, mapping.getExternalId());
if (vpnUuid == null) {
LOG.error("removeNATFlowEntries : No VPN associated with Ext nw {}. Unable to remove SNAT table entry " + "for fixed ip {}", extNwId, mapping.getInternalIp());
return;
}
VpnInstance vpnInstance = NatUtil.getVpnIdToVpnInstance(dataBroker, vpnUuid.getValue());
if (vpnInstance == null || vpnInstance.getVpnId() == null) {
LOG.error("removeNATFlowEntries: No VPN associated with Ext nw {}. Unable to create SNAT table entry " + "for fixed ip {}", extNwId, mapping.getInternalIp());
return;
}
Uint32 vpnId = vpnInstance.getVpnId();
String vrfId = vpnInstance.getVrfId();
removeSNATTblEntry(dpnId, internalIp, externalIp, routerId, vpnId, removeFlowInvTx);
// Remove the DNAT default FIB flow L3_FIB_TABLE (21) -> PSNAT_TABLE (26) if SNAT is disabled
boolean isSnatEnabled = NatUtil.isSnatEnabledForRouterId(dataBroker, routerName);
if (!isSnatEnabled) {
addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, removeFlowInvTx, false);
}
ProviderTypes provType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNwId);
if (provType == null) {
LOG.error("removeNATFlowEntries : External Network Provider Type missing");
return;
}
if (provType == ProviderTypes.VXLAN) {
floatingIPHandler.onRemoveFloatingIp(dpnId, routerName, routerId, extNwId, mapping, NatConstants.DEFAULT_L3VNI_VALUE, vrfId, removeFlowInvTx);
removeOperationalDS(routerName, interfaceName, internalIp);
return;
}
Uint32 label = getOperationalIpMapping(routerName, interfaceName, internalIp);
if (label.longValue() < 0) {
LOG.error("removeNATFlowEntries : Could not retrieve label for prefix {} in router {}", internalIp, routerId);
return;
}
floatingIPHandler.onRemoveFloatingIp(dpnId, routerName, routerId, extNwId, mapping, label, vrfId, removeFlowInvTx);
removeOperationalDS(routerName, interfaceName, internalIp);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class FloatingIPListener method getAssociatedDpnWithExternalInterface.
private Uint64 getAssociatedDpnWithExternalInterface(final String routerName, Uuid extNwId, Uint64 dpnId, String interfaceName) {
// Get the DPN on which this interface resides
if (dpnId == null) {
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) {
dpnId = NatUtil.getDpIdFromInterface(interfaceState);
}
}
Uint64 updatedDpnId = dpnId;
if (updatedDpnId != null && updatedDpnId.equals(Uint64.ZERO)) {
LOG.debug("getAssociatedDpnWithExternalInterface : The interface {} is not associated with any dpn", interfaceName);
return updatedDpnId;
}
ProviderTypes providerType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNwId);
if (providerType == null) {
LOG.warn("getAssociatedDpnWithExternalInterface : Provider Network Type for router {} and" + " externalNetwork {} is missing.", routerName, extNwId);
return updatedDpnId;
}
// mappings) and then sent out on the external Network.
if (providerType == ProviderTypes.FLAT || providerType == ProviderTypes.VLAN) {
String providerNet = NatUtil.getElanInstancePhysicalNetwok(extNwId.getValue(), dataBroker);
boolean isDpnConnected = natSwitchCache.isSwitchConnectedToExternal(updatedDpnId, providerNet);
if (!isDpnConnected) {
updatedDpnId = centralizedSwitchScheduler.getCentralizedSwitch(routerName);
}
}
return updatedDpnId;
}
Aggregations