use of com.emc.storageos.model.dr.DRNatCheckResponse in project coprhd-controller by CoprHD.
the class DisasterRecoveryService method checkIfBehindNat.
/**
* Check Data Replication If Behind NAT
*
* @param checkParam
* @param clientIp
* @brief Check if behind NAT
* @return DRNatCheckResponse
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN }, blockProxies = true)
@Path("/natcheck")
@ExcludeLicenseCheck
public DRNatCheckResponse checkIfBehindNat(DRNatCheckParam checkParam, @HeaderParam("X-Forwarded-For") String clientIp) {
if (checkParam == null) {
log.error("checkParam is null, X-Forwarded-For is {}", clientIp);
throw APIException.internalServerErrors.invalidNatCheckCall("(null)", clientIp);
}
String ipv4Str = checkParam.getIPv4Address();
String ipv6Str = checkParam.getIPv6Address();
log.info(String.format("Performing NAT check, client address connecting to VIP: %s. Client reports its IPv4 = %s, IPv6 = %s", clientIp, ipv4Str, ipv6Str));
boolean isBehindNat = false;
try {
isBehindNat = sysUtils.checkIfBehindNat(ipv4Str, ipv6Str, clientIp);
} catch (Exception e) {
log.error("Fail to check NAT {}", e);
throw APIException.internalServerErrors.invalidNatCheckCall(e.getMessage(), clientIp);
}
DRNatCheckResponse resp = new DRNatCheckResponse();
resp.setSeenIp(clientIp);
resp.setBehindNAT(isBehindNat);
return resp;
}
use of com.emc.storageos.model.dr.DRNatCheckResponse in project coprhd-controller by CoprHD.
the class DisasterRecoveryServiceTest method testCheckIfBehindNat_NotBehindNAT.
@Test
public void testCheckIfBehindNat_NotBehindNAT() {
natCheckParam.setIPv4Address("10.247.101.110");
DRNatCheckResponse response = drService.checkIfBehindNat(natCheckParam, "10.247.101.110");
assertEquals(false, response.isBehindNAT());
}
use of com.emc.storageos.model.dr.DRNatCheckResponse in project coprhd-controller by CoprHD.
the class DisasterRecoveryServiceTest method mockViPRCoreClient.
protected ViPRCoreClient mockViPRCoreClient(final String uuid) {
class MockViPRCoreClient extends ViPRCoreClient {
@Override
public com.emc.vipr.client.core.Site site() {
com.emc.vipr.client.core.Site site = mock(com.emc.vipr.client.core.Site.class);
SiteConfigRestRep config = new SiteConfigRestRep();
config.setUuid(uuid);
config.setHostIPv4AddressMap(new HashMap<String, String>());
config.setHostIPv6AddressMap(new HashMap<String, String>());
doReturn(config).when(site).getStandbyConfig();
doReturn(null).when(site).syncSite(anyString(), any(SiteConfigParam.class));
doReturn(new DRNatCheckResponse()).when(site).checkIfBehindNat(any(DRNatCheckParam.class));
return site;
}
}
return new MockViPRCoreClient();
}
use of com.emc.storageos.model.dr.DRNatCheckResponse in project coprhd-controller by CoprHD.
the class DisasterRecoveryServiceTest method testCheckIfBehindNat_IsBehindNAT.
@Test
public void testCheckIfBehindNat_IsBehindNAT() {
natCheckParam.setIPv4Address("10.247.101.111");
DRNatCheckResponse response = drService.checkIfBehindNat(natCheckParam, "10.247.101.110");
assertEquals(true, response.isBehindNAT());
}
use of com.emc.storageos.model.dr.DRNatCheckResponse in project coprhd-controller by CoprHD.
the class DisasterRecoveryService method checkNATForAttachStandby.
private void checkNATForAttachStandby(ViPRCoreClient viprCoreClient) {
DualInetAddress inetAddress = coordinator.getInetAddessLookupMap().getDualInetAddress();
String ipv4 = inetAddress.getInet4();
String ipv6 = inetAddress.getInet6();
log.info("Got local node's IP addresses, IPv4 = {}, IPv6 = {}", ipv4, ipv6);
DRNatCheckParam checkParam = new DRNatCheckParam();
checkParam.setIPv4Address(ipv4);
checkParam.setIPv6Address(ipv6);
DRNatCheckResponse resp = viprCoreClient.site().checkIfBehindNat(checkParam);
if (resp.isBehindNAT()) {
throw APIException.internalServerErrors.addStandbyPrecheckFailed(String.format("The remote site sees this node's IP as %s, which is different from the local addresses: %s or %s, it may be behind a NAT.", resp.getSeenIp(), ipv4, ipv6));
}
}
Aggregations