00001 /* 00002 * Copyright (C) 2009, Edmundo Albuquerque de Souza e Silva. 00003 * 00004 * This file may be distributed under the terms of the Q Public License 00005 * as defined by Trolltech AS of Norway and appearing in the file 00006 * LICENSE.QPL included in the packaging of this file. 00007 * 00008 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING 00009 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00010 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, 00011 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 00012 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00013 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 00014 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00015 * 00016 * Thanks: Jose Renato Santos 00017 * 00018 */ 00019 00020 /////////////////////////////////////////////////////////////////////////////// 00021 // msgrouterstorage.h: Defines format for messages exchanged between 00022 // router and storage server 00023 /////////////////////////////////////////////////////////////////////////////// 00024 00025 00026 /////////////////////////////////////////////////////////////////////////////// 00027 // 00028 // ROUTER/STORAGE_SERVER MESSAGES 00029 // ============================== 00030 // 00031 // a) The router can send two types of messages to the storage server 00032 // 1) Data requests 00033 // 2) Parameter request 00034 // 00035 // b) There are 6 types of data request messages: 00036 // 00037 // 1) Read: read data from device and send result through network 00038 // (equivalent to fetch+send) 00039 // 2) Write: receive data from network and write to device 00040 // (equivalent to receive+flush) 00041 // 3) Fetch: read data from device into buffer but do not send it yet 00042 // 4) Receive: receive data from network into buffer but do no write it yet 00043 // 5) Send: send data in buffer through network 00044 // 6) Flush: write data in buffer to the device 00045 // 00046 // For requests of type 1 (read) and 2 (write) there is an additional 00047 // bit on the message code that causes status messages (ack) to be 00048 // be sent to the router after the operation is partially completed 00049 // i.e. after data is received from client (write) or data 00050 // is read from device to buffer (read). All requests causes the storage 00051 // server to send a status message (ack) when the request is completed. 00052 // 00053 // c) There are 2 types of parameter request messages: 00054 // 1) Node information: request parameters global to storage node 00055 // 2) Disk information: request parameters for a specific disk 00056 // 00057 // STORAGE SERVER MESSAGES 00058 // ======================= 00059 // 00060 // a) The storage server can send two types of messages to the router 00061 // 1) Data request status 00062 // Sent after request is completed or partially completed 00063 // 2) Parameter information 00064 // Sent in response to a router info request 00065 // 00066 // b) There are 5 types of data request status messages: 00067 // 1) Read complete: Device read operation completed 00068 // response to requests: Read (optional), and Fetch 00069 // 2) Write complete: Device write operation completed 00070 // response to requests: Write, and Flush 00071 // 3) Receive complete: Data received from client 00072 // response to requests: Write(optional), and Receive 00073 // 4) Send complete: Data sent to client 00074 // response to requests: Read, and Send 00075 // 5) Ready: request accepted and buffer to hold data allocated to it 00076 // Used only for write and receive requests. Used to tell router 00077 // that storage server is ready to receive data from client 00078 // In general, a request can be accepted and the storage server 00079 // may have to wait until buffer space becomes available 00080 // for performing the operation. That does not require any 00081 // special treatment for read operations, but for writes 00082 // it does. The client should not attempt to send 00083 // data before storage server is ready to receive it. 00084 // This message is used to solve this problem. 00085 // 00086 // c) There are 2 types of parameter information messages: 00087 // 1) Node information: inform router about global parameters of storage 00088 // server 00089 // (response to node information request message) 00090 // 2) Disk information: inform router about parameters for a specific disk 00091 // (response to disk information request message) 00092 // 00093 //////////////////////////////////////////////////////////////////////////// 00094 00095 #ifndef __MSGROUTEERSTORAGE_H_ 00096 #define __MSGROUTEERSTORAGE_H_ 00097 00098 // Integer types 00099 #include "vsitypesint.h" 00100 // Definicao de MaxPathSize 00101 #include "RioInterfaceTypes.h" 00102 00103 // Fixed token value, used while security not implemeted. 00104 const u32 RSS_TOKEN_STORAGE = 0x583Af206; 00105 const u32 RSS_TOKEN_ROUTER = 0x72A092F5; 00106 00107 00108 /////////////////////////////////////////////////////////////////////////////// 00109 //********************** From router to storage server **********************// 00110 /////////////////////////////////////////////////////////////////////////////// 00111 00112 //Request messages 00113 00114 // Read data and send result to target 00115 #define MSG_RSS_READ 0x1 00116 // Receive data from source and write to disk 00117 #define MSG_RSS_WRITE 0x2 00118 // Read data from disk to buffer 00119 #define MSG_RSS_FETCH 0x3 00120 // Receive data from source, store on buffer 00121 #define MSG_RSS_RECEIVE 0x4 00122 // Send data from buffer to target 00123 #define MSG_RSS_SEND 0x5 00124 // Flush data in buffer to disk 00125 #define MSG_RSS_FLUSH 0x6 00126 00127 // Cancel data in buffer 00128 #define MSG_RSS_CANCEL 0x7 00129 00130 // ---------------------------------------------------------------------------- 00131 00132 // Request message codes are bit ORed with the following bits 00133 00134 // Do not send final completion message 00135 #define RSS_NOCOMPLETE 0x20 00136 // Send intermediate completion messag usefull only for read and write messages 00137 // (send status message after fetching data from device or receiving data 00138 // from client, respectivelly) 00139 #define RSS_INTERMEDIATE 0x10 00140 00141 00142 // Control Messages 00143 00144 // Request storage node information 00145 #define MSG_RSS_NODEINFO_REQ 0x101 00146 // Request disk information 00147 #define MSG_RSS_DISKINFO_REQ 0x102 00148 00149 // Request disk service time information 00150 #define MSG_RSS_DISKSERVICETIMEINFO_REQ 0x103 00151 00152 // Informations for initialization of the storages 00153 #define MSG_RSS_INITIALIZATION_REQ 0x104 00154 00155 // Start a search in the storage logs. 00156 #define MSG_RSS_START_SEARCH_IN_LOGS_REQ 0x105 00157 00158 // Request a block of a file with a result of an search in the logs. 00159 #define MSG_RSS_BLOCK_SEARCH_FILE_REQ 0x106 00160 00161 // Remove a file with a result of an search in the logs. 00162 #define MSG_RSS_REMOVE_SEARCH_FILE_REQ 0x107 00163 00164 00165 00166 // ---------------------------------------------------------------------------- 00167 00168 /////////////////////////////////////////////////////////////////////////////// 00169 //********************* From storage server to router ***********************// 00170 /////////////////////////////////////////////////////////////////////////////// 00171 00172 // Request status messages (ack) 00173 // In fact all these can be negative acknowledge (Status field in message 00174 // indicates success (0) or error code(<0) ) 00175 // Device read operation completed 00176 #define MSG_RSS_READCOMPLETE 0x801 00177 // Device write operation completed 00178 #define MSG_RSS_WRITECOMPLETE 0x802 00179 // Data receiving operation completed 00180 #define MSG_RSS_RECEIVECOMPLETE 0x804 00181 // Data transmission oper. completed 00182 #define MSG_RSS_SENDCOMPLETE 0x805 00183 // Request ready (accepted with buffer allocated) if status is OK 00184 // (also used for error report if status is not OK (0) ) 00185 #define MSG_RSS_READY 0x806 00186 00187 // buffer free, cancel complete 00188 #define MSG_RSS_CANCELCOMPLETE 0x807 00189 // ---------------------------------------------------------------------------- 00190 00191 // Control Messages 00192 00193 // Node Information 00194 #define MSG_RSS_NODEINFO 0x901 00195 // Disk Information 00196 #define MSG_RSS_DISKINFO 0x902 00197 00198 // Disk Service Time Information 00199 #define MSG_RSS_DISKSERVICETIMEINFO 0x903 00200 00201 // Initialization confirmation of the storages 00202 #define MSG_RSS_CONFIRMATION 0x904 00203 00204 #ifdef RIO_DEBUG2 00205 // Result of the search logs operations (0x105-0x107). Only used for depuration 00206 // purposes. 00207 #define MSG_RSS_SEARCHLOGS_STATUS 0x905 00208 #endif 00209 00210 // ---------------------------------------------------------------------------- 00211 00212 ///////////////////////////// Message format ////////////////////////////////// 00213 00214 // Header format. These fields are present at the begining 00215 // of all messages 00216 struct MsgRSSheader 00217 { 00218 u16 Type; // Message type 00219 u16 Size; // Message size in bytes 00220 u32 Token; // security token. Fixed value for now (RSS_FIXED_TOKEN) 00221 }; 00222 00223 /////////////////////////////////////////////////////////////////////////////// 00224 //********************** From router to storage server **********************// 00225 /////////////////////////////////////////////////////////////////////////////// 00226 00227 /////////////////////////////////////////////////////////////////////////////// 00228 // Request messages: 00229 00230 struct MsgRSSnewRequest 00231 { 00232 u16 Type; // Message type: MSG_RSS_READ, MSG_RSS_WRITE, 00233 // MSG_RSS_FETCH, MSG_RSS_RECEIVE 00234 u16 Size; // Message size in bytes (36) 00235 u32 Token; // security token. Fixed value for now (RSS_FIXED_TOKEN) 00236 u32 ClientId; // Request Id in Client space 00237 u32 RouterId; // Request Id in Router space 00238 u32 IPaddr; // Target IP address 00239 u16 Port; // Target Port 00240 u16 Disk; // Disk Number 00241 u64 Pos; // Position on Disk of first byte to be accessed 00242 // (in bytes) 00243 u32 DataSize; // Data size (in bytes) 00244 /*Modified by Bernardo(not send ack)*/ 00245 u16 StreamTraffic; // Stream Type 00246 // Modificacao usada pela implementacao do controle de fluxo. Um novo 00247 // campo para enviar a taxa de envio do video ao servidor de armazenamento. 00248 u32 VideoRate; 00249 }; 00250 00251 const int SizeMsgRSSnewRequest = sizeof( MsgRSSnewRequest ); 00252 00253 struct MsgRSSpendRequest 00254 { 00255 u16 Type; // Message type: MSG_RSS_SEND, MSG_RSS_FLUSH 00256 u16 Size; // Message size in bytes (16) 00257 u32 Token; // security token. Fixed value for now (RSS_FIXED_TOKEN) 00258 u32 StorageId; // Request Id in Storage Server space (identify Buffer) 00259 u32 RouterId; // Request Id in Router space 00260 00261 // added to support buffers ------------------------------------ 00262 u32 ClientId; // Request Id in Client space 00263 u32 IPaddr; // Target IP address 00264 u16 Port; // Target Port 00265 // ------------------------------------------------------------------------ 00266 /*Modified by Bernardo(not send ack)*/ 00267 u16 StreamTraffic; // Stream Type 00268 // Modificacao usada pela implementacao do controle de fluxo. Um novo 00269 // campo para enviar a taxa de envio do video ao servidor de armazenamento. 00270 u32 VideoRate; 00271 }; 00272 00273 const int SizeMsgRSSpendRequest = sizeof( MsgRSSpendRequest ); 00274 00275 typedef union 00276 { 00277 MsgRSSheader Header; 00278 MsgRSSnewRequest New; 00279 MsgRSSpendRequest Pending; 00280 }MsgRSSrequest; 00281 00282 00283 /////////////////////////////////////////////////////////////////////////////// 00284 // Control messages 00285 00286 struct MsgRSSnodeInfoReq 00287 { 00288 u16 Type; // Message type: MSG_RSS_NODEINFO_REQ 00289 u16 Size; // Message size in bytes (8) 00290 u32 Token; // security token. Fixed value for now (RSS_FIXED_TOKEN) 00291 }; 00292 00293 const int SizeMsgRSSnodeInfoReq = sizeof( MsgRSSnodeInfoReq ); 00294 00295 struct MsgRSSdiskInfoReq 00296 { 00297 u16 Type; // Message type: MSG_RSS_DISKINFO_REQ, 00298 u16 Size; // Message size in bytes (10) 00299 u32 Token; // security token. Fixed value for now (RSS_FIXED_TOKEN) 00300 u16 Disk; // Disk number (Index at Storage Node) 00301 }; 00302 00303 const int SizeMsgRSSdiskInfoReq = sizeof( MsgRSSdiskInfoReq ); 00304 00305 struct MsgRSSdiskServiceTimeInfoReq 00306 { 00307 u16 Type; // Message type: MSG_RSS_DISKINFO_REQ, 00308 u16 Size; // Message size in bytes (10) 00309 u32 Token; // security token. Fixed value for now (RSS_FIXED_TOKEN) 00310 u16 Disk; // Disk number (Index at Storage Node) 00311 u16 DiskId; // Global Disk number (global index) 00312 }; 00313 00314 const int SizeMsgRSSdiskServiceTimeInfoReq = sizeof( MsgRSSdiskServiceTimeInfoReq ); 00315 00316 struct MsgRSSInitializationReq 00317 { 00318 u16 Type; // Message type: MSG_RSS_INITIALIZATION, 00319 u16 Size; // Message size in bytes (12) 00320 u32 Token; // security token. Fixed value for now (RSS_FIXED_TOKEN) 00321 u32 BlockSize; // Disk Block Size 00322 }; 00323 00324 const int SizeMsgRSSInitializationReq = sizeof( MsgRSSInitializationReq ); 00325 00326 struct MsgRSSStartSearchInLogsReq 00327 { 00328 u16 Type; // Message type: MSG_RSS_START_SEARCH_IN_LOGS_REQ, 00329 u16 Size; // Message size in bytes (30) 00330 u32 Token; // security token. Fixed value for now (RSS_FIXED_TOKEN) 00331 u16 SearchType; // Type of search in logs. 00332 u32 StartTime; // Start Time in the logs. 00333 u32 EndTime; // End Time in the logs. 00334 u32 IPaddr; // Target IP address 00335 u16 Port; // Target Port 00336 u32 ClientId; // Request Id in Client space. 00337 }; 00338 00339 const int SizeMsgRSSStartSearchInLogsReq = sizeof( MsgRSSStartSearchInLogsReq ); 00340 00341 struct MsgRSSBlockSearchFileReq 00342 { 00343 u16 Type; // Message type: MSG_RSS_BLOCK_SEARCH_FILE_REQ, 00344 u16 Size; // Message size in bytes (30) 00345 u32 Token; // security token. Fixed value for now (RSS_FIXED_TOKEN) 00346 u32 IPaddr; // Target IP address 00347 u16 Port; // Target Port 00348 u64 FileId; // Search result file id. 00349 u32 Block; // Block number 00350 u32 ClientId; // Request Id in Client space. 00351 }; 00352 00353 const int SizeMsgRSSBlockSearchFileReq = sizeof( MsgRSSBlockSearchFileReq ); 00354 00355 struct MsgRSSRemoveSearchFileReq 00356 { 00357 u16 Type; // Message type: MSG_RSS_REMOVE_SEARCH_FILE_REQ, 00358 u16 Size; // Message size in bytes (16) 00359 u32 Token; // security token. Fixed value for now (RSS_FIXED_TOKEN) 00360 u64 FileId; // Search result file id. 00361 }; 00362 00363 const int SizeMsgRSSRemoveSearchFileReq = sizeof( MsgRSSRemoveSearchFileReq ); 00364 00365 // ---------------------------------------------------------------------------- 00366 00367 // Type used to refer to all types of messages sent by router 00368 typedef union 00369 { 00370 MsgRSSheader Header; 00371 MsgRSSrequest Request; 00372 MsgRSSnodeInfoReq NodeInfo; 00373 MsgRSSdiskInfoReq DiskInfo; 00374 MsgRSSdiskServiceTimeInfoReq DiskServiceTimeInfo; 00375 MsgRSSInitializationReq Initialization; 00376 MsgRSSStartSearchInLogsReq StartSearchInLogs; 00377 MsgRSSBlockSearchFileReq BlockSearchFile; 00378 MsgRSSRemoveSearchFileReq RemoveSearchFile; 00379 }MsgRSSrouter; 00380 00381 const int SizeMsgRSSrouter = sizeof( MsgRSSrouter ); 00382 00383 /////////////////////////////////////////////////////////////////////////////// 00384 //********************* From storage server to router ***********************// 00385 /////////////////////////////////////////////////////////////////////////////// 00386 const s32 ERROR_RSS_INVALID_DISK = -1; 00387 const s32 ERROR_RSS_INVALID_POSITION = -2; 00388 const s32 ERROR_RSS_INVALID_DATASIZE = -3; 00389 const s32 ERROR_RSS_MAX_REQUEST = -4; 00390 const s32 ERROR_RSS_INVALID_REQUESTID = -5; 00391 const s32 ERROR_RSS_IO_FAILED = -6; 00392 const s32 ERROR_RSS_SEND_FAILED = -7; 00393 const s32 ERROR_RSS_RECEIVE_FAILED = -8; 00394 00395 /////////////////////////////////////////////////////////////////////////////// 00396 // Status messages: 00397 00398 struct MsgRSSstatus 00399 { 00400 u16 Type; // Message type: MSG_RSS_READCOMPLETE, 00401 // MSG_RSS_WRITECOMPLETE, 00402 // MSG_RSS_SENDCOMPLETE, 00403 // MSG_RSS_RECEIVECOMPLETE, 00404 // MSG_RSS_RECEIVED, 00405 u16 Size; // Message size in bytes (16) 00406 u32 Token; // security token. Fixed value for now (RSS_FIXED_TOKEN) 00407 u32 RouterId; // Request Id in Router space 00408 u32 StorageId; // Request Id in Storage space 00409 s32 Error; // Error code (0: OK; <0: error) 00410 00411 int ActiveThreads; // Number of active threads when the request 00412 // was submitted to the disk used for read and fetch 00413 // operations 00414 }; 00415 00416 const int SizeMsgRSSstatus = sizeof( MsgRSSstatus ); 00417 00418 /////////////////////////////////////////////////////////////////////////////// 00419 // Control response messages: 00420 struct MsgRSSnodeInfo 00421 { 00422 u16 Type; // Message type: MSG_RSS_NODEINFO 00423 u16 Size; // Message size in bytes (28) 00424 u32 Token; // security token. Fixed value for now (RSS_FIXED_TOKEN) 00425 u32 nDisks; // Number of disks (only 16 lower bits are used) 00426 u32 FragSize; // Size #include "RioInterfaceTypes.h"of buffer fragment (in bytes) 00427 u32 BufferSize; // Storage Server Buffer size (in number of fragments) 00428 u32 MaxReqSize; // Maximum Request Size (in number of fragments) 00429 u32 MaxReq; // Maximum number of requests (excess requests are 00430 // rejected) 00431 }; 00432 00433 const int SizeMsgRSSnodeInfo = sizeof( MsgRSSnodeInfo ); 00434 00435 struct MsgRSSdiskInfo 00436 { 00437 u16 Type; // Message type: MSG_RSS_DISKINFO 00438 u16 Size; // Message size in bytes (20) 00439 u32 Token; // security token. Fixed value for now (RSS_FIXED_TOKEN) 00440 u64 DiskSize; // Disk Size (in sectors) 00441 u16 Disk; // Disk number ( a number between 0 and nDisks) 00442 u16 SectorSize; // Sector size of physical device (mimimum transfer unit) 00443 // (0 indicates disk does not exist) 00444 00445 char DiskName[ MaxPathSize ]; // Device Name - to support df command 00446 // Mudanca para usar um caminho com o 00447 // tamanho maximo (este valor ja era o 00448 // maximo, 256, mas antes tambem era igual a 00449 // 40). 00450 }; 00451 00452 const int SizeMsgRSSdiskInfo = sizeof( MsgRSSdiskInfo ); 00453 00454 struct MsgRSSdiskServiceTimeInfo 00455 { 00456 u16 Type; // Message type: MSG_RSS_DISKINFO 00457 u16 Size; // Message size in bytes (20) 00458 u32 Token; // security token.Fixed value for now (RSS_FIXED_TOKEN) 00459 u16 Disk; // Disk number (Index at Storage Node) 00460 u16 DiskId; // Global Disk number (global index) 00461 double EstimatedDiskServTime; // Average disk service time 00462 double EstimatedServTimeAccT[301]; // Average disk service time according 00463 // number of active threads 00464 }; 00465 00466 const int SizeMsgRSSdiskServiceTimeInfo = sizeof( MsgRSSdiskServiceTimeInfo ); 00467 00468 struct MsgRSSConfirmation 00469 { 00470 u16 Type; // Message type: MSG_RSS_CONFIRMATION 00471 u16 Size; // Message size in bytes (8) 00472 u32 Token; // security token.Fixed value for now (RSS_FIXED_TOKEN) 00473 }; 00474 00475 const int SizeMsgRSSConfirmation = sizeof( MsgRSSConfirmation ); 00476 00477 #ifdef RIO_DEBUG2 00478 struct MsgRSSSearchLogsStatus 00479 { 00480 u16 Type; // Message type: MSG_RSS_SEARCHLOGS_STATUS 00481 u16 Size; // Message size in bytes (18) 00482 u32 Token; // security token.Fixed value for now (RSS_FIXED_TOKEN) 00483 u32 IPaddr; // Target IP address 00484 u16 Port; // Target Port 00485 u16 StatusType; // Tipo da mensagem que gerou o estado. 00486 u32 ClientId; // Request Id in Client space. 00487 s32 Error; // Error code (0: OK; <0: error) 00488 }; 00489 00490 const int SizeMsgRSSSearchLogsStatus = sizeof( MsgRSSSearchLogsStatus ); 00491 #endif 00492 00493 // Type used to refer to all types of messages sent by storage server 00494 typedef union 00495 { 00496 MsgRSSheader Header; 00497 MsgRSSstatus Status; 00498 MsgRSSnodeInfo NodeInfo; 00499 MsgRSSdiskInfo DiskInfo; 00500 MsgRSSdiskServiceTimeInfo DiskServiceTimeInfo; 00501 MsgRSSConfirmation Confirmation; 00502 #ifdef RIO_DEBUG2 00503 MsgRSSSearchLogsStatus SearchLogsStatus; 00504 #endif 00505 } MsgRSSstorage; 00506 00507 const int SizeMsgRSSstorage = sizeof( MsgRSSstorage ); 00508 00509 // Type used to refer to all types of messages sent by either 00510 // the router or storage server 00511 typedef union 00512 { 00513 MsgRSSheader Header; 00514 MsgRSSrouter Router; 00515 MsgRSSstorage Storage; 00516 }MsgRSS; 00517 00518 const int SizeMsgRSS = sizeof( MsgRSS ); 00519 00520 #endif // __MSGROUTERSTORAGE_H_