Пример #1
0
/* Closes reader R opened by dfm_open_reader(). */
void
dfm_close_reader (struct dfm_reader *r)
{
  if (r == NULL)
    return;

  if (fh_unlock (r->lock))
    {
      /* File is still locked by another client. */
      return;
    }

  /* This was the last client, so close the underlying file. */
  if (fh_get_referent (r->fh) != FH_REF_INLINE)
    fn_close (fh_get_file_name (r->fh), r->file);
  else
    {
      /* Skip any remaining data on the inline file. */
      if (r->flags & DFM_SAW_BEGIN_DATA)
        {
          dfm_reread_record (r, 0);
          while (!dfm_eof (r))
            dfm_forward_record (r);
        }
    }

  fh_unref (r->fh);
  ds_destroy (&r->line);
  ds_destroy (&r->scratch);
  free (r);
}
Пример #2
0
int
main(void)
{
    struct ds in;

    ds_init(&in);
    while (!ds_get_line(&in, stdin)) {
        struct ofpbuf odp_key;
        struct flow flow;
        struct ds out;
        int error;
        char *s;

        /* Delete comments, skip blank lines. */
        s = ds_cstr(&in);
        if (*s == '#') {
            puts(s);
            continue;
        }
        if (strchr(s, '#')) {
            *strchr(s, '#') = '\0';
        }
        if (s[strspn(s, " ")] == '\0') {
            putchar('\n');
            continue;
        }

        /* Convert string to OVS DP key. */
        ofpbuf_init(&odp_key, 0);
        error = odp_flow_key_from_string(ds_cstr(&in), &odp_key);
        if (error) {
            printf("odp_flow_key_from_string: error\n");
            goto next;
        }

        /* Convert odp_key to flow. */
        error = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow);
        if (error) {
            printf("odp_flow_key_to_flow: error\n");
            goto next;
        }

        /* Convert cls_rule back to odp_key. */
        ofpbuf_uninit(&odp_key);
        ofpbuf_init(&odp_key, 0);
        odp_flow_key_from_flow(&odp_key, &flow);

        /* Convert odp_key to string. */
        ds_init(&out);
        odp_flow_key_format(odp_key.data, odp_key.size, &out);
        puts(ds_cstr(&out));
        ds_destroy(&out);

    next:
        ofpbuf_uninit(&odp_key);
    }
    ds_destroy(&in);

    return 0;
}
Пример #3
0
static int
parse_actions(void)
{
    struct ds in;

    ds_init(&in);
    vlog_set_levels_from_string_assert("odp_util:console:dbg");
    while (!ds_get_test_line(&in, stdin)) {
        struct ofpbuf odp_actions;
        struct ds out;
        int error;

        /* Convert string to OVS DP actions. */
        ofpbuf_init(&odp_actions, 0);
        error = odp_actions_from_string(ds_cstr(&in), NULL, &odp_actions);
        if (error) {
            printf("odp_actions_from_string: error\n");
            goto next;
        }

        /* Convert odp_actions back to string. */
        ds_init(&out);
        format_odp_actions(&out, odp_actions.data, odp_actions.size);
        puts(ds_cstr(&out));
        ds_destroy(&out);

    next:
        ofpbuf_uninit(&odp_actions);
    }
    ds_destroy(&in);

    return 0;
}
Пример #4
0
void
parse_ofp_flow_mod_file(const char *file_name, uint16_t command,
                        struct ofputil_flow_mod **fms, size_t *n_fms)
{
    size_t allocated_fms;
    FILE *stream;
    struct ds s;

    stream = !strcmp(file_name, "-") ? stdin : fopen(file_name, "r");
    if (stream == NULL) {
        ovs_fatal(errno, "%s: open", file_name);
    }

    allocated_fms = *n_fms;
    ds_init(&s);
    while (!ds_get_preprocessed_line(&s, stream)) {
        if (*n_fms >= allocated_fms) {
            *fms = x2nrealloc(*fms, &allocated_fms, sizeof **fms);
        }
        parse_ofp_flow_mod_str(&(*fms)[*n_fms], ds_cstr(&s), command, false);
        *n_fms += 1;
    }
    ds_destroy(&s);

    if (stream != stdin) {
        fclose(stream);
    }
}
Пример #5
0
static void
test_lex(const char *input)
{
    struct ds output;

    ds_init(&output);
    struct lexer lexer;

    lexer_init(&lexer, input);
    ds_clear(&output);
    while (lexer_get(&lexer) != LEX_T_END) {
        size_t len = output.length;
        lex_token_format(&lexer.token, &output);

        /* Check that the formatted version can really be parsed back
         * losslessly. */
        if (lexer.token.type != LEX_T_ERROR) {
            const char *s = ds_cstr(&output) + len;
            struct lexer l2;

            lexer_init(&l2, s);
            lexer_get(&l2);
            compare_token(&lexer.token, &l2.token);
            lexer_destroy(&l2);
        }
        ds_put_char(&output, ' ');
    }
    lexer_destroy(&lexer);

    ds_chomp(&output, ' ');
    puts(ds_cstr(&output));
    ds_destroy(&output);
}
Пример #6
0
static void
jsonrpc_log_msg(const struct jsonrpc *rpc, const char *title,
                const struct jsonrpc_msg *msg)
{
    if (VLOG_IS_DBG_ENABLED()) {
        struct ds s = DS_EMPTY_INITIALIZER;
        if (msg->method) {
            ds_put_format(&s, ", method=\"%s\"", msg->method);
        }
        if (msg->params) {
            ds_put_cstr(&s, ", params=");
            json_to_ds(msg->params, 0, &s);
        }
        if (msg->result) {
            ds_put_cstr(&s, ", result=");
            json_to_ds(msg->result, 0, &s);
        }
        if (msg->error) {
            ds_put_cstr(&s, ", error=");
            json_to_ds(msg->error, 0, &s);
        }
        if (msg->id) {
            ds_put_cstr(&s, ", id=");
            json_to_ds(msg->id, 0, &s);
        }
        VLOG_DBG("%s: %s %s%s", rpc->name, title,
                 jsonrpc_msg_type_to_string(msg->type), ds_cstr(&s));
        ds_destroy(&s);
    }
}
Пример #7
0
void
handle_acl_log(const struct flow *headers, struct ofpbuf *userdata)
{
    if (!VLOG_IS_INFO_ENABLED()) {
        return;
    }

    struct log_pin_header *lph = ofpbuf_try_pull(userdata, sizeof *lph);
    if (!lph) {
        VLOG_WARN("log data missing");
        return;
    }

    size_t name_len = userdata->size;
    char *name = name_len ? xmemdup0(userdata->data, name_len) : NULL;

    struct ds ds = DS_EMPTY_INITIALIZER;
    ds_put_cstr(&ds, "name=");
    json_string_escape(name_len ? name : "<unnamed>", &ds);
    ds_put_format(&ds, ", verdict=%s, severity=%s: ",
                  log_verdict_to_string(lph->verdict),
                  log_severity_to_string(lph->severity));
    flow_format(&ds, headers, NULL);

    VLOG_INFO("%s", ds_cstr(&ds));
    ds_destroy(&ds);
    free(name);
}
Пример #8
0
/* Generate a syntax fragment for NV and append it to STR */
static void
new_value_append_syntax (GString *str, const struct new_value *nv)
{
  switch (nv->type)
    {
    case NV_NUMERIC:
      g_string_append_printf (str, "%g", nv->v.v);
      break;
    case NV_STRING:
      {
	struct string ds = DS_EMPTY_INITIALIZER;
	syntax_gen_string (&ds, ss_cstr (nv->v.s));
	g_string_append (str, ds_cstr (&ds));
	ds_destroy (&ds);
      }
      break;
    case NV_COPY:
      g_string_append (str, "COPY");
      break;
    case NV_SYSMIS:
      g_string_append (str, "SYSMIS");
      break;
    default:
      /* Shouldn't ever happen */
      g_warning ("Invalid type in new recode value");
      g_string_append (str, "???");
      break;
    }
}
Пример #9
0
static void
test_pcap(struct ovs_cmdl_context *ctx)
{
    size_t total_count, batch_size_;
    struct pcap_file *pcap;
    int err = 0;

    pcap = ovs_pcap_open(ctx->argv[1], "rb");
    if (!pcap) {
        return;
    }

    batch_size_ = 1;
    if (ctx->argc > 2) {
        batch_size_ = strtoul(ctx->argv[2], NULL, 0);
        if (batch_size_ == 0 || batch_size_ > NETDEV_MAX_BURST) {
            ovs_fatal(0,
                      "batch_size must be between 1 and NETDEV_MAX_BURST(%u)",
                      NETDEV_MAX_BURST);
        }
    }

    fatal_signal_init();

    ct = conntrack_init();
    total_count = 0;
    for (;;) {
        struct dp_packet *packet;
        struct dp_packet_batch pkt_batch_;
        struct dp_packet_batch *batch = &pkt_batch_;

        dp_packet_batch_init(batch);
        for (int i = 0; i < batch_size_; i++) {
            err = ovs_pcap_read(pcap, &packet, NULL);
            if (err) {
                break;
            }
            dp_packet_batch_add(batch, packet);
        }
        if (dp_packet_batch_is_empty(batch)) {
            break;
        }
        pcap_batch_execute_conntrack(ct, batch);

        DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
            struct ds ds = DS_EMPTY_INITIALIZER;

            total_count++;

            format_flags(&ds, ct_state_to_string, packet->md.ct_state, '|');
            printf("%"PRIuSIZE": %s\n", total_count, ds_cstr(&ds));

            ds_destroy(&ds);
        }

        dp_packet_delete_batch(batch, true);
    }
    conntrack_destroy(ct);
    ovs_pcap_close(pcap);
}
Пример #10
0
static int
parse_actions(const char *in)
{
    struct ofpbuf odp_actions;
    struct ds out;
    int error;

    /* Convert string to OVS DP actions. */
    ofpbuf_init(&odp_actions, 0);
    error = odp_actions_from_string(in, NULL, &odp_actions);
    if (error) {
        printf("odp_actions_from_string: error\n");
        goto next;
    }

    /* Convert odp_actions back to string. */
    ds_init(&out);
    format_odp_actions(&out, odp_actions.data, odp_actions.size, NULL);
    puts(ds_cstr(&out));
    ds_destroy(&out);

next:
    ofpbuf_uninit(&odp_actions);
    return 0;
}
Пример #11
0
static void
output_frequency_table (const struct two_sample_test *t2s,
			const struct sign_test_params *param,
			const struct dictionary *dict)
{
  int i;
  struct tab_table *table = tab_create (3, 1 + 4 * t2s->n_pairs);

  const struct variable *wv = dict_get_weight (dict);
  const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0;

  tab_set_format (table, RC_WEIGHT, wfmt);
  tab_title (table, _("Frequencies"));

  tab_headers (table, 2, 0, 1, 0);

  /* Vertical lines inside the box */
  tab_box (table, 0, 0, -1, TAL_1,
	   1, 0, tab_nc (table) - 1, tab_nr (table) - 1 );

  /* Box around entire table */
  tab_box (table, TAL_2, TAL_2, -1, -1,
	   0, 0, tab_nc (table) - 1, tab_nr (table) - 1 );

  tab_text (table,  2, 0,  TAB_CENTER, _("N"));

  for (i = 0 ; i < t2s->n_pairs; ++i)
    {
      variable_pair *vp = &t2s->pairs[i];

      struct string pair_name;
      ds_init_cstr (&pair_name, var_to_string ((*vp)[0]));
      ds_put_cstr (&pair_name, " - ");
      ds_put_cstr (&pair_name, var_to_string ((*vp)[1]));


      tab_text (table, 0, 1 + i * 4, TAB_LEFT, ds_cstr (&pair_name));

      ds_destroy (&pair_name);

      tab_hline (table, TAL_1, 0, tab_nc (table) - 1, 1 + i * 4);

      tab_text (table,  1, 1 + i * 4,  TAB_LEFT, _("Negative Differences"));
      tab_text (table,  1, 2 + i * 4,  TAB_LEFT, _("Positive Differences"));
      tab_text (table,  1, 3 + i * 4,  TAB_LEFT, _("Ties"));
      tab_text (table,  1, 4 + i * 4,  TAB_LEFT, _("Total"));

      tab_double (table, 2, 1 + i * 4, TAB_RIGHT, param[i].neg, NULL, RC_WEIGHT);
      tab_double (table, 2, 2 + i * 4, TAB_RIGHT, param[i].pos, NULL, RC_WEIGHT);
      tab_double (table, 2, 3 + i * 4, TAB_RIGHT, param[i].ties, NULL, RC_WEIGHT);
      tab_double (table, 2, 4 + i * 4, TAB_RIGHT,
		  param[i].ties + param[i].neg + param[i].pos, NULL, RC_WEIGHT);
    }

  tab_submit (table);
}
Пример #12
0
static char *
generate_syntax (const struct comment_dialog *cd)
{
    gint i;

    GString *str;
    gchar *text;
    GtkWidget *tv = get_widget_assert (cd->xml, "comments-textview1");
    GtkWidget *check = get_widget_assert (cd->xml, "comments-checkbutton1");
    GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv));

    str = g_string_new ("\n* Data File Comments.\n\n");

    if (dict_get_documents (cd->dict->dict) != NULL)
        g_string_append (str, "DROP DOCUMENTS.\n");

    g_string_append (str, "ADD DOCUMENT\n");

    for (i = 0 ; i < gtk_text_buffer_get_line_count (buffer) ; ++i )
    {
        struct string tmp;
        GtkTextIter start;
        char *line;

        gtk_text_buffer_get_iter_at_line (buffer, &start, i);
        if (gtk_text_iter_ends_line (&start))
            line = g_strdup ("");
        else
        {
            GtkTextIter end = start;
            gtk_text_iter_forward_to_line_end (&end);
            line = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
        }

        ds_init_empty (&tmp);
        syntax_gen_string (&tmp, ss_cstr (line));
        g_free (line);

        g_string_append_printf (str, " %s\n", ds_cstr (&tmp));

        ds_destroy (&tmp);
    }
    g_string_append (str, " .\n");



    if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)))
        g_string_append (str, "DISPLAY DOCUMENTS.\n");

    text = str->str;

    g_string_free (str, FALSE);

    return text;
}
Пример #13
0
static void
output_statistics_table (const struct two_sample_test *t2s,
			 const struct sign_test_params *param)
{
  int i;
  struct tab_table *table = tab_create (1 + t2s->n_pairs, 4);

  tab_title (table, _("Test Statistics"));

  tab_headers (table, 0, 1,  0, 1);

  tab_hline (table, TAL_2, 0, tab_nc (table) - 1, 1);
  tab_vline (table, TAL_2, 1, 0, tab_nr (table) - 1);


  /* Vertical lines inside the box */
  tab_box (table, -1, -1, -1, TAL_1,
	   0, 0,
	   tab_nc (table) - 1, tab_nr (table) - 1);

  /* Box around entire table */
  tab_box (table, TAL_2, TAL_2, -1, -1,
	   0, 0, tab_nc (table) - 1,
	   tab_nr (table) - 1);

  tab_text (table,  0, 1, TAT_TITLE | TAB_LEFT,
	    _("Exact Sig. (2-tailed)"));

  tab_text (table,  0, 2, TAT_TITLE | TAB_LEFT,
	    _("Exact Sig. (1-tailed)"));

  tab_text (table,  0, 3, TAT_TITLE | TAB_LEFT,
	    _("Point Probability"));

  for (i = 0 ; i < t2s->n_pairs; ++i)
    {
      variable_pair *vp = &t2s->pairs[i];

      struct string pair_name;
      ds_init_cstr (&pair_name, var_to_string ((*vp)[0]));
      ds_put_cstr (&pair_name, " - ");
      ds_put_cstr (&pair_name, var_to_string ((*vp)[1]));

      tab_text (table,  1 + i, 0, TAB_LEFT, ds_cstr (&pair_name));
      ds_destroy (&pair_name);

      tab_double (table, 1 + i, 1, TAB_RIGHT,
		  param[i].one_tailed_sig * 2, NULL, RC_PVALUE);

      tab_double (table, 1 + i, 2, TAB_RIGHT, param[i].one_tailed_sig, NULL, RC_PVALUE);
      tab_double (table, 1 + i, 3, TAB_RIGHT, param[i].point_prob, NULL, RC_PVALUE);
    }

  tab_submit (table);
}
Пример #14
0
static void
ipf_print_reass_packet(const char *es, const void *pkt)
{
    static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(10, 10);
    if (!VLOG_DROP_WARN(&rl)) {
        struct ds ds = DS_EMPTY_INITIALIZER;
        ds_put_hex_dump(&ds, pkt, 128, 0, false);
        VLOG_WARN("%s\n%s", es, ds_cstr(&ds));
        ds_destroy(&ds);
    }
}
Пример #15
0
static void
stream_close(struct stream *s)
{
    ds_destroy(&s->log);
    if (s->fds[0] >= 0) {
        close(s->fds[0]);
    }
    if (s->fds[1] >= 0) {
        close(s->fds[1]);
    }
}
Пример #16
0
/* Parse all the labels for the VAR_CNT variables in VARS and add
   the specified labels to those variables.  */
static int
get_label (struct lexer *lexer, struct variable **vars, size_t var_cnt,
           const char *dict_encoding)
{
  /* Parse all the labels and add them to the variables. */
  do
    {
      enum { MAX_LABEL_LEN = 255 };
      int width = var_get_width (vars[0]);
      union value value;
      struct string label;
      size_t trunc_len;
      size_t i;

      /* Set value. */
      value_init (&value, width);
      if (!parse_value (lexer, &value, vars[0]))
        {
          value_destroy (&value, width);
          return 0;
        }
      lex_match (lexer, T_COMMA);

      /* Set label. */
      if (lex_token (lexer) != T_ID && !lex_force_string (lexer))
        {
          value_destroy (&value, width);
          return 0;
        }

      ds_init_substring (&label, lex_tokss (lexer));

      trunc_len = utf8_encoding_trunc_len (ds_cstr (&label), dict_encoding,
                                           MAX_LABEL_LEN);
      if (ds_length (&label) > trunc_len)
	{
	  msg (SW, _("Truncating value label to %d bytes."), MAX_LABEL_LEN);
	  ds_truncate (&label, trunc_len);
	}

      for (i = 0; i < var_cnt; i++)
        var_replace_value_label (vars[i], &value, ds_cstr (&label));

      ds_destroy (&label);
      value_destroy (&value, width);

      lex_get (lexer);
      lex_match (lexer, T_COMMA);
    }
  while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD);

  return 1;
}
Пример #17
0
/* Create a table which can be populated with the encodings for
   the covariance matrix COV */
struct tab_table *
covariance_dump_enc_header (const struct covariance *cov, int length)
{
  struct tab_table *t = tab_create (cov->dim,  length);
  int n;
  int i;

  tab_title (t, "Covariance Encoding");

  tab_box (t, 
	   TAL_2, TAL_2, 0, 0,
	   0, 0,   tab_nc (t) - 1,   tab_nr (t) - 1);

  tab_hline (t, TAL_2, 0, tab_nc (t) - 1, 1);


  for (i = 0 ; i < cov->n_vars; ++i)
    {
      tab_text (t, i, 0, TAT_TITLE, var_get_name (cov->vars[i]));
      tab_vline (t, TAL_1, i + 1, 0, tab_nr (t) - 1);
    }

  n = 0;
  while (i < cov->dim)
    {
      struct string str;
      int idx = i - cov->n_vars;
      const struct interaction *iact =
	categoricals_get_interaction_by_subscript (cov->categoricals, idx);
      int df;

      ds_init_empty (&str);
      interaction_to_string (iact, &str);

      df = categoricals_df (cov->categoricals, n);

      tab_joint_text (t,
		      i, 0,
		      i + df - 1, 0,
		      TAT_TITLE, ds_cstr (&str));

      if (i + df < tab_nr (t) - 1)
	tab_vline (t, TAL_1, i + df, 0, tab_nr (t) - 1);

      i += df;
      n++;
      ds_destroy (&str);
    }

  return t;
}
Пример #18
0
void
ofp_version_usage(void)
{
    struct ds msg = DS_EMPTY_INITIALIZER;

    ofputil_format_version_bitmap_names(&msg, OFPUTIL_DEFAULT_VERSIONS);
    printf(
        "\nOpenFlow version options:\n"
        "  -V, --version           display version information\n"
        "  -O, --protocols         set allowed OpenFlow versions\n"
        "                          (default: %s)\n",
        ds_cstr(&msg));
    ds_destroy(&msg);
}
Пример #19
0
int main()
{
	int rc = 0;

	struct tspec {
		pthread_t t;
		void *(*start) (void *);
	} thr[3] = {{0, &t1_start}, {0, &t2_start}, {0, &t3_start}};

	const size_t N_THREADS = sizeof(thr)/sizeof(thr[0]);
	size_t i = 0;
	void *ret = NULL;

	do {
		rc = ds_init();
		if (rc) break;

		rc = ds_set("MAIN_DONE", false, __func__);

		for (i = 0; i < N_THREADS; ++i) {
			(void) fprintf(stderr, "%s: starting t%ld\n", __func__, (long)i+1);
			rc = pthread_create(&thr[i].t, NULL, thr[i].start, NULL);
			if (rc) break;
		}

		const unsigned int nap = 10;
		(void) fprintf(stderr, "%s: taking a nap for %d seconds\n",
			__func__, nap);
		(void) sleep(nap);
		(void) fprintf(stderr, "%s: woke up\n", __func__);

		rc = ds_signal("MAIN_DONE", __func__);
		if (rc) break;
	} while(0);

	for(i = 0; i < N_THREADS; ++i) {
		if (thr[i].t) {
			(void) fprintf(stderr, "%s: joining t%ld .. ",
				__func__, (long)i+1);
			rc = pthread_join(thr[i].t, &ret);
			(void) fprintf(stderr, "%s\n", rc ? "FAILED" : "done");
		}
	}

	ds_destroy();

	(void) fprintf(stderr, "%s exiting [%d]\n", __func__, rc);
	return rc;
}
Пример #20
0
static bool
switch_status_remote_packet_cb(struct relay *r, void *ss_)
{
    struct switch_status *ss = ss_;
    struct rconn *rc = r->halves[HALF_REMOTE].rconn;
    struct ofpbuf *msg = r->halves[HALF_REMOTE].rxbuf;
    struct switch_status_category *c;
    struct nicira_header *request;
    struct nicira_header *reply;
    struct status_reply sr;
    struct ofpbuf *b;
    int retval;

    if (msg->size < sizeof(struct nicira_header)) {
        return false;
    }
    request = msg->data;
    if (request->header.type != OFPT_EXPERIMENTER
        || request->vendor != htonl(NX_VENDOR_ID)
        || request->subtype != htonl(NXT_STATUS_REQUEST)) {
        return false;
    }

    sr.request.string = (void *) (request + 1);
    sr.request.length = msg->size - sizeof *request;
    ds_init(&sr.output);
    for (c = ss->categories; c < &ss->categories[ss->n_categories]; c++) {
        if (!memcmp(c->name, sr.request.string,
                    MIN(strlen(c->name), sr.request.length))) {
            sr.category = c;
            c->cb(&sr, c->aux);
        }
    }
    reply = make_openflow_xid(sizeof *reply + sr.output.length,
                              OFPT_EXPERIMENTER, request->header.xid, &b);
    reply->vendor = htonl(NX_VENDOR_ID);
    reply->subtype = htonl(NXT_STATUS_REPLY);
    memcpy(reply + 1, sr.output.string, sr.output.length);
    retval = rconn_send(rc, b, NULL);
    if (retval && retval != EAGAIN) {
        VLOG_WARN(LOG_MODULE, "send failed (%s)", strerror(retval));
    }
    ds_destroy(&sr.output);
    return true;
}
Пример #21
0
/* Similar to parse_ofp_flow_mod_str(), except that the string is read from
 * 'stream' and the command is always OFPFC_ADD.  Returns false if end-of-file
 * is reached before reading a flow, otherwise true. */
bool
parse_ofp_flow_mod_file(struct list *packets,
                        enum nx_flow_format *cur, bool *flow_mod_table_id,
                        FILE *stream, uint16_t command)
{
    struct ds s;
    bool ok;

    ds_init(&s);
    ok = ds_get_preprocessed_line(&s, stream) == 0;
    if (ok) {
        parse_ofp_flow_mod_str(packets, cur, flow_mod_table_id,
                               ds_cstr(&s), command, true);
    }
    ds_destroy(&s);

    return ok;
}
Пример #22
0
/* Breaks 'words' into words at white space, respecting shell-like quoting
 * conventions, and appends the words to 'svec'. */
void
svec_parse_words(struct svec *svec, const char *words)
{
    struct ds word = DS_EMPTY_INITIALIZER;
    const char *p, *q;

    for (p = words; *p != '\0'; p = q) {
        int quote = 0;

        while (isspace((unsigned char) *p)) {
            p++;
        }
        if (*p == '\0') {
            break;
        }

        ds_clear(&word);
        for (q = p; *q != '\0'; q++) {
            if (*q == quote) {
                quote = 0;
            } else if (*q == '\'' || *q == '"') {
                quote = *q;
            } else if (*q == '\\' && (!quote || quote == '"')) {
                q++;
                if (*q == '\0') {
                    VLOG_WARN(LOG_MODULE, "%s: ends in trailing backslash", words);
                    break;
                }
                ds_put_char(&word, *q);
            } else if (isspace((unsigned char) *q) && !quote) {
                q++;
                break;
            } else {
                ds_put_char(&word, *q);
            }
        }
        svec_add(svec, ds_cstr(&word));
        if (quote) {
            VLOG_WARN(LOG_MODULE, "%s: word ends inside quoted string", words);
        }
    }
    ds_destroy(&word);
}
Пример #23
0
static void
destroy (struct statistic *s)
{
  struct box_whisker *bw = UP_CAST (s, struct box_whisker, parent.parent);
  struct order_stats *os = &bw->parent;
  struct ll *ll;

  for (ll = ll_head (&bw->outliers); ll != ll_null (&bw->outliers); )
    {
      struct outlier *e = ll_data (ll, struct outlier, ll);

      ll = ll_next (ll);

      ds_destroy (&e->label);
      free (e);
    }

  free (os->k);
  free (s);
};
Пример #24
0
log_wakeup(const struct backtrace *backtrace, const char *format, ...)
{
    struct ds ds;
    va_list args;

    ds_init(&ds);
    va_start(args, format);
    ds_put_format_valist(&ds, format, args);
    va_end(args);

    if (backtrace) {
        int i;

        ds_put_char(&ds, ':');
        for (i = 0; i < backtrace->n_frames; i++) {
            ds_put_format(&ds, " 0x%x", backtrace->frames[i]);
        }
    }
    VLOG_DBG("%s", ds_cstr(&ds));
    ds_destroy(&ds);
}
Пример #25
0
Файл: dpdk.c Проект: shettyg/ovs
static void
dpdk_init__(const struct smap *ovs_other_config)
{
    char **argv = NULL, **argv_to_release = NULL;
    int result;
    int argc, argc_tmp;
    bool auto_determine = true;
    int err = 0;
    cpu_set_t cpuset;
    char *sock_dir_subcomponent;

    if (process_vhost_flags("vhost-sock-dir", xstrdup(ovs_rundir()),
                            NAME_MAX, ovs_other_config,
                            &sock_dir_subcomponent)) {
        struct stat s;
        if (!strstr(sock_dir_subcomponent, "..")) {
            vhost_sock_dir = xasprintf("%s/%s", ovs_rundir(),
                                       sock_dir_subcomponent);

            err = stat(vhost_sock_dir, &s);
            if (err) {
                VLOG_ERR("vhost-user sock directory '%s' does not exist.",
                         vhost_sock_dir);
            }
        } else {
            vhost_sock_dir = xstrdup(ovs_rundir());
            VLOG_ERR("vhost-user sock directory request '%s/%s' has invalid"
                     "characters '..' - using %s instead.",
                     ovs_rundir(), sock_dir_subcomponent, ovs_rundir());
        }
        free(sock_dir_subcomponent);
    } else {
        vhost_sock_dir = sock_dir_subcomponent;
    }

    argv = grow_argv(&argv, 0, 1);
    argc = 1;
    argv[0] = xstrdup(ovs_get_program_name());
    argc_tmp = get_dpdk_args(ovs_other_config, &argv, argc);

    while (argc_tmp != argc) {
        if (!strcmp("-c", argv[argc]) || !strcmp("-l", argv[argc])) {
            auto_determine = false;
            break;
        }
        argc++;
    }
    argc = argc_tmp;

    /**
     * NOTE: This is an unsophisticated mechanism for determining the DPDK
     * lcore for the DPDK Master.
     */
    if (auto_determine) {
        int i;
        /* Get the main thread affinity */
        CPU_ZERO(&cpuset);
        err = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t),
                                     &cpuset);
        if (!err) {
            for (i = 0; i < CPU_SETSIZE; i++) {
                if (CPU_ISSET(i, &cpuset)) {
                    argv = grow_argv(&argv, argc, 2);
                    argv[argc++] = xstrdup("-c");
                    argv[argc++] = xasprintf("0x%08llX", (1ULL<<i));
                    i = CPU_SETSIZE;
                }
            }
        } else {
            VLOG_ERR("Thread getaffinity error %d. Using core 0x1", err);
            /* User did not set dpdk-lcore-mask and unable to get current
             * thread affintity - default to core 0x1 */
            argv = grow_argv(&argv, argc, 2);
            argv[argc++] = xstrdup("-c");
            argv[argc++] = xasprintf("0x%X", 1);
        }
    }

    argv = grow_argv(&argv, argc, 1);
    argv[argc] = NULL;

    optind = 1;

    if (VLOG_IS_INFO_ENABLED()) {
        struct ds eal_args;
        int opt;
        ds_init(&eal_args);
        ds_put_cstr(&eal_args, "EAL ARGS:");
        for (opt = 0; opt < argc; ++opt) {
            ds_put_cstr(&eal_args, " ");
            ds_put_cstr(&eal_args, argv[opt]);
        }
        VLOG_INFO("%s", ds_cstr_ro(&eal_args));
        ds_destroy(&eal_args);
    }

    argv_to_release = grow_argv(&argv_to_release, 0, argc);
    for (argc_tmp = 0; argc_tmp < argc; ++argc_tmp) {
        argv_to_release[argc_tmp] = argv[argc_tmp];
    }

    /* Make sure things are initialized ... */
    result = rte_eal_init(argc, argv);
    if (result < 0) {
        ovs_abort(result, "Cannot init EAL");
    }
    argv_release(argv, argv_to_release, argc);

    /* Set the main thread affinity back to pre rte_eal_init() value */
    if (auto_determine && !err) {
        err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t),
                                     &cpuset);
        if (err) {
            VLOG_ERR("Thread setaffinity error %d", err);
        }
    }

    rte_memzone_dump(stdout);

    /* We are called from the main thread here */
    RTE_PER_LCORE(_lcore_id) = NON_PMD_CORE_ID;

#ifdef DPDK_PDUMP
    VLOG_INFO("DPDK pdump packet capture enabled");
    err = rte_pdump_init(ovs_rundir());
    if (err) {
        VLOG_INFO("Error initialising DPDK pdump");
        rte_pdump_uninit();
    } else {
        char *server_socket_path;

        server_socket_path = xasprintf("%s/%s", ovs_rundir(),
                                       "pdump_server_socket");
        fatal_signal_add_file_to_unlink(server_socket_path);
        free(server_socket_path);
    }
#endif

    /* Finally, register the dpdk classes */
    netdev_dpdk_register();
}
Пример #26
0
static int
parse_keys(bool wc_keys)
{
    int exit_code = 0;
    struct ds in;

    ds_init(&in);
    vlog_set_levels_from_string_assert("odp_util:console:dbg");
    while (!ds_get_test_line(&in, stdin)) {
        enum odp_key_fitness fitness;
        struct ofpbuf odp_key;
        struct ofpbuf odp_mask;
        struct flow flow;
        struct ds out;
        int error;

        /* Convert string to OVS DP key. */
        ofpbuf_init(&odp_key, 0);
        ofpbuf_init(&odp_mask, 0);
        error = odp_flow_from_string(ds_cstr(&in), NULL,
                                     &odp_key, &odp_mask);
        if (error) {
            printf("odp_flow_from_string: error\n");
            goto next;
        }

        if (!wc_keys) {
            /* Convert odp_key to flow. */
            fitness = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow);
            switch (fitness) {
                case ODP_FIT_PERFECT:
                    break;

                case ODP_FIT_TOO_LITTLE:
                    printf("ODP_FIT_TOO_LITTLE: ");
                    break;

                case ODP_FIT_TOO_MUCH:
                    printf("ODP_FIT_TOO_MUCH: ");
                    break;

                case ODP_FIT_ERROR:
                    printf("odp_flow_key_to_flow: error\n");
                    goto next;
            }
            /* Convert cls_rule back to odp_key. */
            ofpbuf_uninit(&odp_key);
            ofpbuf_init(&odp_key, 0);
            odp_flow_key_from_flow(&odp_key, &flow, flow.in_port.odp_port);

            if (odp_key.size > ODPUTIL_FLOW_KEY_BYTES) {
                printf ("too long: %zu > %d\n",
                        odp_key.size, ODPUTIL_FLOW_KEY_BYTES);
                exit_code = 1;
            }
        }

        /* Convert odp_key to string. */
        ds_init(&out);
        if (wc_keys) {
            odp_flow_format(odp_key.data, odp_key.size,
                            odp_mask.data, odp_mask.size, &out);
        } else {
            odp_flow_key_format(odp_key.data, odp_key.size, &out);
        }
        puts(ds_cstr(&out));
        ds_destroy(&out);

    next:
        ofpbuf_uninit(&odp_key);
    }
    ds_destroy(&in);

    return exit_code;
}
Пример #27
0
static int
parse_filter(char *filter_parse)
{
    struct ds in;
    struct flow flow_filter;
    struct flow_wildcards wc_filter;
    char *error, *filter = NULL;

    vlog_set_levels_from_string_assert("odp_util:console:dbg");
    if (filter_parse && !strncmp(filter_parse, "filter=", 7)) {
        filter = xstrdup(filter_parse + 7);
        memset(&flow_filter, 0, sizeof(flow_filter));
        memset(&wc_filter, 0, sizeof(wc_filter));

        error = parse_ofp_exact_flow(&flow_filter, &wc_filter, NULL, filter,
                                     NULL);
        if (error) {
            ovs_fatal(0, "Failed to parse filter (%s)", error);
        }
    } else {
        ovs_fatal(0, "No filter to parse.");
    }

    ds_init(&in);
    while (!ds_get_test_line(&in, stdin)) {
        struct ofpbuf odp_key;
        struct ofpbuf odp_mask;
        struct ds out;

        /* Convert string to OVS DP key. */
        ofpbuf_init(&odp_key, 0);
        ofpbuf_init(&odp_mask, 0);
        if (odp_flow_from_string(ds_cstr(&in), NULL, &odp_key, &odp_mask)) {
            printf("odp_flow_from_string: error\n");
            goto next;
        }

        if (filter) {
            struct flow flow;
            struct flow_wildcards wc;
            struct match match, match_filter;
            struct minimatch minimatch;

            odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow);
            odp_flow_key_to_mask(odp_mask.data, odp_mask.size, &wc, &flow);
            match_init(&match, &flow, &wc);

            match_init(&match_filter, &flow_filter, &wc);
            match_init(&match_filter, &match_filter.flow, &wc_filter);
            minimatch_init(&minimatch, &match_filter);

            if (!minimatch_matches_flow(&minimatch, &match.flow)) {
                minimatch_destroy(&minimatch);
                goto next;
            }
            minimatch_destroy(&minimatch);
        }
        /* Convert odp_key to string. */
        ds_init(&out);
        odp_flow_format(odp_key.data, odp_key.size,
                        odp_mask.data, odp_mask.size, NULL, &out, false);
        puts(ds_cstr(&out));
        ds_destroy(&out);

    next:
        ofpbuf_uninit(&odp_key);
        ofpbuf_uninit(&odp_mask);
    }
    ds_destroy(&in);

    free(filter);
    return 0;
}
Пример #28
0
int
main(void)
{
    int exit_code = 0;
    struct ds in;

    ds_init(&in);
    vlog_set_levels_from_string("odp_util:console:dbg");
    while (!ds_get_line(&in, stdin)) {
        enum odp_key_fitness fitness;
        struct ofpbuf odp_key;
        struct flow flow;
        struct ds out;
        int error;
        char *s;

        /* Delete comments, skip blank lines. */
        s = ds_cstr(&in);
        if (*s == '#') {
            puts(s);
            continue;
        }
        if (strchr(s, '#')) {
            *strchr(s, '#') = '\0';
        }
        if (s[strspn(s, " ")] == '\0') {
            putchar('\n');
            continue;
        }

        /* Convert string to OVS DP key. */
        ofpbuf_init(&odp_key, 0);
        error = odp_flow_key_from_string(ds_cstr(&in), NULL, &odp_key);
        if (error) {
            printf("odp_flow_key_from_string: error\n");
            goto next;
        }

        /* Convert odp_key to flow. */
        fitness = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow);
        switch (fitness) {
        case ODP_FIT_PERFECT:
            break;

        case ODP_FIT_TOO_LITTLE:
            printf("ODP_FIT_TOO_LITTLE: ");
            break;

        case ODP_FIT_TOO_MUCH:
            printf("ODP_FIT_TOO_MUCH: ");
            break;

        case ODP_FIT_ERROR:
            printf("odp_flow_key_to_flow: error\n");
            goto next;
        }

        /* Convert cls_rule back to odp_key. */
        ofpbuf_uninit(&odp_key);
        ofpbuf_init(&odp_key, 0);
        odp_flow_key_from_flow(&odp_key, &flow);

        if (odp_key.size > ODPUTIL_FLOW_KEY_BYTES) {
            printf ("too long: %zu > %d\n",
                    odp_key.size, ODPUTIL_FLOW_KEY_BYTES);
            exit_code = 1;
        }

        /* Convert odp_key to string. */
        ds_init(&out);
        odp_flow_key_format(odp_key.data, odp_key.size, &out);
        puts(ds_cstr(&out));
        ds_destroy(&out);

    next:
        ofpbuf_uninit(&odp_key);
    }
    ds_destroy(&in);

    return exit_code;
}
static char *
generate_syntax (PsppireDialogAction *a)
{
  PsppireDialogActionIndepSamps *act = PSPPIRE_DIALOG_ACTION_INDEP_SAMPS (a);
  gchar *text;

  GString *str = g_string_new ("T-TEST /VARIABLES=");

  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (act->test_vars_tv), 0, str);

  g_string_append (str, "\n\t/GROUPS=");

  g_string_append (str, var_get_name (act->grp_var));

  if (act->group_defn != GROUPS_UNDEF)
    {
      g_string_append (str, "(");

      {
        const union value *val = 
          (act->group_defn == GROUPS_VALUES) ?
          &act->grp_val[0] :
          &act->cut_point;

        struct string strx;        
        ds_init_empty (&strx);
        syntax_gen_value (&strx, val, var_get_width (act->grp_var),
                          var_get_print_format (act->grp_var));
      
        g_string_append (str, ds_cstr (&strx));
        ds_destroy (&strx);
      }

      if (act->group_defn == GROUPS_VALUES)
	{
	  g_string_append (str, ",");

          {
            struct string strx;
            ds_init_empty (&strx);
            
            syntax_gen_value (&strx, &act->grp_val[1], var_get_width (act->grp_var),
                              var_get_print_format (act->grp_var));
            
            g_string_append (str, ds_cstr (&strx));
            ds_destroy (&strx);
          }
	}

      g_string_append (str, ")");
    }

  tt_options_dialog_append_syntax (act->opts, str);

  g_string_append (str, ".\n");

  text = str->str;

  g_string_free (str, FALSE);

  return text;
}
Пример #30
0
static void
print_netflow(struct ofpbuf *buf)
{
    const struct netflow_v5_header *hdr;
    int i;

    hdr = ofpbuf_try_pull(buf, sizeof *hdr);
    if (!hdr) {
        printf("truncated NetFlow packet header\n");
        return;
    }
    printf("header: v%"PRIu16", "
           "uptime %"PRIu32", "
           "now %"PRIu32".%09"PRIu32", "
           "seq %"PRIu32", "
           "engine %"PRIu8",%"PRIu8,
           ntohs(hdr->version),
           ntohl(hdr->sysuptime),
           ntohl(hdr->unix_secs), ntohl(hdr->unix_nsecs),
           ntohl(hdr->flow_seq),
           hdr->engine_type, hdr->engine_id);
    if (hdr->sampling_interval != htons(0)) {
        printf(", interval %"PRIu16, ntohs(hdr->sampling_interval));
    }
    putchar('\n');

    for (i = 0; i < ntohs(hdr->count); i++) {
        struct netflow_v5_record *rec;

        rec = ofpbuf_try_pull(buf, sizeof *rec);
        if (!rec) {
            printf("truncated NetFlow records\n");
            return;
        }

        printf("seq %"PRIu32": "IP_FMT" > "IP_FMT, ntohl(hdr->flow_seq),
               IP_ARGS(rec->src_addr), IP_ARGS(rec->dst_addr));

        printf(", if %"PRIu16" > %"PRIu16,
               ntohs(rec->input), ntohs(rec->output));

        printf(", %"PRIu32" pkts, %"PRIu32" bytes",
               ntohl(rec->packet_count), ntohl(rec->byte_count));

        switch (rec->ip_proto) {
        case IPPROTO_TCP:
            printf(", TCP %"PRIu16" > %"PRIu16,
                   ntohs(rec->src_port), ntohs(rec->dst_port));
            if (rec->tcp_flags) {
                struct ds s = DS_EMPTY_INITIALIZER;
                packet_format_tcp_flags(&s, rec->tcp_flags);
                printf(" %s", ds_cstr(&s));
                ds_destroy(&s);
            }
            break;

        case IPPROTO_UDP:
            printf(", UDP %"PRIu16" > %"PRIu16,
                   ntohs(rec->src_port), ntohs(rec->dst_port));
            break;

        case IPPROTO_ICMP:
            printf(", ICMP %"PRIu16":%"PRIu16,
                   ntohs(rec->dst_port) >> 8,
                   ntohs(rec->dst_port) & 0xff);
            if (rec->src_port != htons(0)) {
                printf(", src_port=%"PRIu16, ntohs(rec->src_port));
            }
            break;

        default:
            printf(", proto %"PRIu8, rec->ip_proto);
            break;
        }

        if (rec->ip_proto != IPPROTO_TCP && rec->tcp_flags != 0) {
            printf(", flags %"PRIx8, rec->tcp_flags);
        }

        if (rec->ip_proto != IPPROTO_TCP &&
            rec->ip_proto != IPPROTO_UDP &&
            rec->ip_proto != IPPROTO_ICMP) {
            if (rec->src_port != htons(0)) {
                printf(", src_port %"PRIu16, ntohs(rec->src_port));
            }
            if (rec->dst_port != htons(0)) {
                printf(", dst_port %"PRIu16, ntohs(rec->dst_port));
            }
        }

        if (rec->ip_tos) {
            printf(", TOS %"PRIx8, rec->ip_tos);
        }

        printf(", time %"PRIu32"...%"PRIu32,
               ntohl(rec->init_time), ntohl(rec->used_time));

        if (rec->nexthop != htonl(0)) {
            printf(", nexthop "IP_FMT, IP_ARGS(rec->nexthop));
        }
        if (rec->src_as != htons(0) || rec->dst_as != htons(0)) {
            printf(", AS %"PRIu16" > %"PRIu16,
                   ntohs(rec->src_as), ntohs(rec->dst_as));
        }
        if (rec->src_mask != 0 || rec->dst_mask != 0) {
            printf(", mask %"PRIu8" > %"PRIu8, rec->src_mask, rec->dst_mask);
        }
        if (rec->pad1) {
            printf(", pad1 %"PRIu8, rec->pad1);
        }
        if (rec->pad[0] || rec->pad[1]) {
            printf(", pad %"PRIu8", %"PRIu8, rec->pad[0], rec->pad[1]);
        }
        putchar('\n');
    }

    if (buf->size) {
        printf("%zu extra bytes after last record\n", buf->size);
    }
}