Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d175a9531516be93cce7f97fc812f8d4990c1798
[simgrid.git] / docs / source / Models.rst
1 .. _models:
2
3 The SimGrid Models
4 ##################
5
6 .. todo::
7
8    - Main existing models (contention, cste, LM07)
9    - Main concepts (Routing, LMM) + link to the papers
10    - How to switch on the command line
11
12 .. _understanding_lv08:
13
14 The default TCP model
15 *********************
16
17 When simulating a data transfer between two hosts, you may be surprised
18 by the obtained simulation time. Lets consider the following platform:
19
20 .. code-block:: xml
21
22    <host id="A" speed="1Gf" />
23    <host id="B" speed="1Gf" />
24
25    <link id="link1" latency="10ms" bandwidth="1Mbps" />
26
27    <route src="A" dst="B">
28      <link_ctn id="link1" />
29    </route>
30
31 If host `A` sends `100kB` (a hundred kilobytes) to host `B`, one could expect
32 that this communication would take `0.81` seconds to complete according to a
33 simple latency-plus-size-divided-by-bandwidth model (0.01 + 8e5/1e6 = 0.81).
34 However, the default TCP model of SimGrid is a bit more complex than that. It
35
36 accounts for three phenomena that directly impact the simulation time even
37 on such a simple example:
38
39   - The size of a message at the application level (i.e., 100kB in this
40     example) is not the size that will actually be transferred over the
41     network. To mimic the fact that TCP and IP headers are added to each packet of
42     the original payload, the TCP model of SimGrid empirically considers that
43     `only 97% of the nominal bandwidth` are available. In other words, the
44     size of your message is increased by a few percents, whatever this size be.
45
46   - In the real world, the TCP protocol is not able to fully exploit the
47     bandwidth of a link from the emission of the first packet. To reflect this
48     `slow start` phenomenon, the latency declared in the platform file is
49     multiplied by `a factor of 13.01`. Here again, this is an empirically
50     determined value that may not correspond to every TCP implementations on
51     every networks. It can be tuned when more realistic simulated times for
52     short messages are needed though.
53
54   - When data is transferred from A to B, some TCP ACK messages travel in the
55     opposite direction. To reflect the impact of this `cross-traffic`, SimGrid
56     simulates a flow from B to A that represents an additional bandwidth
57     consumption of `0.05`. The route from B to A is implicitly declared in the
58     platform file and uses the same link `link1` as if the two hosts were
59     connected through a communication bus. The bandwidth share allocated to the
60     flow from A to B is then the available bandwidth of `link1` (i.e., 97% of
61     the nominal bandwidth of 1Mb/s) divided by 1.05 (i.e., the total consumption).
62     This feature, activated by default, can be disabled by adding the
63     `--cfg=network/crosstraffic:0` flag to command line.
64
65 As a consequence, the time to transfer 100kB from A to B as simulated by the
66 default TCP model of SimGrid is not 0.81 seconds but
67
68 .. code-block:: python
69
70     0.01 * 13.01 + 800000 / ((0.97 * 1e6) / 1.05) =  0.996079 seconds.
71
72 .. _model_ns3:
73
74 ns-3 as a SimGrid model
75 ***********************
76
77 You can use the well-known `ns-3 packet-level network simulator
78 <http://www.nsnam.org>`_ as a SimGrid model, for example to investigate the
79 validity of your simulation. Just install ns-3 and recompile SimGrid
80 accordingly.
81
82 The SimGrid/ns-3 binding only contains features that are common to both systems.
83 Not all ns-3 models are available from SimGrid (only the TCP and WiFi ones are),
84 while not all SimGrid platform files can be used in conjunction ns-3 (routes
85 must be of length 1). Also, the platform built in ns-3 from the SimGrid
86 description is very basic. Finally, communicating from a host to
87 itself is forbidden in ns-3, so every such communication completes
88 immediately upon startup.
89
90
91 Compiling the ns-3/SimGrid binding
92 ==================================
93
94 Installing ns-3
95 ---------------
96
97 SimGrid requires ns-3 version 3.26 or higher, and you probably want the most
98 recent version of both SimGrid and ns-3. While the Debian package of SimGrid
99 don't have the ns-3 bindings activated, you can still use the packaged version
100 of ns-3 by grabbing the ``libns3-dev ns3`` packages. Alternatively, you can
101 install ns-3 from scratch (see the `ns-3 documentation <http://www.nsnam.org>`_).
102
103 Enabling ns-3 in SimGrid
104 ------------------------
105
106 SimGrid must be recompiled with the ``enable_ns3`` option activated in cmake.
107 Optionally, use ``NS3_HINT`` to tell cmake where ns3 is installed on
108 your disk.
109
110 .. code-block:: console
111
112    $ cmake . -Denable_ns3=ON -DNS3_HINT=/opt/ns3 # or change the path if needed
113
114 By the end of the configuration, cmake reports whether ns-3 was found,
115 and this information is also available in ``include/simgrid/config.h``
116 If your local copy defines the variable ``SIMGRID_HAVE_NS3`` to 1, then ns-3
117 was correctly detected. Otherwise, explore ``CMakeFiles/CMakeOutput.log`` and
118 ``CMakeFiles/CMakeError.log`` to diagnose the problem.
119
120 Test that ns-3 was successfully integrated with the following (from your SimGrid
121 build directory). It will run all SimGrid tests that are related to the ns-3
122 integration. If no test is run at all, you probably forgot to enable ns-3 in cmake.
123
124 .. code-block:: console
125
126    $ ctest -R ns3
127
128 Troubleshooting
129 ---------------
130
131 If you use a version of ns-3 that is not known to SimGrid yet, edit
132 ``tools/cmake/Modules/FindNS3.cmake`` in your SimGrid tree, according to the
133 comments on top of this file. Conversely, if something goes wrong with an old
134 version of either SimGrid or ns-3, try upgrading everything.
135
136 Note that there is a known bug with version 3.31 of ns3, when it's built with
137 MPI support, like it is with the package libns3-dev in Debian 11 « Bullseye ».
138 A simple workaround is to edit the file
139 ``/usr/include/ns3.31/ns3/point-to-point-helper.h`` to remove the ``#ifdef NS3_MPI``
140 include guard.  This can be achieved with the following command (as root):
141
142 .. code-block:: console
143
144    # sed -i '/^#ifdef NS3_MPI/,+2s,^#,//&,' /usr/include/ns3.31/ns3/point-to-point-helper.h
145
146 .. _ns3_use:
147
148 Using ns-3 from SimGrid
149 =======================
150
151 Platform files compatibility
152 ----------------------------
153
154 Any route longer than one will be ignored when using ns-3. They are
155 harmless, but you still need to connect your hosts using one-hop routes.
156 The best solution is to add routers to split your route. Here is an
157 example of an invalid platform:
158
159 .. code-block:: xml
160
161    <?xml version='1.0'?>
162    <!DOCTYPE platform SYSTEM "https://simgrid.org/simgrid.dtd">
163    <platform version="4.1">
164      <zone id="zone0" routing="Floyd">
165        <host id="alice" speed="1Gf" />
166        <host id="bob"   speed="1Gf" />
167
168        <link id="l1" bandwidth="1Mbps" latency="5ms" />
169        <link id="l2" bandwidth="1Mbps" latency="5ms" />
170
171        <route src="alice" dst="bob">
172          <link_ctn id="l1"/>            <!-- !!!! IGNORED WHEN USED WITH ns-3       !!!! -->
173          <link_ctn id="l2"/>            <!-- !!!! ROUTES MUST CONTAIN ONE LINK ONLY !!!! -->
174        </route>
175      </zone>
176    </platform>
177
178 This can be reformulated as follows to make it usable with the ns-3 binding.
179 There is no direct connection from alice to bob, but that's OK because ns-3
180 automatically routes from point to point (using
181 ``ns3::Ipv4GlobalRoutingHelper::PopulateRoutingTables``).
182
183 .. code-block:: xml
184
185    <?xml version='1.0'?>
186    <!DOCTYPE platform SYSTEM "https://simgrid.org/simgrid.dtd">
187    <platform version="4.1">
188      <zone id="zone0" routing="Full">
189        <host id="alice" speed="1Gf" />
190        <host id="bob"   speed="1Gf" />
191
192        <router id="r1" /> <!-- routers are compute-less hosts -->
193
194        <link id="l1" bandwidth="1Mbps" latency="5ms"/>
195        <link id="l2" bandwidth="1Mbps" latency="5ms"/>
196
197        <route src="alice" dst="r1">
198          <link_ctn id="l1"/>
199        </route>
200
201        <route src="r1" dst="bob">
202          <link_ctn id="l2"/>
203        </route>
204      </zone>
205    </platform>
206
207 Once your platform is OK, just change the :ref:`network/model
208 <options_model_select>` configuration option to `ns-3` as follows. The other
209 options can be used as usual.
210
211 .. code-block:: console
212
213    $ ./network-ns3 --cfg=network/model:ns-3 (other parameters)
214
215 Many other files from the ``examples/platform`` directory are usable with the
216 ns-3 model, such as `examples/platforms/dogbone.xml <https://framagit.org/simgrid/simgrid/tree/master/examples/platforms/dogbone.xml>`_.
217 Check the file  `examples/cpp/network-ns3/network-ns3.tesh <https://framagit.org/simgrid/simgrid/tree/master/examples/cpp/network-ns3/network-ns3.tesh>`_
218 to see which ones are used in our regression tests.
219
220 Alternatively, you can manually modify the ns-3 settings by retrieving
221 the ns-3 node from any given host with the
222 :cpp:func:`simgrid::get_ns3node_from_sghost` function (defined in
223 ``simgrid/plugins/ns3.hpp``).
224
225 .. doxygenfunction:: simgrid::get_ns3node_from_sghost
226
227
228 WiFi platforms
229 ^^^^^^^^^^^^^^
230
231 In SimGrid, WiFi networks are modeled with WiFi zones, where a zone contains
232 the access point of the WiFi network and the hosts connected to it (called
233 station in the WiFi world). Links inside WiFi zones are modeled as regular
234 links with a specific attribute, and these links are then added to routes
235 between hosts. The main difference When using ns-3 WiFi networks is that
236 the network performance is not given by the link bandwidth and latency but
237 by the access point WiFi characteristics, and the distance between the access
238 point and the hosts.
239
240 So, to declare a new WiFi network, simply declare a zone with the ``WIFI``
241 routing.
242
243 .. code-block:: xml
244
245         <zone id="SSID_1" routing="WIFI">
246
247 Inside this zone you must declare which host or router will be the access point
248 of the WiFi network.
249
250 .. code-block:: xml
251
252         <prop id="access_point" value="alice"/>
253
254 Afterward simply declare the hosts and routers inside the WiFi network. Remember
255 that one must have the same name as declared in the property "access point".
256
257 .. code-block:: xml
258
259         <router id="alice" speed="1Gf"/>
260         <host id="STA0-0" speed="1Gf"/>
261         <host id="STA0-1" speed="1Gf"/>
262
263 Finally, close the WiFi zone.
264
265 .. code-block:: xml
266
267         </zone>
268
269 The WiFi zone may be connected to another zone using a traditional link and
270 a zoneRoute. Note that the connection between two zones is always wired.
271
272 .. code-block:: xml
273
274         <link id="wireline" bandwidth="100Mbps" latency="2ms" sharing_policy="SHARED"/>
275
276         <zoneRoute src="SSID_1" dst="SSID_2" gw_src="alice" gw_dst="bob">
277             <link_ctn id="wireline"/>
278         </zoneRoute>
279
280 WiFi network performance
281 """"""""""""""""""""""""
282
283 The performance of a wifi network is controlled by 3 property that can be added
284 to hosts connected to the wifi zone:
285
286  * ``mcs`` (`Modulation and Coding Scheme <https://en.wikipedia.org/wiki/Link_adaptation>`_)
287    Roughly speaking, it defines the speed at which the access point is
288    exchanging data with all stations. It depends on its model and configuration,
289    and the possible values are listed for example on Wikipedia.
290    |br| By default, ``mcs=3``.
291    It is a property of the WiFi zone.
292  * ``nss`` (Number of Spatial Streams, or `number of antennas <https://en.wikipedia.org/wiki/IEEE_802.11n-2009#Number_of_antennas>`_)
293    defines the amount of simultaneous data streams that the AP can sustain.
294    Not all value of MCS and NSS are valid nor compatible (cf. `802.11n standard <https://en.wikipedia.org/wiki/IEEE_802.11n-2009#Data_rates>`_).
295    |br| By default, ``nss=1``.
296    It is a property of the WiFi zone.
297  * ``wifi_distance`` is the distance from the station to the access point. Each
298    station can have a specific value.
299    |br| By default, ``wifi_distance=10``.
300    It is a property of stations of the WiFi network.
301
302 Here is an example of a zone changing ``mcs`` and ``nss`` values.
303
304 .. code-block:: xml
305
306         <zone id="SSID_1" routing="WIFI">
307             <prop id="access_point" value="alice"/>
308             <prop id="mcs" value="2"/>
309             <prop id="nss" value="2"/>
310         ...
311         </zone>
312
313 Here is an example of a host changing ``wifi_distance`` value.
314
315 .. code-block:: xml
316
317         <host id="STA0-0" speed="1Gf">
318             <prop id="wifi_distance" value="37"/>
319         </host>
320
321 Random Number Generator
322 -----------------------
323
324 It is possible to define a fixed or random seed to the ns3 random number
325 generator using the config tag.
326
327 .. code-block:: xml
328
329         <?xml version='1.0'?><!DOCTYPE platform SYSTEM "https://simgrid.org/simgrid.dtd">
330         <platform version="4.1">
331             <config>
332                     <prop id = "network/model" value = "ns-3" />
333                     <prop id = "ns3/seed" value = "time" />
334             </config>
335         ...
336         </platform>
337
338 The first property defines that this platform will be used with the ns3 model.
339 The second property defines the seed that will be used. Defined to ``time``
340 it will use a random seed, defined to a number it will use this number as
341 the seed.
342
343 Limitations
344 -----------
345
346 A ns-3 platform is automatically created from the provided SimGrid
347 platform. However, there are some known caveats:
348
349   * The default values (e.g., TCP parameters) are the ns-3 default values.
350   * ns-3 networks are routed using the shortest path algorithm, using ``ns3::Ipv4GlobalRoutingHelper::PopulateRoutingTables``.
351   * End hosts cannot have more than one interface card. So, your SimGrid hosts
352     should be connected to the platform through only one link. Otherwise, your
353     SimGrid host will be considered as a router (FIXME: is it still true?).
354
355 Our goal is to keep the ns-3 plugin of SimGrid as easy (and hopefully readable)
356 as possible. If the current state does not fit your needs, you should modify
357 this plugin, and/or create your own plugin from the existing one. If you come up
358 with interesting improvements, please contribute them back.
359
360 Troubleshooting
361 ---------------
362
363 If your simulation hangs in a communication, this is probably because one host
364 is sending data that is not routable in your platform. Make sure that you only
365 use routes of length 1, and that any host is connected to the platform.
366 Arguably, SimGrid could detect this situation and report it, but unfortunately,
367 this is still to be done.
368
369
370
371 .. |br| raw:: html
372
373    <br />