[dbench @ tridge@samba.org-20080709030609-aepl7hrdkn7mpfoz]
[tridge/dbench.git] / genloadfile / genloadfile.sh
1 #!/bin/sh
2
3 TSHARK=./tshark
4 ECHO=/bin/echo
5
6 # Process the tempfile and convert it into a NBENCH file
7
8 extract_field() {
9         $ECHO "$1" | sed -n -e "s/^.*$2 == //; T; s/ .*$//; p"
10 }
11
12 extract_name() {
13         $ECHO "$1" | sed -n -e "s/^.*$2 == \"\([^\"]*\)\".*$/\"\/clients\/client1\1\"/; T; p"
14 }
15
16 write_andx_pkt() {
17         TIMESTAMP=$1
18         PACKET=$2
19
20         FID=`extract_field "$PACKET" "smb.fid"`
21         OFFSET=`extract_field "$PACKET" "smb.file.rw.offset"`
22         LENGTH=`extract_field "$PACKET" "smb.file.rw.length"`
23
24         COUNT_LOW=`extract_field "$PACKET" "smb.count_low"`
25         COUNT_HIGH=`extract_field "$PACKET" "smb.count_high"`
26         if [ $COUNT_LOW ] && [ $COUNT_HIGH ]; then
27             COUNT=$(( $COUNT_LOW + ($COUNT_HIGH << 16) ))
28         else
29             COUNT=
30         fi
31
32         STATUS=`extract_field "$PACKET" "smb.nt_status"`
33
34         if [ $FID ] && [ $OFFSET ] && [ $LENGTH ] && [ $COUNT ] && [ $STATUS ]; then
35                 $ECHO $TIMESTAMP "WriteX" $FID $OFFSET $LENGTH $COUNT $STATUS
36         else
37                 $ECHO "Incomplete WriteX: TIMESTAMP: $TIMESTAMP, "      \
38                                           "FID: $FID, "                 \
39                                           "OFFSET: $OFFSET, "           \
40                                           "LENGTH: $LENGTH, "           \
41                                           "COUNT: $COUNT, "             \
42                                           "STATUS: $STATUS" 1>&2
43         fi
44 }
45
46 close_pkt() {
47         TIMESTAMP=$1
48         PACKET=$2
49
50         FID=`extract_field "$PACKET" "smb.fid"`
51         STATUS=`extract_field "$PACKET" "smb.nt_status"`
52
53         if [ $FID ]; then
54             $ECHO $TIMESTAMP "Close" $FID $STATUS
55         fi
56 }
57
58 ntcreate_andx_pkt() {
59         TIMESTAMP=$1
60         PACKET=$2
61
62         NAME=`extract_name "$PACKET" "smb.file"`
63         FID=`extract_field "$PACKET" "smb.fid"`
64         OPTIONS=`extract_field "$PACKET" "smb.create_options"`
65         DISPOSITION=`extract_field "$PACKET" "smb.create.disposition"`
66         STATUS=`extract_field "$PACKET" "smb.nt_status"`
67
68         if [ $NAME ] && [ $OPTIONS ] && [ $DISPOSITION ] && [ $FID ] && [ $STATUS ]; then
69                 $ECHO "$TIMESTAMP NTCreateX $NAME $OPTIONS $DISPOSITION $FID $STATUS"
70         else
71                 $ECHO "Incomplete NTCreateX: TIMESTAMP: $TIMESTAMP, "      \
72                                             "NAME: $NAME, "                \
73                                             "OPTIONS: $OPTIONS, "          \
74                                             "DISPOSITION: $DISPOSITION, " \
75                                             "FID: $FID, "                  \
76                                             "STATUS: $STATUS" 1>&2
77         fi
78 }
79
80 read_andx_pkt() {
81         TIMESTAMP=$1
82         PACKET=$2
83
84         FID=`extract_field "$PACKET" "smb.fid"`
85         OFFSET=`extract_field "$PACKET" "smb.file.rw.offset"`
86         LENGTH=`extract_field "$PACKET" "smb.file.rw.length"`
87         COUNT=`extract_field "$PACKET" "smb.data_len_low"`
88         STATUS=`extract_field "$PACKET" "smb.nt_status"`
89
90         if [ $FID ] && [ $OFFSET ] && [ $LENGTH ] && [ $COUNT ] && [ $STATUS ]; then
91                 $ECHO "$TIMESTAMP ReadX $FID $OFFSET $LENGTH $COUNT $STATUS"
92         else
93                 $ECHO "Incomplete ReadX: TIMESTAMP: $TIMESTAMP, "       \
94                                         "FID: $FID, "                   \
95                                         "OFFSET: $OFFSET, "             \
96                                         "LENGTH: $LENGTH, "             \
97                                         "COUNT: $COUNT, "               \
98                                         "STATUS: $STATUS" 1>&2
99         fi
100 }
101
102 trans2_qfi_pkt() {
103         FID=`extract_field "$1" "smb.fid"`
104         LEVEL=`extract_field "$1" "smb.qpi_loi"`
105         STATUS=`extract_field "$1" "smb.nt_status"`
106
107         $ECHO "QUERY_FILE_INFORMATION" $FID $LEVEL $STATUS
108 }
109
110 trans2_qfsi_pkt() {
111         FID=`extract_field "$1" "smb.fid"`
112         LEVEL=`extract_field "$1" "smb.qfsi_loi"`
113         STATUS=`extract_field "$1" "smb.nt_status"`
114
115         $ECHO "QUERY_FS_INFORMATION" $LEVEL $STATUS
116 }
117
118 trans2_qpi_pkt() {
119         NAME=`extract_name "$1" "smb.file"`
120         LEVEL=`extract_field "$1" "smb.qpi_loi"`
121         STATUS=`extract_field "$1" "smb.nt_status"`
122
123         $ECHO "QUERY_PATH_INFORMATION" "$NAME" $LEVEL $STATUS
124 }
125
126 trans2_ff2_pkt() {
127         NAME=`extract_name "$1" "smb.search_pattern"`
128         LEVEL=`extract_field "$1" "smb.ff2_loi"`
129         STATUS=`extract_field "$1" "smb.nt_status"`
130
131         $ECHO "FIND_FIRST" "$NAME" $LEVEL 1000 0 $STATUS
132 }
133
134 delete_pkt() {
135         NAME=`extract_name "$1" "smb.file"`
136         STATUS=`extract_field "$1" "smb.nt_status"`
137
138        $ECHO "Unlink" "$NAME" 0x16 $STATUS
139 }
140
141 createdir_pkt() {
142         NAME=`extract_name "$1" "smb.file"`
143         STATUS=`extract_field "$1" "smb.nt_status"`
144
145         $ECHO "Mkdir" "$NAME" $STATUS
146 }
147
148 deletedir_pkt() {
149         NAME=`extract_name "$1" "smb.file"`
150         STATUS=`extract_field "$1" "smb.nt_status"`
151
152         $ECHO "Rmdir" "$NAME" $STATUS
153 }
154
155 checkdir_pkt() {
156         NAME=`extract_name "$1" "smb.file"`
157         STATUS=`extract_field "$1" "smb.nt_status"`
158
159         $ECHO "Checkdir" "$NAME" $STATUS
160 }
161
162 trans2_sfi_pkt() {
163         TIMESTAMP=$1
164         PACKET=$2
165
166 # !!! TEMPORAL !!!
167         return;
168
169         FID=`extract_field "$PACKET" "smb.fid"`
170         LEVEL=`extract_field "$PACKET" "smb.sfi_loi"`
171         STATUS=`extract_field "$PACKET" "smb.nt_status"`
172
173         $ECHO $PACKET 1>&2
174         $ECHO "SET_FILE_INFORMATION: FID: $FID, LEVEL: $LEVEL, STATUS: $STATUS" 1>&2
175
176         $ECHO "$TIMESTAMP SET_FILE_INFORMATION" $FID $LEVEL $STATUS
177 }
178
179 lockandx_pkt() {
180         FID=`extract_field "$1" "smb.fid"`
181         OFFSET=`extract_field "$1" "smb.lock.offset"`
182         LENGTH=`extract_field "$1" "smb.lock.length"`
183         STATUS=`extract_field "$1" "smb.nt_status"`
184
185         $ECHO "LockX" $FID $OFFSET $LENGTH $STATUS
186 }
187
188 unlockandx_pkt() {
189         FID=`extract_field "$1" "smb.fid"`
190         OFFSET=`extract_field "$1" "smb.lock.offset"`
191         LENGTH=`extract_field "$1" "smb.lock.length"`
192         STATUS=`extract_field "$1" "smb.nt_status"`
193
194         $ECHO "UnlockX" $FID $OFFSET $LENGTH $STATUS
195 }
196
197
198 flush_pkt() {
199         TIMESTAMP=$1
200         PACKET=$2
201
202         FID=`extract_field "$PACKET" "smb.fid"`
203         STATUS=`extract_field "$PACKET" "smb.nt_status"`
204
205         if [ $FID ] && [ $STATUS ]; then
206             $ECHO $TIMESTAMP "Flush" $FID $STATUS
207         else
208             $ECHO "Incomplete Flush: TIMESTAMP: $TIMESTAMP, "   \
209                                     "FID: $FID, "               \
210                                     "STATUS: $STATUS" 1>&2
211         fi
212 }
213
214 rename_pkt() {
215         TIMESTAMP=$1
216         PACKET=$2
217
218         OLDNAME=`extract_name "$PACKET" "smb.old_file"`
219         NEWNAME=`extract_name "$PACKET" "smb.file"`
220         STATUS=`extract_field "$PACKET" "smb.nt_status"`
221
222         if [ $OLDNAME ] && [ $NEWNAME ] && [ $STATUS ]; then
223             $ECHO $TIMESTAMP "Rename" $OLDNAME $NEWNAME $STATUS
224         else
225             $ECHO "Incomplete Rename: TIMESTAMP: $TIMESTAMP, "  \
226                                      "OLDNAME: $OLDNAME, "      \
227                                      "NEWNAME: $NEWNAME, "      \
228                                      "STATUS: $STATUS" 1>&2
229         fi
230 }
231
232 # This script takes a network capture file and generates an nbench load file
233
234 # Currently supported SMB commands are
235 #   Close
236 #   CheckDirectory
237 #   CreateDirectory
238 #   Delete
239 #   DeleteDirectory
240 #   FIND_FIRST2
241 #   Flush
242 #   LockingAndX
243 #   NTCreateAndX
244 #   QueryFileInfo
245 #   QueryFSInfo
246 #   QueryPathInfo
247 #   ReadAndX
248 #   Rename
249 #   WriteAndX
250 #
251
252 $ECHO 0.000000000 Deltree \"/clients/client1\" 0x00000000
253 $ECHO 0.000000000 Mkdir \"/clients\" 0x00000000
254 $ECHO 0.000000000 Mkdir \"/clients/client1\" 0x00000000
255
256 $TSHARK -n -r $1 -R "smb.flags.response==1 and smb.cmd" \
257     -z "proto,colinfo,smb.locking.num_unlocks and smb.cmd==0x24,smb.locking.num_unlocks"                \
258     -z "proto,colinfo,smb.locking.num_locks and smb.cmd==0x24,smb.locking.num_locks"            \
259     -z "proto,colinfo,smb.pid and smb.cmd==0x24,smb.pid"                \
260     -z "proto,colinfo,smb.lock.offset and smb.cmd==0x24,smb.lock.offset"                \
261     -z "proto,colinfo,smb.lock.length and smb.cmd==0x24,smb.lock.length"                \
262     -z "proto,colinfo,smb.pid and smb.cmd==0x2f,smb.pid"                \
263     -z "proto,colinfo,smb.count_low and smb.cmd==0x2f,smb.count_low"            \
264     -z "proto,colinfo,smb.count_high and smb.cmd==0x2f,smb.count_high"          \
265     -z "proto,colinfo,smb.file.rw.offset and smb.cmd==0x2f,smb.file.rw.offset"          \
266     -z "proto,colinfo,smb.file.rw.length and smb.cmd==0x2f,smb.file.rw.length"          \
267     -z "proto,colinfo,smb.qpi_loi and smb.cmd==0x32,smb.qpi_loi"                \
268     -z "proto,colinfo,smb.spi_loi and smb.cmd==0x32,smb.spi_loi"                \
269     -z "proto,colinfo,smb.qfsi_loi and smb.cmd==0x32,smb.qfsi_loi"              \
270     -z "proto,colinfo,smb.ff2_loi and smb.cmd==0x32,smb.ff2_loi"                \
271     -z "proto,colinfo,smb.search_pattern and smb.cmd==0x32,smb.search_pattern"  \
272     -z "proto,colinfo,smb.trans2.cmd and smb.cmd==0x32,smb.trans2.cmd"          \
273     -z "proto,colinfo,smb.data_len_low and smb.cmd==0x2e,smb.data_len_low"      \
274     -z "proto,colinfo,smb.create_flags and smb.cmd==0xa2,smb.create_flags"      \
275     -z "proto,colinfo,smb.create_options and smb.cmd==0xa2,smb.create_options"  \
276     -z "proto,colinfo,smb.create.disposition and smb.cmd==0xa2,smb.create.disposition"  \
277     -z "proto,colinfo,smb.share_access and smb.cmd==0xa2,smb.share_access"      \
278     -z "proto,colinfo,smb.access_mask and smb.cmd==0xa2,smb.access_mask"        \
279     -z "proto,colinfo,smb.nt.function and smb.cmd==0xa0,smb.nt.function"        \
280     -z "proto,colinfo,smb.file.rw.offset,smb.file.rw.offset"                    \
281     -z "proto,colinfo,smb.file.rw.length,smb.file.rw.length"                    \
282     -z "proto,colinfo,smb.file,smb.file"                                        \
283     -z "proto,colinfo,smb.old_file,smb.old_file"                                        \
284     -z "proto,colinfo,smb.fid,smb.fid"                                          \
285     -z "proto,colinfo,smb.nt_status,smb.nt_status"                              \
286     -z "proto,colinfo,smb.cmd,smb.cmd" \
287     -z "proto,colinfo,frame.time_relative,frame.time_relative" \
288 | while read PACKET; do
289
290 TIMESTAMP=`extract_field "$PACKET" "frame.time_relative"`
291 case "$PACKET" in
292
293   # Close
294   *"smb.cmd == 0x04"*)
295         close_pkt "$TIMESTAMP" "$PACKET"
296         ;;
297
298   # CheckDir
299   *"smb.cmd == 0x10"*)
300         $ECHO -n "$TIMESTAMP "
301         checkdir_pkt "$PACKET"
302         ;;
303
304   # CreateDir
305   *"smb.cmd == 0x00"*)
306         $ECHO -n "$TIMESTAMP "
307         createdir_pkt "$PACKET"
308         ;;
309
310   # Delete
311   *"smb.cmd == 0x06"*)
312         $ECHO -n "$TIMESTAMP "
313         delete_pkt "$PACKET"
314         ;;
315
316   # DeleteDir
317   *"smb.cmd == 0x01"*)
318         $ECHO -n "$TIMESTAMP "
319         deletedir_pkt "$PACKET"
320         ;;
321
322   # Flush
323   *"smb.cmd == 0x05"*)
324         flush_pkt "$TIMESTAMP" "$PACKET"
325         ;;
326
327   # LockingAndX   Lock
328   *"smb.cmd == 0x24"*"smb.locking.num_locks == 1"*"smb.locking.num_unlocks == 0"*)
329         lockandx_pkt "$PACKET"
330         ;;
331
332   # LockingAndX   Unlock
333   *"smb.cmd == 0x24"*"smb.locking.num_locks == 0"*"smb.locking.num_unlocks == 1"*)
334         unlockandx_pkt "$PACKET"
335         ;;
336
337   # Logoff
338   *"smb.cmd == 0x74"*)
339         # just ignore any logoffs
340         ;;
341
342   # NegotiateProtocol
343   *"smb.cmd == 0x72"*)
344         # just ignore any negotiate protocol
345         ;;
346
347   # NTCreateAndX
348   *"smb.cmd == 0xa2"*)
349         ntcreate_andx_pkt "$TIMESTAMP" "$PACKET"
350         ;;
351
352   # NT Trans ioctl
353   *"smb.cmd == 0xa0"*"smb.nt.function == 2"*)
354         # ignore
355         ;;
356
357   # NT Trans NOTIFY 
358   *"smb.cmd == 0xa0"*"smb.nt.function == 4"*)
359         # ignore
360         ;;
361
362   # Rename
363   *"smb.cmd == 0x07"*)
364         rename_pkt "$TIMESTAMP" "$PACKET"
365         ;;
366
367   # SessionSetup
368   *"smb.cmd == 0x73"*)
369         # just ignore any sessionsetup
370         ;;
371
372   # ProcessExit
373   *"smb.cmd == 0x11"*)
374         # just ignore any process exit
375         ;;
376
377   # TreeConnect
378   *"smb.cmd == 0x75"*)
379         # just ignore any tree connect
380         ;;
381
382   # TreeDisconnect
383   *"smb.cmd == 0x71"*)
384         # just ignore any tree disconnect
385         ;;
386
387   # Trans
388   *"smb.cmd == 0x25"*)
389         # ignore
390         ;;
391
392   # Trans2 FF2 
393   *"smb.cmd == 0x32"*"smb.trans2.cmd == 0x0001"*)
394         $ECHO -n "$TIMESTAMP "
395         trans2_ff2_pkt "$PACKET"
396         ;;
397
398   # Trans2 GetDfsReferral
399   *"smb.cmd == 0x32"*"smb.trans2.cmd == 0x0010"*)
400         # ignore for now
401         ;;
402
403   # Trans2 QFI 
404   *"smb.cmd == 0x32"*"smb.trans2.cmd == 0x0007"*)
405         $ECHO -n "$TIMESTAMP "
406         trans2_qfi_pkt "$PACKET"
407         ;;
408
409   # Trans2 QFSI 
410   *"smb.cmd == 0x32"*"smb.trans2.cmd == 0x0003"*)
411         $ECHO -n "$TIMESTAMP "
412         trans2_qfsi_pkt "$PACKET"
413         ;;
414
415   # Trans2 QPI 
416   *"smb.cmd == 0x32"*"smb.trans2.cmd == 0x0005"*)
417         $ECHO -n "$TIMESTAMP "
418         trans2_qpi_pkt "$PACKET"
419         ;;
420
421   # Trans2 SFI
422   *"smb.cmd == 0x32"*"smb.trans2.cmd == 0x0008"*)
423         trans2_sfi_pkt "$TIMESTAMP" "$PACKET"
424         ;;
425
426   # ReadAndX
427   *"smb.cmd == 0x2e"*)
428         read_andx_pkt "$TIMESTAMP" "$PACKET"
429         ;;
430
431   # WriteAndX
432   *"smb.cmd == 0x2f"*)
433         write_andx_pkt "$TIMESTAMP" "$PACKET"
434         ;;
435
436   *)
437         $ECHO "Unknown command:$PACKET" 1>&2
438         ;;
439
440 esac
441 done
442
443 $ECHO 0.000000000 Deltree \"/clients/client1\" 0x00000000
444