| OLD | NEW |
| 1 /* | 1 /* |
| 2 * rdbx_driver.c | 2 * rdbx_driver.c |
| 3 * | 3 * |
| 4 * driver for the rdbx implementation (replay database with extended range) | 4 * driver for the rdbx implementation (replay database with extended range) |
| 5 * | 5 * |
| 6 * David A. McGrew | 6 * David A. McGrew |
| 7 * Cisco Systems, Inc. | 7 * Cisco Systems, Inc. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /* | 10 /* |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #ifdef HAVE_CONFIG_H | 46 #ifdef HAVE_CONFIG_H |
| 47 #include <config.h> | 47 #include <config.h> |
| 48 #endif | 48 #endif |
| 49 | 49 |
| 50 #include <stdio.h> /* for printf() */ | 50 #include <stdio.h> /* for printf() */ |
| 51 #include "getopt_s.h" /* for local getopt() */ | 51 #include "getopt_s.h" /* for local getopt() */ |
| 52 | 52 |
| 53 #include "rdbx.h" | 53 #include "rdbx.h" |
| 54 | 54 |
| 55 #ifdef ROC_TEST | 55 #ifdef ROC_TEST |
| 56 #error "rdbx_t won't work with ROC_TEST - bitmask same size as seq_median" | 56 #error "srtp_rdbx_t won't work with ROC_TEST - bitmask same size as seq_median" |
| 57 #endif | 57 #endif |
| 58 | 58 |
| 59 #include "ut_sim.h" | 59 #include "ut_sim.h" |
| 60 | 60 |
| 61 err_status_t | 61 srtp_err_status_t |
| 62 test_replay_dbx(int num_trials, unsigned long ws); | 62 test_replay_dbx(int num_trials, unsigned long ws); |
| 63 | 63 |
| 64 double | 64 double |
| 65 rdbx_check_adds_per_second(int num_trials, unsigned long ws); | 65 rdbx_check_adds_per_second(int num_trials, unsigned long ws); |
| 66 | 66 |
| 67 void | 67 void |
| 68 usage(char *prog_name) { | 68 usage(char *prog_name) { |
| 69 printf("usage: %s [ -t | -v ]\n", prog_name); | 69 printf("usage: %s [ -t | -v ]\n", prog_name); |
| 70 exit(255); | 70 exit(255); |
| 71 } | 71 } |
| 72 | 72 |
| 73 int | 73 int |
| 74 main (int argc, char *argv[]) { | 74 main (int argc, char *argv[]) { |
| 75 double rate; | 75 double rate; |
| 76 err_status_t status; | 76 srtp_err_status_t status; |
| 77 int q; | 77 int q; |
| 78 unsigned do_timing_test = 0; | 78 unsigned do_timing_test = 0; |
| 79 unsigned do_validation = 0; | 79 unsigned do_validation = 0; |
| 80 | 80 |
| 81 /* process input arguments */ | 81 /* process input arguments */ |
| 82 while (1) { | 82 while (1) { |
| 83 q = getopt_s(argc, argv, "tv"); | 83 q = getopt_s(argc, argv, "tv"); |
| 84 if (q == -1) | 84 if (q == -1) |
| 85 break; | 85 break; |
| 86 switch (q) { | 86 switch (q) { |
| 87 case 't': | 87 case 't': |
| 88 do_timing_test = 1; | 88 do_timing_test = 1; |
| 89 break; | 89 break; |
| 90 case 'v': | 90 case 'v': |
| 91 do_validation = 1; | 91 do_validation = 1; |
| 92 break; | 92 break; |
| 93 default: | 93 default: |
| 94 usage(argv[0]); | 94 usage(argv[0]); |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 printf("rdbx (replay database w/ extended range) test driver\n" | 98 printf("rdbx (replay database w/ extended range) test driver\n" |
| 99 "David A. McGrew\n" | 99 "David A. McGrew\n" |
| 100 "Cisco Systems, Inc.\n"); | 100 "Cisco Systems, Inc.\n"); |
| 101 | 101 |
| 102 if (!do_validation && !do_timing_test) | 102 if (!do_validation && !do_timing_test) |
| 103 usage(argv[0]); | 103 usage(argv[0]); |
| 104 | 104 |
| 105 if (do_validation) { | 105 if (do_validation) { |
| 106 printf("testing rdbx_t (ws=128)...\n"); | 106 printf("testing srtp_rdbx_t (ws=128)...\n"); |
| 107 | 107 |
| 108 status = test_replay_dbx(1 << 12, 128); | 108 status = test_replay_dbx(1 << 12, 128); |
| 109 if (status) { | 109 if (status) { |
| 110 printf("failed\n"); | 110 printf("failed\n"); |
| 111 exit(1); | 111 exit(1); |
| 112 } | 112 } |
| 113 printf("passed\n"); | 113 printf("passed\n"); |
| 114 | 114 |
| 115 printf("testing rdbx_t (ws=1024)...\n"); | 115 printf("testing srtp_rdbx_t (ws=1024)...\n"); |
| 116 | 116 |
| 117 status = test_replay_dbx(1 << 12, 1024); | 117 status = test_replay_dbx(1 << 12, 1024); |
| 118 if (status) { | 118 if (status) { |
| 119 printf("failed\n"); | 119 printf("failed\n"); |
| 120 exit(1); | 120 exit(1); |
| 121 } | 121 } |
| 122 printf("passed\n"); | 122 printf("passed\n"); |
| 123 } | 123 } |
| 124 | 124 |
| 125 if (do_timing_test) { | 125 if (do_timing_test) { |
| 126 rate = rdbx_check_adds_per_second(1 << 18, 128); | 126 rate = rdbx_check_adds_per_second(1 << 18, 128); |
| 127 printf("rdbx_check/replay_adds per second (ws=128): %e\n", rate); | 127 printf("rdbx_check/replay_adds per second (ws=128): %e\n", rate); |
| 128 rate = rdbx_check_adds_per_second(1 << 18, 1024); | 128 rate = rdbx_check_adds_per_second(1 << 18, 1024); |
| 129 printf("rdbx_check/replay_adds per second (ws=1024): %e\n", rate); | 129 printf("rdbx_check/replay_adds per second (ws=1024): %e\n", rate); |
| 130 } | 130 } |
| 131 | 131 |
| 132 return 0; | 132 return 0; |
| 133 } | 133 } |
| 134 | 134 |
| 135 void | 135 void |
| 136 print_rdbx(rdbx_t *rdbx) { | 136 print_rdbx(srtp_rdbx_t *rdbx) { |
| 137 char buf[2048]; | 137 char buf[2048]; |
| 138 printf("rdbx: {%llu, %s}\n", | 138 printf("rdbx: {%llu, %s}\n", |
| 139 (unsigned long long)(rdbx->index), | 139 (unsigned long long)(rdbx->index), |
| 140 bitvector_bit_string(&rdbx->bitmask, buf, sizeof(buf)) | 140 bitvector_bit_string(&rdbx->bitmask, buf, sizeof(buf)) |
| 141 ); | 141 ); |
| 142 } | 142 } |
| 143 | 143 |
| 144 | 144 |
| 145 /* | 145 /* |
| 146 * rdbx_check_add(rdbx, idx) checks a known-to-be-good idx against | 146 * rdbx_check_add(rdbx, idx) checks a known-to-be-good idx against |
| 147 * rdbx, then adds it. if a failure is detected (i.e., the check | 147 * rdbx, then adds it. if a failure is detected (i.e., the check |
| 148 * indicates that the value is already in rdbx) then | 148 * indicates that the value is already in rdbx) then |
| 149 * err_status_algo_fail is returned. | 149 * srtp_err_status_algo_fail is returned. |
| 150 * | 150 * |
| 151 */ | 151 */ |
| 152 | 152 |
| 153 err_status_t | 153 srtp_err_status_t |
| 154 rdbx_check_add(rdbx_t *rdbx, uint32_t idx) { | 154 rdbx_check_add(srtp_rdbx_t *rdbx, uint32_t idx) { |
| 155 int delta; | 155 int delta; |
| 156 xtd_seq_num_t est; | 156 srtp_xtd_seq_num_t est; |
| 157 | 157 |
| 158 delta = index_guess(&rdbx->index, &est, idx); | 158 delta = srtp_index_guess(&rdbx->index, &est, idx); |
| 159 | 159 |
| 160 if (rdbx_check(rdbx, delta) != err_status_ok) { | 160 if (srtp_rdbx_check(rdbx, delta) != srtp_err_status_ok) { |
| 161 printf("replay_check failed at index %u\n", idx); | 161 printf("replay_check failed at index %u\n", idx); |
| 162 return err_status_algo_fail; | 162 return srtp_err_status_algo_fail; |
| 163 } | 163 } |
| 164 | 164 |
| 165 /* | 165 /* |
| 166 * in practice, we'd authenticate the packet containing idx, using | 166 * in practice, we'd authenticate the packet containing idx, using |
| 167 * the estimated value est, at this point | 167 * the estimated value est, at this point |
| 168 */ | 168 */ |
| 169 | 169 |
| 170 if (rdbx_add_index(rdbx, delta) != err_status_ok) { | 170 if (srtp_rdbx_add_index(rdbx, delta) != srtp_err_status_ok) { |
| 171 printf("rdbx_add_index failed at index %u\n", idx); | 171 printf("rdbx_add_index failed at index %u\n", idx); |
| 172 return err_status_algo_fail; | 172 return srtp_err_status_algo_fail; |
| 173 } | 173 } |
| 174 | 174 |
| 175 return err_status_ok; | 175 return srtp_err_status_ok; |
| 176 } | 176 } |
| 177 | 177 |
| 178 /* | 178 /* |
| 179 * rdbx_check_expect_failure(rdbx_t *rdbx, uint32_t idx) | 179 * rdbx_check_expect_failure(srtp_rdbx_t *rdbx, uint32_t idx) |
| 180 * | 180 * |
| 181 * checks that a sequence number idx is in the replay database | 181 * checks that a sequence number idx is in the replay database |
| 182 * and thus will be rejected | 182 * and thus will be rejected |
| 183 */ | 183 */ |
| 184 | 184 |
| 185 err_status_t | 185 srtp_err_status_t |
| 186 rdbx_check_expect_failure(rdbx_t *rdbx, uint32_t idx) { | 186 rdbx_check_expect_failure(srtp_rdbx_t *rdbx, uint32_t idx) { |
| 187 int delta; | 187 int delta; |
| 188 xtd_seq_num_t est; | 188 srtp_xtd_seq_num_t est; |
| 189 err_status_t status; | 189 srtp_err_status_t status; |
| 190 | 190 |
| 191 delta = index_guess(&rdbx->index, &est, idx); | 191 delta = srtp_index_guess(&rdbx->index, &est, idx); |
| 192 | 192 |
| 193 status = rdbx_check(rdbx, delta); | 193 status = srtp_rdbx_check(rdbx, delta); |
| 194 if (status == err_status_ok) { | 194 if (status == srtp_err_status_ok) { |
| 195 printf("delta: %d ", delta); | 195 printf("delta: %d ", delta); |
| 196 printf("replay_check failed at index %u (false positive)\n", idx); | 196 printf("replay_check failed at index %u (false positive)\n", idx); |
| 197 return err_status_algo_fail; | 197 return srtp_err_status_algo_fail; |
| 198 } | 198 } |
| 199 | 199 |
| 200 return err_status_ok; | 200 return srtp_err_status_ok; |
| 201 } | 201 } |
| 202 | 202 |
| 203 err_status_t | 203 srtp_err_status_t |
| 204 rdbx_check_add_unordered(rdbx_t *rdbx, uint32_t idx) { | 204 rdbx_check_add_unordered(srtp_rdbx_t *rdbx, uint32_t idx) { |
| 205 int delta; | 205 int delta; |
| 206 xtd_seq_num_t est; | 206 srtp_xtd_seq_num_t est; |
| 207 err_status_t rstat; | 207 srtp_err_status_t rstat; |
| 208 | 208 |
| 209 delta = index_guess(&rdbx->index, &est, idx); | 209 delta = srtp_index_guess(&rdbx->index, &est, idx); |
| 210 | 210 |
| 211 rstat = rdbx_check(rdbx, delta); | 211 rstat = srtp_rdbx_check(rdbx, delta); |
| 212 if ((rstat != err_status_ok) && (rstat != err_status_replay_old)) { | 212 if ((rstat != srtp_err_status_ok) && (rstat != srtp_err_status_replay_old)) { |
| 213 printf("replay_check_add_unordered failed at index %u\n", idx); | 213 printf("replay_check_add_unordered failed at index %u\n", idx); |
| 214 return err_status_algo_fail; | 214 return srtp_err_status_algo_fail; |
| 215 } | 215 } |
| 216 if (rstat == err_status_replay_old) { | 216 if (rstat == srtp_err_status_replay_old) { |
| 217 » return err_status_ok; | 217 » return srtp_err_status_ok; |
| 218 } | 218 } |
| 219 if (rdbx_add_index(rdbx, delta) != err_status_ok) { | 219 if (srtp_rdbx_add_index(rdbx, delta) != srtp_err_status_ok) { |
| 220 printf("rdbx_add_index failed at index %u\n", idx); | 220 printf("rdbx_add_index failed at index %u\n", idx); |
| 221 return err_status_algo_fail; | 221 return srtp_err_status_algo_fail; |
| 222 } | 222 } |
| 223 | 223 |
| 224 return err_status_ok; | 224 return srtp_err_status_ok; |
| 225 } | 225 } |
| 226 | 226 |
| 227 err_status_t | 227 srtp_err_status_t |
| 228 test_replay_dbx(int num_trials, unsigned long ws) { | 228 test_replay_dbx(int num_trials, unsigned long ws) { |
| 229 rdbx_t rdbx; | 229 srtp_rdbx_t rdbx; |
| 230 uint32_t idx, ircvd; | 230 uint32_t idx, ircvd; |
| 231 ut_connection utc; | 231 ut_connection utc; |
| 232 err_status_t status; | 232 srtp_err_status_t status; |
| 233 int num_fp_trials; | 233 int num_fp_trials; |
| 234 | 234 |
| 235 status = rdbx_init(&rdbx, ws); | 235 status = srtp_rdbx_init(&rdbx, ws); |
| 236 if (status) { | 236 if (status) { |
| 237 printf("replay_init failed with error code %d\n", status); | 237 printf("replay_init failed with error code %d\n", status); |
| 238 exit(1); | 238 exit(1); |
| 239 } | 239 } |
| 240 | 240 |
| 241 /* | 241 /* |
| 242 * test sequential insertion | 242 * test sequential insertion |
| 243 */ | 243 */ |
| 244 printf("\ttesting sequential insertion..."); | 244 printf("\ttesting sequential insertion..."); |
| 245 for (idx=0; (int) idx < num_trials; idx++) { | 245 for (idx=0; (int) idx < num_trials; idx++) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 262 } | 262 } |
| 263 printf("\ttesting for false positives..."); | 263 printf("\ttesting for false positives..."); |
| 264 for (idx=0; (int) idx < num_fp_trials; idx++) { | 264 for (idx=0; (int) idx < num_fp_trials; idx++) { |
| 265 status = rdbx_check_expect_failure(&rdbx, idx); | 265 status = rdbx_check_expect_failure(&rdbx, idx); |
| 266 if (status) | 266 if (status) |
| 267 return status; | 267 return status; |
| 268 } | 268 } |
| 269 printf("passed\n"); | 269 printf("passed\n"); |
| 270 | 270 |
| 271 /* re-initialize */ | 271 /* re-initialize */ |
| 272 rdbx_dealloc(&rdbx); | 272 srtp_rdbx_dealloc(&rdbx); |
| 273 | 273 |
| 274 if (rdbx_init(&rdbx, ws) != err_status_ok) { | 274 if (srtp_rdbx_init(&rdbx, ws) != srtp_err_status_ok) { |
| 275 printf("replay_init failed\n"); | 275 printf("replay_init failed\n"); |
| 276 return err_status_init_fail; | 276 return srtp_err_status_init_fail; |
| 277 } | 277 } |
| 278 | 278 |
| 279 /* | 279 /* |
| 280 * test non-sequential insertion | 280 * test non-sequential insertion |
| 281 * | 281 * |
| 282 * this test covers only fase negatives, since the values returned | 282 * this test covers only fase negatives, since the values returned |
| 283 * by ut_next_index(...) are distinct | 283 * by ut_next_index(...) are distinct |
| 284 */ | 284 */ |
| 285 ut_init(&utc); | 285 ut_init(&utc); |
| 286 | 286 |
| 287 printf("\ttesting non-sequential insertion..."); | 287 printf("\ttesting non-sequential insertion..."); |
| 288 for (idx=0; (int) idx < num_trials; idx++) { | 288 for (idx=0; (int) idx < num_trials; idx++) { |
| 289 ircvd = ut_next_index(&utc); | 289 ircvd = ut_next_index(&utc); |
| 290 status = rdbx_check_add_unordered(&rdbx, ircvd); | 290 status = rdbx_check_add_unordered(&rdbx, ircvd); |
| 291 if (status) | 291 if (status) |
| 292 return status; | 292 return status; |
| 293 status = rdbx_check_expect_failure(&rdbx, ircvd); | 293 status = rdbx_check_expect_failure(&rdbx, ircvd); |
| 294 if (status) | 294 if (status) |
| 295 return status; | 295 return status; |
| 296 } | 296 } |
| 297 printf("passed\n"); | 297 printf("passed\n"); |
| 298 | 298 |
| 299 /* re-initialize */ | 299 /* re-initialize */ |
| 300 rdbx_dealloc(&rdbx); | 300 srtp_rdbx_dealloc(&rdbx); |
| 301 | 301 |
| 302 if (rdbx_init(&rdbx, ws) != err_status_ok) { | 302 if (srtp_rdbx_init(&rdbx, ws) != srtp_err_status_ok) { |
| 303 printf("replay_init failed\n"); | 303 printf("replay_init failed\n"); |
| 304 return err_status_init_fail; | 304 return srtp_err_status_init_fail; |
| 305 } | 305 } |
| 306 | 306 |
| 307 /* | 307 /* |
| 308 * test insertion with large gaps. | 308 * test insertion with large gaps. |
| 309 * check for false positives for each insertion. | 309 * check for false positives for each insertion. |
| 310 */ | 310 */ |
| 311 printf("\ttesting insertion with large gaps..."); | 311 printf("\ttesting insertion with large gaps..."); |
| 312 for (idx=0, ircvd=0; (int) idx < num_trials; idx++, ircvd += (1 << (rand() % 1
2))) { | 312 for (idx=0, ircvd=0; (int) idx < num_trials; idx++, ircvd += (1 << (rand() % 1
2))) { |
| 313 status = rdbx_check_add(&rdbx, ircvd); | 313 status = rdbx_check_add(&rdbx, ircvd); |
| 314 if (status) | 314 if (status) |
| 315 return status; | 315 return status; |
| 316 status = rdbx_check_expect_failure(&rdbx, ircvd); | 316 status = rdbx_check_expect_failure(&rdbx, ircvd); |
| 317 if (status) | 317 if (status) |
| 318 return status; | 318 return status; |
| 319 } | 319 } |
| 320 printf("passed\n"); | 320 printf("passed\n"); |
| 321 | 321 |
| 322 rdbx_dealloc(&rdbx); | 322 srtp_rdbx_dealloc(&rdbx); |
| 323 | 323 |
| 324 return err_status_ok; | 324 return srtp_err_status_ok; |
| 325 } | 325 } |
| 326 | 326 |
| 327 | 327 |
| 328 | 328 |
| 329 #include <time.h> /* for clock() */ | 329 #include <time.h> /* for clock() */ |
| 330 #include <stdlib.h> /* for random() */ | 330 #include <stdlib.h> /* for random() */ |
| 331 | 331 |
| 332 double | 332 double |
| 333 rdbx_check_adds_per_second(int num_trials, unsigned long ws) { | 333 rdbx_check_adds_per_second(int num_trials, unsigned long ws) { |
| 334 uint32_t i; | 334 uint32_t i; |
| 335 int delta; | 335 int delta; |
| 336 rdbx_t rdbx; | 336 srtp_rdbx_t rdbx; |
| 337 xtd_seq_num_t est; | 337 srtp_xtd_seq_num_t est; |
| 338 clock_t timer; | 338 clock_t timer; |
| 339 int failures; /* count number of failures */ | 339 int failures; /* count number of failures */ |
| 340 | 340 |
| 341 if (rdbx_init(&rdbx, ws) != err_status_ok) { | 341 if (srtp_rdbx_init(&rdbx, ws) != srtp_err_status_ok) { |
| 342 printf("replay_init failed\n"); | 342 printf("replay_init failed\n"); |
| 343 exit(1); | 343 exit(1); |
| 344 } | 344 } |
| 345 | 345 |
| 346 failures = 0; | 346 failures = 0; |
| 347 timer = clock(); | 347 timer = clock(); |
| 348 for(i=0; (int) i < num_trials; i++) { | 348 for(i=0; (int) i < num_trials; i++) { |
| 349 | 349 |
| 350 delta = index_guess(&rdbx.index, &est, i); | 350 delta = srtp_index_guess(&rdbx.index, &est, i); |
| 351 | 351 |
| 352 if (rdbx_check(&rdbx, delta) != err_status_ok) | 352 if (srtp_rdbx_check(&rdbx, delta) != srtp_err_status_ok) |
| 353 ++failures; | 353 ++failures; |
| 354 else | 354 else |
| 355 if (rdbx_add_index(&rdbx, delta) != err_status_ok) | 355 if (srtp_rdbx_add_index(&rdbx, delta) != srtp_err_status_ok) |
| 356 ++failures; | 356 ++failures; |
| 357 } | 357 } |
| 358 timer = clock() - timer; | 358 timer = clock() - timer; |
| 359 | 359 |
| 360 printf("number of failures: %d \n", failures); | 360 printf("number of failures: %d \n", failures); |
| 361 | 361 |
| 362 rdbx_dealloc(&rdbx); | 362 srtp_rdbx_dealloc(&rdbx); |
| 363 | 363 |
| 364 return (double) CLOCKS_PER_SEC * num_trials / timer; | 364 return (double) CLOCKS_PER_SEC * num_trials / timer; |
| 365 } | 365 } |
| 366 | 366 |
| OLD | NEW |