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 16 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_CONFIG_ETH_WRONG_IP "ifconfig eth0 193.168.7.88 up" 102 #define CMD_CONFIG_ETH_RIGHT_IP "ifconfig eth0 192.168.3.88 up" 103 #define CMD_PIDOF_SOFTBUS "pidof softbus_server" 104 105 #define CMD_CONFIG_WLAN_WRONG_IP "ifconfig wlan0 193.168.3.88 up" 106 107 #define MAX_SESSION_SERVER_NUM_CLIENT 8 108 #define MAX_SESSION_SERVER_NUM_SERVER 32 109 #define TRANS_BYTES_LENGTH_MAX (4 * 1024 * 1024) 110 #define TRANS_MESSAGE_LENGTH_MAX (4 * 1024) 111 #define TRANS_PROXY_BYTES_LENGTH_MAX (4 * 1024 * 1024) 112 #define TRANS_PROXY_MESSAGE_LENGTH_MAX (4 * 1024) 113 #define DEF_SEND_DATA_SID_COUNT 4 114 #define GROUP_ID_LEN 4 115 116 #define CASE_0 0 117 #define CASE_1 1 118 #define CASE_2 2 119 #define CASE_3 3 120 #define CASE_4 4 121 #define CASE_5 5 122 #define CASE_6 6 123 #define CASE_7 7 124 #define CASE_8 8 125 #define CASE_9 9 126 #define CASE_10 10 127 128 typedef enum { 129 SESSION_4DATA = 1, 130 SESSION_4CTL, 131 SESSION_4PROXY, 132 SESSION_4STREAM, 133 } WaitSessionType; 134 135 typedef enum { 136 DATA_TYPE_MSG = 1, 137 DATA_TYPE_BYTE, 138 } DataType; 139 140 typedef enum { 141 STATE_ONLINE = 1, 142 STATE_OFFLINE, 143 } WaitNodeStateType; 144 145 typedef enum { 146 CONC_CLOSE_SESSION = 1, 147 CONC_LEAVE_NET, 148 CONC_DIS_NET_RECOVERY, 149 CONC_DIS_NET_NOT_RECOVERY, 150 CONC_DOWN_NET, 151 CONC_SEND_DATA_ONLY, 152 CONC_CLOSE_SESSION_REMOTE, 153 } ConcurrentType; 154 155 typedef enum { 156 CTRL_CODE_CLOSE_WIFI_TEN_SEC = 1, 157 CTRL_CODE_CLOSE_WIFI_TEN_MIN, 158 CTRL_CODE_CLOSE_WIFI_FIVE_MIN, 159 CTRL_CODE_CLOSE_WIFI_THREE_SEC, 160 CTRL_CODE_CHANGE_WIFI_TEN_SEC, 161 CTRL_CODE_CHANGE_WIFI_SIXTY_SEC, 162 CTRL_CODE_CHANGE_WIFI_LOOP20, 163 CTRL_CODE_CLOSE_WIFI_LOOP20, 164 CTRL_CODE_CHANGE_WIFI_LOOP100, 165 CTRL_CODE_CLOSE_WIFI_LOOP100, 166 CTRL_CODE_OPEN_SESSION, 167 CTRL_CODE_OPEN_SESSION_MSG, 168 CTRL_CODE_OPEN_SESSION_FAIL, 169 CTRL_CODE_OPEN_SESSION_NOT_EXIST, 170 CTRL_CODE_CLOSE_SESSION, 171 CTRL_CODE_CLOSE_BR, 172 CTRL_CODE_CLOSE_OPEN_BR, 173 CTRL_CODE_CLOSE_AIR, 174 CTRL_CODE_CLOSE_OPEN_AIR, 175 CTRL_CODE_SEND_BIG_DATA, 176 } CtrlCodeType; 177 178 #define LOG(format, ...) \ 179 do { \ 180 time_t timeSec; \ 181 time(&timeSec); \ 182 struct tm tmRst; \ 183 localtime_r(&timeSec, &tmRst); \ 184 char strTime[10]; \ 185 strftime(strTime, sizeof(strTime), "%H:%M:%S", &tmRst); \ 186 fprintf(stdout, "[Test-softbus] %s " format "\n", strTime, ##__VA_ARGS__); \ 187 } while (0) 188 189 char* GetSoftbusPid(void); 190 char* GetNetworkId(void); 191 uint64_t GetCurrentTimeOfMs(void); 192 int Wait(int timeout); 193 int Wait4Session(int timeout, WaitSessionType type); 194 int WaitNodeCount(int timeout, WaitNodeStateType state, int expectCount); 195 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 void ResetWaitFlag(void); 205 void ResetWaitFlag4Data(void); 206 void ResetWaitFlag4Ctl(void); 207 void ResetWaitFlag4Proxy(void); 208 void ResetwaitCount4Online(void); 209 void ResetwaitCount4Offline(void); 210 211 int SendData4Data(DataType type, int size); 212 int SendData4Message(DataType type, int size); 213 214 int CreateSsAndOpenSession4Data(void); 215 int CreateSsAndOpenSession4Ctl(void); 216 int CreateSsAndOpenSession4Proxy(void); 217 int OpenSessionBatch4Data(char groupId[][GROUP_ID_LEN], int* sessionId, int count); 218 int OpenSessionBatch4Ctl(char groupId[][GROUP_ID_LEN], int* sessionId, int count); 219 int OpenSession4DataByP2p(void); 220 int OpenSession4ProxyByP2p(void); 221 int CloseSessionBatch4Data(int* sessionId, int count); 222 int CloseSessionBatch4Ctl(int* sessionId, int count); 223 int GetCurrentSessionId4Data(void); 224 int GetCurrentSessionId4Ctl(void); 225 int GetCurrentSessionId4Proxy(void); 226 void SetCurrentSessionId4Data(int sessionId); 227 void SetCurrentSessionId4Ctl(int sessionId); 228 void SetCurrentSessionId4Proxy(int sessionId); 229 void ResetClosedSessionCount4Data(void); 230 void ResetClosedSessionCount4Ctrl(void); 231 int GetClosedSessionCount4Data(void); 232 int GetClosedSessionCount4Ctrl(void); 233 int CloseSessionAndRemoveSs4Data(void); 234 int CloseSessionAndRemoveSs4Ctl(void); 235 int CloseSessionAndRemoveSs4Proxy(void); 236 void AddPermission(void); 237 238 ISessionListener* GetSessionListenser4Data(void); 239 ISessionListener* GetSessionListenser4Ctl(void); 240 ISessionListener* GetSessionListenser4Proxy(void); 241 ISessionListener* GetSessionListenser4Stream(void); 242 243 SessionAttribute* GetSessionAttr4Ctl(void); 244 SessionAttribute* GetSessionAttr4Data(void); 245 SessionAttribute* GetSessionAttr4Proxy(void); 246 SessionAttribute* GetSessionAttr4DataP2p(void); 247 SessionAttribute* GetSessionAttr4ProxyP2p(void); 248 IFileReceiveListener* GetRecvFileListener(void); 249 IFileSendListener* GetSendFileListener(void); 250 251 #ifdef __cplusplus 252 } 253 #endif 254 #endif