|
libFAUDES
Sections
Index
|
faudes::nDevice Class Reference
|
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, EventSet > | mInputSubscriptions |
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, ClientState > | mOutputClientStates |
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 *) |
An nDevice implements networked IO via a simple tcp/ip protocol.
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:
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.
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 |
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 |
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>
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.
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.
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.
rTr | TokenReader to read from | |
rLabel | Section to read | |
pContext | Read context to provide contextual information |
Exception |
|
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.
rTw | Reference to TokenWriter | |
rLabel | Label of section to write | |
pContext | Read context to provide contextual information |
Exception |
|
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.
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.
Exception |
|
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.
Exception |
|
Implements faudes::vDevice.
Definition at line 431 of file iop_simplenet.cpp.
void* NDeviceListen | ( | void * | ) | [friend] |
void* NDeviceReply | ( | void * | ) | [friend] |
void* NDeviceServer | ( | void * | ) | [friend] |
SimplenetAddress faudes::nDevice::mAddress [protected] |
Simplenet: address of my server port.
Definition at line 541 of file iop_simplenet.h.
int faudes::nDevice::mBroadcastSocket [protected] |
Background: udp broadcast socket (background only).
Definition at line 571 of file iop_simplenet.h.
SimplenetAddress faudes::nDevice::mEffectiveAddress [protected] |
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.
std::map<int, ClientState> faudes::nDevice::mOutputClientStates [protected] |
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.
int faudes::nDevice::mServerSocket [protected] |
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.
TaNameSet<AttributeSimplenetEvent>* faudes::nDevice::pConfiguration [protected] |
Overall configuration (with actual type).
Definition at line 535 of file iop_simplenet.h.
libFAUDES 2.18b --- 2010-12-17 --- c++ source docu by doxygen 1.6.3