About
User Reference
C++ API
luafaudes
Developer
Links
libFAUDES online
libFAUDES

Sections

Index

faudes::nDevice Class Reference
[IO Device PlugIn]

An nDevice implements networked IO via a simple tcp/ip protocol. More...

#include <iop_simplenet.h>

List of all members.

Classes

struct  ClientState
 Background: state of a connection to a client (shared). More...
struct  ServerState
 Background: state of a connection to an event server (shared). More...

Public Member Functions

 nDevice (void)
 Default constructor.
virtual ~nDevice (void)
 Explicit destructor.
virtual void Clear (void)
 Clear all configuration.
virtual void Compile (void)
 Set up internal data structures.
void InsertNodeAddress (const std::string &rNode, const SimplenetAddress &rAddress)
 Add entry to node name resolution.
virtual void Start (void)
 Activate the device.
virtual void Stop (void)
 Deactivate the device.
virtual void Reset (void)
 Reset device.
virtual void WriteOutput (Idx output)
 Run output command.

Protected Member Functions

virtual void DoReadPreface (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Actual method to read device configuration from tokenreader.
virtual void DoWritePreface (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Actual method to write the device configuration to a TokenWriter.

Protected Attributes

TaNameSet
< AttributeSimplenetEvent > * 
pConfiguration
 Overall configuration (with actual type).
std::string mNetwork
 Simplenet: network id.
SimplenetAddress mAddress
 Simplenet: address of my server port.
SimplenetAddress mEffectiveAddress
 Simplenet: effective address of my server port.
std::set< std::string > mNetworkNodes
 Simplenet: list of nodes in this network.
std::set< std::string > mInputServers
 Simplenet: list of event server addresses.
std::map< std::string, EventSetmInputSubscriptions
 Compiled data: map subscriptions.
pthread_mutex_t mMutex
 Background: mutex for below shared variables.
pthread_t mThreadListen
 Background: thread handle (global).
bool mStopListen
 Background: request to join via flag (mutexed).
int mServerSocket
 Background: server socket to listen (background only).
struct sockaddr_in mServerAddress
 Background: server port to bind (background only).
int mBroadcastSocket
 Background: udp broadcast socket (background only).
std::map< int, ClientStatemOutputClientStates
 Background: map sockets to connection states (shared).
std::map< std::string,
ServerState
mInputServerStates
 Background: connection states to event servers (by node name).

Friends

void * NDeviceListen (void *)
void * NDeviceServer (void *)
void * NDeviceReply (void *)

Detailed Description

An nDevice implements networked IO via a simple tcp/ip protocol.

Networking

The purpose of this implementation of networked discrete events is to provide a basis for case studies. However, simple networked events via nDevice must not be confused with ongoing research that addresses synchronisation and real time behaviour. We take a really pragmatic approach here.

Our network is identified by its network name. It consists a number of nodes, each identified by its node name. In the current implementation, each node knows about the entire network ie knows about all other nodes. Each node plays two roles:

  • the server role to send event notifications, and
  • the client role to receive event notifications.

As a server, the node is configured to listen on its server port for incomming tcp connections. When a client (eg some other node in client role) connects to the tcp port, the server replies to a simple command set in order to allow the client to subscribe to the nodes output events. When the application executes an output on the node, this is notified to all connected clients and the clients will interpret the event as a input reading. Vice versa, the node itself has the role of a client and subscribes its input events from all other nodes.

Protocol Details

The protocol for commands and notification is libFAUDES-token based and can be inspected eg via nc or telnet; see the shell script in the tutorial. Event notifications are sent spontaneous to all subscribing nodes in the format <Notify> "event" </Notify>. Commands are accepted in the format <Cmd> "command" </Cmd> and will be answered accordingly.

Command on tcp server port Reply
<Cmd> "Info" </Cmd> Configuration of node as token string
<Cmd> "Status" </Cmd> Up/StartUop/Down/ShutDown
<Cmd> "ResetRequest" </Cmd> acknowledge
<Subscribe> "ev1" ... "evN" </Subscribe> Positive Acknowledge to accept subscription of events

Name Resolution

On the technical side, each node needs to figure the ip addresses incl tcp ports on which the other nodes provide their service. To ease configuration, this information is distributed by udp datagrams. In order to locate the other nodes within the network, a node may broadcasts a network request datagramm. Each node that receives such a request, replies with an advert datagramm to provide its address. Thus, the simple net nodes rely on some underlying name resolution by dns services, but node configuration itself refers to simple-net node names only. Since each node knows about the names of all participating nodes, each node will know when all connections are up.

Broadcast on simplenet udp port Reply
<Request> "network" </Request> Advertisement of networkname, nodename and ip-address:port

File IO

For token IO, the nDevice reads and writes a section with label "SimplenetDevice". There are no relevant attributes yet. Simple machine example:

 <SimplenetDevice>

 "simplemachine"     % node id
 1000                % time scale (ms/ftu)
 "localhost:40000"   % server tcp port 
 "simpleloop"        % network id

 <Network>           
 "simplemachine"     % other nodes ..,
 "simplesupervisor"  % ... in this network
 </Network>

 <SimplenetEvents>
 "alpha"  <Input></Input>
 "beta"   <Output></Output>
 "mue"    <Output></Output>
 "lambda" <Input></Input>
 </SimplenetEvents>

 </SimplenetDevice>

Implementation Notes

The current status of the code is premature; network io assumes reasonably large buffers; thread/select mechanism is inefficient; exception handling wont work; etc etc

Definition at line 416 of file iop_simplenet.h.


Constructor & Destructor Documentation

faudes::nDevice::nDevice ( void   ) 

Default constructor.

Definition at line 283 of file iop_simplenet.cpp.

faudes::nDevice::~nDevice ( void   )  [virtual]

Explicit destructor.

Definition at line 300 of file iop_simplenet.cpp.


Member Function Documentation

void faudes::nDevice::Clear ( void   )  [virtual]

Clear all configuration.

This implies Stop().

Reimplemented from faudes::vDevice.

Definition at line 309 of file iop_simplenet.cpp.

void faudes::nDevice::Compile ( void   )  [virtual]

Set up internal data structures.

Reimplemented from faudes::vDevice.

Definition at line 337 of file iop_simplenet.cpp.

void faudes::nDevice::DoReadPreface ( TokenReader rTr,
const std::string &  rLabel = "",
const Type pContext = 0 
) [protected, virtual]

Actual method to read device configuration from tokenreader.

This method calls the base class to read the device name and the the timescale. It then reads address, networkid and nodes. Overall device configuration is consists of DoReadPreface, DoReadConfiguration and Compile. It isimplemented in vDevice. The label and context parameters are ignored.

Parameters:
rTr TokenReader to read from
rLabel Section to read
pContext Read context to provide contextual information
Exceptions:
Exception 
  • IO error (id 1)

Reimplemented from faudes::vDevice.

Definition at line 370 of file iop_simplenet.cpp.

void faudes::nDevice::DoWritePreface ( TokenWriter rTw,
const std::string &  rLabel = "",
const Type pContext = 0 
) const [protected, virtual]

Actual method to write the device configuration to a TokenWriter.

This method calls the base class vDevice to write the device name and the time scale. It then writes network related data. The label and context parameters are ignored.

Parameters:
rTw Reference to TokenWriter
rLabel Label of section to write
pContext Read context to provide contextual information
Exceptions:
Exception 
  • IO errors (id 2)

Reimplemented from faudes::vDevice.

Definition at line 346 of file iop_simplenet.cpp.

void faudes::nDevice::InsertNodeAddress ( const std::string &  rNode,
const SimplenetAddress rAddress 
)

Add entry to node name resolution.

Parameters:
rNode Name of node to register
rAddress Address incl port

Definition at line 319 of file iop_simplenet.cpp.

void faudes::nDevice::Reset ( void   )  [virtual]

Reset device.

Resets buffered input events and current time.

Reimplemented from faudes::vDevice.

Definition at line 1129 of file iop_simplenet.cpp.

void faudes::nDevice::Start ( void   )  [virtual]

Activate the device.

This function enables output execution and input reading. It starts the background thread for incomming connections and tries to connect to relevant servers.

Exceptions:
Exception 
  • Not yet configured (id 551)
  • Fatal network error (id 553)
  • Fatal pthread error (id 554)

Reimplemented from faudes::vDevice.

Definition at line 475 of file iop_simplenet.cpp.

void faudes::nDevice::Stop ( void   )  [virtual]

Deactivate the device.

This function disables output execution and input reading. It stops the backhround thread to provide connections and disconnects from any servers.

Reimplemented from faudes::vDevice.

Definition at line 576 of file iop_simplenet.cpp.

void faudes::nDevice::WriteOutput ( Idx  output  )  [virtual]

Run output command.

Exceptions:
Exception 
  • unknown output event (id 65)

Implements faudes::vDevice.

Definition at line 431 of file iop_simplenet.cpp.


Friends And Related Function Documentation

void* NDeviceListen ( void *   )  [friend]
void* NDeviceReply ( void *   )  [friend]
void* NDeviceServer ( void *   )  [friend]

Member Data Documentation

Simplenet: address of my server port.

Definition at line 541 of file iop_simplenet.h.

Background: udp broadcast socket (background only).

Definition at line 571 of file iop_simplenet.h.

Simplenet: effective address of my server port.

Definition at line 544 of file iop_simplenet.h.

std::set<std::string> faudes::nDevice::mInputServers [protected]

Simplenet: list of event server addresses.

Definition at line 550 of file iop_simplenet.h.

std::map<std::string,ServerState> faudes::nDevice::mInputServerStates [protected]

Background: connection states to event servers (by node name).

Definition at line 593 of file iop_simplenet.h.

std::map<std::string,EventSet> faudes::nDevice::mInputSubscriptions [protected]

Compiled data: map subscriptions.

Definition at line 553 of file iop_simplenet.h.

pthread_mutex_t faudes::nDevice::mMutex [protected]

Background: mutex for below shared variables.

Definition at line 556 of file iop_simplenet.h.

std::string faudes::nDevice::mNetwork [protected]

Simplenet: network id.

Definition at line 538 of file iop_simplenet.h.

std::set<std::string> faudes::nDevice::mNetworkNodes [protected]

Simplenet: list of nodes in this network.

Definition at line 547 of file iop_simplenet.h.

Background: map sockets to connection states (shared).

Definition at line 582 of file iop_simplenet.h.

struct sockaddr_in faudes::nDevice::mServerAddress [protected]

Background: server port to bind (background only).

Definition at line 568 of file iop_simplenet.h.

Background: server socket to listen (background only).

Definition at line 565 of file iop_simplenet.h.

bool faudes::nDevice::mStopListen [protected]

Background: request to join via flag (mutexed).

Definition at line 562 of file iop_simplenet.h.

pthread_t faudes::nDevice::mThreadListen [protected]

Background: thread handle (global).

Definition at line 559 of file iop_simplenet.h.

Overall configuration (with actual type).

Definition at line 535 of file iop_simplenet.h.


The documentation for this class was generated from the following files:

libFAUDES 2.20d --- 2011.04.26 --- c++ source docu by doxygen