1.\" 2.\" $FreeBSD$ 3.\" 4.Dd September 28, 1998 5.Dt DUMMYNET 4 6.Os 7.Sh NAME 8.Nm dummynet 9.Nd flexible bandwidth manager and delay emulator 10.Sh SYNOPSIS 11.In sys/types.h 12.In sys/queue.h 13.In netinet/in.h 14.In netinet/ip_fw.h 15.Ft int 16.Fn setsockopt raw_socket IPPROTO_IP "ipfw option" "struct ipfw" size 17.Sh DESCRIPTION 18dummynet is a system facility that permits the control of traffic 19going through the various network interfaces, by applying bandwidth 20and queue size limitations, and simulating delays and losses. 21.Pp 22In its current implementation, 23packet selection is done with the 24.Nm ipfw 25program, by means of 26.Dq pipe 27rules. 28A dummynet 29.Em pipe 30is characterized by a bandwidth, delay, queue size, and loss 31rate, which can be configured with the 32.Nm ipfw 33program. 34Pipes are 35numbered from 1 to 65534, and packets can be passed through multiple 36pipes depending on the ipfw configuration. 37.Pp 38Dummynet operates at the ip level, but if bridging extensions are 39enabled, it is possible to pass bridged packets through pipes as well. 40.Sh USAGE 41Packets are sent to a pipe using the command 42.Bd -literal 43 ipfw add pipe NNN .... 44.Ed 45.Pp 46and pipes are configured as follows: 47.Bd -literal 48 ipfw pipe NNN config bw B delay D queue Q plr P 49.Ed 50.Pp 51where the bandwidth B can be expressed in bit/s, Kbit/s, Mbit/s, 52Bytes/s, KBytes/s, MBytes/s , delay in milliseconds, queue size in 53packets or Bytes, plr is the fraction of packets randomly dropped. 54.Pp 55Getting ipfw to work right is not very intuitive, especially when 56the system is acting as a router or a bridge. 57.Pp 58When acting as a router, the same ruleset is applied on both the 59input and the output path for routed packets, so you have to make 60sure that a packet does not go through the same pipe twice (unless 61this is what you really want). 62.Pp 63When acting as a bridge, the 64.Nm ipfw 65filter is invoked only once, in the input path, 66for bridged packets. 67.Pp 68Also, when simulating true full-duplex channels, be sure to pass 69traffic through two different pipes, depending on the direction. 70E.g. a suitable rule set for simulating an asymmetric bidirectional 71link would be the following: 72.Bd -literal 73 ipfw add pipe 1 ip from A to B out 74 ipfw add pipe 2 ip from B to A in 75 ipfw pipe 1 config bw 1Mbit/s delay 80ms 76 ipfw pipe 2 config bw 128Kbit/s delay 300ms 77.Ed 78.Sh OPERATION 79The 80.Nm ipfw 81code is used to select packets that must be subject to 82bandwidth/queue/delay/losses, and returns the identifier of 83the ``pipe'' describing such limitations. 84.Pp 85Selected packets are first queued in a bounded size queue, from which 86they are extracted at the programmed rate and passed to a second queue 87where delay is simulated. 88At the output from the second queue packets 89are reinjected into the protocol stack at the same point they came 90from (i.e. ip_input(), ip_output(), bdg_forward() ). 91Depending on the setting of the sysctl variable 92.Ql net.inet.ip.fw.one_pass , 93packets coming from a pipe can be either forwarded to their 94destination, or passed again through the 95.Nm ipfw 96rules, starting from the one after the matching rule. 97.Pp 98.Nm 99performs its task once per timer tick. 100The granularity of operation is 101thus controlled by the kernel option 102.Bd -literal 103 options HZ 104.Ed 105.Pp 106whose default value (100) means a granularity of 10ms. 107For an accurate simulation of high data rates it might be necessary to 108reduce the timer granularity to 1ms or less. 109Consider, however, 110that some interfaces using programmed I/O may require a considerable 111time to output packets. 112So, reducing the granularity too much might 113actually cause ticks to be missed thus reducing the accuracy of 114operation. 115.Sh KERNEL OPTIONS 116The following options in the kernel configuration file are related 117to 118.Nm 119operation: 120.Bd -literal 121 IPFIREWALL - enable ipfirewall (required for dummynet). 122 IPFIREWALL_VERBOSE - enable firewall output. 123 IPFIREWALL_VERBOSE_LIMIT - limit firewall output. 124 DUMMYNET - enable dummynet operation. 125 NMBCLUSTERS - set the amount of network packet buffers 126 HZ - sets the timer granularity 127.Ed 128.Pp 129Generally, the following options are required: 130.Bd -literal 131 options IPFIREWALL 132 options DUMMYNET 133.Ed 134.Pp 135additionally, one may want to increase the number 136of mbuf clusters (used to store network packets) according to the 137sum of the bandwidth-delay products and queue sizes of all configured 138pipes. 139.Sh SYSCTL VARIABLES 140.Ql net.inet.ip.fw.one_pass 141is set to 1 if we want packets to pass through the firewall code only 142once. 143.Pp 144.Ql net.link.ether.bridge_ipfw 145is set if we want bridged packets to pass through the firewall code. 146.Sh COMMANDS 147The following socket options are used to manage pipes: 148.Pp 149IP_DUMMYNET_CONFIGURE updates a pipe configuration (or creates a 150new one. 151.Pp 152IP_DUMMYNET_DEL deletes all pipes having the matching rule number. 153.Pp 154IP_DUMMYNET_GET returns the pipes matching the number. 155.Pp 156IP_FW_FLUSH flushes the pipes matching the number. 157.Pp 158When the kernel security level is greater than 2, only IP_DUMMYNET_GET 159is allowed. 160.Sh SEE ALSO 161.Xr setsockopt 2 , 162.Xr bridge 4 , 163.Xr ip 4 , 164.Xr ipfw 8 , 165.Xr sysctl 8 166.Sh BUGS 167This manpage is not illustrating all the possible ways to use 168dummynet. 169.Sh HISTORY 170.Nm 171was initially implemented as a testing tool for TCP congestion control 172by 173.An Luigi Rizzo Aq luigi@iet.unipi.it , 174as described on ACM Computer 175Communication Review, Jan.97 issue. 176Later it has been then modified 177to work at the ip and bridging level, and integrated with the IPFW 178packet filter. 179