4
* replay database with extended packet indices, using a rollover counter
14
#include "datatypes.h"
17
/* #define ROC_TEST */
21
typedef uint16_t sequence_number_t; /* 16 bit sequence number */
22
typedef uint32_t rollover_counter_t; /* 32 bit rollover counter */
24
#else /* use small seq_num and roc datatypes for testing purposes */
26
typedef unsigned char sequence_number_t; /* 8 bit sequence number */
27
typedef uint16_t rollover_counter_t; /* 16 bit rollover counter */
31
#define seq_num_median (1 << (8*sizeof(sequence_number_t) - 1))
32
#define seq_num_max (1 << (8*sizeof(sequence_number_t)))
35
* An xtd_seq_num_t is a 64-bit unsigned integer used as an 'extended'
39
typedef uint64_t xtd_seq_num_t;
43
* An rdbx_t is a replay database with extended range; it uses an
44
* xtd_seq_num_t and a bitmask of recently received indices.
56
* initializes the rdbx pointed to by its argument, setting the
57
* rollover counter and sequence number to zero
61
rdbx_init(rdbx_t *rdbx);
65
* rdbx_estimate_index(rdbx, guess, s)
67
* given an rdbx and a sequence number s (from a newly arrived packet),
68
* sets the contents of *guess to contain the best guess of the packet
69
* index to which s corresponds, and returns the difference between
70
* *guess and the locally stored synch info
74
rdbx_estimate_index(const rdbx_t *rdbx,
79
* rdbx_check(rdbx, delta);
81
* rdbx_check(&r, delta) checks to see if the xtd_seq_num_t
82
* which is at rdbx->window_start + delta is in the rdb
87
rdbx_check(const rdbx_t *rdbx, int difference);
90
* replay_add_index(rdbx, delta)
92
* adds the xtd_seq_num_t at rdbx->window_start + delta to replay_db
93
* (and does *not* check if that xtd_seq_num_t appears in db)
95
* this function should be called *only* after replay_check has
96
* indicated that the index does not appear in the rdbx, and a mutex
97
* should protect the rdbx between these calls if necessary.
101
rdbx_add_index(rdbx_t *rdbx, int delta);
104
* xtd_seq_num_t functions - these are *internal* functions of rdbx, and
105
* shouldn't be used to manipulate rdbx internal values. use the rdbx
110
/* index_init(&pi) initializes a packet index pi (sets it to zero) */
113
index_init(xtd_seq_num_t *pi);
115
/* index_advance(&pi, s) advances a xtd_seq_num_t forward by s */
118
index_advance(xtd_seq_num_t *pi, sequence_number_t s);
122
* index_guess(local, guess, s)
124
* given a xtd_seq_num_t local (which represents the highest
125
* known-to-be-good index) and a sequence number s (from a newly
126
* arrived packet), sets the contents of *guess to contain the best
127
* guess of the packet index to which s corresponds, and returns the
128
* difference between *guess and *local
132
index_guess(const xtd_seq_num_t *local,
133
xtd_seq_num_t *guess,
134
sequence_number_t s);