String srcIp = rule.getSrcIp();
String dstIP = rule.getDstIp();
String iNatRuleName = generateInatRuleName(srcIp, dstIP);
String rNatRuleName = generateRnatRuleName(srcIp, dstIP);
inat iNatRule = null;
rnat rnatRule = null;
if (!rule.revoked()) {
try {
iNatRule = inat.get(_netscalerService, iNatRuleName);
} catch (nitro_exception e) {
if (e.getErrorCode() != NitroError.NS_RESOURCE_NOT_EXISTS) {
throw e;
}
}
if (iNatRule == null) {
iNatRule = new inat();
iNatRule.set_name(iNatRuleName);
iNatRule.set_publicip(srcIp);
iNatRule.set_privateip(dstIP);
iNatRule.set_usnip("OFF");
iNatRule.set_usip("ON");
try {
apiCallResult = inat.add(_netscalerService, iNatRule);
} catch (nitro_exception e) {
if (e.getErrorCode() != NitroError.NS_RESOURCE_EXISTS) {
throw e;
}
}
s_logger.debug("Created Inat rule on the Netscaler device " + _ip + " to enable static NAT from " + srcIp + " to " + dstIP);
}
try {
rnat[] rnatRules = rnat.get(_netscalerService);
if (rnatRules != null) {
for (rnat rantrule : rnatRules) {
if (rantrule.get_network().equalsIgnoreCase(rNatRuleName)) {
rnatRule = rantrule;
break;
}
}
}
} catch (nitro_exception e) {
throw e;
}
if (rnatRule == null) {
rnatRule = new rnat();
rnatRule.set_natip(srcIp);
rnatRule.set_network(dstIP);
rnatRule.set_netmask("255.255.255.255");
try {
apiCallResult = rnat.update(_netscalerService, rnatRule);
} catch (nitro_exception e) {
if (e.getErrorCode() != NitroError.NS_RESOURCE_EXISTS) {
throw e;