• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef _WIFI_HOST_TG_H
16 #define _WIFI_HOST_TG_H
17 
18 #include "sockets.h"
19 
20 /// Number of traffic stream
21 #define FHOST_TG_MAX_TRAFFIC_STREAMS 3
22 /// Number of TG send buffers (credits)
23 #define FHOST_TG_SEND_BUF_CNT        8
24 
25 /// Traffic sending direction
26 #define FHOST_TG_DIRECT_SEND                1
27 /// Traffic receiving direction
28 #define FHOST_TG_DIRECT_RECV                2
29 
30 /// TG profile ID
31 enum profile_id
32 {
33     /// Profile Types
34     /// Large file transfer between endpoints
35     FHOST_PROF_FILE_TX = 1,
36     /// A group/multicast traffic Real Audio stream
37     FHOST_PROF_MCAST,
38     /// IPTV stream
39     FHOST_PROF_IPTV,
40     /// A series of client / server transactions
41     FHOST_PROF_TRANSC,
42     /// NOT USED
43     FHOST_PROF_START_SYNC,
44     /// NOT USED
45     FHOST_PROF_CALI_RTD = FHOST_PROF_START_SYNC,
46     /// NOT USED
47     FHOST_PROF_UAPSD,
48     /// NOT USED
49     FHOST_PROF_LAST
50 };
51 
52 /*
53  * TYPE DEFINITIONS
54  ****************************************************************************************
55  */
56 /// TG Time structure used for TG send process
57 struct fhost_tg_time
58 {
59     /// second
60     uint32_t sec;
61     /// microsecond
62     uint32_t usec;
63 };
64 
65 /// TG profile
66 struct fhost_tg_profile
67 {
68      /// Profile ID
69     enum profile_id prof_id;
70     /// Traffic direction
71     int direction;
72     /// IP address of destination
73     uint32_t dst_ip;
74     /// Send destination port
75     uint32_t dst_port;
76     /// IP address of source
77     uint32_t src_ip;
78     /// Local port
79     uint32_t src_port;
80     /// Traffic rate (pkts /s)
81     uint32_t rate;
82     /// Packet size
83     uint32_t pksize;
84     /// Traffic duration
85     uint32_t duration;
86     /// TOS value to be put in the IP header
87     uint16_t tos;
88 };
89 
90 /// TG statistics
91 struct fhost_tg_stats
92 {
93     /// Number of TX frames sent
94     uint32_t tx_frames;
95     /// Number of RX frames received
96     uint32_t rx_frames;
97     /// Counter for send command
98     uint32_t counter_send;
99     /// Counter for recv command
100     uint32_t counter_recv;
101     /// Number of TX buffer bytes
102     uint32_t tx_bytes;
103     /// Number of RX buffer bytes
104     uint32_t rx_bytes;
105     /// Traffic throughput
106     uint32_t throughput;
107     /// Number of expected frames
108     uint32_t expected;
109     /// Number of lost frames
110     uint32_t lost;
111     /// Number of unordered frames
112     uint32_t unordered;
113     /// Round trip time delay of transaction
114     uint32_t rt_time;
115 };
116 
117 /// TG stream
118 struct fhost_tg_stream
119 {
120     /// Stream ID
121     uint32_t id;
122     /// State of TG stream (true for active, false for inactive)
123     bool active;
124     /// TG semaphore used to synchronize the TG thread and the FHOST IPC one
125     rtos_semaphore tg_semaphore;
126     /// NET_TG Semaphore used to synchronize the process in the net_tg_al layer
127     rtos_semaphore net_tg_semaphore;
128     /// Handle of TG send task (not used yet)
129     rtos_task_handle tg_handle;
130     /// TG mutex used when we modify the credits for sending process
131     rtos_mutex tg_mutex;
132     /// Param pointer for NET TG AL
133     void *arg;
134     /// Credits for TG sending buffer
135     int8_t credits;
136     /// Timestamp used for transaction
137     struct fhost_tg_time transc_timestamp;
138     /// TG profile
139     struct fhost_tg_profile prof;
140     /// TG statistics
141     struct fhost_tg_stats stats;
142 };
143 
144 /*
145  * GLOBAL VARIABLES
146  ****************************************************************************************
147  */
148 /// Table of TG streams
149 extern struct fhost_tg_stream g_streams[FHOST_TG_MAX_TRAFFIC_STREAMS];
150 
151 /*
152  * FUNCTIONS
153  ****************************************************************************************
154  */
155 /**
156  ****************************************************************************************
157  * @brief Start TG stream configuration
158  * This function configures the TG stream with certain characteristics.
159  *
160  * @param[in] stream_id    TG stream ID
161  * @param[in] prof         TG profile ID
162  * @param[in] direction    Direction of stream (DIRECT_SEND, DIRECT_RECV)
163  * @param[in] rip          Destination IP address
164  * @param[in] dst_port     Destination port
165  * @param[in] lip          Local IP address
166  * @param[in] src_port     Local port
167  * @param[in] rate         Traffic rate (pkts / s)
168  * @param[in] pksize       Packet size
169  * @param[in] duration     Traffic duration
170  * @param[in] tos          Type of service
171  *
172  * @return 0 on success and !=0 otherwise
173  ****************************************************************************************
174  */
175 int fhost_tg_config(u32_t stream_id, u32_t prof, int direction, u32_t rip, u32_t dst_port,
176         u32_t lip, u32_t src_port, u32_t rate, u32_t pksize, u32_t duration, uint16_t tos);
177 
178 /**
179  ****************************************************************************************
180  * @brief Start TG traffic for sending or receiving process according to the direction
181  * of TG stream
182  * If it's sending direction :
183  * This function creates the RTOS task dedicated to the TG send processing.
184  * We can send several TG streams at the same time.
185  * If it's receiving direction :
186  * This function starts the receiving server dedicated to the TG recv processing.
187  * We can also receive several TG streams at the same time.
188  *
189  * @param[in] stream_id    TG stream ID
190  *
191  * @return 0 on success and !=0 otherwise
192  ****************************************************************************************
193  */
194 int fhost_tg_start(u32_t stream_id);
195 
196 /**
197  ****************************************************************************************
198  * @brief Start TG stop task
199  * This function stops the TG sending or receiving process according to TG stream ID
200  * and return the statistics
201  *
202  * @param[in] stream_id    TG stream ID
203  *
204  * @return pointer to the statistics structure of stream, NULL if error
205  ****************************************************************************************
206  */
207 struct fhost_tg_stats *fhost_tg_stop(u32_t stream_id);
208 
209 #endif // _WIFI_HOST_TG_H
210 
211