From owner-freebsd-net Sat Jul 17 11:41:21 1999 Delivered-To: freebsd-net@freebsd.org Received: from mgo.iij.ad.jp (mgo.iij.ad.jp [202.232.15.6]) by hub.freebsd.org (Postfix) with ESMTP id 4B82814BD5 for ; Sat, 17 Jul 1999 11:41:17 -0700 (PDT) (envelope-from nagao@iij.ad.jp) Received: from ns.iij.ad.jp (root@ns.iij.ad.jp [192.168.2.8]) by mgo.iij.ad.jp (8.8.8/MGO1.0) with ESMTP id DAA16077; Sun, 18 Jul 1999 03:41:15 +0900 (JST) Received: from localhost (yuzu.iij.ad.jp [192.168.4.215]) by ns.iij.ad.jp (8.8.5/3.5Wpl7) with ESMTP id DAA10351; Sun, 18 Jul 1999 03:41:15 +0900 (JST) To: des@flood.ping.uio.no Cc: net@freebsd.org Subject: Re: dummynet -> rate limiting In-Reply-To: References: X-Mailer: Mew version 1.94b37 on Emacs 20.3 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Sun_Jul_18_03:40:17_1999_595)--" Content-Transfer-Encoding: 7bit Message-Id: <19990718034115X.nagao@iij.ad.jp> Date: Sun, 18 Jul 1999 03:41:15 +0900 (JST) From: NAGAO Tadaaki X-Dispatcher: imput version 990623(IM117) Lines: 163 Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org ----Next_Part(Sun_Jul_18_03:40:17_1999_595)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, In message , Dag-Erling Smorgrav 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 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