Пример #1
0
void
olsr_free_tc_packet(struct tc_message *message)
{
  struct tc_mpr_addr *mprs = NULL, *prev_mprs = NULL;
  ATTACHED_NETWORK *tmp = NULL, *del = NULL;

  if(!message)
    return;

  //free local interface block
  OLSR_DeleteList_Static(&message->local_iface_list);

  mprs = message->mpr_selector_address;

  while (mprs)
    {
      prev_mprs = mprs;
      mprs = mprs->next;
      free(prev_mprs);
    }

  tmp = message->attached_net_addr;
  while(tmp)
    {
      del = tmp;
      tmp = tmp->next;
      free(del);
    }

}
Пример #2
0
void
free_tlv_block(OLSR_LIST *tlv_block)
{
  OLSR_LIST_ENTRY *tmp = NULL;
  BASE_TLV *data_base_tlv = NULL;

  tmp = tlv_block->head;
  while (tmp)
    {
      data_base_tlv = (BASE_TLV *)tmp->data;
      if(data_base_tlv->value)
      free(data_base_tlv->value);

      tmp = tmp->next;
    }

  OLSR_DeleteList_Static(tlv_block);
}
Пример #3
0
/**
 *Free the memory allocated for a HELLO packet.
 *
 *@param message the pointer to the packet to erase
 *
 *@return nada
 */
void
olsr_free_hello_packet(struct hello_message *message)
{
  struct hello_neighbor *nb = NULL, *prev_nb = NULL;

  if(!message)
    return;

  //free local interface block
  OLSR_DeleteList_Static(&message->local_iface_list);

  nb = message->neighbors;

  while (nb)
    {
      prev_nb = nb;
      nb = nb->next;
      free(prev_nb);
    }
}
Пример #4
0
OLSR_LIST *proc_mpr_set_per_interface(struct olsrv2 *olsr,
                      union olsr_ip_addr *local_iface_addr)
{
  OLSR_LIST *MPR_set = NULL, N, N2;

  OLSR_LIST *retList = NULL;
  OLSR_LIST_ENTRY *tmp = NULL, *retList_tmp = NULL;
  OLSR_LINK_TUPLE *link_data = NULL;
  OLSR_2NEIGH_TUPLE *two_neigh_data = NULL;
  OLSR_MPR_N_TUPLE *mpr_n_data = NULL;
  OLSR_MPR_N2_TUPLE *mpr_n2_data = NULL;

  int hash_index;
  olsr_time_t time;
  get_current_time(olsr, &time);

  if (DEBUG_OLSRV2)
  {
      olsr_printf("\n[Start MPR selection per interface]\n");
  }

  //Init MPR set
  MPR_set = (OLSR_LIST *)olsr_malloc(sizeof(OLSR_LIST), __FUNCTION__);
  OLSR_InitList(MPR_set);

  //Create MPR N
  // N - the set of such neighbor interfaces
  if (DEBUG_OLSRV2)
  {
      olsr_printf("[Create N]\n");
      olsr_printf("[Appendix A.2]\n");
  }
  OLSR_InitList(&N);

  tmp = olsr->link_set.head;
  while (tmp != NULL){
    link_data = (OLSR_LINK_TUPLE *)tmp->data;
    if (link_data->L_willingness > WILL_NEVER &&
       get_link_status(time,
               link_data->L_SYM_time,
               link_data->L_ASYM_time,
               link_data->L_LOST_LINK_time) == SYMMETRIC){
      if (equal_ip_addr(olsr, &link_data->L_local_iface_addr,
               local_iface_addr)){


    if (search_mprN_for_exist(olsr, &N, &link_data->L_neighbor_iface_addr)
       == OLSR_FALSE){


      // Calculate D(y), where y is a member of N, for all interfaces in N.
      int retNum = check_2neigh_set_for_mpr_n_exist_num_entry(olsr, local_iface_addr,
                                &link_data->L_neighbor_iface_addr);
      if (retNum > 0){
        insert_mprN(&N, &link_data->L_neighbor_iface_addr,
            /*retList->numEntry*/retNum, 0,
            link_data->L_willingness);

      }
    }
      }
    }
    tmp = tmp->next;
  }

  //print_mprN(olsr, &N);

  //Create MPR N2
  // N2 - the set of such 2-hop neighbor interfaces
  if (DEBUG_OLSRV2)
  {
      olsr_printf("[Create N2]\n");
  }

  OLSR_InitList(&N2);
  for (hash_index = 0; hash_index < HASHSIZE; hash_index++)
    {
      tmp = olsr->two_neigh_set[hash_index].list.head;
      while (tmp != NULL){
    two_neigh_data = (OLSR_2NEIGH_TUPLE *)tmp->data;

    if (search_mprN_for_exist(olsr, &N, &two_neigh_data->N2_neighbor_iface_addr)
       == OLSR_TRUE &&
       search_association_set_for_addr_exist(olsr, &two_neigh_data->N2_2hop_iface_addr)
       == OLSR_FALSE){

      if (equal_ip_addr(olsr, &two_neigh_data->N2_local_iface_addr,
               local_iface_addr)){
        if (search_mprN_for_exist(olsr, &N, &two_neigh_data->N2_2hop_iface_addr)
           == OLSR_TRUE){
          tmp = tmp->next;
          continue;
        }


        if (search_mprN2_for_exist(olsr, &N2, &two_neigh_data->N2_2hop_iface_addr) == OLSR_FALSE)
        {
          insert_mprN2(&N2, &two_neigh_data->N2_2hop_iface_addr);
        }
      }

    }
    tmp = tmp->next;
      }
    }
  //print_mprN2(olsr, &N2);


  //Appendix A.1
  // Start with an MPR set made of all members of N with N_willingness
  // equal to WILL_ALWAYS
  if (DEBUG_OLSRV2)
  {
      olsr_printf("[Appendix A.1]\n");
  }

  tmp = N.head;
  while (tmp != NULL){
    mpr_n_data = (OLSR_MPR_N_TUPLE *)tmp->data;
    if (mpr_n_data->willingness == WILL_ALWAYS)
      insert_mpr_set_per_interface(MPR_set, local_iface_addr, &mpr_n_data->addr);
    tmp = tmp->next;
  }

  update_mprN2(olsr,
           &N2, MPR_set, local_iface_addr);

  //print_mprN2(olsr, &N2);

  //Appendix A.3
  // Add to the MPR set those interfaces in N, which are the *only*
  // nodes to provide reachability to an interface in N2.  For
  // example, if interface B in N2 can be reached only through a
  // symmetric link to interface A in N, then add interface B to the
  // MPR set.  Remove the interfaces from N2 which are now covered by
  // a interface in the MPR set.
  if (DEBUG_OLSRV2)
  {
      olsr_printf("[Appendix A.3]\n");
  }

  tmp = N2.head;
  while (tmp != NULL){
    mpr_n2_data = (OLSR_MPR_N2_TUPLE *)tmp->data;
    retList =
      search_2neigh_set_for_mpr_n2(olsr,
                   local_iface_addr,
                   &mpr_n2_data->addr);
    if (retList != NULL){
      if (retList->numEntry == 1){

    two_neigh_data = (OLSR_2NEIGH_TUPLE *)retList->head->data;
    insert_mpr_set_per_interface(MPR_set,
                     local_iface_addr,
                     &two_neigh_data->N2_neighbor_iface_addr);
    update_mprN2_locally(olsr,
                 &N2,
                 local_iface_addr,
                 &two_neigh_data->N2_neighbor_iface_addr);
    tmp = N2.head;
    OLSR_DeleteList_Search(retList);
    continue;
      }
      OLSR_DeleteList_Search(retList);
    }

    tmp = tmp->next;
  }

  //print_mprN2(olsr, &N2);

  //Appendix A.4
  // While there exist interfaces in N2 which are not covered by at
  // least one interface in the MPR set:
  if (DEBUG_OLSRV2)
  {
      olsr_printf("[Appendix A.4]\n");
  }

  while (N2.head != NULL){
    //Appendix A.4.1
    // For each interface in N, calculate the reachability, i.e.,
    // the number of interfaces in N2 which are not yet covered by
    // at least one node in the MPR set, and which are reachable
    // through this neighbor interface;
    //OLSR_LIST *ret;

    olsr_u32_t max_willingness, max_reachability, max_D;
    olsr_u32_t i;
    union olsr_ip_addr mpr_addr;
    union olsr_ip_addr random_mpr[OLSR_MAX_DUPLICATE_MPR];

    memset(&mpr_addr, 0, sizeof(olsr_ip_addr));

    if (DEBUG_OLSRV2)
    {
    olsr_printf("[Appendix A.4.1]\n");
    }


    tmp = N.head;
    while (tmp != NULL){
      mpr_n_data = (OLSR_MPR_N_TUPLE *)tmp->data;
      mpr_n_data->reachability = 0;

      retList =
    search_2neigh_set_for_mpr_n(olsr,
                    local_iface_addr,
                    &mpr_n_data->addr);

      if (retList != NULL){
    retList_tmp = retList->head;
    while (retList_tmp != NULL){
      two_neigh_data = (OLSR_2NEIGH_TUPLE *)retList_tmp->data;

      if (search_mprN2_for_exist(olsr, &N2, &two_neigh_data->N2_2hop_iface_addr)
         == OLSR_TRUE){
        mpr_n_data->reachability++;
      }

      retList_tmp = retList_tmp->next;
    }
    OLSR_DeleteList_Search(retList);
      }

      tmp = tmp->next;
    }

    //print_mprN(olsr, &N);


    //Appendix A.4.2(XXX)
    // Select as a MPR the interface with highest N_willingness
    // among the interfaces in N with non-zero reachability.
    // In case of multiple choice select the interface which provides
    // reachability to the maximum number of interfaces in N2.
    // In case of multiple interfaces providing the same amount of
    // reachability, select the interface as MPR whose D(y) is
    // greater.
    // Remove the interfaces from N2 which are now covered by an interface in the MPR set.

    tmp = N.head;
    max_willingness = WILL_NEVER; //0
    max_reachability = 0;
    max_D = 0;
    i = 0;

    while (tmp != NULL){
      mpr_n_data = (OLSR_MPR_N_TUPLE *)tmp->data;

      if (mpr_n_data->reachability == 0){
    tmp = tmp->next;
    continue;
      }

      //check willingness
      if (mpr_n_data->willingness > max_willingness){
    max_willingness = mpr_n_data->willingness;
    max_reachability = mpr_n_data->reachability;
    max_D = mpr_n_data->D;
    i = 0;
    mpr_addr = mpr_n_data->addr;
      }
      else if (mpr_n_data->willingness == max_willingness){

    //check reachability
    if (mpr_n_data->reachability > max_reachability){
      max_reachability = mpr_n_data->reachability;
      max_D = mpr_n_data->D;
      i = 0;
      mpr_addr = mpr_n_data->addr;
    }
    else if (mpr_n_data->reachability == max_reachability){

      //check D(y)
      if (mpr_n_data->D > max_D){
        max_D = mpr_n_data->D;
        i = 0;
        mpr_addr = mpr_n_data->addr;
      }
      else if (mpr_n_data->D == max_D){

        if (i == 0){
          random_mpr[i++] = mpr_addr;
        }
        if (i < OLSR_MAX_DUPLICATE_MPR){
          random_mpr[i++] = mpr_n_data->addr;
        }

      }
    }
      }
      tmp = tmp->next;

    }// ....now checked duplication

    if (max_willingness == WILL_NEVER){
      olsr_error("MPR selection is wrong "
         "there is no MPR which have available willingness, "
         "or non-zero-reachability");
    }

    if (i != 0){
      i = (olsr_u32_t)(random(olsr)%i);
      mpr_addr = random_mpr[i];
    }

    insert_mpr_set_per_interface(MPR_set,
                 local_iface_addr,
                 &mpr_addr);

    update_mprN2_locally(olsr,
             &N2,
             local_iface_addr,
             &mpr_addr);

    //print_mpr_set_per_interface(olsr, MPR_set);
  }

  //print_mpr_set_per_interface(olsr, MPR_set);

  if (DEBUG_OLSRV2)
  {
      olsr_printf("[Complete MPR selection per interface]\n\n");
  }

  OLSR_DeleteList_Static(&N);
  OLSR_DeleteList_Static(&N2);

  return MPR_set;
}
Пример #5
0
void
init_forward_infomation(struct olsrv2 *olsr, unsigned char index)
{
  OLSR_DeleteList_Static(&olsr->forward_info[index].msg_list);
  assert(olsr->forward_info[index].msg_list.head == NULL);
}