Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | Related Pages | Examples

protocol.html

00001 /**
00002 @page Protocol Protocol
00003 
00004 
00005 @section Introduction Introduction
00006 Our framework is built on top of the UDP protocol. By doing this we
00007 are able to make use of this protocol's error detection service. But
00008 in order to offer the services we wish to we need to build some additional
00009 services on top of the UDP protocol. We will in this part of the report
00010 give a description of these services.
00011 
00012 
00013 @section IOTTLU Implications of the transport layer used
00014 As described in the report we have chosen to build our framework on
00015 top of the UDP transport layer protocol. This choice has the following
00016 implications on the building of our framework.
00017 
00018 @subsection ServicesOffered Services offered
00019 UDP offers no guarantees other than error detection but does have
00020 a low header overhead and allows us to build on top of it with almost
00021 no restrictions except those described in section @ref Limitations.
00022 
00023 @subsection Limitations Limitations
00024 We have no flow control, congestion control, reliability or error
00025 correction. Furthermore the limit on a UDP datagram's size is 65507,
00026 or 64K-8-20. 8 for the UDP packet header and 20 for the IP-headers.
00027 This puts a restriction on the size of data sent with this protocol
00028 in one packet to 65507 bytes.
00029 
00030 
00031 @section Packet-formats Packet formats
00032 Framework packets consists of the five fields shown in figure @ref The-header-format.
00033 
00034 <DIV align="center">
00035 @anchor The-header-format
00036 <TABLE>
00037 <CAPTION ALIGN="BOTTOM"><STRONG>Figure 1:</STRONG>
00038 The header format of framework packets.</CAPTION>
00039 <TR><TD>
00040 <DIV ALIGN="CENTER">
00041 <IMG
00042  WIDTH="514" HEIGHT="86" ALIGN="BOTTOM" BORDER="0"
00043  SRC="images/img1.png"
00044  ALT="\includegraphics[%
00045 scale=0.69]{/tmp/lyx_tmpdir15948UmioPa/lyx_tmpbuf0/_home_emanuel_DIKU_DataNet_dataNet_Report_figs_PacketHeader}">
00046 </DIV>
00047 <P></TD></TR>
00048 </TABLE>
00049 </DIV>
00050 
00051 <P>
00052 The main functions and formats of the fields are as follows:
00053 <P>
00054 
00055 <UL>
00056 <LI>R<SMALL>ELIABLE</SMALL>: This field has the size and type of 1 byte or 8
00057 bits. This field decides whether or not the packet should be sent
00058 reliable. If the value of this field is 1-255 reliable transfer should
00059 be used. Reliable transfer means that delivery of this packet is required.
00060 If the value is set to 0 this packet will be sent unreliable.
00061 </LI>
00062 <LI>T<SMALL>YPE</SMALL>: This field has the size and type of 1 byte. This lets
00063 us know what kind of object the receiver is. If the value is zero
00064 it is a system packet intended for the framework. What the framework
00065 is to do with this packet will be decided by the <I>receiver</I> field.
00066 If the values of this field is set to 1 the packet is intended for
00067 a plug-in. Which plug-in the packet should be delivered to is decided
00068 by the <I>receiver</I> field. If the value of the field is 2 this
00069 packet is a create-object-packet.
00070 If the value is 3 the packet is a destroy object packet. Values from
00071 4-255 can be used in any way the user of the framework wishes. This
00072 field will not make any sense to the framework unless it is combined
00073 with the <I>receiver</I> field in a right way.
00074 </LI>
00075 <LI>P<SMALL>RIORITY</SMALL>: This field has the size and type of 1 byte. Decides
00076 which priority the packet should be given. 0 for highest and 255 for
00077 lowest priority - any number between 0 and 255 can be used. An example of
00078 queue is that a packet with a priority of 0 is put in the very front
00079 of the queue - or at least right after all the other priority 0 packets.
00080 The dispatcher at the receiving end grabs the priority 0 packet as
00081 soon as it realizes that such a packet exists in the in-queue.
00082 </LI>
00083 <LI>R<SMALL>ECEIVER</SMALL>: This field has the size and type of 1 unsigned
00084 integer. If the value of the <I>type</I> field is between 4 and 255
00085 this field lets the framework know which data object to deliver the
00086 packet to. If the value of the type field is 0, meaning this
00087 packet is a system packet, the value of the receiver field has the
00088 following meanings: 10001 means that this a handshake initialisation
00089 packet sent from a client to server requesting the server to connect.
00090 10002 is one of two replies the server framework can give the client
00091 on this initial request. 10002 means that the client is not welcome
00092 to connect to the server. 10003 is the second possible reply to 10001
00093 - a value of 10003 means that this packet contains a description of
00094 the server framework setup. To a 10003 message the client can reply
00095 in two ways. With a 10004 message which lets the server know that the client
00096 framework cannot conform to the setup of the server and will disconnect.
00097 A 10005 message means that the client can match the setup of the
00098 server and that it is now ready to receive packets. For more information
00099 on the handshaking procedure please see section @ref Handshaking.
00100 A value of 20001 is used for acknowledgement packets and finally a
00101 value of 30001 is used for framework heartbeats allowing the client
00102 framework to stay connected with the server framework.
00103 </LI>
00104 <LI>S<SMALL>EQUENCE </SMALL>N<SMALL>UMBER</SMALL>: This field has the size and
00105 type of an unsigned integer. Sequence numbers are assigned
00106 in increasing order to all packets. They are assigned by priority
00107 meaning that each priority have their own channel. For reliable packets
00108 they are further more assigned by the client, so the receiving client has a
00109 chance of knowing which sequence number to expect next for a given
00110 priority. 
00111 
00112 </LI>
00113 <LI>D<SMALL>ATA:</SMALL> The data segment may contain all types of data. However
00114 the maximum size of the data segment is 65496 bytes since 12 bytes
00115 are used by the framework packet header; therefore we get 65507-12.
00116 65507 is the number deduced in section @ref Limitations. The framework
00117 expect all incoming data to be in network byte order.
00118 </LI>
00119 </UL>
00120 
00121 
00122 @subsection DataFormats Data formats
00123 All data received by the framework will be expected being in network
00124 byte order and the framework will make sure to convert it into host
00125 byte order before delivering it. The fundamental data types are those
00126 used in the C++ programming language which are described in the C++
00127 reference manual<A NAME="tex2html2" HREF="#foot46"><SUP>1</SUP></A>.
00128 All data sent from the framework are also sent in network byte order.
00129 
00130 The maximum size of a framework packet is limited to 65507 (header
00131 included) due to the use of UDP as the underlying transport layer.
00132 
00133 @section Connection Connection
00134 Although the GaNeF protocol is built on top of the UDP protocol it
00135 is not connectionless. Connection between client and server is established,
00136 maintained and closed down. This section will go through the various
00137 phases of the client/server connection.
00138 
00139 
00140 @subsection Handshaking Handshaking
00141 To establish connection between a client and a game server the handshaking
00142 protocol shown on figure @ref The-handshaking-phase is used.
00143 
00144 <DIV ALIGN="CENTER">
00145 @anchor The-handshaking-phase
00146 <TABLE>
00147 <CAPTION ALIGN="BOTTOM"><STRONG>Figure 2:</STRONG> The handshaking phase. </CAPTION>
00148 <TR><TD>
00149 <DIV ALIGN="CENTER">
00150 <IMG
00151  WIDTH="456" HEIGHT="313" ALIGN="BOTTOM" BORDER="0"
00152  SRC="images/img2.png"
00153  ALT="\includegraphics[%
00154 scale=0.62]{/tmp/lyx_tmpdir15948UmioPa/lyx_tmpbuf0/_home_emanuel_DIKU_DataNet_dataNet_Report_figs_HandShakingProtocol}">
00155 </DIV>
00156 
00157 <P></TD></TR>
00158 </TABLE>
00159 </DIV>
00160 
00161 The client initiates the handshaking with a request, which is the
00162 packet called I<SMALL>NIT </SMALL>P<SMALL>ACKET</SMALL> on figure @ref The-handshaking-phase.
00163 It is possible for the game developer to send some data along with
00164 this initial request - this data is what we call tagalong on the
00165 diagram and the framework will ask the game for this data. Such data
00166 could for instance be the client's user name and password which would then 
00167 be delivered to the game at the server side of the framework along
00168 with the initial packet.
00169 The server can reply to the I<SMALL>NIT </SMALL>P<SMALL>ACKET</SMALL> in two ways. The
00170 first is by telling the client that it is not possible for it to connect
00171 to this server at this time; this message is the first D<SMALL>ISCONTINUE</SMALL>
00172 
00173 message shown on the figure (again it is possible for the game developer
00174 to send some data along with this message). If the server accepts
00175 the client it will reply the I<SMALL>NIT </SMALL>P<SMALL>ACKET</SMALL> with a S<SMALL>ETUP
00176 </SMALL>D<SMALL>ESCRIPTION</SMALL> packet containing a description of the server's setup.
00177 The client can reply to this message in one of two ways. If it cannot
00178 conform to the description given by the server it will reply with
00179 a D<SMALL>ISCONTINUE</SMALL> message. If it can conform to the setup described
00180 by the server it will reply the S<SMALL>ETUP </SMALL>D<SMALL>ESCRIPTION</SMALL> message
00181 with a R<SMALL>EADY</SMALL> message letting the server know that the client
00182 is now ready to receive packets from the server.
00183 
00184 <UL>
00185 <LI>I<SMALL>NIT </SMALL>P<SMALL>ACKET:</SMALL> The fields of the I<SMALL>NIT </SMALL>P<SMALL>ACKET</SMALL> should
00186 have the following values: <I>Reliable</I> = 1, <I>Type</I> = 0, <I>Priority</I>
00187 = 0, <I>Receiver</I> = 10001, <I>Sequence Number</I> = any unsigned
00188 integer value and <I>Data</I> = any data value(s).
00189 </LI>
00190 <LI>D<SMALL>ISCONTINUE:</SMALL> From server to client. The fields of this packet
00191 should have the following values: <I>Reliable</I> = 1, <I>Type</I>
00192 = 0, <I>Priority</I> = 0, <I>Receiver</I> = 10002, <I>Sequence
00193 Number</I> = any unsigned integer value and <I>Data</I> = any data value(s).
00194 </LI>
00195 <LI>S<SMALL>ETUP </SMALL>D<SMALL>ESCRIPTION:</SMALL> <I>Reliable</I> = 1, <I>Type</I> = 0,
00196 <I>Priority</I> = 0, <I>Receiver</I> = 10003, <I>Sequence Number</I>
00197 = any unsigned integer value and <I>Data</I> = the first unsigned
00198 int of the data field should tell the client how long the server will
00199 wait before the client will be disconnected. That is, this value tells
00200 the client at which rate it should send heart beats. The next value
00201 should also be an unsigned int. This integer tells the client how
00202 many unique plug-in IDs it should read from the packet. The next values
00203 read from the packet will be plug-in IDs of type unsigned integer.
00204 Any data after the plug-in IDs will be considered data sent from the
00205 client game to the game engine running on the server and will therefore
00206 be forwarded to the server framework's game.
00207 </LI>
00208 <LI>D<SMALL>ISCONTINUE:</SMALL> From client to server. The fields of this packet
00209 should have the following values: <I>Reliable</I> = 1, <I>Type</I>
00210 = 0, <I>Priority</I> = 0, <I>Receiver</I> = 10004, <I>Sequence
00211 Number</I> = any unsigned integer value and <I>Data</I> = any data the
00212 client wishes the framework to deliver to the game on the server.
00213 </LI>
00214 <LI>R<SMALL>EADY:</SMALL> <I>Reliable</I> = 1, <I>Type</I> = 0, <I>Priority</I>
00215 = 0, <I>Receiver</I> = 10005, <I>Sequence Number</I> = any unsigned
00216 integer value and <I>Data</I> = no data.
00217 </LI>
00218 </UL>
00219 
00220 @subsection States States
00221 On figure @ref The-handshaking-phase we see a description of
00222 the states the client enters as the handshaking phase evolves. These
00223 are states used and maintained inside the framework Mainly for the
00224 server and client to know in which way to handle the packets on their
00225 incoming socket.
00226 
00227 
00228 @subsection HeartBeats Heartbeats
00229 After the connection has been established the connection needs to
00230 be maintained. This is done by the client sending heartbeats to the
00231 server. As mentioned in section @ref Handshaking the server
00232 will disconnect the client if it has not heard anything from it during
00233 the period of time stated in the SETUP DESCRIPTION message.
00234 In this implementation the client sends heartbeats to the server
00235 after half of that period of time has passed. The syntax of a heart
00236 beat packet is <I>Reliable</I> = 1, <I>Type</I> = 0, <I>Priority</I>
00237 = 0, <I>Receiver</I> = 30001, <I>Sequence Number</I> = any sequence
00238 number will do.
00239 
00240 
00241 @subsection CloseDownConnection Close down of connection
00242 When a client wishes to disconnect it can just stop sending packets
00243 to the server. When this happens the server will timeout the client
00244 and disconnect then it. This also means that if the game developer
00245 wishes to send some data from the client to the server on disconnect,
00246 he has to do so explicitly; that is, he cannot do it by sending a
00247 message along with any disconnect message sent between the frameworks
00248 as he was able to during the connection establishment.
00249 
00250 
00251 @section Guarantees Guarantees
00252 
00253 @subsection Guarantees-packets packets
00254 Our framework makes no guarantee on delivery when packets are sent unreliably.
00255 It works by best effort and sends unreliable packets by UDP. However,
00256 it does guarantee that the unreliable packets which arrives in the
00257 other end are delivered in the order they were sent. Packets arriving out of order
00258 on the receiving side are simply discarded. Please see figure @ref The-reception-of.
00259 Sending packets unreliably guarantees that the packet will be delivered
00260 at most once.
00261 To send a packet unreliably the <I>Reliable</I> field of the packet
00262 header should be set to 0.
00263 
00264 
00265 <DIV ALIGN="CENTER">
00266 @anchor The-reception-of
00267 <TABLE>
00268 <CAPTION ALIGN="BOTTOM"><STRONG>Figure 3:</STRONG>
00269 The reception of unreliable packets
00270 at the receiver. The number indicates a packet's sequence number.
00271 Packets marked with an arrow will be discarded on the receiving side
00272 since they arrive out of order.</CAPTION>
00273 <TR><TD>
00274 <DIV ALIGN="CENTER">
00275 <IMG
00276  WIDTH="476" HEIGHT="50" ALIGN="BOTTOM" BORDER="0"
00277  SRC="images/img3.png"
00278  ALT="\includegraphics[%
00279 scale=0.82]{/tmp/lyx_tmpdir15948UmioPa/lyx_tmpbuf0/_home_emanuel_DIKU_DataNet_dataNet_Report_figs_UreliableDiscard}">
00280 </DIV>
00281 <P></TD></TR>
00282 </TABLE>
00283 </DIV>
00284 
00285 
00286 
00287 @subsection Reliablepackets Reliable packets
00288 Our framework can guarantee delivery of packets if they are sent reliably.
00289 When packets are sent reliable It also guarantees that the packets
00290 are delivered in the same order as they were sent. Sending a packet
00291 reliable also means that the packet is guaranteed to be delivered
00292 exactly once at the receiving side.
00293 
00294 
00295 
00296 <DIV ALIGN="CENTER"><A NAME="130"></A>
00297 <TABLE>
00298 <CAPTION ALIGN="BOTTOM"><STRONG>Figure 4:</STRONG>
00299 The buffering of reliable packets. Reliable packets are buffered
00300 until they are ready for delivery to ensure they are delivered in
00301 the right order.</CAPTION>
00302 <TR><TD>
00303 <DIV ALIGN="CENTER">
00304 <IMG
00305  WIDTH="480" HEIGHT="82" ALIGN="BOTTOM" BORDER="0"
00306  SRC="images/img4.png"
00307  ALT="\includegraphics[%
00308 scale=0.82]{/tmp/lyx_tmpdir15948UmioPa/lyx_tmpbuf0/_home_emanuel_DIKU_DataNet_dataNet_Report_figs_RealiableNoDiscard}">
00309 </DIV>
00310 <P></TD></TR>
00311 </TABLE>
00312 </DIV>
00313 
00314 This is done by storing packets temporarily in a buffer until all
00315 preceding packets have been received. When all these packets have
00316 been received the packets waiting are marked as being ready for delivery
00317 and thereby delivered when the main loop of the game is ready for
00318 this. To send a packet reliably the packet header field <I>Reliable</I>
00319 should be set to 1.
00320 
00321 
00322 
00323 @subsubsection Acknowledgements Acknowledgements
00324 Whenever the framework receives a reliable packet it lets the sender
00325 know that is has received this packet by sending by an acknowledgement.
00326 An acknowledgement packet has the format shown on figure @ref Format-of-an.
00327 In our implementation acknowledgement packets are sent unreliable.
00328 This can be done so because if the acknowledgement packet is lost
00329 during transfer the sender of the original reliable packet will notice
00330 this and resend the packet. In this case we can re-acknowledge the
00331 packet. Also, if we sent the acknowledgement packet reliable we
00332 would enter a never-ending loop where acknowledgement packets are
00333 acknowledged with acknowledgements which again are acknowledge with
00334 acknowledgements and so forth.
00335 
00336 
00337 <DIV ALIGN="CENTER">
00338 @anchor Format-of-an
00339 <TABLE>
00340 <CAPTION ALIGN="BOTTOM"><STRONG>Figure 5:</STRONG>
00341 Format of an acknowledgement packet. Only
00342 the fields filled out will be used - the rest of the fields are ignored
00343 by the framework.</CAPTION>
00344 <TR><TD>
00345 
00346 <DIV ALIGN="CENTER">
00347 <IMG
00348  WIDTH="474" HEIGHT="57" ALIGN="BOTTOM" BORDER="0"
00349  SRC="images/img5.png"
00350  ALT="\includegraphics[%
00351 scale=0.85]{/tmp/lyx_tmpdir15948UmioPa/lyx_tmpbuf0/_home_emanuel_DIKU_DataNet_dataNet_Report_figs_AckPacket}">
00352 </DIV>
00353 
00354 <P></TD></TR>
00355 </TABLE>
00356 </DIV>
00357 
00358 
00359 @subsubsection Timeouts Timeouts
00360 A possibly lost packet is discovered by the framework by timeouts.
00361 All packets sent reliable are given a timeout. The timeout is calculated
00362 as the average round trip time (RTT) multiplied by a factor chosen
00363 by the game developer. A RTT is the time passed from when a reliable
00364 packet has been sent until we have received its acknowledgement. The
00365 calculation of the average timeout is done with a precision
00366 <A NAME="tex2html7" HREF="#foot142"><SUP>2</SUP></A> decided by the
00367 game developer. When a timeout occurs the packet in question is resent
00368 by the framework. Please note that no negative acknowledgements are
00369 sent back to the game.
00370 
00371 @subsection Queues
00372 At both the sending and the receiving side we maintain queues. At
00373 the sending side for packets waiting to be sent and on the receiving
00374 side for packets waiting to be delivered. These queues are implemented
00375 in such a way that hey have influence on in which order packets are
00376 sent or delivered. Firstly packets which the lowest priority are sent/delivered
00377 first. Then we we look at the sequence number of the packet, then
00378 the type (this means that e.g. system packets are sent/delivered before
00379 other types of packets, see section @ref Packet-formats), then
00380 we look at the ID of the receiving object (receiver on figure @ref The-header-format)
00381 and finally we look at how this packet is to be sent to (client ID)
00382  this last check is only relevant on the server since this last
00383 values always will be the same on the clients, namely 0. This scheme
00384 means that we cannot allow packets with different priority to use the
00385 same sequencer since this would cause the packets to be delivered out
00386 of order (because high priority packets are delivered first. Therefore
00387 we maintain a channel for each priority so that each priority is given
00388 its own sequencer. Furthermore, on the server side each client is
00389 also given its own sequencer. 
00390 
00391 We also allow for unreliable packets to be replaced by newer packets
00392 in the queue. This will happen if an unreliable packet arrives at
00393 the queue with the same priority, type, receiver and client ID as an existing. If
00394 this is the case, we assume that this packet is a newer update of the
00395 same type to the client in question - this is valid for both in- and out-queues.
00396 The sequence number is irrelevant in this, since unreliable packets
00397 are given a sequence number the moment they are sent, and therefore
00398 all have the same sequence number when in the out-queue.
00399 
00400 
00401 @subsection SequenceNumbering Sequence numbering
00402 
00403 @subsubsection Unreliable-Packets Unreliable packets
00404 All unreliable packets sent by the framework with the same priority share the same sequencer.
00405 For every unreliable packet sent the unreliable sequence number is
00406 increased by one. For the server this means that if it sends an unreliable
00407 packet with sequence number J to client X with priority U, the next unreliable packet
00408 it will send will have sequence number J+1 - if this packet is also
00409 sent to client Y and has priority U. This conforms with the description given in section
00410 @ref Unreliable-Packets where we guaranteed at-most-once delivery for
00411 unreliable packets sent with the same priority. 
00412 
00413 @subsubsection ReliablePackets Reliable packets
00414 The scheme for reliable packets is a little more complex. The server
00415 assigns sequencers to the clients in the following way. For each priority
00416 a packet can have it receives on sequencer. This means that each client
00417 are assigned 256 sequencers for priority 0 through 255. So at any
00418 given time each of the priorities may have a different sequence number
00419 as shown on figure @ref sequenceno. The clients use the same
00420 sequencing scheme, however the clients only have one ``client''
00421 which is the server.
00422 
00423 <P>
00424 
00425 <DIV ALIGN="CENTER">
00426 @anchor sequenceno
00427 <TABLE>
00428 <CAPTION ALIGN="BOTTOM"><STRONG>Figure 6:</STRONG>
00429 Reliable packets are given a sequence number
00430 depending on the priority they have and the client they are destined
00431 for.</CAPTION>
00432 <TR><TD><IMG
00433  WIDTH="542" HEIGHT="83" BORDER="0"
00434  SRC="images/img6.png"
00435  ALT="\begin{figure}\begin{center}\begin{tabular}{\vert&gt;{\raggedright }p{1.8cm}\vert&gt;{...
00436 ...&amp;
00437 ...&amp;
00438 150485\tabularnewline
00439 \hline
00440 \end{tabular}\end{center}\par\end{figure}"></TD></TR>
00441 </TABLE>
00442 </DIV>
00443 
00444 @subsubsection SequenceNumberWrap Sequence number wrap
00445 As the framework is implemented wraps are not handled. Wraps occur
00446 when sequence numbers become too large to fit within the data type
00447 they are represented with. For sequence numbers in the framework,
00448 which are represented by unsigned integers, their maximum value is
00449 4,294,967,295. This means that the framework can send 1000 packets per
00450 second before the sequence number wraps after
00451 49.7 days given that the same priority and reliability is used for all
00452 packets - in our framework this
00453 would lead to a in communication since lower sequence numbers are not accepted. If we assume
00454 that all priorities are used equally, the number of days is 12725.8
00455 before the first sequence number wraps.
00456 
00457 
00458 <HR>
00459 <H4>Footnotes</H4>
00460 
00461 <A NAME="foot46"></A><A
00462  HREF="#tex2html2"><SUP>1</SUP></A> http://www.cplusplus.com/doc/tutorial/variables.html
00463 
00464 <A NAME="foot142"></A><A
00465  HREF="#tex2html7"><SUP>2</SUP></A> Precision here meaning the number RTTs to calculate the average on.
00466 
00467 */

Generated on Mon Feb 6 12:24:50 2006 for Ganef by  doxygen 1.4.4