1 /* 2 * reporting.h -- performance metrics reporting, headers. 3 * 4 * Written by Stanislav Shalunov, http://www.internet2.edu/~shalunov/ 5 * Bernhard Lutzmann, belu@users.sf.net 6 * Federico Montesino Pouzols, fedemp@altern.org 7 * 8 * @(#) $Id: reporting.h,v 1.1.2.5 2006/08/20 18:06:19 fedemp Exp $ 9 * 10 * Copyright 2005, 2006, Internet2. 11 * Legal conditions are in file LICENSE 12 * (MD5 = ecfa50d1b0bfbb81b658c810d0476a52). 13 */ 14 15 #ifndef THRULAY_REPORTING_H_INCLUDED 16 #define THRULAY_REPORTING_H_INCLUDED 17 18 /** 19 * @file reporting.h 20 * 21 * @short metrics computation and reporting (header). 22 **/ 23 24 /** 25 * Initialize reordering. 26 * 27 * 28 * @return 29 * @retval 0 on success. 30 * @retval -1 on error (failed calloc()). 31 */ 32 int 33 reordering_init(uint64_t max); 34 35 /** 36 * Update reordering accounting for next received packet. 37 * 38 * @param packet_sqn packet sequence number. 39 * 40 * @return 41 * @retval 0 on success. 42 */ 43 int 44 reordering_checkin(uint64_t packet_sqn); 45 46 /** 47 * Get j-1 reordering. 48 * 49 * @return j-1 reordering. 50 */ 51 double 52 reordering_output(uint64_t j); 53 54 /** 55 * Deinitialize reordering. 56 */ 57 void 58 reordering_exit (void); 59 60 /** 61 * Initialize duplication. 62 * 63 * @return 64 * @retval 0 on success. 65 * @retval -1 on error (failed malloc()). 66 */ 67 int 68 duplication_init(uint64_t npackets); 69 70 /** 71 * Update duplication accounting for next received packet and check 72 * whether it is duplicated. 73 * 74 * @param packet_sqn packet sequence number. 75 * 76 * @return 77 * @retval 0 if not duplicated. 78 * @retval 1 if duplicated. 79 */ 80 int 81 duplication_check(uint64_t packet_sqn); 82 83 /** 84 * Deinitialize duplication. 85 */ 86 void 87 duplication_exit(void); 88 89 /* 90 * Quantiles 91 * 92 * References: 93 * [1] Manku, Rajagopalan, Lindsay: "Approximate Medians and other Quantiles 94 * in One Pass and with Limited Memory", 95 * http://www-db.stanford.edu/~manku/papers/98sigmod-quantiles.pdf 96 */ 97 98 #define QUANTILE_EPS 0.005 99 100 /** 101 * Initialize quantiles. This sets values for `quantile_b' and `quantile_k'. 102 * Then allocates memory for quantile buffers and input buffer. 103 * 104 * @param max_seq Maximum number of sequences that should be handled 105 * in parallel. 106 * 107 * @return 108 * @retval 0 on success. 109 * @retval -1 on error (failed malloc()). 110 * 111 * See section 4.5 "The New Algorithm" of paper [1] (see above). 112 **/ 113 int 114 quantile_init(uint16_t max_seq, double eps, uint64_t N); 115 116 int 117 quantile_init_seq(uint16_t seq); 118 119 /** 120 * Update quantiles for next value. 121 * 122 * @param seq Sequence index. 123 * 124 * @return 125 * @retval 0 on success. 126 * @retval -1 quantiles not initialized. 127 * @retval -2 need an empty buffer for new operation. 128 * @retval -3 bad input sequence length in new operation. 129 * @retval -4 not enough buffers for collapse operation. 130 * @retval -5 bad sequence index. 131 */ 132 int 133 quantile_value_checkin(uint16_t seq, double value); 134 135 /* 136 * Perform last algorithm operation with a possibly not full 137 * input buffer. 138 * 139 * @param seq Sequence index. 140 * 141 * @return 142 * @retval 0 on success. 143 * @retval -1 quantiles not initialized. 144 * @retval -2 need an empty buffer for new operation. 145 * @retval -3 bad input sequence length in new operation. 146 * @retval -4 not enough buffers for collapse operation. 147 */ 148 int 149 quantile_finish(uint16_t seq); 150 151 /* Implementation of OUTPUT operation from section 3.3 of paper [1]. 152 * 153 * Takes c>= full input buffers in linked list. Fourth parameter is set 154 * to phi-quantile. 155 * 156 * @param seq Sequence index 157 * 158 * @return 159 * @retval 0 on success. 160 * @retval -1 bad number of full buffers. 161 */ 162 int 163 quantile_output(uint16_t seq, uint64_t npackets, double phi, double *result); 164 165 /** 166 * Deinitializes a quantile sequence. Free memory of quantile buffers 167 * and input buffer. 168 * 169 * @param seq Sequence index. 170 **/ 171 void 172 quantile_exit_seq(uint16_t seq); 173 174 /** 175 * Deinitialize quantiles. Deinitializes all sequences and frees all 176 * structures. 177 **/ 178 void 179 quantile_exit(void); 180 181 #endif /* ifndef THRULAY_REPORTING_H_INCLUDED */ 182