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.


Small Stuff That Matters – Ubuntu File Associations

March 10, 2009

Often times there is a little thing that you would like to figure out how to do it and because it is little you tend to delay trying to figure out due to your busy schedule.

An example of this little thing is figuring out how to associate an application to a file based on file type on Ubuntu. In my case is PDF files. By default “Document Viewer” is used to display the content of a PDF file and it works, but I prefer to use Acrobat Reader. Of course the solution is already out there if you search for it, but what I am amazed at is people are really happy whey they found that solution and I know this because of their thank you notes.

Following the DRY principle, here is the link to the solution that I found.