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/log.h"
23 #include "ns3/qos-utils.h"
24 #include "ns3/ctrl-headers.h"
25 
26 using namespace ns3;
27 
28 NS_LOG_COMPONENT_DEFINE ("BlockAckTest");
29 
44 //-------------------------------------------------------------------------------------
45 
46 /* ----- = old packets
47  * +++++ = new packets
48  *
49  * CASE A: startSeq < endSeq
50  * - - +
51  * initial buffer state: 0 16 56000
52  *
53  *
54  * 0 4095
55  * |------|++++++++++++++++|-----|
56  * ^ ^
57  * | startSeq | endSeq = 4000
58  *
59  * first received packet's sequence control = 64016 (seqNum = 4001, fragNum = 0) -
60  * second received packet's sequence control = 63984 (seqNum = 3999, fragNum = 0) +
61  * 4001 is older seq number so this packet should be inserted at the buffer's begin.
62  * 3999 is previous element of older of new packets: it should be inserted at the end of buffer.
63  *
64  * expected buffer state: 64016 0 16 56000 63984
65  *
66  */
68 {
69 public:
71  virtual ~PacketBufferingCaseA ();
72 private:
73  virtual void DoRun (void);
74  std::list<uint16_t> m_expectedBuffer;
75 };
76 
78  : TestCase ("Check correct order of buffering when startSequence < endSeq")
79 {
80  m_expectedBuffer.push_back (64016);
81  m_expectedBuffer.push_back (0);
82  m_expectedBuffer.push_back (16);
83  m_expectedBuffer.push_back (56000);
84  m_expectedBuffer.push_back (63984);
85 }
86 
88 {
89 }
90 
91 void
93 {
94  std::list<uint16_t> m_buffer;
95  std::list<uint16_t>::iterator i,j;
96  m_buffer.push_back (0);
97  m_buffer.push_back (16);
98  m_buffer.push_back (56000);
99 
100  uint16_t endSeq = 4000;
101 
102  uint16_t receivedSeq = 4001 * 16;
103  uint32_t mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
104  /* cycle to right position for this packet */
105  for (i = m_buffer.begin (); i != m_buffer.end (); i++)
106  {
107  if (QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) >= mappedSeq)
108  {
109  //position found
110  break;
111  }
112  }
113  m_buffer.insert (i, receivedSeq);
114 
115  receivedSeq = 3999 * 16;
116  mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
117  /* cycle to right position for this packet */
118  for (i = m_buffer.begin (); i != m_buffer.end (); i++)
119  {
120  if (QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) >= mappedSeq)
121  {
122  //position found
123  break;
124  }
125  }
126  m_buffer.insert (i, receivedSeq);
127 
128  for (i = m_buffer.begin (), j = m_expectedBuffer.begin (); i != m_buffer.end (); i++, j++)
129  {
130  NS_TEST_EXPECT_MSG_EQ (*i, *j, "error in buffer order");
131  }
132 }
133 
134 
165 {
166 public:
168  virtual ~PacketBufferingCaseB ();
169 private:
170  virtual void DoRun (void);
171  std::list<uint16_t> m_expectedBuffer;
172 };
173 
175  : TestCase ("Check correct order of buffering when startSequence > endSeq")
176 {
177  m_expectedBuffer.push_back (240);
178  m_expectedBuffer.push_back (241);
179  m_expectedBuffer.push_back (256);
180  m_expectedBuffer.push_back (64000);
181  m_expectedBuffer.push_back (64800);
182  m_expectedBuffer.push_back (16);
183 }
184 
186 {
187 }
188 
189 void
191 {
192  std::list<uint16_t> m_buffer;
193  std::list<uint16_t>::iterator i,j;
194  m_buffer.push_back (256);
195  m_buffer.push_back (64000);
196  m_buffer.push_back (16);
197 
198  uint16_t endSeq = 10;
199 
200  uint16_t receivedSeq = 15 * 16;
201  uint32_t mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
202  /* cycle to right position for this packet */
203  for (i = m_buffer.begin (); i != m_buffer.end (); i++)
204  {
205  if (QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) >= mappedSeq)
206  {
207  //position found
208  break;
209  }
210  }
211  m_buffer.insert (i, receivedSeq);
212 
213  receivedSeq = 15 * 16 + 1;
214  mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
215  /* cycle to right position for this packet */
216  for (i = m_buffer.begin (); i != m_buffer.end (); i++)
217  {
218  if (QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) >= mappedSeq)
219  {
220  //position found
221  break;
222  }
223  }
224  m_buffer.insert (i, receivedSeq);
225 
226  receivedSeq = 4050 * 16;
227  mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
228  /* cycle to right position for this packet */
229  for (i = m_buffer.begin (); i != m_buffer.end (); i++)
230  {
231  if (QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) >= mappedSeq)
232  {
233  //position found
234  break;
235  }
236  }
237  m_buffer.insert (i, receivedSeq);
238 
239  for (i = m_buffer.begin (), j = m_expectedBuffer.begin (); i != m_buffer.end (); i++, j++)
240  {
241  NS_TEST_EXPECT_MSG_EQ (*i, *j, "error in buffer order");
242  }
243 }
244 
245 
253 {
254 public:
256 private:
257  virtual void DoRun ();
259 };
260 
262  : TestCase ("Check the correctness of block ack compressed bitmap")
263 {
264 }
265 
266 void
268 {
270 
271  //Case 1: startSeq < endSeq
272  // 179 242
274  for (uint32_t i = 179; i < 220; i++)
275  {
277  }
278  for (uint32_t i = 225; i <= 242; i++)
279  {
281  }
282  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0xffffc1ffffffffffLL, "error in compressed bitmap");
284  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0xffffc1ffffffffffLL, "error in compressed bitmap");
285  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (220), false, "error in compressed bitmap");
286  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (225), true, "error in compressed bitmap");
287  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (1500), false, "error in compressed bitmap");
288 
290 
291  //Case 2: startSeq > endSeq
292  // 4090 58
294  for (uint32_t i = 4090; i != 10; i = (i + 1) % 4096)
295  {
297  }
298  for (uint32_t i = 22; i < 25; i++)
299  {
301  }
302  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0x00000000007000ffffLL, "error in compressed bitmap");
304  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0x00000000007000ffffLL, "error in compressed bitmap");
305  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (4090), true, "error in compressed bitmap");
306  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (4095), true, "error in compressed bitmap");
307  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (10), false, "error in compressed bitmap");
308  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (35), false, "error in compressed bitmap");
309  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (80), false, "error in compressed bitmap");
310 }
311 
319 {
320 public:
322 };
323 
325  : TestSuite ("wifi-block-ack", UNIT)
326 {
327  AddTestCase (new PacketBufferingCaseA, TestCase::QUICK);
328  AddTestCase (new PacketBufferingCaseB, TestCase::QUICK);
329  AddTestCase (new CtrlBAckResponseHeaderTest, TestCase::QUICK);
330 }
331 
std::list< uint16_t > m_expectedBuffer
expected test buffer
A suite of tests to run.
Definition: test.h:1342
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
bool IsPacketReceived(uint16_t seq) const
Check if the packet with the given sequence number was ACKed in this Block ACK response.
#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
Headers for Block ack response.
Definition: ctrl-headers.h:190
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:77
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
uint64_t GetCompressedBitmap(void) const
Return the compressed bitmap from the block ACK response header.