Example #1
0
/*
 * rt_recvfrom - Wrapper for recv_from. Binds received LSA to the sender node
 * and returns the pointer to it.
 *
 * @param sockfd        routing daemon socket identifier
 * @param forwarder_id  pointer to the node id of the forwarder
 * @param dl            pointer to direct neighbors table
 * @param lsa_size      size of LSA received
 * @return              the received LSA
 */
LSA *rt_recvfrom(int sockfd, int *forwarder_id, direct_links *dl, int *lsa_size)
{
    struct sockaddr_in cli_addr;
    socklen_t clilen;
    clilen = sizeof(cli_addr);

    char buf[MAX_BUF];

    int ret;

    LSA *lsa = NULL;

    link_entry *forwarder;

    ret = recvfrom(sockfd, buf, MAX_LSA_LEN, 0, (struct sockaddr *)&cli_addr, &clilen);

    if (ret < 5*sizeof(int))
    {
        return NULL;
    }

    lsa = bytes_to_packet( buf, ret);

    forwarder = lookup_link_entry(dl, &cli_addr);

    *forwarder_id = forwarder->id;
    *lsa_size = ret;

    return lsa;
}
static void
default_lq_parser_ffeth(struct olsr *olsr, struct interface *in_if, union olsr_ip_addr *from_addr)
{
  const union olsr_ip_addr *main_addr;
  struct link_entry *lnk;
  struct default_lq_ffeth_hello *lq;
  uint32_t seq_diff;

  /* Find main address */
  main_addr = mid_lookup_main_addr(from_addr);

  /* Loopup link entry */
  lnk = lookup_link_entry(from_addr, main_addr, in_if);
  if (lnk == NULL) {
    return;
  }

  lq = (struct default_lq_ffeth_hello *)lnk->linkquality;

  /* ignore double package */
  if (lq->last_seq_nr == olsr->olsr_seqno) {
    struct ipaddr_str buf;
    olsr_syslog(OLSR_LOG_INFO, "detected duplicate packet with seqnr %d from %s on %s (%d Bytes)",
		olsr->olsr_seqno,olsr_ip_to_string(&buf, from_addr),in_if->int_name,ntohs(olsr->olsr_packlen));
    return;
  }

  if (lq->last_seq_nr > olsr->olsr_seqno) {
    seq_diff = (uint32_t) olsr->olsr_seqno + 65536 - lq->last_seq_nr;
  } else {
    seq_diff = olsr->olsr_seqno - lq->last_seq_nr;
  }

  /* Jump in sequence numbers ? */
  if (seq_diff > 256) {
    seq_diff = 1;
  }

  lq->received[lq->activePtr]++;
  lq->total[lq->activePtr] += seq_diff;

  lq->last_seq_nr = olsr->olsr_seqno;
  lq->missed_hellos = 0;
}
Example #3
0
void
update_hysteresis_incoming(union olsr_ip_addr *remote, struct interface *local, uint16_t seqno)
{
  struct link_entry *lnk = lookup_link_entry(remote, NULL, local);

  /* Calculate new quality */
  if (lnk != NULL) {
#ifdef DEBUG
    struct ipaddr_str buf;
#endif
    lnk->L_link_quality = olsr_hyst_calc_stability(lnk->L_link_quality);
#ifdef DEBUG
    OLSR_PRINTF(3, "HYST[%s]: %f\n", olsr_ip_to_string(&buf, remote), lnk->L_link_quality);
#endif

    /*
     * see how many packets we have missed and update the link quality
     * for each missed packet; HELLOs have already been accounted for by
     * the timeout function and the number of missed HELLOs has already
     * been added to olsr_seqno there
     */

    if (lnk->olsr_seqno_valid && (unsigned short)(seqno - lnk->olsr_seqno) < 100)
      while (lnk->olsr_seqno != seqno) {
        lnk->L_link_quality = olsr_hyst_calc_instability(lnk->L_link_quality);
#ifdef DEBUG
        OLSR_PRINTF(5, "HYST[%s] PACKET LOSS! %f\n", olsr_ip_to_string(&buf, remote), lnk->L_link_quality);
#endif
        if (lnk->L_link_quality < olsr_cnf->hysteresis_param.thr_low)
          break;

        lnk->olsr_seqno++;
      }

    lnk->olsr_seqno = seqno + 1;
    lnk->olsr_seqno_valid = true;

    //printf("Updating seqno to: %d\n", lnk->olsr_seqno);
  }
  return;
}