1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     rdt_ResendQueue.h
4 
5   Copyright (C)2009-2012 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 46347 $
14  *---------------------------------------------------------------------------*/
15 
16 #include "stdafx.h"
17 
18 #ifndef NN_LIBRARIES_RDT_CTR_RDT_RESEND_QUEUE_H_
19 #define NN_LIBRARIES_RDT_CTR_RDT_RESEND_QUEUE_H_
20 
21 #include "rdt_Deque.h"
22 
23 #include "rdt_Segment.h"
24 
25 #include "rdt_Utility.h"
26 
27 
28 namespace nn { namespace rdt { namespace CTR {
29 
30 /* Please see man pages for details
31 
32 
33 
34 
35 */
36 
37 class ResendQueue{
38 public:
39 /* Please see man pages for details
40 
41 */
42     ResendQueue(void);
43 
44 /* Please see man pages for details
45 
46 */
47    ~ResendQueue(void);
48 
49 /* Please see man pages for details
50 
51 
52 
53 
54 
55 */
56     bool Push(const Segment &seg);
57 
58 /* Please see man pages for details
59 
60 
61 */
62     bool Front(Segment *pSeg) const;
63 
64 /* Please see man pages for details
65 
66 
67 */
68     void Remove(u32 ack);
69 
70 /* Please see man pages for details
71 
72 */
SetDefaultTimeout(MSEC_T msec)73     void SetDefaultTimeout(MSEC_T msec) { m_defaultTimeout = msec; }
74 
75 /* Please see man pages for details
76 
77 
78 */
79     bool IsResendRequired(void) const;
80 
81 /* Please see man pages for details
82 
83 
84 
85 */
86     u32 GetTotalDataSize(void) const;
87 
88 /* Please see man pages for details
89 
90 */
91     void Clear(void);
92 
93 
94 /* Please see man pages for details
95 
96 
97   */
98     void TryAgain(void);
99 
100 /* Please see man pages for details
101 
102 
103 
104 
105 
106  */
107     bool IsResendMode(void) const;
108 
109 /* Please see man pages for details
110 
111 
112 
113  */
IsFull(void)114     bool IsFull(void) const { return m_queue.IsFull(); }
115 
116 /* Please see man pages for details
117 
118 */
119     void PrintDebugInfo(void) const;
120 
121 /* Please see man pages for details
122 
123 */
124     static void Test(void);
125 
126 private:
127 /* Please see man pages for details
128 
129 */
130     ResendQueue           (const ResendQueue&);
131 
132 /* Please see man pages for details
133 
134 */
135     ResendQueue& operator=(const ResendQueue&);
136 
137     // If the queue capacity is not larger than the window size notified from the receiving side, then the queue may be filled.
138     //
139     // If the RDT payload is 1400 bytes, then this is 16 * 1400 = 22400 bytes, and if the receive buffer (window size) on the receiving side is set to be larger than this, the sending side queue may become blocked.
140     //
141     //
142     static const size_t DEPTH = 16;
143 
144     // TODO: Parameters must be adjusted for each platform. There is a major influence on the throughput.
145     // Before, this value was 500. Then, it took 35 seconds to send and receive 256 KB of data.
146 //    static const MSEC_T DEFAULT_TIMEOUT = 100;
147     static const MSEC_T DEFAULT_TIMEOUT = 50;  // 150 to 180KB
148 
149     // Timeout value for segments containing SYN.
150     // Preparations to work around the bug that causes the connection to be in a half-open state when resend is at a fast pace similar to data segments.
151     //
152     static const MSEC_T SYN_SEGMENT_TIMEOUT = 200;
153 
154     bool checkTimeStamp(void) const;
155 
156     struct SegmentWithTime
157     {
SegmentWithTimeSegmentWithTime158         SegmentWithTime(void) : timeStamp(0), timeOut(0), resendMark(false) {}
IsTimeOutSegmentWithTime159         bool IsTimeOut(void) const { return (timeStamp + timeOut < GetCurrentTimeAsMillisecond()); }
160 
161         Segment segment;
162         MSEC_T timeStamp;  // Time of the send
163         MSEC_T timeOut;    // If the time specified here is exceeded, this becomes a resend target.
164         bool resendMark;   // Marking is done on elements in the instant of entering resend mode.
165         u8   padding[7];   // Padding
166     };
167 
168     MSEC_T                        m_defaultTimeout; // Timeout (in milliseconds)
169     Deque<SegmentWithTime, DEPTH> m_queue;          // Resend queue
170 
171     bool                          m_bResendMode;    // Resend mode flag
172     u8                            m_padding[7];
173 };
174 
175 
176 }}} // namespace nn::rdt::CTR
177 
178 #endif  // end of NN_LIBRARIES_RDT_CTR_RDT_RESEND_QUEUE_H_
179