]> rtime.felk.cvut.cz Git - rpp-test-sw.git/blob - rpp-test-sw/commands/cmd_iperf.c
Change license to MIT
[rpp-test-sw.git] / rpp-test-sw / commands / cmd_iperf.c
1 /*
2  * Copyright (C) 2012-2019 Czech Technical University in Prague
3  *
4  * Created on: 25.3.2019
5  *
6  * Authors:
7  *     - Jakub Nejedly
8  *
9  * Permission is hereby granted, free of charge, to any person
10  * obtaining a copy of this software and associated documentation
11  * files (the "Software"), to deal in the Software without
12  * restriction, including without limitation the rights to use,
13  * copy, modify, merge, publish, distribute, sublicense, and/or sell
14  * copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following
16  * conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  *
30  * File : cmd_iperf.c
31  *
32  * Abstract:
33  *
34  *
35  */
36
37 #include "cmd_iperf.h"
38
39 #ifndef DOCGEN
40
41
42 #include "cmdproc_freertos.h"
43 #include "rpp/rpp.h"
44
45 #include "lwip/opt.h"
46 #include "lwip/tcp.h"
47
48
49
50 static err_t lwiperf_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err){
51
52         LWIP_UNUSED_ARG(arg);
53
54         if (err == ERR_OK && p != NULL) {
55         tcp_recved(pcb, p->tot_len);
56         pbuf_free(p);
57
58         } else if (err != ERR_OK && p != NULL) {
59         pbuf_free(p);
60
61         }
62
63         if (err == ERR_OK && p == NULL) {
64                 tcp_arg(pcb, NULL);
65         tcp_sent(pcb, NULL);
66         tcp_recv(pcb, NULL);
67         tcp_close(pcb);
68         }
69         return ERR_OK;
70 }
71
72 static err_t lwiperf_accept(void *arg, struct tcp_pcb *pcb, err_t err){
73
74         LWIP_UNUSED_ARG(arg);
75         LWIP_UNUSED_ARG(err);
76
77         tcp_arg(pcb, NULL);
78         tcp_sent(pcb, NULL);
79         tcp_recv(pcb, lwiperf_recv);
80         return ERR_OK;
81 }
82
83
84
85
86 int cmd_do_eth_lwiperf(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]){
87
88         // test ethinit
89         if (!isPostInitialized()) {
90                 rpp_sci_printf("Eth not initialized run 'ethinit' command first.\n");
91                 return FAILURE;
92         }
93
94         //err_t err = ERR_OK;
95
96         struct tcp_pcb *pcb;
97
98         pcb = tcp_new();
99         tcp_bind(pcb, IP_ADDR_ANY, 5001); // bind to iperf port
100         pcb = tcp_listen(pcb);
101         tcp_accept(pcb, lwiperf_accept);
102
103         rpp_sci_printf("Iperf initialized \r\n");
104         
105
106         return ERR_OK;
107 }
108
109
110
111 #endif  /* DOCGEN */
112
113 cmd_des_t const cmd_des_ethiperf = {
114         0, 0,
115         "ethiperf","Command to test IP Bandwidth",
116         "### Command syntax ###\n"
117         "\n"
118         "    ethiperf \n"
119         "\n"
120         "### Description ###\n"
121         "Command start iperf server on platform. To test internet bandwidth run iperf -c [board_IP] at testing computer."
122         "\n"
123         "### Example ###\n"
124         "\n"
125         "    --> ethiperf\n"
126         "At testing computer\n"
127         "    --> ethiperf -c 10.35.95.25\n",
128         CMD_HANDLER(cmd_do_eth_lwiperf), (void *)&cmd_list_iperf
129 };
130
131 /** List of commands for adc, defined as external */
132 cmd_des_t const *cmd_list_iperf[] = {
133         &cmd_des_ethiperf,
134         NULL
135 };
136