Skip to content

Commit 8b7dbfe

Browse files
Merge pull request #11 from cisco-system-traffic-generator/master
rebase
2 parents 7cca1d1 + 9d13b24 commit 8b7dbfe

Some content is hidden

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

52 files changed

+4153
-204
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: java
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.cisco.trex.stateless;
2+
3+
import com.cisco.trex.util.TRexClientUtil;
4+
import com.cisco.trex.util.TRexServerMode;
5+
import org.junit.Test;
6+
7+
public class TRexClientUtilTest {
8+
@Test
9+
public void getModeTest() {
10+
TRexServerMode mode = TRexClientUtil.getMode("trex-host", "4501");
11+
System.out.println(mode);
12+
}
13+
}

src/main/java/com/cisco/trex/ClientBase.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.stream.Collectors;
1414
import java.util.stream.StreamSupport;
1515

16+
import com.cisco.trex.util.Constants;
1617
import org.apache.commons.lang.StringUtils;
1718
import org.slf4j.Logger;
1819
import org.slf4j.LoggerFactory;
@@ -49,7 +50,6 @@
4950
public abstract class ClientBase {
5051

5152
protected static final Logger LOGGER = LoggerFactory.getLogger(ClientBase.class);
52-
protected static final String JSON_RPC_VERSION = "2.0";
5353
protected static final Gson GSON = buildGson();
5454
protected String host;
5555
protected String port;
@@ -74,7 +74,7 @@ private String buildRequest(String methodName, Map<String, Object> payload) {
7474
}
7575
Map<String, Object> parameters = new HashMap<>();
7676
parameters.put("id", "aggogxls");
77-
parameters.put("jsonrpc", JSON_RPC_VERSION);
77+
parameters.put("jsonrpc", Constants.JSON_RPC_VERSION);
7878
parameters.put("method", methodName);
7979
payload.put("api_h", apiH);
8080
parameters.put("params", payload);
@@ -232,7 +232,7 @@ public TRexCommand buildCommand(String methodName, Map<String, Object> parameter
232232
Map<String, Object> payload = new HashMap<>();
233233
int cmdId = randomizer.nextInt() & Integer.MAX_VALUE; //get a positive random value
234234
payload.put("id", cmdId);
235-
payload.put("jsonrpc", JSON_RPC_VERSION);
235+
payload.put("jsonrpc", Constants.JSON_RPC_VERSION);
236236
payload.put("method", methodName);
237237
if (!StringUtils.isEmpty(this.masterHandler)) {
238238
payload.put("handler", this.masterHandler);
@@ -314,6 +314,21 @@ public TRexClientResult<PortStatus> getPortStatus(int portIdx) {
314314
return callMethod("get_port_status", parameters, PortStatus.class);
315315
}
316316

317+
/**
318+
* Get Port Status including profile transmitting state
319+
*
320+
* @param portIdx
321+
* @param profileId
322+
* @return PortStatus
323+
*/
324+
public TRexClientResult<PortStatus> getPortStatus(int portIdx, String profileId) {
325+
Map<String, Object> parameters = new HashMap<>();
326+
parameters.put("port_id", portIdx);
327+
parameters.put("profile_id", profileId);
328+
parameters.put("block", false);
329+
return callMethod("get_port_status", parameters, PortStatus.class);
330+
}
331+
317332
/**
318333
* @param portIndex
319334
* @return PortStatistics
@@ -525,6 +540,14 @@ protected Map<String, Object> createPayload(int portIndex) {
525540
}
526541
return payload;
527542
}
543+
544+
protected Map<String, Object> createPayload(int portIndex, String profileId) {
545+
Map<String, Object> payload = createPayload(portIndex);
546+
if (profileId != null && !profileId.isEmpty()) {
547+
payload.put("profile_id", profileId);
548+
}
549+
return payload;
550+
}
528551

529552
protected abstract void serverAPISync() throws TRexConnectionException;
530553

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+
}

0 commit comments

Comments
 (0)