]> git.proxmox.com Git - ceph.git/blame - ceph/src/messages/MMonPing.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / messages / MMonPing.h
CommitLineData
f67539c2
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/**
4 * This is used to send pings between monitors for
5 * heartbeat purposes. We include a timestamp and distinguish between
6 * outgoing pings and responses to those. If you set the
7 * min_message in the constructor, the message will inflate itself
8 * to the specified size -- this is good for dealing with network
9 * issues with jumbo frames. See http://tracker.ceph.com/issues/20087
10 *
11 */
12
13#ifndef CEPH_MMONPING_H
14#define CEPH_MMONPING_H
15
16#include "common/Clock.h"
17
18#include "msg/Message.h"
19#include "mon/ConnectionTracker.h"
20
21class MMonPing final : public Message {
22private:
23 static constexpr int HEAD_VERSION = 1;
24 static constexpr int COMPAT_VERSION = 1;
25
26 public:
27 enum {
28 PING = 1,
29 PING_REPLY = 2,
30 };
31 const char *get_op_name(int op) const {
32 switch (op) {
33 case PING: return "ping";
34 case PING_REPLY: return "ping_reply";
35 default: return "???";
36 }
37 }
38
39 __u8 op = 0;
40 utime_t stamp;
41 bufferlist tracker_bl;
42 uint32_t min_message_size = 0;
43
44 MMonPing(__u8 o, utime_t s, const bufferlist& tbl,
45 uint32_t min_message)
46 : Message{MSG_MON_PING, HEAD_VERSION, COMPAT_VERSION},
47 op(o), stamp(s), tracker_bl(tbl), min_message_size(min_message)
48 {}
49 MMonPing(__u8 o, utime_t s, const bufferlist& tbl)
50 : Message{MSG_MON_PING, HEAD_VERSION, COMPAT_VERSION},
51 op(o), stamp(s), tracker_bl(tbl) {}
52 MMonPing()
53 : Message{MSG_MON_PING, HEAD_VERSION, COMPAT_VERSION}
54 {}
55private:
56 ~MMonPing() final {}
57
58public:
59 void decode_payload() override {
60 auto p = payload.cbegin();
61 decode(op, p);
62 decode(stamp, p);
63 decode(tracker_bl, p);
64
65 int payload_mid_length = p.get_off();
66 uint32_t size;
67 decode(size, p);
68 p += size;
69 min_message_size = size + payload_mid_length;
70 }
71 void encode_payload(uint64_t features) override {
72 using ceph::encode;
73 encode(op, payload);
74 encode(stamp, payload);
75 encode(tracker_bl, payload);
76
77 size_t s = 0;
78 if (min_message_size > payload.length()) {
79 s = min_message_size - payload.length();
80 }
81 encode((uint32_t)s, payload);
82 if (s) {
83 // this should be big enough for normal min_message padding sizes. since
84 // we are targeting jumbo ethernet frames around 9000 bytes, 16k should
85 // be more than sufficient! the compiler will statically zero this so
86 // that at runtime we are only adding a bufferptr reference to it.
87 static char zeros[16384] = {};
88 while (s > sizeof(zeros)) {
89 payload.append(buffer::create_static(sizeof(zeros), zeros));
90 s -= sizeof(zeros);
91 }
92 if (s) {
93 payload.append(buffer::create_static(s, zeros));
94 }
95 }
96 }
97
98 std::string_view get_type_name() const override { return "mon_ping"; }
20effc67 99 void print(std::ostream& out) const override {
f67539c2
TL
100 out << "mon_ping(" << get_op_name(op)
101 << " stamp " << stamp
102 << ")";
103 }
104private:
105 template<class T, typename... Args>
106 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
107};
108
109#endif