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