1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
17 * This is used to send pings between daemons (so far, the OSDs) for
18 * heartbeat purposes. We include a timestamp and distinguish between
19 * outgoing pings and responses to those. If you set the
20 * min_message in the constructor, the message will inflate itself
21 * to the specified size -- this is good for dealing with network
22 * issues with jumbo frames. See http://tracker.ceph.com/issues/20087
26 #ifndef CEPH_MOSDPING_H
27 #define CEPH_MOSDPING_H
29 #include "common/Clock.h"
31 #include "msg/Message.h"
32 #include "osd/osd_types.h"
35 class MOSDPing
: public Message
{
37 static constexpr int HEAD_VERSION
= 5;
38 static constexpr int COMPAT_VERSION
= 4;
49 const char *get_op_name(int op
) const {
51 case HEARTBEAT
: return "heartbeat";
52 case START_HEARTBEAT
: return "start_heartbeat";
53 case STOP_HEARTBEAT
: return "stop_heartbeat";
54 case YOU_DIED
: return "you_died";
55 case PING
: return "ping";
56 case PING_REPLY
: return "ping_reply";
57 default: return "???";
62 epoch_t map_epoch
= 0;
64 utime_t ping_stamp
; ///< when the PING was sent
65 ceph::signedspan mono_ping_stamp
; ///< relative to sender's clock
66 ceph::signedspan mono_send_stamp
; ///< replier's send stamp
67 std::optional
<ceph::time_detail::signedspan
> delta_ub
; ///< ping sender
70 uint32_t min_message_size
= 0;
72 MOSDPing(const uuid_d
& f
, epoch_t e
, __u8 o
,
78 std::optional
<ceph::time_detail::signedspan
> delta_ub
= {})
79 : Message
{MSG_OSD_PING
, HEAD_VERSION
, COMPAT_VERSION
},
80 fsid(f
), map_epoch(e
), op(o
),
86 min_message_size(min_message
)
89 : Message
{MSG_OSD_PING
, HEAD_VERSION
, COMPAT_VERSION
}
92 ~MOSDPing() override
{}
95 void decode_payload() override
{
96 auto p
= payload
.cbegin();
100 decode(ping_stamp
, p
);
102 int payload_mid_length
= p
.get_off();
106 if (header
.version
>= 5) {
108 decode(mono_ping_stamp
, p
);
109 decode(mono_send_stamp
, p
);
114 min_message_size
= size
+ payload_mid_length
;
116 void encode_payload(uint64_t features
) override
{
118 encode(fsid
, payload
);
119 encode(map_epoch
, payload
);
121 encode(ping_stamp
, payload
);
124 if (min_message_size
> payload
.length()) {
125 s
= min_message_size
- payload
.length();
127 encode((uint32_t)s
, payload
);
129 encode(up_from
, payload
);
130 encode(mono_ping_stamp
, payload
);
131 encode(mono_send_stamp
, payload
);
132 encode(delta_ub
, payload
);
135 // this should be big enough for normal min_message padding sizes. since
136 // we are targeting jumbo ethernet frames around 9000 bytes, 16k should
137 // be more than sufficient! the compiler will statically zero this so
138 // that at runtime we are only adding a bufferptr reference to it.
139 static char zeros
[16384] = {};
140 while (s
> sizeof(zeros
)) {
141 payload
.append(buffer::create_static(sizeof(zeros
), zeros
));
145 payload
.append(buffer::create_static(s
, zeros
));
150 std::string_view
get_type_name() const override
{ return "osd_ping"; }
151 void print(ostream
& out
) const override
{
152 out
<< "osd_ping(" << get_op_name(op
)
154 << " up_from " << up_from
155 << " ping_stamp " << ping_stamp
<< "/" << mono_ping_stamp
156 << " send_stamp " << mono_send_stamp
;
158 out
<< " delta_ub " << *delta_ub
;
163 template<class T
, typename
... Args
>
164 friend boost::intrusive_ptr
<T
> ceph::make_message(Args
&&... args
);