A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #include "ns3/test.h"
21 #include "ns3/log.h"
22 #include "ns3/qos-utils.h"
23 #include "ns3/ctrl-headers.h"
24 #include <list>
25 
26 using namespace ns3;
27 
28 NS_LOG_COMPONENT_DEFINE ("BlockAckTest");
38 //-------------------------------------------------------------------------------------
39 
40 /* ----- = old packets
41  * +++++ = new packets
42  *
43  * CASE A: startSeq < endSeq
44  * - - +
45  * initial buffer state: 0 16 56000
46  *
47  *
48  * 0 4095
49  * |------|++++++++++++++++|-----|
50  * ^ ^
51  * | startSeq | endSeq = 4000
52  *
53  * first received packet's sequence control = 64016 (seqNum = 4001, fragNum = 0) -
54  * second received packet's sequence control = 63984 (seqNum = 3999, fragNum = 0) +
55  * 4001 is older seq number so this packet should be inserted at the buffer's begin.
56  * 3999 is previous element of older of new packets: it should be inserted at the end of buffer.
57  *
58  * expected buffer state: 64016 0 16 56000 63984
59  *
60  */
62 {
63 public:
65  virtual ~PacketBufferingCaseA ();
66 private:
67  virtual void DoRun (void);
68  std::list<uint16_t> m_expectedBuffer;
69 };
70 
72  : TestCase ("Check correct order of buffering when startSequence < endSeq")
73 {
74  m_expectedBuffer.push_back (64016);
75  m_expectedBuffer.push_back (0);
76  m_expectedBuffer.push_back (16);
77  m_expectedBuffer.push_back (56000);
78  m_expectedBuffer.push_back (63984);
79 }
80 
82 {
83 }
84 
85 void
87 {
88  std::list<uint16_t> m_buffer;
89  std::list<uint16_t>::iterator i,j;
90  m_buffer.push_back (0);
91  m_buffer.push_back (16);
92  m_buffer.push_back (56000);
93 
94  uint16_t endSeq = 4000;
95 
96  uint16_t receivedSeq = 4001 * 16;
97  uint32_t mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
98  for (i = m_buffer.begin (); i != m_buffer.end () && QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) < mappedSeq; i++)
99  {
100  ;
101  }
102  {
103  m_buffer.insert (i, receivedSeq);
104  }
105 
106  receivedSeq = 3999 * 16;
107  mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
108  for (i = m_buffer.begin (); i != m_buffer.end () && QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) < mappedSeq; i++)
109  {
110  ;
111  }
112  {
113  m_buffer.insert (i, receivedSeq);
114  }
115 
116  for (i = m_buffer.begin (), j = m_expectedBuffer.begin (); i != m_buffer.end (); i++, j++)
117  {
118  NS_TEST_EXPECT_MSG_EQ (*i, *j, "error in buffer order");
119  }
120 }
121 
122 /* ----- = old packets
123  * +++++ = new packets
124  *
125  * CASE B: startSeq > endSeq
126  * - + +
127  * initial buffer state: 256 64000 16
128  *
129  *
130  * 0 4095
131  * |++++++|----------------|++++++|
132  * ^ ^
133  * | endSeq = 10 | startSeq
134  *
135  * first received packet's sequence control = 240 (seqNum = 15, fragNum = 0) -
136  * second received packet's sequence control = 241 (seqNum = 15, fragNum = 1) -
137  * third received packet's sequence control = 64800 (seqNum = 4050, fragNum = 0) +
138  * 240 is an old packet should be inserted at the buffer's begin.
139  * 241 is an old packet: second segment of the above packet.
140  * 4050 is a new packet: it should be inserted between 64000 and 16.
141  *
142  * expected buffer state: 240 241 256 64000 64800 16
143  *
144  */
146 {
147 public:
149  virtual ~PacketBufferingCaseB ();
150 private:
151  virtual void DoRun (void);
152  std::list<uint16_t> m_expectedBuffer;
153 };
154 
156  : TestCase ("Check correct order of buffering when startSequence > endSeq")
157 {
158  m_expectedBuffer.push_back (240);
159  m_expectedBuffer.push_back (241);
160  m_expectedBuffer.push_back (256);
161  m_expectedBuffer.push_back (64000);
162  m_expectedBuffer.push_back (64800);
163  m_expectedBuffer.push_back (16);
164 }
165 
167 {
168 }
169 
170 void
172 {
173  std::list<uint16_t> m_buffer;
174  std::list<uint16_t>::iterator i,j;
175  m_buffer.push_back (256);
176  m_buffer.push_back (64000);
177  m_buffer.push_back (16);
178 
179  uint16_t endSeq = 10;
180 
181  uint16_t receivedSeq = 15 * 16;
182  uint32_t mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
183  for (i = m_buffer.begin (); i != m_buffer.end () && QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) < mappedSeq; i++)
184  {
185  ;
186  }
187  {
188  m_buffer.insert (i, receivedSeq);
189  }
190 
191  receivedSeq = 15 * 16 + 1;
192  mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
193  for (i = m_buffer.begin (); i != m_buffer.end () && QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) < mappedSeq; i++)
194  {
195  ;
196  }
197  {
198  m_buffer.insert (i, receivedSeq);
199  }
200 
201  receivedSeq = 4050 * 16;
202  mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
203  for (i = m_buffer.begin (); i != m_buffer.end () && QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) < mappedSeq; i++)
204  {
205  ;
206  }
207  {
208  m_buffer.insert (i, receivedSeq);
209  }
210 
211  for (i = m_buffer.begin (), j = m_expectedBuffer.begin (); i != m_buffer.end (); i++, j++)
212  {
213  NS_TEST_EXPECT_MSG_EQ (*i, *j, "error in buffer order");
214  }
215 }
216 
217 //Test for block ack header
219 {
220 public:
222 private:
223  virtual void DoRun ();
225 };
226 
228  : TestCase ("Check the correctness of block ack compressed bitmap")
229 {
230 }
231 
232 void
234 {
236 
237  //Case 1: startSeq < endSeq
238  // 179 242
240  for (uint32_t i = 179; i < 220; i++)
241  {
243  }
244  for (uint32_t i = 225; i <= 242; i++)
245  {
247  }
248  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0xffffc1ffffffffffLL, "error in compressed bitmap");
250  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0xffffc1ffffffffffLL, "error in compressed bitmap");
251  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (220), false, "error in compressed bitmap");
252  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (225), true, "error in compressed bitmap");
253  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (1500), false, "error in compressed bitmap");
254 
256 
257  //Case 2: startSeq > endSeq
258  // 4090 58
260  for (uint32_t i = 4090; i != 10; i = (i + 1) % 4096)
261  {
263  }
264  for (uint32_t i = 22; i < 25; i++)
265  {
267  }
268  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0x00000000007000ffffLL, "error in compressed bitmap");
270  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0x00000000007000ffffLL, "error in compressed bitmap");
271  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (4090), true, "error in compressed bitmap");
272  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (4095), true, "error in compressed bitmap");
273  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (10), false, "error in compressed bitmap");
274  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (35), false, "error in compressed bitmap");
275  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (80), false, "error in compressed bitmap");
276 }
277 
279 {
280 public:
282 };
283 
285  : TestSuite ("wifi-block-ack", UNIT)
286 {
287  AddTestCase (new PacketBufferingCaseA, TestCase::QUICK);
288  AddTestCase (new PacketBufferingCaseB, TestCase::QUICK);
289  AddTestCase (new CtrlBAckResponseHeaderTest, TestCase::QUICK);
290 }
291 
std::list< uint16_t > m_expectedBuffer
A suite of tests to run.
Definition: test.h:1105
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
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:265
encapsulates test code
Definition: test.h:929
void SetStartingSequence(uint16_t seq)
Set the starting sequence number from the given raw sequence control field.
CtrlBAckResponseHeader m_blockAckHdr
Headers for Block ack response.
Definition: ctrl-headers.h:183
virtual void DoRun(void)
Implementation to actually run this TestCase.
void SetType(enum BlockAckType type)
Set the block ACK type.
void ResetBitmap(void)
Reset the bitmap to 0.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:184
void SetReceivedPacket(uint16_t seq)
Set the bitmap that the packet with the given sequence number was received.
This simple test verifies the correctness of buffering for packets received under block ack...
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:75
virtual void DoRun()
Implementation to actually run this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
static BlockAckTestSuite g_blockAckTestSuite
std::list< uint16_t > m_expectedBuffer
uint64_t GetCompressedBitmap(void) const
Return the compressed bitmap from the block ACK response header.