summaryrefslogtreecommitdiffstats
path: root/doc/dev/network-protocol.rst
blob: d766a32112184724c925be59ed8d4eec725af770 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
==================
 Network Protocol
==================

This file describes the network protocol used by Ceph.  In order to understand
the way the structures are defined it is recommended to read the introduction
of :doc:`/dev/network-encoding` first.

Hello
=====

The protocol starts with a handshake that confirms that both nodes are talking
ceph and shares some basic information.

Banner
------

The first action is the server sending banner to the client.  The banner is
defined in ``CEPH_BANNER`` from ``src/include/msgr.h``.  This is followed by
the server's then client's address each encoded as a ``entity_addr_t``.

Once the client verifies that the servers banner matches its own it replies with
its banner and its address.

Connect
-------

Once the banners have been verified and the addresses exchanged the connection
negotiation begins.  First the client sends a ``ceph_msg_connect`` structure
with its information.

::
	
	// From src/include/msgr.h
	struct ceph_msg_connect {
		u64le features;            // Supported features (CEPH_FEATURE_*)
		u32le host_type;           // CEPH_ENTITY_TYPE_*
		u32le global_seq;          // Number of connections initiated by this host.
		u32le connect_seq;         // Number of connections initiated in this session.
		u32le protocol_version;
		u32le authorizer_protocol;
		u32le authorizer_len;
		u8    flags;               // CEPH_MSG_CONNECT_*
		u8    authorizer[authorizer_len];
	}

Connect Reply
-------------

Once the connect has been sent the connection has effectively been opened,
however the first message the server sends must be a connect reply message.

::
	
	struct ceph_msg_connect_reply {
		u8    tag; // Tag indicating response code.
		u64le features;
		u32le global_seq;
		u32le connect_seq;
		u32le protocol_version;
		u32le authorizer_len;
		u8    flags;
		u8    authorizer[authorizer_len];
	}

MSGR Protocol
=============

This is a low level protocol over which messages are delivered.  The messages
at this level consist of a tag byte, identifying the type of message, followed
by the message data.

::
	
	// Virtual structure.
	struct {
		u8 tag; // CEPH_MSGR_TAG_*
		u8 data[]; // Length depends on tag and data.
	}

The length of ``data`` is determined by the tag byte and depending on the
message type via information in the ``data`` array itself.

.. note::
	There is no way to determine the length of the message if you do not
	understand the type of message.

The message tags are defined in ``src/include/msgr.h`` and the current ones
are listed below along with the data they include.  Note that the defined
structures don't exist in the source and are merely for representing the
protocol.

CEPH_MSGR_TAG_CLOSE (0x06)
--------------------------

::
	
	struct ceph_msgr_close {
		u8 tag = 0x06;
		u8 data[0]; // No data.
	}

The close message indicates that the connection is being closed.

CEPH_MSGR_TAG_MSG (0x07)
------------------------

::
	
	struct ceph_msgr_msg {
		u8 tag = 0x07;
		ceph_msg_header header;
		u8 front [header.front_len ];
		u8 middle[header.middle_len];
		u8 data  [header.data_len  ];
		ceph_msg_footer footer;
	}
	
	// From src/include/msgr.h
	struct ceph_msg_header {
		u64le seq;       // Sequence number.
		u64le tid;       // Transaction ID.
		u16le type;      // Message type (CEPH_MSG_* or MSG_*).
		u16le priority;  // Priority (higher is more important).
		u16le version;   // Version of message encoding.
		
		u32le front_len;  // The size of the front section.
		u32le middle_len; // The size of the middle section.
		u32le data_len;   // The size of the data section.
		u16le data_off;   // The way data should be aligned by the receiver.
		
		ceph_entity_name src; // Information about the sender.
		
		u16le compat_version; // Oldest compatible encoding version.
		u16le reserved;       // Unused.
		u32le crc;            // CRC of header.
	}
	
	// From src/include/msgr.h
	struct ceph_msg_footer {
		u32le front_crc;  // Checksums of the various sections.
		u32le middle_crc; //
		u32le data_crc;   //
		u64le sig; // Cryptographic signature.
		u8    flags;
	}

Messages are the business logic of Ceph.  They are what is used to send data and
requests between nodes.  The message header contains the length of the message
so unknown messages can be handled gracefully.

There are two names for the message type constants ``CEPH_MSG_*`` and ``MSG_*``.
The only difference between the two is that the first are considered "public"
while the second is for internal use only.  There is no protocol-level
difference.

CEPH_MSGR_TAG_ACK (0x08)
------------------------

::
	
	struct ceph_msgr_ack {
		u8    tag = 0x08;
		u64le seq; // The sequence number of the message being acknowledged.
	}

CEPH_MSGR_TAG_KEEPALIVE (0x09)
------------------------------

::
	
	struct ceph_msgr_keepalive {
		u8 tag = 0x09;
		u8 data[0]; // No data.
	}

CEPH_MSGR_TAG_KEEPALIVE2 (0x0E)
-------------------------------

::
	
	struct ceph_msgr_keepalive2 {
		u8      tag = 0x0E;
		utime_t timestamp;
	}

CEPH_MSGR_TAG_KEEPALIVE2_ACK (0x0F)
-----------------------------------

::
	
	struct ceph_msgr_keepalive2_ack {
		u8      tag = 0x0F;
		utime_t timestamp;
	}

.. vi: textwidth=80 noexpandtab