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 #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");
29 
39 //-------------------------------------------------------------------------------------
40 
41 /* ----- = old packets
42  * +++++ = new packets
43  *
44  * CASE A: startSeq < endSeq
45  * - - +
46  * initial buffer state: 0 16 56000
47  *
48  *
49  * 0 4095
50  * |------|++++++++++++++++|-----|
51  * ^ ^
52  * | startSeq | endSeq = 4000
53  *
54  * first received packet's sequence control = 64016 (seqNum = 4001, fragNum = 0) -
55  * second received packet's sequence control = 63984 (seqNum = 3999, fragNum = 0) +
56  * 4001 is older seq number so this packet should be inserted at the buffer's begin.
57  * 3999 is previous element of older of new packets: it should be inserted at the end of buffer.
58  *
59  * expected buffer state: 64016 0 16 56000 63984
60  *
61  */
63 {
64 public:
66  virtual ~PacketBufferingCaseA ();
67 private:
68  virtual void DoRun (void);
69  std::list<uint16_t> m_expectedBuffer;
70 };
71 
73  : TestCase ("Check correct order of buffering when startSequence < endSeq")
74 {
75  m_expectedBuffer.push_back (64016);
76  m_expectedBuffer.push_back (0);
77  m_expectedBuffer.push_back (16);
78  m_expectedBuffer.push_back (56000);
79  m_expectedBuffer.push_back (63984);
80 }
81 
83 {
84 }
85 
86 void
88 {
89  std::list<uint16_t> m_buffer;
90  std::list<uint16_t>::iterator i,j;
91  m_buffer.push_back (0);
92  m_buffer.push_back (16);
93  m_buffer.push_back (56000);
94 
95  uint16_t endSeq = 4000;
96 
97  uint16_t receivedSeq = 4001 * 16;
98  uint32_t mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
99  for (i = m_buffer.begin (); i != m_buffer.end () && QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) < mappedSeq; i++)
100  {
101  ;
102  }
103  {
104  m_buffer.insert (i, receivedSeq);
105  }
106 
107  receivedSeq = 3999 * 16;
108  mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
109  for (i = m_buffer.begin (); i != m_buffer.end () && QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) < mappedSeq; i++)
110  {
111  ;
112  }
113  {
114  m_buffer.insert (i, receivedSeq);
115  }
116 
117  for (i = m_buffer.begin (), j = m_expectedBuffer.begin (); i != m_buffer.end (); i++, j++)
118  {
119  NS_TEST_EXPECT_MSG_EQ (*i, *j, "error in buffer order");
120  }
121 }
122 
123 /* ----- = old packets
124  * +++++ = new packets
125  *
126  * CASE B: startSeq > endSeq
127  * - + +
128  * initial buffer state: 256 64000 16
129  *
130  *
131  * 0 4095
132  * |++++++|----------------|++++++|
133  * ^ ^
134  * | endSeq = 10 | startSeq
135  *
136  * first received packet's sequence control = 240 (seqNum = 15, fragNum = 0) -
137  * second received packet's sequence control = 241 (seqNum = 15, fragNum = 1) -
138  * third received packet's sequence control = 64800 (seqNum = 4050, fragNum = 0) +
139  * 240 is an old packet should be inserted at the buffer's begin.
140  * 241 is an old packet: second segment of the above packet.
141  * 4050 is a new packet: it should be inserted between 64000 and 16.
142  *
143  * expected buffer state: 240 241 256 64000 64800 16
144  *
145  */
147 {
148 public:
150  virtual ~PacketBufferingCaseB ();
151 private:
152  virtual void DoRun (void);
153  std::list<uint16_t> m_expectedBuffer;
154 };
155 
157  : TestCase ("Check correct order of buffering when startSequence > endSeq")
158 {
159  m_expectedBuffer.push_back (240);
160  m_expectedBuffer.push_back (241);
161  m_expectedBuffer.push_back (256);
162  m_expectedBuffer.push_back (64000);
163  m_expectedBuffer.push_back (64800);
164  m_expectedBuffer.push_back (16);
165 }
166 
168 {
169 }
170 
171 void
173 {
174  std::list<uint16_t> m_buffer;
175  std::list<uint16_t>::iterator i,j;
176  m_buffer.push_back (256);
177  m_buffer.push_back (64000);
178  m_buffer.push_back (16);
179 
180  uint16_t endSeq = 10;
181 
182  uint16_t receivedSeq = 15 * 16;
183  uint32_t mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
184  for (i = m_buffer.begin (); i != m_buffer.end () && QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) < mappedSeq; i++)
185  {
186  ;
187  }
188  {
189  m_buffer.insert (i, receivedSeq);
190  }
191 
192  receivedSeq = 15 * 16 + 1;
193  mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
194  for (i = m_buffer.begin (); i != m_buffer.end () && QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) < mappedSeq; i++)
195  {
196  ;
197  }
198  {
199  m_buffer.insert (i, receivedSeq);
200  }
201 
202  receivedSeq = 4050 * 16;
203  mappedSeq = QosUtilsMapSeqControlToUniqueInteger (receivedSeq, endSeq);
204  for (i = m_buffer.begin (); i != m_buffer.end () && QosUtilsMapSeqControlToUniqueInteger ((*i), endSeq) < mappedSeq; i++)
205  {
206  ;
207  }
208  {
209  m_buffer.insert (i, receivedSeq);
210  }
211 
212  for (i = m_buffer.begin (), j = m_expectedBuffer.begin (); i != m_buffer.end (); i++, j++)
213  {
214  NS_TEST_EXPECT_MSG_EQ (*i, *j, "error in buffer order");
215  }
216 }
217 
218 //Test for block ack header
220 {
221 public:
223 private:
224  virtual void DoRun ();
226 };
227 
229  : TestCase ("Check the correctness of block ack compressed bitmap")
230 {
231 }
232 
233 void
235 {
237 
238  //Case 1: startSeq < endSeq
239  // 179 242
241  for (uint32_t i = 179; i < 220; i++)
242  {
244  }
245  for (uint32_t i = 225; i <= 242; i++)
246  {
248  }
249  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0xffffc1ffffffffffLL, "error in compressed bitmap");
251  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0xffffc1ffffffffffLL, "error in compressed bitmap");
252  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (220), false, "error in compressed bitmap");
253  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (225), true, "error in compressed bitmap");
254  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (1500), false, "error in compressed bitmap");
255 
257 
258  //Case 2: startSeq > endSeq
259  // 4090 58
261  for (uint32_t i = 4090; i != 10; i = (i + 1) % 4096)
262  {
264  }
265  for (uint32_t i = 22; i < 25; i++)
266  {
268  }
269  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0x00000000007000ffffLL, "error in compressed bitmap");
271  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.GetCompressedBitmap (), 0x00000000007000ffffLL, "error in compressed bitmap");
272  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (4090), true, "error in compressed bitmap");
273  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (4095), true, "error in compressed bitmap");
274  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (10), false, "error in compressed bitmap");
275  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (35), false, "error in compressed bitmap");
276  NS_TEST_EXPECT_MSG_EQ (m_blockAckHdr.IsPacketReceived (80), false, "error in compressed bitmap");
277 }
278 
280 {
281 public:
283 };
284 
286  : TestSuite ("wifi-block-ack", UNIT)
287 {
288  AddTestCase (new PacketBufferingCaseA, TestCase::QUICK);
289  AddTestCase (new PacketBufferingCaseB, TestCase::QUICK);
290  AddTestCase (new CtrlBAckResponseHeaderTest, TestCase::QUICK);
291 }
292 
std::list< uint16_t > m_expectedBuffer
A suite of tests to run.
Definition: test.h:1276
#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:273
encapsulates test code
Definition: test.h:1108
void SetStartingSequence(uint16_t seq)
Set the starting sequence number from the given raw sequence control field.
CtrlBAckResponseHeader m_blockAckHdr
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:190
Headers for Block ack response.
Definition: ctrl-headers.h:183
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(enum 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.
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.