2 * Mausezahn - A fast versatile traffic generator
3 * Copyright (C) 2008 Herbert Haas
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License version 2 as published by the
7 * Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html
23 // ***************************************************************************
25 // This sections contains:
27 // - complexity() ... calculates and reports how many frames will
29 // - send_frame() ... the general and mighty SENDING FUNCTION.
31 // ***************************************************************************
37 // Calculates the number of frames to be sent.
38 // Should be used as standard output except the
39 // 'quiet' option (-q) has been specified.
56 if (tx
.count
==0) goto infinity
;
60 // How many sequence numbers?
63 sn1
= tx
.tcp_seq_start
;
64 sn2
= tx
.tcp_seq_stop
;
65 delta
= tx
.tcp_seq_delta
;
67 if (sn1
<sn2
) // the easier case
69 nr_sqnr
= (sn2
-sn1
)/delta
;
73 nr_sqnr
= (sn2
+ (0xffffffff - sn1
)) / delta
;
75 //fprintf(stderr,"SQNR Range = %lu\n",nr_sqnr);
81 nr_dp
= tx
.dp_stop
- tx
.dp_start
+ 1;
82 //fprintf(stderr,"DP Range = %lu\n",nr_dp);
87 nr_sp
= tx
.sp_stop
- tx
.sp_start
+ 1;
88 //fprintf(stderr,"SP Range = %lu\n",nr_sp);
91 if (tx
.ip_dst_isrange
)
95 nr_da
= get_ip6_range_count(tx
.ip6_dst_start
, tx
.ip6_dst_stop
);
99 nr_da
= tx
.ip_dst_stop
- tx
.ip_dst_start
+ 1;
101 //fprintf(stderr,"DA Range = %lu\n",nr_da);
104 if (tx
.ip_src_isrange
)
108 nr_sa
= get_ip6_range_count(tx
.ip6_src_start
, tx
.ip6_src_stop
);
112 nr_sa
= tx
.ip_src_stop
- tx
.ip_src_start
+ 1;
114 //fprintf(stderr,"SA Range = %lu\n",nr_sa);
133 fprintf(stderr
, "You must be crazy...\n");
135 else if (total_d
>0xffffffff)
137 fprintf(stderr
, "Do you REALLY know what you are doing?\n");
139 else if (total_d
>0xffffff)
141 fprintf(stderr
, "Do you know what you are doing?\n");
146 cli_print(gcli
, "Mausezahn will send %.Lf frames...\r", total_d
);
150 fprintf(stderr
, "Mausezahn will send %.Lf frames... ", total_d
);
152 if (verbose
) fprintf(stderr
,"\n");
166 cli_print(gcli
, "Mausezahn will send frames infinitely...\n");
170 fprintf(stderr
, "Mausezahn will send frames infinitely...\n");
180 ///////////////////////////////////////////////////////////////////////
182 // Send complete frame (layers 2, 3, 4) multiple times if required
185 int send_frame (libnet_t
*l
, libnet_ptag_t t3
, libnet_ptag_t t4
)
189 int // local vars are faster ;-)
199 tcp_seq_delta
= tx
.tcp_seq_delta
;
200 dp_isrange
= tx
.dp_isrange
;
201 sp_isrange
= tx
.sp_isrange
;
202 ip_dst_isrange
= tx
.ip_dst_isrange
;
203 ip_src_isrange
= tx
.ip_src_isrange
| tx
.ip_src_rand
;
204 if (mode
== RTP
) rtp_mode
= 1;
206 if (count
==0) goto AGAIN
;
208 for (i
=0; i
<count
; i
++)
229 if (verbose
) (void) print_frame_details();
231 if (mz_rand
) tx
.delay
=(unsigned int) tx
.delay
*rand()/RAND_MAX
;
232 if (tx
.delay
) SLEEP (tx
.delay
);
234 // No layer-2 modifications done here
235 // (see create_eth_frame which does L2 modifications additionally)
240 if (update_TCP_SQNR(l
, t4
)==0) // end of range not yet reached
248 if (update_DPORT(l
, t4
)==0) // end of range not yet reached
256 if (update_SPORT(l
, t4
)==0) // end of range not yet reached
265 if (update_IP_DA(l
, t3
)==0) // end of range not yet reached
271 if (ip_src_isrange
) // also catches random SA (see above)
273 if (update_IP_SA(l
, t3
)==0) // end of range not yet reached
279 if (rtp_mode
) // update SQNR and Timestamps in RTP header and payload
285 if (!count
) goto AGAIN
;