From 22c0670e84bd075c5c11e13e0c72b120e566ca8f Mon Sep 17 00:00:00 2001 From: HuangXin Date: Fri, 15 Jan 2021 15:37:58 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E6=9B=B4=E6=96=B0UMCc?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E3=80=81=E5=88=A0=E9=99=A4=E9=98=B2=E6=8A=A4?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E4=B8=9A=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechBypassAbilityImpl.java | 114 +++++++++++++++++- src/main/java/com/dispose/common/Helper.java | 23 ++-- .../dev/config/TemplateConfigureTest.java | 1 - 3 files changed, 119 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index ec2d41b9..9d29a734 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -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(); } // 清理旁路手动牵引策略 diff --git a/src/main/java/com/dispose/common/Helper.java b/src/main/java/com/dispose/common/Helper.java index 73f98ca2..48d27a94 100644 --- a/src/main/java/com/dispose/common/Helper.java +++ b/src/main/java/com/dispose/common/Helper.java @@ -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> result = TemplateConfigure.UMC_TEMPLATE.stream() -// .collect(Collectors.groupingBy(TemplateInfo::getType)); - - - Optional 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(""); } } diff --git a/src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java b/src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java index 59442906..d126ee74 100644 --- a/src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java +++ b/src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java @@ -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,