libtins  4.0
ack_tracker.h
1 /*
2  * Copyright (c) 2017, 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 <tins/config.h>
34 
35 #ifdef TINS_HAVE_ACK_TRACKER
36 
37 #include <vector>
38 #include <boost/icl/interval_set.hpp>
39 #include <tins/macros.h>
40 
41 namespace Tins {
42 
43 class PDU;
44 
45 namespace TCPIP {
46 
52 class TINS_API AckedRange {
53 public:
54  typedef boost::icl::discrete_interval<uint32_t> interval_type;
55 
62  AckedRange(uint32_t first, uint32_t last);
63 
69  interval_type next();
70 
75  bool has_next() const;
76 
80  uint32_t first() const;
81 
85  uint32_t last() const;
86 private:
87  uint32_t first_;
88  uint32_t last_;
89 };
90 
94 class TINS_API AckTracker {
95 public:
99  typedef boost::icl::interval_set<uint32_t> interval_set_type;
100 
104  AckTracker();
105 
112  AckTracker(uint32_t initial_ack, bool use_sack = true);
113 
117  void process_packet(const PDU& packet);
118 
122  void use_sack();
123 
127  uint32_t ack_number() const;
128 
132  const interval_set_type& acked_intervals() const;
133 
140  bool is_segment_acked(uint32_t sequence_number, uint32_t length) const;
141 private:
142  void process_sack(const std::vector<uint32_t>& sack);
143  void cleanup_sacked_intervals(uint32_t old_ack, uint32_t new_ack);
144 
145  interval_set_type acked_intervals_;
146  uint32_t ack_number_;
147  bool use_sack_;
148 };
149 
150 } // TCPIP
151 } // Tins
152 
153 #endif // TINS_HAVE_ACK_TRACKER
154 
155 #endif // TINS_TCP_IP_ACK_TRACKER_H
156 
The Tins namespace.
Definition: address_range.h:38