void rtinit0() { int i, j; struct distance_table *thisnode0; thisnode0 = &dt0; // set the temporary packet mincosts to INFINITY somePacket.mincost[0] = INFINITY; somePacket.mincost[1] = INFINITY; somePacket.mincost[2] = INFINITY; somePacket.mincost[3] = INFINITY; printf("At time t = %f, rtinit0() called\n", clocktime); // set links from node i to node j as INFINITY for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { thisnode0->costs[i][j]= INFINITY; } } neighbor0 = getNeighborCosts(0); // link weight from node 0 thisnode0->costs[0][0] = neighbor0->NodeCosts[0]; thisnode0->costs[1][1] = neighbor0->NodeCosts[1]; thisnode0->costs[2][2] = neighbor0->NodeCosts[2]; thisnode0->costs[3][3] = neighbor0->NodeCosts[3]; // check each distance from node i to node j in comparison to our somePacket for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { if (somePacket.mincost[i] > thisnode0->costs[i][j]) { somePacket.mincost[i] = thisnode0->costs[i][j]; } } } // set somePacket's sourceID to 0 (we're in node0) // use tolayer2 to send to another node, depending on the destID somePacket.sourceid = 0; somePacket.destid = 1; toLayer2(somePacket); printf("At time t = %f, node 0 sends packet to node 1 with: %d %d %d %d\n", clocktime, somePacket.mincost[0], somePacket.mincost[1], somePacket.mincost[2], somePacket.mincost[3]); somePacket.destid = 2; toLayer2(somePacket); printf("At time t = %f, node 0 sends packet to node 2 with: %d %d %d %d\n", clocktime, somePacket.mincost[0], somePacket.mincost[1], somePacket.mincost[2], somePacket.mincost[3]); somePacket.destid = 3; toLayer2(somePacket); printf("At time t = %f, node 0 sends packet to node 3 with: %d %d %d %d\n", clocktime, somePacket.mincost[0], somePacket.mincost[1], somePacket.mincost[2], somePacket.mincost[3]); printdt0(0, neighbor0, thisnode0); printf("We are done with rtinit0 routine\n"); }
void rtupdate0( struct RoutePacket *rcvdpkt ) { int i, j, rcvdSource, update = 0; struct distance_table *thisnode0; thisnode0 = &dt0; for (i = 0; i < 4; i++) { somePacket.mincost[i] = INFINITY; } printf("Now we are in rtupdate0()\n"); // check what sourceID of received packet is rcvdSource = rcvdpkt->sourceid; printf("Received packet's source ID is %d\n", rcvdSource); for (i = 0; i < 4; i++) { // go through and see if we need to update distance-table with new mincost if (thisnode0->costs[i][rcvdSource] > (thisnode0->costs[rcvdSource][rcvdSource] + rcvdpkt->mincost[i])) { thisnode0->costs[i][rcvdSource] = (thisnode0->costs[rcvdSource][rcvdSource] + rcvdpkt->mincost[i]); update = 1; } } // for this case, we update distance table if (update == 1) { for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { if (somePacket.mincost[i] > thisnode0->costs[i][j]) { somePacket.mincost[i] = thisnode0->costs[i][j]; } } } printf("We updated distance table from rtupdate0()\n"); // set somePacket's sourceID to 0 (we're in node0) // use tolayer2 to send to another node, depending on the destID somePacket.sourceid = 0; somePacket.destid = 1; toLayer2(somePacket); printf("At time t = %f, node 0 sends packet to node 1 with: %d %d %d %d\n", clocktime, somePacket.mincost[0], somePacket.mincost[1], somePacket.mincost[2], somePacket.mincost[3]); somePacket.destid = 2; toLayer2(somePacket); printf("At time t = %f, node 0 sends packet to node 2 with: %d %d %d %d\n", clocktime, somePacket.mincost[0], somePacket.mincost[1], somePacket.mincost[2], somePacket.mincost[3]); somePacket.destid = 3; toLayer2(somePacket); printf("At time t = %f, node 0 sends packet to node 3 with: %d %d %d %d\n", clocktime, somePacket.mincost[0], somePacket.mincost[1], somePacket.mincost[2], somePacket.mincost[3]); } printdt0(0, neighbor0, thisnode0); printf("We are done with rtupdate0()\n"); }
void rtinit0() { int custos[4] = {0,1,3,7}; //vetor com os meus custos para os nós 0,1,2 e 3 respectivamente int i,j; for(i=0; i<4; i++) { envio.sourceid = NODE_ID; // todos sairão com o sourceid = 0 envio.destid = i+1; // como eu começo apartir de '0' e não vou mandar para mim mesmo eu incrementei '+1' for(j=0; j<4; j++) { envio.mincost[j] = custos[j]; // preenchendo os custos dos pacotes a enviar if(i==j) dt0.costs[i][j] = custos[i]; // se os indices da matriz forem iguais, então atualizo meus custos buscando no vetor de custos else dt0.costs[i][j] = INFINITO; // senão eu coloco o valor correspondente ao INFINITO } if(i+1!=4) tolayer2(envio); } printdt0(&dt0); }