- You must work individually.
- You should submit all files in a single zip file.
Project: Wireless MAC Protocols
Wireless nodes typically use a Medium Access Control (MAC) protocol to share the wireless spectrum so that all of the nodes in a space can effectively send and receive wireless packets. In this project, you will simulate a couple different MAC protocols and then compare the effectiveness of each approach.
Download the files associated with this HW.
You will simulate a simple network consisting of multiple transmitting nodes (stations) and a single receiving node (the access point). Each station is programmed to send packets at a fixed average rate to the access point. The access point will count how many packets are received successfully from each station.
A packet is dropped if there is a collision, i.e. at least one other station is transmitting at the same time. Since all stations are transmitting to a single access point, if any two stations are transmitting simultaneously there will be a collision at the access point.
To try to avoid collisions every station is running the same MAC protocol. In this project there are four different MAC protocols:
NullMac: This is essentially the same as no MAC protocol. Each station transmits whenever it has data ready. If it receives an ACK it waits for the next packet to send, otherwise it tries to immediately retransmit the packet.
NullMacExponentialBackoff: Stations still transmit whenever they have data to send, but if they do not receive an ACK they use a random binary exponential backoff scheme before retrying to send the message. Assume a time of (self.interval)
CSMA_CA/CSMA_CD: Stations sense the wireless channel before transmitting. If they detect another transmitter they use a random binary exponential backoff before trying again. If the channel is clear they transmit and wait for an ACK. If they do not receive an ACK they retransmit by repeating the entire process. Keep trying until the packet is transmitted successfully. (You might notice that this is a little slow, so try upgrading your implementation, by implementing Collision CD instead. CSMA_CD).
RTS_CTS: Stations still use CSMA/CA or CSMA/CD, but if they do not sense any other transmitters they send a “Request To Send” (RTS) packet to the access point. If the access point responds with a “Clear To Send” (CTS) message then they transmit their packet. The simulator uses a slightly modified version of the “sense” operation that also detects if another station has the channel reserved.
The simulated network also has two modes for the transmission and reception range of the stations:
all: In this case, all stations are within radio range of all other stations. That is, when one station transmits all other stations can receive the transmission (even though it is only being sent to the access point).
neighbors: In this case, each node can only hear transmissions from its adjacent neighbors. In the simulator, this means each station can hear messages from the stations with indices one greater and one less than its own index.
Finally, the access point has two modes. In the normal mode, it can only listen for transmissions from a single station at a time. If there is more than one station transmitting then the packets will collide and the access point will not be able to receive the packets. In “special” mode the access point can hear from all stations simultaneously. We don’t use the option in this assignment but it could be used to establish a baseline when measuring the performance of the network.
The access point in the simulator keeps track of the number of packets successfully received from each station. The simulator ends when the access point has received at least a certain number of packets from every station.
There are two main deliverables for this project.
Deliverable 1: MAC Protocol Implementations
You must modify
mac.py to implement the three other MAC protocols (
NullMac is provided).
Deliverable 2: Evaluation of MAC Protocols with 4 nodes
With the MAC protocols implemented you must now evaluate them to see how they perform. You will create two graphs, each with the following characteristics:
- The X-axis is the packet transmission rate of the stations. This should range from 2 pkts/second to 20 pkts/second. Choose a reasonable number of points in between to measure.
- The Y-axis is the time the simulator has to run for the access point to collect 100 packets from each station.
- For each X-axis point, you should measure four values: the time to receive 100 packets from each station using each of the four MAC protocols. NOTE: you will find that the
NullMacprotocol performs very badly. You do not need to measure it beyond 20 packets/second (and you likely cannot anyway).
- Every simulation should use four stations and the access point should collect at least 100 packets from each station.
You will follow these steps twice to generate the two graphs: once with the transmission range set to
all (i.e. all stations can hear all other stations) and once with the transmission range set to
neighbors (i.e. stations can only hear transmissions from the stations “next” to them).
These graphs should illustrate the tradeoffs between the different MAC protocols.
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 the MAC protocols. Each MAC protocol is its own class and is a subclass of the generic
Stationclass. The rough templates are sketched out for you.
mac.py there are four 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.
bool self.sense(): This function senses the wireless channel and returns
Trueif the station detects energy on the channel (i.e. another station is currently transmitting) or
Falseif not. It will also return
Trueif a different station has been granted the
void self.send(string packet): This function sends a packet from the station to the access point. There are two valid packets to send:
DATAis a normal data packet and is what the access point will collect and use to increment the count from the station.
RTSis a signal to the access point that this station would like exclusive access to the wireless channel to send a packet.
string self.receive(): This function blocks until a message is received from the access point or enough time has expired that the station knows it is not getting a response.
'ACK'meaning the station got an ACK from the access point and can safely go back to waiting for the station to send a new packet. If the station sent an
'CTS'indicating that this station has access to the wireless channel. If a sent packet resulted in a collision, then the access point could not successfully decode it and will not be able to reply. In this case
receive()will return the
Nonetype to indicate that the station did not receive anything.
Command Line Interface
The simulator exposes many configuration options via the command line. The generic interface looks like:
python3 project.py <# stations> <pkts/s>
For example, to specify a stations transmission rate of 20 packets/second from four stations using CSMA/CA, where the access point is trying to collect 200 packets from each station, and all stations can hear all other stations:
python3 project.py 4 20 200 all normal CSMA_CA
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.
- Unlike the other network simulators we have seen in this class, this simulator runs in “real-time”. That is, if a single station wants to send 100 packets at 1 pkt/sec, it will take 100 actual seconds for that simulation to run.
- Transmitting a
DATApacket takes 10 ms.
- Transmitting a
CTSpackets takes 5 ms.
- For simplicity, packets from the access point to a station take no time.
- Receiving a
CTSmessage from the access point gives that station the wireless channel long enough for only a single
- 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.
You should submit:
- Your fully implemented
- Two graphs comparing the performance of each MAC protocol.
- One with the transmission range set to “all”.
- One with the transmission range set to “neighbors”.
- Once you have implemented the MAC protocols you should be able to write a script to collect the data for the graphs.
- It might be helpful to run each trial a couple of times and average the times to get a more reliable measurement.
- You can comment out
print()statements if that is helpful.
This HW is adapted from Brad Campbell PhD and is used with permission.