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