36 #define LOG(kind, ...) \
37 GNUNET_log_from (kind, "testbed-api-topology", __VA_ARGS__)
43 #define DEFAULT_RETRY_CNT 3
358 overlay = &
tc->u.overlay;
365 "Error while establishing a link: %s -- Retrying\n",
423 overlay = &
tc->u.overlay;
424 overlay->
nlinks =
tc->link_array_size;
425 for (
p = 0;
p <
tc->link_array_size;
p++)
451 overlay = &
tc->u.overlay;
460 for (
p = 0;
p <
tc->link_array_size;
p++)
487 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
492 overlay = &
tc->u.overlay;
503 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
508 underlay = &
tc->u.underlay;
529 tc->link_array_size =
tc->num_peers - 1;
532 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
536 overlay = &
tc->u.overlay;
543 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
547 underlay = &
tc->u.underlay;
554 for (cnt = 0; cnt < (
tc->link_array_size); cnt++)
569 tc->link_array_size =
tc->num_peers - 1;
572 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
576 overlay = &
tc->u.overlay;
583 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
587 underlay = &
tc->u.underlay;
594 for (cnt =
tc->link_array_size; cnt; cnt--)
611 tc->link_array_size++;
614 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
618 overlay = &
tc->u.overlay;
621 *
tc->link_array_size);
625 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
629 underlay = &
tc->u.underlay;
632 *
tc->link_array_size);
642 unsigned int **rows_len)
645 unsigned int sq_floor;
647 unsigned int *_rows_len;
650 unsigned int _num_peers;
655 sq_floor = (
unsigned int) sq;
656 _rows = (sq_floor + 1);
658 for (y = 0; y < _rows - 1; y++)
659 _rows_len[y] = sq_floor;
660 _num_peers = sq_floor * sq_floor;
661 cnt = (_num_peers < 2) ? _num_peers : 2 * _num_peers;
667 _rows_len[_rows - 1] = ++x;
672 cnt += (x < 2) ? x : 2 * x;
673 cnt += (y < 2) ? y : 2 * y;
674 if (0 == _rows_len[_rows - 1])
678 if (NULL != rows_len)
679 *rows_len = _rows_len;
695 unsigned int *rows_len;
701 tc->link_array_size =
705 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
709 overlay = &
tc->u.overlay;
715 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
719 underlay = &
tc->u.underlay;
727 for (y = 0; y < rows; y++)
729 for (x = 0; x < rows_len[y] - 1; x++)
738 offset += rows_len[y];
740 for (x = 0; x < rows_len[0]; x++)
743 for (y = 0; y < rows - 1; y++)
745 if (x >= rows_len[y + 1])
748 make_link (cnt, offset + x, offset + rows_len[y] + x,
tc);
749 offset += rows_len[y];
780 if (1 ==
tc->num_peers)
784 index =
tc->link_array_size;
794 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
798 overlay = &
tc->u.overlay;
814 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
818 underlay = &
tc->u.underlay;
834 for (cnt = 0; cnt <
links; cnt++)
843 while (A_rand == B_rand);
867 unsigned int etaboff;
871 unsigned int random_peer;
874 unsigned int redo_threshold;
877 tc->link_array_size =
tc->num_peers *
m;
880 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
884 overlay = &
tc->u.overlay;
886 *
tc->link_array_size);
890 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
894 underlay = &
tc->u.underlay;
896 *
tc->link_array_size);
919 random_peer = etab[off];
920 if (cap < deg[random_peer])
922 if (++redo_threshold >
GNUNET_MAX (1, cap / 2))
926 for (cnt2 = 0; cnt2 < etaboff; cnt2++)
928 if (random_peer == etab[cnt2])
933 etab[cnt2 - off] = etab[cnt2];
939 for (cnt2 = 0; cnt2 < cnt; cnt2++)
940 if (random_peer == used[cnt2])
945 used[cnt] = random_peer;
949 etab[etaboff++] = used[cnt];
950 etab[etaboff++] =
peer;
961 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
965 overlay = &
tc->u.overlay;
968 *
tc->link_array_size);
972 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
976 underlay = &
tc->u.underlay;
979 *
tc->link_array_size);
1002 unsigned long int other_peer_id;
1021 _ (
"Topology file %s not found\n"),
1029 _ (
"Topology file %s has no data\n"),
1037 _ (
"Topology file %s cannot be read\n"),
1047 if (0 != isspace ((
unsigned char)
data[offset]))
1055 buf = strchr (&
data[offset],
':');
1059 _ (
"Failed to read peer index from toology file: %s"),
filename);
1068 _ (
"Value in given topology file: %s out of range\n"),
filename);
1074 _ (
"Failed to read peer index from topology file: %s"),
filename);
1080 _ (
"Topology file needs more peers than given ones\n"));
1083 state = OTHER_PEER_INDEX;
1084 offset += ((
unsigned int) (
buf - &
data[offset])) + 1;
1087 case OTHER_PEER_INDEX:
1089 other_peer_id = (
unsigned int) strtoul (&
data[offset], &
end, 10);
1093 _ (
"Value in given topology file: %s out of range\n"),
filename);
1099 _ (
"Failed to read peer index from topology file: %s"),
filename);
1102 if (
tc->num_peers <= other_peer_id)
1105 _ (
"Topology file needs more peers than given ones\n"));
1110 tc->link_array_size++;
1113 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1117 overlay = &
tc->u.overlay;
1124 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1128 underlay = &
tc->u.underlay;
1132 *
tc->link_array_size);
1136 offset +=
end - &
data[offset];
1141 _ (
"Ignoring to connect peer %lu to peer %lu\n"),
1144 while ((
'\n' !=
data[offset]) && (
'|' !=
data[offset]) && (offset <
fs))
1146 if ((offset <
fs) &&
1147 (
'\n' ==
data[offset]))
1149 else if ((offset <
fs) &&
1150 (
'|' ==
data[offset]))
1152 state = OTHER_PEER_INDEX;
1165 "Removing link data read from the file\n");
1166 tc->link_array_size = 0;
1169 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1173 overlay = &
tc->u.overlay;
1179 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1183 underlay = &
tc->u.underlay;
1202 unsigned int offset;
1203 unsigned int neighbour;
1205 tc->link_array_size =
tc->num_peers * (
tc->num_peers - 1);
1208 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1212 overlay = &
tc->u.overlay;
1218 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1222 underlay = &
tc->u.underlay;
1228 for (cnt = 0; cnt <
tc->num_peers; cnt++)
1230 for (neighbour = 0; neighbour <
tc->num_peers; neighbour++)
1232 if (neighbour == cnt)
1287 c =
peers[0]->controller;
1289 tc->type = TOPOLOGYCONTEXT_TYPE_OVERLAY;
1290 overlay = &
tc->u.overlay;
1293 overlay->
op_cls = op_cls;
1339 cap = (uint16_t) va_arg (va,
unsigned int);
1340 m = (uint8_t) va_arg (va,
unsigned int);
1349 filename = va_arg (va,
const char *);
1365 switch (secondary_option)
1368 overlay->
retry_cnt = va_arg (va,
unsigned int);
1390 "Generated topology with %u connections\n",
1391 tc->link_array_size);
1434 va_start (vargs, topo);
1437 comp_cb, comp_cb_cls,
1447 const char *topology_string)
1514 memset (&
tc, 0,
sizeof(
tc));
1516 tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY;
1517 underlay = &
tc.u.underlay;
1518 va_start (vargs, cls);
1569 cap = (uint16_t) va_arg (vargs,
unsigned int);
1570 m = (uint8_t) va_arg (vargs,
unsigned int);
1579 for (cnt = 0; cnt <
tc.link_array_size; cnt++)
static int retry_entry(void *cls, const struct GNUNET_HashCode *key, void *entry)
Add entries to the message queue.
enum GNUNET_TESTBED_TopologyOption topology
The topology to generate.
static int ret
Return value of the commandline.
static struct GNUNET_ARM_Operation * op
Current operation.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
static int end
Set if we are to shutdown all services (including ARM).
static struct CadetPeer * peers
Operation to get peer ids.
static char * peer_id
Option –peer.
static unsigned int num_peers
static unsigned long long max_connections
If there are at least this many connections, old ones will be removed.
static struct GNUNET_FS_Handle * fs
Handle to FS service.
uint32_t data
The data value.
uint16_t status
See PRISM_STATUS_*-constants.
enum State state
current state of profiling
static struct GNUNET_CONTAINER_MultiPeerMap * links
Map from PIDs to struct VirtualLink entries describing links CORE knows to exist.
static struct GNUNET_OS_Process * p
Helper process we started.
API for writing tests and creating large-scale emulation testbeds for GNUnet.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Generate a random unsigned 64-bit value.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_VA_ARG_ENUM(va, X)
wrap va_arg for enums
#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_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_malloc_large(size)
Wrapper around malloc.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_TESTBED_TopologyOption
Topologies and topology options supported for testbeds.
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_underlay_configure_topology(void *op_cls, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, enum GNUNET_TESTBED_TopologyOption topo,...)
Configure overall network topology to have a particular shape.
void(* GNUNET_TESTBED_TopologyCompletionCallback)(void *cls, unsigned int nsuccess, unsigned int nfailures)
Callbacks of this type are called when topology configuration is completed.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_overlay_configure_topology(void *op_cls, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, unsigned int *max_connections, GNUNET_TESTBED_TopologyCompletionCallback comp_cb, void *comp_cb_cls, enum GNUNET_TESTBED_TopologyOption topo,...)
All peers must have been started before calling this function.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_overlay_connect(void *op_cls, GNUNET_TESTBED_OperationCompletionCallback cb, void *cb_cls, struct GNUNET_TESTBED_Peer *p1, struct GNUNET_TESTBED_Peer *p2)
Both peers must have been started before calling this function.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_overlay_configure_topology_va(void *op_cls, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, unsigned int *max_connections, GNUNET_TESTBED_TopologyCompletionCallback comp_cb, void *comp_cb_cls, enum GNUNET_TESTBED_TopologyOption topo, va_list va)
All peers must have been started before calling this function.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_underlay_configure_topology_va(void *op_cls, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, enum GNUNET_TESTBED_TopologyOption topo, va_list ap)
Configure overall network topology to have a particular shape.
@ 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_RETRY_CNT
How many times should the failed overlay connect operations be retried before giving up.
@ 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.
@ GNUNET_TESTBED_TOPOLOGY_OPTION_END
The options should always end with this.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Handle to interact with a GNUnet testbed controller.
struct OperationQueue * opq_parallel_topology_config_operations
Operation queue for simultaneous topology configuration operations.
Opaque handle to an abstract operation to be executed by the testing framework.
A peer controlled by the testing framework.
Representation of an overlay link.
struct TopologyContext * tc
The topology context this link is a part of.
uint32_t B
position of peer B's handle in peers array
struct GNUNET_TESTBED_Operation * op
An operation corresponding to this link.
uint32_t A
position of peer A's handle in peers array
struct RetryListEntry * prev
the prev pointer for the DLL
struct RetryListEntry * next
the next pointer for the DLL
struct OverlayLink * link
The link to be retired.
Context information for overlay topologies.
struct GNUNET_TESTBED_Peer ** peers
The array of peers.
unsigned int retry_cnt
How many retries to do before we give up.
unsigned int nlinks
Number of links to try.
void * comp_cb_cls
The closure for the above callback.
struct RetryListEntry * rl_tail
DLL tail for retry list.
struct RetryListEntry * rl_head
DLL head for retry list.
unsigned int nsuccess
Total successfully established overlay connections.
unsigned int nfailures
Total failed overlay connections.
struct OverlayLink * link_array
An array of links; this array is of size link_array_size.
void * op_cls
The operation closure.
unsigned int ncompleted
How many links have been completed.
GNUNET_TESTBED_TopologyCompletionCallback comp_cb
topology generation completion callback
Topology context information for underlay topologies.
struct UnderlayLink * link_array
The link array.
Context information for topology operations.
@ TOPOLOGYCONTEXT_TYPE_UNDERLAY
Type for underlay topology.
@ TOPOLOGYCONTEXT_TYPE_OVERLAY
Type for overlay topology.
unsigned int num_peers
The number of peers.
unsigned int link_array_size
The size of the link array.
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
enum TopologyContext::@62 type
The type of this context.
union TopologyContext::@63 u
struct TopologyContextUnderlay underlay
Topology context information for underlay topology.
Representation of an underlay link.
uint32_t latency
Latency of the link in milliseconds.
uint32_t B
position of peer B's handle in peers array
uint32_t loss
Loss in the link in percentage of message dropped.
uint32_t A
position of peer A's handle in peers array
uint32_t bandwidth
Bandwidth of the link in bytes per second.
Interface for functions internally exported from testbed_api.c.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_operation_create_(void *cls, OperationStart start, OperationRelease release)
Create an 'operation' to be performed.
void GNUNET_TESTBED_operation_queue_insert_(struct OperationQueue *queue, struct GNUNET_TESTBED_Operation *op)
Add an operation to a queue.
void GNUNET_TESTBED_operation_begin_wait_(struct GNUNET_TESTBED_Operation *op)
Marks the given operation as waiting on the queues.
internal API to access the 'operations' subsystem
internal API to access the 'peers' subsystem
int GNUNET_TESTBED_underlay_construct_(int num_peers, underlay_link_processor proc, void *cls,...)
Function to construct an underlay topology.
#define DEFAULT_RETRY_CNT
Default number of retires.
static void overlay_link_completed(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
Callback to be called when an overlay_link operation complete.
static void gen_topo_scale_free(struct TopologyContext *tc, uint16_t cap, uint8_t m)
Generates scale free network.
static void gen_topo_line(struct TopologyContext *tc)
Generates line topology.
static void gen_topo_star(struct TopologyContext *tc)
Generates star topology.
int GNUNET_TESTBED_topology_get_(enum GNUNET_TESTBED_TopologyOption *topology, const char *topology_string)
Get a topology from a string input.
static void make_link(unsigned int offset, uint32_t A, uint32_t B, struct TopologyContext *tc)
Populates the OverlayLink structure.
static void gen_topo_from_file(struct TopologyContext *tc, const char *filename)
Generates topology from the given file.
static void opstart_overlay_configure_topology(void *cls)
Function called when a overlay connect operation is ready.
static void gen_topo_clique(struct TopologyContext *tc)
Generates clique topology.
static const char * topology_strings[]
A array of names representing topologies.
unsigned int GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows, unsigned int **rows_len)
Returns the number of links that are required to generate a 2d torus for the given number of peers.
static void gen_topo_random(struct TopologyContext *tc, unsigned int links, int append)
Generates ring topology.
static void oprelease_overlay_configure_topology(void *cls)
Callback which will be called when overlay connect operation is released.
#define LOG(kind,...)
Generic loggins shorthand.
char * GNUNET_TESTBED_topology_to_str_(enum GNUNET_TESTBED_TopologyOption topology)
Returns the string corresponding to the given topology.
static void gen_topo_2dtorus(struct TopologyContext *tc)
Generates ring topology.
static void gen_topo_ring(struct TopologyContext *tc)
Generates ring topology.
header for intra library exported functions
int(* underlay_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.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.