Re: [ovs-dev] [PATCH v8] utilities/ofctl: add-meters for save and restore

2023-04-10 Thread 0-day Robot
Bleep bloop.  Greetings Wan Junjie, I am a robot and I have tried out your 
patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
WARNING: Line lacks whitespace around operator
#195 FILE: lib/ofp-meter.c:871:
error = parse_ofp_meter_mod_str(&(*mms)[*n_mms], ds_cstr(), command,

Lines checked: 702, Warnings: 1, Errors: 0


Please check this out.  If you feel there has been an error, please email 
acon...@redhat.com

Thanks,
0-day Robot
___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


[ovs-dev] [PATCH v8] utilities/ofctl: add-meters for save and restore

2023-04-10 Thread Wan Junjie via dev
put dump-meters' result in one line so add-meters can handle.
save and restore meters when restart ovs.
bundle functions are not implemented in this patch.

Signed-off-by: Wan Junjie 

---
v8:
fix missing code for testcase

v7:
typo in code

v6:
code style

v5:
merge oneline to verbosity higher bits
remove duplicate dump_meters code

v4:
code refactor according to comments

v3:
add '--oneline' option for dump-meter(s) command

v2:
fix failed testcases, as dump-meters format changes
---
 include/openvswitch/ofp-meter.h |   9 ++-
 include/openvswitch/ofp-print.h |  10 +++
 lib/ofp-meter.c | 100 ++-
 lib/ofp-print.c |  19 +++--
 tests/dpif-netdev.at|  44 --
 utilities/ovs-ofctl.8.in|  25 +-
 utilities/ovs-ofctl.c   | 137 
 utilities/ovs-save  |   8 ++
 8 files changed, 301 insertions(+), 51 deletions(-)

diff --git a/include/openvswitch/ofp-meter.h b/include/openvswitch/ofp-meter.h
index 6776eae87..a8ee2d61d 100644
--- a/include/openvswitch/ofp-meter.h
+++ b/include/openvswitch/ofp-meter.h
@@ -17,6 +17,7 @@
 #ifndef OPENVSWITCH_OFP_METER_H
 #define OPENVSWITCH_OFP_METER_H 1
 
+#include 
 #include "openflow/openflow.h"
 #include "openvswitch/ofp-protocol.h"
 
@@ -61,7 +62,8 @@ int ofputil_decode_meter_config(struct ofpbuf *,
 struct ofputil_meter_config *,
 struct ofpbuf *bands);
 void ofputil_format_meter_config(struct ds *,
- const struct ofputil_meter_config *);
+ const struct ofputil_meter_config *,
+ bool oneline);
 
 struct ofputil_meter_mod {
 uint16_t command;
@@ -79,6 +81,11 @@ char *parse_ofp_meter_mod_str(struct ofputil_meter_mod *, 
const char *string,
 OVS_WARN_UNUSED_RESULT;
 void ofputil_format_meter_mod(struct ds *, const struct ofputil_meter_mod *);
 
+char *parse_ofp_meter_mod_file(const char *file_name, int command,
+   struct ofputil_meter_mod **mms, size_t *n_mms,
+   enum ofputil_protocol *usable_protocols)
+OVS_WARN_UNUSED_RESULT;
+
 struct ofputil_meter_stats {
 uint32_t meter_id;
 uint32_t flow_count;
diff --git a/include/openvswitch/ofp-print.h b/include/openvswitch/ofp-print.h
index d76f06872..b7f8d15e9 100644
--- a/include/openvswitch/ofp-print.h
+++ b/include/openvswitch/ofp-print.h
@@ -38,6 +38,16 @@ struct dp_packet;
 extern "C" {
 #endif
 
+/* manipulate higher bits in verbosity for other usage */
+#define ONELINE_BIT 7
+#define ONELINE_MASK (1 << ONELINE_BIT)
+#define VERBOSITY_MASK (~ONELINE_MASK)
+
+#define VERBOSITY(verbosity) (verbosity & ~VERBOSITY_MASK)
+
+#define ONELINE_SET(verbosity) (verbosity | ONELINE_MASK)
+#define ONELINE_GET(verbosity) (verbosity & ONELINE_MASK)
+
 void ofp_print(FILE *, const void *, size_t, const struct ofputil_port_map *,
const struct ofputil_table_map *, int verbosity);
 void ofp_print_packet(FILE *stream, const void *data,
diff --git a/lib/ofp-meter.c b/lib/ofp-meter.c
index 9ea40a0bf..6d760620d 100644
--- a/lib/ofp-meter.c
+++ b/lib/ofp-meter.c
@@ -15,6 +15,7 @@
  */
 
 #include 
+#include 
 #include "openvswitch/ofp-meter.h"
 #include "byte-order.h"
 #include "nx-match.h"
@@ -57,7 +58,7 @@ void
 ofputil_format_meter_band(struct ds *s, enum ofp13_meter_flags flags,
   const struct ofputil_meter_band *mb)
 {
-ds_put_cstr(s, "\ntype=");
+ds_put_cstr(s, "type=");
 switch (mb->type) {
 case OFPMBT13_DROP:
 ds_put_cstr(s, "drop");
@@ -343,7 +344,8 @@ ofp_print_meter_flags(struct ds *s, enum ofp13_meter_flags 
flags)
 
 void
 ofputil_format_meter_config(struct ds *s,
-const struct ofputil_meter_config *mc)
+const struct ofputil_meter_config *mc,
+bool oneline)
 {
 uint16_t i;
 
@@ -354,6 +356,7 @@ ofputil_format_meter_config(struct ds *s,
 
 ds_put_cstr(s, "bands=");
 for (i = 0; i < mc->n_bands; ++i) {
+ds_put_cstr(s, oneline ? " ": "\n");
 ofputil_format_meter_band(s, mc->flags, >bands[i]);
 }
 ds_put_char(s, '\n');
@@ -578,6 +581,24 @@ parse_ofp_meter_mod_str__(struct ofputil_meter_mod *mm, 
char *string,
 
 /* Meters require at least OF 1.3. */
 *usable_protocols = OFPUTIL_P_OF13_UP;
+if (command == -2) {
+size_t len;
+
+string += strspn(string, " \t\r\n");   /* Skip white space. */
+len = strcspn(string, ", \t\r\n"); /* Get length of the first token. */
+
+if (!strncmp(string, "add", len)) {
+command = OFPMC13_ADD;
+} else if (!strncmp(string, "delete", len)) {
+command = OFPMC13_DELETE;
+} else if (!strncmp(string, "modify", len)) {
+command = OFPMC13_MODIFY;
+} else {
+len = 0;
+