-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplicationDataHandler.cc
136 lines (118 loc) · 2.93 KB
/
ApplicationDataHandler.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
/*
* ApplicationDataHandler.cc
*
* Created on: 24.08.2020
* Author: krassus
*/
#include "ns3/log.h"
#include "ns3/ptr.h"
#include "ns3/packet.h"
#include "ns3/integer.h"
#include "EEBTPDataHeader.h"
#include "ApplicationDataHandler.h"
namespace ns3
{
NS_LOG_COMPONENT_DEFINE("ApplicationDataHandler");
NS_OBJECT_ENSURE_REGISTERED(ApplicationDataHandler);
ApplicationDataHandler::ApplicationDataHandler()
{
this->packetCount = 0;
this->currentSeqNo = 0;
}
ApplicationDataHandler::~ApplicationDataHandler()
{
}
TypeId ApplicationDataHandler::GetTypeId()
{
static TypeId tid = TypeId("ns3::ApplicationDataHandler")
.SetParent<Object>()
.AddConstructor<ApplicationDataHandler>();
return tid;
}
TypeId ApplicationDataHandler::GetInstanceTypeId() const
{
return GetTypeId();
}
/*
* Application data handler
*/
bool ApplicationDataHandler::handleApplicationData(Ptr<Packet> packet)
{
EEBTPDataHeader header;
packet->PeekHeader(header);
if (header.GetSequenceNumber() > this->currentSeqNo + 16)
{
NS_LOG_DEBUG("Dropping data packet with seqNo " << header.GetSequenceNumber() << " because it is out of our sliding window (" << this->currentSeqNo << " -> " << (this->currentSeqNo + 16) << ")");
}
else
{
bool isMissing = false;
for (uint i = 0; i < this->missingSeqNos.size(); i++)
{
if (this->missingSeqNos[i] == header.GetSequenceNumber())
{
isMissing = true;
this->missingSeqNos.erase(this->missingSeqNos.begin() + i);
break;
}
}
if (!isMissing)
{
if (this->currentSeqNo < header.GetSequenceNumber())
{
NS_LOG_DEBUG("Received data packet with dSeqNo = " << header.GetSequenceNumber());
this->packetCount++;
this->currentSeqNo++;
while (this->currentSeqNo != header.GetSequenceNumber())
{
this->missingSeqNos.push_back(this->currentSeqNo);
this->currentSeqNo++;
}
}
else
{
NS_LOG_DEBUG("Dropping data packet with dSeqNo = " << header.GetSequenceNumber() << " because it is a duplicate");
return false;
}
}
else
NS_LOG_DEBUG("Received missing data packet with dSeqNo = " << header.GetSequenceNumber());
return true;
}
return false;
}
/*Ptr<Packet> ApplicationDataHandler::getLastPacket()
{
return *(this->packets.end()-1);
}
Ptr<Packet> ApplicationDataHandler::getPacketBySeqNo(uint32_t seqNo)
{
EEBTPDataHeader hdr;
for(Ptr<Packet> pkt : this->packets)
{
pkt->PeekHeader(hdr);
if(hdr.GetSequenceNumber() == seqNo)
return pkt;
}
return 0;
}*/
std::vector<uint32_t> ApplicationDataHandler::getMissingSeqNos()
{
return this->missingSeqNos;
}
/*
* For the initiator to count sequence numbers
*/
uint32_t ApplicationDataHandler::getLastSeqNo()
{
return this->currentSeqNo;
}
void ApplicationDataHandler::incrementSeqNo()
{
this->currentSeqNo++;
}
uint32_t ApplicationDataHandler::getPacketCount()
{
return this->packetCount;
}
}