11package com .cisco .trex .stateful .api .lowlevel ;
22
3+ import com .google .gson .Gson ;
34import com .google .gson .JsonArray ;
45import com .google .gson .JsonObject ;
6+ import com .google .gson .JsonSyntaxException ;
7+
58import java .io .UnsupportedEncodingException ;
69import java .nio .charset .StandardCharsets ;
710import java .security .MessageDigest ;
@@ -249,10 +252,32 @@ public void delay(int usec) {
249252 * @param buf l7 stream as string
250253 */
251254 public void send (String buf ) {
255+ send (buf , 0 , null );
256+ }
257+
258+ /**
259+ * send (l7_buffer) over TCP and wait for the buffer to be acked by peer. Rx side could work in
260+ * parallel
261+ *
262+ * <p>example1 send (buffer1) send (buffer2)
263+ *
264+ * <p>Will behave differently than
265+ *
266+ * <p>example1 send (buffer1+ buffer2)
267+ *
268+ * <p>in the first example there would be PUSH in the last byte of the buffer and immediate ACK
269+ * from peer while in the last example the buffer will be sent together (might be one segment)
270+ *
271+ * @param buf l7 stream as string
272+ * @param size total size of l7 stream, effective only when size > buf.length
273+ * @param fill l7 stream filled by string, only if size is effective
274+ */
275+ public void send (String buf , int size , String fill ) {
252276 // we support bytes or ascii strings
277+ System .out .println ("testing being by leo \n " );
253278 ASTFCmdSend cmd = null ;
254279 try {
255- cmd = new ASTFCmdSend (buf .getBytes ("ascii" ));
280+ cmd = new ASTFCmdSend (buf .getBytes ("ascii" ), size , ( fill != null ) ? fill . getBytes ( "ascii" ) : null );
256281 } catch (UnsupportedEncodingException e ) {
257282 throw new IllegalStateException ("Unsupported Encoding Exception" , e );
258283 }
@@ -268,9 +293,20 @@ public void send(String buf) {
268293 * @param buf l7 stream as string
269294 */
270295 public void sendMsg (String buf ) {
296+ sendMsg (buf , 0 , null );
297+ }
298+
299+ /**
300+ * send UDP message
301+ *
302+ * @param buf l7 stream as string
303+ * @param size total size of l7 stream, effective only when size > buf.length
304+ * @param fill l7 stream filled by string, only if size is effective
305+ */
306+ public void sendMsg (String buf , int size , String fill ) {
271307 ASTFCmdTxPkt cmd = null ;
272308 try {
273- cmd = new ASTFCmdTxPkt (buf .getBytes ("ascii" ));
309+ cmd = new ASTFCmdTxPkt (buf .getBytes ("ascii" ), size , ( fill != null ) ? fill . getBytes ( "ascii" ) : null );
274310 } catch (UnsupportedEncodingException e ) {
275311 throw new IllegalStateException ("Unsupported Encoding Exception" , e );
276312 }
@@ -662,7 +698,12 @@ public int add(String base64Buf) {
662698 public JsonArray toJson () {
663699 JsonArray jsonArray = new JsonArray ();
664700 for (String buf : list ) {
665- jsonArray .add (buf );
701+ try {
702+ JsonObject jsonObj = new Gson ().fromJson (buf , JsonObject .class );
703+ jsonArray .add (jsonObj );
704+ } catch (JsonSyntaxException e ) {
705+ jsonArray .add (buf );
706+ }
666707 }
667708 return jsonArray ;
668709 }
0 commit comments