import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfacesBuilder;
import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
LOG.debug("installSnatMissEntry : installSnatMissEntry called for dpnId {} with primaryBucket {} ", dpnId,
listBucketInfo.get(0));
// Install the select group
- long groupId = createGroupId(getGroupIdKey(routerName));
-
- GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll,
- listBucketInfo);
- LOG.debug("installing the PSNAT to NAPTSwitch GroupEntity:{} with GroupId: {}", groupEntity, groupId);
- mdsalManager.addGroup(confTx, groupEntity);
-
- // Add the flow to send the packet to the group only after group is available in Config datastore
- eventCallbacks.onAddOrUpdate(LogicalDatastoreType.CONFIGURATION,
- NatUtil.getGroupInstanceId(dpnId, groupId), (unused, newGroupId) -> {
- LOG.info("group {} is created in the config", groupId);
- ListenableFutures.addErrorLogging(
- txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
- innerConfTx -> addSnatMissFlowForGroup(innerConfTx, dpnId, routerId, groupId)),
- LOG, "Error adding flow for the group {}",groupId);
- return DataTreeEventCallbackRegistrar.NextAction.UNREGISTER;
- }, Duration.ofSeconds(5), iid -> LOG.error("groupId {} not found in config datastore", groupId));
+ long groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, getGroupIdKey(routerName));
+ if (groupId != NatConstants.INVALID_ID) {
+ GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll,
+ listBucketInfo);
+ LOG.debug("installing the PSNAT to NAPTSwitch GroupEntity:{} with GroupId: {}", groupEntity, groupId);
+ mdsalManager.addGroup(confTx, groupEntity);
+
+ // Add the flow to send the packet to the group only after group is available in Config datastore
+ eventCallbacks.onAddOrUpdate(LogicalDatastoreType.CONFIGURATION,
+ NatUtil.getGroupInstanceId(dpnId, groupId), (unused, newGroupId) -> {
+ LOG.info("group {} is created in the config", groupId);
+ ListenableFutures.addErrorLogging(
+ txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+ innerConfTx -> addSnatMissFlowForGroup(innerConfTx, dpnId, routerId, groupId)),
+ LOG, "Error adding flow for the group {}",groupId);
+ return DataTreeEventCallbackRegistrar.NextAction.UNREGISTER;
+ }, Duration.ofSeconds(5), iid -> LOG.error("groupId {} not found in config datastore", groupId));
+ } else {
+ LOG.error("installSnatMissEntry: Unable to get groupId for routerName:{}", routerName);
+ }
}
private void addSnatMissFlowForGroup(TypedReadWriteTransaction<Configuration> confTx,
protected void removeSnatMissEntry(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
Long routerId, String routerName) throws ExecutionException, InterruptedException {
- LOG.debug("installSnatMissEntry : Removing SNAT miss entry from switch {}", dpnId);
+ LOG.debug("removeSnatMissEntry : Removing SNAT miss entry from switch {}", dpnId);
// Install the select group
- long groupId = createGroupId(getGroupIdKey(routerName));
-
- LOG.debug("removing the PSNAT to NAPTSwitch on DPN {} with GroupId: {}", dpnId, groupId);
- mdsalManager.removeGroup(confTx, dpnId, groupId);
-
+ long groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, getGroupIdKey(routerName));
+ if (groupId != NatConstants.INVALID_ID) {
+ LOG.debug("removeSnatMissEntry : removing the PSNAT to NAPTSwitch on DPN {} with GroupId: {}", dpnId,
+ groupId);
+ mdsalManager.removeGroup(confTx, dpnId, groupId);
+ } else {
+ LOG.error("removeSnatMissEntry: Unable to get groupId for routerName:{}", routerName);
+ }
// Install miss entry pointing to group
- LOG.debug("installSnatMissEntry : buildSnatFlowEntity is called for dpId {}, routerName {} and groupId {}",
+ LOG.debug("removeSnatMissEntry : buildSnatFlowEntity is called for dpId {}, routerName {} and groupId {}",
dpnId, routerName, groupId);
String flowRef = getFlowRef(dpnId, NwConstants.PSNAT_TABLE, routerId);
+ tableId + NatConstants.FLOWID_SEPARATOR + routerID;
}
- protected long createGroupId(String groupIdKey) {
- AllocateIdInput getIdInput = new AllocateIdInputBuilder()
- .setPoolName(NatConstants.SNAT_IDPOOL_NAME).setIdKey(groupIdKey)
- .build();
- try {
- Future<RpcResult<AllocateIdOutput>> result = idManager.allocateId(getIdInput);
- RpcResult<AllocateIdOutput> rpcResult = result.get();
- return rpcResult.getResult().getIdValue();
- } catch (NullPointerException | InterruptedException | ExecutionException e) {
- LOG.error("createGroupId: Exception while creating group with key : {}",groupIdKey, e);
- }
- return 0;
- }
-
protected String getGroupIdKey(String routerName) {
return "snatmiss." + routerName;
}
return;
}
- long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(subnetName), idManager);
-
- LOG.info("installExtNetGroupEntries : Installing ext-net group {} entry for subnet {} with macAddress {} "
- + "(extInterfaces: {})", groupId, subnetName, macAddress, Arrays.toString(extInterfaces.toArray()));
- for (String extInterface : extInterfaces) {
- BigInteger dpId = NatUtil.getDpnForInterface(odlInterfaceRpcService, extInterface);
- if (BigInteger.ZERO.equals(dpId)) {
- LOG.info("installExtNetGroupEntries: No DPN for interface {}. NAT ext-net flow will not be installed "
- + "for subnet {}", extInterface, subnetName);
- return;
+ long groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME,
+ NatUtil.getGroupIdKey(subnetName));
+ if (groupId != NatConstants.INVALID_ID) {
+ LOG.info("installExtNetGroupEntries : Installing ext-net group {} entry for subnet {} with macAddress {} "
+ + "(extInterfaces: {})", groupId, subnetName, macAddress,
+ Arrays.toString(extInterfaces.toArray()));
+ for (String extInterface : extInterfaces) {
+ BigInteger dpId = NatUtil.getDpnForInterface(odlInterfaceRpcService, extInterface);
+ if (BigInteger.ZERO.equals(dpId)) {
+ LOG.info(
+ "installExtNetGroupEntries: No DPN for interface {}. NAT ext-net flow will not be installed "
+ + "for subnet {}", extInterface, subnetName);
+ return;
+ }
+ installExtNetGroupEntry(groupId, subnetName, extInterface, macAddress, dpId);
}
- installExtNetGroupEntry(groupId, subnetName, extInterface, macAddress, dpId);
+ } else {
+ LOG.error("installExtNetGroupEntries: Unable to get groupId for subnet:{}", subnetName);
}
}
networkId, subnetName, dpnId);
//return;
}
-
- long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(subnetName), idManager);
- LOG.info("installExtNetGroupEntry : Installing ext-net group {} entry for subnet {} with macAddress {} "
- + "(extInterface: {})", groupId, subnetName, macAddress, extInterface);
- installExtNetGroupEntry(groupId, subnetName, extInterface, macAddress, dpnId);
+ long groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(subnetName));
+ if (groupId != NatConstants.INVALID_ID) {
+ LOG.info(
+ "installExtNetGroupEntry : Installing ext-net group {} entry for subnet {} with macAddress {} "
+ + "(extInterface: {})", groupId, subnetName, macAddress, extInterface);
+ installExtNetGroupEntry(groupId, subnetName, extInterface, macAddress, dpnId);
+ } else {
+ LOG.error("installExtNetGroupEntry: Unable to get groupId for subnet:{}", subnetName);
+ }
}
private void installExtNetGroupEntry(long groupId, String subnetName, String extInterface,
return;
}
- long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(subnetName), idManager);
-
- for (String extInterface : extInterfaces) {
- GroupEntity groupEntity = buildEmptyExtNetGroupEntity(subnetName, groupId, extInterface);
- if (groupEntity != null) {
- LOG.info("removeExtNetGroupEntries : Remove ext-net Group: id {}, subnet id {}", groupId, subnetName);
- natServiceCounters.removeExternalNetworkGroup();
- mdsalManager.syncRemoveGroup(groupEntity);
+ long groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(subnetName));
+ if (groupId != NatConstants.INVALID_ID) {
+ for (String extInterface : extInterfaces) {
+ GroupEntity groupEntity = buildEmptyExtNetGroupEntity(subnetName, groupId,
+ extInterface);
+ if (groupEntity != null) {
+ LOG.info("removeExtNetGroupEntries : Remove ext-net Group: id {}, subnet id {}",
+ groupId, subnetName);
+ natServiceCounters.removeExternalNetworkGroup();
+ mdsalManager.syncRemoveGroup(groupEntity);
+ }
}
+ } else {
+ LOG.error("removeExtNetGroupEntries: Unable to get groupId for subnet:{}", subnetName);
}
}
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeGre;
LOG.debug("installNaptPfibExternalOutputFlow - dpnId {} extVpnId {} subnetId {}",
dpnId, extVpnId, subnetId);
FlowEntity postNaptFlowEntity = buildNaptPfibFlowEntity(dpnId, extVpnId);
- mdsalManager.addFlow(confTx, postNaptFlowEntity);
+ if (postNaptFlowEntity != null) {
+ mdsalManager.addFlow(confTx, postNaptFlowEntity);
+ }
}
}
}
LOG.debug("installSnatMissEntry : called for dpnId {} with primaryBucket {} ",
dpnId, bucketInfo.get(0));
// Install the select group
- long groupId = createGroupId(getGroupIdKey(routerName));
+ long groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME,
+ NatUtil.getGroupIdKey(routerName));
+ if (groupId == NatConstants.INVALID_ID) {
+ LOG.error("installSnatMissEntry: Unable to obtain group ID for Key: {}", routerName);
+ return;
+ }
GroupEntity groupEntity =
MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, bucketInfo);
LOG.debug("installSnatMissEntry : installing the SNAT to NAPT GroupEntity:{}", groupEntity);
mdsalManager.installFlow(flowEntity);
}
- long installGroup(BigInteger dpnId, String routerName, List<BucketInfo> bucketInfo) {
- long groupId = createGroupId(getGroupIdKey(routerName));
+ void installGroup(BigInteger dpnId, String routerName, long groupId, List<BucketInfo> bucketInfo) {
GroupEntity groupEntity =
MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, bucketInfo);
LOG.debug("installGroup : installing the SNAT to NAPT GroupEntity:{}", groupEntity);
mdsalManager.syncInstallGroup(groupEntity);
- return groupId;
}
private FlowEntity buildSnatFlowEntity(BigInteger dpId, String routerName, long routerId, long groupId) {
.FLOWID_SEPARATOR + routerID;
}
- private String getGroupIdKey(String routerName) {
- return "snatmiss." + routerName;
- }
-
- protected long createGroupId(String groupIdKey) {
- AllocateIdInput getIdInput = new AllocateIdInputBuilder()
- .setPoolName(NatConstants.SNAT_IDPOOL_NAME).setIdKey(groupIdKey)
- .build();
- try {
- Future<RpcResult<AllocateIdOutput>> result = idManager.allocateId(getIdInput);
- RpcResult<AllocateIdOutput> rpcResult = result.get();
- return rpcResult.getResult().getIdValue();
- } catch (NullPointerException | InterruptedException | ExecutionException e) {
- LOG.error("Exception While allocating id for group: {}", groupIdKey, e);
- }
- return 0;
- }
-
protected void handleSwitches(BigInteger dpnId, String routerName, long routerId, BigInteger primarySwitchId) {
LOG.debug("handleSwitches : Installing SNAT miss entry in switch {}", dpnId);
List<ActionInfo> listActionInfoPrimary = new ArrayList<>();
handleDisableSnat(router, networkUuid, externalIps, true, null, primarySwitchId,
routerId, tx);
}
- natOverVxlanUtil.releaseVNI(routerName);
+ 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);
}
LOG.error("handleDisableSnatInternetVpn : Failed to remove fib entries for routerId {} "
+ "in naptSwitchDpnId {}", routerId, naptSwitchDpnId, ex);
}
- natOverVxlanUtil.releaseVNI(vpnId);
+ if (NatUtil.releaseId(idManager, NatConstants.ODL_VNI_POOL_NAME, vpnId) == NatConstants.INVALID_ID) {
+ LOG.error("handleDisableSnatInternetVpn : Unable to release VNI for vpnId {} ", vpnId);
+ }
} catch (InterruptedException | ExecutionException e) {
LOG.error("handleDisableSnatInternetVpn: Exception while handling disableSNATInternetVpn for router {} "
+ "with internet vpn {}", routerName, vpnId, e);
mdsalManager.removeFlow(removeFlowInvTx, preSnatFlowEntity);
//Remove the group entry which forwards the traffic to the out port (VXLAN tunnel).
- long groupId = createGroupId(getGroupIdKey(routerName));
-
- LOG.info("removeFlowsFromNonActiveSwitches : Remove the group {} for the non active switch with "
- + "the DPN ID {} and router ID {}", groupId, dpnId, routerId);
- mdsalManager.removeGroup(removeFlowInvTx, dpnId, groupId);
+ long groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME,
+ NatUtil.getGroupIdKey(routerName));
+ if (groupId != NatConstants.INVALID_ID) {
+ LOG.info(
+ "removeFlowsFromNonActiveSwitches : Remove the group {} for the non active switch with "
+ + "the DPN ID {} and router ID {}", groupId, dpnId, routerId);
+ mdsalManager.removeGroup(removeFlowInvTx, dpnId, groupId);
+ } else {
+ LOG.error("removeFlowsFromNonActiveSwitches: Unable to obtained groupID for router:{}", routerName);
+ }
}
}
}
getRoutersIdentifier(bgpVpnId), rtrs);
// Get the allocated Primary NAPT Switch for this router
- LOG.debug("changeLocalVpnIdToBgpVpnId : Router ID value {} ", routerId);
-
LOG.debug("changeLocalVpnIdToBgpVpnId : Update the Router ID {} to the BGP VPN ID {} ",
routerId, bgpVpnId);
addDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, writeFlowInvTx);
// Get the group ID
BigInteger primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
- createGroupId(getGroupIdKey(routerName));
installFlowsWithUpdatedVpnId(primarySwitchId, routerName, bgpVpnId, routerId, true, writeFlowInvTx,
extNwProvType);
}
addDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, NatConstants.INVALID_ID, writeFlowInvTx);
// Get the group ID
- createGroupId(getGroupIdKey(routerName));
BigInteger primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
installFlowsWithUpdatedVpnId(primarySwitchId, routerName, NatConstants.INVALID_ID, routerId, true,
writeFlowInvTx, extNwProvType);
LOG.debug("installFlowsWithUpdatedVpnId : Install group in non NAPT switch {}", dpnId);
List<BucketInfo> bucketInfoForNonNaptSwitches =
getBucketInfoForNonNaptSwitches(dpnId, primarySwitchId, routerName, routerId);
- long groupId = createGroupId(getGroupIdKey(routerName));
- if (!isSnatCfgd) {
- groupId = installGroup(dpnId, routerName, bucketInfoForNonNaptSwitches);
- }
-
- LOG.debug(
+ long groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME,
+ NatUtil.getGroupIdKey(routerName));
+ if (groupId != NatConstants.INVALID_ID) {
+ if (!isSnatCfgd) {
+ installGroup(dpnId, routerName, groupId, bucketInfoForNonNaptSwitches);
+ }
+ LOG.debug(
"installFlowsWithUpdatedVpnId : Update the {} ID {} in the SNAT miss entry pointing to group "
- + "{} in the non NAPT switch {}", idType, changedVpnId, groupId, dpnId);
- FlowEntity flowEntity = buildSnatFlowEntityWithUpdatedVpnId(dpnId, routerName, groupId, changedVpnId);
- mdsalManager.addFlow(confTx, flowEntity);
+ + "{} in the non NAPT switch {}", idType, changedVpnId, groupId, dpnId);
+ FlowEntity flowEntity = buildSnatFlowEntityWithUpdatedVpnId(dpnId, routerName,
+ groupId, changedVpnId);
+ mdsalManager.addFlow(confTx, flowEntity);
+ } else {
+ LOG.error("installFlowsWithUpdatedVpnId: Unable to get groupId for router:{}", routerName);
+ }
} else {
LOG.debug(
"installFlowsWithUpdatedVpnId : Update the {} ID {} in the SNAT miss entry pointing to group "
NatUtil.getIntExtPortMapIdentifier(routerId, interfaceName, internalIp);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
LogicalDatastoreType.OPERATIONAL, intExtPortMapIdentifier).toJavaUtil().map(
- InternalToExternalPortMap::getLabel).orElse(NatConstants.INVALID_ID);
+ InternalToExternalPortMap::getLabel).orElse(Long.valueOf(NatConstants.INVALID_ID));
}
static void updateOperationalDS(DataBroker dataBroker, String routerId, String interfaceName, long label,
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.utils.JvmGlobalLocks;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.DeleteIdPoolInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.DeleteIdPoolOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalIpsCounter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpPortMap;
createNaptPortPool(extIp);
LOG.debug("getExternalAddressMapping : Created Pool for next Ext IP {}", extIp);
}
- AllocateIdInput getIdInput = new AllocateIdInputBuilder()
- .setPoolName(extIp).setIdKey(internalIpPort)
- .build();
- try {
- Future<RpcResult<AllocateIdOutput>> result = idManager.allocateId(getIdInput);
- RpcResult<AllocateIdOutput> rpcResult;
- if (result != null && result.get().isSuccessful()) {
- LOG.debug("getExternalAddressMapping : Got id from idManager");
- rpcResult = result.get();
- } else {
- LOG.error("getExternalAddressMapping : getExternalAddressMapping, idManager could not "
- + "allocate id retry if subnet");
- if (!extSubnetFlag) {
- LOG.error("getExternalAddressMapping : getExternalAddressMapping returning null "
- + "for single IP case, may be ports exhausted");
- return null;
- }
- LOG.debug("getExternalAddressMapping : Could be ports exhausted case, "
- + "try with another externalIP if possible");
- nextExtIpFlag = true;
- continue;
- }
- int extPort = rpcResult.getResult().getIdValue().intValue();
- // Write to ip-port-map before returning
- IpPortExternalBuilder ipExt = new IpPortExternalBuilder();
- IpPortExternal ipPortExt = ipExt.setIpAddress(extIp).setPortNum(extPort).build();
- IpPortMap ipm = new IpPortMapBuilder().withKey(new IpPortMapKey(internalIpPort))
- .setIpPortInternal(internalIpPort).setIpPortExternal(ipPortExt).build();
- LOG.debug("getExternalAddressMapping : writing into ip-port-map with "
- + "externalIP {} and port {}",
- ipPortExt.getIpAddress(), ipPortExt.getPortNum());
- try {
- MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
- getIpPortMapIdentifier(segmentId, internalIpPort, protocol), ipm);
- } catch (UncheckedExecutionException uee) {
- LOG.error("getExternalAddressMapping : Failed to write into ip-port-map with exception",
- uee);
+ int extPort = NatUtil.getUniqueId(idManager, extIp, internalIpPort);
+ if (extPort == NatConstants.INVALID_ID) {
+ LOG.error("getExternalAddressMapping : getExternalAddressMapping, idManager could not "
+ + "allocate id retry if subnet");
+ if (!extSubnetFlag) {
+ LOG.error("getExternalAddressMapping : getExternalAddressMapping returning null "
+ + "for single IP case, may be ports exhausted");
+ return null;
}
+ LOG.debug("getExternalAddressMapping : Could be ports exhausted case, "
+ + "try with another externalIP if possible");
+ nextExtIpFlag = true;
+ continue;
+ }
+ // Write to ip-port-map before returning
+ IpPortExternalBuilder ipExt = new IpPortExternalBuilder();
+ IpPortExternal ipPortExt = ipExt.setIpAddress(extIp).setPortNum(extPort).build();
+ IpPortMap ipm = new IpPortMapBuilder().withKey(new IpPortMapKey(internalIpPort))
+ .setIpPortInternal(internalIpPort).setIpPortExternal(ipPortExt).build();
+ LOG.debug("getExternalAddressMapping : writing into ip-port-map with "
+ + "externalIP {} and port {}",
+ ipPortExt.getIpAddress(), ipPortExt.getPortNum());
+ try {
+ MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ getIpPortMapIdentifier(segmentId, internalIpPort, protocol), ipm);
+ } catch (UncheckedExecutionException uee) {
+ LOG.error("getExternalAddressMapping : Failed to write into ip-port-map with exception",
+ uee);
+ }
- // Write to snat-internal-ip-port-info
- String internalIpAddress = sourceAddress.getIpAddress();
- int ipPort = sourceAddress.getPortNumber();
- ProtocolTypes protocolType = NatUtil.getProtocolType(protocol);
- final ReentrantLock lock = lockFor(segmentId, internalIpAddress, protocolType);
- lock.lock();
+ // Write to snat-internal-ip-port-info
+ String internalIpAddress = sourceAddress.getIpAddress();
+ int ipPort = sourceAddress.getPortNumber();
+ ProtocolTypes protocolType = NatUtil.getProtocolType(protocol);
+ final ReentrantLock lock = lockFor(segmentId, internalIpAddress, protocolType);
+ lock.lock();
+ try {
+ List<Integer> portList = new ArrayList<>(
+ NatUtil.getInternalIpPortListInfo(dataBroker, segmentId, internalIpAddress,
+ protocolType));
+ portList.add(ipPort);
+
+ IntIpProtoTypeBuilder builder = new IntIpProtoTypeBuilder();
+ IntIpProtoType intIpProtocolType =
+ builder.withKey(new IntIpProtoTypeKey(protocolType)).setPorts(portList).build();
try {
- List<Integer> portList = new ArrayList<>(
- NatUtil.getInternalIpPortListInfo(dataBroker, segmentId, internalIpAddress,
- protocolType));
- portList.add(ipPort);
-
- IntIpProtoTypeBuilder builder = new IntIpProtoTypeBuilder();
- IntIpProtoType intIpProtocolType =
- builder.withKey(new IntIpProtoTypeKey(protocolType)).setPorts(portList).build();
- try {
- MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
- NatUtil.buildSnatIntIpPortIdentifier(segmentId, internalIpAddress, protocolType),
- intIpProtocolType);
- } catch (Exception ex) {
- LOG.error("getExternalAddressMapping : Failed to write into snat-internal-ip-port-info "
- + "with exception", ex);
- }
- } finally {
- lock.unlock();
+ MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ NatUtil.buildSnatIntIpPortIdentifier(segmentId, internalIpAddress, protocolType),
+ intIpProtocolType);
+ } catch (Exception ex) {
+ LOG.error("getExternalAddressMapping : Failed to write into snat-internal-ip-port-info "
+ + "with exception", ex);
}
- SessionAddress externalIpPort = new SessionAddress(extIp, extPort);
- LOG.debug("getExternalAddressMapping : successfully returning externalIP {} "
- + "and port {}", externalIpPort.getIpAddress(), externalIpPort.getPortNumber());
- return externalIpPort;
- } catch (InterruptedException | ExecutionException e) {
- LOG.error("getExternalAddressMapping : Exception caught", e);
- return null;
+ } finally {
+ lock.unlock();
}
+ SessionAddress externalIpPort = new SessionAddress(extIp, extPort);
+ LOG.debug("getExternalAddressMapping : successfully returning externalIP {} "
+ + "and port {}", externalIpPort.getIpAddress(), externalIpPort.getPortNumber());
+ return externalIpPort;
} // end of for loop
LOG.error("getExternalAddressMapping : Unable to handle external IP address and port mapping with segmentId {},"
+ "internalIp {} and internalPort {}", segmentId, sourceAddress.getIpAddress(),
try {
removeFromIpPortMapDS(segmentId, internalIpPort, protocol);
// Finally release port from idmanager
- removePortFromPool(internalIpPort, existingIpPort.getIpAddress());
+ long releasedId = NatUtil.releaseId(idManager, existingIpPort.getIpAddress(), internalIpPort);
+ if (releasedId == NatConstants.INVALID_ID) {
+ LOG.error("releaseIpExtPortMapping : Unable to release ID for key {}",
+ existingIpPort.getIpAddress());
+ }
} catch (Exception e) {
LOG.error("releaseIpExtPortMapping : failed, Removal of ipportmap {} for "
+ "router {} failed", internalIpPort, segmentId, e);
}
void removePortFromPool(String internalIpPort, String externalIp) {
- LOG.debug("removePortFromPool : method called");
- ReleaseIdInput idInput = new ReleaseIdInputBuilder()
- .setPoolName(externalIp)
- .setIdKey(internalIpPort).build();
- try {
- RpcResult<ReleaseIdOutput> rpcResult = idManager.releaseId(idInput).get();
- if (!rpcResult.isSuccessful()) {
- LOG.error("removePortFromPool : idmanager failed to remove port from pool {}", rpcResult.getErrors());
- }
- LOG.debug("removePortFromPool : Removed port from pool for InternalIpPort {} with externalIp {}",
- internalIpPort, externalIp);
- } catch (InterruptedException | ExecutionException e) {
- LOG.error("removePortFromPool : idmanager failed when removing entry in pool with key {} with Exception",
- internalIpPort, e);
+ if (NatUtil.releaseId(idManager, externalIp, internalIpPort) == NatConstants.INVALID_ID) {
+ LOG.error("Unable to release id {} from Pool {}", internalIpPort, externalIp);
}
}
}
//remove group in new naptswitch, coz this switch acted previously as ordinary switch
- long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
- try {
- LOG.info("isNaptSwitchDown : Removing NAPT Group in new naptSwitch {}", naptSwitch);
- mdsalManager.removeGroup(confTx, naptSwitch, groupId);
- } catch (Exception ex) {
- LOG.error("isNaptSwitchDown : Failed to remove group in new naptSwitch {}", naptSwitch, ex);
+ long groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME,
+ NatUtil.getGroupIdKey(routerName));
+ if (groupId != NatConstants.INVALID_ID) {
+ try {
+ LOG.info("isNaptSwitchDown : Removing NAPT Group in new naptSwitch {}",
+ naptSwitch);
+ mdsalManager.removeGroup(confTx, naptSwitch, groupId);
+ } catch (Exception ex) {
+ LOG.error("isNaptSwitchDown : Failed to remove group in new naptSwitch {}",
+ naptSwitch, ex);
+ }
+ } else {
+ LOG.error("NAT Service : Unable to obtain groupId for router:{}", routerName);
}
}
return true;
}
Long bgpVpnId;
if (routerId.equals(routerVpnId)) {
- bgpVpnId = NatConstants.INVALID_ID;
+ bgpVpnId = Long.valueOf(NatConstants.INVALID_ID);
} else {
bgpVpnId = routerVpnId;
}
} catch (Exception ex) {
LOG.error("getVpnIdForRouter : Exception while retrieving vpnId for router {}", routerId, ex);
}
- return NatConstants.INVALID_ID;
+ return Long.valueOf(NatConstants.INVALID_ID);
}
@NonNull
protected void installSnatGroupEntry(BigInteger dpnId, List<BucketInfo> bucketInfo, String routerName) {
GroupEntity groupEntity = null;
try {
- long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
- LOG.debug("installSnatGroupEntry : install SnatMissEntry for groupId {} for dpnId {} for router {}",
+ long groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME,
+ NatUtil.getGroupIdKey(routerName));
+ if (groupId != NatConstants.INVALID_ID) {
+ LOG.debug(
+ "installSnatGroupEntry : install SnatMissEntry for groupId {} for dpnId {} for router {}",
groupId, dpnId, routerName);
- groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName,
- GroupTypes.GroupAll, bucketInfo);
- mdsalManager.syncInstallGroup(groupEntity);
- LOG.debug("installSnatGroupEntry : installed the SNAT to NAPT GroupEntity:{}", groupEntity);
+ groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName,
+ GroupTypes.GroupAll, bucketInfo);
+ mdsalManager.syncInstallGroup(groupEntity);
+ LOG.debug("installSnatGroupEntry : installed the SNAT to NAPT GroupEntity:{}",
+ groupEntity);
+ } else {
+ LOG.error("installSnatGroupEntry: Unable to obtain groupId for router:{}", routerName);
+ }
} catch (Exception ex) {
LOG.error("installSnatGroupEntry : Failed to install group for groupEntity {}", groupEntity, ex);
}
int EVENT_QUEUE_LENGTH = 1000000;
String FLOWID_PREFIX = "L3.";
int DEFAULT_DNAT_FLOW_PRIORITY = 10;
- long INVALID_ID = -1;
+ int INVALID_ID = -1;
short SNAT_FIB_FLOW_PRIORITY = 42;
short SNAT_TRK_FLOW_PRIORITY = 6;
short SNAT_NEW_FLOW_PRIORITY = 5;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.port.info.FloatingIpIdToPortMapping;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private NatEvpnUtil() { }
- static long getLPortTagForRouter(String routerIdKey, IdManagerService idManager) {
- AllocateIdInput getIdInput = new AllocateIdInputBuilder()
- .setPoolName(IfmConstants.IFM_IDPOOL_NAME).setIdKey(routerIdKey)
- .build();
- try {
- Future<RpcResult<AllocateIdOutput>> result = idManager.allocateId(getIdInput);
- RpcResult<AllocateIdOutput> rpcResult = result.get();
- return rpcResult.getResult().getIdValue();
- } catch (NullPointerException | InterruptedException | ExecutionException e) {
- LOG.error("getLPortTagForRouter : ID manager failed while allocating lport_tag for router {}.",
- routerIdKey, e);
- }
- return 0;
- }
-
public static void releaseLPortTagForRouter(DataBroker dataBroker, IdManagerService idManager, String routerName) {
String rd = NatUtil.getVpnRd(dataBroker, routerName);
LOG.info("releaseLPortTagForRouter : Router:{} is not part of L3VPNOverVxlan", routerName);
return;
}
- ReleaseIdInput getIdInput = new ReleaseIdInputBuilder()
- .setPoolName(IfmConstants.IFM_IDPOOL_NAME).setIdKey(routerName)
- .build();
- try {
- RpcResult<ReleaseIdOutput> rpcResult = idManager.releaseId(getIdInput).get();
- if (!rpcResult.isSuccessful()) {
- LOG.error("releaseLPortTagForRouter:ID manager failed while releasing allocated lport_tag "
- + "for router {}. Exception {} ", routerName, rpcResult.getErrors());
- return;
- }
- } catch (NullPointerException | InterruptedException | ExecutionException e) {
- LOG.error("releaseLPortTagForRouter:ID : ID manager failed while releasing allocated lport_tag "
- + "for router {}.", routerName, e);
+ if (NatUtil.releaseId(idManager, IfmConstants.IFM_IDPOOL_NAME, routerName) == NatConstants.INVALID_ID) {
+ LOG.error("releaseLPortTagForRouter: Unable to release VNI for router {}", routerName);
}
}
String rd = NatUtil.getVpnRd(dataBroker, routerName);
long l3Vni = getL3Vni(dataBroker, rd);
if (isL3VpnOverVxLan(l3Vni)) {
- long routerLportTag = getLPortTagForRouter(routerName, idManager);
- if (routerLportTag != 0) {
+ int routerLportTag = NatUtil.getUniqueId(idManager, IfmConstants.IFM_IDPOOL_NAME, routerName);
+ if (routerLportTag != NatConstants.INVALID_ID) {
LOG.trace("getTunnelIdForRouter : Successfully allocated Router_lPort_Tag = {} from ID Manager for "
+ "Router ID = {}", routerLportTag, routerId);
return routerLportTag;
if (!naptStatus) {
LOG.debug("removeSNATFromDPN:SNAT->NaptSwitchDown:Switch with DpnId {} is not naptSwitch for router {}",
dpnId, routerName);
- long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
+ long groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME,
+ NatUtil.getGroupIdKey(routerName));
FlowEntity flowEntity = null;
try {
- flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId,
- routerVpnId, NatConstants.DEL_FLOW);
- if (flowEntity == null) {
- LOG.error("removeSNATFromDPN : SNAT -> Failed to populate flowentity for "
- + "router {} with dpnId {} groupIs {}", routerName, dpnId, groupId);
- return;
+ if (groupId != NatConstants.INVALID_ID) {
+ flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId,
+ routerVpnId, NatConstants.DEL_FLOW);
+ if (flowEntity == null) {
+ LOG.error(
+ "removeSNATFromDPN : SNAT -> Failed to populate flowentity for "
+ + "router {} with dpnId {} groupIs {}", routerName, dpnId,
+ groupId);
+ return;
+ }
+ LOG.debug(
+ "removeSNATFromDPN : SNAT->Removing default SNAT miss entry flow entity {}",
+ flowEntity);
+ mdsalManager.removeFlow(confTx, flowEntity);
+ } else {
+ LOG.error("removeSNATFromDPN : Failed to Obtain groupID for router {}", routerName);
}
- LOG.debug("removeSNATFromDPN : SNAT->Removing default SNAT miss entry flow entity {}", flowEntity);
- mdsalManager.removeFlow(confTx, flowEntity);
-
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : SNAT->Failed to remove default SNAT miss entry flow entity {}",
flowEntity, ex);
//remove group
try {
LOG.info("removeSNATFromDPN : SNAT->Removing NAPT Group :{} on Dpn {}", groupId, dpnId);
- mdsalManager.removeGroup(confTx, dpnId, groupId);
+ if (groupId != NatConstants.INVALID_ID) {
+ mdsalManager.removeGroup(confTx, dpnId, groupId);
+ }
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : SNAT->Failed to remove group {}", groupId, ex);
return;
srcDpnId, routerName);
List<BucketInfo> bucketInfoForNonNaptSwitches =
externalRouterListner.getBucketInfoForNonNaptSwitches(srcDpnId, primaryDpnId, routerName, routerId);
- long groupId = externalRouterListner.installGroup(srcDpnId, routerName, bucketInfoForNonNaptSwitches);
-
- LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> in the SNAT miss entry pointing to group {} "
- + "in the non NAPT switch {}", groupId, srcDpnId);
- FlowEntity flowEntity =
- externalRouterListner.buildSnatFlowEntityWithUpdatedVpnId(srcDpnId, routerName, groupId, vpnId);
- mdsalManager.addFlow(confTx, flowEntity);
+ long groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME,
+ NatUtil.getGroupIdKey(routerName));
+ if (groupId != NatConstants.INVALID_ID) {
+ externalRouterListner.installGroup(srcDpnId, routerName, groupId, bucketInfoForNonNaptSwitches);
+ LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> in the SNAT miss entry pointing to group {} "
+ + "in the non NAPT switch {}", groupId, srcDpnId);
+ FlowEntity flowEntity =
+ externalRouterListner.buildSnatFlowEntityWithUpdatedVpnId(srcDpnId, routerName, groupId, vpnId);
+ mdsalManager.addFlow(confTx, flowEntity);
+ } else {
+ LOG.error("hndlTepAddOnNonNaptSwitch: Unable to obtain group ID for Key: {}", routerName);
+ }
}
return true;
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.BridgeRefInfo;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.bridge.ref.info.BridgeRefEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.bridge.ref.info.BridgeRefEntryKey;
try {
return confTx.read(getVpnInstanceToVpnIdIdentifier(vpnName)).get().toJavaUtil().map(
org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id
- .VpnInstance::getVpnId).orElse(NatConstants.INVALID_ID);
+ .VpnInstance::getVpnId).orElse(Long.valueOf(NatConstants.INVALID_ID));
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error retrieving VPN id for {}", vpnName, e);
}
Uuid networkId = NatUtil.getNetworkIdFromRouterId(broker, routerId);
if (networkId == null) {
LOG.error("getNetworkVpnIdFromRouterId : networkId is null");
- return NatConstants.INVALID_ID;
+ return Long.valueOf(NatConstants.INVALID_ID);
}
//Get the VPN ID from the ExternalNetworks model
Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(broker, networkId);
if (vpnUuid == null) {
LOG.error("getNetworkVpnIdFromRouterId : vpnUuid is null");
- return NatConstants.INVALID_ID;
+ return Long.valueOf(NatConstants.INVALID_ID);
}
Long vpnId = NatUtil.getVpnId(broker, vpnUuid.getValue());
return vpnId;
InstanceIdentifier<Routermapping> routerMappingId = NatUtil.getRouterVpnMappingId(routerName);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
LogicalDatastoreType.OPERATIONAL, routerMappingId).toJavaUtil().map(Routermapping::getVpnId).orElse(
- NatConstants.INVALID_ID);
+ Long.valueOf(NatConstants.INVALID_ID));
}
@Nullable
return "snatmiss." + routerName;
}
- public static long createGroupId(String groupIdKey, IdManagerService idManager) {
- AllocateIdInput getIdInput = new AllocateIdInputBuilder()
- .setPoolName(NatConstants.SNAT_IDPOOL_NAME).setIdKey(groupIdKey)
- .build();
+ public static int getUniqueId(IdManagerService idManager, String poolName, String idKey) {
+
+ AllocateIdInput getIdInput = (new AllocateIdInputBuilder()).setPoolName(poolName).setIdKey(idKey).build();
try {
Future<RpcResult<AllocateIdOutput>> result = idManager.allocateId(getIdInput);
- RpcResult<AllocateIdOutput> rpcResult = result.get();
- return rpcResult.getResult().getIdValue();
- } catch (NullPointerException | InterruptedException | ExecutionException e) {
- LOG.error("createGroupId : Creating Group with Key: {} failed", groupIdKey, e);
+ RpcResult<AllocateIdOutput> rpcResult = (RpcResult)result.get();
+ return rpcResult.isSuccessful() ? rpcResult.getResult().getIdValue().intValue() : NatConstants.INVALID_ID;
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("releaseId: Exception when releasing Id for key {} from pool {}", idKey, poolName, e);
}
- return 0;
+ return NatConstants.INVALID_ID;
+ }
+
+ public static Integer releaseId(IdManagerService idManager, String poolName, String idKey) {
+ ReleaseIdInput idInput = new ReleaseIdInputBuilder().setPoolName(poolName).setIdKey(idKey).build();
+ try {
+ Future<RpcResult<ReleaseIdOutput>> result = idManager.releaseId(idInput);
+ if (result == null || result.get() == null || !result.get().isSuccessful()) {
+ LOG.error("releaseId: RPC Call to release Id from pool {} with key {} returned with Errors {}",
+ poolName, idKey,
+ (result != null && result.get() != null) ? result.get().getErrors() : "RpcResult is null");
+ } else {
+ return 1;
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("releaseId: Exception when releasing Id for key {} from pool {}", idKey, poolName, e);
+ }
+ return NatConstants.INVALID_ID;
}
// TODO Clean up the exception handling
List<InstructionInfo> instructions = new ArrayList<>();
List<ActionInfo> actionsInfo = new ArrayList<>();
- long groupId = createGroupId(NatUtil.getGroupIdKey(subnetId), idManager);
+ long groupId = getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(subnetId));
+ if (groupId == NatConstants.INVALID_ID) {
+ LOG.error("Unable to get groupId for subnet {} while building defauly flow entity", subnetId);
+ return null;
+ }
actionsInfo.add(new ActionGroup(groupId));
String flowRef = getFlowRef(dpId, NwConstants.L3_FIB_TABLE, defaultIP, vpnId);
instructions.add(new InstructionApplyActions(actionsInfo));
if (!naptStatus) {
LOG.debug("removeSNATFromDPN: Switch with DpnId {} is not naptSwitch for router {}",
dpnId, routerName);
- long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
+ long groupId = getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(routerName));
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:{} "
+ if (groupId != NatConstants.INVALID_ID) {
+ 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;
+ return;
+ }
+ LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity {}",
+ flowEntity);
+ mdsalManager.removeFlow(confTx, flowEntity);
+ } else {
+ LOG.error("removeSNATFromDPN: Unable to get groupId for router:{}", routerName);
}
- 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 {}",
//remove group
GroupEntity groupEntity = null;
try {
- groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName,
- GroupTypes.GroupAll, emptyList() /*listBucketInfo*/);
- LOG.info("removeSNATFromDPN : Removing NAPT GroupEntity:{}", groupEntity);
- mdsalManager.removeGroup(groupEntity);
+ if (groupId != NatConstants.INVALID_ID) {
+ groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName,
+ GroupTypes.GroupAll, emptyList() /*listBucketInfo*/);
+ LOG.info("removeSNATFromDPN : Removing NAPT GroupEntity:{}", groupEntity);
+ mdsalManager.removeGroup(groupEntity);
+ } else {
+ LOG.error("removeSNATFromDPN: Unable to get groupId for router:{}", routerName);
+ }
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : Failed to remove group entity {}", groupEntity, ex);
return;
naptSwitchHA.installSnatGroupEntry(dpnId, bucketInfo, routerName);
// Install miss entry (table 26) pointing to group
- long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
- FlowEntity flowEntity =
+ long groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME,
+ NatUtil.getGroupIdKey(routerName));
+ if (groupId != NatConstants.INVALID_ID) {
+ 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 {}",
+ 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 {}",
+ return;
+ }
+ LOG.debug(
+ "handleSNATForDPN : Successfully installed flow for dpnId {} router {} group {}",
dpnId, routerName, groupId);
- mdsalManager.addFlow(confTx, flowEntity);
+ mdsalManager.addFlow(confTx, flowEntity);
+ } else {
+ LOG.error("handleSNATForDPN : Failed to Obtain groupId for router {}", routerName);
+ }
}
-
} catch (InterruptedException | ExecutionException e) {
LOG.error("handleSNATForDPN : Exception in handleSNATForDPN", e);
}
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;
+ long groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME,
+ NatUtil.getGroupIdKey(routerName));
try {
- flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId, routerVpnId,
- NatConstants.DEL_FLOW);
- if (flowEntity == null) {
- LOG.error("removeSNATFromDPN : Failed to populate flowentity for router:{} "
+
+ if (groupId != NatConstants.INVALID_ID) {
+ 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;
+ return;
+ }
+ LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity {}",
+ flowEntity);
+ mdsalManager.removeFlow(confTx, flowEntity);
+ } else {
+ LOG.error("removeSNATFromDPN : Failed to Obtained Groupid for Router {}", routerName);
}
- 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);
@Override
protected void addSnatMissEntry(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId, Long routerId,
String routerName, BigInteger primarySwitchId) {
- LOG.debug("installSnatMissEntry : Installing SNAT miss entry in switch {}", dpnId);
+ LOG.debug("addSnatMissEntry : Installing SNAT miss entry in switch {}", dpnId);
List<ActionInfo> listActionInfoPrimary = new ArrayList<>();
String ifNamePrimary = NatUtil.getTunnelInterfaceName(dpnId, primarySwitchId, itmManager);
List<BucketInfo> listBucketInfo = new ArrayList<>();
if (ifNamePrimary != null) {
- LOG.debug("installSnatMissEntry : On Non- Napt switch , Primary Tunnel interface is {}", ifNamePrimary);
+ LOG.debug("addSnatMissEntry : On Non- Napt switch , Primary Tunnel interface is {}", ifNamePrimary);
listActionInfoPrimary = NatUtil.getEgressActionsForInterface(odlInterfaceRpcService, itmManager,
interfaceManager, ifNamePrimary, routerId, true);
}
BucketInfo bucketPrimary = new BucketInfo(listActionInfoPrimary);
listBucketInfo.add(0, bucketPrimary);
- LOG.debug("installSnatMissEntry : installSnatMissEntry called for dpnId {} with primaryBucket {} ", dpnId,
+ LOG.debug("addSnatMissEntry : addSnatMissEntry called for dpnId {} with primaryBucket {} ", dpnId,
listBucketInfo.get(0));
// Install the select group
- long groupId = createGroupId(getGroupIdKey(routerName));
- GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll,
- listBucketInfo);
- LOG.debug("installSnatMissEntry : installing the SNAT to NAPT GroupEntity:{}", groupEntity);
- mdsalManager.addGroup(confTx, groupEntity);
- // Install miss entry pointing to group
- LOG.debug("installSnatMissEntry : buildSnatFlowEntity is called for dpId {}, routerName {} and groupId {}",
+ long groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, getGroupIdKey(routerName));
+ if (groupId != NatConstants.INVALID_ID) {
+ GroupEntity groupEntity = MDSALUtil
+ .buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll,
+ listBucketInfo);
+ LOG.debug("addSnatMissEntry : installing the SNAT to NAPT GroupEntity:{}", groupEntity);
+ mdsalManager.addGroup(confTx, groupEntity);
+ // Install miss entry pointing to group
+ LOG.debug(
+ "addSnatMissEntry : buildSnatFlowEntity is called for dpId {}, routerName {} and groupId {}",
dpnId, routerName, groupId);
- List<MatchInfo> matches = new ArrayList<>();
- matches.add(new MatchEthernetType(0x0800L));
- matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId), MetaDataUtil.METADATA_MASK_VRFID));
-
- List<ActionInfo> actionsInfo = new ArrayList<>();
-
- BigInteger tunnelId = BigInteger.valueOf(routerId);
- if (elanManager.isOpenStackVniSemanticsEnforced()) {
- tunnelId = natOverVxlanUtil.getRouterVni(routerName, routerId);
- }
+ List<MatchInfo> matches = new ArrayList<>();
+ matches.add(new MatchEthernetType(0x0800L));
+ matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId),
+ MetaDataUtil.METADATA_MASK_VRFID));
- actionsInfo.add(new ActionSetFieldTunnelId(tunnelId));
- LOG.debug("AbstractSnatService : Setting the tunnel to the list of action infos {}", actionsInfo);
- actionsInfo.add(new ActionGroup(groupId));
- List<InstructionInfo> instructions = new ArrayList<>();
- instructions.add(new InstructionApplyActions(actionsInfo));
- String flowRef = getFlowRef(dpnId, NwConstants.PSNAT_TABLE, routerId);
- NatUtil.addFlow(confTx, mdsalManager, dpnId, NwConstants.PSNAT_TABLE, flowRef,
- NatConstants.DEFAULT_PSNAT_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches,
+ List<ActionInfo> actionsInfo = new ArrayList<>();
+
+ BigInteger tunnelId = BigInteger.valueOf(routerId);
+ if (elanManager.isOpenStackVniSemanticsEnforced()) {
+ tunnelId = natOverVxlanUtil.getRouterVni(routerName, routerId);
+ }
+
+ actionsInfo.add(new ActionSetFieldTunnelId(tunnelId));
+ LOG.debug("addSnatMissEntry : Setting the tunnel to the list of action infos {}",
+ actionsInfo);
+ actionsInfo.add(new ActionGroup(groupId));
+ List<InstructionInfo> instructions = new ArrayList<>();
+ instructions.add(new InstructionApplyActions(actionsInfo));
+ String flowRef = getFlowRef(dpnId, NwConstants.PSNAT_TABLE, routerId);
+ NatUtil.addFlow(confTx, mdsalManager, dpnId, NwConstants.PSNAT_TABLE, flowRef,
+ NatConstants.DEFAULT_PSNAT_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE,
+ matches,
instructions);
+ } else {
+ LOG.error("installSnatMissEntry: Unable to get groupId for router:{}", routerName);
+ }
}
@Override