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