Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 #ifndef _LIB_BULK_IO_H
00026 #define _LIB_BULK_IO_H
00027 
00028 #if defined(solaris)
00029 #include <stdio.h>
00030 #include <errno.h>
00031 #include <sys/types.h>
00032 #include <sys/stat.h>
00033 #include <fcntl.h>
00034 #include <netdb.h>
00035 #include <sys/types.h>
00036 #include <sys/socket.h>
00037 #include <netinet/in.h>
00038 #include <sys/time.h>
00039 #include <unistd.h>
00040 #include <sys/mman.h>
00041 
00042 #include <netinet/in_systm.h>
00043 
00044 #include "P_InkBulkIO.h"
00045 
00046 struct InkBulkIOState
00047 {
00048   int biofd;
00049   void *sharedBuffer;
00050   int sharedBufferSize;
00051   InkBulkIOFreeBlockInfo_t freeList;
00052   struct InkBulkIOBlock *blockInfo;
00053   int numBlocks;
00054 };
00055 
00056 struct InkBulkIOSplit
00057 {
00058   char *header;
00059   int nbytes;
00060   struct InkBulkIOAddrInfo dest;
00061 };
00062 
00063 struct InkBulkIOAggregator
00064 {
00065   InkBulkIOAggregator()
00066   {
00067     metaReqCount = 0;
00068     metablockInfo.ptr = NULL;
00069     metablockInfo.id = 0xffffffff;
00070     metablockReqPtr = NULL;
00071 
00072     lastReqFragCount = 0;
00073     lastReq = NULL;
00074     reqblockInfo.ptr = NULL;
00075     reqblockInfo.id = 0xffffffff;
00076     reqblockPktPtr = NULL;
00077 
00078   };
00079   struct InkBulkIOBlock metablockInfo;
00080   
00081   uint32_t *metablockReqPtr;
00082   uint32_t metaReqCount;
00083   struct InkBulkIOBlock reqblockInfo;
00084   
00085   struct InkBulkIOPkt *reqblockPktPtr;
00086   
00087   uint32_t lastReqFragCount;
00088   struct InkBulkIORequest *lastReq;
00089   void ResetLastRequestInfo()
00090   {
00091     lastReqFragCount = 0;
00092     lastReq = NULL;
00093     reqblockInfo.ptr = NULL;
00094     reqblockInfo.id = 0xffffffff;
00095     reqblockPktPtr = NULL;
00096   };
00097   void ResetMetaBlockInfo()
00098   {
00099     metaReqCount = 0;
00100     metablockInfo.ptr = NULL;
00101     metablockInfo.id = 0xffffffff;
00102     metablockReqPtr = NULL;
00103   };
00104   bool AppendLastRequest()
00105   {
00106     if (metaReqCount >= INKBIO_MAX_REQS_PER_REQ_BLOCK)
00107       return false;
00108 
00109     memcpy(metablockReqPtr, &(reqblockInfo.id), sizeof(uint32_t));
00110     metablockReqPtr++;
00111     metaReqCount++;
00112     return true;
00113   };
00114   void TerminateMetaBlock()
00115   {
00116     *metablockReqPtr = 0xffffffff;
00117   };
00118   void TerminateLastRequest()
00119   {
00120     reqblockPktPtr->blockID = 0xffffffff;
00121     reqblockPktPtr->pktsize = 0xffff;
00122     reqblockPktPtr->inChain = 0;
00123     reqblockPktPtr->reserved = 0;
00124   };
00125   void InitMetaBlock()
00126   {
00127     metablockReqPtr = (uint32_t *) metablockInfo.ptr;
00128     metaReqCount = 0;
00129   };
00130   void InitSendtoReqBlock()
00131   {
00132     reqblockPktPtr = (struct InkBulkIOPkt *)
00133       ((caddr_t) reqblockInfo.ptr + sizeof(InkBulkIORequest));
00134     lastReq = (struct InkBulkIORequest *) reqblockInfo.ptr;
00135     lastReq->reqType = INKBIO_SENDTO_REQUEST;
00136     lastReq->request.sendto.pktCount = 0;
00137     lastReqFragCount = 0;
00138   };
00139   void InitSplitReqBlock()
00140   {
00141     reqblockPktPtr = (struct InkBulkIOPkt *)
00142       ((caddr_t) reqblockInfo.ptr + sizeof(InkBulkIORequest));
00143     lastReq = (struct InkBulkIORequest *) reqblockInfo.ptr;
00144     lastReq->reqType = INKBIO_SPLIT_REQUEST;
00145     lastReq->request.split.recvCount = 0;
00146     lastReq->request.split.perDestHeader = 0;
00147     lastReqFragCount = 0;
00148   };
00149 
00150 };
00151 
00152 
00153 
00154 
00155 struct InkBulkIOState *BulkIOInit(int blockcount);
00156 void BulkIOClose(struct InkBulkIOState *bioCookie);
00157 
00158 int BulkIOBlkAlloc(struct InkBulkIOState *bioCookie, int blkCount, struct InkBulkIOBlock *bioResult);
00159 
00160 int BulkIOAddPkt(struct InkBulkIOState *bioCookie,
00161                  struct InkBulkIOAggregator *bioAggregator, UDPPacketInternal * pkt, int sourcePort);
00162 
00163 int BulkIOSplitPkt(struct InkBulkIOState *bioCookie,
00164                    struct InkBulkIOAggregator *bioAggregator, UDPPacketInternal * pkt, int sourcePort);
00165 
00166 int BulkIOAppendToReqBlock(struct InkBulkIOState *bioCookie,
00167                            struct InkBulkIOAggregator *bioAggregator, Ptr<IOBufferBlock> pkt);
00168 
00169 void BulkIORequestComplete(struct InkBulkIOState *bioCookie, struct InkBulkIOAggregator *bioAggregator);
00170 
00171 void BulkIOFlush(struct InkBulkIOState *bioCookie, struct InkBulkIOAggregator *bioAggregator);
00172 
00173 void CopyFromIOBufferBlock(char *dest, Ptr<IOBufferBlock> pktChain, uint32_t nbytes);
00174 #endif
00175 
00176 #endif