33 #define LOG(type, ...) GNUNET_log (type, __VA_ARGS__)
36 #define LOG_ERROR(...) LOG (GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__)
43 #define LOG_SQLITE(db, msg, level, cmd) \
46 GNUNET_log_from (level, \
48 _ ("`%s' failed at %s:%d with error: %s\n"), \
52 sqlite3_errmsg (db)); \
54 GNUNET_asprintf (msg, \
55 _ ("`%s' failed at %s:%u with error: %s"), \
59 sqlite3_errmsg (db)); \
66 static struct sqlite3 *
db;
104 unsigned int bandwidth,
105 unsigned int latency,
108 if ((SQLITE_OK != sqlite3_bind_int (
stmt_insert, 1, A)) ||
109 (SQLITE_OK != sqlite3_bind_int (
stmt_insert, 2, B)) ||
110 (SQLITE_OK != sqlite3_bind_int (
stmt_insert, 3, bandwidth)) ||
111 (SQLITE_OK != sqlite3_bind_int (
stmt_insert, 4, latency)) ||
112 (SQLITE_OK != sqlite3_bind_int (
stmt_insert, 5, loss)))
122 fprintf (stdout,
"%u -> %u\n", A, B);
125 if ((SQLITE_OK != sqlite3_bind_int (
stmt_insert, 1, B)) ||
126 (SQLITE_OK != sqlite3_bind_int (
stmt_insert, 2, A)))
136 fprintf (stdout,
"%u -> %u\n", B, A);
153 const char *query_create =
"CREATE TABLE whitelist ("
156 "bandwidth INTEGER DEFAULT NULL,"
157 "latency INTEGER DEFAULT NULL,"
158 "loss INTEGER DEFAULT NULL,"
162 " ) ON CONFLICT IGNORE"
164 const char *query_insert =
"INSERT INTO whitelist("
179 if (SQLITE_OK != sqlite3_open (dbfile, &
db))
184 if (0 != sqlite3_exec (
db, query_create, NULL, NULL, NULL))
188 "Error: %d. Perhaps the database `%s' already exits.\n",
189 sqlite3_errcode (
db),
194 sqlite3_exec (
db,
"PRAGMA synchronous = 0;", NULL, NULL, NULL));
196 sqlite3_prepare_v2 (
db, query_insert, -1, &
stmt_insert, NULL))
223 const char *topology_string;
224 unsigned int arg_uint1;
225 unsigned int arg_uint2;
226 const char *arg_str1;
235 LOG_ERROR (
_ (
"Need at least 2 arguments\n"));
238 if (NULL == (dbfile =
args[argc++]))
240 LOG_ERROR (
_ (
"Database filename missing\n"));
245 if (NULL == (topology_string =
args[argc++]))
252 LOG_ERROR (
_ (
"Invalid topology: %s\n"), topology_string);
265 LOG_ERROR (
_ (
"An argument is missing for given topology `%s'\n"),
269 if (-1 == sscanf (
value,
"%u", &arg_uint1))
271 LOG_ERROR (
_ (
"Invalid argument `%s' given as topology argument\n"),
278 if (NULL == (arg_str1 =
args[argc++]))
280 LOG_ERROR (
_ (
"Filename argument missing for topology `%s'\n"),
295 LOG_ERROR (
_ (
"Second argument for topology `%s' is missing\n"),
299 if (-1 == sscanf (
value,
"%u", &arg_uint2))
301 LOG_ERROR (
_ (
"Invalid argument `%s'; expecting unsigned int\n"),
value);
360 main (
int argc,
char *
const argv[])
377 "gnunet-underlay-topology",
379 "Generates SQLite3 database representing a given underlay topology.\n"
380 "Usage: gnunet-underlay-topology [OPTIONS] db-filename TOPO [TOPOOPTS]\n"
381 "The following options are available for TOPO followed by TOPOOPTS if applicable:\n"
384 "\t RANDOM <num_rnd_links>\n"
385 "\t SMALL_WORLD <num_rnd_links>\n"
386 "\t SMALL_WORLD_RING <num_rnd_links>\n"
389 "\t SCALE_FREE <cap> <m>\n"
390 "\t FROM_FILE <filename>\n"
392 "\t num_rnd_links: The number of random links\n"
393 "\t cap: the maximum number of links a node can have\n"
394 "\t m: the number of links a node should have while joining the network\n"
395 "\t filename: the path of the file which contains topology information\n"
396 "NOTE: the format of the above file is described here: https://www.gnunet.org/content/topology-file-format\n"),
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
static int setup_db(const char *dbfile)
Open the database file, creating a new database if not existing and setup the whitelist table.
static int exit_result
program result
enum GNUNET_TESTBED_TopologyOption topology
The topology to generate.
#define LOG_SQLITE(db, msg, level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' on file 'file...
static struct sqlite3 * db
Handle to the sqlite3 database.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config)
Main run function.
struct sqlite3_stmt * stmt_insert
Prepared statement for inserting link values into db.
static unsigned int num_peers
The number of peers to include in the topology.
static int link_processor(void *cls, unsigned int A, unsigned int B, unsigned int bandwidth, unsigned int latency, unsigned int loss)
Functions of this type are called to process underlay link.
int main(int argc, char *const argv[])
Main.
#define gettext_noop(String)
static int ret
Return value of the commandline.
static char * value
Value of the record to add/remove.
static const struct GNUNET_CONFIGURATION_Handle * config
API for writing tests and creating large-scale emulation testbeds for GNUnet.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
GNUNET_TESTBED_TopologyOption
Topologies and topology options supported for testbeds.
@ GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD
Small-world network (2d torus plus random links).
@ GNUNET_TESTBED_TOPOLOGY_FROM_FILE
Read a topology from a given file.
@ GNUNET_TESTBED_TOPOLOGY_RING
Ring topology.
@ GNUNET_TESTBED_TOPOLOGY_CLIQUE
A clique (everyone connected to everyone else).
@ GNUNET_TESTBED_TOPOLOGY_SCALE_FREE
Scale free topology.
@ GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI
Random graph.
@ GNUNET_TESTBED_TOPOLOGY_STAR
Star topology.
@ GNUNET_TESTBED_TOPOLOGY_2D_TORUS
2-d torus.
@ GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING
Small-world network (ring plus random links).
@ GNUNET_TESTBED_TOPOLOGY_LINE
Straight line topology.
Definition of a command line option.
int GNUNET_TESTBED_underlay_construct_(int num_peers, underlay_link_processor proc, void *cls,...)
Function to construct an underlay topology.
int GNUNET_TESTBED_topology_get_(enum GNUNET_TESTBED_TopologyOption *topology, const char *topology_string)
Get a topology from a string input.
header for intra library exported functions