-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme.binary_protocol_faq
300 lines (226 loc) · 11.7 KB
/
readme.binary_protocol_faq
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
The OpenPegasus Binary Protocol FAQ
===================================
This FAQ (Frequently Asked Questions) hopefully addresses questions you might
have about the the OpenPegasus Binary Protocol. If you find your question was
not addressed, please ask your question on the OpenPegasus mailing list and
request that the answer be included in this document.
What is the Binary Protocol?
============================
The binary protocol is a fast protocol for client-server communication. It
allows local clients to send binary messages to the OpenPegasus server and
receive binary responses. This protocol is much faster than the default
XML protocol. When the binary protocol is enabled, local clients use it to
communicate with the OpenPegasus server. Examples of local clients include:
(1) out-of-process providers making up-calls, (2) any provider making a local
connection with the CIMClient class, (2) any local process making a local
connection with the CIMClient class.
Why use the Binary Protocol?
============================
The main reason to use the binary protocol is to improve performance of the
server and clients. Some operations execute as much as 4 times faster with
the binary protocol.
How big are binary messages?
============================
Binary messages are slightly larger than XML messages for two reasons:
(1) Strings are transmitted using 2-byte characters and (2) Objects are
aligned on 8-byte boundaries.
What are the basic rules for encoding messages?
===============================================
The encoding rules were designed for speed rather than size. The basic rules
are:
(1) All basic types are aligned on 8-byte boundaries. For example, a uint32
starts on an 8-byte boundary and is followed by 4 padding bytes so that
the next type is aligned on an 8-byte boundary. This alignment has 2
advantages: (1) it allows any basic type to be dereferenced directly in
the buffer without having to relocate it and (2) it is inexpensive to
calculate the alignment of the next type.
There are 2 other data alignment techniques we could have chosen:
(*) Don't align at all. Just pack types into the buffer end-to-end.
This technique yields smaller messages but sacrifices
performance since types cannot be assigned directly to or
from the data buffer (some operating systems generate data
alignment errors).
(*) Align types on their "natural boundaries". This means that
a type should be aligned on boundaries divisible by its size.
For example, a 2-byte integer should be aligned on a 2-byte
boundary, or a 4-byte integer should be aligned on a 4-byte
boundary. This alignment technique allows types to be directly
assigned to or from the data buffer. However, aligning the data
buffer for the next type is slightly more expensive since it
requires a few extra instructions to compute the alignment
boundary than our approach.
(2) Types are serialized into the message in their native representations.
We do not change the representation to either big endian or little
endian. Instead, the recipient of the message is responsible for
converting the data into its native representation. If both processes
have the same native representation, then the reordering of bytes can
be avoided (this is always the case with local processes). This policy
has been referred to as "reader makes right". That is, the reader is
responsible for making the incoming data into the "right"
representation.
(3) All arrays are represented by their size followed by their elements.
The size is always 4 bytes with 4 extra bytes of padding. In this way,
the elements always begin on an 8-byte boundary. The elements are packed
end to end with no padding.
(4) Strings are represented like arrays (size plus elements).
(5) Boolean are represented as a single byte, either 0 or 1.
(6) Complex objects that have optional elements or boolean elements, often
employ a single 4-byte bit mask that indicates which flags are true
and which elements are present in the network buffer. For example,
the CIMProperty representation has a bit mask that indicates whether
the property:
(*) is an array.
(*) is propagated.
(*) has qualifiers.
(*) has a non-empty references class .
(*) has a non-empty class origin.
This save considerable space. For example, if there are no qualifiers,
then we save 8 bytes that would be needed to represent an empty
qualifier array.
What is the layout of a binary message?
=======================================
Binary messages are comprised of a header followed by a body. The header has
the following elements:
(1) Magic number - contains 0xF00DFACE.
(2) Version number - 1 for the first version.
(3) Flags - flags used to represent boolean options of the message.
(4) Message ID - same as the message ID in a CIM message.
(5) Operation - an integer representing the CIM operation, given as follows:
(*) Invalid = 1
(*) GetClass = 2
(*) GetInstance = 3
(*) IndicationDelivery = 4 (binary version not implemented)
(*) DeleteClass = 5
(*) DeleteInstance = 6
(*) CreateClass = 7
(*) CreateInstance = 8
(*) ModifyClass = 9
(*) ModifyInstance = 10
(*) EnumerateClasses = 11
(*) EnumerateClassNames = 12
(*) EnumerateInstances = 13
(*) EnumerateInstanceNames = 14
(*) ExecQuery = 15
(*) Associators = 16
(*) AssociatorNames = 17
(*) References = 18
(*) ReferenceNames = 19
(*) GetProperty = 20
(*) SetProperty = 21
(*) GetQualifier = 22
(*) SetQualifier = 23
(*) DeleteQualifier = 24
(*) EnumerateQualifiers = 25
(*) InvokeMethod = 26
Does the binary protocol use HTTP?
==================================
Yes. The binary protocol uses the existing OpenPegasus HTTP infrastructure.
It preserve the same headers as the conventional protocol.
Does the binary protocol define new HTTP headers?
=================================================
Yes. It defines two new headers:
Content-Type: application/x-openpegasus
Accept: application/x-openpegasus
The first header is borne by both binary requests and binary responses.
It indicates that the content (payload) contains an OpenPegasus binary messages.
The second header is sent by a request and indicates that the client can
handle OpenPegasus binary responses.
The client can combine these headers to achieve 4 different behaviors:
(1) Binary request/Binary response:
Content-Type: application/x-openpegasus
Accept: application/x-openpegasus
(2) Binary request/XML response:
Content-Type: application/x-openpegasus
(3) XML request/binary response:
Accept: application/x-openpegasus
(4) XML request/XML response:
(omit both headers)
Only 1 and 4 can be achieved without minor code changes to OpenPegasus.
How does protocol versioning work?
==================================
The binary messages carries a version number in the header. This will be used
to support backwards compatibility with clients. The server must never be
modified to send version N+1 messages to version N clients.
Does the binary protocol support remote communication?
======================================================
Yes, although there is no official SDK interface for enabling it. To enable
it, one must obtain the CIMClientRep from the CIMClient instance and set
the following data members to true.
CIMClientRep::_binaryRequest
CIMClientRep::_binaryResponse
The following code fragment shows how one might do this in a program.
static void _SetBinaryRequest(CIMClient& client, Boolean flag)
{
CIMClientRep* rep = *(reinterpret_cast<CIMClientRep**>(&client));
rep->setBinaryRequest(flag);
}
static void _SetBinaryResponse(CIMClient& client, Boolean flag)
{
CIMClientRep* rep = *(reinterpret_cast<CIMClientRep**>(&client));
rep->setBinaryResponse(flag);
}
...
CIMClient client;
_SetBinaryRequest(client, true);
_SetBinaryResponse(client, true);
client.connect("localhost", 22000, String(), String());
This forces a remote binary connection.
What is on-demand de-serialization?
===================================
The binary protocol supports a feature we call "on-demand de-serialization".
When using out-of-process providers, data may be de-serialized unnecessarily.
Consider the following sequence of events.
(1) The client sends an EnumerateInstances request to the server.
(2) The server de-serializes the request.
(3) The server serializes the request for the provider agent.
(4) The provider agent de-serializes the request.
(5) The provider agent obtains response.
(6) The provider agent serializes the response for the server.
(7) The server de-serializes the request.
(8) The server serializes the request for the client.
(9) The client de-serializes the request.
The on-demand de-serialization feature eliminates the de-serialization of the
returned instances, saving them in a data buffer. Then in step 8, the data
buffer is sent to the client. This optimization avoids one de-serialization and
one serialization. For the EnumerateInstances operation, this optimization
alone doubles the speed of servicing this operation.
On-demand de-serialization is implemented for the following operations:
(1) EnumerateInstances
(2) GetInstance
(3) Associators
(4) ExecQuery
Where is the binary encoding/decoding code located?
===================================================
The source code for encoding and decoding binary requests and responses is
all included in a single module. The source files are located here:
pegasus/src/Pegaus/Common/BinaryCodec.h
pegasus/src/Pegaus/Common/BinaryCodec.cpp
The source code that implements the encoding of objects themselves is located
here:
pegasus/src/Pegaus/Common/CIMBuffer.h
pegasus/src/Pegaus/Common/CIMBuffer.cpp
How do you build OpenPegasus with binary protocol support?
==========================================================
To build OpenPegasus with binary protocol support, define the following
environment variable first:
$ export PEGASUS_ENABLE_PROTOCOL_BINARY=true
Are there further improvements that could be made to the protocol?
==================================================================
Yes, here are a few.
(1) Excessive copying is required to convert CIMBuffer objects into
Buffer objects. CIMBuffer could be reimplemented to use Buffer
as its representation. Then it would be possible to "swap" their
implementations rather than copying one to the other.
(2) It might have been better to align objects on their natural boundaries
rather than on 8-byte boundaries. This would probably reduce the
message size by 25% or so.
(3) The on-demand de-serialization should probably be extended to operations
other than just GetInstance and EnumerateInstances. For example, the
following operations would benefit the most.
(*) EnumerateInstanceNames
(*) AssociatorNames
(*) References
(*) ReferenceNames
(*) InvokeMethod
(4) The binary protocol should be extended to support the pull-operations
whenever they are implemented for XML.