1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2018 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 #ifndef TCP_TX_ITEM_H
20 #define TCP_TX_ITEM_H
21 
22 #include "ns3/packet.h"
23 #include "ns3/nstime.h"
24 #include "ns3/sequence-number.h"
25 
26 namespace ns3 {
27 /**
28  * \ingroup tcp
29  *
30  * \brief Item that encloses the application packet and some flags for it
31  */
32 class TcpTxItem
33 {
34 public:
35   // Default constructor, copy-constructor, destructor
36 
37   /**
38    * \brief Print the time
39    * \param os ostream
40    * \param unit Time::Unit
41    */
42   void Print (std::ostream &os, Time::Unit unit = Time::S) const;
43 
44   /**
45    * \brief Get the size in the sequence number space
46    *
47    * \return 1 if the packet size is 0 or there's no packet, otherwise the size of the packet
48    */
49   uint32_t GetSeqSize (void) const;
50 
51   /**
52    * \brief Is the item sacked?
53    * \return true if the item is sacked, false otherwise
54    */
55   bool IsSacked (void) const;
56 
57   /**
58    * \brief Is the item retransmitted?
59    * \return true if the item have been retransmitted
60    */
61   bool IsRetrans (void) const;
62 
63   /**
64    * \brief Get a copy of the Packet underlying this item
65    * \return a copy of the Packet
66    */
67   Ptr<Packet> GetPacketCopy (void) const;
68 
69   /**
70    * \brief Get the Packet underlying this item
71    * \return a pointer to a const Packet
72    */
73   Ptr<const Packet> GetPacket (void) const;
74 
75   /**
76    * \brief Get a reference to the time the packet was sent for the last time
77    * \return a reference to the last sent time
78    */
79   const Time & GetLastSent (void) const;
80 
81   /**
82    * \brief Various rate-related information, can be accessed by TcpRateOps.
83    *
84    * Note: This is not enforced through C++, but you developer must honour
85    * this description.
86    */
87   struct RateInformation
88   {
89     uint64_t m_delivered {0};          //!< Connection's delivered data at the time the packet was sent
90     Time m_deliveredTime {Time::Max ()};//!< Connection's delivered time at the time the packet was sent
91     Time m_firstSent     {Time::Max ()};//!< Connection's first sent time at the time the packet was sent
92     bool m_isAppLimited  {false};      //!< Connection's app limited at the time the packet was sent
93   };
94 
95   /**
96    * \brief Get (to modify) the Rate Information of this item
97    *
98    * \return A reference to the rate information.
99    */
100   RateInformation & GetRateInformation (void);
101 
102   bool m_retrans       {false};      //!< Indicates if the segment is retransmitted
103 
104 private:
105   // Only TcpTxBuffer is allowed to touch this part of the TcpTxItem, to manage
106   // its internal lists and counters
107   friend class TcpTxBuffer;
108 
109   SequenceNumber32 m_startSeq {0};   //!< Sequence number of the item (if transmitted)
110   Ptr<Packet> m_packet {nullptr};    //!< Application packet (can be null)
111   bool m_lost          {false};      //!< Indicates if the segment has been lost (RTO)
112   Time m_lastSent      {Time::Max ()};//!< Timestamp of the time at which the segment has been sent last time
113   bool m_sacked        {false};      //!< Indicates if the segment has been SACKed
114 
115   RateInformation m_rateInfo;        //!< Rate information of the item
116 };
117 
118 } //namespace ns3
119 
120 #endif /* TCP_TX_ITEM_H */
121