- void handleSNATForDPN(BigInteger dpnId, String routerName, long routerId, Long routerVpnId,
- TypedReadWriteTransaction<Configuration> confTx, ProviderTypes extNwProvType) {
- //Check if primary and secondary switch are selected, If not select the role
- //Install select group to NAPT switch
- //Install default miss entry to NAPT switch
- BigInteger naptSwitch;
- try {
- BigInteger naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
- if (naptId == null || naptId.equals(BigInteger.ZERO)
- || !NatUtil.getSwitchStatus(dataBroker, naptId) && !upgradeState.isUpgradeInProgress()) {
- LOG.debug("handleSNATForDPN : NaptSwitch is down or not selected for router {},naptId {}",
- routerName, naptId);
- naptSwitch = dpnId;
- boolean naptstatus = naptSwitchHA.updateNaptSwitch(routerName, naptSwitch);
- if (!naptstatus) {
- LOG.error("handleSNATForDPN : Failed to update newNaptSwitch {} for routername {}",
- naptSwitch, routerName);
- return;
- }
- LOG.debug("handleSNATForDPN : Switch {} is elected as NaptSwitch for router {}", dpnId, routerName);
-
- // When NAPT switch is elected during first VM comes up for the given Router
- if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
- NatOverVxlanUtil.validateAndCreateVxlanVniPool(dataBroker, nvpnManager,
- idManager, NatConstants.ODL_VNI_POOL_NAME);
- }
-
- Routers extRouters = NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
- if (extRouters != null) {
- NatUtil.createRouterIdsConfigDS(dataBroker, routerId, routerName);
- naptSwitchHA.subnetRegisterMapping(extRouters, routerId);
- }
-
- naptSwitchHA.installSnatFlows(routerName, routerId, naptSwitch, routerVpnId, confTx);
-
- // Install miss entry (table 26) pointing to table 46
- FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName,
- routerVpnId, NatConstants.ADD_FLOW);
- if (flowEntity == null) {
- LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {}",
- routerName, dpnId);
- return;
- }
- LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {}", dpnId, routerName);
- mdsalManager.addFlow(confTx, flowEntity);
- //Removing primary flows from old napt switch
- if (naptId != null && !naptId.equals(BigInteger.ZERO)) {
- LOG.debug("handleSNATForDPN : Removing primary flows from old napt switch {} for router {}",
- naptId, routerName);
- naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, routerId, naptId, null, confTx);
- }
- } else if (naptId.equals(dpnId)) {
- LOG.debug("handleSNATForDPN : NaptSwitch {} gone down during cluster reboot came alive", naptId);
- } else {
- naptSwitch = naptId;
- LOG.debug("handleSNATForDPN : Napt switch with Id {} is already elected for router {}",
- naptId, routerName);
-
- //installing group
- List<BucketInfo> bucketInfo = naptSwitchHA.handleGroupInNeighborSwitches(dpnId,
- routerName, routerId, naptSwitch);
- naptSwitchHA.installSnatGroupEntry(dpnId, bucketInfo, routerName);
-
- // Install miss entry (table 26) pointing to group
- long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
- FlowEntity flowEntity =
- naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId,
- routerVpnId, NatConstants.ADD_FLOW);
- if (flowEntity == null) {
- LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {} groupId {}",
- routerName, dpnId, groupId);
- return;
- }
- LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {} group {}",
- dpnId, routerName, groupId);
- mdsalManager.addFlow(confTx, flowEntity);
- }
-
- } catch (InterruptedException | ExecutionException e) {
- LOG.error("handleSNATForDPN : Exception in handleSNATForDPN", e);
- }
- }
-
- // TODO Clean up the exception handling
- @SuppressWarnings("checkstyle:IllegalCatch")
- void removeSNATFromDPN(BigInteger dpnId, String routerName, long routerId, long routerVpnId,
- Uuid extNetworkId, TypedReadWriteTransaction<Configuration> confTx) {
- //irrespective of naptswitch or non-naptswitch, SNAT default miss entry need to be removed
- //remove miss entry to NAPT switch
- //if naptswitch elect new switch and install Snat flows and remove those flows in oldnaptswitch
-
- Collection<String> externalIpCache = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
- ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNetworkId);
- if (extNwProvType == null) {
- return;
- }
- //Get the external IP labels other than VXLAN provider type. Since label is not applicable for VXLAN
- Map<String, Long> externalIpLabel;
- if (extNwProvType == ProviderTypes.VXLAN) {
- externalIpLabel = null;
- } else {
- externalIpLabel = NatUtil.getExternalIpsLabelForRouter(dataBroker, routerId);
- }
- BigInteger naptSwitch = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
- if (naptSwitch == null || naptSwitch.equals(BigInteger.ZERO)) {
- LOG.error("removeSNATFromDPN : No naptSwitch is selected for router {}", routerName);
- return;
- }
- try {
- boolean naptStatus =
- naptSwitchHA.isNaptSwitchDown(routerName, routerId, dpnId, naptSwitch, routerVpnId,
- externalIpCache, confTx);
- if (!naptStatus) {
- LOG.debug("removeSNATFromDPN: Switch with DpnId {} is not naptSwitch for router {}",
- dpnId, routerName);
- long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
- FlowEntity flowEntity = null;
- try {
- flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId, routerVpnId,
- NatConstants.DEL_FLOW);
- if (flowEntity == null) {
- LOG.error("removeSNATFromDPN : Failed to populate flowentity for router:{} "
- + "with dpnId:{} groupId:{}", routerName, dpnId, groupId);
- return;
- }
- LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity {}", flowEntity);
- mdsalManager.removeFlow(confTx, flowEntity);
-
- } catch (Exception ex) {
- LOG.error("removeSNATFromDPN : Failed to remove default SNAT miss entry flow entity {}",
- flowEntity, ex);
- return;
- }
- LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routername {}",
- dpnId, routerName);
-
- //remove group
- GroupEntity groupEntity = null;
- try {
- groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName,
- GroupTypes.GroupAll, Collections.emptyList() /*listBucketInfo*/);
- LOG.info("removeSNATFromDPN : Removing NAPT GroupEntity:{}", groupEntity);
- mdsalManager.removeGroup(groupEntity);
- } catch (Exception ex) {
- LOG.error("removeSNATFromDPN : Failed to remove group entity {}", groupEntity, ex);
- return;
- }
- LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routerName {}",
- dpnId, routerName);
- } else {
- naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, routerId, naptSwitch,
- externalIpLabel, confTx);
- //remove table 26 flow ppointing to table46
- FlowEntity flowEntity = null;
- try {
- flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName, routerVpnId,
- NatConstants.DEL_FLOW);
- if (flowEntity == null) {
- LOG.error("removeSNATFromDPN : Failed to populate flowentity for router {} with dpnId {}",
- routerName, dpnId);
- return;
- }
- LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity for router {} with "
- + "dpnId {} in napt switch {}", routerName, dpnId, naptSwitch);
- mdsalManager.removeFlow(confTx, flowEntity);
-
- } catch (Exception ex) {
- LOG.error("removeSNATFromDPN : Failed to remove default SNAT miss entry flow entity {}",
- flowEntity, ex);
- return;
- }
- LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routername {}",
- dpnId, routerName);
-
- //best effort to check IntExt model
- naptSwitchHA.bestEffortDeletion(routerId, routerName, externalIpLabel, confTx);
- }
- } catch (InterruptedException | ExecutionException e) {
- LOG.error("removeSNATFromDPN : Exception while handling naptSwitch down for router {}", routerName, e);
- }
- }
-
- private void installDefaultNatRouteForRouterExternalSubnets(BigInteger dpnId, Collection<Uuid> externalSubnetIds) {