• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
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 
16 #ifndef NET_TRANS_COMMON_H
17 #define NET_TRANS_COMMON_H
18 
19 #include <pthread.h>
20 #include <securec.h>
21 #include <sys/time.h>
22 #include <unistd.h>
23 
24 #include "common_list.h"
25 #include "discovery_service.h"
26 #include "session.h"
27 #include "softbus_bus_center.h"
28 #include "softbus_common.h"
29 #include "softbus_def.h"
30 #include "softbus_errcode.h"
31 #include "softbus_utils.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #define DEF_GROUP_ID "DEF_GROUP_ID"
38 #define DEF_SESSION_KEY "DEF_SESSION_KEY"
39 #define DEF_PKG_NAME "com.communication.demo1"
40 #define PKG_NAME_TWO "com.communication.demo2"
41 #define PKG_NAME_THREE "com.communication.demo3"
42 #define PKG_NAME_FOUR "com.communication.demo4"
43 
44 #define SESSION_NAME_DATA "com.communication.demo1.data"
45 #define SESSION_NAME_CTL "com.communication.demo1.control"
46 #define SESSION_NAME_PASS "com.communication.demo1.passive"
47 #define SESSION_NAME_FAIL "com.communication.demo1.fail"
48 #define SESSION_NAME_PERF "com.communication.demo1.perf"
49 #define SESSION_NAME_PROXY "com.communication.demo1.proxy"
50 #define SESSION_NAME_FILE "com.communication.demo1.file"
51 #define DSOFT_PKG_NAME "com.plrdtest.dsoftbus"
52 #define SESSION_NAME_DSOFT_DATA "com.plrdtest.dsoftbus.data"
53 #define RECV_FILE_PATH "/data/"
54 
55 #define CTRL_MSG_CLOSE_WIFI_THREE_SEC "close wifi 3sec"
56 #define CTRL_MSG_CLOSE_WIFI_TEN_MIN "close wifi 10min"
57 #define CTRL_MSG_CLOSE_WIFI_FIVE_MIN "close wifi 5min"
58 #define CTRL_MSG_CLOSE_WIFI_TEN_SEC "close wifi 10sec"
59 #define CTRL_MSG_CHANGE_WIFI_TEN_SEC "change wifi 10sec"
60 #define CTRL_MSG_CHANGE_WIFI_SIXTY_SEC "change wifi 60sec"
61 #define CTRL_MSG_CLOSE_WIFI_LOOP20 "close wifi loop 20"
62 #define CTRL_MSG_CHANGE_WIFI_LOOP20 "change wifi loop 20"
63 #define CTRL_MSG_CLOSE_WIFI_LOOP100 "close wifi loop 100"
64 #define CTRL_MSG_CHANGE_WIFI_LOOP100 "change wifi loop 100"
65 
66 #define CTRL_MSG_OPEN_SESSION "open session"
67 #define CTRL_MSG_OPEN_SESSION_MSG "open session msg"
68 #define CTRL_MSG_OPEN_SESSION_NOT_EXIST "open session not exist"
69 #define CTRL_MSG_OPEN_SESSION_FAIL "open session fail"
70 #define CTRL_MSG_CLOSE_SESSION "close session"
71 
72 #define CTRL_MSG_CLOSE_BR "close br"
73 #define CTRL_MSG_CLOSE_OPEN_BR "close-open br"
74 #define CTRL_MSG_CLOSE_AIR "close air"
75 #define CTRL_MSG_CLOSE_OPEN_AIR "close-open air"
76 #define CTRL_MSG_SEND_BIG_DATA "send big data"
77 
78 #define WAIT_DEF_VALUE (-1)
79 #define WAIT_SUCCESS_VALUE 1
80 #define WAIT_FAIL_VALUE 0
81 #define SESSION_ID_MIN 1
82 #define MAX_SESSION_NUM 16
83 #define BOOL_TRUE 1
84 #define BOOL_FALSE 0
85 #define OPEN_SESSION_TIMEOUT 19
86 #define MULTI_REMOTE_DEV_COUNT 3
87 #define DEF_REMOTE_DEV_COUNT 1
88 #define SIZE_1K 1024
89 
90 #define CMD_DOWN_ETH "ifconfig eth0 down"
91 #define CMD_CONFIG_ETH_WRONG_IP "ifconfig eth0 193.168.7.88 up"
92 #define CMD_CONFIG_ETH_RIGHT_IP "ifconfig eth0 192.168.3.88 up"
93 #define CMD_PIDOF_SOFTBUS "pidof softbus_server"
94 
95 #define CMD_CONFIG_WLAN_WRONG_IP "ifconfig wlan0 193.168.3.88 up"
96 
97 #define MAX_SESSION_SERVER_NUM_CLIENT 8
98 #define MAX_SESSION_SERVER_NUM_SERVER 32
99 #define TRANS_BYTES_LENGTH_MAX (4 * 1024 * 1024)
100 #define TRANS_MESSAGE_LENGTH_MAX 4096
101 #define TRANS_PROXY_BYTES_LENGTH_MAX (4 * 1024)
102 #define TRANS_PROXY_MESSAGE_LENGTH_MAX 1024
103 #define DEF_SEND_DATA_SID_COUNT 4
104 #define GROUP_ID_LEN 4
105 
106 #define CASE_0 0
107 #define CASE_1 1
108 #define CASE_2 2
109 #define CASE_3 3
110 #define CASE_4 4
111 #define CASE_5 5
112 #define CASE_6 6
113 #define CASE_7 7
114 #define CASE_8 8
115 #define CASE_9 9
116 #define CASE_10 10
117 
118 typedef enum {
119     SESSION_4DATA = 1,
120     SESSION_4CTL,
121 } WaitSessionType;
122 
123 typedef enum {
124     DATA_TYPE_MSG = 1,
125     DATA_TYPE_BYTE,
126 } DataType;
127 
128 typedef enum {
129     STATE_ONLINE = 1,
130     STATE_OFFLINE,
131 } WaitNodeStateType;
132 
133 typedef enum {
134     CONC_CLOSE_SESSION = 1,
135     CONC_LEAVE_NET,
136     CONC_DIS_NET_RECOVERY,
137     CONC_DIS_NET_NOT_RECOVERY,
138     CONC_DOWN_NET,
139     CONC_SEND_DATA_ONLY,
140     CONC_CLOSE_SESSION_REMOTE,
141 } ConcurrentType;
142 
143 typedef enum {
144     CTRL_CODE_CLOSE_WIFI_TEN_SEC = 1,
145     CTRL_CODE_CLOSE_WIFI_TEN_MIN,
146     CTRL_CODE_CLOSE_WIFI_FIVE_MIN,
147     CTRL_CODE_CLOSE_WIFI_THREE_SEC,
148     CTRL_CODE_CHANGE_WIFI_TEN_SEC,
149     CTRL_CODE_CHANGE_WIFI_SIXTY_SEC,
150     CTRL_CODE_CHANGE_WIFI_LOOP20,
151     CTRL_CODE_CLOSE_WIFI_LOOP20,
152     CTRL_CODE_CHANGE_WIFI_LOOP100,
153     CTRL_CODE_CLOSE_WIFI_LOOP100,
154     CTRL_CODE_OPEN_SESSION,
155     CTRL_CODE_OPEN_SESSION_MSG,
156     CTRL_CODE_OPEN_SESSION_FAIL,
157     CTRL_CODE_OPEN_SESSION_NOT_EXIST,
158     CTRL_CODE_CLOSE_SESSION,
159     CTRL_CODE_CLOSE_BR,
160     CTRL_CODE_CLOSE_OPEN_BR,
161     CTRL_CODE_CLOSE_AIR,
162     CTRL_CODE_CLOSE_OPEN_AIR,
163     CTRL_CODE_SEND_BIG_DATA,
164 } CtrlCodeType;
165 
166 #define LOG(format, ...)                                                           \
167     do {                                                                           \
168         time_t timeSec;                                                            \
169         time(&timeSec);                                                            \
170         struct tm tmRst;                                                           \
171         localtime_r(&timeSec, &tmRst);                                             \
172         char strTime[10];                                                          \
173         strftime(strTime, sizeof(strTime), "%H:%M:%S", &tmRst);                    \
174         fprintf(stdout, "[Test-softbus] %s " format "\n", strTime, ##__VA_ARGS__); \
175     } while (0)
176 
177 int Wait(int timeout);
178 int Wait4Session(int timeout, WaitSessionType type);
179 int WaitNodeCount(int timeout, WaitNodeStateType state, int expectCount);
180 
181 void TestSetUp(void);
182 void TestTearDown(void);
183 
184 int StartDiscoveryDevice(void);
185 
186 int JoinNetwork(void);
187 int LeaveNetWork(void);
188 int RegisterDeviceStateDefCallback(void);
189 int UnRegisterDeviceStateDefCallback(void);
190 int DiscoverAndJoinNetwork(void);
191 int CheckRemoteDeviceIsNull(int isSetNetId);
192 int GetRemoteDeviceNetId(char** netId);
193 int SetCurrentNetworkId(int index);
194 int SetRemoteDeviceNetIdToGarray(void);
195 
196 uint64_t GetCurrentTimeOfMs(void);
197 
198 void ResetWaitFlag(void);
199 void ResetWaitFlag4Data(void);
200 void ResetWaitFlag4Ctl(void);
201 void ResetWaitCount4Offline(void);
202 void ResetWaitCount4Online(void);
203 
204 int SendData4Data(DataType type, int size);
205 int SendCtrlMsgToRemote(CtrlCodeType code);
206 
207 int CreateSsAndOpenSession4Data(void);
208 int CreateSsAndOpenSession4Ctl(void);
209 int OpenSession4Ctl(void);
210 int OpenSession4Data(void);
211 int OpenSessionBatch4Data(char groupId[][GROUP_ID_LEN], int* sessionId, int count);
212 int OpenSessionBatch4Ctl(char groupId[][GROUP_ID_LEN], int* sessionId, int count);
213 int CloseSessionBatch4Data(int* sessionId, int count);
214 int CloseSessionBatch4Ctl(int* sessionId, int count);
215 void* OpenSessionTask4Data(void* param);
216 void* OpenSessionTask4Ctl(void* param);
217 
218 int OpenSession4Perf(void);
219 int OpenSession4PerfWithParam(const char* sessionName, const char* groupId, char* netId);
220 int SendData4Perf(int sessionId, char* dataMsg, char* dataByte);
221 void SetTransStartTime(void);
222 
223 void* SendDataTask1(void* param);
224 void* SendDataTask2(void* param);
225 void* SendDataTask3(void* param);
226 
227 char* GetSoftbusPid(void);
228 char* GetNetworkId(void);
229 int GetCurrentSessionId4Data(void);
230 int GetCurrentSessionId4Ctl(void);
231 void SetCurrentSessionId4Data(int sessionId);
232 void SetCurrentSessionId4Ctl(int sessionId);
233 ISessionListener* GetSessionListenser4Data(void);
234 ISessionListener* GetSessionListenser4Ctl(void);
235 ISessionListener* GetSessionListenser4Pass(void);
236 ISessionListener* GetSessionListenser4Perf(void);
237 ISessionListener* GetSessionListenser4Proxy(void);
238 SessionAttribute* GetSessionAttr4Pass(void);
239 SessionAttribute* GetSessionAttr4Ctl(void);
240 SessionAttribute* GetSessionAttr4Data(void);
241 SessionAttribute* GetSessionAttr4Perf(void);
242 SessionAttribute* GetSessionAttr4Proxy(void);
243 IFileReceiveListener* GetRecvFileListener(void);
244 IFileSendListener* GetSendFileListener(void);
245 
246 pthread_barrier_t* GetThreadBarrier(void);
247 int GetThreadResult4Data(void);
248 int GetThreadResult4Ctl(void);
249 int* GetSid4Task2(void);
250 int* GetSid4Task3(void);
251 void ResetMsgStat4Control(void);
252 void ResetByteStat4Control(void);
253 ConnectionAddr* GetConnectAddr(void);
254 
255 void ResetClosedSessionCount4Data(void);
256 void ResetClosedSessionCount4Ctrl(void);
257 int GetClosedSessionCount4Data(void);
258 int GetClosedSessionCount4Ctrl(void);
259 void ResetOpenSessionCount4Data(void);
260 void ResetOpenSessionCount4Ctrl(void);
261 int GetOpenSessionCount4Data(void);
262 int GetOpenSessionCount4Ctrl(void);
263 
264 int CloseSessionAndRemoveSs4Data(void);
265 int CloseSessionAndRemoveSs4Ctl(void);
266 
267 #ifdef __cplusplus
268 }
269 #endif
270 #endif
271