+
+static void
+ofctl_meter_mod__(const char *bridge, const char *str, int command)
+{
+ struct ofputil_meter_mod mm;
+ struct vconn *vconn;
+ enum ofputil_protocol protocol;
+ enum ofputil_protocol usable_protocols;
+ enum ofp_version version;
+
+ if (str) {
+ char *error;
+ error = parse_ofp_meter_mod_str(&mm, str, command, &usable_protocols);
+ if (error) {
+ ovs_fatal(0, "%s", error);
+ }
+ } else {
+ usable_protocols = OFPUTIL_P_OF13_UP;
+ mm.command = command;
+ mm.meter.meter_id = OFPM13_ALL;
+ }
+
+ protocol = open_vconn_for_flow_mod(bridge, &vconn, usable_protocols);
+ version = ofputil_protocol_to_ofp_version(protocol);
+ transact_noreply(vconn, ofputil_encode_meter_mod(version, &mm));
+ vconn_close(vconn);
+}
+
+static void
+ofctl_meter_request__(const char *bridge, const char *str,
+ enum ofputil_meter_request_type type)
+{
+ struct ofputil_meter_mod mm;
+ struct vconn *vconn;
+ enum ofputil_protocol usable_protocols;
+ enum ofputil_protocol protocol;
+ enum ofp_version version;
+
+ if (str) {
+ char *error;
+ error = parse_ofp_meter_mod_str(&mm, str, -1, &usable_protocols);
+ if (error) {
+ ovs_fatal(0, "%s", error);
+ }
+ } else {
+ usable_protocols = OFPUTIL_P_OF13_UP;
+ mm.meter.meter_id = OFPM13_ALL;
+ }
+
+ protocol = open_vconn_for_flow_mod(bridge, &vconn, usable_protocols);
+ version = ofputil_protocol_to_ofp_version(protocol);
+ transact_noreply(vconn, ofputil_encode_meter_request(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);
+}
+
+static void
+ofctl_mod_meter(int argc OVS_UNUSED, char *argv[])
+{
+ ofctl_meter_mod__(argv[1], argv[2], OFPMC13_MODIFY);
+}
+
+static void
+ofctl_del_meters(int argc, char *argv[])
+{
+ ofctl_meter_mod__(argv[1], argc > 2 ? argv[2] : NULL, OFPMC13_DELETE);
+}
+
+static void
+ofctl_dump_meters(int argc, char *argv[])
+{
+ ofctl_meter_request__(argv[1], argc > 2 ? argv[2] : NULL,
+ OFPUTIL_METER_CONFIG);
+}
+
+static void
+ofctl_meter_stats(int argc, char *argv[])
+{
+ ofctl_meter_request__(argv[1], argc > 2 ? argv[2] : NULL,
+ OFPUTIL_METER_STATS);
+}
+
+static void
+ofctl_meter_features(int argc OVS_UNUSED, char *argv[])
+{
+ ofctl_meter_request__(argv[1], NULL, OFPUTIL_METER_FEATURES);
+}
+