[ovs-dev] [oftest 1/5] netdev-dummy: Limit receive queue length to 100 packets.

Ben Pfaff blp at nicira.com
Fri Feb 1 22:23:54 UTC 2013


It doesn't seem like a good idea to allow the queue length to grow without
bound, even for a test-only device.

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

diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index f81b68e..001d188 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -53,10 +53,14 @@ struct netdev_dev_dummy {
     struct list devs;           /* List of child "netdev_dummy"s. */
 };
 
+/* Max 'recv_queue_len' in struct netdev_dummy. */
+#define NETDEV_DUMMY_MAX_QUEUE 100
+
 struct netdev_dummy {
     struct netdev netdev;
     struct list node;           /* In netdev_dev_dummy's "devs" list. */
     struct list recv_queue;
+    int recv_queue_len;         /* list_size(&recv_queue). */
     bool listening;
 };
 
@@ -140,6 +144,7 @@ netdev_dummy_open(struct netdev_dev *netdev_dev_, struct netdev **netdevp)
     netdev = xmalloc(sizeof *netdev);
     netdev_init(&netdev->netdev, netdev_dev_);
     list_init(&netdev->recv_queue);
+    netdev->recv_queue_len = 0;
     netdev->listening = false;
 
     *netdevp = &netdev->netdev;
@@ -176,6 +181,7 @@ netdev_dummy_recv(struct netdev *netdev_, void *buffer, size_t size)
     }
 
     packet = ofpbuf_from_list(list_pop_front(&netdev->recv_queue));
+    netdev->recv_queue_len--;
     if (packet->size > size) {
         return -EMSGSIZE;
     }
@@ -201,6 +207,7 @@ netdev_dummy_drain(struct netdev *netdev_)
 {
     struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
     ofpbuf_list_delete(&netdev->recv_queue);
+    netdev->recv_queue_len = 0;
     return 0;
 }
 
@@ -445,9 +452,11 @@ netdev_dummy_receive(struct unixctl_conn *conn,
 
         n_listeners = 0;
         LIST_FOR_EACH (dev, node, &dummy_dev->devs) {
-            if (dev->listening) {
+            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++;
             }
         }
-- 
1.7.2.5




More information about the dev mailing list