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.

335 lines
9.6 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. PROTOCOL.H
  5. Abstract:
  6. Another Reliable Protocol - CPP implementation
  7. Author:
  8. Aaron Ogus (aarono)
  9. Environment:
  10. Win32/COM
  11. Revision History:
  12. Date Author Description
  13. ====== ====== ============================================================
  14. 12/10/96 aarono Original
  15. 2/11/97 aarono Removed channel from header, now rides in body of 1st packet.
  16. along with the length field.
  17. 3/12/97 aarono channel is gone, not relevant to transport protocol, can be
  18. prepended to messages that want it. Length field is gone,
  19. not required.
  20. 6/6/98 aarono Turn on throttling and windowing - fix some definitions
  21. --*/
  22. #ifndef _PROTOCOL_H_
  23. #define _PROTOCOL_H_
  24. #pragma pack(push,1)
  25. typedef unsigned char byte;
  26. typedef unsigned short word;
  27. typedef unsigned int dword;
  28. //
  29. // ARP - Another Reliable Protocol - Packet Definitions
  30. //
  31. // Terminology
  32. //
  33. // message - an arbitrary sized chunk of data
  34. // to be sent from one computer to a another over
  35. // the available media.
  36. //
  37. // packet - a piece of a message broken down
  38. // for the media, including protocol information
  39. // to allow the message to be reconstructed at
  40. // the other end.
  41. //
  42. // frame - an instance of a packet.
  43. //
  44. // Assumptions:
  45. //
  46. // All values on the wire are little endian.
  47. //
  48. // This protocol allows packets to arrive out of
  49. // order but is optimized for the in-order case.
  50. //
  51. #define EXT 0x80 /* EXTENSION BIT */
  52. #define BIG 0x40 /* BIG HEADERS (FAST MEDIA) */
  53. #define CMD 0x20 /* COMMAND FRAME */
  54. #define STA 0x10
  55. #define EOM 0x08 /* END OF MESSAGE */
  56. #define SAK 0x04 /* SEND ME AN ACK */
  57. #define ACK 0x02 /* ACKNOWLEDGE FRAME */
  58. #define RLY 0x01 /* RELIABLE FRAME */
  59. // Shifts used in small extended fields.
  60. #define nNACK_MSK 0x60
  61. #define nNACK_SHIFT 5
  62. #define CMD_MSK 0x1F
  63. #define IDMSK (pCmdInfo->IDMSK)
  64. #define SEQMSK (pCmdInfo->SEQMSK)
  65. // Note: abort packets contain serial numbers but no sequence numbers.
  66. // the nACK field can be used to abort many messages at the same
  67. // time. (using ABORT2 or ABORT3). Also just the messageid is
  68. // provided in the abort case.
  69. typedef struct _Packet1 { // simple small -I- frame
  70. byte flags;
  71. byte messageid;
  72. byte sequence;
  73. byte serial;
  74. byte data[0];
  75. } Packet1, *pPacket1;
  76. typedef struct _Packet2 { // simple large -I- frame
  77. byte flags;
  78. word messageid;
  79. word sequence;
  80. byte serial;
  81. byte data[0];
  82. } Packet2, *pPacket2;
  83. typedef struct {
  84. byte flag1; // header flags
  85. byte flag2; // extended flags for small hdr/command for lrg
  86. byte flag3; // nNACK for large hdr.
  87. byte pad; // make it a dword.
  88. } FLAGS, *pFLAGS;
  89. // different frame components that may be part of any
  90. // frame. type 1 - small frames, type 2 - large frames
  91. //
  92. // ACKNOWLEDGE information
  93. //
  94. typedef struct _ACK1 {
  95. byte messageid;
  96. byte sequence;
  97. byte serial;
  98. dword bytes; // bytes received from remote
  99. dword time; // time when bytes received was this value
  100. } ACK1, *pACK1;
  101. typedef struct _ACK2 {
  102. word messageid;
  103. word sequence;
  104. byte serial;
  105. dword bytes; // bytes received from remote
  106. dword time; // remote time when bytes receive was this value
  107. } ACK2, *pACK2;
  108. //
  109. // ABORT
  110. //
  111. typedef struct _ABT1 {
  112. byte messageid;
  113. byte sequence;
  114. } ABT1, *pABT1;
  115. typedef struct _ABT2 {
  116. word messageid;
  117. word sequence;
  118. } ABT2, *pABT2;
  119. //
  120. // MISSING packet information
  121. //
  122. typedef struct _NACK1 {
  123. byte messageid;
  124. byte sequence;
  125. dword bytes; // bytes received from remote
  126. dword time; // remote time when bytes received was this value
  127. byte mask[0];
  128. } NACK1, *pNACK1;
  129. typedef struct _NACK2 {
  130. word messageid;
  131. word sequence;
  132. dword bytes; // bytes received from remote
  133. dword time; // remote time when bytes received was this value
  134. byte mask[0];
  135. } NACK2, *pNACK2;
  136. //
  137. // COMMAND information (including -I- frames)
  138. //
  139. typedef struct _CMD1 {
  140. byte messageid;
  141. byte sequence;
  142. byte serial;
  143. byte data[0];
  144. } CMD1, *pCMD1;
  145. typedef struct _CMD2 {
  146. word messageid;
  147. word sequence;
  148. byte serial;
  149. byte data[0];
  150. } CMD2, *pCMD2;
  151. #pragma pack(pop)
  152. #endif
  153. /*==============================================================================
  154. Protocol Operational description
  155. ================================
  156. Characteristics:
  157. ----------------
  158. The ARP protocol provides for reliable and non-reliable packet delivery
  159. over an existing non-reliable (datagram) protocol. It is assumed that
  160. packet length information and addressing information is carried by the
  161. datagram protocol and these fields are therefore ambiguous and excluded
  162. from ARP.
  163. ARP is optimized to provide a minimum of overhead in the case of low
  164. bandwidth links. The overhead per-packet is 3 bytes.
  165. ARP's default command is the delivery of I frames. This avoids the need
  166. for a command field in the protocol header for the most common frame type.
  167. ARP does segmentation and reassembly on large datagram messages. This
  168. allows for datagram delivery of messages larger than 1 packet.
  169. ARP does a hybrid of windowing with selective NACK of missing packets,
  170. allowing optimal operation on both good and weak links, regardless
  171. of latency.
  172. ARP assigns each frame a serial number that is used in the ACK responses.
  173. This allows the protocol to keep up to date latency information as well
  174. as recognize which packet is being responded to in a retry situation.
  175. The serial number allows the protocol to adjust timeouts reliably.
  176. ARP allows multiple messages to be sent concurrently. Having multiple
  177. messages prevents the system from blocking on retry from a single packet
  178. transmission failure. It also allows better use of available bandwidth
  179. since the protocol does not wait for the ACK from one message before
  180. sending the next.
  181. {FUTURE: What about packet sub-allocation? Bandwidth allocation?}
  182. Header Description:
  183. -------------------
  184. Flags:
  185. +-----+-----+-----+-----+-----+-----+-----+-----+
  186. | EXT | BIG | CMD | STA | EOM | SAK | ACK | RLY |
  187. +-----+-----+-----+-----+-----+-----+-----+-----+
  188. Extended Flags:
  189. Small:
  190. +-----+-----+-----+-----+-----+-----+-----+-----+
  191. | EXT | nNACK | COMMAND |
  192. +-----+-----+-----+-----+-----+-----+-----+-----+
  193. Big:
  194. +-----+-----------------------------------------+
  195. | EXT | COMMAND | (only if CMD & BIG set)
  196. +-----+-----------------------------------------+
  197. | EXT | nNACK |
  198. +-----+-----------------------------------------+
  199. Flags:
  200. STA - start of a message.
  201. EOM - this bit is set when the packet is the last packet of a message
  202. ACK - used to signify that this is an ACK packet, otherwise a COMMAND
  203. - if nACK != 0, the ACK is informative only. i.e - tells client
  204. last ACKed frame that instigated the nACK to update latency
  205. information. An ACK without nACK indicates all frames up
  206. to the ACK frame were successfully received. Any bit set
  207. in the nACK mask indicates a missing frame, any 0 bit indicates
  208. a frame that was successfully received.
  209. SAK - when this bit is set, the receiver must send an ACK packet
  210. for this packet.
  211. RLY - indicates that this message is being delivered reliably.
  212. BIG - when this bit is set, the packets are in large format TYPE 3.
  213. CMD - command frame. When this bit is set, the packet contains a
  214. command. If there is no COMMAND field it is an I frame.
  215. EXT - when the BIG bit is not set, indicates extended flags are present.
  216. Extended Flags:
  217. nNACK - if non-zero indicates presence of nNACK byte masks. The NACK
  218. field consists of a sequence number followed by nNACK byte masks.
  219. Each bit in the mask represents a packet after the packet specified
  220. in the sequence number. The packet in the sequence number is also
  221. being NACKed.
  222. Command:
  223. The command field is used to specify protocol subcommands. The following
  224. are defined. Commands larger than 15 require BIG packets. Commands that
  225. require responses include the response in the ACK packet. All protocol
  226. commands are unreliable. Each command has its own messageid sequence and
  227. serial. This means commands can be of arbitrary length. The Response
  228. to a command is also a command.
  229. 0000 0 - Default - I Frame or ACK/NACK (nACK != 0)
  230. 0001 1 - ABORT
  231. 0010 2 - Ping - send packet back to sender.
  232. 0011 3 - Ping Response - a message being returned.
  233. 0100 4 - GetTime - Get the tick count.
  234. 0101 5 - Get Time Response - Response to the Get Time request.
  235. 0110 6 - SetTime - Set the tick count.
  236. 0111 7 - Set Time Response - Response to the Set Time request.
  237. Rule for processing EXT bits. If a byte in the flags has the high
  238. bit set, there is one more byte. Ignore any bits beyond what you know
  239. how to process.
  240. Sample Packets:
  241. ===============
  242. Time setting algorithm?
  243. Bandwidth Calculations?
  244. Scheduling?
  245. Window Size?
  246. Interpacket wait?
  247. Send Queue Management?
  248. Command for selective NACK.
  249. RLY bit separates 2 streams - reliable/datagram. For piggyback
  250. ACK this means reliable piggyback ACKs are only on reliable streams
  251. and datagram piggyback ACKs are only on non-reliable streams.
  252. ==============================================================================*/
  253. #ifdef __DPMESS_INCLUDED__
  254. #define MAX_SEND_HEADER (sizeof(Packet2)+sizeof(MSG_PROTOCOL))
  255. // leave space for a 128 bit NACK message, this is the maximum window we ever allow
  256. #define MAX_SYS_HEADER (sizeof(NACK2)+(128/8)+sizeof(MSG_PROTOCOL))
  257. #endif