• 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 #include "nativetoken_kit.h"
34 #include "token_setproc.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #define DEF_GROUP_ID "DEF_GROUP_ID"
41 #define DEF_SESSION_KEY "DEF_SESSION_KEY"
42 #define DEF_PKG_NAME "com.communication.demo1"
43 #define PKG_NAME_TWO "com.communication.demo2"
44 #define PKG_NAME_THREE "com.communication.demo3"
45 #define PKG_NAME_FOUR "com.communication.demo4"
46 #define SESSIONNAME_MAX "com.communication.demo.max.len.1234567890123456\
47     0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\
48     012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"
49 #define SESSIONNAME_MAX_OUT "com.communication.demo.max.len.1234567890123456\
50     0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\
51     0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
52 #define PKGNAME_MAX "com.communication.demo.max.len.12345678901234567890123456789012"
53 #define PKGNAME_MAX_OUT "com.communication.demo.max.len.123456789012345678901234567890123"
54 
55 #define SESSION_NAME_DATA "com.communication.demo1.data"
56 #define SESSION_NAME_CTL "com.communication.demo1.control"
57 #define SESSION_NAME_PASS "com.communication.demo1.passive"
58 #define SESSION_NAME_FAIL "com.communication.demo1.fail"
59 #define SESSION_NAME_PERF "com.communication.demo1.perf"
60 #define SESSION_NAME_PROXY "com.communication.demo1.proxy"
61 #define SESSION_NAME_FILE "com.communication.demo1.file"
62 #define SESSION_NAME_STREAM "com.communication.demo1.stream"
63 #define DSOFT_PKG_NAME "com.plrdtest.dsoftbus"
64 #define SESSION_NAME_DSOFT_DATA "com.plrdtest.dsoftbus.data"
65 #define RECV_FILE_PATH "/data/"
66 
67 #define CTRL_MSG_CLOSE_WIFI_THREE_SEC "close wifi 3sec"
68 #define CTRL_MSG_CLOSE_WIFI_TEN_MIN "close wifi 10min"
69 #define CTRL_MSG_CLOSE_WIFI_FIVE_MIN "close wifi 5min"
70 #define CTRL_MSG_CLOSE_WIFI_TEN_SEC "close wifi 10sec"
71 #define CTRL_MSG_CHANGE_WIFI_TEN_SEC "change wifi 10sec"
72 #define CTRL_MSG_CHANGE_WIFI_SIXTY_SEC "change wifi 60sec"
73 #define CTRL_MSG_CLOSE_WIFI_LOOP20 "close wifi loop 20"
74 #define CTRL_MSG_CHANGE_WIFI_LOOP20 "change wifi loop 20"
75 #define CTRL_MSG_CLOSE_WIFI_LOOP100 "close wifi loop 100"
76 #define CTRL_MSG_CHANGE_WIFI_LOOP100 "change wifi loop 100"
77 
78 #define CTRL_MSG_OPEN_SESSION "open session"
79 #define CTRL_MSG_OPEN_SESSION_MSG "open session msg"
80 #define CTRL_MSG_OPEN_SESSION_NOT_EXIST "open session not exist"
81 #define CTRL_MSG_OPEN_SESSION_FAIL "open session fail"
82 #define CTRL_MSG_CLOSE_SESSION "close session"
83 
84 #define CTRL_MSG_CLOSE_BR "close br"
85 #define CTRL_MSG_CLOSE_OPEN_BR "close-open br"
86 #define CTRL_MSG_CLOSE_AIR "close air"
87 #define CTRL_MSG_CLOSE_OPEN_AIR "close-open air"
88 #define CTRL_MSG_SEND_BIG_DATA "send big data"
89 
90 #define WAIT_DEF_VALUE (-1)
91 #define WAIT_SUCCESS_VALUE 1
92 #define WAIT_FAIL_VALUE 0
93 #define SESSION_ID_MIN 1
94 #define MAX_SESSION_NUM 16
95 #define BOOL_TRUE 1
96 #define BOOL_FALSE 0
97 #define OPEN_SESSION_TIMEOUT 19
98 #define MULTI_REMOTE_DEV_COUNT 3
99 #define DEF_REMOTE_DEV_COUNT 1
100 #define SIZE_1K 1024
101 
102 #define CMD_DOWN_ETH "ifconfig eth0 down"
103 #define CMD_CONFIG_ETH_WRONG_IP "ifconfig eth0 193.168.7.88 up"
104 #define CMD_CONFIG_ETH_RIGHT_IP "ifconfig eth0 192.168.3.88 up"
105 #define CMD_PIDOF_SOFTBUS "pidof softbus_server"
106 
107 #define CMD_CONFIG_WLAN_WRONG_IP "ifconfig wlan0 193.168.3.88 up"
108 
109 #define MAX_SESSION_SERVER_NUM_CLIENT 8
110 #define MAX_SESSION_SERVER_NUM_SERVER 32
111 #define TRANS_BYTES_LENGTH_MAX (4 * 1024 * 1024)
112 #define TRANS_MESSAGE_LENGTH_MAX 4096
113 #define TRANS_PROXY_BYTES_LENGTH_MAX (4 * 1024)
114 #define TRANS_PROXY_MESSAGE_LENGTH_MAX 1024
115 #define DEF_SEND_DATA_SID_COUNT 4
116 #define GROUP_ID_LEN 4
117 
118 #define CASE_0 0
119 #define CASE_1 1
120 #define CASE_2 2
121 #define CASE_3 3
122 #define CASE_4 4
123 #define CASE_5 5
124 #define CASE_6 6
125 #define CASE_7 7
126 #define CASE_8 8
127 #define CASE_9 9
128 #define CASE_10 10
129 
130 typedef enum {
131     SESSION_4DATA = 1,
132     SESSION_4CTL,
133     SESSION_4PROXY,
134     SESSION_4STREAM,
135 } WaitSessionType;
136 
137 typedef enum {
138     DATA_TYPE_MSG = 1,
139     DATA_TYPE_BYTE,
140 } DataType;
141 
142 typedef enum {
143     STATE_ONLINE = 1,
144     STATE_OFFLINE,
145 } WaitNodeStateType;
146 
147 typedef enum {
148     CONC_CLOSE_SESSION = 1,
149     CONC_LEAVE_NET,
150     CONC_DIS_NET_RECOVERY,
151     CONC_DIS_NET_NOT_RECOVERY,
152     CONC_DOWN_NET,
153     CONC_SEND_DATA_ONLY,
154     CONC_CLOSE_SESSION_REMOTE,
155 } ConcurrentType;
156 
157 typedef enum {
158     CTRL_CODE_CLOSE_WIFI_TEN_SEC = 1,
159     CTRL_CODE_CLOSE_WIFI_TEN_MIN,
160     CTRL_CODE_CLOSE_WIFI_FIVE_MIN,
161     CTRL_CODE_CLOSE_WIFI_THREE_SEC,
162     CTRL_CODE_CHANGE_WIFI_TEN_SEC,
163     CTRL_CODE_CHANGE_WIFI_SIXTY_SEC,
164     CTRL_CODE_CHANGE_WIFI_LOOP20,
165     CTRL_CODE_CLOSE_WIFI_LOOP20,
166     CTRL_CODE_CHANGE_WIFI_LOOP100,
167     CTRL_CODE_CLOSE_WIFI_LOOP100,
168     CTRL_CODE_OPEN_SESSION,
169     CTRL_CODE_OPEN_SESSION_MSG,
170     CTRL_CODE_OPEN_SESSION_FAIL,
171     CTRL_CODE_OPEN_SESSION_NOT_EXIST,
172     CTRL_CODE_CLOSE_SESSION,
173     CTRL_CODE_CLOSE_BR,
174     CTRL_CODE_CLOSE_OPEN_BR,
175     CTRL_CODE_CLOSE_AIR,
176     CTRL_CODE_CLOSE_OPEN_AIR,
177     CTRL_CODE_SEND_BIG_DATA,
178 } CtrlCodeType;
179 
180 #define LOG(format, ...)                                                           \
181     do {                                                                           \
182         time_t timeSec;                                                            \
183         time(&timeSec);                                                            \
184         struct tm tmRst;                                                           \
185         localtime_r(&timeSec, &tmRst);                                             \
186         char strTime[10];                                                          \
187         strftime(strTime, sizeof(strTime), "%H:%M:%S", &tmRst);                    \
188         fprintf(stdout, "[Test-softbus] %s " format "\n", strTime, ##__VA_ARGS__); \
189     } while (0)
190 
191 int Wait(int timeout);
192 int Wait4Session(int timeout, WaitSessionType type);
193 int WaitNodeCount(int timeout, WaitNodeStateType state, int expectCount);
194 
195 void AddPermission (void);
196 void sleepn(int n);
197 void TestSetUp(void);
198 void TestTearDown(void);
199 
200 int RegisterDeviceStateDefCallback(void);
201 int UnRegisterDeviceStateDefCallback(void);
202 int CheckRemoteDeviceIsNull(int isSetNetId);
203 
204 uint64_t GetCurrentTimeOfMs(void);
205 
206 void ResetWaitFlag(void);
207 void ResetWaitFlag4Data(void);
208 void ResetWaitFlag4Ctl(void);
209 void ResetWaitFlag4Proxy(void);
210 void ResetwaitCount4Online(void);
211 void ResetwaitCount4Offline(void);
212 
213 int SendData4Data(DataType type, int size);
214 int SendData4Message(DataType type, int size);
215 
216 int CreateSsAndOpenSession4Data(void);
217 int CreateSsAndOpenSession4Ctl(void);
218 int CreateSsAndOpenSession4Proxy(void);
219 int OpenSessionBatch4Data(char groupId[][GROUP_ID_LEN], int* sessionId, int count);
220 int OpenSessionBatch4Ctl(char groupId[][GROUP_ID_LEN], int* sessionId, int count);
221 int OpenSession4DataByP2p(void);
222 int OpenSession4ProxyByP2p(void);
223 int CloseSessionBatch4Data(int* sessionId, int count);
224 int CloseSessionBatch4Ctl(int* sessionId, int count);
225 
226 char* GetSoftbusPid(void);
227 char* GetNetworkId(void);
228 int GetCurrentSessionId4Data(void);
229 int GetCurrentSessionId4Ctl(void);
230 int GetCurrentSessionId4Proxy(void);
231 void SetCurrentSessionId4Data(int sessionId);
232 void SetCurrentSessionId4Ctl(int sessionId);
233 void SetCurrentSessionId4Proxy(int sessionId);
234 ISessionListener* GetSessionListenser4Data(void);
235 ISessionListener* GetSessionListenser4Ctl(void);
236 ISessionListener* GetSessionListenser4Proxy(void);
237 ISessionListener* GetSessionListenser4Stream(void);
238 
239 SessionAttribute* GetSessionAttr4Ctl(void);
240 SessionAttribute* GetSessionAttr4Data(void);
241 SessionAttribute* GetSessionAttr4Proxy(void);
242 SessionAttribute* GetSessionAttr4DataP2p(void);
243 SessionAttribute* GetSessionAttr4ProxyP2p(void);
244 IFileReceiveListener* GetRecvFileListener(void);
245 IFileSendListener* GetSendFileListener(void);
246 
247 void ResetClosedSessionCount4Data(void);
248 void ResetClosedSessionCount4Ctrl(void);
249 int GetClosedSessionCount4Data(void);
250 int GetClosedSessionCount4Ctrl(void);
251 
252 int CloseSessionAndRemoveSs4Data(void);
253 int CloseSessionAndRemoveSs4Ctl(void);
254 int CloseSessionAndRemoveSs4Proxy(void);
255 
256 #ifdef __cplusplus
257 }
258 #endif
259 #endif
260