X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Frmr%2Fcommon%2Fsrc%2Frtc_static.c;h=15fe56720f016622fa7097a765715959fc5baa0c;hb=05850e0815095c029ecff43ac8e0983f2fba4fb6;hp=03f9db0e84abab6576a2d7e07aa18b7d41c29ecd;hpb=fc2112d22bf69b4bfbe0c419ed366f0d0ec370ca;p=ric-plt%2Flib%2Frmr.git diff --git a/src/rmr/common/src/rtc_static.c b/src/rmr/common/src/rtc_static.c index 03f9db0..15fe567 100644 --- a/src/rmr/common/src/rtc_static.c +++ b/src/rmr/common/src/rtc_static.c @@ -76,15 +76,18 @@ static void* rtc_file( void* vctx ) { ctx->flags |= CFL_NO_RTACK; // no attempt to ack when reading from a file while( 1 ) { if( vfd >= 0 ) { - wbuf[0] = 0; - lseek( vfd, 0, 0 ); - read( vfd, wbuf, 10 ); - vlevel = atoi( wbuf ); + memset( wbuf, 0, sizeof( char ) * 11 ); + if( lseek( vfd, 0, SEEK_SET ) == 0 && read( vfd, wbuf, 10 ) > 0 ) { + vlevel = atoi( wbuf ); + } } read_static_rt( ctx, vlevel ); // seed the route table if one provided if( ctx->shutdown != 0 ) { // allow for graceful termination and unit testing + if( vfd >= 0 ) { + close( vfd ); + } return NULL; } sleep( 60 ); @@ -97,9 +100,10 @@ static int refresh_vlevel( int vfd ) { if( vfd >= 0 ) { // if file is open, read current value rbuf[0] = 0; - lseek( vfd, 0, 0 ); - read( vfd, rbuf, 10 ); - vlevel = atoi( rbuf ); + memset( rbuf, 0, sizeof( char ) * 11 ); + if( lseek( vfd, 0, SEEK_SET ) == 0 && read( vfd, rbuf, 10 ) > 0 ) { + vlevel = atoi( rbuf ); + } } return vlevel; @@ -261,6 +265,8 @@ static void* rtc( void* vctx ) { int count_delay = 30; // number of seconds between writing count info; initially every 30s int bump_freq = 0; // time at which we will bump count frequency to every 5 minutes int flags = 0; + int rt_req_freq = DEF_RTREQ_FREQ; // request frequency (sec) when wanting a new table + int nxt_rt_req = 0; // time of next request if( (ctx = (uta_ctx_t *) vctx) == NULL ) { @@ -268,11 +274,25 @@ static void* rtc( void* vctx ) { return NULL; } + if( (ctx->ephash = rmr_sym_alloc( RT_SIZE )) == NULL ) { // master hash table for endpoints (each rt will reference this) + rmr_vlog( RMR_VL_CRIT, "rmr_rtc: internal mishap: unable to allocate an endpoint hash table\n" ); + return NULL; + } + if( (eptr = getenv( ENV_VERBOSE_FILE )) != NULL ) { vfd = open( eptr, O_RDONLY ); vlevel = refresh_vlevel( vfd ); } + if( (eptr = getenv( ENV_RTREQ_FREA )) != NULL ) { + 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_INFO, "rmr_rtc: RT request frequency set to: %d seconds", rt_req_freq ); + 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; @@ -331,11 +351,12 @@ static void* rtc( void* vctx ) { blabber = 0; while( 1 ) { // until the cows return, pigs fly, or somesuch event likely not to happen while( msg == NULL || msg->len <= 0 ) { // until we actually have something from the other side - if( (flags & RTCFL_HAVE_UPDATE) == 0 ) { // no route table updated from rt mgr; request one + if( (flags & RTCFL_HAVE_UPDATE) == 0 && time( NULL ) >= nxt_rt_req ) { // no route table updated from rt mgr; request one if( ctx->rtg_whid < 0 ) { ctx->rtg_whid = rmr_wh_open( pvt_cx, rtg_addr ); } send_update_req( pvt_cx, ctx ); + nxt_rt_req = time( NULL ) + rt_req_freq; } msg = rmr_torcv_msg( pvt_cx, msg, 1000 );