33import com .google .gson .JsonArray ;
44import com .google .gson .JsonObject ;
55import java .io .UnsupportedEncodingException ;
6- import java .nio .charset .Charset ;
76import java .nio .charset .StandardCharsets ;
87import java .security .MessageDigest ;
98import java .security .NoSuchAlgorithmException ;
@@ -26,19 +25,15 @@ public class ASTFProgram {
2625 private static final int MIN_DELAY = 50 ;
2726 private static final int MAX_DELAY = 700000 ;
2827 private static final int MAX_KEEPALIVE = 500000 ;
29- private static final Charset UTF_8 = Charset .forName ("UTF-8" );
3028 private static final String COMMANDS = "commands" ;
3129
32- private Map <String , Integer > vars = new HashMap ();
33- private Map <String , Integer > labels = new HashMap ();
34- private Map <String , List <ASTFCmd >> fields = new HashMap ();
35- private int totalSendBytes = 0 ;
36- private int totalRcvBytes = 0 ;
37- private int payloadLen = 0 ;
30+ private Map <String , Integer > vars = new HashMap <> ();
31+ private Map <String , Integer > labels = new HashMap <> ();
32+ private Map <String , List <ASTFCmd >> fields = new HashMap <> ();
33+ private long totalSendBytes ;
34+ private long totalRcvBytes ;
35+ private int payloadLen ;
3836
39- private String filePath ;
40- private SideType side ;
41- private List <ASTFCmd > commands ;
4237 private boolean stream = true ;
4338 private static BufferList bufList = new BufferList ();
4439
@@ -75,9 +70,6 @@ public ASTFProgram(String filePath, SideType side) {
7570 * @param stream
7671 */
7772 public ASTFProgram (String filePath , SideType side , List <ASTFCmd > commands , boolean stream ) {
78- this .filePath = filePath ;
79- this .side = side ;
80- this .commands = commands ;
8173 this .stream = stream ;
8274 fields .put (COMMANDS , new ArrayList <ASTFCmd >());
8375 if (filePath != null ) {
@@ -106,12 +98,12 @@ private void createCmdFromCap(
10698 throw new IllegalStateException (
10799 String .format ("cmds size %s is not equal to dirs size %s" , cmds .size (), dirs .size ()));
108100 }
109- if (cmds .size () == 0 ) {
101+ if (cmds .isEmpty () ) {
110102 return ;
111103 }
112104
113- List <ASTFCmd > newCmds = new ArrayList ();
114- int totRcvBytes = 0 ;
105+ List <ASTFCmd > newCmds = new ArrayList <> ();
106+ long totRcvBytes = 0 ;
115107 boolean rx = false ;
116108 int maxDelay = 0 ;
117109
@@ -143,7 +135,6 @@ private void createCmdFromCap(
143135 SideType lastDir = null ;
144136 for (int i = 0 ; i < cmds .size (); i ++) {
145137 SideType dir = dirs .get (i );
146- CPacketData cmd = cmds .get (i );
147138 Double time = times .get (i );
148139
149140 if (dir == initSide ) {
@@ -208,7 +199,7 @@ private void setCmds(List<ASTFCmd> commands) {
208199 * @param progS AstfProgram server
209200 */
210201 public void updateKeepAlive (ASTFProgram progS ) {
211- if (fields .get (COMMANDS ).size () > 0 ) {
202+ if (! fields .get (COMMANDS ).isEmpty () ) {
212203 ASTFCmd cmd = fields .get (COMMANDS ).get (0 );
213204 if (cmd instanceof ASTFCmdKeepaliveMsg ) {
214205 progS .fields .get (COMMANDS ).add (0 , cmd );
@@ -217,7 +208,7 @@ public void updateKeepAlive(ASTFProgram progS) {
217208 }
218209
219210 /**
220- * delay for a random time betwean min-max usec with uniform distribution
211+ * delay for a random time between min-max usec with uniform distribution
221212 *
222213 * @param minUsec
223214 * @param maxUsec
@@ -289,15 +280,15 @@ public void sendMsg(String buf) {
289280 }
290281
291282 /**
292- * Send l7_buffer by splitting it into small chunks and issue a delay betwean each chunk. This is
283+ * Send l7_buffer by splitting it into small chunks and issue a delay between each chunk. This is
293284 * a utility command that works on top of send/delay command
294285 *
295286 * <p>example1: send (buffer1,100,10) will split the buffer to buffers of 100 bytes with delay of
296287 * 10usec
297288 *
298289 * @param l7Buf l7 stream as string
299290 * @param chunkSize size of each chunk
300- * @param delayUsec the delay in usec to insert betwean each write
291+ * @param delayUsec the delay in usec to insert between each write
301292 */
302293 public void sendChunk (String l7Buf , int chunkSize , int delayUsec ) {
303294 int size = l7Buf .length ();
@@ -320,8 +311,9 @@ public void sendChunk(String l7Buf, int chunkSize, int delayUsec) {
320311 /**
321312 * recv bytes command
322313 *
323- * @param bytes
314+ * @param bytes @Deprecated use method with Long instead
324315 */
316+ @ Deprecated
325317 public void recv (int bytes ) {
326318 recv (bytes , false );
327319 }
@@ -330,29 +322,72 @@ public void recv(int bytes) {
330322 * recv bytes command
331323 *
332324 * @param bytes
333- * @param clear
334325 */
326+ public void recv (long bytes ) {
327+ recv (bytes , false );
328+ }
329+
330+ /**
331+ * recv bytes command
332+ *
333+ * @param bytes
334+ * @param clear @Deprecated use method with long instead
335+ */
336+ @ Deprecated
335337 public void recv (int bytes , boolean clear ) {
338+ recv ((long ) bytes , clear );
339+ }
340+
341+ /**
342+ * recv bytes command
343+ *
344+ * @param bytes
345+ * @param clear
346+ */
347+ public void recv (long bytes , boolean clear ) {
336348 this .totalRcvBytes += bytes ;
337349 fields .get (COMMANDS ).add (new ASTFCmdRecv (totalRcvBytes , clear ));
338350 }
339351
340352 /**
341353 * recv msg, works for UDP flow
342354 *
343- * @param pkts wait until the rx packet watermark is reached on flow counter.
355+ * @param pkts wait until the rx packet watermark is reached on flow counter. @Deprecated use
356+ * method with long instead
344357 */
358+ @ Deprecated
345359 public void recvMsg (int pkts ) {
360+ recvMsg ((long ) pkts , false );
361+ }
362+
363+ /**
364+ * recv msg, works for UDP flow
365+ *
366+ * @param pkts wait until the rx packet watermark is reached on flow counter.
367+ */
368+ public void recvMsg (long pkts ) {
346369 recvMsg (pkts , false );
347370 }
348371
349372 /**
350373 * recv Msg cmd
351374 *
352375 * @param pkts wait until the rx packet watermark is reached on flow counter.
353- * @param clear when reach the watermark clear the flow counter
376+ * @param clear when reach the watermark clear the flow counter @Deprecated use method with long
377+ * instead
354378 */
379+ @ Deprecated
355380 public void recvMsg (int pkts , boolean clear ) {
381+ recvMsg ((long ) pkts , clear );
382+ }
383+
384+ /**
385+ * recv Msg cmd
386+ *
387+ * @param pkts wait until the rx packet watermark is reached on flow counter.
388+ * @param clear when reach the watermark clear the flow counter
389+ */
390+ public void recvMsg (long pkts , boolean clear ) {
356391 this .totalRcvBytes += pkts ;
357392 fields .get (COMMANDS ).add (new ASTFCmdRecvMsg (this .totalRcvBytes , clear ));
358393 }
@@ -404,8 +439,9 @@ public void setKeepAliveMsg(int msec) {
404439 * set var command
405440 *
406441 * @param varId
407- * @param value
442+ * @param value @Deprecated use method with Long instead
408443 */
444+ @ Deprecated
409445 public void setVar (String varId , int value ) {
410446 addVar (varId );
411447 fields .get (COMMANDS ).add (new ASTFCmdSetVal (varId , (long ) value ));
@@ -447,9 +483,19 @@ public void jmpNz(String varId, String label) {
447483 /**
448484 * get the total send bytes of the program
449485 *
450- * @return sent bytes
486+ * @return sent bytes @Deprecated use getTotalSendBytesLong instead
451487 */
488+ @ Deprecated
452489 public int getTotalSendBytes () {
490+ return (int ) totalSendBytes ;
491+ }
492+
493+ /**
494+ * get the total send bytes of the program
495+ *
496+ * @return sent bytes
497+ */
498+ public long getTotalSendBytesLong () {
453499 return totalSendBytes ;
454500 }
455501
@@ -562,7 +608,7 @@ private void compile() {
562608 }
563609 }
564610
565- private boolean isNumber (String str ) {
611+ private static boolean isNumber (String str ) {
566612 for (char c : str .toCharArray ()) {
567613 if (c < 48 || c > 57 ) {
568614 return false ;
@@ -595,12 +641,11 @@ public int add(String base64Buf) {
595641 String sha256Buf = encodeSha256 (base64Buf );
596642 if (bufHash .containsKey (sha256Buf )) {
597643 return bufHash .get (sha256Buf );
598- } else {
599- bufList .add (base64Buf );
600- int newIndex = bufList .size () - 1 ;
601- bufHash .put (sha256Buf , newIndex );
602- return newIndex ;
603644 }
645+ bufList .add (base64Buf );
646+ int newIndex = bufList .size () - 1 ;
647+ bufHash .put (sha256Buf , newIndex );
648+ return newIndex ;
604649 }
605650
606651 /**
@@ -621,7 +666,7 @@ public JsonArray toJson() {
621666 * @param buf should be base64 encode string
622667 * @return Hex string of the sha256 encode buf
623668 */
624- private static String encodeSha256 (String buf ) {
669+ static String encodeSha256 (String buf ) {
625670 try {
626671 MessageDigest sha256 = MessageDigest .getInstance ("MD5" );
627672 byte [] hashInBytes = sha256 .digest (buf .getBytes (StandardCharsets .UTF_8 ));
0 commit comments