ALOHA and CSMA/CA Packetized Wireless Networks
This example shows how to simulate a basic ALOHA or CSMA/CA MAC using Simulink®, Stateflow® and the Communications Toolbox™.
ALOHA: ALOHA is a seminal random-access protocol that became operational in 1971. In ALOHA, nodes transmit packets as soon as these are available, without sensing the wireless carrier. As a result, wireless packets may collide at a receiver if they are transmitted simultaneously. Hence, successful packet reception is acknowledged by transmitting a short acknowledgment packet. If an acknowledgment is not received timely enough, then the data packet is resent at a later instant determined, e.g., by binary exponential backoff.
CSMA/CA: Carrier Sense Multiple Access with Collision Avoidance is an improved random-access scheme, according to which wireless nodes first sense the wireless medium before transmitting their data packets. If the medium is sensed busy, then transmissions are deferred, e.g., according to a binary exponential backoff. Collision avoidance is enabled by: (i) waiting for an interframe spacing (IFS) duration after the channel has been sensed idle, (ii) transmitting only after a certain number of (not necessarily contiguous) sensed idle time slots, chosen randomly from the contention window (i.e., an adaptive range of possible backoff durations), (iii) exchanging Request-to-Send and Clear-to-Send frames (RTS and CTS). Out of these three methods, this example models the first two (IFS and contention window). CSMA/CA has been employed in Ethernet, IEEE® 802.11, and IEEE 802.15.4, among other standards.
This example models a three-node PHY/MAC network. All nodes are within range; transmissions between two nodes can be received by and interfere with the third one.
The default configuration enables data frame transmissions from node 1 to node 3, from node 3 to node 2, and from node 2 to node 1. Acknowledgment frames are transmitted from node 3 to node 1, from node 2 to node 3, and from node 1 to node 2.
The MAC scheme can be either ALOHA or CSMA/CA, as determined by the top-level switch. MAC frames are encoded to or decoded from a PHY waveform using a QPSK-based PHY layer.
The MAC layer operates at a very fine timescale (every 0.8 microseconds), as the backoff duration is typically much shorter than the duration of a data frame. As a result, the Simulink model is scalar-based (i.e., the length of most signals is equal to 1) and the MAC/PHY layers do not process frames, i.e., batches of samples.
Each radio transceiver is a joint PHY and MAC implementation enabling both receive and transmit operations. The left side of the next diagram corresponds to the PHY layer, while the right side corresponds to the Data Link Layer (MAC and Logical Link Control).
On the receive-side chain, the transceiver decodes the PHY layer of the received waveforms and passes the corresponding MAC Protocol Data Unit (MPDU) to the MAC layer, which processes data and acknowledgment frames.
On the transmit-side chain, the Data Link layer initiates MAC frame transmissions either when the Logical Link Control sublayer determines that a new data frame is injected or when the MAC sublayer needs to transmit an acknowledgment for a received data frame. The data MAC frames are generated by prepending a MAC header and appending a CRC MAC footer to a payload that is the input from the higher, third layer (network layer). The acknowledgment MAC frames do not contain a payload; they only contain the MAC header and CRC footer.
Logical Link Control
The Logical Link Control (LLC) sublayer is responsible for injecting data packets into the transceiver. It is mainly implemented using a Stateflow chart. The packet interarrival time is exponentially distributed, which corresponds to a Poisson process.
Then, the Stateflow chart counts down the packet inter-arrival time until the next packet arrives. This chart also models the segmentation of large packets into smaller data frames by determining the number of additional frame transmissions ("TxMore").
ALOHA MAC Layer
When the top-level MAC switch is set to ALOHA, the MAC subsystem of the Data link layer essentially operates as the following Stateflow chart:
The left side of the chart is responsible for acknowledging a received data frame. Before transmitting the acknowledgment, the transmitter first waits for a short interframe spacing (SIFS). Then, it outputs a positive 'TxAckOn' signal for the duration of the acknowledgment frame.
The right side of the chart is responsible for transmitting a data frame. Before transmitting the data frame, the transmitter first waits for a short interframe spacing (SIFS). Then, it transmits the signal, without sensing the wireless medium, by outputting a positive 'TxDataOn' signal for the duration of the data frame. Subsequently, the node awaits to receive an acknowledgment within a certain time interval. If the acknowledgment is received before timeout, the current data frame transmission is concluded. If it is not, then the node enters a backoff state and it doubles its contention window (CW) every time except for the first backoff instance. The backoff duration is randomly chosen from the [0, CW] interval. If the maximum number of backoff attempts is reached, then the transceiver declares a failure in transmitting this data frame.
CSMA/CA MAC Layer
When the top-level MAC switch is set to CSMA/CA, the MAC subsystem of the Data link layer essentially operates as the following Stateflow chart:
The CSMA/CA chart has some similarities with the ALOHA chart, but it also has some differences:
The transceiver senses the wireless medium.
Data frames are not transmitted before an interframe spacing (IFS) duration elapses since the wireless medium has been sensed as idle.
The backoff counter decrements only when the medium is sensed idle.
Transmitter: The transmitter performs QPSK modulation on the MPDU bits. The bit rate is 20 MHz and the symbol rate is 10 MHz. The QPSK symbols are subsequently filtered with the raised cosine filter of the "Tx/Rx Switch" subsystem.
Channel: The filtered PHY waveform passes through a network channel, which imposes multipath fading and white Gaussian noise. The network channel allows each node to receive superimposed signals transmitted by multiple other nodes. Multipath fading is applied using the NetworkChannel System block. White noise is added using the multichannel capability of the AWGN Channel block.
Receiver: Transceivers process the signal waveform only when its amplitude exceeds a certain threshold (see Signal Detection subsystem). Subsequently, the received waveform is equalized using a Decision Feedback Equalizer (DFE); this component reduces intersymbol interference (ISI) caused by multipath fading, corrects small symbol timing offsets and carrier offsets, and its fast convergence suits packetized networks. Next, the equalized QPSK symbols are demodulated. The corresponding bits are passed to a CRC detector in order to identify the frame start, the PHY payload length and the frame type (data or acknowledgment).
Model simulation shows one scope for each transceiver. Each scope depicts the transmitted signal (top axes) and the backoff counter (bottom axes) for each transceiver.
At the same time, the top-level model depicts per-node throughput in three display blocks. Throughput is calculated by measuring the number of successfully acknowledged data packets.
The used MAC scheme can be toggled between ALOHA and CSMA/CA (default). Changing the MAC scheme to ALOHA yields lower node throughput for the default packet arrival rates. This is because ALOHA packets collide more frequently as nodes do not sense the wireless carrier.
The packet arrival rates can be customized through the dialog mask of each node. The network saturation point can be empirically and iteratively found, e.g., by gradually increasing the same packet arrival rate for each node. Increasing low arrival rates can increase node throughput; increasing high arrival rates (past the saturation point) can actually have a detrimental effect on throughput as packets collide and nodes backoff more frequently.
If the arrival rates are disproportional for each node, then unfairness scenarios can be established. For example, one node may be capturing the medium very frequently and maintain a low contention window, while other nodes may back off for a long time and only sporadically access the medium.
You can change the random seed of the nodes at their block mask to enable different random-access scenarios. For example, for a given packet arrival rate, the random seed determines how soon the first transmission occurs.
N. Abramson, The ALOHA System Final Technical Report, NASA Advanced Research Projects Agency, October 11, 1974
IEEE Standard for Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications, Nov. 1997. P802.11