Пример #1
0
/** Implements the init_output function of the plugin API */
int bgpcorsaro_pfxmonitor_init_output(bgpcorsaro_t *bgpcorsaro)
{
  struct bgpcorsaro_pfxmonitor_state_t *state;
  bgpcorsaro_plugin_t *plugin = PLUGIN(bgpcorsaro);
  assert(plugin != NULL);

  if ((state = malloc_zero(sizeof(struct bgpcorsaro_pfxmonitor_state_t))) ==
      NULL) {
    bgpcorsaro_log(__func__, bgpcorsaro,
                   "could not malloc bgpcorsaro_pfxmonitor_state_t");
    goto err;
  }
  bgpcorsaro_plugin_register_state(bgpcorsaro->plugin_manager, plugin, state);

  /* initialize state with default values */
  state = STATE(bgpcorsaro);
  strncpy(state->metric_prefix, PFXMONITOR_DEFAULT_METRIC_PFX,
          PFXMONITOR_METRIC_PFX_LEN);
  strncpy(state->ip_space_name, PFXMONITOR_DEFAULT_IPSPACE_NAME,
          PFXMONITOR_METRIC_PFX_LEN);

  if ((state->poi = bgpstream_ip_counter_create()) == NULL) {
    goto err;
  }
  state->peer_asns_th = PFXMONITOR_DEFAULT_PEER_ASNS_THRESHOLD;
  state->more_specific = 0;

  /* parse the arguments */
  if (parse_args(bgpcorsaro) != 0) {
    goto err;
  }

  graphite_safe(state->metric_prefix);
  graphite_safe(state->ip_space_name);

  /* create all the sets and maps we need */
  if ((state->overlapping_pfx_cache = bgpstream_pfx_storage_set_create()) ==
        NULL ||
      (state->non_overlapping_pfx_cache = bgpstream_pfx_storage_set_create()) ==
        NULL ||
      (state->pfx_info = kh_init(pfx_info_map)) == NULL ||
      (state->unique_origins = bgpstream_id_set_create()) == NULL ||
      (state->peer_asns = bgpstream_id_set_create()) == NULL) {
    goto err;
  }

  /* defer opening the output file until we start the first interval */

  return 0;

err:
  bgpcorsaro_pfxmonitor_close_output(bgpcorsaro);
  return -1;
}
Пример #2
0
/** Implements the init_output function of the plugin API */
int bgpcorsaro_pacifier_init_output(bgpcorsaro_t *bgpcorsaro)
{
  struct bgpcorsaro_pacifier_state_t *state;
  bgpcorsaro_plugin_t *plugin = PLUGIN(bgpcorsaro);
  assert(plugin != NULL);

  if((state = malloc_zero(sizeof(struct bgpcorsaro_pacifier_state_t))) == NULL)
    {
      bgpcorsaro_log(__func__, bgpcorsaro,
		     "could not malloc bgpcorsaro_pacifier_state_t");
      goto err;
    }
  bgpcorsaro_plugin_register_state(bgpcorsaro->plugin_manager, plugin, state);


  // initializing state
  state = STATE(bgpcorsaro);
  state->tv_start = 0;      // 0 means it is the first interval, so the time has to be initialized at interval start
  state->wait = 30;         // 30 seconds is the default wait time, between start and end
  state->tv_first_time = 0; // 0 means it is the first interval, so the time has to be initialized at interval start
  state->intervals = 0;     // number of intervals processed
  state->adaptive = 0;      // default behavior is not adaptive
  
  /* parse the arguments */
  if(parse_args(bgpcorsaro) != 0)
    {
      return -1;
    }

  /* defer opening the output file until we start the first interval */

  return 0;

 err:
  bgpcorsaro_pacifier_close_output(bgpcorsaro);
  return -1;
}