diff options
author | Ben Pfaff <blp@ovn.org> | 2019-04-30 15:07:07 -0700 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2019-06-09 16:19:30 -0700 |
commit | 4304fd986e11a889af4b8f50e052279b602e5c2a (patch) | |
tree | f2c17bb5ce86e99264e4d2e1ef43ee33e0bfc153 /utilities | |
parent | 9f0721e989fcaee69882130e31bc4ce223d7f59d (diff) | |
download | openvswitch-4304fd986e11a889af4b8f50e052279b602e5c2a.tar.gz |
ovs-ofctl: New testing command "parse-group".
This will be used in an upcoming test.
Acked-by: Numan Siddique <nusiddiq@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'utilities')
-rw-r--r-- | utilities/ovs-ofctl.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index 63620e4fb..754629d3d 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 }, |