Round trip and Flood in C¶
authors: | Stefanos Florescu |
---|---|
date: | March 2020 |
The Roundtrip demonstrator has two different experiments. The first experiment
sets up one main master hub and three hubs. The master hub sends the value 1
and starts measuring time upon sending the message. This message travels from hub
to hub with each hub adding 1 until it returns to the master. Upon arrival of the modified
integer from the third hub at the master, the clock is stopped and the time it took
for the roundtrip is displayed.
Similarly to the simple roundtrip experiment, the flood experiment has the same setup of master and three hubs. The only difference is that the master now sends a bunch of messages at the same time. The hubs read the messages one by one, process them (by adding 1) and pass them on. The master will start measuring time from the moment he sends his first message and up to the moment he receives the last message from the last hub.
More information on these demonstrators can be found in the Backlog.
Building and running the executables¶
Make sure your local repo is up to date with the HighTech-nl repo
and move into the directory /dds-demonstrators/src/demonstrators/RoundTrip/C
:
$ mkdir build
$ cd build
$ cmake ..
$ make
Also, after the build
directory has been initialized using the cmake ..
command, the two scripts run_roundtrip.sh
and run_flood.sh
can be used to compile the executables and run the experiments. These two scripts
are similar with the only differences being that they call different
executables. For example the run_roundtrip.sh
includes the following:
#!/bin/bash
cmake --build $PWD/build/
echo "Deleting old log file."
rm $PWD/roundtrip.log
echo "Running Roundtrip Demonstrator...press ^C to exit"
./build/Hub_roundtrip topic_2 topic_3 &
./build/Hub_roundtrip topic_3 topic_4 &
./build/Hub_roundtrip topic_4 topic_1 &
./build/Master_roundtrip topic_1 topic_2 > roundtrip.log
The master will output all his measurements into the .log
file in each respective
case. Furthermore, the first argument passed to each Hub/Master executable is
the topic name on which that entity will be listening on, while the second argument
is the topic on which that entity will write to. In order to see the output of the experiment
simply open the respective .log
file.
Note
The Master/Hub can be executed on different nodes, such as Raspberry Pis and PCs. See Setting up Raspberry Pi network for details on how to connect to the Raspberry Pis.
Note
In the case of the flood experiment, the number of samples the Master will send
can be defined in the Master_flood.c
file by changing the #define FLOOD_SAMPLES
number.
Running the Round trip in a Docker Container¶
Similarly to what we described above, the Round trip and Flood experiments can be executed from a Docker Container. First make sure you follow the guide on how to build the Docker Image which can be found in the Docker Guide: How to create and run a Docker Image under “Building Demo Image”. First create a new container using:
$ docker run -it --network="host" --name <container name> <image name>
You can open another terminal/Powershell and have as many processes on that container as you want using per terminal:
$ docker exec -it <existing container name> bash
Navigate into the Roundtrip/
directory and either experiment using:
$ ./docker_run_roundtrip.sh
$ ./docker_run_flood.sh
Warning
Due to the networking issue of the Docker Desktop (see in Docker Guide: How to create and run a Docker Image
under “Running Docker Containers” for more info) on Windows/MacOS we need to change
the DDS networking interface in the docker_cyclonedds_config.xml
in /root/
.
The video in Matrix Board Communication in C shows how this is done. On a Linux machine
this is not required and your container will communicate over the network.