D-A0-1658-9

Dick Lei 01/03/2003

Network & Systems II

Programming Assignment

The following is my program 10 simulation analysis:

The average of 10 simulation time required to converge:11.0533404

The range of simulation time required to converge: 9.642933 ~ 13.664860

Last node to reach convergence all is: Node 2

Simulation 1
Node0 / Node1 / Node2 / Node3
Number of update message sent / 12 / 6 / 6 / 8
Number of update messagereceived / 9 / 6 / 11 / 6
Total number of message sent / 32
Simulation time required to converge / 9.972750
Last node to reach convergence. / Node 2
Simulation 2
Node0 / Node1 / Node2 / Node3
Number of update message sent / 12 / 6 / 6 / 8
Number of update message received / 9 / 6 / 11 / 6
Total number of message sent / 32
Simulation time required to converge / 11.379566
Last node to reach convergence. / Node 2
Simulation 3
Node0 / Node1 / Node2 / Node3
Number of update message sent / 12 / 6 / 6 / 8
Number of update message received / 9 / 6 / 11 / 6
Total number of message sent / 32
Simulation time required to converge / 9.972750
Last node to reach convergence. / Node 2
Simulation 4
Node0 / Node1 / Node2 / Node3
Number of update message sent / 12 / 6 / 6 / 8
Number of update message received / 9 / 6 / 11 / 6
Total number of message sent / 32
Simulation time required to converge / 10.809314
Last node to reach convergence. / Node 2
Simulation 5
Node0 / Node1 / Node2 / Node3
Number of update message sent / 12 / 6 / 6 / 8
Number of update message received / 9 / 6 / 11 / 6
Total number of message sent / 32
Simulation time required to converge / 10.430216
Last node to reach convergence. / Node 2
Simulation 6
Node0 / Node1 / Node2 / Node3
Number of update message sent / 12 / 6 / 6 / 8
Number of update message received / 9 / 6 / 11 / 6
Total number of message sent / 32
Simulation time required to converge / 9.642933
Last node to reach convergence. / Node 2
Simulation 7
Node0 / Node1 / Node2 / Node3
Number of update message sent / 12 / 6 / 6 / 8
Number of update message received / 9 / 6 / 11 / 6
Total number of message sent / 32
Simulation time required to converge / 11.995451
Last node to reach convergence. / Node 2
Simulation 8
Node0 / Node1 / Node2 / Node3
Number of update message sent / 12 / 6 / 6 / 8
Number of update message received / 9 / 6 / 11 / 6
Total number of message sent / 32
Simulation time required to converge / 12.585688
Last node to reach convergence. / Node 2
Simulation 9
Node0 / Node1 / Node2 / Node3
Number of update message sent / 12 / 6 / 6 / 8
Number of update message received / 9 / 6 / 11 / 6
Total number of message sent / 32
Simulation time required to converge / 9.700778
Last node to reach convergence. / Node 2
Simulation 10
Node0 / Node1 / Node2 / Node3
Number of update message sent / 12 / 6 / 6 / 8
Number of update message received / 9 / 6 / 11 / 6
Total number of message sent / 32
Simulation time required to converge / 13.664860
Last node to reach convergence. / Node 2

Source Code for Node0.c

#include "DVsim.h"

#include "stdio.h"

#include "stdlib.h"

void rtinit0()

{

struct rtpkt rcvpkts;

int i, j, g ;

double clock;

for(i=1 ; i<=3; i++)

for(j=1; j<=3; j++)

{

if(i==j)

dt[0].costs[i][j]=linkcost[0][j];

else

dt[0].costs[i][j]=INF;

}

dt[0].rcount=0;

dt[0].scount=0;

clock=get_clock();

printf("Time %f NODE 0: Initial Distance Table\n", clock);

printdt_0(&dt[0]);

min_cost[0][0]=0;

min_cost[0][1]=1;

min_cost[0][2]=3;

min_cost[0][3]=7;

rcvpkts.sourceid=0;

rcvpkts.destid=1;

for(i=0; i<=3; i++)

rcvpkts.mincost[i]=min_cost[0][i];

tolayer2(rcvpkts);

rcvpkts.sourceid=0;

rcvpkts.destid=2;

for(i=0; i<=3; i++)

rcvpkts.mincost[i]=min_cost[0][i];

tolayer2(rcvpkts);

rcvpkts.sourceid=0;

rcvpkts.destid=3;

for(i=0; i<=3; i++)

rcvpkts.mincost[i]=min_cost[0][i];

tolayer2(rcvpkts);

printf("\n");

for(i=1; i<=3; i++)

{

dt[0].scount=dt[0].scount+1;

clock=get_clock();

printf("Time %f NODE 0: Sending cost update to Node %d: 0 1 3 7\n", clock, i);

}

}

void rtupdate0 (struct rtpkt *rcvdpkt)

{

struct rtpkt rcvpkts;

int i;

int m;

int change;

double clock;

m=rcvdpkt->sourceid;

clock=get_clock();

printf("Time %f NODE 0: Received cost update from Node %d: %d %d %d %d\n",

clock,m, rcvdpkt->mincost[0], rcvdpkt->mincost[1], rcvdpkt->mincost[2],

rcvdpkt->mincost[3]);

dt[0].rcount=dt[0].rcount+1;

for(i=0; i<=3; i++)

{

if(dt[0].costs[i][m] > (linkcost[0][m]+rcvdpkt->mincost[i]))

{

dt[0].costs[i][m]=linkcost[0][m]+rcvdpkt->mincost[i];

if(dt[0].costs[i][m]<min_cost[0][i])

{

change=1;

min_cost[0][i]=dt[0].costs[i][m];

}

}

}

printdt_0(&dt[0]);

if(change==1)

{

clock=get_clock();

printf("Time %f NODE 0: New minimum costs.\n", clock);

rcvpkts.sourceid=0;

rcvpkts.destid=1;

for(i=0; i<=3; i++)

rcvpkts.mincost[i]=min_cost[0][i];

tolayer2(rcvpkts);

rcvpkts.sourceid=0;

rcvpkts.destid=2;

for(i=0; i<=3; i++)

rcvpkts.mincost[i]=min_cost[0][i];

tolayer2(rcvpkts);

rcvpkts.sourceid=0;

rcvpkts.destid=3;

for(i=0; i<=3; i++)

rcvpkts.mincost[i]=min_cost[0][i];

tolayer2(rcvpkts);

printf("\n");

for(i=1; i<=3; i++)

{

dt[0].scount=dt[0].scount+1;

clock=get_clock();

printf("Time %f NODE 0: Sending cost update to Node %d: %d %d %d %d \n", clock, i, min_cost[0][0], min_cost[0][1], min_cost[0][2], min_cost[0][3]);

}

}

else

{

clock=get_clock();

printf("Time %f NODE 0: No change in minimum costs.\n", clock);

}

}

void printdt_0 (struct distance_table *t)

{

printf("\t\t ------\n");

printf("\t\t | via \n");

printf("\t\t D0 | 1 2 3 \n");

printf("\t\t ----|------\n");

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");

}

void linkhandler0 (int linkid, int newcost) {}

Sample Output

Time 0.000000 NODE 0: Initial Distance Table

------

| via

D0 | 1 2 3

----|------

1| 1 999 999

dest 2| 999 3 999
3| 999 999 7

------

Time 0.000000 NODE 0: Sending cost update to Node 1: 0 1 3 7

Time 0.000000 NODE 0: Sending cost update to Node 2: 0 1 3 7

Time 0.000000 NODE 0: Sending cost update to Node 3: 0 1 3 7

Time 0.000000 NODE 1: Initial Distance Table

------

| via

D1 | 0 2

----|------

0| 1 999

dest 2| 999 1

3| 999 999

------

Time 0.000000 NODE 1: Sending cost update to Node 0: 1 0 1 999

Time 0.000000 NODE 1: Sending cost update to Node 2: 1 0 1 999

Time 0.000000 NODE 2: Initial Distance Table

------

| via

D2 | 0 1 3

----|------

0| 3 999 999

dest 1| 999 1 999

3| 999 999 2

------

Time 0.000000 NODE 2: Sending cost update to Node 0: 3 1 0 2

Time 0.000000 NODE 2: Sending cost update to Node 1: 3 1 0 2

Time 0.000000 NODE 2: Sending cost update to Node 3: 3 1 0 2
Time 0.000000 NODE 3: Initial Distance Table

------
| via

D3 | 0 2

----|------

0| 7 999

dest 1| 999 999

2| 999 2

------

Time 0.000000 NODE 3: Sending cost update to Node 0: 7 999 2 0

Time 0.000000 NODE 3: Sending cost update to Node 2: 7 999 2 0

Time 0.502699 NODE 0: Received cost update from Node 1: 1 0 1 999

------

| via

D0 | 1 2 3

----|------

1| 1 999 999

dest 2| 2 3 999

3| 999 999 7

------

Time 0.502699 NODE 0: New minimum costs.

Time 0.502699 NODE 0: Sending cost update to Node 1: 0 1 2 7

Time 0.502699 NODE 0: Sending cost update to Node 2: 0 1 2 7

Time 0.502699 NODE 0: Sending cost update to Node 3: 0 1 2 7

Time 0.703779 NODE 0: Received cost update from Node 2: 3 1 0 2

------

| via

D0 | 1 2 3

----|------

1| 1 4 999

dest 2| 2 3 999

3| 999 5 7

------

Time 0.703779 NODE 0: New minimum costs

Time 0.703779 NODE 0: Sending cost update to Node 1: 0 1 2 5

Time 0.703779 NODE 0: Sending cost update to Node 2: 0 1 2 5

Time 0.703779 NODE 0: Sending cost update to Node 3: 0 1 2 5

Time 0.818148 NODE 1: Received cost update from Node 0: 1 3 7 25

------

| via

D1 | 0 2

----|------

0| 1 999

dest 2| 4 1

3| 8 999
------

Time 0.818148 NODE 1: New minimum costs.

Time 0.818148 NODE 1: Sending cost update to Node 0: 1 0 1 8

Time 0.818148 NODE 1: Sending cost update to Node 2: 1 0 1 8

Time 0.962496 NODE 0: Received cost update from Node 3: 7 999 2 0

------

| via

D0 | 1 2 3

----|------

1| 1 4 999

dest 2| 2 3 9

3| 999 5 7

------

Time 0.962496 NODE 0: No change in minimum costs.

Time 1.281685 NODE 0: Received cost update from Node 1: 1 0 1 8

------

| via

D0 | 1 2 3

----|------

1| 1 4 999

dest 2| 2 3 9

3| 9 5 7

------

Time 1.281685 NODE 0: No change in minimum costs.

Time 1.591672 NODE 2: Received cost update from Node 0: 0 1 3 7

------

| via
D2 | 0 1 3

----|------

0| 3 999 999

dest 1| 4 1 999

3| 10 999 2

------

Time 1.591672 NODE 2:No change in minimum costs.

Time 1.821100 NODE 3: Received cost update from Node 0: 0 1 3 7

------

| via

D3 | 0 2

----|------

0| 7 999

dest 1| 8 999

2| 10 2

------

Time 1.821100 NODE 3: New minimum costs.

Time 1.821100 NODE 3: Sending cost update to Node 0: 7 8 2

Time 1.821100 NODE 3: Sending cost update to Node 2: 7 8 2 0

Time 2.331857 NODE 3: Received cost update from Node 2: 3 1 0 2

------

| via

D3 | 0 2

----|------

0| 7 5

dest 1| 8 3

2| 10 2

------

Time 2.331857 NODE 3: New minimum costs.

Time 2.331857 NODE 3: Sending cost update to Node 0: 5 3 2 0

Time 2.331857 NODE 3: Sending cost update to Node 2: 5 3 2 0

Time 2.414629 NODE 1: Received cost update from Node 2: 1 0 2 25

------

| via

D1 | 0 2

----|------

0| 1 4

dest 2| 4 1

3| 8 3

------

Time 2.414629 NODE 1: New minimum costs.

Time 2.414629 NODE 1: Sending cost update to Node 0: 1 0 1 3

Time 2.414629 NODE 1: Sending cost update to Node 2: 1 0 1 3

Time 2.878368 NODE 0: Received cost update from Node 3: 7 8 2 0

------

| via

D0 | 1 2 3

----|------

1| 1 4 15

dest 2| 2 3 9

3| 9 5 7

------

Time 2.878368 NODE 0: No change in minimum costs.

Time 3.009996 NODE 1: Received cost update from Node 0: 1 2 7 25

------

| via

D1 | 0 2

----|------
0| 1 4

dest 2| 3 1

3| 8 3
------

Time 3.009996 NODE 1: No change in minimum costs.

Time 3.015341 NODE 2: Received cost update from Node 1: 1 0 1 999

------

| via

D2 | 0 1 3

----|------

0| 3 2 999

dest 1| 4 1 999

3| 10 999 2

------

Time 3.015341 NODE 2: New minimum costs.

Time 3.015341 NODE 2: Sending cost update to Node 0: 2 1 0 2

Time 3.015341 NODE 2: Sending cost update to Node 1: 2 1 0 2

Time 3.015341 NODE 2: Sending cost update to Node 3: 2 1 0 2

Time 3.647266 NODE 0: Received cost update from Node 3: 5 3 2 0

------

| via

D0 | 1 2 3
----|------

1| 1 4 10

dest 2| 2 3 9

3| 9 5 7

------

Time 3.647266 NODE 0: No change in minimum costs.

Time 3.710406 NODE 3: Received cost update from Node 0: 0 1 2 7
------

| via

D3 | 0 2

----|------

0| 7 5

dest 1| 8 3

2| 9 2

------

Time 3.710406 NODE 3: No Change in minimum costs.

Time 4.501796 NODE 3: Received cost update from Node 0: 0 1 2 5

------

| via

D3 | 0 2

----|------

0| 7 5

dest 1| 8 3

2| 9 2

------

Time 4.501796 NODE 3: No Change in minimum costs.

Time 4.768255 NODE 2: Received cost update from Node 3: 7 999 2 0

------
| via
D2 | 0 1 3

----|------

0| 3 2 9

dest 1| 4 1 999

3| 10 999 2

------

Time 4.768255 NODE 2:No change in minimum costs.

Time 4.804420 NODE 1: Received cost update from Node 0: 1 2 5 25

------

| via
D1 | 0 2

----|------
0| 1 4

dest 2| 3 1

3| 6 3

------

Time 4.804420 NODE 1: No change in minimum costs.

Time 5.176188 NODE 2: Received cost update from Node 0: 0 1 2 7

------

| via

D2 | 0 1 3
----|------
0| 3 2 9
dest 1| 4 1 999

3| 10 999 2

------

Time 5.176188 NODE 2:No change in minimum costs.

Time 5.444784 NODE 0: Received cost update from Node 1: 1 0 1 3
------

| via

D0 | 1 2 3

----|------

1| 1 4 10

dest 2| 2 3 9

3| 4 5 7

------

Time 5.444784 NODE 0: New minimum costs.

Time 5.444784 NODE 0: Sending cost update to Node 1: 0 1 2 4

Time 5.444784 NODE 0: Sending cost update to Node 2: 0 1 2 4

Time 5.444784 NODE 0: Sending cost update to Node 3: 0 1 2 4

Time 5.712174 NODE 1: Received cost update from Node 2: 1 0 2 25

------

| via

D1 | 0 2

----|------

0| 1 3

dest 2| 3 1

3| 6 3
------

Time 5.712174 NODE 1: No change in minimum costs.

Time 5.932206 NODE 2: Received cost update from Node 0: 0 1 2 5

------
| via
D2 | 0 1 3

----|------

0| 3 2 9
dest 1| 4 1 999

3| 8 999 2

------

Time 5.932206 NODE 2:No change in minimum costs.

Time 6.158353 NODE 3: Received cost update from Node 2: 2 1 0 2
------

| via

D3 | 0 2

----|------

0| 7 4

dest 1| 8 3

2| 9 2

------
Time 6.158353 NODE 3: New minimum costs

Time 6.158353 NODE 3: Sending cost update to Node 0: 4 3 2 0

Time 6.158353 NODE 3: Sending cost update to Node 2: 4 3 2 0

Time 6.428089 NODE 0: Received cost update from Node 2: 2 1 0 2

------

| via

D0 | 1 2 3

----|------
1| 1 4 10
dest 2| 2 3 9
3| 4 5 7
------

Time 6.428089 NODE 0: No change in minimum costs.
Time 6.452950 NODE 1: Received cost update from Node 0: 1 2 4 25

------

| via

D1 | 0 2

----|------

0| 1 3

dest 2| 3 1

3| 5 3

------

Time 6.452950 NODE 1: No change in minimum costs.

Time 6.483686 NODE 2: Received cost update from Node 1: 1 0 1 8
------

| via

D2 | 0 1 3
----|------
0| 3 2 9

dest 1| 4 1 999

3| 8 9 2
------

Time 6.483686 NODE 2:No change in minimum costs.

Time 6.777147 NODE 3: Received cost update from Node 0: 0 1 2 4

------

| via

D3 | 0 2

----|------

0| 7 4

dest 1| 8 3

2| 9 2
------

Time 6.777147 NODE 3: No Change in minimum costs.

Time 6.914994 NODE 0: Received cost update from Node 3: 4 3 2 0
------
| via

D0 | 1 2 3

----|------
1| 1 4 10

dest 2| 2 3 9
3| 4 5 7

------

Time 6.914994 NODE 0: No change in minimum costs.

Time 7.721876 NODE 2: Received cost update from Node 3: 7 8 2 0

------

| via

D2 | 0 1 3
----|------
0| 3 2 9
dest 1| 4 1 10

3| 8 9 2

------

Time 7.721876 NODE 2:No change in minimum costs.

Time 9.341982 NODE 2: Received cost update from Node 3: 5 3 2 0

------

| via

D2 | 0 1 3

----|------

0| 3 2 7

dest 1| 4 1 5
3| 8 9 2

------

Time 9.341982 NODE 2:No change in minimum costs.

Time 10.726672 NODE 2: Received cost update from Node 1: 1 0 1 3

------

| via
D2 | 0 1 3

----|------

0| 3 2 7

dest 1| 4 1 5

3| 8 4 2

------

Time 10.726672 NODE 2:No change in minimum costs.

Time 12.607049 NODE 2: Received cost update from Node 0: 0 1 2 4

------

| via

D2 | 0 1 3

----|------

0| 3 2 7

dest 1| 4 1 5

3| 7 4 2

------

Time 12.607049 NODE 2:No change in minimum costs.

Time 14.134785 NODE 2: Received cost update from Node 3: 4 3 2 0

------

| via

D2 | 0 1 3

----|------

0| 3 2 6

dest 1| 4 1 5

3| 7 4 2

------

Time 14.134785 NODE 2:No change in minimum costs.

Simulator terminated at t=14.134785, no packets in medium

Node 0 Total message send: 12

Node 0 Total message received 9

Node 1 Total message sent 6

Node 1 Total message received 6

Node 2 Total message sent 6

Node 2 Total message received 11

Node 3 Total message sent 8

Node 3 Total message received 6

Total number of message sent 32