From: Isaku Yamahata Date: Wed, 1 Aug 2012 15:24:10 +0000 (+0900) Subject: ofp-actions/instruction: helper functions for intructions X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a359d5ad700c7175c75134cce3cee8d87d19d67c;p=openvswitch 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 --- diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index b84ca63d..6503f61c 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 604b56c2..2e021819 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 */