Beispiel #1
0
/* Use HTB as a upload qdisc.
 * dev is name of device to attach qdisc to (typically an IMQ)
 * upload_limit is in kbits/s
 * Some ideas here from Rudy's qos-scripts
 * http://forum.openwrt.org/viewtopic.php?id=4112&p=1
 */
static int
tc_attach_upload_qdisc(const char dev[], int upload_limit)
{
	int rc = 0;
	int burst;
	int mtu = MTU + 40;

	burst = upload_limit * 1000 / 8 / HZ; /* burst (buffer size) in bytes */
	burst = burst < mtu ? mtu : burst; /* but burst should be at least mtu */

	rc |= tc_do_command("qdisc add dev %s root handle 1: htb default 2 r2q %d", dev, 1700);
	rc |= tc_do_command("class add dev %s parent 1: classid 1:1 htb rate 100Mbps ceil 100Mbps burst %d cburst %d mtu %d",
						dev, burst*10, burst, mtu);
	rc |= tc_do_command("class add dev %s parent 1:1 classid 1:2 htb rate %dkbit ceil %dkbit burst %d cburst %d mtu %d prio 1",
						dev, upload_limit, upload_limit, burst*10, burst, mtu);

	return rc;
}
Beispiel #2
0
/* Use HTB as a download qdisc.
 * dev is name of device to attach qdisc to (typically an IMQ)
 * download_limit is in kbits/s
 * Some ideas here from Rudy's qos-scripts 
 * http://forum.openwrt.org/viewtopic.php?id=4112&p=1
 */
static int
tc_attach_download_qdisc(char *dev, int download_limit) {
  int burst;
  int mtu = MTU + 40;
  int rc = 0;
  int r2q = 10;

  /* to avoid some kernel warnings with small rates */
  if(download_limit < 120) r2q = 1;

  burst = download_limit * 1000 / 8 / HZ; /* burst (buffer size) in bytes */
  burst = burst < mtu ? mtu : burst; /* but burst should be at least mtu */
  

  rc |= tc_do_command("qdisc add dev %s root handle 1: htb default 1 r2q %d", dev, r2q);
  rc |= tc_do_command("class add dev %s parent 1: classid 1:1 htb rate %dkbit ceil %dkbit burst %d cburst %d mtu %d prio 1",
		      dev, download_limit, download_limit, burst*2, burst, mtu);
  return rc;

}