ITS
BroadcastForwardingPacketBuffer.cpp
Go to the documentation of this file.
2 
4 
6 {
7  m_mutex = new QMutex;
8 }
9 
11 {
13 }
14 
15 void BroadcastForwardingPacketBuffer::addPacket(BasicHeader bh, CommonHeader ch, GACPacket gac, QByteArray payload, QByteArray sender, uchar* destination, uchar* forwarder)
16 {
17  QMutexLocker locker(m_mutex);
18  BroadcastForwardingPacketEntry bfpe(bh, ch, gac, payload, sender, destination, forwarder);
19 
20  /* If the number of packet exceed the max buffer size, the first packet will be dropped and the packet will be added to the end of the queue */
22  {
23  m_bcForwardPacketBuffer.pop_front();
25  }
26 
27  /* If packet is already in the buffer, replace the old one with the new one */
28  if(int pos = m_bcForwardPacketBuffer.indexOf(bfpe) >= 0)
29  m_bcForwardPacketBuffer.replace(pos, bfpe);
30  else
31  {
32  bfpe.m_elapsed.start();
33  m_bcForwardPacketBuffer.push_back(bfpe);
35  }
36 }
37 
38 void BroadcastForwardingPacketBuffer::addPacket(BasicHeader bh, CommonHeader ch, GBCPacket gbc, QByteArray payload, QByteArray sender, uchar* destination, uchar* forwarder)
39 {
40  QMutexLocker locker(m_mutex);
41  BroadcastForwardingPacketEntry bfpe(bh, ch, gbc, payload, sender, destination, forwarder);
42 
43  /* If the number of packet exceed the max buffer size, the first packet will be dropped and the packet will be added to the end of the queue */
45  {
46  m_bcForwardPacketBuffer.pop_front();
48  }
49 
50  /* If packet is already in the buffer, replace the old one with the new one */
51  int pos = m_bcForwardPacketBuffer.indexOf(bfpe);
52  if(pos >= 0)
53  m_bcForwardPacketBuffer.replace(pos, bfpe);
54  else
55  {
56  bfpe.m_elapsed.start();
57  m_bcForwardPacketBuffer.push_back(bfpe);
59  }
60 }
61 
62 void BroadcastForwardingPacketBuffer::addPacket(BasicHeader bh, CommonHeader ch, TSBPacket tsb, QByteArray payload, QByteArray sender)
63 {
64  QMutexLocker locker(m_mutex);
65  BroadcastForwardingPacketEntry bfpe(bh, ch, tsb, payload, sender);
66 
67  /* If the number of packet exceed the max buffer size, the first packet will be dropped and the packet will be added to the end of the queue */
69  {
70  m_bcForwardPacketBuffer.pop_front();
72  }
73 
74  /* If packet is already in the buffer, replace the old one with the new one */
75  if(int pos = m_bcForwardPacketBuffer.indexOf(bfpe) >= 0)
76  m_bcForwardPacketBuffer.replace(pos, bfpe);
77  else
78  {
79  bfpe.m_elapsed.start();
80  m_bcForwardPacketBuffer.push_back(bfpe);
82  }
83 }
84 
85 void BroadcastForwardingPacketBuffer::addPacket(BasicHeader bh, CommonHeader ch, SHBPacket shb, QByteArray payload, QByteArray sender)
86 {
87  QMutexLocker locker(m_mutex);
88  BroadcastForwardingPacketEntry bfpe(bh, ch, shb, payload, sender);
89 
90  /* If the number of packet exceed the max buffer size, the first packet will be dropped and the packet will be added to the end of the queue */
92  {
93  m_bcForwardPacketBuffer.pop_front();
95  }
96 
97  /* If packet is already in the buffer, replace the old one with the new one */
98  if(int pos = m_bcForwardPacketBuffer.indexOf(bfpe) >= 0)
99  m_bcForwardPacketBuffer.replace(pos, bfpe);
100  else
101  {
102  bfpe.m_elapsed.start();
103  m_bcForwardPacketBuffer.push_back(bfpe);
105  }
106 }
107 
109 {
110  bool b = false;
111  QMutexLocker locker(m_mutex);
112  for(QVector<BroadcastForwardingPacketEntry>::Iterator i = m_bcForwardPacketBuffer.begin();i != m_bcForwardPacketBuffer.end(); ++i)
113  if(i->commonHeader().headerType() == CommonHeader::headerType_geoUnicast && isDuplicatePacketDetectionTimestampSN(i->gacPacket().soPv().timestamp(), packet.soPv().timestamp(), i->gacPacket().sequenceNumber(), packet.sequenceNumber()))
114  b = true;
115  return b;
116 }
117 
119 {
120  bool b = false;
121  QMutexLocker locker(m_mutex);
122  for(QVector<BroadcastForwardingPacketEntry>::Iterator i = m_bcForwardPacketBuffer.begin();i != m_bcForwardPacketBuffer.end(); ++i)
123  if(i->commonHeader().headerType() == CommonHeader::headerType_geoBroadcast && isDuplicatePacketDetectionTimestampSN(i->gbcPacket().soPv().timestamp(), packet.soPv().timestamp(), i->gbcPacket().sequenceNumber(), packet.sequenceNumber()))
124  b = true;
125  return b;
126 }
127 
129 {
130  bool b = false;
131  QMutexLocker locker(m_mutex);
132  for(QVector<BroadcastForwardingPacketEntry>::Iterator i = m_bcForwardPacketBuffer.begin();i != m_bcForwardPacketBuffer.end(); ++i)
133  if(i->commonHeader().headerType() == CommonHeader::headerType_topologicallyScopedBroadcast && i->commonHeader().headerSubType() == CommonHeader::headerSubTypeTopologicallyScopedBroadcast_multiHop && isDuplicatePacketDetectionTimestampSN(i->tsbPacket().soPv().timestamp(), packet.soPv().timestamp(), i->tsbPacket().sequenceNumber(), packet.sequenceNumber()))
134  b = true;
135  return b;
136 }
137 
139 {
140  bool b = false;
141  QMutexLocker locker(m_mutex);
142  for(QVector<BroadcastForwardingPacketEntry>::Iterator i = m_bcForwardPacketBuffer.begin();i != m_bcForwardPacketBuffer.end(); ++i)
143  if(i->commonHeader().headerType() == CommonHeader::headerType_topologicallyScopedBroadcast && i->commonHeader().headerSubType() == CommonHeader::headerSubTypeTopologicallyScopedBroadcast_singleHop && isDuplicatePacketDetectionTimestamp(i->tsbPacket().soPv().timestamp(), packet.soPv().timestamp()))
144  b = true;
145  return b;
146 }
147 
149 {
150  QMutexLocker locker(m_mutex);
151  m_bcForwardPacketBuffer.clear();
153 }
BroadcastForwardingPacketBuffer()
BroadcastForwardingPacketBuffer Default constructor.
QVector< BroadcastForwardingPacketEntry > m_bcForwardPacketBuffer
LongPositionVector soPv() const
soPv TSB SO PV getter.
Definition: TSBPacket.h:73
LongPositionVector soPv() const
soPv SO PV getter.
Definition: GBCPacket.h:95
quint32 timestamp() const
timestamp Timestamp field getter
quint16 sequenceNumber() const
sequenceNumber Sequence number getter.
Definition: GBCPacket.h:90
QElapsedTimer m_elapsed
bool isDuplicatePacketDetectionTimestampSN(quint32 lastReceivedTimestamp, quint32 nowReceivedTimestamp, quint16 lastReceivedSN, quint16 nowReceivedSN)
isDuplicatePacketDetectionTimestamp Calculate if the packet is a duplicate using the timestamp and th...
Definition: apiNetwork.cpp:104
void addPacket(BasicHeader bh, CommonHeader ch, GACPacket packet, QByteArray payload, QByteArray sender, uchar *destination, uchar *forwarder)
addPacket Add packet to the buffer.
#define itsGnBcForwardingPacketBufferSize
Definition: constantes.h:126
Buffer used for broadcast forwarding.
quint16 sequenceNumber() const
sequenceNumber TSB sequence number getter.
Definition: TSBPacket.h:68
bool isDuplicateTimestamp(GACPacket packet)
isDuplicateTimestamp Check is the packet is duplicate.
bool isDuplicatePacketDetectionTimestamp(quint32 lastReceivedTimestamp, quint32 nowReceivedTimestamp)
isDuplicatePacketDetectionTimestamp Calculate if the packet is a duplicate using the timestamp of the...
Definition: apiNetwork.cpp:95
LongPositionVector soPv() const
soPv SHB SO PV getter.
Definition: SHBPacket.h:66