MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TransporterInternalDefinitions.hpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef TransporterInternalDefinitions_H
20 #define TransporterInternalDefinitions_H
21 
22 #if defined DEBUG_TRANSPORTER || defined VM_TRACE
23 #include <NdbOut.hpp>
24 #endif
25 
26 #define NDB_TCP_TRANSPORTER
27 
28 #ifdef HAVE_NDB_SHM
29 #define NDB_SHM_TRANSPORTER
30 #endif
31 
32 #ifdef HAVE_NDB_SCI
33 #define NDB_SCI_TRANSPORTER
34 #endif
35 
36 #ifdef DEBUG_TRANSPORTER
37 #define DEBUG(x) ndbout << x << endl
38 #else
39 #define DEBUG(x)
40 #endif
41 
42 #if defined VM_TRACE || defined DEBUG_TRANSPORTER
43 #define WARNING(X) ndbout << X << endl;
44 #else
45 #define WARNING(X)
46 #endif
47 
48 // Calculate a checksum
49 inline
50 Uint32
51 computeChecksum(const Uint32 * const startOfData, int nWords) {
52  Uint32 chksum = startOfData[0];
53  for (int i=1; i < nWords; i++)
54  chksum ^= startOfData[i];
55  return chksum;
56 }
57 
58 struct Protocol6 {
59  Uint32 word1;
60  Uint32 word2;
61  Uint32 word3;
62 
110  static Uint32 getByteOrder (const Uint32 & word1);
111  static Uint32 getCompressed (const Uint32 & word1);
112  static Uint32 getSignalIdIncluded(const Uint32 & word1);
113  static Uint32 getCheckSumIncluded(const Uint32 & word1);
114  static Uint32 getPrio (const Uint32 & word1);
115  static Uint32 getMessageLength (const Uint32 & word1);
116 
117  static void setByteOrder (Uint32 & word1, Uint32 byteOrder);
118  static void setCompressed (Uint32 & word1, Uint32 compressed);
119  static void setSignalIdIncluded(Uint32 & word1, Uint32 signalId);
120  static void setCheckSumIncluded(Uint32 & word1, Uint32 checkSum);
121  static void setPrio (Uint32 & word1, Uint32 prio);
122  static void setMessageLength (Uint32 & word1, Uint32 messageLen);
123 
124  static void createSignalHeader(SignalHeader * const dst,
125  const Uint32 & word1,
126  const Uint32 & word2,
127  const Uint32 & word3);
128 
129  static void createProtocol6Header(Uint32 & word1,
130  Uint32 & word2,
131  Uint32 & word3,
132  const SignalHeader * const src);
133 };
134 
135 #define WORD1_BYTEORDER_MASK (0x81000081)
136 #define WORD1_SIGNALID_MASK (0x00000004)
137 #define WORD1_COMPRESSED_MASK (0x00000008)
138 #define WORD1_CHECKSUM_MASK (0x00000010)
139 #define WORD1_PRIO_MASK (0x00000060)
140 #define WORD1_MESSAGELEN_MASK (0x00FFFF00)
141 #define WORD1_SIGNAL_LEN_MASK (0x7C000000)
142 #define WORD1_FRAG_INF_MASK (0x00000002)
143 #define WORD1_FRAG_INF2_MASK (0x02000000)
144 
145 #define WORD1_FRAG_INF_SHIFT (1)
146 #define WORD1_SIGNALID_SHIFT (2)
147 #define WORD1_COMPRESSED_SHIFT (3)
148 #define WORD1_CHECKSUM_SHIFT (4)
149 #define WORD1_PRIO_SHIFT (5)
150 #define WORD1_MESSAGELEN_SHIFT (8)
151 #define WORD1_FRAG_INF2_SHIFT (25)
152 #define WORD1_SIGNAL_LEN_SHIFT (26)
153 
154 #define WORD2_VERID_GSN_MASK (0x000FFFFF)
155 #define WORD2_TRACE_MASK (0x03f00000)
156 #define WORD2_SEC_COUNT_MASK (0x0c000000)
157 
158 #define WORD2_TRACE_SHIFT (20)
159 #define WORD2_SEC_COUNT_SHIFT (26)
160 
161 #define WORD3_SENDER_MASK (0x0000FFFF)
162 #define WORD3_RECEIVER_MASK (0xFFFF0000)
163 
164 #define WORD3_RECEIVER_SHIFT (16)
165 
166 inline
167 Uint32
168 Protocol6::getByteOrder(const Uint32 & word1){
169  return word1 & 1;
170 }
171 
172 inline
173 Uint32
174 Protocol6::getCompressed(const Uint32 & word1){
175  return (word1 & WORD1_COMPRESSED_MASK) >> WORD1_COMPRESSED_SHIFT;
176 }
177 
178 inline
179 Uint32
180 Protocol6::getSignalIdIncluded(const Uint32 & word1){
181  return (word1 & WORD1_SIGNALID_MASK) >> WORD1_SIGNALID_SHIFT;
182 }
183 
184 inline
185 Uint32
186 Protocol6::getCheckSumIncluded(const Uint32 & word1){
187  return (word1 & WORD1_CHECKSUM_MASK) >> WORD1_CHECKSUM_SHIFT;
188 }
189 
190 inline
191 Uint32
192 Protocol6::getMessageLength(const Uint32 & word1){
193  return (word1 & WORD1_MESSAGELEN_MASK) >> WORD1_MESSAGELEN_SHIFT;
194 }
195 
196 inline
197 Uint32
198 Protocol6::getPrio(const Uint32 & word1){
199  return (word1 & WORD1_PRIO_MASK) >> WORD1_PRIO_SHIFT;
200 }
201 
202 inline
203 void
204 Protocol6::setByteOrder(Uint32 & word1, Uint32 byteOrder){
205  Uint32 tmp = byteOrder;
206  tmp |= (tmp << 7);
207  tmp |= (tmp << 24);
208  word1 |= (tmp & WORD1_BYTEORDER_MASK);
209 }
210 
211 inline
212 void
213 Protocol6::setCompressed(Uint32 & word1, Uint32 compressed){
214  word1 |= ((compressed << WORD1_COMPRESSED_SHIFT) & WORD1_COMPRESSED_MASK);
215 }
216 
217 inline
218 void
219 Protocol6::setSignalIdIncluded(Uint32 & word1, Uint32 signalId){
220  word1 |= ((signalId << WORD1_SIGNALID_SHIFT) & WORD1_SIGNALID_MASK);
221 }
222 
223 inline
224 void
225 Protocol6::setCheckSumIncluded(Uint32 & word1, Uint32 checkSum){
226  word1 |= ((checkSum << WORD1_CHECKSUM_SHIFT) & WORD1_CHECKSUM_MASK);
227 }
228 
229 inline
230 void
231 Protocol6::setMessageLength(Uint32 & word1, Uint32 messageLen){
232  word1 |= ((messageLen << WORD1_MESSAGELEN_SHIFT) & WORD1_MESSAGELEN_MASK);
233 }
234 
235 inline
236 void
237 Protocol6::setPrio(Uint32 & word1, Uint32 prio){
238  word1 |= ((prio << WORD1_PRIO_SHIFT) & WORD1_PRIO_MASK);
239 }
240 
241 inline
242 void
243 Protocol6::createSignalHeader(SignalHeader * const dst,
244  const Uint32 & word1,
245  const Uint32 & word2,
246  const Uint32 & word3){
247 
248  Uint32 signal_len = (word1 & WORD1_SIGNAL_LEN_MASK)>> WORD1_SIGNAL_LEN_SHIFT;
249  Uint32 fragInfo1 = (word1 & WORD1_FRAG_INF_MASK) >> (WORD1_FRAG_INF_SHIFT-1);
250  Uint32 fragInfo2 = (word1 & WORD1_FRAG_INF2_MASK) >> (WORD1_FRAG_INF2_SHIFT);
251  Uint32 trace = (word2 & WORD2_TRACE_MASK) >> WORD2_TRACE_SHIFT;
252  Uint32 verid_gsn = (word2 & WORD2_VERID_GSN_MASK);
253  Uint32 secCount = (word2 & WORD2_SEC_COUNT_MASK) >> WORD2_SEC_COUNT_SHIFT;
254 
255  dst->theTrace = trace;
256  dst->m_noOfSections = secCount;
257  dst->m_fragmentInfo = fragInfo1 | fragInfo2;
258 
259  dst->theLength = signal_len;
260  dst->theVerId_signalNumber = verid_gsn;
261 
262  Uint32 sBlockNum = (word3 & WORD3_SENDER_MASK);
263  Uint32 rBlockNum = (word3 & WORD3_RECEIVER_MASK) >> WORD3_RECEIVER_SHIFT;
264 
265  dst->theSendersBlockRef = sBlockNum;
266  dst->theReceiversBlockNumber = rBlockNum;
267 }
268 
269 inline
270 void
271 Protocol6::createProtocol6Header(Uint32 & word1,
272  Uint32 & word2,
273  Uint32 & word3,
274  const SignalHeader * const src){
275  const Uint32 signal_len = src->theLength;
276  const Uint32 fragInfo = src->m_fragmentInfo;
277  const Uint32 fragInfo1 = (fragInfo & 2);
278  const Uint32 fragInfo2 = (fragInfo & 1);
279 
280  const Uint32 trace = src->theTrace;
281  const Uint32 verid_gsn = src->theVerId_signalNumber;
282  const Uint32 secCount = src->m_noOfSections;
283 
284  word1 |= ((signal_len << WORD1_SIGNAL_LEN_SHIFT) & WORD1_SIGNAL_LEN_MASK);
285  word1 |= ((fragInfo1 << (WORD1_FRAG_INF_SHIFT-1)) & WORD1_FRAG_INF_MASK);
286  word1 |= ((fragInfo2 << WORD1_FRAG_INF2_SHIFT) & WORD1_FRAG_INF2_MASK);
287 
288  word2 |= ((trace << WORD2_TRACE_SHIFT) & WORD2_TRACE_MASK);
289  word2 |= (verid_gsn & WORD2_VERID_GSN_MASK);
290  word2 |= ((secCount << WORD2_SEC_COUNT_SHIFT) & WORD2_SEC_COUNT_MASK);
291 
292  Uint32 sBlockNum = src->theSendersBlockRef ;
293  Uint32 rBlockNum = src->theReceiversBlockNumber ;
294 
295  word3 |= (sBlockNum & WORD3_SENDER_MASK);
296  word3 |= ((rBlockNum << WORD3_RECEIVER_SHIFT) & WORD3_RECEIVER_MASK);
297 }
298 
299 // Define of TransporterInternalDefinitions_H
300 #endif