Simulation

This module contains the simulation setup and execution.

ControlledEnvironment

class cs143sim.simulation.ControlledEnvironment(controller)[source]

SimPy Environment with a reference to its Controller

Parameters:controllerController that created the Environment

Controller

class cs143sim.simulation.Controller(case='cs143sim/cases/case0.txt')[source]

Controller that prepares, starts, and cleans up a run of the simulation

Parameters:

case (str) – path to simulation input file

Variables:
  • env – SimPy simulation Environment
  • flows (dict) – all Flows in the simulation
  • hosts (dict) – all Hosts in the simulation
  • links (dict) – all Links in the simulation
  • routers (dict) – all Routers in the simulation
  • buffer_occupancy (dict) – buffer occupancy records for each link; Links key to lists of (time, value) tuples
  • flow_rate (dict) – flow rate records for each flow; Flows key to lists of (time, value) tuples
  • link_rate (dict) – link rate records for each link; Links key to lists of (time, value) tuples
  • packet_delay (dict) – packet delay records for each flow; Flows key to lists of (time, value) tuples
  • packet_loss (dict) – packet loss records for each link; Links key to lists of (time, value) tuples
  • window_size (dict) – window size records for each flow; Flows key to lists of (time, value) tuples
make_flow(name, source, destination, amount, start_time, algorithm)[source]

Make a new Flow and add it to self.flows

Parameters:
  • name (str) – new Flow name
  • source – source Host
  • destination – destination Host
  • amount (int) – amount of data to transfer, in bits
  • start_time (float) – time the new Flow starts
make_host(name, ip_address)[source]

Make a new Host and add it to self.hosts

Parameters:
  • name (str) – new Host name
  • ip_address (str) – new Host‘s IP address

Make a new Host and add it to self.hosts

Parameters:
  • name (str) – new Link name
  • source – source Host or Router
  • destination – destination Host or Router
  • rate (float) – rate of data transfer, in Mbps
  • delay (float) – delay for data transfer, in ms
  • buffer_capacity (int) – size of receiver Buffer, in KB
make_router(name, ip_address, update_time)[source]

Make a new Router and add it to self.routers

Parameters:
read_case(case)[source]

Read input file at path case and create actors accordingly

Parameters:case (str) – path to simulation input file
record(recorder, actor, value)[source]

Record the time and value in the recorder keyed by the actor

Parameters:
  • recorder (dict) – recorder to record the change
  • actorActor that experienced the change
  • value – new value of changed quantity
record_buffer_occupancy(link, buffer_occupancy)[source]

Record the occupancy of a link buffer

Parameters:
  • linkLink changing its buffer occupancy
  • buffer_occupancy (float) – new buffer occupancy (bytes)
record_flow_rate(flow, packet_size)[source]

Record the size of a delivered packet

Parameters:
  • flowFlow to which the delivered packet belongs
  • packet_size (float) – size of the delivered packet (bits)

Record the duration a link sends a packet

Parameters:
  • linkLink sending the packet
  • packet_size (float) – size of the delivered packet (bits)
record_packet_delay(flow, packet_delay)[source]

Record the delay of a delivered packet

Parameters:
  • flowFlow to which the delivered packet belongs
  • packet_delay (int) – time since the delivered packet was sent (ms)
record_packet_loss(link)[source]

Record a packet loss

Parameters:linkLink that dropped the packet
record_window_size(flow, window_size)[source]

Record the flow’s window size

Parameters:
  • flowFlow changing its window size
  • window_size (int) – new window size
run(until=None)[source]

Run the simulation for a specified duration

Parameters:until (float) – simulation duration