Ver Fonte

update: iperf,优化代码,client模式测60秒

Wendal Chen há 1 mês atrás
pai
commit
2abdb31a6e

+ 9 - 1
components/network/iperf/binding/luat_lib_iperf.c

@@ -79,7 +79,15 @@ static void iperf_start_cb(void* args) {
         LLOGD("server listen %s:%d", buff, ctx->port);
     }
     else {
-        luat_lwiperf_start_tcp_client(remote_ip, ctx->port, LWIPERF_CLIENT, iperf_report_cb, NULL, &drv->netif->ip_addr);
+        lwiperf_client_conf_t conf = {0};
+        conf.remote_addr = remote_ip;
+        conf.remote_port = ctx->port;
+        conf.type = LWIPERF_CLIENT;
+        conf.report_fn = iperf_report_cb;
+        conf.report_arg = NULL;
+        conf.local_addr = &drv->netif->ip_addr;
+        conf.amount = htonl((u32_t)-6000); // 默认测试60秒
+        luat_lwiperf_start_tcp_client(&conf);
         ipaddr_ntoa_r(remote_ip, buff2, sizeof(buff2));
         LLOGD("client connect %s --> %s:%d", buff, buff2, ctx->port);
     }

+ 14 - 7
components/network/iperf/include/luat_lwiperf.h

@@ -74,6 +74,7 @@ enum lwiperf_client_type
   LWIPERF_TRADEOFF
 };
 
+
 /** Prototype of a report function that is called when a session is finished.
     This report function can show the test results.
     @param report_type contains the test result */
@@ -81,15 +82,21 @@ typedef void (*lwiperf_report_fn)(void *arg, enum lwiperf_report_type report_typ
   const ip_addr_t* local_addr, u16_t local_port, const ip_addr_t* remote_addr, u16_t remote_port,
   u32_t bytes_transferred, u32_t ms_duration, u32_t bandwidth_kbitpsec);
 
+
+typedef struct lwiperf_client_conf
+{
+  const ip_addr_t* remote_addr;
+  u16_t remote_port;
+  enum lwiperf_client_type type;
+  lwiperf_report_fn report_fn;
+  void* report_arg;
+  const ip_addr_t* local_addr;
+  u32_t amount; /* in bytes, 0 means infinite */
+}lwiperf_client_conf_t;
+
 void* luat_lwiperf_start_tcp_server(const ip_addr_t* local_addr, u16_t local_port,
                                lwiperf_report_fn report_fn, void* report_arg);
-void* luat_lwiperf_start_tcp_server_default(lwiperf_report_fn report_fn, void* report_arg);
-void* luat_lwiperf_start_tcp_client(const ip_addr_t* remote_addr, u16_t remote_port,
-                               enum lwiperf_client_type type,
-                               lwiperf_report_fn report_fn, void* report_arg,
-                               const ip_addr_t* local_addr);
-void* luat_lwiperf_start_tcp_client_default(const ip_addr_t* remote_addr,
-                               lwiperf_report_fn report_fn, void* report_arg);
+void* luat_lwiperf_start_tcp_client(lwiperf_client_conf_t* client_conf);
 
 void  luat_lwiperf_abort(void* lwiperf_session);
 

+ 8 - 36
components/network/iperf/src/luat_lwiperf.c

@@ -673,21 +673,7 @@ static void iperf_free(size_t line, void* ptr);
    lwiperf_list_add(&conn->base);
    return ERR_OK;
  }
- 
- /**
-  * @ingroup iperf
-  * Start a TCP iperf server on the default TCP port (5001) and listen for
-  * incoming connections from iperf clients.
-  *
-  * @returns a connection handle that can be used to abort the server
-  *          by calling @ref lwiperf_abort()
-  */
- void *
- luat_lwiperf_start_tcp_server_default(lwiperf_report_fn report_fn, void *report_arg)
- {
-   return luat_lwiperf_start_tcp_server(IP_ADDR_ANY, LWIPERF_TCP_PORT_DEFAULT,
-                                   report_fn, report_arg);
- }
+
  
  /**
   * @ingroup iperf
@@ -765,19 +751,6 @@ static void iperf_free(size_t line, void* ptr);
    return ERR_OK;
  }
  
- /**
-  * @ingroup iperf
-  * Start a TCP iperf client to the default TCP port (5001).
-  *
-  * @returns a connection handle that can be used to abort the client
-  *          by calling @ref lwiperf_abort()
-  */
- void*  luat_lwiperf_start_tcp_client_default(const ip_addr_t* remote_addr,
-                                lwiperf_report_fn report_fn, void* report_arg)
- {
-   return  luat_lwiperf_start_tcp_client(remote_addr, LWIPERF_TCP_PORT_DEFAULT, LWIPERF_CLIENT,
-                                   report_fn, report_arg, NULL);
- }
  
  /**
   * @ingroup iperf
@@ -786,15 +759,14 @@ static void iperf_free(size_t line, void* ptr);
   * @returns a connection handle that can be used to abort the client
   *          by calling @ref lwiperf_abort()
   */
- void*  luat_lwiperf_start_tcp_client(const ip_addr_t* remote_addr, u16_t remote_port,
-   enum lwiperf_client_type type, lwiperf_report_fn report_fn, void* report_arg, const ip_addr_t* local_addr)
+ void*  luat_lwiperf_start_tcp_client(lwiperf_client_conf_t* client_conf)
  {
    err_t ret;
    lwiperf_settings_t settings;
    lwiperf_state_tcp_t *state = NULL;
  
    memset(&settings, 0, sizeof(settings));
-   switch (type) {
+   switch (client_conf->type) {
    case LWIPERF_CLIENT:
      /* Unidirectional tx only test */
      settings.flags = 0;
@@ -814,16 +786,16 @@ static void iperf_free(size_t line, void* ptr);
    settings.num_threads = htonl(1);
    settings.remote_port = htonl(LWIPERF_TCP_PORT_DEFAULT);
    /* TODO: implement passing duration/amount of bytes to transfer */
-   settings.amount = htonl((u32_t)-1000);
+   settings.amount = client_conf->amount;
    LLOGD("准备启动iperf客户端");
-   ret = lwiperf_tx_start_impl(remote_addr, remote_port, &settings, report_fn, report_arg, NULL, &state, local_addr);
+   ret = lwiperf_tx_start_impl(client_conf->remote_addr, client_conf->remote_port, &settings, client_conf->report_fn, client_conf->report_arg, NULL, &state, client_conf->local_addr);
    if (ret == ERR_OK) {
      LWIP_ASSERT("state != NULL", state != NULL);
-     if (type != LWIPERF_CLIENT) {
+     if (client_conf->type != LWIPERF_CLIENT) {
        /* start corresponding server now */
        lwiperf_state_tcp_t *server = NULL;
        ret = lwiperf_start_tcp_server_impl(&state->conn_pcb->local_ip, LWIPERF_TCP_PORT_DEFAULT,
-         report_fn, report_arg, (lwiperf_state_base_t *)state, &server);
+         client_conf->report_fn, client_conf->report_arg, (lwiperf_state_base_t *)state, &server);
        if (ret != ERR_OK) {
          /* starting server failed, abort client */
          luat_lwiperf_abort(state);
@@ -832,7 +804,7 @@ static void iperf_free(size_t line, void* ptr);
        /* make this server accept one connection only */
        server->specific_remote = 1;
        server->remote_addr = state->conn_pcb->remote_ip;
-       if (type == LWIPERF_TRADEOFF) {
+       if (client_conf->type == LWIPERF_TRADEOFF) {
          /* tradeoff means that the remote host connects only after the client is done,
             so keep the listen pcb open until the client is done */
          server->client_tradeoff_mode = 1;

+ 1 - 23
olddemo/iperf/air8101/main.lua

@@ -2,28 +2,6 @@
 PROJECT = "wifidemo"
 VERSION = "1.0.0"
 
--- 引入必要的库文件(lua编写), 内部库不需要require
-sys = require("sys")
-require("sysplus")
-
---[[
-本demo演示AP的配网实例
-1. 启动后, 会创建一个 luatos_ + mac地址的热点
-2. 热点密码是 12341234
-3. 热点网关是 192.168.4.1, 同时也是配网网页的ip
-4. http://192.168.4.1
-]]
-
-
-if wdt then
-    --添加硬狗防止程序卡死,在支持的设备上启用这个功能
-    wdt.init(9000)--初始化watchdog设置为9s
-    sys.timerLoopStart(wdt.feed, 3000)--3s喂一次狗
-end
-
--- 初始化LED灯, 开发板上左右2个led分别是gpio12/gpio13
-local LEDA= gpio.setup(12, 0, gpio.PULLUP)
--- local LEDB= gpio.setup(13, 0, gpio.PULLUP)
 
 local scan_result = {}
 
@@ -36,7 +14,7 @@ sys.taskInit(function()
     sys.wait(100)
     iperf.client(socket.LWIP_STA, "47.94.236.172")
 
-    sys.wait(30*1000)
+    sys.wait(90*1000)
     iperf.abort()
 end)