REM:
1. 更新upf设备防护对象和心跳获取接口
This commit is contained in:
chenlinghy 2021-07-29 11:00:12 +08:00
parent 23c0b35c4a
commit 9a5c08b4b4
1 changed files with 8 additions and 131 deletions

View File

@ -1,24 +1,18 @@
package com.dispose.ability.impl;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeConfigValue;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode;
import com.dispose.common.Helper;
import com.dispose.common.IpAddrType;
import com.dispose.common.NetflowDirection;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.dispose.pojo.entity.ServiceInfo;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.pojo.vo.DeviceFirewareInfo;
import com.pengxin.dispose.common.PengXinDisposeAbilityRsp;
import com.pengxin.dispose.common.PengXinStartTaskItem;
import com.pengxin.dispose.common.PengXinStartTaskRsp;
import com.pengxin.dispose.common.PengXinStopTaskRsp;
import com.pengxin.dispose.common.PengXinTaskStatusRsp;
import com.pengxin.dispose.protocol.PengXinInterface;
import inet.ipaddr.IPAddress;
import inet.ipaddr.IPAddressString;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@ -30,18 +24,11 @@ import java.util.List;
/**
* The type upf ability.
*
* @author Nicole
*/
@Slf4j
public class UpfAbilityImpl extends PengXinAbilityImpl {
/**
* The Protect ip v 4.
*/
private final List<String> protectIpV4 = new ArrayList<>();
/**
* The Protect ip v 6.
*/
private final List<String> protectIpV6 = new ArrayList<>();
/**
* The Restful interface.
*/
@ -54,15 +41,6 @@ public class UpfAbilityImpl extends PengXinAbilityImpl {
* The Task req id.
*/
private Long taskReqId = System.currentTimeMillis();
/**
* The Timer cnt.
*/
private long timerCnt = 0;
/**
* The Device link status.
*/
private boolean deviceLinkStatus = false;
/**
* The Url root path.
*/
@ -300,39 +278,8 @@ public class UpfAbilityImpl extends PengXinAbilityImpl {
*/
@Override
public boolean getDeviceLinkStatus() {
return deviceLinkStatus;
}
/**
* Dev get link status.
*/
private void devGetLinkStatus() {
try {
String url = urlRootPath + "dispose_device/information/linkstatus";
if (token == null || token.length() == 0) {
deviceLinkStatus = false;
return;
}
ErrorCode err = restfulInterface.getLinkStatus(url, token);
if (err == ErrorCode.ERR_LOGOUT) {
// 重新登录获取 token
upgradeToken();
err = restfulInterface.getLinkStatus(url, token);
}
if (err == ErrorCode.ERR_OK) {
deviceLinkStatus = true;
}
return;
} catch (Exception ex) {
log.error(ex.getMessage());
}
deviceLinkStatus = false;
//upf设备不提供链接状态接口默认该设备在线
return true;
}
/**
@ -340,45 +287,7 @@ public class UpfAbilityImpl extends PengXinAbilityImpl {
*/
@Override
public void getDisposeDeviceProtectObject() {
if (token == null || token.length() == 0) {
return;
}
try {
String url = urlRootPath + "dispose_device/information/capacity";
ProtocolRespDTO<PengXinDisposeAbilityRsp> rspInfo = restfulInterface.getDeviceDisposeAbility(url, token);
if (rspInfo != null && rspInfo.getCode() == ErrorCode.ERR_OK.getHttpCode()
&& rspInfo.getMsgContent().getStatus() == ErrorCode.ERR_OK.getCode()) {
rspInfo.getMsgContent().getCapacity().forEach(v -> {
if (v.getObjectType().equals(DisposeObjectType.DOMAIN.getValue())) {
log.error("Unsupported: {}", v.getObjectType());
} else if (v.getObjectType().equals(DisposeObjectType.URL.getValue())) {
log.error("Unsupported: {}", v.getObjectType());
} else {
synchronized (this) {
protectIpV4.clear();
protectIpV6.clear();
if (v.getIpType() == null || v.getIpType().equals(IpAddrType.IPV4_IPV6.getValue())) {
if (v.getDisposeIp() == null) {
protectIpV4.add("");
protectIpV6.add("");
}
} else if (v.getIpType().equals(IpAddrType.IPV4.getValue())) {
protectIpV4.add("");
} else if (v.getIpType().equals(IpAddrType.IPV6.getValue())) {
protectIpV6.add("");
}
}
}
});
}
} catch (Exception ignored) {
}
//upf设备不提供处置能力接口
}
/**
@ -389,34 +298,9 @@ public class UpfAbilityImpl extends PengXinAbilityImpl {
*/
@Override
public boolean isCarryProtectIp(String ipAddress) {
boolean ret = false;
IPAddress address = new IPAddressString(ipAddress).getAddress();
synchronized (this) {
if (address.isIPv4()) {
ret = protectIpV4.stream().anyMatch(v -> Helper.ipInRange(v, ipAddress));
}
if (address.isIPv6()) {
ret = protectIpV6.stream().anyMatch(v -> Helper.ipInRange(v, ipAddress));
}
}
if (!ret) {
// 更新设备防护IP
getDisposeDeviceProtectObject();
synchronized (this) {
if (address.isIPv4()) {
ret = protectIpV4.stream().anyMatch(v -> Helper.ipInRange(v, ipAddress));
}
if (address.isIPv6()) {
ret = protectIpV6.stream().anyMatch(v -> Helper.ipInRange(v, ipAddress));
}
}
}
return ret;
//根据设备提供的处置能力,涉及处置能力处置对象类型IP类型和该能力能够处置的IP因现在未提供处置能力接口默认所有的处置IP都支持
//如果提供处置能力接口入参ipAddress会根据能够处置的IP范围进行判断
return true;
}
/**
@ -476,15 +360,8 @@ public class UpfAbilityImpl extends PengXinAbilityImpl {
*/
@Override
public void periodTaskRuntime() {
//防护对象和设备状态都是默认值不根据设备实时状态获取不做处理
log.debug("++++UPF Period Task Running");
// 更新防护对象
getDisposeDeviceProtectObject();
// 更新心跳状态
if (timerCnt++ % DisposeConfigValue.HEART_PERIOD_OF_SECOND == 0) {
devGetLinkStatus();
}
log.debug("----UPF Period Task Running");
}
/**