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