-
Notifications
You must be signed in to change notification settings - Fork 2
/
not_initial_subflow_data_handover_cdf.py
executable file
·246 lines (210 loc) · 10.6 KB
/
not_initial_subflow_data_handover_cdf.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
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright 2015 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
import argparse
import common as co
import common_graph as cog
import matplotlib
# Do not use any X11 backend
matplotlib.use('Agg')
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
import matplotlib.pyplot as plt
import mptcp
import numpy as np
import os
import tcp
##################################################
## 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="+")
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 ##
##################################################
connections = cog.fetch_valid_data(stat_dir_exp, args)
multiflow_connections, singleflow_connections = cog.get_multiflow_connections(connections)
##################################################
## PLOTTING RESULTS ##
##################################################
INITIAL_SF = 'Additional SFs'
INITIAL_SFS = '2 Initial SFs'
nb_conns = 0
nb_bytes = {co.C2S: 0, co.S2C: 0}
count_handover = 0
count_0 = {co.C2S: 0, co.S2C: 0}
missing_add_addrs = []
missing_rm_addrs = []
no_add_addrs = []
no_rm_addrs = []
results = {co.C2S: {INITIAL_SF: [], INITIAL_SFS: []}, co.S2C: {INITIAL_SF: [], INITIAL_SFS: []}}
for fname, conns in multiflow_connections.iteritems():
for conn_id, conn in conns.iteritems():
# Restrict to connections using at least 2 SFs
take = False
nb_flows = 0
for flow_id, flow in conn.flows.iteritems():
if flow.attr[co.C2S].get(co.BYTES, 0) > 0 or flow.attr[co.S2C].get(co.BYTES, 0) > 0:
nb_flows += 1
if nb_flows >= 2:
take = True
if take:
# Detect now if there is handover
initial_sf_ts = float('inf')
last_acks = []
min_time_last_ack = float('inf')
for flow_id, flow in conn.flows.iteritems():
if co.START not in flow.attr or flow.attr[co.SADDR] == co.IP_PROXY:
continue
if flow.attr[co.START] < initial_sf_ts:
initial_sf_ts = flow.attr[co.START]
flow_bytes = 0
for direction in co.DIRECTIONS:
flow_bytes += flow.attr[direction].get(co.BYTES_DATA, 0)
if flow_bytes > 0 and flow.attr[co.S2C].get(co.TIME_LAST_ACK_TCP, 0.0) > 0.0 and flow.attr[co.S2C].get(co.TIME_FIN_ACK_TCP, 0.0) == 0.0:
last_acks.append(flow.attr[co.S2C][co.TIME_LAST_ACK_TCP])
min_time_last_ack = min(min_time_last_ack, flow.attr[co.S2C][co.TIME_LAST_ACK_TCP])
if initial_sf_ts == float('inf'):
continue
# Now store the delta and record connections with handover
handover_detected = False
min_delta = float('inf')
for flow_id, flow in conn.flows.iteritems():
if handover_detected or co.START not in flow.attr or flow.attr[co.SADDR] == co.IP_PROXY:
continue
delta = flow.attr[co.START] - initial_sf_ts
min_last_acks = float('inf')
if len(last_acks) >= 1:
min_last_acks = min(last_acks)
max_last_payload = 0 - float('inf')
if flow.attr[co.C2S].get(co.BYTES, 0) > 0 or flow.attr[co.S2C].get(co.BYTES, 0) > 0:
if flow.attr[co.S2C].get(co.TIME_LAST_ACK_TCP, 0.0) > min_last_acks:
max_last_payload = max([flow.attr[direction][co.TIME_LAST_PAYLD_TCP] for direction in co.DIRECTIONS])
# handover_delta = flow.attr[co.START] + max_last_payload - min_last_acks
handover_delta = max_last_payload - min_last_acks
if delta > 0.0 and handover_delta > 0.0:
# A subflow is established after the last ack of the client seen --> Handover
count_handover += 1
handover_detected = True
if handover_detected:
conn_bytes_tcp = 0
time_initial_sf = float('inf')
flow_id_initial_sf = None
for flow_id, flow in conn.flows.iteritems():
if flow.attr.get(co.START, float('inf')) < time_initial_sf:
time_initial_sf = flow.attr[co.START]
flow_id_initial_sf = flow_id
count_actual_lost_subflows = 0
for flow_id, flow in conn.flows.iteritems():
if flow.attr.get(co.START, 0.0) > 0.0 and flow.attr.get(co.DURATION, 0.0) > 0.0 and flow.attr[co.S2C].get(co.TIME_FIN_ACK_TCP, 0.0) == 0.0:
# Only if flow is used
if flow.attr[co.C2S].get(co.BYTES, 0) > 0 or flow.attr[co.S2C].get(co.BYTES, 0) > 0:
count_actual_lost_subflows += 1
if len(conn.attr.get(co.ADD_ADDRS, [])) < count_actual_lost_subflows:
missing_add_addrs.append((fname, conn_id))
if len(conn.attr.get(co.RM_ADDRS, [])) < count_actual_lost_subflows:
missing_rm_addrs.append((fname, conn_id))
if len(conn.attr.get(co.ADD_ADDRS, [])) == 0:
no_add_addrs.append((fname, conn_id))
if len(conn.attr.get(co.RM_ADDRS, [])) == 0:
no_rm_addrs.append((fname, conn_id))
if not isinstance(flow_id_initial_sf, int):
continue
# time_second_sf = float('inf')
# flow_id_second_sf = None
# for flow_id, flow in conn.flows.iteritems():
# if not flow_id == flow_id_initial_sf:
# if flow.attr.get(co.START, float('inf')) < time_second_sf:
# time_second_sf = flow.attr[co.START]
# flow_id_second_sf = flow_id
#
# if not isinstance(flow_id_second_sf, int):
# continue
nb_conns += 1
for direction in co.DIRECTIONS:
# First count number of total data bytes
conn_bytes_tcp = 0
for flow_id, flow in conn.flows.iteritems():
conn_bytes_tcp += flow.attr[direction].get(co.BYTES, 0)
if conn_bytes_tcp <= 0:
break
nb_bytes[direction] += conn_bytes_tcp
bytes_not_initial_sf = 0
for flow_id, flow in conn.flows.iteritems():
if not flow_id == flow_id_initial_sf:
bytes_not_initial_sf += conn.flows[flow_id].attr[direction].get(co.BYTES, 0)
# bytes_initial_sfs = bytes_initial_sf + conn.flows[flow_id_second_sf].attr[direction].get(co.BYTES_DATA, 0) + 0.0
results[direction][INITIAL_SF].append((bytes_not_initial_sf + 0.0) / conn_bytes_tcp)
if (bytes_not_initial_sf + 0.0) / conn_bytes_tcp == 0.0:
count_0[direction] += 1
print("LOW", (bytes_not_initial_sf + 0.0) / conn_bytes_tcp, bytes_not_initial_sf, conn_bytes_tcp, fname, conn_id)
# results[direction][INITIAL_SFS].append((bytes_initial_sfs + 0.0) / conn_bytes_tcp)
base_graph_name = 'not_initial_sf_bytes_handover_'
color = {INITIAL_SF: 'red', INITIAL_SFS: 'blue'}
ls = {INITIAL_SFS: '--', INITIAL_SF: '-'}
for direction in co.DIRECTIONS:
plt.figure()
plt.clf()
fig, ax = plt.subplots()
graph_fname = os.path.splitext(base_graph_name)[0] + "cdf_" + direction + ".pdf"
graph_full_path = os.path.join(sums_dir_exp, graph_fname)
for label in [INITIAL_SF]:
sample = np.array(sorted(results[direction][label]))
sorted_array = np.sort(sample)
yvals = np.arange(len(sorted_array)) / float(len(sorted_array))
if len(sorted_array) > 0:
# Add a last point
sorted_array = np.append(sorted_array, sorted_array[-1])
yvals = np.append(yvals, 1.0)
ax.plot(sorted_array, yvals, color=color[label], linestyle=ls[label], linewidth=2, label=label)
# Shrink current axis's height by 10% on the top
# box = ax.get_position()
# ax.set_position([box.x0, box.y0,
# box.width, box.height * 0.9])
# ax.set_xscale('log')
# Put a legend above current axis
# ax.legend(loc='lower center', bbox_to_anchor=(0.5, 1.05), fancybox=True, shadow=True, ncol=ncol)
ax.legend(loc='best')
plt.xlabel('Fraction of total unique bytes', fontsize=24)
plt.ylabel("CDF", fontsize=24)
plt.savefig(graph_full_path)
plt.close('all')
print("NB CONNS: ", nb_conns)
print("NB BYTES: ", nb_bytes)
print("COUNT 0", count_0)
print(count_handover)
print("MISSING ADD ADDRS", missing_add_addrs)
print("MISSING RM ADDRS", missing_rm_addrs)
print("MISSING ADD ADDRS", len(missing_add_addrs))
print("MISSING RM ADDRS", len(missing_rm_addrs))
print("NO ADD ADDRS", len(no_add_addrs))
print("NO RM ADDRS", len(no_rm_addrs))