Rerouting outbound traffic to a simulated device on localhost

In this post, we will outline how we reroute traffic meant for a specific IP back to a synthetic device running on localhost. This is useful for testers who work with products that monitor IT infrastructure, infrastructure management application testers and network testers. We will be using a couple of Python modules (fake-switches, snmpsim) and editing the iptables of the central monitoring server.

 

1. Background
One of Qxf2’s favourite clients works in the IT Services Management and IT Automation space. They have a suite of world class IT management and monitoring tools. Some of their data collection happens over SNMP. Without revealing much, the product involves a central monitoring server that collects data from a variety of agents and devices that are either discovered or explicitly added using an IP.

 

2. Why use simulated devices?
We use a combination of real and synthetic devices when testing the product. The real devices are needed because (to paraphrase Conan Doyle) – life is infinitely stranger than anything which the mind of a QA could invent. We need simulated devices (generic devices/switches/routers) to test portions of the platform in a consistent and repeatable manner.

 

3. Scope of this blog post
In this post, we will make an already setup monitoring server to run 2 simulated devices.

a) All outgoing TCP connections from the monitoring server to the IP 2.2.2.2 will be routed to a fake switch on 127.0.0.1:8085
b) All outgoing UDP connections (SNMP uses UDP) from the monitoring server to the IP 2.2.2.3 will be routed to a simulated device on 127.0.0.1:8086

Note: There is nothing special about the IPs 2.2.2.2 and 2.2.2.3 being used here. You can substitute it with any IP you want.

 

4. Toolbelt:
We have chosen to use two Python modules – fake-switches and snmpsim – to simulate our devices. We chose these two modules because of their ease of getting setup and are sufficiently configurable for our purpose. Setup is literally a ‘pip install’ followed by one command to kick off the device. In this post, we will not go over the configuration of the devices themselves. Instead, we will focus on how to make the monitoring server think that is talking to a specific IP address when in reality, it is talking to one of our simulated devices.

 

5. Rerouting all outgoing TCP traffic to 2.2.2.2 back to localhost:8085

a) [setup] pip install fake-switches
b) Start a switch on port 8085
fake-switches --hostname my-great-switch --username admin --password istrator --listen-host 127.0.0.1 --listen-port 8085 &
c) Change the IPtables
sudo iptables -t nat -A OUTPUT -p tcp -d 2.2.2.2 --dport 1:65535 -j DNAT --to-destination 127.0.0.1:8085
d) To test the rerouting, run ssh admin@2.2.2.2 and verify that you can login using the password set in step b)

 

6. Rerouting all outgoing UDP traffic to 2.2.2.3 back to localhost:8086

a) [setup] pip install snmpsim
b) Start a snmpsim device on 8086
snmpsimd.py --data-dir=./data --agent-udpv4-endpoint=127.0.0.1:8086 &
c) Changed the iptables
sudo iptables -t nat -A OUTPUT -p udp -d 2.2.2.3 --dport 1:65535 -j DNAT --to-destination 127.0.0.1:8086
d) To test the rerouting, run snmpwalk -v1 -c public 2.2.2.2 and verify you see some SNMP response

 

And that’s it! We have skipped over many details in this post because we cannot share screenshots and steps specific to the application we are testing. If you feel like you need more help, please post a question below.


Arunkumar Muralidharan

I want to find out what conditions produce remarkable software. A few years ago, I chose to work as the first professional tester at a startup. I successfully won credibility for testers and established a world-class team. I have lead the testing for early versions of multiple products. Today, I run Qxf2 Services. Qxf2 provides software testing services for startups. If you are interested in what Qxf2 offers or simply want to talk about testing, you can contact me at: mak@qxf2.com. I like testing, math, chess and dogs.

Be First to Comment

Leave a Reply

Your email address will not be published.