Skip to content

Commit c787f7e

Browse files
author
Egor Blagov
committed
Merge remote-tracking branch 'stanley/master'
- Removed unused imports in conflicting file
2 parents a1db26b + 9b025c3 commit c787f7e

35 files changed

+3248
-40
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.cisco.trex.stateful;
2+
3+
import com.google.gson.JsonArray;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
/**
9+
* Astf Association
10+
*/
11+
public class AstfAssociation {
12+
13+
private List<AstfAssociationRule> astfAssociationRuleList;
14+
15+
/**
16+
* construct
17+
*
18+
* @param astfAssociationRuleList
19+
*/
20+
public AstfAssociation(List<AstfAssociationRule> astfAssociationRuleList) {
21+
this.astfAssociationRuleList = astfAssociationRuleList;
22+
}
23+
24+
/**
25+
* construct
26+
*
27+
* @param astfAssociationRule
28+
*/
29+
public AstfAssociation(AstfAssociationRule astfAssociationRule) {
30+
astfAssociationRuleList = new ArrayList();
31+
astfAssociationRuleList.add(astfAssociationRule);
32+
}
33+
34+
/**
35+
* to json format
36+
*
37+
* @return JsonArray
38+
*/
39+
public JsonArray toJson() {
40+
JsonArray jsonArray = new JsonArray();
41+
for (AstfAssociationRule rule : astfAssociationRuleList) {
42+
jsonArray.add(rule.toJson());
43+
}
44+
return jsonArray;
45+
}
46+
47+
/**
48+
* get Port
49+
*
50+
* @return port
51+
*/
52+
public int getPort() {
53+
if (astfAssociationRuleList.size() != 1) {
54+
throw new IllegalStateException(String.format("rule list size should be 1, but it's %s now", astfAssociationRuleList.size()));
55+
}
56+
return astfAssociationRuleList.get(0).getPort();
57+
}
58+
59+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.cisco.trex.stateful;
2+
3+
import com.google.gson.JsonObject;
4+
import org.apache.commons.lang.StringUtils;
5+
6+
/**
7+
* Astf Association Rule
8+
*/
9+
public class AstfAssociationRule {
10+
private JsonObject fields = new JsonObject();
11+
private int port;
12+
13+
/**
14+
* construct
15+
*
16+
* @param ipStart
17+
* @param ipEnd
18+
* @param port
19+
*/
20+
public AstfAssociationRule(String ipStart, String ipEnd, int port) {
21+
this.port = port;
22+
fields.addProperty("port", port);
23+
if (!StringUtils.isEmpty(ipStart)) {
24+
fields.addProperty("ip_start", ipStart);
25+
}
26+
if (!StringUtils.isEmpty(ipStart)) {
27+
fields.addProperty("ip_end", ipEnd);
28+
}
29+
}
30+
31+
/**
32+
* construct
33+
*
34+
* @param port
35+
*/
36+
public AstfAssociationRule(int port) {
37+
this(null, null, port);
38+
}
39+
40+
/**
41+
* get port
42+
*
43+
* @return port
44+
*/
45+
public int getPort() {
46+
return this.port;
47+
}
48+
49+
/**
50+
* to json format
51+
*
52+
* @return JsonObject
53+
*/
54+
public JsonObject toJson() {
55+
return fields;
56+
}
57+
}
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
package com.cisco.trex.stateful;
2+
3+
/**
4+
* Astf Cap Info,for pcap file usage
5+
*/
6+
public class AstfCapInfo {
7+
private String filePath;//pcap file name. Filesystem directory location is relative to the profile file in case it is not start with
8+
private float cps;//new connection per second rate
9+
private AstfAssociation assoc;//rule for server association in default take the destination port from pcap file
10+
private AstfIpGen astfIpGen;//tuple generator for this template
11+
private int port;//Override destination port, by default is taken from pcap
12+
private float l7Percent;//L7 stream bandwidth percent
13+
private AstfGlobalInfoPerTemplate serverGlobInfo;//server global param
14+
private AstfGlobalInfoPerTemplate clientGlobInfo;//client global param
15+
private int limit;//Limit the number of flows
16+
17+
private AstfCapInfo(AstfCapInfoBuilder builder) {
18+
filePath = builder.filePath;
19+
cps = builder.cps;
20+
assoc = builder.assoc;
21+
astfIpGen = builder.astfIpGen;
22+
port = builder.port;
23+
l7Percent = builder.l7Percent;
24+
serverGlobInfo = builder.serverGlobInfo;
25+
clientGlobInfo = builder.clientGlobInfo;
26+
limit = builder.limit;
27+
paramCheck();
28+
}
29+
30+
/**
31+
* new AstfCapInfo builder
32+
*
33+
* @return new builder
34+
*/
35+
public static AstfCapInfoBuilder newBuilder() {
36+
return new AstfCapInfoBuilder();
37+
}
38+
39+
private void paramCheck() {
40+
if (l7Percent > 0) {
41+
if (cps > 0) {
42+
throw new IllegalStateException(String.format("bad param combination,l7Percent %s ,cps %s ", l7Percent, cps));
43+
}
44+
l7Percent = l7Percent;
45+
cps = cps;
46+
} else {
47+
if (cps > 0) {
48+
cps = cps;
49+
} else {
50+
cps = 1;
51+
}
52+
}
53+
if (assoc == null) {
54+
if (port > 0) {
55+
assoc = new AstfAssociation(new AstfAssociationRule(port));
56+
} else {
57+
assoc = null;
58+
}
59+
}
60+
}
61+
62+
/**
63+
* getFilePath
64+
*
65+
* @return filePath
66+
*/
67+
public String getFilePath() {
68+
return filePath;
69+
}
70+
71+
/**
72+
* getCps
73+
*
74+
* @return cps
75+
*/
76+
public float getCps() {
77+
return cps;
78+
}
79+
80+
/**
81+
* getAssoc
82+
*
83+
* @return assoc
84+
*/
85+
public AstfAssociation getAssoc() {
86+
return assoc;
87+
}
88+
89+
/**
90+
* getAstfIpGen
91+
*
92+
* @return astfIpGen
93+
*/
94+
public AstfIpGen getAstfIpGen() {
95+
return astfIpGen;
96+
}
97+
98+
/**
99+
* getPort
100+
*
101+
* @return port
102+
*/
103+
public int getPort() {
104+
return port;
105+
}
106+
107+
/**
108+
* getL7Percent
109+
*
110+
* @return l7Percent
111+
*/
112+
public float getL7Percent() {
113+
return l7Percent;
114+
}
115+
116+
/**
117+
* getServerGlobInfo
118+
*
119+
* @return serverGlobInfo
120+
*/
121+
public AstfGlobalInfoPerTemplate getServerGlobInfo() {
122+
return serverGlobInfo;
123+
}
124+
125+
/**
126+
* getClientGlobInfo
127+
*
128+
* @return clientGlobInfo
129+
*/
130+
public AstfGlobalInfoPerTemplate getClientGlobInfo() {
131+
return clientGlobInfo;
132+
}
133+
134+
/**
135+
* getLimit
136+
*
137+
* @return limit
138+
*/
139+
public int getLimit() {
140+
return limit;
141+
}
142+
143+
/**
144+
* AstfCapInfo builder
145+
*/
146+
public static final class AstfCapInfoBuilder {
147+
private String filePath;
148+
private float cps;
149+
private AstfAssociation assoc;
150+
private AstfIpGen astfIpGen;
151+
private int port;
152+
private float l7Percent;
153+
private AstfGlobalInfoPerTemplate serverGlobInfo;
154+
private AstfGlobalInfoPerTemplate clientGlobInfo;
155+
private int limit;
156+
157+
public AstfCapInfoBuilder filePath(String val) {
158+
filePath = val;
159+
return this;
160+
}
161+
162+
public AstfCapInfoBuilder cps(float val) {
163+
cps = val;
164+
return this;
165+
}
166+
167+
public AstfCapInfoBuilder assoc(AstfAssociation val) {
168+
assoc = val;
169+
return this;
170+
}
171+
172+
public AstfCapInfoBuilder astfIpGen(AstfIpGen val) {
173+
astfIpGen = val;
174+
return this;
175+
}
176+
177+
public AstfCapInfoBuilder port(int val) {
178+
port = val;
179+
return this;
180+
}
181+
182+
public AstfCapInfoBuilder l7Percent(float val) {
183+
l7Percent = val;
184+
return this;
185+
}
186+
187+
public AstfCapInfoBuilder serverGlobInfo(AstfGlobalInfoPerTemplate val) {
188+
serverGlobInfo = val;
189+
return this;
190+
}
191+
192+
public AstfCapInfoBuilder clientGlobInfo(AstfGlobalInfoPerTemplate val) {
193+
clientGlobInfo = val;
194+
return this;
195+
}
196+
197+
public AstfCapInfoBuilder limit(int val) {
198+
limit = val;
199+
return this;
200+
}
201+
202+
public AstfCapInfo build() {
203+
return new AstfCapInfo(this);
204+
}
205+
}
206+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.cisco.trex.stateful;
2+
3+
import com.google.gson.JsonObject;
4+
5+
/**
6+
* abstract Astf Client Template class
7+
*/
8+
abstract class AstfClientTemplate extends AstfTemplateBase {
9+
private AstfCluster astfCluster;
10+
private AstfIpGen iPGen;
11+
private AstfProgram astfProgram;
12+
13+
/**
14+
* construct
15+
*
16+
* @param iPGen
17+
* @param astfCluster
18+
* @param astfProgram
19+
*/
20+
public AstfClientTemplate(AstfIpGen iPGen, AstfCluster astfCluster, AstfProgram astfProgram) {
21+
super(astfProgram);
22+
this.iPGen = iPGen;
23+
this.astfCluster = astfCluster == null ? new AstfCluster() : astfCluster;
24+
this.astfProgram = astfProgram;
25+
}
26+
27+
/**
28+
* to json format
29+
*
30+
* @return JsonObject
31+
*/
32+
@Override
33+
public JsonObject toJson() {
34+
JsonObject json = super.toJson();
35+
json.add("ip_gen", iPGen.toJson());
36+
json.add("cluster", astfCluster.toJson());
37+
return json;
38+
}
39+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.cisco.trex.stateful;
2+
3+
import com.google.gson.JsonObject;
4+
5+
/**
6+
* for future use
7+
*/
8+
public class AstfCluster {
9+
10+
/**
11+
* to json format
12+
*
13+
* @return JsonObject
14+
*/
15+
public JsonObject toJson() {
16+
return new JsonObject();
17+
}
18+
}

0 commit comments

Comments
 (0)