00001 /* -*- mode: c++; c-basic-offset: 3; -*- */ 00002 #ifndef _GDS_FRAMEXMITTYPE_H 00003 #define _GDS_FRAMEXMITTYPE_H 00004 /*----------------------------------------------------------------------*/ 00005 /* */ 00006 /* Module Name: framexmit */ 00007 /* */ 00008 /* Module Description: API for broadcasting frames */ 00009 /* implements a reliable UDP/IP broadcast for */ 00010 /* large data sets over high speed links */ 00011 /* */ 00012 /* Module Arguments: none */ 00013 /* */ 00014 /* Revision History: */ 00015 /* Rel Date Programmer Comments */ 00016 /* 1.0 10Aug99 D. Sigg First release */ 00017 /* */ 00018 /* Documentation References: */ 00019 /* Man Pages: doc/index.html (use doc++) */ 00020 /* References: none */ 00021 /* */ 00022 /* Author Information: */ 00023 /* Name Telephone Fax e-mail */ 00024 /* Daniel Sigg (509) 372-8132 (509) 372-8137 sigg_d@ligo.mit.edu */ 00025 /* */ 00026 /* Code Compilation and Runtime Specifications: */ 00027 /* Code Compiled on: Ultra-Enterprise, Solaris 5.7 */ 00028 /* Compiler Used: egcs-1.1.2 */ 00029 /* Runtime environment: sparc/solaris */ 00030 /* */ 00031 /* Code Standards Conformance: */ 00032 /* Code Conforms to: LIGO standards. OK */ 00033 /* Lint. TBD */ 00034 /* ANSI OK */ 00035 /* POSIX OK */ 00036 /* */ 00037 /* Known Bugs, Limitations, Caveats: */ 00038 /* */ 00039 /* */ 00040 /* */ 00041 /* ------------------- */ 00042 /* */ 00043 /* LIGO */ 00044 /* */ 00045 /* THE LASER INTERFEROMETER GRAVITATIONAL WAVE OBSERVATORY. */ 00046 /* */ 00047 /* (C) The LIGO Project, 1996. */ 00048 /* */ 00049 /* */ 00050 /* California Institute of Technology */ 00051 /* LIGO Project MS 51-33 */ 00052 /* Pasadena CA 91125 */ 00053 /* */ 00054 /* Massachusetts Institute of Technology */ 00055 /* LIGO Project MS NW17-161 */ 00056 /* Cambridge MA 01239 */ 00057 /* */ 00058 /* LIGO Hanford Observatory */ 00059 /* P.O. Box 1970 S9-02 */ 00060 /* Richland WA 99352 */ 00061 /* */ 00062 /* LIGO Livingston Observatory */ 00063 /* 19100 LIGO Lane Rd. */ 00064 /* Livingston, LA 70754 */ 00065 /* */ 00066 /*----------------------------------------------------------------------*/ 00067 00068 // include files 00069 #include <sys/types.h> 00070 #include <netinet/in.h> 00071 #include <inttypes.h> 00072 00073 namespace framexmit { 00074 00075 00082 00084 const int frameXmitPort = 7096; 00086 const unsigned char mcast_TTL = 1; 00088 const int daemonPriority = 1; 00090 const int sndDefaultBuffers = 7; 00092 const int packetSize = 64000; 00094 const int packetBurst = 4; 00096 const int packetBurstInterval = 1000; 00098 const int sndDelayTick = 1000; 00100 const int rcvDelayTick = 1000; 00102 const int maximumRetransmit = 200; 00104 const int sndInBuffersize = 65536; 00106 const int sndOutBuffersize = 4 * 65536; 00108 const int rcvInBuffersize = 4 * 65536; 00110 const int rcvInBufferMax = 16 * 65536; 00112 const int rcvOutBuffersize = 65536; 00114 const int rcvpacketbuffersize = 1024; 00116 const int maxRetry = 5; 00118 const int retryTimeout = 250000; 00120 const int maxSequenceOutOfSync = 5; 00122 const double retransmissionAverage = 10.1; 00124 const double rcvErrorRate = 0; 00125 00127 const int PKT_BROADCAST = 123; 00129 const int PKT_REBROADCAST = 124; 00131 const int PKT_REQUEST_RETRANSMIT = 125; 00132 00134 struct packetHeader { 00136 int32_t pktType; 00138 int32_t pktLen; 00140 uint32_t seq; 00142 int32_t pktNum; 00144 int32_t pktTotal; 00146 uint32_t checksum; 00148 uint32_t timestamp; 00150 uint32_t duration; 00152 inline void hton(); 00154 inline void ntoh(); 00155 }; 00156 00158 struct packet { 00160 packetHeader header; 00162 char payload[packetSize]; 00164 inline void hton(); 00166 inline void ntoh(); 00167 }; 00168 00170 struct retransmitpacket { 00172 packetHeader header; 00174 int32_t pktResend[packetSize / sizeof (int32_t)]; 00176 inline void hton(); 00178 inline void ntoh(); 00179 }; 00180 00181 00186 class auto_pkt_ptr { 00187 private: 00188 packet* ptr; 00189 mutable bool owns; 00190 public: 00191 00197 explicit auto_pkt_ptr (packet* p = 0) : ptr(p), owns(p) { 00198 } 00199 00205 auto_pkt_ptr (const auto_pkt_ptr& a) : ptr(a.ptr), owns(a.owns) { 00206 a.owns = 0; 00207 } 00208 00214 auto_pkt_ptr& operator= (const auto_pkt_ptr& a) { 00215 if (&a != this) { 00216 if (owns) 00217 delete ptr; 00218 owns = a.owns; 00219 ptr = a.ptr; 00220 a.owns = 0; 00221 } 00222 return *this; 00223 } 00224 00227 ~auto_pkt_ptr() { 00228 if (owns) 00229 delete ptr; 00230 } 00231 00234 packet& operator*() const { 00235 return *ptr; } 00236 00239 packet* operator->() const { 00240 return ptr; } 00241 00244 packet* get() const { 00245 return ptr; } 00246 00249 packet* release() const { 00250 owns = false; 00251 return ptr; } 00252 00255 bool operator== (const auto_pkt_ptr& a) const { 00256 if (!owns || !a.owns) { 00257 return false; 00258 } 00259 return ((ptr->header.seq == a.ptr->header.seq) && 00260 (ptr->header.pktNum == a.ptr->header.pktNum)); 00261 } 00262 00265 bool operator< (const auto_pkt_ptr& a) const { 00266 if (!owns || !a.owns) { 00267 return owns; 00268 } 00269 return ((ptr->header.seq < a.ptr->header.seq) || 00270 ((ptr->header.seq == a.ptr->header.seq) && 00271 (ptr->header.pktNum < a.ptr->header.pktNum))); 00272 } 00273 }; 00274 00275 inline void packetHeader::hton() 00276 { 00277 pktType = htonl (pktType); 00278 pktLen = htonl (pktLen); 00279 seq = htonl (seq); 00280 pktNum = htonl (pktNum); 00281 pktTotal = htonl (pktTotal); 00282 checksum = htonl (checksum); 00283 timestamp = htonl (timestamp); 00284 duration = htonl (duration); 00285 } 00286 00287 inline void packetHeader::ntoh() 00288 { 00289 pktType = ntohl (pktType); 00290 pktLen = ntohl (pktLen); 00291 seq = ntohl (seq); 00292 pktNum = ntohl (pktNum); 00293 pktTotal = ntohl (pktTotal); 00294 checksum = ntohl (checksum); 00295 timestamp = ntohl (timestamp); 00296 duration = ntohl (duration); 00297 } 00298 00299 inline void packet::hton() 00300 { 00301 // payload not swapped 00302 header.hton(); 00303 } 00304 00305 inline void packet::ntoh() 00306 { 00307 header.ntoh(); 00308 // payload not swapped 00309 } 00310 00311 inline void retransmitpacket::hton() 00312 { 00313 for (int i = 0; i < header.pktLen/(int)sizeof(int32_t); ++i) 00314 pktResend[i] = htonl (pktResend[i]); 00315 header.hton(); 00316 } 00317 00318 inline void retransmitpacket::ntoh() 00319 { 00320 header.ntoh(); 00321 for (int i = 0; i < header.pktLen/(int)sizeof(int32_t); ++i) 00322 pktResend[i] = ntohl (pktResend[i]); 00323 } 00324 00328 } 00329 00330 #endif // _GDS_FRAMEXMITTYPE_H
1.5.4