libtins  3.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
ack_tracker.h
1 /*
2  * Copyright (c) 2016, Matias Fontanini
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef TINS_TCP_IP_ACK_TRACKER_H
31 #define TINS_TCP_IP_ACK_TRACKER_H
32 
33 #include "../config.h"
34 
35 #ifdef TINS_HAVE_ACK_TRACKER
36 
37 #include <vector>
38 #include <boost/icl/interval_set.hpp>
39 
40 namespace Tins {
41 
42 class PDU;
43 
44 namespace TCPIP {
45 
51 class AckedRange {
52 public:
53  typedef boost::icl::discrete_interval<uint32_t> interval_type;
54 
61  AckedRange(uint32_t first, uint32_t last);
62 
68  interval_type next();
69 
74  bool has_next() const;
75 
79  uint32_t first() const;
80 
84  uint32_t last() const;
85 private:
86  uint32_t first_;
87  uint32_t last_;
88 };
89 
93 class AckTracker {
94 public:
98  typedef boost::icl::interval_set<uint32_t> interval_set_type;
99 
103  AckTracker();
104 
111  AckTracker(uint32_t initial_ack, bool use_sack = true);
112 
116  void process_packet(const PDU& packet);
117 
121  void use_sack();
122 
126  uint32_t ack_number() const;
127 
131  const interval_set_type& acked_intervals() const;
132 
139  bool is_segment_acked(uint32_t sequence_number, uint32_t length) const;
140 private:
141  void process_sack(const std::vector<uint32_t>& sack);
142  void cleanup_sacked_intervals(uint32_t old_ack, uint32_t new_ack);
143 
144  interval_set_type acked_intervals_;
145  uint32_t ack_number_;
146  bool use_sack_;
147 };
148 
149 } // TCPIP
150 } // Tins
151 
152 #endif // TINS_HAVE_ACK_TRACKER
153 
154 #endif // TINS_TCP_IP_ACK_TRACKER_H
155 
interval_type next()
Gets the next acked interval in this range.
void use_sack()
Indicates whether Selective ACKs should be processed.
AckedRange(uint32_t first, uint32_t last)
Constructs an acked range.
bool has_next() const
uint32_t ack_number() const
bool is_segment_acked(uint32_t sequence_number, uint32_t length) const
Indicates whether the given segment has been already ACKed.
const interval_set_type & acked_intervals() const
Retrieves all acked intervals by Selective ACKs.
uint32_t first() const
Allows tracking acknowledged intervals in a TCP stream.
Definition: ack_tracker.h:93
uint32_t last() const
void process_packet(const PDU &packet)
Process a packet.
boost::icl::interval_set< uint32_t > interval_set_type
Definition: ack_tracker.h:98
Represents an acknowledged segment range.
Definition: ack_tracker.h:51
Base class for protocol data units.
Definition: pdu.h:108