]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #pragma once | |
5 | ||
6 | #include "include/ceph_features.h" | |
7 | ||
8 | namespace ceph::net { | |
9 | ||
10 | using peer_type_t = int; | |
11 | ||
12 | /** | |
13 | * A Policy describes the rules of a Connection. Is there a limit on how | |
14 | * much data this Connection can have locally? When the underlying connection | |
15 | * experiences an error, does the Connection disappear? Can this Messenger | |
16 | * re-establish the underlying connection? | |
17 | */ | |
18 | template<class ThrottleType> | |
19 | struct Policy { | |
20 | /// If true, the Connection is tossed out on errors. | |
21 | bool lossy; | |
22 | /// If true, the underlying connection can't be re-established from this end. | |
23 | bool server; | |
24 | /// If true, we will standby when idle | |
25 | bool standby; | |
26 | /// If true, we will try to detect session resets | |
27 | bool resetcheck; | |
9f95a23c TL |
28 | |
29 | /// Server: register lossy client connections. | |
30 | bool register_lossy_clients = true; | |
31 | // The net result of this is that a given client can only have one | |
32 | // open connection with the server. If a new connection is made, | |
33 | // the old (registered) one is closed by the messenger during the accept | |
34 | // process. | |
35 | ||
11fdf7f2 TL |
36 | /** |
37 | * The throttler is used to limit how much data is held by Messages from | |
38 | * the associated Connection(s). When reading in a new Message, the Messenger | |
39 | * will call throttler->throttle() for the size of the new Message. | |
40 | */ | |
41 | ThrottleType* throttler_bytes; | |
42 | ThrottleType* throttler_messages; | |
43 | ||
44 | /// Specify features supported locally by the endpoint. | |
45 | uint64_t features_supported; | |
46 | /// Specify features any remotes must have to talk to this endpoint. | |
47 | uint64_t features_required; | |
48 | ||
49 | Policy() | |
50 | : lossy(false), server(false), standby(false), resetcheck(true), | |
51 | throttler_bytes(NULL), | |
52 | throttler_messages(NULL), | |
53 | features_supported(CEPH_FEATURES_SUPPORTED_DEFAULT), | |
54 | features_required(0) {} | |
55 | private: | |
9f95a23c | 56 | Policy(bool l, bool s, bool st, bool r, bool rlc, uint64_t req) |
11fdf7f2 | 57 | : lossy(l), server(s), standby(st), resetcheck(r), |
9f95a23c | 58 | register_lossy_clients(rlc), |
11fdf7f2 TL |
59 | throttler_bytes(NULL), |
60 | throttler_messages(NULL), | |
61 | features_supported(CEPH_FEATURES_SUPPORTED_DEFAULT), | |
62 | features_required(req) {} | |
63 | ||
64 | public: | |
65 | static Policy stateful_server(uint64_t req) { | |
9f95a23c TL |
66 | return Policy(false, true, true, true, true, req); |
67 | } | |
68 | static Policy stateless_registered_server(uint64_t req) { | |
69 | return Policy(true, true, false, false, true, req); | |
11fdf7f2 TL |
70 | } |
71 | static Policy stateless_server(uint64_t req) { | |
9f95a23c | 72 | return Policy(true, true, false, false, false, req); |
11fdf7f2 TL |
73 | } |
74 | static Policy lossless_peer(uint64_t req) { | |
9f95a23c | 75 | return Policy(false, false, true, false, true, req); |
11fdf7f2 TL |
76 | } |
77 | static Policy lossless_peer_reuse(uint64_t req) { | |
9f95a23c | 78 | return Policy(false, false, true, true, true, req); |
11fdf7f2 TL |
79 | } |
80 | static Policy lossy_client(uint64_t req) { | |
9f95a23c | 81 | return Policy(true, false, false, false, true, req); |
11fdf7f2 TL |
82 | } |
83 | static Policy lossless_client(uint64_t req) { | |
9f95a23c | 84 | return Policy(false, false, false, true, true, req); |
11fdf7f2 TL |
85 | } |
86 | }; | |
87 | ||
88 | template<class ThrottleType> | |
89 | class PolicySet { | |
90 | using policy_t = Policy<ThrottleType> ; | |
91 | /// the default Policy we use for Pipes | |
92 | policy_t default_policy; | |
93 | /// map specifying different Policies for specific peer types | |
94 | std::map<int, policy_t> policy_map; // entity_name_t::type -> Policy | |
95 | ||
96 | public: | |
97 | const policy_t& get(peer_type_t peer_type) const { | |
98 | if (auto found = policy_map.find(peer_type); found != policy_map.end()) { | |
99 | return found->second; | |
100 | } else { | |
101 | return default_policy; | |
102 | } | |
103 | } | |
104 | policy_t& get(peer_type_t peer_type) { | |
105 | if (auto found = policy_map.find(peer_type); found != policy_map.end()) { | |
106 | return found->second; | |
107 | } else { | |
108 | return default_policy; | |
109 | } | |
110 | } | |
111 | void set(peer_type_t peer_type, const policy_t& p) { | |
112 | policy_map[peer_type] = p; | |
113 | } | |
114 | const policy_t& get_default() const { | |
115 | return default_policy; | |
116 | } | |
117 | void set_default(const policy_t& p) { | |
118 | default_policy = p; | |
119 | } | |
120 | void set_throttlers(peer_type_t peer_type, | |
121 | ThrottleType* byte_throttle, | |
122 | ThrottleType* msg_throttle) { | |
123 | auto& policy = get(peer_type); | |
124 | policy.throttler_bytes = byte_throttle; | |
125 | policy.throttler_messages = msg_throttle; | |
126 | } | |
127 | }; | |
128 | ||
129 | } |