resources module¶
-
class
resources.ACK(src, dest, fid, pid, expected)¶ Bases:
resources.PacketThis 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.RoutingThis 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.PacketQueueSimPy 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:
objectSimPy 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.DOWNorresources.UP), each of which has a dedicated buffer. New packets are added to the appropriate buffer, to be dequeued by theprocess.Linkthat 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: Packetor 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
LinkBufferobject 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.EventSimPy 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)¶
- buffer (
-
class
resources.MonitoredEnvironment(initial_time=0, step=100000000)¶ Bases:
simpy.core.EnvironmentSimPy 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
updatemethod 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
stepparameter 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:
objectThis 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:
objectSimPy 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
PacketQueueobject 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: alias of
ReceivePacket
-
class
resources.ReceivePacket(resource, packet)¶ Bases:
simpy.events.EventSimPy 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)¶
- resource (
-
class
resources.Routing(payload)¶ Bases:
resources.PacketThis 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