This commit moves the main logic of send_packet() function into the ofproto-dpif-xlate module.
Signed-off-by: Alex Wang <al...@nicira.com> --- ofproto/ofproto-dpif-xlate.c | 55 +++++++++++++++++++++++++++++++++++++ ofproto/ofproto-dpif-xlate.h | 1 + ofproto/ofproto-dpif.c | 61 ++++++++---------------------------------- ofproto/ofproto-dpif.h | 1 + 4 files changed, 68 insertions(+), 50 deletions(-) diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index a5b6814..bb160b5 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -2694,3 +2694,58 @@ out: rule_actions_unref(actions); } + +/* Sends 'packet' out 'ofport'. + * May modify 'packet'. + * Returns 0 if successful, otherwise a positive errno value. */ +int +xlate_send_packet(const struct ofport_dpif *ofport, struct ofpbuf *packet) +{ + uint64_t odp_actions_stub[1024 / 8]; + struct xport *xport; + struct ofpbuf key, odp_actions; + struct dpif_flow_stats stats; + struct odputil_keybuf keybuf; + struct ofpact_output output; + struct xlate_out xout; + struct xlate_in xin; + struct flow flow; + union flow_in_port in_port_; + int error; + + ovs_rwlock_rdlock(&xlate_rwlock); + xport = xport_lookup(ofport); + if (!xport) { + error = EINVAL; + goto out; + } + + ofpbuf_use_stub(&odp_actions, odp_actions_stub, sizeof odp_actions_stub); + ofpbuf_use_stack(&key, &keybuf, sizeof keybuf); + + /* Use OFPP_NONE as the in_port to avoid special packet processing. */ + in_port_.ofp_port = OFPP_NONE; + flow_extract(packet, 0, 0, NULL, &in_port_, &flow); + odp_flow_key_from_flow(&key, &flow, ofp_port_to_odp_port(xport->xbridge, OFPP_LOCAL)); + dpif_flow_stats_extract(&flow, packet, time_msec(), &stats); + + ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output); + output.port = xport->ofp_port; + output.max_len = 0; + + xlate_in_init(&xin, xport->xbridge->ofproto, &flow, NULL, 0, packet); + xin.ofpacts_len = sizeof output; + xin.ofpacts = &output.ofpact; + xin.resubmit_stats = &stats; + xlate_actions(&xin, &xout); + + error = dpif_execute(xport->xbridge->dpif, + key.data, key.size, + xout.odp_actions.data, xout.odp_actions.size, + packet); + xlate_out_uninit(&xout); + +out: + ovs_rwlock_unlock(&xlate_rwlock); + return error; +} diff --git a/ofproto/ofproto-dpif-xlate.h b/ofproto/ofproto-dpif-xlate.h index a54a9e4..98c0746 100644 --- a/ofproto/ofproto-dpif-xlate.h +++ b/ofproto/ofproto-dpif-xlate.h @@ -154,4 +154,5 @@ void xlate_in_init(struct xlate_in *, struct ofproto_dpif *, void xlate_out_uninit(struct xlate_out *); void xlate_actions_for_side_effects(struct xlate_in *); void xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src); +int xlate_send_packet(const struct ofport_dpif *, struct ofpbuf *); #endif /* ofproto-dpif-xlate.h */ diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 80874b8..44f5fbf 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -540,9 +540,6 @@ static int expire(struct dpif_backer *); /* NetFlow. */ static void send_netflow_active_timeouts(struct ofproto_dpif *); -/* Utilities. */ -static int send_packet(const struct ofport_dpif *, struct ofpbuf *packet); - /* Global variables. */ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); @@ -2018,7 +2015,7 @@ send_bpdu_cb(struct ofpbuf *pkt, int port_num, void *ofproto_) VLOG_WARN_RL(&rl, "%s: cannot send BPDU on port %d " "with unknown MAC", ofproto->up.name, port_num); } else { - send_packet(ofport, pkt); + ofproto_dpif_send_packet(ofport, pkt); } } ofpbuf_delete(pkt); @@ -2614,7 +2611,7 @@ send_pdu_cb(void *port_, const void *pdu, size_t pdu_size) pdu_size); memcpy(packet_pdu, pdu, pdu_size); - send_packet(port, &packet); + ofproto_dpif_send_packet(port, &packet); ofpbuf_uninit(&packet); } else { VLOG_ERR_RL(&rl, "port %s: cannot obtain Ethernet address of iface " @@ -2651,7 +2648,7 @@ bundle_send_learning_packets(struct ofbundle *bundle) LIST_FOR_EACH (learning_packet, list_node, &packets) { int ret; - ret = send_packet(learning_packet->private_p, learning_packet); + ret = ofproto_dpif_send_packet(learning_packet->private_p, learning_packet); if (ret) { error = ret; n_errors++; @@ -2873,7 +2870,7 @@ port_run_fast(struct ofport_dpif *ofport) ofpbuf_init(&packet, 0); cfm_compose_ccm(ofport->cfm, &packet, ofport->up.pp.hw_addr); - send_packet(ofport, &packet); + ofproto_dpif_send_packet(ofport, &packet); ofpbuf_uninit(&packet); } @@ -2882,7 +2879,7 @@ port_run_fast(struct ofport_dpif *ofport) ofpbuf_init(&packet, 0); bfd_put_packet(ofport->bfd, &packet, ofport->up.pp.hw_addr); - send_packet(ofport, &packet); + ofproto_dpif_send_packet(ofport, &packet); ofpbuf_uninit(&packet); } } @@ -4945,55 +4942,19 @@ rule_modify_actions(struct rule *rule_, bool reset_counters) /* Sends 'packet' out 'ofport'. * May modify 'packet'. * Returns 0 if successful, otherwise a positive errno value. */ -static int -send_packet(const struct ofport_dpif *ofport, struct ofpbuf *packet) +int +ofproto_dpif_send_packet(const struct ofport_dpif *ofport, struct ofpbuf *packet) { struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto); - uint64_t odp_actions_stub[1024 / 8]; - struct ofpbuf key, odp_actions; - struct dpif_flow_stats stats; - struct odputil_keybuf keybuf; - struct ofpact_output output; - struct xlate_out xout; - struct xlate_in xin; - struct flow flow; - union flow_in_port in_port_; int error; - ofpbuf_use_stub(&odp_actions, odp_actions_stub, sizeof odp_actions_stub); - ofpbuf_use_stack(&key, &keybuf, sizeof keybuf); - - /* Use OFPP_NONE as the in_port to avoid special packet processing. */ - in_port_.ofp_port = OFPP_NONE; - flow_extract(packet, 0, 0, NULL, &in_port_, &flow); - odp_flow_key_from_flow(&key, &flow, ofp_port_to_odp_port(ofproto, - OFPP_LOCAL)); - dpif_flow_stats_extract(&flow, packet, time_msec(), &stats); + error = xlate_send_packet(ofport, packet); - ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output); - output.port = ofport->up.ofp_port; - output.max_len = 0; - - xlate_in_init(&xin, ofproto, &flow, NULL, 0, packet); - xin.ofpacts_len = sizeof output; - xin.ofpacts = &output.ofpact; - xin.resubmit_stats = &stats; - xlate_actions(&xin, &xout); - - error = dpif_execute(ofproto->backer->dpif, - key.data, key.size, - xout.odp_actions.data, xout.odp_actions.size, - packet); - xlate_out_uninit(&xout); - - if (error) { - VLOG_WARN_RL(&rl, "%s: failed to send packet on port %s (%s)", - ofproto->up.name, netdev_get_name(ofport->up.netdev), - ovs_strerror(error)); + if (!error) { + ofproto->stats.tx_packets++; + ofproto->stats.tx_bytes += packet->size; } - ofproto->stats.tx_packets++; - ofproto->stats.tx_bytes += packet->size; return error; } diff --git a/ofproto/ofproto-dpif.h b/ofproto/ofproto-dpif.h index 14a9669..0863efd 100644 --- a/ofproto/ofproto-dpif.h +++ b/ofproto/ofproto-dpif.h @@ -95,6 +95,7 @@ bool vsp_adjust_flow(const struct ofproto_dpif *, struct flow *); void ofproto_dpif_send_packet_in(struct ofproto_dpif *, struct ofputil_packet_in *pin); +int ofproto_dpif_send_packet(const struct ofport_dpif *, struct ofpbuf *); void ofproto_dpif_flow_mod(struct ofproto_dpif *, struct ofputil_flow_mod *); struct ofport_dpif *odp_port_to_ofport(const struct dpif_backer *, odp_port_t); -- 1.7.9.5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev