aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/tcp.h6
-rw-r--r--include/net/tcp.h7
-rw-r--r--net/ipv4/tcp_cong.c1
-rw-r--r--net/ipv4/tcp_input.c7
-rwxr-xr-x[-rw-r--r--]net/ipv4/tcp_mytcp.c372
-rwxr-xr-x[-rw-r--r--]net/ipv4/tcp_mytcp.h0
6 files changed, 321 insertions, 72 deletions
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 5feb49ee9..f2be9dbaa 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -471,12 +471,18 @@ struct tcp_sock {
471 u32 mytcp_bytes_send; 471 u32 mytcp_bytes_send;
472 u32 mytcp_acked_bytes; 472 u32 mytcp_acked_bytes;
473 u32 mytcp_acked_seq_last; 473 u32 mytcp_acked_seq_last;
474
475 // add
476 int exit_slow_start_flag;
474 477
475 // new 478 // new
476 u32 my_ip_rtt; 479 u32 my_ip_rtt;
477 480
481 u32 mytcp_average_rtt;
482
478 u32 my_last_ack; 483 u32 my_last_ack;
479 u32 my_ack_seq_gap; 484 u32 my_ack_seq_gap;
485 u32 mytcp_this_rtt_count;
480 // new ended 486 // new ended
481}; 487};
482 488
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 7a8f950f5..69417ebf6 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1210,7 +1210,12 @@ static inline unsigned int tcp_packets_in_flight(const struct tcp_sock *tp)
1210 1210
1211static inline bool tcp_in_slow_start(const struct tcp_sock *tp) 1211static inline bool tcp_in_slow_start(const struct tcp_sock *tp)
1212{ 1212{
1213 return tp->snd_cwnd < tp->snd_ssthresh; 1213 // return tp->snd_cwnd < tp->snd_ssthresh;
1214 if(tp->exit_slow_start_flag!=1){
1215 return tp->snd_cwnd < tp->snd_ssthresh;
1216 }else{
1217 return 0;
1218 }
1214} 1219}
1215 1220
1216static inline bool tcp_in_initial_slowstart(const struct tcp_sock *tp) 1221static inline bool tcp_in_initial_slowstart(const struct tcp_sock *tp)
diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
index be24f070c..949fe9df3 100644
--- a/net/ipv4/tcp_cong.c
+++ b/net/ipv4/tcp_cong.c
@@ -409,6 +409,7 @@ u32 tcp_slow_start(struct tcp_sock *tp, u32 acked)
409 else{ 409 else{
410 cwnd_full = min((cwnd + tp->mytcp_stopped_cwnd), tp->snd_ssthresh); 410 cwnd_full = min((cwnd + tp->mytcp_stopped_cwnd), tp->snd_ssthresh);
411 tp->snd_cwnd = min(cwnd_full, tp->snd_cwnd_clamp); 411 tp->snd_cwnd = min(cwnd_full, tp->snd_cwnd_clamp);
412 tp->mytcp_stopped_cwnd = 0;
412// printk(KERN_DEBUG "full_pipe_flag == 0, the cwnd is %u, the mytcp_stopped_cwnd is %u\n",tp->snd_cwnd, tp->mytcp_stopped_cwnd); 413// printk(KERN_DEBUG "full_pipe_flag == 0, the cwnd is %u, the mytcp_stopped_cwnd is %u\n",tp->snd_cwnd, tp->mytcp_stopped_cwnd);
413 tp->mytcp_stopped_cwnd = 0; 414 tp->mytcp_stopped_cwnd = 0;
414 } 415 }
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 2e878f392..c934446f3 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -3098,6 +3098,13 @@ static bool tcp_ack_update_rtt(struct sock *sk, const int flag,
3098 3098
3099 /* RFC6298: only reset backoff on valid RTT measurement. */ 3099 /* RFC6298: only reset backoff on valid RTT measurement. */
3100 inet_csk(sk)->icsk_backoff = 0; 3100 inet_csk(sk)->icsk_backoff = 0;
3101 //打印RTT
3102 struct inet_sock *inet2;
3103 inet2 = inet_sk(sk);
3104 if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){
3105 printk(KERN_DEBUG "in tcp_ack_update_rtt now RTT is %ld\n",rs->rtt_us);
3106 // printk(KERN_DEBUG "in tcp_ack_update_rtt cwnd is %u\n", tp->snd_cwnd);
3107 }
3101 return true; 3108 return true;
3102} 3109}
3103 3110
diff --git a/net/ipv4/tcp_mytcp.c b/net/ipv4/tcp_mytcp.c
index 6e9bb84e5..56cf935a3 100644..100755
--- a/net/ipv4/tcp_mytcp.c
+++ b/net/ipv4/tcp_mytcp.c
@@ -9,8 +9,8 @@
9#include <net/tcp.h> 9#include <net/tcp.h>
10#include <linux/time.h> // for gettimeofday() 10#include <linux/time.h> // for gettimeofday()
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include "/home/player/Desktop/ohos/src/kernel/linux/linux-5.10/drivers/net/wireless/ath/ath10k/core.h"
13#include "/home/player/Desktop/ohos/src/kernel/linux/linux-5.10/include/net/mac80211.h" 12#include "/home/player/Desktop/ohos/src/kernel/linux/linux-5.10/include/net/mac80211.h"
13#include "/home/player/Desktop/ohos/src/kernel/linux/linux-5.10/drivers/net/wireless/ath/ath10k/core.h"
14#include "tcp_vegas.h" 14#include "tcp_vegas.h"
15 15
16#include "tcp_mytcp.h" 16#include "tcp_mytcp.h"
@@ -29,7 +29,7 @@
29//int this_flow_num; 29//int this_flow_num;
30 30
31static int gamma = 2; 31static int gamma = 2;
32static int RQ_allow = 40; 32static int RQ_allow = 10;
33 33
34module_param(gamma, int, 0644); 34module_param(gamma, int, 0644);
35MODULE_PARM_DESC(gamma, "limit on increase (scale by 2)"); 35MODULE_PARM_DESC(gamma, "limit on increase (scale by 2)");
@@ -113,11 +113,13 @@ void tcp_mytcp_pkts_acked(struct sock *sk, const struct ack_sample *sample)
113 113
114 vrtt = sample->rtt_us + 1; 114 vrtt = sample->rtt_us + 1;
115// mytcp->rtt_of_this_packet = sample->rtt_us; 115// mytcp->rtt_of_this_packet = sample->rtt_us;
116 tp->my_ip_rtt = sample->rtt_us; 116 tp->my_ip_rtt = sample->rtt_us;//目前的rtt
117 117
118 buffer_queue = tp->write_seq - tp->snd_una; //sndbuffer中的当前队列长度,单位为byte 118 buffer_queue = tp->write_seq - tp->snd_una; //sndbuffer中的当前队列长度,单位为byte
119// printk(KERN_DEBUG "packets inflight are %u\n", tp->packets_out); 119// printk(KERN_DEBUG "packets inflight are %u\n", tp->packets_out);
120 printk(KERN_DEBUG "the mytcp RTT is %u\n",sample->rtt_us); 120 // printk(KERN_DEBUG "the mytcp RTT is %u\n",sample->rtt_us);
121 // printk(KERN_DEBUG "in mytcp, the cubic cwnd is %u\n",tp->snd_cwnd);
122
121 123
122 124
123 /* Filter to find propagation delay: */ 125 /* Filter to find propagation delay: */
@@ -202,6 +204,19 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
202 int buffer_queue; 204 int buffer_queue;
203 int min_inflight; 205 int min_inflight;
204 206
207 struct inet_sock *inet2;
208 inet2 = inet_sk(sk);
209
210
211
212 // if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){
213 // printk(KERN_DEBUG "cubictcp_cong_avoid has receive acked is %u\n", acked);
214 // printk(KERN_DEBUG "cubictcp_cong_avoid the ack is %u\n", ack);
215 // printk(KERN_DEBUG "cubictcp_cong_avoid tp->snd_nxt %u\n", tp->snd_nxt);
216
217 // }
218
219
205 mytcp->inflight_2pre = mytcp->inflight_1pre; 220 mytcp->inflight_2pre = mytcp->inflight_1pre;
206 mytcp->inflight_1pre = mytcp->inflight_now; 221 mytcp->inflight_1pre = mytcp->inflight_now;
207 222
@@ -230,12 +245,25 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
230// mytcp->min_queue = mytcp_min_tx_queue; 245// mytcp->min_queue = mytcp_min_tx_queue;
231 246
232 mytcp->min_queue_within_t = tp->mytcp_est_rq; 247 mytcp->min_queue_within_t = tp->mytcp_est_rq;
248
249
250 if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){
251 // printk(KERN_DEBUG "min_queue_within_t is %u\n", mytcp->min_queue_within_t);
252 // printk(KERN_DEBUG "the mytcp RTT is %u\n",sample->rtt_us);
253 printk(KERN_DEBUG "in mytcp the cwnd is %u\n", tp->snd_cwnd);
254
255 }
256
233 mytcp->min_queue = tp->mytcp_est_rq; 257 mytcp->min_queue = tp->mytcp_est_rq;
234 258
235 if ((mytcp->min_queue_within_t > 0) && (mytcp->max_queue_within_t > mytcp->min_queue_within_t)){ 259 if ((mytcp->min_queue_within_t > 0) && (mytcp->max_queue_within_t > mytcp->min_queue_within_t)){
236 mytcp->one_full_ronund_send = mytcp->max_queue_within_t - mytcp->min_queue_within_t; 260 mytcp->one_full_ronund_send = mytcp->max_queue_within_t - mytcp->min_queue_within_t;
237 mytcp->threshold = (mytcp->one_full_ronund_send * 5) / 100; 261 mytcp->threshold = (mytcp->one_full_ronund_send * 5) / 100;
238 mytcp->threshold = max(mytcp->threshold,RQ_allow); 262 // mytcp->threshold = max(mytcp->threshold,RQ_allow);
263 if(RQ_allow > mytcp->threshold){
264 mytcp->threshold = RQ_allow;
265 }
266// mytcp->threshold = max(mytcp->threshold,1);
239 } 267 }
240 else{ 268 else{
241 mytcp->threshold = RQ_allow; 269 mytcp->threshold = RQ_allow;
@@ -253,24 +281,32 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
253 } 281 }
254 282
255 283
256 if (tcp_in_slow_start(tp)) { 284 if (tcp_in_slow_start(tp) && tp->exit_slow_start_flag != 1) {
257 tcp_slow_start(tp, acked); 285 tcp_slow_start(tp, acked);
258 mytcp->cwnd_hold = tp->snd_cwnd; 286 mytcp->cwnd_hold = tp->snd_cwnd;
259 } 287 }
260 288
289 if((tp->mytcp_average_rtt != 0) &&((tp->mytcp_average_rtt - mytcp->min_rtt) > 20000)){
290 tp->exit_slow_start_flag = 1;
291 }
292
293
294
261//当没有显式拥塞的信息返回时,按照正常的QCC逻辑利用驱动残余队列调整cwnd 295//当没有显式拥塞的信息返回时,按照正常的QCC逻辑利用驱动残余队列调整cwnd
262 if (!tp->mytcp_ece_flag){ 296 if (!tp->mytcp_ece_flag){
263 297
264 //与BBR类似,当连续三轮网卡发送检测出超过阈值的堆积时,才判定占满带宽,退出慢启动。 298 //与BBR类似,当连续三轮网卡发送检测出超过阈值的堆积时,才判定占满带宽,退出慢启动。
265 if(/*mytcp_round_count*/ tp->mytcp_round_flag >= 1 && tcp_in_slow_start(tp)){ 299 if(/*mytcp_round_count*/ tp->mytcp_round_flag >= 1 && tcp_in_slow_start(tp) && tp->exit_slow_start_flag != 1){
266 //mytcp_round_count = 0; 300 //mytcp_round_count = 0;
267 tp->mytcp_round_flag = 0; 301 tp->mytcp_round_flag = 0;
268 if (tcp_in_slow_start(tp)) { 302 if (tcp_in_slow_start(tp)) {
303 printk(KERN_DEBUG "qcc in slow start and slow start\n");
269 int flag_count = 0; 304 int flag_count = 0;
270 mytcp->full_flag_3 = mytcp->full_flag_2; 305 mytcp->full_flag_3 = mytcp->full_flag_2;
271 mytcp->full_flag_2 = mytcp->full_flag_1; 306 mytcp->full_flag_2 = mytcp->full_flag_1;
272 mytcp->min_queue_within_t = tp->mytcp_est_rq; 307 mytcp->min_queue_within_t = tp->mytcp_est_rq;
273 mytcp->full_flag_1 = mytcp->min_queue_within_t; 308 mytcp->full_flag_1 = mytcp->min_queue_within_t;
309
274 if(mytcp->full_flag_1 > mytcp->threshold){ 310 if(mytcp->full_flag_1 > mytcp->threshold){
275 flag_count ++; 311 flag_count ++;
276 tp->mytcp_full_pipe_flag = 1; 312 tp->mytcp_full_pipe_flag = 1;
@@ -287,19 +323,38 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
287// printk(KERN_DEBUG "in slow start, the flag1 is %d, the flag2 is %d, the flag3 is %d\n", mytcp->full_flag_1, mytcp->full_flag_2, mytcp->full_flag_3); 323// printk(KERN_DEBUG "in slow start, the flag1 is %d, the flag2 is %d, the flag3 is %d\n", mytcp->full_flag_1, mytcp->full_flag_2, mytcp->full_flag_3);
288 //判定占满的条件是残余队列连续三轮大于阈值,或者一旦超过50(表明此时堆积很大) 324 //判定占满的条件是残余队列连续三轮大于阈值,或者一旦超过50(表明此时堆积很大)
289 //50这个参数取的经验值,调试分析发现这一个值可以有一定变化影响也不大,因为于拥塞避免阶段也具有调整能力 325 //50这个参数取的经验值,调试分析发现这一个值可以有一定变化影响也不大,因为于拥塞避免阶段也具有调整能力
290 if ((flag_count >= 3 && /*mytcp_round_max*/tp->mytcp_est_max_queue_real > 50) || (mytcp->full_flag_1 > 80) || (mytcp->loss_cnt > 3)) 326 if ( ((tp->mytcp_average_rtt != 0) &&((tp->mytcp_average_rtt - mytcp->min_rtt) > 20000))|| (flag_count >= 3 && /*mytcp_round_max*/tp->mytcp_est_max_queue_real > 50) || (mytcp->full_flag_1 > 80) || (mytcp->loss_cnt > 3))
291 { 327 {
328
329 if((tp->mytcp_average_rtt - mytcp->min_rtt) > 20000){
330 printk(KERN_DEBUG " mytcp->min_rtt is %u\n",mytcp->min_rtt);
331 printk(KERN_DEBUG " tp->mytcp_average_rtt is %u\n",tp->mytcp_average_rtt);
332 printk(KERN_DEBUG "exit slow start because rtt is too big\n");
333 }
334
292 // mytcp->time_last = ktime_get_real_ns(); 335 // mytcp->time_last = ktime_get_real_ns();
293 // mytcp->cwnd_first = tp->snd_cwnd - mytcp->full_flag_1; 336 // mytcp->cwnd_first = tp->snd_cwnd - mytcp->full_flag_1;
294 mytcp->cwnd_first = tp->snd_cwnd; 337 mytcp->cwnd_first = tp->snd_cwnd;
338
339 if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){
340 printk(KERN_DEBUG "exit slow start flag_count >=3 cwnd_first is %u\n", mytcp->cwnd_first);
341 }
295 // tp->snd_cwnd = mytcp->cwnd_first; 342 // tp->snd_cwnd = mytcp->cwnd_first;
296 // tp->snd_ssthresh = tcp_mytcp_ssthresh(tp)/2; 343 // tp->snd_ssthresh = tcp_mytcp_ssthresh(tp)/2;
344 if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){
345 printk(KERN_DEBUG "in slow start, full, before ssthresh change the snd_cwnd is %d, the ssh is %d\n", mytcp->cwnd_first, tp->snd_ssthresh);
346 }
297 tp->snd_ssthresh = mytcp->cwnd_first/2; 347 tp->snd_ssthresh = mytcp->cwnd_first/2;
298 mytcp->time_last = ktime_get_real_ns(); 348 mytcp->time_last = ktime_get_real_ns();
299 mytcp->beg_snd_nxt = tp->snd_nxt; 349 mytcp->beg_snd_nxt = tp->snd_nxt;
300 tp->mytcp_bytes_send = 0; 350 tp->mytcp_bytes_send = 0;
301 tp->mytcp_acked_seq_last = ack; 351 tp->mytcp_acked_seq_last = ack;
302 printk(KERN_DEBUG "in slow start, full, the snd_cwnd is %d, the ssh is %d\n", mytcp->cwnd_first, tp->snd_ssthresh); 352 tp->exit_slow_start_flag = 1;
353 if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){
354 printk(KERN_DEBUG "dport is %u and sport is %u\n", ntohs(inet2->inet_dport), ntohs(inet2->inet_dport));
355 printk(KERN_DEBUG "exit slow start\n");
356 printk(KERN_DEBUG "in slow start, full, after ssthresh change the snd_cwnd is %d, the ssh is %d\n", mytcp->cwnd_first, tp->snd_ssthresh);
357 }
303 } 358 }
304// printk(KERN_DEBUG "in slow start, the source port is %d, the snd_cwnd is %d, \n", tp->myfast_source, tp->snd_cwnd); 359// printk(KERN_DEBUG "in slow start, the source port is %d, the snd_cwnd is %d, \n", tp->myfast_source, tp->snd_cwnd);
305 } 360 }
@@ -327,7 +382,11 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
327 tp->mytcp_round_flag = 0; 382 tp->mytcp_round_flag = 0;
328 // mytcp->cwnd_last = tp->snd_cwnd; 383 // mytcp->cwnd_last = tp->snd_cwnd;
329 if (mytcp->cong_flag == 3){ 384 if (mytcp->cong_flag == 3){
330 tp->snd_cwnd = mytcp->cwnd_first; 385 printk(KERN_DEBUG "mytcp->cong_flag ==3\n");
386 if (tp->exit_slow_start_flag==1 && mytcp->cwnd_first > 0){
387 tp->snd_cwnd = mytcp->cwnd_first;
388 }
389
331 if(mytcp->max_queue_within_t > /*mytcp_round_max*/tp->mytcp_est_max_queue_real){ 390 if(mytcp->max_queue_within_t > /*mytcp_round_max*/tp->mytcp_est_max_queue_real){
332 mytcp->max_queue_first = mytcp->max_queue_within_t; 391 mytcp->max_queue_first = mytcp->max_queue_within_t;
333 } 392 }
@@ -342,16 +401,41 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
342 } 401 }
343 402
344 else if (mytcp->cong_flag < 3){ 403 else if (mytcp->cong_flag < 3){
345 tp->snd_cwnd = mytcp->cwnd_first; 404 printk(KERN_DEBUG "mytcp->cong_flag = %u the cwnd will be cwnd_first and cwnd is %u\n",mytcp->cong_flag,tp->snd_cwnd);
405 printk(KERN_DEBUG "the cwnd_first is %d\n",mytcp->cwnd_first);
406 printk(KERN_DEBUG "the ssthresh is %u\n",tp->snd_ssthresh);
407 if (tp->exit_slow_start_flag==1 && mytcp->cwnd_first > 0){
408 tp->snd_cwnd = mytcp->cwnd_first;
409 }
346 mytcp->cong_flag ++; 410 mytcp->cong_flag ++;
347// printk(KERN_DEBUG "mytcp->cong_flag < 3, snd_cwnd is %u\n", tp->snd_cwnd); 411 printk(KERN_DEBUG "mytcp->cong_flag < 3, the cwnd is %u\n", tp->snd_cwnd);
348 } 412 }
349 413
350 else{ 414 else{
415
416 //////////////
417
418 // if (mytcp->throughput_now > 0 && (tp->mytcp_average_rtt - mytcp->min_rtt) > 20000){
419
420 // printk(KERN_DEBUG "the cwnd_last will change now it is %u\n",mytcp->cwnd_last);
421 // u32 more_rtt = tp->mytcp_average_rtt - mytcp->min_rtt - 20000;
422
423 // u32 more_cwnd_in_air = (((mytcp->throughput_now * 2)/1) * more_rtt)/(tp->mss_cache*8);
424 // printk(KERN_DEBUG "the more_cwnd_in_air is %u\n",more_cwnd_in_air);
425 // if(mytcp->cwnd_last > more_cwnd_in_air/2)
426 // {
427 // mytcp->cwnd_last = max(mytcp->cwnd_last - more_cwnd_in_air/2,mytcp->cwnd_last/2);
428 // }
429 // printk(KERN_DEBUG "the cwnd_last has change it is %u\n",mytcp->cwnd_last);
430
431 // }
432
351 mytcp->queue_last = mytcp->queue_now; 433 mytcp->queue_last = mytcp->queue_now;
352 if(mytcp->min_last == 0 && mytcp->min_queue_within_t == 0){ //连续n轮最小队列长度为0,则cwnd增长步长变为n*10 434 if(mytcp->min_last == 0 && mytcp->min_queue_within_t == 0){ //连续n轮最小队列长度为0,则cwnd增长步长变为n*10
353 // mytcp->cwnd_last = mytcp->cwnd_last + mytcp->threshold; 435 // mytcp->cwnd_last = mytcp->cwnd_last + mytcp->threshold;
354 mytcp->cwnd_last = mytcp->cwnd_last + RQ_allow; 436 // mytcp->cwnd_last = mytcp->cwnd_last + RQ_allow;
437 mytcp->cwnd_last = mytcp->cwnd_last;
438
355 } 439 }
356 440
357 else { 441 else {
@@ -361,20 +445,78 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
361 mytcp->min_last = mytcp->min_queue_within_t; 445 mytcp->min_last = mytcp->min_queue_within_t;
362 446
363 if(mytcp->min_queue_within_t > 0 && mytcp->min_queue_within_t < mytcp->threshold){ 447 if(mytcp->min_queue_within_t > 0 && mytcp->min_queue_within_t < mytcp->threshold){
448 if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){
449 printk(KERN_DEBUG "RQ is suitable cwnd will not change, snd_cwnd is %u\n", tp->snd_cwnd);
450 }
364 tp->snd_cwnd = tp->snd_cwnd; 451 tp->snd_cwnd = tp->snd_cwnd;
365 mytcp->cwnd_first = tp->snd_cwnd; 452 mytcp->cwnd_first = tp->snd_cwnd;
366 mytcp->max_queue_first = mytcp->max_queue_now; 453 mytcp->max_queue_first = mytcp->max_queue_now;
454 if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){
455 printk(KERN_DEBUG "RQ is suitable cwnd not change, snd_cwnd is %u\n", tp->snd_cwnd);
456 printk(KERN_DEBUG "cwnd_first is %u\n", mytcp->cwnd_first);
457 }
367// printk(KERN_DEBUG "suitable, snd_cwnd is %u\n", tp->snd_cwnd); 458// printk(KERN_DEBUG "suitable, snd_cwnd is %u\n", tp->snd_cwnd);
368 // printk(KERN_DEBUG "111111111111111111111111111, into the update, snd_cwnd is %u\n", tp->snd_cwnd); 459 // printk(KERN_DEBUG "111111111111111111111111111, into the update, snd_cwnd is %u\n", tp->snd_cwnd);
369 } 460 }
370// else if(/*mytcp->max_queue_now > 10 && */mytcp->queue_now > 5){ //确保队列中至少有5个包的进出 461// else if(/*mytcp->max_queue_now > 10 && */mytcp->queue_now > 5){ //确保队列中至少有5个包的进出
371 else{ 462 else{
372 if(mytcp->min_queue_within_t > mytcp->threshold){ 463 if(mytcp->min_queue_within_t > mytcp->threshold){
373 tp->snd_cwnd = mytcp->cwnd_last - (mytcp->min_queue_within_t - mytcp->threshold); 464
465 if (mytcp->throughput_now > 0 && (tp->mytcp_average_rtt - mytcp->min_rtt) > 20000){
466 printk(KERN_DEBUG "the cwnd_last will change now it is %u\n",mytcp->cwnd_last);
467 u32 more_rtt = tp->mytcp_average_rtt - mytcp->min_rtt - 20000;
468 u32 more_cwnd_in_air = (((mytcp->throughput_now * 2)/1) * more_rtt)/(tp->mss_cache*8);
469 printk(KERN_DEBUG "the more_cwnd_in_air is %u\n",more_cwnd_in_air);
470 if(mytcp->cwnd_last > more_cwnd_in_air/2)
471 {
472 mytcp->cwnd_last = max(mytcp->cwnd_last - more_cwnd_in_air/2,mytcp->cwnd_last/2);
473 }
474 printk(KERN_DEBUG "the cwnd_last has change it is %u\n",mytcp->cwnd_last);
475 }
476
477 if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){
478 printk(KERN_DEBUG "long,the cwnd will down now the snd_cwnd is %u\n", tp->snd_cwnd);
479 printk(KERN_DEBUG "RQ is %u\n", mytcp->min_queue_within_t);
480 printk(KERN_DEBUG "mytcp->threshold is %u\n", mytcp->threshold);
481 // printk(KERN_DEBUG "cwnd will be mytcp->cwnd_last - (mytcp->min_queue_within_t - mytcp->threshold); is %u\n", mytcp->threshold);
482 }
483 // u32 more_cwnd = ((mytcp->min_queue_within_t - mytcp->threshold)*(mytcp->min_queue_within_t - mytcp->threshold/2))/mytcp->threshold;//此时残余队列长度减阈值
484 u32 more_cwnd = mytcp->min_queue_within_t - mytcp->threshold;
485 printk(KERN_DEBUG "the more_cwnd is %u\n", more_cwnd);
486
487 if(more_cwnd < mytcp->cwnd_last){
488 // tp->snd_cwnd = mytcp->cwnd_last - (mytcp->min_queue_within_t - mytcp->threshold);
489
490 tp->snd_cwnd = mytcp->cwnd_last - more_cwnd;
491 if(tp->snd_cwnd < 10){
492 // printk(KERN_DEBUG "now cwnd < 10 so make it 10 \n");
493 tp->snd_cwnd = 10;
494 }
495 // printk(KERN_DEBUG "too_long, snd_cwnd is %u\n", tp->snd_cwnd);
496 }else{
497 tp->snd_cwnd -= 10;
498 // printk(KERN_DEBUG "too_long, mytcp->cwnd_last is %u\n", mytcp->cwnd_last);
499 // printk(KERN_DEBUG "too_long, mytcp->min_queue_within_t is %u\n", mytcp->min_queue_within_t);
500 // printk(KERN_DEBUG "too_long, mytcp->threshold is %u\n", mytcp->threshold);
501 // printk(KERN_DEBUG "too_long, mytcp->min_queue_within_t - mytcp->threshold is %u\n", mytcp->min_queue_within_t - mytcp->threshold);
502 // printk(KERN_DEBUG "too_long, snd_cwnd is %u\n", tp->snd_cwnd);
503 // printk(KERN_DEBUG "now cwnd < 0 so make it 10\n");
504 }
505
506 if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){
507 printk(KERN_DEBUG "long,the cwnd has down now the snd_cwnd is %u\n", tp->snd_cwnd);
508 }
509 // tp->snd_cwnd = mytcp->cwnd_last - (mytcp->min_queue_within_t - mytcp->threshold);
374// printk(KERN_DEBUG "too_long, snd_cwnd is %u\n", tp->snd_cwnd); 510// printk(KERN_DEBUG "too_long, snd_cwnd is %u\n", tp->snd_cwnd);
375 } 511 }
376 if(mytcp->min_queue_within_t == 0){ 512 if(mytcp->min_queue_within_t == 0){
513 if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){
514 printk(KERN_DEBUG "RQ is 0 cwnd will change + 步长, snd_cwnd is %u\n", tp->snd_cwnd);
515 }
377 tp->snd_cwnd = mytcp->cwnd_last + mytcp->threshold; 516 tp->snd_cwnd = mytcp->cwnd_last + mytcp->threshold;
517 if(ntohs(inet2->inet_dport) == 5201 || ntohs(inet2->inet_sport) == 5201){
518 printk(KERN_DEBUG "RQ is 0 cwnd has change, snd_cwnd is %u\n", tp->snd_cwnd);
519 }
378// printk(KERN_DEBUG "empty, snd_cwnd is %u\n", tp->snd_cwnd); 520// printk(KERN_DEBUG "empty, snd_cwnd is %u\n", tp->snd_cwnd);
379 } 521 }
380 } 522 }
@@ -389,8 +531,8 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
389 531
390 } 532 }
391 533
392 printk(KERN_DEBUG "111111111111111111111111111, into the cong_avoid, tp->snd_cwnd is %u\n", tp->snd_cwnd); 534 // printk(KERN_DEBUG "111111111111111111111111111, into the cong_avoid, tp->snd_cwnd is %u\n", tp->snd_cwnd);
393 printk(KERN_DEBUG "111111111111111111111111111, into the cong_avoid, min_queue_within_t is %d\n", mytcp->min_queue_within_t); 535 // printk(KERN_DEBUG "111111111111111111111111111, into the cong_avoid, min_queue_within_t is %d\n", mytcp->min_queue_within_t);
394 // printk(KERN_DEBUG "111111111111111111111111111, into the cong_avoid, queue last is %d\n", mytcp->queue_last); 536 // printk(KERN_DEBUG "111111111111111111111111111, into the cong_avoid, queue last is %d\n", mytcp->queue_last);
395 // printk(KERN_DEBUG "111111111111111111111111111, into the cong_avoid, queue now is %d\n", mytcp->queue_now); 537 // printk(KERN_DEBUG "111111111111111111111111111, into the cong_avoid, queue now is %d\n", mytcp->queue_now);
396 538
@@ -401,8 +543,10 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
401 tp->mytcp_est_max_queue_real = 0; 543 tp->mytcp_est_max_queue_real = 0;
402// mytcp->min_queue_within_t = 1000; 544// mytcp->min_queue_within_t = 1000;
403// mytcp_actual_min_queue = 1000; 545// mytcp_actual_min_queue = 1000;
404 if (tp->snd_cwnd < 10) 546 if (tp->snd_cwnd < 10){
405 tp->snd_cwnd = 10; 547 tp->snd_cwnd = 10;
548 printk(KERN_DEBUG "snd_cwnd < 10 so make cwnd is 10\n");
549 }
406 // if (tp->snd_cwnd > 30) 550 // if (tp->snd_cwnd > 30)
407 // tp->snd_cwnd = 30; 551 // tp->snd_cwnd = 30;
408 else if (tp->snd_cwnd > tp->snd_cwnd_clamp) 552 else if (tp->snd_cwnd > tp->snd_cwnd_clamp)
@@ -419,73 +563,158 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
419 } 563 }
420 } 564 }
421 565
566// // 每一个rtt统计一次有线瓶颈的场景
567// if (after(ack, mytcp->beg_snd_nxt) && !tcp_in_slow_start(tp)){ //瓶颈为有线部分时的处理
568
569// int packets_in_air;
570// int RQ_wire;
571// int RQ_wire2;
572// int extra_cwnd;
573// int throughput2;
574
575// mytcp->beg_snd_nxt = tp->snd_nxt;
576// mytcp->time_now = ktime_get_real_ns();
577
578// //从确认占满链路后100ms再开始计算吞吐量,避免慢启动发送窗口耗尽对带宽估算的影响。
579// // if ((mytcp->time_now - mytcp->time_last)>(100*1000)){
580
581// tp->mytcp_acked_bytes = ack - tp->mytcp_acked_seq_last;
582// mytcp->throughput_now = (tp->mytcp_bytes_send * 8) / ((mytcp->time_now - mytcp->time_last)/1000);
583// throughput2 = (tp->mytcp_acked_bytes * 8) / ((mytcp->time_now - mytcp->time_last)/1000);
584
585// if (mytcp->throughput_now > 0){
586// packets_in_air = (((mytcp->throughput_now * 2)/1) * mytcp->min_rtt)/(tp->mss_cache*8);
587// RQ_wire = tp->packets_out - mytcp->min_queue - packets_in_air;
588// }
589
590// else {
591// RQ_wire = 0;
592// }
593
594// if(RQ_wire < 0){
595// RQ_wire = 0;
596// }
597
598// if(RQ_wire > mytcp->threshold){
599// extra_cwnd = RQ_wire - mytcp->threshold;
600// // tp->snd_cwnd = mytcp->cwnd_last - (RQ_wire - mytcp->threshold);
601// }
602
603// else{
604// extra_cwnd = 0;
605// // tp->snd_cwnd = tp->snd_cwnd;
606// }
607
608// // tp->snd_cwnd = mytcp->cwnd_last - max(tp->mytcp_ece_count, extra_cwnd);
609// tp->snd_cwnd = mytcp->cwnd_last -extra_cwnd;
610
611// if (tp->snd_cwnd > (2*packets_in_air)){
612// tp->snd_cwnd = (2*packets_in_air);
613// }
614
615// // printk(KERN_DEBUG "the bytes ackes is %llu, time interval is %llu\n", tp->bytes_acked, mytcp->time_now - mytcp->time_last);
616// printk(KERN_DEBUG "the throughput is %u, throughput2 is %u, RQ_wire is %u\n", mytcp->throughput_now, throughput2, RQ_wire);
617// printk(KERN_DEBUG "wired bottle, the packets out is %u, min queue is %u, packets in air is %d, the RQ wire is %d\n",
618// tp->packets_out, mytcp->min_queue, packets_in_air, RQ_wire);
619// // printk(KERN_DEBUG "wired bottle, the mytcp_ece_count is %u, extra_cwnd is %u\n",tp->mytcp_ece_count, extra_cwnd);
620// printk(KERN_DEBUG ",wired bottle, into the cong_avoid, the cwnd is %u\n", tp->snd_cwnd);
621// // }
622// //将ece计数器置0,重新开始统计下一轮rtt内的ece数量
623// tp->mytcp_ece_count = 0;
624// tp->mytcp_bytes_send = 0;
625// tp->mytcp_acked_seq_last = ack;
626// mytcp->time_last = mytcp->time_now;
627// mytcp->cwnd_hold = tp->snd_cwnd;
628// }
629
630// else{
631// tp->snd_cwnd = mytcp->cwnd_hold;
632// // printk(KERN_DEBUG "111111111111111111111111111, else, the cwnd is %u\n", tp->snd_cwnd);
633// }
422// 每一个rtt统计一次有线瓶颈的场景 634// 每一个rtt统计一次有线瓶颈的场景
423 if (after(ack, mytcp->beg_snd_nxt) && !tcp_in_slow_start(tp)){ //瓶颈为有线部分时的处理 635 if (after(ack, mytcp->beg_snd_nxt)){ //瓶颈为有线部分时的处理
424 636 printk(KERN_DEBUG "此时经历了一轮RTT\n");
425 int packets_in_air;
426 int RQ_wire;
427 int RQ_wire2;
428 int extra_cwnd;
429 int throughput2;
430
431 mytcp->beg_snd_nxt = tp->snd_nxt; 637 mytcp->beg_snd_nxt = tp->snd_nxt;
432 mytcp->time_now = ktime_get_real_ns(); 638 tp->mytcp_this_rtt_count = 0;
639 if(!tcp_in_slow_start(tp)){
640 int packets_in_air;
641 int RQ_wire;
642 int RQ_wire2;
643 int extra_cwnd;
644 int throughput2;
433 645
434 //从确认占满链路后100ms再开始计算吞吐量,避免慢启动发送窗口耗尽对带宽估算的影响。 646
435// if ((mytcp->time_now - mytcp->time_last)>(100*1000)){ 647 mytcp->time_now = ktime_get_real_ns();
436 648
437 tp->mytcp_acked_bytes = ack - tp->mytcp_acked_seq_last; 649 //从确认占满链路后100ms再开始计算吞吐量,避免慢启动发送窗口耗尽对带宽估算的影响。
438 mytcp->throughput_now = (tp->mytcp_bytes_send * 8) / ((mytcp->time_now - mytcp->time_last)/1000); 650 // if ((mytcp->time_now - mytcp->time_last)>(100*1000)){
439 throughput2 = (tp->mytcp_acked_bytes * 8) / ((mytcp->time_now - mytcp->time_last)/1000);
440 651
441 if (mytcp->throughput_now > 0){ 652 tp->mytcp_acked_bytes = ack - tp->mytcp_acked_seq_last;
442 packets_in_air = (((mytcp->throughput_now * 2)/1) * mytcp->min_rtt)/(tp->mss_cache*8); 653 mytcp->throughput_now = (tp->mytcp_bytes_send * 8) / ((mytcp->time_now - mytcp->time_last)/1000);
443 RQ_wire = tp->packets_out - mytcp->min_queue - packets_in_air; 654 throughput2 = (tp->mytcp_acked_bytes * 8) / ((mytcp->time_now - mytcp->time_last)/1000);
444 }
445 655
446 else { 656 if (mytcp->throughput_now > 0){
447 RQ_wire = 0; 657 packets_in_air = (((mytcp->throughput_now * 2)/1) * mytcp->min_rtt)/(tp->mss_cache*8);
448 } 658 printk(KERN_DEBUG "the mytcp->throughput_now is > 0\n");
659 RQ_wire = tp->packets_out - mytcp->min_queue - packets_in_air;
660 }
449 661
450 if(RQ_wire < 0){ 662 else {
451 RQ_wire = 0; 663 RQ_wire = 0;
452 } 664 }
453 665
454 if(RQ_wire > mytcp->threshold){ 666 if(RQ_wire < 0){
455 extra_cwnd = RQ_wire - mytcp->threshold; 667 RQ_wire = 0;
456// tp->snd_cwnd = mytcp->cwnd_last - (RQ_wire - mytcp->threshold); 668 }
457 }
458 669
459 else{ 670 if(RQ_wire > mytcp->threshold){
460 extra_cwnd = 0; 671 extra_cwnd = RQ_wire - mytcp->threshold;
461// tp->snd_cwnd = tp->snd_cwnd; 672 // tp->snd_cwnd = mytcp->cwnd_last - (RQ_wire - mytcp->threshold);
462 } 673 }
463 674
464 tp->snd_cwnd = mytcp->cwnd_last - max(tp->mytcp_ece_count, extra_cwnd); 675 else{
676 extra_cwnd = 0;
677 // tp->snd_cwnd = tp->snd_cwnd;
678 }
465 679
466 if (tp->snd_cwnd > (2*packets_in_air)){ 680 // tp->snd_cwnd = mytcp->cwnd_last - max(tp->mytcp_ece_count, extra_cwnd);
467 tp->snd_cwnd = (2*packets_in_air); 681 tp->snd_cwnd = mytcp->cwnd_last -extra_cwnd;
468 }
469 682
470// printk(KERN_DEBUG "the bytes ackes is %llu, time interval is %llu\n", tp->bytes_acked, mytcp->time_now - mytcp->time_last); 683 tp->snd_cwnd = max(mytcp->cwnd_last - extra_cwnd,tp->snd_cwnd/2);//吕超加的,为了控制保证吞吐量不会过低
471 printk(KERN_DEBUG "the throughput is %u, throughput2 is %u, RQ_wire is %u\n", mytcp->throughput_now, throughput2, RQ_wire);
472 printk(KERN_DEBUG "wired bottle, the packets out is %u, min queue is %u, packets in air is %d, the RQ wire is %d\n",
473 tp->packets_out, mytcp->min_queue, packets_in_air, RQ_wire);
474// printk(KERN_DEBUG "wired bottle, the mytcp_ece_count is %u, extra_cwnd is %u\n",tp->mytcp_ece_count, extra_cwnd);
475 printk(KERN_DEBUG "111111111111111111111111111, wired bottle, into the cong_avoid, the cwnd is %u\n", tp->snd_cwnd);
476// }
477 //将ece计数器置0,重新开始统计下一轮rtt内的ece数量
478 tp->mytcp_ece_count = 0;
479 tp->mytcp_bytes_send = 0;
480 tp->mytcp_acked_bytes = ack;
481 mytcp->time_last = mytcp->time_now;
482 mytcp->cwnd_hold = tp->snd_cwnd;
483 }
484 684
485 else{ 685 if (tp->snd_cwnd > (2*packets_in_air)){
686 tp->snd_cwnd = (2*packets_in_air);
687 }
688 if(tp->snd_cwnd < 10){
689 tp->snd_cwnd = 10;
690 }
691
692 // printk(KERN_DEBUG "the bytes ackes is %llu, time interval is %llu\n", tp->bytes_acked, mytcp->time_now - mytcp->time_last);
693 printk(KERN_DEBUG "the throughput is %u, throughput2 is %u, RQ_wire is %u\n", mytcp->throughput_now, throughput2, RQ_wire);
694 printk(KERN_DEBUG "wired bottle, the packets out is %u, min queue is %u, packets in air is %d, the RQ wire is %d\n",
695 tp->packets_out, mytcp->min_queue, packets_in_air, RQ_wire);
696 // printk(KERN_DEBUG "wired bottle, the mytcp_ece_count is %u, extra_cwnd is %u\n",tp->mytcp_ece_count, extra_cwnd);
697 printk(KERN_DEBUG ",wired bottle, into the cong_avoid, the cwnd is %u\n", tp->snd_cwnd);
698 // }
699 //将ece计数器置0,重新开始统计下一轮rtt内的ece数量
700 tp->mytcp_ece_count = 0;
701 tp->mytcp_bytes_send = 0;
702 tp->mytcp_acked_seq_last = ack;
703 mytcp->time_last = mytcp->time_now;
704 mytcp->cwnd_hold = tp->snd_cwnd;
705 }
706 else{
486 tp->snd_cwnd = mytcp->cwnd_hold; 707 tp->snd_cwnd = mytcp->cwnd_hold;
487// printk(KERN_DEBUG "111111111111111111111111111, else, the cwnd is %u\n", tp->snd_cwnd);
488 } 708 }
709 }
710 else{//本轮rtt没有结束
711 tp->mytcp_average_rtt = ((tp->mytcp_average_rtt)*(tp->mytcp_this_rtt_count)+tp->my_ip_rtt)/(tp->mytcp_this_rtt_count+1);
712 printk(KERN_DEBUG "now average RTT is %u\n",tp->mytcp_average_rtt);
713 tp->mytcp_this_rtt_count += 1;
714
715 tp->snd_cwnd = mytcp->cwnd_hold;
716// printk(KERN_DEBUG "111111111111111111111111111, else, the cwnd is %u\n", tp->snd_cwnd);
717 }
489 718
490 719
491 720
@@ -496,6 +725,8 @@ static void tcp_mytcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
496 725
497 726
498 727
728
729
499/* Extract info for Tcp socket info provided via netlink. */ 730/* Extract info for Tcp socket info provided via netlink. */
500size_t tcp_mytcp_get_info(struct sock *sk, u32 ext, int *attr, 731size_t tcp_mytcp_get_info(struct sock *sk, u32 ext, int *attr,
501 union tcp_cc_info *info) 732 union tcp_cc_info *info)
@@ -550,4 +781,3 @@ MODULE_DESCRIPTION("TCP mytcp");
550 781
551 782
552 783
553
diff --git a/net/ipv4/tcp_mytcp.h b/net/ipv4/tcp_mytcp.h
index ff70d94a6..ff70d94a6 100644..100755
--- a/net/ipv4/tcp_mytcp.h
+++ b/net/ipv4/tcp_mytcp.h