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) 2017 Christoph Doepmann <doepmanc@informatik.hu-berlin.de> | 3 * Copyright (c) 2017 Christoph Doepmann <doepmanc@informatik.hu-berlin.de> |
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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 static TypeId tid = TypeId ("ns3::TcpDropRatioErrorModel") | 244 static TypeId tid = TypeId ("ns3::TcpDropRatioErrorModel") |
245 .SetParent<TcpGeneralErrorModel> () | 245 .SetParent<TcpGeneralErrorModel> () |
246 ; | 246 ; |
247 return tid; | 247 return tid; |
248 } | 248 } |
249 | 249 |
250 bool | 250 bool |
251 TcpDropRatioErrorModel::ShouldDrop (const Ipv4Header &ipHeader, const TcpHeader
&tcpHeader, | 251 TcpDropRatioErrorModel::ShouldDrop (const Ipv4Header &ipHeader, const TcpHeader
&tcpHeader, |
252 uint32_t packetSize) | 252 uint32_t packetSize) |
253 { | 253 { |
254 NS_UNUSED(ipHeader); | 254 NS_UNUSED (ipHeader); |
255 NS_UNUSED(tcpHeader); | 255 NS_UNUSED (tcpHeader); |
256 NS_UNUSED(packetSize); | 256 NS_UNUSED (packetSize); |
257 return m_prng->GetValue () < m_dropRatio;· | 257 return m_prng->GetValue () < m_dropRatio;· |
258 } | 258 } |
259 | 259 |
260 /** | 260 /** |
261 * \ingroup internet-tests | 261 * \ingroup internet-tests |
262 * \ingroup test | 262 * \ingroup test |
263 * \brief Test the new formula for calculating TCP's advertised window size. | 263 * \brief Test the new formula for calculating TCP's advertised window size. |
264 * | 264 * |
265 * In TcpSocketBase, the advertised window is now calculated as | 265 * In TcpSocketBase, the advertised window is now calculated as |
266 * | 266 * |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 { | 346 { |
347 return CreateObject<TcpDropRatioErrorModel> (m_lossRatio); | 347 return CreateObject<TcpDropRatioErrorModel> (m_lossRatio); |
348 } | 348 } |
349 | 349 |
350 void | 350 void |
351 TcpAdvertisedWindowTest::InvalidAwndCb (uint16_t oldAwnd, uint16_t newAwnd) | 351 TcpAdvertisedWindowTest::InvalidAwndCb (uint16_t oldAwnd, uint16_t newAwnd) |
352 { | 352 { |
353 NS_TEST_ASSERT_MSG_EQ (oldAwnd, newAwnd, | 353 NS_TEST_ASSERT_MSG_EQ (oldAwnd, newAwnd, |
354 "Old and new AWND calculations do not match."); | 354 "Old and new AWND calculations do not match."); |
355 } | 355 } |
| 356 //----------------------------------------------------------------------------- |
| 357 |
| 358 class TcpAdvWindowOnLossTest : public TcpGeneralTest |
| 359 { |
| 360 public: |
| 361 /** |
| 362 * \brief Constructor |
| 363 * \param desc description |
| 364 * \param size segment size |
| 365 * \param packets number of packets to send |
| 366 * \param lossRatio error ratio |
| 367 */ |
| 368 TcpAdvWindowOnLossTest (const std::string &desc, uint32_t size, uint32_t packe
ts, |
| 369 std::vector<uint32_t> &toDrop); |
| 370 |
| 371 protected: |
| 372 virtual void ConfigureEnvironment (); |
| 373 virtual Ptr<TcpSocketMsgBase> CreateReceiverSocket (Ptr<Node> node); |
| 374 virtual Ptr<TcpSocketMsgBase> CreateSenderSocket (Ptr<Node> node); |
| 375 virtual Ptr<ErrorModel> CreateReceiverErrorModel (); |
| 376 |
| 377 private: |
| 378 /** \brief Callback called for the update of the awnd |
| 379 * \param oldAwnd Old advertised window |
| 380 * \param newAwnd new value |
| 381 */ |
| 382 void InvalidAwndCb (uint16_t oldAwnd, uint16_t newAwnd); |
| 383 uint32_t m_pktSize; //!< Packet size |
| 384 uint32_t m_pktCount; //!< Pkt count |
| 385 std::vector<uint32_t> m_toDrop; //!< Sequences to drop |
| 386 }; |
| 387 |
| 388 TcpAdvWindowOnLossTest::TcpAdvWindowOnLossTest (const std::string &desc, |
| 389 uint32_t size, uint32_t packets, |
| 390 std::vector<uint32_t> &toDrop) |
| 391 : TcpGeneralTest (desc), |
| 392 m_pktSize (size), |
| 393 m_pktCount (packets), |
| 394 m_toDrop (toDrop) |
| 395 { |
| 396 } |
| 397 |
| 398 void |
| 399 TcpAdvWindowOnLossTest::ConfigureEnvironment () |
| 400 { |
| 401 TcpGeneralTest::ConfigureEnvironment (); |
| 402 SetAppPktCount (m_pktCount); |
| 403 SetPropagationDelay (MilliSeconds (50)); |
| 404 SetTransmitStart (Seconds (2.0)); |
| 405 SetAppPktSize (m_pktSize); |
| 406 } |
| 407 |
| 408 Ptr<TcpSocketMsgBase> |
| 409 TcpAdvWindowOnLossTest::CreateReceiverSocket (Ptr<Node> node) |
| 410 { |
| 411 NS_LOG_FUNCTION (this); |
| 412 |
| 413 Ptr<TcpSocketMsgBase> sock = CreateSocket (node, TcpSocketAdvertisedWindowProx
y::GetTypeId (), m_congControlTypeId); |
| 414 DynamicCast<TcpSocketAdvertisedWindowProxy> (sock)->SetExpectedSegmentSize (50
0); |
| 415 DynamicCast<TcpSocketAdvertisedWindowProxy> (sock)->SetInvalidAwndCb ( |
| 416 MakeCallback (&TcpAdvWindowOnLossTest::InvalidAwndCb, this)); |
| 417 |
| 418 return sock; |
| 419 } |
| 420 |
| 421 Ptr<TcpSocketMsgBase> |
| 422 TcpAdvWindowOnLossTest::CreateSenderSocket (Ptr<Node> node) |
| 423 { |
| 424 auto socket = TcpGeneralTest::CreateSenderSocket (node); |
| 425 socket->SetAttribute("InitialCwnd", UintegerValue (10*m_pktSize)); |
| 426 |
| 427 return socket; |
| 428 } |
| 429 |
| 430 Ptr<ErrorModel> |
| 431 TcpAdvWindowOnLossTest::CreateReceiverErrorModel () |
| 432 { |
| 433 Ptr<TcpSeqErrorModel> m_errorModel = CreateObject<TcpSeqErrorModel> (); |
| 434 for (std::vector<uint32_t>::iterator it = m_toDrop.begin (); it != m_toDrop.en
d (); ++it) |
| 435 { |
| 436 m_errorModel->AddSeqToKill (SequenceNumber32 (*it)); |
| 437 } |
| 438 |
| 439 return m_errorModel; |
| 440 } |
| 441 |
| 442 void |
| 443 TcpAdvWindowOnLossTest::InvalidAwndCb (uint16_t oldAwnd, uint16_t newAwnd) |
| 444 { |
| 445 NS_TEST_ASSERT_MSG_EQ (oldAwnd, newAwnd, |
| 446 "Old and new AWND calculations do not match."); |
| 447 } |
356 | 448 |
357 //----------------------------------------------------------------------------- | 449 //----------------------------------------------------------------------------- |
358 | 450 |
359 /** | 451 /** |
360 * \ingroup internet-tests | 452 * \ingroup internet-tests |
361 * \ingroup test | 453 * \ingroup test |
362 * | 454 * |
363 * \brief Test Suite for TCP adv window | 455 * \brief Test Suite for TCP adv window |
364 */ | 456 */ |
365 class TcpAdvertisedWindowTestSuite : public TestSuite | 457 class TcpAdvertisedWindowTestSuite : public TestSuite |
366 { | 458 { |
367 public: | 459 public: |
368 TcpAdvertisedWindowTestSuite () : TestSuite ("tcp-advertised-window-test", UNI
T) | 460 TcpAdvertisedWindowTestSuite () : TestSuite ("tcp-advertised-window-test", UNI
T) |
369 { | 461 { |
370 AddTestCase (new TcpAdvertisedWindowTest ("TCP advertised window size, small
seg + no loss", 500, 100, 0.0), | 462 AddTestCase (new TcpAdvertisedWindowTest ("TCP advertised window size, small
seg + no loss", 500, 100, 0.0), |
371 TestCase::QUICK); | 463 TestCase::QUICK); |
372 AddTestCase (new TcpAdvertisedWindowTest ("TCP advertised window size, small
seg + loss", 500, 100, 0.1), | 464 AddTestCase (new TcpAdvertisedWindowTest ("TCP advertised window size, small
seg + loss", 500, 100, 0.1), |
373 TestCase::QUICK); | 465 TestCase::QUICK); |
374 AddTestCase (new TcpAdvertisedWindowTest ("TCP advertised window size, large
seg + no loss", 1000, 100, 0.0), | 466 AddTestCase (new TcpAdvertisedWindowTest ("TCP advertised window size, large
seg + no loss", 1000, 100, 0.0), |
375 TestCase::QUICK); | 467 TestCase::QUICK); |
376 AddTestCase (new TcpAdvertisedWindowTest ("TCP advertised window size, large
seg + small loss", 1000, 100, 0.1), | 468 AddTestCase (new TcpAdvertisedWindowTest ("TCP advertised window size, large
seg + small loss", 1000, 100, 0.1), |
377 TestCase::QUICK); | 469 TestCase::QUICK); |
378 AddTestCase (new TcpAdvertisedWindowTest ("TCP advertised window size, large
seg + big loss", 1000, 100, 0.3), | 470 AddTestCase (new TcpAdvertisedWindowTest ("TCP advertised window size, large
seg + big loss", 1000, 100, 0.3), |
379 TestCase::QUICK); | 471 TestCase::QUICK); |
380 AddTestCase (new TcpAdvertisedWindowTest ("TCP advertised window size, compl
ete loss", 1000, 100, 1.0), | 472 AddTestCase (new TcpAdvertisedWindowTest ("TCP advertised window size, compl
ete loss", 1000, 100, 1.0), |
381 TestCase::QUICK); | 473 TestCase::QUICK); |
| 474 |
| 475 std::vector<uint32_t> toDrop; |
| 476 toDrop.push_back(8001); |
| 477 toDrop.push_back(9001); |
| 478 AddTestCase (new TcpAdvWindowOnLossTest ("TCP advertised window size, after
FIN loss", 1000, 10, toDrop)); |
382 } | 479 } |
383 }; | 480 }; |
384 | 481 |
385 static TcpAdvertisedWindowTestSuite g_tcpAdvertisedWindowTestSuite; //<! static
obj for test initialization | 482 static TcpAdvertisedWindowTestSuite g_tcpAdvertisedWindowTestSuite; //<! static
obj for test initialization |
386 | 483 |
LEFT | RIGHT |