summaryrefslogtreecommitdiff
path: root/staging/send.c
blob: 5ad1a203e52c71589c9751392631a012546c38e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
 * Mausezahn - A fast versatile traffic generator
 * Copyright (C) 2008 Herbert Haas
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 2 as published by the 
 * Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with 
 * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html
 * 
*/





// ***************************************************************************
// 
//    This sections contains:
//     
//     -  complexity() ... calculates and reports how many frames will 
//                         be generated.
//     -  send_frame() ... the general and mighty SENDING FUNCTION.
//
// ***************************************************************************

#include "mz.h"
#include "cli.h"


// Calculates the number of frames to be sent.
// Should be used as standard output except the
// 'quiet' option (-q) has been specified.
int complexity()
{
   unsigned long int 
     nr_sqnr = 1, 
     nr_dp   = 1, 
     nr_sp   = 1,
     nr_da   = 1,
     nr_sa   = 1;
   
   u_int32_t 
     sn1, 
     sn2, 
     delta;

   long double ref;
   
   if (tx.count==0) goto infinity;
   
   total_d = 1.0;
   
   // How many sequence numbers?
   if (tx.tcp_seq_delta)
     {
	sn1 = tx.tcp_seq_start;
	sn2 = tx.tcp_seq_stop;
	delta = tx.tcp_seq_delta;
	
	if (sn1<sn2) // the easier case
	  {
	     nr_sqnr = (sn2-sn1)/delta;
	  }
	else
	  {
	     nr_sqnr = (sn2 + (0xffffffff - sn1)) / delta;
	  }
	//fprintf(stderr,"SQNR Range = %lu\n",nr_sqnr);
	nr_sqnr +=1;
     }
   
   if (tx.dp_isrange)
     {
	nr_dp = tx.dp_stop - tx.dp_start + 1;
	//fprintf(stderr,"DP Range = %lu\n",nr_dp);
     }

   if (tx.sp_isrange)
     {
	nr_sp = tx.sp_stop - tx.sp_start + 1;
	//fprintf(stderr,"SP Range = %lu\n",nr_sp);
     }
   
   if (tx.ip_dst_isrange)
     {
	nr_da = tx.ip_dst_stop - tx.ip_dst_start + 1;
	//fprintf(stderr,"DA Range = %lu\n",nr_da);
     }
   
   if (tx.ip_src_isrange)
     {
	nr_sa = tx.ip_src_stop - tx.ip_src_start + 1;
	//fprintf(stderr,"SA Range = %lu\n",nr_sa);
     }
   
   total_d *= tx.count;
   total_d *= nr_sqnr;
   total_d *= nr_dp;
   total_d *= nr_sp;
   total_d *= nr_da;
   total_d *= nr_sa;  
   



   ref=0xffffffff;

   ref*=ref;
   
   if (total_d>ref)
     {
	fprintf(stderr, "You must be crazy...\n");
     }
   else if (total_d>0xffffffff)
     {
	fprintf(stderr, "Do you REALLY know what you do?\n");
     }
   else if (total_d>0xffffff)
     {
	fprintf(stderr, "Do you know what you do?\n");
     }

   if (mz_port)
     {
	cli_print(gcli, "Mausezahn will send %.Lf frames...\r", total_d);
     }
   else
     {
	fprintf(stderr, "Mausezahn will send %.Lf frames... ", total_d);
	fflush(stderr);
	if (verbose) fprintf(stderr,"\n");
     }
   
   
   
   mz_start = clock();
   
   infinity:
   
   
    if (tx.count==0)
     {
	if (mz_port)
	  {
	     cli_print(gcli, "Mausezahn will send frames infinitly...\n");
	  }
	else
	  {
	     fprintf(stderr, "Mausezahn will send frames infinitly...\n");
	  }
     }
   
   
   return 0;
}



///////////////////////////////////////////////////////////////////////
//
// Send complete frame (layers 2, 3, 4) multiple times if required
// 
// 
int send_frame (libnet_t *l, libnet_ptag_t  t3, libnet_ptag_t  t4)
{
   int i=0, count;

   int // local vars are faster ;-)
     tcp_seq_delta,
     dp_isrange,
     sp_isrange,
     ip_dst_isrange,
     ip_src_isrange,
     rtp_mode=0;

   
   count = tx.count;
   tcp_seq_delta = tx.tcp_seq_delta;
   dp_isrange = tx.dp_isrange;
   sp_isrange = tx.sp_isrange;
   ip_dst_isrange = tx.ip_dst_isrange;
   ip_src_isrange = tx.ip_src_isrange | tx.ip_src_rand;
   if (mode == RTP) rtp_mode = 1;
   
   if (count==0) goto AGAIN;

   for (i=0; i<count; i++)
     {

	AGAIN:

	if (verbose) (void) print_frame_details();
	libnet_write(l);
	if (mz_rand) tx.delay=(unsigned int) tx.delay*rand()/RAND_MAX;
	if (tx.delay) SLEEP (tx.delay);
	
	//   No layer-2 modifications done here 
	//   (see create_eth_frame which does L2 modifications additionally)

	
	if (tcp_seq_delta)
	  {
	     if (update_TCP_SQNR(l, t4)==0) // end of range not yet reached
	       {
		  goto AGAIN;
	       }
	  }
	
	if (dp_isrange)
	  {
	     if (update_DPORT(l, t4)==0) // end of range not yet reached
	       {
		  goto AGAIN;
	       }
	  }
	
	if (sp_isrange)
	  {
	     if (update_SPORT(l, t4)==0) // end of range not yet reached
	       {
		  goto AGAIN;
	       }
	  }
	

	if (ip_dst_isrange)
	  {
	     if (update_IP_DA(l, t3)==0) // end of range not yet reached
	       {
		  goto AGAIN;
	       }
	  }
	
	if (ip_src_isrange) // also catches random SA (see above)
	  {
	     if (update_IP_SA(l, t3)==0) // end of range not yet reached
	       {
		  goto AGAIN;
	       }
	  }

	if (rtp_mode) // update SQNR and Timestamps in RTP header and payload
	  {
	     update_RTP(l, t4);
	  }
	
	
	if (!count) goto AGAIN;
     }
   

   
   libnet_destroy(l);
   
   return 0;
}

git.cgi/linux/net-next.git/log/tools/perf/util/comm.c?id=a9306a63631493afc75893a4ac405d4e1cbae6aa'>logplain -rw-r--r--comm.h561logplain -rw-r--r--config.c16262logplain -rw-r--r--config.h2113logplain -rw-r--r--counts.c1026logplain -rw-r--r--counts.h790logplain -rw-r--r--cpumap.c12627logplain -rw-r--r--cpumap.h1954logplain -rw-r--r--cs-etm.h2061logplain -rw-r--r--ctype.c2018logplain -rw-r--r--data-convert-bt.c36671logplain -rw-r--r--data-convert-bt.h302logplain -rw-r--r--data-convert.h141logplain -rw-r--r--data.c3459logplain -rw-r--r--data.h1369logplain -rw-r--r--db-export.c11434logplain -rw-r--r--db-export.h3816logplain -rw-r--r--debug.c4417logplain -rw-r--r--debug.h2023logplain -rw-r--r--demangle-java.c4219logplain -rw-r--r--demangle-java.h249logplain -rw-r--r--demangle-rust.c6602logplain -rw-r--r--demangle-rust.h170logplain -rw-r--r--drv_configs.c1834logplain -rw-r--r--drv_configs.h844logplain -rw-r--r--dso.c31994logplain -rw-r--r--dso.h10399logplain -rw-r--r--dwarf-aux.c33828logplain -rw-r--r--dwarf-aux.h5101logplain -rw-r--r--dwarf-regs.c1816logplain -rw-r--r--env.c1884logplain -rw-r--r--env.h1268logplain -rw-r--r--event.c36670logplain -rw-r--r--event.h15997logplain -rw-r--r--evlist.c47104logplain -rw-r--r--evlist.h12584logplain -rw-r--r--evsel.c63917logplain -rw-r--r--evsel.h13041logplain -rw-r--r--evsel_fprintf.c5831logplain -rw-r--r--find-vdso-map.c581logplain -rw-r--r--genelf.c11653logplain -rw-r--r--genelf.h1814logplain -rw-r--r--genelf_debug.c14374logplain -rwxr-xr-xgenerate-cmdlist.sh1141logplain -rw-r--r--group.h122logplain -rw-r--r--header.c73410logplain -rw-r--r--header.h4365logplain -rw-r--r--help-unknown-cmd.c3221logplain