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

openflow-1.0: Rename ofp_match to ofp10_match, OFPFW_* to OFPFW10_*.

This better fits our general policy of adding a version number suffix
to structures and constants whose values differ from one OpenFlow
version to the next.

Reviewed-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
Ben Pfaff
2012-05-21 21:51:03 -07:00
parent 7c00ccb674
commit eec25dc1ae
14 changed files with 145 additions and 133 deletions

View File

@@ -72,7 +72,7 @@ ofputil_netmask_to_wcbits(ovs_be32 netmask)
return 32 - ip_count_cidr_bits(netmask);
}
/* A list of the FWW_* and OFPFW_ bits that have the same value, meaning, and
/* A list of the FWW_* and OFPFW10_ bits that have the same value, meaning, and
* name. */
#define WC_INVARIANT_LIST \
WC_INVARIANT_BIT(IN_PORT) \
@@ -81,7 +81,7 @@ ofputil_netmask_to_wcbits(ovs_be32 netmask)
/* Verify that all of the invariant bits (as defined on WC_INVARIANT_LIST)
* actually have the same names and values. */
#define WC_INVARIANT_BIT(NAME) BUILD_ASSERT_DECL(FWW_##NAME == OFPFW_##NAME);
#define WC_INVARIANT_BIT(NAME) BUILD_ASSERT_DECL(FWW_##NAME == OFPFW10_##NAME);
WC_INVARIANT_LIST
#undef WC_INVARIANT_BIT
@@ -93,11 +93,12 @@ static const flow_wildcards_t WC_INVARIANTS = 0
#undef WC_INVARIANT_BIT
;
/* Converts the wildcard in 'ofpfw' into a flow_wildcards in 'wc' for use in
* struct cls_rule. It is the caller's responsibility to handle the special
* case where the flow match's dl_vlan is set to OFP_VLAN_NONE. */
/* Converts the OpenFlow 1.0 wildcards in 'ofpfw' (OFPFW10_*) into a
* flow_wildcards in 'wc' for use in struct cls_rule. It is the caller's
* responsibility to handle the special case where the flow match's dl_vlan is
* set to OFP_VLAN_NONE. */
void
ofputil_wildcard_from_openflow(uint32_t ofpfw, struct flow_wildcards *wc)
ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *wc)
{
BUILD_ASSERT_DECL(FLOW_WC_SEQ == 11);
@@ -105,53 +106,53 @@ ofputil_wildcard_from_openflow(uint32_t ofpfw, struct flow_wildcards *wc)
flow_wildcards_init_catchall(wc);
wc->wildcards = (OVS_FORCE flow_wildcards_t) ofpfw & WC_INVARIANTS;
/* Wildcard fields that aren't defined by ofp_match or tun_id. */
/* Wildcard fields that aren't defined by ofp10_match or tun_id. */
wc->wildcards |= (FWW_ARP_SHA | FWW_ARP_THA | FWW_NW_ECN | FWW_NW_TTL
| FWW_IPV6_LABEL);
if (ofpfw & OFPFW_NW_TOS) {
if (ofpfw & OFPFW10_NW_TOS) {
/* OpenFlow 1.0 defines a TOS wildcard, but it's much later in
* the enum than we can use. */
wc->wildcards |= FWW_NW_DSCP;
}
wc->nw_src_mask = ofputil_wcbits_to_netmask(ofpfw >> OFPFW_NW_SRC_SHIFT);
wc->nw_dst_mask = ofputil_wcbits_to_netmask(ofpfw >> OFPFW_NW_DST_SHIFT);
wc->nw_src_mask = ofputil_wcbits_to_netmask(ofpfw >> OFPFW10_NW_SRC_SHIFT);
wc->nw_dst_mask = ofputil_wcbits_to_netmask(ofpfw >> OFPFW10_NW_DST_SHIFT);
if (!(ofpfw & OFPFW_TP_SRC)) {
if (!(ofpfw & OFPFW10_TP_SRC)) {
wc->tp_src_mask = htons(UINT16_MAX);
}
if (!(ofpfw & OFPFW_TP_DST)) {
if (!(ofpfw & OFPFW10_TP_DST)) {
wc->tp_dst_mask = htons(UINT16_MAX);
}
if (!(ofpfw & OFPFW_DL_SRC)) {
if (!(ofpfw & OFPFW10_DL_SRC)) {
memset(wc->dl_src_mask, 0xff, ETH_ADDR_LEN);
}
if (!(ofpfw & OFPFW_DL_DST)) {
if (!(ofpfw & OFPFW10_DL_DST)) {
memset(wc->dl_dst_mask, 0xff, ETH_ADDR_LEN);
}
/* VLAN TCI mask. */
if (!(ofpfw & OFPFW_DL_VLAN_PCP)) {
if (!(ofpfw & OFPFW10_DL_VLAN_PCP)) {
wc->vlan_tci_mask |= htons(VLAN_PCP_MASK | VLAN_CFI);
}
if (!(ofpfw & OFPFW_DL_VLAN)) {
if (!(ofpfw & OFPFW10_DL_VLAN)) {
wc->vlan_tci_mask |= htons(VLAN_VID_MASK | VLAN_CFI);
}
}
/* Converts the ofp_match in 'match' into a cls_rule in 'rule', with the given
* 'priority'. */
/* Converts the ofp10_match in 'match' into a cls_rule in 'rule', with the
* given 'priority'. */
void
ofputil_cls_rule_from_match(const struct ofp_match *match,
unsigned int priority, struct cls_rule *rule)
ofputil_cls_rule_from_ofp10_match(const struct ofp10_match *match,
unsigned int priority, struct cls_rule *rule)
{
uint32_t ofpfw = ntohl(match->wildcards) & OFPFW_ALL;
uint32_t ofpfw = ntohl(match->wildcards) & OFPFW10_ALL;
/* Initialize rule->priority, rule->wc. */
rule->priority = !ofpfw ? UINT16_MAX : priority;
ofputil_wildcard_from_openflow(ofpfw, &rule->wc);
ofputil_wildcard_from_ofpfw10(ofpfw, &rule->wc);
/* Initialize most of rule->flow. */
rule->flow.nw_src = match->nw_src;
@@ -166,12 +167,12 @@ ofputil_cls_rule_from_match(const struct ofp_match *match,
rule->flow.nw_proto = match->nw_proto;
/* Translate VLANs. */
if (!(ofpfw & OFPFW_DL_VLAN) && match->dl_vlan == htons(OFP_VLAN_NONE)) {
if (!(ofpfw & OFPFW10_DL_VLAN) && match->dl_vlan == htons(OFP_VLAN_NONE)) {
/* Match only packets without 802.1Q header.
*
* When OFPFW_DL_VLAN_PCP is wildcarded, this is obviously correct.
* When OFPFW10_DL_VLAN_PCP is wildcarded, this is obviously correct.
*
* If OFPFW_DL_VLAN_PCP is matched, the flow match is contradictory,
* If OFPFW10_DL_VLAN_PCP is matched, the flow match is contradictory,
* because we can't have a specific PCP without an 802.1Q header.
* However, older versions of OVS treated this as matching packets
* withut an 802.1Q header, so we do here too. */
@@ -190,50 +191,53 @@ ofputil_cls_rule_from_match(const struct ofp_match *match,
cls_rule_zero_wildcarded_fields(rule);
}
/* Convert 'rule' into the OpenFlow match structure 'match'. */
/* Convert 'rule' into the OpenFlow 1.0 match structure 'match'. */
void
ofputil_cls_rule_to_match(const struct cls_rule *rule, struct ofp_match *match)
ofputil_cls_rule_to_ofp10_match(const struct cls_rule *rule,
struct ofp10_match *match)
{
const struct flow_wildcards *wc = &rule->wc;
uint32_t ofpfw;
/* Figure out most OpenFlow wildcards. */
ofpfw = (OVS_FORCE uint32_t) (wc->wildcards & WC_INVARIANTS);
ofpfw |= ofputil_netmask_to_wcbits(wc->nw_src_mask) << OFPFW_NW_SRC_SHIFT;
ofpfw |= ofputil_netmask_to_wcbits(wc->nw_dst_mask) << OFPFW_NW_DST_SHIFT;
ofpfw |= (ofputil_netmask_to_wcbits(wc->nw_src_mask)
<< OFPFW10_NW_SRC_SHIFT);
ofpfw |= (ofputil_netmask_to_wcbits(wc->nw_dst_mask)
<< OFPFW10_NW_DST_SHIFT);
if (wc->wildcards & FWW_NW_DSCP) {
ofpfw |= OFPFW_NW_TOS;
ofpfw |= OFPFW10_NW_TOS;
}
if (!wc->tp_src_mask) {
ofpfw |= OFPFW_TP_SRC;
ofpfw |= OFPFW10_TP_SRC;
}
if (!wc->tp_dst_mask) {
ofpfw |= OFPFW_TP_DST;
ofpfw |= OFPFW10_TP_DST;
}
if (eth_addr_is_zero(wc->dl_src_mask)) {
ofpfw |= OFPFW_DL_SRC;
ofpfw |= OFPFW10_DL_SRC;
}
if (eth_addr_is_zero(wc->dl_dst_mask)) {
ofpfw |= OFPFW_DL_DST;
ofpfw |= OFPFW10_DL_DST;
}
/* Translate VLANs. */
match->dl_vlan = htons(0);
match->dl_vlan_pcp = 0;
if (rule->wc.vlan_tci_mask == htons(0)) {
ofpfw |= OFPFW_DL_VLAN | OFPFW_DL_VLAN_PCP;
ofpfw |= OFPFW10_DL_VLAN | OFPFW10_DL_VLAN_PCP;
} else if (rule->wc.vlan_tci_mask & htons(VLAN_CFI)
&& !(rule->flow.vlan_tci & htons(VLAN_CFI))) {
match->dl_vlan = htons(OFP_VLAN_NONE);
} else {
if (!(rule->wc.vlan_tci_mask & htons(VLAN_VID_MASK))) {
ofpfw |= OFPFW_DL_VLAN;
ofpfw |= OFPFW10_DL_VLAN;
} else {
match->dl_vlan = htons(vlan_tci_to_vid(rule->flow.vlan_tci));
}
if (!(rule->wc.vlan_tci_mask & htons(VLAN_PCP_MASK))) {
ofpfw |= OFPFW_DL_VLAN_PCP;
ofpfw |= OFPFW10_DL_VLAN_PCP;
} else {
match->dl_vlan_pcp = vlan_tci_to_pcp(rule->flow.vlan_tci);
}
@@ -256,7 +260,8 @@ ofputil_cls_rule_to_match(const struct cls_rule *rule, struct ofp_match *match)
}
/* Given a 'dl_type' value in the format used in struct flow, returns the
* corresponding 'dl_type' value for use in an OpenFlow ofp_match structure. */
* corresponding 'dl_type' value for use in an ofp10_match or ofp11_match
* structure. */
ovs_be16
ofputil_dl_type_to_openflow(ovs_be16 flow_dl_type)
{
@@ -265,7 +270,7 @@ ofputil_dl_type_to_openflow(ovs_be16 flow_dl_type)
: flow_dl_type);
}
/* Given a 'dl_type' value in the format used in an OpenFlow ofp_match
/* Given a 'dl_type' value in the format used in an ofp10_match or ofp11_match
* structure, returns the corresponding 'dl_type' value for use in struct
* flow. */
ovs_be16
@@ -1402,12 +1407,12 @@ ofputil_decode_flow_mod(struct ofputil_flow_mod *fm,
* ofputil_normalize_rule() can put wildcards where the original flow
* didn't have them. */
priority = ntohs(ofm->priority);
if (!(ofm->match.wildcards & htonl(OFPFW_ALL))) {
if (!(ofm->match.wildcards & htonl(OFPFW10_ALL))) {
priority = UINT16_MAX;
}
/* Translate the rule. */
ofputil_cls_rule_from_match(&ofm->match, priority, &fm->cr);
ofputil_cls_rule_from_ofp10_match(&ofm->match, priority, &fm->cr);
ofputil_normalize_rule(&fm->cr);
/* Translate the message. */
@@ -1487,7 +1492,7 @@ ofputil_encode_flow_mod(const struct ofputil_flow_mod *fm,
case OFPUTIL_P_OF10_TID:
msg = ofpbuf_new(sizeof *ofm + actions_len);
ofm = put_openflow(sizeof *ofm, OFPT10_FLOW_MOD, msg);
ofputil_cls_rule_to_match(&fm->cr, &ofm->match);
ofputil_cls_rule_to_ofp10_match(&fm->cr, &ofm->match);
ofm->cookie = fm->new_cookie;
ofm->command = htons(command);
ofm->idle_timeout = htons(fm->idle_timeout);
@@ -1565,7 +1570,7 @@ ofputil_decode_ofpst_flow_request(struct ofputil_flow_stats_request *fsr,
(const struct ofp_flow_stats_request *) oh;
fsr->aggregate = aggregate;
ofputil_cls_rule_from_match(&ofsr->match, 0, &fsr->match);
ofputil_cls_rule_from_ofp10_match(&ofsr->match, 0, &fsr->match);
fsr->out_port = ntohs(ofsr->out_port);
fsr->table_id = ofsr->table_id;
fsr->cookie = fsr->cookie_mask = htonll(0);
@@ -1652,7 +1657,7 @@ ofputil_encode_flow_stats_request(const struct ofputil_flow_stats_request *fsr,
type = fsr->aggregate ? OFPST_AGGREGATE : OFPST_FLOW;
ofsr = ofputil_make_stats_request(sizeof *ofsr, type, 0, &msg);
ofputil_cls_rule_to_match(&fsr->match, &ofsr->match);
ofputil_cls_rule_to_ofp10_match(&fsr->match, &ofsr->match);
ofsr->table_id = fsr->table_id;
ofsr->out_port = htons(fsr->out_port);
break;
@@ -1763,8 +1768,8 @@ ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *fs,
}
fs->cookie = get_32aligned_be64(&ofs->cookie);
ofputil_cls_rule_from_match(&ofs->match, ntohs(ofs->priority),
&fs->rule);
ofputil_cls_rule_from_ofp10_match(&ofs->match, ntohs(ofs->priority),
&fs->rule);
fs->table_id = ofs->table_id;
fs->duration_sec = ntohl(ofs->duration_sec);
fs->duration_nsec = ntohl(ofs->duration_nsec);
@@ -1857,7 +1862,7 @@ ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *fs,
ofs->length = htons(len);
ofs->table_id = fs->table_id;
ofs->pad = 0;
ofputil_cls_rule_to_match(&fs->rule, &ofs->match);
ofputil_cls_rule_to_ofp10_match(&fs->rule, &ofs->match);
ofs->duration_sec = htonl(fs->duration_sec);
ofs->duration_nsec = htonl(fs->duration_nsec);
ofs->priority = htons(fs->rule.priority);
@@ -1953,8 +1958,8 @@ ofputil_decode_flow_removed(struct ofputil_flow_removed *fr,
const struct ofp_flow_removed *ofr;
ofr = (const struct ofp_flow_removed *) oh;
ofputil_cls_rule_from_match(&ofr->match, ntohs(ofr->priority),
&fr->rule);
ofputil_cls_rule_from_ofp10_match(&ofr->match, ntohs(ofr->priority),
&fr->rule);
fr->cookie = ofr->cookie;
fr->reason = ofr->reason;
fr->duration_sec = ntohl(ofr->duration_sec);
@@ -2009,7 +2014,7 @@ ofputil_encode_flow_removed(const struct ofputil_flow_removed *fr,
ofr = make_openflow_xid(sizeof *ofr, OFPT_FLOW_REMOVED, htonl(0),
&msg);
ofputil_cls_rule_to_match(&fr->rule, &ofr->match);
ofputil_cls_rule_to_ofp10_match(&fr->rule, &ofr->match);
ofr->cookie = fr->cookie;
ofr->priority = htons(fr->rule.priority);
ofr->reason = fr->reason;
@@ -3127,7 +3132,7 @@ make_flow_mod(uint16_t command, const struct cls_rule *rule,
ofm->header.length = htons(size);
ofm->cookie = 0;
ofm->priority = htons(MIN(rule->priority, UINT16_MAX));
ofputil_cls_rule_to_match(rule, &ofm->match);
ofputil_cls_rule_to_ofp10_match(rule, &ofm->match);
ofm->command = htons(command);
return out;
}