Store and use a replay of events for the DNS resolver. More...
Data Structures | |
| struct | replay_scenario |
| A replay scenario. More... | |
| struct | replay_moment |
| A replay moment. More... | |
| struct | replay_range |
| Range of timesteps, and canned replies to matching queries. More... | |
| struct | replay_runtime |
| Replay storage of runtime information. More... | |
| struct | fake_pending |
| Pending queries to network, fake replay version. More... | |
| struct | replay_answer |
| An answer that is pending to happen. More... | |
| struct | fake_timer |
| Timers with callbacks, fake replay version. More... | |
| struct | replay_var |
| Replay macro variable. More... | |
Functions | |
| struct replay_scenario * | replay_scenario_read (FILE *in, const char *name, int *lineno) |
| Read a replay scenario from the file. | |
| void | replay_scenario_delete (struct replay_scenario *scen) |
| Delete scenario. | |
| int | replay_var_compare (const void *a, const void *b) |
| compare two replay_vars | |
| struct fake_timer * | replay_get_oldest_timer (struct replay_runtime *runtime) |
| get oldest enabled fake timer | |
| void | strip_end_white (char *p) |
| strip whitespace from end of string | |
| rbtree_type * | macro_store_create (void) |
| Create variable storage. | |
| void | macro_store_delete (rbtree_type *store) |
| Delete variable storage. | |
| char * | macro_process (rbtree_type *store, struct replay_runtime *runtime, char *text) |
| Apply macro substitution to string. | |
| char * | macro_lookup (rbtree_type *store, char *name) |
| Look up a macro value. | |
| int | macro_assign (rbtree_type *store, char *name, char *value) |
| Set macro value. | |
| void | macro_print_debug (rbtree_type *store) |
| Print macro variables stored as debug info. | |
| void | testbound_selftest (void) |
| testbounds self test | |
Store and use a replay of events for the DNS resolver.
Used to test known scenarios to get known outcomes.
File format for replay files.
; unbound.conf options.
; ...
; additional commandline options to pass to unbound
COMMANDLINE cmdline_option
; autotrust key file contents, also adds auto-trust-anchor-file: "x" to cfg
AUTOTRUST_FILE id
; contents of that file
AUTOTRUST_END
; temp file names are echoed as "tmp/xxx.fname"
TEMPFILE_NAME fname
; temp file contents, inline, deleted at end of run
TEMPFILE_CONTENTS fname
; contents of that file
; this creates $INCLUDE /tmp/xxx.fname
$INCLUDE_TEMPFILE fname
TEMPFILE_END
CONFIG_END
; comment line.
SCENARIO_BEGIN name_of_scenario
RANGE_BEGIN start_time end_time
; give ip of the virtual server, it matches any ip if not present.
ADDRESS ip_address
match_entries
RANGE_END
; more RANGE items.
; go to the next moment
STEP time_step event_type [ADDRESS ip_address]
; event_type can be:
o NOTHING - nothing
o QUERY - followed by entry
o CHECK_ANSWER - followed by entry
o CHECK_OUT_QUERY - followed by entry (if copy-id it is also reply).
o REPLY - followed by entry
o TIMEOUT
o TIME_PASSES ELAPSE [seconds] - increase 'now' time counter, can be
a floating point number.
TIME_PASSES EVAL [macro] - expanded for seconds to move time.
o TRAFFIC - like CHECK_ANSWER, causes traffic to flow.
actually the traffic flows before this step is taken.
the step waits for traffic to stop.
o CHECK_AUTOTRUST [id] - followed by FILE_BEGIN [to match] FILE_END.
The file contents is macro expanded before match.
o CHECK_TEMPFILE [fname] - followed by FILE_BEGIN [to match] FILE_END
o INFRA_RTT [ip] [dp] [rtt] - update infra cache entry with rtt.
o FLUSH_MESSAGE name type class - flushes entry in message cache.
o EXPIRE_MESSAGE name type class - expires entry in message cache.
o ERROR
; following entry starts on the next line, ENTRY_BEGIN.
; more STEP items
SCENARIO_END
Calculations, a macro-like system: ${$myvar + 3600}
STEP 10 ASSIGN myvar = 3600
; ASSIGN event. '=' is syntactic sugar here. 3600 is some expression.
${..} is macro expanded from its expression. Text substitution.
o $var replaced with its value. var is identifier [azAZ09_]*
o number is that number.
o ${variables and arithmetic }
o +, -, / and *. Note, evaluated left-to-right. Use ${} for brackets.
So again, no precedence rules, so 2+3*4 == ${2+3}*4 = 20.
Do 2+${3*4} to get 24.
o ${function params}
o ${time} is the current time for the simulated unbound.
o ${ctime value} is the text ctime(value), Fri 3 Aug 2009, ...
o ${timeout} is the time until next timeout in comm_timer list.
o ${range lower value upper} checks if lower<=value<=upper
returns value if check succeeds.
; Example file
SCENARIO_BEGIN Example scenario
RANGE_BEGIN 0 100
ENTRY_BEGIN
; precoded answers to queries.
ENTRY_END
END_RANGE
STEP 0 QUERY
ENTRY_BEGIN
; query
ENTRY_END
; a query is sent out to the network by resolver.
; precoded answer from range is returned.
; algorithm will do precoded answers from RANGE immediately, except if
; the next step specifically checks for that OUT_QUERY.
; or if none of the precoded answers match.
STEP 1 CHECK_ANSWER
ENTRY_BEGIN
; what the reply should look like
ENTRY_END
; successful termination. (if the answer was OK).
; also, all answers must have been checked with CHECK_ANSWER.
; and, no more pending out_queries (that have not been checked).
SCENARIO_END
| struct replay_scenario * replay_scenario_read | ( | FILE * | in, |
| const char * | name, | ||
| int * | lineno | ||
| ) |
Read a replay scenario from the file.
| in | file to read from. |
| name | name to print in errors. |
| lineno | incremented for every line read. |
References sldns_file_parse_state::default_ttl, fatal_exit(), sldns_file_parse_state::lineno, log_err(), log_info(), make_scenario(), MAX_LINE_LEN, replay_scenario::mom_first, replay_scenario::mom_last, replay_moment::mom_next, replay_range::next_range, parse_keyword(), replay_scenario::range_list, replay_moment_read(), replay_range_read(), replay_scenario_delete(), and replay_moment::time_step.
Referenced by setup_playback().
| void replay_scenario_delete | ( | struct replay_scenario * | scen | ) |
Delete scenario.
| scen | to delete. |
References replay_scenario::mom_first, replay_moment::mom_next, replay_range::next_range, replay_scenario::range_list, replay_moment_delete(), replay_range_delete(), and replay_scenario::title.
Referenced by fake_event_cleanup(), and replay_scenario_read().
| rbtree_type * macro_store_create | ( | void | ) |
Create variable storage.
References rbtree_create(), and replay_var_compare().
Referenced by testbound_selftest().
| void macro_store_delete | ( | rbtree_type * | store | ) |
Delete variable storage.
| store | the macro storage to free up. |
References del_macro(), and traverse_postorder().
Referenced by comm_base_delete(), and testbound_selftest().
| char * macro_process | ( | rbtree_type * | store, |
| struct replay_runtime * | runtime, | ||
| char * | text | ||
| ) |
Apply macro substitution to string.
| store | variable store. |
| runtime | the runtime to look up values as needed. |
| text | string to work on. |
References macro_expand(), fake_timer::next, and fake_timer::runtime.
Referenced by autotrust_check(), moment_assign(), tempfile_check(), testbound_selftest(), and time_passes().
| char * macro_lookup | ( | rbtree_type * | store, |
| char * | name | ||
| ) |
Look up a macro value.
Like calling ${$name}.
| store | variable store |
| name | macro name |
References macro_getvar(), replay_var::name, and replay_var::value.
Referenced by testbound_selftest().
| int macro_assign | ( | rbtree_type * | store, |
| char * | name, | ||
| char * | value | ||
| ) |
Set macro value.
| store | variable store |
| name | macro name |
| value | text to set it to. Not expanded. |
References rbnode_type::key, macro_getvar(), replay_var::name, replay_var::node, rbtree_insert(), and replay_var::value.
Referenced by moment_assign(), and testbound_selftest().