summaryrefslogtreecommitdiff
path: root/storage/ndb/src/common/transporter/TransporterInternalDefinitions.hpp
blob: 49c8b04c74acff05a81476ec8d8e2d7058f4b64d (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
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
/* Copyright (C) 2003 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA */

#ifndef TransporterInternalDefinitions_H
#define TransporterInternalDefinitions_H

#if defined DEBUG_TRANSPORTER || defined VM_TRACE
#include <NdbOut.hpp>
#endif

#define NDB_TCP_TRANSPORTER

#ifdef HAVE_NDB_SHM
#define NDB_SHM_TRANSPORTER
#endif

#ifdef HAVE_NDB_SCI
#define NDB_SCI_TRANSPORTER
#endif

#ifdef DEBUG_TRANSPORTER
#define DEBUG(x) ndbout << x << endl
#else
#define DEBUG(x)
#endif

#if defined VM_TRACE || defined DEBUG_TRANSPORTER
#define WARNING(X) ndbout << X << endl;
#else
#define WARNING(X)
#endif

// Calculate a checksum
inline
Uint32
computeChecksum(const Uint32 * const startOfData, int nWords) {
  Uint32 chksum = startOfData[0];
  for (int i=1; i < nWords; i++)
    chksum ^= startOfData[i];
  return chksum;
}

struct Protocol6 {
  Uint32 word1;
  Uint32 word2;
  Uint32 word3;
  
/**
 *
 * b = Byte order           -  4 Bits (Note 1 significant bit)
 * g = GSN                  - 16 Bits
 * p = Prio                 -  2 Bits
 * c = Checksum included    -  1 Bit
 * z = Compression          -  1 Bit
 * v = Version id           -  4 Bits
 * i = Signal id included   -  1 Bit
 * m = Message length       - 16 Bits (0-65536) (In word -> 0-256k bytes)
 * d = Signal data length   -  5 Bits (0-31)
 * t = trace                -  6 Bits (0-63)
 * r = Recievers block no   - 16 Bits
 * s = Senders block no     - 16 Bits
 * u = Unused               -  7 Bits
 * f = FragmentInfo1        -  1 Bit
 * h = FragmentInfo2        -  1 bit
 * n = No of segments       -  2 Bits

 * Word 1
 *
 *
 *           1111111111222222222233
 * 01234567890123456789012345678901
 * bfizcppbmmmmmmmmmmmmmmmmbhdddddb

 **
 * Word 2
 *
 *           1111111111222222222233
 * 01234567890123456789012345678901
 * ggggggggggggggggvvvvttttttnn  
 
 **
 * Word 3
 *
 *           1111111111222222222233
 * 01234567890123456789012345678901
 * rrrrrrrrrrrrrrrrssssssssssssssss

 **
 * Word 4 (Optional Signal Id)
 */
  
  /**
   * 0 = Big endian (Sparc), 1 = Little endian (Intel)
   */
  static Uint32 getByteOrder       (const Uint32 & word1);
  static Uint32 getCompressed      (const Uint32 & word1);
  static Uint32 getSignalIdIncluded(const Uint32 & word1);
  static Uint32 getCheckSumIncluded(const Uint32 & word1);
  static Uint32 getPrio            (const Uint32 & word1);
  static Uint32 getMessageLength   (const Uint32 & word1);

  static void setByteOrder       (Uint32 & word1, Uint32 byteOrder);
  static void setCompressed      (Uint32 & word1, Uint32 compressed);
  static void setSignalIdIncluded(Uint32 & word1, Uint32 signalId);
  static void setCheckSumIncluded(Uint32 & word1, Uint32 checkSum);
  static void setPrio            (Uint32 & word1, Uint32 prio);
  static void setMessageLength   (Uint32 & word1, Uint32 messageLen);
  
  static void createSignalHeader(SignalHeader * const dst,
				 const Uint32 & word1, 
				 const Uint32 & word2, 
				 const Uint32 & word3);
  
  static void createProtocol6Header(Uint32 & word1, 
				    Uint32 & word2, 
				    Uint32 & word3,
				    const SignalHeader * const src);
};  

#define WORD1_BYTEORDER_MASK   (0x81000081)
#define WORD1_SIGNALID_MASK    (0x00000004)
#define WORD1_COMPRESSED_MASK  (0x00000008)
#define WORD1_CHECKSUM_MASK    (0x00000010)
#define WORD1_PRIO_MASK        (0x00000060)
#define WORD1_MESSAGELEN_MASK  (0x00FFFF00)
#define WORD1_SIGNAL_LEN_MASK  (0x7C000000)
#define WORD1_FRAG_INF_MASK    (0x00000002)
#define WORD1_FRAG_INF2_MASK   (0x02000000)

#define WORD1_FRAG_INF_SHIFT   (1)
#define WORD1_SIGNALID_SHIFT   (2)
#define WORD1_COMPRESSED_SHIFT (3)
#define WORD1_CHECKSUM_SHIFT   (4)
#define WORD1_PRIO_SHIFT       (5)
#define WORD1_MESSAGELEN_SHIFT (8)
#define WORD1_FRAG_INF2_SHIFT  (25)
#define WORD1_SIGNAL_LEN_SHIFT (26)

#define WORD2_VERID_GSN_MASK   (0x000FFFFF)
#define WORD2_TRACE_MASK       (0x03f00000)
#define WORD2_SEC_COUNT_MASK   (0x0c000000)

#define WORD2_TRACE_SHIFT      (20)
#define WORD2_SEC_COUNT_SHIFT  (26)

#define WORD3_SENDER_MASK      (0x0000FFFF)
#define WORD3_RECEIVER_MASK    (0xFFFF0000)

#define WORD3_RECEIVER_SHIFT   (16)

inline
Uint32
Protocol6::getByteOrder(const Uint32 & word1){
  return word1 & 1;
}

inline
Uint32
Protocol6::getCompressed(const Uint32 & word1){
  return (word1 & WORD1_COMPRESSED_MASK) >> WORD1_COMPRESSED_SHIFT;
}

inline
Uint32
Protocol6::getSignalIdIncluded(const Uint32 & word1){
  return (word1 & WORD1_SIGNALID_MASK) >> WORD1_SIGNALID_SHIFT;
}

inline
Uint32
Protocol6::getCheckSumIncluded(const Uint32 & word1){
  return (word1 & WORD1_CHECKSUM_MASK) >> WORD1_CHECKSUM_SHIFT;
}

inline
Uint32
Protocol6::getMessageLength(const Uint32 & word1){
  return (word1 & WORD1_MESSAGELEN_MASK) >> WORD1_MESSAGELEN_SHIFT;
}

inline
Uint32
Protocol6::getPrio(const Uint32 & word1){
  return (word1 & WORD1_PRIO_MASK) >> WORD1_PRIO_SHIFT;
}

inline
void
Protocol6::setByteOrder(Uint32 & word1, Uint32 byteOrder){
  Uint32 tmp = byteOrder;
  tmp |= (tmp << 7);
  tmp |= (tmp << 24);
  word1 |= (tmp & WORD1_BYTEORDER_MASK);
}

inline
void
Protocol6::setCompressed(Uint32 & word1, Uint32 compressed){
  word1 |= ((compressed << WORD1_COMPRESSED_SHIFT) & WORD1_COMPRESSED_MASK);
}

inline
void
Protocol6::setSignalIdIncluded(Uint32 & word1, Uint32 signalId){
  word1 |= ((signalId << WORD1_SIGNALID_SHIFT) & WORD1_SIGNALID_MASK);
}

inline
void
Protocol6::setCheckSumIncluded(Uint32 & word1, Uint32 checkSum){
  word1 |= ((checkSum << WORD1_CHECKSUM_SHIFT) & WORD1_CHECKSUM_MASK);
}

inline
void
Protocol6::setMessageLength(Uint32 & word1, Uint32 messageLen){
  word1 |= ((messageLen << WORD1_MESSAGELEN_SHIFT) & WORD1_MESSAGELEN_MASK);
}

inline
void
Protocol6::setPrio(Uint32 & word1, Uint32 prio){
  word1 |= ((prio << WORD1_PRIO_SHIFT) & WORD1_PRIO_MASK);
}

inline
void
Protocol6::createSignalHeader(SignalHeader * const dst,
			      const Uint32 & word1, 
			      const Uint32 & word2, 
			      const Uint32 & word3){
  
  Uint32 signal_len = (word1 & WORD1_SIGNAL_LEN_MASK)>> WORD1_SIGNAL_LEN_SHIFT;
  Uint32 fragInfo1  = (word1 & WORD1_FRAG_INF_MASK) >> (WORD1_FRAG_INF_SHIFT-1);
  Uint32 fragInfo2  = (word1 & WORD1_FRAG_INF2_MASK) >> (WORD1_FRAG_INF2_SHIFT);
  Uint32 trace      = (word2 & WORD2_TRACE_MASK) >> WORD2_TRACE_SHIFT;
  Uint32 verid_gsn  = (word2 & WORD2_VERID_GSN_MASK);
  Uint32 secCount   = (word2 & WORD2_SEC_COUNT_MASK) >> WORD2_SEC_COUNT_SHIFT;
  
  dst->theTrace              = trace;
  dst->m_noOfSections        = secCount;
  dst->m_fragmentInfo        = fragInfo1 | fragInfo2;
  
  dst->theLength             = signal_len;
  dst->theVerId_signalNumber = verid_gsn;
  
  Uint32 sBlockNum  = (word3 & WORD3_SENDER_MASK);
  Uint32 rBlockNum  = (word3 & WORD3_RECEIVER_MASK) >> WORD3_RECEIVER_SHIFT;
  
  dst->theSendersBlockRef      = sBlockNum;
  dst->theReceiversBlockNumber = rBlockNum;
}

inline
void
Protocol6::createProtocol6Header(Uint32 & word1, 
				 Uint32 & word2, 
				 Uint32 & word3,
				 const SignalHeader * const src){
  const Uint32 signal_len = src->theLength;
  const Uint32 fragInfo   = src->m_fragmentInfo;
  const Uint32 fragInfo1 = (fragInfo & 2);
  const Uint32 fragInfo2 = (fragInfo & 1);
  
  const Uint32 trace      = src->theTrace;
  const Uint32 verid_gsn  = src->theVerId_signalNumber;
  const Uint32 secCount   = src->m_noOfSections;
  
  word1 |= ((signal_len << WORD1_SIGNAL_LEN_SHIFT) & WORD1_SIGNAL_LEN_MASK);
  word1 |= ((fragInfo1 << (WORD1_FRAG_INF_SHIFT-1)) & WORD1_FRAG_INF_MASK);
  word1 |= ((fragInfo2 << WORD1_FRAG_INF2_SHIFT) & WORD1_FRAG_INF2_MASK);

  word2 |= ((trace << WORD2_TRACE_SHIFT) & WORD2_TRACE_MASK);
  word2 |= (verid_gsn & WORD2_VERID_GSN_MASK);
  word2 |= ((secCount << WORD2_SEC_COUNT_SHIFT) & WORD2_SEC_COUNT_MASK);
  
  Uint32 sBlockNum  = src->theSendersBlockRef ;
  Uint32 rBlockNum  = src->theReceiversBlockNumber ;
  
  word3 |= (sBlockNum & WORD3_SENDER_MASK);
  word3 |= ((rBlockNum << WORD3_RECEIVER_SHIFT) & WORD3_RECEIVER_MASK);
}

// Define of TransporterInternalDefinitions_H
#endif