Beispiel #1
0
/**
 * context: {router, peer}
 * tokens: {file|-}
 */
static int cli_peer_record(cli_ctx_t * ctx,
			   cli_cmd_t * cmd)
{
  bgp_peer_t * peer= _peer_from_context(ctx);
  const char * arg= cli_get_arg_value(cmd, 0);
  gds_stream_t * stream;
  
  /* Get filename */
  if (strcmp(arg, "-") == 0) {
    bgp_peer_set_record_stream(peer, NULL);
  } else {
    stream= stream_create_file(arg);
    if (stream == NULL) {
      cli_set_user_error(cli_get(), "could not open \"%s\" for writing", arg);
      return CLI_ERROR_COMMAND_FAILED;
    }
    if (bgp_peer_set_record_stream(peer, stream) < 0) {
      stream_destroy(&stream);
      cli_set_user_error(cli_get(), "could not set the peer record stream");
      return CLI_ERROR_COMMAND_FAILED;
    }
  }

  return CLI_SUCCESS;
}
Beispiel #2
0
/**
 * context: {}
 * tokens : {}
 * options: {--output=FILE}
 */
static int cli_bgp_topology_stat(cli_ctx_t * ctx, cli_cmd_t * cmd)
{
  gds_stream_t * stream= gdsout;
  as_level_topo_t * topo= aslevel_get_topo();
  const char * arg;

  if (topo == NULL) {
    cli_set_user_error(cli_get(), "no topology loaded");
    return CLI_ERROR_COMMAND_FAILED;
  }

  arg= cli_get_opt_value(cmd, "output");
  if (arg != NULL) {
    stream= stream_create_file(arg);
    if (stream == NULL) {
      cli_set_user_error(cli_get(), "unable to create \"%s\"", arg);
      return CLI_ERROR_COMMAND_FAILED;
    }
  }

  aslevel_stat_degree(stream, topo, 1, 1, 1);
  
  if (stream != gdsout)
    stream_destroy(&stream);

  return CLI_SUCCESS;
}
Beispiel #3
0
/**
 * context: {}
 * tokens : {}
 * options: {--output=FILE}
 */
static int cli_bgp_topology_dump(cli_ctx_t * ctx, cli_cmd_t * cmd)
{
  gds_stream_t * stream= gdsout;
  const char * arg;
  int result;

  arg= cli_get_opt_value(cmd, "output");
  if (arg != NULL) {
    stream= stream_create_file(arg);
    if (stream == NULL) {
      cli_set_user_error(cli_get(), "unable to create \"%s\"", arg);
      return CLI_ERROR_COMMAND_FAILED;
    }
  }

  //  result= aslevel_topo_dump_stubs(stream);
  result= aslevel_topo_dump(stream);

  if (stream != gdsout)
    stream_destroy(&stream);

  if (result != ASLEVEL_SUCCESS) {
    cli_set_user_error(cli_get(), "could not dump topology (%s)",
		       aslevel_strerror(result));
    return CLI_ERROR_COMMAND_FAILED;
  }

  return CLI_SUCCESS;
}
static void _set_log_progress(sched_t * self, const char * filename)
{
  sched_static_t * sched= (sched_static_t *) self;

  if (sched->pProgressLogStream != NULL)
    stream_destroy(&sched->pProgressLogStream);

  if (filename != NULL) {
    sched->pProgressLogStream= stream_create_file(filename);
    stream_printf(sched->pProgressLogStream, "# C-BGP Queue Progress\n");
    stream_printf(sched->pProgressLogStream, "# <step> <time (us)> <depth>\n");
  }
}
Beispiel #5
0
/**
 * context: {}
 * tokens : {prefix}
 * options: {--output=FILE,--exact-match,--preserve-dups}
 */
static int cli_bgp_topology_recordroute(cli_ctx_t * ctx, cli_cmd_t * cmd)
{
  ip_pfx_t prefix;
  gds_stream_t * stream= gdsout;
  const char * arg= cli_get_arg_value(cmd, 0);
  int result;
  uint8_t options= 0;

  // Destination prefix
  if (str2prefix(arg, &prefix) < 0) {
    cli_set_user_error(cli_get(), "invalid prefix \"%s\"", arg);
    return CLI_ERROR_COMMAND_FAILED;
  }

  // Optional output file ?
  arg= cli_get_opt_value(cmd, "output");
  if (arg != NULL) {
    stream= stream_create_file(arg);
    if (stream == NULL) {
      cli_set_user_error(cli_get(), "unable to create \"%s\"", arg);
      return CLI_ERROR_COMMAND_FAILED;
    }
  }

  if (cli_has_opt_value(cmd, "exact-match"))
    options|= AS_RECORD_ROUTE_OPT_EXACT_MATCH;
  if (cli_has_opt_value(cmd, "preserve-dups"))
    options|= AS_RECORD_ROUTE_OPT_PRESERVE_DUPS;

  // Record routes
  result= aslevel_topo_record_route(stream, prefix, options);
  if (result != ASLEVEL_SUCCESS) {
    cli_set_user_error(cli_get(), "could not record route (%s)",
		       aslevel_strerror(result));
    return CLI_ERROR_COMMAND_FAILED;
  }

  if (stream != gdsout)
    stream_destroy(&stream);

  return CLI_SUCCESS;
}
Beispiel #6
0
/**
 * context: {}
 * tokens : {file}
 */
int cli_net_traffic_save(cli_ctx_t * ctx, cli_cmd_t * cmd)
{
  const char * arg= cli_get_arg_value(cmd, 0);
  gds_stream_t * stream;
  int result;

  // Get the optional parameter
  stream= stream_create_file(arg);
  if (stream == NULL) {
    cli_set_user_error(cli_get(), "could not create \"%d\"", arg);
    return CLI_ERROR_COMMAND_FAILED;
  }

  // Save traffic matrix
  result= network_links_save(stream, network_get_default());
  if (result != 0) {
    cli_set_user_error(cli_get(), "could not save traffic matrix (%s)",
		       network_strerror(result));
    return CLI_ERROR_COMMAND_FAILED;
  }

  return CLI_SUCCESS;
}
Beispiel #7
0
int main(int argc, char **argv)
{
    demux_res_t demux_res;
    unsigned int output_size, i;

    set_endian();

    setup_environment(argc, argv);

    input_stream = stream_create_file(input_file, 1);
    if (!input_stream)
    {
        fprintf(stderr, "failed to create input stream from file\n");
        return 0;
    }

    /* if qtmovie_read returns successfully, the stream is up to
     * the movie data, which can be used directly by the decoder */
    if (!qtmovie_read(input_stream, &demux_res))
    {
        fprintf(stderr, "failed to load the QuickTime movie headers\n");
        return 0;
    }

    /* initialise the sound converter */
    init_sound_converter(&demux_res);

    /* write wav output headers */
    if (write_wav_format)
    {
        /* calculate output size */
        output_size = 0;
        for (i = 0; i < demux_res.num_sample_byte_sizes; i++)
        {
            unsigned int thissample_duration;
            unsigned int thissample_bytesize;

            get_sample_info(&demux_res, i, &thissample_duration,
                            &thissample_bytesize);

            output_size += thissample_duration * (demux_res.sample_size / 8)
                           * demux_res.num_channels;
        }
        wavwriter_writeheaders(output_file,
                               output_size,
                               demux_res.num_channels,
                               demux_res.sample_rate,
                               demux_res.sample_size);
    }

    /* will convert the entire buffer */
    GetBuffer(&demux_res);

    stream_destroy(input_stream);

    if (output_opened)
        fclose(output_file);

    if (input_opened)
        fclose(input_file);

    return 0;
}