Previous Contents Next AMnet documentation

AMnet documentation

Contact:
flexinet-support@ibr.cs.tu-bs.de

http://www.flexinet.de


The AMnet HOWTO


10. Writing new AMnet modules

10.1 The module concept

All modules are shared libraries. Native modules can be loaded directly, Java modules require a wrapper application (e.g. libwrapperJava.so) and hardware modules need a wrapper as well (e.g. libwrapperHardware.so).

All modules (and wrappers) have to provide the following functions:

char *initModule(char *initData, int *error)
Initializes and configures a module. If a problem with the received data is encountered, an errorcode == NULL is returned. Otherwise, the return value is a pointer to the global data, a module requires. Warning: Modules are not allowed to specify data of the form "int fd;". They have to move the data into a configuration block and return its address on init. This configuration block is passed together with every data block to all functions as the last parameter "conf". Only exception: The "run" function (see below).
char *configure(char *paramType, char *paramName, char *paramValue, char *conf)
(Re)configures the module. The return value is a pointer to the new configuration values ("conf" at all other function calls).
int run(struct manage *data)
Processes all available data. If additional data is required for processing, an error code has to be returned. The modules' own global variables can be determined with the following function: char *conf = getModuleConf(data);
int shutdownModule(char *conf)
Switches the module off. All allocated resources have to be freed now (e.g. the memory allocated for the configuration).
int getStatus(char *conf)
Returns the status of the module.

10.2 Java Modules

The processing of Java modules is much easier. They are a standard class, which has to provide the following functions:

public int initModule(byte initData[])
public void shutdownModule()
public byte []run(byte data[])
public void configure(byte confData[])
public String getStatus()
These functions are similar to their C counterparts. In opposite to the native C modules, Java modules can store their global data in a much easier way, since these are instance variables and a separate instance is created for every single class. Therefore, the handling of confiuration pointers can be avoided.

10.3 Writing a new AMnet module

In order to develop own modules, the user should make himself familiar with the demo modules in the amnet/user/ee/src/modules directory. pc.c is a very simple module, that counts the packets in the input chain. This module can be used as an example for storing global variables in a configuration block. A little more complex example is the module mpeg.c, which can be used together with a MPEG filter library to filter a MPEG stream. Two aspects of this module are very important. First the module realizes a buffer management, because the MPEG filter requires a minimal amount of data in order to work. Secondly, this module shows how a module with several parameters can be configured.

The compilation of user provided modules requires modification of the Makefile in the directory amnet/user/ee.


Previous Contents Next