📄 networkinterfaces.c
字号:
} else { return 1.0 / (loss * neigh_loss); }} /* CalcEtx */#endif /* USING_THALES_LINK_COST_ROUTING *//* ------------------------------------------------------------------------- * Function : GetBestTwoNeighbors * Description: Find at most two best neighbors on a network interface to forward * a BMF packet to * Input : intf - the network interface * source - the source IP address of the BMF packet * forwardedBy - the IP address of the node that forwarded the BMF * packet * forwardedTo - the IP address of the node to which the BMF packet * was directed * Output : result - the list of the two best neighbors. If only one best * neighbor is found, the second list entry is NULL. If no neigbors * are found, the first and second list entries are both NULL. * nPossibleNeighbors - number of found possible neighbors * Data Used : none * ------------------------------------------------------------------------- */void GetBestTwoNeighbors( struct TBestNeighbors* result, struct TBmfInterface* intf, union olsr_ip_addr* source, union olsr_ip_addr* forwardedBy, union olsr_ip_addr* forwardedTo, int* nPossibleNeighbors){ result->links[0] = NULL; result->links[1] = NULL; /* handle the non-LQ case */ if (olsr_cnf->lq_level == 0) { struct link_entry* walker; *nPossibleNeighbors = 0; /* TODO: get_link_set() is not thread-safe! */ for (walker = get_link_set(); walker != NULL; walker = walker->next) { union olsr_ip_addr* neighborMainIp; /* Consider only links from the specified interface */ if (! COMP_IP(&intf->intAddr, &walker->local_iface_addr)) { continue; /* for */ } OLSR_PRINTF( 8, "%s: ----> Considering forwarding pkt on \"%s\" to %s\n", PLUGIN_NAME_SHORT, intf->ifName, olsr_ip_to_string(&walker->neighbor_iface_addr)); neighborMainIp = MainAddressOf(&walker->neighbor_iface_addr); /* Consider only neighbors with an IP address that differs from the * passed IP addresses (if passed). Rely on short-circuit boolean evaluation. */ if (source != NULL && COMP_IP(neighborMainIp, MainAddressOf(source))) { OLSR_PRINTF( 9, "%s: ----> Not forwarding to %s: is source of pkt\n", PLUGIN_NAME_SHORT, olsr_ip_to_string(&walker->neighbor_iface_addr)); continue; /* for */ } /* Rely on short-circuit boolean evaluation */ if (forwardedBy != NULL && COMP_IP(neighborMainIp, MainAddressOf(forwardedBy))) { OLSR_PRINTF( 9, "%s: ----> Not forwarding to %s: is the node that forwarded the pkt\n", PLUGIN_NAME_SHORT, olsr_ip_to_string(&walker->neighbor_iface_addr)); continue; /* for */ } /* Rely on short-circuit boolean evaluation */ if (forwardedTo != NULL && COMP_IP(neighborMainIp, MainAddressOf(forwardedTo))) { OLSR_PRINTF( 9, "%s: ----> Not forwarding to %s: is the node to which the pkt was forwarded\n", PLUGIN_NAME_SHORT, olsr_ip_to_string(&walker->neighbor_iface_addr)); continue; /* for */ } /* Found a candidate neighbor to direct our packet to */ *nPossibleNeighbors += 1; /* In the non-LQ case, it is not possible to select neigbors * by quality or cost. So just remember the first two found links. */ if (result->links[0] == NULL) { result->links[0] = walker; } else if (result->links[1] == NULL) { result->links[1] = walker; } /* if */ } /* for */ } /* handle the LQ case */ else {#ifdef USING_THALES_LINK_COST_ROUTING struct link_entry* walker; float previousLinkCost = 2 * INFINITE_COST; float bestLinkCost = 2 * INFINITE_COST; float oneButBestLinkCost = 2 * INFINITE_COST; *nPossibleNeighbors = 0; if (forwardedBy != NULL) { /* Retrieve the cost of the link from 'forwardedBy' to myself */ struct link_entry* bestLinkFromForwarder = get_best_link_to_neighbor(forwardedBy); if (bestLinkFromForwarder != NULL) { previousLinkCost = bestLinkFromForwarder->link_cost; } } /* TODO: get_link_set() is not thread-safe! */ for (walker = get_link_set(); walker != NULL; walker = walker->next) { union olsr_ip_addr* neighborMainIp; struct link_entry* bestLinkToNeighbor; struct tc_entry* tcLastHop; /* Consider only links from the specified interface */ if (! COMP_IP(&intf->intAddr, &walker->local_iface_addr)) { continue; /* for */ } OLSR_PRINTF( 9, "%s: ----> Considering forwarding pkt on \"%s\" to %s\n", PLUGIN_NAME_SHORT, intf->ifName, olsr_ip_to_string(&walker->neighbor_iface_addr)); neighborMainIp = MainAddressOf(&walker->neighbor_iface_addr); /* Consider only neighbors with an IP address that differs from the * passed IP addresses (if passed). Rely on short-circuit boolean evaluation. */ if (source != NULL && COMP_IP(neighborMainIp, MainAddressOf(source))) { OLSR_PRINTF( 9, "%s: ----> Not forwarding to %s: is source of pkt\n", PLUGIN_NAME_SHORT, olsr_ip_to_string(&walker->neighbor_iface_addr)); continue; /* for */ } /* Rely on short-circuit boolean evaluation */ if (forwardedBy != NULL && COMP_IP(neighborMainIp, MainAddressOf(forwardedBy))) { OLSR_PRINTF( 9, "%s: ----> Not forwarding to %s: is the node that forwarded the pkt\n", PLUGIN_NAME_SHORT, olsr_ip_to_string(&walker->neighbor_iface_addr)); continue; /* for */ } /* Rely on short-circuit boolean evaluation */ if (forwardedTo != NULL && COMP_IP(neighborMainIp, MainAddressOf(forwardedTo))) { OLSR_PRINTF( 9, "%s: ----> Not forwarding to %s: is the node to which the pkt was forwarded\n", PLUGIN_NAME_SHORT, olsr_ip_to_string(&walker->neighbor_iface_addr)); continue; /* for */ } /* Found a candidate neighbor to direct our packet to */ if (walker->link_cost >= INFINITE_COST) { OLSR_PRINTF( 9, "%s: ----> Not forwarding to %s: link is timing out\n", PLUGIN_NAME_SHORT, olsr_ip_to_string(&walker->neighbor_iface_addr)); continue; /* for */ } /* Compare costs to check if the candidate neighbor is best reached via 'intf' */ OLSR_PRINTF( 9, "%s: ----> Forwarding pkt to %s will cost %5.2f\n", PLUGIN_NAME_SHORT, olsr_ip_to_string(&walker->neighbor_iface_addr), walker->link_cost); /* If the candidate neighbor is best reached via another interface, then skip * the candidate neighbor; the candidate neighbor has been / will be selected via that * other interface. * TODO: get_best_link_to_neighbor() is not thread-safe. */ bestLinkToNeighbor = get_best_link_to_neighbor(&walker->neighbor_iface_addr); if (walker != bestLinkToNeighbor) { if (bestLinkToNeighbor == NULL) { OLSR_PRINTF( 9, "%s: ----> Not forwarding to %s: no link found\n", PLUGIN_NAME_SHORT, olsr_ip_to_string(&walker->neighbor_iface_addr)); } else { struct interface* bestIntf = if_ifwithaddr(&bestLinkToNeighbor->local_iface_addr); OLSR_PRINTF( 9, "%s: ----> Not forwarding to %s: \"%s\" gives a better link to this neighbor, costing %5.2f\n", PLUGIN_NAME_SHORT, olsr_ip_to_string(&walker->neighbor_iface_addr), bestIntf->int_name, bestLinkToNeighbor->link_cost); } continue; /* for */ } if (forwardedBy != NULL) { OLSR_PRINTF( 9, "%s: ----> 2-hop path from %s via me to %s will cost %5.2f\n", PLUGIN_NAME_SHORT, olsr_ip_to_string(forwardedBy), olsr_ip_to_string(&walker->neighbor_iface_addr), previousLinkCost + walker->link_cost); } /* Check the topology table whether the 'forwardedBy' node is itself a direct * neighbor of the candidate neighbor, at a lower cost than the 2-hop route * via myself. If so, we do not need to forward the BMF packet to the candidate * neighbor, because the 'forwardedBy' node will forward the packet. */ if (forwardedBy != NULL) { /* TODO: olsr_lookup_tc_entry() is not thread-safe. */ tcLastHop = olsr_lookup_tc_entry(MainAddressOf(forwardedBy)); if (tcLastHop != NULL) { struct topo_dst* tcDest; /* TODO: olsr_tc_lookup_dst() is not thread-safe. */ tcDest = olsr_tc_lookup_dst(tcLastHop, MainAddressOf(&walker->neighbor_iface_addr)); /* Rely on short-circuit boolean evaluation */ if (tcDest != NULL && previousLinkCost + walker->link_cost > tcDest->link_cost) { OLSR_PRINTF( 9, "%s: ----> Not forwarding to %s: I am not an MPR between %s and %s, direct link costs %5.2f\n", PLUGIN_NAME_SHORT, olsr_ip_to_string(&walker->neighbor_iface_addr), olsr_ip_to_string(forwardedBy), olsr_ip_to_string(&walker->neighbor_iface_addr), tcDest->link_cost); continue; /* for */ } /* if */ } /* if */ } /* if */ *nPossibleNeighbors += 1; /* Remember the best two links. If all are very bad, remember none. */ if (walker->link_cost < bestLinkCost) { result->links[1] = result->links[0]; result->links[0] = walker; bestLinkCost = walker->link_cost; } else if (walker->link_cost < oneButBestLinkCost) { result->links[1] = walker; oneButBestLinkCost = walker->link_cost; } /* if */ } /* for */#else /* USING_THALES_LINK_COST_ROUTING */ struct link_entry* walker; float previousLinkEtx = 2 * INFINITE_ETX; float bestEtx = 2 * INFINITE_ETX; float oneButBestEtx = 2 * INFINITE_ETX; *nPossibleNeighbors = 0; if (forwardedBy != NULL) { /* Retrieve the cost of the link from 'forwardedBy' to myself */ struct link_entry* bestLinkFromForwarder = get_best_link_to_neighbor(forwardedBy); if (bestLinkFromForwarder != NULL) { previousLinkEtx = CalcEtx( bestLinkFromForwarder->loss_link_quality, bestLinkFromForwarder->neigh_link_quality); } } /* TODO: get_link_set() is not thread-safe! */ for (walker = get_link_set(); walker != NULL; walker = walker->next) { union olsr_ip_addr* neighborMainIp; struct link_entry* bestLinkToNeighbor; struct tc_entry* tcLastHop; float currEtx; /* Consider only links from the specified interface */ if (! COMP_IP(&intf->intAddr, &walker->local_iface_addr)) { continue; /* for */ } OLSR_PRINTF( 9, "%s: ----> Considering forwarding pkt on \"%s\" to %s\n", PLUGIN_NAME_SHORT, intf->ifName, olsr_ip_to_string(&walker->neighbor_iface_addr)); neighborMainIp = MainAddressOf(&walker->neighbor_iface_addr); /* Consider only neighbors with an IP address that differs from the * passed IP addresses (if passed). Rely on short-circuit boolean evaluation. */ if (source != NULL && COMP_IP(neighborMainIp, MainAddressOf(source))) { OLSR_PRINTF( 9, "%s: ----> Not forwarding to %s: is source of pkt\n", PLUGIN_NAME_SHORT, olsr_ip_to_string(&walker->neighbor_iface_addr)); continue; /* for */ } /* Rely on short-circuit boolean evaluation */ if (forwardedBy != NULL && COMP_IP(neighborMainIp, MainAddressOf(forwardedBy))) { OLSR_PRINTF( 9, "%s: ----> Not forwarding to %s: is the node that forwarded the pkt\n", PLUGIN_NAME_SHORT, olsr_ip_to_string(&walker->neighbor_iface_addr)); continue; /* for */ } /* Rely on short-circuit boolean evaluation */ if (forwardedTo != NULL && COMP_IP(neighborMainIp, MainAddressOf(forwardedTo))) { OLSR_PRINTF( 9, "%s: ----> Not forwarding to %s: is the node to which the pkt was forwarded\n", PLUGIN_NAME_SHORT, olsr_ip_to_string(&walker->neighbor_iface_addr)); continue; /* for */ } /* Found a candidate neighbor to direct our packet to */ /* Calculate the link quality (ETX) of the link to the found neighbor */ currEtx = CalcEtx( walker->loss_link_quality,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -