-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig_creator.py
More file actions
186 lines (162 loc) · 4.97 KB
/
config_creator.py
File metadata and controls
186 lines (162 loc) · 4.97 KB
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
"""
Script designed for debugging pusposes: building configs, running
single experiments.
"""
import json
import logging
import os
import pprint
import time
import click
from srt_utils.exceptions import SrtUtilsException
from srt_utils.runners import SingleExperimentRunner
logger = logging.getLogger(__name__)
def create_task_config(
obj_type,
obj_config,
runner_type,
runner_config,
sleep_after_start: str=None,
sleep_after_stop: str=None,
stop_order: int=None
):
return {
'obj_type': obj_type,
'obj_config': obj_config,
'runner_type': runner_type,
'runner_config': runner_config,
'sleep_after_start': sleep_after_start,
'sleep_after_stop': sleep_after_stop,
'stop_order': stop_order,
}
def create_experiment_config(config_path: str, resultsdir: str):
if os.path.exists(config_path):
logger.error(
'Specified config path already exists, please restart '
'the script with non-existing one'
)
return
logger.info('Creating experiment config')
LORUNNER_CONFIG = {}
RERUNNER_USEAST_CONFIG = {
'username': 'msharabayko',
'host': '23.96.93.54',
}
RERUNNER_EUNORTH_CONFIG = {
'username': 'msharabayko',
'host': '40.69.89.21',
}
config = {}
config['collect_results_path'] = resultsdir # path to collect experiment results
config['stop_after'] = 40 # time to wait since the last task have been started and then stop the experiment
config['ignore_stop_order'] = True # stop the tasks in a specified order if True, otherwise the reverse order is used
config['tasks'] = {}
# Task 1 - Start tshark on a sender side
TSHARK_SND_CONFIG = {
'path': 'tshark',
'interface': 'eth0',
'port': '4200',
'dirpath': '_results',
}
config['tasks']['1'] = create_task_config(
'tshark',
TSHARK_SND_CONFIG,
'remote-runner',
RERUNNER_USEAST_CONFIG
)
# Task 2 - Start tshark on a receiver side
TSHARK_RCV_CONFIG = {
'path': 'tshark',
'interface': 'eth0',
'port': '4200',
'dirpath': '_results',
}
config['tasks']['2'] = create_task_config(
'tshark',
TSHARK_RCV_CONFIG,
'remote-runner',
RERUNNER_EUNORTH_CONFIG
)
# Task 3 - Start srt-xtransmit application (rcv)
SRT_XTRANSMIT_RCV_CONFIG = {
'type': 'rcv',
'path': '/home/msharabayko/projects/srt/srt-xtransmit/_build/bin/srt-xtransmit',
'port': '4200',
'attrs_values': [
('transtype', 'live'),
('rcvbuf', '1000000000'),
('sndbuf', '1000000000'),
],
'options_values': [
('--msgsize', '1316'),
],
'statsdir': '_results',
'statsfreq': '100'
}
config['tasks']['3']= create_task_config(
'srt-xtransmit',
SRT_XTRANSMIT_RCV_CONFIG,
'remote-runner',
RERUNNER_EUNORTH_CONFIG
)
# Task 4 - Start srt-xtransmit application (snd)
SRT_XTRANSMIT_SND_CONFIG = {
'type': 'snd',
'path': '/home/msharabayko/projects/srt/srt-xtransmit/_build/bin/srt-xtransmit',
'port': '4200',
'host': '40.69.89.21',
'attrs_values': [
('transtype', 'live'),
('rcvbuf', '1000000000'),
('sndbuf', '1000000000'),
],
'options_values': [
('--msgsize', '1316'),
('--sendrate', '15Mbps'),
('--duration', '30'),
],
'statsdir': '_results',
'statsfreq': '100'
}
config['tasks']['4']= create_task_config(
'srt-xtransmit',
SRT_XTRANSMIT_SND_CONFIG,
'remote-runner',
RERUNNER_USEAST_CONFIG
)
# TODO: sort_dicts option - added in Python 3.8
# pp = pprint.PrettyPrinter(indent=2, sort_dicts=False)
pp = pprint.PrettyPrinter(indent=2)
pp.pprint(config)
with open(config_path, "w") as write_file:
json.dump(config, write_file, indent=4)
return config
@click.command()
@click.argument(
'config_path',
type=click.Path()
)
@click.option(
'--resultsdir',
required=True,
help = 'Directory path to store experiment results.'
)
def main(config_path, resultsdir):
logging.basicConfig(
level=logging.INFO,
format='%(asctime)-15s [%(levelname)s] %(message)s',
)
config = create_experiment_config(config_path, resultsdir)
try:
exp_runner = SingleExperimentRunner.from_config(config)
exp_runner.start()
logger.info(f"Sleeping {config['stop_after']}s after experiment start")
time.sleep(config['stop_after'])
exp_runner.stop()
exp_runner.collect_results()
except SrtUtilsException as error:
logger.error(f'Failed to run experiment. Reason: {error}', exc_info=True)
finally:
exp_runner.clean_up()
if __name__ == '__main__':
main()