LEFT | RIGHT |
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2011 Universita' di Firenze, Italy | 3 * Copyright (c) 2011 Universita' di Firenze, Italy |
4 *· | 4 *· |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 m_receivedPacketClient = packet->Copy(); | 252 m_receivedPacketClient = packet->Copy(); |
253 } | 253 } |
254 } | 254 } |
255 } | 255 } |
256 | 256 |
257 void | 257 void |
258 Ipv4FragmentationTest::HandleReadIcmpClient (Ipv4Address icmpSource, | 258 Ipv4FragmentationTest::HandleReadIcmpClient (Ipv4Address icmpSource, |
259 uint8_t icmpTtl, uint8_t icmpType, | 259 uint8_t icmpTtl, uint8_t icmpType, |
260 uint8_t icmpCode, uint32_t icmpInfo
) | 260 uint8_t icmpCode, uint32_t icmpInfo
) |
261 { | 261 { |
262 NS_UNUSED(icmpSource); | 262 NS_UNUSED (icmpSource); |
263 NS_UNUSED(icmpTtl); | 263 NS_UNUSED (icmpTtl); |
264 NS_UNUSED(icmpCode); | 264 NS_UNUSED (icmpCode); |
265 NS_UNUSED(icmpInfo); | 265 NS_UNUSED (icmpInfo); |
266 m_icmpType = icmpType; | 266 m_icmpType = icmpType; |
267 } | 267 } |
268 | 268 |
269 void | 269 void |
270 Ipv4FragmentationTest::SetFill (uint8_t *fill, uint32_t fillSize, uint32_t dataS
ize) | 270 Ipv4FragmentationTest::SetFill (uint8_t *fill, uint32_t fillSize, uint32_t dataS
ize) |
271 { | 271 { |
272 if (dataSize != m_dataSize) | 272 if (dataSize != m_dataSize) |
273 { | 273 { |
274 delete [] m_data; | 274 delete [] m_data; |
275 m_data = new uint8_t [dataSize]; | 275 m_data = new uint8_t [dataSize]; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 clientDev->SetReceiveErrorModel (clientDevErrorModel); | 371 clientDev->SetReceiveErrorModel (clientDevErrorModel); |
372 StartClient (clientNode); | 372 StartClient (clientNode); |
373 | 373 |
374 // some small packets, some rather big ones | 374 // some small packets, some rather big ones |
375 uint32_t packetSizes[5] = {1000, 2000, 5000, 10000, 65000}; | 375 uint32_t packetSizes[5] = {1000, 2000, 5000, 10000, 65000}; |
376 | 376 |
377 // using the alphabet | 377 // using the alphabet |
378 uint8_t fillData[78]; | 378 uint8_t fillData[78]; |
379 for ( uint32_t k=48; k<=125; k++ ) | 379 for ( uint32_t k=48; k<=125; k++ ) |
380 { | 380 { |
381 fillData[k-48] = static_cast<uint8_t>(k); | 381 fillData[k-48] = static_cast<uint8_t> (k); |
382 } | 382 } |
383 | 383 |
384 // First test: normal channel, no errors, no delays | 384 // First test: normal channel, no errors, no delays |
385 for( int i= 0; i<5; i++) | 385 for( int i= 0; i<5; i++) |
386 { | 386 { |
387 uint32_t packetSize = packetSizes[i]; | 387 uint32_t packetSize = packetSizes[i]; |
388 | 388 |
389 SetFill (fillData, 78, packetSize); | 389 SetFill (fillData, 78, packetSize); |
390 | 390 |
391 m_receivedPacketServer = Create<Packet> (); | 391 m_receivedPacketServer = Create<Packet> (); |
392 Simulator::ScheduleWithContext (m_socketClient->GetNode ()->GetId (), Seco
nds (0), | 392 Simulator::ScheduleWithContext (m_socketClient->GetNode ()->GetId (), Seco
nds (0), |
393 &Ipv4FragmentationTest::SendClient, this); | 393 &Ipv4FragmentationTest::SendClient, this); |
394 Simulator::Run (); | 394 Simulator::Run (); |
395 | 395 |
396 uint8_t recvBuffer[65000]; | 396 uint8_t recvBuffer[65000]; |
397 | 397 |
398 uint16_t recvSize = static_cast<uint16_t>(m_receivedPacketServer->GetSize
()); | 398 uint16_t recvSize = static_cast<uint16_t> (m_receivedPacketServer->GetSize
()); |
399 | 399 |
400 NS_TEST_EXPECT_MSG_EQ (recvSize, packetSizes[i], "Packet size not correct"
); | 400 NS_TEST_EXPECT_MSG_EQ (recvSize, packetSizes[i], "Packet size not correct"
); |
401 | 401 |
402 m_receivedPacketServer->CopyData(recvBuffer, 65000); | 402 m_receivedPacketServer->CopyData(recvBuffer, 65000); |
403 NS_TEST_EXPECT_MSG_EQ (memcmp(m_data, recvBuffer, m_receivedPacketServer->
GetSize ()), | 403 NS_TEST_EXPECT_MSG_EQ (memcmp(m_data, recvBuffer, m_receivedPacketServer->
GetSize ()), |
404 0, "Packet content differs"); | 404 0, "Packet content differs"); |
405 } | 405 } |
406 | 406 |
407 // Second test: normal channel, no errors, delays each 2 packets. | 407 // Second test: normal channel, no errors, delays each 2 packets. |
408 // Each other fragment will arrive out-of-order. | 408 // Each other fragment will arrive out-of-order. |
409 // The packets should be received correctly since reassembly will reorder the
fragments. | 409 // The packets should be received correctly since reassembly will reorder the
fragments. |
410 channel->SetJumpingMode(true); | 410 channel->SetJumpingMode(true); |
411 for( int i= 0; i<5; i++) | 411 for( int i= 0; i<5; i++) |
412 { | 412 { |
413 uint32_t packetSize = packetSizes[i]; | 413 uint32_t packetSize = packetSizes[i]; |
414 | 414 |
415 SetFill (fillData, 78, packetSize); | 415 SetFill (fillData, 78, packetSize); |
416 | 416 |
417 m_receivedPacketServer = Create<Packet> (); | 417 m_receivedPacketServer = Create<Packet> (); |
418 Simulator::ScheduleWithContext (m_socketClient->GetNode ()->GetId (), Seco
nds (0), | 418 Simulator::ScheduleWithContext (m_socketClient->GetNode ()->GetId (), Seco
nds (0), |
419 &Ipv4FragmentationTest::SendClient, this); | 419 &Ipv4FragmentationTest::SendClient, this); |
420 Simulator::Run (); | 420 Simulator::Run (); |
421 | 421 |
422 uint8_t recvBuffer[65000]; | 422 uint8_t recvBuffer[65000]; |
423 | 423 |
424 uint16_t recvSize = static_cast<uint16_t>(m_receivedPacketServer->GetSize
()); | 424 uint16_t recvSize = static_cast<uint16_t> (m_receivedPacketServer->GetSize
()); |
425 | 425 |
426 NS_TEST_EXPECT_MSG_EQ (recvSize, packetSizes[i], "Packet size not correct"
); | 426 NS_TEST_EXPECT_MSG_EQ (recvSize, packetSizes[i], "Packet size not correct"
); |
427 | 427 |
428 m_receivedPacketServer->CopyData(recvBuffer, 65000); | 428 m_receivedPacketServer->CopyData(recvBuffer, 65000); |
429 NS_TEST_EXPECT_MSG_EQ (memcmp(m_data, recvBuffer, m_receivedPacketServer->
GetSize ()), | 429 NS_TEST_EXPECT_MSG_EQ (memcmp(m_data, recvBuffer, m_receivedPacketServer->
GetSize ()), |
430 0, "Packet content differs"); | 430 0, "Packet content differs"); |
431 } | 431 } |
432 channel->SetJumpingMode(false); | 432 channel->SetJumpingMode(false); |
433 | 433 |
434 // Third test: normal channel, some errors, no delays. | 434 // Third test: normal channel, some errors, no delays. |
(...skipping 13 matching lines...) Expand all Loading... |
448 | 448 |
449 // reset the model, we want to receive the very first fragment. | 449 // reset the model, we want to receive the very first fragment. |
450 serverDevErrorModel->Reset(); | 450 serverDevErrorModel->Reset(); |
451 | 451 |
452 m_receivedPacketServer = Create<Packet> (); | 452 m_receivedPacketServer = Create<Packet> (); |
453 m_icmpType = 0; | 453 m_icmpType = 0; |
454 Simulator::ScheduleWithContext (m_socketClient->GetNode ()->GetId (), Seco
nds (0), | 454 Simulator::ScheduleWithContext (m_socketClient->GetNode ()->GetId (), Seco
nds (0), |
455 &Ipv4FragmentationTest::SendClient, this); | 455 &Ipv4FragmentationTest::SendClient, this); |
456 Simulator::Run (); | 456 Simulator::Run (); |
457 | 457 |
458 uint16_t recvSize = static_cast<uint16_t>(m_receivedPacketServer->GetSize
()); | 458 uint16_t recvSize = static_cast<uint16_t> (m_receivedPacketServer->GetSize
()); |
459 | 459 |
460 NS_TEST_EXPECT_MSG_EQ ((recvSize == 0), true, "Server got a packet, someth
ing wrong"); | 460 NS_TEST_EXPECT_MSG_EQ ((recvSize == 0), true, "Server got a packet, someth
ing wrong"); |
461 NS_TEST_EXPECT_MSG_EQ ((m_icmpType == 11), true, "Client did not receive I
CMP::TIME_EXCEEDED"); | 461 NS_TEST_EXPECT_MSG_EQ ((m_icmpType == 11), true, "Client did not receive I
CMP::TIME_EXCEEDED"); |
462 } | 462 } |
463 | 463 |
464 // Fourth test: normal channel, no errors, no delays. | 464 // Fourth test: normal channel, no errors, no delays. |
465 // We check tags | 465 // We check tags |
466 clientDevErrorModel->Disable (); | 466 clientDevErrorModel->Disable (); |
467 serverDevErrorModel->Disable (); | 467 serverDevErrorModel->Disable (); |
468 for (int i= 0; i<5; i++) | 468 for (int i= 0; i<5; i++) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 Ipv4FragmentationTestSuite (); | 528 Ipv4FragmentationTestSuite (); |
529 }; | 529 }; |
530 | 530 |
531 Ipv4FragmentationTestSuite::Ipv4FragmentationTestSuite () | 531 Ipv4FragmentationTestSuite::Ipv4FragmentationTestSuite () |
532 : TestSuite ("ipv4-fragmentation", UNIT) | 532 : TestSuite ("ipv4-fragmentation", UNIT) |
533 { | 533 { |
534 AddTestCase (new Ipv4FragmentationTest, TestCase::QUICK); | 534 AddTestCase (new Ipv4FragmentationTest, TestCase::QUICK); |
535 } | 535 } |
536 | 536 |
537 static Ipv4FragmentationTestSuite g_ipv4fragmentationTestSuite; //!< Static vari
able for test initialization | 537 static Ipv4FragmentationTestSuite g_ipv4fragmentationTestSuite; //!< Static vari
able for test initialization |
LEFT | RIGHT |