Skip to content

Commit 53c3322

Browse files
ningning-chenNingning Chen
andauthored
Sync TRex new python APIs to java low-level APIs (#128)
Sync TRex new python APIs to java low-level APIs Co-authored-by: Ningning Chen <[email protected]>
1 parent 732a357 commit 53c3322

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2323
-1014
lines changed
Lines changed: 346 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,346 @@
1+
package com.cisco.trex.stateful;
2+
3+
import com.cisco.trex.stateful.api.lowlevel.ASTFProfile;
4+
import com.cisco.trex.stateful.model.ServerStatus;
5+
import com.cisco.trex.stateless.exception.TRexConnectionException;
6+
import com.cisco.trex.stateless.exception.TRexTimeoutException;
7+
import java.util.concurrent.TimeUnit;
8+
import org.junit.BeforeClass;
9+
import org.junit.Test;
10+
11+
public class ASTFTRexTest {
12+
13+
public static final String CLIENT_USER = "system-tests-user";
14+
static final String HOST = "trex-host";
15+
static final String RPC_PORT = "4501";
16+
public static TRexAstfClient client;
17+
private int fsize = 10;
18+
private int nflows = 1;
19+
private int tinc = 0;
20+
ASTFProfile profile;
21+
private String profileId;
22+
private static final String PROFILEID_PREFIX = "astf_profile_";
23+
protected static final long DEFAULT_CLIENT_MASK = Long.parseLong("ffffffff", 16);
24+
protected static final double DEFAULT_DURATION = -1.0;
25+
protected static final int DEFAULT_LATENCY_PPS = 0;
26+
protected static final int DEFAULT_MULT = 1;
27+
28+
@BeforeClass
29+
public static void setUp() throws TRexConnectionException, TRexTimeoutException {
30+
client = new TRexAstfClient(HOST, RPC_PORT, CLIENT_USER);
31+
client.connect();
32+
client.acquirePorts(true);
33+
}
34+
35+
@Test
36+
public void testAstfFtpSim() throws InterruptedException {
37+
profile = AstfFtpSim.createProfile(fsize, nflows, tinc, "defaultName");
38+
profileId = PROFILEID_PREFIX + System.currentTimeMillis();
39+
System.out.print("testAstfFtpSim PROFILE:" + profile.toJson());
40+
profile.clearCache();
41+
ServerStatus.State status = client.syncWithServer().getState();
42+
43+
System.out.println(
44+
String.format(
45+
"Overal traffic state before startTraffic: %s", client.syncWithServer().getState()));
46+
47+
client.loadProfile(profileId, profile.toJson().toString());
48+
client.startTraffic(
49+
profileId,
50+
DEFAULT_CLIENT_MASK,
51+
DEFAULT_DURATION,
52+
false,
53+
DEFAULT_LATENCY_PPS,
54+
DEFAULT_MULT,
55+
false);
56+
57+
System.out.println(
58+
String.format(
59+
"Traffic state after startTraffic: %s",
60+
client.syncWithServer().getStateProfile().get(profileId)));
61+
System.out.println(
62+
String.format(
63+
"Overal traffic state after startTraffic: %s", client.syncWithServer().getState()));
64+
65+
// send for 10 seconds
66+
TimeUnit.SECONDS.sleep(10);
67+
System.out.println(
68+
String.format(
69+
"Traffic state after a while after startTraffic: %s",
70+
client.syncWithServer().getStateProfile().get(profileId)));
71+
System.out.println(
72+
String.format(
73+
"Overal traffic state after startTraffic: %s", client.syncWithServer().getState()));
74+
75+
client.stopTraffic();
76+
// wait for 10 seconds for stopping procedure
77+
TimeUnit.SECONDS.sleep(10);
78+
System.out.println(
79+
String.format(
80+
"Traffic state after stopTraffic: %s",
81+
client.syncWithServer().getStateProfile().get(profileId)));
82+
System.out.println(
83+
String.format(
84+
"Overal traffic state after stopTraffic: %s", client.syncWithServer().getState()));
85+
}
86+
87+
@Test
88+
public void testFtpMultipleFlowsSim() throws InterruptedException {
89+
profile = FtpMultipleFlowsSim.createProfile(fsize, nflows, tinc, "defaultName");
90+
profileId = PROFILEID_PREFIX + System.currentTimeMillis();
91+
System.out.print("testFtpMultipleFlowsSim PROFILE:" + profile.toJson());
92+
profile.clearCache();
93+
ServerStatus.State status = client.syncWithServer().getState();
94+
95+
System.out.println(
96+
String.format(
97+
"Overal traffic state before startTraffic: %s", client.syncWithServer().getState()));
98+
99+
client.loadProfile(profileId, profile.toJson().toString());
100+
client.startTraffic(
101+
profileId,
102+
DEFAULT_CLIENT_MASK,
103+
DEFAULT_DURATION,
104+
false,
105+
DEFAULT_LATENCY_PPS,
106+
DEFAULT_MULT,
107+
false);
108+
109+
System.out.println(
110+
String.format(
111+
"Traffic state after startTraffic: %s",
112+
client.syncWithServer().getStateProfile().get(profileId)));
113+
System.out.println(
114+
String.format(
115+
"Overal traffic state after startTraffic: %s", client.syncWithServer().getState()));
116+
117+
// send for 10 seconds
118+
TimeUnit.SECONDS.sleep(10);
119+
System.out.println(
120+
String.format(
121+
"Traffic state after a while after startTraffic: %s",
122+
client.syncWithServer().getStateProfile().get(profileId)));
123+
System.out.println(
124+
String.format(
125+
"Overal traffic state after startTraffic: %s", client.syncWithServer().getState()));
126+
127+
client.stopTraffic();
128+
// wait for 10 seconds for stopping procedure
129+
TimeUnit.SECONDS.sleep(10);
130+
System.out.println(
131+
String.format(
132+
"Traffic state after stopTraffic: %s",
133+
client.syncWithServer().getStateProfile().get(profileId)));
134+
System.out.println(
135+
String.format(
136+
"Overal traffic state after stopTraffic: %s", client.syncWithServer().getState()));
137+
}
138+
139+
@Test
140+
public void testHttpSimple() throws InterruptedException {
141+
profile = HttpSimple.getProfile();
142+
profileId = PROFILEID_PREFIX + System.currentTimeMillis();
143+
System.out.print("testHttpSimple PROFILE:" + profile.toJson());
144+
profile.clearCache();
145+
ServerStatus.State status = client.syncWithServer().getState();
146+
147+
System.out.println(
148+
String.format(
149+
"Overal traffic state before startTraffic: %s", client.syncWithServer().getState()));
150+
151+
client.loadProfile(profileId, profile.toJson().toString());
152+
client.startTraffic(
153+
profileId,
154+
DEFAULT_CLIENT_MASK,
155+
DEFAULT_DURATION,
156+
false,
157+
DEFAULT_LATENCY_PPS,
158+
DEFAULT_MULT,
159+
false);
160+
161+
System.out.println(
162+
String.format(
163+
"Traffic state after startTraffic: %s",
164+
client.syncWithServer().getStateProfile().get(profileId)));
165+
System.out.println(
166+
String.format(
167+
"Overal traffic state after startTraffic: %s", client.syncWithServer().getState()));
168+
169+
// send for 10 seconds
170+
TimeUnit.SECONDS.sleep(10);
171+
System.out.println(
172+
String.format(
173+
"Traffic state after a while after startTraffic: %s",
174+
client.syncWithServer().getStateProfile().get(profileId)));
175+
System.out.println(
176+
String.format(
177+
"Overal traffic state after startTraffic: %s", client.syncWithServer().getState()));
178+
179+
client.stopTraffic();
180+
// wait for 10 seconds for stopping procedure
181+
TimeUnit.SECONDS.sleep(10);
182+
System.out.println(
183+
String.format(
184+
"Traffic state after stopTraffic: %s",
185+
client.syncWithServer().getStateProfile().get(profileId)));
186+
System.out.println(
187+
String.format(
188+
"Overal traffic state after stopTraffic: %s", client.syncWithServer().getState()));
189+
}
190+
191+
@Test
192+
public void testMixPcapFileAstfTraffic() throws InterruptedException {
193+
profile = MixPcapFileAstfTraffic.createProfile();
194+
profileId = PROFILEID_PREFIX + System.currentTimeMillis();
195+
System.out.print("testMixPcapFileAstfTraffic PROFILE:" + profile.toJson());
196+
profile.clearCache();
197+
ServerStatus.State status = client.syncWithServer().getState();
198+
199+
System.out.println(
200+
String.format(
201+
"Overal traffic state before startTraffic: %s", client.syncWithServer().getState()));
202+
203+
client.loadProfile(profileId, profile.toJson().toString());
204+
client.startTraffic(
205+
profileId,
206+
DEFAULT_CLIENT_MASK,
207+
DEFAULT_DURATION,
208+
false,
209+
DEFAULT_LATENCY_PPS,
210+
DEFAULT_MULT,
211+
false);
212+
213+
System.out.println(
214+
String.format(
215+
"Traffic state after startTraffic: %s",
216+
client.syncWithServer().getStateProfile().get(profileId)));
217+
System.out.println(
218+
String.format(
219+
"Overal traffic state after startTraffic: %s", client.syncWithServer().getState()));
220+
221+
// send for 10 seconds
222+
TimeUnit.SECONDS.sleep(10);
223+
System.out.println(
224+
String.format(
225+
"Traffic state after a while after startTraffic: %s",
226+
client.syncWithServer().getStateProfile().get(profileId)));
227+
System.out.println(
228+
String.format(
229+
"Overal traffic state after startTraffic: %s", client.syncWithServer().getState()));
230+
231+
client.stopTraffic();
232+
// wait for 10 seconds for stopping procedure
233+
TimeUnit.SECONDS.sleep(10);
234+
System.out.println(
235+
String.format(
236+
"Traffic state after stopTraffic: %s",
237+
client.syncWithServer().getStateProfile().get(profileId)));
238+
System.out.println(
239+
String.format(
240+
"Overal traffic state after stopTraffic: %s", client.syncWithServer().getState()));
241+
}
242+
243+
@Test
244+
public void testParamTcpDelayAck() throws InterruptedException {
245+
profile = ParamTcpDelayAck.createProfile();
246+
profileId = PROFILEID_PREFIX + System.currentTimeMillis();
247+
System.out.print("testParamTcpDelayAck PROFILE:" + profile.toJson());
248+
profile.clearCache();
249+
ServerStatus.State status = client.syncWithServer().getState();
250+
251+
System.out.println(
252+
String.format(
253+
"Overal traffic state before startTraffic: %s", client.syncWithServer().getState()));
254+
255+
client.loadProfile(profileId, profile.toJson().toString());
256+
client.startTraffic(
257+
profileId,
258+
DEFAULT_CLIENT_MASK,
259+
DEFAULT_DURATION,
260+
false,
261+
DEFAULT_LATENCY_PPS,
262+
DEFAULT_MULT,
263+
false);
264+
265+
System.out.println(
266+
String.format(
267+
"Traffic state after startTraffic: %s",
268+
client.syncWithServer().getStateProfile().get(profileId)));
269+
System.out.println(
270+
String.format(
271+
"Overal traffic state after startTraffic: %s", client.syncWithServer().getState()));
272+
273+
// send for 10 seconds
274+
TimeUnit.SECONDS.sleep(10);
275+
System.out.println(
276+
String.format(
277+
"Traffic state after a while after startTraffic: %s",
278+
client.syncWithServer().getStateProfile().get(profileId)));
279+
System.out.println(
280+
String.format(
281+
"Overal traffic state after startTraffic: %s", client.syncWithServer().getState()));
282+
283+
client.stopTraffic();
284+
// wait for 10 seconds for stopping procedure
285+
TimeUnit.SECONDS.sleep(10);
286+
System.out.println(
287+
String.format(
288+
"Traffic state after stopTraffic: %s",
289+
client.syncWithServer().getStateProfile().get(profileId)));
290+
System.out.println(
291+
String.format(
292+
"Overal traffic state after stopTraffic: %s", client.syncWithServer().getState()));
293+
}
294+
295+
@Test
296+
public void testParamTcpKeepalive() throws InterruptedException {
297+
profile = ParamTcpKeepalive.createProfile();
298+
profileId = PROFILEID_PREFIX + System.currentTimeMillis();
299+
System.out.print("testParamTcpKeepalive PROFILE:" + profile.toJson());
300+
profile.clearCache();
301+
ServerStatus.State status = client.syncWithServer().getState();
302+
303+
System.out.println(
304+
String.format(
305+
"Overal traffic state before startTraffic: %s", client.syncWithServer().getState()));
306+
307+
client.loadProfile(profileId, profile.toJson().toString());
308+
client.startTraffic(
309+
profileId,
310+
DEFAULT_CLIENT_MASK,
311+
DEFAULT_DURATION,
312+
false,
313+
DEFAULT_LATENCY_PPS,
314+
DEFAULT_MULT,
315+
false);
316+
317+
System.out.println(
318+
String.format(
319+
"Traffic state after startTraffic: %s",
320+
client.syncWithServer().getStateProfile().get(profileId)));
321+
System.out.println(
322+
String.format(
323+
"Overal traffic state after startTraffic: %s", client.syncWithServer().getState()));
324+
325+
// send for 10 seconds
326+
TimeUnit.SECONDS.sleep(10);
327+
System.out.println(
328+
String.format(
329+
"Traffic state after a while after startTraffic: %s",
330+
client.syncWithServer().getStateProfile().get(profileId)));
331+
System.out.println(
332+
String.format(
333+
"Overal traffic state after startTraffic: %s", client.syncWithServer().getState()));
334+
335+
client.stopTraffic();
336+
// wait for 10 seconds for stopping procedure
337+
TimeUnit.SECONDS.sleep(10);
338+
System.out.println(
339+
String.format(
340+
"Traffic state after stopTraffic: %s",
341+
client.syncWithServer().getStateProfile().get(profileId)));
342+
System.out.println(
343+
String.format(
344+
"Overal traffic state after stopTraffic: %s", client.syncWithServer().getState()));
345+
}
346+
}

0 commit comments

Comments
 (0)