A Discrete-Event Network Simulator
API
block-ack-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009, 2010 MIRKO BANCHI
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mirko Banchi <mk.banchi@gmail.com>
19  */
20 
21 #include "ns3/test.h"
22 #include "ns3/qos-utils.h"
23 #include "ns3/ctrl-headers.h"
24 
25 using namespace ns3;
26 
41 //-------------------------------------------------------------------------------------
42 
43 /* ----- = old packets
44  * +++++ = new packets
45  *
46  * CASE A: startSeq < endSeq
47  * - - +
48  * initial buffer state: 0 16 56000
49  *
50  *
51  * 0 4095
52  * |------|++++++++++++++++|-----|
53  * ^ ^
54  * | startSeq | endSeq = 4000
55  *
56  * first received packet's sequence control = 64016 (seqNum = 4001, fragNum = 0) -
57  * second received packet's sequence control = 63984 (seqNum = 3999, fragNum = 0) +
58  * 4001 is older seq number so this packet should be inserted at the buffer's begin.
59  * 3999 is previous element of older of new packets: it should be inserted at the end of buffer.
60  *
61  * expected buffer state: 64016 0 16 56000 63984
62  *
63  */
65 {
66 public:
68  virtual ~PacketBufferingCaseA ();
69 private:
70  virtual void DoRun (void);
71  std::list<uint16_t> m_expectedBuffer;
72 };
73 
75  : TestCase ("Check correct order of buffering when startSequence < endSeq")
76 {
77  m_expectedBuffer.push_back (64016);
78  m_expectedBuffer.push_back (0);
79  m_expectedBuffer.push_back (16);
80  m_expectedBuffer.push_back (56000);
81  m_expectedBuffer.push_back (63984);
82 }
83 
85 {
86 }
87 
88 void
90 {
91  std::list<uint16_t> m_buffer;
92  std::list<uint16_t>::iterator i,j;
93  m_buffer.push_back (0);
94  m_buffer.push_back (16);
95  m_buffer.push_back (56000);
96 
97  uint16_t endSeq = 4000;
98 
99  uint16_t receivedSeq = 4001 * 16;
100  uint32_t mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
101  /* cycle to right position for this packet */
102  for (i = m_buffer.begin (); i != m_buffer.end (); i++)
103  {
104  if (QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) >= mappedSeq)
105  {
106  //position found
107  break;
108  }
109  }
110  m_buffer.insert (i, receivedSeq);
111 
112  receivedSeq = 3999 * 16;
113  mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
114  /* cycle to right position for this packet */
115  for (i = m_buffer.begin (); i != m_buffer.end (); i++)
116  {
117  if (QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) >= mappedSeq)
118  {
119  //position found
120  break;
121  }
122  }
123  m_buffer.insert (i, receivedSeq);
124 
125  for (i = m_buffer.begin (), j = m_expectedBuffer.begin (); i != m_buffer.end (); i++, j++)
126  {
127  NS_TEST_EXPECT_MSG_EQ (*i, *j, "error in buffer order");
128  }
129 }
130 
131 
162 {
163 public:
165  virtual ~PacketBufferingCaseB ();
166 private:
167  virtual void DoRun (void);
168  std::list<uint16_t> m_expectedBuffer;
169 };
170 
172  : TestCase ("Check correct order of buffering when startSequence > endSeq")
173 {
174  m_expectedBuffer.push_back (240);
175  m_expectedBuffer.push_back (241);
176  m_expectedBuffer.push_back (256);
177  m_expectedBuffer.push_back (64000);
178  m_expectedBuffer.push_back (64800);
179  m_expectedBuffer.push_back (16);
180 }
181 
183 {
184 }
185 
186 void
188 {
189  std::list<uint16_t> m_buffer;
190  std::list<uint16_t>::iterator i,j;
191  m_buffer.push_back (256);
192  m_buffer.push_back (64000);
193  m_buffer.push_back (16);
194 
195  uint16_t endSeq = 10;
196 
197  uint16_t receivedSeq = 15 * 16;
198  uint32_t mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
199  /* cycle to right position for this packet */
200  for (i = m_buffer.begin (); i != m_buffer.end (); i++)
201  {
202  if (QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) >= mappedSeq)
203  {
204  //position found
205  break;
206  }
207  }
208  m_buffer.insert (i, receivedSeq);
209 
210  receivedSeq = 15 * 16 + 1;
211  mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
212  /* cycle to right position for this packet */
213  for (i = m_buffer.begin (); i != m_buffer.end (); i++)
214  {
215  if (QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) >= mappedSeq)
216  {
217  //position found
218  break;
219  }
220  }
221  m_buffer.insert (i, receivedSeq);
222 
223  receivedSeq = 4050 * 16;
224  mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
225  /* cycle to right position for this packet */
226  for (i = m_buffer.begin (); i != m_buffer.end (); i++)
227  {
228  if (QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) >= mappedSeq)
229  {
230  //position found
231  break;
232  }
233  }
234  m_buffer.insert (i, receivedSeq);
235 
236  for (i = m_buffer.begin (), j = m_expectedBuffer.begin (); i != m_buffer.end (); i++, j++)
237  {
238  NS_TEST_EXPECT_MSG_EQ (*i, *j, "error in buffer order");
239  }
240 }
241 
242 
250 {
251 public:
253 private:
254  virtual void DoRun ();
256 };
257 
259  : TestCase ("Check the correctness of block ack compressed bitmap")
260 {
261 }
262 
263 void
265 {
267 
268  //Case 1: startSeq < endSeq
269  // 179 242
271  for (uint16_t i = 179; i < 220; i++)
272  {
274  }
275  for (uint16_t i = 225; i <= 242; i++)
276  {
278  }
279  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0xffffc1ffffffffffLL, "error in compressed bitmap");
281  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0xffffc1ffffffffffLL, "error in compressed bitmap");
282  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (220), false, "error in compressed bitmap");
283  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (225), true, "error in compressed bitmap");
284  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (1500), false, "error in compressed bitmap");
285 
287 
288  //Case 2: startSeq > endSeq
289  // 4090 58
291  for (uint16_t i = 4090; i != 10; i = (i + 1) % 4096)
292  {
294  }
295  for (uint16_t i = 22; i < 25; i++)
296  {
298  }
299  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0x00000000007000ffffLL, "error in compressed bitmap");
301  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0x00000000007000ffffLL, "error in compressed bitmap");
302  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (4090), true, "error in compressed bitmap");
303  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (4095), true, "error in compressed bitmap");
304  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (10), false, "error in compressed bitmap");
305  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (35), false, "error in compressed bitmap");
306  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (80), false, "error in compressed bitmap");
307 }
308 
316 {
317 public:
319 };
320 
322  : TestSuite ("wifi-block-ack", UNIT)
323 {
324  AddTestCase (new PacketBufferingCaseA, TestCase::QUICK);
325  AddTestCase (new PacketBufferingCaseB, TestCase::QUICK);
326  AddTestCase (new CtrlBAckResponseHeaderTest, TestCase::QUICK);
327 }
328 
std::list< uint16_t > m_expectedBuffer
expected test buffer
A suite of tests to run.
Definition: test.h:1342
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition: test.h:285
encapsulates test code
Definition: test.h:1155
void SetStartingSequence(uint16_t seq)
Set the starting sequence number from the given raw sequence control field.
CtrlBAckResponseHeader m_blockAckHdr
block ack header
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
uint64_t GetCompressedBitmap(void) const
Return the compressed bitmap from the block ACK response header.
bool IsPacketReceived(uint16_t seq) const
Check if the packet with the given sequence number was ACKed in this Block ACK response.
Headers for Block ack response.
Definition: ctrl-headers.h:181
Packet Buffering Case B.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetType(BlockAckType type)
Set the block ACK type.
void ResetBitmap(void)
Reset the bitmap to 0.
void SetReceivedPacket(uint16_t seq)
Set the bitmap that the packet with the given sequence number was received.
Packet Buffering Case A.
uint32_t QosUtilsMapSeqControlToUniqueInteger(uint16_t seqControl, uint16_t endSequence)
Next function is useful to correctly sort buffered packets under block ack.
Definition: qos-utils.cc:72
virtual void DoRun()
Implementation to actually run this TestCase.
Block Ack Test Suite.
Test for block ack header.
virtual void DoRun(void)
Implementation to actually run this TestCase.
static BlockAckTestSuite g_blockAckTestSuite
the test suite
std::list< uint16_t > m_expectedBuffer
expected test buffer