parent
8912c33132
commit
22c0670e84
src
main/java/com/dispose
test/java/com/dispose/test/dev/config
|
@ -11,6 +11,7 @@ import com.dispose.common.ErrorCode;
|
|||
import com.dispose.common.Helper;
|
||||
import com.dispose.common.IpAddrType;
|
||||
import com.dispose.common.NetflowDirection;
|
||||
import com.dispose.config.TemplateConfigure;
|
||||
import com.dispose.pojo.dto.protocol.device.ability.DpBypassManager;
|
||||
import com.dispose.pojo.dto.protocol.device.ability.DpProtectObject;
|
||||
import com.dispose.pojo.dto.protocol.device.ability.DpProtectionStrategyInfo;
|
||||
|
@ -68,7 +69,87 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
|||
*/
|
||||
private long timerCnt = 0;
|
||||
|
||||
private ErrorCode createUMCPortectObject(String objName, String ipSegment, int ipType) {
|
||||
/**
|
||||
* Remove umc protect object error code.
|
||||
*
|
||||
* @param objName the obj name
|
||||
* @return the error code
|
||||
*/
|
||||
private ErrorCode removeUMCProtectObject(String objName) {
|
||||
NtcRequestResultInfo ret;
|
||||
|
||||
// 更新防护策略模板和防护对象关联关系
|
||||
getProtectionStrategyTemplateAssociation();
|
||||
// 更新防护对象
|
||||
getDisposeDeviceProtectObject();
|
||||
// 更新手动旁路牵引策略
|
||||
upgradeTractionStrategy();
|
||||
|
||||
// 清理关联的旁路手动牵引策略
|
||||
for (DpTractionStrategy v : dpBypassManager.getTractionStrategyName().values()) {
|
||||
// 如果防护对象关联了旁路手动牵引策略,那么删除该策略
|
||||
if (v.getProtectName().equals(objName)) {
|
||||
// 如果策略正在运行,直接报错
|
||||
if (v.isRunning()) {
|
||||
log.error("!!!!Remove Traction Strategy Error, It's Running: {}", v);
|
||||
return ErrorCode.ERR_CALLDEVICE;
|
||||
}
|
||||
|
||||
ret = getCleanTypePort().delBypassManualTractionStrategyForUMC(v.getPolicyName());
|
||||
|
||||
if (ret.getResultRetVal() == 0) {
|
||||
log.debug("Remove Traction Strategy {} Succeed", v.getPolicyName());
|
||||
} else {
|
||||
log.error("!!!!Remove Traction Strategy {} Error: {}", v.getPolicyName(),
|
||||
ret.getResultInfo().getValue());
|
||||
return ErrorCode.ERR_CALLDEVICE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 解除关联的防护模板
|
||||
for (DpProtectionStrategyInfo v : dpBypassManager.getProtectStrategy().values()) {
|
||||
if (v.getProtectTargetName().equals(objName)) {
|
||||
ret = getCleanTypePort().disableProtectionStrategyTemplateForUMC(objName, v.getProtectStrategyName());
|
||||
|
||||
if (ret.getResultRetVal() == 0) {
|
||||
log.debug("Disable Protection Strategy Template {} Succeed", objName);
|
||||
} else {
|
||||
log.error("!!!!Disable Protection Strategy Template {} Error: {}", objName,
|
||||
ret.getResultInfo().getValue());
|
||||
return ErrorCode.ERR_CALLDEVICE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 删除防护对象
|
||||
ret = getCleanTypePort().deleteProtectionObjectForUMC(objName);
|
||||
|
||||
if (ret.getResultRetVal() == 0) {
|
||||
log.debug("Delete Protection Object {} Succeed", objName);
|
||||
} else {
|
||||
log.error("!!!!Delete Protection Object {} Error: {}", objName,
|
||||
ret.getResultInfo().getValue());
|
||||
return ErrorCode.ERR_CALLDEVICE;
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create umc portect object error code.
|
||||
*
|
||||
* @param objName the obj name
|
||||
* @param ipSegment the ip segment
|
||||
* @param ipType the ip type
|
||||
* @param type the type
|
||||
* @param bandWidth the band width
|
||||
* @return the error code
|
||||
*/
|
||||
private ErrorCode createUMCPortectObject(String objName, String ipSegment, int ipType, String type,
|
||||
Long bandWidth) {
|
||||
// 创建对象
|
||||
NtcRequestResultInfo ret = getCleanTypePort()
|
||||
.addProtectionObjectForUMC("",
|
||||
allCleanupDevices,
|
||||
|
@ -79,12 +160,35 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
|||
|
||||
if (ret.getResultRetVal() == 0) {
|
||||
log.debug("Add Protection Object {} Succeed", objName);
|
||||
return ErrorCode.ERR_OK;
|
||||
|
||||
} else {
|
||||
log.error("!!!!Add Protection Object {}, {}, {} Error: {}", objName, ipSegment, ipType,
|
||||
ret.getResultInfo().getValue());
|
||||
return ErrorCode.ERR_CALLDEVICE;
|
||||
}
|
||||
|
||||
// 关联模板
|
||||
String template = Helper.getDpTemplate(type, bandWidth);
|
||||
|
||||
// 未找到合适的模板
|
||||
if (TemplateConfigure.UMC_TEMPLATE.stream().noneMatch(v -> v.getName().equals(template))) {
|
||||
log.error("!!!!DpTech Can't Math Template: {}, {} From {}", type, bandWidth,
|
||||
TemplateConfigure.UMC_TEMPLATE);
|
||||
return ErrorCode.ERR_NOSUCHTYPE;
|
||||
}
|
||||
|
||||
// UMC关联模板
|
||||
ret = getCleanTypePort().linkProtectionStrategyTemplateForUMC(objName, template);
|
||||
|
||||
if (ret.getResultRetVal() == 0) {
|
||||
log.debug("{} Link Protection Strategy Template {} Succeed", objName, template);
|
||||
} else {
|
||||
log.error("!!!!{} Link Protection Strategy Template {} Error: {}", objName, template,
|
||||
ret.getResultInfo().getValue());
|
||||
return ErrorCode.ERR_CALLDEVICE;
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,9 +349,9 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets protection strategy template.
|
||||
* Gets protection strategy template association.
|
||||
*/
|
||||
private void getProtectionStrategyTemplate() {
|
||||
private void getProtectionStrategyTemplateAssociation() {
|
||||
try {
|
||||
log.info("++++Begging DPTech Get All Protection Strategy Association Relation");
|
||||
|
||||
|
@ -586,7 +690,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
|||
|
||||
if (timerCnt++ % DpTechConfigValue.PROTECTION_UPGRADE_PERIOD == 0) {
|
||||
// 更新防护对象与目标关联关系
|
||||
getProtectionStrategyTemplate();
|
||||
getProtectionStrategyTemplateAssociation();
|
||||
}
|
||||
|
||||
// 清理旁路手动牵引策略
|
||||
|
|
|
@ -31,7 +31,7 @@ public class Helper {
|
|||
/**
|
||||
* Instantiates a new Helper.
|
||||
*/
|
||||
private Helper () {
|
||||
private Helper() {
|
||||
throw new AssertionError("Instantiating utility class.");
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,8 @@ public class Helper {
|
|||
} else if (addr.isIPv6() && ipV6All.equals(rangeIp)) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
// 处理CIDR格式
|
||||
if (rangeIp.contains(cidrSplit)) {
|
||||
|
@ -182,7 +183,8 @@ public class Helper {
|
|||
addr = new IPAddressString(ipAddr).toAddress();
|
||||
IPAddressSeqRange range = lower.toSequentialRange(upper);
|
||||
return range.contains(addr);
|
||||
} catch (AddressStringException ignored) {}
|
||||
} catch (AddressStringException ignored) {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -216,18 +218,13 @@ public class Helper {
|
|||
* @return the dp template
|
||||
*/
|
||||
public static String getDpTemplate(String type, Long bandWidth) {
|
||||
// Map<String, List<TemplateInfo>> result = TemplateConfigure.UMC_TEMPLATE.stream()
|
||||
// .collect(Collectors.groupingBy(TemplateInfo::getType));
|
||||
|
||||
|
||||
|
||||
Optional<String> ret = TemplateConfigure.UMC_TEMPLATE.stream()
|
||||
.filter(v -> v.getType().equals(type))
|
||||
.filter(v -> bandWidth > v.getBandMin() && bandWidth <= v.getBandMax())
|
||||
.findFirst()
|
||||
.map(TemplateInfo::getName);
|
||||
.filter(v -> (bandWidth == 0 && v.getBandMin() == 0)
|
||||
|| (bandWidth > v.getBandMin() && (bandWidth <= v.getBandMax() || v.getBandMax() == -1L)))
|
||||
.map(TemplateInfo::getName)
|
||||
.findFirst();
|
||||
|
||||
log.info("{}", ret);
|
||||
return "";
|
||||
return ret.orElse("");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,6 @@ public class TemplateConfigureTest extends InitTestEnvironment {
|
|||
*/
|
||||
@Test
|
||||
public void templateGetTest() {
|
||||
|
||||
for (String v : new String[]{"DNS", "GAME", "WEB", "GENERAL"}) {
|
||||
for (Long k : new Long[]{0L, 200L, 500L, 800L, 1500L, 1600L}) {
|
||||
log.info("[{}, {}] with template: {}", v, k,
|
||||
|
|
Loading…
Reference in New Issue