ROHC compression/decompression library
rohc_comp_internals.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010,2011,2012,2013,2014 Didier Barvaux
3  * Copyright 2012,2013,2014 Viveris Technologies
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /**
21  * @file rohc_comp_internals.h
22  * @brief Internal structures for ROHC compression
23  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
24  * @author Didier Barvaux <didier@barvaux.org>
25  */
26 
27 #ifndef ROHC_COMP_INTERNALS_H
28 #define ROHC_COMP_INTERNALS_H
29 
30 #include "rohc_internal.h"
31 #include "rohc_traces_internal.h"
32 #include "rohc_packets.h"
33 #include "rohc_comp.h"
34 #include "schemes/comp_wlsb.h"
35 #include "net_pkt.h"
36 #include "feedback.h"
37 
38 #include <stdbool.h>
39 
40 
41 /*
42  * Constants and macros
43  */
44 
45 /** The number of ROHC profiles ready to be used */
46 #define C_NUM_PROFILES 7U
47 
48 /** The default maximal number of packets sent in > IR states (= FO and SO
49  * states) before changing back the state to IR (periodic refreshes) */
50 #define CHANGE_TO_IR_COUNT 1700
51 
52 /** The default maximal delay (in ms) spent in > IR states (= FO and SO states)
53  * before changing back the state to IR (periodic refreshes) */
54 #define CHANGE_TO_IR_TIME 1000U
55 
56 /** The default maximal number of packets sent in > FO states (= SO state)
57  * before changing back the state to FO (periodic refreshes) */
58 #define CHANGE_TO_FO_COUNT 700
59 
60 /** The default maximal delay (in ms) spent in > FO states (= SO state)
61  * before changing back the state to FO (periodic refreshes) */
62 #define CHANGE_TO_FO_TIME 500U
63 
64 /** The minimal number of packets that must be sent while in IR state before
65  * being able to switch to the FO state */
66 #define MAX_IR_COUNT 3U
67 
68 /** The minimal number of packets that must be sent while in CR state before
69  * being able to switch to the FO state */
70 #define MAX_CR_COUNT MAX_IR_COUNT
71 
72 /** The minimal number of packets that must be sent while in FO state before
73  * being able to switch to the SO state */
74 #define MAX_FO_COUNT 3U
75 
76 /** The minimal number of packets that must be sent while in INIT_STRIDE
77  * state before being able to switch to the SEND_SCALED state */
78 #define ROHC_INIT_TS_STRIDE_MIN 3U
79 
80 /**
81  * @brief Default number of transmission for lists to become a reference list
82  *
83  * The minimal number of times of compressed list shall be sent to become
84  * a reference list. L is the name specified in the RFC.
85  */
86 #define ROHC_LIST_DEFAULT_L 5U
87 
88 
89 /** Print a warning trace for the given compression context */
90 #define rohc_comp_warn(context, format, ...) \
91  rohc_warning((context)->compressor, ROHC_TRACE_COMP, \
92  (context)->profile->id, \
93  format, ##__VA_ARGS__)
94 
95 /** Print a debug trace for the given compression context */
96 #define rohc_comp_debug(context, format, ...) \
97  rohc_debug((context)->compressor, ROHC_TRACE_COMP, \
98  (context)->profile->id, \
99  format, ##__VA_ARGS__)
100 
101 /** Dump a buffer for the given compression context */
102 #define rohc_comp_dump_buf(context, descr, buf, buf_len) \
103  do { \
104  if(((context)->compressor->features & ROHC_COMP_FEATURE_DUMP_PACKETS) != 0) { \
105  rohc_dump_buf((context)->compressor->trace_callback, \
106  (context)->compressor->trace_callback_priv, \
107  ROHC_TRACE_COMP, ROHC_TRACE_DEBUG, \
108  descr, buf, buf_len); \
109  } \
110  } while(0)
111 
112 
113 /*
114  * Declare ROHC compression structures that are defined at the end of this
115  * file but used by other structures at the beginning of the file.
116  */
117 
118 struct rohc_comp_ctxt;
119 
120 
121 /*
122  * Definitions of ROHC compression structures
123  */
124 
125 
126 /**
127  * @brief The ROHC compressor
128  */
129 struct rohc_comp
130 {
131  /** The medium associated with the decompressor */
133 
134  /** Enabled/disabled features for the compressor */
136 
137  /** The array of compression contexts that use the compressor */
139  /** The number of compression contexts in use in the array */
141 
142  /** Which profiles are enabled and with one are not? */
144 
145 
146  /* CRC-related variables: */
147 
148  /** The table to enable fast CRC-3 computation */
149  uint8_t crc_table_3[256];
150  /** The table to enable fast CRC-7 computation */
151  uint8_t crc_table_7[256];
152  /** The table to enable fast CRC-8 computation */
153  uint8_t crc_table_8[256];
154 
155 
156  /* segment-related variables */
157 
158 /** The maximal value for MRRU */
159 #define ROHC_MAX_MRRU 65535
160  /** The remaining bytes of the Reconstructed Reception Unit (RRU) waiting
161  * to be split into segments */
162  uint8_t rru[ROHC_MAX_MRRU];
163  /** The offset of the remaining bytes in the RRU buffer */
164  size_t rru_off;
165  /** The number of the remaining bytes in the RRU buffer */
166  size_t rru_len;
167 
168 
169  /* variables related to RTP detection */
170 
171  /** The callback function used to detect RTP packet */
173  /** Pointer to an external memory area provided/used by the callback user */
174  void *rtp_private;
175 
176 
177  /* some statistics about the compression process: */
178 
179  /** The number of sent packets */
181  /** The size of all the received uncompressed IP packets */
183  /** The size of all the sent compressed ROHC packets */
185 
186  /** The last context used by the compressor */
188 
189 
190  /* random callback */
191 
192  /** The user-defined callback for random numbers */
194  /** Private data that will be given to the callback for random numbers */
196 
197 
198  /* user interaction variables: */
199 
200  /** The width of the W-LSB sliding window */
202  /** The maximal number of packets sent in > IR states (= FO and SO
203  * states) before changing back the state to IR (periodic refreshes) */
205  /** The maximal delay spent in > IR states (= FO and SO states) before
206  * changing back the state to IR (periodic refreshes) */
208  /** The maximal number of packets sent in > FO states (= SO state)
209  * before changing back the state to FO (periodic refreshes) */
211  /** The maximal delay spent in > FO states (= SO state) before changing back
212  * the state to FO (periodic refreshes) */
214  /** Maximum Reconstructed Reception Unit */
215  size_t mrru;
216  /** The connection type (currently not used) */
218  /** The number of uncompressed transmissions for list compression (L) */
220 
221  /** The callback function used to manage traces */
223  /** The private context of the callback function used to manage traces */
225 };
226 
227 
228 /**
229  * @brief The ROHC compression profile
230  *
231  * The object defines a ROHC profile. Each field must be filled in
232  * for each new profile.
233  */
235 {
236  /** The profile ID as reserved by IANA */
238 
239  /**
240  * @brief The IP protocol ID used to find out which profile is able to
241  * compress an IP packet
242  */
243  const unsigned short protocol;
244 
245  /**
246  * @brief The handler used to create the profile-specific part of the
247  * compression context from a given packet
248  */
249  bool (*create)(struct rohc_comp_ctxt *const context,
250  const struct net_pkt *const packet)
251  __attribute__((warn_unused_result, nonnull(1, 2)));
252 
253  /**
254  * @brief The handler used to create the profile-specific part of the
255  * compression context from a given context
256  */
257  bool (*clone)(struct rohc_comp_ctxt *const ctxt,
258  const struct rohc_comp_ctxt *const base_ctxt)
259  __attribute__((warn_unused_result, nonnull(1, 2)));
260 
261  /**
262  * @brief The handler used to destroy the profile-specific part of the
263  * compression context
264  */
265  void (*destroy)(struct rohc_comp_ctxt *const context)
266  __attribute__((nonnull(1)));
267 
268  /**
269  * @brief The handler used to check whether an uncompressed IP packet
270  * fits the current profile or not
271  */
272  bool (*check_profile)(const struct rohc_comp *const comp,
273  const struct net_pkt *const packet)
274  __attribute__((warn_unused_result, nonnull(1, 2)));
275 
276  /**
277  * @brief The handler used to check whether an uncompressed IP packet
278  * belongs to a context or not
279  */
280  bool (*check_context)(const struct rohc_comp_ctxt *const context,
281  const struct net_pkt *const packet,
282  size_t *const cr_score)
283  __attribute__((warn_unused_result, nonnull(1, 2, 3)));
284 
285  /**
286  * @brief The handler used to encode uncompressed IP packets
287  *
288  * @param context The compression context
289  * @param ip The IP packet to encode
290  * @param packet_size The length of the IP packet to encode
291  * @param rohc_pkt OUT: The ROHC packet
292  * @param rohc_pkt_max_len The maximum length of the ROHC packet
293  * @param packet_type OUT: The type of ROHC packet that is created
294  * @param payload_offset OUT: The offset for the payload in the IP packet
295  * @return The length of the ROHC packet if successful,
296  * -1 otherwise
297  */
298  int (*encode)(struct rohc_comp_ctxt *const context,
299  const struct net_pkt *const uncomp_pkt,
300  uint8_t *const rohc_pkt,
301  const size_t rohc_pkt_max_len,
302  rohc_packet_t *const packet_type,
303  size_t *const payload_offset)
304  __attribute__((warn_unused_result, nonnull(1, 2, 3, 5, 6)));
305 
306  /**
307  * @brief The handler used to re-initialize a context
308  */
309  bool (*reinit_context)(struct rohc_comp_ctxt *const context)
310  __attribute__((nonnull(1), warn_unused_result));
311 
312  /**
313  * @brief The handler used to warn the profile-specific part of the
314  * context about the arrival of feedback data
315  */
316  bool (*feedback)(struct rohc_comp_ctxt *const context,
317  const enum rohc_feedback_type feedback_type,
318  const uint8_t *const packet,
319  const size_t packet_len,
320  const uint8_t *const feedback_data,
321  const size_t feedback_data_len)
322  __attribute__((warn_unused_result, nonnull(1, 3, 5)));
323 };
324 
325 
326 /**
327  * @brief The ROHC compression context
328  */
330 {
331  /** Whether the context is in use or not */
332  int used;
333  /** The time when the context was created (in seconds) */
334  uint64_t latest_used;
335  /** The time when the context was last used (in seconds) */
336  uint64_t first_used;
337 
338  /** The context unique ID (CID) */
340 
341  /** The associated compressor */
343 
344  /** The associated profile */
345  const struct rohc_comp_profile *profile;
346  /** Profile-specific data, defined by the profiles */
347  void *specific;
348 
349  /** Whether Context Replication (CR) may be used */
351  /** The base context for Context Replication (CR) */
353 
354  /** The operation mode in which the context operates among:
355  * ROHC_U_MODE, ROHC_O_MODE, ROHC_R_MODE */
357  /** The operation state in which the context operates: IR, FO, SO */
359 
360  /* below are some statistics */
361 
362  /* The type of ROHC packet created for the last compressed packet */
364 
365  /** The number of packets sent while in Initialization & Refresh (IR) state */
366  size_t ir_count;
367  /** The number of packets sent while in First Order (FO) state */
368  size_t fo_count;
369  /** The number of packets sent while in Second Order (SO) state */
370  size_t so_count;
371  /** The number of packets sent while in Context Replication (CR) state */
372  size_t cr_count;
373 
374  /**
375  * @brief The number of packet sent while in SO state, used for the periodic
376  * refreshes of the context
377  * @see rohc_comp_periodic_down_transition
378  */
380  /**
381  * @brief The last time that the context was in FO state, used for the
382  * periodic refreshes of the context
383  * @see rohc_comp_periodic_down_transition
384  */
385  struct rohc_ts go_back_fo_time;
386  /**
387  * @brief The number of packet sent while in FO or SO state, used for the
388  * periodic refreshes of the context
389  * @see rohc_comp_periodic_down_transition
390  */
392  /**
393  * @brief The last time that the context was in IR state, used for the
394  * periodic refreshes of the context
395  * @see rohc_comp_periodic_down_transition
396  */
397  struct rohc_ts go_back_ir_time;
398 
399  /** The cumulated size of the uncompressed packets */
401  /** The cumulated size of the compressed packets */
403  /** The cumulated size of the uncompressed headers */
405  /** The cumulated size of the compressed headers */
407 
408  /** The total size of the last uncompressed packet */
410  /** The total size of the last compressed packet */
412  /** The header size of the last uncompressed packet */
414  /** The header size of the last compressed packet */
416 
417  /** The number of sent packets */
419 };
420 
421 
422 void rohc_comp_change_mode(struct rohc_comp_ctxt *const context,
423  const rohc_mode_t new_mode)
424  __attribute__((nonnull(1)));
425 
426 void rohc_comp_change_state(struct rohc_comp_ctxt *const context,
427  const rohc_comp_state_t new_state)
428  __attribute__((nonnull(1)));
429 
430 void rohc_comp_periodic_down_transition(struct rohc_comp_ctxt *const context,
431  const struct rohc_ts pkt_time)
432  __attribute__((nonnull(1)));
433 
434 bool rohc_comp_reinit_context(struct rohc_comp_ctxt *const context)
435  __attribute__((warn_unused_result, nonnull(1)));
436 
437 bool rohc_comp_feedback_parse_opts(const struct rohc_comp_ctxt *const context,
438  const uint8_t *const packet,
439  const size_t packet_len,
440  const uint8_t *const feedback_data,
441  const size_t feedback_data_len,
442  size_t opts_present[ROHC_FEEDBACK_OPT_MAX],
443  uint32_t *const sn_bits,
444  size_t *const sn_bits_nr,
445  uint8_t crc_in_packet,
446  size_t crc_pos_from_end)
447  __attribute__((warn_unused_result, nonnull(1, 2, 4, 6, 7, 8)));
448 
449 #endif
450 
int total_last_uncompressed_size
Definition: rohc_comp_internals.h:409
int(* rohc_comp_random_cb_t)(const struct rohc_comp *const comp, void *const user_context)
The prototype of the callback for random numbers.
Definition: rohc_comp.h:288
struct rohc_comp_ctxt * contexts
Definition: rohc_comp_internals.h:138
void * random_cb_ctxt
Definition: rohc_comp_internals.h:195
size_t rohc_cid_t
Definition: rohc.h:193
int total_compressed_size
Definition: rohc_comp_internals.h:184
rohc_comp_features_t features
Definition: rohc_comp_internals.h:135
rohc_cid_t cid
Definition: rohc_comp_internals.h:339
rohc_mode_t
ROHC operation modes.
Definition: rohc.h:109
int connection_type
Definition: rohc_comp_internals.h:217
int header_last_uncompressed_size
Definition: rohc_comp_internals.h:413
int header_uncompressed_size
Definition: rohc_comp_internals.h:404
bool rohc_comp_reinit_context(struct rohc_comp_ctxt *const context)
Re-initialize the given context.
Definition: rohc_comp.c:2986
uint8_t crc_table_7[256]
Definition: rohc_comp_internals.h:151
void rohc_comp_change_mode(struct rohc_comp_ctxt *const context, const rohc_mode_t new_mode)
Change the mode of the context.
Definition: rohc_comp.c:2838
ROHC compression routines.
const unsigned short protocol
The IP protocol ID used to find out which profile is able to compress an IP packet.
Definition: rohc_comp_internals.h:243
The ROHC compressor.
Definition: rohc_comp_internals.h:129
int num_sent_packets
Definition: rohc_comp_internals.h:418
size_t num_contexts_used
Definition: rohc_comp_internals.h:140
uint64_t periodic_refreshes_fo_timeout_time
Definition: rohc_comp_internals.h:213
rohc_comp_random_cb_t random_cb
Definition: rohc_comp_internals.h:193
uint64_t latest_used
Definition: rohc_comp_internals.h:334
struct rohc_comp * compressor
Definition: rohc_comp_internals.h:342
Network packet (may contains several IP headers)
struct rohc_comp_ctxt * last_context
Definition: rohc_comp_internals.h:187
void * trace_callback_priv
Definition: rohc_comp_internals.h:224
void(* rohc_trace_callback2_t)(void *const priv_ctxt, const rohc_trace_level_t level, const rohc_trace_entity_t entity, const int profile, const char *const format,...)
The function prototype for the trace callback.
Definition: rohc_traces.h:118
bool rohc_comp_feedback_parse_opts(const struct rohc_comp_ctxt *const context, const uint8_t *const packet, const size_t packet_len, const uint8_t *const feedback_data, const size_t feedback_data_len, size_t opts_present[ROHC_FEEDBACK_OPT_MAX], uint32_t *const sn_bits, size_t *const sn_bits_nr, uint8_t crc_in_packet, size_t crc_pos_from_end)
Parse FEEDBACK-2 options.
Definition: rohc_comp.c:3080
int total_compressed_size
Definition: rohc_comp_internals.h:402
Window-based Least Significant Bits (W-LSB) encoding.
size_t go_back_fo_count
The number of packet sent while in SO state, used for the periodic refreshes of the context...
Definition: rohc_comp_internals.h:379
The ROHC compression profile.
Definition: rohc_comp_internals.h:234
struct rohc_medium medium
Definition: rohc_comp_internals.h:132
rohc_rtp_detection_callback_t rtp_callback
Definition: rohc_comp_internals.h:172
size_t wlsb_window_width
Definition: rohc_comp_internals.h:201
bool(* rohc_rtp_detection_callback_t)(const unsigned char *const ip, const unsigned char *const udp, const unsigned char *const payload, const unsigned int payload_size, void *const rtp_private)
The prototype of the RTP detection callback.
Definition: rohc_comp.h:263
The ROHC compression context.
Definition: rohc_comp_internals.h:329
rohc_mode_t mode
Definition: rohc_comp_internals.h:356
const struct rohc_comp_profile * profile
Definition: rohc_comp_internals.h:345
int used
Definition: rohc_comp_internals.h:332
size_t rru_off
Definition: rohc_comp_internals.h:164
const rohc_profile_t id
Definition: rohc_comp_internals.h:237
void * specific
Definition: rohc_comp_internals.h:347
Definition: net_pkt.h:39
rohc_comp_state_t state
Definition: rohc_comp_internals.h:358
bool do_ctxt_replication
Definition: rohc_comp_internals.h:350
size_t rru_len
Definition: rohc_comp_internals.h:166
int total_uncompressed_size
Definition: rohc_comp_internals.h:182
size_t so_count
Definition: rohc_comp_internals.h:370
int total_last_compressed_size
Definition: rohc_comp_internals.h:411
int total_uncompressed_size
Definition: rohc_comp_internals.h:400
bool enabled_profiles[C_NUM_PROFILES]
Definition: rohc_comp_internals.h:143
#define C_NUM_PROFILES
Definition: rohc_comp_internals.h:46
uint8_t crc_table_3[256]
Definition: rohc_comp_internals.h:149
A timestamp for the ROHC library.
Definition: rohc_time.h:51
rohc_packet_t packet_type
Definition: rohc_comp_internals.h:363
size_t fo_count
Definition: rohc_comp_internals.h:368
uint64_t first_used
Definition: rohc_comp_internals.h:336
rohc_comp_features_t
The different features of the ROHC compressor.
Definition: rohc_comp.h:225
rohc_comp_state_t
The different ROHC compressor states.
Definition: rohc_comp.h:82
size_t ir_count
Definition: rohc_comp_internals.h:366
rohc_trace_callback2_t trace_callback
Definition: rohc_comp_internals.h:222
Definition of ROHC packets and extensions.
int header_compressed_size
Definition: rohc_comp_internals.h:406
void rohc_comp_change_state(struct rohc_comp_ctxt *const context, const rohc_comp_state_t new_state)
Change the state of the context.
Definition: rohc_comp.c:2873
int header_last_compressed_size
Definition: rohc_comp_internals.h:415
size_t list_trans_nr
Definition: rohc_comp_internals.h:219
void * rtp_private
Definition: rohc_comp_internals.h:174
size_t go_back_ir_count
The number of packet sent while in FO or SO state, used for the periodic refreshes of the context...
Definition: rohc_comp_internals.h:391
ROHC medium (CID characteristics)
Definition: rohc_internal.h:146
int num_packets
Definition: rohc_comp_internals.h:180
ROHC private common definitions and routines.
Definition: feedback.h:81
size_t periodic_refreshes_ir_timeout_pkts
Definition: rohc_comp_internals.h:204
size_t cr_count
Definition: rohc_comp_internals.h:372
size_t periodic_refreshes_fo_timeout_pkts
Definition: rohc_comp_internals.h:210
rohc_cid_t cr_base_cid
Definition: rohc_comp_internals.h:352
rohc_feedback_type
Definition: feedback.h:42
rohc_profile_t
The different ROHC compression/decompression profiles.
Definition: rohc.h:210
uint8_t crc_table_8[256]
Definition: rohc_comp_internals.h:153
uint8_t rru[ROHC_MAX_MRRU]
Definition: rohc_comp_internals.h:162
uint64_t periodic_refreshes_ir_timeout_time
Definition: rohc_comp_internals.h:207
rohc_packet_t
The different types of ROHC packets.
Definition: rohc_packets.h:55
void rohc_comp_periodic_down_transition(struct rohc_comp_ctxt *const context, const struct rohc_ts pkt_time)
Periodically change the context state after a certain number of packets.
Definition: rohc_comp.c:2900
size_t mrru
Definition: rohc_comp_internals.h:215
#define ROHC_MAX_MRRU
Definition: rohc_comp_internals.h:159
ROHC feedback definitions and formats.
Internal ROHC macros and functions for traces.