-
Notifications
You must be signed in to change notification settings - Fork 19
/
simulator_utils.py
213 lines (175 loc) · 5.74 KB
/
simulator_utils.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
# Copyright 2021 Max Planck Institute for Software Systems, and
# National University of Singapore
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""Provides helper functions for assembling multiple host simulators."""
import typing as tp
from simbricks.orchestration.experiments import Experiment
from simbricks.orchestration.nodeconfig import AppConfig, NodeConfig
from simbricks.orchestration.simulators import (
HostSim, I40eMultiNIC, NetSim, NICSim
)
def create_basic_hosts(
e: Experiment,
num: int,
name_prefix: str,
net: NetSim,
nic_class: tp.Type[NICSim],
host_class: tp.Type[HostSim],
nc_class: tp.Type[NodeConfig],
app_class: tp.Type[AppConfig],
ip_start: int = 1,
ip_prefix: int = 24
) -> tp.List[HostSim]:
"""
Creates and configures multiple hosts to be simulated using the given
parameters.
Args:
num: number of hosts to create
"""
hosts: tp.List[HostSim] = []
for i in range(0, num):
nic = nic_class()
#nic.name = '%s.%d' % (name_prefix, i)
nic.set_network(net)
node_config = nc_class()
node_config.prefix = ip_prefix
ip = ip_start + i
node_config.ip = f'10.0.{int(ip / 256)}.{ip % 256}'
node_config.app = app_class()
host = host_class(node_config)
host.name = f'{name_prefix}.{i}'
host.add_nic(nic)
e.add_nic(nic)
e.add_host(host)
hosts.append(host)
return hosts
def create_multinic_hosts(
e: Experiment,
num: int,
name_prefix: str,
net: NetSim,
host_class: tp.Type[HostSim],
nc_class: tp.Type[NodeConfig],
app_class: tp.Type[AppConfig],
ip_start: int = 1,
ip_prefix: int = 24
) -> tp.List[HostSim]:
"""
Creates and configures multiple hosts to be simulated using the given
parameters. These hosts use multiple NICs.
Args:
num: number of hosts to create
"""
hosts: tp.List[HostSim] = []
mn = I40eMultiNIC()
mn.name = name_prefix
e.add_nic(mn)
for i in range(0, num):
nic = mn.create_subnic()
#nic.name = '%s.%d' % (name_prefix, i)
nic.set_network(net)
node_config = nc_class()
node_config.prefix = ip_prefix
ip = ip_start + i
node_config.ip = f'10.0.{int(ip / 256)}.{ip % 256}'
node_config.app = app_class()
host = host_class(node_config)
host.name = f'{name_prefix}.{i}'
host.add_nic(nic)
e.add_host(host)
hosts.append(host)
return hosts
def create_dctcp_hosts(
e: Experiment,
num: int,
name_prefix: str,
net: NetSim,
nic_class: tp.Type[NICSim],
host_class: tp.Type[HostSim],
nc_class: tp.Type[NodeConfig],
app_class: tp.Type[AppConfig],
cpu_freq: str,
mtu: int,
ip_start: int = 1
) -> tp.List[HostSim]:
"""
Creates and configures multiple hosts to be simulated in a DCTCP experiment
using the given parameters.
Args:
num: number of hosts to create
cpu_freq: CPU frequency to simulate, e.g. '5GHz'
"""
hosts = []
for i in range(0, num):
nic = nic_class()
#nic.name = '%s.%d' % (name_prefix, i)
nic.set_network(net)
node_config = nc_class()
node_config.mtu = mtu
node_config.ip = f'192.168.64.{ip_start + i}'
node_config.app = app_class()
host = host_class(node_config)
host.name = f'{name_prefix}.{i}'
host.cpu_freq = cpu_freq
host.add_nic(nic)
e.add_nic(nic)
e.add_host(host)
hosts.append(host)
return hosts
def create_tcp_cong_hosts(
e: Experiment,
num: int,
name_prefix: str,
net: NetSim,
nic_class: tp.Type[NICSim],
host_class: tp.Union[tp.Type[HostSim], tp.Callable[[NodeConfig], HostSim]],
nc_class: tp.Type[NodeConfig],
app_class: tp.Type[AppConfig],
cpu_freq: str,
mtu: int,
congestion_control: str,
ip_start: int = 1
):
"""
Creates and configures multiple hosts to be simulated in a TCP congestion
control experiment using the given parameters.
Args:
num: number of hosts to create
cpu_freq: CPU frequency to simulate, e.g. '5GHz'
"""
hosts = []
for i in range(0, num):
nic = nic_class()
#nic.name = '%s.%d' % (name_prefix, i)
nic.set_network(net)
node_config = nc_class()
node_config.mtu = mtu
node_config.tcp_congestion_control = congestion_control
node_config.ip = f'192.168.64.{ip_start + i}'
node_config.app = app_class()
host = host_class(node_config)
host.name = f'{name_prefix}.{i}'
host.cpu_freq = cpu_freq
host.add_nic(nic)
e.add_nic(nic)
e.add_host(host)
hosts.append(host)
return hosts