From a359d5ad700c7175c75134cce3cee8d87d19d67c Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Thu, 2 Aug 2012 00:24:10 +0900 Subject: [PATCH] ofp-actions/instruction: helper functions for intructions This patch introduces helper functions - to cast - to convert from/to text Signed-off-by: Isaku Yamahata Signed-off-by: Ben Pfaff --- lib/ofp-actions.c | 42 ++++++++++++++++++++++++++++++++++++++++++ lib/ofp-actions.h | 3 +++ 2 files changed, 45 insertions(+) diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index b84ca63d1..6503f61ca 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -674,6 +674,13 @@ ofpacts_from_openflow11(const union ofp_action *in, size_t n_in, /* OpenFlow 1.1 instructions. */ #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) \ + static inline const struct STRUCT * \ + instruction_get_##ENUM(const struct ofp11_instruction *inst)\ + { \ + assert(inst->type == htons(ENUM)); \ + return (struct STRUCT *)inst; \ + } \ + \ static inline void \ instruction_init_##ENUM(struct STRUCT *s) \ { \ @@ -692,6 +699,41 @@ ofpacts_from_openflow11(const union ofp_action *in, size_t n_in, OVS_INSTRUCTIONS #undef DEFINE_INST +struct instruction_type_info { + enum ovs_instruction_type type; + const char *name; +}; + +static const struct instruction_type_info inst_info[] = { +#define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) {OVSINST_##ENUM, NAME}, +OVS_INSTRUCTIONS +#undef DEFINE_INST +}; + +const char * +ofpact_instruction_name_from_type(enum ovs_instruction_type type) +{ + const struct instruction_type_info *p; + for (p = inst_info; p < &inst_info[ARRAY_SIZE(inst_info)]; p++) { + if (p->type == type) { + return p->name; + } + } + return NULL; +} + +int +ofpact_instruction_type_from_name(const char *name) +{ + const struct instruction_type_info *p; + for (p = inst_info; p < &inst_info[ARRAY_SIZE(inst_info)]; p++) { + if (!strcasecmp(name, p->name)) { + return p->type; + } + } + return -1; +} + static inline struct ofp11_instruction * instruction_next(const struct ofp11_instruction *inst) { diff --git a/lib/ofp-actions.h b/lib/ofp-actions.h index 604b56c26..2e021819d 100644 --- a/lib/ofp-actions.h +++ b/lib/ofp-actions.h @@ -530,4 +530,7 @@ enum { #undef DEFINE_INST }; +const char *ofpact_instruction_name_from_type(enum ovs_instruction_type type); +int ofpact_instruction_type_from_name(const char *name); + #endif /* ofp-actions.h */ -- 2.43.0