process module

class process.FAST(flow, window, timeout, alpha, gamma=0.5)

Bases: process.TCP

SimPy process implementing FAST TCP.

Parameters:
  • flow (Flow) – the flow to link this TCP instance to
  • window (int) – initial window size (packets)
  • timeout (int) – packet acknowledgement timeout (ns)
  • alpha (int) – desired number of enqueued packets at equilibrium
  • gamma (float) – window update weight
acknowledge(ack)

Process an acknowledgement packet.

Parameters:ack (resources.ACK) – the acknowledgement packet
Returns:None
burst(recover=False)

Inject packets into the network.

If recover is True, then the packets are taken from the set of timed out packets.

Parameters:recover (bool) – flag for recovery mode
Returns:None
recover()

Enter recovery mode.

Returns:None
send()

Send all data packets.

Returns:None
class process.Flow(env, host, dest, data, delay, tcp, tcp_params)

Bases: object

SimPy process representing a flow.

Each flow process is connected to a source host, and generates as many packets as are necessary to send all of its data. If data is None, a random, 12-bit number of packets are sent. Every flow needs a TCP algorithm to be specified, from among the currently supported TCP algorithms. At the moment, the only allowed specifiers are “FAST”, and “Reno”. See FAST or Reno for details on what tcp_params should look like.

Parameters:
  • env (simpy.Environment) – the simulation environment
  • host (Host) – the source host of this flow
  • dest (int) – the address of the destination host
  • data (int) – the total amount of data to transmit (bits)
  • delay (int) – initial delay before sending any packets (ns)
  • tcp (str) – TCP algorithm specifier
  • tcp_params (list) – parameters for the TCP algorithm
acknowledge(ack)

Receive an acknowledgement packet.

Acknowledgement packets are passed to the underlying TCP algorithm to be handled.

Parameters:ack (resources.ACK) – acknowledgement packet
Returns:None
allowed_tcp = {'FAST': <class 'process.FAST'>, 'Reno': <class 'process.Reno'>}

A dict mapping TCP specifiers to TCP subclasses.

data

The total amount of data to transfer.

Returns:data size (bits)
Return type:int
dest

The destination address for this flow.

Returns:destination address
Return type:int
env

The simulation environment.

Returns:SimPy environment
Return type:simpy.core.Environment
finished

Transmission finished event.

This event is only successful once all data packets have been sent, and any dropped packets retransmitted successfully.

Returns:finished event
Return type:simpy.events.Event
generate()

Generate packets from this flow.

Returns:None
generator()

Create a packet generator.

If a data size is given, return a generator which yields ceil(data size / packet size) packets. If data size is None, it yields a random, 12-bit number of packets.

Returns:packet generator
Return type:generator
host

The host of this flow.

Returns:localhost
Return type:Host
id

The ID of this flow, assigned by its host.

Returns:flow id, relative to localhost
Return type:int
reset(attr, index=None)

Get the value of the specified attribute, and reset it.

Parameters:
  • attr (str) – attribute name
  • index (object) – index in the container referenced by self.attr
Returns:

self.attr, before resetting its value

Return type:

object

transmit(packet)

Transmit an outbound packet to localhost.

Parameters:packet (resources.Packet) – the data packet to send
Returns:None
class process.Host(env, addr)

Bases: object

SimPy process representing a host.

Each host process has an underlying HostResource which handles (de)queuing packets. This process handles interactions between the host resource, any active flows, and up to one outbound link.

Parameters:
  • env (simpy.Environment) – the simulation environment
  • addr (int) – the address of this host
addr

The address of this host.

Returns:host address
Return type:int
connect(transport)

Connect a new (link) transport handler to this host.

Parameters:transport (Transport) – transport handler
Returns:None
disconnect(transport)

Disconnect an existing transport handler.

If the given transport handler is not connected to this host, do nothing.

Parameters:transport (Transport) – the transport handler to disconnect
Returns:None
env

The simulation environment.

Returns:SimPy environment
Return type:simpy.core.Environment
flows

A list of flows active on this host.

Returns:a list of flows
Return type:[Flow]
receive(packet)

Receive a packet.

Packets may be inbound or outbound, data or acknowledgement packets. Inbound data packets automatically generate an outbound acknowledgement.

Parameters:packet (resources.Packet) – the packet to process
register(flow)

Register a new flow on this host, and return the flow ID.

Parameters:flow (Flow) – a new flow to register with this host
Returns:None
reset(attr, index=None)

Get the value of the specified attribute, and reset it.

Parameters:
  • attr (str) – attribute name
  • index (object) – index in the container referenced by self.attr
Returns:

self.attr, before resetting its value

Return type:

object

transmit(packet)

Transmit a packet.

Inbound data packets are replaced by an acknowledgement packet when they exit the host’s internal queue, so there are only two cases: packets may be outbound, or they are ACK’s destined for a flow on this host.

Parameters:packet (resources.Packet) – the outbound packet
Returns:None
transport

The connected transport handler, if it exists.

Returns:transport handler
Return type:Transport or None

Bases: object

SimPy process representing a link.

Each link process has an underlying LinkResource which handles (de)queuing packets. This process handles interactions between the link resource, and the processes it may connect.

Parameters:
  • env (simpy.Environment) – the simulation environment
  • capacity (int) – the link rate (bps)
  • size (int) – the link buffer size (bits)
  • delay (int) – the link delay in (ns)
  • lid (int) – link id
capacity

The maximum bitrate of the link in bps.

Returns:link rate
Return type:int
connect(A, B)

Connect two network components via this link.

Parameters:
  • A (Host, or Router) – the first new endpoint of this link
  • B (Host, or Router) – the second new endpoint of this link
Returns:

None

cost(direction)

Return the cost of a direction on this link.

Total cost is calculated as propagation delay / log(capacity / data packet size) + cumulative buffer occupancy.

Parameters:direction (int) – link direction
Returns:directional link cost
Return type:float
delay

The link delay in nanoseconds.

Returns:link delay
Return type:int
disconnect()

Disconnect a link from its two endpoints.

Returns:None
endpoints

A list of connected endpoints (up to 1 per direction)

Returns:connected endpoints
Return type:list
env

The simulation environment.

Returns:SimPy environment
Return type:simpy.core.Environment
id

Link id.

Returns:id
Return type:int
receive(direction, packet)

Receive a packet to transmit in a given direction.

New packets are appended to one of the link’s internal directional buffer. All link buffers are drop-tail.

Parameters:
  • direction (int) – the direction to transport the packet
  • packet (resources.Packet) – the packet to send through the link
Returns:

None

reset(attr, index=None)

Get the value of the specified attribute, and reset it.

Parameters:
  • attr (str) – attribute name
  • index (object) – index in the container referenced by self.attr
Returns:

self.attr, before resetting its value

Return type:

object

class process.Reno(flow, window, timeout)

Bases: process.TCP

SimPy process implementing TCP Reno.

Parameters:
  • flow (Flow) – the flow to link this TCP instance to
  • window (int) – initial window size (packets)
  • timeout (int) – packet acknowledgement timeout (ns)
acknowledge(ack)

Process an acknowledgement packet.

Parameters:ack (resources.ACK) – the acknowledgement packet
Returns:None
burst(recover=False)

Inject packets into the network.

If recover is True, then the packets are taken from the set of timed out packets.

Parameters:recover (bool) – flag for recovery mode
Returns:None
send()

Send all data packets.

Returns:None
class process.Router(env, addr)

Bases: object

Simpy process representing a router.

Router objects each have an underlying PacketQueue resource which receives all inbound packets. When a new packet is received, it triggers a packet transmission event. The dequeued packet is routed based on its destination, and data packets are sent to the appropriate transport handler (link).

Parameters:
  • env (simpy.Environment) – the simulation environment
  • addr (int) – the address of this router
addr

The address of this router.

Returns:router address
Return type:int
begin()

Periodically update routing tables with Bellman-Ford.

Returns:None
connect(transport)

Connect an outbound link.

Parameters:transport (Transport) – transport handler
Returns:None
disconnect(transport)

Disconnect a link, if it exists.

Parameters:transport (Transport) – the transport handler to disconnect
Returns:None
env

The simulation environment.

Returns:SimPy environment
Return type:simpy.core.Environment
receive(packet)

Receive a packet, and yield a transmission event.

Parameters:packet (resources.Packet) –
Returns:None
route(address)

Return the correct transport handler for the given address.

Raises a KeyError if the given address is not in the routing table.

Parameters:address (int) – the destination address
Returns:the transport handler selected by the routing policy
Return type:Transport
routers

Transport handlers connected to routers.

Returns:a list of outbound transport handlers
Return type:[Transport]
transmit(packet, transport)

Transmit an outbound packet.

Parameters:
Returns:

None

class process.TCP(flow, window, timeout)

Bases: object

TCP algorithm abstract base class.

This class defines a number of properties & utility functions for use by subclasses, as well as a mostly abstract API for use by the Flow class.

Parameters:
  • flow (Flow) – the flow to link this TCP instance to
  • window (int) – initial window size (packets)
  • timeout (int) – packet acknowledgement timeout (ns)
acknowledge(ack)

Process an acknowledgement packet.

This abstract method must be implemented by a subclass.

Parameters:ack (resources.ACK) – the acknowledgement packet
Returns:None
departure(pid)

Get the departure time of an unacknowledged packet.

Raises a KeyError if the packet is not currently unacknowledged.

Returns:time, if packet id has a match
Return type:int or None
finished

Transmission finished event.

This event is only successful once all data packets have been sent, and any dropped packets retransmitted successfully.

Returns:finish event
Return type:simpy.events.Event
flow

The flow that this TCP algorithm is connected to.

Returns:host flow
Return type:Flow
mark(pid)

Mark a packet as acknowledged.

Raises a KeyError if the packet is not currently unacknowledged.

Parameters:pid (int) – the id of the packet to acknowledge
Returns:None
max_time

The maximum acknowledgement timeout length.

Returns:maximum timeout (ns)
Return type:int
packet(pid)

Get an unacknowledged packet with the given id.

Raises a KeyError if the packet is not currently unacknowledged.

Parameters:pid (int) – packet id
Returns:the unacknowledged packet
Return type:resources.Packet
send()

Send all data packets.

This abstract method must be implemented by a subclass.

Returns:None
timed_out

List of timed out packets.

Returns:timed out packets
Return type:[resources.Packet]
timeout

The time after which packets are considered dropped.

Returns:acknowledgement timeout (ns)
Return type:int
transmit(packet)

Transmit a data packet to the host flow.

Parameters:packet (resources.Packet) – the data packet to send
Returns:None
unacknowledged

Unacknowledged packet dictionary.

This dictionary maps unackowledged packets to their departure time.

Returns:unackowledged packets
Return type:{resources.Packet: int}
window

Transmission window size (bits).

Returns:window size (bits)
Return type:int
class process.Transport(link, direction)

Bases: object

This class is a directional transport handler for a link.

Direction should be one of resources.UP or resources.DOWN

Parameters:
  • link (Link) – the underlying link
  • direction (int) – packet transmission direction
capacity

Capacity of the underlying link in bps.

Returns:link rate
Return type:int
cost

Directional cost of the underlying link.

Returns:link cost
Return type:float
direction

The direction of this transport handler.

Returns:link direction
Return type:int

The link that owns this transport handler.

Returns:underlying link
Return type:Link
reverse()

Return a transport handler in the opposite direction.

Returns:transport handler
Return type:Transport
send(packet)

Send a packet across the link.

Parameters:packet (resources.Packet) – the packet to send
Returns:Link.receive() (generating method)
Return type:generator