/* this program compute the algorithm that the LBA periodically send the probe packet */ #include #include #include #include #include #include #include #include /* following parameters are about the network */ #define LIGHTSPEED 299796.0 /* km/sec */ #define REFRACINDEX 1.4; #define NODELEN 3 #define MAXPNL 30 #define MAX_NODE_NUM 100 #define MAX_AL_LEN 10 #define MAX_TABLE_LEN 100 #define MAX_PATH_NUM 100 #define MAX_WEB_NUM 50 #define MAX_LBA_NUM 20 /* max LBA number */ #define MAX_CLIENT_NUM 50 /* maximum client number */ #define MAX_EVENT_NUM 100000 /* maximum event number */ #define MAX_FILE_TYPE 7 #define ICMPLBAH 34 #define ICMPW 38 #define TOTALEVENT 10000 #define PROPOWER 10000 /* mean 1000 bps */ #define Req_Msg_Size 145 /* bit here is fixed part for example: GET /Stuff/Funny/stilly.html HTTP/1.0 User-agent: NCSA Mosaic for the X Window System/2.5 Accept: text/plain Accept: text/html Accept: application/postscript Accept: image/gif here except of the URL Stuffy/still.html we account rest part as 50 bits because execpt this part, UML and other optinal message, so the Request-Msg-Size = 145 + ( 1~50) randomly number */ #define Resp_Msg 175 /* 175 just for the imformation 175 + actually document size */ /* we account the 175 from example: HTTP/1.0 Status 200 Document follows Server: NCSA/1.4 Date: tue, 4 Jul, 1776 19:17:05 GMT Content-type: text-html Content-length: 5280 Last-modified: Web, 1 Jan 1776 01:00:02 GMT because we can not exactly account the msg, 175+Docoment size + (1~10 random number ) */ #define TCPheader 20; #define UDPheader 8; /* notice uniform all unit bandwitch kps process power kps header bit msg bit document kB distance km */ /* table contains all directly link information */ typedef struct Table { char dest[NODELEN]; /* directly destination node */ float tran_speed; /* bandwitch */ float distance; /* distance */ } table; /* table contains path information */ typedef struct Path { char name[20]; /* path name, put all node name that path passes together */ float totallen; /* total distance */ float avebw; /* total bandwitch */ float totaldelay; /* total time delay */ char dest[5]; int hopnum; } path; /* client information */ typedef struct ClientInfor { char id[NODELEN]; }clientinfor; typedef struct WebInfor { char id[NODELEN]; float prospeed; int loadnum; float accumload; }webinfor; typedef struct Node { char id[NODELEN]; char type[1]; float Prospeed; float time; int linkcount; table tableinfor[MAX_TABLE_LEN]; path pathtable[MAX_PATH_NUM]; int pathnum; webinfor webtable[MAX_WEB_NUM]; int webnum; path webpath[MAX_LBA_NUM]; int clientnum; int subnetnum; clientinfor clienttable[MAX_CLIENT_NUM]; path clientpath[MAX_CLIENT_NUM]; float clientlist[MAX_CLIENT_NUM][10]; int clientid; int TurNum; float accumload; int loadnum; int timeinter; float sload; /* this do not change */ int sloadnum; }node; typedef struct Pack{ float size; char dest[4]; char send[4]; float headerbit; int msgbit; float docubit; char lbaid[4]; } pack; typedef struct erec { float time; char src[4]; pack packinfor; char type[1]; char pathname[10]; float betime; int msg; int clientid; char nextnode[4]; char dest_node[4]; int pathid; }erec; typedef struct enode { float idx; erec e; int num; struct enode *next; } enode; typedef struct file_struct { int id; char type[10]; } filetype; /* here all variable is global variable */ node NodeList[MAX_NODE_NUM]; int al_type;/*here mean the type of algorithm MAX_AL_LEN mean the algorithm length*/ int netsize,totalnode; time_t ltime; struct tm *local; enode eventlist[MAX_EVENT_NUM]; int Eventnum; float TotalResponseTime; filetype filelist[10]; int timeinter = 5; float wpdelay; float pdelay; float rpdelay; float wqdelay; float rqdelay; float qdelay; float trdelay; float prodelay; float lbaqudelay; float totaldelay; int eventcount; int extraevents; float extratime; /* *********** function ******************* */ /****************************************************** print event infor /******************************************************/ /* void print_oneevent(enode *oneevent, FILE *fp) { int dummy,ind1; fprintf(fp,"Event send: "); for(ind1=0;ind1<3;ind1++) fprintf(fp,"%c",oneevent->e.packinfor.send[ind1]); fprintf(fp,"\n"); fprintf(fp,"Event size: %f\n",oneevent->e.packinfor.size); fprintf(fp,"Event type: %c\n",oneevent->e.type[0]); fprintf(fp,"Event Next Node:\n"); for(ind1=0;ind1<3;ind1++) fprintf(fp,"%c",oneevent->e.src[ind1] ); fprintf(fp,"\n"); dummy=strlen( oneevent->e.pathname); fprintf(fp,"Event path:"); for(ind1=0;ind1e.pathname[ind1] ); fprintf(fp,"\n"); fprintf(fp,"Event start: %f\n",oneevent->e.starttime); fprintf(fp,"Event current time: %f\n",oneevent->idx); fprintf(fp,"Event msg: %d\n",oneevent->e.msg); fprintf(fp,"Event size: %d\n",oneevent->e.packinfor.size); } */ /********************************************************** print eventlist /**********************************************************/ /* void print_event( FILE *fp ) { int index,dummy,ind1; fprintf(fp,"Event Num: %d\n",Eventnum); for(index=1;index<=Eventnum;index++) { fprintf(fp,"Event Num: %d\n\n",eventlist[index].num); fprintf(fp,"Event send: "); for(ind1=0;ind1<3;ind1++) fprintf(fp,"%c",eventlist[index].e.packinfor.send[ind1]); fprintf(fp,"\n"); fprintf(fp,"Event size: %f\n",eventlist[index].e.packinfor.size); fprintf(fp,"Event type: %c\n",eventlist[index].e.type[0]); fprintf(fp,"Event Next Node: "); for(ind1=0;ind1<3;ind1++) fprintf(fp,"%c",eventlist[index].e.src[ind1] ); fprintf(fp,"\n"); dummy=strlen( eventlist[index].e.pathname); fprintf(fp,"Event path: "); for(ind1=0;ind1 oneevent->idx) break; } eventlist[index]=*oneevent; for(ind1=index;ind1<=Eventnum-1;ind1++) eventlist[ind1+1]=temp[ind1]; } } int getwebnum() { int num,index; num=0; for(index=1;index<=totalnode;index++) { if(NodeList[index].type[0]=='W') num++; } return num; } int getsubnetnum() { int num,index; num=0; for(index=1;index<=totalnode;index++) { if(NodeList[index].type[0]=='S') num++; } return num; } /* this function is initialed the event node */ void init_eventnode(enode *oneevent) { int ind1,dummy; oneevent->idx=0.0; oneevent->e.time=0.0; oneevent->e.type[0]=' '; dummy=strlen(oneevent->e.src); for(ind1=0;ind1e.src[ind1]=' '; dummy=strlen(oneevent->e.pathname); for(ind1=0;ind1e.pathname[ind1]=' '; } /* this procedure get all parameters */ void getpathpara( int index, int ind1,float *distance, int *hopnum, float *avebw) { int ind2,dummy2,flag,ind3,ind4; int count; char name[4],dummy[40]; int number,flag1,hop; float dis, avbw; dummy2=strlen(NodeList[index].pathtable[ind1].name); /* get the hop */ count=0; hop=0; dis=0; avbw=0; for(ind2=0;ind2=dummy2) break; for(ind4=flag1;ind4e.clientid][2]< oneevent->idx) NodeList[index].clientlist[oneevent->e.clientid][2]=oneevent->idx; else oneevent->idx=NodeList[index].clientlist[oneevent->e.clientid][2]; oneevent->e.type[0]='R'; oneevent->e.betime=oneevent->idx; dummy3=oneevent->idx; /* what kind file type */ oneevent->e.msg=rand()%10+1; oneevent->e.time=0.0; len=strlen(NodeList[index].id); for(ind2=0;ind2e.src[ind2]=NodeList[index].id[ind2]; /* msg sender */ len=strlen(NodeList[index].id); for(ind2=0;ind2e.packinfor.send[ind2]=NodeList[index].id[ind2]; /* msg header and msg size */ oneevent->e.packinfor.headerbit=TCPheader; oneevent->e.packinfor.msgbit=145+( rand()%50+1 ); /* total Msg size header+msg */ oneevent->e.packinfor.size=oneevent->e.packinfor.headerbit/((float)1000)+ oneevent->e.packinfor.msgbit/((float)1000); /* time msg reach the router */ temptime5=oneevent->e.packinfor.size/NodeList[index].clientlist[oneevent->e.clientid][3]; pdelay=pdelay+temptime5; oneevent->idx = temptime5+oneevent->idx; oneevent->e.time = oneevent->e.time+temptime5; temptime= NodeList[index].clientlist[oneevent->e.clientid][1]/LIGHTSPEED/REFRACINDEX; prodelay=prodelay+temptime; temptime2 = oneevent->e.packinfor.size/NodeList[index].clientlist[oneevent->e.clientid][0]; trdelay=trdelay+temptime2; oneevent->idx = temptime + temptime2 + oneevent->idx; oneevent->e.time=oneevent->e.time + temptime + temptime2; inser_event( oneevent); if(eventcount<=TOTALEVENT) { interval=rand()%10; eventstart =time_interval(interval); nextevent.e.type[0]='G'; nextevent.e.clientid=oneevent->e.clientid; for(ind2=0;ind2<3;ind2++) nextevent.e.src[ind2]=NodeList[index].id[ind2]; for(ind2=0;ind2<3;ind2++) nextevent.e.pathname[ind2]=oneevent->e.pathname[ind2]; nextevent.idx= dummy3 + eventstart; inser_event( &nextevent); eventcount++; } } void init_event() { int ind1,ind2; int index; int Lbanum; int interval; float sttime; enode oneevent; Lbanum=netsize; for( index=1;index<=netsize;index++) { if(NodeList[index].type[0]=='S') { Lbanum++; for( ind1=1;ind1<=NodeList[index].clientnum;ind1++) { eventcount++; oneevent.num=eventcount; interval=rand()%10; sttime =time_interval(interval); oneevent.e.type[0]='G'; oneevent.e.clientid=ind1; for(ind2=0;ind2<3;ind2++) oneevent.e.src[ind2]=NodeList[index].id[ind2]; for(ind2=0;ind2<3;ind2++) oneevent.e.pathname[ind2]=NodeList[Lbanum].id[ind2]; oneevent.idx=sttime; oneevent.e.betime=sttime; oneevent.e.time=sttime; inser_event( &oneevent); init_eventnode(&oneevent); } } } } /**************************************************** this function get a event /****************************************************/ enode get_event() { int index; enode oneevent; if(Eventnum!=0) { oneevent=eventlist[1]; Eventnum=Eventnum-1; for(index=1;index<=Eventnum;index++) eventlist[index]=eventlist[index+1]; return oneevent; } else { printf("Program finish!\n"); exit(0); } } void TNNC_2_algorithm( enode *oneevent, int index) { int ind1,webnumm,dummy; static float distf,avebwf,prospeedf; static int hopf,webloadf; float choice1,choice2, loadt; char name1[4]; int flag,ind2; float dummy2; dummy2=NodeList[index].webtable[1].loadnum/NodeList[index].webtable[1].prospeed; choice1=dummy2; webnumm=1; for(ind1=2;ind1<=NodeList[index].webnum;ind1++) { dummy2=NodeList[index].webtable[ind1].loadnum/NodeList[index].webtable[ind1].prospeed; choice2=dummy2; if(choice1 > choice2) { choice1=choice2; webnumm=ind1; } } /* copy the path from the LBA to the Web */ dummy=strlen(NodeList[index].pathtable[webnumm].name); for(ind1=0;ind1e.pathname[ind1]=NodeList[index].pathtable[webnumm].name[ind1]; for(ind1=0;ind1<3;ind1++) name1[ind1]=NodeList[index].pathtable[webnumm].dest[ind1]; flag=0; for(ind1=1;ind1<=totalnode;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[ind1].id[ind2]==name1[ind2]) flag++; if(flag==3) break; else flag=0; } loadt=getfile(oneevent->e.msg); NodeList[ind1].accumload=NodeList[ind1].accumload+loadt; NodeList[ind1].loadnum=NodeList[ind1].loadnum++; NodeList[ind1].sload=NodeList[ind1].sload+loadt; NodeList[ind1].sloadnum=NodeList[ind1].sloadnum++; NodeList[index].webtable[webnumm].accumload=NodeList[index].webtable[webnumm].accumload+loadt; NodeList[index].webtable[webnumm].loadnum=NodeList[index].webtable[webnumm].loadnum+1; } void TNNC_1_algorithm( enode *oneevent, int index) { int ind1,webnumm,dummy; static float distf,avebwf,prospeedf; static int hopf,webloadf; float choice1,choice2, loadt; char name[4]; int flag,ind2; float dummy2,dummy3,dummy4; dummy2=NodeList[index].webtable[1].loadnum/NodeList[index].webtable[1].prospeed; dummy4=NodeList[index].pathtable[1].totallen/NodeList[index].pathtable[1].avebw; choice1=dummy2+dummy4+NodeList[index].pathtable[1].hopnum; webnumm=1; for(ind1=2;ind1<=NodeList[index].webnum;ind1++) { dummy2=NodeList[index].webtable[ind1].loadnum/NodeList[index].webtable[ind1].prospeed; dummy3=NodeList[index].pathtable[ind1].totallen/NodeList[index].pathtable[ind1].avebw; choice2=dummy2+dummy3+NodeList[index].pathtable[ind1].hopnum; if(choice1 > choice2) { choice1=choice2; webnumm=ind1; } } /* copy the path from the LBA to the Web */ dummy=strlen(NodeList[index].pathtable[webnumm].name); for(ind1=0;ind1e.pathname[ind1]=NodeList[index].pathtable[webnumm].name[ind1]; for(ind1=0;ind1<3;ind1++) name[ind1]=NodeList[index].pathtable[webnumm].dest[ind1]; flag=0; for(ind1=1;ind1<=totalnode;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[ind1].id[ind2]==name[ind2]) flag++; if(flag==3) break; else flag=0; } loadt=getfile(oneevent->e.msg); NodeList[ind1].accumload=NodeList[ind1].accumload+loadt; NodeList[ind1].loadnum=NodeList[ind1].loadnum++; NodeList[ind1].sload=NodeList[ind1].sload+loadt; NodeList[ind1].sloadnum=NodeList[ind1].sloadnum++; NodeList[index].webtable[webnumm].accumload=NodeList[index].webtable[webnumm].accumload+loadt; NodeList[index].webtable[webnumm].loadnum=NodeList[index].webtable[webnumm].loadnum+1; } /************************************************************ this procedure calculate that look for the table, but un connected with Web and LBA are not connected /************************************************************/ void TNNC_algorithm( enode *oneevent, int index) { int ind1,webnumm,dummy; static float distf,avebwf,prospeedf; static int hopf,webloadf; float choice1,choice2, loadt; char name1[4]; int flag,ind2; float dummy2,dummy3; dummy2=NodeList[index].pathtable[1].totaldelay+NodeList[index].webtable[1].loadnum/NodeList[index].webtable[1].prospeed; /* if(NodeList[index].pathtable[1].totaldelay>0) { printf("88\n"); } */ choice1=dummy2; webnumm=1; for(ind1=2;ind1<=NodeList[index].webnum;ind1++) { dummy3=NodeList[index].pathtable[ind1].totaldelay+NodeList[index].webtable[ind1].loadnum/NodeList[index].webtable[ind1].prospeed; choice2=dummy3; if(choice1 > choice2) { choice1=choice2; webnumm=ind1; } } /* copy the path from the LBA to the Web */ dummy=strlen(NodeList[index].pathtable[webnumm].name); for(ind1=0;ind1e.pathname[ind1]=NodeList[index].pathtable[webnumm].name[ind1]; for(ind1=0;ind1<3;ind1++) name1[ind1]=NodeList[index].pathtable[webnumm].dest[ind1]; flag=0; for(ind1=1;ind1<=totalnode;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[ind1].id[ind2]==name1[ind2]) flag++; if(flag==3) break; else flag=0; } loadt=getfile(oneevent->e.msg); NodeList[ind1].accumload=NodeList[ind1].accumload+loadt; NodeList[ind1].loadnum=NodeList[ind1].loadnum++; NodeList[ind1].sload=NodeList[ind1].sload+loadt; NodeList[ind1].sloadnum=NodeList[ind1].sloadnum++; NodeList[index].webtable[webnumm].accumload=NodeList[index].webtable[webnumm].accumload+loadt; NodeList[index].webtable[webnumm].loadnum=NodeList[index].webtable[webnumm].loadnum+1; } void R_algorithm(enode *oneevent,int index) { int temp,ind1,ind2,ind3,dummy; int flag=0; char name[4]; float loadt; int webnnum; /* NodeList[].TurNum means the RR number which web sit is assigned */ webnnum=getwebnum(); temp=rand() % webnnum+1; /* copy the path from the LBA to the Web */ dummy=strlen(NodeList[index].pathtable[temp].name); for(ind1=0;ind1e.pathname[ind1]=NodeList[index].pathtable[temp].name[ind1]; for(ind1=0;ind1<3;ind1++) name[ind1]=NodeList[index].pathtable[temp].dest[ind1]; flag=0; for(ind1=1;ind1<=totalnode;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[ind1].id[ind2]==name[ind2]) flag++; if(flag==3) break; else flag=0; } loadt=getfile(oneevent->e.msg); NodeList[ind1].accumload=NodeList[ind1].accumload+loadt; NodeList[ind1].loadnum=NodeList[ind1].loadnum++; NodeList[ind1].sload=NodeList[ind1].sload+loadt; NodeList[ind1].sloadnum=NodeList[ind1].sloadnum++; } /* this load balance algorithm */ void RR_algorithm(enode *oneevent,int index) { int temp,ind1,ind2,ind3,dummy; int flag=0; char name[4]; float loadt; static int webid; int webnnum; /* NodeList[].TurNum means the RR number which web sit is assigned */ webnnum=getwebnum(); webid++; if(webid>webnnum) webid=1; temp=webid; /* copy the path from the LBA to the Web */ dummy=strlen(NodeList[index].pathtable[temp].name); for(ind1=0;ind1e.pathname[ind1]=NodeList[index].pathtable[temp].name[ind1]; for(ind1=0;ind1<3;ind1++) name[ind1]=NodeList[index].pathtable[temp].dest[ind1]; flag=0; for(ind1=1;ind1<=totalnode;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[ind1].id[ind2]==name[ind2]) flag++; if(flag==3) break; else flag=0; } loadt=getfile(oneevent->e.msg); NodeList[ind1].accumload=NodeList[ind1].accumload+loadt; NodeList[ind1].loadnum=NodeList[ind1].loadnum++; NodeList[ind1].sload=NodeList[ind1].sload+loadt; NodeList[ind1].sloadnum=NodeList[ind1].sloadnum++; } void Tc_algorithm(oneevent) { } void Detail_algorithm(oneevent) { } /* compute CPU time */ float cal_time() { float temtime; gettime( <ime ); /* Get time as long integer. */ local = localtime( <ime ); /* Convert to local time. */ temtime=local->tm_hour+local->tm_min; return temtime; } /* this function address a web address */ void LBA_process(int index,enode *oneevent, FILE *fp ) { float times,fintime; float temtime,temtime1,temtime2; int ind1,dummy; int ind2,flag,ind3; char dummy5[3]; float qudelay; enode newevent; /* call CPU time for allocate address start */ times=cal_time(); /* call function to compute the address */ if( al_type==202 ) RR_algorithm(oneevent,index); else if(al_type==203) TNNC_algorithm(oneevent,index); else if( al_type==201 ) R_algorithm(oneevent,index); else if(al_type==204) TNNC_2_algorithm(oneevent, index); else if(al_type==205) TNNC_1_algorithm(oneevent, index); /* compute finish time, so we know how long the allocate to cost */ fintime=cal_time(); temtime1=(fintime-times)/NodeList[index].Prospeed; pdelay=pdelay+temtime1; /* remeber the the initial event time */ temtime=oneevent->idx; qudelay=NodeList[index].time-oneevent->idx; /* update the event time */ if(NodeList[index].time > oneevent->idx) { qdelay=qdelay+qudelay; lbaqudelay=lbaqudelay+qudelay; oneevent->idx=oneevent->idx + qudelay +temtime1; oneevent->e.time=oneevent->e.time+qudelay+temtime1; } else if(NodeList[index].time<=oneevent->idx) { oneevent->idx=oneevent->idx+temtime1; oneevent->e.time=oneevent->e.time+temtime1; } /* get the next node that will process this event along the path */ for(ind1=0;ind1<3;ind1++) dummy5[ind1]=oneevent->e.pathname[ind1]; /* delete the node from the path */ dummy=strlen(oneevent->e.pathname); for(ind1=0;ind1e.pathname[ind1]=oneevent->e.pathname[ind1+3]; /* find the link and send this event to next node */ flag=0; for(ind1=1;ind1<=NodeList[index].linkcount;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[index].tableinfor[ind1].dest[ind2]==dummy5[ind2]) flag++; if(flag==3) break; else flag=0; } /* update the event time */ temtime1=NodeList[index].tableinfor[ind1].distance/LIGHTSPEED/REFRACINDEX; prodelay=prodelay+temtime1; temtime2=oneevent->e.packinfor.size/NodeList[index].tableinfor[ind1].tran_speed; oneevent->idx=oneevent->idx+temtime1+temtime2; oneevent->e.time=oneevent->e.time+temtime1+temtime2; trdelay=trdelay+temtime2; /* update the event receive */ for(ind1=0;ind1<3;ind1++) oneevent->e.src[ind1]=dummy5[ind1]; /* insert event queue */ inser_event(oneevent); /* update the local time */ if(NodeList[index].time==0) NodeList[index].time=temtime + (fintime-times)/NodeList[index].Prospeed; else if(NodeList[index].timetemtime) NodeList[index].time=NodeList[index].time + (fintime-times)/NodeList[index].Prospeed; if ( NodeList[index].time > NodeList[index].timeinter) { for(ind1=1;ind1<=NodeList[index].webnum;ind1++) { newevent.e.type[0]='P'; newevent.e.packinfor.size=ICMPLBAH; newevent.e.packinfor.size = newevent.e.packinfor.size*8/1000.0; newevent.e.pathid=ind1; temtime1=newevent.e.packinfor.size/NodeList[index].Prospeed; NodeList[index].time=NodeList[index].time+temtime1; extraevents++; extratime=0; extratime=extratime+temtime1; newevent.idx=NodeList[index].time; newevent.e.time=0; dummy=strlen(NodeList[index].pathtable[ind1].name); for(ind2=0;ind2e.packinfor.size=ICMPW; oneevent->e.packinfor.size=oneevent->e.packinfor.size*8/1000.0; oneevent->e.type[0]='B'; timedelay=oneevent->e.packinfor.size/NodeList[index].Prospeed; extratime=extratime+timedelay; /* remember the old local time */ temptime=NodeList[index].time; /* update the local time */ if(NodeList[index].time==0) NodeList[index].time = oneevent->idx + timedelay + timedelay2; else if(NodeList[index].time < oneevent->idx) NodeList[index].time = oneevent->idx + timedelay + timedelay2; else if(NodeList[index].time == oneevent->idx) NodeList[index].time=NodeList[index].time + timedelay+timedelay2; else if(NodeList[index].time > oneevent->idx) NodeList[index].time=NodeList[index].time + timedelay+timedelay2; qudelay= temptime - oneevent->idx; /* update the event time */ if(temptime>oneevent->idx) { extratime=extratime+qudelay; oneevent->idx=oneevent->idx + qudelay +timedelay; oneevent->e.time=oneevent->e.time + qudelay +timedelay; } else { oneevent->idx=oneevent->idx+timedelay; oneevent->e.time=oneevent->e.time+timedelay; } /* find the return path */ flag=0; for(ind1=1;ind1<=NodeList[index].subnetnum;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[index].pathtable[ind1].dest[ind2]==oneevent->e.packinfor.send[ind2]) flag++; if(flag==3) break; else flag=0; } dummy=strlen(NodeList[index].pathtable[ind1].name); for(ind2=0;ind2e.pathname[ind2]=NodeList[index].pathtable[ind1].name[ind2]; /* find next node that will process this event */ dummy=strlen(oneevent->e.pathname); for(ind1=0;ind1<3;ind1++) dummy5[ind1]=oneevent->e.pathname[ind1]; for(ind1=0;ind1e.pathname[ind1]=oneevent->e.pathname[ind1+3]; /* compute link cost */ flag=0; for(ind1=1;ind1<=NodeList[index].linkcount;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[index].tableinfor[ind1].dest[ind2]==dummy5[ind2]) flag++; if(flag==3) break; else flag=0; } /* update the event time */ timedelay2=NodeList[index].tableinfor[ind1].distance/LIGHTSPEED/REFRACINDEX; oneevent->idx=oneevent->idx+timedelay2; oneevent->e.time=oneevent->e.time+timedelay2; timedelay2=oneevent->e.packinfor.size/NodeList[index].tableinfor[ind1].tran_speed; oneevent->idx=oneevent->idx+timedelay2; oneevent->e.time=oneevent->e.time+timedelay2; /* send this event to next node */ for(ind1=0;ind1<3;ind1++) oneevent->e.src[ind1]=dummy5[ind1]; /* change event size and type */ /* insert event into queue */ inser_event(oneevent); // fclose(pp); } /* web process this event */ void web_process(int index,enode *oneevent, FILE *fp) { int ind1,ind2,dummy,flag; float timedelay,timedelay2,temptime,starttime,fintime; char dummy5[3]; float load; float filesize; float qudelay; FILE *pp; /* pp=fopen("web.out","a+"); if ( NodeList[index].time > NodeList[index].timeinter) { fprintf(pp,"\n"); fprintf(pp, "time %f\n\n",NodeList[index].time); for(ind1=0;ind1<3;ind1++) fprintf(pp,"%c",NodeList[index].id[ind1]); fprintf(pp," %f %d\n", NodeList[index].accumload/NodeList[index].Prospeed, NodeList[index].loadnum); NodeList[index].timeinter=NodeList[index].timeinter + timeinter; } */ /* process the document delay */ timedelay=oneevent->e.packinfor.size/NodeList[index].Prospeed; filesize = getfile(oneevent->e.msg); NodeList[index].accumload=NodeList[index].accumload-filesize; oneevent->e.packinfor.docubit=filesize; timedelay2=oneevent->e.packinfor.docubit/NodeList[index].Prospeed; pdelay=pdelay+timedelay+timedelay2; wpdelay=wpdelay+timedelay+timedelay2; oneevent->e.packinfor.headerbit=175+(rand()%50+1); oneevent->e.packinfor.size = oneevent->e.packinfor.headerbit/(float)1000+ oneevent->e.packinfor.docubit; /* remember the old local time */ temptime=NodeList[index].time; /* update the local time */ if(NodeList[index].time==0) NodeList[index].time = oneevent->idx + timedelay + timedelay2; else if(NodeList[index].time < oneevent->idx) NodeList[index].time = oneevent->idx + timedelay + timedelay2; else if(NodeList[index].time == oneevent->idx) NodeList[index].time=NodeList[index].time + timedelay+timedelay2; else if(NodeList[index].time > oneevent->idx) NodeList[index].time=NodeList[index].time + timedelay+timedelay2; qudelay= temptime - oneevent->idx; /* update the event time */ if(temptime>oneevent->idx) { qdelay=qdelay+qudelay; wqdelay=wqdelay+qudelay; oneevent->idx=oneevent->idx + qudelay +timedelay+timedelay2; oneevent->e.time=oneevent->e.time + qudelay +timedelay+timedelay2; } else { oneevent->idx=oneevent->idx+timedelay+timedelay2; oneevent->e.time=oneevent->e.time+timedelay+timedelay2; } /* find the return path */ flag=0; for(ind1=1;ind1<=NodeList[index].subnetnum;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[index].pathtable[ind1].dest[ind2]==oneevent->e.packinfor.send[ind2]) flag++; if(flag==3) break; else flag=0; } dummy=strlen(NodeList[index].pathtable[ind1].name); for(ind2=0;ind2e.pathname[ind2]=NodeList[index].pathtable[ind1].name[ind2]; /* find next node that will process this event */ dummy=strlen(oneevent->e.pathname); for(ind1=0;ind1<3;ind1++) dummy5[ind1]=oneevent->e.pathname[ind1]; for(ind1=0;ind1e.pathname[ind1]=oneevent->e.pathname[ind1+3]; /* compute link cost */ flag=0; for(ind1=1;ind1<=NodeList[index].linkcount;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[index].tableinfor[ind1].dest[ind2]==dummy5[ind2]) flag++; if(flag==3) break; else flag=0; } /* update the event time */ timedelay2=NodeList[index].tableinfor[ind1].distance/LIGHTSPEED/REFRACINDEX; prodelay=prodelay+timedelay2; oneevent->idx=oneevent->idx+timedelay2; oneevent->e.time=oneevent->e.time+timedelay2; timedelay2=oneevent->e.packinfor.size/NodeList[index].tableinfor[ind1].tran_speed; oneevent->idx=oneevent->idx+timedelay2; oneevent->e.time=oneevent->e.time+timedelay2; trdelay=trdelay+timedelay2; /* send this event to next node */ for(ind1=0;ind1<3;ind1++) oneevent->e.src[ind1]=dummy5[ind1]; /* change event size and type */ oneevent->e.type[0]='D'; /* insert event into queue */ inser_event(oneevent); // fclose(pp); } /* this function is switch process */ void swit_process(int index,enode *oneevent, FILE *fp) { float trandelay,delaytime2; int dummy,flag,ind1,ind2; char dummy5[4]; float qudelay; /* compute the transmittion cost */ trandelay=oneevent->e.packinfor.size/NodeList[index].Prospeed; pdelay=pdelay+trandelay; rpdelay=rpdelay+trandelay; /* assign local old time */ delaytime2=NodeList[index].time; /* renew the local time */ if(NodeList[index].time==0) NodeList[index].time=oneevent->idx+trandelay; else if(NodeList[index].time < oneevent->idx) NodeList[index].time=oneevent->idx+trandelay; else if(NodeList[index].time > oneevent->idx) NodeList[index].time=NodeList[index].time+trandelay; else if(NodeList[index].time == oneevent->idx) NodeList[index].time=NodeList[index].time+trandelay; qudelay = delaytime2 - oneevent->idx; /* renew the event time */ if(delaytime2>oneevent->idx) { qdelay=qdelay+qudelay; rqdelay=rqdelay+qudelay; oneevent->idx = oneevent->idx + qudelay + trandelay; oneevent->e.time = oneevent->e.time + qudelay+ trandelay; } else { oneevent->idx=oneevent->idx+trandelay; oneevent->e.time=oneevent->e.time+trandelay; } /* get the next node along the path */ for(ind1=0;ind1<3;ind1++) dummy5[ind1]=oneevent->e.pathname[ind1]; /* delete the node that the event already pass */ dummy=strlen(oneevent->e.pathname); for(ind1=0;ind1e.pathname[ind1]=oneevent->e.pathname[ind1+3]; /* find the link information */ flag=0; for(ind1=1;ind1<=NodeList[index].linkcount;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[index].tableinfor[ind1].dest[ind2] == dummy5[ind2]) flag++; if(flag==3) break; else flag=0; } /* compute the link cost and renew the event time, send the event to next node*/ delaytime2=NodeList[index].tableinfor[ind1].distance/LIGHTSPEED/REFRACINDEX; oneevent->idx=oneevent->idx+delaytime2; oneevent->e.time=oneevent->e.time+delaytime2; prodelay=prodelay+delaytime2; delaytime2=oneevent->e.packinfor.size/NodeList[index].tableinfor[ind1].tran_speed; trdelay=trdelay+delaytime2; oneevent->idx=oneevent->idx+delaytime2; oneevent->e.time=oneevent->e.time+delaytime2; /* change the event receivers */ for(ind1=0;ind1<3;ind1++) oneevent->e.src[ind1]=dummy5[ind1]; /* inser_event */ inser_event(oneevent); } void switch_prob(int index, enode *oneevent) { float trandelay,delaytime2; int dummy,flag,ind1,ind2; char dummy5[4]; float qudelay; float temtime1; /* compute the transmittion cost */ trandelay=oneevent->e.packinfor.size/NodeList[index].Prospeed; extratime=extratime+trandelay; // pdelay=pdelay+trandelay; // rpdelay=rpdelay+trandelay; /* assign local old time */ delaytime2=NodeList[index].time; /* renew the local time */ if(NodeList[index].time==0) NodeList[index].time=oneevent->idx+trandelay; else if(NodeList[index].time < oneevent->idx) NodeList[index].time=oneevent->idx+trandelay; else if(NodeList[index].time > oneevent->idx) NodeList[index].time=NodeList[index].time+trandelay; else if(NodeList[index].time == oneevent->idx) NodeList[index].time=NodeList[index].time+trandelay; qudelay = delaytime2 - oneevent->idx; /* renew the event time */ if(delaytime2>oneevent->idx) { // qdelay=qdelay+qudelay; // rqdelay=rqdelay+qudelay; extratime=extratime+qudelay; oneevent->idx = oneevent->idx + qudelay + trandelay; oneevent->e.time = oneevent->e.time + qudelay+ trandelay; } else { oneevent->idx=oneevent->idx+trandelay; oneevent->e.time=oneevent->e.time+trandelay; } /* get the next node along the path */ for(ind1=0;ind1<3;ind1++) dummy5[ind1]=oneevent->e.pathname[ind1]; /* delete the node that the event already pass */ dummy=strlen(oneevent->e.pathname); for(ind1=0;ind1e.pathname[ind1]=oneevent->e.pathname[ind1+3]; /* find the link information */ flag=0; for(ind1=1;ind1<=NodeList[index].linkcount;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[index].tableinfor[ind1].dest[ind2] == dummy5[ind2]) flag++; if(flag==3) break; else flag=0; } /* compute the link cost and renew the event time, send the event to next node*/ delaytime2=NodeList[index].tableinfor[ind1].distance/LIGHTSPEED/REFRACINDEX; oneevent->idx=oneevent->idx+delaytime2; oneevent->e.time=oneevent->e.time+delaytime2; // prodelay=prodelay+delaytime2; delaytime2=oneevent->e.packinfor.size/NodeList[index].tableinfor[ind1].tran_speed; // trdelay=trdelay+delaytime2; oneevent->idx=oneevent->idx+delaytime2; oneevent->e.time=oneevent->e.time+delaytime2; /* change the event receivers */ for(ind1=0;ind1<3;ind1++) oneevent->e.src[ind1]=dummy5[ind1]; inser_event(oneevent); } void comput_path(int index, enode *oneevent) { float trandelay,delaytime2; int dummy,flag,ind1,ind2; char dummy5[4]; float qudelay; float temtime1; /* compute the transmittion cost */ trandelay=oneevent->e.packinfor.size/NodeList[index].Prospeed; extratime=extratime+trandelay; // pdelay=pdelay+trandelay; // rpdelay=rpdelay+trandelay; /* assign local old time */ delaytime2=NodeList[index].time; /* renew the local time */ if(NodeList[index].time==0) NodeList[index].time=oneevent->idx+trandelay; else if(NodeList[index].time < oneevent->idx) NodeList[index].time=oneevent->idx+trandelay; else if(NodeList[index].time > oneevent->idx) NodeList[index].time=NodeList[index].time+trandelay; else if(NodeList[index].time == oneevent->idx) NodeList[index].time=NodeList[index].time+trandelay; qudelay = delaytime2 - oneevent->idx; /* renew the event time */ if(delaytime2>oneevent->idx) { // qdelay=qdelay+qudelay; // rqdelay=rqdelay+qudelay; extratime=extratime+qudelay; oneevent->idx = oneevent->idx + qudelay + trandelay; oneevent->e.time = oneevent->e.time + qudelay+ trandelay; } else { oneevent->idx=oneevent->idx+trandelay; oneevent->e.time=oneevent->e.time+trandelay; } for(ind2=0;ind2<3;ind2++) dummy5[ind2]=oneevent->e.packinfor.lbaid[ind2]; /* find the link information */ flag=0; for(ind1=1;ind1<=NodeList[index].linkcount;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[index].tableinfor[ind1].dest[ind2] == dummy5[ind2]) flag++; if(flag==3) break; else flag=0; } /* compute the link cost and renew the event time, send the event to next node*/ delaytime2=NodeList[index].tableinfor[ind1].distance/LIGHTSPEED/REFRACINDEX; oneevent->idx=oneevent->idx+delaytime2; oneevent->e.time=oneevent->e.time+delaytime2; // prodelay=prodelay+delaytime2; delaytime2=oneevent->e.packinfor.size/NodeList[index].tableinfor[ind1].tran_speed; // trdelay=trdelay+delaytime2; oneevent->idx=oneevent->idx+delaytime2; oneevent->e.time=oneevent->e.time+delaytime2; flag=0; for(ind1=1;ind1<=totalnode;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[ind1].id[ind2] == dummy5[ind2]) flag++; if(flag==3) break; else flag=0; } temtime1=oneevent->e.packinfor.size/NodeList[ind1].Prospeed; extratime=extratime+temtime1; NodeList[ind1].pathtable[oneevent->e.pathid].totaldelay=oneevent->e.time; } /* this function is switch process */ void router_process(int index,enode *oneevent, FILE *fp ) { float trandelay,delaytime2; int dummy,flag,ind1,ind2; char dummy5[4]; float qudelay; /* compute the transmittion cost */ trandelay=oneevent->e.packinfor.size/NodeList[index].Prospeed; pdelay=pdelay+trandelay; rpdelay=rpdelay+trandelay; /* assign local old time */ delaytime2=NodeList[index].time; /* renew the local time */ if(NodeList[index].time==0) NodeList[index].time=oneevent->idx+trandelay; else if(NodeList[index].time< oneevent->idx) NodeList[index].time=oneevent->idx+trandelay; else if(NodeList[index].time>oneevent->idx) NodeList[index].time=NodeList[index].time+trandelay; else if(NodeList[index].time == oneevent->idx) NodeList[index].time=NodeList[index].time+trandelay; qudelay= delaytime2-oneevent->idx; /* renew the event time */ if(delaytime2>oneevent->idx) { qdelay=qdelay+qudelay; rqdelay=rqdelay+qudelay; oneevent->idx=oneevent->idx+qudelay+ trandelay; oneevent->e.time=oneevent->e.time+qudelay+ trandelay; } else { oneevent->idx=oneevent->idx+trandelay; oneevent->e.time=oneevent->e.time+trandelay; } /* get the next node along the path */ for(ind1=0;ind1<3;ind1++) dummy5[ind1]=oneevent->e.pathname[ind1]; /* delete the node that the event already pass */ dummy=strlen(oneevent->e.pathname); for(ind1=0;ind1e.pathname[ind1]=oneevent->e.pathname[ind1+3]; /* find the link information */ flag=0; for(ind1=1;ind1<=NodeList[index].linkcount;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[index].tableinfor[ind1].dest[ind2] == dummy5[ind2]) flag++; if(flag==3) break; else flag=0; } /* compute the link cost and renew the event time, send the event to next node*/ delaytime2=NodeList[index].tableinfor[ind1].distance/LIGHTSPEED/REFRACINDEX; prodelay=prodelay+delaytime2; oneevent->idx=oneevent->idx+delaytime2; oneevent->e.time=oneevent->e.time+delaytime2; delaytime2=oneevent->e.packinfor.size/NodeList[index].tableinfor[ind1].tran_speed; trdelay=trdelay+delaytime2; oneevent->idx=oneevent->idx+delaytime2; oneevent->e.time=oneevent->e.time+delaytime2; /* change the event receivers */ for(ind1=0;ind1<3;ind1++) oneevent->e.src[ind1]=dummy5[ind1]; /* inser_event */ inser_event(oneevent); } void router_prob(int index, enode *oneevent) { float trandelay,delaytime2; int dummy,flag,ind1,ind2; char dummy5[4]; float qudelay; /* compute the transmittion cost */ trandelay=oneevent->e.packinfor.size/NodeList[index].Prospeed; extratime=extratime+trandelay; /* assign local old time */ delaytime2=NodeList[index].time; /* renew the local time */ if(NodeList[index].time==0) NodeList[index].time=oneevent->idx+trandelay; else if(NodeList[index].time< oneevent->idx) NodeList[index].time=oneevent->idx+trandelay; else if(NodeList[index].time>oneevent->idx) NodeList[index].time=NodeList[index].time+trandelay; else if(NodeList[index].time == oneevent->idx) NodeList[index].time=NodeList[index].time+trandelay; qudelay= delaytime2-oneevent->idx; /* renew the event time */ if(delaytime2>oneevent->idx) { extratime=extratime+qudelay; oneevent->idx=oneevent->idx+qudelay+ trandelay; oneevent->e.time=oneevent->e.time+qudelay+ trandelay; } else { oneevent->idx=oneevent->idx+trandelay; oneevent->e.time=oneevent->e.time+trandelay; } /* get the next node along the path */ for(ind1=0;ind1<3;ind1++) dummy5[ind1]=oneevent->e.pathname[ind1]; /* delete the node that the event already pass */ dummy=strlen(oneevent->e.pathname); for(ind1=0;ind1e.pathname[ind1]=oneevent->e.pathname[ind1+3]; /* find the link information */ flag=0; for(ind1=1;ind1<=NodeList[index].linkcount;ind1++) { for(ind2=0;ind2<3;ind2++) if(NodeList[index].tableinfor[ind1].dest[ind2] == dummy5[ind2]) flag++; if(flag==3) break; else flag=0; } /* compute the link cost and renew the event time, send the event to next node*/ delaytime2=NodeList[index].tableinfor[ind1].distance/LIGHTSPEED/REFRACINDEX; oneevent->idx=oneevent->idx+delaytime2; oneevent->e.time=oneevent->e.time+delaytime2; delaytime2=oneevent->e.packinfor.size/NodeList[index].tableinfor[ind1].tran_speed; oneevent->idx=oneevent->idx+delaytime2; oneevent->e.time=oneevent->e.time+delaytime2; /* change the event receivers */ for(ind1=0;ind1<3;ind1++) oneevent->e.src[ind1]=dummy5[ind1]; /* inser_event */ inser_event(oneevent); } void LBA_process_special1(int index, enode *oneevent, FILE *fp) { } void LBA_process_special2(int index, enode *oneevent, FILE *fp) { } void Web_Process_special1(int index, enode *oneevent, FILE *fp) { } void compute_response_time(int index,enode *oneevent) { static int number; FILE *pf; float dummy,dummy1; float timedelay; float temptime; float qudelay; temptime=NodeList[index].clientlist[oneevent->e.clientid][2]; timedelay=oneevent->e.packinfor.size/NodeList[index].clientlist[oneevent->e.clientid][3]; pdelay=pdelay+timedelay; if(NodeList[index].clientlist[oneevent->e.clientid][2]>= oneevent->idx) NodeList[index].clientlist[oneevent->e.clientid][2]= NodeList[index].clientlist[oneevent->e.clientid][2]+timedelay; else if(NodeList[index].clientlist[oneevent->e.clientid][2]< oneevent->idx) NodeList[index].clientlist[oneevent->e.clientid][2]= oneevent->idx+timedelay; qudelay=NodeList[index].clientlist[oneevent->e.clientid][2]-oneevent->idx; if(temptime>oneevent->idx) { qdelay=qdelay+qudelay; rqdelay=rqdelay+qudelay; oneevent->idx= oneevent->idx+ qudelay+timedelay; oneevent->e.time= oneevent->e.time+ qudelay+timedelay; } else { oneevent->idx=oneevent->idx+timedelay; oneevent->e.time=oneevent->e.time+timedelay; } number++; TotalResponseTime=TotalResponseTime + oneevent->e.time; } void computing_time( int index, enode *oneevent, FILE *fp) { float trandelay,delaytime2; int ind1,ind2; float qudelay; /* compute the transmittion cost */ trandelay=oneevent->e.packinfor.size/NodeList[index].Prospeed; pdelay=pdelay+trandelay; rpdelay=rpdelay+trandelay; /* assign local old time */ delaytime2=NodeList[index].time; /* renew the local time */ if(NodeList[index].time==0) NodeList[index].time=oneevent->idx+trandelay; else if(NodeList[index].time< oneevent->idx) NodeList[index].time=oneevent->idx+trandelay; else if(NodeList[index].time>oneevent->idx) NodeList[index].time=NodeList[index].time+trandelay; else if(NodeList[index].time==oneevent->idx) NodeList[index].time=NodeList[index].time+trandelay; qudelay=delaytime2 - oneevent->idx; /* renew the event time */ if(delaytime2>oneevent->idx) { qdelay=qdelay + qudelay; rqdelay=rqdelay+ qudelay; oneevent->idx=oneevent->idx+ qudelay + trandelay; oneevent->e.time=oneevent->e.time+ qudelay + trandelay; } else { oneevent->idx=oneevent->idx+trandelay; oneevent->e.time=oneevent->e.time+trandelay; } /* compute the link cost and renew the event time, send the event to next node*/ delaytime2=NodeList[index].clientlist[ oneevent->e.clientid ][1]/LIGHTSPEED/REFRACINDEX; prodelay=prodelay+delaytime2; oneevent->idx=oneevent->idx+delaytime2; oneevent->e.time=oneevent->e.time+delaytime2; delaytime2=oneevent->e.packinfor.size/NodeList[index].clientlist[oneevent->e.clientid][0]; trdelay=trdelay+delaytime2; oneevent->idx=oneevent->idx+delaytime2; oneevent->e.time=oneevent->e.time+delaytime2; oneevent->e.type[0]='C'; inser_event(oneevent); } /* this function process all event according to type of the event and node */ void process_event(enode *oneevent, FILE *fp) { int index,dummy,ind1,flag,ind2; /* get node that will process this event */ flag=0; for(ind1=1;ind1<=totalnode;ind1++) { for(ind2=0;ind2<3;ind2++) if(oneevent->e.src[ind2]==NodeList[ind1].id[ind2]) flag++; if(flag==3) { index=ind1; break; } else flag=0; } /* according to event type and node event to process event */ if(NodeList[index].type[0]=='S' && oneevent->e.type[0]=='R') swit_process(index,oneevent,fp); else if(NodeList[index].type[0]=='R' && oneevent->e.type[0]=='P') router_prob(index, oneevent); else if (NodeList[index].type[0]== 'R' && oneevent->e.type[0]!='P') router_process(index, oneevent,fp); else if(NodeList[index].type[0]=='W' && oneevent->e.type[0]!='P') web_process(index, oneevent,fp); else if( NodeList[index].type[0]=='W' && oneevent->e.type[0]=='P') prob_web(index, oneevent); else if(NodeList[index].type[0]=='L') LBA_process(index, oneevent,fp); else if( NodeList[index].type[0]=='S' && oneevent->e.type[0]=='D') computing_time(index, oneevent,fp); else if( NodeList[index].type[0]=='S' && oneevent->e.type[0]=='C') compute_response_time(index,oneevent); else if(oneevent->e.type[0]=='G' && NodeList[index].type[0]=='S') generate_event( index, oneevent); else if( oneevent->e.type[0]=='P' && NodeList[index].type[0]=='S') switch_prob(index, oneevent); else if( oneevent->e.type[0]=='B' && NodeList[index].type[0]=='S') comput_path(index,oneevent); } /************************************************************* This procedure generate: 1. Client number of every subnet 2. distance between the each client and Router. 3. Bandwidth from each client to the Router. /*************************************************************/ void init_client() { int index, dummy; for(index=1;index<=netsize;index++) { /* if the node is a sun net, set the distance between Router and the client, banwidth, and processing speed for client we let the client has the same index with the Router associated */ if(NodeList[index].type[0]=='S') { /* generate the client number */ NodeList[index].clientnum=20; for(dummy=1;dummy<=NodeList[index].clientnum;dummy++) { /* generate the distance between the Router and Client 0:bandwidth KB maximum 10 Mbs 1:distance km 2:the local time every client 3:the node's process speed KB */ NodeList[index].clientlist[dummy][0]= 1*5000 + rand()%50; NodeList[index].clientlist[dummy][1]= 0.5 + (rand()%5)*0.1; NodeList[index].clientlist[dummy][2]=0.0; NodeList[index].clientlist[dummy][3]=10000 + rand()%10; } } } } /********************************************************** This procedure generate the file and file size /**********************************************************/ void crea_file(int typenum) { } /********************************************************** this procedure initialize all the file type /**********************************************************/ void init_filetype() { filelist[1].id=1; strcpy(filelist[1].type,"HTML"); filelist[2].id=2; strcpy(filelist[2].type,"Images"); filelist[3].id=3; strcpy(filelist[3].type,"Video"); filelist[4].id=4; strcpy(filelist[4].type,"Sound"); filelist[5].id=5; strcpy(filelist[5].type,"dynamic"); filelist[6].id=6; strcpy(filelist[6].type,"formatted"); filelist[7].id=7; strcpy(filelist[7].type,"other"); } /********************************************************** MAIN PROGRAM CALL THE EVENT PROCESS TILL ALL EVENT IS PROCESSED /**********************************************************/ void main() { enode oneevent; FILE *fp; int ind1, ind2; int num=1; if ((fp = fopen( "fresult.out", "a+")) == NULL) { fprintf(stderr, "Cannot open input file:\n"); exit(1); } /* in this procedure, all node are initialed and event queue is initialed */ init_nodes(NodeList); /* initialize the file type */ init_filetype(); /* in this procedure, randomly generate the client number, distance from the client to the Router, bandwidth, distance fron the Router to LBA */ init_client(); init_event(); do { oneevent=get_event(); process_event(&oneevent,fp); }while(Eventnum>0); if( al_type==201) printf("algorithm: random\n"); else if( al_type==202 ) printf("algorithm: simple RR\n"); else if( al_type==203 ) printf("algorithm: TNNC \n"); else if( al_type==204) printf("algorithm: TNNC-2 \n"); else if( al_type==205) printf("algorithm: TNNC-1 \n"); printf("Total Ave Queuing Delay %f\n",qdelay/eventcount); printf("Ave web Queuing Delay %f\n",wqdelay); printf("Ave router Queuing Delay %f\n",rqdelay); printf("Total Trans Delay %f\n",trdelay/eventcount); printf("Total Prog Delay %f\n",prodelay/eventcount); printf("Total process Delay %f\n",pdelay/eventcount); // printf("web process Delay %f\n",wpdelay); // printf("router process Delay %f\n",rpdelay); printf("average response time %f\n",TotalResponseTime/eventcount); printf("Total response time %f\n",TotalResponseTime); printf("Extra Time %f\n",extratime/eventcount); printf("Extra Events %d\n",extraevents); printf("EXITING , END of SIMULATION\n"); fprintf(fp,"\n\n"); if( al_type==201) fprintf(fp,"algorithm: random\n"); else if( al_type==202 ) fprintf(fp,"algorithm: simple RR\n"); else if( al_type==203 ) fprintf(fp,"algorithm: TNNC \n"); else if( al_type==204) fprintf(fp,"algorithm: TNNC-2 \n"); else if( al_type==205) fprintf(fp,"algorithm: TNNC-1 \n"); fprintf(fp,"TotalEvent: %d\n",TOTALEVENT); fprintf(fp,"Total Queuing Delay %f\n",qdelay/eventcount); fprintf(fp,"web Queuing Delay %f\n",wqdelay/eventcount); fprintf(fp,"router Queuing Delay %f\n",rqdelay/eventcount); fprintf(fp,"lba Queuing Delay %f\n",lbaqudelay/eventcount); fprintf(fp,"\n"); fprintf(fp,"Trans Delay %f\n",trdelay/eventcount); fprintf(fp,"Progation Delay %f\n",prodelay/eventcount); fprintf(fp,"\n"); fprintf(fp,"Total process Delay %f\n",pdelay/eventcount); fprintf(fp,"web process Delay %f\n",wpdelay/eventcount); fprintf(fp,"router process Delay %f\n",rpdelay/eventcount); fprintf(fp,"\n"); fprintf(fp,"average response time %f\n",TotalResponseTime/eventcount); fprintf(fp,"Total response time %f\n",TotalResponseTime); fprintf(fp,"Extra Time %f\n",extratime/eventcount); fprintf(fp,"Extra Events %d\n",extraevents); fprintf(fp,"EXITING , END of SIMULATION\n"); for(ind1=1;ind1<=netsize; ind1++) { if(NodeList[ind1].type[0]=='W') { for(ind2=0;ind2<3;ind2++) fprintf(fp,"%c",NodeList[ind1].id[ind2]); fprintf(fp," load : %f %d\n",NodeList[ind1].sload/10.0, NodeList[ind1].sloadnum); } } fclose(fp); }/* End. */