1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2017 NITK Surathkal
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  * Author: Shravya K.S. <shravya.ks0@gmail.com>
19  *
20  */
21 
22 #ifndef TCP_DCTCP_H
23 #define TCP_DCTCP_H
24 
25 #include "ns3/tcp-congestion-ops.h"
26 #include "ns3/tcp-linux-reno.h"
27 #include "ns3/traced-callback.h"
28 
29 namespace ns3 {
30 
31 /**
32  * \ingroup tcp
33  *
34  * \brief An implementation of DCTCP. This model implements all of the
35  * endpoint capabilities mentioned in the DCTCP SIGCOMM paper.
36  */
37 
38 class TcpDctcp : public TcpLinuxReno
39 {
40 public:
41   /**
42    * \brief Get the type ID.
43    * \return the object TypeId
44    */
45   static TypeId GetTypeId (void);
46 
47   /**
48    * Create an unbound tcp socket.
49    */
50   TcpDctcp ();
51 
52   /**
53    * \brief Copy constructor
54    * \param sock the object to copy
55    */
56   TcpDctcp (const TcpDctcp& sock);
57 
58   /**
59    * \brief Destructor
60    */
61   virtual ~TcpDctcp (void);
62 
63   // Documented in base class
64   virtual std::string GetName () const;
65 
66   /**
67    * \brief Set configuration required by congestion control algorithm,
68    *        This method will force DctcpEcn mode and will force usage of
69    *        either ECT(0) or ECT(1) (depending on the 'UseEct0' attribute),
70    *        despite any other configuration in the base classes.
71    *
72    * \param tcb internal congestion state
73    */
74   virtual void Init (Ptr<TcpSocketState> tcb);
75 
76   /**
77    * TracedCallback signature for DCTCP update of congestion state
78    *
79    * \param [in] bytesAcked Bytes acked in this observation window
80    * \param [in] bytesMarked Bytes marked in this observation window
81    * \param [in] alpha New alpha (congestion estimate) value
82    */
83   typedef void (* CongestionEstimateTracedCallback)(uint32_t bytesAcked, uint32_t bytesMarked, double alpha);
84 
85   // Documented in base class
86   virtual uint32_t GetSsThresh (Ptr<const TcpSocketState> tcb,
87                                 uint32_t bytesInFlight);
88   virtual Ptr<TcpCongestionOps> Fork ();
89   virtual void PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
90                           const Time &rtt);
91   virtual void CwndEvent (Ptr<TcpSocketState> tcb,
92                           const TcpSocketState::TcpCAEvent_t event);
93 private:
94   /**
95    * \brief Changes state of m_ceState to true
96    *
97    * \param tcb internal congestion state
98    */
99   void CeState0to1 (Ptr<TcpSocketState> tcb);
100 
101   /**
102    * \brief Changes state of m_ceState to false
103    *
104    * \param tcb internal congestion state
105    */
106   void CeState1to0 (Ptr<TcpSocketState> tcb);
107 
108   /**
109    * \brief Updates the value of m_delayedAckReserved
110    *
111    * \param tcb internal congestion state
112    * \param event the congestion window event
113    */
114   void UpdateAckReserved (Ptr<TcpSocketState> tcb,
115                           const TcpSocketState::TcpCAEvent_t event);
116 
117   /**
118    * \brief Resets the value of m_ackedBytesEcn, m_ackedBytesTotal and m_nextSeq
119    *
120    * \param tcb internal congestion state
121    */
122   void Reset (Ptr<TcpSocketState> tcb);
123 
124   /**
125    * \brief Initialize the value of m_alpha
126    *
127    * \param alpha DCTCP alpha parameter
128    */
129   void InitializeDctcpAlpha (double alpha);
130 
131   uint32_t m_ackedBytesEcn;             //!< Number of acked bytes which are marked
132   uint32_t m_ackedBytesTotal;           //!< Total number of acked bytes
133   SequenceNumber32 m_priorRcvNxt;       //!< Sequence number of the first missing byte in data
134   bool m_priorRcvNxtFlag;               //!< Variable used in setting the value of m_priorRcvNxt for first time
135   double m_alpha;                       //!< Parameter used to estimate the amount of network congestion
136   SequenceNumber32 m_nextSeq;           //!< TCP sequence number threshold for beginning a new observation window
137   bool m_nextSeqFlag;                   //!< Variable used in setting the value of m_nextSeq for first time
138   bool m_ceState;                       //!< DCTCP Congestion Experienced state
139   bool m_delayedAckReserved;            //!< Delayed Ack state
140   double m_g;                           //!< Estimation gain
141   bool m_useEct0;                       //!< Use ECT(0) for ECN codepoint
142   bool m_initialized;                   //!< Whether DCTCP has been initialized
143   /**
144    * \brief Callback pointer for congestion state update
145    */
146   TracedCallback<uint32_t, uint32_t, double> m_traceCongestionEstimate;
147 };
148 
149 } // namespace ns3
150 
151 #endif /* TCP_DCTCP_H */
152 
153