1 <!-- ##### SECTION ./tmpl/DataDesc.sgml:Long_Description ##### -->
2 <para>In order to allow GRAS to send data over the network (or simply to
3 dupplicate it in SG), you have to describe the structure of data attached
4 with each message. This mecanism is stolen from NWS message passing
7 <para>For each message, you have to declare a structure representing the
8 data to send as payload with the message.</para>
11 <title>Sending (or receiving) simple structures</title>
12 <para>Let's imagin you want to declare a <command>STORE_STATE</command>
13 message, which will send some data to the memory server for inclusion in
14 the database. Here is the structure we want to send:</para>
18 char id[STATE_NAME_SIZE];
26 <para>And here is the structure description GRAS needs to be able to send
27 this over the network:</para>
30 const static DataDescriptor stateDescriptor[] =
31 {SIMPLE_MEMBER(CHAR_TYPE, STATE_NAME_SIZE, offsetof(struct state, id)),
32 SIMPLE_MEMBER(INT_TYPE, 1, offsetof(struct state, rec_size)),
33 SIMPLE_MEMBER(INT_TYPE, 1, offsetof(struct state, rec_count)),
34 SIMPLE_MEMBER(DOUBLE_TYPE, 1, offsetof(struct state, seq_no)),
35 SIMPLE_MEMBER(DOUBLE_TYPE, 1, offsetof(struct state, time_out))};
38 <para>Contrary to what one could think when you first see it, it's pretty
39 easy. A structure descriptor is a list of descriptions, describing each
40 field of the structure. For example, for the first field, you say that
41 the base type is <command>CHAR_TYPE</command>, that there is
42 <command>STATE_NAME_SIZE</command> element of this type and that it's
43 position in the structure is computed by <command>offsetof(struct state,
44 id)</command>. This leads to two remarks:</para>
48 <para>it's impossible to send dynamic sized strings that way. It's a
49 known limitation, but I think we can live with it.</para>
52 <para>Yes, the <command>offsetof(struct state, id)</command>
53 construction is C ANSI and is portable.</para>
59 <title>Sending (or receiving) complex structure</title>
60 <para>How to send non-flat structures, do you ask? It's not harder. Let's
61 imagin you want to send the following structure:</para>
65 unsigned long address;
70 char name[MAX_CLIQUE_NAME_SIZE];
73 char skill[MAX_SKILL_SIZE];
74 char options[MAX_OPTIONS_SIZE];
77 CliqueMember members[MAX_MEMBERS];
83 <para>As you can see, this structure contains an array of another user
84 defined structure. To be able to send <command>struct Clique</command>,
85 you have to describe each structures that way:</para>
88 static const DataDescriptor cliqueMemberDescriptor[] =
89 {SIMPLE_MEMBER(UNSIGNED_LONG_TYPE, 1, offsetof(CliqueMember, address)),
90 SIMPLE_MEMBER(UNSIGNED_LONG_TYPE, 1, offsetof(CliqueMember, port))};
92 static const DataDescriptor cliqueDescriptor[] =
93 {SIMPLE_MEMBER(CHAR_TYPE, MAX_CLIQUE_NAME_SIZE, offsetof(Clique, name)),
94 SIMPLE_MEMBER(DOUBLE_TYPE, 1, offsetof(Clique, whenGenerated)),
95 SIMPLE_MEMBER(DOUBLE_TYPE, 1, offsetof(Clique, instance)),
96 SIMPLE_MEMBER(CHAR_TYPE, MAX_SKILL_SIZE, offsetof(Clique, skill)),
97 SIMPLE_MEMBER(CHAR_TYPE, MAX_OPTIONS_SIZE, offsetof(Clique, options)),
98 SIMPLE_MEMBER(DOUBLE_TYPE, 1, offsetof(Clique, period)),
99 SIMPLE_MEMBER(DOUBLE_TYPE, 1, offsetof(Clique, timeOut)),
100 {STRUCT_TYPE, MAX_MEMBERS, offsetof(Clique, members),
101 (DataDescriptor *)&cliqueMemberDescriptor, cliqueMemberDescriptorLength,
102 PAD_BYTES(CliqueMember, port, unsigned long, 1)},
103 SIMPLE_MEMBER(UNSIGNED_INT_TYPE, 1, offsetof(Clique, count)),
104 SIMPLE_MEMBER(UNSIGNED_INT_TYPE, 1, offsetof(Clique, leader))};
107 <para>So, even if less natural, it is possible to send structures
108 containing structures with these tools.</para>
110 <para>You can see that it's not only impossible to send dynamic-sized
111 strings, it impossible to send dynamic-sized arrays. Here,
112 <command>MAX_MEMBERS</command> is the maximum of members a clique can
113 contain. In NWS, this value is defined to 100. <warning><para>I'm not
114 sure, but I think that all the 100 values are sent each time, even if
115 there is only 3 non-null members. Yes, that's
116 bad.</para></warning></para>
118 <warning><para>The DataDescriptor_t MUST be const. Malloc'ing them and
119 then casting them on argument passing IS NOT OK. This is because we get
120 the number of elements in the array with the sizeof(dd)/sizeof(dd[0]).
125 <!-- ##### SECTION ./tmpl/DataDesc.sgml:See_Also ##### -->
131 <!-- ##### SECTION ./tmpl/DataDesc.sgml:Short_Description ##### -->
135 <!-- ##### SECTION ./tmpl/DataDesc.sgml:Title ##### -->
139 <!-- ##### SECTION ./tmpl/ErrLog.sgml:Long_Description ##### -->
145 <!-- ##### SECTION ./tmpl/ErrLog.sgml:See_Also ##### -->
151 <!-- ##### SECTION ./tmpl/ErrLog.sgml:Short_Description ##### -->
155 <!-- ##### SECTION ./tmpl/ErrLog.sgml:Title ##### -->
159 <!-- ##### SECTION ./tmpl/Socks.sgml:Long_Description ##### -->
165 <!-- ##### SECTION ./tmpl/Socks.sgml:See_Also ##### -->
171 <!-- ##### SECTION ./tmpl/Socks.sgml:Short_Description ##### -->
175 <!-- ##### SECTION ./tmpl/Socks.sgml:Title ##### -->
179 <!-- ##### SECTION ./tmpl/comm_dd_cbps.sgml:Long_Description ##### -->
185 <!-- ##### SECTION ./tmpl/comm_dd_cbps.sgml:See_Also ##### -->
191 <!-- ##### SECTION ./tmpl/comm_dd_cbps.sgml:Short_Description ##### -->
195 <!-- ##### SECTION ./tmpl/comm_dd_cbps.sgml:Title ##### -->
196 Data description callbacks persistant state
199 <!-- ##### SECTION ./tmpl/config.sgml:Long_Description ##### -->
205 <!-- ##### SECTION ./tmpl/config.sgml:See_Also ##### -->
211 <!-- ##### SECTION ./tmpl/config.sgml:Short_Description ##### -->
215 <!-- ##### SECTION ./tmpl/config.sgml:Title ##### -->
219 <!-- ##### SECTION ./tmpl/dd_cbps.sgml:Long_Description ##### -->
225 <!-- ##### SECTION ./tmpl/dd_cbps.sgml:See_Also ##### -->
231 <!-- ##### SECTION ./tmpl/dd_cbps.sgml:Short_Description ##### -->
235 <!-- ##### SECTION ./tmpl/dd_cbps.sgml:Title ##### -->
236 Data description callbacks persistant state
239 <!-- ##### SECTION ./tmpl/dico.sgml:Long_Description ##### -->
245 <!-- ##### SECTION ./tmpl/dico.sgml:See_Also ##### -->
251 <!-- ##### SECTION ./tmpl/dico.sgml:Short_Description ##### -->
255 <!-- ##### SECTION ./tmpl/dico.sgml:Title ##### -->
259 <!-- ##### SECTION ./tmpl/dynar.sgml:Long_Description ##### -->
261 This module provide the quite usual dynamic array facility.
265 <!-- ##### SECTION ./tmpl/dynar.sgml:See_Also ##### -->
271 <!-- ##### SECTION ./tmpl/dynar.sgml:Short_Description ##### -->
275 <!-- ##### SECTION ./tmpl/dynar.sgml:Title ##### -->
279 <!-- ##### SECTION ./tmpl/gras-overview.sgml:Long_Description ##### -->
280 <para>This document introduce the GRAS library (<emphasis>Grid Reality
281 And Simulation</emphasis>, or according to my english dictionary,
282 <emphasis>Generally Recognized As Safe</emphasis> ;).</para>
285 <title>Overview</title>
286 <para>The purpose of the GRAS is to allow the developpement of
287 distributed programs which will work with as few as possible
288 modification both on the SimGrid simulator (SG), and in the Real Life
291 <para>Here are the problems when you want to do so:
294 <para>Communication in SG is done by passing tasks, while in
295 RL, you have to deal with sockets (or any wrapper to it).</para>
297 <listitem><para>In RL, each process should provide a main()
298 function, and it's obviously not the case in SG.</para>
304 <title>Application class target</title>
305 <para>If you want to run your code both in RL and in SG, you won't be
306 able to use the full set of features offered by any of those two
307 worlds. GRAS tries to provide a suffisent set of features to develop
308 your application, and implement them in both worlds.</para>
310 <para>GRAS uses the paradigm of <emphasis>event-driven
311 programming</emphasis>, which is an extension to the message-passing
312 one. Any process of a typical event-driven application declares
313 callback to incoming events, which can be messages from other
314 processes, timers or others.</para>
316 <para>All messages have an header, specifying its type, and attached
317 data, represented as one or several C structures. In order to send
318 the data over the network in RL, a type-description mecanism is
319 provided, and the RL version of GRAS implements CDR
320 functionnalities. That is to say that the data are sent in the native
321 format of the sender host, and converted on the destination host only
324 <para>In order to not reimplement the wheel, GRAS use existing code,
325 and adapt them to make them work together. The SG version naturally
326 use the SimGrid toolkit, while the RL version is based over the
327 communication library used in NWS (note that this library was somehow
328 modified, since the previous version use XDR, ie both the sender and
329 the receiver convert the data from/to a so called network
330 format). That's why some basic knowledge about how NWS work is
331 supposed in this document. But don't worry, you only have to know the
332 basics about NWS, the internals needed to understand the document
333 will be presented when needed.</para>
337 <!-- ##### SECTION ./tmpl/gras-overview.sgml:See_Also ##### -->
343 <!-- ##### SECTION ./tmpl/gras-overview.sgml:Short_Description ##### -->
344 Overview of the GRAS library
347 <!-- ##### SECTION ./tmpl/gras-overview.sgml:Title ##### -->
351 <!-- ##### SECTION ./tmpl/gras.sgml:Long_Description ##### -->
357 <!-- ##### SECTION ./tmpl/gras.sgml:See_Also ##### -->
363 <!-- ##### SECTION ./tmpl/gras.sgml:Short_Description ##### -->
367 <!-- ##### SECTION ./tmpl/gras.sgml:Title ##### -->
371 <!-- ##### SECTION ./tmpl/nws_comm.sgml:Long_Description ##### -->
377 <!-- ##### SECTION ./tmpl/nws_comm.sgml:See_Also ##### -->
383 <!-- ##### SECTION ./tmpl/nws_comm.sgml:Short_Description ##### -->
387 <!-- ##### SECTION ./tmpl/nws_comm.sgml:Title ##### -->
391 <!-- ##### SECTION ./tmpl/trp_socks.sgml:Long_Description ##### -->
397 <!-- ##### SECTION ./tmpl/trp_socks.sgml:See_Also ##### -->
403 <!-- ##### SECTION ./tmpl/trp_socks.sgml:Short_Description ##### -->
407 <!-- ##### SECTION ./tmpl/trp_socks.sgml:Title ##### -->
411 <!-- ##### MACRO BEGIN_DECL ##### -->
417 <!-- ##### MACRO CCRITICAL0 ##### -->
425 <!-- ##### MACRO CCRITICAL1 ##### -->
434 <!-- ##### MACRO CCRITICAL2 ##### -->
444 <!-- ##### MACRO CCRITICAL3 ##### -->
455 <!-- ##### MACRO CCRITICAL4 ##### -->
467 <!-- ##### MACRO CCRITICAL5 ##### -->
480 <!-- ##### MACRO CDEBUG0 ##### -->
488 <!-- ##### MACRO CDEBUG1 ##### -->
497 <!-- ##### MACRO CDEBUG2 ##### -->
507 <!-- ##### MACRO CDEBUG3 ##### -->
518 <!-- ##### MACRO CDEBUG4 ##### -->
530 <!-- ##### MACRO CDEBUG5 ##### -->
543 <!-- ##### MACRO CERROR0 ##### -->
551 <!-- ##### MACRO CERROR1 ##### -->
560 <!-- ##### MACRO CERROR2 ##### -->
570 <!-- ##### MACRO CERROR3 ##### -->
581 <!-- ##### MACRO CERROR4 ##### -->
593 <!-- ##### MACRO CERROR5 ##### -->
606 <!-- ##### MACRO CINFO0 ##### -->
614 <!-- ##### MACRO CINFO1 ##### -->
623 <!-- ##### MACRO CINFO2 ##### -->
633 <!-- ##### MACRO CINFO3 ##### -->
644 <!-- ##### MACRO CINFO4 ##### -->
656 <!-- ##### MACRO CINFO5 ##### -->
669 <!-- ##### MACRO CLOG0 ##### -->
678 <!-- ##### MACRO CLOG1 ##### -->
688 <!-- ##### MACRO CLOG2 ##### -->
699 <!-- ##### MACRO CLOG3 ##### -->
711 <!-- ##### MACRO CLOG4 ##### -->
724 <!-- ##### MACRO CLOG5 ##### -->
738 <!-- ##### MACRO CLOG6 ##### -->
753 <!-- ##### MACRO CRITICAL0 ##### -->
760 <!-- ##### MACRO CRITICAL1 ##### -->
768 <!-- ##### MACRO CRITICAL2 ##### -->
777 <!-- ##### MACRO CRITICAL3 ##### -->
787 <!-- ##### MACRO CRITICAL4 ##### -->
798 <!-- ##### MACRO CRITICAL5 ##### -->
810 <!-- ##### FUNCTION CallAddr ##### -->
821 <!-- ##### FUNCTION CloseSocket ##### -->
830 <!-- ##### FUNCTION CreateLocalChild ##### -->
840 <!-- ##### FUNCTION DROP_SOCKET ##### -->
848 <!-- ##### FUNCTION DataSize ##### -->
858 <!-- ##### ENUM DataTypes ##### -->
871 @UNSIGNED_SHORT_TYPE:
875 <!-- ##### MACRO END_DECL ##### -->
881 <!-- ##### MACRO EODD ##### -->
887 <!-- ##### FUNCTION EstablishAnEar ##### -->
898 <!-- ##### ENUM FormatTypes ##### -->
906 <!-- ##### MACRO GRAS_LOG_MAYDAY ##### -->
912 <!-- ##### MACRO GRAS_LOG_ROOT_CAT ##### -->
918 <!-- ##### MACRO HAVE_DLFCN_H ##### -->
924 <!-- ##### MACRO HAVE_INTTYPES_H ##### -->
930 <!-- ##### MACRO HAVE_LIBPTHREAD ##### -->
936 <!-- ##### MACRO HAVE_MEMORY_H ##### -->
942 <!-- ##### MACRO HAVE_STDINT_H ##### -->
948 <!-- ##### MACRO HAVE_STDLIB_H ##### -->
954 <!-- ##### MACRO HAVE_STRINGS_H ##### -->
960 <!-- ##### MACRO HAVE_STRING_H ##### -->
966 <!-- ##### MACRO HAVE_SYS_STAT_H ##### -->
972 <!-- ##### MACRO HAVE_SYS_TYPES_H ##### -->
978 <!-- ##### MACRO HAVE_UNISTD_H ##### -->
984 <!-- ##### TYPEDEF IPAddress ##### -->
990 <!-- ##### FUNCTION IPAddressImage ##### -->
998 <!-- ##### FUNCTION IPAddressImage_r ##### -->
1006 <!-- ##### FUNCTION IPAddressMachine ##### -->
1014 <!-- ##### FUNCTION IPAddressMachine_r ##### -->
1022 <!-- ##### MACRO IPAddressValue ##### -->
1030 <!-- ##### FUNCTION IPAddressValues ##### -->
1040 <!-- ##### FUNCTION IncomingRequest ##### -->
1050 <!-- ##### FUNCTION IsOkay ##### -->
1058 <!-- ##### FUNCTION IsPipe ##### -->
1066 <!-- ##### MACRO IsValidIP ##### -->
1073 <!-- ##### MACRO LOG6 ##### -->
1087 <!-- ##### FUNCTION MyMachineName ##### -->
1094 <!-- ##### MACRO NO_SOCKET ##### -->
1100 <!-- ##### FUNCTION NotifyOnDisconnection ##### -->
1107 <!-- ##### FUNCTION OpenClientSocket ##### -->
1117 <!-- ##### FUNCTION OpenServerSocket ##### -->
1128 <!-- ##### MACRO PACKAGE ##### -->
1134 <!-- ##### MACRO PACKAGE_BUGREPORT ##### -->
1140 <!-- ##### MACRO PACKAGE_NAME ##### -->
1146 <!-- ##### MACRO PACKAGE_STRING ##### -->
1152 <!-- ##### MACRO PACKAGE_TARNAME ##### -->
1158 <!-- ##### MACRO PACKAGE_VERSION ##### -->
1164 <!-- ##### MACRO PAD_BYTES ##### -->
1174 <!-- ##### FUNCTION PassSocket ##### -->
1183 <!-- ##### FUNCTION Peer ##### -->
1191 <!-- ##### FUNCTION PeerName ##### -->
1199 <!-- ##### FUNCTION PeerName_r ##### -->
1207 <!-- ##### MACRO SIMPLE_DATA ##### -->
1215 <!-- ##### MACRO SIMPLE_MEMBER ##### -->
1224 <!-- ##### MACRO STDC_HEADERS ##### -->
1230 <!-- ##### TYPEDEF Socket ##### -->
1236 <!-- ##### FUNCTION SocketFailure ##### -->
1243 <!-- ##### USER_FUNCTION SocketFunction ##### -->
1250 <!-- ##### FUNCTION SocketInUse ##### -->
1258 <!-- ##### FUNCTION SocketIsAvailable ##### -->
1266 <!-- ##### MACRO VERSION ##### -->
1272 <!-- ##### USER_FUNCTION grasCallbackFunction ##### -->
1281 <!-- ##### FUNCTION grasCloseSocket ##### -->
1289 <!-- ##### FUNCTION grasDataDescCmp ##### -->
1301 <!-- ##### FUNCTION grasDataDescCount ##### -->
1309 <!-- ##### FUNCTION grasDataRecv ##### -->
1317 @description_length:
1321 <!-- ##### FUNCTION grasDataSend ##### -->
1329 @description_length:
1333 <!-- ##### FUNCTION grasDataSize ##### -->
1342 <!-- ##### ENUM grasError_t ##### -->
1357 <!-- ##### FUNCTION grasLock ##### -->
1364 <!-- ##### TYPEDEF grasMessageType_t ##### -->
1370 <!-- ##### FUNCTION grasMsgDiscard ##### -->
1378 <!-- ##### FUNCTION grasMsgEntryGet ##### -->
1386 <!-- ##### TYPEDEF grasMsgEntry_t ##### -->
1392 <!-- ##### FUNCTION grasMsgFree ##### -->
1399 <!-- ##### FUNCTION grasMsgHandle ##### -->
1406 <!-- ##### FUNCTION grasMsgHeaderNew ##### -->
1416 <!-- ##### FUNCTION grasMsgNew ##### -->
1427 <!-- ##### FUNCTION grasMsgRegister ##### -->
1438 <!-- ##### FUNCTION grasMsgSend ##### -->
1449 <!-- ##### FUNCTION grasMsgWait ##### -->
1461 <!-- ##### FUNCTION grasMyMachineName ##### -->
1468 <!-- ##### FUNCTION grasOpenClientSocket ##### -->
1478 <!-- ##### FUNCTION grasOpenServerSocket ##### -->
1488 <!-- ##### MACRO grasPROTOCOL ##### -->
1494 <!-- ##### FUNCTION grasPeerGetAddress ##### -->
1502 <!-- ##### FUNCTION grasPeerGetName ##### -->
1510 <!-- ##### FUNCTION grasRecvData ##### -->
1520 <!-- ##### FUNCTION grasRegisterCallback ##### -->
1529 <!-- ##### FUNCTION grasSendData ##### -->
1539 <!-- ##### FUNCTION grasUnlock ##### -->
1546 <!-- ##### FUNCTION grasUserdataGet ##### -->
1552 <!-- ##### MACRO grasUserdataNew ##### -->
1559 <!-- ##### FUNCTION grasUserdataSet ##### -->
1566 <!-- ##### FUNCTION gras_datadesc_cmp ##### -->
1579 <!-- ##### FUNCTION gras_datadesc_copy_data ##### -->
1588 <!-- ##### FUNCTION gras_dict_cursor_next ##### -->
1596 <!-- ##### FUNCTION gras_dynar_first ##### -->
1605 <!-- ##### FUNCTION gras_dynar_next ##### -->
1615 <!-- ##### FUNCTION gras_lock ##### -->
1622 <!-- ##### FUNCTION gras_log_parent_set ##### -->
1630 <!-- ##### FUNCTION gras_log_threshold_set ##### -->
1638 <!-- ##### FUNCTION gras_sock_client_open ##### -->
1648 <!-- ##### FUNCTION gras_sock_close ##### -->
1656 <!-- ##### FUNCTION gras_sock_get_peer_addr ##### -->
1664 <!-- ##### FUNCTION gras_sock_get_peer_name ##### -->
1672 <!-- ##### FUNCTION gras_sock_server_open ##### -->
1682 <!-- ##### FUNCTION gras_socket_peer_name ##### -->
1690 <!-- ##### FUNCTION gras_unlock ##### -->