[ovs-dev] [PATCH 1/2] ovs-ofctl: Print the offending flow on error when parsing from a file.
Andrew Evans
aevans at nicira.com
Thu Jun 16 01:55:38 UTC 2011
When an error is encountered while parsing flows from a file, ovs-ofctl doesn't
print the flow it can't parse, so it's not always obvious which flow is causing
the error. Print the flow before the error message to make it clear.
---
lib/ofp-parse.c | 32 ++++++++++++++++++++++++++------
lib/ofp-parse.h | 5 +++--
utilities/ovs-ofctl.c | 6 +++---
3 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c
index a4679a3..e378af5 100644
--- a/lib/ofp-parse.c
+++ b/lib/ofp-parse.c
@@ -778,11 +778,13 @@ parse_reg_value(struct cls_rule *rule, int reg_idx, const char *value)
}
/* Convert 'string' (as described in the Flow Syntax section of the ovs-ofctl
- * man page) into 'pf'. If 'actions' is specified, an action must be in
+ * man page) into 'fm'. If 'actions' is specified, an action must be in
* 'string' and may be expanded or reallocated. */
void
-parse_ofp_str(struct flow_mod *fm, struct ofpbuf *actions, char *string)
+parse_ofp_str(struct flow_mod *fm, struct ofpbuf *actions, const char *str_,
+ bool verbose)
{
+ char *string = xstrdup(str_);
char *save_ptr = NULL;
char *name;
@@ -798,12 +800,18 @@ parse_ofp_str(struct flow_mod *fm, struct ofpbuf *actions, char *string)
if (actions) {
char *act_str = strstr(string, "action");
if (!act_str) {
+ if (verbose) {
+ fprintf(stderr, "%s:\n", str_);
+ }
ovs_fatal(0, "must specify an action");
}
*act_str = '\0';
act_str = strchr(act_str + 1, '=');
if (!act_str) {
+ if (verbose) {
+ fprintf(stderr, "%s:\n", str_);
+ }
ovs_fatal(0, "must specify an action");
}
@@ -831,6 +839,9 @@ parse_ofp_str(struct flow_mod *fm, struct ofpbuf *actions, char *string)
value = strtok_r(NULL, ", \t\r\n", &save_ptr);
if (!value) {
+ if (verbose) {
+ fprintf(stderr, "%s:\n", str_);
+ }
ovs_fatal(0, "field %s missing value", name);
}
@@ -875,6 +886,9 @@ parse_ofp_str(struct flow_mod *fm, struct ofpbuf *actions, char *string)
&& isdigit((unsigned char) name[3])) {
unsigned int reg_idx = atoi(name + 3);
if (reg_idx >= FLOW_N_REGS) {
+ if (verbose) {
+ fprintf(stderr, "%s:\n", str_);
+ }
ovs_fatal(0, "only %d registers supported", FLOW_N_REGS);
}
parse_reg_value(&fm->cr, reg_idx, value);
@@ -885,10 +899,15 @@ parse_ofp_str(struct flow_mod *fm, struct ofpbuf *actions, char *string)
* "ovs-ofctl dump-flows" back into commands that parse
* flows. */
} else {
+ if (verbose) {
+ fprintf(stderr, "%s:\n", str_);
+ }
ovs_fatal(0, "unknown keyword %s", name);
}
}
}
+
+ free(string);
}
/* Parses 'string' as an OFPT_FLOW_MOD or NXT_FLOW_MOD with command 'command'
@@ -899,7 +918,8 @@ parse_ofp_str(struct flow_mod *fm, struct ofpbuf *actions, char *string)
* flow. */
void
parse_ofp_flow_mod_str(struct list *packets, enum nx_flow_format *cur_format,
- bool *flow_mod_table_id, char *string, uint16_t command)
+ bool *flow_mod_table_id, char *string, uint16_t command,
+ bool verbose)
{
bool is_del = command == OFPFC_DELETE || command == OFPFC_DELETE_STRICT;
enum nx_flow_format min_format, next_format;
@@ -909,7 +929,7 @@ parse_ofp_flow_mod_str(struct list *packets, enum nx_flow_format *cur_format,
struct flow_mod fm;
ofpbuf_init(&actions, 64);
- parse_ofp_str(&fm, is_del ? NULL : &actions, string);
+ parse_ofp_str(&fm, is_del ? NULL : &actions, string, verbose);
fm.command = command;
min_format = ofputil_min_flow_format(&fm.cr);
@@ -953,7 +973,7 @@ parse_ofp_flow_mod_file(struct list *packets,
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);
+ ds_cstr(&s), command, true);
}
ds_destroy(&s);
@@ -966,7 +986,7 @@ parse_ofp_flow_stats_request_str(struct flow_stats_request *fsr,
{
struct flow_mod fm;
- parse_ofp_str(&fm, NULL, string);
+ parse_ofp_str(&fm, NULL, string, false);
fsr->aggregate = aggregate;
fsr->match = fm.cr;
fsr->out_port = fm.out_port;
diff --git a/lib/ofp-parse.h b/lib/ofp-parse.h
index 8209298..d55159a 100644
--- a/lib/ofp-parse.h
+++ b/lib/ofp-parse.h
@@ -29,11 +29,12 @@ struct flow_stats_request;
struct list;
struct ofpbuf;
-void parse_ofp_str(struct flow_mod *, struct ofpbuf *actions, char *string);
+void parse_ofp_str(struct flow_mod *, struct ofpbuf *actions, const char *str_,
+ bool verbose);
void parse_ofp_flow_mod_str(struct list *packets,
enum nx_flow_format *cur, bool *flow_mod_table_id,
- char *string, uint16_t command);
+ char *string, uint16_t command, bool verbose);
bool parse_ofp_flow_mod_file(struct list *packets,
enum nx_flow_format *cur, bool *flow_mod_table_id,
FILE *, uint16_t command);
diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 473385d..709501a 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -657,7 +657,7 @@ do_flow_mod__(int argc, char *argv[], uint16_t command)
flow_mod_table_id = false;
parse_ofp_flow_mod_str(&requests, &flow_format, &flow_mod_table_id,
- argc > 2 ? argv[2] : "", command);
+ argc > 2 ? argv[2] : "", command, false);
check_final_format_for_flow_mod(flow_format);
open_vconn(argv[1], &vconn);
@@ -1034,7 +1034,7 @@ read_flows_from_file(const char *filename, struct classifier *cls, int index)
struct flow_mod fm;
ofpbuf_init(&actions, 64);
- parse_ofp_str(&fm, &actions, ds_cstr(&s));
+ parse_ofp_str(&fm, &actions, ds_cstr(&s), true);
version = xmalloc(sizeof *version);
version->cookie = fm.cookie;
@@ -1307,7 +1307,7 @@ do_parse_flow(int argc OVS_UNUSED, char *argv[])
list_init(&packets);
parse_ofp_flow_mod_str(&packets, &flow_format, &flow_mod_table_id,
- argv[1], OFPFC_ADD);
+ argv[1], OFPFC_ADD, false);
print_packet_list(&packets);
}
--
1.7.5.rc1
More information about the dev
mailing list