A Discrete-Event Network Simulator
API
tcp-highspeed.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 Natale Patriciello, <natale.patriciello@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  */
19 
20 #include "tcp-highspeed.h"
21 #include "tcp-socket-state.h"
22 
23 #include "ns3/log.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("TcpHighSpeed");
28 NS_OBJECT_ENSURE_REGISTERED (TcpHighSpeed);
29 
30 TypeId
32 {
33  static TypeId tid = TypeId ("ns3::TcpHighSpeed")
35  .AddConstructor<TcpHighSpeed> ()
36  .SetGroupName ("Internet")
37  ;
38  return tid;
39 }
40 
42  : TcpNewReno (),
43  m_ackCnt (0)
44 {
45  NS_LOG_FUNCTION (this);
46 }
47 
49  : TcpNewReno (sock),
50  m_ackCnt (sock.m_ackCnt)
51 {
52  NS_LOG_FUNCTION (this);
53 }
54 
56 {
57  NS_LOG_FUNCTION (this);
58 }
59 
62 {
63  return CopyObject<TcpHighSpeed> (this);
64 }
65 
98 void
100 {
101  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
102 
103  uint32_t segCwnd = tcb->GetCwndInSegments ();
104  uint32_t oldCwnd = segCwnd;
105 
106  if (segmentsAcked > 0)
107  {
108  uint32_t coeffA = TableLookupA (segCwnd);
109  m_ackCnt += segmentsAcked * coeffA;
110  }
111 
112  while (m_ackCnt >= segCwnd)
113  {
114  m_ackCnt -= segCwnd;
115  segCwnd += 1;
116  }
117 
118  if (segCwnd != oldCwnd)
119  {
120  tcb->m_cWnd = segCwnd * tcb->m_segmentSize;
121  NS_LOG_INFO ("In CongAvoid, updated to cwnd " << tcb->m_cWnd <<
122  " ssthresh " << tcb->m_ssThresh);
123  }
124 }
125 
126 std::string
128 {
129  return "TcpHighSpeed";
130 }
131 
140 uint32_t
142  uint32_t bytesInFlight)
143 {
144  NS_LOG_FUNCTION (this << tcb << bytesInFlight);
145 
146  uint32_t segCwnd = bytesInFlight / tcb->m_segmentSize;
147 
148  double b = 1.0 - TableLookupB (segCwnd);
149  uint32_t ssThresh = static_cast<uint32_t> (std::max (2.0, segCwnd * b));
150 
151  NS_LOG_DEBUG ("Calculated b(w) = " << b <<
152  " resulting (in segment) ssThresh=" << ssThresh);
153 
154  return ssThresh * tcb->m_segmentSize;
155 }
156 
157 uint32_t
159 {
160  if (w <= 38)
161  {
162  return 1;
163  }
164  else if (w <= 118)
165  {
166  return 2;
167  }
168  else if (w <= 221)
169  {
170  return 3;
171  }
172  else if (w <= 347)
173  {
174  return 4;
175  }
176  else if (w <= 495)
177  {
178  return 5;
179  }
180  else if (w <= 663)
181  {
182  return 6;
183  }
184  else if (w <= 851)
185  {
186  return 7;
187  }
188  else if (w <= 1058)
189  {
190  return 8;
191  }
192  else if (w <= 1284)
193  {
194  return 9;
195  }
196  else if (w <= 1529)
197  {
198  return 10;
199  }
200  else if (w <= 1793)
201  {
202  return 11;
203  }
204  else if (w <= 2076)
205  {
206  return 12;
207  }
208  else if (w <= 2378)
209  {
210  return 13;
211  }
212  else if (w <= 2699)
213  {
214  return 14;
215  }
216  else if (w <= 3039)
217  {
218  return 15;
219  }
220  else if (w <= 3399)
221  {
222  return 16;
223  }
224  else if (w <= 3778)
225  {
226  return 17;
227  }
228  else if (w <= 4177)
229  {
230  return 18;
231  }
232  else if (w <= 4596)
233  {
234  return 19;
235  }
236  else if (w <= 5036)
237  {
238  return 20;
239  }
240  else if (w <= 5497)
241  {
242  return 21;
243  }
244  else if (w <= 5979)
245  {
246  return 22;
247  }
248  else if (w <= 6483)
249  {
250  return 23;
251  }
252  else if (w <= 7009)
253  {
254  return 24;
255  }
256  else if (w <= 7558)
257  {
258  return 25;
259  }
260  else if (w <= 8130)
261  {
262  return 26;
263  }
264  else if (w <= 8726)
265  {
266  return 27;
267  }
268  else if (w <= 9346)
269  {
270  return 28;
271  }
272  else if (w <= 9991)
273  {
274  return 29;
275  }
276  else if (w <= 10661)
277  {
278  return 30;
279  }
280  else if (w <= 11358)
281  {
282  return 31;
283  }
284  else if (w <= 12082)
285  {
286  return 32;
287  }
288  else if (w <= 12834)
289  {
290  return 33;
291  }
292  else if (w <= 13614)
293  {
294  return 34;
295  }
296  else if (w <= 14424)
297  {
298  return 35;
299  }
300  else if (w <= 15265)
301  {
302  return 36;
303  }
304  else if (w <= 16137)
305  {
306  return 37;
307  }
308  else if (w <= 17042)
309  {
310  return 38;
311  }
312  else if (w <= 17981)
313  {
314  return 39;
315  }
316  else if (w <= 18955)
317  {
318  return 40;
319  }
320  else if (w <= 19965)
321  {
322  return 41;
323  }
324  else if (w <= 21013)
325  {
326  return 42;
327  }
328  else if (w <= 22101)
329  {
330  return 43;
331  }
332  else if (w <= 23230)
333  {
334  return 44;
335  }
336  else if (w <= 24402)
337  {
338  return 45;
339  }
340  else if (w <= 25618)
341  {
342  return 46;
343  }
344  else if (w <= 26881)
345  {
346  return 47;
347  }
348  else if (w <= 28193)
349  {
350  return 48;
351  }
352  else if (w <= 29557)
353  {
354  return 49;
355  }
356  else if (w <= 30975)
357  {
358  return 50;
359  }
360  else if (w <= 32450)
361  {
362  return 51;
363  }
364  else if (w <= 33986)
365  {
366  return 52;
367  }
368  else if (w <= 35586)
369  {
370  return 53;
371  }
372  else if (w <= 37253)
373  {
374  return 54;
375  }
376  else if (w <= 38992)
377  {
378  return 55;
379  }
380  else if (w <= 40808)
381  {
382  return 56;
383  }
384  else if (w <= 42707)
385  {
386  return 57;
387  }
388  else if (w <= 44694)
389  {
390  return 58;
391  }
392  else if (w <= 46776)
393  {
394  return 59;
395  }
396  else if (w <= 48961)
397  {
398  return 60;
399  }
400  else if (w <= 51258)
401  {
402  return 61;
403  }
404  else if (w <= 53667)
405  {
406  return 62;
407  }
408  else if (w <= 56230)
409  {
410  return 63;
411  }
412  else if (w <= 58932)
413  {
414  return 64;
415  }
416  else if (w <= 61799)
417  {
418  return 65;
419  }
420  else if (w <= 64851)
421  {
422  return 66;
423  }
424  else if (w <= 68113)
425  {
426  return 67;
427  }
428  else if (w <= 71617)
429  {
430  return 68;
431  }
432  else if (w <= 75401)
433  {
434  return 69;
435  }
436  else if (w <= 79517)
437  {
438  return 70;
439  }
440  else if (w <= 84035)
441  {
442  return 71;
443  }
444  else if (w <= 89053)
445  {
446  return 72;
447  }
448  else if (w <= 94717)
449  {
450  return 73;
451  }
452  else
453  {
454  return 73;
455  }
456 }
457 
458 double
460 {
461  if (w <= 38)
462  {
463  return 0.50;
464  }
465  else if (w <= 118)
466  {
467  return 0.44;
468  }
469  else if (w <= 221)
470  {
471  return 0.41;
472  }
473  else if (w <= 347)
474  {
475  return 0.38;
476  }
477  else if (w <= 495)
478  {
479  return 0.37;
480  }
481  else if (w <= 663)
482  {
483  return 0.35;
484  }
485  else if (w <= 851)
486  {
487  return 0.34;
488  }
489  else if (w <= 1058)
490  {
491  return 0.33;
492  }
493  else if (w <= 1284)
494  {
495  return 0.32;
496  }
497  else if (w <= 1529)
498  {
499  return 0.31;
500  }
501  else if (w <= 1793)
502  {
503  return 0.30;
504  }
505  else if (w <= 2076)
506  {
507  return 0.29;
508  }
509  else if (w <= 2378)
510  {
511  return 0.28;
512  }
513  else if (w <= 2699)
514  {
515  return 0.28;
516  }
517  else if (w <= 3039)
518  {
519  return 0.27;
520  }
521  else if (w <= 3399)
522  {
523  return 0.27;
524  }
525  else if (w <= 3778)
526  {
527  return 0.26;
528  }
529  else if (w <= 4177)
530  {
531  return 0.26;
532  }
533  else if (w <= 4596)
534  {
535  return 0.25;
536  }
537  else if (w <= 5036)
538  {
539  return 0.25;
540  }
541  else if (w <= 5497)
542  {
543  return 0.24;
544  }
545  else if (w <= 5979)
546  {
547  return 0.24;
548  }
549  else if (w <= 6483)
550  {
551  return 0.23;
552  }
553  else if (w <= 7009)
554  {
555  return 0.23;
556  }
557  else if (w <= 7558)
558  {
559  return 0.22;
560  }
561  else if (w <= 8130)
562  {
563  return 0.22;
564  }
565  else if (w <= 8726)
566  {
567  return 0.22;
568  }
569  else if (w <= 9346)
570  {
571  return 0.21;
572  }
573  else if (w <= 9991)
574  {
575  return 0.21;
576  }
577  else if (w <= 10661)
578  {
579  return 0.21;
580  }
581  else if (w <= 11358)
582  {
583  return 0.20;
584  }
585  else if (w <= 12082)
586  {
587  return 0.20;
588  }
589  else if (w <= 12834)
590  {
591  return 0.20;
592  }
593  else if (w <= 13614)
594  {
595  return 0.19;
596  }
597  else if (w <= 14424)
598  {
599  return 0.19;
600  }
601  else if (w <= 15265)
602  {
603  return 0.19;
604  }
605  else if (w <= 16137)
606  {
607  return 0.19;
608  }
609  else if (w <= 17042)
610  {
611  return 0.18;
612  }
613  else if (w <= 17981)
614  {
615  return 0.18;
616  }
617  else if (w <= 18955)
618  {
619  return 0.18;
620  }
621  else if (w <= 19965)
622  {
623  return 0.17;
624  }
625  else if (w <= 21013)
626  {
627  return 0.17;
628  }
629  else if (w <= 22101)
630  {
631  return 0.17;
632  }
633  else if (w <= 23230)
634  {
635  return 0.17;
636  }
637  else if (w <= 24402)
638  {
639  return 0.16;
640  }
641  else if (w <= 25618)
642  {
643  return 0.16;
644  }
645  else if (w <= 26881)
646  {
647  return 0.16;
648  }
649  else if (w <= 28193)
650  {
651  return 0.16;
652  }
653  else if (w <= 29557)
654  {
655  return 0.15;
656  }
657  else if (w <= 30975)
658  {
659  return 0.15;
660  }
661  else if (w <= 32450)
662  {
663  return 0.15;
664  }
665  else if (w <= 33986)
666  {
667  return 0.15;
668  }
669  else if (w <= 35586)
670  {
671  return 0.14;
672  }
673  else if (w <= 37253)
674  {
675  return 0.14;
676  }
677  else if (w <= 38992)
678  {
679  return 0.14;
680  }
681  else if (w <= 40808)
682  {
683  return 0.14;
684  }
685  else if (w <= 42707)
686  {
687  return 0.13;
688  }
689  else if (w <= 44694)
690  {
691  return 0.13;
692  }
693  else if (w <= 46776)
694  {
695  return 0.13;
696  }
697  else if (w <= 48961)
698  {
699  return 0.13;
700  }
701  else if (w <= 51258)
702  {
703  return 0.13;
704  }
705  else if (w <= 53667)
706  {
707  return 0.12;
708  }
709  else if (w <= 56230)
710  {
711  return 0.12;
712  }
713  else if (w <= 58932)
714  {
715  return 0.12;
716  }
717  else if (w <= 61799)
718  {
719  return 0.12;
720  }
721  else if (w <= 64851)
722  {
723  return 0.11;
724  }
725  else if (w <= 68113)
726  {
727  return 0.11;
728  }
729  else if (w <= 71617)
730  {
731  return 0.11;
732  }
733  else if (w <= 75401)
734  {
735  return 0.10;
736  }
737  else if (w <= 79517)
738  {
739  return 0.10;
740  }
741  else if (w <= 84035)
742  {
743  return 0.10;
744  }
745  else if (w <= 89053)
746  {
747  return 0.10;
748  }
749  else if (w <= 94717)
750  {
751  return 0.09;
752  }
753  else
754  {
755  return 0.09;
756  }
757 }
758 
759 } // namespace ns3
An implementation of TCP HighSpeed.
Definition: tcp-highspeed.h:49
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get slow start threshold following HighSpeed principles.
uint32_t m_segmentSize
Segment size.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
The NewReno implementation.
static double TableLookupB(uint32_t w)
Lookup table for the coefficient b (from RFC 3649)
static uint32_t TableLookupA(uint32_t w)
Lookup table for the coefficient a (from RFC 3649)
#define max(a, b)
Definition: 80211b.c:43
virtual std::string GetName() const
Get the name of the congestion control algorithm.
virtual ~TcpHighSpeed(void)
static TypeId GetTypeId(void)
Get the type ID.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
TracedValue< uint32_t > m_cWnd
Congestion window.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
TcpHighSpeed(void)
Create an unbound tcp socket.
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across sockets.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
uint32_t m_ackCnt
Number of received ACK, corrected with the coefficient a.
Definition: tcp-highspeed.h:99
uint32_t GetCwndInSegments() const
Get cwnd in segments rather than bytes.
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Congestion avoidance of TcpHighSpeed.