X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ofproto%2Fpktbuf.c;h=71be34a61fa433539e456ca95c9befd21f1ba252;hb=26720e2449918b92be1fd0e3a7c57012c057c733;hp=acc0d34d304c308689a11d899a95d7fb24be3374;hpb=e0edde6fee279cdbbf3c179f5f50adaf0c7c7f1e;p=openvswitch diff --git a/ofproto/pktbuf.c b/ofproto/pktbuf.c index acc0d34d..71be34a6 100644 --- a/ofproto/pktbuf.c +++ b/ofproto/pktbuf.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -232,3 +232,23 @@ pktbuf_discard(struct pktbuf *pb, uint32_t id) p->buffer = NULL; } } + +/* Returns the number of packets buffered in 'pb'. Returns 0 if 'pb' is + * null. */ +unsigned int +pktbuf_count_packets(const struct pktbuf *pb) +{ + int n = 0; + + if (pb) { + int i; + + for (i = 0; i < PKTBUF_CNT; i++) { + if (pb->packets[i].buffer) { + n++; + } + } + } + + return n; +}