Exemplo n.º 1
0
/* insert new node as fourth element in queue */
void t_sendqueue4(void)
{
    int result;

    result = coap_insert_node(&sendqueue, node[4]);

    CU_ASSERT(result > 0);

    CU_ASSERT_PTR_EQUAL(sendqueue, node[3]);

    CU_ASSERT_PTR_NOT_NULL(sendqueue->next);
    CU_ASSERT_PTR_EQUAL(sendqueue->next, node[1]);

    CU_ASSERT_PTR_NOT_NULL(sendqueue->next->next);
    CU_ASSERT_PTR_EQUAL(sendqueue->next->next, node[4]);

    CU_ASSERT_PTR_NOT_NULL(sendqueue->next->next->next);
    CU_ASSERT_PTR_EQUAL(sendqueue->next->next->next, node[2]);

    CU_ASSERT(sendqueue->next->t == timestamp[1] - timestamp[3]);
    CU_ASSERT(add_timestamps(sendqueue, 1) == timestamp[3]);
    CU_ASSERT(add_timestamps(sendqueue, 2) == timestamp[1]);
    CU_ASSERT(add_timestamps(sendqueue, 3) == timestamp[4]);
    CU_ASSERT(add_timestamps(sendqueue, 4) == timestamp[2]);
}
Exemplo n.º 2
0
void t_sendqueue1(void)
{
    int result = coap_insert_node(&sendqueue, node[1]);

    CU_ASSERT(result > 0);
    CU_ASSERT_PTR_NOT_NULL(sendqueue);
    CU_ASSERT_PTR_EQUAL(sendqueue, node[1]);
    CU_ASSERT(node[1]->t == timestamp[1]);
}
Exemplo n.º 3
0
void t_sendqueue2(void)
{
    int result;

    result = coap_insert_node(&sendqueue, node[2]);

    CU_ASSERT(result > 0);
    CU_ASSERT_PTR_EQUAL(sendqueue, node[1]);
    CU_ASSERT_PTR_EQUAL(sendqueue->next, node[2]);

    CU_ASSERT(sendqueue->t == timestamp[1]);
    CU_ASSERT(node[2]->t == timestamp[2] - timestamp[1]);
}
Exemplo n.º 4
0
/* insert new node as first element in queue */
void t_sendqueue3(void)
{
    int result;
    result = coap_insert_node(&sendqueue, node[3]);

    CU_ASSERT(result > 0);

    CU_ASSERT_PTR_EQUAL(sendqueue, node[3]);
    CU_ASSERT(node[3]->t == timestamp[3]);

    CU_ASSERT_PTR_NOT_NULL(sendqueue->next);
    CU_ASSERT_PTR_NOT_NULL(sendqueue->next->next);

    CU_ASSERT(sendqueue->next->t == timestamp[1] - timestamp[3]);
    CU_ASSERT(sendqueue->next->next->t == timestamp[2] - timestamp[1]);
}
Exemplo n.º 5
0
int
coap_read(coap_context_t *ctx,
	  struct sockaddr_in6 *src, void *buf,
	  uint16_t bytes_read, struct ip6_metadata *meta) {
  coap_queue_t *node;
  coap_opt_t *opt;

  if ( bytes_read < 0 ) {
    return -1;
  }

  if ( bytes_read < sizeof(coap_hdr_t) || ((coap_hdr_t *)buf)->version != COAP_DEFAULT_VERSION ) {
#ifndef NDEBUG
    //fprintf(stderr, "coap_read: discarded invalid frame\n" );
#endif
    return -1;
  }
  node = coap_new_node();
  if ( !node )
    return -1;

  node->pdu = coap_new_pdu();
  if ( !node->pdu ) {
    coap_delete_node( node );
    return -1;
  }

  /*printf("** coap: coap_read pointers %p %p, %p %p\n",
    &node->remote,
    node->remote,
    src,
    *src,
    sizeof(src),
    sizeof(*src));*/

  memcpy( &node->remote, src, sizeof( *src ) );

  /* "parse" received PDU by filling pdu structure */
  memcpy( node->pdu->hdr, buf, bytes_read );
  node->pdu->length = bytes_read;

  /* finally calculate beginning of data block */
  options_end( node->pdu, &opt );

  if ( (unsigned char *)node->pdu->hdr + node->pdu->length <
       (unsigned char *)opt )
    node->pdu->data = (unsigned char *)node->pdu->hdr + node->pdu->length;
  else
    node->pdu->data = (unsigned char *)opt;

  /* and add new node to receive queue */
  coap_insert_node( &ctx->recvqueue, node, order_transaction_id );

#ifndef NDEBUG
  if ( inet_ntop(src.sin6_family, &src.sin6_addr, addr, INET6_ADDRSTRLEN) == 0 ) {
    //perror("coap_read: inet_ntop");
  } else {
    printf( "** received from [%s]:%d:\n  ",addr,ntohs(src.sin6_port));
  }
  coap_show_pdu( node->pdu );
#endif

  return 0;
}