00001 /***************************************************************************** 00002 Copyright (c) 2001 - 2011, The Board of Trustees of the University of Illinois. 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions are 00007 met: 00008 00009 * Redistributions of source code must retain the above 00010 copyright notice, this list of conditions and the 00011 following disclaimer. 00012 00013 * Redistributions in binary form must reproduce the 00014 above copyright notice, this list of conditions 00015 and the following disclaimer in the documentation 00016 and/or other materials provided with the distribution. 00017 00018 * Neither the name of the University of Illinois 00019 nor the names of its contributors may be used to 00020 endorse or promote products derived from this 00021 software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00024 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 00025 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00026 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 00027 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00028 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00029 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00030 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00031 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00032 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00033 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 *****************************************************************************/ 00035 00036 /***************************************************************************** 00037 written by 00038 Yunhong Gu, last updated 01/02/2011 00039 *****************************************************************************/ 00040 00041 #ifndef __UDT_PACKET_H__ 00042 #define __UDT_PACKET_H__ 00043 00044 00045 #include "udt.h" 00046 00047 #ifdef WIN32 00048 struct iovec 00049 { 00050 int iov_len; 00051 char* iov_base; 00052 }; 00053 #endif 00054 00055 class CChannel; 00056 00057 class CPacket 00058 { 00059 friend class CChannel; 00060 friend class CSndQueue; 00061 friend class CRcvQueue; 00062 00063 public: 00064 int32_t& m_iSeqNo; // alias: sequence number 00065 int32_t& m_iMsgNo; // alias: message number 00066 int32_t& m_iTimeStamp; // alias: timestamp 00067 int32_t& m_iID; // alias: socket ID 00068 char*& m_pcData; // alias: data/control information 00069 00070 static const int m_iPktHdrSize; // packet header size 00071 00072 public: 00073 CPacket(); 00074 ~CPacket(); 00075 00076 // Functionality: 00077 // Get the payload or the control information field length. 00078 // Parameters: 00079 // None. 00080 // Returned value: 00081 // the payload or the control information field length. 00082 00083 int getLength() const; 00084 00085 // Functionality: 00086 // Set the payload or the control information field length. 00087 // Parameters: 00088 // 0) [in] len: the payload or the control information field length. 00089 // Returned value: 00090 // None. 00091 00092 void setLength(int len); 00093 00094 // Functionality: 00095 // Pack a Control packet. 00096 // Parameters: 00097 // 0) [in] pkttype: packet type filed. 00098 // 1) [in] lparam: pointer to the first data structure, explained by the packet type. 00099 // 2) [in] rparam: pointer to the second data structure, explained by the packet type. 00100 // 3) [in] size: size of rparam, in number of bytes; 00101 // Returned value: 00102 // None. 00103 00104 void pack(int pkttype, void* lparam = NULL, void* rparam = NULL, int size = 0); 00105 00106 // Functionality: 00107 // Read the packet vector. 00108 // Parameters: 00109 // None. 00110 // Returned value: 00111 // Pointer to the packet vector. 00112 00113 iovec* getPacketVector(); 00114 00115 // Functionality: 00116 // Read the packet flag. 00117 // Parameters: 00118 // None. 00119 // Returned value: 00120 // packet flag (0 or 1). 00121 00122 int getFlag() const; 00123 00124 // Functionality: 00125 // Read the packet type. 00126 // Parameters: 00127 // None. 00128 // Returned value: 00129 // packet type filed (000 ~ 111). 00130 00131 int getType() const; 00132 00133 // Functionality: 00134 // Read the extended packet type. 00135 // Parameters: 00136 // None. 00137 // Returned value: 00138 // extended packet type filed (0x000 ~ 0xFFF). 00139 00140 int getExtendedType() const; 00141 00142 // Functionality: 00143 // Read the ACK-2 seq. no. 00144 // Parameters: 00145 // None. 00146 // Returned value: 00147 // packet header field (bit 16~31). 00148 00149 int32_t getAckSeqNo() const; 00150 00151 // Functionality: 00152 // Read the message boundary flag bit. 00153 // Parameters: 00154 // None. 00155 // Returned value: 00156 // packet header field [1] (bit 0~1). 00157 00158 int getMsgBoundary() const; 00159 00160 // Functionality: 00161 // Read the message inorder delivery flag bit. 00162 // Parameters: 00163 // None. 00164 // Returned value: 00165 // packet header field [1] (bit 2). 00166 00167 bool getMsgOrderFlag() const; 00168 00169 // Functionality: 00170 // Read the message sequence number. 00171 // Parameters: 00172 // None. 00173 // Returned value: 00174 // packet header field [1] (bit 3~31). 00175 00176 int32_t getMsgSeq() const; 00177 00178 // Functionality: 00179 // Clone this packet. 00180 // Parameters: 00181 // None. 00182 // Returned value: 00183 // Pointer to the new packet. 00184 00185 CPacket* clone() const; 00186 00187 protected: 00188 uint32_t m_nHeader[4]; // The 128-bit header field 00189 iovec m_PacketVector[2]; // The 2-demension vector of UDT packet [header, data] 00190 00191 int32_t __pad; 00192 00193 protected: 00194 CPacket& operator=(const CPacket&); 00195 }; 00196 00198 00199 class CHandShake 00200 { 00201 public: 00202 CHandShake(); 00203 00204 int serialize(char* buf, int& size); 00205 int deserialize(const char* buf, int size); 00206 00207 public: 00208 static const int m_iContentSize; // Size of hand shake data 00209 00210 public: 00211 int32_t m_iVersion; // UDT version 00212 int32_t m_iType; // UDT socket type 00213 int32_t m_iISN; // random initial sequence number 00214 int32_t m_iMSS; // maximum segment size 00215 int32_t m_iFlightFlagSize; // flow control window size 00216 int32_t m_iReqType; // connection request type: 1: regular connection request, 0: rendezvous connection request, -1/-2: response 00217 int32_t m_iID; // socket ID 00218 int32_t m_iCookie; // cookie 00219 uint32_t m_piPeerIP[4]; // The IP address that the peer's UDP port is bound to 00220 }; 00221 00222 00223 #endif