Skip to content

Commit bb33fec

Browse files
committed
Add ASTF statistics support
Signed-off-by: Leo Ma <[email protected]>
1 parent 4ef338b commit bb33fec

File tree

4 files changed

+263
-23
lines changed

4 files changed

+263
-23
lines changed

src/main/java/com/cisco/trex/stateful/TRexAstfClient.java

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
import org.apache.commons.lang.StringUtils;
1515

1616
import com.cisco.trex.ClientBase;
17+
import com.cisco.trex.stateful.model.stats.AstfStatistics;
18+
import com.cisco.trex.stateful.model.stats.MetaData;
1719
import com.cisco.trex.stateless.exception.TRexConnectionException;
1820
import com.cisco.trex.stateless.model.ApiVersionHandler;
1921
import com.cisco.trex.stateless.model.PortStatus;
2022
import com.cisco.trex.stateless.model.TRexClientResult;
23+
import com.cisco.trex.stateless.model.stats.ExtendedPortStatistics;
24+
import com.cisco.trex.stateless.model.stats.XstatsNames;
2125
import com.google.gson.JsonArray;
2226
import com.google.gson.JsonElement;
2327
import com.google.gson.JsonParser;
@@ -314,37 +318,31 @@ public List<String> getProfileIds() {
314318
}
315319

316320
/**
317-
* Get Counter Metadata of profile associated default profile id
318-
* Not finished, needs to return counter object
319-
*/
320-
public void getCounterMetadata() {
321-
getCounterMetadata("");
322-
}
323-
324-
/**
325-
* Get Counter Metadata of profile associated specified profile id
326-
* Not finished, needs to return counter object
321+
* Get ASTF counters of profile associated with specified profile id
322+
*
323+
* @param profileId
324+
* @return AstfStatistics
327325
*/
328-
public void getCounterMetadata(String profileId) {
326+
public AstfStatistics getAstfStatistics(String profileId) {
329327
Map<String, Object> payload = createPayload(profileId);
330-
this.callMethod("get_counter_desc", payload);
328+
return callMethod("get_counter_values", payload, AstfStatistics.class).get()
329+
.setCounterNames(getAstfStatsMetaData());
331330
}
332331

333332
/**
334-
* Get Astf Counters of profile associated default profile id
335-
* Not finished, needs to return counter object
333+
* Get ASTF total counters for all profiles
334+
*
335+
* @return AstfStatistics
336336
*/
337-
public void getAstfCounters() {
338-
getAstfCounters("");
337+
public AstfStatistics getAstfTotalStatistics() {
338+
Map<String, Object> payload = createPayload();
339+
return callMethod("get_total_counter_values", payload, AstfStatistics.class).get()
340+
.setCounterNames(getAstfStatsMetaData());
339341
}
340342

341-
/**
342-
* Get Astf Counters of profile associated specified profile id
343-
* Not finished, needs to return counter object
344-
*/
345-
public void getAstfCounters(String profileId) {
346-
Map<String, Object> payload = this.createPayload(profileId);
347-
this.callMethod("get_counter_values", payload);
343+
private MetaData getAstfStatsMetaData() {
344+
Map<String, Object> payload = createPayload();
345+
return callMethod("get_counter_desc", payload, MetaData.class).get();
348346
}
349347

350348
/**
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.cisco.trex.stateful.model.stats;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
/**
8+
* ASTF statistics
9+
*/
10+
public class AstfStatistics {
11+
12+
/**
13+
* Json Property
14+
*/
15+
@JsonProperty("client")
16+
private Map<Integer, Double> clientCounters = new HashMap<>();
17+
18+
@JsonProperty("server")
19+
private Map<Integer, Double> serverCounters = new HashMap<>();
20+
21+
@JsonProperty("epoch")
22+
private int epoch;
23+
24+
@JsonProperty("name")
25+
private String name;
26+
27+
private Map<String, Double> matchedNameAndValuesForClient = new HashMap<>();
28+
29+
private Map<String, Double> matchedNameAndValuesForServer = new HashMap<>();
30+
31+
@JsonProperty("client")
32+
public Map<Integer, Double> getClientCounters() {
33+
return clientCounters;
34+
}
35+
36+
@JsonProperty("client")
37+
public void setClientCounters(Map<Integer, Double> clientCounters) {
38+
this.clientCounters = clientCounters;
39+
}
40+
41+
@JsonProperty("server")
42+
public Map<Integer, Double> getServerCounters() {
43+
return serverCounters;
44+
}
45+
46+
@JsonProperty("server")
47+
public void setServerCounters(Map<Integer, Double> serverCounters) {
48+
this.serverCounters = serverCounters;
49+
}
50+
51+
@JsonProperty("epoch")
52+
public int getEpoch() {
53+
return epoch;
54+
}
55+
56+
@JsonProperty("epoch")
57+
public void setEpoch(int epoch) {
58+
this.epoch = epoch;
59+
}
60+
61+
@JsonProperty("name")
62+
public String getName() {
63+
return name;
64+
}
65+
66+
@JsonProperty("name")
67+
public void setName(String name) {
68+
this.name = name;
69+
}
70+
71+
/**
72+
* @param metaData
73+
* @return this
74+
*/
75+
public AstfStatistics setCounterNames(MetaData metaData) {
76+
for (Map.Entry<Integer, Double> counter : clientCounters.entrySet()) {
77+
matchedNameAndValuesForClient.put(getCounterName(counter.getKey(), metaData), counter.getValue());
78+
}
79+
80+
for (Map.Entry<Integer, Double> counter : serverCounters.entrySet()) {
81+
matchedNameAndValuesForServer.put(getCounterName(counter.getKey(), metaData), counter.getValue());
82+
}
83+
84+
return this;
85+
}
86+
87+
private String getCounterName(int id, MetaData metaData) {
88+
for (CounterMeta meta : metaData.getData()) {
89+
if (meta.getId() == id) {
90+
return meta.getName();
91+
}
92+
}
93+
94+
return null;
95+
}
96+
97+
public Map<String, Double> getClientStatistics() {
98+
return matchedNameAndValuesForClient;
99+
}
100+
101+
public Map<String, Double> getServerStatistics() {
102+
return matchedNameAndValuesForServer;
103+
}
104+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package com.cisco.trex.stateful.model.stats;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
public class CounterMeta {
6+
7+
@JsonProperty("abs")
8+
public boolean isAbs;
9+
10+
@JsonProperty("help")
11+
public String help;
12+
13+
@JsonProperty("id")
14+
public int id;
15+
16+
@JsonProperty("info")
17+
public String info;
18+
19+
@JsonProperty("name")
20+
public String name;
21+
22+
@JsonProperty("real")
23+
public boolean isReal;
24+
25+
@JsonProperty("units")
26+
public String units;
27+
28+
@JsonProperty("zero")
29+
public boolean isZero;
30+
31+
@JsonProperty("abs")
32+
public boolean getAbs() {
33+
return isAbs;
34+
}
35+
36+
@JsonProperty("abs")
37+
public void setAbs(boolean abs) {
38+
this.isAbs = abs;
39+
}
40+
41+
@JsonProperty("help")
42+
public String getHelp() {
43+
return help;
44+
}
45+
46+
@JsonProperty("help")
47+
public void setHelp(String help) {
48+
this.help = help;
49+
}
50+
51+
@JsonProperty("id")
52+
public int getId() {
53+
return id;
54+
}
55+
56+
@JsonProperty("id")
57+
public void setId(int id) {
58+
this.id = id;
59+
}
60+
61+
@JsonProperty("info")
62+
public String getInfo() {
63+
return info;
64+
}
65+
66+
@JsonProperty("info")
67+
public void setInfo(String info) {
68+
this.info = info;
69+
}
70+
71+
@JsonProperty("name")
72+
public String getName() {
73+
return name;
74+
}
75+
76+
@JsonProperty("name")
77+
public void setName(String name) {
78+
this.name = name;
79+
}
80+
81+
@JsonProperty("real")
82+
public boolean isReal() {
83+
return isReal;
84+
}
85+
86+
@JsonProperty("real")
87+
public void setReal(boolean isReal) {
88+
this.isReal = isReal;
89+
}
90+
91+
@JsonProperty("units")
92+
public String getUnits() {
93+
return units;
94+
}
95+
96+
@JsonProperty("units")
97+
public void setUnits(String units) {
98+
this.units = units;
99+
}
100+
101+
@JsonProperty("zero")
102+
public boolean isZero() {
103+
return isZero;
104+
}
105+
106+
@JsonProperty("zero")
107+
public void setZero(boolean isZero) {
108+
this.isZero = isZero;
109+
}
110+
111+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.cisco.trex.stateful.model.stats;
2+
3+
import java.util.List;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
/**
8+
* Meta data for ASTF statistics
9+
*/
10+
public class MetaData {
11+
12+
@JsonProperty("data")
13+
public List<CounterMeta> data;
14+
15+
@JsonProperty("name")
16+
public String name;
17+
18+
@JsonProperty("data")
19+
public List<CounterMeta> getData() {
20+
return data;
21+
}
22+
23+
@JsonProperty("name")
24+
public String getName() {
25+
return name;
26+
}
27+
}

0 commit comments

Comments
 (0)