Commit efefbcae authored by Ben Pfaff's avatar Ben Pfaff

ofp-actions: Make formatting and parsing functions take a struct argument.

An upcoming commit will add another parameter for parsing and formatting
actions.  It is much easier to add these parameters if they are
encapsulated in a struct, so this commit first makes that change.
Signed-off-by: default avatarBen Pfaff <blp@ovn.org>
Reviewed-by: default avatarYifeng Sun <pkusunyifeng@gmail.com>
Acked-by: default avatarMark Michelson <mmichels@redhat.com>
parent 46ab60bf
......@@ -1064,18 +1064,32 @@ bool ofpacts_equal_stringwise(const struct ofpact a[], size_t a_len,
const struct mf_field *ofpact_get_mf_dst(const struct ofpact *ofpact);
uint32_t ofpacts_get_meter(const struct ofpact[], size_t ofpacts_len);
/* Formatting and parsing ofpacts. */
/* Formatting ofpacts. */
struct ofpact_format_params {
/* Input. */
const struct ofputil_port_map *port_map;
/* Output. */
struct ds *s;
};
void ofpacts_format(const struct ofpact[], size_t ofpacts_len,
const struct ofputil_port_map *, struct ds *);
char *ofpacts_parse_actions(const char *, const struct ofputil_port_map *,
struct ofpbuf *ofpacts,
enum ofputil_protocol *usable_protocols)
const struct ofpact_format_params *);
const char *ofpact_name(enum ofpact_type);
/* Parsing ofpacts. */
struct ofpact_parse_params {
/* Input. */
const struct ofputil_port_map *port_map;
/* Output. */
struct ofpbuf *ofpacts;
enum ofputil_protocol *usable_protocols;
};
char *ofpacts_parse_actions(const char *, const struct ofpact_parse_params *)
OVS_WARN_UNUSED_RESULT;
char *ofpacts_parse_instructions(const char *, const struct ofputil_port_map *,
struct ofpbuf *ofpacts,
enum ofputil_protocol *usable_protocols)
char *ofpacts_parse_instructions(const char *,
const struct ofpact_parse_params *)
OVS_WARN_UNUSED_RESULT;
const char *ofpact_name(enum ofpact_type);
/* Internal use by the helpers below. */
void ofpact_init(struct ofpact *, enum ofpact_type, size_t len);
......
This diff is collapsed.
......@@ -557,8 +557,12 @@ parse_ofp_str__(struct ofputil_flow_mod *fm, int command, char *string,
char *error;
ofpbuf_init(&ofpacts, 32);
error = ofpacts_parse_instructions(act_str, port_map, &ofpacts,
&action_usable_protocols);
struct ofpact_parse_params pp = {
.port_map = port_map,
.ofpacts = &ofpacts,
.usable_protocols = &action_usable_protocols
};
error = ofpacts_parse_instructions(act_str, &pp);
*usable_protocols &= action_usable_protocols;
if (!error) {
enum ofperr err;
......@@ -713,8 +717,12 @@ parse_ofp_packet_out_str__(struct ofputil_packet_out *po, char *string,
}
if (act_str) {
error = ofpacts_parse_actions(act_str, port_map, &ofpacts,
&action_usable_protocols);
struct ofpact_parse_params pp = {
.port_map = port_map,
.ofpacts = &ofpacts,
.usable_protocols = &action_usable_protocols,
};
error = ofpacts_parse_actions(act_str, &pp);
*usable_protocols &= action_usable_protocols;
if (error) {
goto out;
......@@ -1487,8 +1495,12 @@ parse_bucket_str(struct ofputil_bucket *bucket, char *str_,
ds_chomp(&actions, ',');
ofpbuf_init(&ofpacts, 0);
error = ofpacts_parse_actions(ds_cstr(&actions), port_map, &ofpacts,
usable_protocols);
struct ofpact_parse_params pp = {
.port_map = port_map,
.ofpacts = &ofpacts,
.usable_protocols = usable_protocols,
};
error = ofpacts_parse_actions(ds_cstr(&actions), &pp);
ds_destroy(&actions);
if (error) {
ofpbuf_uninit(&ofpacts);
......
......@@ -205,15 +205,20 @@ ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
ds_put_cstr(string, " continuation.conntracked=true\n");
}
struct ofpact_format_params fp = {
.port_map = port_map,
.s = string,
};
if (pin.actions_len) {
ds_put_cstr(string, " continuation.actions=");
ofpacts_format(pin.actions, pin.actions_len, port_map, string);
ofpacts_format(pin.actions, pin.actions_len, &fp);
ds_put_char(string, '\n');
}
if (pin.action_set_len) {
ds_put_cstr(string, " continuation.action_set=");
ofpacts_format(pin.action_set, pin.action_set_len, port_map, string);
ofpacts_format(pin.action_set, pin.action_set_len, &fp);
ds_put_char(string, '\n');
}
......@@ -252,7 +257,11 @@ ofp_print_packet_out(struct ds *string, const struct ofp_header *oh,
match_format(&po.flow_metadata, port_map, string, OFP_DEFAULT_PRIORITY);
ds_put_cstr(string, " actions=");
ofpacts_format(po.ofpacts, po.ofpacts_len, port_map, string);
struct ofpact_format_params fp = {
.port_map = port_map,
.s = string,
};
ofpacts_format(po.ofpacts, po.ofpacts_len, &fp);
if (po.buffer_id == UINT32_MAX) {
ds_put_format(string, " data_len=%"PRIuSIZE, po.packet_len);
......@@ -916,7 +925,11 @@ ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh,
ofp_print_flow_flags(s, fm.flags);
ds_put_cstr(s, "actions=");
ofpacts_format(fm.ofpacts, fm.ofpacts_len, port_map, s);
struct ofpact_format_params fp = {
.port_map = port_map,
.s = s,
};
ofpacts_format(fm.ofpacts, fm.ofpacts_len, &fp);
ofpbuf_uninit(&ofpacts);
return 0;
......@@ -1749,7 +1762,11 @@ ofp_print_flow_stats(struct ds *string, const struct ofputil_flow_stats *fs,
}
ds_put_format(string, "%sactions=%s", colors.actions, colors.end);
ofpacts_format(fs->ofpacts, fs->ofpacts_len, port_map, string);
struct ofpact_format_params fp = {
.port_map = port_map,
.s = string,
};
ofpacts_format(fs->ofpacts, fs->ofpacts_len, &fp);
}
static enum ofperr
......@@ -2544,8 +2561,11 @@ ofp_print_nxst_flow_monitor_reply(struct ds *string,
ds_put_char(string, ' ');
}
ds_put_cstr(string, "actions=");
ofpacts_format(update.ofpacts, update.ofpacts_len, port_map,
string);
struct ofpact_format_params fp = {
.port_map = port_map,
.s = string,
};
ofpacts_format(update.ofpacts, update.ofpacts_len, &fp);
}
}
}
......@@ -2676,7 +2696,11 @@ ofp_print_group(struct ds *s, uint32_t group_id, uint8_t type,
}
ds_put_cstr(s, "actions=");
ofpacts_format(bucket->ofpacts, bucket->ofpacts_len, port_map, s);
struct ofpact_format_params fp = {
.port_map = port_map,
.s = s,
};
ofpacts_format(bucket->ofpacts, bucket->ofpacts_len, &fp);
ds_put_char(s, ',');
}
......
......@@ -506,8 +506,12 @@ ofproto_unixctl_trace_actions(struct unixctl_conn *conn, int argc,
ofpbuf_init(&ofpacts, 0);
/* Parse actions. */
error = ofpacts_parse_actions(argv[--argc], NULL,
&ofpacts, &usable_protocols);
struct ofpact_parse_params pp = {
.port_map = NULL,
.ofpacts = &ofpacts,
.usable_protocols = &usable_protocols,
};
error = ofpacts_parse_actions(argv[--argc], &pp);
if (error) {
unixctl_command_reply_error(conn, error);
free(error);
......
......@@ -700,7 +700,8 @@ xlate_report_actions(const struct xlate_ctx *ctx, enum oftrace_node_type type,
if (OVS_UNLIKELY(ctx->xin->trace)) {
struct ds s = DS_EMPTY_INITIALIZER;
ds_put_format(&s, "%s: ", title);
ofpacts_format(ofpacts, ofpacts_len, NULL, &s);
struct ofpact_format_params fp = { .s = &s };
ofpacts_format(ofpacts, ofpacts_len, &fp);
oftrace_report(ctx->xin->trace, type, ds_cstr(&s));
ds_destroy(&s);
}
......@@ -721,7 +722,8 @@ xlate_report_action_set(const struct xlate_ctx *ctx, const char *verb)
ofpacts_execute_action_set(&action_list, &ctx->action_set);
if (action_list.size) {
struct ds s = DS_EMPTY_INITIALIZER;
ofpacts_format(action_list.data, action_list.size, NULL, &s);
struct ofpact_format_params fp = { .s = &s };
ofpacts_format(action_list.data, action_list.size, &fp);
xlate_report(ctx, OFT_DETAIL, "action set %s: %s",
verb, ds_cstr(&s));
ds_destroy(&s);
......@@ -5050,7 +5052,8 @@ xlate_learn_action(struct xlate_ctx *ctx, const struct ofpact_learn *learn)
ds_put_cstr(&s, " send_flow_rem");
}
ds_put_cstr(&s, " actions=");
ofpacts_format(fm.ofpacts, fm.ofpacts_len, NULL, &s);
struct ofpact_format_params fp = { .s = &s };
ofpacts_format(fm.ofpacts, fm.ofpacts_len, &fp);
xlate_report(ctx, OFT_DETAIL, "%s", ds_cstr(&s));
ds_destroy(&s);
}
......@@ -6170,7 +6173,8 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
if (OVS_UNLIKELY(ctx->xin->trace)) {
struct ds s = DS_EMPTY_INITIALIZER;
ofpacts_format(a, OFPACT_ALIGN(a->len), NULL, &s);
struct ofpact_format_params fp = { .s = &s };
ofpacts_format(a, OFPACT_ALIGN(a->len), &fp);
xlate_report(ctx, OFT_ACTION, "%s", ds_cstr(&s));
ds_destroy(&s);
}
......
......@@ -4395,7 +4395,8 @@ flow_stats_ds(struct ofproto *ofproto, struct rule *rule, struct ds *results)
ds_put_char(results, ',');
ds_put_cstr(results, "actions=");
ofpacts_format(actions->ofpacts, actions->ofpacts_len, NULL, results);
struct ofpact_format_params fp = { .s = results };
ofpacts_format(actions->ofpacts, actions->ofpacts_len, &fp);
ds_put_cstr(results, "\n");
}
......
......@@ -705,7 +705,8 @@ ovn_flow_to_string(const struct ovn_flow *f)
ds_put_format(&s, "priority=%"PRIu16", ", f->priority);
match_format(&f->match, NULL, &s, OFP_DEFAULT_PRIORITY);
ds_put_cstr(&s, ", actions=");
ofpacts_format(f->ofpacts, f->ofpacts_len, NULL, &s);
struct ofpact_format_params fp = { .s = &s };
ofpacts_format(f->ofpacts, f->ofpacts_len, &fp);
return ds_steal_cstr(&s);
}
......
......@@ -806,7 +806,8 @@ sbctl_dump_openflow(struct vconn *vconn, const struct uuid *uuid, bool stats)
}
ds_put_format(&s, "%sactions=%s", colors.actions, colors.end);
ofpacts_format(fs->ofpacts, fs->ofpacts_len, NULL, &s);
struct ofpact_format_params fp = { .s = &s };
ofpacts_format(fs->ofpacts, fs->ofpacts_len, &fp);
}
printf(" %s\n", ds_cstr(&s));
}
......
......@@ -1266,7 +1266,8 @@ test_parse_actions(struct ovs_cmdl_context *ctx OVS_UNUSED)
ofpbuf_init(&ofpacts, 0);
ovnacts_encode(ovnacts.data, ovnacts.size, &ep, &ofpacts);
struct ds ofpacts_s = DS_EMPTY_INITIALIZER;
ofpacts_format(ofpacts.data, ofpacts.size, NULL, &ofpacts_s);
struct ofpact_format_params fp = { .s = &ofpacts_s };
ofpacts_format(ofpacts.data, ofpacts.size, &fp);
printf(" encodes as %s\n", ds_cstr(&ofpacts_s));
ds_destroy(&ofpacts_s);
ofpbuf_uninit(&ofpacts);
......
......@@ -2198,9 +2198,12 @@ ofctl_packet_out(struct ovs_cmdl_context *ctx)
int i;
ofpbuf_init(&ofpacts, 64);
error = ofpacts_parse_actions(ctx->argv[3],
ports_to_accept(ctx->argv[1]), &ofpacts,
&usable_protocols);
struct ofpact_parse_params pp = {
.port_map = ports_to_accept(ctx->argv[1]),
.ofpacts = &ofpacts,
.usable_protocols = &usable_protocols
};
error = ofpacts_parse_actions(ctx->argv[3], &pp);
if (error) {
ovs_fatal(0, "%s", error);
}
......@@ -3185,8 +3188,11 @@ fte_version_format(const struct fte_state *fte_state, const struct fte *fte,
}
ds_put_cstr(s, " actions=");
ofpacts_format(version->ofpacts, version->ofpacts_len,
fte_state->port_map, s);
struct ofpact_format_params fp = {
.port_map = fte_state->port_map,
.s = s,
};
ofpacts_format(version->ofpacts, version->ofpacts_len, &fp);
ds_put_char(s, '\n');
}
......@@ -4042,7 +4048,8 @@ ofctl_parse_actions__(const char *version_s, bool instructions)
/* Print cls_rule. */
ds_init(&s);
ds_put_cstr(&s, "actions=");
ofpacts_format(ofpacts.data, ofpacts.size, NULL, &s);
struct ofpact_format_params fp = { .s = &s };
ofpacts_format(ofpacts.data, ofpacts.size, &fp);
puts(ds_cstr(&s));
ds_destroy(&s);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment