The Multicast/Reduction Network: A User's Guide to MRNet


Table of Contents

1. Introduction
2. Installing and Using MRNet
Supported Platforms and Compilers
System Requirements
Build Configuration
Compilation and Installation
Bugs, Questions and Comments
3. MRNet Components and Abstractions
MRNet Communicators
MRNet Streams
MRNet Filters
4. A Simple Example
The MRNet Interface
MRNet Instantiation
5. The MRNet C++ API Reference
Class Network
Class Communicator
Class Stream
Class Event
6. MRNET Process-tree Topologies
Topology File Format
Topology File Generator
7. Adding New Filters
Loading Filters from a Shared Object File
Defining an MRNet Filter
Creating and Using MRNet Filter Shared Object Files
A. MRNET Format Strings
B. MRNET Data Elements
C. MRNET Event Types
D. A Complete MRNet Example

List of Figures

4.1. MRNet Front-end Sample Code
4.2. MRNet Back-end Sample Code

Chapter 1. Introduction

MRNet is a customizable, high-throughput communication software system for parallel tools with a master/slave architecture. MRNet reduces the cost of these tools' activities by incorporating a tree of processes between the tool's front-end and back-ends. MRNet uses these internal processes to distribute many important tool activities, reducing analysis time and keeping tool front-end loads manageable.

MRNet-based tools send data between front-end and back-ends on logical flows of data called streams. MRNet internal processes use filters to synchronize and aggregate data sent to the tool's front-end. Using filters to manipulate data in parallel as it passes through the network, MRNet can efficiently compute averages, sums, and other more complex aggregations on back-end data.

Several features make MRNet especially well-suited as a general facility for building scalable parallel tools:

  • Flexible organization. MRNet does not dictate the organization of MRNet and tool processes. MRNet process organization is specified in a configuration file that can specify common network layouts like k-ary and k-nomial trees, or custom layouts tailored to the system(s) running the tool. For example, MRNet internal processes can be allocated to dedicated system nodes or co-located with tool back-end and application processes.
  • Scalable, flexible data aggregation. MRNet's built-in filters provide efficient computation of averages, sums, concatenation, and other common data reductions. Custom filters can be loaded dynamically into the network to perform tool-specific aggregation operations.
  • High-bandwidth communication. MRNet transfers data within the tool system using an efficient, packed binary representation. Zero-copy data paths are used whenever possible to reduce the cost of transferring data through internal processes.
  • Scalable multicast. As the number of back-ends increases, serialization when sending control requests limits the scalability of existing tools. MRNet supports efficient message multicast to reduce the cost of issuing control requests from the tool front-end to its back-ends.
  • Multiple concurrent data channels. MRNet supports multiple logical streams of data between tool components. Data aggregation and message multicast takes place within the context of a data stream, and multiple operations (both upward and downward) can be active simultaneously.

Chapter 2. Installing and Using MRNet

For this discussion, $MRNET_ROOT is the location of the top-level directory of the MRNet distribution and $MRNET_ARCH is a string describing the platform (OS and architecture) as discovered by autoconf. For all instructions, it is assumed that the current working directory is $MRNET_ROOT.

Supported Platforms and Compilers

MRNet has been developed to be highly portable; there is no reason why it should not run properly on all common Unix-based platforms. This being said, we have successfully built and tested MRNet using GCC version 3 compilers on the following systems:

  • i686-pc-linux-gnu
  • rs6000-ibm-aix5.1.0.0
  • sparc-sun-solaris2.8

We are currently upgrading our build system to allow the use of native compilers where appropriate, for instance, xlc and xlC in AIX environments.

System Requirements

Here we list the third party tools that MRNet uses and needs for proper installation:

  • GNU make
  • flex
  • bison

Build Configuration

MRNet uses GNU autoconf to discover the platform specific configuration parameters. The script that does this auto-configuration is called configure.

UNIX>  ./configure --help

shows all possible options of the command. Below, we display the MRNet-specific ones:


  --with-libfl                Link line for flex library
  --with-outputlevel          output level (0=>off, *1=>error*, 2=>info, 3=>lo-debug, 4=>mid-debug, 5=>hi-debug)

./configure without any options should give reasonable results, but the user may specify certain options. For example,

UNIX> ./configure CXX=g++ CXXFLAGS=-O3 -with-outputlevel=5 --with-libfl=/usr/local/lib/libfl.a

instructs the configure script to use g++ for the C++ compiler with level 3 optimization, very verbose output and /usr/local/lib/libfl.a as the location of the flex library.

Compilation and Installation

To build the MRNet toolkit by type:

UNIX>  make

After a successful build, the following files will be present:

  • $MRNET_ROOT/lib/$MRNET_ARCH/libmrnet.a: MRNet API library
  • $MRNET_ROOT/bin/$MRNET_ARCH/mrnet_commnode: MRNet internal communcation node (used internally)
  • $MRNET_ROOT/bin/$MRNET_ARCH/mrnet_topgen: MRNet topology file generator
  • $MRNET_ROOT/bin/$MRNET_ARCH/*_[FE,BE]: MRNet test front-end and back-end programs

Bugs, Questions and Comments

MRNet is maintained primarily by Dorian Arnold, Paradyn Project, University of Wisconsin-Madison. Comments and other feedback whether positive or negative are welcome.

Please report bugs to darnold@cs.wisc.edu.

The MRNet webpage is http://www.paradyn.org/mrnet/

Chapter 3. MRNet Components and Abstractions

MRNet has two main types of components: libmrnet.a, a library that is linked into a tool's front-end and back-end components, and mrnet_commnode, a program that runs on intermediate nodes interposed between the application front-end and back-ends. libmrnet.a exports an API (See Chapter 5, The MRNet C++ API Reference) that enables I/O interaction between the front-end and groups of back-ends via MRNet. The primary purpose of mrnet_comm is to distribute data processing functionality across multiple computer hosts and to implement efficient and scalable group communications. The following sub-sections describe the lower-level components of the MRNet API in more detail.

MRNet Communicators

MRNet uses communicators to represent groups of network end-points. Like communicators in MPI, MRNet communicators provide a handle that identifies a set of end-points for point-to-point, multicast or broadcast communications. MPI applications typically have a non-hierarchical layout of potentially identical processes. In contrast, MRNet enforces a tree-like layout of all processes, rooted at the tool front-end. Accordingly, MRNet communicators are created and managed by the front-end, and communication is only allowed between a tool's front-end and its back-ends, i.e. back-ends cannot interact with each other directly via MRNet.

MRNet Streams

A stream is a logical channel that connects the front-end to the end-points of a communicator. All tool-level communication via MRNet must use these streams. Streams carry data packets downstream, from the front-end toward the back-ends, and upstream, from the back-ends toward the front-end. Upward streams are expected to carry data of a specific type allowing data aggregation operations to be associated with a stream. The type is specified using a format string (See Appendix A, MRNET Format Strings) similar to those used in C formatted I/O primitives, e.g. a packet whose data is described by the format string "%d %d %f %s" contains two integers followed by a float then a character string. MRNet expands the standard specification to allow for specifiers that describe arrays of integers and floats.

MRNet Filters

Data Aggregation is the process of merging multiple input data packets and transforming them into one or more output packets. Though it is not necessary for the aggregation to result in less or even different data, aggregations that reduce or modify data values are most common. MRNet uses data filters to aggregate data packets. Filters specify an operation to perform and the type of the data expected on the bound stream. Filter instances are bound to a stream at stream creation. MRNet uses two types of filters: synchronization filters and transformation filters. Synchronization filters organize data packets from downstream nodes into synchronized waves of data packets, while transformation filters operate on the synchronized data packets yielding one or more output packets.

Filters operate on data flowing upstream in the network. Synchronization filters receive packets one at a time and do not output any packets until the specified synchronization criteria has occurred. Transformation filters input the group of synchronized packets, perform some type of data transformation on the data contained in the packets and output one or more packets. A distinction between synchronization and transformation filters is that synchronization filters are independent of the packet data type, but transformation filters operate on packets of a specific type. Synchronization filters provide a mechanism to deal with the asynchronous rrival of packets from children nodes; the synchronizer collects packets and typically aligns them into waves, passing an entire wave onward at the same time. Therefore, synchronization filters do no data transformation and can operate on packets in a type-independent fashion. MRNet currently supports three synchronization modes:

  • Wait For All: wait for a packet from every child node,
  • Time Out: wait a specified time or until a packet has arrived from every child (whichever occurs first), or
  • Do Not Wait: output packets immediately. Synchronization filters use one of these three criteria to determine when to return packets to the stream manager.

Transformation filters combine data from multiple packets by performing an aggregation that yields one or more new data packets. Since transformation filters are expected to perform computational operations on data packets, there is a type requirement for the data packets to be passed to this type of filter: the data format string of the stream's packets and the filter must be the same. Transformation operations must be synchronous, but can carry state from one transformation to the next using static storage structures. MRNet provides several transformation filters that should be of general use:

  • Basic scalar operations: min, max, sum and average on integers or floats.
  • Concatenation: operation that inputs n scalars and outputs a vector of length n of the same base type.

Chapter 7, Adding New Filters describes facilities a tool developer may use to add new filters to the provided set.

Chapter 4. A Simple Example

The MRNet Interface

A complete description of the MRNet API is in Chapter 5, The MRNet C++ API Reference. This section offers a brief overview only. Using libmrnet.a, a tool can leverage a system of internal processes, instances of the mrnet_commnode program, as a communication substrate. After instantiation of the MRNet network (discussed in the section called “MRNet Instantiation”, the front-end and back-end processes are connected by the internal processes. The connection topology and host assignment of these processes is determined by a configuration file, thus the geometry of MRNet's process tree can be customized to suit the physical topology of the underlying hardware resources. While MRNet can generate a variety of standard topologies, users can easily specify their own topologies; see Chapter 6, MRNET Process-tree Topologies for further discussion.

The MRNet API, provided by libmrnet, contains network, end-point, communicator, and stream objects that a tool's front-end and back-end use for communication. The network object is used to instantiate the MRNet network and access end-point objects that represent available tool back-ends. The communicator object is a container for groups of end-points, and streams are used to send data to the end-points in a communicator.

Figure 4.1. MRNet Front-end Sample Code

   front_end_main(){
1.   MR_Network * net;
2.   MR_Communicator * comm;
3.   MR_Stream * stream;
4.   float result;
5.   net = new MR_Network(config_file);
6.   comm = net->get_broadcast_communicator( );
7.   stream = new MR_Stream(comm, FMAX_FIL);
8.   stream->send("%d", FLOAT_MAX_INIT);
9.   stream->recv("%f", result);
   }

A simplified version of code from an example tool front-end is shown in Figure 4.1. In the front-end code, after some variable definitions in lines 1-4, in line 5, an instance of the MRNet network is created using the topology specification in config_file. In line 6, the newly created network object is queried for an auto-generated broadcast communicator that contains all available end-points. In line 7, this communicator is used to established a stream for which the MRNet internal processes will use a filter that finds the maximum floating point data value of the data sent upstream. The front-end then might send one or more initialization messages to the backends; in our example code on line 9, we broadcast an integer initializer and await the single floating point value result.

Figure 4.2. MRNet Back-end Sample Code

   back_end_main(){
1.   MR_Stream * stream;
2.   int val;
3.   MR_Network::init_backend( );
4.   MR_Stream::recv("%d", &val, &stream);
5.   if(val == FLOAT_MAX_INIT){
6.      stream->send("%f", rand_float);
     }
   }

Figure 4.2 shows the code for the back-end that reciprocates the actions of the front-end. Each tool back-end first connects to the appropriate internal process, via the init_backend call in line 3. While the front-end makes a stream-specific recv call, the back-ends make a stream-anonymous recv that returns the integer sent by the front-end along with a stream object representing the stream that the front-end has established. Finally, each back-end sends a scalar floating point value upstream toward the front-end.

A complete example of MRNet code can be found in Appendix D, A Complete MRNet Example.

MRNet Instantiation

While conceptually simple, creating and connecting the internal processes is complicated by interactions with the various job scheduling systems. In the simplest environments, we can launch jobs manually using facilities like rsh or ssh. In more complex environments, it is necessary to submit all requests to a job management system. In this case, we are constrained by the operations provided by the job manager (and these vary from system to system). We currently support two modes of instantiating MRNet-based tools.

In the first mode of process instantiation, MRNet creates the internal and back-end processes, using the specified MRNet topology configuration to determine the hosts on which the components should be located. First, the front-end consults the configuration and uses rsh or ssh to create internal processes for the first level of the communication tree on the appropriate hosts. Upon instantiation, the newly created processes establish a network connection to the process that created it. The first activity on this connection is a message from parent to child containing the portion of the configuration relevant to that child. The child then uses this information to begin instantiation of the sub-tree rooted at that child. When a sub-tree has been established, the root of that sub-tree sends a report to its parent containing the end-points accessible via that sub-tree. Each internal node establishes its children processes and their respective connections sequentially. However, since the various processes are expected to run on different compute nodes, sub-trees in different branches of the network are created in concurrently, maximizing the efficiency of network instantiation.

In the second mode of process instantiation, MRNet relies on a process management system to create some or all of the MRNet processes. This mode accommodates tools that require their back-ends to create, monitor, and control the application processes. For example, IBM's POE uses environment variables to pass information, such as the process' rank within the application's global MPI communicator, to the MPI run-time library in each application process. In cases like this, MRNet cannot provide back-end processes with the environment necessary to start MPI application processes. As a result, MRNet creates its internal processes recursively as in the first instantiation mode, but does not instantiates any back-end processes. MRNet then starts the tool back-ends using the process management system to ensure they have the environment needed to create application processes successfully. When starting the back-ends, MRNet must provide them with the information needed to connect to the MRNet internal process tree, such as the leaf processes' host names and connection port numbers. This information is provided via the environment, using shared filesystems or other information services as available on the target system.

Chapter 5. The MRNet C++ API Reference

All classes are included in the MRN namespace. For this discussion, we do not explicitly include reference to the namespace; for example, when we reference the class Network, we are implying the class MRN::Network.

In MRNet, there are four top-level classes: Network, EndPoint, Communicator, and Stream. The Network class contains primarily static methods that allow one to instantiate, and destroy MRNet process trees and to query instantiated trees for information. Application back-ends are referred to as end-points and are encapsulated by objects of type EndPoint. The Communicator class is used to reference a group of EndPoints and can be used to establish MRNet Streams for unicast, multicast or broadcast communications via the MRNet infrastructure. The public members of these classes are detailed below.

Class Network

static int Network::new_Network(config_file,  
 commnode_exe,  
 backend_exe); 
const char * config_file;
const char *  commnode_exe;
const char *  backend_exe;
Network::new_Network is a static method that is used to instantiate the MRNet process tree. config_file is the path to a configuration file that describes the desired process tree topology. commnode_exe is the path to the mrnet_commnode executable that should have been built at installation time, and backend_exe is the path to the executable to be used for the application's back-end processes. When this function returns without error, all MRNet internal processes and the application back-end processes will have been instantiated using rsh or ssh depending on the setting of the environment variable MRNET_RSH.

Note

If it is necessary to run the rsh with a utility like runauth to non-interactively authenticate the unattended remote process, that command may be specified using the MRNET_RUNAUTH environment variable.

static void Network::delete_Network();

Network::delete_Network is used to tear down the MRNet process tree. When this function is called, each node in the MRNet configuration sends a control message to its immediate children informing them of the "delete network" request. After delivering this message, the process itself terminates. Note: if the application back-ends have not already terminated, invoking this method will cause them to terminate.
static void Network::print_error(error_str); 
const char *  error_str;
Network::print_error prints a message to stderr describing the last error encountered during a MRNet library call. It first prints the null-terminated string, error_str followed by a colon then actual error message followed by a newline.

Class Communicator

static Communicator * Communicator::new_ Communicator(); 
This function returns a pointer to a new Communicator object. The object initially contains no endpoints. Use Communicator::add_EndPoint( ) to populate the communicator.
static Communicator * Communicator::new_ Communicator(orig_comm); 
Communicator & orig_comm;
This function returns a pointer to a new Communicator object that initially contains the set of endpoints contained in orig_comm.
static Communicator * Communicator::get_ BroadcastCommunicator(); 
This function returns a pointer to a default communicator containing all the endpoints available in the system. Multiple calls to this function return the same pointer to the broadcast communicator object created at network instantiation.
int Communicator::add_EndPoint(hostname,  
 port); 
const char *  hostname;
unsigned short  port;
This function is used to add a new EndPoint object to the set contained by the communicator. The original set of endpoints contained by the communicator is tested to see if it already contains the potentially new endpoint. If so, the function silently returns successfully. This function fails if there exists no endpoint defined by hostname:port. This function returns 0 on success, -1 on failure.
int Communicator::add_EndPoint(endpoint); 
EndPoint &  endpoint;
This function is similar to the add_EndPoint() above except that it takes an explicit EndPoint object instead of hostname and port parameters. Success and failure conditions are exactly as stated above. This function also returns 0 on success and -1 on failure.

unsigned int Communicator::size();

This function returns the number of endpoints contained in the communicator.
const char * Communicator::get_HostName(idx); 
unsigned int  idx;
This function returns a character string identifying the hostname of the endpoint at position idx in the set contained by the communicator. A return value of NULL signals that idx> is out of range.
unsigned short Communicator::get_Port(idx); 
unsigned int  idx;
This function returns an unsigned short identifying the connection port of the endpoint at position idx in the set contained by the communicator. A return value of NULL signals that idx> is out of range.
unsigned int Communicator::get_Id(idx); 
unsigned int  idx;
This function returns an unsigned int that is used by MRNet to uniquely identify the endpoint at position idx in the set contained by the communicator. A return value of NULL signals that idx> is out of range.

Class Stream

static Stream * Stream::new_Stream(comm,  
 filter_id); 
Communicator * comm;
unsigned int  filter_id;
Stream::new_Stream creates a MRNet stream object attached to the endpoints specified by the comm argument. The second argument filter_id specifies the filtering operation to apply to data flowing upstream from the application back-ends toward the front-end.
static int Stream::recv(tag,  
 buf,  
 stream); 
int * tag;
void * *  buf;
Stream * *  stream;
This non-blocking function is used to invoke a stream-anonymous receive operation. Any packet available (addressed to any stream) will be returned (in roughly FIFO ordering) via the output parameters passed in. tag will be filled in with the integer tag value that was passed by the corresponding Stream::send() operation. buf is an opaque structure that must be passed to the Stream::unpack described below. Finally, a pointer to the stream to which the packet was addressed will be returned in stream. A return value of -1 indicates an error, 0 indicates no packets were available, and 1 indicates success.
static int Stream::unpack(buf,  
 format_str,  
 ...); 
char * buf;
const char *  format_str;
This function operates similarily to C's sscanf. It takes a buf parameter that was returned by a previous call to Stream::recv(). format_str is a format string describing the datatypes expected in the packet returned by Stream::recv() (See Appendix A, MRNET Format Strings for a full description.) On success, Stream::unpack() returns 0; on failure, -1.
int Stream::send(tag,  
 format_str,  
 ...); 
int  tag;
const char *  format_str;
This function invokes a data output operation on the calling stream. tag is an integer identifier that is expected to classify the data in the packet to be transmitted across the stream. format_str is a format string describing the data in the packet (See Appendix A, MRNET Format Strings for a full description.) On success, Stream::send() returns 0; on failure, -1.

int Stream::flush();

This function commits a flush of all packets currently buffered by the stream pending an output operation. A successful return indicates that all packets on the calling stream have been passed to the operating system kernel for network transmission.

int Stream::recv(tag, buf);
int *tag;
void * * buf;

This non-blocking function is used to invoke a stream-specific receive operation. Packets addressed to the calling stream will be returned in strictly FIFO ordering via the output parameters passed in. tag will be filled in with the integer tag value that was passed by the corresponding Stream::send() operation. buf is an opaque structure that must be passed to the Stream::unpack described below. A return value of -1 indicates an error, 0 indicates no packets were available, and 1 indicates success.

Class Event

Currently, MRNet has a primitive asynchronous error notification based on events. Whenever errors, failures, or other significant events take place at internal or back-end nodes, an event is propagated toward the front-end. This event is placed in a queue which the user can access to determine the systems state. Eventually, MRNet will migrate to error semantics this will give the user more immediate and responsive error notification, including the use of callbacks into the user's space. For now, we describe the portion of the event infrastructure relevant to the user.

static bool Event::have_Event();

Event::have_Event checks the MRNet event queue returning true if new events exist and false, otherwise.

static Event * Event::get_NextEvent();

Event::get_NextEvent returns the next event in the MRNet event queue. A pointer to the event is returned if the queue is non-empty, otherwise, NULL is returned. This function removes the event it returns from the MRNet event queue.

EventType Event::get_Type();

Event::get_Type returns the type of the event. Appendix C, MRNET Event Types defines all the valid event types.

const std::string &Event::get_HostName();

Event::get_HostName returns the name of the host on which the event occured.

unsigned short Event::get_Port();

Event::get_Port returns the MRNet process identifier of the process in which the event occured.
const std::string & Event::get_Description(); 
Event::get_Description returns a string containing a human-readable description of the event.

Chapter 6. MRNET Process-tree Topologies

MRNet allows a tool to specify a node allocation and process connectivity tailored to its computation and communication requirements and to the system where the tool will run. Choosing an appropriate MRNet configuration can be difficult due to the complexity of the tool's own activity and its interaction with the system. This section describes how users may define their own process topologies, and the mrnet_topgen tool provided by MRNet to facilitate the process.

Topology File Format

The first parameter to the Network::new_Network() function is the name of an MRNet topology file. This file defines the topological layout of the front-end, internal nodes, and back-end MRNet and tool processes. In the syntax of the topology file, the hostname:id tuple represents a process with MRNet id id running on hostname. It is important to note that the id is of symbolic value only and does not reflect a port or process number associated with the system. A line in the topology file is always of the form:

hostname1:0 => hostname1:1 hostname1:2 ;

meaning process on hostname1 with MRNet id, 0, has two children, with MRNet ids, 1 and 2, respectively, running on the same host. MRNet will parse the topology file without error if the file properly defines a tree, in the mathematical sense (i.e. a tree must have a single root, no cycles, full connection, and no node can be its own descendant).

Topology File Generator

When the MRNet test programs are built, a topology generator program, $MRNET_ROOT/bin/$MRNET_ARCH/mrnet_topgen, will also be created. The usage of this program is:

mrnet_topgen <infile> <outfile> <befile> <num_backends> <fan-out>

infile is a machine file containing a set of MRNet host/process identifiers in the format, hostname:id, described above. outfile is the name of the MRNet topology file to be created by the generator. befile must be specified, but can be ignored. Finally, num_backends and fan-out define the number of backends and the fan-out to be used at the front-end and all internal nodes, respectively. The specified input machine file must contain enough unique host/process tuples to support the entire process tree. Currently, this program can only build completely balanced trees with the same fan-out at each parent node.

Chapter 7. Adding New Filters

Loading Filters from a Shared Object File

The facility for loading new filter operations into the MRNet system is conveniently similar to the conventional dlopen() facilities for opening a shared object and dynamically loading symbols defined within. The function's signature is:

static int Stream::load_FilterFunc(so_file,  
 func,  
 is_transformation_filter=true); 
const char * so_file;
const char *  func;
bool  is_transformation_filter=true;

so_file is the path to a shared object file that contains the filter function to be loaded and func is the name of the function to be loaded. The last parameter is_transformation_filter defaults to true and can usually be omitted since the common case is to load transformation, not synchronization, filters. Additionally, the shared object file must contain a const char * symbol named by the string formed by the concatenation of the filter function name and the suffix "_format_string". For instance, if the filter function is named my_filter_func, the shared object must define a symbol const char *my_filter_func_format_string. The value of this string will be the MRNet format string describing the format of data that the filter can operate on. A value of "" denotes that the filter can operate on data of arbitrary value.

On success, Stream::load_FilterFunc returns the id of the newly loaded filter which may be used in subsequent calls to Stream::new_Stream(). A value of -1 is returned on failure.

Defining an MRNet Filter

To properly demonstrate MRNet filters, we must discuss MRNet's packet abstraction in more detail. A packet encapsulates a chunk of formatted data, usually created as the result of a Stream::send() call. Let's say a packet was created using the format string "%s %d" describing a null-terminated string, followed by a 32-bit integer, the packet is said to contain 2 data elements, of those types respectively. In the packet class, the operator[] is overloaded so that packet[i] conveniently returns the ith data element in the packet. Furthermore, the data element abstraction contains accessor functions to return proper data values. In the above example, packet[0].get_string() returns the value of the string in the packet and packet[1].get_int32_t() returns the value of the integer that represents the second data element. It is the filter developers responsibility to properly define the format of the data expected by and determine how to access respective elements. Appendix B, MRNET Data Elements contains the full listings of data types and accessor functions available to MRNet filter functions.

A filter function has the following signature

void filter_name(packets_in,  
 packets_out,  
 local_storage); 
std::vector<Packet> &  packets_in;
std::vector<Packet> &  packets_out;
void ** local_storage;

packets_in is the reference to a vector of packets serving as input to the filter function. packets_out is the reference to a vector into which output packets should be placed. local_storage may be used to define and maintain filter-instance specific state.

For each filter function defined in a shared object file, there must be a const char * symbol named by the string formed by the concatenation of the filter function name and the suffix "_format_string". For instance, if the filter function is named my_filter_func, the shared object must define a symbol const char *my_filter_func_format_string. The value of this string will be the MRNet format string describing the format of data that the filter can operate on. A value of "" denotes that the filter can operate on data of arbitrary value.

Creating and Using MRNet Filter Shared Object Files

This topic currently pertains to usage with the GNU C++ compiler only. We will update the topic to discuss using other compilers as well.

Since we use the C facility dlopen() to dynamically load new filter functions, all symbols to be exported this way must be "extern C'd". That is, the symbol definitions must fall with the statements

extern "C"{

and

}

The file that contains the filter functions and format strings may be compiled with the GNU compiler options "-fPIC -shared -rdynamic" to produce a valid shared object.

A front-end that will dynamically load filters must be built with the GNU compiler options "-Wl,-E" to notify the linker export global symbols externally.

Appendix A. MRNET Format Strings

Following the % character introducing a conversion there may be a number of flag characters. u, h, l, and a are special modifiers meaning unsigned, short, long and array, respectivley. The full set of conversions are:

cMatches a signed 8-bit character
ucMatches an unsigned 8-bit character
acMatches an array of signed 8-bit characters
aucMatches an array of unsigned 8-bit characters
hdMatches a signed 16-bit decimal integer
uhdMatches an unsigned 16-bit decimal integer
ahdMatches an array of signed 16-bit decimal integers
auhdMatches an array of unsigned 16-bit decimal integers
dMatches a signed 32-bit decimal integer
udMatches an unsigned 32-bit decimal integer
adMatches an array of signed 32-bit decimal integers
audMatches an array of unsigned 32-bit decimal integers
ldMatches a signed 64-bit decimal integer
uldMatches an unsigned 64-bit decimal integer
aldMatches an array of signed 64-bit decimal integers
auldMatches an array of unsigned 64-bit decimal integers
fMatches a 32-bit floating-point number
afMatches an array of 32-bit floating-point numbers
lfMatches a 64-bit floating-point number
alfMatches an array of 64-bit floating-point numbers
sMatches a null-terminated character string.
asMatches an array of null-terminated character strings.

Appendix B. MRNET Data Elements

Data TypeRead Accessor FunctionWrite Accessor Function
CHAR_Tchar get_char( )void set_char( char )
UCHAR_Tunsigned char get_char( )void set_char( unsigned char )
INT16_Tint16_t get_int16_t( )void set_int16_t( int16_t )
UINT16_Tuint16_t get_uint16_t( )void set_uint16_t( uint16_t )
INT32_Tint32_t get_int32_t( )void set_int32_t( int32_t )
UINT32_Tuint32_t get_uint32_t( )void set_uint32_t( uint32_t )
INT64_Tint64_t get_int64_t( )void set_int64_t( int64_t )
UINT64_Tuint64_t get_uint64_t( )void set_uint64_t( uint64_t )
FLOAT_Tfloat get_float( )void set_float( float )
DOUBLE_Tdouble get_double( )void set_double( double )
STRING_Tchar * get_string( )void set_string( char * )
*_ARRAY_Tvoid * get_array( DataType *, uint32_t * )void set_array( void *, DataType, uint32_t )

Appendix C. MRNET Event Types

EBADCONFIGConfiguration/Initialization Error
ESYSTEMFailed System/Library Call
EPACKINGFailure while packing/unpacking Packet data
EFMTSTRFormat string mismatch Error
EPROTOCOLInternal Protocol Error
UNKNOWN_EVENTUnknown Event

Appendix D. A Complete MRNet Example