| OLD | NEW |
| 1 /* | 1 /* |
| 2 * replay_driver.c | 2 * replay_driver.c |
| 3 * | 3 * |
| 4 * A driver for the replay_database implementation | 4 * A driver for the replay_database implementation |
| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 #include "rdb.h" | 52 #include "rdb.h" |
| 53 #include "ut_sim.h" | 53 #include "ut_sim.h" |
| 54 | 54 |
| 55 /* | 55 /* |
| 56 * num_trials defines the number of trials that are used in the | 56 * num_trials defines the number of trials that are used in the |
| 57 * validation functions below | 57 * validation functions below |
| 58 */ | 58 */ |
| 59 | 59 |
| 60 unsigned num_trials = 1 << 16; | 60 unsigned num_trials = 1 << 16; |
| 61 | 61 |
| 62 err_status_t | 62 srtp_err_status_t |
| 63 test_rdb_db(void); | 63 test_rdb_db(void); |
| 64 | 64 |
| 65 double | 65 double |
| 66 rdb_check_adds_per_second(void); | 66 rdb_check_adds_per_second(void); |
| 67 | 67 |
| 68 int | 68 int |
| 69 main (void) { | 69 main (void) { |
| 70 err_status_t err; | 70 srtp_err_status_t err; |
| 71 | 71 |
| 72 printf("testing anti-replay database (rdb_t)...\n"); | 72 printf("testing anti-replay database (srtp_rdb_t)...\n"); |
| 73 err = test_rdb_db(); | 73 err = test_rdb_db(); |
| 74 if (err) { | 74 if (err) { |
| 75 printf("failed\n"); | 75 printf("failed\n"); |
| 76 exit(1); | 76 exit(1); |
| 77 } | 77 } |
| 78 printf("done\n"); | 78 printf("done\n"); |
| 79 | 79 |
| 80 printf("rdb_check/rdb_adds per second: %e\n", | 80 printf("rdb_check/rdb_adds per second: %e\n", |
| 81 rdb_check_adds_per_second()); | 81 rdb_check_adds_per_second()); |
| 82 | 82 |
| 83 return 0; | 83 return 0; |
| 84 } | 84 } |
| 85 | 85 |
| 86 | 86 |
| 87 void | 87 void |
| 88 print_rdb(rdb_t *rdb) { | 88 print_rdb(srtp_rdb_t *rdb) { |
| 89 printf("rdb: {%u, %s}\n", rdb->window_start, v128_bit_string(&rdb->bitmask)); | 89 printf("rdb: {%u, %s}\n", rdb->window_start, v128_bit_string(&rdb->bitmask)); |
| 90 } | 90 } |
| 91 | 91 |
| 92 err_status_t | 92 srtp_err_status_t |
| 93 rdb_check_add(rdb_t *rdb, uint32_t idx) { | 93 rdb_check_add(srtp_rdb_t *rdb, uint32_t idx) { |
| 94 | 94 |
| 95 if (rdb_check(rdb, idx) != err_status_ok) { | 95 if (srtp_rdb_check(rdb, idx) != srtp_err_status_ok) { |
| 96 printf("rdb_check failed at index %u\n", idx); | 96 printf("rdb_check failed at index %u\n", idx); |
| 97 return err_status_fail; | 97 return srtp_err_status_fail; |
| 98 } | 98 } |
| 99 if (rdb_add_index(rdb, idx) != err_status_ok) { | 99 if (srtp_rdb_add_index(rdb, idx) != srtp_err_status_ok) { |
| 100 printf("rdb_add_index failed at index %u\n", idx); | 100 printf("rdb_add_index failed at index %u\n", idx); |
| 101 return err_status_fail; | 101 return srtp_err_status_fail; |
| 102 } | 102 } |
| 103 | 103 |
| 104 return err_status_ok; | 104 return srtp_err_status_ok; |
| 105 } | 105 } |
| 106 | 106 |
| 107 err_status_t | 107 srtp_err_status_t |
| 108 rdb_check_expect_failure(rdb_t *rdb, uint32_t idx) { | 108 rdb_check_expect_failure(srtp_rdb_t *rdb, uint32_t idx) { |
| 109 err_status_t err; | 109 srtp_err_status_t err; |
| 110 | 110 |
| 111 err = rdb_check(rdb, idx); | 111 err = srtp_rdb_check(rdb, idx); |
| 112 if ((err != err_status_replay_old) && (err != err_status_replay_fail)) { | 112 if ((err != srtp_err_status_replay_old) && (err != srtp_err_status_replay_fail
)) { |
| 113 printf("rdb_check failed at index %u (false positive)\n", idx); | 113 printf("rdb_check failed at index %u (false positive)\n", idx); |
| 114 return err_status_fail; | 114 return srtp_err_status_fail; |
| 115 } | 115 } |
| 116 | 116 |
| 117 return err_status_ok; | 117 return srtp_err_status_ok; |
| 118 } | 118 } |
| 119 | 119 |
| 120 err_status_t | 120 srtp_err_status_t |
| 121 rdb_check_add_unordered(rdb_t *rdb, uint32_t idx) { | 121 rdb_check_add_unordered(srtp_rdb_t *rdb, uint32_t idx) { |
| 122 err_status_t rstat; | 122 srtp_err_status_t rstat; |
| 123 | 123 |
| 124 /* printf("index: %u\n", idx); */ | 124 /* printf("index: %u\n", idx); */ |
| 125 rstat = rdb_check(rdb, idx); | 125 rstat = srtp_rdb_check(rdb, idx); |
| 126 if ((rstat != err_status_ok) && (rstat != err_status_replay_old)) { | 126 if ((rstat != srtp_err_status_ok) && (rstat != srtp_err_status_replay_old)) { |
| 127 printf("rdb_check_add_unordered failed at index %u\n", idx); | 127 printf("rdb_check_add_unordered failed at index %u\n", idx); |
| 128 return rstat; | 128 return rstat; |
| 129 } | 129 } |
| 130 if (rstat == err_status_replay_old) { | 130 if (rstat == srtp_err_status_replay_old) { |
| 131 » return err_status_ok; | 131 » return srtp_err_status_ok; |
| 132 } | 132 } |
| 133 if (rdb_add_index(rdb, idx) != err_status_ok) { | 133 if (srtp_rdb_add_index(rdb, idx) != srtp_err_status_ok) { |
| 134 printf("rdb_add_index failed at index %u\n", idx); | 134 printf("rdb_add_index failed at index %u\n", idx); |
| 135 return err_status_fail; | 135 return srtp_err_status_fail; |
| 136 } | 136 } |
| 137 | 137 |
| 138 return err_status_ok; | 138 return srtp_err_status_ok; |
| 139 } | 139 } |
| 140 | 140 |
| 141 err_status_t | 141 srtp_err_status_t |
| 142 test_rdb_db() { | 142 test_rdb_db() { |
| 143 rdb_t rdb; | 143 srtp_rdb_t rdb; |
| 144 uint32_t idx, ircvd; | 144 uint32_t idx, ircvd; |
| 145 ut_connection utc; | 145 ut_connection utc; |
| 146 err_status_t err; | 146 srtp_err_status_t err; |
| 147 | 147 |
| 148 if (rdb_init(&rdb) != err_status_ok) { | 148 if (srtp_rdb_init(&rdb) != srtp_err_status_ok) { |
| 149 printf("rdb_init failed\n"); | 149 printf("rdb_init failed\n"); |
| 150 return err_status_init_fail; | 150 return srtp_err_status_init_fail; |
| 151 } | 151 } |
| 152 | 152 |
| 153 /* test sequential insertion */ | 153 /* test sequential insertion */ |
| 154 for (idx=0; idx < num_trials; idx++) { | 154 for (idx=0; idx < num_trials; idx++) { |
| 155 err = rdb_check_add(&rdb, idx); | 155 err = rdb_check_add(&rdb, idx); |
| 156 if (err) | 156 if (err) |
| 157 return err; | 157 return err; |
| 158 } | 158 } |
| 159 | 159 |
| 160 /* test for false positives */ | 160 /* test for false positives */ |
| 161 for (idx=0; idx < num_trials; idx++) { | 161 for (idx=0; idx < num_trials; idx++) { |
| 162 err = rdb_check_expect_failure(&rdb, idx); | 162 err = rdb_check_expect_failure(&rdb, idx); |
| 163 if (err) | 163 if (err) |
| 164 return err; | 164 return err; |
| 165 } | 165 } |
| 166 | 166 |
| 167 /* re-initialize */ | 167 /* re-initialize */ |
| 168 if (rdb_init(&rdb) != err_status_ok) { | 168 if (srtp_rdb_init(&rdb) != srtp_err_status_ok) { |
| 169 printf("rdb_init failed\n"); | 169 printf("rdb_init failed\n"); |
| 170 return err_status_fail; | 170 return srtp_err_status_fail; |
| 171 } | 171 } |
| 172 | 172 |
| 173 /* test non-sequential insertion */ | 173 /* test non-sequential insertion */ |
| 174 ut_init(&utc); | 174 ut_init(&utc); |
| 175 | 175 |
| 176 for (idx=0; idx < num_trials; idx++) { | 176 for (idx=0; idx < num_trials; idx++) { |
| 177 ircvd = ut_next_index(&utc); | 177 ircvd = ut_next_index(&utc); |
| 178 err = rdb_check_add_unordered(&rdb, ircvd); | 178 err = rdb_check_add_unordered(&rdb, ircvd); |
| 179 if (err) | 179 if (err) |
| 180 return err; | 180 return err; |
| 181 err = rdb_check_expect_failure(&rdb, ircvd); | 181 err = rdb_check_expect_failure(&rdb, ircvd); |
| 182 if (err) | 182 if (err) |
| 183 return err; | 183 return err; |
| 184 } | 184 } |
| 185 | 185 |
| 186 /* re-initialize */ | 186 /* re-initialize */ |
| 187 if (rdb_init(&rdb) != err_status_ok) { | 187 if (srtp_rdb_init(&rdb) != srtp_err_status_ok) { |
| 188 printf("rdb_init failed\n"); | 188 printf("rdb_init failed\n"); |
| 189 return err_status_fail; | 189 return srtp_err_status_fail; |
| 190 } | 190 } |
| 191 | 191 |
| 192 /* test insertion with large gaps */ | 192 /* test insertion with large gaps */ |
| 193 for (idx=0, ircvd=0; idx < num_trials; idx++, ircvd += (1 << (rand() % 10))) { | 193 for (idx=0, ircvd=0; idx < num_trials; idx++, ircvd += (1 << (rand() % 10))) { |
| 194 err = rdb_check_add(&rdb, ircvd); | 194 err = rdb_check_add(&rdb, ircvd); |
| 195 if (err) | 195 if (err) |
| 196 return err; | 196 return err; |
| 197 err = rdb_check_expect_failure(&rdb, ircvd); | 197 err = rdb_check_expect_failure(&rdb, ircvd); |
| 198 if (err) | 198 if (err) |
| 199 return err; | 199 return err; |
| 200 } | 200 } |
| 201 | 201 |
| 202 /* re-initialize */ | 202 /* re-initialize */ |
| 203 if (rdb_init(&rdb) != err_status_ok) { | 203 if (srtp_rdb_init(&rdb) != srtp_err_status_ok) { |
| 204 printf("rdb_init failed\n"); | 204 printf("rdb_init failed\n"); |
| 205 return err_status_fail; | 205 return srtp_err_status_fail; |
| 206 } | 206 } |
| 207 | 207 |
| 208 /* test loss of first 513 packets */ | 208 /* test loss of first 513 packets */ |
| 209 for (idx=0; idx < num_trials; idx++) { | 209 for (idx=0; idx < num_trials; idx++) { |
| 210 err = rdb_check_add(&rdb, idx + 513); | 210 err = rdb_check_add(&rdb, idx + 513); |
| 211 if (err) | 211 if (err) |
| 212 return err; | 212 return err; |
| 213 } | 213 } |
| 214 | 214 |
| 215 /* test for false positives */ | 215 /* test for false positives */ |
| 216 for (idx=0; idx < num_trials + 513; idx++) { | 216 for (idx=0; idx < num_trials + 513; idx++) { |
| 217 err = rdb_check_expect_failure(&rdb, idx); | 217 err = rdb_check_expect_failure(&rdb, idx); |
| 218 if (err) | 218 if (err) |
| 219 return err; | 219 return err; |
| 220 } | 220 } |
| 221 | 221 |
| 222 | 222 |
| 223 return err_status_ok; | 223 return srtp_err_status_ok; |
| 224 } | 224 } |
| 225 | 225 |
| 226 #include <time.h> /* for clock() */ | 226 #include <time.h> /* for clock() */ |
| 227 #include <stdlib.h> /* for random() */ | 227 #include <stdlib.h> /* for random() */ |
| 228 | 228 |
| 229 #define REPLAY_NUM_TRIALS 10000000 | 229 #define REPLAY_NUM_TRIALS 10000000 |
| 230 | 230 |
| 231 double | 231 double |
| 232 rdb_check_adds_per_second(void) { | 232 rdb_check_adds_per_second(void) { |
| 233 uint32_t i; | 233 uint32_t i; |
| 234 rdb_t rdb; | 234 srtp_rdb_t rdb; |
| 235 clock_t timer; | 235 clock_t timer; |
| 236 int failures = 0; /* count number of failures */ | 236 int failures = 0; /* count number of failures */ |
| 237 | 237 |
| 238 if (rdb_init(&rdb) != err_status_ok) { | 238 if (srtp_rdb_init(&rdb) != srtp_err_status_ok) { |
| 239 printf("rdb_init failed\n"); | 239 printf("rdb_init failed\n"); |
| 240 exit(1); | 240 exit(1); |
| 241 } | 241 } |
| 242 | 242 |
| 243 timer = clock(); | 243 timer = clock(); |
| 244 for(i=0; i < REPLAY_NUM_TRIALS; i+=3) { | 244 for(i=0; i < REPLAY_NUM_TRIALS; i+=3) { |
| 245 if (rdb_check(&rdb, i+2) != err_status_ok) | 245 if (srtp_rdb_check(&rdb, i+2) != srtp_err_status_ok) |
| 246 ++failures; | 246 ++failures; |
| 247 if (rdb_add_index(&rdb, i+2) != err_status_ok) | 247 if (srtp_rdb_add_index(&rdb, i+2) != srtp_err_status_ok) |
| 248 ++failures; | 248 ++failures; |
| 249 if (rdb_check(&rdb, i+1) != err_status_ok) | 249 if (srtp_rdb_check(&rdb, i+1) != srtp_err_status_ok) |
| 250 ++failures; | 250 ++failures; |
| 251 if (rdb_add_index(&rdb, i+1) != err_status_ok) | 251 if (srtp_rdb_add_index(&rdb, i+1) != srtp_err_status_ok) |
| 252 ++failures; | 252 ++failures; |
| 253 if (rdb_check(&rdb, i) != err_status_ok) | 253 if (srtp_rdb_check(&rdb, i) != srtp_err_status_ok) |
| 254 ++failures; | 254 ++failures; |
| 255 if (rdb_add_index(&rdb, i) != err_status_ok) | 255 if (srtp_rdb_add_index(&rdb, i) != srtp_err_status_ok) |
| 256 ++failures; | 256 ++failures; |
| 257 } | 257 } |
| 258 timer = clock() - timer; | 258 timer = clock() - timer; |
| 259 | 259 |
| 260 return (double) CLOCKS_PER_SEC * REPLAY_NUM_TRIALS / timer; | 260 return (double) CLOCKS_PER_SEC * REPLAY_NUM_TRIALS / timer; |
| 261 } | 261 } |
| OLD | NEW |