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) 2014 Natale Patriciello <natale.patriciello@gmail.com> | 3 * Copyright (c) 2014 Natale Patriciello <natale.patriciello@gmail.com> |
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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 */ | 18 */ |
19 | 19 |
20 #ifndef TCPBIC_H | 20 #ifndef TCPBIC_H |
21 #define TCPBIC_H | 21 #define TCPBIC_H |
22 | 22 |
23 #include "ns3/tcp-socket-base.h" | 23 #include "ns3/tcp-socket-base.h" |
24 #include "ns3/timer.h" | 24 #include "ns3/timer.h" |
25 | 25 |
26 namespace ns3 { | 26 namespace ns3 { |
27 | 27 |
28 /** \brief BIC congestion control algorithm | 28 /** \brief BIC congestion control algorithm |
29 * | 29 * |
30 * BIC is optimized for high speed networks with high latency: | 30 * In TCP Bic the congestion control problem is viewed as a search |
31 * so-called "long fat networks". | 31 * problem. Taking as a starting point the current window value |
| 32 * and as a target point the last maximum window value |
| 33 * (i.e. the cWnd value just before the loss event) a binary search |
| 34 * technique can be used to update the cWnd value at the midpoint between |
| 35 * the two, directly or using an additive increase strategy if the distance from |
| 36 * the current window is too large. |
32 * | 37 * |
33 * BIC has a unique congestion window (cwnd) algorithm. This algorithm | 38 * This way, assuming a no-loss period, the congestion window logarithmically |
34 * tries to find the maximum where to keep the window at for a long period | 39 * approaches the maximum value of cWnd until the difference between it and cWnd |
35 * of time, by using a binary search algorithm. | 40 * falls below a preset threshold. After reaching such a value (or the maximum |
| 41 * window is unknown, i.e. the binary search does not start at all) the algorith
m |
| 42 * switches to probing the new maximum window with a 'slow start' strategy. |
| 43 * |
| 44 * If a loss occur in either these phases, the current window (before the loss) |
| 45 * can be treated as the new maximum, and the reduced (with a multiplicative |
| 46 * decrease factor Beta) window size can be used as the new minimum. |
| 47 * |
| 48 * To maintain the performance of TCP Bic as close as possible with the Linux |
| 49 * implementation, and at the same time maintain the friendliness with other TCP |
| 50 * flavors, the cWnd is increased only after a certain number of ACKs |
| 51 * are received, following RFC 6356. After the slow start phase, and after each |
| 52 * new ACK, a value is calculated by the method Update. This number |
| 53 * (m_cnt in the code) represents the ACK packets that should be received |
| 54 * before increasing the cWnd by one segment. After a trivial check on the |
| 55 * arrived ACKs (represented by m_cWndCnt in the code), the |
| 56 * cWnd can be increased and m_cWndCnt can be set to zero, or |
| 57 * otherwise m_cWndCnt can be increased by one and the |
| 58 * cWnd can be left untouched. |
| 59 * |
| 60 * The binary search on the cWnd size space is done by varying the returned |
| 61 * cnt, depending on the internal state of the class (e.g. the last maximum |
| 62 * and the current cWnd size). |
| 63 * |
| 64 * The reference paper for BIC can be found in: |
| 65 * http://an.kaist.ac.kr/courses/2006/cs540/reading/bic-tcp.pdf |
| 66 * |
| 67 * This model has a number of configurable parameters that are exposed as |
| 68 * attributes of the TcpBic TypeId. This model also exports trace sources, |
| 69 * for tracking the congestion window, slow start threshold, and the internat |
| 70 * state of the protocol. |
| 71 * |
| 72 * More information on this implementation: http://dl.acm.org/citation.cfm?id=27
56518 |
36 */ | 73 */ |
37 class TcpBic : public TcpSocketBase | 74 class TcpBic : public TcpSocketBase |
38 { | 75 { |
39 public: | 76 public: |
40 /** | 77 /** |
41 * \brief Get the type ID. | 78 * \brief Get the type ID. |
42 * \return the object TypeId | 79 * \return the object TypeId |
43 */ | 80 */ |
44 static TypeId GetTypeId (void); | 81 static TypeId GetTypeId (void); |
| 82 |
| 83 /** |
| 84 * \brief State of the congestion control machine: open or loss |
| 85 */ |
| 86 enum BicState |
| 87 { |
| 88 OPEN = 0x1, //!< Open state |
| 89 LOSS = 0x2 //!< Loss state |
| 90 }; |
45 | 91 |
46 /** | 92 /** |
47 * \brief Constructor | 93 * \brief Constructor |
48 */ | 94 */ |
49 TcpBic (); | 95 TcpBic (); |
50 | 96 |
51 // From TcpSocketBase | 97 // From TcpSocketBase |
52 virtual int Connect (const Address &address); | 98 virtual int Connect (const Address &address); |
53 virtual int Listen (void); | 99 virtual int Listen (void); |
54 | 100 |
55 protected: | 101 protected: |
56 virtual uint32_t Window (void); // Return the max possible number of unacked
bytes | 102 virtual uint32_t Window (void); // Return the max possible number of unacked
bytes |
57 virtual Ptr<TcpSocketBase> Fork (void); // Call CopyObject<TcpNewReno> to cl
one me | 103 virtual Ptr<TcpSocketBase> Fork (void); // Call CopyObject<TcpNewReno> to cl
one me |
58 virtual void NewAck (SequenceNumber32 const& seq); | 104 virtual void NewAck (SequenceNumber32 const& seq); |
59 virtual void DupAck (const TcpHeader& t, uint32_t count); // Halving cwnd a
nd reset nextTxSequence | 105 virtual void DupAck (const TcpHeader& t, uint32_t count); // Halving cwnd a
nd reset nextTxSequence |
60 virtual void Retransmit (void); // Exit fast recovery upon retransmit timeou
t | 106 virtual void Retransmit (void); // Exit fast recovery upon retransmit timeou
t |
61 | 107 |
62 // Implementing ns3::TcpSocket -- Attribute get/set | 108 // Implementing ns3::TcpSocket -- Attribute get/set |
63 virtual void SetInitialSSThresh (uint32_t threshold); | 109 virtual void SetInitialSSThresh (uint32_t threshold); |
64 virtual uint32_t GetInitialSSThresh (void) const; | 110 virtual uint32_t GetInitialSSThresh (void) const; |
65 virtual void SetInitialCwnd (uint32_t cwnd); | 111 virtual void SetInitialCwnd (uint32_t cwnd); |
66 virtual uint32_t GetInitialCwnd (void) const; | 112 virtual uint32_t GetInitialCwnd (void) const; |
| 113 virtual void ScaleSsThresh (uint8_t scaleFactor); |
67 | 114 |
68 protected: | 115 private: |
69 /** | |
70 * \brief State of the congestion control machine: open or loss | |
71 */ | |
72 enum BicState | |
73 { | |
74 OPEN = 0x1, //!< Open state | |
75 LOSS = 0x2, //!< Loss state | |
76 }; | |
77 | |
78 uint32_t m_initialCwnd; //!< Initial cWnd | 116 uint32_t m_initialCwnd; //!< Initial cWnd |
79 | 117 |
80 // User parameters | 118 // User parameters |
81 bool m_fastConvergence; //!< Enable or disable fast convergence algorithm | 119 bool m_fastConvergence; //!< Enable or disable fast convergence algorithm |
82 double m_beta; //!< Beta for cubic multiplicative increase | 120 double m_beta; //!< Beta for cubic multiplicative increase |
83 uint32_t m_maxIncr; //!< Maximum window increment | 121 uint32_t m_maxIncr; //!< Maximum window increment |
84 uint32_t m_lowWnd; //!< Lower bound on congestion window | 122 uint32_t m_lowWnd; //!< Lower bound on congestion window |
85 int m_smoothPart; //!< Number of RTT needed to reach Wmax from Wmax
-B | 123 int m_smoothPart; //!< Number of RTT needed to reach Wmax from Wmax
-B |
86 | 124 |
87 // Bic parameters | 125 // Bic parameters |
88 uint32_t m_cWndCnt; //!< cWnd integer-to-float counter | 126 uint32_t m_cWndCnt; //!< cWnd integer-to-float counter |
89 uint32_t m_lastMaxCwnd; //!< Last maximum cWnd | 127 uint32_t m_lastMaxCwnd; //!< Last maximum cWnd |
90 uint32_t m_lastCwnd; //!< Last cWnd | 128 uint32_t m_lastCwnd; //!< Last cWnd |
91 Time m_epochStart; //!< Beginning of an epoch | 129 Time m_epochStart; //!< Beginning of an epoch |
92 Time m_lastTime; | |
93 | 130 |
94 TracedValue<uint32_t> m_cWnd; //!< Congestion window | 131 TracedValue<uint32_t> m_cWnd; //!< Congestion window |
95 TracedValue<uint32_t> m_ssThresh; //!< Slow start threshold | 132 TracedValue<uint32_t> m_ssThresh; //!< Slow start threshold |
| 133 TracedValue<uint8_t> m_bicState; //!< Bic state |
96 | 134 |
97 uint8_t m_bicState; //!< Bic state | 135 uint8_t m_b; //!< Binary search coefficient |
| 136 uint32_t m_retxThresh; //!< Fast Retransmit threshold |
98 | 137 |
99 private: | 138 private: |
100 /** | 139 /** |
101 * \brief Reset BIC parameters | 140 * \brief Reset BIC parameters |
102 */ | 141 */ |
103 void Reset (void); | 142 void Reset (void); |
104 | 143 |
105 /** | 144 /** |
106 * \brief Initialize the algorithm | 145 * \brief Initialize the algorithm |
107 */ | 146 */ |
108 void Init (void); | 147 void Init (void); |
109 | 148 |
110 /** | 149 /** |
111 * \brief The congestion avoidance phase of Cubic | 150 * \brief The congestion avoidance algorithm of BIC is implemented here |
112 */ | 151 */ |
113 void CongAvoid (void); | 152 void CongAvoid (void); |
114 | 153 |
115 /** | 154 /** |
116 * \brief Bic window update after a new ack received | 155 * \brief Bic window update after a new ack received |
117 */ | 156 */ |
118 uint32_t Update(void); | 157 uint32_t Update (void); |
119 | 158 |
120 /** | 159 /** |
121 * \brief Cubic window update after a loss | 160 * \brief Window update after a loss |
122 */ | 161 */ |
123 void RecalcSsthresh (void); | 162 void RecalcSsthresh (void); |
124 }; | 163 }; |
125 | 164 |
126 } // namespace ns3 | 165 } // namespace ns3 |
127 #endif // TCPBIC_H | 166 #endif // TCPBIC_H |
LEFT | RIGHT |