diff mbox series

[ovs-dev,07/10] ovs-ofctl: New testing command "parse-group".

Message ID 20190430232728.31093-7-blp@ovn.org
State Accepted
Commit 4304fd986e11a889af4b8f50e052279b602e5c2a
Headers show
Series [ovs-dev,01/10] ofp-actions: Make encap action really require OF1.3+. | expand

Commit Message

Ben Pfaff April 30, 2019, 11:27 p.m. UTC
This will be used in an upcoming test.

Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 lib/ofp-group.c       |  5 ++++-
 utilities/ovs-ofctl.c | 41 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lib/ofp-group.c b/lib/ofp-group.c
index da5ff5848ccf..b675e802c317 100644
--- a/lib/ofp-group.c
+++ b/lib/ofp-group.c
@@ -1,5 +1,5 @@ 
 /*
- * Copyright (c) 2008-2017 Nicira, Inc.
+ * Copyright (c) 2008-2017, 2019 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -2014,6 +2014,8 @@  ofputil_encode_ofp11_group_mod(enum ofp_version ofp_version,
     ogm->type = gm->type;
     ogm->group_id = htonl(gm->group_id);
 
+    ofpmsg_update_length(b);
+
     return b;
 }
 
@@ -2080,6 +2082,7 @@  ofputil_encode_ofp15_group_mod(enum ofp_version ofp_version,
     }
 
     id_pool_destroy(bucket_ids);
+    ofpmsg_update_length(b);
     return b;
 }
 
diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 63620e4fb331..754629d3dfbb 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -1,5 +1,5 @@ 
 /*
- * Copyright (c) 2008-2017 Nicira, Inc.
+ * Copyright (c) 2008-2017, 2019 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -4175,6 +4175,44 @@  ofctl_parse_flows(struct ovs_cmdl_context *ctx)
     free(fms);
 }
 
+/* "parse-group GROUP": parses the argument as a group (like add-group) and
+ * prints it back to stdout.  */
+static void
+ofctl_parse_group(struct ovs_cmdl_context *ctx)
+{
+    enum ofputil_protocol usable_protocols;
+    struct ofputil_group_mod gm;
+    char *error = parse_ofp_group_mod_str(&gm, OFPGC11_ADD, ctx->argv[1], NULL,
+                                          NULL, &usable_protocols);
+    if (error) {
+        ovs_fatal(0, "%s", error);
+    }
+
+    char *usable_s = ofputil_protocols_to_string(usable_protocols);
+    printf("usable protocols: %s\n", usable_s);
+    free(usable_s);
+
+    if (!(usable_protocols & allowed_protocols)) {
+        ovs_fatal(0, "no usable protocol");
+    }
+    enum ofputil_protocol protocol = 0;
+    for (int i = 0; i < sizeof(enum ofputil_protocol) * CHAR_BIT; i++) {
+        protocol = 1 << i;
+        if (protocol & usable_protocols & allowed_protocols) {
+            break;
+        }
+    }
+
+    enum ofp_version version = ofputil_protocol_to_ofp_version(protocol);
+    printf("chosen version: %s\n", ofputil_version_to_string(version));
+
+    struct ofpbuf *msg = ofputil_encode_group_mod(version, &gm, NULL, false);
+    ofp_print(stdout, msg->data, msg->size, NULL, NULL, verbosity);
+    ofpbuf_delete(msg);
+
+    ofputil_uninit_group_mod(&gm);
+}
+
 static void
 ofctl_parse_nxm__(bool oxm, enum ofp_version version)
 {
@@ -5033,6 +5071,7 @@  static const struct ovs_cmdl_command all_commands[] = {
     /* Undocumented commands for testing. */
     { "parse-flow", NULL, 1, 1, ofctl_parse_flow, OVS_RW },
     { "parse-flows", NULL, 1, 1, ofctl_parse_flows, OVS_RW },
+    { "parse-group", NULL, 1, 1, ofctl_parse_group, OVS_RW },
     { "parse-nx-match", NULL, 0, 0, ofctl_parse_nxm, OVS_RW },
     { "parse-nxm", NULL, 0, 0, ofctl_parse_nxm, OVS_RW },
     { "parse-oxm", NULL, 1, 1, ofctl_parse_oxm, OVS_RW },