|
|
||||||
|
Classes |
Public Member Functions |
Protected Member Functions |
Protected Attributes |
Friends |
List of all members
faudes::nDevice Class Reference Detailed DescriptionAn nDevice implements networked IO via a simple TCP/IP protocol. NetworkingThe 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:
In their server role, each node is configured to listen on its server port for incomming TCP connections. When a client (i.e. 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 event on the node, this is notified to all connected clients and the clients will interpret the event as an input reading. Vice versa, the each node itself has the role of a client and subscribes to relevant output events served by other nodes in their server role. Protocol DetailsThe 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 connected clients in the format
A minimal alternative implementation for a node consists of (1) a TCP server that ignores all incomming messages and issues event notifications to any relevant events; and, (2) a TCP client that subscribes to all events and then listens to event notifications. All other commands are optional and may change in future revisions of this protocol. Name ResolutionOn 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. By default, UDP broadcasts are addressed to 255.255.255.255:40000. Since routers are not meant to pass-on broadcasts, nDevice name resolution is restricted to one subnet. If the local host is connected to multiple subnets, you need to specify the relevant subset explicitly by setting the appropriate broadcast address, e.g. 192.168.2.255:40000. To restrict networks to the local machine, set the broadcast address to the loopback device 127.0.0.1:40000. To span a network accross multiple subnets, server addresses can be explicitly specified as an attribute in the node configuration; e.g.
File IOFor token IO, the nDevice reads and writes a section with label <SimplenetDevice name="SimpleMachine">
<!-- Time scale in ms/ftiu -->
<TimeScale value="1000"/>
<!-- IP address of this node, incl. server TCP port -->
<ServerAddress value="localhost:40000"/>
<!-- Broadcaset address for node resolution (optional)
<BroadcastAddress value="255.255.255.255:40000"/>
<!-- Network topology -->
<Network name="SimpleLoop">
<Node name="SimpleMachine"/>
<Node name="SimpleSupervisor"/>
</Network>
<!-- Event configuration -->
<EventConfiguration>
<Event name="alpha" iotype="input"/>
<Event name="beta" iotype="output"/>
<Event name="mue" iotype="output"/>
<Event name="lambda" iotype="input"/>
</EventConfiguration>
</SimplenetDevice>
void BroadcastAddress(const std::string &rAddr) Set broadcast address for address resolution Note: you can only set the broadcast address while the d... Definition: iop_simplenet.cpp:308 void ServerAddress(const std::string &rAddr) Set server address of this node. Definition: iop_simplenet.cpp:302 Implementation NotesThe 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 435 of file iop_simplenet.h.
Constructor & Destructor Documentation◆ nDevice()
Default constructor. Definition at line 265 of file iop_simplenet.cpp. ◆ ~nDevice()
Explicit destructor. Definition at line 283 of file iop_simplenet.cpp. Member Function Documentation◆ BroadcastAddress()
Set broadcast address for address resolution Note: you can only set the broadcast address while the device is down.
Definition at line 308 of file iop_simplenet.cpp. ◆ Clear()
Clear all configuration. This implies Stop(). Reimplemented from faudes::vDevice. Definition at line 292 of file iop_simplenet.cpp. ◆ ClearNodes()
Add a node to the network configuration. Note: you can only configure the network while the device is down. Definition at line 333 of file iop_simplenet.cpp. ◆ Compile()
Set up internal data structures. Reimplemented from faudes::vDevice. Definition at line 358 of file iop_simplenet.cpp. ◆ DoReadPreface()
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.
Reimplemented from faudes::vDevice. Definition at line 399 of file iop_simplenet.cpp. ◆ DoWritePreface()
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.
Reimplemented from faudes::vDevice. Definition at line 367 of file iop_simplenet.cpp. ◆ InsInputEvent()
Insert event as input event. Note: you can only configure events while the device is down.
Definition at line 339 of file iop_simplenet.cpp. ◆ InsNode()
Add a node to the network configuration. Note: you can only configure the network while the device is down.
Definition at line 321 of file iop_simplenet.cpp. ◆ InsNodeAddress()
Add entry to node name resolution. Note: you can only configure the network while the device is down.
Definition at line 327 of file iop_simplenet.cpp. ◆ InsOutputEvent()
Insert event as output event. Note: you can only configure event while the device is down.
Definition at line 348 of file iop_simplenet.cpp. ◆ NetworkName()
Set network name to participate. Note: you can only set the network name while the device is down.
Definition at line 315 of file iop_simplenet.cpp. ◆ Reset()
Reset device. Resets buffered input events and current time. Reimplemented from faudes::vDevice. Definition at line 1275 of file iop_simplenet.cpp. ◆ ServerAddress()
Set server address of this node. Note: you can only set th server address while the device is down.
Definition at line 302 of file iop_simplenet.cpp. ◆ Start()
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.
Reimplemented from faudes::vDevice. Definition at line 536 of file iop_simplenet.cpp. ◆ Stop()
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 634 of file iop_simplenet.cpp. ◆ WriteOutput()
Run output command.
Implements faudes::vDevice. Definition at line 485 of file iop_simplenet.cpp. Friends And Related Function Documentation◆ NDeviceListen
Definition at line 677 of file iop_simplenet.cpp. ◆ NDeviceReply
◆ NDeviceServer
Member Data Documentation◆ mBroadcastAddress
Simplenet: address for udp broadcast (255.255.255.255:40000. Definition at line 640 of file iop_simplenet.h. ◆ mBroadcastSocket
Background: udp broadcast socket (background only) Definition at line 664 of file iop_simplenet.h. ◆ mEffectiveListenAddress
Simplenet: effective address of my server port. Definition at line 643 of file iop_simplenet.h. ◆ mInputServerStates
Background: connection states to event servers (by node name) Definition at line 687 of file iop_simplenet.h. ◆ mInputSubscriptions
Compiled data: map subscriptions. Definition at line 649 of file iop_simplenet.h. ◆ mListenAddress
Simplenet: address of my server incl port (localhost:40000) Definition at line 637 of file iop_simplenet.h. ◆ mListenSocket
Background: server socket to listen (background only) Definition at line 661 of file iop_simplenet.h. ◆ mMutex
Background: mutex for below shared variables. Definition at line 652 of file iop_simplenet.h. ◆ mNetwork
Simplenet: network id. Definition at line 634 of file iop_simplenet.h. ◆ mNetworkNodes
Simplenet: list of nodes in this network incl default addresses. Definition at line 646 of file iop_simplenet.h. ◆ mOutputClientStates
Background: map sockets to connection states (shared) Definition at line 675 of file iop_simplenet.h. ◆ mStopListen
Background: request to join via flag (mutexed) Definition at line 658 of file iop_simplenet.h. ◆ mThreadListen
Background: thread handle (global) Definition at line 655 of file iop_simplenet.h. ◆ pConfiguration
Overall configuration (with actual type) Definition at line 631 of file iop_simplenet.h. The documentation for this class was generated from the following files: libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen |