Left: | ||
Right: |
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) 2007 Georgia Tech Research Corporation | 3 * Copyright (c) 2007 Georgia Tech Research Corporation |
4 * Copyright (c) 2010 Adrian Sai-wah Tam | 4 * Copyright (c) 2010 Adrian Sai-wah Tam |
5 * | 5 * |
6 * This program is free software; you can redistribute it and/or modify | 6 * This program is free software; you can redistribute it and/or modify |
7 * it under the terms of the GNU General Public License version 2 as | 7 * it under the terms of the GNU General Public License version 2 as |
8 * published by the Free Software Foundation; | 8 * published by the Free Software Foundation; |
9 * | 9 * |
10 * This program is distributed in the hope that it will be useful, | 10 * This program is distributed in the hope that it will be useful, |
(...skipping 28 matching lines...) Expand all Loading... | |
39 #include "ns3/packet.h" | 39 #include "ns3/packet.h" |
40 #include "ns3/uinteger.h" | 40 #include "ns3/uinteger.h" |
41 #include "ns3/double.h" | 41 #include "ns3/double.h" |
42 #include "ns3/trace-source-accessor.h" | 42 #include "ns3/trace-source-accessor.h" |
43 #include "tcp-socket-base.h" | 43 #include "tcp-socket-base.h" |
44 #include "tcp-l4-protocol.h" | 44 #include "tcp-l4-protocol.h" |
45 #include "ipv4-end-point.h" | 45 #include "ipv4-end-point.h" |
46 #include "ipv6-end-point.h" | 46 #include "ipv6-end-point.h" |
47 #include "ipv6-l3-protocol.h" | 47 #include "ipv6-l3-protocol.h" |
48 #include "tcp-header.h" | 48 #include "tcp-header.h" |
49 #include "tcp-option-snack.h" | |
50 #include "tcp-option-winscale.h" | 49 #include "tcp-option-winscale.h" |
51 #include "tcp-option-ts.h" | 50 #include "tcp-option-ts.h" |
Tommaso Pecorella
2014/08/17 10:38:13
I'd rather use all the options, and add attributes
n.p
2014/08/23 10:30:37
Use.. in what sense?
Tommaso Pecorella
2014/08/25 14:40:15
tcp-option-mss.h, nop, etc... missing headers incl
| |
52 #include "rtt-estimator.h" | 51 #include "rtt-estimator.h" |
53 | 52 |
54 #include <math.h> | 53 #include <math.h> |
55 #include <algorithm> | 54 #include <algorithm> |
56 | 55 |
57 NS_LOG_COMPONENT_DEFINE ("TcpSocketBase"); | 56 NS_LOG_COMPONENT_DEFINE ("TcpSocketBase"); |
58 | 57 |
59 namespace ns3 { | 58 namespace ns3 { |
60 | 59 |
61 NS_OBJECT_ENSURE_REGISTERED (TcpSocketBase); | 60 NS_OBJECT_ENSURE_REGISTERED (TcpSocketBase); |
(...skipping 18 matching lines...) Expand all Loading... | |
80 MakeUintegerAccessor (&TcpSocketBase::m_maxWinSize), | 79 MakeUintegerAccessor (&TcpSocketBase::m_maxWinSize), |
81 MakeUintegerChecker<uint16_t> ()) | 80 MakeUintegerChecker<uint16_t> ()) |
82 .AddAttribute ("IcmpCallback", "Callback invoked whenever an icmp error is r eceived on this socket.", | 81 .AddAttribute ("IcmpCallback", "Callback invoked whenever an icmp error is r eceived on this socket.", |
83 CallbackValue (), | 82 CallbackValue (), |
84 MakeCallbackAccessor (&TcpSocketBase::m_icmpCallback), | 83 MakeCallbackAccessor (&TcpSocketBase::m_icmpCallback), |
85 MakeCallbackChecker ()) | 84 MakeCallbackChecker ()) |
86 .AddAttribute ("IcmpCallback6", "Callback invoked whenever an icmpv6 error i s received on this socket.", | 85 .AddAttribute ("IcmpCallback6", "Callback invoked whenever an icmpv6 error i s received on this socket.", |
87 CallbackValue (), | 86 CallbackValue (), |
88 MakeCallbackAccessor (&TcpSocketBase::m_icmpCallback6), | 87 MakeCallbackAccessor (&TcpSocketBase::m_icmpCallback6), |
89 MakeCallbackChecker ()) | 88 MakeCallbackChecker ()) |
90 .AddAttribute ("SNACK", "Enable or disable SNACK option", | |
91 BooleanValue (false), | |
92 MakeBooleanAccessor (&TcpSocketBase::m_snackEnabled), | |
93 MakeBooleanChecker ()) | |
Tom Henderson
2014/08/26 16:52:30
is this supposed to be SACK?
| |
94 .AddAttribute ("WindowScaling", "Enable or disable Window Scaling option", | 89 .AddAttribute ("WindowScaling", "Enable or disable Window Scaling option", |
95 BooleanValue (true), | 90 BooleanValue (true), |
96 MakeBooleanAccessor (&TcpSocketBase::m_winScalingEnabled), | 91 MakeBooleanAccessor (&TcpSocketBase::m_winScalingEnabled), |
97 MakeBooleanChecker ()) | 92 MakeBooleanChecker ()) |
98 .AddAttribute ("Timestamp", "Enable or disable Timestamp option", | 93 .AddAttribute ("Timestamp", "Enable or disable Timestamp option", |
99 BooleanValue (true), | 94 BooleanValue (true), |
100 MakeBooleanAccessor (&TcpSocketBase::m_timestampEnabled), | 95 MakeBooleanAccessor (&TcpSocketBase::m_timestampEnabled), |
101 MakeBooleanChecker ()) | 96 MakeBooleanChecker ()) |
102 .AddTraceSource ("RTO", | 97 .AddTraceSource ("RTO", |
103 "Retransmission timeout", | 98 "Retransmission timeout", |
(...skipping 2027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2131 * | 2126 * |
2132 * \param tcpHeader TCP header for the incoming packet | 2127 * \param tcpHeader TCP header for the incoming packet |
2133 */ | 2128 */ |
2134 void | 2129 void |
2135 TcpSocketBase::EstimateRtt (const TcpHeader& tcpHeader) | 2130 TcpSocketBase::EstimateRtt (const TcpHeader& tcpHeader) |
2136 { | 2131 { |
2137 Time nextRtt; | 2132 Time nextRtt; |
2138 | 2133 |
2139 if (m_timestampEnabled) | 2134 if (m_timestampEnabled) |
2140 { | 2135 { |
2141 nextRtt = TcpOptionTS::EstimateRttFromTs (m_lastEchoedTime); | 2136 nextRtt = TcpOptionTS::ElapsedTimeFromTsValue (m_lastEchoedTime); |
2142 } | 2137 } |
2143 else | 2138 else |
2144 { | 2139 { |
2145 // Use m_rtt for the estimation. Note, RTT of duplicated acknowledgement | 2140 // Use m_rtt for the estimation. Note, RTT of duplicated acknowledgement |
2146 // (which should be ignored) is handled by m_rtt. | 2141 // (which should be ignored) is handled by m_rtt. |
2147 nextRtt = m_rtt->EstimateRttFromSeq (tcpHeader.GetAckNumber () ); | 2142 nextRtt = m_rtt->EstimateRttFromSeq (tcpHeader.GetAckNumber () ); |
2148 } | 2143 } |
2149 | 2144 |
2150 //nextRtt will be zero for dup acks. Don't want to update lastRtt in that cas e | 2145 //nextRtt will be zero for dup acks. Don't want to update lastRtt in that cas e |
2151 //but still needed to do list clearing that is done in EstimateRttFromSeq. | 2146 //but still needed to do list clearing that is done in EstimateRttFromSeq. |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2488 /** \brief Read and then parse options from TcpHeader | 2483 /** \brief Read and then parse options from TcpHeader |
2489 * | 2484 * |
2490 * This method sequentially check each kind of option, and if it | 2485 * This method sequentially check each kind of option, and if it |
2491 * is present in the header, starts its processing. | 2486 * is present in the header, starts its processing. |
2492 * | 2487 * |
2493 * To deal with hosts which don't have the option enabled (or | 2488 * To deal with hosts which don't have the option enabled (or |
2494 * implemented) we disable all option, and then re-enable them | 2489 * implemented) we disable all option, and then re-enable them |
2495 * if in the packet there is the option itself. | 2490 * if in the packet there is the option itself. |
2496 * | 2491 * |
2497 * \param header Tcp header from which read and parse options | 2492 * \param header Tcp header from which read and parse options |
2498 */ | 2493 */ |
Tom Henderson
2014/08/26 16:52:29
general comment: Doxygen should be moved from imp
| |
2499 void | 2494 void |
2500 TcpSocketBase::ReadOptions (const TcpHeader& header) | 2495 TcpSocketBase::ReadOptions (const TcpHeader& header) |
2501 { | 2496 { |
2502 NS_LOG_FUNCTION (this << header); | 2497 NS_LOG_FUNCTION (this << header); |
2503 | 2498 |
2504 if (header.HasOption (TcpOption::SNACK)) | |
2505 { | |
2506 ProcessOptionSnack (header.GetOption(TcpOption::SNACK)); | |
2507 } | |
2508 | |
2509 if ((header.GetFlags () & TcpHeader::SYN)) | 2499 if ((header.GetFlags () & TcpHeader::SYN)) |
2510 { | 2500 { |
2511 if (m_winScalingEnabled) | 2501 if (m_winScalingEnabled) |
2512 { | 2502 { |
2513 m_winScalingEnabled = false; | 2503 m_winScalingEnabled = false; |
2514 | 2504 |
2515 if (header.HasOption (TcpOption::WINSCALE)) | 2505 if (header.HasOption (TcpOption::WINSCALE)) |
2516 { | 2506 { |
2517 m_winScalingEnabled = true; | 2507 m_winScalingEnabled = true; |
2518 ProcessOptionWScale (header.GetOption (TcpOption::WINSCALE)); | 2508 ProcessOptionWScale (header.GetOption (TcpOption::WINSCALE)); |
Tom Henderson
2014/08/26 16:52:30
I might rewrite this as:
if (m_winScalingEnable
| |
2519 } | 2509 } |
2520 } | 2510 } |
2521 } | 2511 } |
2522 | 2512 |
2523 m_timestampEnabled = false; | 2513 m_timestampEnabled = false; |
2524 if (header.HasOption (TcpOption::TS)) | 2514 if (header.HasOption (TcpOption::TS)) |
2525 { | 2515 { |
2526 m_timestampEnabled = true; | 2516 m_timestampEnabled = true; |
2527 ProcessOptionTimestamp (header.GetOption (TcpOption::TS)); | 2517 ProcessOptionTimestamp (header.GetOption (TcpOption::TS)); |
2528 } | 2518 } |
2529 } | 2519 } |
2530 | 2520 |
2531 /** \brief Add options to TcpHeader | 2521 /** \brief Add options to TcpHeader |
2532 * | 2522 * |
2533 * Test each option, and if it is enabled on our side, add it | 2523 * Test each option, and if it is enabled on our side, add it |
2534 * to the header | 2524 * to the header |
Tommaso Pecorella
2014/08/17 10:38:13
The logic of this function should be triple checke
n.p
2014/08/23 10:30:37
Some option can be inserted only in SYN packet (li
Tommaso Pecorella
2014/08/25 14:40:15
That's my point. As I wrote in the (separate) mail
Tom Henderson
2014/08/26 16:52:30
Does there need to be any provision for extensibil
| |
2535 * | 2525 * |
2536 * \param header TcpHeader to add options to | 2526 * \param header TcpHeader to add options to |
2537 */ | 2527 */ |
2538 void | 2528 void |
2539 TcpSocketBase::AddOptions (TcpHeader& header) | 2529 TcpSocketBase::AddOptions (TcpHeader& header) |
2540 { | 2530 { |
2541 NS_LOG_FUNCTION (this << header); | 2531 NS_LOG_FUNCTION (this << header); |
2542 | 2532 |
2543 if (m_snackEnabled) | |
2544 { | |
2545 AddOptionSnack (header); | |
2546 } | |
2547 | |
2548 // The window scaling option is set only on SYN packets | 2533 // The window scaling option is set only on SYN packets |
2549 if (m_winScalingEnabled && (header.GetFlags () & TcpHeader::SYN)) | 2534 if (m_winScalingEnabled && (header.GetFlags () & TcpHeader::SYN)) |
2550 { | 2535 { |
2551 AddOptionWScale (header); | 2536 AddOptionWScale (header); |
2552 } | 2537 } |
2553 | 2538 |
2554 if (m_timestampEnabled) | 2539 if (m_timestampEnabled) |
2555 { | 2540 { |
2556 AddOptionTimestamp (header); | 2541 AddOptionTimestamp (header); |
2557 } | 2542 } |
2558 } | |
2559 | |
2560 void | |
2561 TcpSocketBase::ProcessOptionSnack (const Ptr<const TcpOption> option) | |
2562 { | |
2563 NS_LOG_FUNCTION (this << option); | |
2564 | |
2565 | |
2566 } | |
2567 | |
2568 void | |
2569 TcpSocketBase::AddOptionSnack (TcpHeader& header) | |
2570 { | |
2571 NS_LOG_FUNCTION (this << header); | |
2572 | |
2573 TcpOptionSnack option; | |
2574 | |
2575 (void) header; | |
2576 (void) option; | |
2577 } | 2543 } |
2578 | 2544 |
2579 /** | 2545 /** |
2580 * \brief Read and parse the Window scale option | 2546 * \brief Read and parse the Window scale option |
2581 * | 2547 * |
2582 * Read the window scale option (encoded logarithmically) and save it. | 2548 * Read the window scale option (encoded logarithmically) and save it. |
2583 * For RFC 1323, the value can't exceed 14. | 2549 * For RFC 1323, the value can't exceed 14. |
2584 * | 2550 * |
2585 * \param option Window scale option read from the header | 2551 * \param option Window scale option read from the header |
2586 */ | 2552 */ |
2587 void | 2553 void |
2588 TcpSocketBase::ProcessOptionWScale (const Ptr<const TcpOption> option) | 2554 TcpSocketBase::ProcessOptionWScale (const Ptr<const TcpOption> option) |
2589 { | 2555 { |
2590 NS_LOG_FUNCTION (this << option); | 2556 NS_LOG_FUNCTION (this << option); |
2591 | 2557 |
2592 Ptr<const TcpOptionWinScale> ts = DynamicCast<const TcpOptionWinScale> (option ); | 2558 Ptr<const TcpOptionWinScale> ts = DynamicCast<const TcpOptionWinScale> (option ); |
2593 | 2559 |
2594 // In naming, we do the contrary of RFC 1323. The received scaling factor | 2560 // In naming, we do the contrary of RFC 1323. The received scaling factor |
2595 // is Rcv.Wind.Scale (and not Snd.Wind.Scale) | 2561 // is Rcv.Wind.Scale (and not Snd.Wind.Scale) |
2596 m_rcvScaleFactor = ts->GetScale (); | 2562 m_rcvScaleFactor = ts->GetScale (); |
2597 | 2563 |
2598 if (m_rcvScaleFactor > 14) | 2564 if (m_rcvScaleFactor > 14) |
2599 { | 2565 { |
2600 m_rcvScaleFactor = 14; | 2566 m_rcvScaleFactor = 14; |
Tom Henderson
2014/08/26 16:52:29
isn't this a symptom of a protocol error? I would
| |
2601 } | 2567 } |
2602 | 2568 |
2603 m_sndScaleFactor = CalculateWScale (); | 2569 m_sndScaleFactor = CalculateWScale (); |
Tom Henderson
2014/08/26 16:52:29
why is this being performed on the receive-side pr
| |
2604 | 2570 |
2605 NS_LOG_INFO (m_node->GetId () << " Received a scale factor of " << | 2571 NS_LOG_INFO (m_node->GetId () << " Received a scale factor of " << |
2606 static_cast<int> (m_rcvScaleFactor)); | 2572 static_cast<int> (m_rcvScaleFactor)); |
2607 } | 2573 } |
2608 | 2574 |
2609 uint8_t | 2575 uint8_t |
2610 TcpSocketBase::CalculateWScale () const | 2576 TcpSocketBase::CalculateWScale () const |
2611 { | 2577 { |
2612 uint32_t maxSpace = m_rxBuffer.MaxBufferSize (); | 2578 uint32_t maxSpace = m_rxBuffer.MaxBufferSize (); |
2613 uint8_t scale = 0; | 2579 uint8_t scale = 0; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2693 | 2659 |
2694 option->SetTimestamp(TcpOptionTS::NowToTsValue ()); | 2660 option->SetTimestamp(TcpOptionTS::NowToTsValue ()); |
2695 option->SetEcho(m_timestampToEcho); | 2661 option->SetEcho(m_timestampToEcho); |
2696 | 2662 |
2697 header.AppendOption (option); | 2663 header.AppendOption (option); |
2698 NS_LOG_INFO (m_node->GetId () << " Add option TS, ts=" << | 2664 NS_LOG_INFO (m_node->GetId () << " Add option TS, ts=" << |
2699 option->GetTimestamp () << " echo=" << m_timestampToEcho); | 2665 option->GetTimestamp () << " echo=" << m_timestampToEcho); |
2700 } | 2666 } |
2701 | 2667 |
2702 } // namespace ns3 | 2668 } // namespace ns3 |
LEFT | RIGHT |