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 NSTACKX_DFILE_CONFIG_H 17 #define NSTACKX_DFILE_CONFIG_H 18 19 #include <stdint.h> 20 21 #include "nstackx_config.h" 22 #include "nstackx_util.h" 23 #include "nstackx_dfile_frame.h" 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /** 29 * Enable(1) or Disable(0) fillp support in nStackx Dmsg 30 */ 31 32 /* for struct */ 33 typedef struct DFileConfig { 34 uint16_t dataFrameSize; 35 uint16_t sendRate; 36 } DFileConfig; 37 38 typedef struct DFileTransConfig { 39 uint32_t maxRtt; 40 uint8_t maxAckCnt; /* Sender wait for number of "maxAckCnt" ACK before timeout */ 41 uint8_t maxCtrlFrameRetryCnt; /* Max retry count for control frame */ 42 uint32_t maxCtrlFrameTimeout; /* Max timeout value for control frame */ 43 uint32_t maxFileHeaderConfirmFrameTimeout; /* Max timeout value for wait file header confirm frame */ 44 uint32_t maxFileWriteTimeout; /* Max timeout value for writing all file data */ 45 uint32_t initialRecvIdleTimeout; /* Initial idle timeout value for receiver */ 46 uint8_t maxRecvIdleCnt; /* Max successive idle count before receiver timeout */ 47 uint32_t initialAckInterval; /* Initial ACK interval during normal stage */ 48 uint32_t recvLimitAckInterval; /* Adjusted ACK interval after receiving 90% frames */ 49 uint32_t lastFrameAckInterval; /* Adjusted ACK interval after receiving last frame of last file */ 50 uint32_t maxRetryPageCnt; /* Max number of ACK packets containing retry units per interval */ 51 uint32_t maxRetryListNodeCnt; /* Max number of retry nodes (retry unit) during transfer. */ 52 } DFileTransConfig; 53 54 #define DFILE_MEGABYTES 1048576 55 #define DFILE_KILOBYTES 1024 56 #define DATA_FRAME_SEND_INTERVAL_MS 5 57 #define MSEC_TICKS_PER_SEC 1000 58 #define USEC_TICKS_PER_MSEC 1000 59 #define DATA_FRAME_SEND_INTERVAL_US (USEC_TICKS_PER_MSEC * DATA_FRAME_SEND_INTERVAL_MS) 60 #define NSTACKX_INIT_ACK_COUNT 50 61 #define NSTACKX_INIT_ACK_INTERVAL 50 62 #define NSTACKX_INIT_RATE_STAT_INTERVAL 50000 63 #define NSTACKX_ACK_INTERVAL 200 64 #define NSTACKX_RATE_STAT_INTERVAL 200000 65 #define NSTACKX_CONTROL_INTERVAL 200000 66 #define NSTACKX_CONGESTION_CONTROL_TIMES 5 67 #define NSTACKX_MAX_CONTROL_TIMES 10 68 #define NSTACKX_MIN_SENDRATE 3 69 70 #define NSTACKX_MAX_ACK_COUNT 50 71 #define NSTACKX_DROP_ACK_FIRST_LEVEL 3 72 #define NSTACKX_DROP_ACK_SECOND_LEVEL 8 73 #define NSTACKX_DROP_ACK_DIVIDE 15 74 75 #define NSTACKX_SEND_ACK_PER_THREE_RECYCLE 5 76 #define NSTACKX_SEND_ACK_PER_TWO_RECYCLE 2 77 #define NSTACKX_SEND_ACK_PER_ONE_RECYCLE 1 78 #define NSTACKX_DIVISION_COMPENSATION_RATE 3 79 #define NSTACKX_MAX_CLIENT_SEND_THREAD_NUM 3 80 /* 01 single path 02 multi path */ 81 #define NSTACKX_DFILE_VERSION 0x01 82 83 /* for P2P */ 84 /* DFile session configuration */ 85 #define NSTACKX_P2P_SEND_RATE (210 * 1024 * 1024) 86 #define NSTACKX_P2P_COMPENSATION_RATE 1 87 #define NSTACKX_P2P_FRAME_SIZE_TIMES 1 88 #define NSTACKX_P2P_INIT_SPEED_DIVISOR 2 89 /* DFile trans configuration */ 90 #define NSTACKX_P2P_UDP_RTT 200 91 #define NSTACKX_P2P_MAX_CONTROL_FRAME_RETRY_COUNT 75 92 #define NSTACKX_P2P_MAX_CONTROL_FRAME_TIMEOUT 10000 93 #define NSTACKX_P2P_MAX_FILE_HEADER_CONFIRM_FRAME_TIMEOUT 5000 94 #define NSTACKX_P2P_RECEIVED_LIMIT_ACK_INTERVAL 500 95 #define NSTACKX_P2P_RECEIVED_LAST_FRAME_ACK_INTERVAL 100 96 #define NSTACKX_P2P_RECEIVER_IDLE_INIT_TIMEOUT 10000 97 #define NSTACKX_P2P_RECEIVER_IDLE_MAX_COUNT 1 98 #define NSTACKX_P2P_MAX_RETRY_PAGE_COUNT 16 99 #define NSTACKX_P2P_MIN_RETRY_PAGE_COUNT 3 100 #define NSTACKX_P2P_MAX_RETRY_LIST_NODE_NUM 100000 101 #define NSTACKX_P2P_WRITE_ALL_FILE_DATA_TIMEOUT 10000 102 #define NSTACKX_P2P_CLINET_SEND_THREAD_NUM_NON_GSO 3 103 #define NSTACKX_P2P_CLIENT_SEND_THREAD_NUM_GSO 1 104 #define NSTACKX_P2P_SEND_BLOCK_QUEUE_MAX_LEN 5000 105 #define NSTACKX_P2P_RECV_BLOCK_QUEUE_MAX_LEN 50000 106 107 #if (NSTACKX_P2P_CLINET_SEND_THREAD_NUM_NON_GSO > NSTACKX_MAX_CLIENT_SEND_THREAD_NUM) ||\ 108 (NSTACKX_P2P_CLIENT_SEND_THREAD_NUM_GSO > NSTACKX_MAX_CLIENT_SEND_THREAD_NUM) 109 #error OVER THE MAX SEND NUM! 110 #endif 111 112 /* for WLAN */ 113 /* DFile session configuration */ 114 #define NSTACKX_WLAN_SEND_RATE (30 * 1024 * 1024) 115 #define NSTACKX_WLAN_COMPENSATION_RATE 2 116 #define NSTACKX_WLAN_FRAME_SIZE_TIMES 1 117 #define NSTACKX_WLAN_INIT_SPEED_DIVISOR 2 118 #define NSTACKX_WLAN_INIT_RATE (3 * 1024 * 1024) /* can not get wifi rate */ 119 120 /* DFile trans configuration */ 121 #define NSTACKX_WLAN_UDP_RTT 200 122 #define NSTACKX_WLAN_MAX_CONTROL_FRAME_RETRY_COUNT 75 123 #define NSTACKX_WLAN_MAX_CONTROL_FRAME_TIMEOUT 5000 124 #define NSTACKX_WLAN_MAX_FILE_HEADER_CONFIRM_FRAME_TIMEOUT 5000 125 #define NSTACKX_WLAN_RECEIVED_LIMIT_ACK_INTERVAL 500 126 #define NSTACKX_WLAN_RECEIVED_LAST_FRAME_ACK_INTERVAL 100 127 #define NSTACKX_WLAN_RECEIVER_IDLE_INIT_TIMEOUT 10000 128 #define NSTACKX_WLAN_RECEIVER_IDLE_MAX_COUNT 1 129 #define NSTACKX_WLAN_MAX_RETRY_PAGE_COUNT 16 130 #define NSTACKX_WLAN_MIN_RETRY_PAGE_COUNT 1 131 #define NSTACKX_WLAN_MAX_RETRY_LIST_NODE_NUM 50000 132 #define NSTACKX_WLAN_WRITE_ALL_FILE_DATA_TIMEOUT 1000 133 #define NSTACKX_WLAN_CLIENT_SEND_THREAD_NUM 1 134 #define NSTACKX_WLAN_CLIENT_SEND_THREAD_NUM_MP 2 135 #define NSTACKX_WLAN_SEND_BLOCK_QUEUE_MAX_LEN 1000 136 #define NSTACKX_WLAN_RECV_BLOCK_QUEUE_MAX_LEN 20000 137 /* thread name */ 138 #define DFFILE_MAIN_THREAD_NAME "dfile_mainloop" 139 #define DFFILE_RECV_THREAD_NAME "dfile_recv" 140 #define DFFILE_SEND_THREAD_NAME_PREFIX "dfile_send_" 141 #define DFFILE_IO_THREAD_NAME_PREFIX "dfile_io_" 142 #define DFFILE_CONTROL_THREAD_NAME "dfile_control" 143 144 /* bind type */ 145 typedef struct BindInfo { 146 pid_t tid; 147 uint32_t cpuMask; 148 } BindInfo; 149 150 #define DFILE_BIND_TYPE_INDEX_MAX 2 151 #define GSO_TYPE_INDEX_MAX 2 152 #define DFILE_MAX_THREAD_NUM 8 153 154 #define POS_IO_THERD_START 0 155 #define POS_SEND_THERD_START 3 156 #define POS_RECV_THERD_START 6 157 #define POS_MAIN_THERD_START 7 158 159 #define KEEP_ALIVE_IDLE 60 160 #define KEEP_ALIVE_CNT 5 161 #define KEEP_ALIVE_INTERVAL 1 162 #define TCP_USER_TIMEOUT_VALUE 60000 163 164 typedef enum { 165 INIT_STATUS = -1, 166 HIGH_SPEED = 0, 167 LOW_SPEED, 168 } BindType; 169 170 #define SPEED_BOUNDS 120 171 172 typedef enum { 173 STATE_TRANS_INIT = 0, 174 STATE_TRANS_DONE, 175 } TransIdState; 176 177 struct DFileSession; 178 179 /* for function */ 180 int32_t GetDFileConfig(DFileConfig *dFileConfig, uint16_t mtu, uint16_t connType); 181 int32_t ConfigDFileTrans(uint16_t connType, DFileTransConfig *transConfig); 182 void SetTidToBindInfo(const struct DFileSession *session, uint32_t pos); 183 void SetTcpKeepAlive(SocketDesc fd); 184 void DFileGetCipherCaps(struct DFileSession *session, SettingFrame *settingFramePara); 185 void DFileChooseCipherType(SettingFrame *hostSettingFrame, struct DFileSession *session); 186 187 #ifdef __cplusplus 188 } 189 #endif 190 191 #endif /* #ifndef NSTACKX_DFILE_CONFIG_H */ 192