Skip to content

Commit

Permalink
ofpbuf: Simplify ofpbuf API.
Browse files Browse the repository at this point in the history
ofpbuf was complicated due to its wide usage across all
layers of OVS, Now we have introduced independent dp_packet
which can be used for datapath packet, we can simplify ofpbuf.
Following patch removes DPDK mbuf and access API of ofpbuf
members.

Signed-off-by: Pravin B Shelar <[email protected]>
Acked-by: Jarno Rajahalme <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
Pravin B Shelar committed Mar 3, 2015
1 parent cf62fa4 commit 6fd6ed7
Show file tree
Hide file tree
Showing 42 changed files with 705 additions and 1,058 deletions.
2 changes: 1 addition & 1 deletion lib/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ bundle_parse__(const char *s, char **save_ptr,
}
ofpbuf_put(ofpacts, &slave_port, sizeof slave_port);

bundle = ofpacts->frame;
bundle = ofpacts->header;
bundle->n_slaves++;
}
ofpact_update_len(ofpacts, &bundle->ofpact);
Expand Down
41 changes: 18 additions & 23 deletions lib/dpctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,10 +933,10 @@ dpctl_put_flow(int argc, const char *argv[], enum dpif_flow_put_flags flags,
FOR_EACH_CORE_ON_NUMA (iter, dump) {
if (ovs_numa_core_is_pinned(iter->core_id)) {
error = dpif_flow_put(dpif, flags,
ofpbuf_data(&key), ofpbuf_size(&key),
ofpbuf_size(&mask) == 0 ? NULL : ofpbuf_data(&mask),
ofpbuf_size(&mask), ofpbuf_data(&actions),
ofpbuf_size(&actions), ufid_present ? &ufid : NULL,
key.data, key.size,
mask.size == 0 ? NULL : mask.data,
mask.size, actions.data,
actions.size, ufid_present ? &ufid : NULL,
iter->core_id, dpctl_p->print_statistics ? &stats : NULL);
}
}
Expand All @@ -946,10 +946,10 @@ dpctl_put_flow(int argc, const char *argv[], enum dpif_flow_put_flags flags,
}
} else {
error = dpif_flow_put(dpif, flags,
ofpbuf_data(&key), ofpbuf_size(&key),
ofpbuf_size(&mask) == 0 ? NULL : ofpbuf_data(&mask),
ofpbuf_size(&mask), ofpbuf_data(&actions),
ofpbuf_size(&actions), ufid_present ? &ufid : NULL,
key.data, key.size,
mask.size == 0 ? NULL : mask.data,
mask.size, actions.data,
actions.size, ufid_present ? &ufid : NULL,
PMD_ID_NULL, dpctl_p->print_statistics ? &stats : NULL);
}
if (error) {
Expand Down Expand Up @@ -1123,8 +1123,8 @@ dpctl_del_flow(int argc, const char *argv[], struct dpctl_params *dpctl_p)

FOR_EACH_CORE_ON_NUMA (iter, dump) {
if (ovs_numa_core_is_pinned(iter->core_id)) {
error = dpif_flow_del(dpif, ofpbuf_data(&key),
ofpbuf_size(&key), ufid_present ? &ufid : NULL,
error = dpif_flow_del(dpif, key.data,
key.size, ufid_present ? &ufid : NULL,
iter->core_id, dpctl_p->print_statistics ? &stats : NULL);
}
}
Expand All @@ -1133,7 +1133,7 @@ dpctl_del_flow(int argc, const char *argv[], struct dpctl_params *dpctl_p)
error = EINVAL;
}
} else {
error = dpif_flow_del(dpif, ofpbuf_data(&key), ofpbuf_size(&key),
error = dpif_flow_del(dpif, key.data, key.size,
ufid_present ? &ufid : NULL, PMD_ID_NULL,
dpctl_p->print_statistics ? &stats : NULL);
}
Expand Down Expand Up @@ -1246,7 +1246,7 @@ dpctl_parse_actions(int argc, const char *argv[], struct dpctl_params* dpctl_p)
}

ds_init(&s);
format_odp_actions(&s, ofpbuf_data(&actions), ofpbuf_size(&actions));
format_odp_actions(&s, actions.data, actions.size);
dpctl_print(dpctl_p, "%s\n", ds_cstr(&s));
ds_destroy(&s);

Expand Down Expand Up @@ -1390,12 +1390,11 @@ dpctl_normalize_actions(int argc, const char *argv[],
}

ds_clear(&s);
odp_flow_format(ofpbuf_data(&keybuf), ofpbuf_size(&keybuf), NULL, 0, NULL,
odp_flow_format(keybuf.data, keybuf.size, NULL, 0, NULL,
&s, dpctl_p->verbosity);
dpctl_print(dpctl_p, "input flow: %s\n", ds_cstr(&s));

error = odp_flow_key_to_flow(ofpbuf_data(&keybuf), ofpbuf_size(&keybuf),
&flow);
error = odp_flow_key_to_flow(keybuf.data, keybuf.size, &flow);
if (error) {
dpctl_error(dpctl_p, error, "odp_flow_key_to_flow");
goto out_freekeybuf;
Expand All @@ -1411,14 +1410,12 @@ dpctl_normalize_actions(int argc, const char *argv[],

if (dpctl_p->verbosity) {
ds_clear(&s);
format_odp_actions(&s, ofpbuf_data(&odp_actions),
ofpbuf_size(&odp_actions));
format_odp_actions(&s, odp_actions.data, odp_actions.size);
dpctl_print(dpctl_p, "input actions: %s\n", ds_cstr(&s));
}

hmap_init(&actions_per_flow);
NL_ATTR_FOR_EACH (a, left, ofpbuf_data(&odp_actions),
ofpbuf_size(&odp_actions)) {
NL_ATTR_FOR_EACH (a, left, odp_actions.data, odp_actions.size) {
const struct ovs_action_push_vlan *push;
switch(nl_attr_type(a)) {
case OVS_ACTION_ATTR_POP_VLAN:
Expand Down Expand Up @@ -1451,8 +1448,7 @@ dpctl_normalize_actions(int argc, const char *argv[],
for (i = 0; i < n_afs; i++) {
struct actions_for_flow *af = afs[i];

sort_output_actions(ofpbuf_data(&af->actions),
ofpbuf_size(&af->actions));
sort_output_actions(af->actions.data, af->actions.size);

if (af->flow.vlan_tci != htons(0)) {
dpctl_print(dpctl_p, "vlan(vid=%"PRIu16",pcp=%d): ",
Expand All @@ -1472,8 +1468,7 @@ dpctl_normalize_actions(int argc, const char *argv[],
}

ds_clear(&s);
format_odp_actions(&s, ofpbuf_data(&af->actions),
ofpbuf_size(&af->actions));
format_odp_actions(&s, af->actions.data, af->actions.size);
dpctl_print(dpctl_p, ds_cstr(&s));

ofpbuf_uninit(&af->actions);
Expand Down
26 changes: 11 additions & 15 deletions lib/dpif-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1573,19 +1573,19 @@ dp_netdev_flow_to_dpif_flow(const struct dp_netdev_flow *netdev_flow,
miniflow_expand(&netdev_flow->cr.mask->mf, &wc.masks);

/* Key */
offset = ofpbuf_size(key_buf);
offset = key_buf->size;
flow->key = ofpbuf_tail(key_buf);
odp_flow_key_from_flow(key_buf, &netdev_flow->flow, &wc.masks,
netdev_flow->flow.in_port.odp_port, true);
flow->key_len = ofpbuf_size(key_buf) - offset;
flow->key_len = key_buf->size - offset;

/* Mask */
offset = ofpbuf_size(mask_buf);
offset = mask_buf->size;
flow->mask = ofpbuf_tail(mask_buf);
odp_flow_key_from_mask(mask_buf, &wc.masks, &netdev_flow->flow,
odp_to_u32(wc.masks.in_port.odp_port),
SIZE_MAX, true);
flow->mask_len = ofpbuf_size(mask_buf) - offset;
flow->mask_len = mask_buf->size - offset;

/* Actions */
actions = dp_netdev_flow_get_actions(netdev_flow);
Expand Down Expand Up @@ -2711,13 +2711,14 @@ dp_netdev_upcall(struct dp_netdev_pmd_thread *pmd, struct dp_packet *packet_,
packet_str = ofp_packet_to_string(dp_packet_data(packet_),
dp_packet_size(packet_));

odp_flow_key_format(ofpbuf_data(&key), ofpbuf_size(&key), &ds);
odp_flow_key_format(key.data, key.size, &ds);

VLOG_DBG("%s: %s upcall:\n%s\n%s", dp->name,
dpif_upcall_type_to_string(type), ds_cstr(&ds), packet_str);

ofpbuf_uninit(&key);
free(packet_str);

ds_destroy(&ds);
}

Expand Down Expand Up @@ -2947,13 +2948,9 @@ fast_path_processing(struct dp_netdev_pmd_thread *pmd,
* the actions. Otherwise, if there are any slow path actions,
* we'll send the packet up twice. */
dp_netdev_execute_actions(pmd, &packets[i], 1, true,
ofpbuf_data(&actions),
ofpbuf_size(&actions));

add_actions = ofpbuf_size(&put_actions)
? &put_actions
: &actions;
actions.data, actions.size);

add_actions = put_actions.size ? &put_actions : &actions;
if (OVS_LIKELY(error != ENOSPC)) {
/* XXX: There's a race window where a flow covering this packet
* could have already been installed since we last did the flow
Expand All @@ -2965,8 +2962,8 @@ fast_path_processing(struct dp_netdev_pmd_thread *pmd,
netdev_flow = dp_netdev_pmd_lookup_flow(pmd, &keys[i]);
if (OVS_LIKELY(!netdev_flow)) {
netdev_flow = dp_netdev_flow_add(pmd, &match, &ufid,
ofpbuf_data(add_actions),
ofpbuf_size(add_actions));
add_actions->data,
add_actions->size);
}
ovs_mutex_unlock(&pmd->flow_mutex);

Expand Down Expand Up @@ -3183,8 +3180,7 @@ dp_execute_cb(void *aux_, struct dp_packet **packets, int cnt,
NULL);
if (!error || error == ENOSPC) {
dp_netdev_execute_actions(pmd, &packets[i], 1, may_steal,
ofpbuf_data(&actions),
ofpbuf_size(&actions));
actions.data, actions.size);
} else if (may_steal) {
dp_packet_delete(packets[i]);
}
Expand Down
14 changes: 7 additions & 7 deletions lib/dpif-netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,8 @@ dpif_netlink_port_add__(struct dpif_netlink *dpif, struct netdev *netdev,
}
nl_msg_end_nested(&options, ext_ofs);
}
request.options = ofpbuf_data(&options);
request.options_len = ofpbuf_size(&options);
request.options = options.data;
request.options_len = options.size;
}

request.port_no = *port_nop;
Expand Down Expand Up @@ -1469,7 +1469,7 @@ dpif_netlink_flow_dump_next(struct dpif_flow_dump_thread *thread_,

n_flows = 0;
while (!n_flows
|| (n_flows < max_flows && ofpbuf_size(&thread->nl_flows))) {
|| (n_flows < max_flows && thread->nl_flows.size)) {
struct dpif_netlink_flow datapath_flow;
struct ofpbuf nl_flow;
int error;
Expand Down Expand Up @@ -1973,7 +1973,7 @@ parse_odp_packet(const struct dpif_netlink *dpif, struct ofpbuf *buf,
struct ofpbuf b;
int type;

ofpbuf_use_const(&b, ofpbuf_data(buf), ofpbuf_size(buf));
ofpbuf_use_const(&b, buf->data, buf->size);

nlmsg = ofpbuf_try_pull(&b, sizeof *nlmsg);
genl = ofpbuf_try_pull(&b, sizeof *genl);
Expand Down Expand Up @@ -2393,7 +2393,7 @@ dpif_netlink_vport_from_ofpbuf(struct dpif_netlink_vport *vport,

dpif_netlink_vport_init(vport);

ofpbuf_use_const(&b, ofpbuf_data(buf), ofpbuf_size(buf));
ofpbuf_use_const(&b, buf->data, buf->size);
nlmsg = ofpbuf_try_pull(&b, sizeof *nlmsg);
genl = ofpbuf_try_pull(&b, sizeof *genl);
ovs_header = ofpbuf_try_pull(&b, sizeof *ovs_header);
Expand Down Expand Up @@ -2561,7 +2561,7 @@ dpif_netlink_dp_from_ofpbuf(struct dpif_netlink_dp *dp, const struct ofpbuf *buf

dpif_netlink_dp_init(dp);

ofpbuf_use_const(&b, ofpbuf_data(buf), ofpbuf_size(buf));
ofpbuf_use_const(&b, buf->data, buf->size);
nlmsg = ofpbuf_try_pull(&b, sizeof *nlmsg);
genl = ofpbuf_try_pull(&b, sizeof *genl);
ovs_header = ofpbuf_try_pull(&b, sizeof *ovs_header);
Expand Down Expand Up @@ -2719,7 +2719,7 @@ dpif_netlink_flow_from_ofpbuf(struct dpif_netlink_flow *flow,

dpif_netlink_flow_init(flow);

ofpbuf_use_const(&b, ofpbuf_data(buf), ofpbuf_size(buf));
ofpbuf_use_const(&b, buf->data, buf->size);
nlmsg = ofpbuf_try_pull(&b, sizeof *nlmsg);
genl = ofpbuf_try_pull(&b, sizeof *genl);
ovs_header = ofpbuf_try_pull(&b, sizeof *ovs_header);
Expand Down
10 changes: 5 additions & 5 deletions lib/dpif.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ dpif_probe_feature(struct dpif *dpif, const char *name,
* restarted) at just the right time such that feature probes from the
* previous run are still present in the datapath. */
error = dpif_flow_put(dpif, DPIF_FP_CREATE | DPIF_FP_MODIFY | DPIF_FP_PROBE,
ofpbuf_data(key), ofpbuf_size(key), NULL, 0, NULL, 0,
key->data, key->size, NULL, 0, NULL, 0,
ufid, PMD_ID_NULL, NULL);
if (error) {
if (error != EINVAL) {
Expand All @@ -888,14 +888,14 @@ dpif_probe_feature(struct dpif *dpif, const char *name,
}

ofpbuf_use_stack(&reply, &stub, sizeof stub);
error = dpif_flow_get(dpif, ofpbuf_data(key), ofpbuf_size(key), ufid,
error = dpif_flow_get(dpif, key->data, key->size, ufid,
PMD_ID_NULL, &reply, &flow);
if (!error
&& (!ufid || (flow.ufid_present && ovs_u128_equal(ufid, &flow.ufid)))) {
enable_feature = true;
}

error = dpif_flow_del(dpif, ofpbuf_data(key), ofpbuf_size(key), ufid,
error = dpif_flow_del(dpif, key->data, key->size, ufid,
PMD_ID_NULL, NULL);
if (error) {
VLOG_WARN("%s: failed to delete %s feature probe flow",
Expand Down Expand Up @@ -1103,8 +1103,8 @@ dpif_execute_helper_cb(void *aux_, struct dp_packet **packets, int cnt,
odp_put_tunnel_action(&md->tunnel, &execute_actions);
ofpbuf_put(&execute_actions, action, NLA_ALIGN(action->nla_len));

execute.actions = ofpbuf_data(&execute_actions);
execute.actions_len = ofpbuf_size(&execute_actions);
execute.actions = execute_actions.data;
execute.actions_len = execute_actions.size;
} else {
execute.actions = action;
execute.actions_len = NLA_ALIGN(action->nla_len);
Expand Down
6 changes: 3 additions & 3 deletions lib/jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ jsonrpc_run(struct jsonrpc *rpc)
struct ofpbuf *buf = ofpbuf_from_list(rpc->output.next);
int retval;

retval = stream_send(rpc->stream, ofpbuf_data(buf), ofpbuf_size(buf));
retval = stream_send(rpc->stream, buf->data, buf->size);
if (retval >= 0) {
rpc->backlog -= retval;
ofpbuf_pull(buf, retval);
if (!ofpbuf_size(buf)) {
if (!buf->size) {
list_remove(&buf->list_node);
rpc->output_count--;
ofpbuf_delete(buf);
Expand Down Expand Up @@ -257,7 +257,7 @@ jsonrpc_send(struct jsonrpc *rpc, struct jsonrpc_msg *msg)

buf = xmalloc(sizeof *buf);
ofpbuf_use(buf, s, length);
ofpbuf_set_size(buf, length);
buf->size = length;
list_push_back(&rpc->output, &buf->list_node);
rpc->output_count++;
rpc->backlog += length;
Expand Down
6 changes: 3 additions & 3 deletions lib/learn.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ learn_execute(const struct ofpact_learn *learn, const struct flow *flow,
}
ofpact_pad(ofpacts);

fm->ofpacts = ofpbuf_data(ofpacts);
fm->ofpacts_len = ofpbuf_size(ofpacts);
fm->ofpacts = ofpacts->data;
fm->ofpacts_len = ofpacts->size;
}

/* Perform a bitwise-OR on 'wc''s fields that are relevant as sources in
Expand Down Expand Up @@ -380,7 +380,7 @@ learn_parse__(char *orig, char *arg, struct ofpbuf *ofpacts)
char *error;

spec = ofpbuf_put_zeros(ofpacts, sizeof *spec);
learn = ofpacts->frame;
learn = ofpacts->header;
learn->n_specs++;

error = learn_parse_spec(orig, name, value, spec);
Expand Down
16 changes: 8 additions & 8 deletions lib/learning-switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,12 @@ lswitch_process_packet(struct lswitch *sw, const struct ofpbuf *msg)

switch (type) {
case OFPTYPE_ECHO_REQUEST:
process_echo_request(sw, ofpbuf_data(msg));
process_echo_request(sw, msg->data);
break;

case OFPTYPE_FEATURES_REPLY:
if (sw->state == S_FEATURES_REPLY) {
if (!process_switch_features(sw, ofpbuf_data(msg))) {
if (!process_switch_features(sw, msg->data)) {
sw->state = S_SWITCHING;
} else {
rconn_disconnect(sw->rconn);
Expand All @@ -378,7 +378,7 @@ lswitch_process_packet(struct lswitch *sw, const struct ofpbuf *msg)
break;

case OFPTYPE_PACKET_IN:
process_packet_in(sw, ofpbuf_data(msg));
process_packet_in(sw, msg->data);
break;

case OFPTYPE_FLOW_REMOVED:
Expand Down Expand Up @@ -451,7 +451,7 @@ lswitch_process_packet(struct lswitch *sw, const struct ofpbuf *msg)
case OFPTYPE_BUNDLE_ADD_MESSAGE:
default:
if (VLOG_IS_DBG_ENABLED()) {
char *s = ofp_to_string(ofpbuf_data(msg), ofpbuf_size(msg), 2);
char *s = ofp_to_string(msg->data, msg->size, 2);
VLOG_DBG_RL(&rl, "%016llx: OpenFlow packet ignored: %s",
sw->datapath_id, s);
free(s);
Expand Down Expand Up @@ -656,8 +656,8 @@ process_packet_in(struct lswitch *sw, const struct ofp_header *oh)
po.packet_len = 0;
}
po.in_port = pi.fmd.in_port;
po.ofpacts = ofpbuf_data(&ofpacts);
po.ofpacts_len = ofpbuf_size(&ofpacts);
po.ofpacts = ofpacts.data;
po.ofpacts_len = ofpacts.size;

/* Send the packet, and possibly the whole flow, to the output port. */
if (sw->max_idle >= 0 && (!sw->ml || out_port != OFPP_FLOOD)) {
Expand All @@ -675,8 +675,8 @@ process_packet_in(struct lswitch *sw, const struct ofp_header *oh)
fm.idle_timeout = sw->max_idle;
fm.buffer_id = pi.buffer_id;
fm.out_port = OFPP_NONE;
fm.ofpacts = ofpbuf_data(&ofpacts);
fm.ofpacts_len = ofpbuf_size(&ofpacts);
fm.ofpacts = ofpacts.data;
fm.ofpacts_len = ofpacts.size;
buffer = ofputil_encode_flow_mod(&fm, sw->protocol);

queue_tx(sw, buffer);
Expand Down
3 changes: 1 addition & 2 deletions lib/netdev-dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,7 @@ eth_from_packet_or_flow(const char *s)
}

/* Convert odp_key to flow. */
fitness = odp_flow_key_to_flow(ofpbuf_data(&odp_key),
ofpbuf_size(&odp_key), &flow);
fitness = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow);
if (fitness == ODP_FIT_ERROR) {
ofpbuf_uninit(&odp_key);
return NULL;
Expand Down
Loading

0 comments on commit 6fd6ed7

Please sign in to comment.