[ovs-dev] treewide: Use packet batch APIs
diff mbox series

Message ID 20190707125006.GA25323@Nover
State New
Headers show
Series
  • [ovs-dev] treewide: Use packet batch APIs
Related show

Commit Message

Paul Chaignon July 7, 2019, 12:50 p.m. UTC
This patch replaces direct accesses to dp_packet_batch and dp_packet
internal components by the appropriate API calls.  It extends commit
1270b6e52 (treewide: Wider use of packet batch APIs).

This patch was generated using the following semantic patch (cf.
http://coccinelle.lip6.fr).

// <smpl>
@ dp_packet @
struct dp_packet_batch *b1;
struct dp_packet_batch b2;
struct dp_packet *p;
expression e;
@@

(
- b1->packets[b1->count++] = p;
+ dp_packet_batch_add(b1, p);
|
- b2.packets[b2.count++] = p;
+ dp_packet_batch_add(&b2, p);
|
- p->packet_type == htonl(PT_ETH)
+ dp_packet_is_eth(p)
|
- p->packet_type != htonl(PT_ETH)
+ !dp_packet_is_eth(p)
|
- b1->count == 0
+ dp_packet_batch_is_empty(b1)
|
- !b1->count
+ dp_packet_batch_is_empty(b1)
|
  b1->count = e;
|
  b1->count++
|
  b2.count = e;
|
  b2.count++
|
- b1->count
+ dp_packet_batch_size(b1)
|
- b2.count
+ dp_packet_batch_size(&b2)
)
// </smpl>

Signed-off-by: Paul Chaignon <paul.chaignon@orange.com>
---
 lib/dpif-netdev.c  | 7 ++++---
 lib/flow.c         | 2 +-
 lib/netdev-dpdk.c  | 3 ++-
 lib/netdev-dummy.c | 2 +-
 lib/packets.c      | 4 ++--
 lib/pcap-file.c    | 2 +-
 6 files changed, 11 insertions(+), 9 deletions(-)

Patch
diff mbox series

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index f4b59e41b..1b19b8870 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -4264,7 +4264,7 @@  dp_netdev_process_rxq_port(struct dp_netdev_pmd_thread *pmd,
         /* At least one packet received. */
         *recirc_depth_get() = 0;
         pmd_thread_ctx_time_update(pmd);
-        batch_cnt = batch.count;
+        batch_cnt = dp_packet_batch_size(&batch);
         if (pmd_perf_metrics_enabled(pmd)) {
             /* Update batch histogram. */
             s->current.batches++;
@@ -6249,7 +6249,7 @@  packet_batch_per_flow_update(struct packet_batch_per_flow *batch,
 {
     batch->byte_count += dp_packet_size(packet);
     batch->tcp_flags |= tcp_flags;
-    batch->array.packets[batch->array.count++] = packet;
+    dp_packet_batch_add(&batch->array, packet);
 }
 
 static inline void
@@ -6271,7 +6271,8 @@  packet_batch_per_flow_execute(struct packet_batch_per_flow *batch,
     struct dp_netdev_actions *actions;
     struct dp_netdev_flow *flow = batch->flow;
 
-    dp_netdev_flow_used(flow, batch->array.count, batch->byte_count,
+    dp_netdev_flow_used(flow, dp_packet_batch_size(&batch->array),
+                        batch->byte_count,
                         batch->tcp_flags, pmd->ctx.now / 1000);
 
     actions = dp_netdev_flow_get_actions(flow);
diff --git a/lib/flow.c b/lib/flow.c
index de9370449..31d1d191e 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -1101,7 +1101,7 @@  parse_tcp_flags(struct dp_packet *packet)
     ovs_be16 dl_type;
     uint8_t nw_frag = 0, nw_proto = 0;
 
-    if (packet->packet_type != htonl(PT_ETH)) {
+    if (!dp_packet_is_eth(packet)) {
         return 0;
     }
 
diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index a380b6ffe..b5168b939 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -2466,7 +2466,8 @@  netdev_dpdk_vhost_send(struct netdev *netdev, int qid,
         dpdk_do_tx_copy(netdev, qid, batch);
         dp_packet_delete_batch(batch, true);
     } else {
-        __netdev_dpdk_vhost_send(netdev, qid, batch->packets, batch->count);
+        __netdev_dpdk_vhost_send(netdev, qid, batch->packets,
+                                 dp_packet_batch_size(batch));
     }
     return 0;
 }
diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index f0c0fbae8..95e1a329a 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -1108,7 +1108,7 @@  netdev_dummy_send(struct netdev *netdev, int qid OVS_UNUSED,
         const void *buffer = dp_packet_data(packet);
         size_t size = dp_packet_size(packet);
 
-        if (packet->packet_type != htonl(PT_ETH)) {
+        if (!dp_packet_is_eth(packet)) {
             error = EPFNOSUPPORT;
             break;
         }
diff --git a/lib/packets.c b/lib/packets.c
index a8fd61fc0..e147e6874 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -246,7 +246,7 @@  push_eth(struct dp_packet *packet, const struct eth_addr *dst,
 {
     struct eth_header *eh;
 
-    ovs_assert(packet->packet_type != htonl(PT_ETH));
+    ovs_assert(!dp_packet_is_eth(packet));
     eh = dp_packet_resize_l2(packet, ETH_HEADER_LEN);
     eh->eth_dst = *dst;
     eh->eth_src = *src;
@@ -265,7 +265,7 @@  pop_eth(struct dp_packet *packet)
     ovs_be16 ethertype;
     int increment;
 
-    ovs_assert(packet->packet_type == htonl(PT_ETH));
+    ovs_assert(dp_packet_is_eth(packet));
     ovs_assert(l3 != NULL);
 
     if (l2_5) {
diff --git a/lib/pcap-file.c b/lib/pcap-file.c
index e4e92b8c2..f0cac8e0f 100644
--- a/lib/pcap-file.c
+++ b/lib/pcap-file.c
@@ -282,7 +282,7 @@  ovs_pcap_write(struct pcap_file *p_file, struct dp_packet *buf)
     struct pcaprec_hdr prh;
     struct timeval tv;
 
-    ovs_assert(buf->packet_type == htonl(PT_ETH));
+    ovs_assert(dp_packet_is_eth(buf));
 
     xgettimeofday(&tv);
     prh.ts_sec = tv.tv_sec;