📄 olsr.cc
字号:
OLSR::node_id(ra_addr()), OLSR::node_id(tuple->nb_iface_addr())); updated_link_tuple(tuple); state_.erase_nb2hop_tuples(get_main_addr(tuple->nb_iface_addr())); state_.erase_mprsel_tuples(get_main_addr(tuple->nb_iface_addr())); mpr_computation(); rtable_computation();}////// \brief Adds a duplicate tuple to the Duplicate Set.////// \param tuple the duplicate tuple to be added.///voidOLSR::add_dup_tuple(OLSR_dup_tuple* tuple) { /*debug("%f: Node %d adds dup tuple: addr = %d seq_num = %d\n", CURRENT_TIME, OLSR::node_id(ra_addr()), OLSR::node_id(tuple->addr()), tuple->seq_num());*/ state_.insert_dup_tuple(tuple);}////// \brief Removes a duplicate tuple from the Duplicate Set.////// \param tuple the duplicate tuple to be removed.///voidOLSR::rm_dup_tuple(OLSR_dup_tuple* tuple) { /*debug("%f: Node %d removes dup tuple: addr = %d seq_num = %d\n", CURRENT_TIME, OLSR::node_id(ra_addr()), OLSR::node_id(tuple->addr()), tuple->seq_num());*/ state_.erase_dup_tuple(tuple);}////// \brief Adds a link tuple to the Link Set (and an associated neighbor tuple to the Neighbor Set).////// \param tuple the link tuple to be added./// \param willingness willingness of the node which is going to be inserted in the Neighbor Set.///voidOLSR::add_link_tuple(OLSR_link_tuple* tuple, u_int8_t willingness) { double now = CURRENT_TIME; debug("%f: Node %d adds link tuple: nb_addr = %d\n", now, OLSR::node_id(ra_addr()), OLSR::node_id(tuple->nb_iface_addr())); state_.insert_link_tuple(tuple); // Creates associated neighbor tuple OLSR_nb_tuple* nb_tuple = new OLSR_nb_tuple; nb_tuple->nb_main_addr() = get_main_addr(tuple->nb_iface_addr()); nb_tuple->willingness() = willingness; if (tuple->sym_time() >= now) nb_tuple->status() = OLSR_STATUS_SYM; else nb_tuple->status() = OLSR_STATUS_NOT_SYM; add_nb_tuple(nb_tuple);}////// \brief Removes a link tuple from the Link Set.////// \param tuple the link tuple to be removed.///voidOLSR::rm_link_tuple(OLSR_link_tuple* tuple) { nsaddr_t nb_addr = get_main_addr(tuple->nb_iface_addr()); double now = CURRENT_TIME; debug("%f: Node %d removes link tuple: nb_addr = %d\n", now, OLSR::node_id(ra_addr()), OLSR::node_id(tuple->nb_iface_addr())); // Prints this here cause we are not actually calling rm_nb_tuple() (efficiency stuff) debug("%f: Node %d removes neighbor tuple: nb_addr = %d\n", now, OLSR::node_id(ra_addr()), OLSR::node_id(nb_addr)); state_.erase_link_tuple(tuple); OLSR_nb_tuple* nb_tuple = state_.find_nb_tuple(nb_addr); state_.erase_nb_tuple(nb_tuple); delete nb_tuple;}////// \brief This function is invoked when a link tuple is updated. Its aim is to/// also update the corresponding neighbor tuple if it is needed.////// \param tuple the link tuple which has been updated.///voidOLSR::updated_link_tuple(OLSR_link_tuple* tuple) { double now = CURRENT_TIME; // Each time a link tuple changes, the associated neighbor tuple must be recomputed OLSR_nb_tuple* nb_tuple = state_.find_nb_tuple(get_main_addr(tuple->nb_iface_addr())); if (nb_tuple != NULL) { if (use_mac() && tuple->lost_time() >= now) nb_tuple->status() = OLSR_STATUS_NOT_SYM; else if (tuple->sym_time() >= now) nb_tuple->status() = OLSR_STATUS_SYM; else nb_tuple->status() = OLSR_STATUS_NOT_SYM; } debug("%f: Node %d has updated link tuple: nb_addr = %d status = %s\n", now, OLSR::node_id(ra_addr()), OLSR::node_id(tuple->nb_iface_addr()), ((nb_tuple->status() == OLSR_STATUS_SYM) ? "sym" : "not_sym"));}////// \brief Adds a neighbor tuple to the Neighbor Set.////// \param tuple the neighbor tuple to be added.///voidOLSR::add_nb_tuple(OLSR_nb_tuple* tuple) { debug("%f: Node %d adds neighbor tuple: nb_addr = %d status = %s\n", CURRENT_TIME, OLSR::node_id(ra_addr()), OLSR::node_id(tuple->nb_main_addr()), ((tuple->status() == OLSR_STATUS_SYM) ? "sym" : "not_sym")); state_.insert_nb_tuple(tuple);}////// \brief Removes a neighbor tuple from the Neighbor Set.////// \param tuple the neighbor tuple to be removed.///voidOLSR::rm_nb_tuple(OLSR_nb_tuple* tuple) { debug("%f: Node %d removes neighbor tuple: nb_addr = %d status = %s\n", CURRENT_TIME, OLSR::node_id(ra_addr()), OLSR::node_id(tuple->nb_main_addr()), ((tuple->status() == OLSR_STATUS_SYM) ? "sym" : "not_sym")); state_.erase_nb_tuple(tuple);}////// \brief Adds a 2-hop neighbor tuple to the 2-hop Neighbor Set.////// \param tuple the 2-hop neighbor tuple to be added.///voidOLSR::add_nb2hop_tuple(OLSR_nb2hop_tuple* tuple) { debug("%f: Node %d adds 2-hop neighbor tuple: nb_addr = %d nb2hop_addr = %d\n", CURRENT_TIME, OLSR::node_id(ra_addr()), OLSR::node_id(tuple->nb_main_addr()), OLSR::node_id(tuple->nb2hop_addr())); state_.insert_nb2hop_tuple(tuple);}////// \brief Removes a 2-hop neighbor tuple from the 2-hop Neighbor Set.////// \param tuple the 2-hop neighbor tuple to be removed.///voidOLSR::rm_nb2hop_tuple(OLSR_nb2hop_tuple* tuple) { debug("%f: Node %d removes 2-hop neighbor tuple: nb_addr = %d nb2hop_addr = %d\n", CURRENT_TIME, OLSR::node_id(ra_addr()), OLSR::node_id(tuple->nb_main_addr()), OLSR::node_id(tuple->nb2hop_addr())); state_.erase_nb2hop_tuple(tuple);}////// \brief Adds an MPR selector tuple to the MPR Selector Set.////// Advertised Neighbor Sequence Number (ANSN) is also updated.////// \param tuple the MPR selector tuple to be added.///voidOLSR::add_mprsel_tuple(OLSR_mprsel_tuple* tuple) { debug("%f: Node %d adds MPR selector tuple: nb_addr = %d\n", CURRENT_TIME, OLSR::node_id(ra_addr()), OLSR::node_id(tuple->main_addr())); state_.insert_mprsel_tuple(tuple); ansn_ = (ansn_ + 1)%(OLSR_MAX_SEQ_NUM + 1);}////// \brief Removes an MPR selector tuple from the MPR Selector Set.////// Advertised Neighbor Sequence Number (ANSN) is also updated.////// \param tuple the MPR selector tuple to be removed.///voidOLSR::rm_mprsel_tuple(OLSR_mprsel_tuple* tuple) { debug("%f: Node %d removes MPR selector tuple: nb_addr = %d\n", CURRENT_TIME, OLSR::node_id(ra_addr()), OLSR::node_id(tuple->main_addr())); state_.erase_mprsel_tuple(tuple); ansn_ = (ansn_ + 1)%(OLSR_MAX_SEQ_NUM + 1);}////// \brief Adds a topology tuple to the Topology Set.////// \param tuple the topology tuple to be added.///voidOLSR::add_topology_tuple(OLSR_topology_tuple* tuple) { debug("%f: Node %d adds topology tuple: dest_addr = %d last_addr = %d seq = %d\n", CURRENT_TIME, OLSR::node_id(ra_addr()), OLSR::node_id(tuple->dest_addr()), OLSR::node_id(tuple->last_addr()), tuple->seq()); state_.insert_topology_tuple(tuple);}////// \brief Removes a topology tuple from the Topology Set.////// \param tuple the topology tuple to be removed.///voidOLSR::rm_topology_tuple(OLSR_topology_tuple* tuple) { debug("%f: Node %d removes topology tuple: dest_addr = %d last_addr = %d seq = %d\n", CURRENT_TIME, OLSR::node_id(ra_addr()), OLSR::node_id(tuple->dest_addr()), OLSR::node_id(tuple->last_addr()), tuple->seq()); state_.erase_topology_tuple(tuple);}////// \brief Adds an interface association tuple to the Interface Association Set.////// \param tuple the interface association tuple to be added.///voidOLSR::add_ifaceassoc_tuple(OLSR_iface_assoc_tuple* tuple) { debug("%f: Node %d adds iface association tuple: main_addr = %d iface_addr = %d\n", CURRENT_TIME, OLSR::node_id(ra_addr()), OLSR::node_id(tuple->main_addr()), OLSR::node_id(tuple->iface_addr())); state_.insert_ifaceassoc_tuple(tuple);}////// \brief Removes an interface association tuple from the Interface Association Set.////// \param tuple the interface association tuple to be removed.///voidOLSR::rm_ifaceassoc_tuple(OLSR_iface_assoc_tuple* tuple) { debug("%f: Node %d removes iface association tuple: main_addr = %d iface_addr = %d\n", CURRENT_TIME, OLSR::node_id(ra_addr()), OLSR::node_id(tuple->main_addr()), OLSR::node_id(tuple->iface_addr())); state_.erase_ifaceassoc_tuple(tuple);}////// \brief Gets the main address associated with a given interface address.////// \param iface_addr the interface address./// \return the corresponding main address.///nsaddr_tOLSR::get_main_addr(nsaddr_t iface_addr) { OLSR_iface_assoc_tuple* tuple = state_.find_ifaceassoc_tuple(iface_addr); if (tuple != NULL) return tuple->main_addr(); return iface_addr;}////// \brief Determines which sequence number is bigger (as it is defined in RFC 3626).////// \param s1 a sequence number./// \param s2 a sequence number./// \return true if s1 > s2, false in other case.///boolOLSR::seq_num_bigger_than(u_int16_t s1, u_int16_t s2) { return (s1 > s2 && s1-s2 <= OLSR_MAX_SEQ_NUM/2) || (s2 > s1 && s2-s1 > OLSR_MAX_SEQ_NUM/2);}////// \brief This auxiliary function (defined in RFC 3626) is used for calculating the MPR Set.////// \param tuple the neighbor tuple which has the main address of the node we are going to calculate its degree to./// \return the degree of the node.///intOLSR::degree(OLSR_nb_tuple* tuple) { int degree = 0; for (nb2hopset_t::iterator it = nb2hopset().begin(); it != nb2hopset().end(); it++) { OLSR_nb2hop_tuple* nb2hop_tuple = *it; if (nb2hop_tuple->nb_main_addr() == tuple->nb_main_addr()) { OLSR_nb_tuple* nb_tuple = state_.find_nb_tuple(nb2hop_tuple->nb_main_addr()); if (nb_tuple == NULL) degree++; } } return degree;}////// \brief Converts a decimal number of seconds to the mantissa/exponent format.////// \param seconds decimal number of seconds we want to convert./// \return the number of seconds in mantissa/exponent format.///u_int8_tOLSR::seconds_to_emf(double seconds) { // This implementation has been taken from unik-olsrd-0.4.5 (mantissa.c), // licensed under the GNU Public License (GPL) int a, b = 0; while (seconds/OLSR_C >= pow((double)2, (double)b)) b++; b--; if (b < 0) { a = 1; b = 0; } else if (b > 15) { a = 15; b = 15; } else { a = (int)(16*((double)seconds/(OLSR_C*(double)pow(2, b))-1)); while (a >= 16) { a -= 16; b++; } } return (u_int8_t)(a*16+b);}////// \brief Converts a number of seconds in the mantissa/exponent format to a decimal number.////// \param olsr_format number of seconds in mantissa/exponent format./// \return the decimal number of seconds.///doubleOLSR::emf_to_seconds(u_int8_t olsr_format) { // This implementation has been taken from unik-olsrd-0.4.5 (mantissa.c), // licensed under the GNU Public License (GPL) int a = olsr_format >> 4; int b = olsr_format - a*16; return (double)(OLSR_C*(1+(double)a/16)*(double)pow(2,b));}////// \brief Returns the identifier of a node given the address of the attached OLSR agent.////// \param addr the address of the OLSR routing agent./// \return the identifier of the node.///intOLSR::node_id(nsaddr_t addr) { // Preventing a bad use for this function if ((u_int32_t)addr == IP_BROADCAST) return addr; // Getting node id Node* node = Node::get_node_by_address(addr); assert(node != NULL); return node->nodeid();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -