Changelog:
- 14 Nov 2024: fix bug in
access_point.py
where sense() might sometimes crash - 20 Nov 2024: fix major bug in
simtime.py
where time would advance too quickly. - 21 Nov 2024: modify supplied mac.py to not
import time
to avoid confusion - 21 Nov 2024: specify recommended testing with around 20 packets/second to test with
- 3 Dec 2024: use
--mac
argument correctly in examples
This is based on an assignment originally constructed by Brad Campbell.
If you downloaded
simtime.py
before noon 20 Nov, get an updated version here
1 Your Task
Download the skeleton code at here [last updated 2024-11-20 noon]
The skeleton code includes a simulator for a network where several randomly placed
stations
need to transmit packets to a central access point. The access point implements per-packet acknowledgments and simulatenously receives from each of 11 channels (frequencies). To simplify the assignmet, we will assume that acknowledgments are always received reliably.Your job is to improve the MAC protocol used by the stations to send a specified number of packets within a
goal
time computed byproject.py
.In the initial implementation, the stations make three attempts to transmit packets on wireless channel 1 at 0 dB of power.
You can edit the code for the stations to more intelligently choose
- when to (re)transmit;
- which channels to use;
- the transmit power;
- how many time to retransmit.
Unfortunately, you don’t have the capability to modify the access point, so you can’t implement features like RTS/CTS.
Write a brief description of your chosen MAC protocol and how choose those settings; place this in a comment at the top in your
mac.py
.Test your code and produce a graph of your results as the number of stations used varies from 10 to 100 in increments of 5, graphing the total time needed to receive 150 packets. Label the axes of your graph. We recommend testing with around 20 packets/second.
Place this graph in a file called
graph.pdf
orgraph.png
Submit your modified
mac.py
(with the comment) and your graph to the submission site.
2 Simulation Interface
The simulator uses a few files:
project.py
: The top level file that sets up the simulation and starts it. You shouldn’t need to modify this.access_point.py
: The code that simulates the access point that receives all packets. Again, you shouldn’t need to modify this.station.py
: A helper file that implements the low level functions for stations in the context of the simulator. This includes the functions you will call to implement the MAC protocols. You shouldn’t need to modify this file.mac.py
: Where you will actually implement your MAC protocol. The MAC protocol is its own class, and is a subclass of the genericStation
class. The rough template is sketched out for you.
2.1 Station Interface
Inside of mac.py
there are three functions provided by the generic station class that you will use to implement each MAC protocol. The NullMac
implementation provides a simple example.
void self.wait_for_next_transmission()
: This function blocks until a packet is ready to be sent by the station. Each MAC protocol should wait on this function to return in a loop. When it does return, the MAC protocol implementation should use the correct approach (based on which MAC protocol it is) to transmit a packet to the access point. The return value is a packet that you should pass tosend()
.string self.send(packet, tx_power, channel)
. Send a packet (retrieved fromwait_for_next_transmission()
) to the access point. TX power should be the transmit power in dB with a maximum of 20 dB (reasonable for WiFi). Channel is a WiFi channel number between 1 and 11 (inclusive).If the packet transmission was successful this will return
'ACK'
. If not,send()
will return'NOACK'
.bool self.sense(channel)
. Sense the specific wireless channel (between 1 and 11) to see if there are any detectable active transmissions. ReturnsTrue
if the channel is busy,False
otherwise.
2.2 Command Line Interface
The simulator exposes many configuration options via the command line. The generic interface looks like:
./project.py <# stations> <pkts/s> <pkts> --mac <mac>
For example, to specify a stations transmission rate of 20 packets/second from eighteen stations using YourMac, where the access point is trying to collect 200 packets from each station:
./project.py 18 20 200 --mac YourMac
2.3 Simulator Specifics
There are a few helpful details about the simulator environment that are useful to know. These are simplifications that make the situation easier to model without compromising the ability to compare different MAC protocols.
This simulator uses a simulated clock controlled by the included
simtime
module. This includes asleep()
function that sleeps for an amount of simulated time.In the default mode, the clock will only advanced when all threads are either sleeping or waiting on a queue. Then, the simulator will figure out the next time threads would wake up from sleeping, advance the clock to that time and wake up those threads.
Alternately, there is a
real time
mode you can enable with--real-time
. In this mode thesleep()
function calls thereal
time.sleep()
function.Transmitting a
DATA
packet takes 10 ms.For simplicity, packets from the access point to a station take no time and are never lost.
The stations should continue to transmit at the same rate even after the access point has received the minimum number of packets it is looking for.