Reliable Multicast via NORM (NACK-Oriented Reliable Multicast) ******
- Filename: rel_mcast.h * Author: Alex Velazquez * Created: 2011-03-31 * Adjustable settings of the NORM protocol: ***************************
- Description: Var.name: Set with: * (coconfig + .cpp) * ------------------------------------------------------------— * Debug level debugLevel setDebugLevel(int) * Multicast address mcastAddr constructor (has default) * Multicast port mcastPort constructor (has default) * Multicast interface mcastIface constructor * MTU mtu setMTU(int) * TTL ttl setTTL(int) * Loopback behavior lback setLoopback(bool) * Group size groupSize server's constructor * Send buffer space sndBufferSpace setBufferSpace(unsigned int) * Receive buffer space rcvBufferSpace setBufferSpace(unsigned int) * Block size blockSize setBlocksAndParity(int,int) * Parity numParity setBlocksAndParity(int,int) * Max cache bytes txCacheSize setTxCacheBounds(int,int,int) * Min cache num txCacheMin setTxCacheBounds(int,int,int) * Max cache num txCacheMax setTxCacheBounds(int,int,int) * TX Rate txRate setTransferRate(int) * Backoff factor backoffFactor setBackoffFactor(double) * UDP sock.buff.size sockBufferSize setSockBufferSize(int) * Read timeout (sec) readTimeoutSec setTimeout(int) * Write timeout (ms) writeTimeoutMsec setTimeout(int) * Retry timeout (us) retryTimeout setRetryTimeout(int) * Max obj length (B) maxLength setMaxLength(int) * Example covise configuration file: **********************************
<?xml version="1.0"?>
<COCONFIG version="1" > <GLOBAL> <COVER> <MultiPC>
<SyncMode value="MULTICAST" >
<Multicast> <debugLevel value="0" > <mcastAddr value="224.223.222.221" > <mcastPort value="23232" > <mtu value="1500" > <ttl value="1" > <lback value="off" > <sndBufferSpace value="1000000" > <rcvBufferSpace value="1000000" > <blockSize value="4" > <numParity value="0" > <txCacheSize value="100000000" > <txCacheMin value="1" > <txCacheMax value="128" > <txRate value="1000" > <backoffFactor value="0.0" > <sockBufferSize value="512000" > <readTimeoutSec value="30" > <writeTimeoutMsec value="500" > <retryTimeout value="100" > <maxLength value="1000000" > </Multicast>
</MultiPC> </COVER> </GLOBAL> </COCONFIG> Creating server/client instances: ***********************************
1) Server (master):
Determine server's parameters int numClients = 1; // Number of clients char *addr = "224.223.222.221"; // Any Class-D IP address int port = 23232; // Any valid port number
Call server's constructor (could also call Rel_Mcast(true, numClients) for default addr/port) multicast = new Rel_Mcast(true, numClients, addr, port);
Set any non-default settings (advanced) e.g. multicast->setTimeout(1000); // Write timeout etc....
Initialize the server (may fail if the addr/port is invalid or in use) if (multicast->init() != Rel_Mcast::RM_OK) delete multicast;
Write a multicast message multicast->write_mcast("Testing 123", 12);
Clean up by calling destructor sleep(10); delete multicast;
2) Clients (slaves):
Determine client's parameters int clientID = 1; // Any integer greater than 0 and unique among clients char *addr = "224.223.222.221"; // Any Class-D IP address int port = 23232; // Any valid port number
Call client's constructor (could also call Rel_Mcast(clientID) to choose default addr/port) multicast = new Rel_Mcast(clientID, addr, port);
Set any non-default settings (advanced) e.g. multicast->setTimeout(20); // Read timeout etc....
Initialize the client (may fail if the addr/port is invalid or in use) if ( multicast->init() != Rel_Mcast::RM_OK ) delete multicast;
Receive an incoming multicast char *buffer = new char[12]; multicast->read_mcast(buffer, 12); printf("Received: %d\n", buffer);
Clean up by calling destructor delete multicast;