View | Details | Raw Unified | Return to bug 2876
Collapse All | Expand All

(-)i/src/internet/model/tcp-rx-buffer.h (+6 lines)
 Lines 175-180   public: Link Here 
175
   */
175
   */
176
  uint32_t GetSackListSize () const;
176
  uint32_t GetSackListSize () const;
177
177
178
  /**
179
   * \brief Says if a FIN bit has been received
180
   * \return true if we received a FIN bit
181
   */
182
  bool GotFin () const { return m_gotFin; }
183
178
private:
184
private:
179
  /**
185
  /**
180
   * \brief Update the sack list, with the block seq starting at the beginning
186
   * \brief Update the sack list, with the block seq starting at the beginning
(-)i/src/internet/model/tcp-socket-base.cc (-3 / +8 lines)
 Lines 2981-2995   uint16_t Link Here 
2981
TcpSocketBase::AdvertisedWindowSize (bool scale) const
2981
TcpSocketBase::AdvertisedWindowSize (bool scale) const
2982
{
2982
{
2983
  NS_LOG_FUNCTION (this << scale);
2983
  NS_LOG_FUNCTION (this << scale);
2984
  uint32_t w = (m_rxBuffer->MaxRxSequence () > m_rxBuffer->NextRxSequence ()) ?
2984
  uint32_t w;
2985
    m_rxBuffer->MaxRxSequence () - m_rxBuffer->NextRxSequence () : 0;
2986
2985
2987
  // We don't want to advertise 0 after a FIN is received. So, we just use
2986
  // We don't want to advertise 0 after a FIN is received. So, we just use
2988
  // the previous value of the advWnd.
2987
  // the previous value of the advWnd.
2989
  if (m_rxBuffer->Finished ())
2988
  if (m_rxBuffer->GotFin ())
2990
    {
2989
    {
2991
      w = m_advWnd;
2990
      w = m_advWnd;
2992
    }
2991
    }
2992
  else
2993
    {
2994
      uint32_t max = m_rxBuffer->MaxRxSequence ().GetValue ();
2995
      uint32_t next = m_rxBuffer->NextRxSequence ().GetValue ();
2996
      w = ( max > next ) ? max - next : 0;
2997
    }
2993
2998
2994
  // Ugly, but we are not modifying the state, that variable
2999
  // Ugly, but we are not modifying the state, that variable
2995
  // is used only for tracing purpose.
3000
  // is used only for tracing purpose.
(-)i/src/internet/test/tcp-advertised-window-test.cc (+97 lines)
 Lines 350-355   TcpAdvertisedWindowTest::InvalidAwndCb (uint16_t oldAwnd, uint16_t newAwnd) Link Here 
350
  NS_TEST_ASSERT_MSG_EQ (oldAwnd, newAwnd,
350
  NS_TEST_ASSERT_MSG_EQ (oldAwnd, newAwnd,
351
                         "Old and new AWND calculations do not match.");
351
                         "Old and new AWND calculations do not match.");
352
}
352
}
353
//-----------------------------------------------------------------------------
354
355
class TcpAdvWindowOnLossTest : public TcpGeneralTest
356
{
357
public:
358
  /**
359
   * \brief Constructor
360
   * \param desc description
361
   * \param size segment size
362
   * \param packets number of packets to send
363
   * \param lossRatio error ratio
364
   */
365
  TcpAdvWindowOnLossTest (const std::string &desc, uint32_t size, uint32_t packets,
366
                          std::vector<uint32_t> &toDrop);
367
368
protected:
369
  virtual void ConfigureEnvironment ();
370
  virtual Ptr<TcpSocketMsgBase> CreateReceiverSocket (Ptr<Node> node);
371
  virtual Ptr<TcpSocketMsgBase> CreateSenderSocket (Ptr<Node> node);
372
  virtual Ptr<ErrorModel> CreateReceiverErrorModel ();
373
374
private:
375
  /** \brief Callback called for the update of the awnd
376
   * \param oldAwnd Old advertised window
377
   * \param newAwnd new value
378
   */
379
  void InvalidAwndCb (uint16_t oldAwnd, uint16_t newAwnd);
380
  uint32_t m_pktSize; //!< Packet size
381
  uint32_t m_pktCount; //!< Pkt count
382
  std::vector<uint32_t> m_toDrop; //!< Sequences to drop
383
};
384
385
TcpAdvWindowOnLossTest::TcpAdvWindowOnLossTest (const std::string &desc,
386
                                                uint32_t size, uint32_t packets,
387
                                                std::vector<uint32_t> &toDrop)
388
  : TcpGeneralTest (desc),
389
    m_pktSize (size),
390
    m_pktCount (packets),
391
    m_toDrop (toDrop)
392
{
393
}
394
395
void
396
TcpAdvWindowOnLossTest::ConfigureEnvironment ()
397
{
398
  TcpGeneralTest::ConfigureEnvironment ();
399
  SetAppPktCount (m_pktCount);
400
  SetPropagationDelay (MilliSeconds (50));
401
  SetTransmitStart (Seconds (2.0));
402
  SetAppPktSize (m_pktSize);
403
}
404
405
Ptr<TcpSocketMsgBase>
406
TcpAdvWindowOnLossTest::CreateReceiverSocket (Ptr<Node> node)
407
{
408
  NS_LOG_FUNCTION (this);
409
410
  Ptr<TcpSocketMsgBase> sock = CreateSocket (node, TcpSocketAdvertisedWindowProxy::GetTypeId (), m_congControlTypeId);
411
  DynamicCast<TcpSocketAdvertisedWindowProxy> (sock)->SetExpectedSegmentSize (500);
412
  DynamicCast<TcpSocketAdvertisedWindowProxy> (sock)->SetInvalidAwndCb (
413
        MakeCallback (&TcpAdvWindowOnLossTest::InvalidAwndCb, this));
414
415
  return sock;
416
}
417
418
Ptr<TcpSocketMsgBase>
419
TcpAdvWindowOnLossTest::CreateSenderSocket (Ptr<Node> node)
420
{
421
  auto socket = TcpGeneralTest::CreateSenderSocket (node);
422
  socket->SetAttribute("InitialCwnd", UintegerValue (10*m_pktSize));
423
424
  return socket;
425
}
426
427
Ptr<ErrorModel>
428
TcpAdvWindowOnLossTest::CreateReceiverErrorModel ()
429
{
430
  Ptr<TcpSeqErrorModel> m_errorModel = CreateObject<TcpSeqErrorModel> ();
431
  for (std::vector<uint32_t>::iterator it = m_toDrop.begin (); it != m_toDrop.end (); ++it)
432
    {
433
      m_errorModel->AddSeqToKill (SequenceNumber32 (*it));
434
    }
435
436
  return m_errorModel;
437
}
438
439
void
440
TcpAdvWindowOnLossTest::InvalidAwndCb (uint16_t oldAwnd, uint16_t newAwnd)
441
{
442
  NS_TEST_ASSERT_MSG_EQ (oldAwnd, newAwnd,
443
                         "Old and new AWND calculations do not match.");
444
}
353
445
354
//-----------------------------------------------------------------------------
446
//-----------------------------------------------------------------------------
355
447
 Lines 376-381   public: Link Here 
376
                 TestCase::QUICK);
468
                 TestCase::QUICK);
377
    AddTestCase (new TcpAdvertisedWindowTest ("TCP advertised window size, complete loss", 1000, 100, 1.0),
469
    AddTestCase (new TcpAdvertisedWindowTest ("TCP advertised window size, complete loss", 1000, 100, 1.0),
378
                 TestCase::QUICK);
470
                 TestCase::QUICK);
471
472
    std::vector<uint32_t> toDrop;
473
    toDrop.push_back(8001);
474
    toDrop.push_back(9001);
475
    AddTestCase (new TcpAdvWindowOnLossTest ("TCP advertised window size, after FIN loss", 1000, 10, toDrop));
379
  }
476
  }
380
};
477
};
381
478

Return to bug 2876