5 /*! \page PageBaseConnection Connection
7 \section BaseConnectionOverview Overview
9 Connections are used to provide an abstract kommunikation layer for the
10 communication in a cluster system. The abstract framework provides functions
11 for architecture independen encoding, unicasting, multicast and
12 synchronisation. A concrete hardware is choosen by creating concrete
13 instances of connections through a connection factory. New hardware can be
14 integrated by adding new connection types to the factory. Currentliy there is
15 support for the following ethernet communication models.
19 * pipelined Stream Sockets
21 If somebody has access to infiniband or myrinet, it would be great to have
22 support for this networks.
24 In a cluster system often a huge amount of data has to be sent to a lot of
25 receivers. For example in OpenSG the change list has to be sent to all
26 rendering nodes in each frame. As there is a wide variety to do this best
27 with different networks, there is a special connection type that encapsulates
28 multipoint and single point connections.
30 Communication is the most critical point in clustering. This the
31 communication overhead has to be as small as possible. Because of this we do
32 no special encoding to guarantee that a receiver gets the data it expects.
33 For example if a sender sends Real32 values and a receiver reads Int32
34 values, this will not be detected by any mechanism of the communication
35 framework. So if you send data over a connection, the receiver must exactly
36 know how many data it has to read and in wich type the data is encoded. This
37 makes debugging of communications sometimes very difficult but the advantage
38 is that the available bandwidth is fully available for the data transfer.
40 There are two types of connections. A PointConnection is used to send and
41 receive with one communication endpoint. A GroupConnection is used to send
42 and receive from one or more communication endpoints. GroupConnections can be
43 used to multicast data simultaniously to many destinations. It is possible to
44 communicate between two PointConnections and between a GroupConnection and
45 many PointConnections.
47 \section BaseConnectionCreate Creating connections
49 A connection is created by the ConnectionFactory or by instanciating
50 concrete connection types. If the factory is used, then the type of
51 connection can be configured at runtime. Connections can be destroied
52 with the delete command.
55 GroupConnection *group = ConnectionFactory::the().createGroup("Multicast");
56 PointConnection *point = ConnectionFactory::the().createPoint("Multicast");
57 PointConnection *group = new GroupSockConnection();
58 PointConnection *point = new PointSockConnection();
61 \section BaseConnectionConnect Connecting
63 A connection is established with the connectPoint and connectGroup
64 method. This methos has two parameters. First is the address that identifies
65 the destination. The syntax of the addresse depends on the type of a
66 connection. Multicast, StreamSock and SockPipeline are using the format
69 Connecting two PointConnections:
72 Connection::Channel c = point.connectPoint("196.168.1.22:1234");
78 Connection::Channel c = point.acceptPoint();
84 Connecting tree PointConnections with one GroupConnection
87 if(point.connectGroup("196.168.1.22:1234") < 0)
91 if(point.connectGroup("196.168.1.22:1234") < 0)
95 if(point.connectGroup("196.168.1.22:1234") < 0)
100 Connection::Channel c;
101 if(point.acceptPoint() < 0)
103 if(point.acceptPoint() < 0)
105 if(point.acceptPoint() < 0)
109 Connecting one GroupConnection with tree PointConnections
113 if(point.acceptGroup() < 0)
118 if(point.acceptGroup() < 0)
123 if(point.acceptGroup() < 0)
128 Connection::Channel c;
129 // wait a maximum of 40 seconds for each connection
130 if(point.connectPoint("196.168.1.30:1234",40) < 0)
132 if(point.connectPoint("196.168.1.31:1234",40) < 0)
134 if(point.connectPoint("196.168.1.32:1234",40) < 0)
138 All methods that establish a connection return a Channel id or -1 on
139 error. Channel ids can be used in GroupConnections to distinguish incomming
142 \section BaseConnectionData Data transmission
144 Data is transferred with putValue and getValue. Per default data is buffered
145 and will be sent if the buffer is full or the flush method is called. As a
146 connection can be connected to more then one endpoint, a source has to be
147 selected with selectChannel. After a channel is selected, only data from this
148 channel is processed by getValue and getValues.
154 connection->putValue(count);
155 connection->putValues(values,100);
158 connection->selectChannel();
159 connection->getValue(count);
160 connection->getValues(values,100);
163 putValue, putValues, getValue and getValues are doing a network byte order
164 encoding if both endpoints are based on different architectures. This can be
165 switched off if a homogenious cluster is used.
168 connection->setNetworkOrder(false);
171 By default a connection tries to minimize the number of data that is
172 copyied. To do this, for lage memory blocks only a tag is written in the
173 output buffer. If the buffer is full or flush is called, then first the
174 buffer is send and afterwards the large memory blocks. Thise technique
175 provides buffering for mall data blocks and unbufferd transmission for large
176 blocks. This is very efficient and works fine as long as the data is not
177 modified between putValue and the actual data transmission. If this can not
178 be guaranteed, then a copy operation can be forced. This option must be set
179 by both communication endpoints.
182 connection->forceCopy();
185 In forceCopy mode the whole data is bufferd. In contrast an unbuffered mode
186 can be enabled with forceDirectIO method.
189 connection->forceDirectIO();
192 It is not possible to change the transmission mode for connected Connections.
194 \section BaseConnectionReadMany Reading from many sources
196 Sometimes it is important to read some data exactly once from each endpoint
197 of a GroupConnection. To do this a selection mechanism is available.
200 Connection::Channel channel;
201 while(group->getSelectionCount() > 0)
203 channel = mConnection->selectChannel();
204 group->getValue(result); // Getting data
205 group->subSelection(channel);
207 mConnection->resetSelection();
210 \section BaseConnectionSync Synchronisation
212 In a cluster environment it is often neccessary to synchronize two ore more
213 nodes. To do this sync and wait operations are available.
230 \section BaseConnectionInterface Selecting an Interface
232 The bind method of a connection binds a connection to a hardware ressource.
233 If more then one ressource is available, then you have to define the
234 interface on which incomming connections are expected. This is done mit the
238 connectionA->setInterface("196.168.10.22");
239 connectionB->setInterface("134.213.21.11");
241 // accept from network 1
242 connectionA->bind(":1234");
243 connectionA->accept();
245 // accept from network 2
246 connectionB->bind(":1234");
247 connectionB->accept();
250 \section BaseConnectionDestination Setting the Multicast address
252 If a group connection is based on a hardware that is able to do multicast,
253 then the destination address is used to selection a multicast channel of the
254 network layer. For ethernet this is the multicast address.
257 group->setDestination("237.32.12.22");
259 if(group->acceptPoint() < 0)