OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2017 NITK Surathkal |
| 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: Shravya K.S. <shravya.ks0@gmail.com> |
| 19 * |
| 20 */ |
| 21 |
| 22 #include "ns3/ipv4.h" |
| 23 #include "ns3/ipv6.h" |
| 24 #include "../model/ipv4-end-point.h" |
| 25 #include "../model/ipv6-end-point.h" |
| 26 #include "tcp-general-test.h" |
| 27 #include "ns3/node.h" |
| 28 #include "ns3/log.h" |
| 29 #include "tcp-error-model.h" |
| 30 #include "ns3/tcp-l4-protocol.h" |
| 31 #include "ns3/tcp-dctcp.h" |
| 32 #include "ns3/string.h" |
| 33 |
| 34 using namespace ns3; |
| 35 |
| 36 NS_LOG_COMPONENT_DEFINE ("TcpDctcpTestSuite"); |
| 37 |
| 38 /** |
| 39 * \ingroup internet-test |
| 40 * \ingroup tests |
| 41 * |
| 42 * \brief Validates the setting of ECT and ECE codepoints for DCTCP enabled traf
fic |
| 43 */ |
| 44 class TcpDctcpCodePointsTest : public TcpGeneralTest |
| 45 { |
| 46 public: |
| 47 /** |
| 48 * \brief Constructor |
| 49 * |
| 50 * \param testCase Test case number |
| 51 * \param desc Description about the test |
| 52 */ |
| 53 TcpDctcpCodePointsTest (uint8_t testCase, const std::string &desc); |
| 54 |
| 55 protected: |
| 56 virtual void Tx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who); |
| 57 virtual void Rx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who); |
| 58 virtual Ptr<TcpSocketMsgBase> CreateSenderSocket (Ptr<Node> node); |
| 59 virtual Ptr<TcpSocketMsgBase> CreateReceiverSocket (Ptr<Node> node); |
| 60 void ConfigureProperties (); |
| 61 |
| 62 private: |
| 63 uint32_t m_senderSent; |
| 64 uint32_t m_receiverSent; |
| 65 uint32_t m_senderReceived; |
| 66 uint8_t m_testCase; |
| 67 }; |
| 68 |
| 69 TcpDctcpCodePointsTest::TcpDctcpCodePointsTest (uint8_t testCase, const std::str
ing &desc) |
| 70 : TcpGeneralTest (desc), |
| 71 m_senderSent (0), |
| 72 m_receiverSent (0), |
| 73 m_senderReceived (0), |
| 74 m_testCase (testCase) |
| 75 { |
| 76 } |
| 77 |
| 78 void |
| 79 TcpDctcpCodePointsTest::Tx (const Ptr<const Packet> p, const TcpHeader &h, Socke
tWho who) |
| 80 { |
| 81 if (who == SENDER && (m_testCase == 1 || m_testCase == 2)) |
| 82 { |
| 83 m_senderSent++; |
| 84 SocketIpTosTag ipTosTag; |
| 85 p->PeekPacketTag (ipTosTag); |
| 86 if (m_testCase == 1) |
| 87 { |
| 88 if (m_senderSent == 1) |
| 89 { |
| 90 NS_TEST_ASSERT_MSG_EQ ((ipTosTag.GetTos ()), 0x1, "IP TOS should h
ave ECT1 for SYN packet for DCTCP traffic"); |
| 91 } |
| 92 if (m_senderSent == 3) |
| 93 { |
| 94 NS_TEST_ASSERT_MSG_EQ ((ipTosTag.GetTos ()), 0x1, "IP TOS should h
ave ECT1 for data packets for DCTCP traffic"); |
| 95 } |
| 96 } |
| 97 else |
| 98 { |
| 99 if (m_senderSent == 1) |
| 100 { |
| 101 NS_TEST_ASSERT_MSG_NE ((ipTosTag.GetTos ()), 0x1, "IP TOS should n
ot have ECT1 for SYN packet for DCTCP traffic"); |
| 102 } |
| 103 if (m_senderSent == 3) |
| 104 { |
| 105 NS_TEST_ASSERT_MSG_EQ ((ipTosTag.GetTos ()), 0x2, "IP TOS should h
ave ECT0 for data packets for non-DCTCP but ECN enabled traffic"); |
| 106 } |
| 107 } |
| 108 } |
| 109 else if (who == RECEIVER && (m_testCase == 1 || m_testCase == 2)) |
| 110 { |
| 111 m_receiverSent++; |
| 112 SocketIpTosTag ipTosTag; |
| 113 p->PeekPacketTag (ipTosTag); |
| 114 if (m_testCase == 1) |
| 115 { |
| 116 if (m_receiverSent == 1) |
| 117 { |
| 118 NS_TEST_ASSERT_MSG_EQ ((ipTosTag.GetTos ()), 0x1, "IP TOS should h
ave ECT1 for SYN+ACK packet for DCTCP traffic"); |
| 119 } |
| 120 if (m_receiverSent == 2) |
| 121 { |
| 122 NS_TEST_ASSERT_MSG_EQ ((ipTosTag.GetTos ()), 0x1, "IP TOS should h
ave ECT1 for pure ACK packets for DCTCP traffic"); |
| 123 } |
| 124 } |
| 125 else |
| 126 { |
| 127 if (m_receiverSent == 1) |
| 128 { |
| 129 NS_TEST_ASSERT_MSG_NE ((ipTosTag.GetTos ()), 0x2, "IP TOS should n
ot have ECT0 for SYN+ACK packet for non-DCTCP traffic"); |
| 130 } |
| 131 if (m_receiverSent == 2) |
| 132 { |
| 133 NS_TEST_ASSERT_MSG_NE ((ipTosTag.GetTos ()), 0x2, "IP TOS should n
ot have ECT0 for pure ACK packets for non-DCTCP traffic"); |
| 134 } |
| 135 } |
| 136 } |
| 137 } |
| 138 |
| 139 void |
| 140 TcpDctcpCodePointsTest::Rx (const Ptr<const Packet> p, const TcpHeader &h, Socke
tWho who) |
| 141 { |
| 142 if (who == SENDER && m_testCase == 3) |
| 143 { |
| 144 m_senderReceived++; |
| 145 if (m_senderReceived == 2 && m_testCase == 3) |
| 146 { |
| 147 NS_TEST_ASSERT_MSG_NE (((h.GetFlags ()) & TcpHeader::ECE), 0, "The fla
g ECE should be set in TCP header of the packet sent by the receiver when it rec
eives a packet with CE bit set in IP header"); |
| 148 } |
| 149 if (m_senderReceived > 2 && m_testCase == 3) |
| 150 { |
| 151 NS_TEST_ASSERT_MSG_EQ (((h.GetFlags ()) & TcpHeader::ECE), 0, "The fla
g ECE should be not be set in TCP header of the packet sent by the receiver if i
t receives a packet without CE bit set in IP header inspite of Sender not sendin
g CWR flags to it"); |
| 152 } |
| 153 } |
| 154 } |
| 155 |
| 156 void |
| 157 TcpDctcpCodePointsTest::ConfigureProperties () |
| 158 { |
| 159 TcpGeneralTest::ConfigureProperties (); |
| 160 SetEcn (SENDER); |
| 161 SetEcn (RECEIVER); |
| 162 } |
| 163 |
| 164 /** |
| 165 * \ingroup internet-test |
| 166 * \ingroup tests |
| 167 * |
| 168 * \brief A TCP socket which sends a data packet with CE flags set for test 3. |
| 169 * |
| 170 * The SendDataPacket function of this class sends data packet numbered 1 with
CE flags set and also doesn't set |
| 171 * CWR flags on receipt of ECE flags for test 3. This is done to verify that DCT
CP receiver sends ECE only if it |
| 172 * receives CE inspite of sender not sending CWR flags for ECE |
| 173 * |
| 174 */ |
| 175 class TcpDctcpCongestedRouter : public TcpSocketMsgBase |
| 176 { |
| 177 public: |
| 178 /** |
| 179 * \brief Get the type ID. |
| 180 * \return the object TypeId |
| 181 */ |
| 182 static TypeId GetTypeId (void); |
| 183 |
| 184 uint32_t m_dataPacketSent; |
| 185 uint8_t m_testCase; |
| 186 |
| 187 TcpDctcpCongestedRouter () |
| 188 : TcpSocketMsgBase () |
| 189 { |
| 190 m_dataPacketSent = 0; |
| 191 } |
| 192 |
| 193 /** |
| 194 * \brief Constructor. |
| 195 * \param other The object to copy from. |
| 196 */ |
| 197 TcpDctcpCongestedRouter (const TcpDctcpCongestedRouter &other) |
| 198 : TcpSocketMsgBase (other) |
| 199 { |
| 200 } |
| 201 |
| 202 void SetTestCase (uint8_t testCase); |
| 203 protected: |
| 204 virtual uint32_t SendDataPacket (SequenceNumber32 seq, uint32_t maxSize, bool
withAck); |
| 205 virtual void ReTxTimeout (); |
| 206 Ptr<TcpSocketBase> Fork (void); |
| 207 }; |
| 208 |
| 209 NS_OBJECT_ENSURE_REGISTERED (TcpDctcpCongestedRouter); |
| 210 |
| 211 TypeId |
| 212 TcpDctcpCongestedRouter::GetTypeId (void) |
| 213 { |
| 214 static TypeId tid = TypeId ("ns3::TcpDctcpCongestedRouter") |
| 215 .SetParent<TcpSocketMsgBase> () |
| 216 .SetGroupName ("Internet") |
| 217 .AddConstructor<TcpDctcpCongestedRouter> () |
| 218 ; |
| 219 return tid; |
| 220 } |
| 221 |
| 222 void |
| 223 TcpDctcpCongestedRouter::ReTxTimeout () |
| 224 { |
| 225 TcpSocketBase::ReTxTimeout (); |
| 226 } |
| 227 |
| 228 void |
| 229 TcpDctcpCongestedRouter::SetTestCase (uint8_t testCase) |
| 230 { |
| 231 m_testCase = testCase; |
| 232 } |
| 233 |
| 234 uint32_t |
| 235 TcpDctcpCongestedRouter::SendDataPacket (SequenceNumber32 seq, uint32_t maxSize,
bool withAck) |
| 236 { |
| 237 NS_LOG_FUNCTION (this << seq << maxSize << withAck); |
| 238 m_dataPacketSent++; |
| 239 |
| 240 bool isRetransmission = false; |
| 241 if (seq != m_tcb->m_highTxMark) |
| 242 { |
| 243 isRetransmission = true; |
| 244 } |
| 245 |
| 246 Ptr<Packet> p = m_txBuffer->CopyFromSequence (maxSize, seq); |
| 247 uint32_t sz = p->GetSize (); // Size of packet |
| 248 uint8_t flags = withAck ? TcpHeader::ACK : 0; |
| 249 uint32_t remainingData = m_txBuffer->SizeFromSequence (seq + SequenceNumber32
(sz)); |
| 250 |
| 251 if (withAck) |
| 252 { |
| 253 m_delAckEvent.Cancel (); |
| 254 m_delAckCount = 0; |
| 255 } |
| 256 |
| 257 // For test 3, we don't send CWR flags on receipt of ECE to check if Receiver
sends ECE only when there is CE flags |
| 258 if (m_tcb->m_ecnState == TcpSocketState::ECN_ECE_RCVD && m_ecnEchoSeq.Get () >
m_ecnCWRSeq.Get () && !isRetransmission && m_testCase != 3) |
| 259 { |
| 260 NS_LOG_INFO ("Backoff mechanism by reducing CWND by half because we've re
ceived ECN Echo"); |
| 261 m_congestionControl->ReduceCwnd (m_tcb); |
| 262 m_tcb->m_ssThresh = m_tcb->m_cWnd; |
| 263 flags |= TcpHeader::CWR; |
| 264 m_ecnCWRSeq = seq; |
| 265 m_tcb->m_ecnState = TcpSocketState::ECN_CWR_SENT; |
| 266 NS_LOG_DEBUG (TcpSocketState::EcnStateName[m_tcb->m_ecnState] << " -> ECN_
CWR_SENT"); |
| 267 NS_LOG_INFO ("CWR flags set"); |
| 268 NS_LOG_DEBUG (TcpSocketState::TcpCongStateName[m_tcb->m_congState] << " ->
CA_CWR"); |
| 269 if (m_tcb->m_congState == TcpSocketState::CA_OPEN) |
| 270 { |
| 271 m_congestionControl->CongestionStateSet (m_tcb, TcpSocketState::CA_CWR
); |
| 272 m_tcb->m_congState = TcpSocketState::CA_CWR; |
| 273 } |
| 274 } |
| 275 /* |
| 276 * Add tags for each socket option. |
| 277 * Note that currently the socket adds both IPv4 tag and IPv6 tag |
| 278 * if both options are set. Once the packet got to layer three, only |
| 279 * the corresponding tags will be read. |
| 280 */ |
| 281 if (GetIpTos ()) |
| 282 { |
| 283 SocketIpTosTag ipTosTag; |
| 284 |
| 285 NS_LOG_LOGIC (" ECT bits should not be set on retransmitted packets "); |
| 286 if (m_testCase == 3 && m_dataPacketSent == 1 && !isRetransmission) |
| 287 { |
| 288 ipTosTag.SetTos (GetIpTos () | 0x3); |
| 289 } |
| 290 else |
| 291 { |
| 292 if (m_tcb->m_ecnState != TcpSocketState::ECN_DISABLED && (GetIpTos ()
& 0x3) == 0 && !isRetransmission) |
| 293 { |
| 294 ipTosTag.SetTos (GetIpTos () | 0x1); |
| 295 } |
| 296 else |
| 297 { |
| 298 ipTosTag.SetTos (GetIpTos ()); |
| 299 } |
| 300 } |
| 301 p->AddPacketTag (ipTosTag); |
| 302 } |
| 303 else |
| 304 { |
| 305 SocketIpTosTag ipTosTag; |
| 306 if (m_testCase == 3 && m_dataPacketSent == 1 && !isRetransmission) |
| 307 { |
| 308 ipTosTag.SetTos (0x3); |
| 309 } |
| 310 else |
| 311 { |
| 312 if (m_tcb->m_ecnState != TcpSocketState::ECN_DISABLED && !isRetransmis
sion) |
| 313 { |
| 314 ipTosTag.SetTos (0x1); |
| 315 } |
| 316 } |
| 317 p->AddPacketTag (ipTosTag); |
| 318 } |
| 319 |
| 320 if (IsManualIpv6Tclass ()) |
| 321 { |
| 322 SocketIpv6TclassTag ipTclassTag; |
| 323 if (m_testCase == 3 && m_dataPacketSent == 1 && !isRetransmission ) |
| 324 { |
| 325 ipTclassTag.SetTclass (GetIpv6Tclass () | 0x3); |
| 326 } |
| 327 else |
| 328 { |
| 329 if (m_tcb->m_ecnState != TcpSocketState::ECN_DISABLED && (GetIpv6Tclas
s () & 0x3) == 0 && !isRetransmission) |
| 330 { |
| 331 ipTclassTag.SetTclass (GetIpv6Tclass () | 0x1); |
| 332 } |
| 333 else |
| 334 { |
| 335 ipTclassTag.SetTclass (GetIpv6Tclass ()); |
| 336 } |
| 337 } |
| 338 p->AddPacketTag (ipTclassTag); |
| 339 } |
| 340 else |
| 341 { |
| 342 SocketIpv6TclassTag ipTclassTag; |
| 343 if (m_testCase == 3 && m_dataPacketSent == 1 && !isRetransmission) |
| 344 { |
| 345 ipTclassTag.SetTclass (0x3); |
| 346 } |
| 347 else |
| 348 { |
| 349 if (m_tcb->m_ecnState != TcpSocketState::ECN_DISABLED && !isRetransmis
sion) |
| 350 { |
| 351 ipTclassTag.SetTclass (0x1); |
| 352 } |
| 353 } |
| 354 p->AddPacketTag (ipTclassTag); |
| 355 } |
| 356 |
| 357 if (IsManualIpTtl ()) |
| 358 { |
| 359 SocketIpTtlTag ipTtlTag; |
| 360 ipTtlTag.SetTtl (GetIpTtl ()); |
| 361 p->AddPacketTag (ipTtlTag); |
| 362 } |
| 363 |
| 364 if (IsManualIpv6HopLimit ()) |
| 365 { |
| 366 SocketIpv6HopLimitTag ipHopLimitTag; |
| 367 ipHopLimitTag.SetHopLimit (GetIpv6HopLimit ()); |
| 368 p->AddPacketTag (ipHopLimitTag); |
| 369 } |
| 370 |
| 371 uint8_t priority = GetPriority (); |
| 372 if (priority) |
| 373 { |
| 374 SocketPriorityTag priorityTag; |
| 375 priorityTag.SetPriority (priority); |
| 376 p->ReplacePacketTag (priorityTag); |
| 377 } |
| 378 |
| 379 if (m_closeOnEmpty && (remainingData == 0)) |
| 380 { |
| 381 flags |= TcpHeader::FIN; |
| 382 if (m_state == ESTABLISHED) |
| 383 { // On active close: I am the first one to send FIN |
| 384 NS_LOG_DEBUG ("ESTABLISHED -> FIN_WAIT_1"); |
| 385 m_state = FIN_WAIT_1; |
| 386 } |
| 387 else if (m_state == CLOSE_WAIT) |
| 388 { // On passive close: Peer sent me FIN already |
| 389 NS_LOG_DEBUG ("CLOSE_WAIT -> LAST_ACK"); |
| 390 m_state = LAST_ACK; |
| 391 } |
| 392 } |
| 393 TcpHeader header; |
| 394 header.SetFlags (flags); |
| 395 header.SetSequenceNumber (seq); |
| 396 header.SetAckNumber (m_rxBuffer->NextRxSequence ()); |
| 397 if (m_endPoint) |
| 398 { |
| 399 header.SetSourcePort (m_endPoint->GetLocalPort ()); |
| 400 header.SetDestinationPort (m_endPoint->GetPeerPort ()); |
| 401 } |
| 402 else |
| 403 { |
| 404 header.SetSourcePort (m_endPoint6->GetLocalPort ()); |
| 405 header.SetDestinationPort (m_endPoint6->GetPeerPort ()); |
| 406 } |
| 407 header.SetWindowSize (AdvertisedWindowSize ()); |
| 408 AddOptions (header); |
| 409 |
| 410 if (m_retxEvent.IsExpired ()) |
| 411 { |
| 412 // Schedules retransmit timeout. m_rto should be already doubled. |
| 413 |
| 414 NS_LOG_LOGIC (this << " SendDataPacket Schedule ReTxTimeout at time " << |
| 415 Simulator::Now ().GetSeconds () << " to expire at time " << |
| 416 (Simulator::Now () + m_rto.Get ()).GetSeconds () ); |
| 417 m_retxEvent = Simulator::Schedule (m_rto, &TcpDctcpCongestedRouter::ReTxTi
meout, this); |
| 418 } |
| 419 |
| 420 m_txTrace (p, header, this); |
| 421 |
| 422 if (m_endPoint) |
| 423 { |
| 424 m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (), |
| 425 m_endPoint->GetPeerAddress (), m_boundnetdevice); |
| 426 NS_LOG_DEBUG ("Send segment of size " << sz << " with remaining data " << |
| 427 remainingData << " via TcpL4Protocol to " << m_endPoint->Ge
tPeerAddress () << |
| 428 ". Header " << header); |
| 429 } |
| 430 else |
| 431 { |
| 432 m_tcp->SendPacket (p, header, m_endPoint6->GetLocalAddress (), |
| 433 m_endPoint6->GetPeerAddress (), m_boundnetdevice); |
| 434 NS_LOG_DEBUG ("Send segment of size " << sz << " with remaining data " << |
| 435 remainingData << " via TcpL4Protocol to " << m_endPoint6->G
etPeerAddress () << |
| 436 ". Header " << header); |
| 437 } |
| 438 |
| 439 UpdateRttHistory (seq, sz, isRetransmission); |
| 440 |
| 441 // Notify the application of the data being sent unless this is a retransmit |
| 442 if (seq + sz > m_tcb->m_highTxMark) |
| 443 { |
| 444 Simulator::ScheduleNow (&TcpDctcpCongestedRouter::NotifyDataSent, this, |
| 445 (seq + sz - m_tcb->m_highTxMark.Get ())); |
| 446 } |
| 447 // Update highTxMark |
| 448 m_tcb->m_highTxMark = std::max (seq + sz, m_tcb->m_highTxMark.Get ()); |
| 449 return sz; |
| 450 } |
| 451 |
| 452 Ptr<TcpSocketBase> |
| 453 TcpDctcpCongestedRouter::Fork (void) |
| 454 { |
| 455 return CopyObject<TcpDctcpCongestedRouter> (this); |
| 456 } |
| 457 |
| 458 Ptr<TcpSocketMsgBase> |
| 459 TcpDctcpCodePointsTest::CreateSenderSocket (Ptr<Node> node) |
| 460 { |
| 461 if (m_testCase == 2) |
| 462 { |
| 463 return TcpGeneralTest::CreateSenderSocket (node); |
| 464 } |
| 465 else if (m_testCase == 3) |
| 466 { |
| 467 Ptr<TcpDctcpCongestedRouter> socket = DynamicCast<TcpDctcpCongestedRouter>
( |
| 468 CreateSocket (node, |
| 469 TcpDctcpCongestedRouter::GetTypeId (), |
| 470 TcpDctcp::GetTypeId ())); |
| 471 socket->SetTestCase (m_testCase); |
| 472 return socket; |
| 473 } |
| 474 else |
| 475 { |
| 476 return TcpGeneralTest::CreateSocket (node, TcpSocketMsgBase::GetTypeId (),
TcpDctcp::GetTypeId ()); |
| 477 } |
| 478 } |
| 479 |
| 480 Ptr<TcpSocketMsgBase> |
| 481 TcpDctcpCodePointsTest::CreateReceiverSocket (Ptr<Node> node) |
| 482 { |
| 483 if (m_testCase == 2) |
| 484 { |
| 485 return TcpGeneralTest::CreateReceiverSocket (node); |
| 486 } |
| 487 else |
| 488 { |
| 489 return TcpGeneralTest::CreateSocket (node, TcpSocketMsgBase::GetTypeId (),
TcpDctcp::GetTypeId ()); |
| 490 } |
| 491 } |
| 492 |
| 493 /** |
| 494 * \ingroup internet-test |
| 495 * \ingroup tests |
| 496 * |
| 497 * \brief DCTCP should be same as NewReno during slow start |
| 498 */ |
| 499 class TcpDctcpToNewReno : public TestCase |
| 500 { |
| 501 public: |
| 502 /** |
| 503 * \brief Constructor |
| 504 * |
| 505 * \param cWnd congestion window |
| 506 * \param segmentSize segment size |
| 507 * \param ssThresh slow start threshold |
| 508 * \param segmentsAcked segments acked |
| 509 * \param highTxMark high tx mark |
| 510 * \param lastAckedSeq last acked seq |
| 511 * \param rtt RTT |
| 512 * \param name Name of the test |
| 513 */ |
| 514 TcpDctcpToNewReno (uint32_t cWnd, uint32_t segmentSize, uint32_t ssThresh, |
| 515 uint32_t segmentsAcked, SequenceNumber32 highTxMark, |
| 516 SequenceNumber32 lastAckedSeq, Time rtt, const std::string
&name); |
| 517 |
| 518 private: |
| 519 virtual void DoRun (void); |
| 520 /** \brief Execute the test |
| 521 */ |
| 522 void ExecuteTest (void); |
| 523 |
| 524 uint32_t m_cWnd; //!< cWnd |
| 525 uint32_t m_segmentSize; //!< segment size |
| 526 uint32_t m_segmentsAcked; //!< segments acked |
| 527 uint32_t m_ssThresh; //!< ss thresh |
| 528 Time m_rtt; //!< rtt |
| 529 SequenceNumber32 m_highTxMark; //!< high tx mark |
| 530 SequenceNumber32 m_lastAckedSeq; //!< last acked seq |
| 531 Ptr<TcpSocketState> m_state; //!< state |
| 532 }; |
| 533 |
| 534 TcpDctcpToNewReno::TcpDctcpToNewReno (uint32_t cWnd, uint32_t segmentSize, uint3
2_t ssThresh, |
| 535 uint32_t segmentsAcked, SequenceNumber32 h
ighTxMark, |
| 536 SequenceNumber32 lastAckedSeq, Time rtt, c
onst std::string &name) |
| 537 : TestCase (name), |
| 538 m_cWnd (cWnd), |
| 539 m_segmentSize (segmentSize), |
| 540 m_segmentsAcked (segmentsAcked), |
| 541 m_ssThresh (ssThresh), |
| 542 m_rtt (rtt), |
| 543 m_highTxMark (highTxMark), |
| 544 m_lastAckedSeq (lastAckedSeq) |
| 545 { |
| 546 } |
| 547 |
| 548 void |
| 549 TcpDctcpToNewReno::DoRun () |
| 550 { |
| 551 Simulator::Schedule (Seconds (0.0), &TcpDctcpToNewReno::ExecuteTest, this); |
| 552 Simulator::Run (); |
| 553 Simulator::Destroy (); |
| 554 } |
| 555 |
| 556 void |
| 557 TcpDctcpToNewReno::ExecuteTest () |
| 558 { |
| 559 m_state = CreateObject <TcpSocketState> (); |
| 560 m_state->m_cWnd = m_cWnd; |
| 561 m_state->m_ssThresh = m_ssThresh; |
| 562 m_state->m_segmentSize = m_segmentSize; |
| 563 m_state->m_highTxMark = m_highTxMark; |
| 564 m_state->m_lastAckedSeq = m_lastAckedSeq; |
| 565 |
| 566 Ptr<TcpSocketState> state = CreateObject <TcpSocketState> (); |
| 567 state->m_cWnd = m_cWnd; |
| 568 state->m_ssThresh = m_ssThresh; |
| 569 state->m_segmentSize = m_segmentSize; |
| 570 state->m_highTxMark = m_highTxMark; |
| 571 state->m_lastAckedSeq = m_lastAckedSeq; |
| 572 |
| 573 Ptr<TcpDctcp> cong = CreateObject <TcpDctcp> (); |
| 574 cong->IncreaseWindow (m_state, m_segmentsAcked); |
| 575 |
| 576 Ptr<TcpNewReno> NewRenoCong = CreateObject <TcpNewReno> (); |
| 577 NewRenoCong->IncreaseWindow (state, m_segmentsAcked); |
| 578 |
| 579 NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), state->m_cWnd.Get (), |
| 580 "cWnd has not updated correctly"); |
| 581 } |
| 582 /** |
| 583 * \ingroup internet-test |
| 584 * \ingroup tests |
| 585 * |
| 586 * \brief Test to validate cWnd decrement DCTCP |
| 587 */ |
| 588 class TcpDctcpDecrementTest : public TestCase |
| 589 { |
| 590 public: |
| 591 /** |
| 592 * \brief Constructor |
| 593 * |
| 594 * \param cWnd congestion window |
| 595 * \param segmentSize segment size |
| 596 * \param segmentsAcked segments acked |
| 597 * \param highTxMark high tx mark |
| 598 * \param lastAckedSeq last acked seq |
| 599 * \param rtt RTT |
| 600 * \param name Name of the test |
| 601 */ |
| 602 TcpDctcpDecrementTest (uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsA
cked, SequenceNumber32 nextTxSequence, |
| 603 SequenceNumber32 lastAckedSeq, Time rtt, const std::str
ing &name); |
| 604 |
| 605 private: |
| 606 virtual void DoRun (void); |
| 607 /** \brief Execute the test |
| 608 */ |
| 609 void ExecuteTest (void); |
| 610 |
| 611 uint32_t m_cWnd; //!< cWnd |
| 612 uint32_t m_segmentSize; //!< segment size |
| 613 uint32_t m_segmentsAcked; //!< segments acked |
| 614 Time m_rtt; //!< rtt |
| 615 SequenceNumber32 m_nextTxSequence; //!< next seq num to be sent |
| 616 SequenceNumber32 m_lastAckedSeq; //!< last acked seq |
| 617 Ptr<TcpSocketState> m_state; //!< state |
| 618 }; |
| 619 |
| 620 TcpDctcpDecrementTest::TcpDctcpDecrementTest (uint32_t cWnd, uint32_t segmentSiz
e, uint32_t segmentsAcked, SequenceNumber32 nextTxSequence, |
| 621 SequenceNumber32 lastAckedSeq, Tim
e rtt, const std::string &name) |
| 622 : TestCase (name), |
| 623 m_cWnd (cWnd), |
| 624 m_segmentSize (segmentSize), |
| 625 m_segmentsAcked (segmentsAcked), |
| 626 m_rtt (rtt), |
| 627 m_nextTxSequence (nextTxSequence), |
| 628 m_lastAckedSeq (lastAckedSeq) |
| 629 { |
| 630 } |
| 631 |
| 632 void |
| 633 TcpDctcpDecrementTest::DoRun () |
| 634 { |
| 635 Simulator::Schedule (Seconds (0.0), &TcpDctcpDecrementTest::ExecuteTest, this)
; |
| 636 Simulator::Run (); |
| 637 Simulator::Destroy (); |
| 638 } |
| 639 |
| 640 void |
| 641 TcpDctcpDecrementTest::ExecuteTest (void) |
| 642 { |
| 643 m_state = CreateObject <TcpSocketState> (); |
| 644 m_state->m_cWnd = m_cWnd; |
| 645 m_state->m_segmentSize = m_segmentSize; |
| 646 m_state->m_nextTxSequence = m_nextTxSequence; |
| 647 m_state->m_lastAckedSeq = m_lastAckedSeq; |
| 648 |
| 649 Ptr<TcpDctcp> cong = CreateObject <TcpDctcp> (); |
| 650 m_state->m_ecnState = TcpSocketState::ECN_IDLE; |
| 651 cong->PktsAcked (m_state, m_segmentsAcked, m_rtt); |
| 652 cong->ReduceCwnd (m_state); |
| 653 NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), m_cWnd, |
| 654 "cWnd has updated correctly"); |
| 655 |
| 656 m_state->m_ecnState = TcpSocketState::ECN_ECE_RCVD; |
| 657 cong->PktsAcked (m_state, m_segmentsAcked, m_rtt); |
| 658 cong->ReduceCwnd (m_state); |
| 659 |
| 660 uint32_t val = (uint32_t)(m_cWnd * (1 - 0.0625 / 2.0)); |
| 661 NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), val, |
| 662 "cWnd has updated correctly"); |
| 663 |
| 664 } |
| 665 |
| 666 /** |
| 667 * \ingroup internet-test |
| 668 * \ingroup tests |
| 669 * |
| 670 * \brief TCP DCTCP TestSuite |
| 671 */ |
| 672 class TcpDctcpTestSuite : public TestSuite |
| 673 { |
| 674 public: |
| 675 TcpDctcpTestSuite () : TestSuite ("tcp-dctcp-test", UNIT) |
| 676 { |
| 677 AddTestCase (new TcpDctcpCodePointsTest (1, "ECT Test : Check if ECT is set
on Syn, Syn+Ack, Ack and Data packets for DCTCP packets"), |
| 678 TestCase::QUICK); |
| 679 AddTestCase (new TcpDctcpCodePointsTest (2, "ECT Test : Check if ECT is not
set on Syn, Syn+Ack and Ack but set on Data packets for non-DCTCP but ECN enable
d traffic"),TestCase::QUICK); |
| 680 AddTestCase (new TcpDctcpCodePointsTest (3, "ECE Functionality Test: ECE sho
uld only be sent by reciever when it receives CE flags"), |
| 681 TestCase::QUICK); |
| 682 AddTestCase (new TcpDctcpToNewReno (2 * 1446, 1446, 4 * 1446, 2, SequenceNum
ber32 (4753), SequenceNumber32 (3216), MilliSeconds (100), "DCTCP falls to New R
eno for slowstart"), TestCase::QUICK); |
| 683 AddTestCase (new TcpDctcpDecrementTest (4 * 1446, 1446, 2, SequenceNumber32
(3216), SequenceNumber32 (4753), MilliSeconds (100), "DCTCP decrement test"), Te
stCase::QUICK); |
| 684 } |
| 685 }; |
| 686 |
| 687 static TcpDctcpTestSuite g_tcpdctcpTest; //!< static var for test initialization |
OLD | NEW |