Merge remote-tracking branch 'origin/v2.0.5_dev' into v2.0.5_dev

This commit is contained in:
HuangXin 2021-01-14 18:10:54 +08:00
commit cc97418d1f
3 changed files with 85 additions and 31 deletions

View File

@ -104,8 +104,7 @@ public class DisposeTaskController {
String endTime = String.valueOf(req.getDisposeTime() == -1 ? 5256000: req.getDisposeTime());
NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class,
Optional.ofNullable(req.getFlowDirection()).orElse(2));
Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType())
.orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()}));
Long attackType = DDoSAttackType.getTypeMaskFromAttackType(new Integer[]{DDoSAttackType.RST_FLOOD.getValue()});
Integer flowBand = Optional.ofNullable(req.getFlowBandwidth())
.orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH);
@ -185,8 +184,7 @@ public class DisposeTaskController {
Optional.ofNullable(req.getFlowDirection())
.orElse(2)))
.attackType(DDoSAttackType.getTypeMaskFromAttackType(
Optional.ofNullable(req.getAttackType())
.orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})))
new Integer[]{DDoSAttackType.RST_FLOOD.getValue()}))
.flowBandWidth(Optional.ofNullable(req.getFlowBandwidth())
.orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH))
.build();
@ -236,8 +234,7 @@ public class DisposeTaskController {
String endTime = String.valueOf(req.getDisposeTime());
NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class,
Optional.ofNullable(req.getFlowDirection()).orElse(2));
Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType())
.orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()}));
Long attackType = DDoSAttackType.getTypeMaskFromAttackType(new Integer[]{DDoSAttackType.RST_FLOOD.getValue()});
Integer flowBand = Optional.ofNullable(req.getFlowBandwidth())
.orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH);

View File

@ -133,28 +133,24 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
// 设置任务状态为启动中
deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTING);
// 遍历设备攻击类型
for (DpTechAttackType t : DpTechAttackType.maskToDdosAttackType(deviceTask.getTaskAttackType())) {
// 启动迪普设备采用一种攻击类型
DpTechAttackType attackType = DpTechAttackType.maskToDdosAttackType(deviceTask.getTaskAttackType()).get(0);
// 出方向
if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) {
// 已经启动过的任务不再重复启动
if ((deviceTask.getExecAttackTypeOut() & t.getAttackTypeMask()) != 0) {
continue;
}
// 设置启动任务攻击类型状态
deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT,
t.getValue());
attackType.getValue());
// 调用迪普设备启动处置任务
ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(),
disposeTask.getDisposeCapacity(), NetflowDirection.DIRECTION_OUT,
t.getValue(), null);
attackType.getValue(), null);
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 标志启动成功
deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT,
t.getValue());
attackType.getValue());
log.info("DPTECH_UMC setup task {}, {} succeed: {}", t, NetflowDirection.DIRECTION_OUT, deviceTask);
log.info("DPTECH_UMC setup task {}, {} succeed: {}", attackType, NetflowDirection.DIRECTION_OUT, deviceTask);
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
} else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES * 10) {
@ -164,35 +160,31 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry());
//清除任务攻击类型启动标志
deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT,
t.getValue());
log.error("DPTECH_UMC setup task {}, {} times {} error: {}", t,
attackType.getValue());
log.error("DPTECH_UMC setup task {}, {} times {} error: {}", attackType,
NetflowDirection.DIRECTION_OUT, deviceTask.getErrRetry(), deviceTask);
} else {
log.error("DPTECH_UMC setup task {}, {} error {}: {}", t,
log.error("DPTECH_UMC setup task {}, {} error {}: {}", attackType,
NetflowDirection.DIRECTION_OUT, ret.getFirstParam(), deviceTask);
}
}
// 入方向
if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) {
// 已经启动过的任务不再重复启动
if ((deviceTask.getExecAttackTypeIn() & t.getAttackTypeMask()) != 0) {
continue;
}
// 设置启动任务攻击类型状态
deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN,
t.getValue());
attackType.getValue());
// 调用迪普设备启动处置任务
ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(),
disposeTask.getDisposeCapacity(), NetflowDirection.DIRECTION_IN,
t.getValue(), null);
attackType.getValue(), null);
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 标志启动成功
deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN,
t.getValue());
attackType.getValue());
log.info("DPTECH_UMC setup task {}, {} succeed: {}", t, NetflowDirection.DIRECTION_IN, deviceTask);
log.info("DPTECH_UMC setup task {}, {} succeed: {}", attackType, NetflowDirection.DIRECTION_IN, deviceTask);
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0);
} else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES * 10) {
@ -202,15 +194,15 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry());
//清除任务攻击类型启动标志
deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN,
t.getValue());
log.error("DPTECH_UMC setup task {}, {} times {} error: {}", t,
attackType.getValue());
log.error("DPTECH_UMC setup task {}, {} times {} error: {}", attackType,
NetflowDirection.DIRECTION_IN, deviceTask.getErrRetry(), deviceTask);
} else {
log.error("DPTECH_UMC setup task {}, {} error {}: {}", t,
log.error("DPTECH_UMC setup task {}, {} error {}: {}", attackType,
NetflowDirection.DIRECTION_IN, ret.getFirstParam(), deviceTask);
}
}
}
// 检查需要处置的各种攻击类型任务启动状态与处置任务执行状态判断该处置任务是否调用成功
boolean taskSetupSucceed = true;

View File

@ -0,0 +1,65 @@
package com.dispose.test.dev.service;
import com.dispose.service.TemplateService;
import com.dispose.test.dev.Global.InitTestEnvironment;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@Transactional
@Rollback
public class TemplateServiceTest extends InitTestEnvironment {
@Resource
private TemplateService templateService;
@Test
public void getTemplateTest() {
Assert.assertEquals("Game_Server_10G", templateService.getTemplate("GAME",1600L));
Assert.assertEquals("Game_Server_10G", templateService.getTemplate("GAME", (long) 1500.5));
Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME",1500L));
Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME",(long) 1499.5));
Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME", 1L));
Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME", 100L));
Assert.assertNull(templateService.getTemplate("GAME",-1L));
log.info("GAME, 0L-----------template: {}", templateService.getTemplate("GAME", 0L));
log.info("GAME, 0.9-----------template: {}", templateService.getTemplate("GAME", (long) 0.9));
Assert.assertEquals("DNS_Server_10G", templateService.getTemplate("DNS",1600L));
Assert.assertEquals("DNS_Server_1G", templateService.getTemplate("DNS",1500L));
Assert.assertEquals("DNS_Server_1G", templateService.getTemplate("DNS",1L));
//Assert.assertEquals("Game_Server_1G", templateService.getTemplate("DNS",0L));
Assert.assertNull(templateService.getTemplate("DNS",-1L));
Assert.assertEquals("WEB_Server_10G", templateService.getTemplate("WEB",1600L));
Assert.assertEquals("WEB_Server_1G", templateService.getTemplate("WEB",1500L));
Assert.assertEquals("WEB_Server_1G", templateService.getTemplate("WEB",1L));
//Assert.assertEquals("Game_Server_1G", templateService.getTemplate("WEB",0L));
Assert.assertNull(templateService.getTemplate("WEB",-1L));
Assert.assertEquals("General_Server_10G", templateService.getTemplate("GENERAL",1600L));
Assert.assertEquals("General_Server_1G", templateService.getTemplate("GENERAL",1500L));
Assert.assertEquals("General_Server_100M", templateService.getTemplate("GENERAL",500L));
Assert.assertEquals("General_Server_100M", templateService.getTemplate("GENERAL",1L));
//Assert.assertEquals("General_Server_100M", templateService.getTemplate("GENERAL",0L));
Assert.assertNull(templateService.getTemplate("GENERAL",-1L));
Assert.assertNull(templateService.getTemplate("ALL",100L));
}
}