======================================================================================================
SimPyNet is a composition of three words that characterise the project
- Simulator
- Python
- Network
simpynet
is a framework totally written in Python
,it is able to simulate the mechanism at any level of the TCP/IP protocol suite model (physical,link, network, transport, application).
simpynet
is based on the DES (Discrete-Event-Simulation) simulation model.
The simulator doesn't provide a GUI (such as other simulator GNS3,OMNeT++) but is recommended for teaching purpose, because are required programming skills.
simpynet
provides a logging
mechanism and collectors
machanism. The first is utilized for logging the information during the exectution of the simulation the latter for collectiong parameters in order to realize statistical
analysis.
simpynet
was born as support theaching software for the course of Computer Network at University of Florence.
- Python 2.7
- simpy
- Download the archive of the latest release X.Y
- Unpack the archive name
tar -xzf simpynet-X.Y.tar.gz
(orzip
) and will unpack into a directorysimpynet-x.y
- Create a virtualenv and activate it with the command
source /path_to_venv/bin/activate
- Enter in the
simpynet-x.y
directory and run the commandpython setup.py install
This program simulate a DHCP client and DHCP server interaction: the client asks for an IP address and the server will send the rigth one.
Create a new file called prova.py
and paste inside the followed code.
import simpynet as spn
def DHCP_network( env ):
"""
|dhcp_client|------link 1------ |dhcp_server|
"""
# creates the two Host: client and server with their own MAC and IP address
c_host = spn.Host( env, spn.Mac('aa.aa.aa.aa.aa.aa'), spn.IP('0.0.0.0') )
s_host = spn.Host( env, spn.Mac('bb.bb.bb.bb.bb.bb'), spn.IP('192.168.1.1') )
# create a Link1 with propagation delay and trasmission delay one
l1 = spn.Link(env, lambda x,y: 1 , lambda src,trg,l: 1)
#plugs the link to the host server and the host client
spn.physical.plug( l1 , c_host )
spn.physical.plug( l1 , s_host )
# wrap the general HOst in the DHCP client and server
client=spn.DHCP_client( env , c_host )
server=spn.DHCP_server( env , s_host )
# function exeuted by the client to choose the DHVP server
def choose_ip_server( lista_ip):
if len(lista_ip) > 0:
return lista_ip.pop(0)
else: return None
#function executed by the server whe it must choose an IP address for the client
def choose_ip_for_client():
return '123'
server.add_function_choose( choose_ip_for_client)
client.add_function_choose( choose_ip_server)
def funct():
yield env.timeout(1)
client.send_DHCP_DISCOVERED()
env.process( funct())
Add this three line of code for running the simulation at the end of the file.
e=spn.Environment() # create a new Environment
e.add_network(DHCP_network) # add the network to the environment
e.run( 1, spn.__TRANSPORT_LOG_N__) #run the simulation, and save the log information up to Transort level
- Open the terminal and run
python prova.py
- Look in the same level wher the file
prova.py
is. There is a file namedsimpynet_log
where the logging information of the simulation are stored.