@@ -90,26 +90,26 @@ def capture_packets(t_out, t_err, ints_list, capture_dir):
90
90
def workload (net , hosts ):
91
91
net .pingAll ()
92
92
93
- def get_tshark_counts (t_outfile , tshark_filter_funs , ctlr ):
93
+ def get_tshark_counts (t_outfile , params , ctlr ):
94
+ filter_funs = params ['filter_funs' ].split (',' )
95
+ test_nums = params ['test_nums' ].split (',' )
96
+ assert len (filter_funs ) == len (test_nums )
97
+ tshark_counts = {}
98
+
94
99
if ctlr == 'bucket' :
95
- return bucket_get_tshark_counts ( t_outfile , tshark_filter_funs )
100
+ counting_fun = bucket_tshark_filter_count
96
101
elif ctlr == 'path_query' :
97
- return path_query_get_tshark_counts ( t_outfile , tshark_filter_funs )
102
+ counting_fun = path_query_tshark_filter_count
98
103
else :
99
104
raise RuntimeError ('unknown controller!' )
100
105
101
- def bucket_get_tshark_counts (t_outfile , tshark_filter_funs ):
102
- tshark_counts = {}
103
- for f in tshark_filter_funs .split (',' ):
104
- count_ref = len (tshark_counts .keys ())
105
- tshark_counts .update ([(count_ref ,
106
- tshark_filter_count (t_outfile , f ))])
106
+ for i in range (0 , len (filter_funs )):
107
+ bucket_ref = test_nums [i ]
108
+ f = filter_funs [i ]
109
+ tshark_counts .update ([(bucket_ref , counting_fun (t_outfile , f ))])
107
110
return tshark_counts
108
111
109
- def path_query_get_tshark_counts (t_outfile , tshark_filter_funs ):
110
- pass
111
-
112
- def tshark_filter_count (t_outfile , filter_fun ):
112
+ def bucket_tshark_filter_count (t_outfile , filter_fun ):
113
113
global ints_map
114
114
t_out = open (t_outfile , 'r' )
115
115
pkt_count = 0
@@ -125,6 +125,37 @@ def tshark_filter_count(t_outfile, filter_fun):
125
125
byte_count += bytes_fun (line )
126
126
return (pkt_count , byte_count )
127
127
128
+ def get_key_str (line ):
129
+ """ This function matches closely with the get_key_str() function in
130
+ path_query.py, since they both generate keys to aggregate the same set of
131
+ packets in different ways -- the latter to group packet counts retrieved
132
+ from query-matched packets, and this one to group packets filtered from
133
+ tshark."""
134
+ global rev_ints_map
135
+ ethtype = 'ip' if __get_ip_srcip (line ) != '' else 'arp'
136
+ srcip_fun = __get_ip_srcip if ethtype == 'ip' else __get_arp_srcip
137
+ dstip_fun = __get_ip_dstip if ethtype == 'ip' else __get_arp_dstip
138
+ pred = "int:%s,ethtype:%s,srcip:%s,dstip:%s" % (
139
+ rev_ints_map [__get_interface_id (line )],
140
+ ethtype , srcip_fun (line ), dstip_fun (line ))
141
+ return pred
142
+
143
+ def path_query_tshark_filter_count (t_outfile , filter_fun ):
144
+ global ints_map
145
+ t_out = open (t_outfile , 'r' )
146
+ predwise_count = {}
147
+ filter_fun = globals ()[filter_fun ]
148
+ if 'any' not in ints_map :
149
+ bytes_fun = get_bytes
150
+ else :
151
+ bytes_fun = get_bytes_cooked_capture
152
+ for line in t_out :
153
+ if filter_fun (line .strip ()):
154
+ pred = get_key_str (line )
155
+ (pkt_count , byte_count ) = predwise_count .get (pred , (0 , 0 ))
156
+ predwise_count [pred ] = (pkt_count + 1 , byte_count + bytes_fun (line ))
157
+ return predwise_count
158
+
128
159
def ctlr_counts (c_outfile , c_name ):
129
160
c_out = open (c_outfile , 'r' )
130
161
if c_name == 'bucket' :
@@ -159,8 +190,9 @@ def path_query_ctlr_counts(c_out):
159
190
bucket_p = re .compile ("Bucket [0-9a-zA-Z._]+ [0-9a-zA-Z,:._\-]+ counts: \[[0-9]+, [0-9]+\]$" )
160
191
for line in c_out :
161
192
if bucket_p .match (line .strip ()):
162
- (bucket_id , pkt_count , byte_count , pred ) = (
193
+ (bucket_id , pkt_count , byte_count , inter_str ) = (
163
194
__parse_ctlr_count_line__ (line ))
195
+ pred = inter_str .split ()[0 ]
164
196
try :
165
197
buckets_preds_counts [bucket_id ][pred ] = (pkt_count , byte_count )
166
198
except KeyError :
@@ -220,7 +252,9 @@ def test_bucket_single_test():
220
252
221
253
""" Verify results """
222
254
print "Verifying correctness..."
223
- tshark_counts = get_tshark_counts (t_outfile , args .tshark_filter_funs , c_name )
255
+ tshark_filter_params = {'filter_funs' : args .tshark_filter_funs ,
256
+ 'test_nums' : args .test_nums }
257
+ tshark_counts = get_tshark_counts (t_outfile , tshark_filter_params , c_name )
224
258
buckets_counts = ctlr_counts (c_outfile , c_name )
225
259
success_file = adjust_path (args .success_file )
226
260
write_passfail_info (success_file , tshark_counts , buckets_counts , c_name )
@@ -241,6 +275,9 @@ def parse_args():
241
275
parser .add_argument ("--tshark_filter_funs" , default = "filt_test0" ,
242
276
help = "Filter functions to parse tshark output " +
243
277
"(multiple values can be comma separated" )
278
+ parser .add_argument ("--test_nums" , default = "0" ,
279
+ help = "Test numbers to distinguish controller outputs" +
280
+ " (multiple values can be comma separated)" )
244
281
parser .add_argument ("--topo_args" , default = "3" ,
245
282
help = "Arguments to the topology class constructor " +
246
283
"(separated by commas)" )
@@ -298,8 +335,18 @@ def bucket_write_passfail_info(success_file, tshark_counts, buckets_counts):
298
335
passfail .write (output_str )
299
336
passfail .close ()
300
337
301
- def path_query_write_passfail_info ():
302
- pass
338
+ def path_query_write_passfail_info (success_file , tshark_counts , buckets_counts ):
339
+ print "In path query passfail info. I got the following counts:"
340
+ print "TShark:"
341
+ print "Bucket references:" , tshark_counts .keys ()
342
+ for vals in tshark_counts .values ():
343
+ for (k , v ) in vals .iteritems ():
344
+ print k , v
345
+ print "Buckets:"
346
+ print "Bucket references:" , buckets_counts .keys ()
347
+ for vals in buckets_counts .values ():
348
+ for (k , v ) in vals .iteritems ():
349
+ print k , v
303
350
304
351
### Helpers to extract specific headers from tshark output ###
305
352
ints_map = {}
0 commit comments