-
Notifications
You must be signed in to change notification settings - Fork 2
/
summary_imc.py
executable file
·1921 lines (1675 loc) · 104 KB
/
summary_imc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright 2015 Matthieu Baerts & Quentin De Coninck
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
# To install on this machine: matplotlib, numpy
from __future__ import print_function
##################################################
## IMPORTS ##
##################################################
import argparse
import common as co
from math import ceil
import matplotlib
# Do not use any X11 backend
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import mptcp
import numpy as np
import os
import os.path
import pickle
import sys
import tcp
import time
##################################################
## ARGUMENTS ##
##################################################
parser = argparse.ArgumentParser(
description="Summarize stat files generated by analyze")
parser.add_argument("-s",
"--stat", help="directory where the stat files are stored", default=co.DEF_STAT_DIR+'_'+co.DEF_IFACE)
parser.add_argument('-S',
"--sums", help="directory where the summary graphs will be stored", default=co.DEF_SUMS_DIR+'_'+co.DEF_IFACE)
parser.add_argument("-d",
"--dirs", help="list of directories to aggregate", nargs="+")
parser.add_argument("-r",
"--remove", help="if set, remove outliers from dataset", action="store_true")
args = parser.parse_args()
stat_dir_exp = os.path.abspath(os.path.expanduser(args.stat))
sums_dir_exp = os.path.abspath(os.path.expanduser(args.sums))
co.check_directory_exists(sums_dir_exp)
##################################################
## GET THE DATA ##
##################################################
def check_in_list(dirpath, dirs):
""" Check if dirpath is one of the dir in dirs, True if dirs is empty """
if not dirs:
return True
return os.path.basename(dirpath) in dirs
def fetch_data(dir_exp):
co.check_directory_exists(dir_exp)
dico = {}
for dirpath, dirnames, filenames in os.walk(dir_exp):
if check_in_list(dirpath, args.dirs):
for fname in filenames:
try:
stat_file = open(os.path.join(dirpath, fname), 'r')
dico[fname] = pickle.load(stat_file)
stat_file.close()
except IOError as e:
print(str(e) + ': skip stat file ' + fname, file=sys.stderr)
return dico
connections = fetch_data(stat_dir_exp)
def ensures_smartphone_to_proxy():
for fname in connections.keys():
for conn_id in connections[fname].keys():
if isinstance(connections[fname][conn_id], mptcp.MPTCPConnection):
inside = True
for flow_id, flow in connections[fname][conn_id].flows.iteritems():
if not flow.attr[co.DADDR].startswith('172.17.') and not flow.attr[co.DADDR] == co.IP_PROXY:
connections[fname].pop(conn_id, None)
inside = False
break
if inside:
for direction in co.DIRECTIONS:
# This is a fix for wrapping seq num
if connections[fname][conn_id].attr[direction][co.BYTES_MPTCPTRACE] < -1:
connections[fname][conn_id].attr[direction][co.BYTES_MPTCPTRACE] = 2**32 + connections[fname][conn_id].attr[direction][co.BYTES_MPTCPTRACE]
ensures_smartphone_to_proxy()
def get_multiflow_connections(connections):
multiflow_connections = {}
singleflow_connections = {}
for fname, conns_fname in connections.iteritems():
for conn_id, conn in conns_fname.iteritems():
if isinstance(conn, mptcp.MPTCPConnection):
if len(conn.flows) > 1:
if fname not in multiflow_connections:
multiflow_connections[fname] = {}
multiflow_connections[fname][conn_id] = conn
else:
if fname not in singleflow_connections:
singleflow_connections[fname] = {}
singleflow_connections[fname][conn_id] = conn
return multiflow_connections, singleflow_connections
multiflow_connections, singleflow_connections = get_multiflow_connections(connections)
def filter_connections(connections, min_bytes=None, max_bytes=None):
filtered = {}
for fname, data in connections.iteritems():
filtered[fname] = {}
for conn_id, conn in data.iteritems():
if isinstance(conn, mptcp.MPTCPConnection):
mptcp_bytes = conn.attr[co.S2D].get(co.BYTES_MPTCPTRACE, 0) + conn.attr[co.D2S].get(co.BYTES_MPTCPTRACE, 0)
if (min_bytes and mptcp_bytes >= min_bytes) or (max_bytes and mptcp_bytes <= max_bytes):
filtered[fname][conn_id] = conn
return filtered
# connections = filter_connections(connections)
##################################################
## PLOTTING RESULTS ##
##################################################
def fog_plot_with_bytes_wifi_cell_per_condition(log_file=sys.stdout):
data = {co.S2D: {'all': {'Connections': []}}, co.D2S: {'all': {'Connections': []}}}
color = {'Connections': 'orange'}
base_graph_name = "fog_bytes"
for fname, conns in connections.iteritems():
for conn_id, conn in conns.iteritems():
if co.BYTES in conn.attr[co.S2D]:
data[co.S2D]['all']['Connections'].append([conn.attr[co.S2D][co.BYTES].get(co.WIFI, 0), conn.attr[co.S2D][co.BYTES].get(co.CELL, 0)])
if co.BYTES in conn.attr[co.D2S]:
data[co.D2S]['all']['Connections'].append([conn.attr[co.D2S][co.BYTES].get(co.WIFI, 0), conn.attr[co.D2S][co.BYTES].get(co.CELL, 0)])
co.scatter_plot_with_direction(data, "Bytes on Wi-Fi", "Bytes on cellular", color, sums_dir_exp, base_graph_name)
def fog_plot_with_packs_wifi_cell_per_condition(log_file=sys.stdout):
data = {co.S2D: {'all': {'Connections': []}}, co.D2S: {'all': {'Connections': []}}}
color = {'Connections': 'orange'}
base_graph_name = "fog_packs"
for fname, conns in connections.iteritems():
for conn_id, conn in conns.iteritems():
# conn is then a MPTCPConnection, be still better to be sure of
if isinstance(conn, mptcp.MPTCPConnection):
packs = {co.S2D: {co.CELL: 0, co.WIFI: 0, '?': 0}, co.D2S: {co.CELL: 0, co.WIFI: 0, '?': 0}}
for flow_id, flow in conn.flows.iteritems():
if co.S2D not in flow.attr:
continue
if co.PACKS not in flow.attr[co.S2D] or co.PACKS not in flow.attr[co.D2S]:
break
interface = flow.attr[co.IF]
packs[co.S2D][interface] += flow.attr[co.S2D][co.PACKS]
packs[co.D2S][interface] += flow.attr[co.D2S][co.PACKS]
if packs[co.S2D][co.CELL] == 0 and packs[co.S2D][co.WIFI] == 0 and packs[co.D2S][co.CELL] == 0 and packs[co.D2S][co.WIFI] == 0:
continue
data[co.S2D]['all']['Connections'].append([packs[co.S2D][co.WIFI], packs[co.S2D][co.CELL]])
data[co.D2S]['all']['Connections'].append([packs[co.D2S][co.WIFI], packs[co.D2S][co.CELL]])
co.scatter_plot_with_direction(data, "Packets on wifi", "Packets on cellular", color, sums_dir_exp, base_graph_name)
def fog_duration_bytes(log_file=sys.stdout):
data = {'all': {'Connections': []}}
color = {'Connections': 'orange'}
base_graph_name = "fog_duration_bytes"
for fname, conns in connections.iteritems():
for conn_id, conn in conns.iteritems():
if isinstance(conn, tcp.TCPConnection):
duration = conn.flow.attr[co.DURATION]
elif isinstance(conn, mptcp.MPTCPConnection):
duration = conn.attr[co.DURATION]
nb_bytes = 0
if co.BYTES in conn.attr[co.S2D]:
nb_bytes = conn.attr[co.S2D][co.BYTES].get(co.WIFI, 0) + conn.attr[co.S2D][co.BYTES].get(co.CELL, 0) + conn.attr[co.S2D][co.BYTES].get('?', 0)
if co.BYTES in conn.attr[co.D2S]:
nb_bytes += conn.attr[co.D2S][co.BYTES].get(co.WIFI, 0) + conn.attr[co.D2S][co.BYTES].get(co.CELL, 0) + conn.attr[co.D2S][co.BYTES].get('?', 0)
data['all']['Connections'].append([duration, nb_bytes])
co.scatter_plot(data, "Duration [s]", "Bytes on connection", color, sums_dir_exp, base_graph_name, plot_identity=False)
def cdf_duration(log_file=sys.stdout):
data_duration = {'all': {co.DURATION: []}}
color = ['red']
base_graph_name_duration = "summary_cdf_duration"
base_graph_path_duration = os.path.join(sums_dir_exp, base_graph_name_duration)
base_graph_name_duration_hist = "summary_hist_duration"
base_graph_path_duration_hist = os.path.join(sums_dir_exp, base_graph_name_duration_hist)
for fname, conns in connections.iteritems():
for conn_id, conn in conns.iteritems():
if isinstance(conn, tcp.TCPConnection):
duration = conn.flow.attr[co.DURATION]
elif isinstance(conn, mptcp.MPTCPConnection):
duration = conn.attr[co.DURATION]
data_duration['all'][co.DURATION].append(duration)
co.plot_cdfs_natural(data_duration, color, 'Seconds [s]', base_graph_path_duration)
co.plot_cdfs_natural(data_duration, color, 'Seconds [s]', base_graph_path_duration + '_log', xlog=True)
# weights = []
# for dataset_results in data_duration['all'][co.DURATION]:
# weights.append(np.ones_like(dataset_results) / len(data_duration['all'][co.DURATION]))
plt.figure()
plt.hist(data_duration['all'][co.DURATION], bins=np.logspace(-3, 5, 81), log=True)
plt.xlabel("Duration of connections [s]", fontsize=18)
plt.ylabel("Connections", fontsize=18)
plt.gca().set_xscale("log")
plt.savefig(base_graph_path_duration_hist + "_log.pdf")
plt.close()
plt.figure()
plt.hist(data_duration['all'][co.DURATION], bins=np.logspace(-3, 5, 81))
plt.xlabel("Duration of connections [s]", fontsize=18)
plt.ylabel("Connections", fontsize=18)
plt.gca().set_xscale("log")
plt.savefig(base_graph_path_duration_hist + ".pdf")
plt.close()
print("50th percentile", np.percentile(data_duration['all'][co.DURATION], 50), file=log_file)
print("60th percentile", np.percentile(data_duration['all'][co.DURATION], 60), file=log_file)
print("70th percentile", np.percentile(data_duration['all'][co.DURATION], 70), file=log_file)
def cdfs_bytes(log_file=sys.stdout):
data_bytes = {'all': {co.BYTES: []}}
data_bytes_with_dir = {co.S2D: {'all': {co.BYTES: []}}, co.D2S: {'all': {co.BYTES: []}}}
color = ['red']
base_graph_name_bytes = "summary_cdf_bytes"
base_graph_path_bytes = os.path.join(sums_dir_exp, base_graph_name_bytes)
for fname, conns in connections.iteritems():
for conn_id, conn in conns.iteritems():
# An alternative version could be written with the bytes returned by mptcptrace, it would then be
# nb_bytes_s2d = conn.attr[co.S2D][co.BYTES_MPTCPTRACE]
# nb_bytes_d2s = conn.attr[co.D2S][co.BYTES_MPTCPTRACE]
if co.BYTES in conn.attr[co.S2D]:
nb_bytes_s2d = conn.attr[co.S2D][co.BYTES].get(co.WIFI, 0) + conn.attr[co.S2D][co.BYTES].get(co.CELL, 0)
if co.BYTES in conn.attr[co.D2S]:
nb_bytes_d2s = conn.attr[co.D2S][co.BYTES].get(co.WIFI, 0) + conn.attr[co.D2S][co.BYTES].get(co.CELL, 0)
data_bytes['all'][co.BYTES].append(nb_bytes_s2d + nb_bytes_d2s)
data_bytes_with_dir[co.S2D]['all'][co.BYTES].append(nb_bytes_s2d)
data_bytes_with_dir[co.D2S]['all'][co.BYTES].append(nb_bytes_d2s)
co.plot_cdfs_natural(data_bytes, color, 'Bytes', base_graph_path_bytes)
co.plot_cdfs_with_direction(data_bytes_with_dir, color, 'Bytes', base_graph_path_bytes, natural=True)
def cdf_number_subflows(log_file=sys.stdout):
subflows = {'all': {'Subflows': []}}
nb_subflows = {}
color = ['red']
base_graph_name_subflows = "cdf_number_subflows"
base_graph_path_subflows = os.path.join(sums_dir_exp, base_graph_name_subflows)
for fname, conns in connections.iteritems():
for conn_id, conn in conns.iteritems():
# Make sure we have MPTCPConnections, but it should always be the case
if isinstance(conn, mptcp.MPTCPConnection):
subflows['all']['Subflows'].append(len(conn.flows))
if len(conn.flows) not in nb_subflows:
nb_subflows[len(conn.flows)] = 1
else:
nb_subflows[len(conn.flows)] += 1
elif isinstance(conn, tcp.TCPConnection):
print("WARNING: there is a TCPConnection!")
co.plot_cdfs_natural(subflows, color, '# of subflows', base_graph_path_subflows)
print(nb_subflows, file=log_file)
def count_unused_subflows(log_file=sys.stdout):
count = 0
count_total = 0
for fname, conns in connections.iteritems():
for conn_id, conn in conns.iteritems():
# Still make sure it's MPTCPConnections
if isinstance(conn, mptcp.MPTCPConnection):
for flow_id, flow in conn.flows.iteritems():
unused_subflow = True
for direction in co.DIRECTIONS:
# Count data bytes
if flow.attr[direction].get(co.BYTES_DATA, 0) > 0:
unused_subflow = False
count_total += 1
if unused_subflow:
count += 1
count_multiflow = 0
count_unused_multiflow = 0
count_unused_additional = 0
count_unused_best_avg_rtt = 0
count_multiflow_additional = 0
bytes_when_unused = []
duration_when_unused = []
for fname, conns, in multiflow_connections.iteritems():
for conn_id, conn in conns.iteritems():
# Still make sure it's MPTCPConnections
if isinstance(conn, mptcp.MPTCPConnection):
start_time = float('inf')
for flow_id, flow in conn.flows.iteritems():
start_time = min(start_time, flow.attr.get(co.START, float('inf')))
if start_time == float('inf'):
continue
for flow_id, flow in conn.flows.iteritems():
unused_subflow = True
for direction in co.DIRECTIONS:
# Count data bytes
if flow.attr[direction].get(co.BYTES_DATA, 0) > 0:
unused_subflow = False
if unused_subflow:
count_unused_multiflow += 1
count_multiflow += 1
if not start_time == flow.attr.get(co.START, float('inf')):
count_multiflow_additional += 1
if unused_subflow:
count_unused_additional += 1
min_rtt_avg = float('inf')
for fid, fl in conn.flows.iteritems():
if co.RTT_AVG in flow.attr[co.D2S]:
min_rtt_avg = min(min_rtt_avg, fl.attr[co.D2S].get(co.RTT_AVG, float('inf')))
if co.RTT_AVG in flow.attr[co.D2S] and flow.attr[co.D2S][co.RTT_AVG] == min_rtt_avg:
count_unused_best_avg_rtt += 1
bytes_when_unused.append(conn.attr[co.D2S].get(co.BYTES_MPTCPTRACE, 0))
if co.DURATION in conn.attr:
duration_when_unused.append(conn.attr[co.DURATION])
print("Number of unused subflows:", count, file=log_file)
print("Number of total subflows:", count_total, file=log_file)
print("Number of subflows in multiflow connections", count_multiflow, file=log_file)
print("Number of additional subflows in multiflow connections", count_multiflow_additional, file=log_file)
print("Number of unused subflows on multiflow connections", count_unused_multiflow, file=log_file)
print("Number of unused additional subflows on multiflow connections", count_unused_additional, file=log_file)
print("Number of unused additional subflows on multiflow connections with best RTT", count_unused_best_avg_rtt, file=log_file)
print(np.min(bytes_when_unused), np.percentile(bytes_when_unused, 50), np.mean(bytes_when_unused), np.percentile(bytes_when_unused, 75), np.percentile(bytes_when_unused, 90), np.percentile(bytes_when_unused, 95), np.percentile(bytes_when_unused, 96), np.percentile(bytes_when_unused, 97), np.percentile(bytes_when_unused, 98), np.percentile(bytes_when_unused, 99), np.max(bytes_when_unused), file=log_file)
print(np.min(duration_when_unused), np.percentile(duration_when_unused, 50), np.mean(duration_when_unused), np.percentile(duration_when_unused, 75), np.percentile(duration_when_unused, 90), np.percentile(duration_when_unused, 95), np.percentile(duration_when_unused, 96), np.percentile(duration_when_unused, 97), np.percentile(duration_when_unused, 98), np.percentile(duration_when_unused, 99), np.max(duration_when_unused), file=log_file)
def textual_summary(log_file=sys.stdout):
data = {'all': {'<1s': 0, ">=1s<10K": 0, ">=1s>=10K": 0, "<9s": 0, ">=9s<10K": 0, ">=9s>=10K": 0, '<10K': 0, '<1K': 0, '1B': 0, '2B': 0, '>=100s': 0, '<10s': 0, '>=1M': 0}}
count = {'all': {'<1s': 0, ">=1s<10K": 0, ">=1s>=10K": 0, "<9s": 0, ">=9s<10K": 0, ">=9s>=10K": 0, '<10K': 0, '<1K': 0, '1B': 0, '2B': 0, '>=100s': 0, '<10s': 0, '>=1M': 0}}
tot_count = {'all': 0.0}
total_bytes = {'all': {co.S2D: 0, co.D2S: 0}}
for fname, conns in connections.iteritems():
for conn_id, conn in conns.iteritems():
if isinstance(conn, tcp.TCPConnection):
duration = conn.flow.attr[co.DURATION]
elif isinstance(conn, mptcp.MPTCPConnection):
duration = conn.attr[co.DURATION]
nb_bytes_s2d = 0
nb_bytes_d2s = 0
# An alternative version could be written with the bytes returned by mptcptrace, it would then be
nb_bytes_s2d = conn.attr[co.S2D][co.BYTES_MPTCPTRACE]
nb_bytes_d2s = conn.attr[co.D2S][co.BYTES_MPTCPTRACE]
# if co.BYTES in conn.attr[co.S2D]:
# nb_bytes_s2d = conn.attr[co.S2D][co.BYTES].get(co.WIFI, 0) + conn.attr[co.S2D][co.BYTES].get(co.CELL, 0) + conn.attr[co.S2D][co.BYTES].get('?', 0)
# if co.BYTES in conn.attr[co.D2S]:
# nb_bytes_d2s = conn.attr[co.D2S][co.BYTES].get(co.WIFI, 0) + conn.attr[co.D2S][co.BYTES].get(co.CELL, 0) + conn.attr[co.D2S][co.BYTES].get('?', 0)
if duration < 1:
data['all']['<1s'] += nb_bytes_s2d + nb_bytes_d2s
count['all']['<1s'] += 1
else:
if nb_bytes_s2d + nb_bytes_d2s < 10000:
data['all'][">=1s<10K"] += nb_bytes_s2d + nb_bytes_d2s
count['all'][">=1s<10K"] += 1
else:
data['all'][">=1s>=10K"] += nb_bytes_s2d + nb_bytes_d2s
count['all'][">=1s>=10K"] += 1
if duration >= 100.0:
count['all']['>=100s'] += 1
data['all']['>=100s'] += nb_bytes_s2d + nb_bytes_d2s
elif duration < 10.0:
count['all']['<10s'] += 1
data['all']['<10s'] += nb_bytes_s2d + nb_bytes_d2s
if nb_bytes_s2d + nb_bytes_d2s == 2:
count['all']['2B'] += 1
data['all']['2B'] += nb_bytes_s2d + nb_bytes_d2s
elif nb_bytes_s2d + nb_bytes_d2s == 1:
count['all']['1B'] += 1
data['all']['1B'] += nb_bytes_s2d + nb_bytes_d2s
if nb_bytes_s2d + nb_bytes_d2s < 1000:
count['all']['<1K'] += 1
data['all']['<1K'] += nb_bytes_s2d + nb_bytes_d2s
if nb_bytes_s2d + nb_bytes_d2s < 10000:
count['all']['<10K'] += 1
data['all']['<10K'] += nb_bytes_s2d + nb_bytes_d2s
elif nb_bytes_s2d + nb_bytes_d2s >= 1000000:
count['all']['>=1M'] += 1
data['all']['>=1M'] += nb_bytes_s2d + nb_bytes_d2s
if duration < 9:
data['all']["<9s"] += nb_bytes_s2d + nb_bytes_d2s
count['all']["<9s"] += 1
else:
if nb_bytes_s2d + nb_bytes_d2s < 10000:
data['all'][">=9s<10K"] += nb_bytes_s2d + nb_bytes_d2s
count['all'][">=9s<10K"] += 1
else:
data['all'][">=9s>=10K"] += nb_bytes_s2d + nb_bytes_d2s
count['all'][">=9s>=10K"] += 1
tot_count['all'] += 1
total_bytes['all'][co.S2D] += nb_bytes_s2d
total_bytes['all'][co.D2S] += nb_bytes_d2s
for cond, data_cond in data.iteritems():
print(cond + " with " + str(tot_count[cond]) + "connections:", file=log_file)
print("TOTAL BYTES S2D", total_bytes['all'][co.S2D], file=log_file)
print("TOTAL BYTES D2S", total_bytes['all'][co.D2S], file=log_file)
for dur_type, value in data_cond.iteritems():
print(dur_type + " (has " + str(count[cond][dur_type]) + " with " + str(count[cond][dur_type] * 100 / (tot_count[cond] + 0.00001)) + "%): " + str(value) + " bytes (" + str(value * 100 / (total_bytes[cond][co.S2D] + total_bytes[cond][co.D2S] + 0.00001)) + "%)", file=log_file)
def count_ip_type(log_file=sys.stdout):
results = {co.IPv4: [], co.IPv6: []}
for fname, data in connections.iteritems():
for conn_id, conn in data.iteritems():
if isinstance(conn, mptcp.MPTCPConnection):
for flow_id, flow in conn.flows.iteritems():
ip_type = flow.attr[co.TYPE]
if flow.attr[co.SADDR] not in results[ip_type]:
results[ip_type].append(flow.attr[co.SADDR])
print("IPv4", file=log_file)
print(results[co.IPv4], file=log_file)
print("IPv6", file=log_file)
print(results[co.IPv6], file=log_file)
print("IPv4", len(results[co.IPv4]), "IPv6", len(results[co.IPv6]), file=log_file)
def count_packet(log_file=sys.stdout):
count = {co.S2D: 0, co.D2S: 0}
for fname, data in connections.iteritems():
for conn_id, conn in data.iteritems():
if isinstance(conn, mptcp.MPTCPConnection):
for flow_id, flow in conn.flows.iteritems():
for direction in co.DIRECTIONS:
count[direction] += flow.attr[direction].get(co.PACKS, 0)
print("NB PACKETS S2D", count[co.S2D], "NB PACKETS D2S", count[co.D2S], file=log_file)
def count_ports(log_file=sys.stdout):
count = {co.SPORT: {}, co.DPORT: {}}
for fname, data in connections.iteritems():
for conn_id, conn in data.iteritems():
if isinstance(conn, mptcp.MPTCPConnection):
for flow_id, flow in conn.flows.iteritems():
for port in [co.SPORT, co.DPORT]:
if flow.attr[port] in count[port]:
count[port][flow.attr[port]] += 1
else:
count[port][flow.attr[port]] = 1
print("PORT SOURCE", file=log_file)
print(count[co.SPORT], file=log_file)
print("PORT DEST", file=log_file)
print(count[co.DPORT], file=log_file)
def count_ports_mptcp(log_file=sys.stdout):
count_mptcp = {}
for fname, data in connections.iteritems():
for conn_id, conn in data.iteritems():
if isinstance(conn, mptcp.MPTCPConnection):
if conn.flows['0'].attr[co.DPORT] in count_mptcp:
count_mptcp[conn.flows['0'].attr[co.DPORT]] += 1
else:
count_mptcp[conn.flows['0'].attr[co.DPORT]] = 1
print("PORT DEST MPTCP", file=log_file)
print(count_mptcp, file=log_file)
def count_on_filtered(min_bytes=1000000, log_file=sys.stdout):
count_bytes = {co.S2D: 0, co.D2S: 0}
count_packs = {co.S2D: 0, co.D2S: 0}
count_conn = 0
ports = {co.SPORT: {}, co.DPORT: {}}
for fname, data in connections.iteritems():
for conn_id, conn in data.iteritems():
if isinstance(conn, mptcp.MPTCPConnection):
mptcp_bytes = conn.attr[co.S2D].get(co.BYTES_MPTCPTRACE, 0) + conn.attr[co.D2S].get(co.BYTES_MPTCPTRACE, 0)
if mptcp_bytes >= min_bytes:
count_conn += 1
for direction in co.DIRECTIONS:
count_bytes[direction] += conn.attr[direction].get(co.BYTES_MPTCPTRACE, 0)
for flow_id, flow in conn.flows.iteritems():
for port in [co.SPORT, co.DPORT]:
if flow.attr[port] in ports[port]:
ports[port][flow.attr[port]] += 1
else:
ports[port][flow.attr[port]] = 1
for direction in co.DIRECTIONS:
count_packs[direction] += flow.attr[direction].get(co.PACKS, 0)
print("NB CONN FILTERED", count_conn, file=log_file)
print("BYTES S2D FILTERED", count_bytes[co.S2D], "BYTES D2S FILTERED", count_bytes[co.D2S], file=log_file)
print("PACKS S2D FILTERED", count_packs[co.S2D], "PACKS D2S FILTERED", count_packs[co.D2S], file=log_file)
print("PORT SOURCE FILTER", file=log_file)
print(ports[co.SPORT], file=log_file)
print("PORT DEST FILTER", file=log_file)
print(ports[co.DPORT], file=log_file)
def box_plot_cellular_percentage(log_file=sys.stdout, limit_duration=0, limit_bytes=0):
base_graph_name_bytes = "summary_fraction_cellular"
base_graph_path_bytes = os.path.join(sums_dir_exp, base_graph_name_bytes)
fog_base_graph_name_bytes = "fog_cellular"
fog_base_graph_path_bytes = os.path.join(sums_dir_exp, fog_base_graph_name_bytes)
color = {'Connections': 'orange'}
data_bytes = {'all': {}}
data_frac = {'all': {}}
nb_zero = {'all': {}}
bytes_zero = {'all': {}}
nb_one = {'all': {}}
bytes_one = {'all': {}}
tot_conn = {'all': {}}
tot_bytes = {'all': {}}
for cond in data_frac:
data_frac[cond] = {co.S2D: {}, co.D2S: {}}
for cond in data_bytes:
data_bytes[cond] = {co.S2D: {}, co.D2S: {}}
for cond in nb_zero:
nb_zero[cond] = {co.S2D: {}, co.D2S: {}}
for cond in bytes_zero:
bytes_zero[cond] = {co.S2D: {}, co.D2S: {}}
for cond in nb_one:
nb_one[cond] = {co.S2D: {}, co.D2S: {}}
for cond in bytes_one:
bytes_one[cond] = {co.S2D: {}, co.D2S: {}}
for cond in tot_conn:
tot_conn[cond] = {co.S2D: {}, co.D2S: {}}
for cond in tot_bytes:
tot_bytes[cond] = {co.S2D: {}, co.D2S: {}}
for fname, data in connections.iteritems():
app = "Connections"
for conn_id, conn in data.iteritems():
if app not in data_frac['all'][co.S2D]:
for direction in data_frac['all'].keys():
data_frac['all'][direction][app] = []
data_bytes['all'][direction][app] = []
nb_zero['all'][direction][app] = 0
bytes_zero['all'][direction][app] = 0
nb_one['all'][direction][app] = 0
bytes_one['all'][direction][app] = 0
tot_conn['all'][direction][app] = 0
tot_bytes['all'][direction][app] = 0
# Only interested on MPTCP connections
if isinstance(conn, mptcp.MPTCPConnection):
if conn.attr[co.DURATION] < limit_duration:
continue
conn_bytes_s2d = {'cellular': 0, 'wifi': 0, '?': 0}
conn_bytes_d2s = {'cellular': 0, 'wifi': 0, '?': 0}
if co.BYTES in conn.attr[co.S2D]:
for interface in conn.attr[co.S2D][co.BYTES]:
conn_bytes_s2d[interface] += conn.attr[co.S2D][co.BYTES][interface]
if co.BYTES in conn.attr[co.D2S]:
for interface in conn.attr[co.D2S][co.BYTES]:
conn_bytes_d2s[interface] += conn.attr[co.D2S][co.BYTES][interface]
for flow_id, flow in conn.flows.iteritems():
if co.S2D not in flow.attr or co.D2S not in flow.attr or co.REINJ_ORIG_BYTES not in flow.attr[co.S2D] or co.REINJ_ORIG_BYTES not in flow.attr[co.D2S]:
break
interface = flow.attr[co.IF]
conn_bytes_s2d[interface] -= flow.attr[co.S2D][co.REINJ_ORIG_BYTES]
conn_bytes_d2s[interface] -= flow.attr[co.D2S][co.REINJ_ORIG_BYTES]
if conn_bytes_s2d['cellular'] + conn_bytes_s2d['wifi'] > limit_bytes:
frac_cell_s2d = (max(0.0, min(1.0, (conn_bytes_s2d['cellular'] + 0.0) / (conn_bytes_s2d['cellular'] + conn_bytes_s2d['wifi']))))
if frac_cell_s2d == 0:
nb_zero['all'][co.S2D][app] += 1
bytes_zero['all'][co.S2D][app] += conn_bytes_s2d['wifi']
elif frac_cell_s2d == 1:
nb_one['all'][co.S2D][app] += 1
bytes_one['all'][co.S2D][app] += conn_bytes_s2d['cellular']
data_frac['all'][co.S2D][app].append(frac_cell_s2d)
data_bytes['all'][co.S2D][app].append(conn_bytes_s2d['cellular'] + conn_bytes_s2d['wifi'])
tot_conn['all'][co.S2D][app] += 1
tot_bytes['all'][co.S2D][app] += conn_bytes_s2d['cellular'] + conn_bytes_s2d['wifi']
if conn_bytes_d2s['cellular'] + conn_bytes_d2s['wifi'] > limit_bytes:
frac_cell_d2s = max(0.0, min(1.0, ((conn_bytes_d2s['cellular'] + 0.0) / (conn_bytes_d2s['cellular'] + conn_bytes_d2s['wifi']))))
if frac_cell_d2s == 0:
nb_zero['all'][co.D2S][app] += 1
bytes_zero['all'][co.D2S][app] += conn_bytes_d2s['wifi']
elif frac_cell_d2s == 1:
nb_one['all'][co.D2S][app] += 1
bytes_one['all'][co.D2S][app] += conn_bytes_d2s['cellular']
data_frac['all'][co.D2S][app].append(frac_cell_d2s)
data_bytes['all'][co.D2S][app].append(conn_bytes_d2s['cellular'] + conn_bytes_d2s['wifi'])
tot_conn['all'][co.D2S][app] += 1
tot_bytes['all'][co.D2S][app] += conn_bytes_d2s['cellular'] + conn_bytes_d2s['wifi']
data_scatter = {co.S2D: {}, co.D2S: {}}
for condition in data_bytes:
for direction in data_bytes[condition]:
nb_zeros = 0.
bytes_zeros = 0.
nb_ones = 0.
bytes_ones = 0.
total_conn = 0.
total_bytes = 0.
data_scatter[direction][condition] = {}
for app in data_bytes[condition][direction]:
data_scatter[direction][condition][app] = zip(data_bytes[condition][direction][app], data_frac[condition][direction][app])
print(condition, direction, app, "NB ZERO", nb_zero[condition][direction][app], "BYTES ZERO", bytes_zero[condition][direction][app], "NB ONE", nb_one[condition][direction][app], "BYTES ONE", bytes_one[condition][direction][app], file=log_file)
nb_zeros += nb_zero[condition][direction][app]
bytes_zeros += bytes_zero[condition][direction][app]
nb_ones += nb_one[condition][direction][app]
bytes_ones += bytes_one[condition][direction][app]
total_conn += tot_conn[condition][direction][app]
total_bytes += tot_bytes[condition][direction][app]
if total_bytes > 0 and total_bytes > 0:
print("TOTAL:", nb_zeros, "zero conns over", total_conn, nb_zeros / total_conn * 100., "%", bytes_zeros, "zero bytes over", total_bytes, bytes_zeros / total_bytes * 100., "%", nb_ones, "connections full cellular", nb_ones / total_conn * 100., "%", bytes_ones, "bytes cellular", bytes_ones / total_bytes * 100., "%", file=log_file)
co.scatter_plot_with_direction(data_scatter, "Bytes on connection", "Fraction of bytes on cellular", color, sums_dir_exp, fog_base_graph_path_bytes, plot_identity=False, log_scale_y=False, y_to_one=True, label_order=['Dailymotion', 'Drive', 'Dropbox', 'Facebook', 'Firefox', 'Messenger', 'Spotify', 'Youtube'])
for cond, data_cond in data_frac.iteritems():
for direction, data_dir in data_cond.iteritems():
plt.figure()
fig, ax = plt.subplots()
apps = data_dir.keys()
to_plot = []
for app in apps:
for point in data_frac[cond][direction][app]:
to_plot.append(point)
if to_plot:
plt.hist(to_plot, bins=50)
plt.xlabel("Fraction of bytes on cellular", fontsize=18)
plt.ylabel("Number of connections", fontsize=18)
plt.xlim([0.0, 1.0])
plt.savefig(base_graph_path_bytes + "_hist_" + cond + "_" + direction + ".pdf")
plt.close()
for cond, data_cond in data_frac.iteritems():
for direction, data_dir in data_cond.iteritems():
plt.figure()
fig, ax = plt.subplots()
apps = data_dir.keys()
to_plot = []
for app in apps:
to_plot.append(data_frac[cond][direction][app])
if to_plot:
plt.boxplot(to_plot)
plt.xticks(range(1, len(apps) + 1), apps)
plt.tick_params(axis='both', which='major', labelsize=10)
plt.tick_params(axis='both', which='minor', labelsize=8)
plt.ylabel("Fraction of bytes on cellular", fontsize=18)
plt.ylim([0.0, 1.0])
plt.savefig(base_graph_path_bytes + "_" + cond + "_" + direction + ".pdf")
plt.close()
def cdf_bytes_all(log_file=sys.stdout):
base_graph_name_bytes = "cdf_bytes_all"
base_graph_path_bytes = os.path.join(sums_dir_exp, base_graph_name_bytes)
tot_bytes = {'all': {'bytes': []}}
data_frac = {'all': {}}
for cond in data_frac:
data_frac[cond] = {co.S2D: {}, co.D2S: {}}
for fname, data in connections.iteritems():
app = 'all'
for conn_id, conn in data.iteritems():
if app not in data_frac['all'][co.S2D]:
for direction in data_frac['all'].keys():
data_frac['all'][direction][app] = []
# Only interested on MPTCP connections
elif isinstance(conn, mptcp.MPTCPConnection):
conn_bytes_s2d = {'cellular': 0, 'wifi': 0, '?': 0}
conn_bytes_d2s = {'cellular': 0, 'wifi': 0, '?': 0}
if co.BYTES in conn.attr[co.S2D]:
for interface in conn.attr[co.S2D][co.BYTES]:
conn_bytes_s2d[interface] += conn.attr[co.S2D][co.BYTES][interface]
if co.BYTES in conn.attr[co.D2S]:
for interface in conn.attr[co.D2S][co.BYTES]:
conn_bytes_d2s[interface] += conn.attr[co.D2S][co.BYTES][interface]
for flow_id, flow in conn.flows.iteritems():
if co.REINJ_ORIG_BYTES not in flow.attr[co.S2D] or co.REINJ_ORIG_BYTES not in flow.attr[co.D2S]:
break
interface = flow.attr[co.IF]
conn_bytes_s2d[interface] -= flow.attr[co.S2D][co.REINJ_ORIG_BYTES]
conn_bytes_d2s[interface] -= flow.attr[co.D2S][co.REINJ_ORIG_BYTES]
tot_bytes['all']['bytes'].append(conn_bytes_s2d['cellular'] + conn_bytes_s2d['wifi'])
co.plot_cdfs_natural(tot_bytes, ['r'], "Bytes", base_graph_path_bytes)
def cdf_rtt_s2d_all(log_file=sys.stdout, min_samples=5, min_bytes=100):
wifi = "wifi"
cell = "cellular"
aggl_res = {'all': {wifi: [], cell: [], '?': []}}
graph_fname = "rtt_avg_s2d_all.pdf"
graph_full_path = os.path.join(sums_dir_exp, graph_fname)
for fname, data in connections.iteritems():
for conn_id, conn in data.iteritems():
if isinstance(conn, mptcp.MPTCPConnection):
for flow_id, flow in conn.flows.iteritems():
if co.S2D not in flow.attr or co.RTT_SAMPLES not in flow.attr[co.S2D]:
break
if flow.attr[co.S2D][co.RTT_SAMPLES] >= min_samples and flow.attr[co.S2D][co.BYTES] >= min_bytes:
aggl_res['all'][flow.attr[co.IF]] += [(flow.attr[co.S2D][co.RTT_AVG], fname)]
elif isinstance(conn, tcp.TCPConnection):
if co.S2D not in conn.flow.attr or co.RTT_SAMPLES not in conn.flow.attr[co.S2D]:
break
if conn.flow.attr[co.S2D][co.RTT_SAMPLES] >= min_samples and conn.flow.attr[co.S2D][co.BYTES] >= min_bytes:
aggl_res['all'][conn.flow.attr[co.IF]] += [(conn.flow.attr[co.S2D][co.RTT_AVG], fname)]
aggl_res['all'].pop('?', None)
co.log_outliers(aggl_res, remove=args.remove)
co.plot_cdfs_natural(aggl_res, ['red', 'blue', 'green', 'black'], 'RTT (ms)', graph_full_path)
co.plot_cdfs_natural(aggl_res, ['red', 'blue', 'green', 'black'], 'RTT (ms)', os.path.splitext(graph_full_path)[0] + '_cut.pdf', xlim=1000)
def cdf_rtt_d2s_all(log_file=sys.stdout, min_samples=5):
wifi = "wifi"
cell = "cellular"
aggl_res = {'all': {wifi: [], cell: [], '?': []}}
graph_fname = "rtt_avg_d2s_all.pdf"
graph_full_path = os.path.join(sums_dir_exp, graph_fname)
for fname, data in connections.iteritems():
for conn_id, conn in data.iteritems():
if isinstance(conn, mptcp.MPTCPConnection):
for flow_id, flow in conn.flows.iteritems():
if co.D2S not in flow.attr or co.RTT_SAMPLES not in flow.attr[co.D2S]:
break
if flow.attr[co.D2S][co.RTT_SAMPLES] >= min_samples:
aggl_res['all'][flow.attr[co.IF]] += [(flow.attr[co.D2S][co.RTT_AVG], fname)]
elif isinstance(conn, tcp.TCPConnection):
if co.D2S not in conn.flow.attr or co.RTT_SAMPLES not in conn.flow.attr[co.D2S]:
break
if conn.flow.attr[co.D2S][co.RTT_SAMPLES] >= min_samples:
aggl_res['all'][conn.flow.attr[co.IF]] += [(conn.flow.attr[co.D2S][co.RTT_AVG], fname)]
aggl_res['all'].pop('?', None)
co.log_outliers(aggl_res, remove=args.remove)
co.plot_cdfs_natural(aggl_res, ['red', 'blue', 'green', 'black'], 'RTT (ms)', os.path.splitext(graph_full_path)[0] + '.pdf')
co.plot_cdfs_natural(aggl_res, ['red', 'blue', 'green', 'black'], 'RTT (ms)', os.path.splitext(graph_full_path)[0] + '_cut.pdf', xlim=1000)
def difference_rtt_d2s(log_file=sys.stdout, min_bytes=1000000):
# Computed only on MPTCP connections with 2 subflows and at least 1MB
results = {'two_sf': {'diff': []}}
graph_fname = "rtt_avg_diff_2sf.pdf"
graph_full_path = os.path.join(sums_dir_exp, graph_fname)
for fname, data in connections.iteritems():
for conn_id, conn in data.iteritems():
if isinstance(conn, mptcp.MPTCPConnection):
if len(conn.flows) == 2:
if conn.attr[co.D2S].get(co.BYTES_MPTCPTRACE, 0) >= min_bytes:
is_ok = True
for flow_id, flow in conn.flows.iteritems():
if co.START not in flow.attr:
is_ok = False
if not is_ok:
continue
time_init_sf = float('inf')
rtt_init_sf = -1.0
rtt_second_sf = -1.0
for flow_id, flow in conn.flows.iteritems():
if flow.attr[co.START] < time_init_sf:
time_init_sf = flow.attr[co.START]
rtt_second_sf = rtt_init_sf
rtt_init_sf = flow.attr[co.D2S][co.RTT_AVG]
else:
rtt_second_sf = flow.attr[co.D2S][co.RTT_AVG]
results['two_sf']['diff'].append(rtt_init_sf - rtt_second_sf)
co.plot_cdfs_natural(results, ['red', 'blue', 'green', 'black'], 'Initial SF AVG RTT - Second SF AVG RTT', os.path.splitext(graph_full_path)[0] + '.pdf')
def reinject_plot(log_file=sys.stdout, min_bytes=0.0):
base_graph_fname = "reinject_bytes"
base_graph_full_path = os.path.join(sums_dir_exp, base_graph_fname)
results = {co.S2D: {'all': {'all': []}}, co.D2S: {'all': {'all': []}}}
results_packs = {co.S2D: {'all': {'all': []}}, co.D2S: {'all': {'all': []}}}
for fname, data in multiflow_connections.iteritems():
for conn_id, conn in data.iteritems():
reinject_bytes_s2d = 0.0
reinject_bytes_d2s = 0.0
reinject_packs_s2d = 0.0
reinject_packs_d2s = 0.0
bytes_s2d = 0.0
bytes_d2s = 0.0
packs_s2d = 0.0
packs_d2s = 0.0
for flow_id, flow in conn.flows.iteritems():
if co.S2D in flow.attr and co.D2S in flow.attr:
if co.REINJ_ORIG_BYTES in flow.attr[co.S2D] and co.REINJ_ORIG_BYTES in flow.attr[co.D2S]:
if co.BYTES in flow.attr[co.S2D]:
bytes_s2d += flow.attr[co.S2D][co.BYTES]
else:
continue
if co.BYTES in flow.attr[co.D2S]:
bytes_d2s += flow.attr[co.D2S][co.BYTES]
else:
continue
reinject_bytes_s2d += flow.attr[co.S2D][co.REINJ_ORIG_BYTES]
reinject_bytes_d2s += flow.attr[co.D2S][co.REINJ_ORIG_BYTES]
reinject_packs_s2d += flow.attr[co.S2D][co.REINJ_ORIG_PACKS]
reinject_packs_d2s += flow.attr[co.D2S][co.REINJ_ORIG_PACKS]
packs_s2d += flow.attr[co.S2D][co.PACKS]
packs_d2s += flow.attr[co.D2S][co.PACKS]
if bytes_s2d > min_bytes and packs_s2d > 0:
results[co.S2D]['all']['all'].append(reinject_bytes_s2d / bytes_s2d)
results_packs[co.S2D]['all']['all'].append(reinject_packs_s2d / packs_s2d)
if bytes_d2s > min_bytes and packs_d2s > 0:
if (reinject_bytes_d2s / bytes_d2s) >= 0.5:
print("reinj: " + str(reinject_bytes_d2s) + " tot: " + str(bytes_d2s) + " " + fname + " " + conn_id)
results[co.D2S]['all']['all'].append(reinject_bytes_d2s / bytes_d2s)
results_packs[co.D2S]['all']['all'].append(reinject_packs_d2s / packs_d2s)
for direction in results:
for condition in results[direction]:
plt.figure()
fig, ax = plt.subplots()
apps = results[direction][condition].keys()
to_plot = []
for app in apps:
to_plot.append(results[direction][condition][app])
if to_plot:
plt.boxplot(to_plot)
plt.xticks(range(1, len(apps) + 1), apps)
plt.tick_params(axis='both', which='major', labelsize=10)
plt.tick_params(axis='both', which='minor', labelsize=8)
plt.ylabel("Fraction of bytes reinjected", fontsize=18)
plt.savefig(base_graph_full_path + "_" + condition + "_" + direction + ".pdf")
plt.close()
packs_base_graph_fname = "reinject_packs"
packs_base_graph_full_path = os.path.join(sums_dir_exp, packs_base_graph_fname)
plt.figure()
fig, ax = plt.subplots()
apps = results_packs[direction][condition].keys()
to_plot = []
for app in apps:
to_plot.append(results_packs[direction][condition][app])
if to_plot:
plt.boxplot(to_plot)
plt.xticks(range(1, len(apps) + 1), apps)
plt.tick_params(axis='both', which='major', labelsize=10)
plt.tick_params(axis='both', which='minor', labelsize=8)
plt.ylabel("Fraction of packs reinjected", fontsize=18)
plt.savefig(packs_base_graph_full_path + "_" + condition + "_" + direction + ".pdf")
plt.close()
def retrans_plot(log_file=sys.stdout, min_bytes=0.0):
base_graph_fname = "retrans_bytes"
base_graph_full_path = os.path.join(sums_dir_exp, base_graph_fname)
results = {co.S2D: {'all': {'all': []}}, co.D2S: {'all': {'all': []}}}
results_packs = {co.S2D: {'all': {'all': []}}, co.D2S: {'all': {'all': []}}}
for fname, data in singleflow_connections.iteritems():
for conn_id, conn in data.iteritems():
bytes_retrans_s2d = 0.0
bytes_retrans_d2s = 0.0
packs_retrans_s2d = 0.0
packs_retrans_d2s = 0.0
bytes_s2d = 0.0
bytes_d2s = 0.0
packs_s2d = 0.0
packs_d2s = 0.0
for flow_id, flow in conn.flows.iteritems():
if co.S2D in flow.attr and co.D2S in flow.attr:
if co.BYTES_RETRANS in flow.attr[co.S2D] and co.BYTES_RETRANS in flow.attr[co.D2S]:
if co.BYTES in flow.attr[co.S2D]:
bytes_s2d += flow.attr[co.S2D][co.BYTES]
else:
continue
if co.BYTES in flow.attr[co.D2S]:
bytes_d2s += flow.attr[co.D2S][co.BYTES]
else:
continue
bytes_retrans_d2s += flow.attr[co.D2S][co.BYTES_RETRANS]
bytes_retrans_s2d += flow.attr[co.S2D][co.BYTES_RETRANS]
packs_retrans_s2d += flow.attr[co.S2D][co.PACKS_RETRANS]
packs_retrans_d2s += flow.attr[co.D2S][co.PACKS_RETRANS]
packs_s2d += flow.attr[co.S2D][co.PACKS]
packs_d2s += flow.attr[co.D2S][co.PACKS]
if bytes_s2d > min_bytes and packs_s2d > 0:
results[co.S2D]['all']['all'].append(bytes_retrans_s2d / bytes_s2d)
results_packs[co.S2D]['all']['all'].append(bytes_retrans_s2d / packs_s2d)
if bytes_d2s > min_bytes and packs_d2s > 0:
if (bytes_retrans_d2s / bytes_d2s) >= 0.5:
print("retrans: " + str(bytes_retrans_d2s) + " tot: " + str(bytes_d2s) + " " + fname + " " + conn_id)
results[co.D2S]['all']['all'].append(bytes_retrans_d2s / bytes_d2s)
results_packs[co.D2S]['all']['all'].append(bytes_retrans_d2s / packs_d2s)
for direction in results:
for condition in results[direction]:
plt.figure()
fig, ax = plt.subplots()
apps = results[direction][condition].keys()
to_plot = []
for app in apps:
to_plot.append(results[direction][condition][app])
if to_plot:
plt.boxplot(to_plot)
plt.xticks(range(1, len(apps) + 1), apps)
plt.tick_params(axis='both', which='major', labelsize=10)
plt.tick_params(axis='both', which='minor', labelsize=8)
plt.ylabel("Fraction of bytes retransmitted", fontsize=18)
plt.savefig(base_graph_full_path + "_" + condition + "_" + direction + ".pdf")
plt.close()
packs_base_graph_fname = "retrans_packs"
packs_base_graph_full_path = os.path.join(sums_dir_exp, packs_base_graph_fname)
plt.figure()
fig, ax = plt.subplots()
apps = results_packs[direction][condition].keys()
to_plot = []
for app in apps:
to_plot.append(results_packs[direction][condition][app])
if to_plot:
plt.boxplot(to_plot)
plt.xticks(range(1, len(apps) + 1), apps)
plt.tick_params(axis='both', which='major', labelsize=10)
plt.tick_params(axis='both', which='minor', labelsize=8)
plt.ylabel("Fraction of packs retransmitted", fontsize=18)
plt.savefig(packs_base_graph_full_path + "_" + condition + "_" + direction + ".pdf")
plt.close()
def reinject_plot_relative_to_data(log_file=sys.stdout, min_bytes=0.0):
base_graph_fname = "reinject_data_bytes"
base_graph_full_path = os.path.join(sums_dir_exp, base_graph_fname)
results = {co.S2D: {'all': {'all': []}}, co.D2S: {'all': {'all': []}}}
for fname, data in multiflow_connections.iteritems():
for conn_id, conn in data.iteritems():
if co.S2D not in conn.attr or co.D2S not in conn.attr:
continue
reinject_bytes_s2d = 0.0
reinject_bytes_d2s = 0.0
bytes_s2d = 0.0