import java.util.*;
public class Node {
int costs[][]=new int [4][4];
int mincosts[]=new int [4];
int dest[]=null;
ArrayList packets=new ArrayList();
Simulator sim=null;
/**
*@param args
*/
public RoutingPacket creatertpkt(int srcid, int destid,int mincosts[])
{
RoutingPacket oRPacket =new RoutingPacket();
oRPacket.setSourceid(srcid);
oRPacket.setDestid(destid);
oRPacket.setMincost(mincosts);
return oRPacket;
}
void rtinit(int srcid,int dest[], int initcosts[][],int initMinCosts[],Simulator s)
{
System.out.println("Entering rtinit\n");
costs=initcosts;
mincosts=initMinCosts;
sim=s;
this.dest=dest;
for(int i=0; i<dest.length ;i++)sim.toLayer2(creatertpkt(srcid,dest[i],mincosts));
//packets.add(creatertpkt(srcid,dest[i].mincosts));
printTable();
}
public void rtupdate(RoutingPacket oReceivedPacket){
System.out.println("Entering rtupdate");
int destid, i,j;
int srcid = oReceivedPacket.sourceid;
for(destid=0; destid < 4; destid++)
{
int mincosts12[] = {999,999,999,999};
//if there is a new min distance
if (oReceivedPacket.mincost[destid]!=999)
{
//update distance table
this.costs[destid][srcid] = this.costs[srcid][srcid] + oReceivedPacket.mincost[destid];
//find new min for the destination cost
if(this.costs[destid][srcid]<this.mincosts[destid]){
//update min cost table
this.mincosts[destid] =this.costs[destid][srcid];
mincosts12[destid] =this.costs[destid][srcid];
//send new minimum value to all its neighbors
for(int k=0;k<this.dest.length;k++)sim.toLayer2(creatertpkt(srcid,this.dest[k],mincosts12));
}
}
}
printTable();
}
void printTable()
{
System.out.println(" via \n");
System.out.println(" D01 | 1 2 3 \n");
System.out.println(" ===|==============\n");
System.out.println(" 1| "+costs[1][1]+" "+costs[1][2]+" "+costs[1][3]);
System.out.println(" 2| "+costs[2][1]+" "+costs[2][2]+" "+costs[2][3]);
System.out.println(" 3| "+costs[3][1]+" "+costs[3][2]+" "+costs[3][3]);
}
}
jayturner 0 Newbie Poster
jayturner 0 Newbie Poster
stultuske 1,116 Posting Maven Featured Poster
jayturner 0 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.