-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotMessageSequenceChartCalc.py
172 lines (141 loc) · 7.45 KB
/
PlotMessageSequenceChartCalc.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
import datetime
import pandas
import pandas as pd
from dateutil import parser as dp
import cv2
import numpy as np
df = pd.DataFrame(columns=['timestamp', 'type', 'direction', 'source', 'destination', 'id', 'size', 'connection'])
def create_packet(timestamp, type, direction, source, destination, id, size, connection):
entry = dict()
entry["timestamp"] = timestamp.timestamp() * 1000000
entry["type"] = type
entry["direction"] = direction
entry["source"] = source
entry["destination"] = destination
entry["id"] = id
entry["size"] = size
entry["connection"] = connection
return entry
current_id = 0
current_timestamp = datetime.datetime.fromtimestamp(0)
LOCAL = "local"
REMOTE = "remote"
IN = "in"
OUT = "out"
TER_ID = 0
SAT_ID = 1
SOURCE = "192.168.1.1:1111"
DESTINATION = "192.168.1.2:80"
# request
packet = create_packet(current_timestamp, LOCAL, OUT, SOURCE, DESTINATION, 0, 193, SAT_ID)
df = pd.concat([df, pandas.DataFrame.from_records([packet])], ignore_index=True)
current_timestamp += datetime.timedelta(milliseconds=15)
packet = create_packet(current_timestamp, REMOTE, IN, SOURCE, DESTINATION, 0, 193, SAT_ID)
df = pd.concat([df, pandas.DataFrame.from_records([packet])], ignore_index=True)
# send < 74kb
# duration to get 74 kb from server bw=1GBit rtt=1ms: 74us
# average processing delay: 50us
# two packets before switching to SAT
# 0,008192 s
current_timestamp += datetime.timedelta(milliseconds=1)
current_timestamp += datetime.timedelta(microseconds=50)
packet = create_packet(current_timestamp, REMOTE, OUT, SOURCE, DESTINATION, current_id, 1024, TER_ID)
df = pd.concat([df, pandas.DataFrame.from_records([packet])], ignore_index=True)
packet = create_packet(current_timestamp + datetime.timedelta(milliseconds=15), LOCAL, IN, SOURCE, DESTINATION, current_id, 1024, TER_ID)
df = pd.concat([df, pandas.DataFrame.from_records([packet])], ignore_index=True)
current_id += 1
current_timestamp += datetime.timedelta(microseconds=4096)
packet = create_packet(current_timestamp, REMOTE, OUT, SOURCE, DESTINATION, current_id, 1024, TER_ID)
df = pd.concat([df, pandas.DataFrame.from_records([packet])], ignore_index=True)
packet = create_packet(current_timestamp + datetime.timedelta(milliseconds=15), LOCAL, IN, SOURCE, DESTINATION, current_id, 1024, TER_ID)
df = pd.concat([df, pandas.DataFrame.from_records([packet])], ignore_index=True)
current_id += 1
current_timestamp += datetime.timedelta(microseconds=50)
# send 100000 - 2048 = 97952 bytes remaining
# send 97952 bytes SAT = 95,65625 ~ 96 packets
# send 96 packets SAT
# 0,003932 s
# 0,01567232
step_size = 15672 / 96
for i in range(96):
packet = create_packet(current_timestamp, REMOTE, OUT, SOURCE, DESTINATION, current_id, 1024, SAT_ID)
df = pd.concat([df, pandas.DataFrame.from_records([packet])], ignore_index=True)
packet = create_packet(current_timestamp + datetime.timedelta(milliseconds=300), LOCAL, IN, SOURCE, DESTINATION, current_id, 1024, SAT_ID)
df = pd.concat([df, pandas.DataFrame.from_records([packet])], ignore_index=True)
current_id += 1
current_timestamp += datetime.timedelta(microseconds=step_size)
# send 73376 bytes TER
# 72 packets TER
# 0,293504 s
# step_size = 293504 / 72
# for i in range(72):
# packet = create_packet(current_timestamp, REMOTE, OUT, SOURCE, DESTINATION, current_id, 1024, TER_ID)
# df = pd.concat([df, pandas.DataFrame.from_records([packet])], ignore_index=True)
# packet = create_packet(current_timestamp + datetime.timedelta(milliseconds=15), LOCAL, IN, SOURCE, DESTINATION, current_id, 1024, TER_ID)
# df = pd.concat([df, pandas.DataFrame.from_records([packet])], ignore_index=True)
#
# current_id += 1
# current_timestamp += datetime.timedelta(microseconds=step_size)
# close packet
current_timestamp = current_timestamp - datetime.timedelta(microseconds=step_size) + datetime.timedelta(milliseconds=300)
packet = create_packet(current_timestamp, LOCAL, OUT, SOURCE, DESTINATION, 1, 32, TER_ID)
df = pd.concat([df, pandas.DataFrame.from_records([packet])], ignore_index=True)
current_timestamp += datetime.timedelta(milliseconds=15)
packet = create_packet(current_timestamp, REMOTE, IN, SOURCE, DESTINATION, 1, 32, TER_ID)
df = pd.concat([df, pandas.DataFrame.from_records([packet])], ignore_index=True)
packet = create_packet(current_timestamp, REMOTE, OUT, SOURCE, DESTINATION, current_id, 32, TER_ID)
df = pd.concat([df, pandas.DataFrame.from_records([packet])], ignore_index=True)
current_timestamp += datetime.timedelta(milliseconds=15)
packet = create_packet(current_timestamp, LOCAL, IN, SOURCE, DESTINATION, current_id, 32, TER_ID)
df = pd.concat([df, pandas.DataFrame.from_records([packet])], ignore_index=True)
# draw
max_timestamp = df["timestamp"].max()
min_timestamp = df["timestamp"].min()
diff_timestamp = max_timestamp - min_timestamp
IMG_WIDTH = 1250
IMG_HEIGHT = 2000
#us_to_height = IMG_HEIGHT / diff_timestamp
us_to_height = IMG_HEIGHT / 400000
PADDING_LEFT = 250
PADDING_RIGHT = 50
PADDING_TOP = 50
PADDING_BOTTOM = 50
img = np.zeros((IMG_HEIGHT + PADDING_TOP + PADDING_BOTTOM, IMG_WIDTH + PADDING_LEFT + PADDING_RIGHT, 3), np.uint8)
img.fill(255)
# draw timestamps
#step_timestamp = diff_timestamp / 4
step_timestamp = 1200000 / 4
for i in range(5):
cv2.line(img, (PADDING_LEFT - 50, PADDING_TOP + int(i * step_timestamp * us_to_height)), (PADDING_LEFT, PADDING_TOP + int(i * step_timestamp * us_to_height)), (0, 0, 0), 2)
cv2.putText(img, str(int(i * step_timestamp / 1000)) + " ms", (50, PADDING_TOP + int(i * step_timestamp * us_to_height) + 8), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 1, 2)
# draw vertical lines
cv2.line(img, (PADDING_LEFT, PADDING_TOP), (PADDING_LEFT, IMG_HEIGHT + PADDING_TOP), (0, 0, 0), 2)
cv2.line(img, (IMG_WIDTH - 1, PADDING_TOP), (IMG_WIDTH - 1, IMG_HEIGHT + PADDING_TOP), (0, 0, 0), 2)
# draw packet lines
for index, row in df[df["type"] == "local"].iterrows():
if row["connection"] == TER_ID:
packet_arrival = df.where(df.type == "remote").where(df.direction != row['direction']).where(df.id == row["id"]).where(df.connection == TER_ID).where(df.source == row["source"]).where(df.destination == row["destination"]).dropna().reset_index(drop=True)
else:
packet_arrival = df.where(df.type == "remote").where(df.direction != row['direction']).where(df.id == row["id"]).where(df.connection == SAT_ID).where(df.source == row["source"]).where(df.destination == row["destination"]).dropna().reset_index(drop=True)
if packet_arrival.shape[0] != 1:
continue
packet_arrival = packet_arrival.to_dict()
if row["direction"] == "out":
if row["connection"] == TER_ID: # ter packet
color = (255, 0, 0)
else: # sat packet
color = (0, 255, 0)
if row["size"] == 32: # close packet
color = (0, 0, 255)
cv2.arrowedLine(img, (PADDING_LEFT, PADDING_TOP + int((row["timestamp"] - min_timestamp) * us_to_height)), (IMG_WIDTH - 2, PADDING_TOP + int((packet_arrival["timestamp"][0] - min_timestamp) * us_to_height)), color, 2, tipLength=0.01)
else:
if row["connection"] == SAT_ID:
color = (255, 0, 0)
else:
color = (0, 255, 0)
if row["size"] == 32:
color = (0, 0, 255)
cv2.arrowedLine(img, (IMG_WIDTH - 2, PADDING_TOP + int((packet_arrival["timestamp"][0] - min_timestamp) * us_to_height)), (PADDING_LEFT, PADDING_TOP + int((row["timestamp"] - min_timestamp) * us_to_height)), color, 2, tipLength=0.01)
cv2.imshow("Test", img)
cv2.imwrite("test.jpg", img)
cv2.waitKey(0)