📄 cbr_client.pc
字号:
#ifdef EXCEL /* Remove statistic file formatted for excel. */ remove(APP_CBR_CLIENT_FILE); #endif clientPtr = AppCbrClientNewCbrClient(nodePtr, serverAddr, itemsToSend, itemSize, interval, startTime, endTime); if (clientPtr == NULL) { printf("CBR Client: Node %ld cannot allocate memory for new client\n", nodePtr->nodeAddr); assert(FALSE); } timerMsg = GLOMO_MsgAlloc(nodePtr, GLOMO_APP_LAYER, APP_CBR_CLIENT, MSG_APP_TimerExpired); GLOMO_MsgInfoAlloc(nodePtr, timerMsg, sizeof(AppTimer)); timer = (AppTimer *)GLOMO_MsgReturnInfo(timerMsg); timer->uniqueId = clientPtr->uniqueId; timer->type = APP_TIMER_SEND_PKT; #ifdef DEBUG ctoa(startTime, clockStr); printf("CBR Client: Node %ld starting client at %s\n", nodePtr->nodeAddr, clockStr); #endif GLOMO_MsgSend(nodePtr, timerMsg, startTime);}/* * NAME: AppCbrClientPrintStats. * PURPOSE: Prints statistics of a CbrClient session. * PARAMETERS: nodePtr - pointer to the this node. * clientPtr - pointer to the cbr client data structure. * RETURN: none. */void AppCbrClientPrintStats(GlomoNode *nodePtr, GlomoAppCbrClient *clientPtr) { FILE *excel = NULL; clocktype throughput; char clockStr[GLOMO_MAX_STRING_LENGTH]; char startStr[GLOMO_MAX_STRING_LENGTH]; char closeStr[GLOMO_MAX_STRING_LENGTH]; char sessionStatusStr[GLOMO_MAX_STRING_LENGTH]; char throughputStr[GLOMO_MAX_STRING_LENGTH]; char buf[GLOMO_MAX_STRING_LENGTH]; #ifdef EXCEL excel = fopen(APP_CBR_CLIENT_FILE, "a"); if (excel == NULL) { fprintf(stderr, "CBR Client: cannot open excel file.\n"); assert(FALSE); } #endif GLOMO_PrintClockInSecond(clientPtr->sessionStart, startStr); GLOMO_PrintClockInSecond(clientPtr->sessionLastSent, closeStr); if (clientPtr->sessionIsClosed == FALSE) { clientPtr->sessionFinish = simclock(); sprintf(sessionStatusStr, "Not closed"); } else { sprintf(sessionStatusStr, "Closed"); } if (clientPtr->sessionFinish <= clientPtr->sessionStart) { throughput = 0; } else { throughput = (clientPtr->numBytesSent * 8.0 * SECOND) / (clientPtr->sessionFinish - clientPtr->sessionStart); } ctoa(throughput, throughputStr); sprintf(buf, "(%d) Server address: %d", clientPtr->uniqueId, clientPtr->remoteAddr); GLOMO_PrintStat(nodePtr, "AppCbrClient", buf); sprintf(buf, "(%d) First packet sent at [s]: %s", clientPtr->uniqueId, startStr); GLOMO_PrintStat(nodePtr, "AppCbrClient", buf); sprintf(buf, "(%d) Last packet sent at [s]: %s", clientPtr->uniqueId, closeStr); GLOMO_PrintStat(nodePtr, "AppCbrClient", buf); sprintf(buf, "(%d) Session status: %s", clientPtr->uniqueId, sessionStatusStr); GLOMO_PrintStat(nodePtr, "AppCbrClient", buf); sprintf(buf, "(%d) Total number of bytes sent: %ld", clientPtr->uniqueId, clientPtr->numBytesSent); GLOMO_PrintStat(nodePtr, "AppCbrClient", buf); sprintf(buf, "(%d) Total number of packets sent: %ld", clientPtr->uniqueId, clientPtr->numPktsSent); GLOMO_PrintStat(nodePtr, "AppCbrClient", buf); sprintf(buf, "(%d) Throughput (bits per second): %s", clientPtr->uniqueId, throughputStr); GLOMO_PrintStat(nodePtr, "AppCbrClient", buf); #ifdef EXCEL fprintf(excel, "%ld\t%ld\t%d\t%s\t%s\t%ld\t%ld\t%s\n", clientPtr->localAddr, clientPtr->remoteAddr, clientPtr->uniqueId, startStr, closeStr, clientPtr->numBytesSent, clientPtr->numPktsSent, throughputStr); fflush(excel); fclose(excel); #endif}/* * NAME: AppCbrClientFinalize. * PURPOSE: Collect statistics of a CbrClient session. * PARAMETERS: nodePtr - pointer to the node. * clientPtr - pointer to the cbr client data structure. * RETURN: none. */voidAppCbrClientFinalize(GlomoNode *nodePtr, GlomoAppCbrClient *clientPtr){ if (nodePtr->appData.appStats == TRUE) { AppCbrClientPrintStats(nodePtr, clientPtr); }}/* * NAME: AppCbrClientGetCbrClient. * PURPOSE: search for a cbr client data structure. * PARAMETERS: nodePtr - pointer to the node. * uniqueId - connection ID of the cbr client. * RETURN: the pointer to the cbr client data structure, * NULL if nothing found. */static GlomoAppCbrClient *AppCbrClientGetCbrClient(GlomoNode *nodePtr, int uniqueId){ AppInfo *appList = nodePtr->appData.appPtr; GlomoAppCbrClient *cbrClient; for (; appList != NULL; appList = appList->appNext) { if (appList->appType == APP_CBR_CLIENT) { cbrClient = (GlomoAppCbrClient *) appList->appDetail; if (cbrClient->uniqueId == uniqueId) { return cbrClient; } } } return NULL;}/* * NAME: AppCbrClientNewCbrClient. * PURPOSE: create a new cbr client data structure, place it * at the beginning of the application list. * PARAMETERS: nodePtr - pointer to the node. * remoteAddr - remote address. * itemsToSend - number of cbr items to send in simulation. * itemSize - size of each packet. * interval - time between two packets. * startTime - when the node will start sending. * RETURN: the pointer to the created cbr client data structure, * NULL if no data structure allocated. */static GlomoAppCbrClient *AppCbrClientNewCbrClient(GlomoNode *nodePtr, NODE_ADDR remoteAddr, long itemsToSend, long itemSize, clocktype interval, clocktype startTime, clocktype endTime){ char clockStr[GLOMO_MAX_STRING_LENGTH]; AppInfo *newApp; GlomoAppCbrClient *cbrClient; newApp = (AppInfo *) pc_malloc(sizeof(AppInfo)); if (newApp == NULL) { printf("CBR Client: Node %d unable to allocate AppInfo\n", nodePtr->nodeAddr); assert(FALSE); } cbrClient = (GlomoAppCbrClient *) pc_malloc(sizeof(GlomoAppCbrClient)); if (cbrClient == NULL) { printf("CBR Client: Node %d unable to allocate cbr client structure\n", nodePtr->nodeAddr); assert(FALSE); } /* * fill in cbr info. */ newApp->appType = APP_CBR_CLIENT; cbrClient->localAddr = nodePtr->nodeAddr; cbrClient->remoteAddr = remoteAddr; cbrClient->interval = interval; cbrClient->sessionStart = simclock() + startTime; cbrClient->sessionIsClosed = FALSE; cbrClient->sessionLastSent = simclock(); cbrClient->sessionFinish = simclock(); cbrClient->endTime = endTime; cbrClient->numBytesSent = 0; cbrClient->numPktsSent = 0; cbrClient->itemsToSend = itemsToSend; cbrClient->itemSize = itemSize; cbrClient->uniqueId = nodePtr->appData.uniqueId++; cbrClient->seqNo = 0; #ifdef DEBUG printf("CBR Client: Node %ld created new cbr client structure\n", nodePtr->nodeAddr); printf(" localAddr = %ld\n", cbrClient->localAddr); printf(" remoteAddr = %ld\n", cbrClient->remoteAddr); ctoa(cbrClient->interval, clockStr); printf(" interval = %s\n", clockStr); ctoa(cbrClient->sessionStart, clockStr); printf(" sessionStart = %s\n", clockStr); printf(" numBytesSent = %ld\n", cbrClient->numBytesSent); printf(" numPktsSent = %ld\n", cbrClient->numPktsSent); printf(" itemsToSend = %ld\n", cbrClient->itemsToSend); printf(" itemSize = %ld\n", cbrClient->itemSize); printf(" uniqueId = %ld\n", cbrClient->uniqueId); printf(" seqNo = %ld\n", cbrClient->seqNo); #endif newApp->appDetail = cbrClient; newApp->appNext = nodePtr->appData.appPtr; nodePtr->appData.appPtr = newApp; return cbrClient;}/* * NAME: AppCbrClientScheduleNextPkt. * PURPOSE: schedule the next packet the client will send. If next packet * won't arrive until the finish deadline, schedule a close. * PARAMETERS: nodePtr - pointer to the node, * clientPtr - pointer to the cbr client data structure. * RETRUN: none. */static voidAppCbrClientScheduleNextPkt(GlomoNode *nodePtr, GlomoAppCbrClient *clientPtr){ char clockStr[GLOMO_MAX_STRING_LENGTH]; AppTimer *timer; long layer; Message *timerMsg; timerMsg = GLOMO_MsgAlloc(nodePtr, GLOMO_APP_LAYER, APP_CBR_CLIENT, MSG_APP_TimerExpired); GLOMO_MsgInfoAlloc(nodePtr, timerMsg, sizeof(AppTimer)); timer = (AppTimer *)GLOMO_MsgReturnInfo(timerMsg); timer->uniqueId = clientPtr->uniqueId; timer->type = APP_TIMER_SEND_PKT; #ifdef DEBUG printf("CBR Client: Node %ld scheduling next data packet\n", nodePtr->nodeAddr); printf(" timer type is %d\n", timer->type); ctoa(clientPtr->interval, clockStr); printf(" interval is %s\n", clockStr); #endif GLOMO_MsgSend(nodePtr, timerMsg, clientPtr->interval);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -