blackwidow.network package

Submodules

blackwidow.network.device module

class blackwidow.network.device.Device(net_addr)[source]

Bases: object

Super class for the Host and Router classes.

Parameters:

net_addr : string

A unique id for the device in the network.

Attributes

network_id (string) A unique id of the device in the network.
links (list) A list of links that the device is connected to.

Methods

add_link(link) Adds the specified Link object to links.
delete_link(link) Remotes the specified Link object from links.

Add link to list of links.

Parameters:

link : Link

The link to add to the device.

Remove link from list of links.

Parameters:

link : Link

The link to remove from the device.

send(packet)[source]

Virtual method for sending device packets.

Parameters:

packet : Packet

Packet to send.

blackwidow.network.event module

class blackwidow.network.event.Event(type, src_id, f, **kwargs)[source]

Event object to run.

This object contains a function to run with any arguments. This is used by other objects to run specific functions at some time.

Parameters:

type : string

A message specifying the type of the event.

src_id : string

The id of the source object creating the event.

f : func

The function to run.

kwargs : dict

Keyword arguments to provide to f.

Notes

The event is initialized with a id. The Event class keeps a static id that is updated for each event to create a unique id.

Attributes

id (string) The event id.
src_id (string) The id of the object that created the link.
type (string) The type of the event.

Methods

run() Runs the event.
run()[source]

Runs the event.

Calls the function f with keyword arguments kwargs.

blackwidow.network.fast_flow module

class blackwidow.network.fast_flow.FastFlow(flow_id, source, destination, amount, env, time, bw)[source]

Bases: blackwidow.network.flow.Flow

Implements FAST TCP. Flows will trigger host behavior.

Parameters:

flow_id : string

A unique id for the flow.

source : Device

The source for the flow.

destination : Device

The destination for the flow.

amount : int

The amount of data to send in MB.

env : Network

The network that the flow belongs to.

time : float

The amount of time to wait before starting to send in ms.

bw : Blackwidow

The printer to print data to

Attributes

flow_id (string) The flow id.
src (Device) The source for the flow.
dest (Device) The destination for the flow.
amount (int) The amount of data left to send in MB.
env (Network) The network that the flow belongs to.
flow_start (float) The amount of time to wait before starting to send. Specified in ms.
pack_num (int) The next pack_num to check to send.
cwnd (float) Congestion window size.
ssthresh (float) Slow start threshold
resend_time (float) ms before packets are sent after an ack receival
min_RTT (float) Minimum round trip time observed for this flow
last_RTT (float) Last round trip time observed for this flow
SRTT (float) Weighted average of round trip times biased towards recent RTT
RTTVAR (float) Variance of round trip times
RTO (float) Retransmission timeout in ms
packets_sent (list) List of packets that have been sent but haven’t had their ack received
packets_time_out (list) List of packets that have exceeded timeout and need to be resent
acks_arrived (set) Set of ack packets that have been received
done (int) 0 if flow isn’t finished; 1 if flow is finished. Used to avoid decrementing flow more than once.
send_rate (Rate_Graph) Keeps track of the rate the flow is sending at and outputs to CSV file in real time.
receive_rate (Rate_Graph) Keeps track of the rate the flow is receiving at and outputs to CSV file in real time.
alpha (float) alpha in FAST TCP algorithm; alpha = 20 because link rates are between 10 Mbps and 1 Gbps.
gamma (float) gamma in FAST TCP algorithm; smoothing factor for window size
total_num_pack (int) total number of packets that need to be sent

Methods

send_packet() Send a packet.
_reset_window()[source]

This is called when a packet timeout occurs by the parent Flow class. Does nothing since FAST TCP automatically updates every 20 ms.

_respond_to_ack()[source]

Overwrites parent Flow class’ method because it shouldn’t change window size.

_update_window()[source]

Send a packet.

send_packet()[source]

Send a packet. The difference between FastFlow’s send_packet and Flow’s send_packet is the ending behavior. FastFlow just keeps resending packets it hasn’t received yet until it is done after it has sent all the packets once.

blackwidow.network.flow module

class blackwidow.network.flow.Flow(flow_id, source, destination, amount, env, time, bw)[source]

Bases: object

Simple class for flows. Flows will trigger host behavior. Has slow start and congestion avoidance.

Parameters:

flow_id : string

A unique id for the flow.

source : Device

The source for the flow.

destination : Device

The destination for the flow.

amount : int

The amount of data to send in MB.

env : Network

The network that the flow belongs to.

time : float

The amount of time to wait before starting to send. Specified in ms.

bw : Blackwidow

The printer to print data to

Attributes

flow_id (string) The flow id.
src (Device) The source for the flow.
dest (Device) The destination for the flow.
amount (int) The amount of data left to send in MB.
env (Network) The network that the flow belongs to.
flow_start (float) The amount of time to wait before starting to send. Specified in ms.
pack_num (int) The next pack_num to check to send.
cwnd (float) Congestion window size.
ssthresh (float) Slow start threshold
resend_time (float) ms before packets are sent after an ack receival
min_RTT (float) Minimum round trip time observed for this flow
last_RTT (float) Last round trip time observed for this flow
SRTT (float) Weighted average of round trip times biased towards recent RTT
RTTVAR (float) Variance of round trip times
RTO (float) Retransmission timeout in ms
packets_sent (list) List of packets that have been sent but haven’t had their ack received
packets_time_out (list) List of packets that have exceeded timeout and need to be resent
acks_arrived (set) Set of ack packets that have been received
done (int) 0 if flow isn’t finished; 1 if flow is finished Used to avoid decrementing flow more than once.
send_rate (Rate_Graph) Keeps track of the rate the flow is sending at and outputs to CSV file in real time.
receive_rate (Rate_Graph) Keeps track of the rate the flow is receiving at and outputs to CSV file in real time.

Methods

receive(packet) Generate an ack or respond to bad packet.
send_packet() Send a packet.
_reset_window()[source]

Called when a packet timeout occurs. Sets ssthresh to max(2, cwnd/2) and cwnd to 1.

_respond_to_ack()[source]

Update window size.

_send_ack(packet)[source]

Creates ack for packet. Parameters ———- packet : Packet

The packet to be received.
_timeout(pack_num)[source]

Generate an ack or respond to bad packet. Parameters ———- pack_num : `Packet`number

The packet number of the packet to check for timeout.
_update_RTT(packet)[source]

Update last RTT and min RTT and retransmission timeout. Parameters ———- packet : Packet

The packet that was received. Need this to get the timestamp
receive(packet)[source]

Generate an ack or respond to bad packet. Parameters ———- packet : Packet

The packet to be received.
send_packet()[source]

Send a packet.

blackwidow.network.host module

class blackwidow.network.host.Host(host_id)[source]

Bases: blackwidow.network.device.Device

Simple class for hosts.

Hosts are mainly responsible for recording their time data. They don’t trigger events in the simulation, but it will be useful to separate host data (end to end data). Flows will trigger host behavior.

Parameters:

host_id : string

A unique id for the host.

Attributes

network_id (string) A unique id of the device in the network.
links (list) A list of links that the host is connected to.
flows (list) A list of flows that use the host.

Methods

add_flow(flow) Adds receiving flow to host.
delete_flow(flow) Delete flow from the host.
send(packet) Sends a packet to a link.
receive(packet) Receives a packet from a link.
add_flow(flow)[source]

Add receiving flow to host.

Parameters:

flow : Flow

The flow to add to the host.

delete_flow(flow)[source]

Delete flow from host.

Parameters:

flow : Flow

The flow to add to the host.

receive(packet)[source]

Send packet to flow to process.

Parameters:

packet : Packet

The packet to be received.

send(packet)[source]

Connects to a link.

Parameters:

packet : Packet

The packet to send.

blackwidow.network.network module

class blackwidow.network.network.Network(bw)[source]

Python representation of the network.

Each host, router, link, and flow object is denoted by a unique character id, and placed in a distinct dictionary. The check_id function checks the unique id constraint before construction any new objects. This is a global id constraint across all objects.

Parameters:

bw : Blackwidow

The simulation object containing settings and data recording.

Attributes

time (float) The currenet simulation time.

Methods

add_event(event, delay) Function to add an event to the queue
add_flow(flow_id, flow_src, flow_dest, ...) Adds a flow to the network.
add_host(host_id) Construct host and add to dictionary of hosts.
add_link(link_id, device_id1, device_id2, ...) Adds a link to the network.
add_router(router_id) Construct router and add to dictionary of routers.
check_id(obj_id) Check if the id is not already used.
decrement_flows() Decrements the number of active flows.
delete_device(device_id) Deletes a device in the network.
delete_flow(flow_id) Delete a flow from the network.
delete_link(link_id) Deletes a link from the network.
dump([output]) Prints out network and returns networkx graph
empty() Empties the event queue.
run() Runs the network.
to_json() Returns a JSON representation of the network.
add_event(event, delay)[source]

Function to add an event to the queue

This function adds an event to the queue to be run after delay time.

Parameters:

event : Event

The event to be run.

delay : float

The amount of time in ms to wait before running the event.

add_flow(flow_id, flow_src, flow_dest, data_amt, flow_start)[source]

Adds a flow to the network.

Parameters:

flow_id : string

A unique id for the flow.

flow_src : string

The id for the source Device for the flow.

flow_dest : string

The id for the destination Device for the flow.

data_amt : float

The amount of data for the flow to send in MB.

flow_start : float

The amount of time to wait before starting the flow in ms.

add_host(host_id)[source]

Construct host and add to dictionary of hosts.

Parameters:

host_id : string

A unique id for the host.

Adds a link to the network.

Parameters:

link_id : string

A unique id for the link.

device_id1 : string

The id of one of the Device objects to connect to the link.

device_id2 : string

The id of one of the Device objects to connect to the link.

delay : float

The propagation delay of the link in ms.

rate : float

The rate at which the link can send a packet in Mbps.

capacity : int

The capacity of the link buffer in KB.

add_router(router_id)[source]

Construct router and add to dictionary of routers.

Parameters:

router_id : string

A unique id for the router.

check_id(obj_id)[source]

Check if the id is not already used.

This function checks if the id is not already used. This function raises an exception if object id is not unique.

Parameters:

obj_id : string

The id to check.

decrement_flows()[source]

Decrements the number of active flows.

delete_device(device_id)[source]

Deletes a device in the network.

Parameters:

device_id : string

The id of the Device to delete.

delete_flow(flow_id)[source]

Delete a flow from the network.

Parameters:

flow_id : string

The id of the flow to delete.

Deletes a link from the network.

Parameters:

link_id : string

The id of the link to delete.

dump(output=False)[source]

Prints out network and returns networkx graph

Prints the devices, links, and flows associated with the network, and returns a pydot object with the network graph.

Parameters:

output : boolean, optional

Specifies whether to print the network information (the default is False).

Returns:

pydot

pydot object containing the network graph

empty()[source]

Empties the event queue.

run()[source]

Runs the network.

Dequeues events from the queue and runs them in order until the queue is empty or there are 0 flows active.

Returns:

time : int

The amount of time taken for the network to run.

to_json()[source]

Returns a JSON representation of the network.

blackwidow.network.packet module

class blackwidow.network.packet.AckPacket(packet_id, src, dest, flow_id, next_expected_id=0, timestamp=0)[source]

Bases: blackwidow.network.packet.Packet

Class for acknowledgement packets

Parameters:

packet_id : int

A unique id for the packet within a flow

src : Device

The device a packet originated from

dest : Device

The destination of the packet

flow_id : string

The flow_id of the flow this packet is in

next_expected_id : int

The next packet that the destination expects from the source.

timestamp : float, optional

The default value is 0 when this parameter is not used. This is used to track when the packet or the packet this is associated with if it is an ack was sent. This parameter is used to calculate round trip time in flow.

Attributes

pack_id (int) The packet id or the id of the packet an ack is associated with.
src (Device) The device a packet originated from
dest (Device) The destination of the packet
flow_id (string) The flow_id of the flow this packet is in
timestamp (float, optional) The default value is 0 when this parameter is not used. This is used to track when the packet or the packet this is associated with if it is an ack was sent. This parameter is used to calculate round trip time in flow.
is_ack (boolean) True if ack packet; False otherwise.
is_routing (boolean) True if routing packet; False otherwise.
size (int) Size in bits of packet.
next_expected_id (int) The next packet that the destination expects from the source.
class blackwidow.network.packet.DataPacket(packet_id, src, dest, flow_id, timestamp=0)[source]

Bases: blackwidow.network.packet.Packet

Class for data packets

Parameters:

packet_id : int

A unique id for the packet within a flow

src : Device

The device a packet originated from

dest : Device

The destination of the packet

flow_id : string

The flow_id of the flow this packet is in

timestamp : float, optional

The default value is 0 when this parameter is not used. This is used to track when the packet or the packet this is associated with if it is an ack was sent. This parameter is used to calculate round trip time in flow.

Attributes

pack_id (int) The packet id or the id of the packet an ack is associated with.
src (Device) The device a packet originated from
dest (Device) The destination of the packet
flow_id (string) The flow_id of the flow this packet is in
timestamp (float, optional) The default value is 0 when this parameter is not used. This is used to track when the packet or the packet this is associated with if it is an ack was sent. This parameter is used to calculate round trip time in flow.
is_ack (boolean) True if ack packet; False otherwise.
is_routing (boolean) True if routing packet; False otherwise.
size (int) Size in bits of packet.
class blackwidow.network.packet.Packet(packet_id, src, dest, flow_id, timestamp=0)[source]

Bases: object

Super class for DataPackets and AckPackets

Parameters:

packet_id : int

A unique id for the packet within a flow

src : Device

The device a packet originated from

dest : Device

The destination of the packet

flow_id : string

The flow_id of the flow this packet is in

timestamp : float, optional

The default value is 0 when this parameter is not used. This is used to track when the packet or the packet this is associated with if it is an ack was sent. This parameter is used to calculate round trip time in flow.

Attributes

pack_id (int) The packet id or the id of the packet an ack is associated with.
src (Device) The device a packet originated from
dest (Device) The destination of the packet
flow_id (string) The flow_id of the flow this packet is in
timestamp (float, optional) The default value is 0 when this parameter is not used. This is used to track when the packet or the packet this is associated with if it is an ack was sent. This parameter is used to calculate round trip time in flow.
is_ack (boolean) True if ack packet; False otherwise.
is_routing (boolean) True if routing packet; False otherwise.
size (int) Size in bits of packet.
class blackwidow.network.packet.RoutingPacket(packet_id, src, dest, flow_id, routing_table, size)[source]

Bases: blackwidow.network.packet.Packet

Class for routing packets

Parameters:

packet_id : int

A unique id for the packet within a flow

src : Device

The device a packet originated from

dest : Device

The destination of the packet

flow_id : string

The flow_id of the flow this packet is in

routing_table : dictionary

Routing table to be updated

Attributes

pack_id (int) The packet id or the id of the packet an ack is associated with.
src (Device) The device a packet originated from
dest (Device) The destination of the packet
flow_id (string) The flow_id of the flow this packet is in
timestamp (float, optional) The default value is 0 when this parameter is not used. This is used to track when the packet or the packet this is associated with if it is an ack was sent. This parameter is used to calculate round trip time in flow.
is_ack (boolean) True if ack packet; False otherwise.
is_routing (boolean) True if routing packet; False otherwise.
size (int) Size in bits of packet.
routing_table (dictionary) Routing table to be updated

blackwidow.network.rate_graph module

class blackwidow.network.rate_graph.Data(time, size)[source]

Bases: object

Class to represent an amount of data and the time it was sent. It is used as a priority queue object with time as the priority.

Parameters:

time : float

Represents the network time this object was transferred.

size : int

The number of bits this object represents

Attributes

time (float) Represents the network time this object was transferred.
size (int) The number of bits this object represents
class blackwidow.network.rate_graph.Rate_Graph(object_id, name, env, bw)[source]

Bases: object

Class to graph rates.

Parameters:

object_id : string

The id of the object recording.

name : string

The name of this Rate_Graph. Should specify which flow, link, or device is using it.

env : Network

The network that the flow belongs to.

bw : Blackwidow

The printer to print data to

Attributes

object_id (string) The id of the object recording.
name (string) The name of this Rate_Graph. Should specify which flow, link, or device is using it.
env (Network) The network that the flow belongs to.
bw (Blackwidow) The printer to print data to
window_size (float) ms to average over
bits_in_window (int) Number of bits that were sent in the last window_size ms
interval (float) Record a data point every interval ms.
window (PriorityQueue) Keeps track of each object recorded within last window_size ms.

Methods

add_point(packet, time) Adds a point to the queue Parameters ———- packet : Packet The packet which was sent or received.
graph() Graphs current rate
peek_time() Return the time of the first object in the queue
remove_points(time) Removes data before time Parameters ———- time : float The network’s current time.
add_point(packet, time)[source]

Adds a point to the queue Parameters ———- packet : Packet

The packet which was sent or received.
time : float
The network’s current time.
graph()[source]

Graphs current rate

peek_time()[source]

Return the time of the first object in the queue

remove_points(time)[source]

Removes data before time Parameters ———- time : float

The network’s current time.

blackwidow.network.reno_flow module

class blackwidow.network.reno_flow.RenoFlow(flow_id, source, destination, amount, env, time, bw)[source]

Bases: blackwidow.network.tahoe_flow.TahoeFlow

Implements TCP Reno. Adds Fast Retransmit and Fast Recovery Flows will trigger host behavior. Has slow start and congestion avoidance.

Parameters:

flow_id : string

A unique id for the flow.

source : Device

The source for the flow.

destination : Device

The destination for the flow.

amount : int

The amount of data to send in MB.

env : Network

The network that the flow belongs to.

time : float

The amount of time to wait before starting to send in ms.

bw : Blackwidow

The printer to print data to

Attributes

flow_id (string) The flow id.
src (Device) The source for the flow.
dest (Device) The destination for the flow.
amount (int) The amount of data left to send in MB.
env (Network) The network that the flow belongs to.
flow_start (float) The amount of time to wait before starting to send. Specified in ms.
pack_num (int) The next pack_num to check to send.
cwnd (float) Congestion window size.
ssthresh (float) Slow start threshold
resend_time (float) ms before packets are sent after an ack receival
min_RTT (float) Minimum round trip time observed for this flow
last_RTT (float) Last round trip time observed for this flow
SRTT (float) Weighted average of round trip times biased towards recent RTT
RTTVAR (float) Variance of round trip times
RTO (float) Retransmission timeout in ms
packets_sent (list) List of packets that have been sent but haven’t had their ack received
packets_time_out (list) List of packets that have exceeded timeout and need to be resent
acks_arrived (set) Set of ack packets that have been received
done (int) 0 if flow isn’t finished; 1 if flow is finished Used to avoid decrementing flow more than once.
send_rate (Rate_Graph) Keeps track of the rate the flow is sending at and outputs to CSV file in real time.
receive_rate (Rate_Graph) Keeps track of the rate the flow is receiving at and outputs to CSV file in real time.
packets_arrived (list) Keeps track of packets(not acks) that have not arrived. Filled with all possible packet numbers when the flow starts and numbers are removed as each packet reaches the destination
total_num_packets (int) Total number of packets that need to be sent
last_pack_rec (int) Packet number of previous next packet expected by the destination
counter (int) Keeps track of duplicate acknowledgements

Methods

receive(packet) Generate an ack or respond to bad packet.
_reset_window()[source]

Called when a packet timeout occurs. Sets ssthresh to max(2, cwnd/2) and cwnd to 1. Resets counter

_send_ack(packet)[source]

Creates ack for packet.

receive(packet)[source]

Generate an ack or respond to bad packet. Parameters ———- packet : Packet

The packet to be received.

blackwidow.network.router module

class blackwidow.network.router.Router(router_id, env, bw)[source]

Bases: blackwidow.network.device.Device

Class for routers.

Routers are responsible for initializing and updating their routing table, and sending packets based on their routing table.

Parameters:

router_id : string

A unique id for the router.

Attributes

network_id (string) A unique id of the device in the network.
links (list) A list of links that the router is connected to.
routing_table (dict) A dictionary representing the router’s routing table.
new_routing_table (dict) A dictionary representing the router’s new routing table.
env (Network) The network that the link belongs to.
bw (Blackwidow) BlackWidow simulation object containing simulation settings.
send_rate (Rate_Graph object) Send rate graphing object.
receive_rate (Rate_Graph object) Receive rate graphing object.

Methods

add_link(link) Adds a link to the router.
send(packet) Sends a packet to a link.
receive(packet) Receives a packet from a link.
start_new_routing() Starts a new routing round.
send_routing() Sends a routing packet to all neighbors.
update_route() Update the new_routing_table based on routing packets.
_distance(link) Gets the distance of a link.
_distance(link)[source]

Get the distance of the link.

Parameters:

link : Link

Link to get distance of.

Overrides Device.add_link() to add to routing table.

Parameters:

link : Link

The link to add to the router.

receive(packet)[source]

Process packet by sending it out.

If the packet is routing, calls update_route to update the new_routing_table.

Parameters:

packet : Packet

Received packet.

send(packet)[source]

Send packet to appropriate link.

First looks in the new routing table to see if we know how to reach it there. Otherwise uses the old routing table.

Parameters:

packet : Packet

Packet to send through the router.

send_routing()[source]

Send routing packets to all neighbors.

start_new_routing()[source]

Start a new routing round.

If there is dynamic routing, updates the routing table to the new routing table built up by dynamic routing and measures the distance for each link.

update_route(packet)[source]

Update routing table.

Goes through the routing table contained in the routing packet and determines if it contains a better way to get to each destination. This uses a distributed version of the Bellman-Ford algorithm.

Parameters:

packet : Packet

Routing packet to update the route.

blackwidow.network.tahoe_flow module

class blackwidow.network.tahoe_flow.TahoeFlow(flow_id, source, destination, amount, env, time, bw)[source]

Bases: blackwidow.network.flow.Flow

Implements TCP Tahoe. Flows will trigger host behavior. Slow start and congestion avoidance already implemented in Flow. Just sets parameters for TCP Tahoe

Parameters:

flow_id : string

A unique id for the flow.

source : Device

The source for the flow.

destination : Device

The destination for the flow.

amount : int

The amount of data to send in MB.

env : Network

The network that the flow belongs to.

time : float

The amount of time to wait before starting to send in ms.

bw : Blackwidow

The printer to print data to

Attributes

flow_id (string) The flow id.
src (Device) The source for the flow.
dest (Device) The destination for the flow.
amount (int) The amount of data left to send in MB.
env (Network) The network that the flow belongs to.
flow_start (float) The amount of time to wait before starting to send. Specified in ms.
pack_num (int) The next pack_num to check to send.
cwnd (float) Congestion window size.
ssthresh (float) Slow start threshold
resend_time (float) ms before packets are sent after an ack receival
min_RTT (float) Minimum round trip time observed for this flow
last_RTT (float) Last round trip time observed for this flow
SRTT (float) Weighted average of round trip times biased towards recent RTT
RTTVAR (float) Variance of round trip times
RTO (float) Retransmission timeout in ms
packets_sent (list) List of packets that have been sent but haven’t had their ack received
packets_time_out (list) List of packets that have exceeded timeout and need to be resent
acks_arrived (set) Set of ack packets that have been received
done (int) 0 if flow isn’t finished; 1 if flow is finished Used to avoid decrementing flow more than once.
send_rate (Rate_Graph) Keeps track of the rate the flow is sending at and outputs to CSV file in real time.
receive_rate (Rate_Graph) Keeps track of the rate the flow is receiving at and outputs to CSV file in real time.

Methods