-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEEBTPHeader_SrcPath.cc
179 lines (143 loc) · 3.84 KB
/
EEBTPHeader_SrcPath.cc
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
/*
* EEBTPHeader_SrcPath.cc
*
* Created on: 21.07.2020
* Author: krassus
*/
#include "bitset"
#include "ns3/log.h"
#include "ns3/integer.h"
#include "EEBTPHeader_SrcPath.h"
namespace ns3
{
NS_OBJECT_ENSURE_REGISTERED(EEBTPHeaderSrcPath);
EEBTPHeaderSrcPath::EEBTPHeaderSrcPath() : EEBTPHeader()
{
}
EEBTPHeaderSrcPath::~EEBTPHeaderSrcPath()
{
}
TypeId EEBTPHeaderSrcPath::GetTypeId()
{
static TypeId tid = TypeId("ns3::EEBTPHeaderSrcPath")
.SetParent<EEBTPHeader>()
.AddConstructor<EEBTPHeaderSrcPath>();
return tid;
}
TypeId EEBTPHeaderSrcPath::GetInstanceTypeId() const
{
return GetTypeId();
}
void EEBTPHeaderSrcPath::Print(std::ostream &os) const
{
os << "originator=" << originator.operator ns3::Address();
}
uint32_t EEBTPHeaderSrcPath::GetSerializedSize() const
{
uint32_t sSize = 21; //Minimum header size
if (this->frameType < 2 || this->frameType == 3)
{
sSize += 1;
sSize += this->path.size() * 6;
}
return sSize;
}
void EEBTPHeaderSrcPath::Serialize(Buffer::Iterator start) const
{
//Write the frame type
uint8_t ft = this->frameType;
if (this->receivingProblems)
ft |= 0b10000000;
if (this->gameFinished)
ft |= 0b01000000;
start.WriteU8(ft);
//Write sequence number and game ID
uint64_t seqNo_gid = ((uint64_t)this->seqNo << 48) | this->gameID;
start.WriteU64(seqNo_gid);
//Write current transmission power
uint8_t buff[4];
memcpy(&buff, &this->txPower_dBm, sizeof(this->txPower_dBm));
start.Write(buff, 4);
//Write highest maxTxPower
memcpy(&buff, &this->highest_maxTxPower_dBm, sizeof(this->highest_maxTxPower_dBm));
start.Write(buff, 4);
//Write second highest maxTxPower
memcpy(&buff, &this->second_maxTxPower_dBm, sizeof(this->second_maxTxPower_dBm));
start.Write(buff, 4);
uint8_t addr[6];
if (this->frameType < 2)
{
//Write length of the node list
start.WriteU8(this->path.size());
//Write path
for (uint i = 0; i < this->path.size(); i++)
{
this->path[i].CopyTo(addr);
start.Write(addr, 6);
}
}
else if (this->frameType == 3)
{
this->recipient.CopyTo(addr);
start.Write(addr, 6);
}
}
uint32_t EEBTPHeaderSrcPath::Deserialize(Buffer::Iterator start)
{
uint32_t bytesRead = 13;
//Read the frame type
this->frameType = start.ReadU8();
//Check for receiving problem flag
if ((this->frameType & 0b10000000) == 0b10000000)
this->receivingProblems = true;
else
this->receivingProblems = false;
//Check for game finished flag
if ((this->frameType & 0b01000000) == 0b01000000)
this->gameFinished = true;
else
this->gameFinished = false;
//Set correct frameType
this->frameType &= 0b00111111;
//Read sequence number and game ID
this->gameID = start.ReadU64();
this->seqNo = this->gameID >> 48;
this->gameID &= ((uint64_t)-1) >> 16;
//Read the current transmission power of the remote node
uint8_t buff[4];
start.Read(buff, 4);
memcpy(&this->txPower_dBm, &buff, sizeof(this->txPower_dBm));
//Read highest maxTxPower
start.Read(buff, 4);
memcpy(&this->highest_maxTxPower_dBm, &buff, sizeof(this->highest_maxTxPower_dBm));
//Read second highest maxTxPower
start.Read(buff, 4);
memcpy(&this->second_maxTxPower_dBm, &buff, sizeof(this->second_maxTxPower_dBm));
//Only frame type 0 and 1 have a src path
uint8_t addr[6];
if (this->frameType == 1 || this->frameType == 3)
{
//Read length of the node list
uint length = start.ReadU8();
bytesRead += 1;
//Read path
Mac48Address node;
for (uint i = 0; i < length; i++)
{
start.Read(addr, 6);
node.CopyFrom(addr);
this->addNodeToPath(node);
bytesRead += 6;
}
}
return bytesRead;
}
void EEBTPHeaderSrcPath::addNodeToPath(Mac48Address addr)
{
this->path.push_back(addr);
}
std::vector<Mac48Address> EEBTPHeaderSrcPath::getSrcPath()
{
return this->path;
}
}