Skip to content

Commit 2a62510

Browse files
Merge pull request #85 from cisco-system-traffic-generator/astf-cleanup
Astf cleanup
2 parents b673d3d + 7dd015d commit 2a62510

19 files changed

+60
-92
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ build/
77
.settings/
88
/bin/
99
target/
10+
pom.xml

src/main/java/com/cisco/trex/stateful/api/lowlevel/ASTFAssociation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public ASTFAssociation(List<ASTFAssociationRule> astfAssociationRuleList) {
2424
* @param astfAssociationRule
2525
*/
2626
public ASTFAssociation(ASTFAssociationRule astfAssociationRule) {
27-
astfAssociationRuleList = new ArrayList();
27+
astfAssociationRuleList = new ArrayList<>();
2828
astfAssociationRuleList.add(astfAssociationRule);
2929
}
3030

src/main/java/com/cisco/trex/stateful/api/lowlevel/ASTFCapInfo.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class ASTFCapInfo {
1515
private ASTFGlobalInfoPerTemplate clientGlobInfo; // client global param
1616
private int limit; // Limit the number of flows
1717

18-
private ASTFCapInfo(AstfCapInfoBuilder builder) {
18+
ASTFCapInfo(AstfCapInfoBuilder builder) {
1919
filePath = builder.filePath;
2020
cps = builder.cps;
2121
assoc = builder.assoc;
@@ -43,12 +43,9 @@ private void paramCheck() {
4343
throw new IllegalStateException(
4444
String.format("bad param combination,l7Percent %s ,cps %s ", l7Percent, cps));
4545
}
46-
l7Percent = l7Percent;
47-
cps = cps;
46+
4847
} else {
49-
if (cps > 0) {
50-
cps = cps;
51-
} else {
48+
if (cps <= 0) {
5249
cps = 1;
5350
}
5451
}
@@ -145,15 +142,15 @@ public int getLimit() {
145142
/** AstfCapInfo builder */
146143
public static final class AstfCapInfoBuilder {
147144

148-
private String filePath;
149-
private float cps;
150-
private ASTFAssociation assoc;
151-
private ASTFIpGen astfIpGen;
152-
private int port;
153-
private float l7Percent;
154-
private ASTFGlobalInfoPerTemplate serverGlobInfo;
155-
private ASTFGlobalInfoPerTemplate clientGlobInfo;
156-
private int limit;
145+
String filePath;
146+
float cps;
147+
ASTFAssociation assoc;
148+
ASTFIpGen astfIpGen;
149+
int port;
150+
float l7Percent;
151+
ASTFGlobalInfoPerTemplate serverGlobInfo;
152+
ASTFGlobalInfoPerTemplate clientGlobInfo;
153+
int limit;
157154

158155
public AstfCapInfoBuilder filePath(String val) {
159156
filePath = val;

src/main/java/com/cisco/trex/stateful/api/lowlevel/ASTFClientTemplate.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
abstract class ASTFClientTemplate extends ASTFTemplateBase {
1010
private ASTFCluster astfCluster;
1111
private ASTFIpGen iPGen;
12-
private ASTFProgram astfProgram;
1312

1413
/**
1514
* construct
@@ -22,7 +21,6 @@ public ASTFClientTemplate(ASTFIpGen iPGen, ASTFCluster astfCluster, ASTFProgram
2221
super(astfProgram);
2322
this.iPGen = iPGen;
2423
this.astfCluster = astfCluster == null ? new ASTFCluster() : astfCluster;
25-
this.astfProgram = astfProgram;
2624
}
2725

2826
/**

src/main/java/com/cisco/trex/stateful/api/lowlevel/ASTFCmdSend.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public String buf() {
6060
return base64Buf;
6161
}
6262

63-
private String encodeBase64(byte[] bytes) {
63+
private static String encodeBase64(byte[] bytes) {
6464
Base64.Encoder encoder = Base64.getEncoder();
6565
return encoder.encodeToString(bytes);
6666
}

src/main/java/com/cisco/trex/stateful/api/lowlevel/ASTFCmdTxPkt.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public int bufLen() {
6565
return bufLen;
6666
}
6767

68-
private String encodeBase64(byte[] bytes) {
68+
private static String encodeBase64(byte[] bytes) {
6969
Base64.Encoder encoder = Base64.getEncoder();
7070
return encoder.encodeToString(bytes);
7171
}

src/main/java/com/cisco/trex/stateful/api/lowlevel/ASTFGlobalInfoPerTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class ASTFGlobalInfoPerTemplate implements ASTFGlobalInfoBase {
1010
private JsonObject tcp = new JsonObject();
1111
private JsonObject ip = new JsonObject();
1212
private static final Set<String> tcpParamSet =
13-
new HashSet(Arrays.asList("initwnd", "mss", "no_delay", "rxbufsize", "txbufsize"));
13+
new HashSet<>(Arrays.asList("initwnd", "mss", "no_delay", "rxbufsize", "txbufsize"));
1414

1515
@Override
1616
public ASTFGlobalInfoBase scheduler(SchedulerParam schedulerParam, int value) {

src/main/java/com/cisco/trex/stateful/api/lowlevel/ASTFIpGen.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
/** Java implementation for TRex python sdk ASTFIpGen class */
66
public class ASTFIpGen {
7-
private ASTFIpGenDist distClient;
8-
private ASTFIpGenDist distServer;
9-
private ASTFIpGenGlobal ipGenGlobal;
10-
117
private JsonObject fields = new JsonObject();
128

139
/**
@@ -19,9 +15,6 @@ public class ASTFIpGen {
1915
*/
2016
public ASTFIpGen(
2117
ASTFIpGenDist distClient, ASTFIpGenDist distServer, ASTFIpGenGlobal ipGenGlobal) {
22-
this.distClient = distClient;
23-
this.distServer = distServer;
24-
this.ipGenGlobal = ipGenGlobal;
2518

2619
this.fields.add("dist_client", distClient.toJson());
2720
distClient.setDirection("c");

src/main/java/com/cisco/trex/stateful/api/lowlevel/ASTFProfile.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@ public class ASTFProfile {
1717

1818
private static final String L7_PRECENT = "l7_percent";
1919
private static final String CPS = "cps";
20-
21-
private ASTFIpGen astfIpGen;
2220
private ASTFGlobalInfo astfClientGlobalInfo;
2321
private ASTFGlobalInfo astfServerGlobalInfo;
2422
private List<ASTFTemplate> astfTemplateList;
25-
private List<ASTFCapInfo> astfCapInfoList;
26-
27-
private Map<String, Integer> tgName2TgId =
28-
new LinkedHashMap<>(); // template group name -> template group id
23+
private Map<String, Integer> tgName2TgId = new LinkedHashMap<>(); // template group name ->
24+
// template group id
2925

3026
/**
3127
* construct
@@ -57,11 +53,9 @@ public ASTFProfile(
5753

5854
if (astfTemplateList == null && astfCapInfoList == null) {
5955
throw new IllegalStateException(
60-
String.format(
61-
"bad param combination,AstfTemplate and AstfCapInfo should not be null at the same time "));
56+
"bad param combination,AstfTemplate and AstfCapInfo should not be null at the same time ");
6257
}
6358
this.astfTemplateList = astfTemplateList;
64-
this.astfCapInfoList = astfCapInfoList;
6559

6660
for (ASTFTemplate template : astfTemplateList) {
6761
if (template.getTgName() == null) {
@@ -77,10 +71,10 @@ public ASTFProfile(
7771
}
7872

7973
/** for pcap file parse scenario */
80-
if (astfCapInfoList != null && astfCapInfoList.size() != 0) {
74+
if (astfCapInfoList != null && !astfCapInfoList.isEmpty()) {
8175
String mode = null;
82-
List<Map<String, Object>> allCapInfo = new ArrayList();
83-
List<Integer> dPorts = new ArrayList();
76+
List<Map<String, Object>> allCapInfo = new ArrayList<>();
77+
List<Integer> dPorts = new ArrayList<>();
8478
int totalPayload = 0;
8579
for (ASTFCapInfo capInfo : astfCapInfoList) {
8680
String capFile = capInfo.getFilePath();
@@ -128,7 +122,7 @@ public ASTFProfile(
128122
dPorts.add(dPort);
129123

130124
/** add param to cap info map */
131-
HashMap<String, Object> map = new HashMap();
125+
HashMap<String, Object> map = new HashMap<>();
132126
map.put("ip_gen", ipGen);
133127
map.put("prog_c", progC);
134128
map.put("prog_s", progS);

src/main/java/com/cisco/trex/stateful/api/lowlevel/ASTFProgram.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private void createCmdFromCap(
113113
newCmds.add(new ASTFCmdConnect());
114114
}
115115

116-
ASTFCmd newCmd = null;
116+
ASTFCmd newCmd;
117117
for (int i = 0; i < cmds.size(); i++) {
118118
SideType dir = dirs.get(i);
119119
CPacketData cmd = cmds.get(i);
@@ -625,7 +625,7 @@ private static boolean isNumber(String str) {
625625

626626
/** cached Buffer class for inner use */
627627
static class BufferList {
628-
List<String> bufList = new ArrayList<>();
628+
List<String> list = new ArrayList<>();
629629
Map<String, Integer> bufHash = new HashMap<>();
630630

631631
/**
@@ -634,7 +634,7 @@ static class BufferList {
634634
* @return buf list length
635635
*/
636636
public int getLen() {
637-
return bufList.size();
637+
return list.size();
638638
}
639639

640640
/**
@@ -648,8 +648,8 @@ public int add(String base64Buf) {
648648
if (bufHash.containsKey(sha256Buf)) {
649649
return bufHash.get(sha256Buf);
650650
}
651-
bufList.add(base64Buf);
652-
int newIndex = bufList.size() - 1;
651+
list.add(base64Buf);
652+
int newIndex = list.size() - 1;
653653
bufHash.put(sha256Buf, newIndex);
654654
return newIndex;
655655
}
@@ -661,7 +661,7 @@ public int add(String base64Buf) {
661661
*/
662662
public JsonArray toJson() {
663663
JsonArray jsonArray = new JsonArray();
664-
for (String buf : bufList) {
664+
for (String buf : list) {
665665
jsonArray.add(buf);
666666
}
667667
return jsonArray;

0 commit comments

Comments
 (0)