Пример #1
0
void etx_handle_beacon(ipv6_addr_t *candidate_address)
{
    /*
     * Handle the ETX probe that has been received and update all infos.
     * If the candidate address is unknown, try to add it to my struct.
     */

    DEBUG(
        "ETX beacon package received with following values:\n"
        "\tPackage Option:%x\n"
        "\t   Data Length:%u\n"
        "\tSource Address:%d\n\n", etx_rec_buf[ETX_PKT_OPT], etx_rec_buf[ETX_PKT_LEN],
        candidate_address->uint8[ETX_IPV6_LAST_BYTE]);

    etx_neighbor_t *candidate = etx_find_candidate(candidate_address);

    if (candidate == NULL) {
        //Candidate was not found in my list, I should add it
        candidate = etx_add_candidate(candidate_address);

        if (candidate == NULL) {
            DEBUGF("[ERROR] Candidate could not get added\n");
            DEBUG("Increase the constant ETX_MAX_CANDIDATE_NEIHGBORS\n");
            return;
        }
    }

    //I have received 1 packet from this candidate in this round
    //This value will be reset by etx_update to 0
    candidate->tx_cur_round = 1;

    // If i find my address in this probe, update the packet_rx value for
    // this candidate.
    etx_probe_t *rec_pkt = etx_get_rec_buf();

    for (uint8_t i = 0; i < rec_pkt->length / ETX_TUPLE_SIZE; i++) {
        DEBUG("\tIPv6 short Addr:%u\n"
              "\tPackets f. Addr:%u\n\n", rec_pkt->data[i * ETX_TUPLE_SIZE],
              rec_pkt->data[i * ETX_TUPLE_SIZE + ETX_PKT_REC_OFFSET]);

        if (rec_pkt->data[i * ETX_TUPLE_SIZE]
            == own_address->uint8[ETX_IPV6_LAST_BYTE]) {

            candidate->packets_rx = rec_pkt->data[i * ETX_TUPLE_SIZE
                                                  + ETX_PKT_REC_OFFSET];
        }
    }

    //Last, update the ETX value for this candidate
    etx_update(candidate);
}
Пример #2
0
double etx_get_metric(ipv6_addr_t * address) {
    etx_neighbor_t * candidate = etx_find_candidate(address);
    if (candidate != NULL ) {
        if (etx_count_packet_tx(candidate) > 0) {
            //this means the current etx_value is not outdated
            return candidate->cur_etx;
        } else {
            //The last time I received a packet is too long ago to give a
            //good estimate of the etx value
            return 0;
        }
    }
    return 0;
}