Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill trailing whitespaces in docs.
[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 WiFi platforms
221 ^^^^^^^^^^^^^^
222
223 In SimGrid, WiFi networks are modeled with WiFi zones, where a zone contains
224 the access point of the WiFi network and the hosts connected to it (called
225 station in the WiFi world). Links inside WiFi zones are modeled as regular
226 links with a specific attribute, and these links are then added to routes
227 between hosts. The main difference When using ns-3 WiFi networks is that
228 the network performance is not given by the link bandwidth and latency but
229 by the access point WiFi characteristics, and the distance between the access
230 point and the hosts.
231
232 So, to declare a new WiFi network, simply declare a zone with the ``WIFI``
233 routing.
234
235 .. code-block:: xml
236
237         <zone id="SSID_1" routing="WIFI">
238
239 Inside this zone you must declare which host or router will be the access point
240 of the WiFi network.
241
242 .. code-block:: xml
243
244         <prop id="access_point" value="alice"/>
245
246 Afterward simply declare the hosts and routers inside the WiFi network. Remember
247 that one must have the same name as declared in the property "access point".
248
249 .. code-block:: xml
250
251         <router id="alice" speed="1Gf"/>
252         <host id="STA0-0" speed="1Gf"/>
253         <host id="STA0-1" speed="1Gf"/>
254
255 Finally, close the WiFi zone.
256
257 .. code-block:: xml
258
259         </zone>
260
261 The WiFi zone may be connected to another zone using a traditional link and
262 a zoneRoute. Note that the connection between two zones is always wired.
263
264 .. code-block:: xml
265
266         <link id="wireline" bandwidth="100Mbps" latency="2ms" sharing_policy="SHARED"/>
267
268         <zoneRoute src="SSID_1" dst="SSID_2" gw_src="alice" gw_dst="bob">
269             <link_ctn id="wireline"/>
270         </zoneRoute>
271
272 WiFi network performance
273 """"""""""""""""""""""""
274
275 The performance of a wifi network is controlled by 3 property that can be added
276 to hosts connected to the wifi zone:
277
278  * ``mcs`` (`Modulation and Coding Scheme <https://en.wikipedia.org/wiki/Link_adaptation>`_)
279    Roughly speaking, it defines the speed at which the access point is
280    exchanging data with all stations. It depends on its model and configuration,
281    and the possible values are listed for example on Wikipedia.
282    |br| By default, ``mcs=3``.
283    It is a property of the WiFi zone.
284  * ``nss`` (Number of Spatial Streams, or `number of antennas <https://en.wikipedia.org/wiki/IEEE_802.11n-2009#Number_of_antennas>`_)
285    defines the amount of simultaneous data streams that the AP can sustain.
286    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>`_).
287    |br| By default, ``nss=1``.
288    It is a property of the WiFi zone.
289  * ``wifi_distance`` is the distance from the station to the access point. Each
290    station can have a specific value.
291    |br| By default, ``wifi_distance=10``.
292    It is a property of stations of the WiFi network.
293
294 Here is an example of a zone changing ``mcs`` and ``nss`` values.
295
296 .. code-block:: xml
297
298         <zone id="SSID_1" routing="WIFI">
299             <prop id="access_point" value="alice"/>
300             <prop id="mcs" value="2"/>
301             <prop id="nss" value="2"/>
302         ...
303         </zone>
304
305 Here is an example of a host changing ``wifi_distance`` value.
306
307 .. code-block:: xml
308
309         <host id="STA0-0" speed="1Gf">
310             <prop id="wifi_distance" value="37"/>
311         </host>
312
313 Random Number Generator
314 -----------------------
315
316 It is possible to define a fixed or random seed to the ns3 random number
317 generator using the config tag.
318
319 .. code-block:: xml
320
321         <?xml version='1.0'?><!DOCTYPE platform SYSTEM "https://simgrid.org/simgrid.dtd">
322         <platform version="4.1">
323             <config>
324                     <prop id = "network/model" value = "ns-3" />
325                     <prop id = "ns3/seed" value = "time" />
326             </config>
327         ...
328         </platform>
329
330 The first property defines that this platform will be used with the ns3 model.
331 The second property defines the seed that will be used. Defined to ``time``
332 it will use a random seed, defined to a number it will use this number as
333 the seed.
334
335 Limitations
336 -----------
337
338 A ns-3 platform is automatically created from the provided SimGrid
339 platform. However, there are some known caveats:
340
341   * The default values (e.g., TCP parameters) are the ns-3 default values.
342   * ns-3 networks are routed using the shortest path algorithm, using ``ns3::Ipv4GlobalRoutingHelper::PopulateRoutingTables``.
343   * End hosts cannot have more than one interface card. So, your SimGrid hosts
344     should be connected to the platform through only one link. Otherwise, your
345     SimGrid host will be considered as a router (FIXME: is it still true?).
346
347 Our goal is to keep the ns-3 plugin of SimGrid as easy (and hopefully readable)
348 as possible. If the current state does not fit your needs, you should modify
349 this plugin, and/or create your own plugin from the existing one. If you come up
350 with interesting improvements, please contribute them back.
351
352 Troubleshooting
353 ---------------
354
355 If your simulation hangs in a communication, this is probably because one host
356 is sending data that is not routable in your platform. Make sure that you only
357 use routes of length 1, and that any host is connected to the platform.
358 Arguably, SimGrid could detect this situation and report it, but unfortunately,
359 this is still to be done.
360
361
362
363 .. |br| raw:: html
364
365    <br />