<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Corelatus' Blog</title>
	<atom:link href="http://corelatus.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://corelatus.wordpress.com</link>
	<description>mostly narrowband telecommunications</description>
	<lastBuildDate>Wed, 07 Apr 2010 13:06:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='corelatus.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Corelatus' Blog</title>
		<link>http://corelatus.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://corelatus.wordpress.com/osd.xml" title="Corelatus&#039; Blog" />
	<atom:link rel='hub' href='http://corelatus.wordpress.com/?pushpress=hub'/>
		<item>
		<title>So long, wordpress</title>
		<link>http://corelatus.wordpress.com/2010/01/29/so-long-wordpress/</link>
		<comments>http://corelatus.wordpress.com/2010/01/29/so-long-wordpress/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 10:12:02 +0000</pubDate>
		<dc:creator>Matt Lang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.corelatus.com/2010/01/29/so-long-wordpress/</guid>
		<description><![CDATA[I no longer use wordpress to host this blog, I compile it to static files using chronicle instead. It&#8217;s still at the same address (blog.corelatus.com), though, so the only way to see this post is to stumble on it via &#8230; <a href="http://corelatus.wordpress.com/2010/01/29/so-long-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=116&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I no longer use wordpress to host this blog, I compile it to static files using chronicle instead. It&#8217;s still at the <a href='http://blog.corelatus.com/'>same address (blog.corelatus.com)</a>, though, so the only way to see this post is to stumble on it via a search engine.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/corelatus.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/corelatus.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/corelatus.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/corelatus.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/corelatus.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/corelatus.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/corelatus.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/corelatus.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/corelatus.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/corelatus.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/corelatus.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/corelatus.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/corelatus.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/corelatus.wordpress.com/116/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=116&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://corelatus.wordpress.com/2010/01/29/so-long-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deeae26c450dfdfc49174cfd396e6471?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">corelatus</media:title>
		</media:content>
	</item>
		<item>
		<title>Audio power levels on E1/T1 timeslots: the digital milliwatt</title>
		<link>http://corelatus.wordpress.com/2009/10/10/audio-power-levels-on-e1t1-timeslots-the-digital-milliwatt/</link>
		<comments>http://corelatus.wordpress.com/2009/10/10/audio-power-levels-on-e1t1-timeslots-the-digital-milliwatt/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 19:33:52 +0000</pubDate>
		<dc:creator>Matt Lang</dc:creator>
				<category><![CDATA[GTH]]></category>
		<category><![CDATA[Telecom signalling]]></category>

		<guid isPermaLink="false">http://blog.corelatus.com/?p=97</guid>
		<description><![CDATA[Sometimes, you want to know when the audio on an E1/T1 timeslot has gotten louder than some limit. In a voice mail application, that&#8217;s useful for catching mistakes such as a subscriber leaving a message but then not hanging up &#8230; <a href="http://corelatus.wordpress.com/2009/10/10/audio-power-levels-on-e1t1-timeslots-the-digital-milliwatt/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=97&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sometimes, you want to know when the audio on an E1/T1 timeslot has gotten louder than some limit. In a voice mail application, that&#8217;s useful for catching mistakes such as a subscriber leaving a message but then not hanging up the phone properly&#8212;you don&#8217;t want to record hours and hours of silence. In an IVR application, you might want to keep an eye on the audio level so that a frustrated (shouting!) subscriber can be forwarded to a human operator.</p>
<p>GTH provides a &#8220;level detector&#8221; to do that sort of thing. You start a level detector on a timeslot, give it a loudness threshold, and it&#8217;ll notify you whenever the audio on the timeslot goes over that threshold. Here&#8217;s an example command which notifies you if the power on timeslot 13 of an E1/T1 is louder than -20dBm0:</p>
<p><code><br />
  &lt;new&gt;&lt;level_detector threshold='-20'&gt;<br />
     &lt;pcm_source span='2A' timeslot='13'/&gt;<br />
  &lt;/level_detector&gt;&lt;/new&gt;<br />
</code></p>
<p>The algorithm is:</p>
<p><code><br />
   Take a 100ms block of audio (800 samples)<br />
   Square all the samples<br />
   Sum the squares<br />
   If the sum exceeds the loudness threshold, send an XML event<br />
</code></p>
<p>There are some details to worry about.</p>
<h3>The digital milliwatt</h3>
<p>The threshold, e.g. -20 in the example above, has to be relative to something. The standard reference power level in telecommunications is the milliwatt.  ITU-T G.711, table 5 and 6 defines the sequences which represent a milliwatt:</p>
<p>A-law: 34 21 21 34 b4 a1 a1 b4<br />
&mu;-law: 1e 0b 0b 1e 9e 8b 8b 9e.</p>
<p>Here&#8217;s what a few periods of the digital milliwatt look like:</p>
<p><img src="http://corelatus.files.wordpress.com/2009/10/small_linear_milliwatt.png?w=384&#038;h=288" alt="small_linear_milliwatt" title="small_linear_milliwatt" width="384" height="288" class="alignnone size-full wp-image-102" /></p>
<p>In this post, the unit &#8216;dBm0&#8242; means power, in dB relative to the digital milliwatt, as defined by the sequences above. If you have no idea what dB means, wikipedia has a <a href="http://en.wikipedia.org/wiki/Decibel">decent article</a>.</p>
<h3>What&#8217;s the loudest possible sound on a timeslot?</h3>
<p>170 is the highest value possible in A-law encoding. It corresponds to linear 4032. That&#8217;s about 6dB louder than the digital milliwatt.</p>
<p>85 is the smallest value possible in A-law encoding. It corresponds to linear -1. That&#8217;s about 66dB softer than the digital milliwatt.</p>
<p>The range -66dBm0&#8230;+6dBm0 sets an upper bound on the range of power on a timeslot. Then there are other things which further limit the practical range, so you&#8217;re unlikely to actually use a +6dBm0 threshold in practice, but it&#8217;s there if you want it.</p>
<h3>Is the G.711 definition the best one?</h3>
<p>The sequence given in G.711 is a 1kHz sine wave. The sampling rate on E1/T1 is 8kHz, so the reference sequence can be expressed in just eight values. That&#8217;s nice, but that also leads to small errors, about 0.13dB, because of quantisation.</p>
<p>ITU-T O.133 discusses that problem in detail and proposes a test signal which specfically is <b>not</b> 1kHz (i.e. not a submultiple of the sampling rate). For most practical purposes, 0.13dB doesn&#8217;t matter and so the simple and robust thing to do is to use the well-defined and well-known G.711 sequence as a reference.</p>
<p>Here&#8217;s what a few periods of a 1020Hz signal look like. Notice that the samples, i.e. the red crosses, don&#8217;t appear in the same spot one period later&#8212;that way we don&#8217;t get the same errors over and over again.</p>
<div id="attachment_106" class="wp-caption aligncenter" style="width: 394px"><a href="http://corelatus.files.wordpress.com/2009/10/small_1020hz1.png"><img src="http://corelatus.files.wordpress.com/2009/10/small_1020hz1.png?w=384&#038;h=288" alt="1020Hz signal sampled at 125us intervals" title="small_1020Hz" width="384" height="288" class="size-full wp-image-106" /></a><p class="wp-caption-text">1020Hz signal sampled at 125us intervals</p></div>
<h3>Testing pitfall: the .wav header</h3>
<p>GTH <em>player</em>s play raw A-law or &mu;-law data. If you feed a player a .wav file in 8kHz A-law, or &mu;-law if your network uses &mu;-law, there will be a very short bit of noise at the start of the playback because the .wav header gets treated as though it were audio.</p>
<p>When testing level detection, especially at quiet levels, that header noise is enough to trigger a detector. Here&#8217;s a .wav of a 1000Hz sine wave at about -30dBm0:</p>
<pre>
00000000  52 49 46 46 42 27 00 00  57 41 56 45 66 6d 74 20  |RIFFB'..WAVEfmt |
00000010  12 00 00 00 06 00 01 00  40 1f 00 00 40 1f 00 00  |........@...@...|
00000020  01 00 08 00 00 00 66 61  63 74 04 00 00 00 10 27  |......fact.....'|
00000030  00 00 64 61 74 61 10 27  00 00 d5 c4 f5 f1 f3 f1  |..data.'........|
00000040  f5 c4 d5 44 75 71 73 71  75 44 d5 c4 f5 f1 f3 f1  |...DuqsquD......|
*
00002740  f5 c4 d5 44 75 71 73 71  75 44                    |...DuqsquD|
</pre>
<p>The first 58 octets (bytes) are the header. If we turn that header into a periodic signal, it&#8217;s at about -8dBm0, which is fairly loud. With the default <em>period</em> parameter of 100ms in the level detector, that&#8217;ll cause a false level of about -11dBm0.</p>
<h3>The period parameter</h3>
<p>The <em>level_detector</em> has an optional parameter, the period. The period sets the size of the audio block the GTH considers when measuring the power. A short <em>period</em> makes the GTH responsive to sudden changes in power on the timeslot, which would be useful in an application such as figuring out which of the people in a conference call are currently talking. A long <em>period</em> averages out the power over a longer time, which is useful in deciding whether a voicemail recording has finished.</p>
<p>The default is 100ms.</p>
<h3>Sample files</h3>
<p><a href="http://www.corelatus.com/blog/milliwatt_reference.zip">This .zip file</a> contains sample recordings with 1kHz sine waves at 0, -10, -20, -30, -40 and -50 dBm0. The .wav versions are useful for listening to or importing into an audio editing program to calibrate the level meter. The .raw versions are just plain A-law samples&#8212;you can use them with a GTH player.</p>
<p>(Aside: wordpress.com won&#8217;t let me put audio files here. I don&#8217;t know whether that&#8217;s because they don&#8217;t want people filling up their servers with audio, or if it&#8217;s to avoid record label copyright claims. You never know, someone might have a claim on a 1kHz sine wave&#8230;).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/corelatus.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/corelatus.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/corelatus.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/corelatus.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/corelatus.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/corelatus.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/corelatus.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/corelatus.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/corelatus.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/corelatus.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/corelatus.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/corelatus.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/corelatus.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/corelatus.wordpress.com/97/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=97&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://corelatus.wordpress.com/2009/10/10/audio-power-levels-on-e1t1-timeslots-the-digital-milliwatt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deeae26c450dfdfc49174cfd396e6471?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">corelatus</media:title>
		</media:content>

		<media:content url="http://corelatus.files.wordpress.com/2009/10/small_linear_milliwatt.png" medium="image">
			<media:title type="html">small_linear_milliwatt</media:title>
		</media:content>

		<media:content url="http://corelatus.files.wordpress.com/2009/10/small_1020hz1.png" medium="image">
			<media:title type="html">small_1020Hz</media:title>
		</media:content>
	</item>
		<item>
		<title>How does TCP behave on an interrupted network?</title>
		<link>http://corelatus.wordpress.com/2009/08/27/how-does-tcp-behave-on-an-interrupted-network/</link>
		<comments>http://corelatus.wordpress.com/2009/08/27/how-does-tcp-behave-on-an-interrupted-network/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 13:49:13 +0000</pubDate>
		<dc:creator>Matt Lang</dc:creator>
				<category><![CDATA[GTH]]></category>
		<category><![CDATA[Questions from customers]]></category>

		<guid isPermaLink="false">http://blog.corelatus.com/?p=83</guid>
		<description><![CDATA[GTH E1/T1 modules are always controlled by a general-purpose server, usually some sort of unix machine. The server and GTH are connected by ethernet and communicate using TCP sockets. Normally, that ethernet connection is chosen to be simple and reliable, &#8230; <a href="http://corelatus.wordpress.com/2009/08/27/how-does-tcp-behave-on-an-interrupted-network/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=83&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>GTH E1/T1 modules are always controlled by a general-purpose server, usually some sort of unix machine. The server and GTH are connected by ethernet and communicate using TCP sockets. Normally, that ethernet connection is chosen to be simple and reliable, for instance by putting the server and the GTH in the same rack, connected to the same ethernet switch. </p>
<p>I experimented a bit to see what happens when that network gets interrupted. I<br />
interrupted the network in a reproduceable way by disabling and re-enabling the server&#8217;s ethernet port for a known length of time while running a &lt;recorder&gt;. (A &lt;recorder&gt; sends all the data, typically someone talking, from an E1 timeslot to the server over a TCP socket, 8000 octets per second.)</p>
<h3>Capturing the ethernet packets</h3>
<p>Here&#8217;s what I did to capture traffic and interrupt the ethernet:</p>
<p>  <code><br />
  tcpdump -w /tmp/capture.pcap -s 0 not port 22<br />
  sudo ifconfig eth0 down; sleep 5; sudo ifconfig eth0 up<br />
  </code></p>
<h3>A trace where traffic recovers in time to prevent an overrun</h3>
<p>The GTH buffers about two seconds of timeslot traffic. So a &#8216;sleep&#8217; of<br />
about a second won&#8217;t result in an overrun. Here&#8217;s what it looks like in wireshark:</p>
<table>
<tr>
<td>Packet</td>
<td>Time</td>
<td>Direction</td>
<td>Flags</td>
<td>Seq. #</td>
</tr>
<tr>
<td colspan="5">
<hr /></td>
</tr>
<tr>
<td>133 </td>
<td>  7.596 </td>
<td>  GTH -&gt; server</td>
<td> [PSH, ACK] </td>
<td>59393</td>
</tr>
<tr>
<td>134 </td>
<td>  7.633 </td>
<td>  server -&gt; GTH</td>
<td> [ACK]      </td>
<td>1    </td>
</tr>
<tr>
<td>135 </td>
<td>  7.724 </td>
<td>  GTH -&gt; server</td>
<td> [PSH, ACK] </td>
<td>60417</td>
</tr>
<tr>
<td>136 </td>
<td>  7.761 </td>
<td>  server -&gt; GTH</td>
<td> [ACK]      </td>
<td>1	       </td>
</tr>
<tr>
<td>137 </td>
<td>  7.852 </td>
<td>  GTH -&gt; server</td>
<td> [PSH, ACK] </td>
<td>61441</td>
</tr>
<tr>
<td>138 </td>
<td>  7.889 </td>
<td>  server -&gt; GTH</td>
<td> [ACK] </td>
<td>1	       </td>
</tr>
<tr>
<td>139 </td>
<td>  7.980 </td>
<td>  GTH -&gt; server</td>
<td> [PSH, ACK] </td>
<td>62465</td>
</tr>
<tr>
<td>140 </td>
<td>  8.017 </td>
<td>  server -&gt; GTH</td>
<td> [ACK] </td>
<td>1	       </td>
</tr>
<tr>
<td>141 </td>
<td>  8.108 </td>
<td>  GTH -&gt; server</td>
<td> [PSH, ACK] </td>
<td>63489</td>
</tr>
<tr>
<td>142 </td>
<td>  8.145 </td>
<td>  server -&gt; GTH</td>
<td> [ACK] </td>
<td>1	       </td>
</tr>
<tr>
<td>143 </td>
<td>  8.236 </td>
<td>  GTH -&gt; server</td>
<td> [PSH, ACK] </td>
<td>64513</td>
</tr>
<tr>
<td>144 </td>
<td>  8.273 </td>
<td>  server -&gt; GTH</td>
<td> [ACK] </td>
<td>1	       </td>
</tr>
<tr>
<td>145 </td>
<td>  8.364 </td>
<td>  GTH -&gt; server</td>
<td> [PSH, ACK] </td>
<td>65537</td>
</tr>
<tr>
<td>146 </td>
<td>  8.401 </td>
<td>  server -&gt; GTH</td>
<td> [ACK] </td>
<td>1	       </td>
</tr>
<tr>
<td>147 </td>
<td> 10.151 </td>
<td>  GTH -&gt; server</td>
<td> [PSH, ACK] </td>
<td>66561</td>
</tr>
<tr>
<td>148 </td>
<td> 10.151 </td>
<td>  server -&gt; GTH</td>
<td> [ACK] </td>
<td>1	       </td>
</tr>
<tr>
<td>149 </td>
<td> 10.151 </td>
<td>  GTH -&gt; server</td>
<td> [ACK] </td>
<td>67585     </td>
</tr>
<tr>
<td>150 </td>
<td> 10.151 </td>
<td>  server -&gt; GTH</td>
<td> [ACK] </td>
<td>1         </td>
</tr>
</table>
<p>Everything up to packet 146 is normal: the GTH (172.16.2.5) sends 8000 octets every second and the server (172.16.2.1) acks them. It happens to be in chunks of 1024 octets about eight times per second. After packet 146, about 8.4 seconds after the capture started, the ethernet interface went down and stayed down for 1s. The TCP stream started up again after about 1.5s and then &#8216;caught up&#8217; by sending many packets in quick succession.</p>
<h3>A trace where traffic didn&#8217;t recover</h3>
<p>I took a second trace similar to the first one, except this time, I disabled ethernet for about five seconds:</p>
<pre>
Packet Time     Source IP     Dest IP    SPort   DPort
----------------------------------------------------------------------
 28   1.040083  172.16.2.5 -&gt; 172.16.2.1 54271 &gt; 45195 [PSH, ACK] Seq=7169
 29   1.040095  172.16.2.1 -&gt; 172.16.2.5 45195 &gt; 54271 [ACK] Seq=1
 30   1.168065  172.16.2.5 -&gt; 172.16.2.1 54271 &gt; 45195 [PSH, ACK] Seq=8193
 31   1.168078  172.16.2.1 -&gt; 172.16.2.5 45195 &gt; 54271 [ACK] Seq=1
 32   1.296067  172.16.2.5 -&gt; 172.16.2.1 54271 &gt; 45195 [PSH, ACK] Seq=9217
 33   1.296079  172.16.2.1 -&gt; 172.16.2.5 45195 &gt; 54271 [ACK] Seq=1
 34   1.424068  172.16.2.5 -&gt; 172.16.2.1 54271 &gt; 45195 [PSH, ACK] Seq=10241
 35   1.424081  172.16.2.1 -&gt; 172.16.2.5 45195 &gt; 54271 [ACK] Seq=1
 36   7.782851  172.16.2.5 -&gt; 172.16.2.1 54271 &gt; 45195 [PSH, ACK] Seq=11265
 37   7.782863  172.16.2.1 -&gt; 172.16.2.5 45195 &gt; 54271 [ACK] Seq=1
 38   7.783406  172.16.2.5 -&gt; 172.16.2.1 54271 &gt; 45195 [ACK] Seq=12289
 39   7.783413  172.16.2.1 -&gt; 172.16.2.5 45195 &gt; 54271 [ACK] Seq=1
 40   7.783569  172.16.2.5 -&gt; 172.16.2.1 54271 &gt; 45195 [ACK] Seq=13737
...
 50   7.784962  172.16.2.5 -&gt; 172.16.2.1 54271 &gt; 45195 [FIN, PSH, ACK] Seq=23873
 51   7.784972  172.16.2.1 -&gt; 172.16.2.5 45195 &gt; 54271 [ACK] Seq=1
 52   7.785026  172.16.2.1 -&gt; 172.16.2.5 45195 &gt; 54271 [FIN, ACK] Seq=1
 53   7.785348  172.16.2.5 -&gt; 172.16.2.1 54271 &gt; 45195 [ACK] Seq=25322
</pre>
<p>Everything is normal up to packet 35. Then, ethernet is suspended for five seconds and TCP takes a further second to recover, which causes a buffer overrun on the GTH (172.16.2.5). The GTH closes the socket at packet 50 and also sends an overrun event to the application so that it knows why the socket was closed.</p>
<h3>Bottom line</h3>
<p>GTH uses IP for control and traffic. It is important that the IP link between the GTH and the server is simple and reliable. Ideally the GTH and server should be in the same rack and be connected by an ethernet switch.</p>
<p>It&#8217;s possible for a system to survive a short interruption (less than a second) to the ethernet traffic without pre-recorded calls getting interrupted. For longer interruptions, all bets are off.</p>
<p>(Interruptions aren&#8217;t the only type of network problem, e.g. radio networks such as 802.11 can suffer significant packet loss, which can trigger TCP congestion avoidance. But that&#8217;s another topic.)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/corelatus.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/corelatus.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/corelatus.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/corelatus.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/corelatus.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/corelatus.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/corelatus.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/corelatus.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/corelatus.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/corelatus.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/corelatus.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/corelatus.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/corelatus.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/corelatus.wordpress.com/83/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=83&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://corelatus.wordpress.com/2009/08/27/how-does-tcp-behave-on-an-interrupted-network/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deeae26c450dfdfc49174cfd396e6471?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">corelatus</media:title>
		</media:content>
	</item>
		<item>
		<title>Capturing SS7 with wireshark or tshark</title>
		<link>http://corelatus.wordpress.com/2009/08/10/capturing-ss7-with-wireshark-or-tshark/</link>
		<comments>http://corelatus.wordpress.com/2009/08/10/capturing-ss7-with-wireshark-or-tshark/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 18:40:39 +0000</pubDate>
		<dc:creator>Matt Lang</dc:creator>
				<category><![CDATA[Questions from customers]]></category>
		<category><![CDATA[Telecom signalling]]></category>

		<guid isPermaLink="false">http://blog.corelatus.com/?p=77</guid>
		<description><![CDATA[I often use wireshark to look at SS7 signalling on E1 links. Up until today, I&#8217;ve always done that by capturing the signalling (from a GTH), then converting the captured data to libpcap format and finally loading the file into &#8230; <a href="http://corelatus.wordpress.com/2009/08/10/capturing-ss7-with-wireshark-or-tshark/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=77&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I often use wireshark to look at SS7 signalling on E1 links. Up until today, I&#8217;ve always done that by capturing the signalling (from a GTH), then converting the captured data to libpcap format and finally loading the file into wireshark.</p>
<p>Someone showed me a better way today: wireshark can read from a pipe or from standard input. That lets me see and filter the packets in wireshark in real time. Here&#8217;s how to do it, using the save_to_pcap demo program (included in <a href="http://www.corelatus.com/gth/api/gth_c_examples.zip">gth_c_examples</a>):</p>
<pre>
&gt; ./save_to_pcap gth21 1A 2A 16 - | wireshark -k -i -
capturing packets, press ^C to abort
saving capture to stdout
</pre>
<p>The same thing works for tshark:</p>
<pre>
 &gt;./save_to_pcap gth21 1A 2A 16 - | tshark -V -i -
capturing packets, press ^C to abort
saving capture to stdout
Capturing on -
Frame 1 (15 bytes on wire, 15 bytes captured)
    Arrival Time: Aug 10, 2009 20:38:29.388000000
...
   Message Transfer Part Level 2
    .000 1101 = Backward sequence number: 13
    1... .... = Backward indicator bit: 1
    .011 1000 = Forward sequence number: 56
    1... .... = Forward indicator bit: 1
    ..00 0000 = Length Indicator: 0
    00.. .... = Spare: 0
...
</pre>
<h3>A few rough edges</h3>
<p>Piping to wireshark/tshark works on all the *nixes, i.e. linux, BSD, OSX, Solaris, but for some reason it doesn&#8217;t work on windows. On Windows, you have to save the pcap files and open them. I&#8217;m not sure why that is, but then again I rarely use windows, so maybe there&#8217;s some easy way around that. If someone knows, send me some mail, or comment.</p>
<p>Wireshark needs both the -i and -k switches for piping to work. That took me a while to figure out. Seems unnecessary.</p>
<p>On some older (as of August 2009) versions of wireshark, possibly in combination with older libraries, the &#8220;-i -&#8221; switch doesn&#8217;t work, at least according to google, even though the tshark version works. Both work fine for me on Debian Linux.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/corelatus.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/corelatus.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/corelatus.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/corelatus.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/corelatus.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/corelatus.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/corelatus.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/corelatus.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/corelatus.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/corelatus.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/corelatus.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/corelatus.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/corelatus.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/corelatus.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=77&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://corelatus.wordpress.com/2009/08/10/capturing-ss7-with-wireshark-or-tshark/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deeae26c450dfdfc49174cfd396e6471?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">corelatus</media:title>
		</media:content>
	</item>
		<item>
		<title>Generating DTMF using a &#8216;player&#8217; on GTH</title>
		<link>http://corelatus.wordpress.com/2009/06/09/generating-dtmf-using-a-player-on-gth/</link>
		<comments>http://corelatus.wordpress.com/2009/06/09/generating-dtmf-using-a-player-on-gth/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 10:31:17 +0000</pubDate>
		<dc:creator>Matt Lang</dc:creator>
				<category><![CDATA[GTH]]></category>
		<category><![CDATA[Questions from customers]]></category>
		<category><![CDATA[Telecom signalling]]></category>

		<guid isPermaLink="false">http://blog.corelatus.com/?p=63</guid>
		<description><![CDATA[The GTH can transmit in-band signalling tones on a timeslot. That&#8217;s useful for testing and for building active in-band signalling systems. DTMF The tones transmitted when the subscriber presses a number key on fixed or mobile handset are called DTMF. &#8230; <a href="http://corelatus.wordpress.com/2009/06/09/generating-dtmf-using-a-player-on-gth/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=63&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The GTH can <em>transmit</em> in-band signalling tones on a timeslot. That&#8217;s useful for testing and for building active in-band signalling systems.</p>
<h3>DTMF</h3>
<p>The tones transmitted when the subscriber presses a number key on fixed or mobile handset are called DTMF. Wikipedia has an <a href="http://en.wikipedia.org/wiki/DTMF">article</a> about it. To generate DTMF, all we really need to know is that there are 16 possible DTMF signals, that each signal is made up of two sine waves of particular frequencies and that sending the signal for 100ms is a reasonable thing to do.</p>
<p>Here&#8217;s a .zip file with <a href="http://www.corelatus.com/~matthias/blog/dtmf_tones.zip">DTMF tones</a> in it. Each file is raw ALAW data, i.e. it&#8217;s ready for the GTH to play (transmit) on a timeslot.</p>
<p>The GTH has two ways of playing tones. One way is to stream the audio data in over a TCP socket each time we want to play it. I wrote a <a href="http://blog.corelatus.com/2009/03/06/gth-audio-streaming-why-stream-over-tcp/">post about that</a> earlier. The other way is to store the sample data on the GTH and command its playback whenever it&#8217;s needed. Since there&#8217;s a small number of different tones (12, or 16 if you want to use the A/B/C/D tones as well) and the tones are short, storing them on the GTH makes sense. To store the tone:</p>
<p><code><br />
&lt;new&gt;&lt;clip&nbsp;name='dtmf5'/&gt;&lt;/new&gt;&nbsp;<br />
(and now send the 800 byte file)<br />
</code></p>
<p>to play the tone later on:</p>
<p><code><br />
&lt;new&gt;&lt;player&gt;&lt;clip&nbsp;id='clip&nbsp;dtmf5'/&gt;&lt;pcm_sink&nbsp;span='3A'&nbsp;timeslot='19'/&gt;&lt;/player&gt;&lt;/new&gt;&nbsp;<br />
</code></p>
<h3>Sequences of tones</h3>
<p>Sometimes you want to transmit a sequence of DTMF tones, for instance to simulate a subscriber dialling a number. The GTH lets you start a player with a sequence of tones like this:</p>
<p><code><br />
&lt;new&gt;&lt;player&gt;&lt;clip&nbsp;id='clip&nbsp;dtmf5'/&gt;&lt;clip&nbsp;id='clip&nbsp;dtmf6'/&gt;&lt;clip&nbsp;id='clip&nbsp;dtmf8'/&gt;&lt;pcm_sink&nbsp;span='3A'&nbsp;timeslot='19'/&gt;&lt;/player&gt;&lt;/new&gt;&nbsp;<br />
</code></p>
<p>But that isn&#8217;t a valid sequence of DTMF tones. Why not? Because DTMF expects a gap between tones. The cleanest way to handle that is to define another clip consisting of just silence and putting it between each tone. A good &#8216;silence&#8217; value on E1 lines is 0&#215;54. 60ms (480 samples) is a reasonable length.</p>
<h3>Other in-band tones</h3>
<p>DTMF in-band signalling is used in pretty much all handsets (telephones), mostly for dialling, but also to navigate menus in IVR systems. But before SS7 became popular, in-band signalling in the form of CAS and SS5 was even used to communicate call setup information between exchanges. GTH can also generate those tones, but that can be the subject of another post.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/corelatus.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/corelatus.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/corelatus.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/corelatus.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/corelatus.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/corelatus.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/corelatus.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/corelatus.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/corelatus.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/corelatus.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/corelatus.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/corelatus.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/corelatus.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/corelatus.wordpress.com/63/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=63&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://corelatus.wordpress.com/2009/06/09/generating-dtmf-using-a-player-on-gth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deeae26c450dfdfc49174cfd396e6471?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">corelatus</media:title>
		</media:content>
	</item>
		<item>
		<title>Perl example code for GTH: SS7 ISUP decoding and playback/record</title>
		<link>http://corelatus.wordpress.com/2009/05/28/perl-example-code-for-gth-isup-decoding-and-playbackrecord/</link>
		<comments>http://corelatus.wordpress.com/2009/05/28/perl-example-code-for-gth-isup-decoding-and-playbackrecord/#comments</comments>
		<pubDate>Thu, 28 May 2009 21:25:45 +0000</pubDate>
		<dc:creator>Matt Lang</dc:creator>
				<category><![CDATA[GTH]]></category>

		<guid isPermaLink="false">http://blog.corelatus.com/?p=69</guid>
		<description><![CDATA[To help people get started, www.corelatus.com has some example code for doing useful things with GTH units. Now it also has Perl example code. It does the same thing as the python examples: Enable an E1/T1 port Start MTP-2 monitoring &#8230; <a href="http://corelatus.wordpress.com/2009/05/28/perl-example-code-for-gth-isup-decoding-and-playbackrecord/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=69&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>To help people get started, www.corelatus.com has some example code for doing useful things with GTH units.</p>
<p>Now it also has Perl example code. It does the same thing as the python examples:</p>
<ul>
<li>Enable an E1/T1 port
</li>
<li>Start MTP-2 monitoring on a timeslot and decode SS7 ISUP (to print out when calls start and stop). I wrote a post a while back about <a href="http://blog.corelatus.com/2009/03/25/decoding-mtp-3-and-isup/">how to decode ISUP</a>.
</li>
<li>Dump the contents of a timeslot to a file (for later analysis)
</li>
<li>Feed a file into a timeslot (for playback of previously captured files)
</li>
</ul>
<p>It&#8217;s built on top of a Perl module which provides a Perl API for a subset of the <a href="http://www.corelatus.com/gth/api/">GTH API</a>.</p>
<h3>A quick example</h3>
<p>Here&#8217;s a quick example of how it&#8217;s used. We want to enable (turn on) the first E1/T1 interface on a GTH module:</p>
<p><code><br />
my $api = gth_control-&gt;new($host);<br />
$api-&gt;send("&lt;set name='pcm$span'&gt;&lt;attribute name='mode' value='E1'/&gt;&lt;/set&gt;");<br />
defined $api-&gt;next_non_event()-&gt;{ok} || die("error from GTH (bogus PCM?)");<br />
$api-&gt;bye();<br />
</code></p>
<h3>It&#8217;s good for experimenting.</h3>
<p>The Perl module the examples are based on, gth_control.pm, is at a level which makes it useful for experiments and prototypes. To build a full-fledged product on top of it, more work is needed.</p>
<p>For a start, you&#8217;d probably want to move the XML generation (like the &#8216;&lt;set name=&#8230;&#8217; code above) out of the application code and into the gth_control.pm module, thus making it a pure Perl interface.</p>
<p>Next, you need to come up with a strategy to deal with concurrency, because being limited to recording one timeslot at a time is fine for lab work, but not fine for (say) a voicemail system.</p>
<h3>Download</h3>
<p>The zipfile of the code is linked from the bottom of the <a href="http://www.corelatus.com/gth/api/">API page</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/corelatus.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/corelatus.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/corelatus.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/corelatus.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/corelatus.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/corelatus.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/corelatus.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/corelatus.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/corelatus.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/corelatus.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/corelatus.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/corelatus.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/corelatus.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/corelatus.wordpress.com/69/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=69&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://corelatus.wordpress.com/2009/05/28/perl-example-code-for-gth-isup-decoding-and-playbackrecord/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deeae26c450dfdfc49174cfd396e6471?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">corelatus</media:title>
		</media:content>
	</item>
		<item>
		<title>Decoding MTP-3 and ISUP</title>
		<link>http://corelatus.wordpress.com/2009/03/25/decoding-mtp-3-and-isup/</link>
		<comments>http://corelatus.wordpress.com/2009/03/25/decoding-mtp-3-and-isup/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 16:38:18 +0000</pubDate>
		<dc:creator>Matt Lang</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[GTH]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Telecom signalling]]></category>

		<guid isPermaLink="false">http://blog.corelatus.com/?p=43</guid>
		<description><![CDATA[Sometimes, you want to look at the signalling on an E1 and use it to figure out when telephone calls start and stop. In SS7 networks, call setup and tear-down is done by the ISUP layer, which fits in to &#8230; <a href="http://corelatus.wordpress.com/2009/03/25/decoding-mtp-3-and-isup/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=43&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sometimes, you want to look at the signalling on an E1 and use it to figure out when telephone calls start and stop. In SS7 networks, call setup and tear-down is done by the ISUP layer, which fits in to the SS7 stack like this:</p>
<p>Layer 4: ISUP<br />
Layer 3: MTP-3<br />
Layer 2: MTP-2<br />
Layer 1: MTP-1 (typically an 2Mbit/s E1 or a 1.5Mbit/s/T1)</p>
<p>If you have a <a href="http://www.corelatus.com/">GTH</a> connected to the E1 you&#8217;re interested in, either via a DXC or a monitor point, the GTH takes care of layers one and two. That leaves MTP-3 and ISUP to you.</p>
<p>The easiest way to decode MTP-3 and ISUP is to let <a href="http://www.wireshark.org/">wireshark</a> do it for you. There&#8217;s a <a href="//www.corelatus.com/gth/api/save_to_pcap/index.html">note</a> about how to do that on Corelatus&#8217; official site. But this blog entry is about how to decode MTP-3 and ISUP yourself.</p>
<h3>A signal unit (packet)</h3>
<p>In SS7, packets are usually called &#8220;signal units&#8221;. Here&#8217;s what an SS7 signal unit looks like &#8216;on the wire&#8217;, octet by octet, with MTP-2 and MTP-1 already decoded:<br />
<code><br />
8d c8 1f 85 02 40 00 00  35 00 01 00 21 00 0a 02<br />
02 08 06 01 10 12 52 55  21 0a 06 07 01 11 13 53<br />
55 00 6e 00<br />
</code></p>
<h3>MTP-3</h3>
<p>The start of the packet is the MTP-2 (ITU-T Q.703) and MTP-3 (ITU-T Q.704) headers. These headers are easy to decode because they are always fixed-length:</p>
<table style="height:118px;" border="0">
<tbody>
<tr>
<th>Octet(s)</th>
<th>Value</th>
<th>Purpose</th>
</tr>
<tr>
<td>00&#8211;01</td>
<td>8d c8</td>
<td>MTP-2 sequence numbers, safe to ignore</td>
</tr>
<tr>
<td>02</td>
<td>1f</td>
<td>MTP-2 length indicator. Anything less than 3 is reserved for MTP-2 itself and should be discarded.</td>
</tr>
<tr>
<td>03</td>
<td>85</td>
<td>MTP-2 SIO. The SIO tells us which &#8216;service&#8217; the signal unit is intended for. Q.704 sections14.2.1 and 14.2.2 tell us that anything ending in hex 5 is for ISUP.</td>
</tr>
<tr>
<td>04&#8211;07</td>
<td>02 40 00 00</td>
<td>MTP-3 Routing label. The routing label is just a &#8220;from&#8221; and &#8220;to&#8221; address in the SS7 network. For most applications we can ignore it. Q.704 figure 3 shows what&#8217;s in the routing label.</td>
</tr>
</tbody>
</table>
<p>Upshot: to see calls start and stop, all we have to do for MTP-3 is:</p>
<ol>
<li>Look at the length indicator (offset 2) and discard any signal unit where it&#8217;s less than 3.</li>
<li>Look at the SIO (offset 3). Discard if (SIO &amp; 0x0f != 5)</li>
</ol>
<h3>ISUP</h3>
<p>The rest of the signal unit is ISUP. Annex C in ITU-T Q.767 tells us how to decode ISUP. ISUP is fiddly because there are several types of ISUP packets, because several of those types have optional fields and because some of those fields are variable length. Here are the octets we have left after removing MTP-2 and MTP-3:<br />
<code><br />
35 00 01 00 21 00 0a 02<br />
02 08 06 01 10 12 52 55<br />
21 0a 06 07 01 11 13 53<br />
55 00 6e 00<br />
</code><br />
The first two octets are the CIC. The third octet is the Message type.</p>
<p>The <strong>CIC</strong> (Q.767 C.1.2) tells us which circuit this call uses. All the signalling for one call has the same CIC. In ITU networks, it&#8217;s a 12-bit value packed into the field in little-endian byte order. In this case CIC=0&#215;0035. We&#8217;re sniffing an E1 line, so C.1.2.a tells us that the lower five bits correspond to the timeslot (timeslot 5) and the rest identifies the E1 itself.</p>
<p>The <strong>Message Type</strong> (Q.767 Table C-3) field tells us what sort of ISUP message this signal unit is. 0&#215;01 is an IAM. 0&#215;10 is RLC. For a minimal &#8220;show me what calls are going through the system&#8221; hack, we only need to look at the IAM (comes at the start of the call, contains the A and B numbers) and the RLC (sent when the call is finished) messages.</p>
<p>Now we know that the CIC=0&#215;35, that the message is an IAM and we still have about a dozen octets to decode. Q.767 table C-16 tells us how to decode an IAM. There are some uninteresting fixed-length fields followed by the B number and then the A number. Look at the code (or Q.767, section C.3.7) if you&#8217;re interested in the details. All we really care about is that these octets<br />
<code><br />
06 01 10 12 52 55 21<br />
</code><br />
represent the B number: 21255512. You can see the number in the raw data if you skip the first three octets and swap every second digit.</p>
<p>Turning those ISUP steps into an algorithm to decode one signal unit:</p>
<ol>
<li>Save the CIC</li>
<li>Is the message an IAM? Decode it as an IAM, which is fiddly.</li>
<li>Is the message an RLC? Just print the CIC.</li>
</ol>
<p>That&#8217;s all you need to do to make a simple system which prints the start and end of each call. To do something useful, you need to maintain a table of in-progress calls and match up the IAM and RLC messages with the same CIC. You also need to handle things like systems restarting.</p>
<h3>Further reading</h3>
<p>The ITU now have most of their standards freely available at www.itu.int. So one way to learn more about MTP-3 and ISUP is to read the standards, e.g. all the Q-series standards about signalling are <a href="http://www.itu.int/rec/T-REC-Q/en">here</a>.</p>
<h3>Erlang code</h3>
<p>Everything discussed above is implemented in the ss7_sniffer.erl <a href="http://http://www.corelatus.com/gth/api/gth_erlang_api.zip">example</a> on corelatus.com. It makes good use of Erlang&#8217;s binary syntax, e.g. here&#8217;s the MTP-3 decoder:</p>
<p><code><br />
mtp3(&lt;&lt;_Sub:4,&nbsp;Service_indicator:4&gt;&gt;,&nbsp;&lt;&lt;DPC:14,&nbsp;OPC:14,&nbsp;SLS:4,<br />
&nbsp;Rest/binary&gt;&gt;)&nbsp;-&gt;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;Service_indicator&nbsp;of&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;-&gt;&nbsp;%&nbsp;Management&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ignore;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;-&gt;&nbsp;%&nbsp;Test/maintenance&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ignore;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;3&nbsp;-&gt;&nbsp;%&nbsp;SCCP&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ignore;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;5&nbsp;-&gt;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isup(DPC,&nbsp;OPC,&nbsp;SLS,&nbsp;Rest);&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;9&nbsp;-&gt;&nbsp;%&nbsp;B-ISUP;&nbsp;similar&nbsp;to&nbsp;ISUP,&nbsp;but&nbsp;not&nbsp;compatible.&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ignore;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;X&nbsp;-&gt;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;io:fwrite("ignoring&nbsp;SU&nbsp;with unexpected&nbsp;service&nbsp;indicator=~p\n",&nbsp;[X])&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;end.<br />
</code></p>
<p>It looks a lot like one of the examples in the original paper about the binary syntax.</p>
<h3>Python Code</h3>
<p>The same thing done in Python is fairly straightforward once you discover the Python &#8216;struct&#8217; library, which is basically the same thing as PERL&#8217;s pack/unpack. The code is in sniff_isup.py, inside the <a href="http://www.corelatus.com/gth/api/gth_python_examples.zip">GTH python examples</a> zip. </p>
<p>It feels like I haven&#8217;t discovered whatever it is python people use to unpack bitfields, e.g. something neater than:<br />
<code><br />
    is_even = ((ord(num[1]) &amp; 0x80) == 0)<br />
</code><br />
or, better still, a clean way to decode the MTP-3 routing label.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/corelatus.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/corelatus.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/corelatus.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/corelatus.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/corelatus.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/corelatus.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/corelatus.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/corelatus.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/corelatus.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/corelatus.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/corelatus.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/corelatus.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/corelatus.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/corelatus.wordpress.com/43/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=43&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://corelatus.wordpress.com/2009/03/25/decoding-mtp-3-and-isup/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deeae26c450dfdfc49174cfd396e6471?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">corelatus</media:title>
		</media:content>
	</item>
		<item>
		<title>The timestamp field in signalling headers</title>
		<link>http://corelatus.wordpress.com/2009/03/23/the-timestamp-field-in-signalling-headers/</link>
		<comments>http://corelatus.wordpress.com/2009/03/23/the-timestamp-field-in-signalling-headers/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 20:40:32 +0000</pubDate>
		<dc:creator>Matt Lang</dc:creator>
				<category><![CDATA[GTH]]></category>
		<category><![CDATA[Questions from customers]]></category>
		<category><![CDATA[Telecom signalling]]></category>

		<guid isPermaLink="false">http://blog.corelatus.com/?p=28</guid>
		<description><![CDATA[When the Corelatus GTH is used to monitor (sniff) signalling, it sends each sniffed packet to your server over a TCP socket, along with a header. For instance, for SS7 MTP-2 the header looks like this: octet 0x00: Length (16 &#8230; <a href="http://corelatus.wordpress.com/2009/03/23/the-timestamp-field-in-signalling-headers/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=28&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When the Corelatus GTH is used to monitor (sniff) signalling, it sends each sniffed packet to your server over a TCP socket, along with a header. For instance, for SS7 MTP-2 the header looks like this:<br />
<code><br />
octet 0x00:  Length (16 bits)<br />
octet 0x02:  Tag (16 bits)<br />
octet 0x04:  Flags (16 bits)<br />
octet 0x06: Timestamp (48 bits)<br />
</code></p>
<p>Every field is big-endian, i.e. the most significant byte comes first. Here&#8217;s an actual header from a GTH, octet by octet:<br />
<code><br />
00 1c 00 00 00 00 01 20  34 ee fa 61 99 99 99 99 ...<br />
</code></p>
<p>The timestamp is thus 0x012034eefa61, or decimal 1237838658145. For most applications, you just want to know which packet came first, so the interpretation of that number doesn&#8217;t matter much, though it&#8217;s useful to know that it&#8217;s the number of <strong>milli</strong>seconds since the unix epoch. (wikipedia has a decent <a href="http://en.wikipedia.org/wiki/Unix_time">article about unix time</a>)</p>
<p>Sometimes, though, you want to represent that as a human-readable time. Unix (and, most likely, Win32) provides functions to do that in the C library, so, after throwing away the last three digits (the milliseconds), this C program does it:<br />
<code><br />
#include &lt;time.h&gt;<br />
#include &lt;stdio.h&gt;<br />
&nbsp;<br />
int main() {<br />
  const time_t time_stamp = 1237838658;<br />
  printf("%d corresponds to %s\n", time_stamp, ctime(&amp;time_stamp));<br />
&nbsp;<br />
  return 0;<br />
}<br />
</code></p>
<p>The output agrees with what the clock on my wall says:<br />
<code><br />
1237838658 corresponds to Mon Mar 23 21:04:18 2009<br />
</code></p>
<h3>Python</h3>
<p>Since I&#8217;ve been messing around with python, the same thing in python:<br />
<code><br />
&gt;&gt;&gt; import time<br />
&gt;&gt;&gt; time.ctime(1237838658)<br />
'Mon Mar 23 21:04:18 2009'<br />
</code></p>
<h3>Erlang</h3>
<p>Erlang doesn&#8217;t have an interface to the &#8216;ctime&#8217; call, but you can use the gregorian calendar functions:<br />
<code><br />
1&gt; Epoch = calendar:datetime_to_gregorian_seconds({{1970, 1, 1}, {0,0,0}}).<br />
62167219200<br />
2&gt; calendar:gregorian_seconds_to_datetime(1237838658 + Epoch).<br />
{{2009,3,23},{20,4,18}}<br />
</code></p>
<h3>Why use milliseconds?</h3>
<p>Why is the GTH timestamp in milliseconds instead of either seconds or a &#8216;timeval&#8217;-like seconds + microseconds?</p>
<p>We chose millisecond resolution for several reasons. Firstly, the shortest possible useful packet in SS7 takes a bit more than a millisecond to transmit at 64kbit/s. Secondly, the practical limit of NTP time synchronisation over the internet is about one millisecond at a typical site.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/corelatus.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/corelatus.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/corelatus.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/corelatus.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/corelatus.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/corelatus.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/corelatus.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/corelatus.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/corelatus.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/corelatus.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/corelatus.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/corelatus.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/corelatus.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/corelatus.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=28&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://corelatus.wordpress.com/2009/03/23/the-timestamp-field-in-signalling-headers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deeae26c450dfdfc49174cfd396e6471?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">corelatus</media:title>
		</media:content>
	</item>
		<item>
		<title>GTH audio streaming: why stream over TCP?</title>
		<link>http://corelatus.wordpress.com/2009/03/06/gth-audio-streaming-why-stream-over-tcp/</link>
		<comments>http://corelatus.wordpress.com/2009/03/06/gth-audio-streaming-why-stream-over-tcp/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 11:32:20 +0000</pubDate>
		<dc:creator>Matt Lang</dc:creator>
				<category><![CDATA[GTH]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.corelatus.com/?p=20</guid>
		<description><![CDATA[GTH lets you stream audio from a TCP socket to a timeslot on an E1/T1 line. Some people are surprised by the choice to use TCP. When I added that support back in 2002, my first thought was to use &#8230; <a href="http://corelatus.wordpress.com/2009/03/06/gth-audio-streaming-why-stream-over-tcp/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=20&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>GTH lets you stream audio from a TCP socket to a timeslot on an E1/T1 line. Some people are surprised by the choice to use TCP. When I added that support back in 2002, my first thought was to use RTP (<a href="http://www.faqs.org/rfcs/rfc1889.html">RFC 1889</a>). RTP is simple: you just dump the audio in a UDP packet with some timestamping information and shoot it out on ethernet at the right rate.</p>
<p>I&#8217;d worked with RTP before and I&#8217;d been at a couple of SIP interops where  <em>most</em> of the attendees had trouble emitting audio at &#8216;the right rate&#8217;, i.e. 8000 samples/s. One manufacturer&#8217;s system would emit 8007 samples/s. Another would play it back at 7999 samples/s. What do you do with the extra 8 samples per second? If you do nothing, you get endlessly growing delays and, eventually, a buffer overflow. If you come up with a strategy for throwing away samples, it&#8217;s bound to interact badly with something, sooner or later.</p>
<p>The thing is, when you&#8217;re streaming in pre-recorded audio, you don&#8217;t need it to be at the right rate. You just need to make sure it doesn&#8217;t overrun or underrun the GTH&#8217;s internal buffer. I.e. you need flow control, not rate control. TCP has flow control, and everyone knows how to use TCP sockets. In 2002, doing things that way was right at the limit of what our 50MHz embedded CPU could keep up with. Now it&#8217;s no problem at all.</p>
<p><strong>Python</strong></p>
<p>I&#8217;m playing around with python at the moment. Here&#8217;s how to put some<br />
data on an E1 timeslot, straight from the python shell. First, set up a listening TCP socket:</p>
<p><code><br />
import socket<br />
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br />
s.listen(0)<br />
addr, port = s.getsockname()<br />
</code></p>
<p>Next, open another socket to the GTH command port (2089) and tell it we want to stream in audio on the socket we opened above:<br />
<code><br />
a = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br />
a.connect(("172.16.2.7", 2089))<br />
my_ip, _port = a.getsockname()<br />
command = "" % (my_ip, port)<br />
header = "Content-type: text/xml\r\nContent-length: %d\r\n\r\n" % len(command)<br />
a.sendall(header + command)<br />
</code></p>
<p>Finally, accept() and send the data:</p>
<p><code><br />
d, _ = s.accept()<br />
d.sendall("hello world")<br />
d.close()<br />
</code></p>
<p>That looks OK to me, though I imagine the style betrays my Erlang mindset. There&#8217;s a more complete python example at the bottom of the <a href="http://www.corelatus.com/gth/api/">API page</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/corelatus.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/corelatus.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/corelatus.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/corelatus.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/corelatus.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/corelatus.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/corelatus.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/corelatus.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/corelatus.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/corelatus.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/corelatus.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/corelatus.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/corelatus.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/corelatus.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=20&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://corelatus.wordpress.com/2009/03/06/gth-audio-streaming-why-stream-over-tcp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deeae26c450dfdfc49174cfd396e6471?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">corelatus</media:title>
		</media:content>
	</item>
		<item>
		<title>SOX parameters for downsampling to 8kHz Alaw</title>
		<link>http://corelatus.wordpress.com/2009/02/19/sox-parameters-for-downsampling-to-8khz-alaw/</link>
		<comments>http://corelatus.wordpress.com/2009/02/19/sox-parameters-for-downsampling-to-8khz-alaw/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 19:26:03 +0000</pubDate>
		<dc:creator>Matt Lang</dc:creator>
				<category><![CDATA[GTH]]></category>
		<category><![CDATA[Questions from customers]]></category>

		<guid isPermaLink="false">http://corelatus.wordpress.com/?p=7</guid>
		<description><![CDATA[A technician working for an operator mailed me a few days ago wondering why the recorded voice clips they use for their IVR sound so bad, “like they’re coming from the bottom of a deep well”. It turned out that &#8230; <a href="http://corelatus.wordpress.com/2009/02/19/sox-parameters-for-downsampling-to-8khz-alaw/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=7&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div class="entry-content">
<div class="snap_preview">
<p>A technician working for an operator mailed me a few days ago wondering why the recorded voice clips they use for their IVR sound so bad, “like they’re coming from the bottom of a deep well”. It turned out that the clips actually sounded OK on a telephone, just not through his laptop&#8217;s speaker. He asked if I recommend any specific filter parameters when converting audio from 44.1kHz wav to 8kHz Alaw voice clips.</p>
<h5>An example</h5>
<p>I took this audio snippet from the introduction to an audio book. It was originally a .ogg file. I converted it to a .wav file with a 44.1kHz sampling rate and 16 bits per sample. For my purposes any artefacts from ogg vorbis are negligible.</p>
<p><a href="http://www.corelatus.com/%7Ematthias/1_mono.wav">1_mono.wav</a> (44.1kHz, 16 bit linear samples)</p>
<p>Next, I converted it to 8kHz Alaw using  	<a href="http://sox.sourceforge.net/">sox</a>. 8kHz Alaw is 	what runs on the fixed telephone network in most of the world. 	(The US uses a minor variant, μlaw):</p>
<p><code>sox 1_mono.wav -A -r 8000 2_8kHz_alaw.wav</code></p>
<p><a href="http://www.corelatus.com/%7Ematthias/2_8kHz_alaw.wav">2_8kHz_alaw.wav</a> (8kHz, 8 bit Alaw samples)</p>
<p>That sounds a bit less clear than the original, but it’s OK. It’s what you’d expect coming out of a telephone. There’s some weirdness though. The audible difference between the two files varies from one PC to another and even one playback program to another. Why? Because laptop speakers vary in quality and because playback programs usually quietly convert everything back to 48kHz or 44.1kHz sampling rates, and they do it with different approaches. For fun, I resampled to 44.1kHz:</p>
<p><code>sox 2_8kHz_alaw.wav -r 44100 -s 3_resampled.wav</code></p>
<p><a href="http://www.corelatus.com/%7Ematthias/3_resampled.wav">3_resampled.wav</a> (44.1kHz, 16 bit linear samples)</p>
<p>2_8kHz_alaw.wav and 3_resampled.wav should sound almost the 	same. But on some PCs they sound markedly different.</p>
<h5>The GTH just plays octets (bytes)</h5>
<p>The GTH has a simple approach to playing back audio. It just copies the bytes you give it to the destination timeslot. No format or rate conversion happens, though the GTH does make sure the data is played out at the E1&#8242;s frame rate (8000Hz). The downside of that is that you have to convert all the files for your IVR system before giving them to a GTH, e.g. using sox. The upside is that it’s simple. Nothing happens behind your back.</p>
<h5>What are the best SOX options to use?</h5>
<p>I don’t know. I used to suggest the following as a reasonable starting 	point:</p>
<p><code>sox original.wav -r 8000 -c 1 -A -t raw gth.raw resample -q</code></p>
<p>As of a few years ago, sox improved and the ‘resample’ effect got deprecated. So now I suggest just letting sox do what it thinks is best:</p>
<p><code>sox original.wav -r 8000 -c 1 -A -t raw gth.raw</code></p>
<p>At the time of writing, it uses its “rate” effect with reasonable default parameters for the bandwidth and filter characteristics. I experimented a bit with the -m, -h, -v and -s switches for the “rate” effect. I could not reliably hear a difference, let alone decide that one sounded better.</p>
<h5>Why does the phone system use 8kHz anyway?</h5>
<p>There’s a certain sound quality level expected in telephone networks, and part of that is that the network carries everything up to about 3500Hz. Analog local loop specifications mention that, and pretty much all digital telephone systems use an 8kHz sampling rate, which is what you need to be able to carry audio up to 3.5kHz. Even the GSM and AMR codecs start off with the assumption that the incoming audio is limited to 3500Hz.</p>
<p>So the bar is set pretty low. I haven’t come across any systems which set out to provide higher quality, e.g. even skype compresses the hell out of the audio to save bandwidth. Even when both parties in a conversation have huge amounts of it. Surprising, why not aim for VOIP to sound much better than a regular telephone?</p></div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/corelatus.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/corelatus.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/corelatus.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/corelatus.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/corelatus.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/corelatus.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/corelatus.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/corelatus.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/corelatus.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/corelatus.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/corelatus.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/corelatus.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/corelatus.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/corelatus.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=corelatus.wordpress.com&amp;blog=6650584&amp;post=7&amp;subd=corelatus&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://corelatus.wordpress.com/2009/02/19/sox-parameters-for-downsampling-to-8khz-alaw/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.corelatus.com/%7Ematthias/1_mono.wav" length="327724" type="audio/x-wav" />
<enclosure url="http://www.corelatus.com/%7Ematthias/2_8kHz_alaw.wav" length="29780" type="audio/x-wav" />
<enclosure url="http://www.corelatus.com/%7Ematthias/3_resampled.wav" length="327730" type="audio/x-wav" />
	
		<media:content url="http://1.gravatar.com/avatar/deeae26c450dfdfc49174cfd396e6471?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">corelatus</media:title>
		</media:content>
	</item>
	</channel>
</rss>
