Пример #1
0
int bgpstream_datasource_mgr_update_input_queue(
  bgpstream_datasource_mgr_t *datasource_mgr, bgpstream_input_mgr_t *input_mgr)
{
  bgpstream_debug("\tBSDS_MGR: get data start");
  if (datasource_mgr == NULL) {
    return -1; // no datasource manager
  }
  int results = -1;

  do {
    switch (datasource_mgr->datasource) {
#ifdef WITH_DATA_INTERFACE_SINGLEFILE
    case BGPSTREAM_DATA_INTERFACE_SINGLEFILE:
      results = bgpstream_singlefile_datasource_update_input_queue(
        datasource_mgr->singlefile_ds, input_mgr);
      break;
#endif

#ifdef WITH_DATA_INTERFACE_CSVFILE
    case BGPSTREAM_DATA_INTERFACE_CSVFILE:
      results = bgpstream_csvfile_datasource_update_input_queue(
        datasource_mgr->csvfile_ds, input_mgr);
      break;
#endif

#ifdef WITH_DATA_INTERFACE_SQLITE
    case BGPSTREAM_DATA_INTERFACE_SQLITE:
      results = bgpstream_sqlite_datasource_update_input_queue(
        datasource_mgr->sqlite_ds, input_mgr);
      break;
#endif

#ifdef WITH_DATA_INTERFACE_BROKER
    case BGPSTREAM_DATA_INTERFACE_BROKER:
      results = bgpstream_broker_datasource_update_input_queue(
        datasource_mgr->broker_ds, input_mgr);
      break;
#endif

    default:
      fprintf(stderr, "Invalid data interface\n");
      break;
    }
    if (results == 0 && datasource_mgr->blocking) {
      // results = 0 => 2+ time and database did not give any error
      sleep(datasource_mgr->backoff_time);
      datasource_mgr->backoff_time = datasource_mgr->backoff_time * 2;
      if (datasource_mgr->backoff_time > DATASOURCE_BLOCKING_MAX_WAIT) {
        datasource_mgr->backoff_time = DATASOURCE_BLOCKING_MAX_WAIT;
      }
    }
    bgpstream_debug("\tBSDS_MGR: got %d (blocking: %d)", results,
                    datasource_mgr->blocking);
  } while (datasource_mgr->blocking && results == 0);

  datasource_mgr->backoff_time = DATASOURCE_BLOCKING_MIN_WAIT;

  bgpstream_debug("\tBSDS_MGR: get data end");
  return results;
}
Пример #2
0
static void instantiate_filter(bgpstream_t *bs, bgpstream_filter_item_t *item)
{

  bgpstream_filter_type_t usetype = item->termtype;

  switch (item->termtype) {
  case BGPSTREAM_FILTER_TYPE_RECORD_TYPE:
  case BGPSTREAM_FILTER_TYPE_ELEM_PREFIX_MORE:
  case BGPSTREAM_FILTER_TYPE_ELEM_PREFIX_LESS:
  case BGPSTREAM_FILTER_TYPE_ELEM_PREFIX_ANY:
  case BGPSTREAM_FILTER_TYPE_ELEM_PREFIX_EXACT:
  case BGPSTREAM_FILTER_TYPE_ELEM_COMMUNITY:
  case BGPSTREAM_FILTER_TYPE_ELEM_PEER_ASN:
  case BGPSTREAM_FILTER_TYPE_PROJECT:
  case BGPSTREAM_FILTER_TYPE_COLLECTOR:
  case BGPSTREAM_FILTER_TYPE_ELEM_ASPATH:
  case BGPSTREAM_FILTER_TYPE_ELEM_IP_VERSION:
  case BGPSTREAM_FILTER_TYPE_ELEM_TYPE:
    bgpstream_debug("Added filter for %s", item->value);
    bgpstream_add_filter(bs, usetype, item->value);
    break;

  default:
    bgpstream_debug("Implementation of filter type %s is still to come!",
                    bgpstream_filter_type_to_string(item->termtype));
    break;
  }
}
bgpstream_singlefile_datasource_t *
bgpstream_singlefile_datasource_create(bgpstream_filter_mgr_t *filter_mgr,
                                       char *singlefile_rib_mrtfile,
                                       char *singlefile_upd_mrtfile)
{
  bgpstream_debug("\t\tBSDS_CLIST: create singlefile_ds start");  
  bgpstream_singlefile_datasource_t *singlefile_ds = (bgpstream_singlefile_datasource_t*) malloc(sizeof(bgpstream_singlefile_datasource_t));
  if(singlefile_ds == NULL) {
    bgpstream_log_err("\t\tBSDS_CLIST: create singlefile_ds can't allocate memory");    
    return NULL; // can't allocate memory
  }
  singlefile_ds->filter_mgr = filter_mgr;
  singlefile_ds->rib_filename[0] = '\0';
  singlefile_ds->rib_header[0] = '\0';
  singlefile_ds->last_rib_filetime = 0;
  if(singlefile_rib_mrtfile != NULL)
    {
      strcpy(singlefile_ds->rib_filename, singlefile_rib_mrtfile);
    }
  singlefile_ds->update_filename[0] = '\0';
  singlefile_ds->update_header[0] = '\0';
  singlefile_ds->last_update_filetime = 0;
  if(singlefile_upd_mrtfile != NULL)
    {
      strcpy(singlefile_ds->update_filename, singlefile_upd_mrtfile);
    }
  bgpstream_debug("\t\tBSDS_CLIST: create customlist_ds end");
  return singlefile_ds;
}
Пример #4
0
/* turn on the bgpstream interface, i.e.:
 * it makes the interface ready
 * for a new get next call
*/
int bgpstream_start(bgpstream_t *bs) {
  bgpstream_debug("BS: init start");
  if(bs == NULL || (bs != NULL && bs->status != BGPSTREAM_STATUS_ALLOCATED)) {
    return 0; // nothing to init
  }

  // validate the filters that have been set
  int rc;
  if((rc = bgpstream_filter_mgr_validate(bs->filter_mgr)) != 0) {
    return rc;
  }

  // turn on datasource interface
  bgpstream_datasource_mgr_init(bs->datasource_mgr, bs->filter_mgr);
  if(bs->datasource_mgr->status == BGPSTREAM_DATASOURCE_STATUS_ON) {
    bs->status = BGPSTREAM_STATUS_ON; // interface is on
    bgpstream_debug("BS: init end: ok");
    return 0;
  }
  else{
    // interface is not on (something wrong with datasource)
    bs->status = BGPSTREAM_STATUS_ALLOCATED;
    bgpstream_debug("BS: init warning: check if the datasource provided is ok");
    bgpstream_debug("BS: init end: not ok");
    return -1;
  }
}
Пример #5
0
/* destroy the memory allocated for bgpstream filter */
void bgpstream_filter_mgr_destroy(bgpstream_filter_mgr_t *bs_filter_mgr)
{
  bgpstream_debug("\tBSF_MGR:: destroy start");
  if (bs_filter_mgr == NULL) {
    return; // nothing to destroy
  }
  // destroying filters
  bgpstream_interval_filter_t *tif;
  khiter_t k;
  // projects
  if (bs_filter_mgr->projects != NULL) {
    bgpstream_str_set_destroy(bs_filter_mgr->projects);
  }
  // collectors
  if (bs_filter_mgr->collectors != NULL) {
    bgpstream_str_set_destroy(bs_filter_mgr->collectors);
  }
  // bgp_types
  if (bs_filter_mgr->bgp_types != NULL) {
    bgpstream_str_set_destroy(bs_filter_mgr->bgp_types);
  }
  // peer asns
  if (bs_filter_mgr->peer_asns != NULL) {
    bgpstream_id_set_destroy(bs_filter_mgr->peer_asns);
  }
  // aspath expressions
  if (bs_filter_mgr->aspath_exprs != NULL) {
    bgpstream_str_set_destroy(bs_filter_mgr->aspath_exprs);
  }
  // prefixes
  if (bs_filter_mgr->prefixes != NULL) {
    bgpstream_patricia_tree_destroy(bs_filter_mgr->prefixes);
  }
  // communities
  if (bs_filter_mgr->communities != NULL) {
    kh_destroy(bgpstream_community_filter, bs_filter_mgr->communities);
  }
  // time_intervals
  tif = NULL;
  while (bs_filter_mgr->time_intervals != NULL) {
    tif = bs_filter_mgr->time_intervals;
    bs_filter_mgr->time_intervals = bs_filter_mgr->time_intervals->next;
    free(tif);
  }
  // rib/update frequency
  if (bs_filter_mgr->last_processed_ts != NULL) {
    for (k = kh_begin(bs_filter_mgr->last_processed_ts);
         k != kh_end(bs_filter_mgr->last_processed_ts); ++k) {
      if (kh_exist(bs_filter_mgr->last_processed_ts, k)) {
        free(kh_key(bs_filter_mgr->last_processed_ts, k));
      }
    }
    kh_destroy(collector_ts, bs_filter_mgr->last_processed_ts);
  }
  // free the mgr structure
  free(bs_filter_mgr);
  bs_filter_mgr = NULL;
  bgpstream_debug("\tBSF_MGR:: destroy end");
}
Пример #6
0
/* configure the interface so that it blocks
 * waiting for new data
 */
void bgpstream_set_live_mode(bgpstream_t *bs) {
  bgpstream_debug("BS: set_live_mode start");
  if(bs == NULL || (bs != NULL && bs->status != BGPSTREAM_STATUS_ALLOCATED)) {
    return; // nothing to customize
  }
  bgpstream_datasource_mgr_set_blocking(bs->datasource_mgr);
  bgpstream_debug("BS: set_blocking stop");
}
Пример #7
0
/* turn off the bgpstream interface */
void bgpstream_stop(bgpstream_t *bs) {
  bgpstream_debug("BS: close start");
  if(bs == NULL || (bs != NULL && bs->status != BGPSTREAM_STATUS_ON)) {
    return; // nothing to close
  }
  bgpstream_datasource_mgr_close(bs->datasource_mgr);
  bs->status = BGPSTREAM_STATUS_OFF; // interface is off
  bgpstream_debug("BS: close end");
}
Пример #8
0
/* configure the interface so that it connects
 * to a specific datasource interface
 */
void bgpstream_set_data_interface(bgpstream_t *bs,
                                  bgpstream_data_interface_id_t datasource) {
  bgpstream_debug("BS: set_data_interface start");
  if(bs == NULL || (bs != NULL && bs->status != BGPSTREAM_STATUS_ALLOCATED)) {
    return; // nothing to customize
  }
  bgpstream_datasource_mgr_set_data_interface(bs->datasource_mgr, datasource);
  bgpstream_debug("BS: set_data_interface stop");
}
Пример #9
0
void bgpstream_add_rib_period_filter(bgpstream_t *bs, uint32_t period)
{
  bgpstream_debug("BS: set_filter start");
  if(bs == NULL || (bs != NULL && bs->status != BGPSTREAM_STATUS_ALLOCATED)) {
    return; // nothing to customize
  }
  bgpstream_filter_mgr_rib_period_filter_add(bs->filter_mgr, period);
  bgpstream_debug("BS: set_filter end");
}
Пример #10
0
void bgpstream_datasource_mgr_init(bgpstream_datasource_mgr_t *datasource_mgr,
                                   bgpstream_filter_mgr_t *filter_mgr)
{
  bgpstream_debug("\tBSDS_MGR: init start");
  if (datasource_mgr == NULL) {
    return; // no manager
  }

  void *ds = NULL;

  switch (datasource_mgr->datasource) {
#ifdef WITH_DATA_INTERFACE_SINGLEFILE
  case BGPSTREAM_DATA_INTERFACE_SINGLEFILE:
    datasource_mgr->singlefile_ds = bgpstream_singlefile_datasource_create(
      filter_mgr, datasource_mgr->singlefile_rib_mrtfile,
      datasource_mgr->singlefile_upd_mrtfile);
    ds = (void *)datasource_mgr->singlefile_ds;
    break;
#endif

#ifdef WITH_DATA_INTERFACE_CSVFILE
  case BGPSTREAM_DATA_INTERFACE_CSVFILE:
    datasource_mgr->csvfile_ds = bgpstream_csvfile_datasource_create(
      filter_mgr, datasource_mgr->csvfile_file);
    ds = (void *)datasource_mgr->csvfile_ds;
    break;
#endif

#ifdef WITH_DATA_INTERFACE_SQLITE
  case BGPSTREAM_DATA_INTERFACE_SQLITE:
    datasource_mgr->sqlite_ds = bgpstream_sqlite_datasource_create(
      filter_mgr, datasource_mgr->sqlite_file);
    ds = (void *)datasource_mgr->sqlite_ds;
    break;
#endif

#ifdef WITH_DATA_INTERFACE_BROKER
  case BGPSTREAM_DATA_INTERFACE_BROKER:
    datasource_mgr->broker_ds = bgpstream_broker_datasource_create(
      filter_mgr, datasource_mgr->broker_url, datasource_mgr->broker_params,
      datasource_mgr->broker_params_cnt);
    ds = (void *)datasource_mgr->broker_ds;
    break;
#endif

  default:
    ds = NULL;
  }

  if (ds == NULL) {
    datasource_mgr->status = BGPSTREAM_DATASOURCE_STATUS_ERROR;
  } else {
    datasource_mgr->status = BGPSTREAM_DATASOURCE_STATUS_ON;
  }
  bgpstream_debug("\tBSDS_MGR: init end");
}
Пример #11
0
void bgpstream_datasource_mgr_set_blocking(
  bgpstream_datasource_mgr_t *datasource_mgr)
{
  bgpstream_debug("\tBSDS_MGR: set blocking start");
  if (datasource_mgr == NULL) {
    return; // no manager
  }
  datasource_mgr->blocking = 1;
  bgpstream_debug("\tBSDS_MGR: set blocking end");
}
Пример #12
0
/* configure filters in order to select a subset of the bgp data available */
void bgpstream_add_filter(bgpstream_t *bs,
                          bgpstream_filter_type_t filter_type,
			  const char* filter_value) {
  bgpstream_debug("BS: set_filter start");
  if(bs == NULL || (bs != NULL && bs->status != BGPSTREAM_STATUS_ALLOCATED)) {
    return; // nothing to customize
  }
  bgpstream_filter_mgr_filter_add(bs->filter_mgr, filter_type, filter_value);
  bgpstream_debug("BS: set_filter end");
}
Пример #13
0
/* allocate memory for a new bgpstream filter */
bgpstream_filter_mgr_t *bgpstream_filter_mgr_create()
{
  bgpstream_debug("\tBSF_MGR: create start");
  bgpstream_filter_mgr_t *bs_filter_mgr =
    (bgpstream_filter_mgr_t *)malloc_zero(sizeof(bgpstream_filter_mgr_t));
  if (bs_filter_mgr == NULL) {
    return NULL; // can't allocate memory
  }
  bgpstream_debug("\tBSF_MGR: create end");
  return bs_filter_mgr;
}
void
bgpstream_singlefile_datasource_destroy(bgpstream_singlefile_datasource_t* singlefile_ds)
{
  bgpstream_debug("\t\tBSDS_CLIST: destroy singlefile_ds start");  
  if(singlefile_ds == NULL) {
    return; // nothing to destroy
  }
  singlefile_ds->filter_mgr = NULL;
  free(singlefile_ds);
  bgpstream_debug("\t\tBSDS_CLIST: destroy singlefile_ds end");  
}
Пример #15
0
void bgpstream_datasource_mgr_set_data_interface(
  bgpstream_datasource_mgr_t *datasource_mgr,
  const bgpstream_data_interface_id_t datasource)
{
  bgpstream_debug("\tBSDS_MGR: set data interface start");
  if (datasource_mgr == NULL) {
    return; // no manager
  }
  datasource_mgr->datasource = datasource;
  bgpstream_debug("\tBSDS_MGR: set  data interface end");
}
int
bgpstream_csvfile_datasource_update_input_queue(bgpstream_csvfile_datasource_t* csvfile_ds,
                                                bgpstream_input_mgr_t *input_mgr) {
  bgpstream_debug("\t\tBSDS_CSVFILE: csvfile_ds update input queue start");
  
  io_t *file_io = NULL;
  char buffer[BUFFER_LEN];
  int read = 0;

  struct timeval tv;
  gettimeofday(&tv, NULL);
  
  /* we accept all timestamp earlier than now() - 1 second */
  csvfile_ds->max_accepted_ts = tv.tv_sec - 1;

  csvfile_ds->num_results = 0;
  csvfile_ds->max_ts_infile = 0;
  csvfile_ds->input_mgr = input_mgr;
  
  if((file_io = wandio_create(csvfile_ds->csvfile_file)) == NULL)
    {
      bgpstream_log_err("\t\tBSDS_CSVFILE: create csvfile_ds can't open file %s", csvfile_ds->csvfile_file);    
      return -1;
    }

    while((read = wandio_read(file_io, &buffer, BUFFER_LEN)) > 0)
    {
      if(csv_parse(&(csvfile_ds->parser), buffer, read,
		   parse_csvfile_field,
		   parse_csvfile_rowend,
		   csvfile_ds) != read)
	{
          bgpstream_log_err("\t\tBSDS_CSVFILE: CSV error %s", csv_strerror(csv_error(&(csvfile_ds->parser))));         
	  return -1;
	}
    }

  if(csv_fini(&(csvfile_ds->parser),
	      parse_csvfile_field,
	      parse_csvfile_rowend,
	      csvfile_ds) != 0)
    {
      bgpstream_log_err("\t\tBSDS_CSVFILE: CSV error %s", csv_strerror(csv_error(&(csvfile_ds->parser))));         
      return -1;
    }
  
  wandio_destroy(file_io);
  csvfile_ds->input_mgr = NULL;
  csvfile_ds->last_processed_ts = csvfile_ds->max_ts_infile;
  
  bgpstream_debug("\t\tBSDS_CSVFILE: csvfile_ds update input queue end");
  return csvfile_ds->num_results;
}
Пример #17
0
void bgpstream_add_interval_filter(bgpstream_t *bs,
				   uint32_t begin_time,
                                   uint32_t end_time) {
  bgpstream_debug("BS: set_filter start");
  if(bs == NULL || (bs != NULL && bs->status != BGPSTREAM_STATUS_ALLOCATED)) {
    return; // nothing to customize
  }
  if(end_time == BGPSTREAM_FOREVER) {
    bgpstream_set_live_mode(bs);
  }
  bgpstream_filter_mgr_interval_filter_add(bs->filter_mgr, begin_time, end_time);
  bgpstream_debug("BS: set_filter end");
}
Пример #18
0
void bgpstream_filter_mgr_rib_period_filter_add(
  bgpstream_filter_mgr_t *bs_filter_mgr, uint32_t period)
{
  bgpstream_debug("\tBSF_MGR:: add_filter start");
  assert(bs_filter_mgr != NULL);
  if (period != 0 && bs_filter_mgr->last_processed_ts == NULL) {
    if ((bs_filter_mgr->last_processed_ts = kh_init(collector_ts)) == NULL) {
      bgpstream_log_warn(
        "\tBSF_MGR: can't allocate memory for collectortype map");
    }
  }
  bs_filter_mgr->rib_period = period;
  bgpstream_debug("\tBSF_MGR:: add_filter end");
}
Пример #19
0
void bgpstream_set_data_interface_option(bgpstream_t *bs,
			        bgpstream_data_interface_option_t *option_type,
                                const char *option_value) {

  bgpstream_debug("BS: set_data_interface_options start");
  if(bs == NULL || (bs != NULL && bs->status != BGPSTREAM_STATUS_ALLOCATED)) {
    return; // nothing to customize
  }

  bgpstream_datasource_mgr_set_data_interface_option(bs->datasource_mgr,
                                                     option_type, option_value);

  bgpstream_debug("BS: set_data_interface_options stop");
}
bgpstream_csvfile_datasource_t *
bgpstream_csvfile_datasource_create(bgpstream_filter_mgr_t *filter_mgr, 
                                    char *csvfile_file)
{
  bgpstream_debug("\t\tBSDS_CSVFILE: create csvfile_ds start");  
  bgpstream_csvfile_datasource_t *csvfile_ds = (bgpstream_csvfile_datasource_t*) malloc_zero(sizeof(bgpstream_csvfile_datasource_t));
  if(csvfile_ds == NULL) {
    bgpstream_log_err("\t\tBSDS_CSVFILE: create csvfile_ds can't allocate memory");    
    goto err;
  }  
  if(csvfile_file == NULL)
    {
      bgpstream_log_err("\t\tBSDS_CSVFILE: create csvfile_ds no file provided");    
      goto err;
    }
  if((csvfile_ds->csvfile_file = strdup(csvfile_file)) == NULL)
    {
      bgpstream_log_err("\t\tBSDS_CSVFILE: can't allocate memory for filename");    
      goto err;
    }
  
  /* cvs file parser options */
  unsigned char options = CSV_STRICT | CSV_REPALL_NL | CSV_STRICT_FINI |
                CSV_APPEND_NULL | CSV_EMPTY_IS_NULL;

  if(csv_init(&(csvfile_ds->parser), options) !=0)
    {
      bgpstream_log_err("\t\tBSDS_CSVFILE: can't initialize csv parser");    
      goto err;
    }

  csvfile_ds->current_field = CSVFILE_PATH;
  
  csvfile_ds->filter_mgr = filter_mgr;
  csvfile_ds->input_mgr = NULL;

  csvfile_ds->num_results = 0;

  csvfile_ds->max_ts_infile = 0;
  csvfile_ds->last_processed_ts = 0;
  csvfile_ds->max_accepted_ts = 0;

  bgpstream_debug("\t\tBSDS_CSVFILE: create csvfile_ds end");
  return csvfile_ds;
  
 err:
  bgpstream_csvfile_datasource_destroy(csvfile_ds);
  return NULL;
}
Пример #21
0
/* destroy a bgpstream interface istance
 */
void bgpstream_destroy(bgpstream_t *bs){
  bgpstream_debug("BS: destroy start");
  if(bs == NULL) {
    return; // nothing to destroy
  }
  bgpstream_input_mgr_destroy(bs->input_mgr);
  bs->input_mgr = NULL;
  bgpstream_reader_mgr_destroy(bs->reader_mgr);
  bs->reader_mgr = NULL;
  bgpstream_filter_mgr_destroy(bs->filter_mgr);
  bs->filter_mgr = NULL;
  bgpstream_datasource_mgr_destroy(bs->datasource_mgr);
  bs->datasource_mgr = NULL;
  free(bs);
  bgpstream_debug("BS: destroy end");
}
Пример #22
0
static int bgpstream_parse_quotedvalue(char *value, fp_state_t *state,
                                       bgpstream_filter_item_t *curr)
{

  char *endquote = NULL;

  /* Check for end quote */
  endquote = strchr(value, '"');

  if (endquote != NULL) {
    *endquote = '\0';
    *state = ENDVALUE;
  }

  if (strlen(value) == 0)
    return *state;

  if (curr->value == NULL) {
    curr->value = strdup(value);
  } else {
    /* Append this part of the value to whatever we've already got */
    /* +2 = 1 byte for space, 1 byte for null */
    curr->value = realloc(curr->value, strlen(curr->value) + strlen(value) + 2);
    assert(curr->value);
    strncat(curr->value, " ", 1);
    strncat(curr->value, value, strlen(value));
  }

  if (*state == ENDVALUE) {
    /* Create our new filter here? */
    bgpstream_debug("Set our quoted value to %s", curr->value);
  }

  return *state;
}
Пример #23
0
bgpstream_datasource_mgr_t *bgpstream_datasource_mgr_create()
{
  bgpstream_debug("\tBSDS_MGR: create start");
  bgpstream_datasource_mgr_t *datasource_mgr =
    (bgpstream_datasource_mgr_t *)malloc(sizeof(bgpstream_datasource_mgr_t));
  if (datasource_mgr == NULL) {
    return NULL; // can't allocate memory
  }
  // default values
  datasource_mgr->datasource =
    BGPSTREAM_DATA_INTERFACE_BROKER; // default data source
  datasource_mgr->blocking = 0;
  datasource_mgr->backoff_time = DATASOURCE_BLOCKING_MIN_WAIT;
// datasources (none of them is active at the beginning)

#ifdef WITH_DATA_INTERFACE_SINGLEFILE
  datasource_mgr->singlefile_ds = NULL;
  GET_DEFAULT_STR_VALUE(datasource_mgr->singlefile_rib_mrtfile,
                        BGPSTREAM_DS_SINGLEFILE_RIB_FILE);
  GET_DEFAULT_STR_VALUE(datasource_mgr->singlefile_upd_mrtfile,
                        BGPSTREAM_DS_SINGLEFILE_UPDATE_FILE);
#endif

#ifdef WITH_DATA_INTERFACE_CSVFILE
  datasource_mgr->csvfile_ds = NULL;
  GET_DEFAULT_STR_VALUE(datasource_mgr->csvfile_file,
                        BGPSTREAM_DS_CSVFILE_CSV_FILE);
#endif

#ifdef WITH_DATA_INTERFACE_SQLITE
  datasource_mgr->sqlite_ds = NULL;
  GET_DEFAULT_STR_VALUE(datasource_mgr->sqlite_file,
                        BGPSTREAM_DS_SQLITE_DB_FILE);
#endif

#ifdef WITH_DATA_INTERFACE_BROKER
  datasource_mgr->broker_ds = NULL;
  GET_DEFAULT_STR_VALUE(datasource_mgr->broker_url, BGPSTREAM_DS_BROKER_URL);
  datasource_mgr->broker_params = NULL;
  datasource_mgr->broker_params_cnt = 0;
#endif

  datasource_mgr->status = BGPSTREAM_DATASOURCE_STATUS_OFF;

  bgpstream_debug("\tBSDS_MGR: create end");
  return datasource_mgr;
}
void
bgpstream_csvfile_datasource_destroy(bgpstream_csvfile_datasource_t* csvfile_ds) {
  bgpstream_debug("\t\tBSDS_CSVFILE: destroy csvfile_ds start");  
  if(csvfile_ds == NULL) {
    return; // nothing to destroy
  }
  csvfile_ds->filter_mgr = NULL;
  if(csvfile_ds->csvfile_file !=NULL)
    {
      free(csvfile_ds->csvfile_file);
    }
  if(&(csvfile_ds->parser) != NULL)
    {
      csv_free(&(csvfile_ds->parser));
    }
  free(csvfile_ds);
  bgpstream_debug("\t\tBSDS_CSVFILE: destroy csvfile_ds end");  
}
Пример #25
0
void bgpstream_datasource_mgr_destroy(
  bgpstream_datasource_mgr_t *datasource_mgr)
{
  bgpstream_debug("\tBSDS_MGR: destroy start");
  if (datasource_mgr == NULL) {
    return; // no manager to destroy
  }
// destroy any active datasource (if they have not been destroyed before)
#ifdef WITH_DATA_INTERFACE_SINGLEFILE
  bgpstream_singlefile_datasource_destroy(datasource_mgr->singlefile_ds);
  datasource_mgr->singlefile_ds = NULL;
  free(datasource_mgr->singlefile_rib_mrtfile);
  free(datasource_mgr->singlefile_upd_mrtfile);
#endif

#ifdef WITH_DATA_INTERFACE_CSVFILE
  bgpstream_csvfile_datasource_destroy(datasource_mgr->csvfile_ds);
  datasource_mgr->csvfile_ds = NULL;
  free(datasource_mgr->csvfile_file);
#endif

#ifdef WITH_DATA_INTERFACE_SQLITE
  bgpstream_sqlite_datasource_destroy(datasource_mgr->sqlite_ds);
  datasource_mgr->sqlite_ds = NULL;
  free(datasource_mgr->sqlite_file);
#endif

#ifdef WITH_DATA_INTERFACE_BROKER
  bgpstream_broker_datasource_destroy(datasource_mgr->broker_ds);
  datasource_mgr->broker_ds = NULL;
  free(datasource_mgr->broker_url);
  int i;
  for (i = 0; i < datasource_mgr->broker_params_cnt; i++) {
    free(datasource_mgr->broker_params[i]);
    datasource_mgr->broker_params[i] = NULL;
  }
  free(datasource_mgr->broker_params);
  datasource_mgr->broker_params = NULL;
  datasource_mgr->broker_params_cnt = 0;
#endif

  free(datasource_mgr);
  bgpstream_debug("\tBSDS_MGR: destroy end");
}
Пример #26
0
void bgpstream_datasource_mgr_close(bgpstream_datasource_mgr_t *datasource_mgr)
{
  bgpstream_debug("\tBSDS_MGR: close start");
  if (datasource_mgr == NULL) {
    return; // no manager to destroy
  }
  switch (datasource_mgr->datasource) {
#ifdef WITH_DATA_INTERFACE_SINGLEFILE
  case BGPSTREAM_DATA_INTERFACE_SINGLEFILE:
    bgpstream_singlefile_datasource_destroy(datasource_mgr->singlefile_ds);
    datasource_mgr->singlefile_ds = NULL;
    break;
#endif

#ifdef WITH_DATA_INTERFACE_CSVFILE
  case BGPSTREAM_DATA_INTERFACE_CSVFILE:
    bgpstream_csvfile_datasource_destroy(datasource_mgr->csvfile_ds);
    datasource_mgr->csvfile_ds = NULL;
    break;
#endif

#ifdef WITH_DATA_INTERFACE_SQLITE
  case BGPSTREAM_DATA_INTERFACE_SQLITE:
    bgpstream_sqlite_datasource_destroy(datasource_mgr->sqlite_ds);
    datasource_mgr->sqlite_ds = NULL;
    break;
#endif

#ifdef WITH_DATA_INTERFACE_BROKER
  case BGPSTREAM_DATA_INTERFACE_BROKER:
    bgpstream_broker_datasource_destroy(datasource_mgr->broker_ds);
    datasource_mgr->broker_ds = NULL;
    break;
#endif

  default:
    assert(0);
    break;
  }
  datasource_mgr->status = BGPSTREAM_DATASOURCE_STATUS_OFF;
  bgpstream_debug("\tBSDS_MGR: close end");
}
int
bgpstream_singlefile_datasource_update_input_queue(bgpstream_singlefile_datasource_t* singlefile_ds,
                                                   bgpstream_input_mgr_t *input_mgr)
{
    bgpstream_debug("\t\tBSDS_CLIST: singlefile_ds update input queue start");
    struct timeval tv;
    gettimeofday(&tv, NULL);
    uint32_t now  = tv.tv_sec;
    int num_results = 0;
    
    /* check digest, if different (or first) then add files to input queue) */
    if(singlefile_ds->rib_filename[0] != '\0' &&
       now - singlefile_ds->last_rib_filetime > RIB_FREQUENCY_CHECK  &&
       same_header(singlefile_ds->rib_filename, singlefile_ds->rib_header) == 0)
      {
        /* fprintf(stderr, "new RIB at: %"PRIu32"\n", now); */
        singlefile_ds->last_rib_filetime = now;
        num_results += bgpstream_input_mgr_push_sorted_input(input_mgr, strdup(singlefile_ds->rib_filename),
							     strdup("singlefile_ds"),
							     strdup("singlefile_ds"),
                                                             strdup("ribs"),
							     singlefile_ds->last_rib_filetime,
                                                             RIB_FREQUENCY_CHECK);
      }

    if(singlefile_ds->update_filename[0] != '\0' &&
       now - singlefile_ds->last_update_filetime > UPDATE_FREQUENCY_CHECK  &&
       same_header(singlefile_ds->update_filename, singlefile_ds->update_header) == 0)
      {
        /* fprintf(stderr, "new updates at: %"PRIu32"\n", now); */
        singlefile_ds->last_update_filetime = now;
        num_results += bgpstream_input_mgr_push_sorted_input(input_mgr, strdup(singlefile_ds->update_filename),
							     strdup("singlefile_ds"),
							     strdup("singlefile_ds"),
                                                             strdup("updates"),
							     singlefile_ds->last_update_filetime,
                                                             UPDATE_FREQUENCY_CHECK);
      }
    
    bgpstream_debug("\t\tBSDS_CLIST: singlefile_ds update input queue end");  
    return num_results;
}
Пример #28
0
static int bgpstream_parse_prefixext(char *ext, fp_state_t *state,
                                     bgpstream_filter_item_t *curr)
{

  assert(curr->termtype == BGPSTREAM_FILTER_TYPE_ELEM_PREFIX_MORE);

  if (strcmp(ext, "any") == 0) {
    /* Any prefix that our prefix belongs to */
    bgpstream_debug("Got an 'any' prefix");
    curr->termtype = BGPSTREAM_FILTER_TYPE_ELEM_PREFIX_ANY;
    *state = VALUE;
    return *state;
  }

  if (strcmp(ext, "more") == 0) {
    /* Either match this prefix or any more specific prefixes */
    bgpstream_debug("Got an 'more' prefix");
    curr->termtype = BGPSTREAM_FILTER_TYPE_ELEM_PREFIX_MORE;
    *state = VALUE;
    return *state;
  }

  if (strcmp(ext, "less") == 0) {
    /* Either match this prefix or any less specific prefixes */
    bgpstream_debug("Got an 'less' prefix");
    curr->termtype = BGPSTREAM_FILTER_TYPE_ELEM_PREFIX_LESS;
    *state = VALUE;
    return *state;
  }

  if (strcmp(ext, "exact") == 0) {
    /* Only match exactly this prefix */
    bgpstream_debug("Got an 'exact' prefix");
    curr->termtype = BGPSTREAM_FILTER_TYPE_ELEM_PREFIX_EXACT;
    *state = VALUE;
    return *state;
  }

  /* At this point, assume we're looking at a value instead */
  return bgpstream_parse_value(ext, state, curr);
}
Пример #29
0
/* allocate memory for a bs_record */
bgpstream_record_t *bgpstream_record_create()
{
  bgpstream_debug("BS: create record start");
  bgpstream_record_t *bs_record;
  if ((bs_record = (bgpstream_record_t *)malloc(sizeof(bgpstream_record_t))) ==
      NULL) {
    return NULL; // can't allocate memory
  }

  bs_record->bs = NULL;
  bs_record->bd_entry = NULL;

  if ((bs_record->elem_generator = bgpstream_elem_generator_create()) == NULL) {
    bgpstream_record_destroy(bs_record);
    return NULL;
  }

  bgpstream_record_clear(bs_record);

  bgpstream_debug("BS: create record end");
  return bs_record;
}
Пример #30
0
/* free memory associated to a bs_record  */
void bgpstream_record_destroy(bgpstream_record_t *const bs_record)
{
  bgpstream_debug("BS: destroy record start");
  if (bs_record == NULL) {
    bgpstream_debug("BS: record destroy end");
    return; // nothing to do
  }
  if (bs_record->bd_entry != NULL) {
    bgpstream_debug("BS - free bs_record->bgpdump_entry");
    bgpdump_free_mem(bs_record->bd_entry);
    bs_record->bd_entry = NULL;
  }

  if (bs_record->elem_generator != NULL) {
    bgpstream_elem_generator_destroy(bs_record->elem_generator);
    bs_record->elem_generator = NULL;
  }

  bgpstream_debug("BS - free bs_record");
  free(bs_record);
  bgpstream_debug("BS: destroy record end");
}