X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Frmr%2Fcommon%2Fsrc%2Frt_generic_static.c;h=d65acdfa8a15cc08abca762f9196e110b3f9acda;hb=d9de79acd9c205dc4f795e90a98331628ed6c85b;hp=253e7ab1c9ccda33f025bb9948b2cb4199f8f097;hpb=b7a31bd94da349e9c49f6dd7a5bcded74877a8ae;p=ric-plt%2Flib%2Frmr.git diff --git a/src/rmr/common/src/rt_generic_static.c b/src/rmr/common/src/rt_generic_static.c index 253e7ab..d65acdf 100644 --- a/src/rmr/common/src/rt_generic_static.c +++ b/src/rmr/common/src/rt_generic_static.c @@ -60,7 +60,8 @@ typedef struct thing_list { // ---- debugging/testing ------------------------------------------------------------------------- /* - Dump stats for an endpoint in the RT. + Dump some stats for an endpoint in the RT. This is generally called to + verify endpoints after a table load/change. */ static void ep_stats( void* st, void* entry, char const* name, void* thing, void* vcounter ) { int* counter; @@ -74,7 +75,34 @@ static void ep_stats( void* st, void* entry, char const* name, void* thing, void (*counter)++; } - fprintf( stderr, "[DBUG] endpoint: %s open=%d\n", ep->name, ep->open ); + fprintf( stderr, "[DBUG] RMR sends: target=%s open=%d\n", ep->name, ep->open ); +} + +/* + Dump counts for an endpoint in the RT. The vid parm is assumed to point to + the 'source' information and is added to each message. +*/ +static void ep_counts( void* st, void* entry, char const* name, void* thing, void* vid ) { + endpoint_t* ep; + char* id; + + if( (ep = (endpoint_t *) thing) == NULL ) { + return; + } + + if( (id = (char *) vid) == NULL ) { + id = "missing"; + } + + fprintf( stderr, "[INFO] RMR sends: ts=%lld src=%s target=%s open=%d succ=%lld fail=%lld (hard=%lld soft=%lld)\n", + (long long) time( NULL ), + id, + ep->name, + ep->open, + ep->scounts[EPSC_GOOD], + ep->scounts[EPSC_FAIL] + ep->scounts[EPSC_TRANS], + ep->scounts[EPSC_FAIL], + ep->scounts[EPSC_TRANS] ); } /* @@ -124,6 +152,19 @@ static void rt_stats( route_table_t* rt ) { free( counter ); } +/* + Given a route table, cause endpoint counters to be written to stderr. The id + parm is written as the "source" in the output. +*/ +static void rt_epcounts( route_table_t* rt, char* id ) { + if( rt == NULL ) { + fprintf( stderr, "[INFO] RMR endpoint: no counts: empty table\n" ); + return; + } + + rmr_sym_foreach_class( rt->hash, 1, ep_counts, id ); // run endpoints in the active table +} + // ------------------------------------------------------------------------------------------------ /* @@ -153,6 +194,39 @@ static char* clip( char* buf ) { return buf; } +/* + This accepts a pointer to a nil terminated string, and ensures that there is a + newline as the last character. If there is not, a new buffer is allocated and + the newline is added. If a new buffer is allocated, the buffer passed in is + freed. The function returns a pointer which the caller should use, and must + free. In the event of an error, a nil pointer is returned. +*/ +static char* ensure_nlterm( char* buf ) { + char* nb = NULL; + int len = 1; + + + nb = buf; + if( buf == NULL || (len = strlen( buf )) < 2 ) { + if( (nb = (char *) malloc( sizeof( char ) * 2 )) != NULL ) { + *nb = '\n'; + *(nb+1) = 0; + } + } else { + if( buf[len-1] != '\n' ) { + fprintf( stderr, "[WRN] rmr buf_check: input buffer was not newline terminated (file missing final \\n?)\n" ); + if( (nb = (char *) malloc( sizeof( char ) * (len + 2) )) != NULL ) { + memcpy( nb, buf, len ); + *(nb+len) = '\n'; // insert \n and nil into the two extra bytes we allocated + *(nb+len+1) = 0; + } + + free( buf ); + } + } + + return nb; +} /* Given a message type create a route table entry and add to the hash keyed on the @@ -168,7 +242,7 @@ static rtable_ent_t* uta_add_rte( route_table_t* rt, uint64_t key, int nrrgroups } if( (rte = (rtable_ent_t *) malloc( sizeof( *rte ) )) == NULL ) { - fprintf( stderr, "rmr_add_rte: malloc failed for entry\n" ); + fprintf( stderr, "[ERR] rmr_add_rte: malloc failed for entry\n" ); return NULL; } memset( rte, 0, sizeof( *rte ) ); @@ -193,7 +267,7 @@ static rtable_ent_t* uta_add_rte( route_table_t* rt, uint64_t key, int nrrgroups rmr_sym_map( rt->hash, key, rte ); // add to hash using numeric mtype as key - if( DEBUG ) fprintf( stderr, "[DBUG] route table entry created: k=%lx groups=%d\n", key, nrrgroups ); + if( DEBUG ) fprintf( stderr, "[DBUG] route table entry created: k=%llx groups=%d\n", (long long) key, nrrgroups ); return rte; } @@ -238,17 +312,20 @@ static void build_entry( uta_ctx_t* ctx, char* ts_field, uint32_t subid, char* r rte = uta_add_rte( ctx->new_rtable, key, ngtoks ); // get/create entry for this key for( grp = 0; grp < ngtoks; grp++ ) { - if( (ntoks = uta_tokenise( gtokens[grp], tokens, 64, ',' )) > 0 ) { + if( (ntoks = uta_rmip_tokenise( gtokens[grp], ctx->ip_list, tokens, 64, ',' )) > 0 ) { // remove any referneces to our ip addrs for( i = 0; i < ntoks; i++ ) { - if( DEBUG > 1 || (vlevel > 1)) fprintf( stderr, "[DBUG] add endpoint %s\n", ts_field ); - uta_add_ep( ctx->new_rtable, rte, tokens[i], grp ); + if( strcmp( tokens[i], ctx->my_name ) != 0 ) { // don't add if it is us -- cannot send to ourself + if( DEBUG > 1 || (vlevel > 1)) fprintf( stderr, "[DBUG] add endpoint ts=%s %s\n", ts_field, tokens[i] ); + uta_add_ep( ctx->new_rtable, rte, tokens[i], grp ); + } } } } } } else { - if( DEBUG || (vlevel > 2) ) + if( DEBUG || (vlevel > 2) ) { fprintf( stderr, "entry not included, sender not matched: %s\n", tokens[1] ); + } } } @@ -489,7 +566,7 @@ static void read_static_rt( uta_ctx_t* ctx, int vlevel ) { return; } - if( (fbuf = uta_fib( fname ) ) == NULL ) { // read file into a single buffer (nil terminated string) + if( (fbuf = ensure_nlterm( uta_fib( fname ) ) ) == NULL ) { // read file into a single buffer (nil terminated string) fprintf( stderr, "[WRN] rmr read_static: seed route table could not be opened: %s: %s\n", fname, strerror( errno ) ); return; } @@ -506,8 +583,8 @@ static void read_static_rt( uta_ctx_t* ctx, int vlevel ) { if( (eor = strchr( rec, '\n' )) != NULL ) { *eor = 0; } else { - fprintf( stderr, "[WARN] rmr read_static: seed route table had malformed records (missing newline): %s\n", fname ); - fprintf( stderr, "[WARN] rmr read_static: seed route table not used%s\n", fname ); + fprintf( stderr, "[WRN] rmr read_static: seed route table had malformed records (missing newline): %s\n", fname ); + fprintf( stderr, "[WRN] rmr read_static: seed route table not used: %s\n", fname ); free( fbuf ); return; } @@ -812,14 +889,14 @@ static endpoint_t* rt_ensure_ep( route_table_t* rt, char const* ep_name ) { endpoint_t* ep; if( !rt || !ep_name || ! *ep_name ) { - fprintf( stderr, "[WARN] rmr: rt_ensure: internal mishap, something undefined rt=%p ep_name=%p\n", rt, ep_name ); + fprintf( stderr, "[WRN] rmr: rt_ensure: internal mishap, something undefined rt=%p ep_name=%p\n", rt, ep_name ); errno = EINVAL; return NULL; } if( (ep = uta_get_ep( rt, ep_name )) == NULL ) { // not there yet, make if( (ep = (endpoint_t *) malloc( sizeof( *ep ) )) == NULL ) { - fprintf( stderr, "[WARN] rmr: rt_ensure: malloc failed for endpoint creation: %s\n", ep_name ); + fprintf( stderr, "[WRN] rmr: rt_ensure: malloc failed for endpoint creation: %s\n", ep_name ); errno = ENOMEM; return NULL; } @@ -828,6 +905,7 @@ static endpoint_t* rt_ensure_ep( route_table_t* rt, char const* ep_name ) { ep->addr = uta_h2ip( ep_name ); ep->name = strdup( ep_name ); pthread_mutex_init( &ep->gate, NULL ); // init with default attrs + memset( &ep->scounts[0], 0, sizeof( ep->scounts ) ); rmr_sym_put( rt->hash, ep_name, 1, ep ); }