use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.
the class ExternalRoutersListener method update.
@Override
public void update(InstanceIdentifier<Routers> identifier, Routers original, Routers update) {
if (natMode != NatMode.Controller) {
return;
}
LOG.trace("update : origRouter: {} updatedRouter: {}", original, update);
String routerName = original.getRouterName();
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("update : external router event - Invalid routerId for routerName {}", routerName);
return;
}
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + update.key(), () -> {
List<ListenableFuture<?>> futures = new ArrayList<>();
futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, writeFlowInvTx -> {
futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, removeFlowInvTx -> {
Uint32 bgpVpnId = NatConstants.INVALID_ID;
Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
if (bgpVpnUuid != null) {
bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
}
// BigInteger dpnId = getPrimaryNaptSwitch(routerName);
/* Get Primary Napt Switch for existing router from "router-to-napt-switch" DS.
* if dpnId value is null or zero then go for electing new Napt switch for existing router.
*/
Uint64 dpnId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
boolean isPrimaryNaptSwitchNotSelected = (dpnId == null || dpnId.equals(Uint64.valueOf(BigInteger.ZERO)));
Uuid networkId = original.getNetworkId();
// Check if its update on SNAT flag
boolean originalSNATEnabled = original.isEnableSnat();
boolean updatedSNATEnabled = update.isEnableSnat();
LOG.debug("update :called with originalFlag and updatedFlag for SNAT enabled " + "as {} and {} with Elected Dpn {}(isPrimaryNaptSwitchNotSelected:{})", originalSNATEnabled, updatedSNATEnabled, dpnId, isPrimaryNaptSwitchNotSelected);
// 3. First Elect dpnId and process other changes with valid dpnId
if (originalSNATEnabled != updatedSNATEnabled || isPrimaryNaptSwitchNotSelected) {
if (originalSNATEnabled && !updatedSNATEnabled) {
if (isPrimaryNaptSwitchNotSelected) {
LOG.info("No Action to be taken when SNAT is disabled " + "with no Napt Switch Election for Router {}", routerName);
return;
}
// SNAT disabled for the router
Uuid networkUuid = original.getNetworkId();
LOG.info("update : SNAT disabled for Router {}", routerName);
Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
handleDisableSnat(original, networkUuid, externalIps, false, vpnName, dpnId, routerId, removeFlowInvTx);
} else if (updatedSNATEnabled) {
LOG.info("update : SNAT enabled for Router {}", routerName);
addOrDelDefFibRouteToSNAT(routerName, routerId, bgpVpnId, bgpVpnUuid, true, writeFlowInvTx);
if (isPrimaryNaptSwitchNotSelected) {
dpnId = selectNewNAPTSwitch(routerName);
if (dpnId != null && !dpnId.equals(Uint64.valueOf(BigInteger.ZERO))) {
handleEnableSnat(update, routerId, dpnId, bgpVpnId, removeFlowInvTx);
} else {
LOG.error("update : Failed to elect Napt Switch During update event" + " of router {}", routerName);
}
}
}
LOG.info("update : no need to process external/subnet changes as it's will taken care" + "in handleDisableSnat/handleEnableSnat");
return;
}
if (!Objects.equals(original.getExtGwMacAddress(), update.getExtGwMacAddress())) {
NatUtil.installRouterGwFlows(txRunner, vpnManager, original, dpnId, NwConstants.DEL_FLOW);
NatUtil.installRouterGwFlows(txRunner, vpnManager, update, dpnId, NwConstants.ADD_FLOW);
}
if (updatedSNATEnabled != originalSNATEnabled) {
LOG.info("update : no need to process external/subnet changes as it's will taken care in " + "handleDisableSnat/handleEnableSnat");
return;
}
// Check if the Update is on External IPs
LOG.debug("update : Checking if this is update on External IPs for router {}", routerName);
List<String> originalExternalIps = NatUtil.getIpsListFromExternalIps(new ArrayList<ExternalIps>(original.nonnullExternalIps().values()));
List<String> updatedExternalIps = NatUtil.getIpsListFromExternalIps(new ArrayList<ExternalIps>(update.nonnullExternalIps().values()));
// Check if the External IPs are removed during the update.
Set<String> removedExternalIps = new HashSet<>(originalExternalIps);
removedExternalIps.removeAll(updatedExternalIps);
if (removedExternalIps.size() > 0) {
LOG.debug("update : Start processing of the External IPs removal for router {}", routerName);
vpnManager.removeArpResponderFlowsToExternalNetworkIps(routerName, removedExternalIps, original.getExtGwMacAddress(), dpnId, networkId);
for (String removedExternalIp : removedExternalIps) {
/*
1) Remove the mappings in the IntExt IP model which has external IP.
2) Remove the external IP in the ExternalCounter model.
3) For the corresponding subnet IDs whose external IP mapping was removed, allocate one of the
least loaded external IP.
Store the subnet IP and the reallocated external IP mapping in the IntExtIp model.
4) Increase the count of the allocated external IP by one.
5) Advertise to the BGP if external IP is allocated for the first time for the router
i.e. the route for the external IP is absent.
6) Remove the NAPT translation entries from Inbound and Outbound NAPT tables for
the removed external IPs and also from the model.
7) Advertise to the BGP for removing the route for the removed external IPs.
*/
String[] externalIpParts = NatUtil.getExternalIpAndPrefix(removedExternalIp);
String externalIp = externalIpParts[0];
String externalIpPrefix = externalIpParts[1];
String externalIpAddrStr = externalIp + "/" + externalIpPrefix;
LOG.debug("update : Clear the routes from the BGP and remove the FIB and TS " + "entries for removed external IP {}", externalIpAddrStr);
Uuid vpnUuId = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
String vpnName = "";
if (vpnUuId != null) {
vpnName = vpnUuId.getValue();
}
clrRtsFromBgpAndDelFibTs(dpnId, routerId, externalIpAddrStr, vpnName, networkId, update.getExtGwMacAddress(), removeFlowInvTx);
LOG.debug("update : Remove the mappings in the IntExtIP model which has external IP.");
// Get the internal IPs which are associated to the removed external IPs
List<IpMap> ipMaps = naptManager.getIpMapList(dataBroker, routerId);
List<String> removedInternalIps = new ArrayList<>();
for (IpMap ipMap : ipMaps) {
if (ipMap.getExternalIp().equals(externalIpAddrStr)) {
removedInternalIps.add(ipMap.getInternalIp());
}
}
LOG.debug("update : Remove the mappings of the internal IPs from the IntExtIP model.");
for (String removedInternalIp : removedInternalIps) {
LOG.debug("update : Remove the IP mapping of the internal IP {} for the " + "router ID {} from the IntExtIP model", removedInternalIp, routerId);
naptManager.removeFromIpMapDS(routerId, removedInternalIp);
}
LOG.debug("update : Remove the count mapping of the external IP {} for the " + "router ID {} from the ExternalIpsCounter model.", externalIpAddrStr, routerId);
naptManager.removeExternalIpCounter(routerId, externalIpAddrStr);
LOG.debug("update : Allocate the least loaded external IPs to the subnets " + "whose external IPs were removed.");
for (String removedInternalIp : removedInternalIps) {
allocateExternalIp(dpnId, update, routerId, routerName, networkId, removedInternalIp, writeFlowInvTx);
}
LOG.debug("update : Remove the NAPT translation entries from " + "Inbound and Outbound NAPT tables for the removed external IPs.");
// Get the internalIP and internal Port which were associated to the removed external IP.
Map<ProtocolTypes, List<String>> protoTypesIntIpPortsMap = new HashMap<>();
InstanceIdentifier<IpPortMapping> ipPortMappingId = InstanceIdentifier.builder(IntextIpPortMap.class).child(IpPortMapping.class, new IpPortMappingKey(routerId)).build();
Optional<IpPortMapping> ipPortMapping;
try {
ipPortMapping = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, ipPortMappingId);
} catch (InterruptedException | ExecutionException e) {
LOG.error("Failed to read ipPortMapping for router id {}", routerId, e);
ipPortMapping = Optional.empty();
}
if (ipPortMapping.isPresent()) {
for (IntextIpProtocolType intextIpProtocolType : ipPortMapping.get().nonnullIntextIpProtocolType().values()) {
ProtocolTypes protoType = intextIpProtocolType.getProtocol();
for (IpPortMap ipPortMap : intextIpProtocolType.nonnullIpPortMap().values()) {
IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
if (ipPortExternal.getIpAddress().equals(externalIp)) {
List<String> removedInternalIpPorts = protoTypesIntIpPortsMap.get(protoType);
if (removedInternalIpPorts != null) {
removedInternalIpPorts.add(ipPortMap.getIpPortInternal());
protoTypesIntIpPortsMap.put(protoType, removedInternalIpPorts);
} else {
removedInternalIpPorts = new ArrayList<>();
removedInternalIpPorts.add(ipPortMap.getIpPortInternal());
protoTypesIntIpPortsMap.put(protoType, removedInternalIpPorts);
}
}
}
}
}
// Remove the IP port map from the intext-ip-port-map model, which were containing
// the removed external IP.
Set<Map.Entry<ProtocolTypes, List<String>>> protoTypesIntIpPorts = protoTypesIntIpPortsMap.entrySet();
Map<String, List<String>> internalIpPortMap = new HashMap<>();
for (Map.Entry protoTypesIntIpPort : protoTypesIntIpPorts) {
ProtocolTypes protocolType = (ProtocolTypes) protoTypesIntIpPort.getKey();
List<String> removedInternalIpPorts = (List<String>) protoTypesIntIpPort.getValue();
for (String removedInternalIpPort : removedInternalIpPorts) {
// Remove the IP port map from the intext-ip-port-map model,
// which were containing the removed external IP
naptManager.removeFromIpPortMapDS(routerId, removedInternalIpPort, protocolType);
// Remove the IP port incomint packer map.
naptPacketInHandler.removeIncomingPacketMap(routerId + NatConstants.COLON_SEPARATOR + removedInternalIpPort);
String[] removedInternalIpPortParts = removedInternalIpPort.split(NatConstants.COLON_SEPARATOR);
if (removedInternalIpPortParts.length == 2) {
String removedInternalIp = removedInternalIpPortParts[0];
String removedInternalPort = removedInternalIpPortParts[1];
List<String> removedInternalPortsList = internalIpPortMap.get(removedInternalPort);
if (removedInternalPortsList != null) {
removedInternalPortsList.add(removedInternalPort);
internalIpPortMap.put(removedInternalIp, removedInternalPortsList);
naptPacketInHandler.removeIncomingPacketMap(routerId + NatConstants.COLON_SEPARATOR + removedInternalIp + NatConstants.COLON_SEPARATOR + removedInternalPort);
// Remove the NAPT translation entries from Outbound NAPT table
naptEventHandler.removeNatFlows(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId, removedInternalIp, Integer.parseInt(removedInternalPort), protocolType.getName());
naptEventHandler.removeNatFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId, removedInternalIp, Integer.parseInt(removedInternalPort), protocolType.getName());
} else {
removedInternalPortsList = new ArrayList<>();
removedInternalPortsList.add(removedInternalPort);
internalIpPortMap.put(removedInternalIp, removedInternalPortsList);
naptPacketInHandler.removeIncomingPacketMap(routerId + NatConstants.COLON_SEPARATOR + removedInternalIp + NatConstants.COLON_SEPARATOR + removedInternalPort);
// Remove the NAPT translation entries from Outbound NAPT table
naptEventHandler.removeNatFlows(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId, removedInternalIp, Integer.parseInt(removedInternalPort), protocolType.getName());
naptEventHandler.removeNatFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId, removedInternalIp, Integer.parseInt(removedInternalPort), protocolType.getName());
}
}
}
}
// Delete the entry from SnatIntIpPortMap DS
Set<String> internalIps = internalIpPortMap.keySet();
for (String internalIp : internalIps) {
LOG.debug("update : Removing IpPort having the internal IP {} from the " + "model SnatIntIpPortMap", internalIp);
naptManager.removeFromSnatIpPortDS(routerId, internalIp);
}
naptManager.removeNaptPortPool(externalIp);
}
LOG.debug("update : End processing of the External IPs removal for router {}", routerName);
}
// Check if the External IPs are added during the update.
Set<String> addedExternalIps = new HashSet<>(updatedExternalIps);
addedExternalIps.removeAll(originalExternalIps);
if (addedExternalIps.size() != 0) {
LOG.debug("update : Start processing of the External IPs addition for router {}", routerName);
vpnManager.addArpResponderFlowsToExternalNetworkIps(routerName, addedExternalIps, update.getExtGwMacAddress(), dpnId, update.getNetworkId());
for (String addedExternalIp : addedExternalIps) {
/*
1) Do nothing in the IntExtIp model.
2) Initialise the count of the added external IP to 0 in the ExternalCounter model.
*/
String[] externalIpParts = NatUtil.getExternalIpAndPrefix(addedExternalIp);
String externalIp = externalIpParts[0];
String externalIpPrefix = externalIpParts[1];
String externalpStr = externalIp + "/" + externalIpPrefix;
LOG.debug("update : Initialise the count mapping of the external IP {} for the " + "router ID {} in the ExternalIpsCounter model.", externalpStr, routerId);
naptManager.initialiseNewExternalIpCounter(routerId, externalpStr);
subnetRegisterMapping(update, routerId);
LOG.info("update : Installing fib flow fo newly added Ips");
handleSnatReverseTraffic(writeFlowInvTx, dpnId, update, routerId, routerName, externalpStr);
}
LOG.debug("update : End processing of the External IPs addition during the update operation");
}
// Check if its Update on subnets
LOG.debug("update : Checking if this is update on subnets for router {}", routerName);
List<Uuid> originalSubnetIds = original.getSubnetIds();
List<Uuid> updatedSubnetIds = update.getSubnetIds();
Set<Uuid> addedSubnetIds = updatedSubnetIds != null ? new HashSet<>(updatedSubnetIds) : new HashSet<>();
if (originalSubnetIds != null) {
addedSubnetIds.removeAll(originalSubnetIds);
}
// Check if the Subnet IDs are added during the update.
if (addedSubnetIds.size() != 0) {
LOG.debug("update : Start processing of the Subnet IDs addition for router {}", routerName);
for (Uuid addedSubnetId : addedSubnetIds) {
/*
1) Select the least loaded external IP for the subnet and store the mapping of the
subnet IP and the external IP in the IntExtIp model.
2) Increase the count of the selected external IP by one.
3) Advertise to the BGP if external IP is allocated for the first time for the
router i.e. the route for the external IP is absent.
*/
String subnetIp = NatUtil.getSubnetIp(dataBroker, addedSubnetId);
if (subnetIp != null) {
allocateExternalIp(dpnId, update, routerId, routerName, networkId, subnetIp, writeFlowInvTx);
}
}
LOG.debug("update : End processing of the Subnet IDs addition for router {}", routerName);
}
// Check if the Subnet IDs are removed during the update.
Set<Uuid> removedSubnetIds = new HashSet<>(originalSubnetIds);
removedSubnetIds.removeAll(updatedSubnetIds);
if (removedSubnetIds.size() != 0) {
LOG.debug("update : Start processing of the Subnet IDs removal for router {}", routerName);
for (Uuid removedSubnetId : removedSubnetIds) {
String[] subnetAddr = NatUtil.getSubnetIpAndPrefix(dataBroker, removedSubnetId);
if (subnetAddr != null) {
/*
1) Remove the subnet IP and the external IP in the IntExtIp map
2) Decrease the count of the coresponding external IP by one.
3) Advertise to the BGP for removing the routes of the corresponding external
IP if its not allocated to any other internal IP.
*/
String externalIp = naptManager.getExternalIpAllocatedForSubnet(routerId, subnetAddr[0] + "/" + subnetAddr[1]);
if (externalIp == null) {
LOG.error("update : No mapping found for router ID {} and internal IP {}", routerId, subnetAddr[0]);
return;
}
naptManager.updateCounter(routerId, externalIp, false);
// used by any other internal ip in any router
if (!isExternalIpAllocated(externalIp)) {
LOG.debug("update : external ip is not allocated to any other " + "internal IP so proceeding to remove routes");
clrRtsFromBgpAndDelFibTs(dpnId, routerId, networkId, Collections.singleton(externalIp), null, update.getExtGwMacAddress(), removeFlowInvTx);
LOG.debug("update : Successfully removed fib entries in switch {} for " + "router {} with networkId {} and externalIp {}", dpnId, routerId, networkId, externalIp);
}
LOG.debug("update : Remove the IP mapping for the router ID {} and " + "internal IP {} external IP {}", routerId, subnetAddr[0], externalIp);
naptManager.removeIntExtIpMapDS(routerId, subnetAddr[0] + "/" + subnetAddr[1]);
}
}
LOG.debug("update : End processing of the Subnet IDs removal for router {}", routerName);
}
}));
}));
return futures;
}, NatConstants.NAT_DJC_MAX_RETRIES);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route 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.bgp.rib.rev180329.Route in project netvirt by opendaylight.
the class RouterDpnChangeListener method add.
@Override
public void add(final InstanceIdentifier<DpnVpninterfacesList> identifier, final DpnVpninterfacesList dpnInfo) {
LOG.trace("add : key: {}, value: {}", dpnInfo.key(), dpnInfo);
final String routerUuid = identifier.firstKeyOf(RouterDpnList.class).getRouterId();
Uint64 dpnId = dpnInfo.getDpnId();
// check router is associated to external network
InstanceIdentifier<Routers> id = NatUtil.buildRouterIdentifier(routerUuid);
Optional<Routers> routerData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (routerData.isPresent()) {
Routers router = routerData.get();
Uuid networkId = router.getNetworkId();
if (networkId != null) {
if (natMode == NatMode.Conntrack) {
Uint64 naptSwitch = NatUtil.getPrimaryNaptfromRouterName(dataBroker, router.getRouterName());
if (naptSwitch == null || naptSwitch.equals(Uint64.ZERO)) {
LOG.warn("add : NAPT switch is not selected.");
return;
}
// If it is for NAPT switch skip as the flows would be already programmed.
if (naptSwitch.equals(dpnId)) {
LOG.debug("Skipping the notification recived for NAPT switch {}", routerUuid);
return;
}
LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
natServiceManager.notify(confTx, router, null, naptSwitch, dpnId, SnatServiceManager.Action.CNT_ROUTER_ENBL);
if (router.isEnableSnat()) {
natServiceManager.notify(confTx, router, null, naptSwitch, naptSwitch, SnatServiceManager.Action.SNAT_ROUTER_ENBL);
}
}), LOG, "Error notifying NAT service manager");
} else {
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerUuid);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("add : Invalid routerId returned for routerName {}", routerUuid);
return;
}
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerUuid, networkId);
if (extNwProvType == ProviderTypes.FLAT || extNwProvType == ProviderTypes.VLAN) {
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + networkId, () -> {
extNetGroupInstaller.installExtNetGroupEntries(networkId, dpnId);
installDefaultNatRouteForRouterExternalSubnets(dpnId, NatUtil.getExternalSubnetIdsFromExternalIps(new ArrayList<ExternalIps>(router.nonnullExternalIps().values())));
return Collections.emptyList();
});
}
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + router.getRouterName(), () -> {
LOG.debug("add : Router {} is associated with ext nw {}", routerUuid, networkId);
Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerUuid);
return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
Uint32 vpnId;
if (vpnName == null) {
LOG.debug("add : Internal vpn associated to router {}", routerUuid);
vpnId = routerId;
if (vpnId == NatConstants.INVALID_ID) {
LOG.error("add : Invalid vpnId returned for routerName {}", routerUuid);
return;
}
LOG.debug("add : Retrieved vpnId {} for router {}", vpnId, routerUuid);
// Install default entry in FIB to SNAT table
LOG.info("add : Installing default route in FIB on dpn {} for router {} with vpn {}", dpnId, routerUuid, vpnId);
snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, confTx);
} else {
LOG.debug("add : External BGP vpn associated to router {}", routerUuid);
vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
if (vpnId == NatConstants.INVALID_ID) {
LOG.error("add : Invalid vpnId returned for routerName {}", routerUuid);
return;
}
LOG.debug("add : Retrieved vpnId {} for router {}", vpnId, routerUuid);
// Install default entry in FIB to SNAT table
LOG.debug("add : Installing default route in FIB on dpn {} for routerId {} with " + "vpnId {}...", dpnId, routerUuid, vpnId);
snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, routerId, confTx);
}
/* install V6 internet default fallback rule in FIB_TABLE if router
* is having V6 subnet
*/
Uuid internetVpnId = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
if (internetVpnId != null) {
nvpnManager.programV6InternetFallbackFlow(new Uuid(routerUuid), internetVpnId, NwConstants.ADD_FLOW);
}
if (router.isEnableSnat()) {
LOG.info("add : SNAT enabled for router {}", routerUuid);
if (extNwProvType == null) {
LOG.error("add : External Network Provider Type missing");
return;
}
NatUtil.handleSNATForDPN(dataBroker, mdsalManager, idManager, naptSwitchHA, dpnId, router, routerId, vpnId, confTx, extNwProvType, upgradeState);
} else {
LOG.info("add : SNAT is not enabled for router {} to handle addDPN event {}", routerUuid, dpnId);
}
}));
}, NatConstants.NAT_DJC_MAX_RETRIES);
}
// end of controller based SNAT
}
} else {
LOG.debug("add : Router {} is not associated with External network", routerUuid);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.
the class NatTepChangeListener method hndlTepDelForSnatInEachRtr.
private void hndlTepDelForSnatInEachRtr(RoutersList router, Uint32 routerId, Uint64 dpnId, String srcTepIp, Boolean isFipExists, ProviderTypes extNwProvType, TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
/*SNAT :
1) Elect a new switch as the primary NAPT
2) Advertise the new routes to BGP for the newly elected TEP IP as the DPN IP
3) This will make sure old routes are withdrawn and new routes are advertised.
*/
String routerName = router.getRouter();
LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Trying to clear routes to the External fixed IP associated " + "to the router {}", routerName);
// Check if this is externalRouter else ignore
InstanceIdentifier<Routers> extRoutersId = NatUtil.buildRouterIdentifier(routerName);
Optional<Routers> routerData = Optional.empty();
try {
routerData = confTx.read(extRoutersId).get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error retrieving routers {}", extRoutersId, e);
}
if (!routerData.isPresent()) {
LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Ignoring TEP del for router {} since its not External Router", routerName);
return;
}
// Check if the DPN having the router is the NAPT switch
Uint64 naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
if (naptId == null || naptId.equals(Uint64.ZERO) || !naptId.equals(dpnId)) {
LOG.error("hndlTepDelForSnatInEachRtr : SNAT -> Ignoring TEP delete for the DPN {} since" + "srcTepIp : {} is NOT a NAPT switch", dpnId, srcTepIp);
return;
}
if (natMode == NatMode.Conntrack) {
Routers extRouter = routerData.get();
natServiceManager.notify(confTx, extRouter, null, naptId, dpnId, SnatServiceManager.Action.CNT_ROUTER_DISBL);
if (extRouter.isEnableSnat()) {
natServiceManager.notify(confTx, extRouter, null, naptId, dpnId, SnatServiceManager.Action.SNAT_ROUTER_DISBL);
}
} else {
Uuid networkId = routerData.get().getNetworkId();
if (networkId == null) {
LOG.error("hndlTepDelForSnatInEachRtr : SNAT -> Ignoring TEP delete for the DPN {} for router {}" + "as external network configuraton is missing", dpnId, routerName);
return;
}
LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Router {} is associated with ext nw {}", routerId, networkId);
Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
Uint32 bgpVpnId;
if (bgpVpnUuid == null) {
LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Internal VPN-ID {} associated to router {}", routerId, routerName);
bgpVpnId = routerId;
} else {
bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
if (bgpVpnId == NatConstants.INVALID_ID) {
LOG.error("hndlTepDelForSnatInEachRtr :SNAT->Invalid Private BGP VPN ID returned for routerName {}", routerName);
return;
}
}
if (!isFipExists) {
// Remove default entry in FIB to SNAT table
LOG.debug("NAT Service : Installing default route in FIB on DPN {} for router {} with" + " vpn {}...", dpnId, routerName, bgpVpnId);
defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, routerId, confTx);
}
if (routerData.get().isEnableSnat()) {
LOG.info("hndlTepDelForSnatInEachRtr : SNAT enabled for router {}", routerId);
Uint32 routerVpnId = routerId;
if (bgpVpnId != NatConstants.INVALID_ID) {
LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Private BGP VPN ID (Internal BGP VPN ID) {} " + "associated to the router {}", bgpVpnId, routerName);
routerVpnId = bgpVpnId;
} else {
LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Internal L3 VPN ID (Router ID) {} " + "associated to the router {}", routerVpnId, routerName);
}
// Re-elect the other available switch as the NAPT switch and program the NAT flows.
String externalVpnName = NatUtil.getAssociatedVPN(dataBroker, routerData.get().getNetworkId());
NatUtil.removeSNATFromDPN(dataBroker, mdsalManager, idManager, naptSwitchHA, dpnId, routerData.get(), routerId, routerVpnId, externalVpnName, extNwProvType, confTx);
} else {
LOG.info("hndlTepDelForSnatInEachRtr : SNAT is not enabled for router {} to handle addDPN event {}", routerId, dpnId);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.
the class BgpConfigurationManager method onUpdatePushRoute.
/* onUpdatePushRoute
* Get Stale fibDSWriter map, and compare current route/fibDSWriter entry.
* - Entry compare shall include NextHop, Label.
* - If entry matches: delete from STALE Map. NO Change to FIB Config DS.
* - If entry not found, add to FIB Config DS.
* - If entry found, but either Label/NextHop doesn't match.
* - Update FIB Config DS with modified values.
* - delete from Stale Map.
*/
public void onUpdatePushRoute(protocol_type protocolType, String rd, String prefix, int plen, String nextHop, String macaddress, Uint32 label, Uint32 l2label, String routermac, af_afi afi) {
PrefixUpdateEvent prefixUpdateEvent = new PrefixUpdateEvent(protocolType, rd, prefix, plen, nextHop, macaddress, label, l2label, routermac, afi);
bgpUpdatesHistory.addToHistory(TransactionType.ADD, prefixUpdateEvent);
boolean addroute = false;
boolean macupdate = false;
Uint32 l3vni = Uint32.ZERO;
VrfEntry.EncapType encapType = VrfEntry.EncapType.Mplsgre;
if (protocolType.equals(protocol_type.PROTOCOL_EVPN)) {
encapType = VrfEntry.EncapType.Vxlan;
VpnInstanceOpDataEntry vpnInstanceOpDataEntry = bgpUtil.getVpnInstanceOpData(rd);
if (vpnInstanceOpDataEntry != null) {
if (vpnInstanceOpDataEntry.getType() == VpnInstanceOpDataEntry.Type.L2) {
LOG.info("Got RT2 route for RD {} l3label {} l2label {} from tep {} with mac {} remote RD {}", vpnInstanceOpDataEntry.getVpnInstanceName(), label, l2label, nextHop, macaddress, rd);
addTepToElanDS(rd, nextHop, macaddress, l2label);
macupdate = true;
} else {
l3vni = vpnInstanceOpDataEntry.getL3vni();
}
} else {
LOG.error("No corresponding vpn instance found for rd {}. Aborting.", rd);
return;
}
}
if (!staledFibEntriesMap.isEmpty()) {
// restart Scenario, as MAP is not empty.
Map<String, Uint32> map = staledFibEntriesMap.get(rd);
if (map != null) {
String prefixNextHop = appendNextHopToPrefix(prefix + "/" + plen, nextHop);
Uint32 labelInStaleMap = map.get(prefixNextHop);
if (null == labelInStaleMap) {
// New Entry, which happened to be added during restart.
addroute = true;
} else {
map.remove(prefixNextHop);
if (isRouteModified(label, labelInStaleMap)) {
LOG.debug("Route add ** {} ** {}/{} ** {} ** {} ", rd, prefix, plen, nextHop, label);
// Existing entry, where in Label got modified during restart
addroute = true;
}
}
} else {
LOG.debug("rd {} map is null while processing prefix {} ", rd, prefix);
addroute = true;
}
} else {
LOG.debug("Route add ** {} ** {}/{} ** {} ** {} ", rd, prefix, plen, nextHop, label);
addroute = true;
}
if (macupdate) {
LOG.info("ADD: Adding Mac Fib entry rd {} mac{} nexthop {} l2vni {}", rd, macaddress, nextHop, l2label);
fibDSWriter.addMacEntryToDS(rd, macaddress, prefix, Collections.singletonList(nextHop), encapType, l2label, routermac, RouteOrigin.BGP);
LOG.info("ADD: Added Mac Fib entry rd {} prefix {} nexthop {} label {}", rd, macaddress, nextHop, l2label);
} else if (addroute) {
LOG.info("ADD: Adding Fib entry rd {} prefix {} nexthop {} label {} afi {}", rd, prefix, nextHop, label, afi);
// TODO: modify addFibEntryToDS signature
List<String> nextHopList = Collections.singletonList(nextHop);
fibDSWriter.addFibEntryToDS(rd, prefix + "/" + plen, nextHopList, encapType, label, l3vni, routermac, RouteOrigin.BGP);
LOG.info("ADD: Added Fib entry rd {} prefix {} nexthop {} label {}", rd, prefix, nextHop, label);
String vpnName = bgpUtil.getVpnNameFromRd(rd);
if (vpnName != null) {
vpnLinkService.leakRouteIfNeeded(vpnName, prefix, nextHopList, label, RouteOrigin.BGP, NwConstants.ADD_FLOW);
}
}
}
Aggregations