Skip to content
Daniel Zappala edited this page Mar 19, 2014 · 2 revisions

Bene is a simple, event-driven simulator in Python. The heart of the simulator is an event scheduler, which manages a clock for simulated time and a queue of events that will occur in the future:

The simulator takes the most recent event off the queue, advances the clock to the time of this event, and calls an event handler for the event. The event handler generally adds one or more events to the scheduler as a consequence of the scheduled event.

For example, if node is handling a packet at time t1, the handler for this event may schedule an event for that packet to arrive at the next node at time t2. It may also add another event at time t3 for the node to start processing the next packet in the queue.

To start the simulation, you simply add the first event to the queue, and then this event will schedule additional events. The simulation ends when all events have been handled (the event queue is empty), or you may choose to run it for a defined length of time.

Because the simulator is event-driven, you must write all your code to be event-driven as well. Anything that occurs in a handler for an event at time t1 takes places instantaneously at t1. If you need to simulate some event that should take delay seconds, then schedule a new event at t1 + delay, which represents the finish time of that event.

Layers

The simulator includes an application layer, transport layer (transport.py, connection.py, stopandwait.py), network layer (node.py), and link layer (link.py). By convention, any object can be given a packet from its upper layer protocol using its send_packet() method. Likewise, any object can be given a packet from its lower layer protocol using receive_packet() method.

Clone this wiki locally