luat_lwiperf.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * @file
  3. * lwIP iPerf server implementation
  4. */
  5. /*
  6. * Copyright (c) 2014 Simon Goldschmidt
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modification,
  10. * are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * 3. The name of the author may not be used to endorse or promote products
  18. * derived from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  21. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  23. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  25. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  28. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  29. * OF SUCH DAMAGE.
  30. *
  31. * This file is part of the lwIP TCP/IP stack.
  32. *
  33. * Author: Simon Goldschmidt
  34. *
  35. */
  36. #ifndef LWIP_HDR_APPS_LWIPERF_H
  37. #define LWIP_HDR_APPS_LWIPERF_H
  38. #include "lwip/opt.h"
  39. #include "lwip/ip_addr.h"
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. #define LWIPERF_TCP_PORT_DEFAULT 5001
  44. /** lwIPerf test results */
  45. enum lwiperf_report_type
  46. {
  47. /** The server side test is done */
  48. LWIPERF_TCP_DONE_SERVER,
  49. /** The client side test is done */
  50. LWIPERF_TCP_DONE_CLIENT,
  51. /** Local error lead to test abort */
  52. LWIPERF_TCP_ABORTED_LOCAL,
  53. /** Data check error lead to test abort */
  54. LWIPERF_TCP_ABORTED_LOCAL_DATAERROR,
  55. /** Transmit error lead to test abort */
  56. LWIPERF_TCP_ABORTED_LOCAL_TXERROR,
  57. /** Remote side aborted the test */
  58. LWIPERF_TCP_ABORTED_REMOTE
  59. };
  60. /** Control */
  61. enum lwiperf_client_type
  62. {
  63. /** Unidirectional tx only test */
  64. LWIPERF_CLIENT,
  65. /** Do a bidirectional test simultaneously */
  66. LWIPERF_DUAL,
  67. /** Do a bidirectional test individually */
  68. LWIPERF_TRADEOFF
  69. };
  70. /** Prototype of a report function that is called when a session is finished.
  71. This report function can show the test results.
  72. @param report_type contains the test result */
  73. typedef void (*lwiperf_report_fn)(void *arg, enum lwiperf_report_type report_type,
  74. const ip_addr_t* local_addr, u16_t local_port, const ip_addr_t* remote_addr, u16_t remote_port,
  75. u32_t bytes_transferred, u32_t ms_duration, u32_t bandwidth_kbitpsec);
  76. typedef struct lwiperf_client_conf
  77. {
  78. const ip_addr_t* remote_addr;
  79. u16_t remote_port;
  80. enum lwiperf_client_type type;
  81. lwiperf_report_fn report_fn;
  82. void* report_arg;
  83. const ip_addr_t* local_addr;
  84. u32_t amount; /* in bytes, 0 means infinite */
  85. }lwiperf_client_conf_t;
  86. void* luat_lwiperf_start_tcp_server(const ip_addr_t* local_addr, u16_t local_port,
  87. lwiperf_report_fn report_fn, void* report_arg);
  88. void* luat_lwiperf_start_tcp_client(lwiperf_client_conf_t* client_conf);
  89. void luat_lwiperf_abort(void* lwiperf_session);
  90. #ifdef __cplusplus
  91. }
  92. #endif
  93. #endif /* LWIP_HDR_APPS_LWIPERF_H */