summaryrefslogtreecommitdiff
path: root/ofproto
diff options
context:
space:
mode:
authorAndy Zhou <azhou@ovn.org>2017-03-15 18:39:57 -0700
committerAndy Zhou <azhou@ovn.org>2017-04-03 17:51:02 -0700
commit1c2f091b723e26388c41bca73fc183453f6c2ed8 (patch)
tree43360b9a46ad82f6ac4cbeded05e7ba2bc726f18 /ofproto
parent091d64c408682be41ac9934d7300f68c67d0fd92 (diff)
downloadopenvswitch-1c2f091b723e26388c41bca73fc183453f6c2ed8.tar.gz
ofproto: Use macros to define DPIF support fields
When adding a new field in the 'struct dpif_backer_support', the corresponding appctl show command should be updated to display the new field. Currently, there is nothing to remind the developer that to update the show command. This can lead to code maintenance issues. Switch to use macros to define those fields. This makes the show command update automatic. Signed-off-by: Andy Zhou <azhou@ovn.org> Acked-by: Joe Stringer <joe@ovn.org>
Diffstat (limited to 'ofproto')
-rw-r--r--ofproto/ofproto-dpif.c28
-rw-r--r--ofproto/ofproto-dpif.h59
2 files changed, 47 insertions, 40 deletions
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 523adad6f..9556a0e0c 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -4955,13 +4955,13 @@ ofproto_unixctl_dpif_dump_dps(struct unixctl_conn *conn, int argc OVS_UNUSED,
}
static void
-show_dp_feature_b(struct ds *ds, const char *feature, bool b)
+show_dp_feature_bool(struct ds *ds, const char *feature, bool b)
{
ds_put_format(ds, "%s: %s\n", feature, b ? "Yes" : "No");
}
static void
-show_dp_feature_s(struct ds *ds, const char *feature, size_t s)
+show_dp_feature_size_t(struct ds *ds, const char *feature, size_t s)
{
ds_put_format(ds, "%s: %"PRIuSIZE"\n", feature, s);
}
@@ -4969,21 +4969,15 @@ show_dp_feature_s(struct ds *ds, const char *feature, size_t s)
static void
dpif_show_support(const struct dpif_backer_support *support, struct ds *ds)
{
- show_dp_feature_b(ds, "Variable length userdata",
- support->variable_length_userdata);
- show_dp_feature_b(ds, "Masked set action", support->masked_set_action);
- show_dp_feature_b(ds, "Tunnel push pop", support->tnl_push_pop);
- show_dp_feature_b(ds, "Ufid", support->ufid);
- show_dp_feature_b(ds, "Trunc action", support->trunc);
- show_dp_feature_b(ds, "Clone action", support->clone);
- show_dp_feature_s(ds, "Max MPLS depth", support->odp.max_mpls_depth);
- show_dp_feature_b(ds, "Recirc", support->odp.recirc);
- show_dp_feature_b(ds, "CT state", support->odp.ct_state);
- show_dp_feature_b(ds, "CT zone", support->odp.ct_zone);
- show_dp_feature_b(ds, "CT mark", support->odp.ct_mark);
- show_dp_feature_b(ds, "CT label", support->odp.ct_label);
- show_dp_feature_b(ds, "CT State NAT", support->odp.ct_state_nat);
- show_dp_feature_s(ds, "Max sample nesting", support->sample_nesting);
+#define DPIF_SUPPORT_FIELD(TYPE, NAME, TITLE) \
+ show_dp_feature_##TYPE (ds, TITLE, support->NAME);
+ DPIF_SUPPORT_FIELDS
+#undef DPIF_SUPPORT_FIELD
+
+#define ODP_SUPPORT_FIELD(TYPE, NAME, TITLE) \
+ show_dp_feature_##TYPE (ds, TITLE, support->odp.NAME );
+ ODP_SUPPORT_FIELDS
+#undef ODP_SUPPORT_FIELD
}
static void
diff --git a/ofproto/ofproto-dpif.h b/ofproto/ofproto-dpif.h
index cc514d245..81a0bdfda 100644
--- a/ofproto/ofproto-dpif.h
+++ b/ofproto/ofproto-dpif.h
@@ -143,34 +143,47 @@ struct group_dpif *group_dpif_lookup(struct ofproto_dpif *,
* ofproto-dpif) resides. A backer can host several bridges, but a bridge is
* backed by only a single dpif. */
-/* Stores the various features which the corresponding backer supports. */
-struct dpif_backer_support {
- /* True if the datapath supports variable-length
- * OVS_USERSPACE_ATTR_USERDATA in OVS_ACTION_ATTR_USERSPACE actions.
- * False if the datapath supports only 8-byte (or shorter) userdata. */
- bool variable_length_userdata;
-
- /* True if the datapath supports masked data in OVS_ACTION_ATTR_SET
- * actions. */
- bool masked_set_action;
- /* True if the datapath supports tnl_push and pop actions. */
- bool tnl_push_pop;
-
- /* True if the datapath supports OVS_FLOW_ATTR_UFID. */
- bool ufid;
+/* DPIF_SUPPORT_FIELD(TYPE, FIELD_NAME, FIELD_DESCRIPTION)
+ *
+ * Each 'DPIF_SUPPORT_FIELD' defines a member in 'struct dpif_backer_support'
+ * and represents support for a datapath action.
+ * They are defined as macros to keep 'dpif_show_support()' in sync
+ * as new fields are added. */
+#define DPIF_SUPPORT_FIELDS \
+ /* True if the datapath supports variable-length \
+ * OVS_USERSPACE_ATTR_USERDATA in OVS_ACTION_ATTR_USERSPACE actions. \
+ * False if the datapath supports only 8-byte (or shorter) userdata. */ \
+ DPIF_SUPPORT_FIELD(bool, variable_length_userdata, \
+ "Variable length userdata") \
+ \
+ /* True if the datapath supports masked data in OVS_ACTION_ATTR_SET \
+ * actions. */ \
+ DPIF_SUPPORT_FIELD(bool, masked_set_action, "Masked set action") \
+ \
+ /* True if the datapath supports tnl_push and pop actions. */ \
+ DPIF_SUPPORT_FIELD(bool, tnl_push_pop, "Tunnel push pop") \
+ \
+ /* True if the datapath supports OVS_FLOW_ATTR_UFID. */ \
+ DPIF_SUPPORT_FIELD(bool, ufid, "Ufid") \
+ \
+ /* True if the datapath supports OVS_ACTION_ATTR_TRUNC action. */ \
+ DPIF_SUPPORT_FIELD(bool, trunc, "Truncate action") \
+ \
+ /* True if the datapath supports OVS_ACTION_ATTR_CLONE action. */ \
+ DPIF_SUPPORT_FIELD(bool, clone, "Clone action") \
+ \
+ /* Maximum level of nesting allowed by OVS_ACTION_ATTR_SAMPLE action. */\
+ DPIF_SUPPORT_FIELD(size_t, sample_nesting, "Sample nesting")
- /* True if the datapath supports OVS_ACTION_ATTR_TRUNC action. */
- bool trunc;
+/* Stores the various features which the corresponding backer supports. */
+struct dpif_backer_support {
+#define DPIF_SUPPORT_FIELD(TYPE, NAME, TITLE) TYPE NAME;
+ DPIF_SUPPORT_FIELDS
+#undef DPIF_SUPPORT_FIELD
/* Each member represents support for related OVS_KEY_ATTR_* fields. */
struct odp_support odp;
-
- /* True if the datapath supports OVS_ACTION_ATTR_CLONE action. */
- bool clone;
-
- /* Maximum level of nesting allowed by OVS_ACTION_ATTR_SAMPLE action. */
- size_t sample_nesting;
};
/* Reasons that we might need to revalidate every datapath flow, and