-
Notifications
You must be signed in to change notification settings - Fork 221
/
Mac1609_4.h
315 lines (249 loc) · 9.83 KB
/
Mac1609_4.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
//
// Copyright (C) 2012 David Eckhoff <eckhoff@cs.fau.de>
//
// Documentation for these modules is at http://veins.car2x.org/
//
// SPDX-License-Identifier: GPL-2.0-or-later
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#pragma once
#include <queue>
#include <memory>
#include <stdint.h>
#include "veins/veins.h"
#include "veins/base/modules/BaseLayer.h"
#include "veins/modules/phy/PhyLayer80211p.h"
#include "veins/modules/mac/ieee80211p/DemoBaseApplLayerToMac1609_4Interface.h"
#include "veins/modules/utility/Consts80211p.h"
#include "veins/modules/utility/MacToPhyControlInfo11p.h"
#include "veins/base/utils/FindModule.h"
#include "veins/modules/messages/Mac80211Pkt_m.h"
#include "veins/modules/messages/BaseFrame1609_4_m.h"
#include "veins/modules/messages/AckTimeOutMessage_m.h"
#include "veins/modules/messages/Mac80211Ack_m.h"
#include "veins/base/modules/BaseMacLayer.h"
#include "veins/modules/utility/ConstsPhy.h"
#include "veins/modules/utility/HasLogProxy.h"
namespace veins {
/**
* @brief
* Manages timeslots for CCH and SCH listening and sending.
*
* @author David Eckhoff : rewrote complete model
* @author Christoph Sommer : features and bug fixes
* @author Michele Segata : features and bug fixes
* @author Stefan Joerer : features and bug fixes
* @author Gurjashan Pannu: features (unicast model)
* @author Christopher Saloman: initial version
*
* @ingroup macLayer
*
* @see DemoBaseApplLayer
* @see Mac1609_4
* @see PhyLayer80211p
* @see Decider80211p
*/
class DeciderResult80211;
class VEINS_API Mac1609_4 : public BaseMacLayer, public DemoBaseApplLayerToMac1609_4Interface {
public:
// tell to anybody which is interested when the channel turns busy or idle
static const simsignal_t sigChannelBusy;
// tell to anybody which is interested when a collision occurred
static const simsignal_t sigCollision;
// Access categories in increasing order of priority (see IEEE Std 802.11-2012, Table 9-1)
enum t_access_category {
AC_BK = 0,
AC_BE = 1,
AC_VI = 2,
AC_VO = 3
};
class VEINS_API EDCA : HasLogProxy {
public:
class VEINS_API EDCAQueue {
public:
std::queue<BaseFrame1609_4*> queue;
int aifsn; // number of aifs slots for this queue
int cwMin; // minimum contention window
int cwMax; // maximum contention size
int cwCur; // current contention window
int64_t currentBackoff; // current Backoff value for this queue
bool txOP;
int ssrc; // station short retry count
int slrc; // station long retry count
bool waitForAck; // true if the queue is waiting for an acknowledgment for unicast
unsigned long waitOnUnicastID; // unique id of unicast on which station is waiting
AckTimeOutMessage* ackTimeOut; // timer for retransmission on receiving no ACK
EDCAQueue()
{
}
EDCAQueue(int aifsn, int cwMin, int cwMax, t_access_category ac);
~EDCAQueue();
};
EDCA(cSimpleModule* owner, ChannelType channelType, int maxQueueLength = 0);
~EDCA();
void createQueue(int aifsn, int cwMin, int cwMax, t_access_category);
int queuePacket(t_access_category AC, BaseFrame1609_4* cmsg);
void backoff(t_access_category ac);
simtime_t startContent(simtime_t idleSince, bool guardActive);
void stopContent(bool allowBackoff, bool generateTxOp);
void postTransmit(t_access_category, BaseFrame1609_4* wsm, bool useAcks);
void revokeTxOPs();
/** @brief return the next packet to send, send all lower Queues into backoff */
BaseFrame1609_4* initiateTransmit(simtime_t idleSince);
public:
cSimpleModule* owner;
std::map<t_access_category, EDCAQueue> myQueues;
uint32_t maxQueueSize;
simtime_t lastStart; // when we started the last contention;
ChannelType channelType;
/** @brief Stats */
long statsNumInternalContention;
long statsNumBackoff;
long statsSlotsBackoff;
/** @brief Id for debug messages */
std::string myId;
};
public:
Mac1609_4()
: nextChannelSwitch(nullptr)
, nextMacEvent(nullptr)
{
}
~Mac1609_4() override;
/**
* @brief return true if alternate access is enabled
*/
bool isChannelSwitchingActive() override;
simtime_t getSwitchingInterval() override;
bool isCurrentChannelCCH() override;
void changeServiceChannel(Channel channelNumber) override;
/**
* @brief Change the default tx power the NIC card is using
*
* @param txPower_mW the tx power to be set in mW
*/
void setTxPower(double txPower_mW);
/**
* @brief Change the default MCS the NIC card is using
*
* @param mcs the default modulation and coding scheme
* to use
*/
void setMCS(MCS mcs);
/**
* @brief Change the phy layer carrier sense threshold.
*
* @param ccaThreshold_dBm the cca threshold in dBm
*/
void setCCAThreshold(double ccaThreshold_dBm);
protected:
/** @brief States of the channel selecting operation.*/
protected:
/** @brief Initialization of the module and some variables.*/
void initialize(int) override;
/** @brief Delete all dynamically allocated objects of the module.*/
void finish() override;
/** @brief Handle messages from lower layer.*/
void handleLowerMsg(cMessage*) override;
/** @brief Handle messages from upper layer.*/
void handleUpperMsg(cMessage*) override;
/** @brief Handle control messages from upper layer.*/
void handleUpperControl(cMessage* msg) override;
/** @brief Handle self messages such as timers.*/
void handleSelfMsg(cMessage*) override;
/** @brief Handle control messages from lower layer.*/
void handleLowerControl(cMessage* msg) override;
/** @brief Handle received broadcast */
virtual void handleBroadcast(Mac80211Pkt* macPkt, DeciderResult80211* res);
/** @brief Set a state for the channel selecting operation.*/
void setActiveChannel(ChannelType state);
void sendFrame(Mac80211Pkt* frame, omnetpp::simtime_t delay, Channel channelNr, MCS mcs, double txPower_mW);
simtime_t timeLeftInSlot() const;
simtime_t timeLeftTillGuardOver() const;
bool guardActive() const;
void attachControlInfo(Mac80211Pkt* mac, Channel channelNr, MCS mcs, double txPower_mW);
/** @brief maps a application layer priority (up) to an EDCA access category. */
t_access_category mapUserPriority(int prio);
void channelBusy();
void channelBusySelf(bool generateTxOp);
void channelIdle(bool afterSwitch = false);
void setParametersForBitrate(uint64_t bitrate);
void sendAck(LAddress::L2Type recpAddress, unsigned long wsmId);
void handleUnicast(LAddress::L2Type srcAddr, std::unique_ptr<BaseFrame1609_4> wsm);
void handleAck(const Mac80211Ack* ack);
void handleAckTimeOut(AckTimeOutMessage* ackTimeOutMsg);
void handleRetransmit(t_access_category ac);
const LAddress::L2Type& getMACAddress() override
{
ASSERT(myMacAddr != LAddress::L2NULL());
return BaseMacLayer::getMACAddress();
}
protected:
/** @brief Self message to indicate that the current channel shall be switched.*/
cMessage* nextChannelSwitch;
/** @brief Self message to wake up at next MacEvent */
cMessage* nextMacEvent;
/** @brief Last time the channel went idle */
simtime_t lastIdle;
simtime_t lastBusy;
/** @brief Current state of the channel selecting operation.*/
ChannelType activeChannel;
/** @brief access category of last sent packet */
t_access_category lastAC;
/** @brief pointer to last sent packet */
BaseFrame1609_4* lastWSM;
/** @brief pointer to last sent mac frame */
std::unique_ptr<Mac80211Pkt> lastMac;
int headerLength;
bool useSCH;
Channel mySCH;
std::map<ChannelType, std::unique_ptr<EDCA>> myEDCA;
bool idleChannel;
/** @brief stats */
long statsReceivedPackets;
long statsReceivedBroadcasts;
long statsSentPackets;
long statsSentAcks;
long statsTXRXLostPackets;
long statsSNIRLostPackets;
long statsDroppedPackets;
long statsNumTooLittleTime;
long statsNumInternalContention;
long statsNumBackoff;
long statsSlotsBackoff;
simtime_t statsTotalBusyTime;
/** @brief The power (in mW) to transmit with.*/
double txPower;
MCS mcs; ///< Modulation and coding scheme to use unless explicitly specified.
/** @brief Id for debug messages */
std::string myId;
bool useAcks;
double ackErrorRate;
int dot11RTSThreshold;
int dot11ShortRetryLimit;
int dot11LongRetryLimit;
int ackLength;
// indicates rx start within the period of ACK timeout
bool rxStartIndication;
// An ack is sent after SIFS irrespective of the channel state
cMessage* stopIgnoreChannelStateMsg;
bool ignoreChannelState;
// Dont start contention immediately after finishing unicast TX. Wait until ack timeout/ ack Rx
bool waitUntilAckRXorTimeout;
std::set<unsigned long> handledUnicastToApp;
Mac80211pToPhy11pInterface* phy11p;
};
} // namespace veins