Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Mar 1999 08:37:34 +0900 (JST)
From:      NAGAO Tadaaki <nagao@iij.ad.jp>
To:        luigi@labinfo.iet.unipi.it
Cc:        freebsd-net@FreeBSD.ORG
Subject:   Re: dummynet -- limit num of packets per sec.
Message-ID:  <19990329083734O.nagao@iij.ad.jp>
In-Reply-To: <199903281837.UAA04424@labinfo.iet.unipi.it>
References:  <19990329054823Z.nagao@iij.ad.jp> <199903281837.UAA04424@labinfo.iet.unipi.it>

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

Hello,

In message <199903281837.UAA04424@labinfo.iet.unipi.it>,
    Luigi Rizzo <luigi@labinfo.iet.unipi.it> wrote:
> > I added some lines of codes to my local copy of dummynet codes
> > so that the number of packets per second could be limited as well as
> > a bandwidth could now, which I needed to measure the performance of
> > some network software.
> > 
> > Though I'm not sure whether it is useful for limiting the real
> > network traffic, it might be useful for testing some network
> > devices and softwares, and yes, it was really useful for me. :-)
> > 
> > Is there some demand on such a thing?
> > If so, I'll make the diff and/or send-pr on it.
> 
> why not -- send me a diff.

Thanks for replying.

Here attached two diffs; one is for /usr/src/sys/netinet/ip_dummynet.[ch]
and the other for /usr/src/sbin/ipfw/ipfw.c.
Sorry, I didn't write a description for the dummynet manpage, but the
usage is:

       ipfw pipe NNN config pps S

where S is the allowed number of packets per second, and, of course,
other parameters (bw, delay, queue and plr) can be given simultanously.

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

----Next_Part(Mon_Mar_29_08:37:31_1999_595)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="sys.diff"

Index: sys/netinet/ip_dummynet.c
===================================================================
RCS file: /usr/ncvs/src/sys/netinet/ip_dummynet.c,v
retrieving revision 1.7.2.3
diff -u -r1.7.2.3 ip_dummynet.c
--- ip_dummynet.c	1999/03/26 16:48:55	1.7.2.3
+++ ip_dummynet.c	1999/03/28 16:34:51
@@ -160,6 +160,15 @@
 	    pipe->r_len_bytes -= len ;
 
 	    /*
+	     * limit the number of packets per second (pps).
+	     */
+	    if (pipe->pps) {
+		if (pipe->pps_counter < hz)
+		    break;
+		pipe->pps_counter -= hz;
+	    }
+
+	    /*
 	     * to add delay jitter, must act here. A lower value
 	     * (bounded to 0) means lower delay.
 	     */
@@ -258,6 +267,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);
     }
@@ -512,10 +523,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) ;
@@ -527,6 +538,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) ;
@@ -543,6 +555,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.1
diff -u -r1.2.2.1 ip_dummynet.h
--- ip_dummynet.h	1999/01/25 19:19:28	1.2.2.1
+++ ip_dummynet.h	1999/03/28 16:34:54
@@ -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;
 };
 
 /*

----Next_Part(Mon_Mar_29_08:37:31_1999_595)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="ipfw.diff"

Index: sbin/ipfw/ipfw.c
===================================================================
RCS file: /usr/ncvs/src/sbin/ipfw/ipfw.c,v
retrieving revision 1.64.2.1
diff -u -r1.64.2.1 ipfw.c
--- ipfw.c	1999/01/25 19:17:07	1.64.2.1
+++ ipfw.c	1999/03/28 16:35:05
@@ -461,6 +461,7 @@
 		char buf[30] ;
 		char qs[30] ;
 		char plr[30] ;
+		char pps[30] ;
 		int l ;
 
 		if (rulenum != 0 && rulenum != p->pipe_nr)
@@ -485,9 +486,13 @@
 		    sprintf(plr,"plr %f", 1.0*p->plr/(double)(0x7fffffff));
 		else
 		    plr[0]='\0';
+		if (p->pps)
+		    sprintf(pps, "%d pkt/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);
@@ -977,6 +982,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(Mon_Mar_29_08:37:31_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?19990329083734O.nagao>