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_fingerprint.h"
34 #include "rohc_comp.h"
35 #include "schemes/comp_wlsb.h"
37 #include "feedback.h"
38 #include "hashtable.h"
39 
40 #include <stdbool.h>
41 
42 
43 /*
44  * Constants and macros
45  */
46 
47 /** The minimal number of repetitions for the Optimistic Approach */
48 #define ROHC_OA_REPEAT_DEFAULT 4U
49 
50 /** The default maximal number of packets sent in > IR states (= FO and SO
51  * states) before changing back the state to IR (periodic refreshes) */
52 #define CHANGE_TO_IR_COUNT 1700
53 
54 /** The default maximal delay (in ms) spent in > IR states (= FO and SO states)
55  * before changing back the state to IR (periodic refreshes) */
56 #define CHANGE_TO_IR_TIME 1000U
57 
58 /** The default maximal number of packets sent in > FO states (= SO state)
59  * before changing back the state to FO (periodic refreshes) */
60 #define CHANGE_TO_FO_COUNT 700
61 
62 /** The default maximal delay (in ms) spent in > FO states (= SO state)
63  * before changing back the state to FO (periodic refreshes) */
64 #define CHANGE_TO_FO_TIME 500U
65 
66 
67 /** Print a warning trace for the given compression context */
68 #define rohc_comp_warn(context, format, ...) \
69  rohc_warning((context)->compressor, ROHC_TRACE_COMP, \
70  (context)->profile->id, \
71  format, ##__VA_ARGS__)
72 
73 /** Print a debug trace for the given compression context */
74 #define rohc_comp_debug(context, format, ...) \
75  rohc_debug((context)->compressor, ROHC_TRACE_COMP, \
76  (context)->profile->id, \
77  format, ##__VA_ARGS__)
78 
79 /** Dump a buffer for the given compression context */
80 #define rohc_comp_dump_buf(context, descr, buf, buf_len) \
81  do { \
82  if(((context)->compressor->features & ROHC_COMP_FEATURE_DUMP_PACKETS) != 0) { \
83  rohc_dump_buf((context)->compressor->trace_callback, \
84  (context)->compressor->trace_callback_priv, \
85  ROHC_TRACE_COMP, ROHC_TRACE_DEBUG, \
86  descr, buf, buf_len); \
87  } \
88  } while(0)
89 
90 
91 /*
92  * Declare ROHC compression structures that are defined at the end of this
93  * file but used by other structures at the beginning of the file.
94  */
95 
96 struct rohc_comp_ctxt;
97 
98 
99 /*
100  * Definitions of ROHC compression structures
101  */
102 
103 
104 /**
105  * @brief The ROHC compressor
106  */
107 struct rohc_comp
108 {
109  /** The medium associated with the decompressor */
111 
112  /** Enabled/disabled features for the compressor */
114 
115  /** The array of compression contexts that use the compressor */
117  /** The number of compression contexts in use in the array */
122 
123  /** Which profiles are enabled and with one are not? */
125 
126  /* CRC-related variables: */
127 
128 
129  /* segment-related variables */
130 
131  /** The remaining bytes of the Reconstructed Reception Unit (RRU) waiting
132  * to be split into segments */
133  uint8_t *rru;
134  /** The offset of the remaining bytes in the RRU buffer */
135  size_t rru_off;
136  /** The number of the remaining bytes in the RRU buffer */
137  size_t rru_len;
138 
139 
140  /* variables related to RTP detection */
141 
142  /** The callback function used to detect RTP packet */
144  /** Pointer to an external memory area provided/used by the callback user */
145  void *rtp_private;
146 
147 
148  /* some statistics about the compression process: */
149 
150  /** The number of sent packets */
152  /** The size of all the received uncompressed IP packets */
154  /** The size of all the sent compressed ROHC packets */
156 
157  /** The last context used by the compressor */
159 
160 
161  /* random callback */
162 
163  /** The user-defined callback for random numbers */
165  /** Private data that will be given to the callback for random numbers */
167 
168 
169  /* user interaction variables: */
170 
171  /** The nr of Optimistic Approach repetitions to gain transmission confidence */
173  /** The reorder offset specifies how much reordering is handled by the
174  * W-LSB encoding of the MSN in ROHCv2 profiles */
176  /** The maximal number of packets sent in > IR states (= FO and SO
177  * states) before changing back the state to IR (periodic refreshes) */
179  /** The maximal delay spent in > IR states (= FO and SO states) before
180  * changing back the state to IR (periodic refreshes) */
182  /** The maximal number of packets sent in > FO states (= SO state)
183  * before changing back the state to FO (periodic refreshes) */
185  /** The maximal delay spent in > FO states (= SO state) before changing back
186  * the state to FO (periodic refreshes) */
188  /** Maximum Reconstructed Reception Unit */
189  size_t mrru;
190 
191  /** The callback function used to manage traces */
193  /** The private context of the callback function used to manage traces */
195 };
196 
197 
198 /**
199  * @brief The ROHC compression profile
200  *
201  * The object defines a ROHC profile. Each field must be filled in
202  * for each new profile.
203  */
205 {
206  /** The profile ID as reserved by IANA */
208 
209  /**
210  * @brief The handler used to create the profile-specific part of the
211  * compression context from a given packet
212  *
213  * @param context The compression context
214  * @param uncomp_pkt_hdrs The uncompressed headers to initialize the new context
215  * @return true if successful, false otherwise
216  */
217  bool (*create)(struct rohc_comp_ctxt *const context,
218  const struct rohc_pkt_hdrs *const uncomp_pkt_hdrs)
219  __attribute__((warn_unused_result, nonnull(1, 2)));
220 
221  /**
222  * @brief The handler used to create the profile-specific part of the
223  * compression context from a given context
224  */
225  bool (*clone)(struct rohc_comp_ctxt *const ctxt,
226  const struct rohc_comp_ctxt *const base_ctxt)
227  __attribute__((warn_unused_result, nonnull(1, 2)));
228 
229  /**
230  * @brief The handler used to destroy the profile-specific part of the
231  * compression context
232  */
233  void (*destroy)(struct rohc_comp_ctxt *const context)
234  __attribute__((nonnull(1)));
235 
236  /**
237  * @brief The handler used to check whether Context Replication is possible
238  */
239  bool (*is_cr_possible)(const struct rohc_comp_ctxt *const ctxt,
240  const struct rohc_pkt_hdrs *const pkt_hdrs)
241  __attribute__((warn_unused_result, nonnull(1, 2)));
242 
243  /**
244  * @brief The handler used to encode uncompressed IP packets
245  *
246  * @param context The compression context
247  * @param uncomp_pkt_hdrs The uncompressed headers to encode
248  * @param rohc_pkt OUT: The ROHC packet
249  * @param rohc_pkt_max_len The maximum length of the ROHC packet
250  * @param packet_type OUT: The type of ROHC packet that is created
251  * @return The length of the ROHC packet if successful,
252  * -1 otherwise
253  */
254  int (*encode)(struct rohc_comp_ctxt *const context,
255  const struct rohc_pkt_hdrs *const uncomp_pkt_hdrs,
256  uint8_t *const rohc_pkt,
257  const size_t rohc_pkt_max_len,
258  rohc_packet_t *const packet_type)
259  __attribute__((warn_unused_result, nonnull(1, 2, 3, 5)));
260 
261  /**
262  * @brief The handler used to warn the profile-specific part of the
263  * context about the arrival of feedback data
264  */
265  bool (*feedback)(struct rohc_comp_ctxt *const context,
266  const enum rohc_feedback_type feedback_type,
267  const uint8_t *const packet,
268  const size_t packet_len,
269  const uint8_t *const feedback_data,
270  const size_t feedback_data_len)
271  __attribute__((warn_unused_result, nonnull(1, 3, 5)));
272 };
273 
274 
275 /**
276  * @brief The ROHC compression context
277  */
279 {
284 
285  /** The fingerprint of the context */
287 
288  /** Whether the context is in use or not */
289  int used;
290  /** The time when the context was last used (in seconds) */
291  uint64_t latest_used;
292 
293  /** The context unique ID (CID) */
295 
296  /** The associated compressor */
298 
299  /** The associated profile */
300  const struct rohc_comp_profile *profile;
301  /** Profile-specific data, defined by the profiles */
302  void *specific;
303 
304  /** Whether Context Replication (CR) may be used */
306  /** The base context for Context Replication (CR) */
308 
309  /** The operation mode in which the context operates among:
310  * ROHC_U_MODE, ROHC_O_MODE, ROHC_R_MODE */
312  /** The operation state in which the context operates: IR, FO, SO */
314 
315  /* below are some statistics */
316 
317  /* The type of ROHC packet created for the last compressed packet */
319 
320  /** The number of packets sent while in the different compression states */
322 
323  /**
324  * @brief The number of packet sent while in SO state, used for the periodic
325  * refreshes of the context
326  * @see rohc_comp_periodic_down_transition
327  */
329  /**
330  * @brief The last time that the context was in FO state, used for the
331  * periodic refreshes of the context
332  * @see rohc_comp_periodic_down_transition
333  */
335  /**
336  * @brief The number of packet sent while in FO or SO state, used for the
337  * periodic refreshes of the context
338  * @see rohc_comp_periodic_down_transition
339  */
341  /**
342  * @brief The last time that the context was in IR state, used for the
343  * periodic refreshes of the context
344  * @see rohc_comp_periodic_down_transition
345  */
347 
348  /** The cumulated size of the uncompressed packets */
350  /** The cumulated size of the compressed packets */
352  /** The cumulated size of the uncompressed headers */
354  /** The cumulated size of the compressed headers */
356 
357  /** The total size of the last uncompressed packet */
359  /** The total size of the last compressed packet */
361  /** The header size of the last uncompressed packet */
363  /** The header size of the last compressed packet */
365 
366  /** The number of sent packets */
368 };
369 
370 
371 void rohc_comp_change_mode(struct rohc_comp_ctxt *const context,
372  const rohc_mode_t new_mode)
373  __attribute__((nonnull(1)));
374 
375 void rohc_comp_change_state(struct rohc_comp_ctxt *const context,
376  const rohc_comp_state_t new_state)
377  __attribute__((nonnull(1)));
378 
379 bool rohc_comp_reinit_context(struct rohc_comp_ctxt *const context)
380  __attribute__((warn_unused_result, nonnull(1)));
381 
382 bool rohc_comp_feedback_parse_opts(const struct rohc_comp_ctxt *const context,
383  const uint8_t *const packet,
384  const size_t packet_len,
385  const uint8_t *const feedback_data,
386  const size_t feedback_data_len,
387  size_t opts_present[ROHC_FEEDBACK_OPT_MAX],
388  uint32_t *const sn_bits,
389  size_t *const sn_bits_nr,
390  const rohc_feedback_crc_t crc_type,
391  uint8_t crc_in_packet,
392  size_t crc_pos_from_end)
393  __attribute__((warn_unused_result, nonnull(1, 2, 4, 6, 7, 8)));
394 
395 #endif
396 
int total_last_uncompressed_size
Definition: rohc_comp_internals.h:358
rohc_reordering_offset_t reorder_ratio
Definition: rohc_comp_internals.h:175
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:289
The unique fingerprint of one compression context or uncompressed packet.
uint8_t state_oa_repeat_nr
Definition: rohc_comp_internals.h:321
#define ROHC_PROFILE_ID_MINOR_MAX
Definition: rohc_profiles.h:57
void(* destroy)(struct rohc_comp_ctxt *const context)
The handler used to destroy the profile-specific part of the compression context. ...
Definition: rohc_comp_internals.h:233
struct rohc_comp_ctxt * contexts
Definition: rohc_comp_internals.h:116
void * random_cb_ctxt
Definition: rohc_comp_internals.h:166
int total_compressed_size
Definition: rohc_comp_internals.h:155
rohc_comp_features_t features
Definition: rohc_comp_internals.h:113
rohc_cid_t cid
Definition: rohc_comp_internals.h:294
rohc_reordering_offset_t
The different values of reordering offset.
Definition: rohc.h:204
rohc_mode_t
ROHC operation modes.
Definition: rohc.h:112
int header_last_uncompressed_size
Definition: rohc_comp_internals.h:362
struct hashtable contexts_cr
Definition: rohc_comp_internals.h:120
struct rohc_ts go_back_ir_time
The last time that the context was in IR state, used for the periodic refreshes of the context...
Definition: rohc_comp_internals.h:346
uint8_t oa_repetitions_nr
Definition: rohc_comp_internals.h:172
int header_uncompressed_size
Definition: rohc_comp_internals.h:353
bool rohc_comp_reinit_context(struct rohc_comp_ctxt *const context)
Re-initialize the given context.
Definition: rohc_comp.c:4127
uint16_t num_contexts_used
Definition: rohc_comp_internals.h:118
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:3879
ROHC compression routines.
The ROHC compressor.
Definition: rohc_comp_internals.h:107
int num_sent_packets
Definition: rohc_comp_internals.h:367
uint64_t periodic_refreshes_fo_timeout_time
Definition: rohc_comp_internals.h:187
struct rohc_comp_ctxt * next_cr
Definition: rohc_comp_internals.h:283
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, const rohc_feedback_crc_t crc_type, uint8_t crc_in_packet, size_t crc_pos_from_end)
Parse FEEDBACK-2 options.
Definition: rohc_comp.c:4226
rohc_comp_random_cb_t random_cb
Definition: rohc_comp_internals.h:164
uint64_t latest_used
Definition: rohc_comp_internals.h:291
struct rohc_comp * compressor
Definition: rohc_comp_internals.h:297
struct rohc_comp_ctxt * uncompressed_ctxt
Definition: rohc_comp_internals.h:121
struct rohc_comp_ctxt * last_context
Definition: rohc_comp_internals.h:158
void * trace_callback_priv
Definition: rohc_comp_internals.h:194
bool enabled_profiles[ROHC_PROFILE_ID_MAJOR_MAX+1][ROHC_PROFILE_ID_MINOR_MAX+1]
Definition: rohc_comp_internals.h:124
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
struct rohc_comp_ctxt * prev
Definition: rohc_comp_internals.h:280
int total_compressed_size
Definition: rohc_comp_internals.h:351
uint8_t * rru
Definition: rohc_comp_internals.h:133
bool(* feedback)(struct rohc_comp_ctxt *const context, const enum rohc_feedback_type feedback_type, const uint8_t *const packet, const size_t packet_len, const uint8_t *const feedback_data, const size_t feedback_data_len)
The handler used to warn the profile-specific part of the context about the arrival of feedback data...
Definition: rohc_comp_internals.h:265
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:328
The ROHC compression profile.
Definition: rohc_comp_internals.h:204
struct rohc_medium medium
Definition: rohc_comp_internals.h:110
rohc_rtp_detection_callback_t rtp_callback
Definition: rohc_comp_internals.h:143
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:264
The ROHC compression context.
Definition: rohc_comp_internals.h:278
rohc_mode_t mode
Definition: rohc_comp_internals.h:311
const struct rohc_comp_profile * profile
Definition: rohc_comp_internals.h:300
int used
Definition: rohc_comp_internals.h:289
size_t rru_off
Definition: rohc_comp_internals.h:135
const rohc_profile_t id
Definition: rohc_comp_internals.h:207
bool nonnull(1)))
struct rohc_ts go_back_fo_time
The last time that the context was in FO state, used for the periodic refreshes of the context...
Definition: rohc_comp_internals.h:334
Information about the uncompressed packet headers.
void * specific
Definition: rohc_comp_internals.h:302
rohc_comp_state_t state
Definition: rohc_comp_internals.h:313
bool do_ctxt_replication
Definition: rohc_comp_internals.h:305
struct rohc_fingerprint fingerprint
Definition: rohc_comp_internals.h:286
struct rohc_comp_ctxt * next
Definition: rohc_comp_internals.h:281
size_t rru_len
Definition: rohc_comp_internals.h:137
int total_uncompressed_size
Definition: rohc_comp_internals.h:153
int total_last_compressed_size
Definition: rohc_comp_internals.h:360
int total_uncompressed_size
Definition: rohc_comp_internals.h:349
A timestamp for the ROHC library.
Definition: rohc_time.h:51
rohc_packet_t packet_type
Definition: rohc_comp_internals.h:318
rohc_comp_features_t
The different features of the ROHC compressor.
Definition: rohc_comp.h:226
The information collected about the packet headers.
Definition: uncomp_pkt_hdrs.h:102
rohc_comp_state_t
The different ROHC compressor states.
Definition: rohc_comp.h:83
rohc_trace_callback2_t trace_callback
Definition: rohc_comp_internals.h:192
Definition of ROHC packets and extensions.
int header_compressed_size
Definition: rohc_comp_internals.h:355
bool(* create)(struct rohc_comp_ctxt *const context, const struct rohc_pkt_hdrs *const uncomp_pkt_hdrs)
The handler used to create the profile-specific part of the compression context from a given packet...
Definition: rohc_comp_internals.h:217
bool(* is_cr_possible)(const struct rohc_comp_ctxt *const ctxt, const struct rohc_pkt_hdrs *const pkt_hdrs)
The handler used to check whether Context Replication is possible.
Definition: rohc_comp_internals.h:239
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:3939
int header_last_compressed_size
Definition: rohc_comp_internals.h:364
void * rtp_private
Definition: rohc_comp_internals.h:145
uint16_t rohc_cid_t
Definition: rohc.h:196
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:340
ROHC medium (CID characteristics)
Definition: rohc_internal.h:211
int num_packets
Definition: rohc_comp_internals.h:151
ROHC private common definitions and routines.
struct rohc_comp_ctxt * prev_cr
Definition: rohc_comp_internals.h:282
struct hashtable contexts_by_fingerprint
Definition: rohc_comp_internals.h:119
Definition: feedback.h:95
size_t periodic_refreshes_ir_timeout_pkts
Definition: rohc_comp_internals.h:178
size_t periodic_refreshes_fo_timeout_pkts
Definition: rohc_comp_internals.h:184
The unique fingerprint of one compression context or uncompressed packet.
Definition: rohc_fingerprint.h:69
rohc_cid_t cr_base_cid
Definition: rohc_comp_internals.h:307
rohc_feedback_type
Definition: feedback.h:42
bool(* clone)(struct rohc_comp_ctxt *const ctxt, const struct rohc_comp_ctxt *const base_ctxt)
The handler used to create the profile-specific part of the compression context from a given context...
Definition: rohc_comp_internals.h:225
rohc_profile_t
The different ROHC compression/decompression profiles.
Definition: rohc_profiles.h:76
Definition: hashtable.h:45
uint64_t periodic_refreshes_ir_timeout_time
Definition: rohc_comp_internals.h:181
rohc_packet_t
The different types of ROHC packets.
Definition: rohc_packets.h:55
Efficient, secure hash table.
size_t mrru
Definition: rohc_comp_internals.h:189
ROHC feedback definitions and formats.
int(* encode)(struct rohc_comp_ctxt *const context, const struct rohc_pkt_hdrs *const uncomp_pkt_hdrs, uint8_t *const rohc_pkt, const size_t rohc_pkt_max_len, rohc_packet_t *const packet_type)
The handler used to encode uncompressed IP packets.
Definition: rohc_comp_internals.h:254
#define ROHC_PROFILE_ID_MAJOR_MAX
Definition: rohc_profiles.h:54
rohc_feedback_crc_t
Whether the feedback is protected by a CRC or not.
Definition: feedback.h:62
Internal ROHC macros and functions for traces.