[ovs-dev] [tests 08/22] netdev-dummy: Factor some netdev_dummy_receive() code out into new function.

Ben Pfaff blp at nicira.com
Fri Oct 26 00:02:04 UTC 2012


An upcoming patch will add another user.

Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 lib/netdev-dummy.c |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index bfc2997..3aaace3 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -417,6 +417,26 @@ eth_from_packet_or_flow(const char *s)
     return packet;
 }
 
+static int
+netdev_dummy_queue_packet(struct netdev_dev_dummy *dummy_dev,
+                          const void *data, size_t size)
+{
+    struct netdev_dummy *dev;
+    int n_listeners;
+
+    n_listeners = 0;
+    LIST_FOR_EACH (dev, node, &dummy_dev->devs) {
+        if (dev->listening && dev->recv_queue_len < NETDEV_DUMMY_MAX_QUEUE) {
+            struct ofpbuf *packet = ofpbuf_clone_data(data, size);
+            list_push_back(&dev->recv_queue, &packet->list_node);
+            dev->recv_queue_len++;
+            n_listeners++;
+        }
+    }
+
+    return n_listeners;
+}
+
 static void
 netdev_dummy_receive(struct unixctl_conn *conn,
                      int argc, const char *argv[], void *aux OVS_UNUSED)
@@ -433,7 +453,6 @@ netdev_dummy_receive(struct unixctl_conn *conn,
 
     n_listeners = 0;
     for (i = 2; i < argc; i++) {
-        struct netdev_dummy *dev;
         struct ofpbuf *packet;
 
         packet = eth_from_packet_or_flow(argv[i]);
@@ -442,16 +461,8 @@ netdev_dummy_receive(struct unixctl_conn *conn,
             return;
         }
 
-        n_listeners = 0;
-        LIST_FOR_EACH (dev, node, &dummy_dev->devs) {
-            if (dev->listening
-                && dev->recv_queue_len < NETDEV_DUMMY_MAX_QUEUE) {
-                struct ofpbuf *copy = ofpbuf_clone(packet);
-                list_push_back(&dev->recv_queue, &copy->list_node);
-                dev->recv_queue_len++;
-                n_listeners++;
-            }
-        }
+        n_listeners += netdev_dummy_queue_packet(dummy_dev,
+                                                 packet->data, packet->size);
         ofpbuf_delete(packet);
     }
 
-- 
1.7.2.5




More information about the dev mailing list