Skip to content

Commit

Permalink
dp-packet: Remove ofpbuf dependency.
Browse files Browse the repository at this point in the history
Currently dp-packet make use of ofpbuf for managing packet
buffers. That complicates ofpbuf, by making dp-packet
independent of ofpbuf both libraries can be optimized for
their own use case.
This avoids mapping operation between ofpbuf and dp_packet
in datapath upcalls.

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 e14deea commit cf62fa4
Show file tree
Hide file tree
Showing 58 changed files with 1,599 additions and 789 deletions.
23 changes: 12 additions & 11 deletions lib/bfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "byte-order.h"
#include "connectivity.h"
#include "csum.h"
#include "dp-packet.h"
#include "dpif.h"
#include "dynamic-string.h"
#include "flow.h"
Expand Down Expand Up @@ -585,7 +586,7 @@ bfd_should_send_packet(const struct bfd *bfd) OVS_EXCLUDED(mutex)
}

void
bfd_put_packet(struct bfd *bfd, struct ofpbuf *p,
bfd_put_packet(struct bfd *bfd, struct dp_packet *p,
uint8_t eth_src[ETH_ADDR_LEN]) OVS_EXCLUDED(mutex)
{
long long int min_tx, min_rx;
Expand All @@ -609,8 +610,8 @@ bfd_put_packet(struct bfd *bfd, struct ofpbuf *p,
* set. */
ovs_assert(!(bfd->flags & FLAG_POLL) || !(bfd->flags & FLAG_FINAL));

ofpbuf_reserve(p, 2); /* Properly align after the ethernet header. */
eth = ofpbuf_put_uninit(p, sizeof *eth);
dp_packet_reserve(p, 2); /* Properly align after the ethernet header. */
eth = dp_packet_put_uninit(p, sizeof *eth);
memcpy(eth->eth_src,
eth_addr_is_zero(bfd->local_eth_src) ? eth_src
: bfd->local_eth_src,
Expand All @@ -621,7 +622,7 @@ bfd_put_packet(struct bfd *bfd, struct ofpbuf *p,
ETH_ADDR_LEN);
eth->eth_type = htons(ETH_TYPE_IP);

ip = ofpbuf_put_zeros(p, sizeof *ip);
ip = dp_packet_put_zeros(p, sizeof *ip);
ip->ip_ihl_ver = IP_IHL_VER(5, 4);
ip->ip_tot_len = htons(sizeof *ip + sizeof *udp + sizeof *msg);
ip->ip_ttl = MAXTTL;
Expand All @@ -631,12 +632,12 @@ bfd_put_packet(struct bfd *bfd, struct ofpbuf *p,
put_16aligned_be32(&ip->ip_dst, bfd->ip_dst);
ip->ip_csum = csum(ip, sizeof *ip);

udp = ofpbuf_put_zeros(p, sizeof *udp);
udp = dp_packet_put_zeros(p, sizeof *udp);
udp->udp_src = htons(bfd->udp_src);
udp->udp_dst = htons(BFD_DEST_PORT);
udp->udp_len = htons(sizeof *udp + sizeof *msg);

msg = ofpbuf_put_uninit(p, sizeof *msg);
msg = dp_packet_put_uninit(p, sizeof *msg);
msg->vers_diag = (BFD_VERSION << 5) | bfd->diag;
msg->flags = (bfd->state & STATE_MASK) | bfd->flags;

Expand Down Expand Up @@ -702,14 +703,14 @@ bfd_should_process_flow(const struct bfd *bfd_, const struct flow *flow,

void
bfd_process_packet(struct bfd *bfd, const struct flow *flow,
const struct ofpbuf *p) OVS_EXCLUDED(mutex)
const struct dp_packet *p) OVS_EXCLUDED(mutex)
{
uint32_t rmt_min_rx, pkt_your_disc;
enum state rmt_state;
enum flags flags;
uint8_t version;
struct msg *msg;
const uint8_t *l7 = ofpbuf_get_udp_payload(p);
const uint8_t *l7 = dp_packet_get_udp_payload(p);

if (!l7) {
return; /* No UDP payload. */
Expand All @@ -728,11 +729,11 @@ bfd_process_packet(struct bfd *bfd, const struct flow *flow,
goto out;
}

msg = ofpbuf_at(p, l7 - (uint8_t *)ofpbuf_data(p), BFD_PACKET_LEN);
msg = dp_packet_at(p, l7 - (uint8_t *)dp_packet_data(p), BFD_PACKET_LEN);
if (!msg) {
VLOG_INFO_RL(&rl, "%s: Received too-short BFD control message (only "
"%"PRIdPTR" bytes long, at least %d required).",
bfd->name, (uint8_t *) ofpbuf_tail(p) - l7,
bfd->name, (uint8_t *) dp_packet_tail(p) - l7,
BFD_PACKET_LEN);
goto out;
}
Expand All @@ -741,7 +742,7 @@ bfd_process_packet(struct bfd *bfd, const struct flow *flow,
* If the Length field is greater than the payload of the encapsulating
* protocol, the packet MUST be discarded.
*
* Note that we make this check implicity. Above we use ofpbuf_at() to
* Note that we make this check implicitly. Above we use dp_packet_at() to
* ensure that there are at least BFD_PACKET_LEN bytes in the payload of
* the encapsulating protocol. Below we require msg->length to be exactly
* BFD_PACKET_LEN bytes. */
Expand Down
6 changes: 3 additions & 3 deletions lib/bfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ struct dpif_flow_stats;
struct flow;
struct flow_wildcards;
struct netdev;
struct ofpbuf;
struct dp_packet;
struct smap;

void bfd_wait(const struct bfd *);
void bfd_run(struct bfd *);

bool bfd_should_send_packet(const struct bfd *);
void bfd_put_packet(struct bfd *bfd, struct ofpbuf *packet,
void bfd_put_packet(struct bfd *bfd, struct dp_packet *packet,
uint8_t eth_src[ETH_ADDR_LEN]);

bool bfd_should_process_flow(const struct bfd *, const struct flow *,
struct flow_wildcards *);
void bfd_process_packet(struct bfd *, const struct flow *,
const struct ofpbuf *);
const struct dp_packet *);

struct bfd *bfd_configure(struct bfd *, const char *name,
const struct smap *smap,
Expand Down
12 changes: 6 additions & 6 deletions lib/cfm.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

#include "byte-order.h"
#include "connectivity.h"
#include "dp-packet.h"
#include "dynamic-string.h"
#include "flow.h"
#include "hash.h"
#include "hmap.h"
#include "netdev.h"
#include "ofpbuf.h"
#include "packets.h"
#include "poll-loop.h"
#include "random.h"
Expand Down Expand Up @@ -563,7 +563,7 @@ cfm_should_send_ccm(struct cfm *cfm) OVS_EXCLUDED(mutex)
/* Composes a CCM message into 'packet'. Messages generated with this function
* should be sent whenever cfm_should_send_ccm() indicates. */
void
cfm_compose_ccm(struct cfm *cfm, struct ofpbuf *packet,
cfm_compose_ccm(struct cfm *cfm, struct dp_packet *packet,
uint8_t eth_src[ETH_ADDR_LEN]) OVS_EXCLUDED(mutex)
{
uint16_t ccm_vlan;
Expand All @@ -586,7 +586,7 @@ cfm_compose_ccm(struct cfm *cfm, struct ofpbuf *packet,

atomic_read_relaxed(&cfm->extended, &extended);

ccm = ofpbuf_l3(packet);
ccm = dp_packet_l3(packet);
ccm->mdlevel_version = 0;
ccm->opcode = CCM_OPCODE;
ccm->tlv_offset = 70;
Expand Down Expand Up @@ -747,7 +747,7 @@ cfm_should_process_flow(const struct cfm *cfm_, const struct flow *flow,
* every packet whose flow returned true when passed to
* cfm_should_process_flow. */
void
cfm_process_heartbeat(struct cfm *cfm, const struct ofpbuf *p)
cfm_process_heartbeat(struct cfm *cfm, const struct dp_packet *p)
OVS_EXCLUDED(mutex)
{
struct ccm *ccm;
Expand All @@ -758,8 +758,8 @@ cfm_process_heartbeat(struct cfm *cfm, const struct ofpbuf *p)

atomic_read_relaxed(&cfm->extended, &extended);

eth = ofpbuf_l2(p);
ccm = ofpbuf_at(p, (uint8_t *)ofpbuf_l3(p) - (uint8_t *)ofpbuf_data(p),
eth = dp_packet_l2(p);
ccm = dp_packet_at(p, (uint8_t *)dp_packet_l3(p) - (uint8_t *)dp_packet_data(p),
CCM_ACCEPT_LEN);

if (!ccm) {
Expand Down
6 changes: 3 additions & 3 deletions lib/cfm.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "packets.h"

struct flow;
struct ofpbuf;
struct dp_packet;
struct netdev;
struct flow_wildcards;

Expand Down Expand Up @@ -93,13 +93,13 @@ struct cfm *cfm_ref(const struct cfm *);
void cfm_unref(struct cfm *);
void cfm_run(struct cfm *);
bool cfm_should_send_ccm(struct cfm *);
void cfm_compose_ccm(struct cfm *, struct ofpbuf *packet, uint8_t eth_src[ETH_ADDR_LEN]);
void cfm_compose_ccm(struct cfm *, struct dp_packet *packet, uint8_t eth_src[ETH_ADDR_LEN]);
void cfm_wait(struct cfm *);
bool cfm_configure(struct cfm *, const struct cfm_settings *);
void cfm_set_netdev(struct cfm *, const struct netdev *);
bool cfm_should_process_flow(const struct cfm *cfm, const struct flow *,
struct flow_wildcards *);
void cfm_process_heartbeat(struct cfm *, const struct ofpbuf *packet);
void cfm_process_heartbeat(struct cfm *, const struct dp_packet *packet);
bool cfm_check_status_change(struct cfm *);
int cfm_get_fault(const struct cfm *);
uint64_t cfm_get_flap_count(const struct cfm *);
Expand Down
Loading

0 comments on commit cf62fa4

Please sign in to comment.