Quick IP prefix calculation

It’s a quite common task that you need to translate an IP address into a prefix — for example, when creating an IP prefix list from a set of addresses. Here’s a simple Perl script that helps it:

sudo apt-get install libnetaddr-ip-perl
cat >getprefix.pl <<'EOT'
use strict;
use warnings;
use NetAddr::IP;
if( scalar(@ARGV) == 0 ) {
    die("Usage: $0 PREFIX ...");
}
foreach my $pref (@ARGV) {
    my $ip = NetAddr::IP->new($pref) or
        die("Cannot create NetAddr::IP from $pref");
    print $ip->network()->cidr(), "\n";
}
EOT

# testing
cat >/tmp/x <<'EOT'
10.1.1.1/23
192.168.5.3/28
EOT

cat /tmp/x | xargs perl getprefix.pl | awk '{print "set ", $1}'
set  10.1.0.0/23
set  192.168.5.0/28


, ,

Leave a comment

Quality Assurance for VoIP calls

A customer has requested to set up a QA service that would continuously monitor the voice quality in their telephony infrastructure. They use a number of telephony carriers, and a set of applications on top of Plivo and FreeSWITCH. Also the conference module in FreeSWITCH is actively used.

Measuring jitter and packet loss, like it’s done in VoIPmonitor, is not sufficient, as we need to monitor end-to-end performance, including that of the FreeSWITCH server itself. So, there has to be a software component that compares the source audio with the recording on the other end of a call.

There are currently two major player on the market for voice quality measurements:

  1. ITU-T PESQ algorithm is proposed as an ITU recommendation P.862. Its source code is available at the ITU website and on Github. But the algorithm is patented, and the source code license does not allow any production use. The evaluation went quite smoothly, and the algorithm was able to detect even minor distortions, like one 20ms frame loss in a 2-minute call. The PESQ algorithm is designed and calibrated to be used for audio files of 6 to 20 seconds in length. Processing of a 2-minute recording takes approximately 5 seconds on a modern Xeon CPU. Commercial software is provided by OPTICOM and PsyTechnics.
  2. Sevana Oy is a Finnish/Estonian company that provides their own algorithms and software product for voice quality assessment. Their AQuA (Audio Quality Analyzer) software provides a fast and reliable way to compare the audio files: processing of a 2-minutes recording took about half a second on a modern CPU. Sevana has kindly provided a 10-days evaluation license and a fully functional software package, and the customer decided to go ahead with purchasing the license.

The simplest single-server license for Sevana AQuA allows running only one AQuA process at a time, so we wrapped its execution into a Perl script that utilizes a simple exclusive locking mechanism and performs audio file processing one at a time.

AQuA produces two scores in each measurement: the similarity percentage, and the MOS score. Both metrics are useful for quality analysis (for example, a 20ms frame added or lost inside of a silent pause influences the similarity score more significantly than MOS). It also takes a number of command-line options which can increase its tolerance to certain types of distortions, such as frequencies outside of G.711 range.

FreeSWITCH software is used as the SIP server for sending and terminating voice calls and for recording the received audio. It allows recording in several different formats: a) raw codec recording, done in the same thread as RTP processing; b) 16-bit signed PCM in WAV format, and file writing is done in a separate thread; c) compressed voice in a number of formats. The first two options produce similar results (raw codec recording had difficulties in the beginning). In case of raw codec recording, an additional step is required to convert the input files into 16-bit PCM WAV.

The call recording server requires to have a precise clock reference, so a baremetal hardware is required. Virtualized environments add up some uncontrollable imprecision to the virtual machines, although a thorough lab test is requires to verify this. It also depends on the type of hypervisor, as they implement the system clock differently.

The Linux kernel provides access to various clock sources. TSC is commonly used as default, and there is also HPET clock on modern hardware platforms. HPET is supposed to provide a more precise clock source, but it appears that it depends on CPU load: we accidentally discovered that audio recording in FreeSWITCH is significantly distorted when there’s some CPU activity is done in parallel (Debian package builder was working on the same 8-core machine). So far, TSC clock on a baremetal server provided the most reliable results.

The recording is done into a tmpfs mounted partition, in order to avoid any dependency on I/O load. The processing script performs the quality assessment on recorded files, and then moves or deletes them, depending on the measured score.

The SIP service was attached to an unusual UDP port, as port 5060 is frequently accessed by port scanners in public Internet. The DNS NAPTR and SRV records are used in order to use a universal SIP URI string, without having to reconfigure the remote servers if the IP address or UDP port changes.

Jitter buffer is disabled by default in FreeSWITCH, and it has to be activated whenever the calls are terminated on the server. In our case, the “jitterbuffer_msec” variable is set to “50:50″ in the dialplan before answering and recording the call. With this, the jitter buffer is not allowed to grow dynamically above 50ms. So, we tolerate most of typical Internet-imposed jitter, but clock drift on the sending side would cause packet drop on the receiver.

The dialplan is designed to accept direct SIP calls from remote servers, and PSTN calls from telephony providers. If a remote server calls our QA service directly, it encodes the source name in the user part of the SIP URI. Also there are two options for a QA call: it can playback the test audio, or send silence. In case of PSTN calls, the caller ID is used as the source identifier. The dialplan activates audio recording into a WAV file on a tmpfs partition, and launches the processing script after the hangup.

The conference dialer is used for testing the conferencing performance on a production FreeSWITCH server. It requires a conferencing profile that does not play any greetings to conference participants. Also in case of more than two participants, only one has to be chosen as a speaker, and all others would be listeners. A dedicated SIP URI on the QA server is reserved to playback the test audio and not to perform any recording.

Each measurement result for QA calls is stored in an SQL database for further processing, and also sent to Syslog for real-time monitoring.

The test audio is a concatenation of speech samples from ITU-T Recommendation P.50 Appendix I, resampled from 16KHz to 8KHz and stored as 16-bit signed PCM audio.

 

, , , , ,

Leave a comment

Simulating NAT with two Linux boxes

I needed to test some master-slave software in a situation that the master communicated to the slave over NAT (master’s IP address was replaced with the firewall’s external address), and then NAT would be removed, keeping master and slave addresses the same, but the slave would see the master directly.

This is the test scenario that worked on my desk, without having to add any routing to the LAN.

atom02 is the computer that emulates the slave system. It is connected back-to-back to alix102, and has only one IP address to communicate to:

ip link set dev eth0 up
ip addr add 192.168.1.50/31 dev eth0

alix102 is a Linux box with multiple Ethernet ports: eth0 is connected to my home LAN and has a DHCP address 192.168.1.142/24. Also eth1 (192.168.1.51/31) is connected directly to atom02.

The following configuration makes alix102 answer to ARP requests for 192.168.1.50 and forward packets to atom02, replacing the source address with 192.168.1.51. Also atom02 can make an SSH connection to 192.168.1.51:3022 and it will be connected to another box in the LAN that emulates the software master (192.168.1.147:22).

# enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
# Bring up eth1
ip link set dev eth1 up
ip addr add 192.168.1.51/31 dev eth1
# Enable proxy ARP on eth0
echo 1 > /proc/sys/net/ipv4/conf/eth0/proxy_arp
# Set up the NAT translation
iptables -t nat -A POSTROUTING -o eth1 -j SNAT --to 192.168.1.51
iptables -t nat -A PREROUTING -p tcp --dport 3022 -i eth1 -j DNAT --to 192.168.1.147:22

After that, atom02 can be re-connected directly into the LAN, keeping the address 192.168.1.50 with /24 network mask, and the software can be tested with direct communication. Alix102 has to be disconnected from the LAN, so that it does not pollute it with proxy ARP responses.

Leave a comment

Linux reboot freezes on Acer Aspire One

I needed to install CentOS 6 on one an old Acer Aspire One notebook (with Intel Atom CPU) for some software testing. The problem is, that it could not perform a reboot, and I needed to press the power button every time. These instructions for reboot=X parameter for kernel did not help at all.

What really helped, is `kernel-ml` package from elrepo.org repositories. At the moment of writing, it was version `4.0.0-1.el6.elrepo.x86_64`.

Keep in mind that after installing kernnel-ml package, you need to edit /etc/grub.conf and make this new kernel as default. No additional boot options are required.

Leave a comment

Testing FreeSWITCH performance on Scaleway C1

The dedicated ARM hosting servers at Scaleway appear to be a decent platform for a mid-sized PBX.

In short, the platform displays the following results in performance tests:

  • OPUS<->PCMA transcoding: 16 simultaneous calls with  at about 95% total CPU load and no noticeable distortions.
  • SILK<->PCMA transcoding: 72 simultaneous calls were going without distortions, with average total CPU load at 63%. Higher number of calls resulted in noticeable distortions.
  • G722<->PCMA transcoding: 96 simultaneous calls without distortions, at 76% CPU load, and noticeable distortions for higher numbers.

Read the rest of this entry »

, , , ,

3 Comments

Installing FreeSWITCH on Scaleway C1

Scaleway (a cloud service by online.net) offers ARM-based dedicated servers for EUR9.99/month, and the first month free. The platform is powerful enough to run a small or FreeSWITCH server, and it shows nice results in voice quality tests.

These instructions are for Debian Wheezy distribution.

By default, the server is created with Linux kernel 3.2.34, and this kernel version does not have a high-resolution timer. You need to choose 3.19.3 in server settings.

At Scaleway, you get a dedicated public IP address and 1:1 NAT to a private IP address on your server. So, FreeSWITCH SIP profiles need to be updated (“ext-rtp-ip” and “ext-sip-ip” to point to you rpublic IP address).

FreeSWITCH compiles and links “mpg123-1.13.2″ library, which fails to compile on ARM architecture.  You need to edit the corresponding files to point to “mpg123-1.19.0″ and commit back to Git, because the build scripts check if any modified and uncommitted files exist in the source tree. Also the patch forces to use gcc-4.7, as 4.6 is known with some problems on ARM architecture. Read the rest of this entry »

, , , ,

Leave a comment

Simple PBX tutorial for FreeSWITCH

Here is a short tutorial that helps building a PBX with FreeSWITCH.

, , ,

Leave a comment

3G connectivity for PC Engines APU (MU609)

HUAWEI MU609 Mini-PCIe card is available at aliexpress.com for about $40. Comparing to DW5550 card, MU609 is more expensive, but it”s a current hardware, actively supported by the manufacturer.

MU609 supports the traditional PPP interface, as well as CDC Ethernet interface for Linux.

It also has a built-in support for mobile voice calls, but its audio is only available on the physical PCM GPIO interface, which is wired to pins 45, 47, 49, and 51 on the Mini-PCIe plug. These pins are not standardized and marked as “reserved” in Mini-PCIe specification. The PC Engines APU board does not connect these pins to anything.

The card initializes 5 serial-USB devices (ttyUSB0 – ttyUSB4). ttyUSB0 can be used for modem control with AT commands. Detailed documentation for the rest of devices is available at Huawei website. The CDC Ethernet card is initialized as eth3 (because eth0-eth2 are onboard Ethernet adapters).

Setting up the card for automatic startup under Debian:

apt-get install -y picocom ppp

cat >/etc/chatscripts/sunrise.MU609 <<'EOT'
ABORT BUSY
ABORT 'NO CARRIER'
ABORT ERROR
TIMEOUT 10
'' ATZ
OK 'AT+CFUN=1'
OK 'AT+CMEE=1'
OK 'AT\^NDISDUP=1,1,"internet"'
OK
EOT

cat >/etc/chatscripts/gsm_off.MU609 <<'EOT'
ABORT ERROR
TIMEOUT 5
'' AT+CFUN=0 OK
EOT

vi /etc/network/interfaces
allow-hotplug eth3
iface eth3 inet dhcp
    pre-up /usr/sbin/chat -v -f /etc/chatscripts/sunrise.MU609 >/dev/ttyUSB0 </dev/ttyUSB0
    post-down /usr/sbin/chat -v -f /etc/chatscripts/gsm_off.MU609 >/dev/ttyUSB0 </dev/ttyUSB0


, , , ,

Leave a comment

Call generator for performance tests

Here I wrote a simple call generator for FreeSWITCH, and it can be used for performance tests:

https://github.com/voxserv/freeswitch-perf-dialer

, , ,

Leave a comment

3G connectivity for PC Engines APU (DW5550)

In addition to Sierra Wireless MC8775 3G modem, there’s now a new offering for Dell DW5550 (or Ericsson F5521gw, which is the same hardware) mini-PCIe 3G cards at Aliexpress.com, in the price range of $20. This is a newer hardware (the ones I received were manufactured in mid-2012), and it supports higher UMTS speeds and an CDC Ethernet interface in Linux.

This page refers to Ericsson F3507g card, but all instructions are relevant for DW5550. The device identifies itself as Dell DW5550, firmware version R3B01 (Command for retrieving the version: AT+CGMR).

Default Linux kernel 3.2.0 in Debian Wheezy names the CDC Ethernet interface as usb0, and 3.16.0 from Wheezy backports names it as wwan0. Other than that, everything else works the same.

Out of 3 ordered cards, two worked immediately, and one was broken. The seller has kindly offered a replacement for additional $10.

for n in `ls /sys/class/*/*{ACM,wdm,usb0}*/device/interface`;do echo $(echo $n|awk -F '/' '{print $5}') : $(cat $n);done

usb0 : Dell Wireless 5550 HSPA+ Mobile Broadband Mini-Card Network Adapter
ttyACM0 : Dell Wireless 5550 HSPA+ Mobile Broadband Mini-Card Modem
ttyACM1 : Dell Wireless 5550 HSPA+ Mobile Broadband Mini-Card Data Modem
ttyACM2 : Dell Wireless 5550 HSPA+ Mobile Broadband Mini-Card GPS Port
cdc-wdm0 : Dell Wireless 5550 HSPA+ Mobile Broadband Mini-Card Device Management
cdc-wdm1 : Dell Wireless 5550 HSPA+ Mobile Broadband Mini-Card USIM Port

The following commands initiate a 3G connection for a sunrise.ch SIM card:

apt-get install -y picocom ppp
picocom -b 115200 /dev/ttyACM1

AT+CFUN=1
AT+CGDCONT=1,"IP","internet"
AT*ENAP=1,1

Ctrl-a Ctrl-x
dhclient usb0

This Debian wiki page explains how to bring up the connection automatically at Linux startup:

cat >/etc/chatscripts/sunrise.DW5550 <<'EOT'
ABORT BUSY
ABORT 'NO CARRIER'
ABORT ERROR
TIMEOUT 10
'' AT+CFUN=1 OK
\dAT+CGDCONT=1,"IP","internet" OK
\d\d\dAT*ENAP=1,1 OK
EOT

cat >/etc/chatscripts/gsm_off.DW5550 <<'EOT'
ABORT ERROR
TIMEOUT 5
'' AT+CFUN=4 OK
EOT

vi /etc/network/interfaces

allow-hotplug usb0
iface usb0 inet dhcp
    pre-up /usr/sbin/chat -v -f /etc/chatscripts/sunrise.DW5550 >/dev/ttyACM0 </dev/ttyACM0
    post-down /usr/sbin/chat -v -f /etc/chatscripts/gsm_off.DW5550 >/dev/ttyACM0 </dev/ttyACM0

, , , ,

Leave a comment