|
15 | 15 | * ASTF profile |
16 | 16 | */ |
17 | 17 | public class AstfProfile { |
18 | | - protected static final Logger LOGGER = LoggerFactory.getLogger(AstfProfile.class); |
| 18 | + private static final Logger LOGGER = LoggerFactory.getLogger(AstfProfile.class); |
| 19 | + |
| 20 | + private static final String L7_PRECENT = "l7_percent"; |
| 21 | + private static final String CPS = "cps"; |
19 | 22 |
|
20 | 23 | private AstfIpGen astfIpGen; |
21 | 24 | private AstfGlobalInfo astfClientGlobalInfo; |
@@ -53,26 +56,90 @@ public AstfProfile(AstfIpGen defaultIpGen, AstfGlobalInfo astfClientGlobalInfo, |
53 | 56 | this.astfCapInfoList = astfCapInfoList; |
54 | 57 |
|
55 | 58 | /** |
56 | | - * for pcap file scenario |
57 | | - * TODO: need to be implemented in the future |
| 59 | + * for pcap file parse scenario |
58 | 60 | */ |
59 | 61 | if (astfCapInfoList != null && astfCapInfoList.size() != 0) { |
60 | | - |
61 | 62 | String mode = null; |
62 | | - Map<String, Object> allCapInfo = new HashMap(); |
| 63 | + List<Map<String, Object>> allCapInfo = new ArrayList(); |
63 | 64 | List<Integer> dPorts = new ArrayList(); |
64 | 65 | int totalPayload = 0; |
65 | 66 | for (AstfCapInfo capInfo : astfCapInfoList) { |
66 | 67 | String capFile = capInfo.getFilePath(); |
67 | 68 | AstfIpGen ipGen = capInfo.getAstfIpGen() != null ? capInfo.getAstfIpGen() : defaultIpGen; |
68 | 69 | AstfGlobalInfoPerTemplate globC = capInfo.getClientGlobInfo(); |
69 | 70 | AstfGlobalInfoPerTemplate globS = capInfo.getServerGlobInfo(); |
70 | | - AstfProgram progC = new AstfProgram(new File(capFile), AstfProgram.SideType.Client, null, true); |
71 | | - AstfProgram progS = new AstfProgram(new File(capFile), AstfProgram.SideType.Server, null, true); |
| 71 | + AstfProgram progC = new AstfProgram(capFile, AstfProgram.SideType.Client); |
| 72 | + AstfProgram progS = new AstfProgram(capFile, AstfProgram.SideType.Server); |
72 | 73 | progC.updateKeepAlive(progS); |
73 | | - //TODO: analysis pcap file data. |
| 74 | + |
| 75 | + AstfTcpInfo tcpC = new AstfTcpInfo(capFile); |
| 76 | + int tcpCPort = tcpC.getPort(); |
| 77 | + float cps = capInfo.getCps(); |
| 78 | + float l7Percent = capInfo.getL7Percent(); |
| 79 | + if (mode == null) { |
| 80 | + if (l7Percent > 0) { |
| 81 | + mode = L7_PRECENT; |
| 82 | + } else { |
| 83 | + mode = CPS; |
| 84 | + } |
| 85 | + } else { |
| 86 | + if (mode.equals(L7_PRECENT) && l7Percent == 0) { |
| 87 | + throw new IllegalStateException("If one cap specifies l7_percent, then all should specify it"); |
| 88 | + } |
| 89 | + if (mode.equals(CPS) && l7Percent > 0) { |
| 90 | + throw new IllegalStateException("Can't mix specifications of cps and l7_percent in same cap list"); |
| 91 | + } |
| 92 | + } |
| 93 | + totalPayload += progC.getPayloadLen(); |
| 94 | + |
| 95 | + int dPort; |
| 96 | + AstfAssociation myAssoc; |
| 97 | + if (capInfo.getAssoc() == null) { |
| 98 | + dPort = tcpCPort; |
| 99 | + myAssoc = new AstfAssociation(new AstfAssociationRule(dPort)); |
| 100 | + } else { |
| 101 | + dPort = capInfo.getAssoc().getPort(); |
| 102 | + myAssoc = capInfo.getAssoc(); |
| 103 | + throw new IllegalStateException(String.format("More than one cap use dest port %s. This is currently not supported.", dPort)); |
| 104 | + } |
| 105 | + dPorts.add(dPort); |
| 106 | + |
| 107 | + /** |
| 108 | + * add param to cap info map |
| 109 | + */ |
| 110 | + HashMap<String, Object> map = new HashMap(); |
| 111 | + map.put("ip_gen", ipGen); |
| 112 | + map.put("prog_c", progC); |
| 113 | + map.put("prog_s", progS); |
| 114 | + map.put("glob_c", globC); |
| 115 | + map.put("glob_s", globS); |
| 116 | + map.put("cps", cps); |
| 117 | + map.put("d_port", dPort); |
| 118 | + map.put("my_assoc", myAssoc); |
| 119 | + map.put("limit", capInfo.getLimit()); |
| 120 | + allCapInfo.add(map); |
| 121 | + } |
| 122 | + |
| 123 | + //calculate cps from l7 percent |
| 124 | + if (mode.equals(L7_PRECENT)) { |
| 125 | + float percentSum = 0; |
| 126 | + for (Map<String, Object> map : allCapInfo) { |
| 127 | + float newCps = ((AstfProgram) map.get("prog_c")).getPayloadLen() * 100.0f / totalPayload; |
| 128 | + map.put("cps", newCps); |
| 129 | + percentSum += newCps; |
| 130 | + } |
| 131 | + if (percentSum != 100) { |
| 132 | + throw new IllegalStateException("l7_percent values must sum up to 100"); |
| 133 | + } |
74 | 134 | } |
75 | 135 |
|
| 136 | + for (Map<String, Object> map : allCapInfo) { |
| 137 | + AstfTcpClientTemplate tempC = new AstfTcpClientTemplate((AstfProgram) map.get("prog_c"), (AstfIpGen) map.get("ip_gen"), null, |
| 138 | + (int) map.get("d_port"), (float) map.get("cps"), (AstfGlobalInfoPerTemplate) map.get("glob_c"), (int) map.get("limit")); |
| 139 | + AstfTcpServerTemplate tempS = new AstfTcpServerTemplate((AstfProgram) map.get("prog_s"), (AstfAssociation) map.get("my_assoc"), (AstfGlobalInfoPerTemplate) map.get("glob_s")); |
| 140 | + AstfTemplate template = new AstfTemplate(tempC, tempS); |
| 141 | + astfTemplateList.add(template); |
| 142 | + } |
76 | 143 | } |
77 | 144 | } |
78 | 145 |
|
|
0 commit comments