|
110 |
void |
110 |
void |
111 |
Ns3TcpStateTestCase::DoSetup (void) |
111 |
Ns3TcpStateTestCase::DoSetup (void) |
112 |
{ |
112 |
{ |
|
|
113 |
Simulator::Destroy(); |
114 |
|
115 |
// Enable packet metadata |
116 |
Packet::EnablePrinting (); |
117 |
|
113 |
// |
118 |
// |
114 |
// We expect there to be a file called ns3tcp-state-response-vectors.pcap in |
119 |
// We expect there to be a file called ns3tcp-state-response-vectors.pcap in |
115 |
// response-vectors/ of this directory |
120 |
// response-vectors/ of this directory |
|
128 |
m_pcapFile.Open (m_pcapFilename, std::ios::in|std::ios::binary); |
133 |
m_pcapFile.Open (m_pcapFilename, std::ios::in|std::ios::binary); |
129 |
NS_ABORT_MSG_UNLESS (m_pcapFile.GetDataLinkType () == PCAP_LINK_TYPE, "Wrong response vectors in directory"); |
134 |
NS_ABORT_MSG_UNLESS (m_pcapFile.GetDataLinkType () == PCAP_LINK_TYPE, "Wrong response vectors in directory"); |
130 |
} |
135 |
} |
|
|
136 |
|
137 |
// Config |
138 |
std::string tcpModel ("ns3::TcpNewReno"); |
139 |
Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue (tcpModel)); |
140 |
Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); |
141 |
Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); |
142 |
Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (20)); |
143 |
|
144 |
// Logging |
145 |
if (m_writeLogging) |
146 |
{ |
147 |
LogComponentEnableAll (LOG_PREFIX_FUNC); |
148 |
LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); |
149 |
LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); |
150 |
LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); |
151 |
LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); |
152 |
LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); |
153 |
LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); |
154 |
LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); |
155 |
} |
131 |
} |
156 |
} |
132 |
|
157 |
|
133 |
void |
158 |
void |
134 |
Ns3TcpStateTestCase::DoTeardown (void) |
159 |
Ns3TcpStateTestCase::DoTeardown (void) |
135 |
{ |
160 |
{ |
|
|
161 |
// Restore Logging |
162 |
if (m_writeLogging) |
163 |
{ |
164 |
LogComponentDisableAll (LOG_PREFIX_FUNC); |
165 |
LogComponentDisable ("TcpTestCases", LOG_LEVEL_ALL); |
166 |
LogComponentDisable ("ErrorModel", LOG_LEVEL_DEBUG); |
167 |
LogComponentDisable ("TcpTestCases", LOG_LEVEL_ALL); |
168 |
LogComponentDisable ("TcpNewReno", LOG_LEVEL_INFO); |
169 |
LogComponentDisable ("TcpReno", LOG_LEVEL_INFO); |
170 |
LogComponentDisable ("TcpTahoe", LOG_LEVEL_INFO); |
171 |
LogComponentDisable ("TcpSocketBase", LOG_LEVEL_INFO); |
172 |
} |
173 |
|
174 |
// Restore config to usual defaults |
175 |
Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (536)); |
176 |
Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (2)); |
177 |
Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (100)); |
178 |
// No need to restore ns3::TcpL4Protocol::SocketType, ns3::TcpNewReno is already the default |
179 |
|
136 |
m_pcapFile.Close (); |
180 |
m_pcapFile.Close (); |
|
|
181 |
|
182 |
// Enable packet metadata |
183 |
Packet::DisablePrinting (); |
184 |
|
185 |
Simulator::Destroy(); |
137 |
} |
186 |
} |
138 |
|
187 |
|
139 |
void |
188 |
void |
|
177 |
// file and see if it still does the right thing. |
226 |
// file and see if it still does the right thing. |
178 |
// |
227 |
// |
179 |
uint8_t expected[PCAP_SNAPLEN]; |
228 |
uint8_t expected[PCAP_SNAPLEN]; |
180 |
uint32_t tsSec, tsUsec, inclLen, origLen, readLen; |
229 |
uint32_t tsSec=0, tsUsec=0, inclLen=0, origLen=0, readLen=0; |
181 |
m_pcapFile.Read (expected, sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen); |
230 |
m_pcapFile.Read (expected, sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen); |
|
|
231 |
|
232 |
if (readLen != 0 && origLen != 0) |
233 |
{ |
234 |
uint8_t *actual = new uint8_t[readLen]; |
235 |
p->CopyData (actual, readLen); |
182 |
|
236 |
|
183 |
uint8_t *actual = new uint8_t[readLen]; |
237 |
uint32_t result = memcmp (actual, expected, readLen); |
184 |
p->CopyData (actual, readLen); |
|
|
185 |
|
238 |
|
186 |
uint32_t result = memcmp (actual, expected, readLen); |
239 |
delete [] actual; |
187 |
|
240 |
|
188 |
delete [] actual; |
241 |
// |
189 |
|
242 |
// Avoid streams of errors -- only report the first. |
190 |
// |
243 |
// |
191 |
// Avoid streams of errors -- only report the first. |
244 |
if (GetErrorStatus () == false) |
192 |
// |
245 |
{ |
193 |
if (GetErrorStatus () == false) |
246 |
NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); |
|
|
247 |
} |
248 |
} |
249 |
else if (GetErrorStatus () == false) |
194 |
{ |
250 |
{ |
195 |
NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); |
251 |
NS_TEST_EXPECT_MSG_GT (readLen, 0, "Unexpected packet error"); |
196 |
} |
252 |
} |
197 |
} |
253 |
} |
198 |
} |
254 |
} |
|
266 |
// 10Mb/s, 0.1ms 10Mb/s, 0.1ms |
322 |
// 10Mb/s, 0.1ms 10Mb/s, 0.1ms |
267 |
// n0-----------------n1-----------------n2 |
323 |
// n0-----------------n1-----------------n2 |
268 |
|
324 |
|
269 |
std::string tcpModel ("ns3::TcpNewReno"); |
|
|
270 |
|
271 |
Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue (tcpModel)); |
272 |
Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); |
273 |
Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); |
274 |
Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (20)); |
275 |
|
276 |
if (m_writeLogging) |
277 |
{ |
278 |
LogComponentEnableAll (LOG_PREFIX_FUNC); |
279 |
LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); |
280 |
LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); |
281 |
LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); |
282 |
LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); |
283 |
LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); |
284 |
LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); |
285 |
LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); |
286 |
} |
287 |
|
288 |
//////////////////////////////////////////////////////// |
325 |
//////////////////////////////////////////////////////// |
289 |
// Topology construction |
326 |
// Topology construction |
290 |
// |
327 |
// |
291 |
|
328 |
|
292 |
// Create three nodes |
329 |
// Create three nodes |
293 |
NodeContainer n0n1; |
330 |
NodeContainer n0n1; |
294 |
n0n1.Create (2); |
331 |
n0n1.Create (2); |
|
338 |
Simulator::ScheduleNow (&Ns3TcpStateTestCase::StartFlow, this, |
375 |
Simulator::ScheduleNow (&Ns3TcpStateTestCase::StartFlow, this, |
339 |
localSocket, ipInterfs.GetAddress (1), servPort); |
376 |
localSocket, ipInterfs.GetAddress (1), servPort); |
340 |
|
377 |
|
341 |
Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", |
|
|
342 |
MakeCallback (&Ns3TcpStateTestCase::Ipv4L3Tx, this)); |
343 |
|
344 |
//////////////////////////////////////////////////////// |
378 |
//////////////////////////////////////////////////////// |
345 |
// Set up different test cases: Lost model at node n1, different file size |
379 |
// Set up different test cases: Lost model at node n1, different file size |
346 |
// |
380 |
// |
|
411 |
errN1->SetList (dropListN1); |
445 |
errN1->SetList (dropListN1); |
412 |
dev1.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (errN1)); |
446 |
dev1.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (errN1)); |
413 |
|
447 |
|
|
|
448 |
Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", |
449 |
MakeCallback (&Ns3TcpStateTestCase::Ipv4L3Tx, this)); |
450 |
|
414 |
std::ostringstream oss; |
451 |
std::ostringstream oss; |
415 |
oss << "tcp-state" << m_testCase << "-test-case"; |
452 |
oss << "tcp-state" << m_testCase << "-test-case"; |
416 |
if (m_writeResults) |
453 |
if (m_writeResults) |
|
434 |
Simulator::Stop (Seconds (1000)); |
471 |
Simulator::Stop (Seconds (1000)); |
435 |
Simulator::Run (); |
472 |
Simulator::Run (); |
436 |
Simulator::Destroy (); |
473 |
Simulator::Destroy (); |
437 |
|
|
|
438 |
|
439 |
} |
474 |
} |
440 |
|
475 |
|
441 |
class Ns3TcpStateTestSuite : public TestSuite |
476 |
class Ns3TcpStateTestSuite : public TestSuite |
|
447 |
Ns3TcpStateTestSuite::Ns3TcpStateTestSuite () |
482 |
Ns3TcpStateTestSuite::Ns3TcpStateTestSuite () |
448 |
: TestSuite ("ns3-tcp-state", SYSTEM) |
483 |
: TestSuite ("ns3-tcp-state", SYSTEM) |
449 |
{ |
484 |
{ |
450 |
Packet::EnablePrinting (); // Enable packet metadata for all test cases |
|
|
451 |
AddTestCase (new Ns3TcpStateTestCase (0)); |
485 |
AddTestCase (new Ns3TcpStateTestCase (0)); |
452 |
AddTestCase (new Ns3TcpStateTestCase (1)); |
486 |
AddTestCase (new Ns3TcpStateTestCase (1)); |
453 |
AddTestCase (new Ns3TcpStateTestCase (2)); |
487 |
AddTestCase (new Ns3TcpStateTestCase (2)); |