resources module

class resources.ACK(src, dest, fid, pid, expected)

Bases: resources.Packet

This class represents an acknowledgement packet.

Parameters:
  • src (int) – source host id
  • dest (int) – destination address
  • fid (int) – source flow id
  • pid (int) – packet id
  • expected (int) – next expected packet id
size = 512

Packet size (bits).

resources.DOWN = 0

Download direction.

class resources.Finish(payload)

Bases: resources.Routing

This class represents a finish packet.

Finish packets communicate that a router has locally converged, and are used to signal the termination condition for Bellman-Ford dynamic routing.

Parameters:payload (object) – packet payload
class resources.HostResource(env, addr)

Bases: resources.PacketQueue

SimPy resource representing a host.

This is a FIFO resource which handles packets for a host. If an inbound data packet is received, an acknowledgement is generated and sent, and the data packet itself is discarded (data packets don’t have a destination flow). Otherwise, packets emitted by local flows are transmitted into the network.

Parameters:
  • env (simpy.Environment) – the simulation environment
  • addr (int) – the address of this host
class resources.LinkBuffer(env, size, lid)

Bases: object

SimPy resource representing a link’s buffers.

This class is a full-duplex link implemented as a resource. Packet transmission is parametrized by direction, and every link has two allowed directions (resources.DOWN or resources.UP), each of which has a dedicated buffer. New packets are added to the appropriate buffer, to be dequeued by the process.Link that owns the resource instance.

Parameters:
  • env (simpy.Environment) – the simulation environment
  • size (int) – link buffer size, in bits
  • lid (int) – link id
buffered(direction)

Cumulative number of packets in a link buffer.

Parameters:direction (int) – link direction
Returns:cumulative buffer occupancy
Return type:int
dequeue(direction)

Dequeue a packet from the specified buffer.

Parameters:direction (int) – link direction
Returns:the dequeued packet
Return type:Packet or None
dropped

The number of dropped packets.

Returns:dropped packets
Return type:int
enqueue

Enqueue a packet in the specified direction.

This is a SimPy event, which is bound as a method to each LinkBuffer object upon its instantiation. When this event is yielded, it also returns a flag whose truth value indicates whether the packet was dropped (buffer was full) or not.

Parameters:
  • direction (int) – link direction
  • packet (Packet) – packet to enqueue
Returns:

dropped flag

Return type:

bool

alias of LinkEnqueue

id

Link id.

size

Maximum buffer capacity in bits.

Returns:buffer size (bits)
Return type:int
update_buffered(direction, time)

Update the cumulative buffer occupancy.

Parameters:
  • direction (int) – link direction
  • time (int) – time of the update
Returns:

None

class resources.LinkEnqueue(buffer_, direction, packet)

Bases: simpy.events.Event

SimPy event representing packet buffering.

This event represents the enqueuing of a packet in one of a link’s two buffers, as specified by direction. This event may also be used as a context manager.

Parameters:
  • buffer (LinkBuffer) – the buffer that this enqueuing event binds to
  • direction (int) – the direction of the buffer
  • packet (Packet) – the packet to enqueue
cancel(exception, value, traceback)
class resources.MonitoredEnvironment(initial_time=0, step=100000000)

Bases: simpy.core.Environment

SimPy environment with monitoring.

Processes may register identifiers, along with a getter (function) to be periodically called, and its return value recorded. Alternatively, processes may use the update method to add a value for the given identifier. Thus, the environment supports both periodic and process-controlled monitoring.

Parameters:
  • initial_time (int) – simulation time to start at
  • step (int) – registered value update period (ns)
monitored

The timestamped values of all monitored attributes.

Returns:monitored attribute dict
Return type:{str: [(int, object)]}
register(name, getter, avg=False, step=None)

Register a new identifier.

If the avg flag is set, the return value of the getter is divided by the time step over which the update is performed, in order to yield an average. The environment is initialized with a default step, but the step parameter may override it for the given identifier.

Parameters:
  • name (str) – identifier
  • getter (function) – getter function
  • avg (bool) – flag indicating whether to average the getter value
  • step (int) – update period for this identifier
Returns:

None

update(name, value)

Add a value for the specified identifier.

If the given identifier does not exist, an entry for it is created.

Parameters:
  • name (str) – identifier
  • value (object) – the value to add
Returns:

None

values(name)

The values for the given identifier.

Parameters:name (str) – the identifier to retrieve values for
Returns:timestamped values list
Return type:[(int, object)]
class resources.Packet(src, dest, fid, pid, payload=None)

Bases: object

This class represents a packet in our simulation.

Parameters:
  • src (int) – source host id
  • dest (int) – destination address
  • fid (int) – source flow id
  • pid (int) – packet id
  • payload (object) – packet payload
acknowledge(expected)

Generate an acknowledgement for this packet.

Parameters:expected (int) – the next packet id expected (ACK payload)
Returns:an acknowledgement packet matching this packet
Return type:ACK
data

The packet’s payload of data.

Returns:the payload of this packet
Return type:object
dest

The packet’s destination address.

Returns:destination address
Return type:int
flow

The ID of the sender (flow) on the source host.

Returns:flow ID on localhost
Return type:int
id

The ID of this packet.

Returns:packet ID for the source flow
Return type:int
size = 8192

Packet size (bits).

src

The packet’s source address.

Returns:source address
Return type:int
class resources.PacketQueue(env, addr)

Bases: object

SimPy resource for queuing packets.

This class is a FIFO SimPy resource. It receives packets, but does not accept packet transmission requests. Every packet arrival triggers a packet transmission, at which time the next packet in the queue is popped and returned.

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

The address of this resource.

Returns:resource address
Return type:int
receive

Receive a packet.

This is a SimPy event, which is bound as a method to each PacketQueue object upon its instantiation. When this event is yielded, it also returns a packet popped from the queue.

Parameters:
  • direction (int) – link direction
  • packet (Packet) – packet to enqueue
Returns:

a dequeued packet

Return type:

Packet

alias of ReceivePacket

class resources.ReceivePacket(resource, packet)

Bases: simpy.events.Event

SimPy event representing packet arrival.

This event takes a resource as a parameter, and represents the arrival of a packet at that resource. It also triggers a packet transmission for each packet received. This event may also be used as a context manager.

Parameters:
  • resource (PacketQueue) – the packet’s destination queue (resource)
  • packet (Packet) – a packet to receive
cancel(exception, value, traceback)
class resources.Routing(payload)

Bases: resources.Packet

This class represents a routing packet.

Parameters:payload (object) – packet payload
size = 512

Packet size (bits)

resources.UP = 1

Upload diretion.

resources.reset(klass)

Class decorator for adding a reset method.

The reset method takes an object, the name of an attribute, and optionally an index, retrieves the value of the attribute (at the index, if given), resets the value using its type constructor, and returns the original value. This class decorator is primarily for use with MonitoredEnvironment.register(); decorated classes may use the reset method to generically create a getter for a time- averaged value, since it both fetches and resets the value, as long as that value is stored in a class attribute.

Parameters:klass (class) – class to decorate
Returns:the decorated class
Return type:class