/** Implements the end_interval function of the plugin API */
int bgpcorsaro_pfxmonitor_end_interval(bgpcorsaro_t *bgpcorsaro,
                                       bgpcorsaro_interval_t *int_end)
{
  struct bgpcorsaro_pfxmonitor_state_t *state = STATE(bgpcorsaro);

  bgpcorsaro_io_write_interval_end(bgpcorsaro, state->outfile, int_end);

  /* if we are rotating, now is when we should do it */
  if (bgpcorsaro_is_rotate_interval(bgpcorsaro)) {
    /* leave the current file to finish draining buffers */
    assert(state->outfile != NULL);

    /* move on to the next output pointer */
    state->outfile_n = (state->outfile_n + 1) % OUTFILE_POINTERS;

    if (state->outfile_p[state->outfile_n] != NULL) {
      /* we're gonna have to wait for this to close */
      wandio_wdestroy(state->outfile_p[state->outfile_n]);
      state->outfile_p[state->outfile_n] = NULL;
    }

    state->outfile = NULL;
  }

  output_stats_and_reset(state, state->interval_start);

  return 0;
}
示例#2
0
/** Implements the end_interval function of the plugin API */
int bgpcorsaro_pacifier_end_interval(bgpcorsaro_t *bgpcorsaro,
				 bgpcorsaro_interval_t *int_end)
{
  struct bgpcorsaro_pacifier_state_t *state = STATE(bgpcorsaro);

  bgpcorsaro_io_write_interval_end(bgpcorsaro, state->outfile, int_end);

  /* if we are rotating, now is when we should do it */
  if(bgpcorsaro_is_rotate_interval(bgpcorsaro))
    {
      /* leave the current file to finish draining buffers */
      assert(state->outfile != NULL);

      /* move on to the next output pointer */
      state->outfile_n = (state->outfile_n+1) %
	OUTFILE_POINTERS;

      if(state->outfile_p[state->outfile_n] != NULL)
	{
	  /* we're gonna have to wait for this to close */
	  wandio_wdestroy(state->outfile_p[state->outfile_n]);
	  state->outfile_p[state->outfile_n] =  NULL;
	}

      state->outfile = NULL;
    }


  struct timeval tv;
  gettimeofday_wrap(&tv);
  
  int expected_time = 0;
  int diff = 0;

  if(state->adaptive == 0)
    {
      diff = state->wait - (tv.tv_sec - state->tv_start);
    }
  else
    {
      expected_time = state->tv_first_time + state->intervals *  state->wait;
      diff = expected_time - tv.tv_sec ;
    }
  // if the end interval is faster than "the wait" time
  // then we wait for the remaining seconds
  if(diff > 0)
    {
      // fprintf(stderr, "\tWaiting: %d s\n", diff);
      sleep(diff);
      gettimeofday_wrap(&tv);
    }  
  state->tv_start = tv.tv_sec;

  // fprintf(stderr, "END INTERVAL TIME: %d \n", state->tv_start);
  return 0;
}