void rtinit1() {
    int i, j;
    struct distance_table *thisnode1;

    thisnode1 = &dt1;

    // set the temporary packet mincosts to INFINITY
    RPACKET.mincost[0] = INF;
    RPACKET.mincost[1] = INF;
    RPACKET.mincost[2] = INF;
    RPACKET.mincost[3] = INF;

    printf("At time t = %f, rtinit1() 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++) {
            thisnode1->costs[i][j]= INF;
        }
    }

    neighbor1 = getNeighborCosts(1);

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

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

    RPACKET.destid = 2;
    toLayer2(RPACKET);
    printf("At time t = %f, node 1 sends packet to node 2 with: %d %d %d %d\n", clocktime, RPACKET.mincost[0], RPACKET.mincost[1], RPACKET.mincost[2], RPACKET.mincost[3]);

    RPACKET.destid = 3;
    toLayer2(RPACKET);
    printf("At time t = %f, node 1 sends packet to node 3 with: %d %d %d %d\n", clocktime, RPACKET.mincost[0], RPACKET.mincost[1], RPACKET.mincost[2], RPACKET.mincost[3]);

    printdt1(1, neighbor1, thisnode1);
    printf("We are done with rtinit1 routine\n");
}
Beispiel #2
0
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");
}
Beispiel #3
0
void rtinit1() {
    if(TraceLevel > 0){
        printf("At time t=%f, rtinit1() called. \n", clocktime);
    }
    neighbor1 = getNeighborCosts(MY_NUMBER);
    int i, j;
    //Populate distance table with neighbor costs and infinity for everyone else
    for(i=0; i<MAX_NODES; i++){
        for(j=0; j<MAX_NODES; j++){
            if(j != MY_NUMBER){
                dt1.costs[i][j] = INFINITY;
            }
            else{
                dt1.costs[i][j] = neighbor1->NodeCosts[i];
            }
        }
    }
    //Send packets to all neighbors with this node's neighbor costs
    for(i=0; i<MAX_NODES; i++){
        if(neighbor1->NodeCosts[i] != INFINITY && i != MY_NUMBER){
            int costs[MAX_NODES];
            for(j=0; j<MAX_NODES; j++){
                costs[j] = dt1.costs[j][MY_NUMBER];
            }
            struct RoutePacket toSend = {MY_NUMBER, i};
            memcpy(toSend.mincost, costs, sizeof(int)*MAX_NODES);
            if(TraceLevel > 0){
                printf("At time t=%f, node %d sends packet to node %d with:", clocktime,
                    MY_NUMBER, i);
                    for(j=0; j<MAX_NODES; j++){
                        printf(" %d", dt1.costs[j][MY_NUMBER]);
                    }
                    printf("\n");
            }
            toLayer2(toSend);
        }
    }
    if(TraceLevel > 0){
        printdt1(MY_NUMBER, neighbor1, &dt1);
    }
}