SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CCRakNetSlidingWindow.h
Go to the documentation of this file.
1 /*
2 * Original work: Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
16 /*
17 http://www.ssfnet.org/Exchange/tcp/tcpTutorialNotes.html
18
19 cwnd=max bytes allowed on wire at once
20
21 Start:
22 cwnd=mtu
23 ssthresh=unlimited
24
25 Slow start:
26 On ack cwnd*=2
27
28 congestion avoidance:
29 On ack during new period
30 cwnd+=mtu*mtu/cwnd
31
32 on loss or duplicate ack during period:
33 sshtresh=cwnd/2
34 cwnd=MTU
35 This reenters slow start
36
37 If cwnd < ssthresh, then use slow start
38 else use congestion avoidance
39
40
41 */
42
43 #include "defines.h"
44
45 #if USE_SLIDING_WINDOW_CONGESTION_CONTROL==1
46
47 #ifndef __CONGESTION_CONTROL_SLIDING_WINDOW_H
48 #define __CONGESTION_CONTROL_SLIDING_WINDOW_H
49
50 #include "NativeTypes.h"
51 #include "time.h"
52 #include "types.h"
53 #include "DS_Queue.h"
54
56 #define UDP_HEADER_SIZE 28
57
58 #define CC_DEBUG_PRINTF_1(x)
59 #define CC_DEBUG_PRINTF_2(x,y)
60 #define CC_DEBUG_PRINTF_3(x,y,z)
61 #define CC_DEBUG_PRINTF_4(x,y,z,a)
62 #define CC_DEBUG_PRINTF_5(x,y,z,a,b)
63 //#define CC_DEBUG_PRINTF_1(x) printf(x)
64 //#define CC_DEBUG_PRINTF_2(x,y) printf(x,y)
65 //#define CC_DEBUG_PRINTF_3(x,y,z) printf(x,y,z)
66 //#define CC_DEBUG_PRINTF_4(x,y,z,a) printf(x,y,z,a)
67 //#define CC_DEBUG_PRINTF_5(x,y,z,a,b) printf(x,y,z,a,b)
68
70 #define CC_TIME_TYPE_BYTES 8
71
72 #if CC_TIME_TYPE_BYTES==8
73 typedef SLNet::TimeUS CCTimeType;
74 #else
75 typedef SLNet::TimeMS CCTimeType;
76 #endif
77
78 typedef SLNet::uint24_t DatagramSequenceNumberType;
79 typedef double BytesPerMicrosecond;
80 typedef double BytesPerSecond;
81 typedef double MicrosecondsPerByte;
82
83 namespace SLNet
84 {
85
86 class CCRakNetSlidingWindow
87 {
88 public:
89
90 CCRakNetSlidingWindow();
91 ~CCRakNetSlidingWindow();
92
94 void Init(CCTimeType curTime, uint32_t maxDatagramPayload);
95
97 void Update(CCTimeType curTime, bool hasDataToSendOrResend);
98
99 int GetRetransmissionBandwidth(CCTimeType curTime, CCTimeType timeSinceLastTick, uint32_t unacknowledgedBytes, bool isContinuousSend);
100 int GetTransmissionBandwidth(CCTimeType curTime, CCTimeType timeSinceLastTick, uint32_t unacknowledgedBytes, bool isContinuousSend);
101
106 bool ShouldSendACKs(CCTimeType curTime, CCTimeType estimatedTimeToNextTick);
107
110 DatagramSequenceNumberType GetAndIncrementNextDatagramSequenceNumber(void);
111 DatagramSequenceNumberType GetNextDatagramSequenceNumber(void);
112
118 void OnSendBytes(CCTimeType curTime, uint32_t numBytes);
119
121 void OnGotPacketPair(DatagramSequenceNumberType datagramSequenceNumber, uint32_t sizeInBytes, CCTimeType curTime);
122
126 bool OnGotPacket(DatagramSequenceNumberType datagramSequenceNumber, bool isContinuousSend, CCTimeType curTime, uint32_t sizeInBytes, uint32_t *skippedMessageCount);
127
130 void OnResend(CCTimeType curTime, SLNet::TimeUS nextActionTime);
131 void OnNAK(CCTimeType curTime, DatagramSequenceNumberType nakSequenceNumber);
132
137 void OnAck(CCTimeType curTime, CCTimeType rtt, bool hasBAndAS, BytesPerMicrosecond _B, BytesPerMicrosecond _AS, double totalUserDataBytesAcked, bool isContinuousSend, DatagramSequenceNumberType sequenceNumber );
138 void OnDuplicateAck( CCTimeType curTime, DatagramSequenceNumberType sequenceNumber );
139
142 void OnSendAckGetBAndAS(CCTimeType curTime, bool *hasBAndAS, BytesPerMicrosecond *_B, BytesPerMicrosecond *_AS);
143
148 void OnSendAck(CCTimeType curTime, uint32_t numBytes);
149
152 void OnSendNACK(CCTimeType curTime, uint32_t numBytes);
153
160 CCTimeType GetRTOForRetransmission(unsigned char timesSent) const;
161
164 void SetMTU(uint32_t bytes);
165
167 uint32_t GetMTU(void) const;
168
170 BytesPerMicrosecond GetLocalSendRate(void) const {return 0;}
171 BytesPerMicrosecond GetLocalReceiveRate(CCTimeType currentTime) const;
172 BytesPerMicrosecond GetRemoveReceiveRate(void) const {return 0;}
173 //BytesPerMicrosecond GetEstimatedBandwidth(void) const {return B;}
174 BytesPerMicrosecond GetEstimatedBandwidth(void) const {return GetLinkCapacityBytesPerSecond()*1000000.0;}
175 double GetLinkCapacityBytesPerSecond(void) const {return 0;}
176
178 double GetRTT(void) const;
179
180 bool GetIsInSlowStart(void) const {return IsInSlowStart();}
181 uint32_t GetCWNDLimit(void) const {return (uint32_t) 0;}
182
183
185 static bool GreaterThan(DatagramSequenceNumberType a, DatagramSequenceNumberType b);
187 static bool LessThan(DatagramSequenceNumberType a, DatagramSequenceNumberType b);
188 // void SetTimeBetweenSendsLimit(unsigned int bitsPerSecond);
189 uint64_t GetBytesPerSecondLimitByCongestionControl(void) const;
190
191 protected:
192
193 // Maximum amount of bytes that the user can send, e.g. the size of one full datagram
194 uint32_t MAXIMUM_MTU_INCLUDING_UDP_HEADER;
195
196 double cwnd; // max bytes on wire
197 double ssThresh; // Threshhold between slow start and congestion avoidance
198
201 CCTimeType oldestUnsentAck;
202
203 CCTimeType GetSenderRTOForACK(void) const;
204
206 DatagramSequenceNumberType nextDatagramSequenceNumber;
207 DatagramSequenceNumberType nextCongestionControlBlock;
208 bool backoffThisBlock, speedUpThisBlock;
211 DatagramSequenceNumberType expectedNextSequenceNumber;
212
213 bool _isContinuousSend;
214
215 bool IsInSlowStart(void) const;
216
217 double lastRtt, estimatedRTT, deviationRtt;
218
219 };
220
221 }
222
223 #endif
224
225 #endif