Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.

Commit 1cba74f

Browse files
committed
count verification between tshark and controller path query results
1 parent a2431a1 commit 1cba74f

File tree

2 files changed

+86
-11
lines changed

2 files changed

+86
-11
lines changed

pyretic/examples/path_query.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ def print_predwise_entries():
145145
pkt_counts[pred],
146146
byte_counts[pred])
147147

148+
def print_total_entries():
149+
print "Bucket %s total counts: [%d, %d]" % (
150+
str(test_num),
151+
ac.pkt_count,
152+
ac.byte_count)
153+
148154
print '**************'
149155
print datetime.now()
150156
print 'Test', test_num, ' -- got a callback from installed path query!'
@@ -155,6 +161,7 @@ def print_predwise_entries():
155161
ac.byte_count += pkt['payload_len']
156162
update_predwise_counts(pkt)
157163
print_predwise_entries()
164+
print_total_entries()
158165
else:
159166
print "Bucket %s (packet, byte) counts: %s" % (
160167
str(test_num), pkt)

pyretic/tests/test_bucket.py

Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ def path_query_tshark_filter_count(t_outfile, filter_fun):
154154
pred = get_key_str(line)
155155
(pkt_count, byte_count) = predwise_count.get(pred, (0, 0))
156156
predwise_count[pred] = (pkt_count + 1, byte_count + bytes_fun(line))
157+
(pkt_count, byte_count) = predwise_count.get('total', (0, 0))
158+
predwise_count['total'] = (pkt_count + 1, byte_count + bytes_fun(line))
157159
return predwise_count
158160

159161
def ctlr_counts(c_outfile, c_name):
@@ -336,17 +338,83 @@ def bucket_write_passfail_info(success_file, tshark_counts, buckets_counts):
336338
passfail.close()
337339

338340
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
341+
""" Write pass/fail information summary for this test. This function takes
342+
the following steps to determine if the output of the path query controller
343+
is acceptable.
344+
1. ensure the query references obtained from tshark & buckets are the same.
345+
For each query reference,
346+
2. is the total packet count the same?
347+
3. is the difference between total byte counts bounded?*
348+
4. is the set of keys generated from tshark & buckets the same?
349+
For each key of each query reference,
350+
5. is the packet count the same?
351+
6. is the difference between byte counts bounded?*
352+
353+
* TODO(ngsrinivas): some packets show a 4 byte increase in payload size when
354+
they come into the packet interpreter. This needs more investigation.
355+
"""
356+
passfail = open(success_file, 'w')
357+
output_str = ''
358+
if set(tshark_counts.keys()) != set(buckets_counts.keys()):
359+
""" Test numbers mismatch. """
360+
output_str += 'FAIL\n'
361+
output_str += 'Query references mismatch:\n'
362+
output_str += 'TShark: %s\n' % str(tshark_counts.keys())
363+
output_str += 'Bucket: %s\n' % str(buckets_counts.keys())
364+
elif True:
365+
""" Per-query-test checks. """
366+
for q in tshark_counts.keys():
367+
tc = tshark_counts[q]
368+
bc = buckets_counts[q]
369+
(tc_total_pkts, tc_total_bytes) = tc['total']
370+
(bc_total_pkts, bc_total_bytes) = bc['total']
371+
if tc_total_pkts != bc_total_pkts:
372+
output_str += 'FAIL\n'
373+
output_str += 'Query: %s\n' % q
374+
output_str += 'Total packet counts mismatch:\n'
375+
output_str += 'TShark: %d\n' % tc_total_pkts
376+
output_str += 'Bucket: %d\n' % bc_total_pkts
377+
break
378+
elif abs(tc_total_bytes-bc_total_bytes) > 4*tc_total_pkts:
379+
output_str += 'FAIL\n'
380+
output_str += 'Query: %s\n' % q
381+
output_str += 'Total byte count mismatch out of bounds:\n'
382+
output_str += 'TShark: %d\n' % tc_total_bytes
383+
output_str += 'Bucket: %d\n' % bc_total_bytes
384+
break
385+
elif set(tc.keys()) != set(bc.keys()):
386+
output_str += 'FAIL\n'
387+
output_str += 'Query: %s\n' % q
388+
output_str += 'Groups of packets counted differ:\n'
389+
output_str += 'TShark:\n%s\n' % ('\n'.join(tc.keys()))
390+
output_str += 'Bucket:\n%s\n' % ('\n'.join(bc.keys()))
391+
break
392+
elif True:
393+
for pred in tc.keys():
394+
""" Check each predicate within each query. """
395+
(tc_pred_pkts, tc_pred_bytes) = tc[pred]
396+
(bc_pred_pkts, bc_pred_bytes) = bc[pred]
397+
if tc_pred_pkts != bc_pred_pkts:
398+
output_str += 'FAIL\n'
399+
output_str += 'Query: %s\n' % q
400+
output_str += 'Predicate pkt counts mismatch:\n'
401+
output_str += 'Predicate: %s\n' % pred
402+
output_str += 'TShark: %d\n' % tc_pred_pkts
403+
output_str += 'Bucket: %d\n' % bc_pred_pkts
404+
break
405+
elif abs(tc_pred_bytes-bc_pred_bytes) > 4*tc_pred_pkts:
406+
output_str += 'FAIL\n'
407+
output_str += 'Query: %s\n' % q
408+
output_str += 'Predicate byte count mismatch out of bounds:\n'
409+
output_str += 'Predicate: %s\n' % pred
410+
output_str += 'TShark: %d\n' % tc_pred_bytes
411+
output_str += 'Bucket: %d\n' % bc_pred_bytes
412+
break
413+
if output_str == '':
414+
output_str += 'PASS\n'
415+
print output_str
416+
passfail.write(output_str)
417+
passfail.close()
350418

351419
### Helpers to extract specific headers from tshark output ###
352420
ints_map = {}

0 commit comments

Comments
 (0)