The communication node program allows seeing other communication nodes running on the same local area network. It uses UDP multicast messages ( https://tools.ietf.org/html/rfc1112) for one-to-many communication and TCP messages for one-to-one communication. The implementation is done in C++11 with boost::asio as the main networking library. The implementation is primarily Linux based, but has also been tested on Windows. It allows for an arbitrary number of CNs and multiple CNs can run on the same machine.
Figure 1: Class diagram
The main design consists of six classes:
- AsyncUdpMulticastSendingService – class that is responsible for sending the information about this communication node to others. The information is encoded as a JSON string in the following format:
{
"SessionId": "e89a00ca-fa42-432c-8ce3-8149ea935b25",
"TcpServerPort": "54829"
}
The session ID is a unique identifier attributed to each CN, the TCP server port is a port assigned by the OS to this CN.
- AsyncUdpMulticastListenService – other nodes are responsible for listening to incoming multicast, parsing the JSON and storing the session IDs and ports into a shared list.
- CommNodeList – this is a shared directory for different threads to be able to add new CNs, delete non-responding CNs and finally to present them to the user.
- AsyncTcpListenServer – this is a server with the TcpServerPort number referenced above. This asynchronous server responds to queries from other nodes.
- SyncTcpNodeCommsClient – this is the only synchronous communications class. It uses blocking calls to try to measure the round-trip-time for each query and response.
- CommNodeUi – this class presents the information to the user. In Linux this relies on ncurses and in Windows uses a system("clr") to present a continuous table.
In a Linux environment – make sure that git, boost, cmake and ncurses are installed. In Ubuntu:
sudo apt-get install libboost-all-dev libncurses5-dev
From the main directory - move to the build directory and then run cmake in it. The CMakeLists.txt script will automatically git-clone and build googletest as part of the build process.
cd build
cmake ..
make
./commsnode --help
Dependencies:
- 1)MinGW compiler suite with libboost: https://nuwen.net/mingw.html unzip it to C:\MinGW and ensure that "C:\MinGW\bin;C:\MinGW\git\bin" is part of Windows %PATH%
The build can be done from the main directory with a simple Makefile – an example is provided in Makefile.windows
copy Makefile.windows Makefile
make
cd build
Commsnode.exe --help
The unit tests will be built automatically on Linux. The cmake script will clone the latest googletest master from GitHub and build it in place. Following that the unit tests will be built and can be run with
./test_commsnode
The googletest cmake script is based on the following GitHub repository - https://github.com/snikulov/google-test-examples.
In the tools directory two debugging tools are provided rx_udp and rx_tcp. They can be built using the Makefile.linux and Makefile.windows examples in the directory. These tools can be used to analyze the TCP and UDP messages being sent across the network.
Figure 2: Many nodes running on Linux
-
Properly wrap or encapsulate the network I/O calls. Also create mock classes ( googlemock) for unit testing for all of the network facing services. Currently only the classes that are completely internal to this application have unit tests.
-
While the round-trip-time is somewhat accurate (minus some time spent in the application layer), the estimated to and from times are relying on another CNs clock. This is problematic because the other clock might not be synced. Ideally this requires something like the IEEE 1588-2002 ( Precision Time Protocol) to synchronize all of the clocks on the network.