Actors

This module contains all actor definitions.

Actor(env[, name]) Representation of an actor
Buffer(env, capacity, link) Representation of a data storage container
Flow(env, name, source, destination, amount) Representation of a connection between access points
Host(env, name, address) Representation of an access point
Link(env, name, source, destination, delay, ...) Representation of a physical link between access points or routers
Router(env, name, address[, update_time]) Representation of a router

Actor

class cs143sim.actors.Actor(env, name=None)[source]

Representation of an actor

The superclass of all actors defining environment variables.

Parameters:
  • env – SimPy simulation Environment
  • name (str) – name from input file
Variables:
  • env – SimPy simulation Environment
  • name (str) – name from input file

Buffer

class cs143sim.actors.Buffer(env, capacity, link)[source]

Representation of a data storage container

Buffers store data to be linked while Link is busy sending data.

Parameters:
  • capacity (int) – maximum number of bits that can be stored
  • linkLink containing this buffer
Variables:
  • capacity (int) – maximum number of bits that can be stored
  • linkLink containing this buffer
  • packets (list) – Packets currently in storage
  • current_level (int) – the current occupancy of the buffer
add(packet)[source]

Adds packet to packets if capacity will not be exceeded, drops packet if buffer if full.

Parameters:packetPacket added to buffer.
get(timeout=None)[source]

Link get a packet from its buffer.

:param timeout

Flow

class cs143sim.actors.Flow(env, name, source, destination, amount, algorithm=0)[source]

Representation of a connection between access points

Flows try to transmit data from Host to Host.

Parameters:
  • source – source Host
  • destination – destination Host
  • amount (float) – amount of data to transmit
  • algorithm (int) – indicate which tla this flow is using
Variables:
  • source – source Host
  • destination – destination Host
  • amount (float) – amount of data to transmit
  • algorithm (int) – indicate which tla this flow is using
  • rcv_expect_to_receive – next packet expect to receive
  • rcv_received_packets – list of packets that have been received, but not what we need now.
make_ack_packet(packet)[source]

Make an ack packet

make_packet(packet_number)[source]

Make a packet based on the packet number

send_packet(packet)[source]

When possible, TLA use this method to send a packet

time_out(timeout_packet_number)[source]

When time out happens, run TLA

Time_out timers should be reset if a the ack arrive

Host

class cs143sim.actors.Host(env, name, address)[source]

Representation of an access point

Hosts send Packets through a Link to a Router or to another Host.

Parameters:

address (str) – IP address

Variables:

Router

class cs143sim.actors.Router(env, name, address, update_time=1000)[source]

Representation of a router

Routers route packets through the network to their destination Hosts.

Parameters:
  • address (str) – IP address for router
  • links (list) – all connected Links
  • update_time (float) – the time interval of updating routing tables
Variables:
  • address (str) – IP address for router
  • links (list) – all connected Links
  • table (dict) – routing table
  • default_gateway – default out port if can not decide route
  • update_time (float) – the time interval of updating routing tables
generate_router_packet()[source]

Design RouterPacket(source,timestamp,routertable) that send the whole router table of this router to communicate with its neighbor

initialize_routing_table(all_host_ip_addresses)[source]

the key of table is destination (IP_address of hosts) the first element in value of table is the distance between current router to final host the second element in value of table is where to go for next hop

If the host destination is not in neighbor links, then set the distance to be inf, the next_hop to be the default_gateway If the host destination is in its neighbor links, then set the distance to be 1( dynamic still inf?), the next_hop to be direct host destination

react_to_packet_receipt(event)[source]

Read packet head to tell whether is a DataPacket or a RouterPacket

If it is normal packet, call map_route function If it is update_RT_communication packet, call update_router_table function

react_to_routing_table_outdated(event)[source]

Periodically generate RouterPacket to all neighbor links.

send(link, packet)[source]

Send packet to certain link

The packet could be normal packet to forward or communication packet to send to all links.

update_router_table(router_packet)[source]

Check every item in router table if any update

Implement Bellman-Ford algorithm here. Measurement is number of hops if DYNAMIC_ROUTE_DISTANCE_METRIC = False. Measurement is link delay if DYNAMIC_ROUTE_DISTANCE_METRIC = True.