From 00b1c62fe8dc671584841c916040f2effb901552 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 23 Nov 2010 13:33:48 -0800 Subject: [PATCH] ofp-parse: Add support for registers. This updates the ovs-ofctl manpage even though ovs-ofctl doesn't really support registers yet. --- lib/ofp-parse.c | 25 +++++++++++++++++++++++++ utilities/ovs-ofctl.8.in | 17 +++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c index 49408454a..e800edbcf 100644 --- a/lib/ofp-parse.c +++ b/lib/ofp-parse.c @@ -18,6 +18,7 @@ #include "ofp-parse.h" +#include #include #include @@ -515,6 +516,24 @@ parse_field_value(struct cls_rule *rule, enum field_index index, } } +static void +parse_reg_value(struct cls_rule *rule, int reg_idx, const char *value) +{ + uint32_t reg_value, reg_mask; + + if (!strcmp(value, "ANY") || !strcmp(value, "*")) { + cls_rule_set_reg_masked(rule, reg_idx, 0, 0); + } else if (sscanf(value, "%"SCNi32"/%"SCNi32, + ®_value, ®_mask) == 2) { + cls_rule_set_reg_masked(rule, reg_idx, reg_value, reg_mask); + } else if (sscanf(value, "%"SCNi32, ®_value)) { + cls_rule_set_reg(rule, reg_idx, reg_value); + } else { + ovs_fatal(0, "register fields must take the form " + "or /"); + } +} + /* Convert 'string' (as described in the Flow Syntax section of the ovs-ofctl * man page) into 'pf'. If 'actions' is specified, an action must be in * 'string' and may be expanded or reallocated. */ @@ -595,6 +614,12 @@ parse_ofp_str(struct parsed_flow *pf, struct ofpbuf *actions, char *string) } else { parse_field_value(&pf->rule, f->index, value); } + } else if (!strncmp(name, "reg", 3) && isdigit(name[3])) { + unsigned int reg_idx = atoi(name + 3); + if (reg_idx >= FLOW_N_REGS) { + ovs_fatal(0, "only %d registers supported", FLOW_N_REGS); + } + parse_reg_value(&pf->rule, reg_idx, value); } else { ovs_fatal(0, "unknown keyword %s", name); } diff --git a/utilities/ovs-ofctl.8.in b/utilities/ovs-ofctl.8.in index 8cd5ef004..eb20fa761 100644 --- a/utilities/ovs-ofctl.8.in +++ b/utilities/ovs-ofctl.8.in @@ -357,6 +357,23 @@ When \fBtun_id\fR is specified, \fBovs\-ofctl\fR will automatically attempt to negotiate use of one of these extensions, preferring NXM. If the switch does not support either extension, then \fBovs\-ofctl\fR will report a fatal error. +.IP "\fBreg\fIidx\fB=\fIvalue\fR[\fB/\fImask\fR]" +Matches \fIvalue\fR either exactly or with optional \fImask\fR in +register number \fIidx\fR. The valid range of \fIidx\fR depends on +the switch. \fIvalue\fR and \fImask\fR are 32-bit integers, by +default in decimal (use a \fB0x\fR prefix to specify hexadecimal). +Arbitrary \fImask\fR values are allowed: a 1-bit in \fImask\fR +indicates that the corresponding bit in \fIvalue\fR must match +exactly, and a 0-bit wildcards that bit. +.IP +When a packet enters an OpenFlow switch, all of the registers are set +to 0. Only explicit Nicira extension actions change register values. +.IP +Register matches require support for the NXM (Nicira Extended Match) +extension to OpenFlow. When a register match is specified, +\fBovs\-ofctl\fR will automatically attempt to negotiate use of this +extension. If the switch does not support NXM, then \fBovs\-ofctl\fR +will report a fatal error. . .PP The following shorthand notations are also available: -- 2.43.0