99import java .util .Base64 ;
1010import java .util .Collections ;
1111import java .util .HashMap ;
12+ import java .util .Iterator ;
1213import java .util .LinkedList ;
1314import java .util .List ;
1415import java .util .Map ;
@@ -56,7 +57,7 @@ public class TRexClient extends ClientBase {
5657
5758 private static final EtherType QInQ = new EtherType ((short ) 0x88a8 , "802.1Q Provider Bridge (Q-in-Q)" );
5859 private static Integer API_VERSION_MAJOR = 4 ;
59- private static Integer API_VERSION_MINOR = 5 ;
60+ private static Integer API_VERSION_MINOR = 6 ;
6061 private Integer session_id = 123456789 ;
6162
6263 public TRexClient (String host , String port , String userName ) {
@@ -109,7 +110,9 @@ public PortStatus acquirePort(int portIndex, Boolean force) {
109110 public void resetPort (int portIndex ) {
110111 acquirePort (portIndex , true );
111112 stopTraffic (portIndex );
112- removeAllStreams (portIndex );
113+ for (String profileId : getProfileIds (portIndex )) {
114+ removeAllStreams (portIndex , profileId );
115+ }
113116 removeRxQueue (portIndex );
114117 serviceMode (portIndex , false );
115118 releasePort (portIndex );
@@ -124,16 +127,28 @@ public PortStatus serviceMode(int portIndex, Boolean isOn) {
124127 }
125128
126129 public void addStream (int portIndex , Stream stream ) {
127- Map <String , Object > payload = createPayload (portIndex );
128- payload .put ("stream_id" , stream .getId ());
129- payload .put ("stream" , stream );
130- callMethod ("add_stream" , payload );
130+ addStream (portIndex , "" , stream .getId (), stream );
131+ }
132+
133+ public void addStream (int portIndex , String profileId , Stream stream ) {
134+ addStream (portIndex , profileId , stream .getId (), stream );
131135 }
132136
133137 public void addStream (int portIndex , int streamId , JsonObject stream ) {
138+ addStream (portIndex , "" , streamId , stream );
139+ }
140+
141+ public void addStream (int portIndex , String profileId , int streamId , JsonObject stream ) {
142+ addStream (portIndex , profileId , streamId , stream );
143+ }
144+
145+ private void addStream (int portIndex , String profileId , int streamId , Object streamObject ) {
134146 Map <String , Object > payload = createPayload (portIndex );
147+ if (profileId != null && !profileId .isEmpty ()) {
148+ payload .put ("profile_id" , profileId );
149+ }
135150 payload .put ("stream_id" , streamId );
136- payload .put ("stream" , stream );
151+ payload .put ("stream" , streamObject );
137152 callMethod ("add_stream" , payload );
138153 }
139154
@@ -158,12 +173,26 @@ public void removeStream(int portIndex, int streamId) {
158173 }
159174
160175 public void removeAllStreams (int portIndex ) {
176+ removeAllStreams (portIndex , "" );
177+ }
178+
179+ public void removeAllStreams (int portIndex , String profileId ) {
161180 Map <String , Object > payload = createPayload (portIndex );
181+ if (profileId != null && !profileId .isEmpty ()) {
182+ payload .put ("profile_id" , profileId );
183+ }
162184 callMethod ("remove_all_streams" , payload );
163185 }
164-
186+
165187 public List <Stream > getAllStreams (int portIndex ) {
188+ return getAllStreams (portIndex , "" );
189+ }
190+
191+ public List <Stream > getAllStreams (int portIndex , String profileId ) {
166192 Map <String , Object > payload = createPayload (portIndex );
193+ if (profileId != null && !profileId .isEmpty ()) {
194+ payload .put ("profile_id" , profileId );
195+ }
167196 String json = callMethod ("get_all_streams" , payload );
168197 JsonElement response = new JsonParser ().parse (json );
169198 JsonObject streams = response .getAsJsonArray ().get (0 )
@@ -175,11 +204,19 @@ public List<Stream> getAllStreams(int portIndex) {
175204 for (Map .Entry <String , JsonElement > stream : streams .entrySet ()) {
176205 streamList .add (GSON .fromJson (stream .getValue (), Stream .class ));
177206 }
207+
178208 return streamList ;
179209 }
180-
210+
181211 public List <Integer > getStreamIds (int portIndex ) {
212+ return getStreamIds (portIndex , "" );
213+ }
214+
215+ public List <Integer > getStreamIds (int portIndex , String profileId ) {
182216 Map <String , Object > payload = createPayload (portIndex );
217+ if (profileId != null && !profileId .isEmpty ()) {
218+ payload .put ("profile_id" , profileId );
219+ }
183220 String json = callMethod ("get_stream_list" , payload );
184221 JsonElement response = new JsonParser ().parse (json );
185222 JsonArray ids = response .getAsJsonArray ().get (0 ).getAsJsonObject ().get ("result" ).getAsJsonArray ();
@@ -209,6 +246,16 @@ public void updateStreams(int portIndex, List<Integer> streams, boolean force,
209246 callMethod ("update_streams" , payload );
210247 }
211248
249+ public List <String > getProfileIds (int portIndex ) {
250+ Map <String , Object > payload = createPayload (portIndex );
251+ String json = callMethod ("get_profile_list" , payload );
252+ JsonElement response = new JsonParser ().parse (json );
253+ JsonArray ids = response .getAsJsonArray ().get (0 ).getAsJsonObject ().get ("result" ).getAsJsonArray ();
254+ return StreamSupport .stream (ids .spliterator (), false )
255+ .map (JsonElement ::getAsString )
256+ .collect (Collectors .toList ());
257+ }
258+
212259 public ActivePGIds getActivePgids () {
213260 Map <String , Object > parameters = new HashMap <>();
214261 parameters .put ("pgids" , "" );
0 commit comments