Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

445 lines
17 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. ARPSTRUC.H
  5. Abstract:
  6. Structure definitions for the ARP protocol implementation
  7. Author:
  8. Aaron Ogus (aarono)
  9. Environment:
  10. Win32/COM
  11. Revision History:
  12. Date Author Description
  13. ======= ====== ============================================================
  14. 1/27/97 aarono Original
  15. 2/18/98 aarono Added more fields to SEND for SendEx support
  16. 6/6/98 aarono Turn on throttling and windowing
  17. 2/12/00 aarono Concurrency issues, fix VOL usage and Refcount
  18. --*/
  19. #ifndef _ARPSTRUC_H_
  20. #define _ARPSTRUC_H_
  21. #include <windows.h>
  22. #include <mmsystem.h>
  23. #include <dplay.h>
  24. #include "arpd.h"
  25. #include "bufpool.h"
  26. #include "bilink.h"
  27. #include "mydebug.h"
  28. //#include "threads.h"
  29. //#pragma warning( disable : 4090)
  30. #define VOL volatile
  31. //
  32. // Information about sent packets, tracked for operational statistics.
  33. //
  34. #define SENDSTAT_SIGN SIGNATURE('S','T','A','T')
  35. typedef struct PROTOCOL *PPROTOCOL;
  36. typedef struct _SENDSTAT {
  37. #ifdef SIGN
  38. UINT Signature; // Signature for SIGN
  39. #endif
  40. union {
  41. BILINK StatList; // linked on Send and later SESSION.
  42. struct _SENDSTAT *pNext;
  43. };
  44. UINT messageid;
  45. UINT sequence; // sequence number
  46. UINT serial; // serial number
  47. UINT tSent; // tick time when this packet instance sent.
  48. UINT LocalBytesSent; // number of bytes sent on session at send time.
  49. UINT RemoteBytesReceived;// last remote byte report at send time.
  50. UINT tRemoteBytesReceived; // remote timestamp when received.
  51. UINT bResetBias;
  52. } SENDSTAT, *PSENDSTAT;
  53. #define SEND_SIGN SIGNATURE('S','E','N','D')
  54. typedef enum _TRANSMITSTATE {
  55. Start=0, // Never sent a packet.
  56. Sending=1, // Thread to send is running and xmitting.
  57. Throttled=2, // Waiting for send bandwidth.
  58. WaitingForAck=3, // Timer running, listening for ACKs.
  59. WaitingForId=4, // Waiting for a Send Id.
  60. ReadyToSend=5, // Have stuff to xmit, waiting for thread.
  61. TimedOut=6, // Retry timed out.
  62. Cancelled=7, // User cancelled send.
  63. UserTimeOut=8, // Didn't try to send until too late.
  64. Done=9 // Finished sending, singalled sender.
  65. } TRANSMITSTATE;
  66. struct _SESSION;
  67. // this Send is an ACK or NACK (OR'ed into SEND.dwFlags)
  68. #define ASEND_PROTOCOL 0x80000000
  69. #pragma pack(push,1)
  70. typedef struct _SEND{
  71. #ifdef SIGN
  72. UINT Signature; // Signature for SIGN
  73. #endif
  74. CRITICAL_SECTION SendLock; // Lock for Send Structure
  75. UINT RefCount; // @#$%! - not marked volatile since accessed only with Interlocked fns.
  76. VOL TRANSMITSTATE SendState; // State of this message's transmission.
  77. // Lists and Links...
  78. union {
  79. struct _SEND *pNext; // linking on free pool
  80. BILINK SendQ; // linking on session send queue
  81. };
  82. BILINK m_GSendQ; // Global Priority Queue
  83. BILINK TimeoutList; // List of sends waiting for timeout (workaround MMTIMER cancel bug).
  84. struct _SESSION *pSession; // pointer to SESSIONion(gets a ref)
  85. PPROTOCOL pProtocol; // pointer to Protocol instance that created us.
  86. // Send Information
  87. DPID idFrom;
  88. DPID idTo;
  89. WORD wIdTo; // index in table
  90. WORD wIdFrom; // index in table
  91. UINT dwFlags; // Send Flags (include reliable)
  92. PBUFFER pMessage; // Buffer chain describing message.
  93. UINT MessageSize; // Total size of the message.
  94. UINT FrameDataLen; // Data area of each frame.
  95. UINT nFrames; // Number of frames for this message.
  96. UINT Priority; // Send Priority.
  97. // User cancel and complete info
  98. DWORD dwMsgID; // message id given to user, for use in cancel.
  99. LPVOID lpvUserMsgID; // user's own identifier for this send.
  100. BOOL bSendEx; // called through SendEx.
  101. // Vars for reliability
  102. BOOL fSendSmall;
  103. VOL BOOL fUpdate; // update to NS,NR NACKMask made by receive.
  104. UINT messageid; // Message ID number.
  105. UINT serial; // serial number.
  106. VOL UINT OpenWindow; // Number of sends we are trying to get outstanding
  107. VOL UINT NS; // Sequence Sent.
  108. VOL UINT NR; // Sequence ACKED.
  109. UINT SendSEQMSK; // Mask to use.
  110. VOL UINT NACKMask; // Bit pattern of NACKed frames.
  111. // These are the values at NR - updated by ACKs
  112. VOL UINT SendOffset; // Current offset we are sending.
  113. VOL PBUFFER pCurrentBuffer; // Current buffer being sent.
  114. VOL UINT CurrentBufferOffset; // Offset in the current buffer of next packet.
  115. // info to update link characteristics when ACKs come in.
  116. BILINK StatList; // Info for packets already sent.
  117. DWORD BytesThisSend; // number of bytes being sent in the current packet.
  118. // Operational Characteristics
  119. VOL UINT_PTR uRetryTimer;
  120. UINT TimerUnique;
  121. UINT RetryCount; // Number of times we retransmitted.
  122. UINT WindowSize; // Maximum Window Size.
  123. UINT SAKInterval; // interval (frames) at which a SAK is required.
  124. UINT SAKCountDown; // countdown to 0 from interval.
  125. UINT tLastACK; // Time we last got an ACK.
  126. UINT dwSendTime; // time we were called in send.
  127. UINT dwTimeOut; // timeout time.
  128. UINT PacketSize; // Size of packets to send.
  129. UINT FrameSize; // Size of Frames for this send.
  130. // Completion Vars
  131. HANDLE hEvent; // Event to wait on for internal send.
  132. UINT Status; // Send Completion Status.
  133. PASYNCSENDINFO pAsyncInfo; // ptr to Info for completing Async send(NULL=>internal send)
  134. ASYNCSENDINFO AsyncInfo; // actual info (copied at send call).
  135. DWORD tScheduled; // the time we scheduled the retry;
  136. DWORD tRetryScheduled; // expected retry timer run time.
  137. VOL BOOL bCleaningUp; // we are on the queue but don't take a ref pls.
  138. } SEND, *PSEND;
  139. #pragma pack(pop)
  140. #define RECEIVE_SIGN SIGNATURE('R','C','V','_')
  141. // Receive buffers are in reverse receive order. When they have all
  142. // been received, they are then put in proper order.
  143. typedef struct _RECEIVE {
  144. #ifdef SIGN
  145. UINT Signature; // Signature for SIGN
  146. #endif
  147. union {
  148. BILINK pReceiveQ;
  149. struct _RECEIVE * pNext;
  150. };
  151. BILINK RcvBuffList; // List of receive buffers that make up the message.
  152. CRITICAL_SECTION ReceiveLock;
  153. struct _SESSION *pSession;
  154. VOL BOOL fBusy; // Someone is moving this receive.
  155. BOOL fReliable; // Whether this is a reliable receive.
  156. VOL BOOL fEOM; // Whether we received the EOM bit.
  157. UINT command;
  158. UINT messageid;
  159. VOL UINT MessageSize;
  160. VOL UINT iNR; // Absolute index of first receiving packet (reliable only).
  161. VOL UINT NR; // Last in sequence packet received.
  162. VOL UINT NS; // Highest packet number received.
  163. VOL UINT RCVMask; // bitmask of received packets (NR relative)
  164. PUCHAR pSPHeader;
  165. UCHAR SPHeader[0];
  166. } RECEIVE, *PRECEIVE;
  167. #pragma pack(push,1)
  168. typedef struct _CMDINFO {
  169. WORD wIdTo; // index
  170. WORD wIdFrom; // index
  171. DPID idTo; // actual DPID
  172. DPID idFrom; // actual DPID
  173. UINT bytes; // read from ACK.
  174. DWORD tRemoteACK; // remote time remote ACKed/NACKed
  175. UINT tReceived; // timeGetTime() when received.
  176. UINT command;
  177. UINT IDMSK;
  178. USHORT SEQMSK;
  179. USHORT messageid;
  180. USHORT sequence;
  181. UCHAR serial;
  182. UCHAR flags;
  183. PVOID pSPHeader; // used to issue a reply.
  184. } CMDINFO, *PCMDINFO;
  185. #pragma pack(pop)
  186. #define SESSION_SIGN SIGNATURE('S','E','S','S')
  187. // since we now have a full byte for messagid and sequenne in the small headers,
  188. // we no longer have an advantage for full headers until we apply the new
  189. // bitmask package, then we must transit to large frame for windows > 127 messages.
  190. #define MAX_SMALL_CSENDS 29UL // Maximum Concurrent Sends when using small frame headers
  191. #define MAX_LARGE_CSENDS 29UL // Maxinum Concurrent Sends when using large frame headers (could make larger except for mask bits)
  192. #define MAX_SMALL_DG_CSENDS 16UL // Maximum concurrent datagrams when using small frame
  193. #define MAX_LARGE_DG_CSENDS 16UL // Maximum Concurrent datagrams when using large frames.
  194. #define MAX_SMALL_WINDOW 24UL
  195. #define MAX_LARGE_WINDOW 24UL
  196. typedef enum _SESSION_STATE {
  197. Open, // When created and Inited.
  198. Closing, // Don't accept new receives/sends.
  199. Closed // gone.
  200. } SESSION_STATE;
  201. #define SERVERPLAYER_INDEX 0xFFFE
  202. #define SESSION_THROTTLED 0x00000001 // session throttle is on.
  203. #define SESSION_UNTHROTTLED 0x00000002 // unthrottle is deffered to avoid confusing GetMessageQueue.
  204. /////////////////////////////////////////////////////////////////
  205. //
  206. // Transition Matrix for Throttle Adjust
  207. //
  208. // Initial State Event:
  209. // No Drops 1 Drop >1 Drop
  210. //
  211. // Start + Start - Meta -- Start
  212. //
  213. // Meta + Meta - Stable -- Meta
  214. //
  215. // Stable + Stable - Stable -- Meta
  216. //
  217. //
  218. // Engagement of Backlog Throttle goes to MetaStable State.
  219. ///////////////////////////////////////////////////////////////////
  220. #define METASTABLE_GROWTH_RATE 4
  221. #define METASTABLE_ADJUST_SMALL_ERR 12
  222. #define METASTABLE_ADJUST_LARGE_ERR 25
  223. #define START_GROWTH_RATE 50
  224. #define START_ADJUST_SMALL_ERR 25
  225. #define START_ADJUST_LARGE_ERR 50
  226. #define STABLE_GROWTH_RATE 2
  227. #define STABLE_ADJUST_SMALL_ERR 12
  228. #define STABLE_ADJUST_LARGE_ERR 25
  229. typedef enum _ThrottleAdjustState
  230. {
  231. Begin=0, // At start, double until drop or backlog
  232. MetaStable=1, // Meta stable, large deltas for drops
  233. Stable=2 // Stable, small deltas for drops
  234. } eThrottleAdjust;
  235. typedef struct _SESSION {
  236. PPROTOCOL pProtocol; // back ptr to object.
  237. #ifdef SIGN
  238. UINT Signature; // Signature for SIGN
  239. #endif
  240. // Identification
  241. CRITICAL_SECTION SessionLock; // Lock for the SESSIONion.
  242. UINT RefCount; // RefCount for the SESSION. - not vol, only accessed with Interlocked
  243. VOL SESSION_STATE eState;
  244. HANDLE hClosingEvent; // Delete waits on this during close.
  245. DPID dpid; // The remote direct play id for this session.
  246. UINT iSession; // index in the session table
  247. UINT iSysPlayer; // index in session table of sys player.
  248. // NOTE: if iSysPlayer != iSession, then rest of struct not req'd.
  249. BILINK SendQ; // Priority order sendQ;
  250. BOOL fFastLink; // set True when link > 50K/sec, set False when less than 10K/sec.
  251. BOOL fSendSmall; // Whether we are sending small reliable frames.
  252. BOOL fSendSmallDG; // Whether we are sending small datagram frames.
  253. BOOL fReceiveSmall;
  254. BOOL fReceiveSmallDG;
  255. UINT MaxPacketSize; // Largest packet allowed on the media.
  256. // Operating parameters -- Send
  257. // Common
  258. UINT MaxCSends; // maximum number of concurrent sends
  259. UINT MaxCDGSends; // maximum number of concurrent datagram sends
  260. // Reliable
  261. VOL UINT FirstMsg; // First message number being transmitted
  262. VOL UINT LastMsg; // Last message number being transmitted
  263. VOL UINT OutMsgMask; // relative to FirstMsg, unacked messages
  264. UINT nWaitingForMessageid; // number of sends on queue that can't start sending because they don't have an id.
  265. // DataGram
  266. VOL UINT DGFirstMsg; // First message number being transmitted
  267. VOL UINT DGLastMsg; // Last message number being transmitted
  268. VOL UINT DGOutMsgMask; // relative to FirstMsg, not-fully sent messages.
  269. UINT nWaitingForDGMessageid; // number of sends on queue that can't start sending because they don't have an id.
  270. // Send stats are tracked seperately since sends may
  271. // no longer be around when completions come in.
  272. //BILINK OldStatList;
  273. // Operating parameters -- Receive
  274. // DataGram Receive.
  275. BILINK pDGReceiveQ; // queue of ongoing datagram receives
  276. // Reliable Receive.
  277. BILINK pRlyReceiveQ; // queue of ongoing reliable receives
  278. BILINK pRlyWaitingQ; // Queue of out of order reliable receives waiting.
  279. // only used when PROTOCOL_NO_ORDER not set.
  280. VOL UINT FirstRlyReceive;
  281. VOL UINT LastRlyReceive;
  282. VOL UINT InMsgMask; // mask of fully received receives, relative to FirstRlyReceive
  283. // Operational characteristics - MUST BE DWORD ALIGNED!!! - this is because we read and write them
  284. // without a lock and assume the reads and writes are atomic (not in combination)
  285. UINT WindowSize; // Max outstanding packets on a send - reliable
  286. UINT DGWindowSize; // Max outstanding packets on a send - datagram
  287. UINT MaxRetry; // Usual max retries before dropping.
  288. UINT MinDropTime; // Min time to retry before dropping.
  289. UINT MaxDropTime; // After this time always drop.
  290. VOL UINT LocalBytesReceived; // Total Data Bytes received (including retries).
  291. VOL UINT RemoteBytesReceived; // Last value from remote.
  292. VOL DWORD tRemoteBytesReceived; // Remote time last value received.
  293. UINT LongestLatency; // longest observed latency (msec)
  294. UINT ShortestLatency; // shortest observed latency(msec)
  295. UINT LastLatency; // last observed latency (msec)
  296. UINT FpAverageLatency; // average latency (msec 24.8) (128 samples)
  297. UINT FpLocalAverageLatency; // Local average latency (msec 24.8) (16 samples)
  298. UINT FpAvgDeviation; // average deviation of latency. (msec 24.8) (128 samples)
  299. UINT FpLocalAvgDeviation; // average deviation of latency. (msec 24.8) (16 samples)
  300. UINT Bandwidth; // latest observed bandwidth (bps)
  301. UINT HighestBandwidth; // highest observed bandwidth (bps)
  302. // we will use changes in the remote ACK delta to isolate latency in the send direction.
  303. UINT RemAvgACKDelta; // average clock delta between our send time (local time) and remote ACK time (remote time).
  304. UINT RemAvgACKDeltaResidue;
  305. UINT RemAvgACKBias; // This value is used to pull the clock delta into a safe range (not near 0 or -1)
  306. // that won't risk hitting the wraparound when doing calculations
  307. // Throttle statistics
  308. DWORD dwFlags; // Session Flags - currently just "throttle on/off"(MUST STAY THIS WAY)
  309. UINT SendRateThrottle; // current rate (bps) at which we are throttling.
  310. DWORD bhitThrottle; // we hit a throttle
  311. DWORD tNextSend; // when we are allowed to send again.
  312. DWORD tNextSendResidue; // residual from calculating next send time
  313. DWORD_PTR uUnThrottle;
  314. DWORD UnThrottleUnique;
  315. DWORD FpAvgUnThrottleTime; // (24.8) how late Unthrottle usually called. (throttle when send is this far ahead)
  316. // last 16 samples, start at 5 ms.
  317. DWORD tLastSAK; // last time we asked for an ACK
  318. CRITICAL_SECTION SessionStatLock; // [locks this section ------------------------------------------- ]
  319. BILINK DGStatList; // [Send Statistics for Datagrams (for reliable they are on Sends) ]
  320. DWORD BytesSent; // [Total Bytes Sent to this target ]
  321. DWORD BytesLost; // [Total Bytes Lost on the link. ]
  322. DWORD bResetBias; // [Counts down to reset latency bias ]
  323. // [---------------------------------------------------------------]
  324. eThrottleAdjust ThrottleState; // ZEROINIT puts in Start
  325. DWORD GrowCount; // number of times we grew in this state
  326. DWORD ShrinkCount; // number of times we shrank in this state
  327. DWORD tLastThrottleAdjust; // remember when we last throttled to avoid overthrottling.
  328. } SESSION, *PSESSION;
  329. #endif