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