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

Commit 9b0363a

Browse files
committed
w.i.p.: automated fine-grained count checking for path queries
1 parent a90ea18 commit 9b0363a

File tree

1 file changed

+70
-16
lines changed

1 file changed

+70
-16
lines changed

pyretic/tests/test_bucket.py

Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,20 @@ def capture_packets(t_out, t_err, ints_list, capture_dir):
9090
def workload(net, hosts):
9191
net.pingAll()
9292

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 = {}
95103
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))])
97107
return tshark_counts
98108

99109
def tshark_filter_count(t_outfile, filter_fun):
@@ -112,18 +122,48 @@ def tshark_filter_count(t_outfile, filter_fun):
112122
byte_count += bytes_fun(line)
113123
return (pkt_count, byte_count)
114124

115-
def ctlr_counts(c_outfile):
125+
def ctlr_counts(c_outfile, c_name):
116126
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):
117145
buckets_counts = {}
118146
bucket_p = re.compile("Bucket [0-9a-zA-Z._]+ \(packet, byte\) counts: \[[0-9]+, [0-9]+\]")
119147
for line in c_out:
120148
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))
125151
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
127167

128168
def test_bucket_single_test():
129169
""" Main function for a single test case. """
@@ -177,10 +217,10 @@ def test_bucket_single_test():
177217

178218
""" Verify results """
179219
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)
182222
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)
184224

185225
#### Helper functions #####
186226

@@ -234,10 +274,18 @@ def close_fds(fds, fd_str):
234274
fd.close()
235275
print "Closed", fd_str, "file descriptors"
236276

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):
238286
passfail = open(success_file, 'w')
239287
output_str = ''
240-
if tshark_counts == buckets_counts:
288+
if set(tshark_counts.values()) == set(buckets_counts.values()):
241289
output_str += "PASS\n"
242290
else:
243291
output_str += "FAIL\n"
@@ -247,8 +295,12 @@ def write_passfail_info(success_file, tshark_counts, buckets_counts):
247295
passfail.write(output_str)
248296
passfail.close()
249297

298+
def path_query_write_passfail_info():
299+
pass
300+
250301
### Helpers to extract specific headers from tshark output ###
251302
ints_map = {}
303+
rev_ints_map = {}
252304

253305
def __get_frame_len(line):
254306
return line.split(',')[0]
@@ -354,15 +406,17 @@ def filt_path_test_0_5(l):
354406

355407
### Interfaces map for packet capture ###
356408
def map_any():
357-
global ints_map
409+
global ints_map, rev_ints_map
358410
ints_map = {'any': 0}
411+
rev_ints_map = {0: 'any'}
359412
return ["any"]
360413

361414
def map_chain_3_3():
362-
global ints_map
415+
global ints_map, rev_ints_map
363416
ints_list = ["s1-eth1", "s1-eth2", "s2-eth1", "s2-eth2",
364417
"s2-eth3", "s3-eth1", "s3-eth2"]
365418
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))}
366420
return ints_list
367421

368422
### The main thread.

0 commit comments

Comments
 (0)