NewMadeleine

Documentation

nm_headers.h
Go to the documentation of this file.
1/*
2 * NewMadeleine
3 * Copyright (C) 2006-2023 (see AUTHORS file)
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; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#ifndef NM_HEADERS_H
17#define NM_HEADERS_H
18
21{
22 uint16_t v0len;
23} __attribute__((packed));
24
25static inline void nm_header_global_finalize(struct nm_pkt_wrap_s*p_pw)
26{
27 struct nm_header_global_s*h = p_pw->v[0].iov_base;
28 const int v0len = p_pw->v[0].iov_len;
29 assert(p_pw->trk_id == NM_TRK_SMALL);
30 assert(v0len <= UINT16_MAX);
31 h->v0len = v0len;
32}
33
34static inline uint16_t nm_header_global_v0len(const struct nm_pkt_wrap_s*p_pw)
35{
37 const struct nm_header_global_s*h = p_pw->v[0].iov_base;
38 return h->v0len;
39}
40
42#define NM_PROTO_ID_MASK 0x0F
44#define NM_PROTO_FLAG_MASK 0xF0
45
47#define NM_PROTO_SMALL_DATA 0x01
49#define NM_PROTO_SHORT_DATA 0x02
51#define NM_PROTO_PKT_DATA 0x03
53#define NM_PROTO_RDV 0x04
55#define NM_PROTO_RTR 0x05
57#define NM_PROTO_ACK 0x06
59#define NM_PROTO_STRAT 0x07
61#define NM_PROTO_MSG 0x08
63#define NM_PROTO_DEBUG 0x0F
64
66#define NM_PROTO_FLAG_LASTCHUNK 0x10
68#define NM_PROTO_FLAG_ALIGNED 0x20
70#define NM_PROTO_FLAG_ACKREQ 0x40
71
72
73/* Warning : All header structs (except the global one) _MUST_ begin
74 * with the 'proto_id' field
75 */
76
78{
84 uint16_t hlen;
85} __attribute__((packed));
88{
89 uint16_t len;
90 uint16_t skip;
91} __attribute__((packed));
92
94{
100 uint16_t skip;
101} __attribute__((packed));
102
105{
109 uint8_t len;
110} __attribute__((packed));
111
114{
119} __attribute__((packed));
120
122{
130} __attribute__((packed));
131
133{
141} __attribute__((packed));
142
144{
148} __attribute__((packed));
149
152{
156} __attribute__((packed));
157
160{
169{
174};
177{
186};
187
190{
193};
194
197{
199 uint64_t req;
200} __attribute__((packed));
201
204
206
209{
210 PUK_LIST_LINK(nm_ctrl_chunk);
213};
215
217NM_ALLOCATOR_TYPE(nm_ctrl_chunk, struct nm_ctrl_chunk_s);
218
219
220#define NM_HEADER_PKT_DATA_SIZE \
221 sizeof(struct nm_header_pkt_data_s)
222
223#define NM_HEADER_DATA_SIZE \
224 nm_aligned(sizeof(struct nm_header_data_s))
225
226#define NM_HEADER_SHORT_DATA_SIZE \
227 nm_aligned(sizeof(struct nm_header_short_data_s))
228
229#define NM_HEADER_CTRL_SIZE(P_CTRL) \
230 nm_header_ctrl_size(P_CTRL)
231
232static inline size_t nm_header_ctrl_size(const union nm_header_ctrl_generic_s*const p_ctrl)
233{
234 switch(p_ctrl->generic.proto_id & NM_PROTO_ID_MASK)
235 {
236 case NM_PROTO_RDV:
237 return sizeof(struct nm_header_ctrl_rdv_s);
238 break;
239 case NM_PROTO_RTR:
240 return sizeof(struct nm_header_ctrl_rtr_s);
241 break;
242 case NM_PROTO_ACK:
243 return sizeof(struct nm_header_ctrl_ack_s);
244 break;
245 case NM_PROTO_MSG:
246 return sizeof(struct nm_header_msg_s);
247 break;
248 default:
249 NM_FATAL("invalid kind 0x%x for control header.\n", p_ctrl->generic.proto_id);
250 break;
251 }
252}
253
256{
257 assert((flags & NM_PROTO_ID_MASK) == 0x00);
258 p_header->proto_id = NM_PROTO_PKT_DATA | flags;
259 p_header->tag_id = tag_id;
260 p_header->seq = seq;
261 p_header->data_len = len;
262 p_header->chunk_offset = chunk_offset;
263 p_header->hlen = NM_HEADER_PKT_DATA_SIZE;
264}
265
266static inline void nm_header_init_data(struct nm_header_data_s*p_header, nm_core_tag_t tag_id, nm_seq_t seq, uint8_t flags,
268{
269 assert((flags & NM_PROTO_ID_MASK) == 0x00);
270 p_header->proto_id = NM_PROTO_SMALL_DATA | flags;
271 p_header->tag_id = tag_id;
272 p_header->seq = seq;
273 p_header->skip = skip;
274 p_header->len = len;
275 p_header->chunk_offset = chunk_offset;
276}
277
280{
282 p_header->tag_id = tag_id;
283 p_header->seq = seq;
284 p_header->len = len;
285}
286
288{
289 p_ctrl->msg.proto_id = NM_PROTO_MSG;
290 p_ctrl->msg.tag_id = tag_id;
291 p_ctrl->msg.seq = seq;
292 p_ctrl->msg.msg_len = msg_len;
293 }
294
295static inline void nm_header_init_rdv(union nm_header_ctrl_generic_s*p_ctrl, struct nm_req_s*p_pack,
296 nm_len_t chunk_len, nm_len_t chunk_offset, uint8_t rdv_flags)
297{
299 rdv_flags |= NM_PROTO_FLAG_ACKREQ;
300 assert((rdv_flags & NM_PROTO_ID_MASK) == 0);
301 p_ctrl->rdv.proto_id = NM_PROTO_RDV | rdv_flags;
302 p_ctrl->rdv.tag_id = p_pack->tag;
303 p_ctrl->rdv.seq = p_pack->seq;
304 p_ctrl->rdv.chunk_offset = chunk_offset;
305 p_ctrl->rdv.chunk_len = chunk_len;
306 p_ctrl->rdv.msg_len = p_pack->pack.len;
307 p_ctrl->rdv.priority = p_pack->pack.priority;
308}
309
312 const void*p_rdv_data)
313{
314 p_ctrl->rtr.proto_id = NM_PROTO_RTR;
315 p_ctrl->rtr.tag_id = tag;
316 p_ctrl->rtr.seq = seq;
317 p_ctrl->rtr.trk_id = trk_id;
318 p_ctrl->rtr.chunk_offset = chunk_offset;
319 p_ctrl->rtr.chunk_len = chunk_len;
320 if(p_rdv_data != NULL)
321 {
322 memcpy(&p_ctrl->rtr.rdv_data[0], p_rdv_data, NM_HEADER_RTR_DATA_SIZE);
323 }
324}
325
327{
328 p_ctrl->ack.proto_id = NM_PROTO_ACK;
329 p_ctrl->ack.tag_id = tag;
330 p_ctrl->ack.seq = seq;
331}
332
333static inline void nm_header_init_debug(struct nm_header_debug_s*p_header, int req)
334{
335 p_header->proto_id = NM_PROTO_DEBUG;
336 p_header->req = req;
337}
338
339#endif /* NM_HEADER_H */
#define NM_REQ_FLAG_PACK_SYNCHRONOUS
flag pack as synchronous (i.e.
without even the implied warranty of !MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU !General Public License for more details !mpif h
Definition: mpif.h:19
nm_tag_t tag
the user-supplied tag
#define NM_TRK_SMALL
#define NM_PROTO_ID_MASK
mask for proto ID part
Definition: nm_headers.h:42
static void nm_header_init_msg(union nm_header_ctrl_generic_s *p_ctrl, nm_core_tag_t tag_id, nm_seq_t seq, nm_len_t msg_len)
Definition: nm_headers.h:287
NM_ALLOCATOR_TYPE(nm_ctrl_chunk, struct nm_ctrl_chunk_s)
allocator for control chunks
static void nm_header_init_rtr(union nm_header_ctrl_generic_s *p_ctrl, nm_core_tag_t tag, nm_seq_t seq, nm_trk_id_t trk_id, nm_len_t chunk_offset, nm_len_t chunk_len, const void *p_rdv_data)
Definition: nm_headers.h:310
uint16_t skip
skip value for iovec
Definition: nm_headers.h:1
#define NM_PROTO_PKT_DATA
new optimized packet format
Definition: nm_headers.h:51
#define NM_PROTO_MSG
msg matching informations, contains no data chunk
Definition: nm_headers.h:61
PUK_LIST_CREATE_FUNCS(nm_ctrl_chunk)
static void nm_header_init_data(struct nm_header_data_s *p_header, nm_core_tag_t tag_id, nm_seq_t seq, uint8_t flags, uint16_t skip, nm_len_t len, nm_len_t chunk_offset)
Definition: nm_headers.h:266
#define NM_PROTO_RTR
ready-to-receive, replay to rdv
Definition: nm_headers.h:55
static void nm_header_init_debug(struct nm_header_debug_s *p_header, int req)
Definition: nm_headers.h:333
uint64_t req
a type of debug request; unused for now
Definition: nm_headers.h:1
uint16_t len
chunk len
Definition: nm_headers.h:0
static void nm_header_init_ack(union nm_header_ctrl_generic_s *p_ctrl, nm_core_tag_t tag, nm_seq_t seq)
Definition: nm_headers.h:326
#define NM_PROTO_ACK
an ack for a ssend (sent when receiving first chunk)
Definition: nm_headers.h:57
#define NM_PROTO_FLAG_ACKREQ
data sent as synchronous send- please send an ack on first chunk
Definition: nm_headers.h:70
static size_t nm_header_ctrl_size(const union nm_header_ctrl_generic_s *const p_ctrl)
Definition: nm_headers.h:232
#define NM_PROTO_DEBUG
internal debug msg
Definition: nm_headers.h:63
nm_len_t chunk_len
length of this chunk
Definition: nm_headers.h:4
union nm_header_ctrl_generic_s __attribute__
#define NM_PROTO_SHORT_DATA
a simplified (short header) chunk of data
Definition: nm_headers.h:49
PUK_LIST_DECLARE_TYPE(nm_ctrl_chunk)
nm_core_tag_t tag_id
tag for the message
Definition: nm_headers.h:1
static void nm_header_init_short_data(struct nm_header_short_data_s *p_header, nm_core_tag_t tag_id, nm_seq_t seq, nm_len_t len)
Definition: nm_headers.h:278
nm_trk_id_t trk_id
index of the track relative to the gate
Definition: nm_headers.h:3
#define NM_HEADER_PKT_DATA_SIZE
Definition: nm_headers.h:220
static void nm_header_init_pkt_data(struct nm_header_pkt_data_s *p_header, nm_core_tag_t tag_id, nm_seq_t seq, uint8_t flags, nm_len_t len, nm_len_t chunk_offset)
Definition: nm_headers.h:254
nm_len_t chunk_offset
offset of the enclosed chunk
Definition: nm_headers.h:4
#define NM_PROTO_RDV
rendez-vous request
Definition: nm_headers.h:53
static void nm_header_init_rdv(union nm_header_ctrl_generic_s *p_ctrl, struct nm_req_s *p_pack, nm_len_t chunk_len, nm_len_t chunk_offset, uint8_t rdv_flags)
Definition: nm_headers.h:295
nm_len_t msg_len
length of the full message
Definition: nm_headers.h:3
#define NM_PROTO_FLAG_LASTCHUNK
last chunk of data for the given pack
Definition: nm_headers.h:66
static void nm_header_global_finalize(struct nm_pkt_wrap_s *p_pw)
Definition: nm_headers.h:25
uint16_t v0len
size of v0 actually used ( == offset value to reach v[1] )
Definition: nm_headers.h:0
nm_seq_t seq
sequence number
Definition: nm_headers.h:2
static uint16_t nm_header_global_v0len(const struct nm_pkt_wrap_s *p_pw)
Definition: nm_headers.h:34
#define NM_PROTO_SMALL_DATA
a chunk of data on small trk
Definition: nm_headers.h:47
#define NM_FATAL(format,...)
Definition: nm_log.h:36
nm_onesided_flag_t flags
#define NM_HEADER_RTR_DATA_SIZE
size of rdv data packet with RTR, in bytes
Definition: nm_parameters.h:49
#define NM_PW_GLOBAL_HEADER
pw allocated with a contiguous buffer and a global header has been prepared.
Definition: nm_pkt_wrap.h:50
#define NM_PW_BUF_SEND
use buffer-based driver for send
Definition: nm_pkt_wrap.h:80
#define NM_PW_BUFFER
pw allocated with NM_MAX_UNEXPECTED contiguous buffer.
Definition: nm_pkt_wrap.h:45
int8_t nm_trk_id_t
ID of a track, assigned in order.
Definition: nm_types.h:88
int32_t nm_prio_t
message priority
Definition: nm_types.h:80
uint64_t nm_len_t
data length used by nmad
Definition: nm_types.h:70
uint32_t nm_seq_t
Sequence number for packets on a given gate/tag.
Definition: nm_types.h:104
uint8_t nm_proto_t
protocol flags- not part of the public API, but needed for inline
Definition: nm_types.h:101
An internal tag.
a chunk of control data
Definition: nm_headers.h:209
nm_header_ctrl_generic_t ctrl
Definition: nm_headers.h:212
PUK_LIST_LINK(nm_ctrl_chunk)
nm_gate_t p_gate
Definition: nm_headers.h:211
Connection to another process.
Definition: nm_gate.h:100
base header that matches all data/ctrl headers first fields (except header_strat)
Definition: nm_headers.h:152
nm_proto_t proto_id
Definition: nm_headers.h:153
nm_core_tag_t tag_id
Definition: nm_headers.h:154
nm_core_tag_t tag_id
Definition: nm_headers.h:146
nm_proto_t proto_id
proto ID- should be NM_PROTO_ACK
Definition: nm_headers.h:145
nm_len_t chunk_len
length of this chunk
Definition: nm_headers.h:127
nm_proto_t proto_id
proto ID- should be NM_PROTO_RDV
Definition: nm_headers.h:123
nm_len_t msg_len
length of the full message
Definition: nm_headers.h:128
nm_len_t chunk_offset
offset of this chunk relative to full message
Definition: nm_headers.h:126
nm_core_tag_t tag_id
Definition: nm_headers.h:124
nm_trk_id_t trk_id
index of the track relative to the gate
Definition: nm_headers.h:137
char rdv_data[NM_HEADER_RTR_DATA_SIZE]
Definition: nm_headers.h:140
nm_proto_t proto_id
proto ID- should be NM_PROTO_RTR
Definition: nm_headers.h:134
nm_core_tag_t tag_id
tag of the acknowledged data
Definition: nm_headers.h:135
nm_core_tag_t tag_id
tag for the message
Definition: nm_headers.h:96
nm_len_t len
Definition: nm_headers.h:98
nm_proto_t proto_id
proto ID- should be NM_PROTO_SMALL_DATA
Definition: nm_headers.h:95
nm_seq_t seq
sequence number
Definition: nm_headers.h:97
nm_len_t chunk_offset
Definition: nm_headers.h:99
uint16_t skip
skip offset for data buffer, relative to v0 end (0xFFFF for inline data)
Definition: nm_headers.h:100
header for debug messages
Definition: nm_headers.h:197
uint64_t req
a type of debug request; unused for now
Definition: nm_headers.h:199
nm_proto_t proto_id
Definition: nm_headers.h:198
global header at the beginning of pw
Definition: nm_headers.h:21
uint16_t v0len
size of v0 actually used ( == offset value to reach v[1] )
Definition: nm_headers.h:22
header for msg matching information only, contains no data; for cases where early information is need...
Definition: nm_headers.h:114
nm_seq_t seq
Definition: nm_headers.h:117
nm_proto_t proto_id
proto ID- should be NM_PROTO_MSG
Definition: nm_headers.h:115
nm_len_t msg_len
Definition: nm_headers.h:118
nm_core_tag_t tag_id
Definition: nm_headers.h:116
sub-header for pkt_data chunks
Definition: nm_headers.h:88
uint16_t skip
skip value for iovec
Definition: nm_headers.h:90
uint16_t len
chunk len
Definition: nm_headers.h:89
nm_len_t chunk_offset
offset of the enclosed chunk
Definition: nm_headers.h:83
nm_len_t data_len
length of data enclosed
Definition: nm_headers.h:82
nm_proto_t proto_id
proto ID- should be NM_PROTO_PKT_DATA
Definition: nm_headers.h:79
nm_core_tag_t tag_id
tag for the message
Definition: nm_headers.h:80
uint16_t hlen
length in header (header + data in header)
Definition: nm_headers.h:84
nm_seq_t seq
sequence number
Definition: nm_headers.h:81
header for very short data; single chunk assumed (chunk_offset=0, chunk_len=len, FLAG_LASTCHUNK)
Definition: nm_headers.h:105
nm_core_tag_t tag_id
Definition: nm_headers.h:107
nm_proto_t proto_id
proto ID- should be NM_PROTO_SHORT_DATA
Definition: nm_headers.h:106
header for strategy private packets
Definition: nm_headers.h:190
nm_proto_t proto_id
should be NM_PROTO_STRAT
Definition: nm_headers.h:191
Internal packet wrapper.
Definition: nm_pkt_wrap.h:117
struct iovec * v
IO vector.
Definition: nm_pkt_wrap.h:143
nm_trk_id_t trk_id
assignated track ID.
Definition: nm_pkt_wrap.h:133
nm_pw_flag_t flags
packet flags.
Definition: nm_pkt_wrap.h:139
a generic pack/unpack request
nm_core_tag_t tag
tag to send to/from (works in combination with tag_mask for recv)
nm_prio_t priority
request priority level
nm_req_flag_t flags
flags given by user
struct nm_req_s::@18::@20 pack
nm_len_t len
cumulated data length
nm_seq_t seq
packet sequence number on the given tag
a unified control header type
Definition: nm_headers.h:160
struct nm_header_ctrl_rdv_s rdv
Definition: nm_headers.h:162
struct nm_header_msg_s msg
Definition: nm_headers.h:161
struct nm_header_common_s generic
Definition: nm_headers.h:165
struct nm_header_ctrl_ack_s ack
Definition: nm_headers.h:164
struct nm_header_ctrl_rtr_s rtr
Definition: nm_headers.h:163
a unified data header type
Definition: nm_headers.h:169
struct nm_header_short_data_s short_data
Definition: nm_headers.h:171
struct nm_header_pkt_data_s pkt_data
Definition: nm_headers.h:170
struct nm_header_data_s data
Definition: nm_headers.h:172
struct nm_header_common_s generic
Definition: nm_headers.h:173
a unified header for all types (ctrl/data)
Definition: nm_headers.h:177
struct nm_header_data_s data
Definition: nm_headers.h:181
struct nm_header_msg_s msg
Definition: nm_headers.h:182
struct nm_header_common_s generic
Definition: nm_headers.h:178
struct nm_header_ctrl_rtr_s rtr
Definition: nm_headers.h:184
struct nm_header_pkt_data_s pkt_data
Definition: nm_headers.h:179
struct nm_header_ctrl_ack_s ack
Definition: nm_headers.h:185
struct nm_header_short_data_s short_data
Definition: nm_headers.h:180
struct nm_header_ctrl_rdv_s rdv
Definition: nm_headers.h:183