2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 06:15:47 +00:00

ofp-actions/instruction: helper functions for intructions

This patch introduces helper functions
- to cast
- to convert from/to text

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
Isaku Yamahata
2012-08-02 00:24:10 +09:00
committed by Ben Pfaff
parent 99c476dcd9
commit a359d5ad70
2 changed files with 45 additions and 0 deletions

View File

@@ -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)
{