Skip to content

Commit

Permalink
ofp-parse: Add support for vlan_tci field.
Browse files Browse the repository at this point in the history
Until now, the flow parser has supported dl_vlan and dl_vlan_pcp but not
the fully maskable vlan_tci that NXM allows.  This adds that support.
  • Loading branch information
blp committed Jun 14, 2011
1 parent c168dcc commit 33d8c6b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/ofp-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,35 @@ str_to_tun_id(const char *str, ovs_be64 *tun_idp, ovs_be64 *maskp)
ovs_fatal(0, "%s: bad syntax for tunnel id", str);
}

static void
str_to_vlan_tci(const char *str, ovs_be16 *vlan_tcip, ovs_be16 *maskp)
{
uint16_t vlan_tci, mask;
char *tail;

errno = 0;
vlan_tci = strtol(str, &tail, 0);
if (errno || (*tail != '\0' && *tail != '/')) {
goto error;
}

if (*tail == '/') {
mask = strtol(tail + 1, &tail, 0);
if (errno || *tail != '\0') {
goto error;
}
} else {
mask = UINT16_MAX;
}

*vlan_tcip = htons(vlan_tci);
*maskp = htons(mask);
return;

error:
ovs_fatal(0, "%s: bad syntax for vlan_tci", str);
}

static void
str_to_ipv6(const char *str_, struct in6_addr *addrp, struct in6_addr *maskp)
{
Expand Down Expand Up @@ -552,6 +581,7 @@ parse_protocol(const char *name, const struct protocol **p_out)
FIELD(F_IN_PORT, "in_port", FWW_IN_PORT) \
FIELD(F_DL_VLAN, "dl_vlan", 0) \
FIELD(F_DL_VLAN_PCP, "dl_vlan_pcp", 0) \
FIELD(F_VLAN_TCI, "vlan_tci", 0) \
FIELD(F_DL_SRC, "dl_src", FWW_DL_SRC) \
FIELD(F_DL_DST, "dl_dst", FWW_DL_DST | FWW_ETH_MCAST) \
FIELD(F_DL_TYPE, "dl_type", FWW_DL_TYPE) \
Expand Down Expand Up @@ -611,6 +641,7 @@ parse_field_value(struct cls_rule *rule, enum field_index index,
uint8_t mac[ETH_ADDR_LEN], mac_mask[ETH_ADDR_LEN];
ovs_be64 tun_id, tun_mask;
ovs_be32 ip, mask;
ovs_be16 tci, tci_mask;
struct in6_addr ipv6, ipv6_mask;
uint16_t port_no;

Expand All @@ -635,6 +666,11 @@ parse_field_value(struct cls_rule *rule, enum field_index index,
cls_rule_set_dl_vlan_pcp(rule, str_to_u32(value));
break;

case F_VLAN_TCI:
str_to_vlan_tci(value, &tci, &tci_mask);
cls_rule_set_dl_tci_masked(rule, tci, tci_mask);
break;

case F_DL_SRC:
str_to_mac(value, mac);
cls_rule_set_dl_src(rule, mac);
Expand Down
2 changes: 2 additions & 0 deletions tests/ovs-ofctl.at
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ tun_id=0x1234,cookie=0x5678,actions=flood
actions=drop
reg0=123,actions=move:NXM_NX_REG0[0..5]->NXM_NX_REG1[26..31],load:55->NXM_NX_REG2[0..31],move:NXM_NX_REG0[0..31]->NXM_NX_TUN_ID[0..31],move:NXM_NX_REG0[0..15]->NXM_OF_VLAN_TCI[]
actions=autopath(5,NXM_NX_REG0[])
vlan_tci=0x1123/0x1fff,actions=drop
]])
AT_CHECK([ovs-ofctl -F nxm -mmm parse-flows flows.txt], [0], [stdout])
AT_CHECK([[sed 's/ (xid=0x[0-9a-fA-F]*)//' stdout]], [0],
Expand All @@ -141,6 +142,7 @@ NXT_FLOW_MOD: ADD NXM_NX_TUN_ID(0000000000001234) cookie:0x5678 actions=FLOOD
NXT_FLOW_MOD: ADD <any> actions=drop
NXT_FLOW_MOD: ADD NXM_NX_REG0(0000007b) actions=move:NXM_NX_REG0[0..5]->NXM_NX_REG1[26..31],load:0x37->NXM_NX_REG2[],move:NXM_NX_REG0[]->NXM_NX_TUN_ID[0..31],move:NXM_NX_REG0[0..15]->NXM_OF_VLAN_TCI[]
NXT_FLOW_MOD: ADD <any> actions=autopath(5,NXM_NX_REG0[])
NXT_FLOW_MOD: ADD NXM_OF_VLAN_TCI_W(1123/1fff) actions=drop
]])
AT_CLEANUP

Expand Down
37 changes: 37 additions & 0 deletions utilities/ovs-ofctl.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,43 @@ Extended Match) extension to OpenFlow. When one of these is specified,
extension. If the switch does not support NXM, then \fBovs\-ofctl\fR
will report a fatal error.
.
.IP \fBvlan_tci=\fItci\fR[\fB/\fImask\fR]
Matches modified VLAN TCI \fItci\fR. If \fImask\fR is omitted,
\fItci\fR is the exact VLAN TCI to match; if \fImask\fR is specified,
then a 1-bit in \fItci\fR indicates that the corresponding bit in
\fItci\fR must match exactly, and a 0-bit wildcards that bit. Both
\fItci\fR and \fImask\fR are 16-bit values that are decimal by
default; use a \fB0x\fR prefix to specify them in hexadecimal.
.
.IP
The value that \fBvlan_tci\fR matches against is 0 for a packet that
has no 802.1Q header. Otherwise, it is the TCI value from the 802.1Q
header with the CFI bit (with value \fB0x1000\fR) forced to 1.
.IP
Examples:
.RS
.IP \fBvlan_tci=0\fR
Match only packets without an 802.1Q header.
.IP \fBvlan_tci=0xf123\fR
Match packets tagged with priority 7 in VLAN 0x123.
.IP \fBvlan_tci=0x1123/0x1fff\fR
Match packets tagged with VLAN 0x123 (and any priority).
.IP \fBvlan_tci=0x5000/0xf000\fR
Match packets tagged with priority 2 (in any VLAN).
.IP \fBvlan_tci=0/0xfff\fR
Match packets with no 802.1Q header or tagged with VLAN 0 (and any
priority).
.IP \fBvlan_tci=0x5000/0xe000\fR
Match packets with no 802.1Q header or tagged with priority 2 (in any
VLAN).
.IP \fBvlan_tci=0/0xefff\fR
Match packets with no 802.1Q header or tagged with VLAN 0 and priority
0.
.RE
.IP
Some of these matching possibilities can also be achieved with
\fBdl_vlan\fR and \fBdl_vlan_pcp\fR.
.
.IP \fBarp_sha=\fIxx\fB:\fIxx\fB:\fIxx\fB:\fIxx\fB:\fIxx\fB:\fIxx\fR
.IQ \fBarp_tha=\fIxx\fB:\fIxx\fB:\fIxx\fB:\fIxx\fB:\fIxx\fB:\fIxx\fR
When \fBdl_type\fR specifies ARP, \fBarp_sha\fR and \fBarp_tha\fR match
Expand Down

0 comments on commit 33d8c6b

Please sign in to comment.