mirror of
https://github.com/NLnetLabs/unbound.git
synced 2026-02-03 20:29:28 -05:00
Fake event start.
git-svn-id: file:///svn/unbound/trunk@82 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
1a137359d9
commit
05d471c46e
6 changed files with 222 additions and 47 deletions
|
|
@ -52,7 +52,7 @@ UNITTEST_SRC=testcode/unitmain.c
|
|||
UNITTEST_OBJ=$(addprefix $(BUILD),$(UNITTEST_SRC:.c=.o))
|
||||
DAEMON_SRC=$(wildcard daemon/*.c)
|
||||
DAEMON_OBJ=$(addprefix $(BUILD),$(DAEMON_SRC:.c=.o))
|
||||
TESTBOUND_SRC=testcode/testbound.c testcode/ldns-testpkts.c daemon/worker.c testcode/replay.c
|
||||
TESTBOUND_SRC=testcode/testbound.c testcode/ldns-testpkts.c daemon/worker.c testcode/replay.c testcode/fake_event.c
|
||||
TESTBOUND_OBJ=$(addprefix $(BUILD),$(TESTBOUND_SRC:.c=.o))
|
||||
ALL_SRC=$(COMMON_SRC) $(UNITTEST_SRC) $(DAEMON_SRC) $(TESTBOUND_SRC)
|
||||
ALL_OBJ=$(addprefix $(BUILD),$(ALL_SRC:.c=.o) $(LIBOBJS))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
8 February 2007: Wouter
|
||||
- added tcp test.
|
||||
- replay storage.
|
||||
- testcode/fake_event work.
|
||||
|
||||
7 February 2007: Wouter
|
||||
- return answer with the same ID as query was sent with.
|
||||
|
|
|
|||
72
testcode/fake_event.c
Normal file
72
testcode/fake_event.c
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* testcode/fake_event.c - fake event handling that replays existing scenario.
|
||||
*
|
||||
* Copyright (c) 2007, NLnet Labs. All rights reserved.
|
||||
*
|
||||
* This software is open source.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the NLNET LABS nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Event service that replays a scenario.
|
||||
* This implements the same exported symbols as the files:
|
||||
* util/netevent.c
|
||||
* services/listen_dnsport.c
|
||||
* services/outside_network.c
|
||||
* But these do not actually access the network or events, instead
|
||||
* the scenario is played.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "testcode/fake_event.h"
|
||||
#include "util/netevent.h"
|
||||
#include "services/listen_dnsport.h"
|
||||
#include "services/outside_network.h"
|
||||
#include "testcode/replay.h"
|
||||
|
||||
/** Global variable: the scenario */
|
||||
static struct replay_scenario* scenario = NULL;
|
||||
|
||||
void
|
||||
fake_event_init(struct replay_scenario* scen)
|
||||
{
|
||||
scenario = scen;
|
||||
}
|
||||
|
||||
void
|
||||
fake_event_cleanup()
|
||||
{
|
||||
replay_scenario_delete(scenario);
|
||||
scenario = NULL;
|
||||
}
|
||||
|
||||
/*********** Dummy routines ***********/
|
||||
|
||||
/*********** End of Dummy routines ***********/
|
||||
63
testcode/fake_event.h
Normal file
63
testcode/fake_event.h
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* testcode/fake_event.h - fake event handling that replays existing scenario.
|
||||
*
|
||||
* Copyright (c) 2007, NLnet Labs. All rights reserved.
|
||||
*
|
||||
* This software is open source.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the NLNET LABS nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Event service that replays a scenario.
|
||||
* This implements the same exported symbols as the files:
|
||||
* util/netevent.c
|
||||
* services/listen_dnsport.c
|
||||
* services/outside_network.c
|
||||
* But these do not actually access the network or events, instead
|
||||
* the scenario is played.
|
||||
*/
|
||||
|
||||
#ifndef TESTCODE_FAKE_EVENT_H
|
||||
#define TESTCODE_FAKE_EVENT_H
|
||||
struct replay_scenario;
|
||||
|
||||
/**
|
||||
* Initialise fake event services.
|
||||
*
|
||||
* @param scen: Set the scenario to use for upcoming event handling.
|
||||
*/
|
||||
void fake_event_init(struct replay_scenario* scen);
|
||||
|
||||
/**
|
||||
* Deinit fake event services.
|
||||
*/
|
||||
void fake_event_cleanup();
|
||||
|
||||
#endif /* TESTCODE_FAKE_EVENT_H */
|
||||
|
|
@ -41,4 +41,13 @@
|
|||
|
||||
#include "config.h"
|
||||
#include "testcode/replay.h"
|
||||
struct replay_scenario*
|
||||
replay_scenario_read(FILE* in)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
replay_scenario_delete(struct replay_scenario* scen)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,10 +42,12 @@
|
|||
* File format for replay files.
|
||||
*
|
||||
* ; comment line.
|
||||
* And then a number of entries:
|
||||
* SCENARIO_BEGIN
|
||||
* TITLE name_of_scenario
|
||||
* RANGE start_time end_time
|
||||
* match_entries
|
||||
* END_RANGE
|
||||
* ; more RANGE items.
|
||||
* ; go to the next moment
|
||||
* STEP time_step event_type
|
||||
* ; event_type can be:
|
||||
|
|
@ -55,10 +57,14 @@
|
|||
* o CHECK_OUT_QUERY - followed by entry
|
||||
* o REPLY - followed by entry
|
||||
* o TIMEOUT
|
||||
* o ERROR
|
||||
* ; following entry starts on the next line, ENTRY_BEGIN.
|
||||
* SCENARIO_END
|
||||
*
|
||||
*
|
||||
* ; Example file
|
||||
* SCENARIO_BEGIN
|
||||
* TITLE Example scenario
|
||||
* RANGE 0 100
|
||||
* ENTRY_BEGIN
|
||||
* ; precoded answers to queries.
|
||||
|
|
@ -78,6 +84,7 @@
|
|||
* ; what the reply should look like
|
||||
* ENTRY_END
|
||||
* ; successful termination. (if the answer was OK).
|
||||
* SCENARIO_END
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
|
|
@ -92,10 +99,13 @@ struct replay_answer;
|
|||
struct replay_range;
|
||||
struct entry;
|
||||
|
||||
|
||||
/**
|
||||
* A replay scenario.
|
||||
*/
|
||||
struct replay_scenario {
|
||||
/** name of replay scenario. malloced string. */
|
||||
const char* title;
|
||||
|
||||
/** The list of replay moments. Linked list. Time increases in list. */
|
||||
struct replay_moment* mom_first;
|
||||
|
|
@ -110,23 +120,6 @@ struct replay_scenario {
|
|||
* So: timestep, parts of query, destination --> answer.
|
||||
*/
|
||||
struct replay_range* range_list;
|
||||
|
||||
/**
|
||||
* List of pending queries in order they were sent out. First
|
||||
* one has been sent out most recently. Last one in list is oldest.
|
||||
*/
|
||||
struct fake_pending* pending_list;
|
||||
|
||||
/**
|
||||
* List of answers from the matching list, that need to be returned
|
||||
* to the program.
|
||||
*/
|
||||
struct replay_answer* answer_list;
|
||||
|
||||
/** callback for incoming queries */
|
||||
comm_point_callback_t* callback_query;
|
||||
/** user argument for incoming query callback */
|
||||
void *cb_arg;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -158,6 +151,8 @@ struct replay_moment {
|
|||
repevt_back_reply,
|
||||
/** test fails if query to the network does not match */
|
||||
repevt_back_query,
|
||||
/** an error happens to outbound query */
|
||||
repevt_error,
|
||||
} evt_type;
|
||||
|
||||
/** The sent packet must match this. Incoming events, the data. */
|
||||
|
|
@ -168,34 +163,6 @@ struct replay_moment {
|
|||
ldns_rr* qname;
|
||||
};
|
||||
|
||||
/**
|
||||
* Pending queries to network, fake replay version.
|
||||
*/
|
||||
struct fake_pending {
|
||||
/** what is important only that we remember the query, copied here. */
|
||||
ldns_buffer* buffer;
|
||||
/** and to what address this is sent to. */
|
||||
struct sockaddr_storage addr;
|
||||
/** len of addr */
|
||||
socklen_t addrlen;
|
||||
/** The callback function to call */
|
||||
comm_point_callback_t* callback;
|
||||
/** callback user argument */
|
||||
void* cb_arg;
|
||||
};
|
||||
|
||||
/**
|
||||
* An answer to a back-query, stored so it can be provided as an event.
|
||||
*/
|
||||
struct replay_answer {
|
||||
/** Next in list */
|
||||
struct replay_answer* next;
|
||||
/** pending question this is an answer to */
|
||||
struct fake_pending* question;
|
||||
/** The answer. */
|
||||
ldns_buffer* buf;
|
||||
};
|
||||
|
||||
/**
|
||||
* Range of timesteps, and canned replies to matching queries.
|
||||
*/
|
||||
|
|
@ -212,4 +179,67 @@ struct replay_range {
|
|||
struct replay_range* next_range;
|
||||
};
|
||||
|
||||
/**
|
||||
* Replay storage of runtime information.
|
||||
*/
|
||||
struct replay_runtime {
|
||||
/**
|
||||
* List of pending queries in order they were sent out. First
|
||||
* one has been sent out most recently. Last one in list is oldest.
|
||||
*/
|
||||
struct fake_pending* pending_list;
|
||||
|
||||
/**
|
||||
* List of answers from the matching list, that need to be returned
|
||||
* to the program.
|
||||
*/
|
||||
struct replay_answer* answer_list;
|
||||
|
||||
/** callback for incoming queries */
|
||||
comm_point_callback_t* callback_query;
|
||||
/** user argument for incoming query callback */
|
||||
void *cb_arg;
|
||||
};
|
||||
|
||||
/**
|
||||
* Pending queries to network, fake replay version.
|
||||
*/
|
||||
struct fake_pending {
|
||||
/** what is important only that we remember the query, copied here. */
|
||||
ldns_buffer* buffer;
|
||||
/** and to what address this is sent to. */
|
||||
struct sockaddr_storage addr;
|
||||
/** len of addr */
|
||||
socklen_t addrlen;
|
||||
/** The callback function to call when answer arrives (or timeout) */
|
||||
comm_point_callback_t* callback;
|
||||
/** callback user argument */
|
||||
void* cb_arg;
|
||||
};
|
||||
|
||||
/**
|
||||
* An answer to a back-query, stored so it can be provided as an event.
|
||||
*/
|
||||
struct replay_answer {
|
||||
/** Next in list */
|
||||
struct replay_answer* next;
|
||||
/** pending question this is an answer to */
|
||||
struct fake_pending* question;
|
||||
/** The answer. */
|
||||
ldns_buffer* buf;
|
||||
};
|
||||
|
||||
/**
|
||||
* Read a replay scenario from the file.
|
||||
* @param in: file to read from.
|
||||
* @return: Scenario. NULL if no scenario read.
|
||||
*/
|
||||
struct replay_scenario* replay_scenario_read(FILE* in);
|
||||
|
||||
/**
|
||||
* Delete scenario.
|
||||
* @param scen: to delete.
|
||||
*/
|
||||
void replay_scenario_delete(struct replay_scenario* scen);
|
||||
|
||||
#endif /* TESTCODE_REPLAY_H */
|
||||
|
|
|
|||
Loading…
Reference in a new issue