diff --git a/src/main/java/com/dispose/common/IPAddrType.java b/src/main/java/com/dispose/common/IPAddrType.java index bc3006d3..7c07b84e 100644 --- a/src/main/java/com/dispose/common/IPAddrType.java +++ b/src/main/java/com/dispose/common/IPAddrType.java @@ -63,6 +63,11 @@ public enum IPAddrType { */ public static boolean ipInRange(String rangeIp, String ipAddr) throws AddressStringException { final int numIp = 2; + + if (rangeIp.equals(ipAddr)) { + return true; + } + String[] ipList = rangeIp.split("-"); if (ipList.length != numIp) { diff --git a/src/main/java/com/dispose/dispose/DeviceRouter.java b/src/main/java/com/dispose/dispose/DeviceRouter.java index 5bb172c9..83adcbb8 100644 --- a/src/main/java/com/dispose/dispose/DeviceRouter.java +++ b/src/main/java/com/dispose/dispose/DeviceRouter.java @@ -4,6 +4,7 @@ import com.dispose.common.DisposeDeviceType; import com.dispose.common.GlobalVar; import com.dispose.common.IPAddrType; import com.dispose.dispose.impl.DpTechImpl; +import com.dispose.dispose.impl.HaoHanImpl; import com.dispose.dispose.impl.VirtualDeviceImpl; import java.util.concurrent.ConcurrentHashMap; @@ -36,15 +37,20 @@ public class DeviceRouter { if (DEVICE_CACHE_MAP.containsKey(mapKey)) { return DEVICE_CACHE_MAP.get(mapKey); } else { + DisposeEntryManager dev = null; // 第一次访问创建新对象并缓存 if (GlobalVar.USED_VIRTUAL_DISPOSE_MODE) { // 虚拟设备,供调试业务使用 - DisposeEntryManager dev = new VirtualDeviceImpl(ipAddr); - DEVICE_CACHE_MAP.put(mapKey, dev); - return dev; + dev = new VirtualDeviceImpl(ipAddr); } else if (devType == DisposeDeviceType.DPTECH_UMC.getCode()) { // 迪普设备 - DisposeEntryManager dev = new DpTechImpl(ipAddr); + dev = new DpTechImpl(ipAddr); + } else if (devType == DisposeDeviceType.HAOHAN_PLATFORM.getCode()) { + // 浩瀚设备 + dev = new HaoHanImpl(ipAddr); + } + + if (dev != null) { DEVICE_CACHE_MAP.put(mapKey, dev); return dev; } diff --git a/src/main/java/com/dispose/dispose/DisposeEntryManager.java b/src/main/java/com/dispose/dispose/DisposeEntryManager.java index 8b8a948d..fb7bf455 100644 --- a/src/main/java/com/dispose/dispose/DisposeEntryManager.java +++ b/src/main/java/com/dispose/dispose/DisposeEntryManager.java @@ -90,9 +90,4 @@ public interface DisposeEntryManager { * @return the device info */ DeviceInfo getDeviceInfo(); - - //public NtcRequestResultInfo stopAbnormalTask(String abnormalIp, int attackType, int direction); - - //public NtcRequestResultInfo startAbnormalTask(String abnormalIp, int attackType, int direction); - } diff --git a/src/main/java/com/dispose/dispose/impl/HaoHanImpl.java b/src/main/java/com/dispose/dispose/impl/HaoHanImpl.java new file mode 100644 index 00000000..b4dc3636 --- /dev/null +++ b/src/main/java/com/dispose/dispose/impl/HaoHanImpl.java @@ -0,0 +1,178 @@ +package com.dispose.dispose.impl; + +import com.dispose.common.DeviceCapacity; +import com.dispose.common.ErrorCode; +import com.dispose.common.IPAddrType; +import com.dispose.dispose.DisposeEntryManager; +import com.dispose.dispose.po.DeviceInfo; +import com.dispose.pojo.po.DisposeDeviceCapacity; +import lombok.extern.slf4j.Slf4j; + +import java.util.ArrayList; +import java.util.List; + +/** + * The type Hao han. + * + * @author + */ +@Slf4j +public class HaoHanImpl implements DisposeEntryManager { + + /** + * Instantiates a new Hao han. + * + * @param ipAddr the ip addr + */ + public HaoHanImpl(String ipAddr) { + + } + + /** + * Instantiates a new Hao han. + * + * @param ipAddr the ip addr + * @param type the type + */ + public HaoHanImpl(String ipAddr, IPAddrType type) { + + } + + /** + * Run dispose error code. + * + * @param ip the ip + * @param type the type + * @return the error code + */ + @Override + public ErrorCode runDispose(String ip, DeviceCapacity type) { + return ErrorCode.ERR_OK; + } + + /** + * Stop dispose error code. + * + * @param ipAddr the ip addr + * @param type the type + * @return the error code + */ + @Override + public ErrorCode stopDispose(String ipAddr, DeviceCapacity type) { + return ErrorCode.ERR_OK; + } + + /** + * Gets version. + * + * @return the version + */ + @Override + public String getVersion() { + return "Not Support"; + } + + /** + * Gets device info. + * + * @return the device info + */ + @Override + public DeviceInfo getDeviceInfo() { + // 当前设备接口不支持,返回模拟数据 + return DeviceInfo.builder() + .vendor("HaoHan") + .model("Unknown") + .firmware("Unknown") + .os("Linux Server") + .kernel("Linux") + .arch("x86_64") + .memory(-1) + .freeMemory(-1) + .cpuUsed(-1) + .build(); + } + + /** + * Gets device capacity. + * + * @return the device capacity + */ + @Override + public List getDeviceCapacity() { + List capList = new ArrayList<>(); + + // 保存清洗能力信息 + capList.add(DisposeDeviceCapacity.builder() + // 清洗能力 + .capacity(DeviceCapacity.CLEANUP.getCode()) + .tolFlowCapacity(0) + // IPv4范围 + .protectIpV4(new String[] {"0.0.0.0-255.255.255.255"}) + // IPv6范围 + .protectIpV6(new String[] {""}) + .build()); + + return capList; + } + + /** + * Gets device link status. + * + * @return the device link status + */ + @Override + public boolean getDeviceLinkStatus() { + try { + // 获取防护对象接口调用成功认为设备心跳正常 + getAllProtectionObject(); + return true; + } catch (Exception ex) { + log.error(ex.getMessage()); + } + + return false; + } + + /** + * Gets all detection object. + * + * @param the type parameter + * @return the all detection object + */ + @Override + public T getAllDetectionObject() { + return null; + } + + /** + * Gets all protection object. + * + * @param the type parameter + * @return the all protection object + */ + @Override + public T getAllProtectionObject() { + return null; + } + + /** + * Gets protect devices. + * + * @return the protect devices + */ + @Override + public String getProtectDevices() { + return null; + } + + /** + * Gets detection devices. + * + * @return the detection devices + */ + @Override + public String getDetectionDevices() { + return null; + } +} diff --git a/src/test/java/com/dispose/test/debug/demo.java b/src/test/java/com/dispose/test/debug/demo.java index 51215f01..7fd1be01 100644 --- a/src/test/java/com/dispose/test/debug/demo.java +++ b/src/test/java/com/dispose/test/debug/demo.java @@ -1,16 +1,28 @@ package com.dispose.test.debug; +import com.dispose.common.IPAddrType; import com.dispose.pojo.vo.common.IDArrayReq; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import inet.ipaddr.AddressStringException; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.junit4.SpringRunner; +/** + * The type Demo. + * + * @author + */ @Slf4j public class demo { + /** + * A 1 idid array req test. + * + * @throws JsonProcessingException the json processing exception + */ @Test public void a1_IDIDArrayReqTest() throws JsonProcessingException { String json = "{\"id\":[\"1\", \"123\", \"1234\", \"1234\"]}"; @@ -28,6 +40,19 @@ public class demo { id = new ObjectMapper().readValue(json, IDArrayReq.class); Assert.assertEquals(id.getId().length, 3); - id = new ObjectMapper().readValue(json4, IDArrayReq.class); + //id = new ObjectMapper().readValue(json4, IDArrayReq.class); + } + + /** + * A 2 ip range test. + * + * @throws AddressStringException the address string exception + */ + @Test + public void a2_ipRangeTest() throws AddressStringException { + Assert.assertTrue(IPAddrType.ipInRange("192.168.0.1-192.168.0.100", "192.168.0.30")); + Assert.assertTrue(IPAddrType.ipInRange("192.168.0.30", "192.168.0.30")); + Assert.assertTrue(IPAddrType.ipInRange("192.168.0.40-192.168.0.40", "192.168.0.40")); + Assert.assertTrue(IPAddrType.ipInRange("0.0.0.0-255.255.255.255", "192.168.0.30")); } }