-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameState.h
279 lines (210 loc) · 6.44 KB
/
GameState.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
/*
* SeqNoCache.h
*
* Created on: 02.06.2020
* Author: Kevin Küchler
*/
#ifndef BROADCAST_GAMESTATE_H_
#define BROADCAST_GAMESTATE_H_
#include "map"
#include "stack"
#include "ns3/mac48-address.h"
#include "ns3/node-container.h"
#include "ns3/wifi-net-device.h"
#include "ns3/traffic-control-layer.h"
#include "EEBTPHeader.h"
#include "ApplicationDataHandler.h"
namespace ns3
{
class SendEvent;
class CCSendEvent;
class MutexSendEvent;
class ParentPathCheckEvent;
/*
* A Node holds information about a particular (other)
* node in the network.
*/
class EEBTPNode : public Object
{
public:
EEBTPNode();
EEBTPNode(Mac48Address addr, double power);
virtual ~EEBTPNode();
//static TypeId GetTypeId();
//virtual TypeId GetInstanceTypeId() const;
double getHighestMaxTxPower();
void setHighestMaxTxPower(double maxTxPower);
double getSecondHighestMaxTxPower();
void setSecondHighestMaxTxPower(double maxTxPower);
double getReachPower();
void setReachPower(double minTxPower);
double getNoise();
void updateRxInfo(double rxPower, double noise);
bool hasReachPowerProblem();
void hasReachPowerProblem(bool b);
Mac48Address getAddress();
Mac48Address getParentAddress();
void setParentAddress(Mac48Address addr);
bool hasFinished();
void setFinished(bool f);
bool isOnPath(Mac48Address addr);
std::vector<Mac48Address> getSrcPath();
void setSrcPath(std::vector<Mac48Address> path);
bool reachPowerChanged();
void resetReachPowerChanged();
bool pathChanged();
void resetPathChanged();
uint32_t getConnCounter();
void incrementConnCounter();
void resetConnCounter();
private:
bool finished;
bool hasRpProblem;
bool rpChanged;
bool pChanged;
double noise;
double rxPower;
double reachPower;
double highest_maxTxPower;
double second_maxTxPower;
uint32_t connCounter;
Mac48Address parent;
Mac48Address address;
std::vector<Mac48Address> srcPath;
};
/*
* The GameState holds general information about a
* particular game identified by its gameID.
*/
class GameState : public Object
{
public:
GameState();
GameState(bool initiator, uint64_t gid);
virtual ~GameState();
static TypeId GetTypeId();
virtual TypeId GetInstanceTypeId() const;
bool isInitiator();
uint64_t getGameID();
bool needsCycleCheck();
void setCycleCheckNeeded(bool cc);
Mac48Address getMyAddress();
void setMyAddress(Mac48Address addr);
void finishGame();
bool gameFinished();
Time getTimeFinished();
uint16_t getLastSeqNo(Mac48Address sender, uint8_t ft);
bool checkLastFrameType(Mac48Address sender, uint8_t ft, uint16_t seqNo);
void updateLastFrameType(Mac48Address sender, uint8_t ft, uint16_t seqNo);
uint32_t getUnchangedCounter();
void incrementUnchangedCounter();
void resetUnchangedCounter();
Ptr<EEBTPNode> getParent();
void setParent(Ptr<EEBTPNode> p);
Ptr<EEBTPNode> getContactedParent();
void setContactedParent(Ptr<EEBTPNode> p);
bool hasLastParents();
Ptr<EEBTPNode> popLastParent();
Ptr<EEBTPNode> getLastParent();
uint32_t getLastParentConnCounter();
void pushLastParent(Ptr<EEBTPNode> parent);
void clearLastParents();
void findHighestTxPowers();
double getCostOfCurrentConn();
double getHighestTxPower();
double getSecondHighestTxPower();
bool isNeighbor(Mac48Address n);
void addNeighbor(Mac48Address n);
Ptr<EEBTPNode> getNeighbor(uint32_t index);
Ptr<EEBTPNode> getNeighbor(Mac48Address n);
Ptr<EEBTPNode> getCheapestNeighbor();
void removeNeighbor(Ptr<EEBTPNode> n);
uint32_t getNNeighbors();
bool hasChilds();
bool isChild(Mac48Address c);
bool isChild(Ptr<EEBTPNode> c);
void addChild(Ptr<EEBTPNode> c);
void removeChild(Ptr<EEBTPNode> c);
int getNChilds();
Ptr<EEBTPNode> getChild(int index);
bool allChildsFinished();
bool isBlacklisted(Ptr<EEBTPNode> node);
void updateBlacklist(Ptr<EEBTPNode> node);
void resetBlacklist();
bool isBlacklisted(Mac48Address node, Mac48Address parent);
bool doIncrAfterConfirm();
void setDoIncrAfterConfirm(bool v);
Ptr<SendEvent> getNeighborDiscoveryEvent();
void setNeighborDiscoveryEvent(Ptr<SendEvent> evt);
void resetNeighborDiscoveryEvent();
/*
* Mutex
*/
bool isLocked();
bool isLocked(Ptr<EEBTPNode> node);
void lock(bool l);
void lock(Ptr<EEBTPNode> node, bool l);
int getNChildsLocked();
void resetChildLocks();
Mac48Address getLockedBy();
void setLockedBy(Mac48Address addr);
bool isParentWaitingForLock();
void setParentWaitingForLock(bool b);
Ptr<EEBTPNode> getParentWaitingLockOriginator();
void setParentWaitingLockOriginator(Ptr<EEBTPNode> originator);
bool isNewParentWaitingForLock();
void setNewParentWaitingForLock(bool b);
Ptr<EEBTPNode> getNewParentWaitingLockOriginator();
void setNewParentWaitingLockOriginator(Ptr<EEBTPNode> originator);
Ptr<ApplicationDataHandler> getApplicationDataHandler();
uint32_t getRejectionCounter();
void incrementRejectionCounter();
void resetRejectionCounter();
void setRejectionCounter(uint32_t rj);
Time getLastParentUpdate();
void setLastParentUpdate(Time t);
void resetParentUnchangedCounter();
uint32_t getParentUnchangedCounter();
void incrementParentUnchangedCounter();
Ptr<ParentPathCheckEvent> getPPCEvent();
void setPPCEvent(Ptr<ParentPathCheckEvent>);
bool hadEmptyPathOnConnect();
void setEmptyPathOnConnect(bool b);
private:
bool initiator;
bool endOfGame;
bool doIncrementAfterConfirm;
Mac48Address myAddress;
bool needCycleCheck;
uint32_t rejectionCounter;
Time lastParentUpdate;
bool emptyPathOnConnect;
uint32_t parentUnchangedCounter;
Ptr<ParentPathCheckEvent> ppcEvent;
Time finishTime;
Ptr<EEBTPNode> parent;
Ptr<EEBTPNode> contactedParent;
uint64_t gameID;
uint32_t unchangedCounter;
double highestTxPower;
double secondTxPower;
double costOfCurrentConn;
std::vector<Ptr<EEBTPNode>> neighbors;
std::vector<Ptr<EEBTPNode>> childList;
std::map<Mac48Address, std::map<uint8_t, uint16_t>> frameTypeCache;
std::map<Mac48Address, Mac48Address> blacklist;
std::vector<Ptr<EEBTPNode>> lastParents;
Ptr<SendEvent> neighborDiscoveryEvent;
bool locked;
std::vector<Ptr<EEBTPNode>> locks;
int childsLocked;
bool parentIsWaitingForLock;
bool newParentIsWaitingForLock;
Ptr<EEBTPNode> lockOriginator;
Ptr<EEBTPNode> newParentLockOriginator;
Mac48Address lockedByNode;
std::vector<Mac48Address> srcPath;
Ptr<ApplicationDataHandler> adh;
};
}
#endif /* BROADCAST_GAMESTATE_H_ */