~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/src/common/transporter/TransporterInternalDefinitions.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifndef TransporterInternalDefinitions_H
 
17
#define TransporterInternalDefinitions_H
 
18
 
 
19
#if defined DEBUG_TRANSPORTER || defined VM_TRACE
 
20
#include <NdbOut.hpp>
 
21
#endif
 
22
 
 
23
#define NDB_TCP_TRANSPORTER
 
24
 
 
25
#ifdef HAVE_NDB_SHM
 
26
#define NDB_SHM_TRANSPORTER
 
27
#endif
 
28
 
 
29
#ifdef HAVE_NDB_SCI
 
30
#define NDB_SCI_TRANSPORTER
 
31
#endif
 
32
 
 
33
#ifdef DEBUG_TRANSPORTER
 
34
#define DEBUG(x) ndbout << x << endl
 
35
#else
 
36
#define DEBUG(x)
 
37
#endif
 
38
 
 
39
#if defined VM_TRACE || defined DEBUG_TRANSPORTER
 
40
#define WARNING(X) ndbout << X << endl;
 
41
#else
 
42
#define WARNING(X)
 
43
#endif
 
44
 
 
45
// Calculate a checksum
 
46
inline
 
47
Uint32
 
48
computeChecksum(const Uint32 * const startOfData, int nWords) {
 
49
  Uint32 chksum = startOfData[0];
 
50
  for (int i=1; i < nWords; i++)
 
51
    chksum ^= startOfData[i];
 
52
  return chksum;
 
53
}
 
54
 
 
55
struct Protocol6 {
 
56
  Uint32 word1;
 
57
  Uint32 word2;
 
58
  Uint32 word3;
 
59
  
 
60
/**
 
61
 *
 
62
 * b = Byte order           -  4 Bits (Note 1 significant bit)
 
63
 * g = GSN                  - 16 Bits
 
64
 * p = Prio                 -  2 Bits
 
65
 * c = Checksum included    -  1 Bit
 
66
 * z = Compression          -  1 Bit
 
67
 * v = Version id           -  4 Bits
 
68
 * i = Signal id included   -  1 Bit
 
69
 * m = Message length       - 16 Bits (0-65536) (In word -> 0-256k bytes)
 
70
 * d = Signal data length   -  5 Bits (0-31)
 
71
 * t = trace                -  6 Bits (0-63)
 
72
 * r = Recievers block no   - 16 Bits
 
73
 * s = Senders block no     - 16 Bits
 
74
 * u = Unused               -  7 Bits
 
75
 * f = FragmentInfo1        -  1 Bit
 
76
 * h = FragmentInfo2        -  1 bit
 
77
 * n = No of segments       -  2 Bits
 
78
 
 
79
 * Word 1
 
80
 *
 
81
 *
 
82
 *           1111111111222222222233
 
83
 * 01234567890123456789012345678901
 
84
 * bfizcppbmmmmmmmmmmmmmmmmbhdddddb
 
85
 
 
86
 **
 
87
 * Word 2
 
88
 *
 
89
 *           1111111111222222222233
 
90
 * 01234567890123456789012345678901
 
91
 * ggggggggggggggggvvvvttttttnn  
 
92
 
 
93
 **
 
94
 * Word 3
 
95
 *
 
96
 *           1111111111222222222233
 
97
 * 01234567890123456789012345678901
 
98
 * rrrrrrrrrrrrrrrrssssssssssssssss
 
99
 
 
100
 **
 
101
 * Word 4 (Optional Signal Id)
 
102
 */
 
103
  
 
104
  /**
 
105
   * 0 = Big endian (Sparc), 1 = Little endian (Intel)
 
106
   */
 
107
  static Uint32 getByteOrder       (const Uint32 & word1);
 
108
  static Uint32 getCompressed      (const Uint32 & word1);
 
109
  static Uint32 getSignalIdIncluded(const Uint32 & word1);
 
110
  static Uint32 getCheckSumIncluded(const Uint32 & word1);
 
111
  static Uint32 getPrio            (const Uint32 & word1);
 
112
  static Uint32 getMessageLength   (const Uint32 & word1);
 
113
 
 
114
  static void setByteOrder       (Uint32 & word1, Uint32 byteOrder);
 
115
  static void setCompressed      (Uint32 & word1, Uint32 compressed);
 
116
  static void setSignalIdIncluded(Uint32 & word1, Uint32 signalId);
 
117
  static void setCheckSumIncluded(Uint32 & word1, Uint32 checkSum);
 
118
  static void setPrio            (Uint32 & word1, Uint32 prio);
 
119
  static void setMessageLength   (Uint32 & word1, Uint32 messageLen);
 
120
  
 
121
  static void createSignalHeader(SignalHeader * const dst,
 
122
                                 const Uint32 & word1, 
 
123
                                 const Uint32 & word2, 
 
124
                                 const Uint32 & word3);
 
125
  
 
126
  static void createProtocol6Header(Uint32 & word1, 
 
127
                                    Uint32 & word2, 
 
128
                                    Uint32 & word3,
 
129
                                    const SignalHeader * const src);
 
130
};  
 
131
 
 
132
#define WORD1_BYTEORDER_MASK   (0x81000081)
 
133
#define WORD1_SIGNALID_MASK    (0x00000004)
 
134
#define WORD1_COMPRESSED_MASK  (0x00000008)
 
135
#define WORD1_CHECKSUM_MASK    (0x00000010)
 
136
#define WORD1_PRIO_MASK        (0x00000060)
 
137
#define WORD1_MESSAGELEN_MASK  (0x00FFFF00)
 
138
#define WORD1_SIGNAL_LEN_MASK  (0x7C000000)
 
139
#define WORD1_FRAG_INF_MASK    (0x00000002)
 
140
#define WORD1_FRAG_INF2_MASK   (0x02000000)
 
141
 
 
142
#define WORD1_FRAG_INF_SHIFT   (1)
 
143
#define WORD1_SIGNALID_SHIFT   (2)
 
144
#define WORD1_COMPRESSED_SHIFT (3)
 
145
#define WORD1_CHECKSUM_SHIFT   (4)
 
146
#define WORD1_PRIO_SHIFT       (5)
 
147
#define WORD1_MESSAGELEN_SHIFT (8)
 
148
#define WORD1_FRAG_INF2_SHIFT  (25)
 
149
#define WORD1_SIGNAL_LEN_SHIFT (26)
 
150
 
 
151
#define WORD2_VERID_GSN_MASK   (0x000FFFFF)
 
152
#define WORD2_TRACE_MASK       (0x03f00000)
 
153
#define WORD2_SEC_COUNT_MASK   (0x0c000000)
 
154
 
 
155
#define WORD2_TRACE_SHIFT      (20)
 
156
#define WORD2_SEC_COUNT_SHIFT  (26)
 
157
 
 
158
#define WORD3_SENDER_MASK      (0x0000FFFF)
 
159
#define WORD3_RECEIVER_MASK    (0xFFFF0000)
 
160
 
 
161
#define WORD3_RECEIVER_SHIFT   (16)
 
162
 
 
163
inline
 
164
Uint32
 
165
Protocol6::getByteOrder(const Uint32 & word1){
 
166
  return word1 & 1;
 
167
}
 
168
 
 
169
inline
 
170
Uint32
 
171
Protocol6::getCompressed(const Uint32 & word1){
 
172
  return (word1 & WORD1_COMPRESSED_MASK) >> WORD1_COMPRESSED_SHIFT;
 
173
}
 
174
 
 
175
inline
 
176
Uint32
 
177
Protocol6::getSignalIdIncluded(const Uint32 & word1){
 
178
  return (word1 & WORD1_SIGNALID_MASK) >> WORD1_SIGNALID_SHIFT;
 
179
}
 
180
 
 
181
inline
 
182
Uint32
 
183
Protocol6::getCheckSumIncluded(const Uint32 & word1){
 
184
  return (word1 & WORD1_CHECKSUM_MASK) >> WORD1_CHECKSUM_SHIFT;
 
185
}
 
186
 
 
187
inline
 
188
Uint32
 
189
Protocol6::getMessageLength(const Uint32 & word1){
 
190
  return (word1 & WORD1_MESSAGELEN_MASK) >> WORD1_MESSAGELEN_SHIFT;
 
191
}
 
192
 
 
193
inline
 
194
Uint32
 
195
Protocol6::getPrio(const Uint32 & word1){
 
196
  return (word1 & WORD1_PRIO_MASK) >> WORD1_PRIO_SHIFT;
 
197
}
 
198
 
 
199
inline
 
200
void
 
201
Protocol6::setByteOrder(Uint32 & word1, Uint32 byteOrder){
 
202
  Uint32 tmp = byteOrder;
 
203
  tmp |= (tmp << 7);
 
204
  tmp |= (tmp << 24);
 
205
  word1 |= (tmp & WORD1_BYTEORDER_MASK);
 
206
}
 
207
 
 
208
inline
 
209
void
 
210
Protocol6::setCompressed(Uint32 & word1, Uint32 compressed){
 
211
  word1 |= ((compressed << WORD1_COMPRESSED_SHIFT) & WORD1_COMPRESSED_MASK);
 
212
}
 
213
 
 
214
inline
 
215
void
 
216
Protocol6::setSignalIdIncluded(Uint32 & word1, Uint32 signalId){
 
217
  word1 |= ((signalId << WORD1_SIGNALID_SHIFT) & WORD1_SIGNALID_MASK);
 
218
}
 
219
 
 
220
inline
 
221
void
 
222
Protocol6::setCheckSumIncluded(Uint32 & word1, Uint32 checkSum){
 
223
  word1 |= ((checkSum << WORD1_CHECKSUM_SHIFT) & WORD1_CHECKSUM_MASK);
 
224
}
 
225
 
 
226
inline
 
227
void
 
228
Protocol6::setMessageLength(Uint32 & word1, Uint32 messageLen){
 
229
  word1 |= ((messageLen << WORD1_MESSAGELEN_SHIFT) & WORD1_MESSAGELEN_MASK);
 
230
}
 
231
 
 
232
inline
 
233
void
 
234
Protocol6::setPrio(Uint32 & word1, Uint32 prio){
 
235
  word1 |= ((prio << WORD1_PRIO_SHIFT) & WORD1_PRIO_MASK);
 
236
}
 
237
 
 
238
inline
 
239
void
 
240
Protocol6::createSignalHeader(SignalHeader * const dst,
 
241
                              const Uint32 & word1, 
 
242
                              const Uint32 & word2, 
 
243
                              const Uint32 & word3){
 
244
  
 
245
  Uint32 signal_len = (word1 & WORD1_SIGNAL_LEN_MASK)>> WORD1_SIGNAL_LEN_SHIFT;
 
246
  Uint32 fragInfo1  = (word1 & WORD1_FRAG_INF_MASK) >> (WORD1_FRAG_INF_SHIFT-1);
 
247
  Uint32 fragInfo2  = (word1 & WORD1_FRAG_INF2_MASK) >> (WORD1_FRAG_INF2_SHIFT);
 
248
  Uint32 trace      = (word2 & WORD2_TRACE_MASK) >> WORD2_TRACE_SHIFT;
 
249
  Uint32 verid_gsn  = (word2 & WORD2_VERID_GSN_MASK);
 
250
  Uint32 secCount   = (word2 & WORD2_SEC_COUNT_MASK) >> WORD2_SEC_COUNT_SHIFT;
 
251
  
 
252
  dst->theTrace              = trace;
 
253
  dst->m_noOfSections        = secCount;
 
254
  dst->m_fragmentInfo        = fragInfo1 | fragInfo2;
 
255
  
 
256
  dst->theLength             = signal_len;
 
257
  dst->theVerId_signalNumber = verid_gsn;
 
258
  
 
259
  Uint32 sBlockNum  = (word3 & WORD3_SENDER_MASK);
 
260
  Uint32 rBlockNum  = (word3 & WORD3_RECEIVER_MASK) >> WORD3_RECEIVER_SHIFT;
 
261
  
 
262
  dst->theSendersBlockRef      = sBlockNum;
 
263
  dst->theReceiversBlockNumber = rBlockNum;
 
264
}
 
265
 
 
266
inline
 
267
void
 
268
Protocol6::createProtocol6Header(Uint32 & word1, 
 
269
                                 Uint32 & word2, 
 
270
                                 Uint32 & word3,
 
271
                                 const SignalHeader * const src){
 
272
  const Uint32 signal_len = src->theLength;
 
273
  const Uint32 fragInfo   = src->m_fragmentInfo;
 
274
  const Uint32 fragInfo1 = (fragInfo & 2);
 
275
  const Uint32 fragInfo2 = (fragInfo & 1);
 
276
  
 
277
  const Uint32 trace      = src->theTrace;
 
278
  const Uint32 verid_gsn  = src->theVerId_signalNumber;
 
279
  const Uint32 secCount   = src->m_noOfSections;
 
280
  
 
281
  word1 |= ((signal_len << WORD1_SIGNAL_LEN_SHIFT) & WORD1_SIGNAL_LEN_MASK);
 
282
  word1 |= ((fragInfo1 << (WORD1_FRAG_INF_SHIFT-1)) & WORD1_FRAG_INF_MASK);
 
283
  word1 |= ((fragInfo2 << WORD1_FRAG_INF2_SHIFT) & WORD1_FRAG_INF2_MASK);
 
284
 
 
285
  word2 |= ((trace << WORD2_TRACE_SHIFT) & WORD2_TRACE_MASK);
 
286
  word2 |= (verid_gsn & WORD2_VERID_GSN_MASK);
 
287
  word2 |= ((secCount << WORD2_SEC_COUNT_SHIFT) & WORD2_SEC_COUNT_MASK);
 
288
  
 
289
  Uint32 sBlockNum  = src->theSendersBlockRef ;
 
290
  Uint32 rBlockNum  = src->theReceiversBlockNumber ;
 
291
  
 
292
  word3 |= (sBlockNum & WORD3_SENDER_MASK);
 
293
  word3 |= ((rBlockNum << WORD3_RECEIVER_SHIFT) & WORD3_RECEIVER_MASK);
 
294
}
 
295
 
 
296
// Define of TransporterInternalDefinitions_H
 
297
#endif