Skip to content

Creating Network Transports (C)

James Edmondson edited this page Mar 21, 2019 · 7 revisions

C++ Guides: GAMS Primer | Simulation Primer | Creating Algorithms | Creating Platforms | Creating Threads | Creating Transports | Debugging


Introduction

GAMS provides multicast, broadcast, and unicast transports for knowledge dissemination through stock implementations in the MADARA middleware. There is also support for DDS, but that hasn't been an active development for several years. If other transports are desired for direct communication over other network mediums, e.g. over serial or custom networking transports, this can be accomplished by deriving from the Base Transport class

To simplify the algorithm creation process, we have written a script called gpc.pl that allows quick creation and configuration of not only new user transports and read threads in transports but also custom controllers that utilize your transport. In this wiki, we'll walk through the process of creating and maintaining new transports.


Table of Contents


Creating a new networking transport with the GAMS Project Configurator (gpc.pl)

Creating a new transport can be greatly simplified by using the gpc.pl tool. To use the tool, decide where you want a custom project to be located. We'll refer to this as a PROGRAM_LOCATION environment variable. A good place for this might be in a folder in your home directory, say HOME/gams_examples. The following examples assume perl is installed on your computer and available in the PATH variable. If perl is installed but not in PATH, you will want to call perl on the gpc.pl script to run it.

If you have any questions about usage of gpc.pl, pass the script a -h or --help option for guidance and information.

Generating new algorithm in Windows command shell (cmd in Start->Run)

%GAMS_ROOT%\scripts\projects\gpc.pl --new-transport my_transport --path %PROGRAM_LOCATION%

Generating new algorithm in Linux terminal

$GAMS_ROOT/scripts/projects/gpc.pl --new-transport my_transport --path $PROGRAM_LOCATION

Running these commands will generate a new directory at PROGRAM_LOCATION. Do not create the directory beforehand. Let the tool do that to ensure it doesn't assume the appropriate infrastructure has already been generated. The tool tries to do no harm to your projects when possible, so you can add new algorithms, platforms, simulations, etc. later.

The tool will generate a number of files and a build infrastructure using the MakefileProjectCreator for portability to Windows, Linux, Mac, Android, etc. As far as editing goes, there are fives files that most users may want to edit:

PROGRAM_LOCATION/src/transports/my_transport.h
PROGRAM_LOCATION/src/transports/my_transport.cpp
PROGRAM_LOCATION/src/transports/my_transportReadThread.h
PROGRAM_LOCATION/src/transports/my_transportReadThread.cpp
PROGRAM_LOCATION/src/controller.cpp

The my_transport class is found in the my_transport.h|cpp files. By default this class is a minimal implementation of the MADARA Base Transport class with stubs for the send_data method that disseminates knowledge from the KnowledgeBase, and with the initialization of a read thread using the MADARA Threader class. The read thread for the new transport can be found in my_transportReadThread.h|cpp files. This class implements a MADARA BaseThread. The logic you will want for reading from the network medium will be placed in the run method. The my_transportReadThread class already has an example of calling process_received_update, which calls filters and uses the quality-of-service indicated in the creation of the KnowledgeBase. Your main task is getting data from your network medium and into

The read thread or listener interface for transports is often the hardest to implement for new transports. For best practice guidance, please see the MADARA implementations of read threads for multicast and unicast.

The controller.cpp file contains a custom GAMS controller that initializes your transport along with any other transports you want to add (you can chain together several transports if you want).

Generating/compiling project in Windows command shell (cmd in Start->Run)

cd %PROGRAM_LOCATION%
mwc.pl -type vc12 workspace.mwc
workspace.sln

After opening the Visual Studio project, compile the project with the settings used during compilation of MADARA and GAMS (e.g. 64 bit, Release mode).

Generating/compiling project in Linux terminal

cd %PROGRAM_LOCATION%
mwc.pl -type gnuace workspace.mwc
make

You can speed up compilation by call make with -j , where NUMCORES is the number of cores on your build machine. This essentially will parallelize the build process, but with a project this small, the build process is very quick (should take a few seconds).

Believe it or not, you have already just generated and compiled a custom thread with a custom controller!


C++ Guides: GAMS Primer | Simulation Primer | Creating Algorithms | Creating Platforms | Creating Threads | Creating Transports | Debugging

Clone this wiki locally