mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 06:15:47 +00:00
ofp-actions: Add instructions bitmaps and fix related bug.
This will allow, later, to centralize all of the knowledge of instruction encoding inside ofp-actions. OFPIT11_ALL and OFPIT13_ALL are no longer used, so this commit removes them. Their definitions were wrong (they did not shift each bit into position correctly), so this commit is also a small bug fix. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
This commit is contained in:
@@ -1646,6 +1646,75 @@ OVS_INSTRUCTIONS
|
||||
}
|
||||
}
|
||||
|
||||
/* Two-way translation between OVS's internal "OVSINST_*" representation of
|
||||
* instructions and the "OFPIT_*" representation used in OpenFlow. */
|
||||
struct ovsinst_map {
|
||||
enum ovs_instruction_type ovsinst; /* Internal name for instruction. */
|
||||
int ofpit; /* OFPIT_* number from OpenFlow spec. */
|
||||
};
|
||||
|
||||
static const struct ovsinst_map *
|
||||
get_ovsinst_map(enum ofp_version version)
|
||||
{
|
||||
/* OpenFlow 1.1 and 1.2 instructions. */
|
||||
static const struct ovsinst_map of11[] = {
|
||||
{ OVSINST_OFPIT11_GOTO_TABLE, 1 },
|
||||
{ OVSINST_OFPIT11_WRITE_METADATA, 2 },
|
||||
{ OVSINST_OFPIT11_WRITE_ACTIONS, 3 },
|
||||
{ OVSINST_OFPIT11_APPLY_ACTIONS, 4 },
|
||||
{ OVSINST_OFPIT11_CLEAR_ACTIONS, 5 },
|
||||
{ 0, -1 },
|
||||
};
|
||||
|
||||
/* OpenFlow 1.3+ instructions. */
|
||||
static const struct ovsinst_map of13[] = {
|
||||
{ OVSINST_OFPIT11_GOTO_TABLE, 1 },
|
||||
{ OVSINST_OFPIT11_WRITE_METADATA, 2 },
|
||||
{ OVSINST_OFPIT11_WRITE_ACTIONS, 3 },
|
||||
{ OVSINST_OFPIT11_APPLY_ACTIONS, 4 },
|
||||
{ OVSINST_OFPIT11_CLEAR_ACTIONS, 5 },
|
||||
{ OVSINST_OFPIT13_METER, 6 },
|
||||
{ 0, -1 },
|
||||
};
|
||||
|
||||
return version < OFP13_VERSION ? of11 : of13;
|
||||
}
|
||||
|
||||
/* Converts 'ovsinst_bitmap', a bitmap whose bits correspond to OVSINST_*
|
||||
* values, into a bitmap of instructions suitable for OpenFlow 'version'
|
||||
* (OFP11_VERSION or later), and returns the result. */
|
||||
ovs_be32
|
||||
ovsinst_bitmap_to_openflow(uint32_t ovsinst_bitmap, enum ofp_version version)
|
||||
{
|
||||
uint32_t ofpit_bitmap = 0;
|
||||
const struct ovsinst_map *x;
|
||||
|
||||
for (x = get_ovsinst_map(version); x->ofpit >= 0; x++) {
|
||||
if (ovsinst_bitmap & (1u << x->ovsinst)) {
|
||||
ofpit_bitmap |= 1u << x->ofpit;
|
||||
}
|
||||
}
|
||||
return htonl(ofpit_bitmap);
|
||||
}
|
||||
|
||||
/* Converts 'ofpit_bitmap', a bitmap of instructions from an OpenFlow message
|
||||
* with the given 'version' (OFP11_VERSION or later) into a bitmap whose bits
|
||||
* correspond to OVSINST_* values, and returns the result. */
|
||||
uint32_t
|
||||
ovsinst_bitmap_from_openflow(ovs_be32 ofpit_bitmap_, enum ofp_version version)
|
||||
{
|
||||
uint32_t ofpit_bitmap = ntohl(ofpit_bitmap_);
|
||||
uint32_t ovsinst_bitmap = 0;
|
||||
const struct ovsinst_map *x;
|
||||
|
||||
for (x = get_ovsinst_map(version); x->ofpit >= 0; x++) {
|
||||
if (ofpit_bitmap & (1u << x->ofpit)) {
|
||||
ovsinst_bitmap |= 1u << x->ovsinst;
|
||||
}
|
||||
}
|
||||
return ovsinst_bitmap;
|
||||
}
|
||||
|
||||
static inline struct ofp11_instruction *
|
||||
instruction_next(const struct ofp11_instruction *inst)
|
||||
{
|
||||
|
Reference in New Issue
Block a user