#include <CSMAMacLayer.h>
Inherits BasicMacLayer.
Inheritance diagram for CSMAMacLayer:
Public Member Functions | |
Module_Class_Members (CSMAMacLayer, BasicMacLayer, 0) | |
virtual void | initialize (int) |
Initialization of the module and some variables. | |
virtual void | finish () |
Delete all dynamically allocated objects of the module. | |
virtual void | handleLowerMsg (cMessage *) |
Handle messages from lower layer. | |
virtual void | handleUpperMsg (cMessage *) |
Handle messages from upper layer. | |
virtual void | handleSelfMsg (cMessage *) |
Handle self messages such as timers. | |
virtual void | handleLowerControl (cMessage *msg) |
Handle control messages from lower layer. | |
virtual void | receiveBBItem (int category, const BBItem *details, int scopeModuleId) |
Called by the Blackboard whenever a change occurs we're interested in. | |
Protected Types | |
typedef std::list< MacPkt * > | MacQueue |
enum | States { RX, CCA, TX } |
MAC states. More... | |
Protected Member Functions | |
virtual void | scheduleBackoff () |
schedule a backoff | |
Protected Attributes | |
States | macState |
kepp track of MAC state | |
RadioState::States | radioState |
Current state of active channel (radio), set using radio, updated via BB. | |
int | catRadioState |
category number given by bb for RadioState | |
double | rssi |
Last RSSI level. | |
int | catRSSI |
category number given by bb for RSSI | |
double | busyRSSI |
RSSI level where medium is considered busy. | |
double | slotDuration |
Duration of a slot. | |
double | difs |
Maximum time between a packet and its ACK. | |
SingleChannelRadio * | radio |
cached pointer to radio module | |
MacQueue | macQueue |
A queue to store packets from upper layer in case another packet is still waiting for transmission.. | |
unsigned | queueLength |
length of the queue | |
cMessage * | backoffTimer |
Timer for backoff (non-persistent CSMA). | |
cMessage * | minorMsg |
Multi-purpose message. | |
unsigned | txAttempts |
count the number of tx attempts | |
unsigned | maxTxAttempts |
maximum number of transmission attempts | |
double | bitrate |
the bit rate at which we transmit | |
unsigned | initialCW |
initial contention window size | |
DroppedPacket | droppedPacket |
Inspect reasons for dropped packets. | |
int | catDroppedPacket |
plus category from BB | |
int | nicId |
publish dropped packets nic wide |
This is an implementation of a simple non-persistent CSMA. The idea of nonpersistent CSMA is "listen before talk". Before attempting to transmit, a station will sense the medium for a carrier signal, which, if present, indicates that some other station is sending.
If the channel is busy a random waiting time is computed and after this time the channel is sensed again. Once the channel gets idle the message is sent. (State of the channel is obtained from SnrEval via Blackboard.)
An option of this module is to use a queue. If a packet from the upper layer arrives although there is still another packet waiting for its transmission or being transmitted the new packet can be stored in this queue. The length of this queue can be specified by the user in the omnetpp.ini file. By default the length is 0. If the queue is full or there is no queue (length = 0) new packet(s) will be deleted.
Several stations receive a broadcast request packet, usally exactly at the same time. They will all try to answer at exactly the same time, i.e. they all will sense the channel at exactly the same time and start to transmit because the channel was sensed idle by all of them. Therefore a small random delay should be built into one/some of the upper layers to simulate a random processing time!
The TestApplLayer e.g. implements such a processing delay!
|
MAC states. The MAC states help to keep track what the MAC is actually trying to do -- this is esp. useful when radio switching takes some time. RX -- MAC accepts packets from PHY layer TX -- MAC transmits a packet CCA -- Clear Channel Assessment - MAC checks whether medium is busy |
|
Handle messages from lower layer. Compare the address of this Host with the destination address in frame. If they are equal or the frame is broadcast, we send this frame to the upper layer. If not delete it. Reimplemented from BasicMacLayer. |
|
Handle self messages such as timers. After the timer expires try to retransmit the message by calling handleUpperMsg again. Implements BasicLayer. |
|
Handle messages from upper layer. First it has to be checked whether a frame is currently being transmitted or waiting to be transmitted. If so the newly arrived message is stored in a queue. If there is no queue or it is full print a warning. Before transmitting a frame it is tested whether the channel is busy at the moment or not. If the channel is busy, a short random time will be generated and the MacPkt is buffered for this time, before a next attempt to send the packet is started. If channel is idle the frame will be transmitted immediately. Implements BasicMacLayer. |
|
Called by the Blackboard whenever a change occurs we're interested in. Update the internal copies of interesting BB variables Reimplemented from BasicModule. |
|
schedule a backoff A non-persistent CSMA ideally uses a fixed backoff window, but it could also increase this window in a linear fashion, or even exponential -- here, a linear increase is used. Overwrite this function to define another schedule function. It also checks the retransmission counters -- if you overwrite it, do it with care. |
|
Maximum time between a packet and its ACK. Usually this is slightly more then the tx-rx turnaround time The channel should stay clear within this period of time. |
|
maximum number of transmission attempts The packet is discared when this number is reached. |
|
Multi-purpose message. Keeps track of things like minimum time of clear channel (important for atomic acks) and race condition avoidance. |
|
Duration of a slot. This duration can be a mini-slot (that is an RX-TX-turnaround time) but in general it should be the time it takes to send a packet plus some guard times (RX-TX-turnaround + a minimum inter-packet space). |
|
count the number of tx attempts This holds the number of transmission attempts, since no Acks are used this is the way how we can empty our queue even with overloaded channels. |