Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 Jul 1999 03:41:15 +0900 (JST)
From:      NAGAO Tadaaki <nagao@iij.ad.jp>
To:        des@flood.ping.uio.no
Cc:        net@freebsd.org
Subject:   Re: dummynet -> rate limiting
Message-ID:  <19990718034115X.nagao@iij.ad.jp>
In-Reply-To: <xzpd7xrno4q.fsf@flood.ping.uio.no>
References:  <xzpd7xrno4q.fsf@flood.ping.uio.no>

next in thread | previous in thread | raw e-mail | index | archive | help
----Next_Part(Sun_Jul_18_03:40:17_1999_595)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

In message <xzpd7xrno4q.fsf@flood.ping.uio.no>,
    Dag-Erling Smorgrav <des@flood.ping.uio.no> wrote:
> What do people think about adding rate limiting to dummynet? It would
> work just like bandwidth limiting, except the limit would be in
> packets or kilopackets per second (pps, kpps) instead of bits or bytes
> per second.

I've done that and posted a patch to this mailing list a while back
on March. (But, sorry, the patch had a bug and although it's been
fixed I've forgotten to post and/or send-pr it...)

The most up-to-date patch to -stable branch is attached to this mail.
No manpage patches yet, sorry.
Please use it as a starting point if you are interested in.

BTW, though I think it would be obvious if you read my patch, the usage is:

	ipfw pipe NNN config pps S

where S is the allowed number of packets per second.

Cheers,
NAGAO Tadaaki <nagao@iij.ad.jp>
Applied Technology Division, Internet Initiative Japan Inc.

----Next_Part(Sun_Jul_18_03:40:17_1999_595)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="dummynet-pps.patch"

Index: sys/netinet/ip_dummynet.c
===================================================================
RCS file: /usr/ncvs/src/sys/netinet/ip_dummynet.c,v
retrieving revision 1.7.2.5
diff -u -r1.7.2.5 ip_dummynet.c
--- ip_dummynet.c	1999/05/04 16:23:57	1.7.2.5
+++ ip_dummynet.c	1999/05/05 13:26:37
@@ -148,6 +148,15 @@
 	    int len = pkt->dn_m->m_pkthdr.len ;
 
 	    /*
+	     * limit the number of packets per second (pps).
+	     */
+	    if (pipe->pps) {
+		if (pipe->pps_counter < hz)
+		    break;
+		pipe->pps_counter -= hz;
+	    }
+
+	    /*
 	     * queue limitation: pass packets down if the len is
 	     * such that the pkt would go out before the next tick.
 	     */
@@ -266,6 +275,8 @@
         s = splimp();
 	if (p->r.head != NULL || p->numbytes < p->bandwidth )
 		p->numbytes += p->bandwidth ;
+	if (p->pps && (p->r.head != NULL || p->pps_counter < hz ))
+		p->pps_counter += p->pps ;
 	dn_move(p, 0); /* is it really 0 (also below) ? */
 	splx(s);
     }
@@ -524,10 +535,10 @@
 	    if (p->queue_size_bytes > 1024*1024)
 		p->queue_size_bytes = 1024*1024 ;
 #if 0
-	    printf("ip_dn: config pipe %d %d bit/s %d ms %d bufs\n",
+	    printf("ip_dn: config pipe %d %d bit/s %d ms %d bufs %d pps\n",
 		p->pipe_nr,
 		p->bandwidth * 8 * hz ,
-		p->delay * 1000 / hz , p->queue_size);
+		p->delay * 1000 / hz , p->queue_size, p->pps);
 #endif
 	    for (a = NULL , b = all_pipes ; b && b->pipe_nr < p->pipe_nr ;
 		 a = b , b = b->next) ;
@@ -539,6 +550,7 @@
 		b->queue_size = p->queue_size ;
 		b->queue_size_bytes = p->queue_size_bytes ;
 		b->plr = p->plr ;
+		b->pps = p->pps ;
 	    } else {
 		int s ;
 		x = malloc(sizeof(struct dn_pipe), M_IPFW, M_DONTWAIT) ;
@@ -555,6 +567,7 @@
 		x->queue_size = p->queue_size ;
 		x->queue_size_bytes = p->queue_size_bytes ;
 		x->plr = p->plr ;
+		x->pps = p->pps ;
 
 		s = splnet() ;
 		x->next = b ;
Index: sys/netinet/ip_dummynet.h
===================================================================
RCS file: /usr/ncvs/src/sys/netinet/ip_dummynet.h,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 ip_dummynet.h
--- ip_dummynet.h	1999/05/04 07:47:45	1.2.2.2
+++ ip_dummynet.h	1999/05/04 15:21:09
@@ -74,6 +74,7 @@
 	int	queue_size_bytes ;
 	int	delay ;			/* really, ticks	*/
 	int	plr ;		/* pkt loss rate (2^31-1 means 100%) */
+	int	pps;			/* packets per sec */
 
         struct	dn_queue r;
         int	r_len;			/* elements in r_queue */
@@ -82,6 +83,7 @@
         struct	dn_queue p ;
         int     ticks_from_last_insert;
         long    numbytes;		/* which can send or receive */
+        long    pps_counter;
 };
 
 /*
Index: sbin/ipfw/ipfw.c
===================================================================
RCS file: /usr/ncvs/src/sbin/ipfw/ipfw.c,v
retrieving revision 1.64.2.6
diff -u -r1.64.2.6 ipfw.c
--- ipfw.c	1999/06/17 13:03:39	1.64.2.6
+++ ipfw.c	1999/06/17 17:56:28
@@ -462,6 +462,7 @@
 		char buf[30] ;
 		char qs[30] ;
 		char plr[30] ;
+		char pps[30] ;
 		int l ;
 
 		if (rulenum != 0 && rulenum != p->pipe_nr)
@@ -486,9 +487,13 @@
 		    sprintf(plr,"plr %f", 1.0*p->plr/(double)(0x7fffffff));
 		else
 		    plr[0]='\0';
+		if (p->pps)
+		    sprintf(pps, "%d pkts/s", p->pps);
+		else
+		    pps[0] = '\0';
 
-		printf("%05d: %s %4d ms %s %s -- %d pkts (%d B) %d drops\n",
-		    p->pipe_nr, buf, p->delay, qs, plr,
+		printf("%05d: %s %s %4d ms %s %s -- %d pkts (%d B) %d drops\n",
+		    p->pipe_nr, buf, pps, p->delay, qs, plr,
 		    p->r_len, p->r_len_bytes, p->r_drops);
 	    }
 	    free(data);
@@ -1005,6 +1010,9 @@
                     pipe.queue_size_bytes = pipe.queue_size ;
                     pipe.queue_size = 0 ;
                 }
+                av+=2; ac-=2;
+            } else if (!strncmp(*av,"pps",strlen(*av)) ) {
+                pipe.pps = strtoul(av[1], NULL, 0);
                 av+=2; ac-=2;
             } else
                 show_usage("unrecognised option ``%s''", *av);

----Next_Part(Sun_Jul_18_03:40:17_1999_595)----


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990718034115X.nagao>