📄 cbr_client.pc
字号:
/* -*- Mode: C; -*- */ /* * GloMoSim is COPYRIGHTED software. Release 2.02 of GloMoSim is available * at no cost to educational users only. * * Commercial use of this software requires a separate license. No cost, * evaluation licenses are available for such purposes; please contact * info@scalable-networks.com * * By obtaining copies of this and any other files that comprise GloMoSim2.02, * you, the Licensee, agree to abide by the following conditions and * understandings with respect to the copyrighted software: * * 1.Permission to use, copy, and modify this software and its documentation * for education and non-commercial research purposes only is hereby granted * to Licensee, provided that the copyright notice, the original author's * names and unit identification, and this permission notice appear on all * such copies, and that no charge be made for such copies. Any entity * desiring permission to use this software for any commercial or * non-educational research purposes should contact: * * Professor Rajive Bagrodia * University of California, Los Angeles * Department of Computer Science * Box 951596 * 3532 Boelter Hall * Los Angeles, CA 90095-1596 * rajive@cs.ucla.edu * * 2.NO REPRESENTATIONS ARE MADE ABOUT THE SUITABILITY OF THE SOFTWARE FOR ANY * PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. * * 3.Neither the software developers, the Parallel Computing Lab, UCLA, or any * affiliate of the UC system shall be liable for any damages suffered by * Licensee from the use of this software. */// Use the latest version of Parsec if this line causes a compiler error./* * $Id: cbr_client.pc,v 1.13 2001/02/15 03:17:26 mineo Exp $ * * Updated for AODV IETF Draft version 13 by Vrishali Wagle * (vrishali@cs.ucsb.edu) */#include <stdlib.h>#include <stdio.h>#include <string.h>#include <assert.h>#include "api.h"#include "structmsg.h"#include "fileio.h"#include "message.h"#include "application.h"#include "app_util.h"#include "cbr_client.h"#define noDEBUG#define noEXCEL/* * NAME: AppLayerCbrClient. * PURPOSE: Models the behaviour of CbrClient Client on receiving the * message encapsulated in msg. * PARAMETERS: nodePtr - pointer to the node which received the message. * msg - message received by the layer * RETURN: none. */voidAppLayerCbrClient(GlomoNode *nodePtr, Message *msg){ char clockStr[GLOMO_MAX_STRING_LENGTH]; char buf[GLOMO_MAX_STRING_LENGTH]; GlomoAppCbrClient *clientPtr; ctoa(simclock(), buf); #ifdef DEBUG printf("CBR Client: Node %ld got a message at %s\n", nodePtr->nodeAddr, buf); #endif switch(msg->eventType) { case MSG_APP_TimerExpired: { AppTimer *timer; timer = (AppTimer *) GLOMO_MsgReturnInfo(msg); #ifdef DEBUG printf("CBR Client: Node %ld at %s got timer %d\n", nodePtr->nodeAddr, buf, timer->type); #endif clientPtr = AppCbrClientGetCbrClient(nodePtr, timer->uniqueId); if (clientPtr == NULL) { printf("CBR Client: Node %ld cannot find cbr client\n", nodePtr->nodeAddr); assert(FALSE); } switch (timer->type) { case APP_TIMER_SEND_PKT: { char payload[MAX_APP_DATA_UNIT]; GlomoAppCbrData data; long layer; if(clientPtr->sessionIsClosed==TRUE) { return; } memset(payload, 0, MAX_APP_DATA_UNIT); #ifdef DEBUG printf("CBR Client: Node %ld has %ld items " "left to send\n", nodePtr->nodeAddr, clientPtr->itemsToSend); #endif if (((clientPtr->itemsToSend > 1) && (simclock() + clientPtr->interval < clientPtr->endTime)) || ((clientPtr->itemsToSend == 0) && (simclock() + clientPtr->interval < clientPtr->endTime)) || ((clientPtr->itemsToSend > 1) && (clientPtr->endTime == 0)) || ((clientPtr->itemsToSend == 0) && (clientPtr->endTime == 0))) { data.type = 'd'; } else { data.type = 'c'; clientPtr->sessionIsClosed = TRUE; clientPtr->sessionFinish = simclock(); } data.uniqueId = clientPtr->uniqueId; data.txTime = simclock(); data.seqNo = clientPtr->seqNo++; memcpy(payload, &data, sizeof(data)); #ifdef DEBUG ctoa(simclock(), clockStr); printf("CBR Client: node %ld sending data packet" " at time %s to CBR server %ld\n", nodePtr->nodeAddr, clockStr, clientPtr->remoteAddr); printf(" size of payload is %d\n", clientPtr->itemSize); #endif AppUdpSendNewDataWithPriority(nodePtr, APP_CBR_SERVER, clientPtr->remoteAddr, payload, clientPtr->itemSize, REAL_TIME, 0); clientPtr->numBytesSent += clientPtr->itemSize; clientPtr->numPktsSent++; clientPtr->sessionLastSent = simclock(); if (clientPtr->itemsToSend > 0) { clientPtr->itemsToSend--; } if (clientPtr->sessionIsClosed == FALSE) { AppCbrClientScheduleNextPkt(nodePtr, clientPtr); } break; } default: assert(FALSE); } break; } case MSG_AODV_CBR_DestinationUnreachable: { AppInfo *appList = nodePtr->appData.appPtr; GlomoAppCbrClient *cbrClient; NODE_ADDR *destAddr; destAddr = (NODE_ADDR*)GLOMO_MsgReturnInfo(msg); for (; appList != NULL; appList = appList->appNext) { if (appList->appType == APP_CBR_CLIENT) { cbrClient = (GlomoAppCbrClient *) appList->appDetail; if (cbrClient->remoteAddr == *destAddr) { cbrClient->sessionIsClosed = TRUE; cbrClient->sessionFinish = simclock(); //schedule event to retry after some time } } } break; } default: ctoa(simclock(), buf); printf("CBR Client: at time %s, node %ld " "received message of unknown type" " %ld.\n", buf, nodePtr->nodeAddr, msg->eventType); assert(FALSE); } GLOMO_MsgFree(nodePtr, msg);}/* * NAME: AppCbrClientInit. * PURPOSE: Initialize a CbrClient session. * PARAMETERS: nodePtr - pointer to the node, * serverAddr - address of the server, * itemsToSend - number of items to send, * itemSize - size of each packet, * interval - interval of packet transmission rate. * startTime - time until the session starts, * endTime - time until the session ends, * RETURN: none. */voidAppCbrClientInit(GlomoNode *nodePtr, NODE_ADDR serverAddr, long itemsToSend, long itemSize, clocktype interval, clocktype startTime, clocktype endTime){ char clockStr[GLOMO_MAX_STRING_LENGTH]; AppTimer *timer; GlomoAppCbrClient *clientPtr; long layer; Message *timerMsg; int minSize; minSize = sizeof(GlomoAppCbrData); /* Check to make sure the number of cbr items is a correct value. */ if (itemsToSend < 0) { printf("CBR Client: Node %ld item to sends needs to be >= 0\n", nodePtr->nodeAddr); exit(0); } /* Make sure that packet is big enough to carry cbr data information. */ if (itemSize < minSize) { printf("CBR Client: Node %ld item size needs to be >= %d.\n", nodePtr->nodeAddr, minSize); exit(0); } /* Make sure that packet is within max limit. */ if (itemSize > MAX_APP_DATA_UNIT) { printf("CBR Client: Node %ld item size needs to be <= %d.\n", nodePtr->nodeAddr, MAX_APP_DATA_UNIT); exit(0); } /* Make sure interval is valid. */ if (interval <= 0) { printf("CBR Client: Node %ld interval needs to be > 0.\n", nodePtr->nodeAddr); exit(0); } /* Make sure start time is valid. */ if (startTime < 0) { printf("CBR Client: Node %ld start time needs to be >= 0.\n", nodePtr->nodeAddr); exit(0); } /* Check to make sure the end time is a correct value. */ if (!((endTime > startTime) || (endTime == 0))) { printf("CBR Client: Node %ld end time needs to be > start time " "or equal to 0.\n", nodePtr->nodeAddr); exit(0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -