Friday, May 20, 2011

Optware/ipkg on Synology DS211+

Note that the following covers the DS211+ device, which is characterized by being based on the Marvell Kirkwood mv6282 ARM core (1.6Ghz version of 1.2Ghz mv6281). AFAIK the content of this blog entry should be equally applicable to all DS211 variations, but you should consult the Synology wiki for your device to be certain.

While quite feature rich out-of-the-box, developer types will likely want to make their NAS do even more, either out of a real need or just to tinker. For instance, I eventually plan to connect my USB weather station and generate live charts. Because of the modding desire, Synology has a faily comprehensive wiki about the subject. To make a long story short, ease of modding is greatly assisted by the possibility of installing Optware package manager.

Installing Optware
Optware (ipkg) is an online package system a la what you may know from Debian/Ubuntu. This makes it easy to locate, install and uninstall compiled binaries (*.ipk) through the command-line.

Bootstrapper and Optware packages are maintained by the NSLU2-Linux community for use with various modifiable hardware devices incl. many Synology products. The installation procedure simply involves you downloading and installing the Optware-bootstrapper for your NAS. Here's what I wrote while logged in as root via SSH/telnet, to get it working.

Download the Optware bootstrapper:

NAS> cd /volume1
NAS> wget
           => `syno-mvkw-bootstrap_1.2-7_arm-ds111.xsh'
Connecting to||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 251,866 (246K) [text/plain]

100%[====================================>] 251,866      435.14K/s             

22:58:08 (434.50 KB/s) - `syno-mvkw-bootstrap_1.2-7_arm-ds111.xsh' saved [251866/251866]

Start the installation:

NAS> sh syno-mvkw-bootstrap_1.2-7_arm-ds111.xsh 
Optware Bootstrap for syno-mvkw.
Extracting archive... please wait
1227+1 records in
1227+1 records out
Creating temporary ipkg repository...
Installing optware-bootstrap package...
Unpacking optware-bootstrap.ipk...Done.
Configuring optware-bootstrap.ipk...Modifying /etc/rc.local
Installing ipkg...
Unpacking ipkg-opt.ipk...Done.
Configuring ipkg-opt.ipk...WARNING: can't open config file: /usr/syno/ssl/openssl.cnf
Removing temporary ipkg repository...
Installing wget...
Installing wget (1.12-2) to root...
Configuring wget
Successfully terminated.
Creating /opt/etc/ipkg/cross-feed.conf...
Setup complete.

BusyBox v1.16.1 (2011-04-08 10:13:55 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.


Note, if you get the message "Error: CPU not Marvell Kirkwood, probably wrong bootstrap.xsh", this is likely due to a too agressive sanity check (mv6281 but not mv6282) in the install script. If the output of the command "cat /proc/cpuinfo" mentions a "Feroceon" CPU, then you may safely open up the file "/volume1/bootstrap/" and edit line 21, changing "Feroceon-KW" to just "Feroceon", and run the script manually with "sh /volume1/bootstrap/".

The above will install a boot hook and create the directories /volume1/bootstrap and /volume1/@Optware where package manager and installed packages will reside. The content in /volume1/@Optware can also be found in /opt, due to an Optware bind mount requirement you can verify by invoking the mount command:

NAS> mount | grep @optware
/volume1/@optware on /opt type bind (bind)

Now reboot the NAS:

NAS> reboot

Managing packages
After a reboot, you can update the list of packages with:

NAS> ipkg update
Updated list of available packages in /opt/lib/ipkg/lists/cross
Successfully terminated.
You can list all packages with "ipkg list" or search specific packages with "ipkg list [wildcard]".

NAS> ipkg list cpu* 
cpufrequtils - 006-2 - To make access to the Linux kernel cpufreq subsystem easier for users and cpufreq userspace tools, a cpufrequtils package was c
Successfully terminated.

To install a package, simply type "ipkg install [name]". You may also browse the available packages by accessing the repository directly from within a browser.

NAS> ipkg install iperf
Installing iperf (2.0.4-1) to root...
Configuring iperf
Successfully terminated.

Removing packages is just as easy as installing:

NAS> ipkg remove iperf 
Removing package iperf from root...
Successfully terminated.

To make sure all installed Optware packages are up to date:

NAS> ipkg upgrade     
Upgrading grep on root from 2.7-1 to 2.8-1...
Configuring grep
update-alternatives: Linking //opt/bin/grep to /opt/bin/grep-grep
update-alternatives: Linking //opt/bin/egrep to /opt/bin/grep-egrep
update-alternatives: Linking //opt/bin/fgrep to /opt/bin/grep-fgrep
Successfully terminated.

Uninstalling Optware
To my knowledge, there isn't a one-liner for uninstalling the Optware system. It involves stopping the Optware service, unmounting the /opt bind mount, deleting the folder/files, editing the Linux service script and rebooting:

NAS> /etc/rc.optware stop
NAS> umount /opt
NAS> rm -rf /volume1/@optware
NAS> rm -f /etc/rc.optware
NAS> echo -e "#!/bin/sh\n" > /etc/rc.local
NAS> reboot

Note that the above wipes the rc.local script. If you have added custom stuff beyond just Optware, you should edit out the Optware stuff manually!

Of course, there aren't as many packages available as one would like, but it's still impressive that you can install Mono, Java, Python, Perl, Lua etc. on a small NAS device just with a single command. Hope this entry helps others get to hacking on their Synology device.

Thursday, May 19, 2011

Home network benchmarking with iperf

Having recently purchased a new NAS device, as well as upgraded network cables in my house to cat6 (1Gbps), I started wondering about just how fast and healthy my network setup was. Are all cables in order? Are any of my switches a bottleneck? Any particular slow endpoints?
performance challenged
There are of course commercial software to assist in this, but after having compiled and loaded up a bunch of Linux software onto my small NAS, it was only natural to give "iperf" a try. It's a small open source client-server utility you start in listening mode on one device, and in transmission mode on another, and have it transfer a bunch of random data over TCP. You can obtain iperf from sourceforge, from your Linux package manager or just Google for precompiled binaries if you are lazy.

Simple unidirectional test
The process is simple, log onto the receiving device and run iperf in listening mode, in the following case it's my Synology NAS:

NAS> iperf -s -p 5555
Server listening on TCP port 5555
TCP window size: 85.3 kByte  (default)

Then also run iperf, though this time in client mode targeting the server you just started:

casper@laptop:~/$ iperf -c -p 5555
Client connecting to, TCP port 5555
TCP window size: 19.0 kByte  (default)
[  3] local port 52742 connected with port 5555
[ ID] Interval       Transfer     Bandwidth
[  3] 0.0-10.3 sec   26.2MBytes   21.4 Mbit/sec

Note that the above result is quite slow, as a consequence of being on congested WiFi and benchmarking the slowest node in my household, the NAS.

This gives you a bps metric for how fast the client could transfer data to the server. To benchmark both upstream and downstream, you must reverse the client-server pair and repeat the process.

Complex bidirectional test case
By running tests between each and every possible node, it becomes possible to draw some interesting conclusions about the setup in general. The wired setup in my household looks roughly like this (without smartphones, TV, PS3, IP phone etc.):

With Gigabit connections between all major nodes, I expected to see throughput up around 90% of the theoretical maximum bandwidth. What I saw was hardly consistent however, as the following graph shows:

Note that solid edges signify physical cat6 cables, dashed edges logical connections. Edges are labeled with directional throughput in Mbps and nodes contains summerized throughput on the form in/downtream and out/uptream.

Lessons learned
Infrastructure nodes like router and switch would appear to have performed optimal, and there is no hinting of faulty cabling. On several occasions, one can observe throughput beyond 940Mbps, or 94% of the theoretical maximum.
I was a little surprised to see that the overall best performer, was actually my 3 year old sub-notebook. The network stack (hardware+software) is obviously very well implemented on the laptop. The PC's, particularly one of them, would probably benefit from a new dedicated Gigabit adapter rather than relying on the one built into the motherboard.
However, the greatest surprise was to see how the NAS struggled, particularly when receiving data and when having to cross 2 switches. In all fairness, the slow CPU of the NAS (1.6GHz ARM) could very likely be key to the poor performance of iperf - loopback tests on all endpoints incl. the NAS suggests this to be the case.

There are of course many other parameters one could care about; ping time, jitter, packet loss, UDP packets, jumbo frames etc. but I was mostly just concerned about TCP bandwidth throughput. I've learned that perhaps I should flash my DD-WRT router back with the original firmware, or perhaps try another open source image like Tomato, in order to see whether I can mitigate some of the observed bandwidth loss. It also seems abundantly clear, that the network system of my NAS device is more optimized for delivering data than receiving it.

I'd like to do a plugin for Synology's management interface, having it run native iperf against a Java implementation hosted by the client as an applet. Currently looking into whether this is possible. I fear it's too low level for Java, as this was one of the reasons I changed to C# for dealing with raw sockets some years ago.