Simulating Network Problem Using iptables Command

October 19, 2009

In a distributed system where communication between services are happening at all time and at the same time network issues or hiccups occur frequently.  A well designed service consumer should able to handle the network connection or timeout issues in a graceful manner.  This issue is magnified to multiple folds if a service client is time bound and expects responses to come back in milliseconds.  So what are the general guidelines or best practices for dealing with the issues outlined above?

Here is a short list of possible solutions.  One must carefully pick the right solution for one’s specific application needs.

  • Exponential backoff – more info
  • Denied access gate with background pinging thread

Regardless of which solution is chosen, what is a good way to simulate the network issues.  This is where the “iptable” command comes in. “iptable” command is generally used by network administrators to administer the tables of IP packet filter rules.  The rule that is useful for our purpose is “DROP”, which drops the packets on the floor.    To simulate a network connection, we can setup a filter rule for a specific host such that all packets that are supposed to go this host will be dropped on the floor.

In short here is the command to set up such filter rule:

sudo iptables -A OUTPUT -p tcp -d <remote host ip> –dport <remote port> -j DROP

When testing is done, make sure to remove the packet filter rule with the following command:

sudo iptables -D OUTPUT -p tcp -d <remote host ip> –dport <remote port> -j DROP

Now we know how to simulate network connection issue and this should help in testing the connection issue error handling code.


Flex Is Not Friendly To REST

December 26, 2007

I am a big fan of Flex until now and the reason is the HTTPService that Flex provides doesn’t play well with REST. You see I am developing an application that uses Jersey/Spring/JPA on the server side and my plan was to use Flex to talk to the server side using Restful style web services. The problem is HTTPService class has several major limitations:

  1. Only GET and POST methods are supported out of the box (unless you use FDS and set useProxy attribute to true)
  2. Not able to set request headers and there is no access to response headers. Therefore I am not able to access the response body in the case of an error.
  3. It HTTPService gets a status code anything other 200, it consider an error. (event 201, ouch!!). The FaultEvent doesn’t provide information about the status code any response body. The Flex client will have no idea what went wrong.

I have spent quite a bit of time reading blogs after blogs about these issues and I don’t see an clean solution out there yet. Here is a list of blogs that talk about the very same issues that I listed above

I am doing research for a couple more days and if I can’t find anything clean solution to overcome these limitations, I am afraid Flex will not be used in this project. This is really disappointing!!

Drop me a note if you know any tips or tricks to overcome the limitations of HTTPService.