Skip to content

Creating a Custom Module

Daniel Stolpmann edited this page Apr 19, 2024 · 1 revision

FlowEmu's modular design makes it easy to implement special functionalities in a custom module. This guide gives an overview of the steps required to add a new module.

Creating the Source Files

The existing modules are a great starting point when implementing a custom module. The simplest module, which only has the bare minimum of code that is required to create a working module is the null module. The null module has a single input and passed the packets to its output without adding any impairments. It can be found in src/modules/null/NullModule.{hpp,cpp}. However, it is strongly recommended to also take a look at the other modules and choose one with a similar functionality as a starting point.

Start by copying the .hpp and .cpp files of the module that you want to use as a template into one of the subfolders of the src/modules directory. If your module does not fit into one of the existing categories, you can simply create a new subfolder. To avoid naming conflicts with the existing module, rename the files, the class, the include guard definitions as well as the names in the getType() function and the constructor.

Registering the Module

A new module has to be registered in the existing code base in two places:

CMake

FlowEmu is build using CMake. In order to build the newly created module with the rest of the emulator and link it into the final binary, the implementation files have to be known to CMake. For this, the .cpp files of your module have to be added to the CMakeLists.txt file in the src directory. Here, all you need to do is to add new lines with the relative paths to all .cpp files of your module. While the order of the lines do not have an influence on the functionality, they are generally sorted alphabetically.

Module Manager

The module manager is the central component in FlowEmu that is managing all modules and handles the creating of the graph. In order to make the module manager aware of the new module, it has to be added to the module_factories map in the src/modules/ModuleManager.cpp file.