[ovs-dev] [PATCH 2/2] feature: Add ovs-ofctl parse-ofpraw command.

Alex Wang alexw at nicira.com
Mon Aug 5 03:14:31 UTC 2013


This commit adds a new commmand "ovs-ofctl parse-ofpraw" to ovs.
It allows user to parse undecoded raw OpenFlow messages into human
readable form. It can parse the output log of "ovs-appctl log/controller"
command.

Signed-off-by: Alex Wang <alexw at nicira.com>
---
 utilities/ovs-ofctl.c |   29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 68b73bf..9f904e3 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -2911,6 +2911,34 @@ ofctl_encode_hello(int argc OVS_UNUSED, char *argv[])
     ofpbuf_delete(hello);
 }
 
+/* "parse-ofpraw file|-": Parses the undecoded raw OpenFlow message 
+ * to human readable format.  The argument is the file that contains
+ * the raw message or "-" for standard input. */
+static void
+ofctl_parse_ofpraw(int argc OVS_UNUSED, char *argv[])
+{
+    int line_number;
+    FILE *file;
+    struct ds s;
+
+    file = !strcmp(argv[1], "-") ? stdin : fopen(argv[1], "r");
+    if (file == NULL) {
+        fprintf(stderr, "%s: open failed (%s)",
+                argv[1], ovs_strerror(errno));
+    }
+
+    ds_init(&s);
+    line_number = 0;
+    while (!ds_get_preprocessed_line(&s, file, &line_number)) {
+        ofp_print(stdout, ds_cstr(&s), s.length, verbosity + 2);
+    }
+
+    ds_destroy(&s);
+    if (file != stdin) {
+        fclose(file);
+    }
+}
+
 static const struct command all_commands[] = {
     { "show", 1, 1, ofctl_show },
     { "monitor", 1, 3, ofctl_monitor },
@@ -2948,6 +2976,7 @@ static const struct command all_commands[] = {
     { "parse-ofp11-match", 0, 0, ofctl_parse_ofp11_match },
     { "parse-ofp11-actions", 0, 0, ofctl_parse_ofp11_actions },
     { "parse-ofp11-instructions", 0, 0, ofctl_parse_ofp11_instructions },
+    { "parse-ofpraw", 1, 1, ofctl_parse_ofpraw },
     { "check-vlan", 2, 2, ofctl_check_vlan },
     { "print-error", 1, 1, ofctl_print_error },
     { "encode-error-reply", 2, 2, ofctl_encode_error_reply },
-- 
1.7.9.5




More information about the dev mailing list