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