-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCsmaCaMac.h
More file actions
253 lines (212 loc) · 6.87 KB
/
Copy pathCsmaCaMac.h
File metadata and controls
253 lines (212 loc) · 6.87 KB
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
//
// Copyright (C) 2016 OpenSim Ltd.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//
#ifndef __INET_CSMAMAC_H
#define __INET_CSMAMAC_H
#include "inet/common/FSMA.h"
#include "inet/common/queue/IPassiveQueue.h"
#include "inet/common/queue/PacketQueue.h"
#include "inet/linklayer/base/MACProtocolBase.h"
#include "inet/physicallayer/contract/packetlevel/IRadio.h"
#include "inet/linklayer/csmaca/CsmaCaMacFrame_m.h"
namespace inet {
using namespace inet::physicallayer;
//@Anjana
INET_API long* getUpdateA();
INET_API long* getUpdateC();
INET_API long* getUpdate();
INET_API long* getUpdateSentA();
INET_API long* getUpdateSentC();
class INET_API CsmaCaMac : public MACProtocolBase
{
protected:
/**
* @name Configuration parameters
*/
//@{
MACAddress address;
bool useAck = true;
double bitrate = NaN;
int headerLength = -1;
int ackLength = -1;
simtime_t ackTimeout = -1;//initially set to -1 changed to -10 by Anjana
simtime_t slotTime = -1;
simtime_t sifsTime = -1;//initially set to -1 changed to -10 by Anjana
simtime_t difsTime = -1;
int maxQueueSize = -1;
int retryLimit = -1;
int cwMin = -1;
int cwMax = -1;
int cwMulticast = -1;
simtime_t updateTime = -1;//@Anjana
static simsignal_t drpPkChannelSignal;
double channelDropProbability=0;
//@}
/**
* @name CsmaCaMac state variables
* Various state information checked and modified according to the state machine.
*/
//@{
enum State {
IDLE,
DEFER,
WAITDIFS,
BACKOFF,
TRANSMIT,
WAITACK,
RECEIVE,
WAITSIFS,
UPDATER,
UPDATES,
};
IRadio *radio = nullptr;
IRadio::TransmissionState transmissionState = IRadio::TRANSMISSION_STATE_UNDEFINED;
cFSM fsm;
/** Remaining backoff period in seconds */
simtime_t backoffPeriod = -1;
/** Number of frame retransmission attempts. */
int retryCounter = -1;
/** Messages received from upper layer and to be transmitted later */
PacketQueue transmissionQueue;
/** Passive queue module to request messages from */
IPassiveQueue *queueModule = nullptr;
//@}
/** @name Timer messages */
//@{
/** End of the Short Inter-Frame Time period */
cMessage *endSifs = nullptr;
/** End of the Data Inter-Frame Time period */
cMessage *endDifs = nullptr;
/** End of the backoff period */
cMessage *endBackoff = nullptr;
/** End of the ack timeout */
cMessage *endAckTimeout = nullptr;
/** Timeout after the transmission of a Data frame */
cMessage *endData = nullptr;
/** Radio state change self message. Currently this is optimized away and sent directly */
cMessage *mediumStateChange = nullptr;
//@}
//@Anjana
/** End of the Update sending Time period */
cMessage *endEvaluationTxr = nullptr;
cMessage *endEvaluationRxr = nullptr;
/** @name Statistics */
//@{
long numRetry;
long numSentWithoutRetry;
long numGivenUp;
long numCollision;
long numSent;
long numReceived;
long numSentBroadcast;
long numReceivedBroadcast;
//@}
//extern int numFwdDownstream;
//long numFwdDownstream;
// long numFwdDownstreamC;
/*long numSentWithoutRetryA;
long numSentWithoutRetryC;
long numSentA;
long numSentC;*/
int nFD;
long origin=5;
long orgId=5;
int numSentData=0;
int numBreak=0;
//int numSentInfo[2]={0};
long numSentInfo[2]={0};
//long numSentC=0;
public:
//long numFwdDownstreamInfo;
/**
* @name Construction functions
*/
//@{
virtual ~CsmaCaMac();
//@}
protected:
/**
* @name Initialization functions
*/
//@{
/** @brief Initialization of the module and its variables */
virtual void initialize(int stage) override;
virtual void initializeQueueModule();
virtual void finish() override;
virtual InterfaceEntry *createInterfaceEntry() override;
//@}
/**
* @name Message handing functions
* @brief Functions called from other classes to notify about state changes and to handle messages.
*/
//@{
virtual void handleSelfMessage(cMessage *msg) override;
virtual void handleUpperPacket(cPacket *msg) override;
virtual void handleLowerPacket(cPacket *msg) override;
virtual void handleWithFsm(cMessage *msg);
virtual void receiveSignal(cComponent *source, simsignal_t signalID, long value, cObject *details) override;
virtual CsmaCaMacDataFrame *encapsulate(cPacket *msg);
virtual cPacket *decapsulate(CsmaCaMacDataFrame *frame);
// virtual cPacket *decapsulate_ack(CsmaCaMacAckFrame *frame);
//@}
/**
* @name Timer functions
* @brief These functions have the side effect of starting the corresponding timers.
*/
//@{
virtual void scheduleSifsTimer(CsmaCaMacFrame *frame);
virtual void scheduleDifsTimer();
virtual void cancelDifsTimer();
virtual void scheduleAckTimeout(CsmaCaMacDataFrame *frame);
virtual void cancelAckTimer();
virtual void invalidateBackoffPeriod();
virtual bool isInvalidBackoffPeriod();
virtual void generateBackoffPeriod();
virtual void decreaseBackoffPeriod();
virtual void scheduleBackoffTimer();
virtual void cancelBackoffTimer();
//@}
//@Anjana
virtual void scheduleUpdateSendTimer(CsmaCaMacFrame *frame);
virtual void scheduleUpdateRecTimeout(CsmaCaMacDataFrame *frame);
virtual void cancelUpdateRecTimer();
/**
* @name Frame transmission functions
*/
//@{
virtual void sendDataFrame(CsmaCaMacDataFrame *frameToSend);
virtual void sendAckFrame();
//@}
//virtual void sendUpdateFrame();//@Anjana
/**
* @name Utility functions
*/
//@{
virtual void finishCurrentTransmission();
virtual void giveUpCurrentTransmission();
virtual void retryCurrentTransmission();
virtual CsmaCaMacDataFrame *getCurrentTransmission();
virtual void popTransmissionQueue();
virtual void resetStateVariables();
virtual bool isMediumFree();
virtual bool isReceiving();
virtual bool isAck(CsmaCaMacFrame *frame);
virtual bool isBroadcast(CsmaCaMacFrame *msg);
virtual bool isForUs(CsmaCaMacFrame *msg);
//@}
};
} // namespace inet
#endif // ifndef __INET_CSMAMAC_H