Skip to content

Commit

Permalink
metaflow: Allow fields to be marked as variable length.
Browse files Browse the repository at this point in the history
Until now, all fields that OVS can match against have been fixed
size (variable length headers can be skipped during parsing but
the match is fixed). However, Geneve options can vary in size
so we must not require the size of these fields to be known
at compile time.

This allows data types to be annotated with not only their size
but whether the field can be smaller than that. The following
patches will change OpenFlow parsing based on that.

Signed-off-by: Jesse Gross <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
jessegross committed Jun 25, 2015
1 parent 3ee6026 commit f047e84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
23 changes: 15 additions & 8 deletions build-aux/extract-ofp-fields
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ VERSION = {"1.0": 0x01,
"1.4": 0x05,
"1.5": 0x06}

TYPES = {"u8": 1,
"be16": 2,
"be32": 4,
"MAC": 6,
"be64": 8,
"IPv6": 16}
TYPES = {"u8": (1, False),
"be16": (2, False),
"be32": (4, False),
"MAC": (6, False),
"be64": (8, False),
"IPv6": (16, False)}

FORMATTING = {"decimal": ("MFS_DECIMAL", 1, 8),
"hexadecimal": ("MFS_HEXADECIMAL", 1, 127),
Expand Down Expand Up @@ -234,14 +234,16 @@ def parse_field(mff, comment):
type_ = m.group(1)
if type_ not in TYPES:
fatal("%s: unknown type %s" % (mff, d['Type']))
f['n_bytes'] = TYPES[type_]

f['n_bytes'] = TYPES[type_][0]
if m.group(2):
f['n_bits'] = int(m.group(2))
if f['n_bits'] > f['n_bytes'] * 8:
fatal("%s: more bits (%d) than field size (%d)"
% (mff, f['n_bits'], 8 * f['n_bytes']))
else:
f['n_bits'] = 8 * f['n_bytes']
f['variable'] = TYPES[type_][1]

if d['Maskable'] == 'no':
f['mask'] = 'MFM_NONE'
Expand Down Expand Up @@ -307,7 +309,12 @@ def make_meta_flow(fields):
output += [" \"%s\", \"%s\"," % (f['name'], f['extra_name'])]
else:
output += [" \"%s\", NULL," % f['name']]
output += [" %d, %d," % (f['n_bytes'], f['n_bits'])]

if f['variable']:
variable = 'true'
else:
variable = 'false'
output += [" %d, %d, %s," % (f['n_bytes'], f['n_bits'], variable)]

if f['writable']:
rw = 'true'
Expand Down
1 change: 1 addition & 0 deletions lib/meta-flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,7 @@ struct mf_field {
*/
unsigned int n_bytes; /* Width of the field in bytes. */
unsigned int n_bits; /* Number of significant bits in field. */
bool variable_len; /* Length is variable, if so width is max. */

/* Properties. */
enum mf_maskable maskable;
Expand Down

0 comments on commit f047e84

Please sign in to comment.