⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tc_set.c

📁 wifi 无线网络路由协议OLSR linux下C代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    if (tc_edge_inv) {#if 0      OLSR_PRINTF(1, "TC:   found inverse edge for %s\n",                  olsr_ip_to_string(&tc_edge_inv->T_dest_addr));#endif      /*       * Connect the edges mutually.       */      tc_edge_inv->edge_inv = tc_edge;      tc_edge->edge_inv = tc_edge_inv;    }  }  /*   * Update the etx.   */  olsr_calc_tc_edge_entry_etx(tc_edge);  return tc_edge;}/** * Delete a TC edge entry. * * @param tc the TC entry * @param tc_edge the TC edge entry */voidolsr_delete_tc_edge_entry(struct tc_edge_entry *tc_edge){  struct tc_entry *tc;  struct tc_edge_entry *tc_edge_inv;#if 0  OLSR_PRINTF(1, "TC: del edge entry %s\n", olsr_tc_edge_to_string(tc_edge));#endif  tc = tc_edge->tc;  avl_delete(&tc->edge_tree, &tc_edge->edge_node);  /*   * Clear the backpointer of our inverse edge.   */  tc_edge_inv = tc_edge->edge_inv;  if (tc_edge_inv) {    tc_edge_inv->edge_inv = NULL;  }  /*   * Delete the tc_entry if the last edge is gone.   */  if (!tc_edge->tc->edge_tree.count) {    /*     * Only remove remote tc entries.     */    if (tc_edge->tc != tc_myself) {      olsr_delete_tc_entry(tc_edge->tc);    }  }  free(tc_edge);}/** * Delete all destinations that have a * lower ANSN than the one in the message * * @param tc the entry to delete edges from * @param msg the message to fetch the ANSN from * @return 1 if any destinations were deleted 0 if not */intolsr_tc_delete_mprs(struct tc_entry *tc, struct tc_message *msg){  struct tc_edge_entry *tc_edge;  int retval;#if 0  OLSR_PRINTF(5, "TC: deleting MPRS\n");#endif  retval = 0;  OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {    if (SEQNO_GREATER_THAN(msg->ansn, tc_edge->T_seq)) {      /*       * Do not delete the edge now, just mark the edge as down.       * Downed edges will be ignored by the SPF computation.       * It could be that a TC message spans across multiple packets,       * which causes an edge delete followed by an edge add.       * If the edge gets refreshed in subsequent packets then we have       * avoided a two edge transistion.       * If the edge really went away then after the garbage collection       * timer has expired olsr_time_out_tc_set() will do the needful.       */      tc_edge->flags |= OLSR_TC_EDGE_DOWN;      olsr_set_tc_edge_timer(tc_edge, OLSR_TC_EDGE_GC_TIME);      retval = 1;    }  } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);  return retval;}/* * Determine if a etx change was more than 10% * Need to know this for triggering a SPF calculation. */static olsr_boololsr_etx_significant_change(float etx1, float etx2){  float rel_lq;  if (etx1 == 0.0 || etx2 == 0.0) {    return OLSR_TRUE;  }  rel_lq = etx1 / etx2;  if (rel_lq > 1.1 || rel_lq < 0.9) {    return OLSR_TRUE;  }  return OLSR_FALSE;}/** * Update the destinations registered on an entry. * Creates new dest-entries if not registered. * Bases update on a receivied TC message * * @param entry the TC entry to check * @msg the TC message to update by * @return 1 if entries are added 0 if not */intolsr_tc_update_mprs(struct tc_entry *tc, struct tc_message *msg){  struct tc_mpr_addr *mprs;  struct tc_edge_entry *tc_edge;  int edge_change;#if 0  OLSR_PRINTF(1, "TC: update MPRS\n");#endif  edge_change = 0;  mprs = msg->multipoint_relay_selector_address;    /* Add all the MPRs */  while (mprs) {    /* First check if we know this edge */    tc_edge = olsr_lookup_tc_edge(tc, &mprs->address);    if(!tc_edge) {            /*       * Yet unknown - create it.       */      olsr_add_tc_edge_entry(tc, &mprs->address, msg->ansn,                             (unsigned int )msg->vtime,                             mprs->link_quality, mprs->neigh_link_quality);      edge_change = 1;    } else {      /*       * We know this edge - Update entry.       */      olsr_set_tc_edge_timer(tc_edge, msg->vtime*1000);      tc_edge->T_seq = msg->ansn;      /*       * Clear the (possibly set) down flag.       */      tc_edge->flags &= ~OLSR_TC_EDGE_DOWN;      /*       * Determine if the etx change is meaningful enough       * in order to trigger a SPF calculation.       */      if (olsr_etx_significant_change(tc_edge->link_quality,                                      mprs->neigh_link_quality)) {        if (msg->hop_count <= olsr_cnf->lq_dlimit)          edge_change = 1;      }      tc_edge->link_quality = mprs->neigh_link_quality;      if (olsr_etx_significant_change(tc_edge->inverse_link_quality,                                      mprs->link_quality)) {        if (msg->hop_count <= olsr_cnf->lq_dlimit)          edge_change = 1;      }      tc_edge->inverse_link_quality = mprs->link_quality;      /*       * Update the etx.       */      olsr_calc_tc_edge_entry_etx(tc_edge);#if 0      if (edge_change) {                  OLSR_PRINTF(1, "TC:   chg edge entry %s\n",                    olsr_tc_edge_to_string(tc_edge));      }#endif    }    mprs = mprs->next;  }  return edge_change;}/** * Lookup an edge hanging off a TC entry. * * @param entry the entry to check * @param dst_addr the destination address to check for * @return a pointer to the tc_edge found - or NULL */struct tc_edge_entry *olsr_lookup_tc_edge(struct tc_entry *tc, union olsr_ip_addr *edge_addr){  struct avl_node *edge_node;  #if 0  OLSR_PRINTF(1, "TC: lookup dst\n");#endif  edge_node = avl_find(&tc->edge_tree, edge_addr);  if (edge_node) {    return edge_node->data;  }  return NULL;}/** * Walk the timers and time out entries. * * @return nada */voidolsr_time_out_tc_set(void){  struct tc_entry *tc;  struct tc_edge_entry *tc_edge;  OLSR_FOR_ALL_TC_ENTRIES(tc)    OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {    /*     * Delete outdated edges.     */    if(TIMED_OUT(tc_edge->T_time)) {      olsr_delete_tc_edge_entry(tc_edge);      changes_topology = OLSR_TRUE;    }  } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);  OLSR_FOR_ALL_TC_ENTRIES_END(tc)}/** * Print the topology table to stdout */intolsr_print_tc_table(void){  struct tc_entry *tc;  struct tc_edge_entry *tc_edge;  char *fstr;  float etx;    OLSR_PRINTF(1, "\n--- %02d:%02d:%02d.%02d ------------------------------------------------- TOPOLOGY\n\n",              nowtm->tm_hour,              nowtm->tm_min,              nowtm->tm_sec,              (int)now.tv_usec / 10000);  if (olsr_cnf->ip_version == AF_INET)    {      OLSR_PRINTF(1, "Source IP addr   Dest IP addr     LQ     ILQ    ETX\n");      fstr = "%-15s  %-15s  %5.3f  %5.3f  %.2f\n";    }  else    {      OLSR_PRINTF(1, "Source IP addr                Dest IP addr                    LQ     ILQ    ETX\n");      fstr = "%-30s%-30s  %5.3f  %5.3f  %.2f\n";    }  OLSR_FOR_ALL_TC_ENTRIES(tc) {    OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {      if (tc_edge->link_quality < MIN_LINK_QUALITY ||          tc_edge->inverse_link_quality < MIN_LINK_QUALITY) {        etx = 0.0;      } else {        etx = 1.0 / (tc_edge->link_quality * tc_edge->inverse_link_quality);      }      OLSR_PRINTF(1, fstr, olsr_ip_to_string(&tc->addr),                  olsr_ip_to_string(&tc_edge->T_dest_addr),                  tc_edge->link_quality, tc_edge->inverse_link_quality, etx);    } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);  } OLSR_FOR_ALL_TC_ENTRIES_END(tc);  return 1;}/* * Local Variables: * c-basic-offset: 2 * End: */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -