feat(API): Add trace data functions
[ric-plt/lib/rmr.git] / src / nanomsg / include / rmr_private.h
1 // : vi ts=4 sw=4 noet :
2 /*
3 ==================================================================================
4         Copyright (c) 2019 Nokia 
5         Copyright (c) 2018-2019 AT&T Intellectual Property.
6
7    Licensed under the Apache License, Version 2.0 (the "License");
8    you may not use this file except in compliance with the License.
9    You may obtain a copy of the License at
10
11        http://www.apache.org/licenses/LICENSE-2.0
12
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18 ==================================================================================
19 */
20
21 /*
22         Mnemonic:       rmr_private.h
23         Abstract:       Private header information for the uta library functions.
24                                 This should contain only things which are specific to nanomsg;
25                                 anything else is defined in the common/rmr_agnostic.h header.
26
27         Author:         E. Scott Daniels
28         Date:           27 November 2018
29
30         Mods:           28 February 2019 - moved most of the crap here to agnosic.
31 */
32
33 #ifndef _rmr_private_h
34 #define _rmr_private_h
35
36 /*
37         Manages an endpoint. Typedef for this is defined in agnostic.h
38 */
39 struct endpoint {
40         char*   name;                   // end point name (symtab reference)
41         char*   proto;                  // connection proto (should only be TCP, but future might bring others)
42         char*   addr;                   // address used for connection
43         int             nn_sock;                // the nano-msg socket to write to for this entry
44         int             open;                   // true if we've established the connection
45 };
46
47 /*
48         Context describing our world. Should be returned to user programme on 
49         call to initialise, and passed as first parm on all calls to other
50         visible functions.
51
52         The typedef for ctx is in the agnostic header
53 */
54 struct uta_ctx {
55         char*   my_name;                        // dns name of this host to set in sender field of a message
56         int             shutdown;                       // threads should exit if this is set
57         int max_mlen;                           // max message length payload+header
58         int     max_plen;                               // max payload length
59         int     flags;                                  // CTXFL_ constants
60         int nrtele;                                     // number of elements in the routing table
61         int     nn_sock;                                // our general listen socket
62         int     trace_data_len;                 // len of tracing data that sits just past header (0 means none)
63         int     d1_len;                                 // lengths for additional post header, pre payload data areas
64         int d2_len;
65         route_table_t* rtable;          // the active route table
66         route_table_t* old_rtable;      // the previously used rt, sits here to allow for draining
67         route_table_t* new_rtable;      // route table under construction
68         if_addrs_t*     ip_list;                // list manager of the IP addresses that are on our known interfaces
69         void*   mring;                          // ring where msgs are queued while waiting for a call response msg
70         
71         char*   rtg_addr;                       // addr/port of the route table generation publisher
72         int             rtg_port;                       // the port that the rtg listens on
73
74         wh_mgt_t*       wormholes;              // wormhole management
75         pthread_t       rtc_th;                 // thread info for the rtc listener
76 };
77
78
79 /*
80         Prototypes of the functions which are defined in our static modules (nothing
81         from common should be here).
82 */
83
84 // ---- housekeeping and initialisation ----------
85 static void* init( char* usr_port, int max_mlen, int flags );
86 static void free_ctx( uta_ctx_t* ctx );
87
88 // --- message and context management --------
89 static rmr_mbuf_t* send_msg( uta_ctx_t* ctx, rmr_mbuf_t* msg, int nn_sock );
90 static void* rcv_payload( uta_ctx_t* ctx, rmr_mbuf_t* old_msg );
91
92
93 // ---- route table and connection management ---------------
94
95 static int uta_link2( char* target );
96 static int rt_link2_ep( endpoint_t* ep );
97 static endpoint_t*  uta_add_ep( route_table_t* rt, rtable_ent_t* rte, char* ep_name, int group  );
98 static int uta_epsock_byname( route_table_t* rt, char* ep_name );
99 static int uta_epsock_rr( route_table_t *rt, int mtype, int group, int* more );
100
101 // ------ msg ------------------------------------------------
102 static rmr_mbuf_t* alloc_zcmsg( uta_ctx_t* ctx, rmr_mbuf_t* msg, int size, int state, int tr_size );
103 static inline rmr_mbuf_t* clone_msg( rmr_mbuf_t* old_msg  );
104 static rmr_mbuf_t* rcv_msg( uta_ctx_t* ctx, rmr_mbuf_t* old_msg );
105 static void* rcv_payload( uta_ctx_t* ctx, rmr_mbuf_t* old_msg );
106 static rmr_mbuf_t* send_msg( uta_ctx_t* ctx, rmr_mbuf_t* msg, int nn_sock );
107 static rmr_mbuf_t* send2ep( uta_ctx_t* ctx, endpoint_t* ep, rmr_mbuf_t* msg );
108
109
110
111 /*
112 // --- message ring --------------------------
113 static void* uta_mk_ring( int size );
114 static void uta_ring_free( void* vr );
115 static inline void* uta_ring_extract( void* vr );
116 static inline int uta_ring_insert( void* vr, void* new_data );
117
118 // --- message and context management --------
119 static int ie_test( void* r, int i_factor, long inserts );
120 static void free_ctx( uta_ctx_t* ctx );
121 static rmr_mbuf_t* alloc_zcmsg( uta_ctx_t* ctx, rmr_mbuf_t* msg, int size, int state );
122 static inline rmr_mbuf_t* clone_msg( rmr_mbuf_t* old_msg  );
123 static rmr_mbuf_t* rcv_msg( uta_ctx_t* ctx, rmr_mbuf_t* old_msg );
124
125 // ----- route table static things ---------
126 static void collect_things( void* st, void* entry, char const* name, void* thing, void* vthing_list );
127 static void del_rte( void* st, void* entry, char const* name, void* thing, void* data );
128 static char* uta_fib( char* fname );
129 static route_table_t* uta_rt_init( );
130 static route_table_t* uta_rt_clone( route_table_t* srt );
131 static void uta_rt_drop( route_table_t* rt );
132 static endpoint_t*  uta_add_ep( route_table_t* rt, rtable_ent_t* rte, char* ep_name, int group  );
133 static rtable_ent_t* uta_add_rte( route_table_t* rt, int mtype, int nrrgroups );
134 static endpoint_t* uta_get_ep( route_table_t* rt, char const* ep_name );
135 static int uta_epsock_byname( route_table_t* rt, char* ep_name );
136 static int uta_epsock_rr( route_table_t *rt, int mtype, int group, int* more );
137 static void read_static_rt( uta_ctx_t* ctx, int vlevel );
138 static void parse_rt_rec( uta_ctx_t* ctx, char* buf, int vlevel );
139 static void* rtc( void* vctx );
140 static endpoint_t* rt_ensure_ep( route_table_t* rt, char const* ep_name );
141
142
143 // --- tools_static protos ------------------
144 static int uta_tokenise( char* buf, char** tokens, int max, char sep );
145 static char* uta_h2ip( char const* hname );
146 static int uta_link2( char* target );
147 static int uta_lookup_rtg( uta_ctx_t* ctx );
148 static int uta_has_str( char const* buf, char const* str, char sep, int max );
149 */
150
151 static int rt_link2_ep( endpoint_t* ep );
152 static rmr_mbuf_t* send2ep( uta_ctx_t* ctx, endpoint_t* ep, rmr_mbuf_t* msg );
153
154 #endif