<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>delx &#187; voip</title>
	<atom:link href="http://delx.net.au/blog/tag/voip/feed/" rel="self" type="application/rss+xml" />
	<link>http://delx.net.au/blog</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 13 Apr 2012 14:05:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>OpenWRT and Guest Networks on the Netgear WNDR3700</title>
		<link>http://delx.net.au/blog/2011/06/openwrt-and-guest-networks-on-the-netgear-wndr3700/</link>
		<comments>http://delx.net.au/blog/2011/06/openwrt-and-guest-networks-on-the-netgear-wndr3700/#comments</comments>
		<pubDate>Wed, 15 Jun 2011 03:45:37 +0000</pubDate>
		<dc:creator>delx</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[openwrt]]></category>
		<category><![CDATA[voip]]></category>

		<guid isPermaLink="false">http://delx.net.au/blog/?p=283</guid>
		<description><![CDATA[In my house I have Debian Linux running on an old laptop acting as my router with a Netgear WNDR3700 acting as an access point (WAN port on this is unused). The AP is configured with WPA2 security, but recently I wanted to connect my Nintendo DS to the wifi network. Now the Netgear has [...]]]></description>
			<content:encoded><![CDATA[<p>In my house I have Debian Linux running on an old laptop acting as my router with a Netgear WNDR3700 acting as an access point (WAN port on this is unused). The AP is configured with WPA2 security, but recently I wanted to connect my Nintendo DS to the wifi network. Now the Netgear has guest networks, which is pretty much what I wanted, but it only allows the guest wifi access to the WAN port, which was useless to me. I also wanted to be able to conveniently enable and disable the insecure network with a button on the access point. Knowing that the hardware supported what I wanted to do, and having had good experiences with <a href="http://openwrt.org">OpenWRT</a> on another router in the past, I set out to see if I could make it work.</p>
<p><span id="more-283"></span></p>
<p>Now the Netgear factory firmware actually is a heavily stripped down old version of OpenWRT. After reading a few of forum posts and wiki pages I decided that I should go for a bleeding edge snapshot version of OpenWRT (r27153). It&#8217;s all working very well now :)</p>
<h4>Installation</h4>
<p>First thing, I grabbed <tt>openwrt-ar71xx-generic-wndr3700-squashfs-factory.img</tt> from the website and flashed it onto the router using the stock firmware&#8217;s upgrade page. This process went smoothly and rebooted the router. I then used telnet to connect and was prompted to set a password. That disabled telnetd and enables the dropbear ssh server. I also put an ssh public key into <tt>/etc/dropbear/authorized_keys</tt>. So far so good.</p>
<p>OpenWRT uses a squashfs as the base read-only filesystem, with jffs2 set up as an overlay filesystem so you can write to anywhere. You can use the builtin <tt>opkg</tt> package manager to install a bunch of useful software beyond what is built in. Currently I have 2.3M used with 4.2M free :)</p>
<p>I didn&#8217;t bother installing a web interface, instead preferring to do all the configuration using the UCI config files in <tt>/etc/config</tt>. See the <a href="http://wiki.openwrt.org/doc/uci">UCI docs</a> for a description of what to put in all these files. Whenever you start a service, eg dnsmasq using the <tt>/etc/init.d/dnsmasq</tt> script, the appropriate UCI files are read, a temporary native config file for the service is created (if appropriate) and any necessary command line args are generated to start the service.</p>
<h4>Syslog</h4>
<p>If you&#8217;re trying to debug something, you can view the syslog on the device using the <tt>logread</tt> command. The <tt>logger</tt> command will echo its arguments to syslog.</p>
<h4>Wireless Setup</h4>
<p>Most of the <tt>/etc/config/wireless</tt> settings are automatically detected. Just set the encryption to psk2 (WPA2 AES) and put in your preferred passphrase and ssid.</p>
<p>The radios on this device support multiple SSIDs. Each of these shows up as a separate network interface in Linux. I chose &#8216;guest&#8217; as the name for this interface.</p>
<pre>
config wifi-iface
  option device radio0
  option network guest
  option mode ap
  option wmm 0
  option encryption none
  option ssid 'your-guest-ssid'
</pre>
<p>Quick note, I discovered that leaving wmm (Wireless MultiMedia extensions?) enabled (the default) made SIP VoIP calls from my Nokia wifi clients unusable. It&#8217;s easy to disable as seen above.</p>
<h4>Firewall (iptables)</h4>
<p>Now we have our guest wifi network interface, lets set up some firewall rules to isolate it from the main lan.</p>
<p>I&#8217;m not using the WAN port on my WNDR3700. There are three interfaces that are relevant. The ethernet switch and my main wifi are both bridged as &#8216;lan&#8217;. This network is served by DHCP and DNS from my Debian router. It is 192.168.1.0/24. I also have the &#8216;guest&#8217; network, which is not bridged, and gets DHCP and DNS from dnsmasq on the WNDR3700, it uses 192.168.2.0/24. dnsmasq is set to forward DNS requests onto my main router and to explicitly ignore the &#8216;lan&#8217; interface.</p>
<p>The firewall policy is to disallow everything on the guest network except:</p>
<ul>
<li>ICMP</li>
<li>DHCP/DNS requests to dnsmasq on the WNDR3700</li>
<li>Packets from 192.168.2.0/24 not addressed to 192.168.0.0/16</li>
</ul>
<p>That last rule ensures that anything coming from the guest network must be using one of the expected addresses, and also that the guest network cannot send packets to hosts on my main lan. By default OpenWRT allows all related,established packets using Linux iptables&#8217; conntrack module.</p>
<p>Here&#8217;s the complete firewall config I&#8217;m using: <a href="/blog/wp-content/uploads/2011/06/etc_config_firewall.txt"><tt>/etc/config/firewall</tt></a>.</p>
<h4>Routing</h4>
<p>My Debian router also needs to know how to route back to the guest wlan subnet.</p>
<pre>
# route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.3
</pre>
<p>This can be put into <tt>/etc/network/interfaces</tt> as a post-up line. It tells the Debian router that whenever it needs to forward traffic from the internet back to the guest wlan it should do so through 192.168.1.3. This is the address of my WNDR3700.</p>
<h4>Cron and Button events</h4>
<p>I wanted to be able to turn the guest network on and off with the push of a button. I also wanted it to automatically disable itself each night at 3am if I forgot to turn it off.</p>
<p>First thing was to write a simple <a href="/blog/wp-content/uploads/2011/06/root_guest-wifi.txt">/root/guest-wifi</a> script to enable/disable the guest wifi network from the command line. Then I&#8217;d hook this up to the button hotplug system and cron.</p>
<p>Cron is installed but not enabled by default:</p>
<pre>
cat &gt; /etc/crontabs/root &lt;&lt;EOT
# m h  dom mon dow   command
  0 3   *   *   *     /root/guest-wifi disable
EOT
ln -s /etc/crontabs/root /etc/crontab
/etc/init.d/cron enable
/etc/init.d/cron start
</pre>
<p>Finally, set up the push button:</p>
<pre>
mkdir /etc/hotplug.d/button
cat &gt; /etc/hotplug.d/button/guest-wifi-toggle &lt;&lt;EOT
#!/bin/sh
if [ "$BUTTON" = "BTN_2" -a "$ACTION" = "pressed" ]; then
  /root/guest-wifi toggle
fi
EOT
chmod +x /etc/hotplug.d/button/guest-wifi-toggle
</pre>
<h4>System upgrades</h4>
<p>You can update and install new packages with opkg, however at some point you may want to upgrade the kernel. Also if you&#8217;re using the squashfs images, anything you upgrade is taking up valuable space on the squashfs and the jffs2 overlay.</p>
<p>OpenWRT has a neat solution: <a href="http://wiki.openwrt.org/doc/howto/generic.sysupgrade">sysupgrade</a>. Always make sure to add any files that you want to keep across upgrades to the <tt>/etc/sysupgrade.conf</tt> file. Any files or directories listed here will be preserved by sysupgrade.</p>
]]></content:encoded>
			<wfw:commentRss>http://delx.net.au/blog/2011/06/openwrt-and-guest-networks-on-the-netgear-wndr3700/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Linux Traffic Control &#8211; QoS</title>
		<link>http://delx.net.au/blog/2008/12/linux-traffic-control-qos/</link>
		<comments>http://delx.net.au/blog/2008/12/linux-traffic-control-qos/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 17:30:59 +0000</pubDate>
		<dc:creator>delx</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[shaping]]></category>
		<category><![CDATA[voip]]></category>

		<guid isPermaLink="false">http://delx.net.au/blog/?p=17</guid>
		<description><![CDATA[I recently started using VoIP, using NodePhone with Internode. This post describes how I implemented QoS on my router to make VoIP work well. It also allows me to prioritise some traffic on my network, such as SSH, while deprioritising others, such as BitTorrent and SFTP. Background You may want to skip this section initially [...]]]></description>
			<content:encoded><![CDATA[<p>I recently started using <acronym title="Voice over Internet Protocol">VoIP</acronym>, using <a href="http://www.internode.on.net/residential/nodephone">NodePhone</a> with <a href="http://www.internode.on.net">Internode</a>. This post describes how I implemented <acronym title="Quality of Service">QoS</acronym> on my router to make VoIP work well. It also allows me to prioritise some traffic on my network, such as SSH, while deprioritising others, such as BitTorrent and SFTP.</p>
<p><span id="more-17"></span></p>
<h3>Background</h3>
<p>You may want to skip this section initially and refer back to it if you come across a concept that you do not fully understand later in the document.</p>
<p>I assume that you have a working understanding of networking. This means you must know what an IP address is, what TCP is, and what the relationship of these to application level protocols HTTP and SSH is. IPv6 is not covered here but probably will be in the future.</p>
<p>QoS, or Quality of Service, is any mechanism for guaranteeing a particular amount of throughput or latency for some type of traffic.</p>
<p>VoIP is basically about making phone calls over your internet connection. NodePhone uses the SIP standard for this. It supports incoming and outgoing calls to the PSTN by giving you an extra phone number. Internode recommends getting a QoS equipped router, but I use a Linux PC as my router and was unwilling to switch for various reasons. Using VoIP without QoS is much like talking on a mobile phone while going through a subway. The call is jittery with frequent voice dropouts.</p>
<p>IP packets have a Type-Of-Service (TOS) field in them. Applications can set this field to values such as Minimise-Delay, or Maximise-Throughput. This allows applications such as BitTorrent to signal that they are more interested in throughput than latency, while an interactive SSH session (think typing at a shell) could signal the opposite. The default is for normal service.</p>
<p>Shaping is when we prioritise outgoing traffic. It is possible to do this really well because our router is in full control of what data is sent out onto the internet. It is possible to specify what rate packets should be sent at and in what order. Eg, VoIP packets before BitTorrent is a sensible rule.</p>
<p>Policing is attempting to enforce rules upon incoming data. This is not possible because we cannot directly influence how much data other computers will send our way. Instead what we do is drop packets that are coming in too fast in the hope that the sender will slow down. Thankfully this is exactly what TCP is designed to do, so this strategy works reasonably well. The aim here is to make your router into a bottleneck that is slightly slower than your internet connection so you influence over the rate at which different classes of packets come in.</p>
<h3>Goal</h3>
<p>I needed to set up QoS to prioritise the VoIP traffic on my network. The existing documentation is not exactly plentiful and while it was invaluable, I found it difficult to understand. There don&#8217;t seem to be any turnkey solutions that do QoS for Linux in the way that I wanted.</p>
<p>I have four categories of traffic.</p>
<ol>
<li>VoIP traffic &#8211; guaranteed 64Kbit, highest priority</li>
<li>High priority &#8211; interactive SSH sessions (not SFTP)</li>
<li>Normal priority &#8211; the default</li>
<li>Low priority &#8211; bulk data transfers like SFTP or BitTorrent</li>
</ol>
<p>If I&#8217;m on a phone call, that traffic absolutely needs priority over everything else. The packets from the VoIP phone call should never be dropped or delayed.</p>
<p>Immediately after that comes other high priority traffic. This is anything with the Minimise-Delay TOS bit set in the IP header. SSH sets Minimise-Delay for interactive shells, but not for SFTP/SCP. Very convenient. Be aware that if you use ControlMaster to piggyback SFTP on an existing SSH connection that the TOS bits are set per TCP connection. I also put ACK packets in here; one of these is sent for every packet that you download. If you&#8217;re doing a large upload then these tiny packets can get delayed, causing your download to slow down. I find it works well to give them a high priority.</p>
<p>Next priority is general traffic, this is the default bucket. By default all traffic goes in here. This includes web traffic, instant messaging, email, etc</p>
<p>Finally we have the data that we don&#8217;t care about at all. I&#8217;m a little nasty and dump any traffic with the Maximise-Throughput TOS bit set in here. That includes my BitTorrents (using <a href="http://libtorrent.rakshasa.no">rtorrent</a>) and SFTP/SCP traffic. This means that the traffic doesn&#8217;t really get it&#8217;s throughput maximised at all, but it works well for my purposes.</p>
<h3>Linux Traffic Control</h3>
<p>This is all done using the Linux Traffic Control system. It&#8217;s made up of a tree of queues, each with a specific algorithm for dequeuing packets.</p>
<p>Have a look at the <a href="http://delx.net.au/hg/jamesstuff/file/b005ac01417d/scripts/shaper">shaper script</a>. All of the rates in this file are specified in Kilobits/sec. You may need to read this text more than once.</p>
<p>I&#8217;m using the Hierarchical Token Bucket (HTB) for each of the four categories mentioned above. Each bucket has an associated rate, maximum rate and priority. The available outgoing bandwidth is measured and divided up amongst the different categories of traffic. The bucket gets a minimum throughput specified by &#8216;rate&#8217;, and a maximum specified by &#8216;ceil&#8217;. This maximum could be reached if one of the other buckets is not using its allowance. For example, while there is no VoIP traffic other buckets can use that 64Kbit allowance. Packets are dequeued from the buckets in order of the priority that each is given. Lower priorities first.</p>
<p>Next we add a Stochastical Fairness Queue (SFQ) to each bucket. The SFQ organises all packets it receives into sessions, like TCP connections, using a hashing algorithm. It dequeues packets from these sessions in a round-robin fashion. This means that if you have two connections they each receive an equal share of the available resources.</p>
<p>Packets are assigned to a particular queue/bucket by inspecting their header for source/dest addresses/ports as well as the TOS field.</p>
<p>Finally, some basic policing is applied to incoming traffic. Incoming VoIP traffic is never policed, but all other incoming traffic is policed at slightly less than the link&#8217;s maximum throughput. This forces the router to be the bottleneck and encourages the sender of any traffic that has been dropped to slow down.</p>
<p>QoS on incoming traffic really needs to be handled by your ISP, and while Internode claims that they do this, I found that I needed these policing rules for VoIP to work while large downloads were occurring. I suspect this is due to Internode not being able to provide proper QoS for my ADSL1 connection on a 1.5Mbit Telstra port.</p>
<h3>References</h3>
<ol>
<li><a href="http://delx.net.au/hg/jamesstuff/raw-file/tip/scripts/shaper">Shaper script</a> &#8211; latest version</li>
<li><a href="http://delx.net.au/hg/jamesstuff/file/b005ac01417d/scripts/shaper">Shaper script</a> &#8211; original version</li>
<li><a href="http://lartc.org/howto/">Linux Advanced Routing &amp; Traffic Control HOWTO</a></li>
<li><a href="http://rfc.sunsite.dk/rfc/rfc1349.html">RFC1349 &#8211; Type of Service in the Internet Protocol Suite</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://delx.net.au/blog/2008/12/linux-traffic-control-qos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

