10704ebd2Sopenharmony_ci/* 20704ebd2Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 30704ebd2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 40704ebd2Sopenharmony_ci * you may not use this file except in compliance with the License. 50704ebd2Sopenharmony_ci * You may obtain a copy of the License at 60704ebd2Sopenharmony_ci * 70704ebd2Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 80704ebd2Sopenharmony_ci * 90704ebd2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 100704ebd2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 110704ebd2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 120704ebd2Sopenharmony_ci * See the License for the specific language governing permissions and 130704ebd2Sopenharmony_ci * limitations under the License. 140704ebd2Sopenharmony_ci */ 150704ebd2Sopenharmony_ci 160704ebd2Sopenharmony_ci#ifndef NET_TRANS_COMMON_H 170704ebd2Sopenharmony_ci#define NET_TRANS_COMMON_H 180704ebd2Sopenharmony_ci 190704ebd2Sopenharmony_ci#include <pthread.h> 200704ebd2Sopenharmony_ci#include <securec.h> 210704ebd2Sopenharmony_ci#include <sys/time.h> 220704ebd2Sopenharmony_ci#include <unistd.h> 230704ebd2Sopenharmony_ci#include "common_list.h" 240704ebd2Sopenharmony_ci#include "session.h" 250704ebd2Sopenharmony_ci#include "softbus_bus_center.h" 260704ebd2Sopenharmony_ci#include "softbus_common.h" 270704ebd2Sopenharmony_ci#include "softbus_def.h" 280704ebd2Sopenharmony_ci#include "softbus_errcode.h" 290704ebd2Sopenharmony_ci#include "softbus_utils.h" 300704ebd2Sopenharmony_ci#include "nativetoken_kit.h" 310704ebd2Sopenharmony_ci#include "token_setproc.h" 320704ebd2Sopenharmony_ci 330704ebd2Sopenharmony_ci#ifdef __cplusplus 340704ebd2Sopenharmony_ciextern "C" { 350704ebd2Sopenharmony_ci#endif 360704ebd2Sopenharmony_ci 370704ebd2Sopenharmony_ci#define DEF_GROUP_ID "DEF_GROUP_ID" 380704ebd2Sopenharmony_ci#define DEF_SESSION_KEY "DEF_SESSION_KEY" 390704ebd2Sopenharmony_ci#define DEF_PKG_NAME "com.communication.demo1" 400704ebd2Sopenharmony_ci#define PKG_NAME_TWO "com.communication.demo2" 410704ebd2Sopenharmony_ci#define PKG_NAME_THREE "com.communication.demo3" 420704ebd2Sopenharmony_ci#define PKG_NAME_FOUR "com.communication.demo4" 430704ebd2Sopenharmony_ci#define SESSIONNAME_MAX "com.communication.demo.max.len.12345678901234567\ 440704ebd2Sopenharmony_ci 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\ 450704ebd2Sopenharmony_ci 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678" 460704ebd2Sopenharmony_ci#define SESSIONNAME_MAX_OUT "com.communication.demo.max.len.12345678901234567\ 470704ebd2Sopenharmony_ci 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\ 480704ebd2Sopenharmony_ci 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" 490704ebd2Sopenharmony_ci#define PKGNAME_MAX "com.communication.demo.max.len.123456789012345678901234567890123" 500704ebd2Sopenharmony_ci#define PKGNAME_MAX_OUT "com.communication.demo.max.len.1234567890123456789012345678901234" 510704ebd2Sopenharmony_ci 520704ebd2Sopenharmony_ci#define SESSION_NAME_DATA "com.communication.demo1.data" 530704ebd2Sopenharmony_ci#define SESSION_NAME_CTL "com.communication.demo1.control" 540704ebd2Sopenharmony_ci#define SESSION_NAME_PASS "com.communication.demo1.passive" 550704ebd2Sopenharmony_ci#define SESSION_NAME_FAIL "com.communication.demo1.fail" 560704ebd2Sopenharmony_ci#define SESSION_NAME_PERF "com.communication.demo1.perf" 570704ebd2Sopenharmony_ci#define SESSION_NAME_PROXY "com.communication.demo1.proxy" 580704ebd2Sopenharmony_ci#define SESSION_NAME_FILE "com.communication.demo1.file" 590704ebd2Sopenharmony_ci#define SESSION_NAME_STREAM "com.communication.demo1.stream" 600704ebd2Sopenharmony_ci#define DSOFT_PKG_NAME "com.plrdtest.dsoftbus" 610704ebd2Sopenharmony_ci#define SESSION_NAME_DSOFT_DATA "com.plrdtest.dsoftbus.data" 620704ebd2Sopenharmony_ci#define RECV_FILE_PATH "/data/" 630704ebd2Sopenharmony_ci 640704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_WIFI_THREE_SEC "close wifi 3sec" 650704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_WIFI_TEN_MIN "close wifi 10min" 660704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_WIFI_FIVE_MIN "close wifi 5min" 670704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_WIFI_TEN_SEC "close wifi 10sec" 680704ebd2Sopenharmony_ci#define CTRL_MSG_CHANGE_WIFI_TEN_SEC "change wifi 10sec" 690704ebd2Sopenharmony_ci#define CTRL_MSG_CHANGE_WIFI_SIXTY_SEC "change wifi 60sec" 700704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_WIFI_LOOP20 "close wifi loop 20" 710704ebd2Sopenharmony_ci#define CTRL_MSG_CHANGE_WIFI_LOOP20 "change wifi loop 20" 720704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_WIFI_LOOP100 "close wifi loop 100" 730704ebd2Sopenharmony_ci#define CTRL_MSG_CHANGE_WIFI_LOOP100 "change wifi loop 100" 740704ebd2Sopenharmony_ci 750704ebd2Sopenharmony_ci#define CTRL_MSG_OPEN_SESSION "open session" 760704ebd2Sopenharmony_ci#define CTRL_MSG_OPEN_SESSION_MSG "open session msg" 770704ebd2Sopenharmony_ci#define CTRL_MSG_OPEN_SESSION_NOT_EXIST "open session not exist" 780704ebd2Sopenharmony_ci#define CTRL_MSG_OPEN_SESSION_FAIL "open session fail" 790704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_SESSION "close session" 800704ebd2Sopenharmony_ci 810704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_BR "close br" 820704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_OPEN_BR "close-open br" 830704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_AIR "close air" 840704ebd2Sopenharmony_ci#define CTRL_MSG_CLOSE_OPEN_AIR "close-open air" 850704ebd2Sopenharmony_ci#define CTRL_MSG_SEND_BIG_DATA "send big data" 860704ebd2Sopenharmony_ci 870704ebd2Sopenharmony_ci#define WAIT_DEF_VALUE (-1) 880704ebd2Sopenharmony_ci#define WAIT_SUCCESS_VALUE 1 890704ebd2Sopenharmony_ci#define WAIT_FAIL_VALUE 0 900704ebd2Sopenharmony_ci#define SESSION_ID_MIN 1 910704ebd2Sopenharmony_ci#define MAX_SESSION_NUM 20 920704ebd2Sopenharmony_ci#define BOOL_TRUE 1 930704ebd2Sopenharmony_ci#define BOOL_FALSE 0 940704ebd2Sopenharmony_ci#define OPEN_SESSION_TIMEOUT 19 950704ebd2Sopenharmony_ci#define MULTI_REMOTE_DEV_COUNT 3 960704ebd2Sopenharmony_ci#define DEF_REMOTE_DEV_COUNT 1 970704ebd2Sopenharmony_ci#define SIZE_1K 1024 980704ebd2Sopenharmony_ci 990704ebd2Sopenharmony_ci#define CMD_DOWN_ETH "ifconfig eth0 down" 1000704ebd2Sopenharmony_ci#define CMD_PIDOF_SOFTBUS "pidof softbus_server" 1010704ebd2Sopenharmony_ci 1020704ebd2Sopenharmony_ci#define MAX_SESSION_SERVER_NUM_CLIENT 8 1030704ebd2Sopenharmony_ci#define MAX_SESSION_SERVER_NUM_SERVER 32 1040704ebd2Sopenharmony_ci#define TRANS_BYTES_LENGTH_MAX (4 * 1024 * 1024) 1050704ebd2Sopenharmony_ci#define TRANS_MESSAGE_LENGTH_MAX (4 * 1024) 1060704ebd2Sopenharmony_ci#define TRANS_PROXY_BYTES_LENGTH_MAX (4 * 1024 * 1024) 1070704ebd2Sopenharmony_ci#define TRANS_PROXY_MESSAGE_LENGTH_MAX (4 * 1024) 1080704ebd2Sopenharmony_ci#define DEF_SEND_DATA_SID_COUNT 4 1090704ebd2Sopenharmony_ci#define GROUP_ID_LEN 4 1100704ebd2Sopenharmony_ci 1110704ebd2Sopenharmony_ci#define CASE_0 0 1120704ebd2Sopenharmony_ci#define CASE_1 1 1130704ebd2Sopenharmony_ci#define CASE_2 2 1140704ebd2Sopenharmony_ci#define CASE_3 3 1150704ebd2Sopenharmony_ci#define CASE_4 4 1160704ebd2Sopenharmony_ci#define CASE_5 5 1170704ebd2Sopenharmony_ci#define CASE_6 6 1180704ebd2Sopenharmony_ci#define CASE_7 7 1190704ebd2Sopenharmony_ci#define CASE_8 8 1200704ebd2Sopenharmony_ci#define CASE_9 9 1210704ebd2Sopenharmony_ci#define CASE_10 10 1220704ebd2Sopenharmony_ci 1230704ebd2Sopenharmony_citypedef enum { 1240704ebd2Sopenharmony_ci SESSION_4DATA = 1, 1250704ebd2Sopenharmony_ci SESSION_4CTL, 1260704ebd2Sopenharmony_ci SESSION_4PROXY, 1270704ebd2Sopenharmony_ci SESSION_4STREAM, 1280704ebd2Sopenharmony_ci} WaitSessionType; 1290704ebd2Sopenharmony_ci 1300704ebd2Sopenharmony_citypedef enum { 1310704ebd2Sopenharmony_ci DATA_TYPE_MSG = 1, 1320704ebd2Sopenharmony_ci DATA_TYPE_BYTE, 1330704ebd2Sopenharmony_ci} DataType; 1340704ebd2Sopenharmony_ci 1350704ebd2Sopenharmony_citypedef enum { 1360704ebd2Sopenharmony_ci STATE_ONLINE = 1, 1370704ebd2Sopenharmony_ci STATE_OFFLINE, 1380704ebd2Sopenharmony_ci} WaitNodeStateType; 1390704ebd2Sopenharmony_ci 1400704ebd2Sopenharmony_citypedef enum { 1410704ebd2Sopenharmony_ci CONC_CLOSE_SESSION = 1, 1420704ebd2Sopenharmony_ci CONC_LEAVE_NET, 1430704ebd2Sopenharmony_ci CONC_DIS_NET_RECOVERY, 1440704ebd2Sopenharmony_ci CONC_DIS_NET_NOT_RECOVERY, 1450704ebd2Sopenharmony_ci CONC_DOWN_NET, 1460704ebd2Sopenharmony_ci CONC_SEND_DATA_ONLY, 1470704ebd2Sopenharmony_ci CONC_CLOSE_SESSION_REMOTE, 1480704ebd2Sopenharmony_ci} ConcurrentType; 1490704ebd2Sopenharmony_ci 1500704ebd2Sopenharmony_citypedef enum { 1510704ebd2Sopenharmony_ci CTRL_CODE_CLOSE_WIFI_TEN_SEC = 1, 1520704ebd2Sopenharmony_ci CTRL_CODE_CLOSE_WIFI_TEN_MIN, 1530704ebd2Sopenharmony_ci CTRL_CODE_CLOSE_WIFI_FIVE_MIN, 1540704ebd2Sopenharmony_ci CTRL_CODE_CLOSE_WIFI_THREE_SEC, 1550704ebd2Sopenharmony_ci CTRL_CODE_CHANGE_WIFI_TEN_SEC, 1560704ebd2Sopenharmony_ci CTRL_CODE_CHANGE_WIFI_SIXTY_SEC, 1570704ebd2Sopenharmony_ci CTRL_CODE_CHANGE_WIFI_LOOP20, 1580704ebd2Sopenharmony_ci CTRL_CODE_CLOSE_WIFI_LOOP20, 1590704ebd2Sopenharmony_ci CTRL_CODE_CHANGE_WIFI_LOOP100, 1600704ebd2Sopenharmony_ci CTRL_CODE_CLOSE_WIFI_LOOP100, 1610704ebd2Sopenharmony_ci CTRL_CODE_OPEN_SESSION, 1620704ebd2Sopenharmony_ci CTRL_CODE_OPEN_SESSION_MSG, 1630704ebd2Sopenharmony_ci CTRL_CODE_OPEN_SESSION_FAIL, 1640704ebd2Sopenharmony_ci CTRL_CODE_OPEN_SESSION_NOT_EXIST, 1650704ebd2Sopenharmony_ci CTRL_CODE_CLOSE_SESSION, 1660704ebd2Sopenharmony_ci CTRL_CODE_CLOSE_BR, 1670704ebd2Sopenharmony_ci CTRL_CODE_CLOSE_OPEN_BR, 1680704ebd2Sopenharmony_ci CTRL_CODE_CLOSE_AIR, 1690704ebd2Sopenharmony_ci CTRL_CODE_CLOSE_OPEN_AIR, 1700704ebd2Sopenharmony_ci CTRL_CODE_SEND_BIG_DATA, 1710704ebd2Sopenharmony_ci} CtrlCodeType; 1720704ebd2Sopenharmony_ci 1730704ebd2Sopenharmony_ci#define LOG(format, ...) \ 1740704ebd2Sopenharmony_ci do { \ 1750704ebd2Sopenharmony_ci time_t timeSec; \ 1760704ebd2Sopenharmony_ci time(&timeSec); \ 1770704ebd2Sopenharmony_ci struct tm tmRst; \ 1780704ebd2Sopenharmony_ci localtime_r(&timeSec, &tmRst); \ 1790704ebd2Sopenharmony_ci char strTime[10]; \ 1800704ebd2Sopenharmony_ci strftime(strTime, sizeof(strTime), "%H:%M:%S", &tmRst); \ 1810704ebd2Sopenharmony_ci fprintf(stdout, "[Test-softbus] %s " format "\n", strTime, ##__VA_ARGS__); \ 1820704ebd2Sopenharmony_ci } while (0) 1830704ebd2Sopenharmony_ci 1840704ebd2Sopenharmony_cichar* GetSoftbusPid(void); 1850704ebd2Sopenharmony_cichar* GetNetworkId(void); 1860704ebd2Sopenharmony_ciuint64_t GetCurrentTimeOfMs(void); 1870704ebd2Sopenharmony_ciint Wait(int timeout); 1880704ebd2Sopenharmony_ciint Wait4Session(int timeout, WaitSessionType type); 1890704ebd2Sopenharmony_ciint WaitNodeCount(int timeout, WaitNodeStateType state, int expectCount); 1900704ebd2Sopenharmony_ci 1910704ebd2Sopenharmony_civoid sleepn(int n); 1920704ebd2Sopenharmony_civoid TestSetUp(void); 1930704ebd2Sopenharmony_civoid TestTearDown(void); 1940704ebd2Sopenharmony_ci 1950704ebd2Sopenharmony_ciint RegisterDeviceStateDefCallback(void); 1960704ebd2Sopenharmony_ciint UnRegisterDeviceStateDefCallback(void); 1970704ebd2Sopenharmony_ciint CheckRemoteDeviceIsNull(int isSetNetId); 1980704ebd2Sopenharmony_ci 1990704ebd2Sopenharmony_civoid ResetWaitFlag(void); 2000704ebd2Sopenharmony_civoid ResetWaitFlag4Data(void); 2010704ebd2Sopenharmony_civoid ResetWaitFlag4Ctl(void); 2020704ebd2Sopenharmony_civoid ResetWaitFlag4Proxy(void); 2030704ebd2Sopenharmony_civoid ResetwaitCount4Online(void); 2040704ebd2Sopenharmony_civoid ResetwaitCount4Offline(void); 2050704ebd2Sopenharmony_ci 2060704ebd2Sopenharmony_ciint SendData4Data(DataType type, int size); 2070704ebd2Sopenharmony_ciint SendData4Message(DataType type, int size); 2080704ebd2Sopenharmony_ci 2090704ebd2Sopenharmony_ciint CreateSsAndOpenSession4Data(void); 2100704ebd2Sopenharmony_ciint CreateSsAndOpenSession4Ctl(void); 2110704ebd2Sopenharmony_ciint CreateSsAndOpenSession4Proxy(void); 2120704ebd2Sopenharmony_ciint OpenSessionBatch4Data(char groupId[][GROUP_ID_LEN], int* sessionId, int count); 2130704ebd2Sopenharmony_ciint OpenSessionBatch4Ctl(char groupId[][GROUP_ID_LEN], int* sessionId, int count); 2140704ebd2Sopenharmony_ciint OpenSession4DataByP2p(void); 2150704ebd2Sopenharmony_ciint OpenSession4ProxyByP2p(void); 2160704ebd2Sopenharmony_ciint CloseSessionBatch4Data(int* sessionId, int count); 2170704ebd2Sopenharmony_ciint CloseSessionBatch4Ctl(int* sessionId, int count); 2180704ebd2Sopenharmony_ciint GetCurrentSessionId4Data(void); 2190704ebd2Sopenharmony_ciint GetCurrentSessionId4Ctl(void); 2200704ebd2Sopenharmony_ciint GetCurrentSessionId4Proxy(void); 2210704ebd2Sopenharmony_civoid SetCurrentSessionId4Data(int sessionId); 2220704ebd2Sopenharmony_civoid SetCurrentSessionId4Ctl(int sessionId); 2230704ebd2Sopenharmony_civoid SetCurrentSessionId4Proxy(int sessionId); 2240704ebd2Sopenharmony_civoid ResetClosedSessionCount4Data(void); 2250704ebd2Sopenharmony_civoid ResetClosedSessionCount4Ctrl(void); 2260704ebd2Sopenharmony_ciint GetClosedSessionCount4Data(void); 2270704ebd2Sopenharmony_ciint GetClosedSessionCount4Ctrl(void); 2280704ebd2Sopenharmony_ciint CloseSessionAndRemoveSs4Data(void); 2290704ebd2Sopenharmony_ciint CloseSessionAndRemoveSs4Ctl(void); 2300704ebd2Sopenharmony_ciint CloseSessionAndRemoveSs4Proxy(void); 2310704ebd2Sopenharmony_civoid AddPermission(void); 2320704ebd2Sopenharmony_ci 2330704ebd2Sopenharmony_ciISessionListener* GetSessionListenser4Data(void); 2340704ebd2Sopenharmony_ciISessionListener* GetSessionListenser4Ctl(void); 2350704ebd2Sopenharmony_ciISessionListener* GetSessionListenser4Proxy(void); 2360704ebd2Sopenharmony_ciISessionListener* GetSessionListenser4Stream(void); 2370704ebd2Sopenharmony_ci 2380704ebd2Sopenharmony_ciSessionAttribute* GetSessionAttr4Ctl(void); 2390704ebd2Sopenharmony_ciSessionAttribute* GetSessionAttr4Data(void); 2400704ebd2Sopenharmony_ciSessionAttribute* GetSessionAttr4Proxy(void); 2410704ebd2Sopenharmony_ciSessionAttribute* GetSessionAttr4DataP2p(void); 2420704ebd2Sopenharmony_ciSessionAttribute* GetSessionAttr4ProxyP2p(void); 2430704ebd2Sopenharmony_ciIFileReceiveListener* GetRecvFileListener(void); 2440704ebd2Sopenharmony_ciIFileSendListener* GetSendFileListener(void); 2450704ebd2Sopenharmony_ci 2460704ebd2Sopenharmony_ci#ifdef __cplusplus 2470704ebd2Sopenharmony_ci} 2480704ebd2Sopenharmony_ci#endif 2490704ebd2Sopenharmony_ci#endif