void
build_tlv_block_for_index_hello(olsr_pktbuf_t *buf,
    BASE_ADDRESS *base, olsr_u32_t index)
{
//Static Fix
  //static olsr_pktbuf_t *tlv_buf = NULL;
  olsr_pktbuf_t *tlv_buf = NULL;

  tlv_buf = olsr_pktbuf_alloc_with_capa(64);
  olsr_pktbuf_clear(tlv_buf);

  //Create TLV "Link Status"
  create_tlv_for_index_hello(tlv_buf, base, index, Link_Status, SYMMETRIC);
  create_tlv_for_index_hello(tlv_buf, base, index, Link_Status, ASYMMETRIC);
  //  create_tlv_for_index_hello(tlv_buf, base, index, Link_Status, HEARD);
  create_tlv_for_index_hello(tlv_buf, base, index, Link_Status, LOST);

  //create TLV OtherNeigh
  create_tlv_for_index_hello(tlv_buf, base, index, Other_Neigh, SYMMETRIC);
  create_tlv_for_index_hello(tlv_buf, base, index, Other_Neigh, LOST);

  //Create TLV "MPR Selection"
  create_tlv_for_index_hello(tlv_buf, base, index, MPR_Selection, OLSR_TRUE);

  // <tlv-block>
  olsr_pktbuf_append_u16(buf, (olsr_u16_t)tlv_buf->len);    // <tlv-length>
  olsr_pktbuf_append_pktbuf(buf, tlv_buf);  // <tlv>*

  olsr_pktbuf_free(&tlv_buf);

  //free(tlv_buf->data);
  //free(tlv_buf);
}
void
build_tlv_block_for_index_attached_network(olsr_pktbuf_t *buf,
                 BASE_ADDRESS *base,
                 olsr_u32_t index)
{
//Static Fix
  //static olsr_pktbuf_t *tlv_buf = NULL;
  olsr_pktbuf_t *tlv_buf = NULL;

  tlv_buf = olsr_pktbuf_alloc_with_capa(64);
  olsr_pktbuf_clear(tlv_buf);

  create_simple_tlv(tlv_buf,
            PREFIX_LENGTH,
            SINGLE_INDEX,
            1,
            0,
            0,
            &base->data[index].Prefix_Length);

  // <tlv-block>
  olsr_pktbuf_append_u16(buf, (olsr_u16_t)tlv_buf->len);    // <tlv-length>
  olsr_pktbuf_append_pktbuf(buf, tlv_buf);  // <tlv

  olsr_pktbuf_free(&tlv_buf);

  //free(tlv_buf->data);
  //free(tlv_buf);
}
/**
 * <tlv-block>
 * = <tlv-length> <tlv>*
 * <tlv>
 * = <type> <tlv-semantics> <length>? <index-start>? <index-stop>? <value>?
 */
static void
build_tlv_msg(olsr_pktbuf_t *pktbuf, OLSR_LIST *tlv_block)
{
//Static Fix
  //static olsr_pktbuf_t *tlv_buf = NULL;
  olsr_pktbuf_t *tlv_buf = NULL;
  OLSR_LIST_ENTRY *p = NULL;

  olsr_u16_t extend_length;
	//wiss: initialisation du buffer temporaire qu'on va s'en servir
  tlv_buf = olsr_pktbuf_alloc_with_capa(64);
  olsr_pktbuf_clear(tlv_buf);

  for (p = tlv_block->head; p != NULL; p = p->next)
    {
      BASE_TLV *const tlv = (BASE_TLV *)p->data;
      olsr_pktbuf_append_u8(tlv_buf, tlv->tlv_type);
      olsr_pktbuf_append_u8(tlv_buf, tlv->tlv_semantics);

      //index start and stop
      if((tlv->tlv_semantics & NO_INDEX) == 0)
    { //wiss: hon bifout kell chi ella el NO_INDEX
      olsr_pktbuf_append_u8(tlv_buf, tlv->index_start);
      if((tlv->tlv_semantics & SINGLE_INDEX) == 0)// wiss: hon bifout kell chi ella el single index
        olsr_pktbuf_append_u8(tlv_buf, tlv->index_stop); // wiss: hon byetaba2 kell chi ella el no index wel single index ya3ni el tabi3i
    }

      //no value bit  unset
      if((tlv->tlv_semantics & NO_VALUE) == 0)
    { // wiss: hon bifout kell chi ella NO_VALUE ya3ni bifout kell chi bass akid mech MPRSELECTOR
      //extended bit
      if((tlv->tlv_semantics & EXTENDED) == 0)  // wiss: chou extended ma fhemet ma mar2et wala marra !!
        olsr_pktbuf_append_u8(tlv_buf, tlv->tlv_length);
      else
        {
          extend_length = tlv->tlv_length;
          olsr_pktbuf_append_u16(tlv_buf, htons(extend_length));
        }
    }
      // value
      if((tlv->tlv_semantics & NO_VALUE) == 0)
    olsr_pktbuf_append_byte_ary(tlv_buf, tlv->value, tlv->tlv_length);
      //multi value bit unsupported
    }
  olsr_pktbuf_append_u16(pktbuf, (olsr_u16_t)tlv_buf->len);
  olsr_pktbuf_append_pktbuf(pktbuf, tlv_buf);

  //XXX:debug_code(print_tlv_msg(msg_head));
  olsr_pktbuf_free(&tlv_buf);

  //free(tlv_buf->data);
  //free(tlv_buf);
}
Example #4
0
File: olsr.cpp Project: LXiong/ccn
void
forward_message(struct olsrv2 *olsr)
{
  const struct message_header* m_header = &olsr->message_header;
  olsr_pktbuf_t* msg = NULL;

  msg = olsr_pktbuf_alloc();
  olsr_pktbuf_clear(msg);

  /* TC should be forwarded all interface.
     but now, we forward only one interface.
     I'll correct later...  */
  build_message_header(olsr, msg, (olsr_u16_t)olsr->message_body_size,
      m_header->message_type,
      &m_header->orig_addr, m_header->ttl - 1, m_header->hop_count + 1,
      m_header->message_seq_num);


  if (m_header->message_type == TC_MESSAGE){
      olsr->stat.numTcRelayed++;
      if (DEBUG_OLSRV2){
        olsr_printf("Increment TC relayed to %d.\n",olsr->stat.numTcRelayed);
      }
  }

  olsr_pktbuf_append_byte_ary(msg, (olsr_u8_t* )olsr->message_body, olsr->message_body_size);


  if (DEBUG_OLSRV2){
      olsr_printf("TTL:%d\nhopcount:%d\nmsg_size:%d\n",m_header->ttl - 1,
                                    m_header->hop_count + 1, (int)msg->len);
  }

  if (m_header->message_type == TC_MESSAGE)
  {
      int ifNum;

      for(ifNum=0; ifNum<olsr->iface_num; ifNum++)
      {
      set_forward_infomation(olsr, msg->data, (unsigned int)msg->len,
          (unsigned char)ifNum);
      }
  }
  else
  {
      set_forward_infomation(olsr, msg->data, (unsigned int)msg->len,
          olsr->parsingIfNum);
  }

  olsr_pktbuf_free(&msg);
}
/*
 * Create <tlv-block> for ...
 * XXX
 */
void build_tlv_block_for_index_local(olsr_pktbuf_t *buf, BASE_ADDRESS *base,
                     olsr_u32_t index) {
//Static Fix
  //static olsr_pktbuf_t *tlv_buf = NULL;
  olsr_pktbuf_t *tlv_buf = NULL;

  tlv_buf = olsr_pktbuf_alloc_with_capa(64);
  olsr_pktbuf_clear(tlv_buf);

  //Create TLV "Interface"
  create_tlv_for_index_hello(tlv_buf, base, index, Other_If, OLSR_TRUE);

  // <tlv-block>
  olsr_pktbuf_append_u16(buf, (olsr_u16_t)tlv_buf->len);    // <tlv-length>
  olsr_pktbuf_append_pktbuf(buf, tlv_buf);  // <tlv>*

  olsr_pktbuf_free(&tlv_buf);

  //free(tlv_buf->data);
  //free(tlv_buf);
}
//create multivalue tlv
void
create_hello_addr_tlv_by_multivalue(void *olsr, OLSR_LIST *tlv_block,
                    OLSR_LIST *block,
                    olsr_u8_t tlv_type)
{
  BASE_TLV base_tlv;
  OLSR_LIST_ENTRY *entry;
  BLOCK_DATA *data, *next_data;

  olsr_u8_t index_start, index_stop;
  olsr_u32_t index, tlv_length;
  olsr_bool set_index_start;
//Static Fix
  //static olsr_pktbuf_t *buf = NULL;
  olsr_pktbuf_t *buf = NULL;

  index_start = index_stop = index =0;

  tlv_length = 0;
  set_index_start = OLSR_FALSE;

  buf = olsr_pktbuf_alloc_with_capa(255 * sizeof(olsr_u8_t));
  olsr_pktbuf_clear(buf);

  entry = block->head;
  while(entry){
    data = (BLOCK_DATA *)entry->data;
    switch(tlv_type){
    case Link_Status:
      {
    if(data->link_status != 255){

      //check index_start set or not
      if(set_index_start == OLSR_FALSE){
        index_start = index;
        set_index_start = OLSR_TRUE;
      }

      index_stop = index;
      tlv_length += sizeof(olsr_u8_t);
      olsr_pktbuf_append_u8(buf, data->link_status);

      //last addr
      if(index == block->numEntry -1){
        base_tlv.tlv_type = tlv_type;
        base_tlv.tlv_semantics = MULTI_VALUE;
        base_tlv.tlv_length = tlv_length;
        base_tlv.index_start = index_start;
        base_tlv.index_stop = index_stop;

        //check semantics
        if(index_start == 0){
          base_tlv.tlv_semantics |= NO_INDEX;
        }else if(index_start == index_stop){
          base_tlv.tlv_semantics |= SINGLE_INDEX;
        }

        //set value
        base_tlv.value = (olsr_u8_t *)olsr_malloc(tlv_length, __FUNCTION__);
        memcpy(base_tlv.value, buf->data, tlv_length);

        //insert list
        OLSR_InsertList( tlv_block, &base_tlv, sizeof(BASE_TLV));
        set_index_start = OLSR_FALSE;
        olsr_pktbuf_clear(buf);
        tlv_length =0;

      }else if (index < block->numEntry -1){
        next_data = (BLOCK_DATA *)entry->next->data;
        if(next_data->link_status == 255){
          base_tlv.tlv_type = tlv_type;
          base_tlv.tlv_semantics = MULTI_VALUE;
          base_tlv.tlv_length = tlv_length;
          base_tlv.index_start = index_start;
          base_tlv.index_stop = index_stop;

          //check semantics
          if(index_start == index_stop){
        base_tlv.tlv_semantics |= SINGLE_INDEX;
          }

          //set value
          base_tlv.value = (olsr_u8_t *)olsr_malloc(tlv_length, __FUNCTION__);
          memcpy(base_tlv.value, buf->data, tlv_length);

          //insert list
          OLSR_InsertList( tlv_block, &base_tlv, sizeof(BASE_TLV));
          set_index_start = OLSR_FALSE;
          olsr_pktbuf_clear(buf);
          tlv_length = 0;
        }
      }//if else if
    }//link_status != 255
      }//case
      break;

    case PREFIX_LENGTH:
      {
    if(data->Prefix_Length != 255){

      //check index_start set or not
      if(set_index_start == OLSR_FALSE){
        index_start = index;
        set_index_start = OLSR_TRUE;
      }

      index_stop = index;
      tlv_length += sizeof(olsr_u8_t);
      olsr_pktbuf_append_u8(buf, data->Prefix_Length);

      //last addr
      if(index == block->numEntry -1){
        base_tlv.tlv_type = tlv_type;
        base_tlv.tlv_semantics = MULTI_VALUE;
        base_tlv.tlv_length = tlv_length;
        base_tlv.index_start = index_start;
        base_tlv.index_stop = index_stop;

        //check semantics
        if(index_start == 0){
          base_tlv.tlv_semantics |= NO_INDEX;
        }else if(index_start == index_stop){
          base_tlv.tlv_semantics |= SINGLE_INDEX;
        }

        //set value
        base_tlv.value = (olsr_u8_t *)olsr_malloc(tlv_length, __FUNCTION__);
        memcpy(base_tlv.value, buf->data, tlv_length);

        //insert list
        OLSR_InsertList( tlv_block, &base_tlv, sizeof(BASE_TLV));
        set_index_start = OLSR_FALSE;
        olsr_pktbuf_clear(buf);
        tlv_length =0;

      }else if (index < block->numEntry -1){
        next_data = (BLOCK_DATA *)entry->next->data;
        if(next_data->Prefix_Length == 255){
          base_tlv.tlv_type = tlv_type;
          base_tlv.tlv_semantics = MULTI_VALUE;
          base_tlv.tlv_length = tlv_length;
          base_tlv.index_start = index_start;
          base_tlv.index_stop = index_stop;

          //check semantics
          if(index_start == index_stop){
        base_tlv.tlv_semantics |= SINGLE_INDEX;
          }

          //set value
          base_tlv.value = (olsr_u8_t *)olsr_malloc(tlv_length, __FUNCTION__);
          memcpy(base_tlv.value, buf->data, tlv_length);

          //insert list
          OLSR_InsertList( tlv_block, &base_tlv, sizeof(BASE_TLV));
          set_index_start = OLSR_FALSE;
          olsr_pktbuf_clear(buf);
          tlv_length = 0;
        }
      }//if else if
    }//Prefix_LENGTH != 255
      }//case
      break;

    default:
      olsr_error("%s\n", __FUNCTION__);

    }//switch

    index++;
    entry = entry->next;
  }
  olsr_pktbuf_free(&buf);

  //free(buf->data);
  //free(buf);
}