1 /*
2    Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #ifndef TransporterDefinitions_H
26 #define TransporterDefinitions_H
27 
28 #include <ndb_global.h>
29 #include <kernel_types.h>
30 #include <NdbOut.hpp>
31 
32 /**
33  * The maximum number of transporters allowed
34  * A maximum is needed to be able to allocate the array of transporters
35  */
36 const int MAX_NTRANSPORTERS = 256;
37 
38 /**
39  * The sendbuffer limit after which the contents of the buffer is sent
40  */
41 const int TCP_SEND_LIMIT = 64000;
42 
43 enum SendStatus {
44   SEND_OK = 0,
45   SEND_BLOCKED = 1,
46   SEND_DISCONNECTED = 2,
47   SEND_BUFFER_FULL = 3,
48   SEND_MESSAGE_TOO_BIG = 4,
49   SEND_UNKNOWN_NODE = 5
50 };
51 
52 enum TransporterType {
53   tt_TCP_TRANSPORTER = 1,
54   tt_SCI_TRANSPORTER = 2,
55   tt_SHM_TRANSPORTER = 3
56 };
57 
58 /**
59  * Maximum message sizes
60  * ---------------------
61  * Maximum byte sizes for sent and received messages.
62  * The maximum send message size is temporarily smaller than
63  * the maximum receive message size to support online
64  * upgrade
65  * Maximum received size increased in :
66  *   mysql-5.1-telco-6.3.18 from 16516 bytes to 32768
67  * Maximum send size increased in :
68  *   mysql-5.1-telco-6.4.0 from 16516 bytes to 32768
69  *
70  * Therefore mysql-5.1-telco-6.4.0 cannot safely communicate
71  * with nodes at versions lower than mysql-5.1-telco-6.3.18
72  *
73  */
74 const Uint32 MAX_RECV_MESSAGE_BYTESIZE = 32768;
75 const Uint32 MAX_SEND_MESSAGE_BYTESIZE = 32768;
76 
77 /**
78  * TransporterConfiguration
79  *
80  * used for setting up a transporter. the union member specific is for
81  * information specific to a transporter type.
82  */
83 struct TransporterConfiguration {
84   Int32 s_port; // negative port number implies dynamic port
85   const char *remoteHostName;
86   const char *localHostName;
87   NodeId remoteNodeId;
88   NodeId localNodeId;
89   NodeId serverNodeId;
90   bool checksum;
91   bool signalId;
92   bool isMgmConnection; // is a mgm connection, requires transforming
93   TransporterType type;
94 
95   union { // Transporter specific configuration information
96 
97     struct {
98       Uint32 sendBufferSize;     // Size of SendBuffer of priority B
99       Uint32 maxReceiveSize;     // Maximum no of bytes to receive
100       Uint32 tcpSndBufSize;
101       Uint32 tcpRcvBufSize;
102       Uint32 tcpMaxsegSize;
103       Uint32 tcpOverloadLimit;
104     } tcp;
105 
106     struct {
107       Uint32 shmKey;
108       Uint32 shmSize;
109       int    signum;
110     } shm;
111 
112     struct {
113       Uint32 sendLimit;        // Packet size
114       Uint32 bufferSize;       // Buffer size
115 
116       Uint32 nLocalAdapters;   // 1 or 2, the number of adapters on local host
117 
118       Uint32 remoteSciNodeId0; // SCInodeId for adapter 1
119       Uint32 remoteSciNodeId1; // SCInodeId for adapter 2
120     } sci;
121   };
122 };
123 
124 struct SignalHeader {
125   Uint32 theVerId_signalNumber;    // 4 bit ver id - 16 bit gsn
126   Uint32 theReceiversBlockNumber;  // Only 16 bit blocknum
127   Uint32 theSendersBlockRef;
128   Uint32 theLength;
129   Uint32 theSendersSignalId;
130   Uint32 theSignalId;
131   Uint16 theTrace;
132   Uint8  m_noOfSections;
133   Uint8  m_fragmentInfo;
134 }; /** 7x4 = 28 Bytes */
135 
136 struct LinearSectionPtr {
137   Uint32 sz;
138   Uint32 * p;
139 };
140 
141 struct SegmentedSectionPtrPOD
142 {
143   Uint32 sz;
144   Uint32 i;
145   struct SectionSegment * p;
146 
setNullSegmentedSectionPtrPOD147   void setNull() { p = 0;}
isNullSegmentedSectionPtrPOD148   bool isNull() const { return p == 0;}
149   inline SegmentedSectionPtrPOD& assign(struct SegmentedSectionPtr&);
150 };
151 
152 struct SegmentedSectionPtr {
153   Uint32 sz;
154   Uint32 i;
155   struct SectionSegment * p;
156 
SegmentedSectionPtrSegmentedSectionPtr157   SegmentedSectionPtr() {}
SegmentedSectionPtrSegmentedSectionPtr158   SegmentedSectionPtr(Uint32 sz_arg, Uint32 i_arg,
159                       struct SectionSegment *p_arg)
160     :sz(sz_arg), i(i_arg), p(p_arg)
161   {}
SegmentedSectionPtrSegmentedSectionPtr162   SegmentedSectionPtr(const SegmentedSectionPtrPOD & src)
163     :sz(src.sz), i(src.i), p(src.p)
164   {}
165 
setNullSegmentedSectionPtr166   void setNull() { p = 0;}
isNullSegmentedSectionPtr167   bool isNull() const { return p == 0;}
168 };
169 
170 inline
171 SegmentedSectionPtrPOD&
assign(struct SegmentedSectionPtr & src)172 SegmentedSectionPtrPOD::assign(struct SegmentedSectionPtr& src)
173 {
174   this->i = src.i;
175   this->p = src.p;
176   this->sz = src.sz;
177   return *this;
178 }
179 
180 /* Abstract interface for iterating over
181  * words in a section
182  */
183 struct GenericSectionIterator {
~GenericSectionIteratorGenericSectionIterator184   virtual ~GenericSectionIterator() {};
185   virtual void reset()=0;
186   virtual const Uint32* getNextWords(Uint32& sz)=0;
187 };
188 
189 struct GenericSectionPtr {
190   Uint32 sz;
191   GenericSectionIterator* sectionIter;
192 };
193 
194 class NdbOut & operator <<(class NdbOut & out, SignalHeader & sh);
195 
196 #endif // Define of TransporterDefinitions_H
197