Tag Archives: networking

adventures in wireless networking

Ever since we moved into our new house, I’ve had dreams about setting up a killer network. Every room in the building wired with gigabit ethernet, etc… but… we have no practical application for it, and the budget is insufficient to allow me to do that kind of stuff just for fun.

Our current situation has computers in 3 rooms of the house: my office, wife’s computer in our bedroom, and the PS3 in the living room. Oh, and the laptop, whenever it’s turned on.

Well, we’ve been using wireless for maybe two years now – and through two wireless routers. We initially got an old D-Link router to go with our first cable modem, but it got fried during a power outage in our apartment (I’d neglected to put it on any sort of power conditioner). Much of the networking hardware died in that. Actually, that was my second wholesale networking hardware failure – the first one happened at our first apartment when (I am guessing) a spike came over the phone line of all things (fried dsl router and the switch it was plugged into).

Anyhow.

The cheap old D-Link 802.11g router was replaced by a Linksys model, since it matched my new modem. They stacked together, which I thought was neat… but it turned out to be a terrible problem. We’ve been suffering with the easily overheated router and modem for a while now without many problems, but then we moved into the new house.

Heat no longer was a problem, my office is huge. I have plenty of room to put the modem and router on opposite ends of their little shelf and not feel bad about it.

The problem in the new place is the relative position of my bedroom with respect to the office. Or, more appropriately, the position of the master bathroom and all of its glorious plumbing (2-head shower, hot tub :P) in between the two 😉

Tarma, my wife’s machine, was using a little usb Linksys wifi adaptor, but it just couldn’t get strong enough of a signal through all of the plumbing to be useful. So we bought her a new PCI card and plugged a ginormous antenna into it. And that worked, for a while, until the strain of a heavy antenna combined with an extended period of moving the machine around and fiddling with things broke the connector loose. It still works fine, but you have to jam it in there. I can probably just solder it in place, but I’ve been kind of lazy – and don’t remember where my soldering stuff is packed anyway 😛

And, we could have lived with that. The computer was stable and wasn’t being moved around any more. Even with the connector loose, the big antenna meant that it could get 40-60% signal through all of the plumbing, except when water was running. Then she gets booted.

No, the last straw was our wireless router (the one that liked to overheat) finally giving up on talking to the modem. It… just refused to acquire an IP address any more. Modem’s fine. ISP is fine. All of the computers in the house are fine. The LAN ports and wireless on the router are fine… but it simply ceased to be useful at actually talking to the internet. And that’s no good.

So, thusly convinced that something needed to be done to feed her addiction, my wife approved the acquisition of some new networking hardware.

And when I arrived at the local emporium of all things expensive and electronic, I decided that 802.11n didn’t sound like all that bad of an idea. It’s backwards compatible with G (and B, for whatever that matters any more), and promises something like 6x the throughput and substantially higher signal range. Better signal means better chance of blasting through the hot tub…

So I bought a D-Link DIR-655 router and DWA-552 nic for Penny’s machine. Set the router up, it worked flawlessly. It’s got a decent admin interface, and all of my old 802.11g devices talk to it wonderfully. It also doesn’t hurt that the wired ports are gigabit, which means the machines in my office are now talking to each other at the speed their ethernet adaptors intended 😉

One thing I do like about the router is that it is capable of running a network in both WPA and WPA2 modes at once. This means that most of my machines are WPA2 encrypted, but those devices that don’t quite support it (like the Playstation…) are at least able to fall back and use WPA. Say what you will about possibly questionable security practices, but I think that this is a fabulous solution – it gives me the highest security realistically available on every device on my network w/o having to spend gobs of money.

So, network upgraded, and all legacy clients confirmed to be operating with better signal quality and security options, it was time to tackle Penny’s machine. This computer has been nothing but trouble since the day we got it. It has heat issues, it has power supply issues, it has WinXP MCE issues, etc… but, it’s still a generally functional system and it still works like a TV+TiVo in our bedroom.

I popped the new NIC into the box and fired it up. Drivers were installed from the disk and networks were identified. Signal strength meter comes up – full bars. Connection speed identified itself at 300Mbit. Penny was filling the tub for Alanna at the time. I considered that a success at the time and called it a night.

Well, the following day, Penny started having stability problems with the machine. Nothing unusual about that. I look at Tarma funny and the audio decides to start stuttering for a month w/o any explanation and then go back to normal. The box is certainly near the top of my list of problem children over the years.

When I got a chance, I fiddled with the box a bit more, streamlined a few things, ran the obligatory spyware/av/adware battery of scans. Nothing came up, machine was clean. It… just lagged beyond reason. I took a look at the task manager and the cpu load was reported to never really drop below 90%, yet the box wasn’t actually doing anything. ‘System idle processes’ were reported to be reliably occupying >80% of the processor’s time.

My first thought was that it was the new wireless card, but it worked fine… it never lost signal, file transfers and net access worked fine. The machine itself was just so slow that we couldn’t ever see anything like a decent transfer rate (so no streaming video from the file server). It couldn’t even play the videos off of the hard drive any more. Heaven forbid you tried to watch television.

After a bit more pondering and discussing the problem with my father and with Danny, I decided to disable to network card and see if it was just the drivers pegging the cpu.

I finally did that tonight.

The instant the interface was disabled, the system load dropped to nil. I turned the device on, and load skyrocketed back to well over 90%.

A bit of very lazy searching didn’t turn up anyone else reporting this problem. And I’d sat on the problem for too long to expect a return on the device from the store… so I decided to check if there were any new drivers.

Sure enough, D-Link had released a new driver last week. (Actually, the version number was several up from what came on the disc with my card, so I’ll assume they’d released a few versions in the interim as well). I installed the new driver, and not only did it upgrade things to 802.11n draft 2.0 (from the draft 1 advertised on the box), it fixed the system load problem. I successfully streamed a 1.3gb video w/o a hitch.

I also upgraded the router’s firmware at the same time, and haven’t noticed any changes in its behavior, but the firmware upgrade process was painless and upgraded it to using draft 2 as well.

I’m happy. Penny’s happy. Alanna’d prolly be happy too if she knew what the whole fuss had been about 😉

I’m kind of annoyed at myself that I didn’t check for new drivers and firmware the minute I installed the devices, but oh well. It works now, and I’m not out $100 for an unusable network card after all. (The Linksys card with the loose antenna connector will probably be put into service elsewhere, I’m just not sure where yet).

flexunit basics

The following is adapted from a brief tutorial I wrote for our company‘s internal conventions wiki.

And yes, I know the syntax hiliting could be better. I’m looking into switching over to WordPress and a new stylesheet, so hopefully this sort of thing will all be resolved in the nearish future.


FlexUnit

FlexUnit is a powerful unit testing framework for as3/flex2 projects. There are two API’s out there called FlexUnit, one is a SourceForge project and one is official from Adobe. The SF project is ancient and unmaintained, I will be referring to the official API.

FlexUnit also has some competition from the AsUnit project, but seems to be slightly less well suiteded for our needs when testing AS3 projects. It does, however, seem to offer fairly good support for AS2 projects. The two frameworks are generally very similar and switching between them should be fairly painless if necessary as they both evolved from and are modeled after JUnit, the industry standard for unit testing in Java.

FlexUnit is available for download from Adobe Labs. You want the zip file.

The official API documentation for FlexUnit is at http://weblogs.macromedia.com/as_libraries/docs/flexunit.

Warning: If your default run target in Flex doesn’t use the right flash player version/options, it is entirely possible that your failures might not be documented. Run the swf again in the standalone debugging player and you should get the information you missed. I’m not entirely certain why this is happening but I don’t much care at the moment.

Using FlexUnit

To make use of FlexUnit in a Flex 2 project only two bits of prep work need to be done:

  • Add the flexunit.swc file (found in the zip on Adobe’s site) to your project’s library path.
  • Create a test runner application in the project. This is Flex, so remember that applications have to be in the root of the project tree.

An example simple test runner (adapted very slightly from Darron Schall’s howto post):

Test Cases

The way the framework functions is by running a series of test cases. Each test case is an instance of the TestCase class which may or may not do any number of things. Test cases may also be organized into TestSuites which are little more than a list of test cases which will be run in order if desired. TestSuite.add() may accept either individual TestCase instances or TestSuites.

The constructor for a test case accepts one argument, the name of the method to be called when the test is run. Thus it is possible and advisable to create a single class for each group of related tests and instantiate multiple copies, each instructed to run a different test.

When a test runs it counts the results of all assertion methods called. These methods are:

  • AssertEquals()
  • AssertFalse()
  • AssertNotNull()
  • AssertNotUndefined()
  • AssertNull()
  • AssertStrictlyEquals()
  • AssertTrue()
  • AssertUndefined()
  • fail()

Each of the assertX() methods takes two parameters, a string describing the error to describe if the test fails and a value to be tested.

Fail may be used to throw error messages if you want to perform more complex tests than the prefab asserts provide.

A sample test case class:
[as3]
package test {
import flexunit.framework.TestCase;
import flexunit.framework.TestSuite;

public class SomeTest extends TestCase {

// declaring the redundant constructor saves you from having to cast when you construct
public function SomeTest( methodName:String ) {
super( methodName );
}// end: constructor

// this method returns a suite containing all of the tests provided by this class in
// the order they should be run
public static function suite() : TestSuite {
var ts:TestSuite = new TestSuite();

ts.addTest( new SomeTest( "testA" ) );
ts.addTest( new SomeTest( "testB" ) );
return ts;
}// end: suite

public function testA() : void {
AssertTrue( "True does not equal true?!", true );

var tmp:Object;
AssertNull( "Tmp should be null here.", tmp );
tmp = {};
AssertNotNull( "Tmp shouldn’t be null any more.", tmp );
}// end: testA

public function testB() : void {
fail( "This test always fails" );
}// end: testB

}// end: class
}// end: package
[/as3]

Asynchronous Tests

FlexUnit offers good support for asynchronous event-driven test cases. AsUnit apparently has also recently (ie, as of early-mid October, 2006) added this support for AS3 projects.

There are a number of asynchronous methods that tests can call but the actual 1st-party documentation on how to use them is a bit thin. In stead, Adobe refers us to hunt down and comprehend the test cases written for the Mappr API. I’ve attempted a bit of this comprehension. The only one of their test suites to use asynchronous calls is the MapprServiceTest class.

Even in this case, they’re only using one aspect of the functionality. That is the TestCase.addAsync() call. This function looks like it might be enough for what we need, it adds a checkpoint to the queue (and pauses it?) and then returns a proxy function that looks like it should clear the checkpoint and then execute the next function in your list.

The framework looks like it has more robust options than this for writing asynchronous tests, but I believe this is all we need for now.

A sample class that tests loading data from an external source might look something like this:
[as3]
package test
{
import flexunit.framework.TestCase;
import flexunit.framework.TestSuite;
import flash.net.URLLoader;
import flash.net.URLRequest;

public class RemoteXMLTest extends TestCase {
private static var TIMEOUT:int= 10000; // 10 seconds
private var loader:URLLoader;

public function RemoteXMLTest( methodName:String ) {
super( methodName );
}

public static function suite() : TestSuite {
var ts:TestSuite = new TestSuite();
ts.addTest( new RemoteXMLTest("doIt") );
return ts;
}

public function doIt() : void {
var request:URLRequest = new URLRequest("http://somewhere.com");
assertNotNull( "request is null", request );

loader = new URLLoader();
assertNotNull( "loader is null", loader );

loader.addEventListener( "complete", addAsync( onLoaded, TIMEOUT ) );
loader.load( request );
}

public function onLoaded( result:Object ) : void {
// don’t actually have to do anything here, but eh, why not?
assertNotUndefined( "we got no result?", result );
}
}
}
[/as3]

hot router blues

I’m not quite sure when it began, but this problem has been plaguing us for months now. My home network seems to have acquired a sudden and violent allergy to downloading torrents of all shapes and sizes.

We have a total of four computers currently on the network, and in regular use. Of them, Rincewind (the old server turned secondary windows desktop) and Vimes (“my” laptop that Penny monopolizes) generally shun the torrents, letting Hedwig (linux server) and Tarma (windows media center type bedroom computer) handle all the dirty work. Which is fine by them, since they’re the machines with the big processors, big ram, and big hard drives (though Rincewind does have a gig of ram and 300gb drive of his own now, shrug).

Traditionally, I have always preferred the command line python scripts to bulky gui applications. So… Hedwig has had a long and only slightly besmirched career as our primary download and redistrobution center.

When Hedwig moved home from the office after I quit my last job, I expected some slowdown – after all, we only have a 5 mbit downstream and 512 kbit upstream. The results of my first batch of downloads led me to believe that the torrent itself was somehow bugged – they were all healthy files with 10 or more seeds and 100 or more general users, yet even after a few hours running, I couldn’t manage to eke out more than 5kbps per torrent.

I let this slide for a while in the face of a new problem. One particular studio whose shows I was interested in watching was having problems with their single-episode torrents and recommended people to just use the batch torrents in stead. This is usually fine by me, but in this case, the batches were 25 episodes huge (~4.5gb) and I only needed one file out of the mix.

So, I hunted around for a client that would allow me to selectively download individual files from batch torrents, and was pleased to find BitComet. I installed it on Tarma and fired it up.

Instantly, I noticed a huge difference. BitComet was actually able to utilize my bandwidth and get me transfers at the rates my connection would actually support. It was great. But, I was still running the mud from home and didn’t want to lock out players, so I throttled things way back – leaving plenty of bandwidth open for no less than 10 users to do their bidding w/o any problems.

Yet… even with a dedicated portion of the pipe, users suddenly began to complain about inability to log in to the game. Once an active socket was opened, there were no problems, but people were generally incapable of opening said sockets…

About the same time, Penny started complaining from the couch that the laptop was having problems browsing web pages. I noticed that I too began to have problems opening up outgoing connections from any of our machines. I throttled the torrents waay back – leaving 3/4 of our bandwidth unused. And still, the problem did not go away.

I quit BitComet. The problem did not go away. I rebooted Tarma. No such luck there either.

Finally, I gave our router a violent kick to the head and rebooted it forcibly. The network was immediately cleansed and back to normal.

This problem has repeated itself numerous times since that first event. It became so reliable – if I so much as looked at BitComet, my network would sieze up – that I stopped downloading files all together until the mud had left the building. And then, I got into the habit of stopping torrents during the day so I could work, and then turning them back on when I went to sleep. I had assumed that BitComet was somehow opening up so many connections that it managed to exhaust the router’s capacity to handle them all.

Until today. [Cue dramatic music and lighting]

The answer (I hope) to all of my woes and problems finally hit me. BitComet was not leaving stale connections around. It has been overheating the router. See… they’re both fairly new (<1 year old) Linksys models, and this particular line of networking hardware is designed to stack together, so the router was sitting directly on top of the modem.

I figure the high number of different sockets created when added to the high amount of wan communication and the fact that Tarma is connected to the network via encrypted wifi (high amounts of radio energy plus extra computational power spent on every packet to maintain security) probably generated more heat than anything else I’ve done to this network.

Since, previously, my high traffic transactions had been mostly one-way communication (sending a file between two machines) and my torrents had been on Hedwig (who is plugged into the network via good old fashioned cat6 twisted pair)… yeah.

When I checked on my torrents this morning (Sousei no Aquarion for Penny), I noticed that they were acting unusually sluggish. Like really really slow. So, since I needed to get onto the web anyways to work on things, I went in to physically reboot the router. It was almost painfully hot to the touch. The modem underneath it was also practically a puddle of molten plastic.

I smacked myself in the head and proceeded to fashion a cardboard stand for the router from the packaging of some Atari computer game or another. There is now at least an inch of airflow between the two devices and I’ve had torrents running all day w/o interrupting my work.

I can even post rants on here and stuff 🙂