資源簡介
來自university of Massachusetts的網絡作業 框架是node0.c DVsim.h DVsim.c,其中有兩個函數需要自己補充,根據自己具體的拓撲圖要修改一些數據結構。

代碼片段和文件信息
/*****************************************************************
* DVsim.c? Distance?Vector?Routing?Simulation?Package
*
* Event?driven?simulation?of?distributed?asynchronous?
* distance?vector?routing.??This?file?contains?the?network
* simulation?code?which?emulates?layer?2?and?below:?
*
*?? -?simulates?packet?tranmissions?between?two?
* ??physically?connected?nodes
*
* -?assumes?with?no?packet?loss?or?corruption
*
*?? -?calls?initializations?routines?rtinit0?etc.?before
*???? ??beginning?simulation
*
*
* Original?code?from?Kurose?and?Ross?Computer?Networking
*
* Modified?by?S.?Dykes? Apr.?2000
* 1.?Changed?RNG?to?use?drand48()?with?seed?=?getpid()
* 2.?Replaced?999?with?INF?
* 3.?created?common?include?file?DVsim.h
* 4.?extended?to?6?node?network?
*
*---------------------------------------------------------------*/
#define DVSIM_H
#include? “DVsim.h“
#include????“time.h“
#define? FROM_layer2?????2
#define? link_CHANGE?????10
/*----------------------------------------
*? Event?list?and?possible?events
*---------------------------------------*/
struct?event?
{
???double evtime;?????????/*?event?time?*/
???int? evtype;?????????/*?event?type?code?*/
???int? eventity;???????/*?entity?where?event?occurs?*/
???struct?rtpkt?*rtpktptr;? /*?ptr?to?packet?(if?any)?assoc?w/?this?event?*/
???struct?event?*prev;
???struct?event?*next;
};
struct?event?*evlist?=?NULL;???
/*--------------------------------
*? Simulation?clock
*-------------------------------*/
double clocktime?=?0.000;
double get_clock()?{?return?clocktime;?}
/*--------------------------------
*? Function?prototypes
*-------------------------------*/
void? init();
void? insertevent?(struct?event?*);
void? printevlist();
void? tolayer2?(struct?rtpkt?);
/*-------------------------------
* MAIN
*-------------------------------*/
main()
{
int?i;
???struct?event?*eventptr;
???
???/*----------------------------------------
???*? Loop?until?we?run?out?of?events
???*---------------------------------------*/
???init();
???while?(1)?
???{
/*----------------------------------------
* Get?next?event?from?top?of?list
*???????Done?if?event?list?is?empty
*---------------------------------------*/
????????if?(!?(eventptr?=?evlist)?)?break;????????????
????????evlist?=?evlist->next;????????
????????if?(evlist)?evlist->prev=NULL;
/*----------------------------------------
* Trace?info
*---------------------------------------*/
????????if?(TRACE>1)?{
???????????printf(“\nMAIN:?rcv?event?t=%.3f?at?%d“?
eventptr->evtime?eventptr->eventity);
???????????if?(eventptr->evtype?==?FROM_layer2?)?{
??????printf(“?src:%2d“??eventptr->rtpktptr->sourceid);
??????????????printf(“?dest:%2d“?eventptr->rtpktptr->destid);
??????????????printf(“?contents:?“);
??????for?(i=0;?irtpktptr->mincost[i]);
??????????????printf(“\n“);
???}
????????}
/*----------------------------------------
* Update?clock?to?next?event?time
*-----------------------------
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2421??2009-11-18?12:51??node3.c
?????文件??????11669??2009-11-18?12:21??DVsim.c
?????文件???????2812??2009-11-18?12:43??DVsim.h
?????文件???????3967??2009-11-18?12:33??node0.c
?????文件???????2421??2009-11-18?12:51??node1.c
?????文件???????2583??2009-11-18?12:51??node2.c
-----------?---------??----------?-----??----
????????????????25873????????????????????6
- 上一篇:MFC DEM內插登高線!!!
- 下一篇:迷宮問題的C++算法實現
評論
共有 條評論