www.pudn.com > router.rar > RDISPLAY.C
/******************************************************************************************/ /* 路由器距离路由算法演示系统 */ /* */ /* 说明:本程序在tc2.0编译环境编译,编译后图形库已加载,未用到系统资源。 */ /* 程序主要是模拟路由器的距离路由算法。在路由器实际的工作中,由于各路由器 */ /* 相互独立工作,产生的路由请求的时间是不确定的,且可能同步。该程序模拟5个 */ /* 路由器的工作过程,因为是在DOS模式下编程,不支持多线程,所以实现同步路由请 */ /* 求较为困难,在这里采取随机产生路由请求的办法进行路由表的更新(非同步)。 */ /* */ /* 作者:刘俊 */ /* 2007.4 */ /******************************************************************************************/ #include#include #include #include #include #include #include #include #include #define INFINITE 5000 #define LEFT 19712 #define RIGHT 19200 #define UP 18432 #define DOWN 20480 #define ENTER 7181 #define ALT_X 11520 void *buf; int cnum=0; int tabcount=0; int jmpcount=0; int stop=0; int init_sign=0; char *char_buf,*p,cbuf[5]; typedef struct { int number; int has_sign; }test; test num_buf[5][5]; typedef struct { int order; /*路由器序号*/ char info[256]; /*欲发送信息*/ int **RouterTable; /*路由表*/ int *Near; /*相邻结点*/ }ROUTERNODE,*LPROUTERNODE; typedef struct { int order; int x; int y; int radius; }CIR_STRUCT,*LPCIR_STRUCT; LPROUTERNODE m; LPCIR_STRUCT lpCir; LPROUTERNODE Create(LPROUTERNODE lpRouterNode,int NodeCount) { /*Create路由器*/ int i=0,j=0; for(i=0;i buffer[i].authoity) { w.authoity=buffer[i].authoity; v=i; } else { if(w.authoity==buffer[i].authoity && lpRouterNode[Source].RouterTable[1][buffer[i].NextNode]==buffer[i].NextNode) { w.authoity=buffer[i].authoity; v=i; } } } for(i=0;i =0) { setlinestyle(DASHED_LINE,0,3); line(lpCir[Source].x,lpCir[Source].y, lpCir[lpRouterNode[Source].RouterTable[1][Destination]].x, lpCir[lpRouterNode[Source].RouterTable[1][Destination]].y ); delay(60000);delay(60000);delay(60000); Shortest(lpRouterNode, NodeCount, lpRouterNode[Source].RouterTable[1][Destination], Destination ); } setlinestyle(0,0,1); return lpRouterNode; } int cur(int x,int y,int cmd,int len,int cor,int bkcor,int wid,int tab,int jmp) { setcolor(cor); line(x,y,x+len,y); delay(30000); switch(cmd) { case RIGHT: setcolor(bkcor); line(x,y,x+len,y+wid); setcolor(cor); line(x-tab,y,x+len-tab,y+wid); break; case LEFT: setcolor(bkcor); line(x,y,x+len,y+wid); setcolor(cor); line(x+tab,y,x+tab+len,y+wid); break; case UP: setcolor(bkcor); line(x,y,x+len,y+wid); setcolor(cor); line(x,y-jmp,x+len,y-jmp+wid); break; case DOWN: setcolor(bkcor); line(x,y,x+len,y); setcolor(cor); line(x,y+jmp,x+len,y+jmp+wid); break; default: setcolor(bkcor); line(x,y,x+len,y+wid); break; } return 0; } int DrowNode(LPCIR_STRUCT c,int cirfillcolor) { setcolor(BLUE); circle((*c).x,(*c).y,(*c).radius); switch((*c).order) { case 0:outtextxy((*c).x,(*c).y,"1");break; case 1:outtextxy((*c).x,(*c).y,"2");break; case 2:outtextxy((*c).x,(*c).y,"3");break; case 3:outtextxy((*c).x,(*c).y,"4");break; case 4:outtextxy((*c).x,(*c).y,"5");break; } setfillstyle(1,cirfillcolor); floodfill((*c).x,(*c).y,BLUE); return 0; } int DrawGraph(LPROUTERNODE lpRouterNode,int NodeCount,int cirfillcolor) { int i,j,k;char ch[25]; for(k=0;k<25;k++)ch[k]='\0'; lpCir=(LPCIR_STRUCT)malloc(NodeCount*sizeof(CIR_STRUCT)); lpCir[0].x=63;lpCir[0].y=175;lpCir[0].radius=30;lpCir[0].order=0; lpCir[1].x=180;lpCir[1].y=92;lpCir[1].radius=30;lpCir[1].order=1; lpCir[2].x=280;lpCir[2].y=233;lpCir[2].radius=30;lpCir[2].order=2; lpCir[3].x=410;lpCir[3].y=76;lpCir[3].radius=30;lpCir[3].order=3; lpCir[4].x=455;lpCir[4].y=200;lpCir[4].radius=30;lpCir[4].order=4; DrowNode(&lpCir[0],cirfillcolor); DrowNode(&lpCir[1],cirfillcolor); DrowNode(&lpCir[2],cirfillcolor); DrowNode(&lpCir[3],cirfillcolor); DrowNode(&lpCir[4],cirfillcolor); for(i=0;i 0 && line2>0) { Shortest(m,5,line1-1,line2-1); } } break; case 3: done=1; break; case 10:done=1; break; } }while(!done); free(buf); free(m); free(lpCir); free(char_buf); closegraph(); restorecrtmode(); }