-
Notifications
You must be signed in to change notification settings - Fork 2
Processor Plugin System
The basic idea of this platform is that it can be very modular and easy to change it's way of working.
For that the code that process a bundle is compiled as a shared library and used as plugin for the platform.
Each processor has to used the plugin API, to do that, each one has to include the PluginAPI.h and add this macro to their code.
NEW_PLUGIN(NameOfTheClass, "Name of the plug-in", "Version of the plug-in",
"Description of the plug-in")
This new processor must be a derived class from the BundleProcessor. The new class must implement the following functions:
virtual void processBundle(std::unique_ptr<BundleContainer> bundleContainer);
Where the input is a BundleContainer (this can be the default one or you can write your own).
If you write your own, or you use the default one you must implement also the function:
virtual std::unique_ptr<BundleContainer> createBundleContainer(std::unique_ptr<Bundle> Bundle);
That generates this BundleContainer given a Bundle.
There are other functions that can be overwritten if needed this are:
virtual void start(
Config config, std::shared_ptr<BundleQueue> bundleQueue,
std::shared_ptr<NeighbourTable> neighbourTable,
std::shared_ptr<ListeningEndpointsTable> listeningAppsTable);
By default starts the threads to process and receive bundles.
virtual void restoreRawBundleContainer(const std::string &data);
This function is called when restoring the bundle containers from disk.
It must be overwritten when a custom bundle container is used.
virtual void discard(std::unique_ptr<BundleContainer> bundleContainer);
This function is called when discarding a bundle container.
With this a new bundle processor can be created, the platform has some examples like:
- BasicBundleProcessor : This processor uses the Worker class to generate default codes form the NodeState and defines a custom process workflow.
- FirstADTNPlusFwk : This defines another workflow for processing the bundles, and uses an extension of the bundle to modify the code to execute.
The compilation example can be found in the CMakeLists.txt.
add_library(aDTNPlus_FirstFwkBundleProcessor MODULE
Node/BundleProcessor/BundleProcessor.cpp
Node/BundleProcessor/FirstADTNPlusFwk.cpp
Node/JsonFacades/NodeStateJson.cpp
Node/JsonFacades/BundleStateJson.cpp
)
To help with the bundleProcess function there are some functions implemented, those functions are the following ones:
- delivery
- forward
- discard
- restore
This functions work as follow
void delivery(BundleContainer &bundleContainer, std::vector<std::string> destinations);
The delivery function takes as argument a bundleContainer pointer and a vector of strings.
This function search for the given destinations, if someone is registered at one of this destinations, the bundle is send to them, if not the bundle is saved at disk as delivered.
void forward(Bundle bundle, std::vector<std::string> nextHop);
The forward function takes as argument a bundle and a vector of strings.
This function sends the bundle to all the given nextHop, it throws a ForwardException if the bundle can not been send to any neighbour of the list.
virtual void discard(std::unique_ptr<BundleContainer> bundleContainer);
The discard function takes as argument a unique pointer of a BundleContainer (it needs ownership of the pointer so the std::move call is needed).
This function removes the local saved bundle and deletes it, after a call to this function the unique_ptr is invalid.
void restore(std::unique_ptr<BundleContainer> bundleContainer);
The restore function takes as argument a unique pointer of a BundleContainer (it needs ownership of the pointer so the std::move call is needed).
This function add the bundleContainer to the queue again, after a call to this function the unique_ptr is invalid.