2

I learn network programming on Python: write client-server and client-client software with TCP, UDP, ICMP, ARP, etc protocols.

I need a tool for emulating network with N hosts with following capabilites:

  1. Lightweight software that can create N (2, 5, 10, ...) hosts with python interpreter on each of them (all are on my computer!). Virtual machines like Virtualbox seem too heavy and impose incredible RAM requirements. I need only python interpreter and network stack support.

  2. The ability to configure the whole network quality like "drop 10% of packets" or "make signal delay to 500 msec"

  3. The ability to configure responses to certain requests for each host apart. Like "ping to google.com from host #5 should return "remote network is not reachable" but "ping to yahoo.com from host #5" should be ok.

  4. Of course there is a full logging what happening in my network.

Is there a such software or framework (for Windows 7 and Linux)?

Kara
  • 6,115
  • 16
  • 50
  • 57
lansman
  • 31
  • 4
  • Also i have a GET request via requests lib or pycurl to remote site. How can i wrap my python script to catch that request and make a response for my own (for debugging and unittesting purposes) **without changing the source code**? – lansman Apr 10 '13 at 09:48

2 Answers2

0

You'll have to write your own code to cover your exact spec.

  1. You can mimic multiple servers using one server with different ports for each host - if you want a different IP you for each host you'll need work out how to create virtual network connections.
  2. To control network noise you can add random and time.sleep statements to your python server app.
  3. You can set different apps on different ports to respond in different ways, if you write the code yourself.
  4. For logging, the python logging module is excellent.

Python has a simple HTTP server built in:

import SimpleHTTPServer
import SocketServer

PORT = 8000

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler

httpd = SocketServer.TCPServer(("", PORT), Handler)

print "serving at port", PORT
httpd.serve_forever()

or you can serve python requests using something like FastCGI

def myapp(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return ['Hello World!\n']

if __name__ == '__main__':
    from fcgi import WSGIServer
    WSGIServer(myapp).run()

just replace myapp with the python commands that you want to be executing.

danodonovan
  • 19,636
  • 10
  • 70
  • 78
0

For listening only you could create multiple interfaces (aliases) like that:

ifconfig eth0:0 192.168.5.12 netmask255.255.255.0 up 
ifconfig eth0:1 192.168.5.13 netmask255.255.255.0 up

Later you make each of the instance of the aplication listen on another interface.

But if you need to send packages from different ifaces you would have to reconfigure routing table everytime you do it. And that does not cover other functions you specified.

I would go with some lightweight, highly configurable linux distro without ui on separate virtual machines.

Jarosław Jaryszew
  • 1,414
  • 1
  • 12
  • 13