RTI Connext Micro  Version 2.4.1.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
netio_address.h
1 /*
2  * FILE: netio_address.h - NETIO Address API
3  *
4  * Copyright 2012-2014 Real-Time Innovations, Inc.
5  *
6  * No duplications, whole or partial, manual or electronic, may be made
7  * without express written permission. Any such copies, or
8  * revisions thereof, must display this notice unaltered.
9  * This code contains trade secrets of Real-Time Innovations, Inc.
10  *
11  * Modification History
12  * --------------------
13  * 05may2014,tk MICRO-72 - Updated based on CR-232
14  * 25apr2012,tk Written
15  */
16 /*ci
17  * \file
18  * \brief NETIO Address API
19  * \defgroup NETIOAddressClass NETIO Address API
20  * \ingroup NETIOCommon
21  *
22  * \details
23  *
24  * This file contains functions to manipulate NETIO addresses.
25  */
26 /*ci \addtogroup NETIOAddressClass
27  * @{
28  */
29 #ifndef netio_address_h
30 #define netio_address_h
31 
32 #ifndef netio_dll_h
33 #include "netio/netio_dll.h"
34 #endif
35 #ifndef osapi_config_h
36 #include "osapi/osapi_config.h"
37 #endif
38 #ifndef osapi_types_h
39 #include "osapi/osapi_types.h"
40 #endif
41 #ifndef reda_sequence_h
42 #include "reda/reda_sequence.h"
43 #endif
44 #ifndef db_db_h
45 #include "db/db_api.h"
46 #endif
47 #ifndef rt_rt_h
48 #include "rt/rt_rt.h"
49 #endif
50 
51 #ifdef __cplusplus
52 extern "C"
53 {
54 #endif
55 
56 /*ci
57  * \def NETIO_ADDRESS_PORT_INVALID
58  * \brief Constant for an invalid port number
59  */
60 #define NETIO_ADDRESS_PORT_INVALID (0)
61 
62 /*ci
63  * \def NETIO_ADDRESS_KIND_INVALID
64  * \brief Constant for an invalid address kind
65  */
66 #define NETIO_ADDRESS_KIND_INVALID (-1)
67 
68 /*ci
69  * \def NETIO_ADDRESS_KIND_RESERVED
70  * \brief Constant reserved for internal address kinds.
71  */
72 #define NETIO_ADDRESS_KIND_RESERVED 0
73 
74 /*ci
75  * \def NETIO_ADDRESS_KIND_UDPv4
76  * \brief Constant reserved for UDPv4 address kinds
77  */
78 #define NETIO_ADDRESS_KIND_UDPv4 1
79 
80 /*ci
81  * \def NETIO_ADDRESS_KIND_UDPv6
82  * \brief Constant reserved for UDPv6 address kinds
83  */
84 #define NETIO_ADDRESS_KIND_UDPv6 2
85 
86 /*ci
87  * \def NETIO_ADDRESS_KIND_SHMEM
88  * \brief Constant reserved for shared memory addresses
89  */
90 #define NETIO_ADDRESS_KIND_SHMEM 3
91 
92 /*ci
93  * \def NETIO_ADDRESS_KIND_GUID
94  * \brief Constant reserved for GUID addresses
95  */
96 #define NETIO_ADDRESS_KIND_GUID 4
97 
98 /*ci
99  * \def NETIO_ADDRESS_MAX_32BIT
100  * \brief The maximum number of 32bit values in an address
101  */
102 #define NETIO_ADDRESS_MAX_32BIT (4)
103 
104 /*ci
105  * \def NETIO_ADDRESS_MAX_8IT
106  * \brief The maximum number of 8bit values in an address
107  */
108 #define NETIO_ADDRESS_MAX_8IT (16)
109 
110 /*ci
111  * \brief 12 byte GUID prefix, can used as part of a complete GUID address
112  */
113 struct NETIO_GuidPrefix
114 {
115  RTI_UINT8 value[12];
116 };
117 
118 /*ci
119  * \brief 4 byte GUID entity part, can used as part of a complete GUID address
120  */
121 struct NETIO_GuidEntity
122 {
123  RTI_UINT8 value[4];
124 };
125 
126 /*ci
127  * \brief Address in RTPS format, commonly used by RTI internally
128  */
129 struct NETIO_AddressRtps
130 {
131  RTI_UINT32 host_id;
132  RTI_UINT32 app_id;
133  RTI_UINT32 instance_id;
134  RTI_UINT32 object_id;
135 };
136 
137 /*ci
138  * \brief Address in GUID format
139  */
140 struct NETIO_Guid {
141  struct NETIO_GuidPrefix prefix;
142  struct NETIO_GuidEntity entity;
143 };
144 
145 /*ci
146  * \brief Address in GUID format, but with individual bytes accessible
147  */
148 struct NETIO_AddressGuidPrefix
149 {
150  RTI_UINT8 prefix[12];
151  RTI_UINT32 entity;
152 };
153 
154 /*ci
155  * \brief Address in UDPv4 format. By internal convention, only the 4 most
156  * significant bytes are used.
157  */
158 struct NETIO_AddressIp4
159 {
160  /*ci
161  * \brief 32 bit IPv4 address in host order
162  */
163  RTI_UINT32 address;
164  RTI_UINT8 _unused[12];
165 };
166 
167 /*ci
168  * \brief Address in UDPv6 format. By internal convention
169  */
170 struct NETIO_AddressIpv6
171 {
172  RTI_UINT8 octet[16];
173 };
174 
175 /*ci
176  * \brief Address in shared memory format. By internal convention
177  */
178 struct NETIO_AddressShem
179 {
180  /*ci
181  * \brief shared memory key
182  */
183  RTI_UINT32 key;
184  RTI_UINT8 guid[12];
185 };
186 
187 /*ci
188  * \brief Convenience structure to initialize an \ref NETIO_Address structure
189  */
190 struct NETIO_AddressInit
191 {
192  RTI_UINT32 val0;
193  RTI_UINT32 val1;
194  RTI_UINT32 val2;
195  RTI_UINT32 val3;
196 };
197 
198 /*ci
199  * \brief Convenience structure to access \ref NETIO_Address as an array of 4
200  * signed integers
201  */
202 struct NETIO_AddressInt32
203 {
204  RTI_INT32 value[4];
205 };
206 
207 /*ci
208  * \brief Convenience structure to access \ref NETIO_Address as an array of 4
209  * unsigned integers
210  */
211 struct NETIO_AddressUInt32
212 {
213  RTI_UINT32 value[4];
214 };
215 
216 /*ci
217  * \brief All the different address formats
218  */
219 union NETIO_AddressValue
220 {
221  struct NETIO_AddressRtps rtps_guid;
222  struct NETIO_Guid guid;
223  struct NETIO_AddressGuidPrefix guid_prefix;
224  struct NETIO_AddressIp4 ipv4;
225  struct NETIO_AddressIpv6 ipv6;
226  struct NETIO_AddressShem shmem;
227  struct NETIO_AddressInit init;
228  struct NETIO_AddressInt32 as_int32;
229  struct NETIO_AddressUInt32 as_uint32;
230 };
231 
232 /*ci
233  * \brief The definition of the NETIO address structure
234  */
235 struct NETIO_Address
236 {
237  /*ci
238  * \brief Address discriminator. Note that the 8 MSB of the kind
239  * is reserved
240  */
241  RTI_INT32 kind;
242 
243  /*ci
244  * \brief Port number
245  */
246  RTI_UINT32 port;
247 
248  /*ci
249  * \brief Address as defined by the discriminator
250  */
251  union NETIO_AddressValue value;
252 };
253 
254 /*ci
255  * \def NETIO_ADDRESS_FLAG_MULTICAST
256  * \brief Flags to indicate is an address is multicast
257  */
258 #define NETIO_ADDRESS_FLAG_MULTICAST (0x80000000)
259 
260 /*ci
261  * \def NETIO_ADDRESS_FLAG_INTERNAL
262  * \brief Flags to indicate is an address is an internal address
263  */
264 #define NETIO_ADDRESS_FLAG_INTERNAL (0x40000000)
265 
266 /*ci
267  * \def NETIO_ADDRESS_IS_MULTICAST
268  * \brief Macro to check is a \ref NETIO_Address is a multicast address
269  */
270 #define NETIO_ADDRESS_IS_MULTICAST(a_) ((a_)->kind & NETIO_ADDRESS_FLAG_MULTICAST)
271 
272 /*ci
273  * \def NETIO_ADDRESS_IS_INTERNAL
274  * \brief Macro to check is a \ref NETIO_Address is an internal address
275  */
276 #define NETIO_ADDRESS_IS_INTERNAL(a_) ((a_)->kind & NETIO_ADDRESS_FLAG_INTERNAL)
277 
278 /*ci
279  * \def NETIO_ADDRESS_SET_MULTICAST
280  * \brief Macro to mark a \ref NETIO_Address as a multicast address
281  */
282 #define NETIO_ADDRESS_SET_MULTICAST(a_) ((a_)->kind | NETIO_ADDRESS_FLAG_MULTICAST)
283 
284 /*ci
285  * \def NETIO_ADDRESS_SET_INTERNAL
286  * \brief Macro to mark a \ref NETIO_Address as an internal address
287  */
288 #define NETIO_ADDRESS_SET_INTERNAL(a_) ((a_)->kind | NETIO_ADDRESS_FLAG_INTERNAL)
289 
290 /*ci
291  * \def NETIO_ADDRESS_SET_KIND
292  * \brief Macro to set the \ref NETIO_Address kind
293  */
294 #define NETIO_ADDRESS_SET_KIND(a_,k_,f_) ((a_)->kind = (k_) | (f_))
295 
296 /*ci
297  * \def NETIO_ADDRESS_GET_KIND
298  * \brief Macro to get the \ref NETIO_Address kind. This macro masks out the
299  * 8 msb
300  */
301 #define NETIO_ADDRESS_GET_KIND(a_) ((a_)->kind & 0x00ffffff)
302 
303 /*ci
304  * \def NETIO_ADDRESS_KIND
305  * \brief Convert a \ref NETIO_Address::kind field to a valid kind
306  */
307 #define NETIO_ADDRESS_KIND(k_) ((k_) & 0x00ffffff)
308 
309 /*ci
310  * \def NETIO_NETMASK_MASK_LENGTH
311  * \brief The maximum number of elements in a netmask
312  */
313 #define NETIO_NETMASK_MASK_LENGTH (4)
314 
315 /*ci
316  * \def NETIO_NETMASK_MASK_SIZE
317  * \brief The size in bytes of a netmask element
318  */
319 #define NETIO_NETMASK_MASK_SIZE ((RTI_INT32)(sizeof(RTI_INT32)))
320 
321 /*ci
322  * \def NETIO_NETMASK_MASK_BITS_PER_UNIT
323  * \brief The number of bits per netmask element
324  */
325 #define NETIO_NETMASK_MASK_BITS_PER_UNIT ((RTI_INT32)(sizeof(RTI_INT32) * 8))
326 
327 /*ci
328  * \def NETIO_NETMASK_MASK_MAX_BITS
329  * \brief The maximum number of bits in a netmask
330  */
331 #define NETIO_NETMASK_MASK_MAX_BITS (NETIO_NETMASK_MAX_LENGTH * NETIO_NETMASK_ELEMENT_SIZE*8)
332 
333 /*ci
334  * \brief Representation of a netmask
335  */
336 struct NETIO_Netmask
337 {
338  /*ci
339  * \brief The number of valid bits in the netmask
340  */
341  RTI_INT32 bits;
342 
343  /*ci
344  * \brief The netmask
345  */
346  RTI_UINT32 mask[NETIO_NETMASK_MASK_LENGTH];
347 };
348 
349 /*ci
350  * \brief \ref NETIO_Netmask initializer
351  */
352 #define NETIO_Netmask_INITIALIZER \
353 {\
354  0,\
355  {0,0,0,0}\
356 }
357 
358 /* The NETIO API uses both individual NETIO_Addresses and NETIO_Netmask
359  * field, as well as sequences of these. Thi declares the sequence
360  * of the respective types.
361  */
362 REDA_DEFINE_SEQUENCE(NETIO_AddressSeq, struct NETIO_Address)
363 REDA_DEFINE_SEQUENCE(NETIO_NetmaskSeq, struct NETIO_Netmask)
364 
365 /*ci
366  * \def NETIO_AddressSeq_INITIALIZER
367  * \brief Macro to initialize a NETIO_Address sequence
368  */
369 #define NETIO_AddressSeq_INITIALIZER REDA_DEFINE_SEQUENCE_INITIALIZER(struct NETIO_Address)
370 
371 /*ci
372  * \def NETIO_NetmaskSeq_INITIALIZER
373  * \brief Macro to initialize a NETIO_Netmask sequence
374  */
375 #define NETIO_NetmaskSeq_INITIALIZER REDA_DEFINE_SEQUENCE_INITIALIZER(struct NETIO_Netmask)
376 
377 /*ci
378  * \def NETIO_ADDRESS_GUID_UNKNOWN
379  * \brief Constant used to initialize an NETIO_Address of the GUID kind to
380  * unknown.
381  */
382 #define NETIO_ADDRESS_GUID_UNKNOWN {{{0,0,0,0,0,0,0,0,0,0,0,0}},{{0,0,0,0}}}
383 
384 /*ci
385  * \brief Compare two NETIO_Addresses
386  *
387  * \details
388  *
389  * This function compares two NETIO_Address structures.
390  *
391  * \param[in] left_addr Left side of the comparison
392  * \param[in] right_addr Right side of the comparison
393  *
394  * \return 0 is left = right, > 0 if left > right, < 0 if left < right
395  */
396 NETIODllExport RTI_INT32
397 NETIO_Address_compare(const struct NETIO_Address *left_addr,
398  const struct NETIO_Address *right_addr);
399 
400 /*ci
401  * \def NETIO_Address_INITIALIZER
402  * Constant to initialize a \ref NETIO_Address
403  */
404 #define NETIO_Address_INITIALIZER \
405 {\
406  NETIO_ADDRESS_KIND_RESERVED, /* kind */ \
407  0, /* port */ \
408  {{0,0,0,0}} /* value */ \
409 }
410 
411 /*ci
412  * \def NETIO_Address_init
413  * Macro to initialize a \ref NETIO_Address to a known state
414  */
415 #define NETIO_Address_init(addr_,kind_) \
416 {\
417  (addr_)->kind = kind_; (addr_)->port = 0; \
418  (addr_)->value.init.val0 = (addr_)->value.init.val1 = 0;\
419  (addr_)->value.init.val2 = (addr_)->value.init.val3 = 0;\
420 }
421 
422 /*ci
423  * \def NETIO_Address_set_ipv4
424  * Macro to set the IPv4 address part of a \ref NETIO_Address
425  */
426 #define NETIO_Address_set_ipv4(addr_,port_,address_) \
427 {\
428  (addr_)->kind = NETIO_ADDRESS_KIND_UDPv4; \
429  (addr_)->port = port_; \
430  (addr_)->value.ipv4.address = address_;\
431 }
432 
433 /*ci
434  * \def NETIO_Address_set_guid
435  * Macro to set the GUID address part of a \ref NETIO_Address
436  */
437 #define NETIO_Address_set_guid(addr_,port_,guid_) \
438 {\
439  (addr_)->kind = NETIO_ADDRESS_KIND_GUID; \
440  (addr_)->port = port_; \
441  OSAPI_Memory_copy(&((addr_)->value.guid),(guid_),16);\
442 }
443 
444 /*ci
445  * \def NETIO_Address_set_guid_from_key
446  * Macro to set the GUID address part of a \ref NETIO_Address from a
447  * DDS Key. DDS keys are received over the arrays as an array of 4 integers
448  * as defined by the DDS specification. Because the key is represented as
449  * 4 integers in the <em> host order </em> of the sender but are internally
450  * representaed as 16 octets (endianess is not an issue), care must be
451  * taken to perform endianness conversion.
452  */
453 #if RTI_ENDIAN_BIG
454 #define NETIO_Address_set_guid_from_key(addr_,port_,key_) \
455 {\
456  (addr_)->kind = NETIO_ADDRESS_KIND_GUID; \
457  (addr_)->port = port_; \
458  OSAPI_Memory_copy(&((addr_)->value.guid),(key_),16);\
459 }
460 
461 #else
462 #define NETIO_Address_set_guid_from_key(addr_,port_,key_) \
463 {\
464  (addr_)->kind = NETIO_ADDRESS_KIND_GUID; \
465  (addr_)->port = port_; \
466  (addr_)->value.rtps_guid.host_id = NETIO_htonl((key_)->value[0]);\
467  (addr_)->value.rtps_guid.app_id = NETIO_htonl((key_)->value[1]);\
468  (addr_)->value.rtps_guid.instance_id = NETIO_htonl((key_)->value[2]);\
469  (addr_)->value.rtps_guid.object_id = NETIO_htonl((key_)->value[3]);\
470 }
471 #endif
472 
473 /*ci
474  * \def NETIO_Address_set_guid_from_int32
475  * Macro to set the GUID address part of a \ref NETIO_Address from a
476  * 4 integers. A GUID is an array of 16 octets and it is necessary
477  * to perform endianess conversion based on the host's endianess
478  */
479 #if RTI_ENDIAN_BIG
480 #define NETIO_Address_set_guid_from_int32(addr_,port_,int0_,int1_,int2_,int3_) \
481 {\
482  (addr_)->kind = NETIO_ADDRESS_KIND_GUID; \
483  (addr_)->port = port_; \
484  (addr_)->value.rtps_guid.host_id = int0_;\
485  (addr_)->value.rtps_guid.app_id = int1_;\
486  (addr_)->value.rtps_guid.instance_id = int2_;\
487  (addr_)->value.rtps_guid.object_id = int3_;\
488 }
489 
490 #else
491 #define NETIO_Address_set_guid_from_int32(addr_,port_,int0_,int1_,int2_,int3_) \
492 {\
493  (addr_)->kind = NETIO_ADDRESS_KIND_GUID; \
494  (addr_)->port = port_; \
495  (addr_)->value.rtps_guid.host_id = NETIO_htonl(int0_);\
496  (addr_)->value.rtps_guid.app_id = NETIO_htonl(int1_);\
497  (addr_)->value.rtps_guid.instance_id = NETIO_htonl(int2_);\
498  (addr_)->value.rtps_guid.object_id = NETIO_htonl(int3_);\
499 }
500 #endif
501 
502 /*ci
503  * \def NETIO_Address_is_udpv4_multicast
504  * Macro to check is an address is a UDPv4 multicast address
505  */
506 #define NETIO_Address_is_udpv4_multicast(addr_) \
507  ((NETIO_ADDRESS_GET_KIND(addr_) == NETIO_ADDRESS_KIND_UDPv4) && \
508  ((addr_)->value.ipv4.address >= 0xe0000000) && \
509  ((addr_)->value.ipv4.address <= 0xefffffff))
510 
511 /*ci
512  * \brief Parse an address string
513  *
514  * \details
515  *
516  * This function parses an NETIO address in stringa format and breaks
517  * it into the individual parts.
518  *
519  * Algorithm:
520  *
521  * An address is on the form:
522  *
523  * [index @][<interface>://][<address>]
524  *
525  * - break address string into 3 parts:
526  * - An optional index. Three index formats are supported
527  * N@ - In this type the low_index = 0 and high_index is N
528  * [N-M]@ - In this type the low_index = N and high_index is M
529  * M@ - In this type the low_index = high_index = M
530  * - An optional interface id (out_id)
531  * - An optional address string (address_string)
532  *
533  * The parse allows an empty string. If an index is not specified -1 is
534  * returned. If a prefix is not specified an empty prefix is returned.
535  *
536  * \param[in] name The address to be parsed
537  * \param[out] base_port The base port in used in port calculation
538  * \param[out] low_index The lowest index parsed from the address
539  * \param[out] high_index The highest index parsed from the address
540  * \param[out] out_id The ComponentFactoryId that successfully parsed it
541  * \param[out] address_string The address part of the NETIO address string
542  * \param[out] address_max_string The maximum length of the address part
543  *
544  * \return RTI_TRUE on success, RTI_FALSE on failure
545  */
546 MUST_CHECK_RETURN NETIODllExport RTI_BOOL
547 NETIO_Address_parse(const char *name,
548  RTI_UINT32 *base_port,
549  RTI_INT32 *low_index,
550  RTI_INT32 *high_index,
551  RT_ComponentFactoryId_T *out_id,
552  char *address_string,
553  RTI_SIZE_T address_max_string);
554 
555 /*ci
556  * \brief The maximum size of an individual address part.
557  */
558 #define NETIO_ADDRESS_TOKEN_MAX_SIZE 256
559 
560 /*ci
561  * \brief The maximum size of an an address prefix. The address prefix
562  * is limited by the the run-time can handle, which is 7 octets, excluding the
563  * NULL termination.
564  */
565 #define NETIO_PREFIX_TOKEN_MAX_SIZE (RT_MAX_FACTORY_NAME + 1)
566 
567 /*ci
568  * \brief Enumeration of what type of address is being resolved. NETIO
569  * supports 2 types of address, meta and user. It is up to the
570  * caller to determine what the definition of user and meta means.
571  */
572 typedef enum
573 {
574  /*ci
575  * \brief The address if for meta traffic
576  */
577  NETIO_ROUTEKIND_META,
578 
579  /*ci
580  * \brief The address if for user traffic
581  */
582  NETIO_ROUTEKIND_USER
583 } NETIO_RouteKind_T;
584 
585 /*ci
586  * \brief Calculate a port number based on user provided information
587  *
588  * \details
589  *
590  * NETIO does not enforce the user of a port calculation function. However,
591  * some layers such as DDS defines a port mapping to enable discovery on
592  * well-known ports. Based on information provided by the caller
593  * the user can calculate specific port numbers which will be used as
594  * part of a \ref NETIO_Address.
595  *
596  * \param[in] param User provided parameter passed transparently
597  * \param[in] kind The type of address the port is calculated for
598  * \param[in] port_base The base-port number, typically used together with an
599  * to calculate the final port
600  * \param[in] index The index has been extracted from an address string
601  * \param[out] address The NETIO_Address structure to update the port for
602  */
603 typedef RTI_BOOL
604 (*NETIO_PortCalculateFunc_T)(void *param,NETIO_RouteKind_T kind,
605  RTI_UINT32 port_base,RTI_INT32 index,
606  struct NETIO_Address *address);
607 
608 #ifdef __cplusplus
609 } /* extern "C" */
610 #endif
611 
612 #endif /* netio_address_h */
613 
614 /*ci @} */
615 

RTI Connext Micro Version 2.4.1.0 Copyright © Thu Nov 20 2014 Real-Time Innovations, Inc