-
Notifications
You must be signed in to change notification settings - Fork 2
/
tcp-cubic.h
executable file
·210 lines (165 loc) · 5.81 KB
/
tcp-cubic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#ifndef TCP_CUBIC_H
#define TCP_CUBIC_H
/**
* Author: Brett Levasseur
*
* This header file contains defines, global variables and function definitions
* to use with TCP CUBIC. The format of this file was designed from other ns-3
* TCP implementation header files.
*/
/**
* The following defines come from the ns-2 implementation and Linux Kernel
* version 3.11 implementation for TCP CUBIC. The Linux implemenation was taken
* from the Web Site:
* http://lxr.free-electrons.com/source/net/ipv4/tcp_cubic.c?v=3.11
*/
#define BICTCP_BETA_SCALE 1024 /* Scale factor beta calculation
* max_cwnd = snd_cwnd * beta
*/
#define BICTCP_B 4 /*
* In binary search,
* go to point (max+min)/N
*/
#define BICTCP_HZ 10 /* BIC HZ 2^10 = 1024 */
#define HZ 1000
#define JIFFY_RATIO 1000
#define ACK_RATIO_SHIFT 4
#include "ns3/tcp-socket-base.h"
#include "ns3/packet.h"
namespace ns3 {
/**
* \ingroup socket
* \ingroup tcp
*
* This class implements TCP Cubic, which as of the time of this writing is one
* of the two major versions of TCP used (Cubic in Linux systems, Compound in
* Windows).
*/
class TcpCubic : public TcpSocketBase
{
public:
static TypeId GetTypeId (void);
/**
* Default constructor.
*/
TcpCubic (void);
/**
* Copy constructor.
*/
TcpCubic (const TcpCubic& sock);
/**
* Default deconstructor.
*/
virtual ~TcpCubic (void);
// From TcpSocketBase
virtual int Connect (const Address &address);
virtual int Listen (void);
protected:
virtual uint32_t Window (void); // Return the max possible number of unacked bytes
virtual Ptr<TcpSocketBase> Fork (void); // Call CopyObject<TcpNewReno> to clone me
virtual void NewAck (SequenceNumber32 const& seq); // Inc cwnd and call NewAck() of parent
virtual void DelAckTimeout (void); // Timeout for delayed ACK
virtual void DupAck (const TcpHeader& t, uint32_t count); // Halving cwnd and reset nextTxSequence
virtual void Retransmit (void); // Exit fast recovery upon retransmit timeout
private:
/**
* Return the index of the last set bit. In the original Linux implementation
* this method is provided in the Linux Kernel. This method is copied from the
* the ns-2 TCP package.
*/
uint32_t fls64(uint64_t a);
/**
* Return the index of the last set bit. The ns-2 implementation of the method
* fls64 uses this method with normal integers. This method is copied from the
* ns-2 TCP package.
*/
int fls(int x);
/**
* The CUBIC algorithm in Linux and ns-2 does not use the normal C++ pow
* function to take the cubed root. Instead they use their own method. While
* this method does not produce a perfect cubed root it is what CUBIC uses.
*/
uint32_t CubicRoot (uint64_t a);
/**
* Get the next size of the congestion window using the CUBIC update algorithm.
* Depending on the current situation this could be a TCP Friendly update or a
* standard CUBIC update for a concave or convex region.
*/
uint32_t CubicUpdate ();
/**
* Get the next size of the congestion window when CUBIC is in the TCP
* TCP Friendly region.
*/
uint32_t CubicTcpFriendliness (uint32_t cnt);
/**
* Setup CUBIC variables. Reset is called at initialization and for timeouts.
*/
void CubicReset ();
unsigned long tcp_time_stamp();
protected:
SequenceNumber32 m_recover; //< Previous highest Tx seqnum for fast recovery
uint32_t m_retxThresh; //< Fast Retransmit threshold
bool m_inFastRec; //< currently in fast recovery
bool m_limitedTx; //< perform limited transmit
// Cubic specific variables
/** Cubic scaling factor. */
uint64_t m_cubeFactor;
/** Constant multiplication decrease factor in Cubic algorithm. */
double m_beta;
/**
* While not part of the original CUBIC algorithm this is used in the real
* Linux implementation instead of the normal C CUBIC scaling factor.
*/
uint32_t m_cubeRttScale;
/**
* BIC Scale. This is not part of the CUBIC paper but it is in the Linux and
* ns-2 implementation.
*/
int m_bicScale;
/**
* This is not part of the CUBIC paper but it is in the Linux and ns-2
* implementation.
*/
uint32_t m_betaScale;
/**
* Limit on increment allowed during binary search. Used by the Linux and
* ns-2 implementation of CUBIC.
*/
int m_maxIncrement;
// Estimate the ratio of Packets/ACKs << 4
uint32_t m_delayedAck;
/**
* The time the last congestion window reduction occured. This is used to
* find the elapsed time 't' used in the Cubic algorithm.
*/
int64_t m_epochStart;
// Time when updated last.
uint32_t m_lastTime;
/** The congestion window size just before the last reduction. */
uint32_t m_windowMax;
/* cwnd before last lost event. */
uint32_t m_lastMax;
/** The previouse congestion window size for the last reduction. */
uint32_t m_lastCwnd;
/**
* Interval between two consecutive loss events in the steady-state.
*/
double m_k;
/** The shortest RTT observed. */
uint32_t m_dMin;
/** The starting size of the congestion window at the last window reduction. */
uint32_t m_originPoint;
/** The new cwnd suggested for TCP freiendliness. */
uint32_t m_tcpCwnd;
/** Flag for TCP Friendly region. */
bool m_tcpFriendly;
/**
* Count of ACKs. Due to the ns-3 implementation of using bytes instead of
* packets this has been implemented as the number of bytes ACKed.
*/
uint32_t m_ackCnt;
/** Track the number of segments acked since the last cwnd increment.. */
uint32_t m_cWndCnt;
};
} // namespace ns3
#endif /* TCP_CUBIC_H */