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);
654 unsigned int **rows_len)
657 unsigned int sq_floor;
659 unsigned int *_rows_len;
662 unsigned int _num_peers;
667 sq_floor = (
unsigned int) sq;
668 _rows = (sq_floor + 1);
670 for (y = 0; y < _rows - 1; y++)
671 _rows_len[y] = sq_floor;
672 _num_peers = sq_floor * sq_floor;
673 cnt = (_num_peers < 2) ? _num_peers : 2 * _num_peers;
679 _rows_len[_rows - 1] = ++x;
684 cnt += (x < 2) ? x : 2 * x;
685 cnt += (y < 2) ? y : 2 * y;
686 if (0 == _rows_len[_rows - 1])
690 if (NULL != rows_len)
691 *rows_len = _rows_len;
707 unsigned int *rows_len;
713 tc->link_array_size =
717 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
721 overlay = &
tc->u.overlay;
727 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
731 underlay = &
tc->u.underlay;
739 for (y = 0; y < rows; y++)
741 for (x = 0; x < rows_len[y] - 1; x++)
750 offset += rows_len[y];
752 for (x = 0; x < rows_len[0]; x++)
755 for (y = 0; y < rows - 1; y++)
757 if (x >= rows_len[y + 1])
760 make_link (cnt, offset + x, offset + rows_len[y] + x,
tc);
761 offset += rows_len[y];
792 if (1 ==
tc->num_peers)
796 index =
tc->link_array_size;
806 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
810 overlay = &
tc->u.overlay;
826 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
830 underlay = &
tc->u.underlay;
846 for (cnt = 0; cnt <
links; cnt++)
855 while (A_rand == B_rand);
879 unsigned int etaboff;
883 unsigned int random_peer;
886 unsigned int redo_threshold;
889 tc->link_array_size =
tc->num_peers *
m;
892 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
896 overlay = &
tc->u.overlay;
898 *
tc->link_array_size);
902 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
906 underlay = &
tc->u.underlay;
908 *
tc->link_array_size);
931 random_peer = etab[off];
932 if (cap < deg[random_peer])
934 if (++redo_threshold >
GNUNET_MAX (1, cap / 2))
938 for (cnt2 = 0; cnt2 < etaboff; cnt2++)
940 if (random_peer == etab[cnt2])
945 etab[cnt2 - off] = etab[cnt2];
951 for (cnt2 = 0; cnt2 < cnt; cnt2++)
952 if (random_peer == used[cnt2])
957 used[cnt] = random_peer;
961 etab[etaboff++] = used[cnt];
962 etab[etaboff++] =
peer;
973 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
977 overlay = &
tc->u.overlay;
980 *
tc->link_array_size);
984 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
988 underlay = &
tc->u.underlay;
991 *
tc->link_array_size);
1014 unsigned long int other_peer_id;
1033 _ (
"Topology file %s not found\n"),
1041 _ (
"Topology file %s has no data\n"),
1049 _ (
"Topology file %s cannot be read\n"),
1059 if (0 != isspace ((
unsigned char)
data[offset]))
1067 buf = strchr (&
data[offset],
':');
1071 _ (
"Failed to read peer index from toology file: %s"),
filename);
1080 _ (
"Value in given topology file: %s out of range\n"),
filename);
1086 _ (
"Failed to read peer index from topology file: %s"),
filename);
1092 _ (
"Topology file needs more peers than given ones\n"));
1095 state = OTHER_PEER_INDEX;
1096 offset += ((
unsigned int) (
buf - &
data[offset])) + 1;
1099 case OTHER_PEER_INDEX:
1101 other_peer_id = (
unsigned int) strtoul (&
data[offset], &
end, 10);
1105 _ (
"Value in given topology file: %s out of range\n"),
filename);
1111 _ (
"Failed to read peer index from topology file: %s"),
filename);
1114 if (
tc->num_peers <= other_peer_id)
1117 _ (
"Topology file needs more peers than given ones\n"));
1122 tc->link_array_size++;
1125 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1129 overlay = &
tc->u.overlay;
1136 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1140 underlay = &
tc->u.underlay;
1144 *
tc->link_array_size);
1148 offset +=
end - &
data[offset];
1153 _ (
"Ignoring to connect peer %lu to peer %lu\n"),
1156 while ((
'\n' !=
data[offset]) && (
'|' !=
data[offset]) && (offset <
fs))
1158 if ((offset <
fs) &&
1159 (
'\n' ==
data[offset]))
1161 else if ((offset <
fs) &&
1162 (
'|' ==
data[offset]))
1164 state = OTHER_PEER_INDEX;
1177 "Removing link data read from the file\n");
1178 tc->link_array_size = 0;
1181 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1185 overlay = &
tc->u.overlay;
1191 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1195 underlay = &
tc->u.underlay;
1214 unsigned int offset;
1215 unsigned int neighbour;
1217 tc->link_array_size =
tc->num_peers * (
tc->num_peers - 1);
1220 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1224 overlay = &
tc->u.overlay;
1230 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1234 underlay = &
tc->u.underlay;
1240 for (cnt = 0; cnt <
tc->num_peers; cnt++)
1242 for (neighbour = 0; neighbour <
tc->num_peers; neighbour++)
1244 if (neighbour == cnt)
1341 c =
peers[0]->controller;
1343 tc->type = TOPOLOGYCONTEXT_TYPE_OVERLAY;
1344 overlay = &
tc->u.overlay;
1347 overlay->
op_cls = op_cls;
1393 cap = (uint16_t) va_arg (va,
unsigned int);
1394 m = (uint8_t) va_arg (va,
unsigned int);
1403 filename = va_arg (va,
const char *);
1419 switch (secondary_option)
1422 overlay->
retry_cnt = va_arg (va,
unsigned int);
1444 "Generated topology with %u connections\n",
1445 tc->link_array_size);
1488 va_start (vargs, topo);
1491 comp_cb, comp_cb_cls,
1510 const char *topology_string)
1577 memset (&
tc, 0,
sizeof(
tc));
1579 tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY;
1580 underlay = &
tc.u.underlay;
1581 va_start (vargs, cls);
1632 cap = (uint16_t) va_arg (vargs,
unsigned int);
1633 m = (uint8_t) va_arg (vargs,
unsigned int);
1642 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.
#define GNUNET_VA_ARG_ENUM(va, X)
wrap va_arg for enums
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
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_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.
unsigned int num_peers
The number of peers.
unsigned int link_array_size
The size of the link array.
enum TopologyContext::@61 type
The type of this context.
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
@ TOPOLOGYCONTEXT_TYPE_UNDERLAY
Type for underlay topology.
@ TOPOLOGYCONTEXT_TYPE_OVERLAY
Type for overlay topology.
union TopologyContext::@62 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.