99import java .util .Base64 ;
1010import java .util .Collections ;
1111import java .util .HashMap ;
12- import java .util .Iterator ;
1312import java .util .LinkedList ;
1413import java .util .List ;
1514import java .util .Map ;
1817import java .util .stream .Collectors ;
1918import java .util .stream .StreamSupport ;
2019
21- import com .cisco .trex .stateless .model .*;
2220import org .pcap4j .packet .ArpPacket ;
2321import org .pcap4j .packet .Dot1qVlanTagPacket ;
2422import org .pcap4j .packet .EthernetPacket ;
2523import org .pcap4j .packet .IcmpV4CommonPacket ;
2624import org .pcap4j .packet .IcmpV4EchoPacket ;
2725import org .pcap4j .packet .IcmpV4EchoReplyPacket ;
28- import org .pcap4j .packet .IcmpV6NeighborAdvertisementPacket ;
2926import org .pcap4j .packet .IllegalRawDataException ;
3027import org .pcap4j .packet .IpV4Packet ;
3128import org .pcap4j .packet .IpV4Rfc791Tos ;
4340import com .cisco .trex .ClientBase ;
4441import com .cisco .trex .stateless .exception .ServiceModeRequiredException ;
4542import com .cisco .trex .stateless .exception .TRexConnectionException ;
43+ import com .cisco .trex .stateless .model .ApiVersionHandler ;
44+ import com .cisco .trex .stateless .model .Ipv6Node ;
45+ import com .cisco .trex .stateless .model .Port ;
46+ import com .cisco .trex .stateless .model .PortStatus ;
47+ import com .cisco .trex .stateless .model .Stream ;
48+ import com .cisco .trex .stateless .model .StreamMode ;
49+ import com .cisco .trex .stateless .model .StreamModeRate ;
50+ import com .cisco .trex .stateless .model .StreamRxStats ;
51+ import com .cisco .trex .stateless .model .StreamVM ;
52+ import com .cisco .trex .stateless .model .TRexClientResult ;
4653import com .cisco .trex .stateless .model .port .PortVlan ;
4754import com .cisco .trex .stateless .model .stats .ActivePGIds ;
4855import com .cisco .trex .stateless .model .stats .ActivePGIdsRPCResult ;
@@ -58,7 +65,7 @@ public class TRexClient extends ClientBase {
5865
5966 private static final EtherType QInQ = new EtherType ((short ) 0x88a8 , "802.1Q Provider Bridge (Q-in-Q)" );
6067 private static Integer API_VERSION_MAJOR = 4 ;
61- private static Integer API_VERSION_MINOR = 6 ;
68+ private static Integer API_VERSION_MINOR = 5 ;
6269 private Integer session_id = 123456789 ;
6370
6471 public TRexClient (String host , String port , String userName ) {
@@ -83,11 +90,11 @@ protected void serverAPISync() throws TRexConnectionException {
8390
8491 if (result .get () == null ) {
8592 TRexConnectionException e = new TRexConnectionException (
86- MessageFormat .format ("Unable to connect to TRex server. Required API version is {0}.{1}. Error: {2}" ,
93+ MessageFormat .format (
94+ "Unable to connect to TRex server. Required API version is {0}.{1}. Error: {2}" ,
8795 API_VERSION_MAJOR ,
8896 API_VERSION_MINOR ,
89- result .getError ()
90- ));
97+ result .getError ()));
9198 LOGGER .error ("Unable to sync client with TRex server due to: API_H is null." , e .getMessage ());
9299 throw e ;
93100 }
@@ -142,12 +149,9 @@ public void addStream(int portIndex, int streamId, JsonObject stream) {
142149 public void addStream (int portIndex , String profileId , int streamId , JsonObject stream ) {
143150 addStream (portIndex , profileId , streamId , stream );
144151 }
145-
152+
146153 private void addStream (int portIndex , String profileId , int streamId , Object streamObject ) {
147- Map <String , Object > payload = createPayload (portIndex );
148- if (profileId != null && !profileId .isEmpty ()) {
149- payload .put ("profile_id" , profileId );
150- }
154+ Map <String , Object > payload = createPayload (portIndex , profileId );
151155 payload .put ("stream_id" , streamId );
152156 payload .put ("stream" , streamObject );
153157 callMethod ("add_stream" , payload );
@@ -178,22 +182,16 @@ public void removeAllStreams(int portIndex) {
178182 }
179183
180184 public void removeAllStreams (int portIndex , String profileId ) {
181- Map <String , Object > payload = createPayload (portIndex );
182- if (profileId != null && !profileId .isEmpty ()) {
183- payload .put ("profile_id" , profileId );
184- }
185+ Map <String , Object > payload = createPayload (portIndex , profileId );
185186 callMethod ("remove_all_streams" , payload );
186187 }
187-
188+
188189 public List <Stream > getAllStreams (int portIndex ) {
189190 return getAllStreams (portIndex , "" );
190191 }
191192
192193 public List <Stream > getAllStreams (int portIndex , String profileId ) {
193- Map <String , Object > payload = createPayload (portIndex );
194- if (profileId != null && !profileId .isEmpty ()) {
195- payload .put ("profile_id" , profileId );
196- }
194+ Map <String , Object > payload = createPayload (portIndex , profileId );
197195 String json = callMethod ("get_all_streams" , payload );
198196 JsonElement response = new JsonParser ().parse (json );
199197 JsonObject streams = response .getAsJsonArray ().get (0 )
@@ -208,16 +206,13 @@ public List<Stream> getAllStreams(int portIndex, String profileId) {
208206
209207 return streamList ;
210208 }
211-
209+
212210 public List <Integer > getStreamIds (int portIndex ) {
213211 return getStreamIds (portIndex , "" );
214212 }
215213
216214 public List <Integer > getStreamIds (int portIndex , String profileId ) {
217- Map <String , Object > payload = createPayload (portIndex );
218- if (profileId != null && !profileId .isEmpty ()) {
219- payload .put ("profile_id" , profileId );
220- }
215+ Map <String , Object > payload = createPayload (portIndex , profileId );
221216 String json = callMethod ("get_stream_list" , payload );
222217 JsonElement response = new JsonParser ().parse (json );
223218 JsonArray ids = response .getAsJsonArray ().get (0 ).getAsJsonObject ().get ("result" ).getAsJsonArray ();
@@ -270,7 +265,15 @@ public PGIdStatsRPCResult getPgidStats(int[] ids) {
270265 }
271266
272267 public void startTraffic (int portIndex , double duration , boolean force , Map <String , Object > mul , int coreMask ) {
273- Map <String , Object > payload = createPayload (portIndex );
268+ List <String > profileIds = getProfileIds (portIndex );
269+ for (String profileId : profileIds ) {
270+ startTraffic (portIndex , profileId , duration , force , mul , coreMask );
271+ }
272+ }
273+
274+ public void startTraffic (int portIndex , String profileId , double duration , boolean force , Map <String , Object > mul ,
275+ int coreMask ) {
276+ Map <String , Object > payload = createPayload (portIndex , profileId );
274277 payload .put ("core_mask" , coreMask );
275278 payload .put ("mul" , mul );
276279 payload .put ("duration" , duration );
@@ -517,12 +520,12 @@ private static Stream build1PktSingleBurstStream(Packet pkt) {
517520 public String resolveIpv6 (int portIndex , String dstIp ) throws ServiceModeRequiredException {
518521 removeRxQueue (portIndex );
519522 setRxQueue (portIndex , 1000 );
520-
523+
521524 EthernetPacket naPacket = new IPv6NeighborDiscoveryService (this ).sendNeighborSolicitation (portIndex , 5 , dstIp );
522525 if (naPacket != null ) {
523526 return naPacket .getHeader ().getSrcAddr ().toString ();
524527 }
525-
528+
526529 return null ;
527530 }
528531
@@ -636,7 +639,14 @@ private EthernetPacket buildIcmpV4Request(String srcMac, String dstMac, String s
636639 }
637640
638641 public void stopTraffic (int portIndex ) {
639- Map <String , Object > payload = createPayload (portIndex );
642+ List <String > profileIds = getProfileIds (portIndex );
643+ for (String profileId : profileIds ) {
644+ stopTraffic (portIndex , profileId );
645+ }
646+ }
647+
648+ public void stopTraffic (int portIndex , String profileId ) {
649+ Map <String , Object > payload = createPayload (portIndex , profileId );
640650 callMethod ("stop_traffic" , payload );
641651 }
642652
0 commit comments