Ensure RT incremental update not applied early
[ric-plt/lib/rmr.git] / src / rmr / common / src / rtc_static.c
index 2525342..10bc2a7 100644 (file)
@@ -1,8 +1,8 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-       Copyright (c) 2019-2020 Nokia
-       Copyright (c) 2018-2020 AT&T Intellectual Property.
+       Copyright (c) 2019-2021 Nokia
+       Copyright (c) 2018-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -117,13 +117,18 @@ static void* rtc_file( void* vctx ) {
        ctx->flags |= CFL_NO_RTACK;                             // no attempt to ack when reading from a file
        while( 1 ) {
                vlevel = refresh_vlevel( 0 );
-               read_static_rt( ctx, vlevel );                                          // seed the route table if one provided
+               read_static_rt( ctx, vlevel );                                          // refresh from the file
 
                if( ctx->shutdown != 0 ) {                                                      // allow for graceful termination and unit testing
                        refresh_vlevel( 1 );                                                            // close the verbose file if open
                        return NULL;
                }
-               sleep( 60 );
+
+               if( ctx->rtable_ready ) {
+                       sleep( 60 );
+               } else {
+                       sleep( 1 );                                                                             // check every second until we have a good one
+               }
        }
 }
 
@@ -186,7 +191,7 @@ static void rtc_parse_msg( uta_ctx_t *ctx, uta_ctx_t* pvt_cx, rmr_mbuf_t* msg, i
                                }
 
                                if( vlevel > 1 ) {
-                                       rmr_vlog_force( RMR_VL_DEBUG, "rmr_rtc_parse_msg: processing (%s)\n", curr );
+                                       rmr_vlog_force( RMR_VL_DEBUG, "rmr_rtc_parse_msg: snarf_fd=%d processing (%s)\n", ctx ? ctx->snarf_rt_fd : -99, curr );
                                }
                                parse_rt_rec( ctx, pvt_cx, curr, vlevel, msg );         // parse record and add to in progress table; ack using rts to msg
 
@@ -297,7 +302,7 @@ static void* rtc( void* vctx ) {
                rt_req_freq = atoi( eptr );
                if( rt_req_freq < 1 || rt_req_freq > 300 ) {
                        rt_req_freq = DEF_RTREQ_FREQ;
-                       rmr_vlog( RMR_VL_WARN, "rmr_rtc: RT request frequency (%d) out of range (1-300), using default", DEF_RTREQ_FREQ );
+                       rmr_vlog( RMR_VL_WARN, "rmr_rtc: RT request frequency (%d) out of range (1-300), using default (%d)\n", rt_req_freq, DEF_RTREQ_FREQ );
                }
        }
        rmr_vlog( RMR_VL_INFO, "rmr_rtc: RT request frequency set to: %d seconds", rt_req_freq );
@@ -305,6 +310,7 @@ static void* rtc( void* vctx ) {
        ctx->flags |= CFL_NO_RTACK;                             // don't ack when reading from a file
        read_static_rt( ctx, vlevel );                  // seed the route table if one provided
        ctx->flags &= ~CFL_NO_RTACK;
+       ctx->flags &= ~CFL_FULLRT;                              // even though rmr-ready goes true, the seed doesn't count as a full RT from route generator
 
 
        my_port = getenv( ENV_CTL_PORT );                               // default port to listen on (likely 4561)
@@ -354,6 +360,8 @@ static void* rtc( void* vctx ) {
 
        ctx->rtg_whid = -1;
 
+       cycle_snarfed_rt( ctx );                                // cause the nrt to be opened
+
        if( DEBUG ) rmr_vlog( RMR_VL_DEBUG, "rtc thread is running and listening; listening for rtg conns on %s\n", my_port );
 
        bump_freq = time( NULL ) + 300;                         // after 5 minutes we decrease the count frequency
@@ -384,6 +392,9 @@ static void* rtc( void* vctx ) {
                        if( ctx->shutdown != 0 ) {
                                break;                                                  // mostly for unit test, but allows a forced stop
                        }
+
+                                                                                               // extra housekeeping chores can be added here...
+                       alarm_if_drops( ctx, pvt_cx );          // send an alarm if message are dropping, clear if we set one and thtings are better
                }
 
                vlevel = refresh_vlevel( 0 );                   // ensure it's fresh when we get a message
@@ -574,6 +585,8 @@ static void* raw_rtc( void* vctx ) {
                                        rt_epcounts( ctx->rtable, ctx->my_name );
                                }
                        }
+
+                       alarm_if_drops( ctx );                          // send an alarm if message are dropping, clear if we set one and thtings are better
                }
 
                vlevel = refresh_vlevel( 0 );                   // ensure it's fresh when we get a message