howto.rst 9.03 KB
Newer Older
Antoine Kaufmann's avatar
Antoine Kaufmann committed
1
..
Antoine Kaufmann's avatar
Antoine Kaufmann committed
2
  Copyright 2022 Max Planck Institute for Software Systems, and
Antoine Kaufmann's avatar
Antoine Kaufmann committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  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.

24
25
.. _sec-howto:

26
###################################
Antoine Kaufmann's avatar
Antoine Kaufmann committed
27
How To
28
29
30
###################################


31
32
.. _sec-howto-createrun:

33
******************************
Antoine Kaufmann's avatar
Antoine Kaufmann committed
34
Create and Run an Experiment
35
36
******************************

37
38
39
40
41
42
43
44
45
46
47
48
49
Experiments are defined in a declarative fashion inside Python modules using
classes. Basically, create a `.py` file and add a global variable
``experiments``, a list which contains multiple instances of the class
:class:`simbricks.orchestration.experiments.Experiment`, each one describing a
standalone experiment. This is very helpful if you wish to evaluate your work in
different environments, for example, you may want to swap out some simulator or
investigate multiple topologies with different scale.

The class :class:`~simbricks.orchestration.experiments.Experiment` provides
methods to add the simulators you wish to run. All available simulators can be
found in the module :mod:`simbricks.orchestration.simulators`. Instantiating
:class:`~simbricks.orchestration.simulators.HostSim` requires you to specify a
:class:`~simbricks.orchestration.nodeconfig.NodeConfig`, which contains the
50
51
configuration for your host, for example, its networking settings, how much
system memory it should have, and most importantly, which applications to run by
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
assigning an :class:`~simbricks.orchestration.nodeconfig.AppConfig`. You can
find predefined classes for node and app configs in the module
:mod:`simbricks.orchestration.nodeconfig`, feel free to add new ones or just
create a new class locally in your experiment's module.

The last step to complete your virtual testbed is to specify which virtual
components connect to each other. You do this by invoking the respective methods
on the simulators you have instantiated. See the different simulator types' base
classes in the module :mod:`~simbricks.orchestration.simulators` for more
information. A simple and complete experiment module in which a client host
pings a server can be found :ref:`below <simple_ping_experiment>`.

If you plan to simulate a topology with multiple hosts, it may be helpful to
take a look at the module :mod:`simbricks.orchestration.simulator_utils` in
which we provide some helper functions to reduce the amount of code you have to
write.

Finally, to run your experiment invoke ``/experiments/run.py`` and provide the
path to your experiment module. In our docker containers, you can just use the
following command from anywhere:
72
73
74
75
76

.. code-block:: bash

  $ simbricks-run --verbose --force <path_to_your_module.py>

77
78
79
``--verbose`` prints all simulators' output to the terminal and ``--force``
forces execution even if there already exist result files for the same
experiment. If ``simbricks-run`` is not available, you can always do 
80
81
82
83
84
85
86

.. code-block:: bash
  
  # from the repository's root directory
  $ cd experiments
  $ python run.py --verbose --force <path_to_your_module.py>

87
88
89
90
While running, you can interrupt the experiment using CTRL+C in your terminal.
This will cleanly stop all simulators and collect their output in a JSON file in
the directory ``experiments/out/<experiment_name>``. These are the necessary
basics to create and run your first experiment. Have fun.
91
92
93
94
95
96

.. literalinclude:: /../experiments/pyexps/simple_ping.py
  :linenos:
  :lines: 25-
  :language: python
  :name: simple_ping_experiment
97
98
99
100
  :caption: A simple experiment with a client host pinging a server, both are
    connected through a network switch. The setup of the two hosts could be
    simplified by using
    :func:`~simbricks.orchestration.simulator_utils.create_basic_hosts`.
101
102
103

.. _sec-howto-nodeconfig:

Antoine Kaufmann's avatar
Antoine Kaufmann committed
104
105
106
********************************
Add a Node or Application Config
********************************
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
The classes :class:`~simbricks.orchestration.nodeconfig.NodeConfig` and
:class:`~simbricks.orchestration.nodeconfig.AppConfig` are used to define the
configuration of the individual host simulators or, more generally, nodes that
should run in your experiment.
:class:`~simbricks.orchestration.nodeconfig.NodeConfig` defines, for example,
the networking configuration like IP address and subnet mask, how much system
memory the node has, and which disk image to run. The latter can be used to, for
example, run a specific version of the Linux kernel on a node. You can find more
information on that in the :ref:`next section <sec-howto-custom_image>`. There
is also an attribute to assign an instance of the class
:class:`~simbricks.orchestration.nodeconfig.AppConfig`, which defines the
concrete application to execute on the node.

You can find predefined classes in the module
:mod:`simbricks.orchestration.nodeconfig`, however, if they don't fit your
use-case, you can easily create your own class. The typical use-case is that you
want to use a pre-defined node configuration but run your own application. The
easiest way is to create a class for that directly in your experiment module,
which inherits from :class:`~simbricks.orchestration.nodeconfig.AppConfig` and
overrides the methods of interest, most notably
:meth:`~simbricks.orchestration.nodeconfig.AppConfig.run_cmds`, which defines
the command to execute for your application. For further information take a look
at the module :mod:`simbricks.orchestration.nodeconfig`.

.. _sec-howto-custom_image:

134
******************************
Antoine Kaufmann's avatar
Antoine Kaufmann committed
135
Add a Custom Image
136
137
138
******************************

******************************
Antoine Kaufmann's avatar
Antoine Kaufmann committed
139
Integrate a New Simulator
140
141
******************************

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
The first step when integrating a new simulator into SimBricks is to implement a
SimBricks adapter for it. You can find the necessary information in the
:ref:`Simulator Adapters <Simulator Adapters>` section. After that, we need to
add a class for the simulator in the SimBricks orchestration framework such that
it can be used when defining experiments. This class basically wraps a command
for launching the simulator and needs to inherit from
:class:`~simbricks.orchestration.simulators.Simulator` and implement relevant
methods. There are several more specialized child classes in the module
:mod:`simbricks.orchestration.simulators` for typical categories of simulators,
which already offer the interfaces to collect parameters like which other
simulators to connect to necessary for creating the launch command. Examples are
:class:`~simbricks.orchestration.simulators.PCIDevSim`,
:class:`~simbricks.orchestration.simulators.NICSim`,
:class:`~simbricks.orchestration.simulators.NetSim`, and
:class:`~simbricks.orchestration.simulators.HostSim`. You can find an example
below of adding a class for the ``NS3`` network simulator.
158

Jonas Kaufmann's avatar
Jonas Kaufmann committed
159
.. code-block:: python
160
  :linenos:
161
162
  :caption: Class implementing the ``NS3`` network simulator in the SimBricks
    orchestration framework.
Jonas Kaufmann's avatar
Jonas Kaufmann committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

  class NS3BridgeNet(NetSim):

    def run_cmd(self, env):
        ports = ''
        for (_, n) in self.connect_sockets(env):
            ports += '--CosimPort=' + n + ' '

        cmd = (
            f'{env.repodir}/sims/external/ns-3'
            f'/cosim-run.sh cosim cosim-bridge-example {ports} {self.opt}'
        )
        print(cmd)

        return cmd
178
179


180
******************************
Antoine Kaufmann's avatar
Antoine Kaufmann committed
181
Add a New Interface
182
******************************
183
184
185
186
187
188

.. autoclass:: simbricks.orchestration.experiments.Experiment
  :members: add_host, add_pcidev, add_nic, add_network

.. automodule:: simbricks.orchestration.simulators

Jonas Kaufmann's avatar
Jonas Kaufmann committed
189
190
191
  .. autoclass:: simbricks.orchestration.simulators.Simulator
    :members: resreq_cores, resreq_mem, prep_cmds, run_cmd, dependencies

192
193
194
195
196
197
198
199
200
  .. autoclass:: simbricks.orchestration.simulators.HostSim
    :members: add_pcidev, add_nic, add_netdirect

  .. autoclass:: simbricks.orchestration.simulators.NICSim
    :members: set_network

  .. autoclass:: simbricks.orchestration.simulators.NetSim
    :members: connect_network

Jonas Kaufmann's avatar
Jonas Kaufmann committed
201
202
  .. autoclass:: simbricks.orchestration.simulators.PCIDevSim

203
204
205
206
207
208
209
210
211
212
213

.. automodule:: simbricks.orchestration.nodeconfig

  .. autoclass:: simbricks.orchestration.nodeconfig.NodeConfig
    :members:
    
  .. autoclass:: simbricks.orchestration.nodeconfig.AppConfig
    :members:

.. automodule:: simbricks.orchestration.simulator_utils
  :members: