1 //--------------------------------------------------------------------------
2 // Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
3 //
4 // This program is free software; you can redistribute it and/or modify it
5 // under the terms of the GNU General Public License Version 2 as published
6 // by the Free Software Foundation.  You may not use, modify or distribute
7 // this program under any other version of the GNU General Public License.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 //--------------------------------------------------------------------------
18 // flush_bucket.h author Russ Combs <rucombs@cisco.com>
19 
20 #ifndef FLUSH_BUCKET_H
21 #define FLUSH_BUCKET_H
22 
23 // FlushBuckets manage a set of flush points for stream_tcp.
24 
25 #include <cstdint>
26 #include <vector>
27 
28 class FlushBucket
29 {
30 public:
31     virtual ~FlushBucket() = default;
32     virtual uint16_t get_next() = 0;
33 
34     static uint16_t get_size();
35     static void set(unsigned sz);
36     static void set();
37     static void clear();
38 
39 protected:
40     FlushBucket() = default;
41 };
42 
43 class ConstFlushBucket : public FlushBucket
44 {
45 public:
ConstFlushBucket(uint16_t fp)46     ConstFlushBucket(uint16_t fp)
47     { pt = fp; }
48 
get_next()49     uint16_t get_next() override
50     { return pt; }
51 
52 private:
53     uint16_t pt;
54 };
55 
56 class VarFlushBucket : public FlushBucket
57 {
58 public:
59     uint16_t get_next() override;
60 
61 protected:
62     VarFlushBucket() = default;
63     void set_next(uint16_t);
64 
65 private:
66     unsigned idx = 0;
67     std::vector<uint16_t> flush_points;
68 };
69 
70 class StaticFlushBucket : public VarFlushBucket
71 {
72 public:
73     StaticFlushBucket();
74 };
75 
76 class RandomFlushBucket : public VarFlushBucket
77 {
78 public:
79     RandomFlushBucket();
80 };
81 
82 #endif
83 
84