[ovs-dev] [RFC PATCH 8/8] ovs-ofctl: Add meter support.

Jarno Rajahalme jarno.rajahalme at nsn.com
Thu Jun 20 14:26:23 UTC 2013


Adds commands add-meter, mod-meter, del-meter, del-meters, dump-meter,
dump-meters, meter-stats, and meter-features.

Syntax is as follows:

add-meter <br> meter=<n> (kbps|pktps) [burst] [stats] bands= type=(drop|dscp_remark) rate=<n> [burst_size=<n>] [prec_level=<n>] <more bands>

mod-meter <br> meter=<n> (kbps|pktps) [burst] [stats] bands= type=(drop|dscp_remark) rate=<n> [burst_size=<n>] [prec_level=<n>] <more bands>

del-meter <br> meter=(<n>|all)

del-meters <br>

dump-meter <br> meter=(<n>|all)

dump-meters <br>

meter-stats <br> [meter=(<n>|all)]

meter-features <br>

Signed-off-by: Jarno Rajahalme <jarno.rajahalme at nsn.com>
---
 utilities/ovs-ofctl.c |   88 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 48f0fbf..7bafaa1 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -2175,6 +2175,86 @@ ofctl_diff_flows(int argc OVS_UNUSED, char *argv[])
         exit(2);
     }
 }
+
+static void
+ofctl_meter_mod__(const char *bridge, const char *str, int command,
+                  bool verbose)
+{
+    struct ofputil_meter_mod mm;
+    struct vconn *vconn;
+
+    if (str) {
+        parse_ofp_meter_mod_str(&mm, str, command, verbose);
+    } else {
+        mm.command = command;
+        mm.meter.meter_id = OFPM13_ALL;
+    }
+    open_vconn(bridge, &vconn);
+    transact_noreply(vconn, ofputil_encode_meter_mod(OFP13_VERSION, &mm));
+    vconn_close(vconn);
+}
+
+
+static void
+ofctl_meter_request__(const char *bridge, const char *str,
+                      enum ofputil_meter_request_type type, bool verbose)
+{
+    struct ofputil_meter_mod mm;
+    struct vconn *vconn;
+
+    if (str) {
+        parse_ofp_meter_mod_str(&mm, str, -1, verbose);
+    } else {
+        mm.meter.meter_id = OFPM13_ALL;
+    }
+
+    open_vconn(bridge, &vconn);
+    transact_noreply(vconn, ofputil_encode_meter_request(OFP13_VERSION,
+                                                         type,
+                                                         mm.meter.meter_id));
+    vconn_close(vconn);
+}
+
+
+static void
+ofctl_add_meter(int argc OVS_UNUSED, char *argv[])
+{
+    ofctl_meter_mod__(argv[1], argv[2], OFPMC13_ADD, true);
+}
+
+static void
+ofctl_mod_meter(int argc OVS_UNUSED, char *argv[])
+{
+    ofctl_meter_mod__(argv[1], argv[2], OFPMC13_MODIFY, true);
+}
+
+static void
+ofctl_del_meters(int argc, char *argv[])
+{
+    ofctl_meter_mod__(argv[1], argc > 2 ? argv[2] : NULL,
+                      OFPMC13_DELETE, true);
+}
+
+static void
+ofctl_dump_meters(int argc, char *argv[])
+{
+    ofctl_meter_request__(argv[1], argc > 2 ? argv[2] : NULL,
+                          OFPUTIL_METER_CONFIG, true);
+}
+
+static void
+ofctl_meter_stats(int argc, char *argv[])
+{
+    ofctl_meter_request__(argv[1], argc > 2 ? argv[2] : NULL,
+                          OFPUTIL_METER_STATS, true);
+}
+
+static void
+ofctl_meter_features(int argc OVS_UNUSED, char *argv[])
+{
+    ofctl_meter_request__(argv[1], NULL, OFPUTIL_METER_FEATURES, true);
+}
+
 
 /* Undocumented commands for unit testing. */
 
@@ -2865,6 +2945,14 @@ static const struct command all_commands[] = {
     { "del-flows", 1, 2, ofctl_del_flows },
     { "replace-flows", 2, 2, ofctl_replace_flows },
     { "diff-flows", 2, 2, ofctl_diff_flows },
+    { "add-meter", 2, 2, ofctl_add_meter },
+    { "mod-meter", 2, 2, ofctl_mod_meter },
+    { "del-meter", 2, 2, ofctl_del_meters },
+    { "del-meters", 1, 1, ofctl_del_meters },
+    { "dump-meter", 2, 2, ofctl_dump_meters },
+    { "dump-meters", 1, 1, ofctl_dump_meters },
+    { "meter-stats", 1, 2, ofctl_meter_stats },
+    { "meter-features", 1, 1, ofctl_meter_features },
     { "packet-out", 4, INT_MAX, ofctl_packet_out },
     { "dump-ports", 1, 2, ofctl_dump_ports },
     { "dump-ports-desc", 1, 1, ofctl_dump_ports_desc },
-- 
1.7.10.4




More information about the dev mailing list