lib/ofp-print.c \
lib/ofp-print.h \
lib/ofp-util.c \
+ lib/ofp-util.def \
lib/ofp-util.h \
lib/ofpbuf.c \
lib/ofpbuf.h \
enum ofp_action_type type = ntohs(a->type);
switch (type) {
-#define OFPAT_ACTION(ENUM, TYPE) \
+#define OFPAT_ACTION(ENUM, STRUCT, NAME) \
case ENUM: { \
static const struct ofputil_action action = { \
- OFPUTIL_##ENUM, sizeof(TYPE), sizeof(TYPE) \
+ OFPUTIL_##ENUM, \
+ sizeof(struct STRUCT), \
+ sizeof(struct STRUCT) \
}; \
return &action; \
}
- OFPAT_ACTION(OFPAT_OUTPUT, struct ofp_action_output);
- OFPAT_ACTION(OFPAT_SET_VLAN_VID, struct ofp_action_vlan_vid);
- OFPAT_ACTION(OFPAT_SET_VLAN_PCP, struct ofp_action_vlan_pcp);
- OFPAT_ACTION(OFPAT_STRIP_VLAN, struct ofp_action_header);
- OFPAT_ACTION(OFPAT_SET_DL_SRC, struct ofp_action_dl_addr);
- OFPAT_ACTION(OFPAT_SET_DL_DST, struct ofp_action_dl_addr);
- OFPAT_ACTION(OFPAT_SET_NW_SRC, struct ofp_action_nw_addr);
- OFPAT_ACTION(OFPAT_SET_NW_DST, struct ofp_action_nw_addr);
- OFPAT_ACTION(OFPAT_SET_NW_TOS, struct ofp_action_nw_tos);
- OFPAT_ACTION(OFPAT_SET_TP_SRC, struct ofp_action_tp_port);
- OFPAT_ACTION(OFPAT_SET_TP_DST, struct ofp_action_tp_port);
- OFPAT_ACTION(OFPAT_ENQUEUE, struct ofp_action_enqueue);
-#undef OFPAT_ACTION
+#include "ofp-util.def"
case OFPAT_VENDOR:
default:
enum nx_action_subtype subtype = ntohs(nah->subtype);
switch (subtype) {
-#define NXAST_ACTION(ENUM, TYPE, EXTENSIBLE) \
- case ENUM: { \
- static const struct ofputil_action action = { \
- OFPUTIL_##ENUM, \
- sizeof(TYPE), \
- EXTENSIBLE ? UINT_MAX : sizeof(TYPE) \
- }; \
- return &action; \
+#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
+ case ENUM: { \
+ static const struct ofputil_action action = { \
+ OFPUTIL_##ENUM, \
+ sizeof(struct STRUCT), \
+ EXTENSIBLE ? UINT_MAX : sizeof(struct STRUCT) \
+ }; \
+ return &action; \
}
- NXAST_ACTION(NXAST_RESUBMIT, struct nx_action_resubmit, false);
- NXAST_ACTION(NXAST_SET_TUNNEL, struct nx_action_set_tunnel, false);
- NXAST_ACTION(NXAST_SET_QUEUE, struct nx_action_set_queue, false);
- NXAST_ACTION(NXAST_POP_QUEUE, struct nx_action_pop_queue, false);
- NXAST_ACTION(NXAST_REG_MOVE, struct nx_action_reg_move, false);
- NXAST_ACTION(NXAST_REG_LOAD, struct nx_action_reg_load, false);
- NXAST_ACTION(NXAST_NOTE, struct nx_action_note, true);
- NXAST_ACTION(NXAST_SET_TUNNEL64, struct nx_action_set_tunnel64, false);
- NXAST_ACTION(NXAST_MULTIPATH, struct nx_action_multipath, false);
- NXAST_ACTION(NXAST_AUTOPATH, struct nx_action_autopath, false);
- NXAST_ACTION(NXAST_BUNDLE, struct nx_action_bundle, true);
- NXAST_ACTION(NXAST_BUNDLE_LOAD, struct nx_action_bundle, true);
- NXAST_ACTION(NXAST_RESUBMIT_TABLE, struct nx_action_resubmit, false);
- NXAST_ACTION(NXAST_OUTPUT_REG, struct nx_action_output_reg, false);
-#undef NXAST_ACTION
+#include "ofp-util.def"
case NXAST_SNAT__OBSOLETE:
case NXAST_DROP_SPOOFED_ARP__OBSOLETE:
return action->code;
}
+/* Returns the 'enum ofputil_action_code' corresponding to 'name' (e.g. if
+ * 'name' is "output" then the return value is OFPUTIL_OFPAT_OUTPUT), or -1 if
+ * 'name' is not the name of any action.
+ *
+ * ofp-util.def lists the mapping from names to action. */
+int
+ofputil_action_code_from_name(const char *name)
+{
+ static const char *names[OFPUTIL_N_ACTIONS] = {
+#define OFPAT_ACTION(ENUM, STRUCT, NAME) NAME,
+#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) NAME,
+#include "ofp-util.def"
+ };
+
+ const char **p;
+
+ for (p = names; p < &names[ARRAY_SIZE(names)]; p++) {
+ if (*p && !strcasecmp(name, *p)) {
+ return p - names;
+ }
+ }
+ return -1;
+}
+
/* Returns true if 'action' outputs to 'port', false otherwise. */
bool
action_outputs_to_port(const union ofp_action *action, ovs_be16 port)
--- /dev/null
+/* -*- c -*- */
+
+#ifndef OFPAT_ACTION
+#define OFPAT_ACTION(ENUM, STRUCT, NAME)
+#endif
+OFPAT_ACTION(OFPAT_OUTPUT, ofp_action_output, "output")
+OFPAT_ACTION(OFPAT_SET_VLAN_VID, ofp_action_vlan_vid, "mod_vlan_vid")
+OFPAT_ACTION(OFPAT_SET_VLAN_PCP, ofp_action_vlan_pcp, "mod_vlan_pcp")
+OFPAT_ACTION(OFPAT_STRIP_VLAN, ofp_action_header, "strip_vlan")
+OFPAT_ACTION(OFPAT_SET_DL_SRC, ofp_action_dl_addr, "mod_dl_src")
+OFPAT_ACTION(OFPAT_SET_DL_DST, ofp_action_dl_addr, "mod_dl_dst")
+OFPAT_ACTION(OFPAT_SET_NW_SRC, ofp_action_nw_addr, "mod_nw_src")
+OFPAT_ACTION(OFPAT_SET_NW_DST, ofp_action_nw_addr, "mod_nw_dst")
+OFPAT_ACTION(OFPAT_SET_NW_TOS, ofp_action_nw_tos, "mod_nw_tos")
+OFPAT_ACTION(OFPAT_SET_TP_SRC, ofp_action_tp_port, "mod_tp_src")
+OFPAT_ACTION(OFPAT_SET_TP_DST, ofp_action_tp_port, "mod_tp_dst")
+OFPAT_ACTION(OFPAT_ENQUEUE, ofp_action_enqueue, "enqueue")
+#undef OFPAT_ACTION
+
+#ifndef NXAST_ACTION
+#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME)
+#endif
+NXAST_ACTION(NXAST_RESUBMIT, nx_action_resubmit, 0, "resubmit")
+NXAST_ACTION(NXAST_SET_TUNNEL, nx_action_set_tunnel, 0, "set_tunnel")
+NXAST_ACTION(NXAST_SET_QUEUE, nx_action_set_queue, 0, "set_queue")
+NXAST_ACTION(NXAST_POP_QUEUE, nx_action_pop_queue, 0, "pop_queue")
+NXAST_ACTION(NXAST_REG_MOVE, nx_action_reg_move, 0, "move")
+NXAST_ACTION(NXAST_REG_LOAD, nx_action_reg_load, 0, "load")
+NXAST_ACTION(NXAST_NOTE, nx_action_note, 1, "note")
+NXAST_ACTION(NXAST_SET_TUNNEL64, nx_action_set_tunnel64, 0, "set_tunnel64")
+NXAST_ACTION(NXAST_MULTIPATH, nx_action_multipath, 0, "multipath")
+NXAST_ACTION(NXAST_AUTOPATH, nx_action_autopath, 0, "autopath")
+NXAST_ACTION(NXAST_BUNDLE, nx_action_bundle, 1, "bundle")
+NXAST_ACTION(NXAST_BUNDLE_LOAD, nx_action_bundle, 1, "bundle_load")
+NXAST_ACTION(NXAST_RESUBMIT_TABLE, nx_action_resubmit, 0, NULL)
+NXAST_ACTION(NXAST_OUTPUT_REG, nx_action_output_reg, 0, NULL)
+#undef NXAST_ACTION
\f
/* Actions. */
+/* The type of an action.
+ *
+ * For each implemented OFPAT_* and NXAST_* action type, there is a
+ * corresponding constant prefixed with OFPUTIL_, e.g.:
+ *
+ * OFPUTIL_OFPAT_OUTPUT
+ * OFPUTIL_OFPAT_SET_VLAN_VID
+ * OFPUTIL_OFPAT_SET_VLAN_PCP
+ * OFPUTIL_OFPAT_STRIP_VLAN
+ * OFPUTIL_OFPAT_SET_DL_SRC
+ * OFPUTIL_OFPAT_SET_DL_DST
+ * OFPUTIL_OFPAT_SET_NW_SRC
+ * OFPUTIL_OFPAT_SET_NW_DST
+ * OFPUTIL_OFPAT_SET_NW_TOS
+ * OFPUTIL_OFPAT_SET_TP_SRC
+ * OFPUTIL_OFPAT_SET_TP_DST
+ * OFPUTIL_OFPAT_ENQUEUE
+ * OFPUTIL_NXAST_RESUBMIT
+ * OFPUTIL_NXAST_SET_TUNNEL
+ * OFPUTIL_NXAST_SET_QUEUE
+ * OFPUTIL_NXAST_POP_QUEUE
+ * OFPUTIL_NXAST_REG_MOVE
+ * OFPUTIL_NXAST_REG_LOAD
+ * OFPUTIL_NXAST_NOTE
+ * OFPUTIL_NXAST_SET_TUNNEL64
+ * OFPUTIL_NXAST_MULTIPATH
+ * OFPUTIL_NXAST_AUTOPATH
+ * OFPUTIL_NXAST_BUNDLE
+ * OFPUTIL_NXAST_BUNDLE_LOAD
+ * OFPUTIL_NXAST_RESUBMIT_TABLE
+ * OFPUTIL_NXAST_OUTPUT_REG
+ *
+ * (The above list helps developers who want to "grep" for these definitions.)
+ */
enum ofputil_action_code {
- /* OFPAT_* actions. */
- OFPUTIL_OFPAT_OUTPUT,
- OFPUTIL_OFPAT_SET_VLAN_VID,
- OFPUTIL_OFPAT_SET_VLAN_PCP,
- OFPUTIL_OFPAT_STRIP_VLAN,
- OFPUTIL_OFPAT_SET_DL_SRC,
- OFPUTIL_OFPAT_SET_DL_DST,
- OFPUTIL_OFPAT_SET_NW_SRC,
- OFPUTIL_OFPAT_SET_NW_DST,
- OFPUTIL_OFPAT_SET_NW_TOS,
- OFPUTIL_OFPAT_SET_TP_SRC,
- OFPUTIL_OFPAT_SET_TP_DST,
- OFPUTIL_OFPAT_ENQUEUE,
-
- /* NXAST_* actions. */
- OFPUTIL_NXAST_RESUBMIT,
- OFPUTIL_NXAST_SET_TUNNEL,
- OFPUTIL_NXAST_SET_QUEUE,
- OFPUTIL_NXAST_POP_QUEUE,
- OFPUTIL_NXAST_REG_MOVE,
- OFPUTIL_NXAST_REG_LOAD,
- OFPUTIL_NXAST_NOTE,
- OFPUTIL_NXAST_SET_TUNNEL64,
- OFPUTIL_NXAST_MULTIPATH,
- OFPUTIL_NXAST_AUTOPATH,
- OFPUTIL_NXAST_BUNDLE,
- OFPUTIL_NXAST_BUNDLE_LOAD,
- OFPUTIL_NXAST_RESUBMIT_TABLE,
- OFPUTIL_NXAST_OUTPUT_REG
+#define OFPAT_ACTION(ENUM, STRUCT, NAME) OFPUTIL_##ENUM,
+#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
+#include "ofp-util.def"
+};
+
+/* The number of values of "enum ofputil_action_code". */
+enum {
+#define OFPAT_ACTION(ENUM, STRUCT, NAME) + 1
+#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
+ OFPUTIL_N_ACTIONS = 0
+#include "ofp-util.def"
};
int ofputil_decode_action(const union ofp_action *);
enum ofputil_action_code ofputil_decode_action_unsafe(
const union ofp_action *);
+int ofputil_action_code_from_name(const char *);
+
#define OFP_ACTION_ALIGN 8 /* Alignment of ofp_actions. */
static inline union ofp_action *