コード例 #1
0
ファイル: node3.c プロジェクト: akshoop/CS-3516
void rtinit3() {
    int i, j;
    struct distance_table *thisnode3;

    thisnode3 = &dt3;

    // 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, rtinit3() 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++) {
            thisnode3->costs[i][j]= INFINITY;
        }
    }

    neighbor3 = getNeighborCosts(3);

    // link weight from node 0
    thisnode3->costs[0][0] = neighbor3->NodeCosts[0];
    thisnode3->costs[1][1] = neighbor3->NodeCosts[1];
    thisnode3->costs[2][2] = neighbor3->NodeCosts[2];
    thisnode3->costs[3][3] = neighbor3->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] > thisnode3->costs[i][j]) {
                somePacket.mincost[i] = thisnode3->costs[i][j];
            }
        }
    }

    // set somePacket's sourceID to 3 (we're in node3)
    // use tolayer2 to send to another node, depending on the destID
    somePacket.sourceid = 3;
    somePacket.destid = 0;
    toLayer2(somePacket);
    printf("At time t = %f, node 3 sends packet to node 0 with: %d %d %d %d\n", clocktime, somePacket.mincost[0], somePacket.mincost[1], somePacket.mincost[2], somePacket.mincost[3]);

    somePacket.destid = 1;
    toLayer2(somePacket);
    printf("At time t = %f, node 3 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 3 sends packet to node 2 with: %d %d %d %d\n", clocktime, somePacket.mincost[0], somePacket.mincost[1], somePacket.mincost[2], somePacket.mincost[3]);

    printdt3(3, neighbor3, thisnode3);
    printf("We are done with rtinit3 routine\n");
}
コード例 #2
0
ファイル: node3.c プロジェクト: akshoop/CS-3516
void rtupdate3( struct RoutePacket *rcvdpkt ) {
    int i, j, rcvdSource, update = 0;
    struct distance_table *thisnode3;

    thisnode3 = &dt3;

    for (i = 0; i < 4; i++) {
            somePacket.mincost[i] = INFINITY;
    }

    printf("Now we are in rtupdate3()\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 (thisnode3->costs[i][rcvdSource] > (thisnode3->costs[rcvdSource][rcvdSource] + rcvdpkt->mincost[i])) {
            thisnode3->costs[i][rcvdSource] = (thisnode3->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] > thisnode3->costs[i][j]) {
                    somePacket.mincost[i] = thisnode3->costs[i][j];
                }
            }
        }
        printf("We updated distance table from rtupdate3()\n");

        // set somePacket's sourceID to 3 (we're in node3)
        // use tolayer2 to send to another node, depending on the destID
        somePacket.sourceid = 3;
        somePacket.destid = 0;
        toLayer2(somePacket);
        printf("At time t = %f, node 3 sends packet to node 0 with: %d %d %d %d\n", clocktime, somePacket.mincost[0], somePacket.mincost[1], somePacket.mincost[2], somePacket.mincost[3]);

        somePacket.destid = 1;
        toLayer2(somePacket);
        printf("At time t = %f, node 3 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 3 sends packet to node 2 with: %d %d %d %d\n", clocktime, somePacket.mincost[0], somePacket.mincost[1], somePacket.mincost[2], somePacket.mincost[3]);
    }

    printdt3(3, neighbor3, thisnode3);

    printf("We are done with rtupdate3()\n");
}
コード例 #3
0
ファイル: node3.c プロジェクト: fladson/trabalhos-bsiufrn
void rtinit3()
{
  int custos[4] = {7,INFINITO,2,0}; //vetor com os meus custos para os nós 0,1,2 e 3 respectivamente
  int i,j;
  for(i=0;i<4;i++){
    envios[i].sourceid = 3; // todos sairão com o sourceid = 3
    envios[i].destid = i;
    for(j=0;j<4;j++){
      envios[i].mincost[j] = custos[j]; // preenchendo os custos dos pacotes a enviar
      if(i==j)
        dt3.costs[i][j] = custos[i]; // se os indices da matriz forem iguais, então atualizo meus custos buscando no vetor de custos
      else
        dt3.costs[i][j] = INFINITO; // senão eu coloco o valor correspondente ao INFINITO
    }
  }
  tolayer2(envios[0]);
  tolayer2(envios[2]);
  printdt3(&dt3);
}
コード例 #4
0
ファイル: node3.c プロジェクト: ediney/redes
void rtinit3() 
{
	extern float clocktime;
	
	packet.mincost[0] = 999;
	packet.mincost[1] = 999;
	packet.mincost[2] = 999;
	packet.mincost[3] = 999;
	
	printf("inside rtinit3\n");
	printf("rtinit3: %f\n", clocktime);
	int i;
	int j;
	
	for (i=0; i<4; i++) {
		for (j=0; j<4; j++) {
			dt3.costs[i][j]= 999;
		}
	}
	
	dt3.costs[0][0]=7;
	dt3.costs[2][2]=2;
	dt3.costs[3][3]=999;
	
	for (i=0; i<4; i++) {
		for (j=0; j<4; j++) {
			if (packet.mincost[i] > dt3.costs[i][j])
				packet.mincost[i] = dt3.costs[i][j];
		}
	}
	
	packet.sourceid = 3;
	packet.destid = 0;
	tolayer2(packet);
	
	packet.sourceid = 3;
	packet.destid = 2;
	tolayer2(packet);
	
	packet.sourceid = 3;
	printdt3(&dt3);
	printf("done with rtinit3\n");
}