Skip to content

Commit

Permalink
ofproto: Break apart into generic and hardware-specific parts.
Browse files Browse the repository at this point in the history
In addition to the changes to ofproto, this commit changes all of the
instances of "struct flow" in the tree so that the "in_port" member is an
OpenFlow port number.  Previously, this member was an OpenFlow port number
in some cases and an ODP port number in other cases.
  • Loading branch information
blp committed May 11, 2011
1 parent f79e673 commit abe529a
Show file tree
Hide file tree
Showing 20 changed files with 5,267 additions and 3,911 deletions.
340 changes: 180 additions & 160 deletions PORTING

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions lib/classifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ cls_rule_set_tun_id_masked(struct cls_rule *rule,
}

void
cls_rule_set_in_port(struct cls_rule *rule, uint16_t odp_port)
cls_rule_set_in_port(struct cls_rule *rule, uint16_t ofp_port)
{
rule->wc.wildcards &= ~FWW_IN_PORT;
rule->flow.in_port = odp_port;
rule->flow.in_port = ofp_port;
}

void
Expand Down Expand Up @@ -506,8 +506,7 @@ cls_rule_format(const struct cls_rule *rule, struct ds *s)
break;
}
if (!(w & FWW_IN_PORT)) {
ds_put_format(s, "in_port=%"PRIu16",",
odp_port_to_ofp_port(f->in_port));
ds_put_format(s, "in_port=%"PRIu16",", f->in_port);
}
if (wc->vlan_tci_mask) {
ovs_be16 vid_mask = wc->vlan_tci_mask & htons(VLAN_VID_MASK);
Expand Down
6 changes: 3 additions & 3 deletions lib/flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ parse_icmpv6(struct ofpbuf *b, struct flow *flow)

}

/* Initializes 'flow' members from 'packet', 'tun_id', and 'in_port.
/* Initializes 'flow' members from 'packet', 'tun_id', and 'ofp_in_port'.
* Initializes 'packet' header pointers as follows:
*
* - packet->l2 to the start of the Ethernet header.
Expand All @@ -322,7 +322,7 @@ parse_icmpv6(struct ofpbuf *b, struct flow *flow)
* present and has a correct length, and otherwise NULL.
*/
int
flow_extract(struct ofpbuf *packet, ovs_be64 tun_id, uint16_t in_port,
flow_extract(struct ofpbuf *packet, ovs_be64 tun_id, uint16_t ofp_in_port,
struct flow *flow)
{
struct ofpbuf b = *packet;
Expand All @@ -333,7 +333,7 @@ flow_extract(struct ofpbuf *packet, ovs_be64 tun_id, uint16_t in_port,

memset(flow, 0, sizeof *flow);
flow->tun_id = tun_id;
flow->in_port = in_port;
flow->in_port = ofp_in_port;

packet->l2 = b.data;
packet->l3 = NULL;
Expand Down
2 changes: 1 addition & 1 deletion lib/flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct flow {
uint32_t regs[FLOW_N_REGS]; /* Registers. */
ovs_be32 nw_src; /* IPv4 source address. */
ovs_be32 nw_dst; /* IPv4 destination address. */
uint16_t in_port; /* Input switch port. */
uint16_t in_port; /* OpenFlow port number of input port. */
ovs_be16 vlan_tci; /* If 802.1Q, TCI | VLAN_CFI; otherwise 0. */
ovs_be16 dl_type; /* Ethernet frame type. */
ovs_be16 tp_src; /* TCP/UDP source port. */
Expand Down
8 changes: 1 addition & 7 deletions lib/nx-match.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ parse_nxm_entry(struct cls_rule *rule, const struct nxm_field *f,
/* Metadata. */
case NFI_NXM_OF_IN_PORT:
flow->in_port = ntohs(get_unaligned_be16(value));
if (flow->in_port == OFPP_LOCAL) {
flow->in_port = ODPP_LOCAL;
}
return 0;

/* Ethernet header. */
Expand Down Expand Up @@ -739,9 +736,6 @@ nx_put_match(struct ofpbuf *b, const struct cls_rule *cr)
/* Metadata. */
if (!(wc & FWW_IN_PORT)) {
uint16_t in_port = flow->in_port;
if (in_port == ODPP_LOCAL) {
in_port = OFPP_LOCAL;
}
nxm_put_16(b, NXM_OF_IN_PORT, htons(in_port));
}

Expand Down Expand Up @@ -1272,7 +1266,7 @@ nxm_read_field(const struct nxm_field *src, const struct flow *flow)
{
switch (src->index) {
case NFI_NXM_OF_IN_PORT:
return flow->in_port == ODPP_LOCAL ? OFPP_LOCAL : flow->in_port;
return flow->in_port;

case NFI_NXM_OF_ETH_DST:
return eth_addr_to_uint64(flow->dl_dst);
Expand Down
5 changes: 3 additions & 2 deletions lib/odp-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ odp_flow_key_from_flow(struct ofpbuf *buf, const struct flow *flow)
nl_msg_put_be64(buf, ODP_KEY_ATTR_TUN_ID, flow->tun_id);
}

nl_msg_put_u32(buf, ODP_KEY_ATTR_IN_PORT, flow->in_port);
nl_msg_put_u32(buf, ODP_KEY_ATTR_IN_PORT,
ofp_port_to_odp_port(flow->in_port));

eth_key = nl_msg_put_unspec_uninit(buf, ODP_KEY_ATTR_ETHERNET,
sizeof *eth_key);
Expand Down Expand Up @@ -551,7 +552,7 @@ odp_flow_key_to_flow(const struct nlattr *key, size_t key_len,
if (nl_attr_get_u32(nla) >= UINT16_MAX) {
return EINVAL;
}
flow->in_port = nl_attr_get_u32(nla);
flow->in_port = odp_port_to_ofp_port(nl_attr_get_u32(nla));
break;

case TRANSITION(ODP_KEY_ATTR_IN_PORT, ODP_KEY_ATTR_ETHERNET):
Expand Down
3 changes: 0 additions & 3 deletions lib/ofp-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,6 @@ parse_field_value(struct cls_rule *rule, enum field_index index,
if (!parse_port_name(value, &port_no)) {
port_no = atoi(value);
}
if (port_no == OFPP_LOCAL) {
port_no = ODPP_LOCAL;
}
cls_rule_set_in_port(rule, port_no);
break;

Expand Down
6 changes: 2 additions & 4 deletions lib/ofp-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ ofputil_cls_rule_from_match(const struct ofp_match *match,
/* Initialize most of rule->flow. */
rule->flow.nw_src = match->nw_src;
rule->flow.nw_dst = match->nw_dst;
rule->flow.in_port = (match->in_port == htons(OFPP_LOCAL) ? ODPP_LOCAL
: ntohs(match->in_port));
rule->flow.in_port = ntohs(match->in_port);
rule->flow.dl_type = ofputil_dl_type_from_openflow(match->dl_type);
rule->flow.tp_src = match->tp_src;
rule->flow.tp_dst = match->tp_dst;
Expand Down Expand Up @@ -272,8 +271,7 @@ ofputil_cls_rule_to_match(const struct cls_rule *rule,

/* Compose most of the match structure. */
match->wildcards = htonl(ofpfw);
match->in_port = htons(rule->flow.in_port == ODPP_LOCAL ? OFPP_LOCAL
: rule->flow.in_port);
match->in_port = htons(rule->flow.in_port);
memcpy(match->dl_src, rule->flow.dl_src, ETH_ADDR_LEN);
memcpy(match->dl_dst, rule->flow.dl_dst, ETH_ADDR_LEN);
match->dl_type = ofputil_dl_type_to_openflow(rule->flow.dl_type);
Expand Down
1 change: 1 addition & 0 deletions ofproto/automake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ofproto_libofproto_a_SOURCES = \
ofproto/netflow.h \
ofproto/ofproto.c \
ofproto/ofproto.h \
ofproto/ofproto-dpif.c \
ofproto/ofproto-sflow.c \
ofproto/ofproto-sflow.h \
ofproto/pktbuf.c \
Expand Down
2 changes: 1 addition & 1 deletion ofproto/connmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ schedule_packet_in(struct ofconn *ofconn, const struct dpif_upcall *upcall,

/* Figure out the easy parts. */
pin.packet = upcall->packet;
pin.in_port = odp_port_to_ofp_port(flow->in_port);
pin.in_port = flow->in_port;
pin.reason = upcall->type == DPIF_UC_MISS ? OFPR_NO_MATCH : OFPR_ACTION;

/* Get OpenFlow buffer_id. */
Expand Down
Loading

0 comments on commit abe529a

Please sign in to comment.