1 /* Copyright (C) 2014 InfiniDB, Inc.
2 
3    This program is free software; you can redistribute it and/or
4    modify it under the terms of the GNU General Public License
5    as published by the Free Software Foundation; version 2 of
6    the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16    MA 02110-1301, USA. */
17 
18 #ifndef UDPC_PROTOC_H
19 #define UDPC_PROTOC_H
20 
21 #include "udpcast.h"
22 
23 #define MAX_BLOCK_SIZE 1456
24 #define MAX_FEC_INTERLEAVE 256
25 
26 /**
27  * This file describes the UDPCast protocol
28  */
29 enum opCode
30 {
31     /* Receiver to sender */
32 
33     CMD_OK,	     /* all is ok, no need to retransmit anything */
34     CMD_RETRANSMIT,  /* receiver asks for some data to be retransmitted */
35     CMD_GO,	     /* receiver tells server to start */
36     CMD_CONNECT_REQ, /* receiver tries to find out server's address */
37     CMD_DISCONNECT,  /* receiver wants to disconnect itself */
38 
39     CMD_UNUSED,	     /* obsolete version of CMD_HELLO, dating back to the
40 		      * time when we had little endianness (PC). This
41 		      * opcode contained a long unnoticed bug with parsing of
42 		      * blocksize */
43 
44     /* Sender to receiver */
45     CMD_REQACK,	     /* server request acknowledgments from receiver */
46     CMD_CONNECT_REPLY, /* receiver tries to find out server's address */
47 
48     CMD_DATA,        /* a block of data */
49     CMD_FEC,	     /* a forward-error-correction block */
50 
51     CMD_HELLO_NEW,	  /* sender says he's up */
52     CMD_HELLO_STREAMING,  /* retransmitted hello during streaming mode */
53 };
54 
55 /* Sender says he's up. This is not in the enum with the others,
56  * because of some endianness Snafu in early versions. However,since
57  * 2005-12-23, new receivers now understand a CMD_HELLO_NEW which is
58  * in sequence. Once enough of those are out in the field, we'll send
59  * CMD_HELLO_NEW by default, and then phase out the old variant. */
60 /* Tried to remove this on 2009-08-30, but noticed that receiver was printing
61  * "unexpected opcode" on retransmitted hello */
62 #define CMD_HELLO 0x0500
63 
64 struct connectReq
65 {
66     unsigned short opCode;
67     short reserved;
68     int capabilities;
69     unsigned int rcvbuf;
70 };
71 struct retransmit
72 {
73     unsigned short opCode;
74     short reserved;
75     int sliceNo;
76     int rxmit;
77     unsigned char map[MAX_SLICE_SIZE / BITS_PER_CHAR];
78 };
79 struct ok
80 {
81     unsigned short opCode;
82     short reserved;
83     int sliceNo;
84 } ok;
85 
86 union message
87 {
88     unsigned short opCode;
89     struct ok ok;
90 
91     struct retransmit retransmit;
92 
93     struct connectReq connectReq;
94 
95     struct go
96     {
97         unsigned short opCode;
98         short reserved;
99     } go;
100 
101     struct disconnect
102     {
103         unsigned short opCode;
104         short reserved;
105     } disconnect;
106 };
107 
108 
109 
110 struct connectReply
111 {
112     unsigned short opCode;
113     short reserved;
114     int clNr;
115     int blockSize;
116     int capabilities;
117     unsigned char mcastAddr[16]; /* provide enough place for IPV6 */
118 };
119 
120 struct hello
121 {
122     unsigned short opCode;
123     short reserved;
124     int capabilities;
125     unsigned char mcastAddr[16]; /* provide enough place for IPV6 */
126     short blockSize;
127 };
128 
129 union serverControlMsg
130 {
131     unsigned short opCode;
132     short reserved;
133     struct hello hello;
134     struct connectReply connectReply;
135 
136 };
137 
138 
139 struct dataBlock
140 {
141     unsigned short opCode;
142     short reserved;
143     int sliceNo;
144     unsigned short blockNo;
145     unsigned short reserved2;
146     int bytes;
147 };
148 
149 struct fecBlock
150 {
151     unsigned short opCode;
152     short stripes;
153     int sliceNo;
154     unsigned short blockNo;
155     unsigned short reserved2;
156     int bytes;
157 };
158 
159 struct reqack
160 {
161     unsigned short opCode;
162     short reserved;
163     int sliceNo;
164     int bytes;
165     int rxmit;
166 };
167 
168 union serverDataMsg
169 {
170     unsigned short opCode;
171     struct reqack reqack;
172     struct dataBlock dataBlock;
173     struct fecBlock fecBlock;
174 };
175 
176 /* ============================================
177  * Capabilities
178  */
179 
180 /* Does the receiver support the new CMD_DATA command, which carries
181  * capabilities mask?
182  * "new generation" receiver:
183  *   - capabilities word included in hello/connectReq commands
184  *   - receiver multicast capable
185  *   - receiver can receive ASYNC and SN
186  */
187 #define CAP_NEW_GEN 0x0001
188 
189 /* Use multicast instead of Broadcast for data */
190 /*#define CAP_MULTICAST 0x0002*/
191 
192 #ifdef BB_FEATURE_UDPCAST_FEC
193 /* Forward error correction */
194 #define CAP_FEC 0x0004
195 #endif
196 
197 /* Supports big endians (a.k.a. network) */
198 #define CAP_BIG_ENDIAN 0x0008
199 
200 /* Support little endians (a.k.a. PC) ==> obsolete! */
201 #define CAP_LITTLE_ENDIAN 0x0010
202 
203 /* This transmission is asynchronous (no receiver reply) */
204 #define CAP_ASYNC 0x0020
205 
206 /* Sender currently supports CAPABILITIES and MULTICAST */
207 #define SENDER_CAPABILITIES ( \
208 	CAP_NEW_GEN | \
209 	CAP_BIG_ENDIAN)
210 
211 
212 #define RECEIVER_CAPABILITIES ( \
213 	CAP_NEW_GEN | \
214 	CAP_BIG_ENDIAN)
215 
216 
217 #endif
218