@@ -90,10 +90,20 @@ 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 ):
94
- tshark_counts = set ()
93
+ def get_tshark_counts (t_outfile , tshark_filter_funs , ctlr ):
94
+ if ctlr == 'bucket' :
95
+ return bucket_get_tshark_counts (t_outfile , tshark_filter_funs )
96
+ elif ctlr == 'path_query' :
97
+ return path_query_get_tshark_counts (t_outfile , tshark_filter_funs )
98
+ else :
99
+ raise RuntimeError ('unknown controller!' )
100
+
101
+ def bucket_get_tshark_counts (t_outfile , tshark_filter_funs ):
102
+ tshark_counts = {}
95
103
for f in tshark_filter_funs .split (',' ):
96
- tshark_counts .add (tshark_filter_count (t_outfile , f ))
104
+ count_ref = len (tshark_counts .keys ())
105
+ tshark_counts .update ([(count_ref ,
106
+ tshark_filter_count (t_outfile , f ))])
97
107
return tshark_counts
98
108
99
109
def tshark_filter_count (t_outfile , filter_fun ):
@@ -112,18 +122,48 @@ def tshark_filter_count(t_outfile, filter_fun):
112
122
byte_count += bytes_fun (line )
113
123
return (pkt_count , byte_count )
114
124
115
- def ctlr_counts (c_outfile ):
125
+ def ctlr_counts (c_outfile , c_name ):
116
126
c_out = open (c_outfile , 'r' )
127
+ if c_name == 'bucket' :
128
+ count_dict = bucket_ctlr_counts (c_out )
129
+ elif c_name == 'path_query' :
130
+ count_dict = path_query_ctlr_counts (c_out )
131
+ else :
132
+ raise RuntimeError ('unknown controller!' )
133
+ c_out .close ()
134
+ return count_dict
135
+
136
+ def __parse_ctlr_count_line__ (line ):
137
+ parts = line .strip ().split ()
138
+ bucket_id = parts [1 ]
139
+ pkt_count = int (parts [- 2 ][1 :- 1 ])
140
+ byte_count = int (parts [- 1 ][:- 1 ])
141
+ inter_str = ' ' .join (parts [2 :- 2 ])
142
+ return (bucket_id , pkt_count , byte_count , inter_str )
143
+
144
+ def bucket_ctlr_counts (c_out ):
117
145
buckets_counts = {}
118
146
bucket_p = re .compile ("Bucket [0-9a-zA-Z._]+ \(packet, byte\) counts: \[[0-9]+, [0-9]+\]" )
119
147
for line in c_out :
120
148
if bucket_p .match (line .strip ()):
121
- parts = line .strip ().split ()
122
- bucket_id = parts [1 ]
123
- pkt_count = int (parts [- 2 ][1 :- 1 ])
124
- byte_count = int (parts [- 1 ][:- 1 ])
149
+ (bucket_id , pkt_count , byte_count , _ ) = (
150
+ __parse_ctlr_count_line__ (line ))
125
151
buckets_counts [bucket_id ] = (pkt_count , byte_count )
126
- return set (buckets_counts .values ())
152
+ return buckets_counts
153
+
154
+ def path_query_ctlr_counts (c_out ):
155
+ buckets_preds_counts = {}
156
+ bucket_p = re .compile ("Bucket [0-9a-zA-Z._]+ [0-9a-zA-Z,:._\-]+ counts: \[[0-9]+, [0-9]+\]$" )
157
+ for line in c_out :
158
+ if bucket_p .match (line .strip ()):
159
+ (bucket_id , pkt_count , byte_count , pred ) = (
160
+ __parse_ctlr_count_line__ (line ))
161
+ try :
162
+ buckets_preds_counts [bucket_id ][pred ] = (pkt_count , byte_count )
163
+ except KeyError :
164
+ buckets_preds_counts [bucket_id ] = {}
165
+ buckets_preds_counts [bucket_id ][pred ] = (pkt_count , byte_count )
166
+ return buckets_preds_counts
127
167
128
168
def test_bucket_single_test ():
129
169
""" Main function for a single test case. """
@@ -177,10 +217,10 @@ def test_bucket_single_test():
177
217
178
218
""" Verify results """
179
219
print "Verifying correctness..."
180
- tshark_counts = get_tshark_counts (t_outfile , args .tshark_filter_funs )
181
- buckets_counts = ctlr_counts (c_outfile )
220
+ tshark_counts = get_tshark_counts (t_outfile , args .tshark_filter_funs , c_name )
221
+ buckets_counts = ctlr_counts (c_outfile , c_name )
182
222
success_file = adjust_path (args .success_file )
183
- write_passfail_info (success_file , tshark_counts , buckets_counts )
223
+ write_passfail_info (success_file , tshark_counts , buckets_counts , c_name )
184
224
185
225
#### Helper functions #####
186
226
@@ -234,10 +274,18 @@ def close_fds(fds, fd_str):
234
274
fd .close ()
235
275
print "Closed" , fd_str , "file descriptors"
236
276
237
- def write_passfail_info (success_file , tshark_counts , buckets_counts ):
277
+ def write_passfail_info (success_file , tshark_counts , buckets_counts , ctlr ):
278
+ if ctlr == 'bucket' :
279
+ bucket_write_passfail_info ()
280
+ elif ctlr == 'path_query' :
281
+ path_query_write_passfail_info ()
282
+ else :
283
+ raise RuntimeError ('unknown controller!' )
284
+
285
+ def bucket_write_passfail_info (success_file , tshark_counts , buckets_counts ):
238
286
passfail = open (success_file , 'w' )
239
287
output_str = ''
240
- if tshark_counts == buckets_counts :
288
+ if set ( tshark_counts . values ()) == set ( buckets_counts . values ()) :
241
289
output_str += "PASS\n "
242
290
else :
243
291
output_str += "FAIL\n "
@@ -247,8 +295,12 @@ def write_passfail_info(success_file, tshark_counts, buckets_counts):
247
295
passfail .write (output_str )
248
296
passfail .close ()
249
297
298
+ def path_query_write_passfail_info ():
299
+ pass
300
+
250
301
### Helpers to extract specific headers from tshark output ###
251
302
ints_map = {}
303
+ rev_ints_map = {}
252
304
253
305
def __get_frame_len (line ):
254
306
return line .split (',' )[0 ]
@@ -354,15 +406,17 @@ def filt_path_test_0_5(l):
354
406
355
407
### Interfaces map for packet capture ###
356
408
def map_any ():
357
- global ints_map
409
+ global ints_map , rev_ints_map
358
410
ints_map = {'any' : 0 }
411
+ rev_ints_map = {0 : 'any' }
359
412
return ["any" ]
360
413
361
414
def map_chain_3_3 ():
362
- global ints_map
415
+ global ints_map , rev_ints_map
363
416
ints_list = ["s1-eth1" , "s1-eth2" , "s2-eth1" , "s2-eth2" ,
364
417
"s2-eth3" , "s3-eth1" , "s3-eth2" ]
365
418
ints_map = {i : ints_list .index (i ) for i in ints_list }
419
+ rev_ints_map = {j : ints_list [j ] for j in range (0 , len (ints_list ))}
366
420
return ints_list
367
421
368
422
### The main thread.
0 commit comments