www.pudn.com > DV.rar > Node.cpp
#include "DVsim.h"
/*------------------------
* rtinit0
*------------------------*/
void rtinit0()
{
struct rtpkt rt;
int i,j;
//
for(i=0;isourceid];
///////////////////////////////////////
for( i=0;isourceid] =
dt[NN].costs[rcvdpkt->sourceid][rcvdpkt->sourceid]+rcvdpkt->mincost[i]
<
dt[NN].costs[i][rcvdpkt->sourceid]?
dt[NN].costs[rcvdpkt->sourceid][rcvdpkt->sourceid]+rcvdpkt->mincost[i]
:
dt[NN].costs[i][rcvdpkt->sourceid];
////////////////////////////////////////
for(i=0;isourceid])
{
flag=0;
break;
}
/////////////////////////////////////////
if(flag==0)//changed
{
rt.sourceid=0;
for(j=0;jsourceid];
rt.destid=1;
tolayer2 (rt);
rt.destid=2;
tolayer2 (rt);
send0+=2;
}
}
/*------------------------
* rtupdate1
*------------------------*/
void rtupdate1 (struct rtpkt *rcvdpkt)
{
int i,j;
int NN=1;
int temp[NODES]={0};
int flag=1;
struct rtpkt rt;
//
recv1++;
//
for( i=0;isourceid];
///////////////////////////////////////
for( i=0;isourceid] =
dt[NN].costs[rcvdpkt->sourceid][rcvdpkt->sourceid]+rcvdpkt->mincost[i]
<
dt[NN].costs[i][rcvdpkt->sourceid]?
dt[NN].costs[rcvdpkt->sourceid][rcvdpkt->sourceid]+rcvdpkt->mincost[i]
:
dt[NN].costs[i][rcvdpkt->sourceid];
////////////////////////////////////////
for(i=0;isourceid])
{
flag=0;
break;
}
//////////////
if(flag==0)//changed
{
rt.sourceid=NN;
for(j=0;jsourceid];
rt.destid=0;
tolayer2 (rt);
rt.destid=3;
tolayer2 (rt);
rt.destid=4;
tolayer2 (rt);
send1+=3;
}
}
/*------------------------
* rtupdate2
*------------------------*/
void rtupdate2 (struct rtpkt *rcvdpkt)
{
int i,j;
int NN=2;
int temp[NODES]={0};
int flag=1;
struct rtpkt rt;
//
recv2++;
//
for( i=0;isourceid];
///////////////////////////////////////
for( i=0;isourceid] =
dt[NN].costs[rcvdpkt->sourceid][rcvdpkt->sourceid]+rcvdpkt->mincost[i]
<
dt[NN].costs[i][rcvdpkt->sourceid]?
dt[NN].costs[rcvdpkt->sourceid][rcvdpkt->sourceid]+rcvdpkt->mincost[i]
:
dt[NN].costs[i][rcvdpkt->sourceid];
////////////////////////////////////////
for(i=0;isourceid])
{
flag=0;
break;
}
/////
if(flag==0)//changed
{
rt.sourceid=NN;
for(j=0;jsourceid];
rt.destid=0;
tolayer2 (rt);
rt.destid=3;
tolayer2 (rt);
rt.destid=4;
tolayer2 (rt);
send2+=3;
}
}
/*------------------------
* rtupdate3
*------------------------*/
void rtupdate3 (struct rtpkt *rcvdpkt)
{
int i,j;
int NN=3;
int temp[NODES]={0};
int flag=1;
struct rtpkt rt;
//
recv3++;
//
for( i=0;isourceid];
///////////////////////////////////////
for( i=0;isourceid] =
dt[NN].costs[rcvdpkt->sourceid][rcvdpkt->sourceid]+rcvdpkt->mincost[i]
<
dt[NN].costs[i][rcvdpkt->sourceid]?
dt[NN].costs[rcvdpkt->sourceid][rcvdpkt->sourceid]+rcvdpkt->mincost[i]
:
dt[NN].costs[i][rcvdpkt->sourceid];
////////////////////////////////////////
for(i=0;isourceid])
{
flag=0;
break;
}
/////
if(flag==0)//changed
{
rt.sourceid=NN;
for(j=0;jsourceid];
rt.destid=1;
tolayer2 (rt);
rt.destid=2;
tolayer2 (rt);
rt.destid=4;
tolayer2 (rt);
send3 += 3;
}
}
/*------------------------
* rtupdate4
*------------------------*/
void rtupdate4 (struct rtpkt *rcvdpkt)
{
int i,j;
int NN=4;
int temp[NODES]={0};
int flag=1;
struct rtpkt rt;
//
recv4++;
//
for( i=0;isourceid];
///////////////////////////////////////
for( i=0;isourceid] =
dt[NN].costs[rcvdpkt->sourceid][rcvdpkt->sourceid]+rcvdpkt->mincost[i]
<
dt[NN].costs[i][rcvdpkt->sourceid]?
dt[NN].costs[rcvdpkt->sourceid][rcvdpkt->sourceid]+rcvdpkt->mincost[i]
:
dt[NN].costs[i][rcvdpkt->sourceid];
////////////////////////////////////////
for(i=0;isourceid])
{
flag=0;
break;
}
/////
if(flag==0)//changed
{
rt.sourceid=NN;
for(j=0;jsourceid];
rt.destid=1;
tolayer2 (rt);
rt.destid=2;
tolayer2 (rt);
rt.destid=3;
tolayer2 (rt);
send4 += 3;
}
}
//
/*----------------------------------------------------
* printdt_0
*
* Prints distance table at node 0.
*
* (Format will be different for other nodes.)
*-----------------------------------------------------*/
void printdt_0 (struct distance_table *t)
{
printf("\t\t ----------------------\n");
printf("\t\t | via \n");
printf("\t\t D0 | 1 2 \n");
printf("\t\t ----|-----------------\n");
printf("\t\t 1| %3d %3d\n", t->costs[1][1], t->costs[1][2]);
printf("\t\t 2| %3d %3d\n", t->costs[2][1] , t->costs[2][2] );
printf("\t\tdest 3| %3d %3d\n", t->costs[3][1] , t->costs[3][2] );
printf("\t\t 4| %3d %3d\n", t->costs[4][1] , t->costs[4][2] );
printf("\t\t ----------------------\n");
}
/*----------------------------------------------------
* printdt_1
*
* Prints distance table at node 1.
*
* (Format will be different for other nodes.)
*-----------------------------------------------------*/
void printdt_1 (struct distance_table *t)
{
printf("\t\t --------------------------\n");
printf("\t\t | via \n");
printf("\t\t D1 | 0 3 4\n");
printf("\t\t ----|-----------------\n");
printf("\t\t 0| %3d %3d %3d\n", t->costs[0][0], t->costs[0][3], t->costs[0][4]);
printf("\t\t 2| %3d %3d %3d\n", t->costs[2][0], t->costs[2][3], t->costs[2][4]);
printf("\t\tdest 3| %3d %3d %3d\n", t->costs[3][0], t->costs[3][3], t->costs[3][4]);
printf("\t\t 4| %3d %3d %3d\n", t->costs[4][0], t->costs[4][3], t->costs[4][4]);
printf("\t\t --------------------------\n");
}
/*----------------------------------------------------
* printdt_2
*
* Prints distance table at node 2.
*
* (Format will be different for other nodes.)
*-----------------------------------------------------*/
void printdt_2 (struct distance_table *t)
{printf("\t\t --------------------------\n");
printf("\t\t | via \n");
printf("\t\t D2 | 0 3 4\n");
printf("\t\t ----|-----------------\n");
printf("\t\t 0| %3d %3d %3d\n", t->costs[0][0], t->costs[0][3], t->costs[0][4]);
printf("\t\t 1| %3d %3d %3d\n", t->costs[1][0], t->costs[1][3], t->costs[1][4]);
printf("\t\tdest 3| %3d %3d %3d\n", t->costs[3][0], t->costs[3][3], t->costs[3][4]);
printf("\t\t 4| %3d %3d %3d\n", t->costs[4][0], t->costs[4][3], t->costs[4][4]);
printf("\t\t --------------------------\n");
}
/*----------------------------------------------------
* printdt_3
*
* Prints distance table at node 3.
*
* (Format will be different for other nodes.)
*-----------------------------------------------------*/
void printdt_3 (struct distance_table *t)
{
printf("\t\t --------------------------\n");
printf("\t\t | via \n");
printf("\t\t D3 | 1 2 4\n");
printf("\t\t ----|-----------------\n");
printf("\t\t 0| %3d %3d %3d\n", t->costs[0][1], t->costs[0][2], t->costs[0][4]);
printf("\t\t 1| %3d %3d %3d\n", t->costs[1][1], t->costs[1][2], t->costs[1][4]);
printf("\t\tdest 2| %3d %3d %3d\n", t->costs[2][1], t->costs[2][2], t->costs[2][4]);
printf("\t\t 4| %3d %3d %3d\n", t->costs[4][1], t->costs[4][2], t->costs[4][4]);
printf("\t\t --------------------------\n");
}
/*----------------------------------------------------
* printdt_4
*
* Prints distance table at node 4.
*
* (Format will be different for other nodes.)
*-----------------------------------------------------*/
void printdt_4 (struct distance_table *t)
{
printf("\t\t --------------------------\n");
printf("\t\t | via \n");
printf("\t\t D4 | 1 2 3\n");
printf("\t\t ----|-----------------\n");
printf("\t\t 0| %3d %3d %3d\n", t->costs[0][1], t->costs[0][2], t->costs[0][3]);
printf("\t\t 1| %3d %3d %3d\n", t->costs[1][1], t->costs[1][2], t->costs[1][3]);
printf("\t\tdest 2| %3d %3d %3d\n", t->costs[2][1], t->costs[2][2], t->costs[2][3]);
printf("\t\t 3| %3d %3d %3d\n", t->costs[3][1], t->costs[3][2], t->costs[3][3]);
printf("\t\t --------------------------\n");
}
/*--------------------------------------------------------------
* linkhandler0
*---------------------------------------------------------------*/
void linkhandler0 (int linkid, int newcost) {}
void linkhandler1 (int linkid, int newcost) {}