GNUnet  0.11.x
Data Structures | Macros | Functions | Variables
testbed_api_topology.c File Reference

topology-generation functions More...

#include "platform.h"
#include "gnunet_testbed_service.h"
#include "testbed_api.h"
#include "testbed_api_peers.h"
#include "testbed_api_operations.h"
#include "testbed_api_topology.h"
Include dependency graph for testbed_api_topology.c:

Go to the source code of this file.

Data Structures

struct  OverlayLink
 Representation of an overlay link. More...
 
struct  UnderlayLink
 Representation of an underlay link. More...
 
struct  RetryListEntry
 
struct  TopologyContextOverlay
 Context information for overlay topologies. More...
 
struct  TopologyContextUnderlay
 Topology context information for underlay topologies. More...
 
struct  TopologyContext
 Context information for topology operations. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "testbed-api-topology", __VA_ARGS__)
 Generic loggins shorthand. More...
 
#define DEFAULT_RETRY_CNT   3
 Default number of retires. More...
 

Functions

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. More...
 
static void opstart_overlay_configure_topology (void *cls)
 Function called when a overlay connect operation is ready. More...
 
static void oprelease_overlay_configure_topology (void *cls)
 Callback which will be called when overlay connect operation is released. More...
 
static void make_link (unsigned int offset, uint32_t A, uint32_t B, struct TopologyContext *tc)
 Populates the OverlayLink structure. More...
 
static void gen_topo_line (struct TopologyContext *tc)
 Generates line topology. More...
 
static void gen_topo_star (struct TopologyContext *tc)
 Generates star topology. More...
 
static void gen_topo_ring (struct TopologyContext *tc)
 Generates ring topology. More...
 
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. More...
 
static void gen_topo_2dtorus (struct TopologyContext *tc)
 Generates ring topology. More...
 
static void gen_topo_random (struct TopologyContext *tc, unsigned int links, int append)
 Generates ring topology. More...
 
static void gen_topo_scale_free (struct TopologyContext *tc, uint16_t cap, uint8_t m)
 Generates scale free network. More...
 
static void gen_topo_from_file (struct TopologyContext *tc, const char *filename)
 Generates topology from the given file. More...
 
static void gen_topo_clique (struct TopologyContext *tc)
 Generates clique topology. More...
 
struct GNUNET_TESTBED_OperationGNUNET_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. More...
 
struct GNUNET_TESTBED_OperationGNUNET_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. More...
 
struct GNUNET_TESTBED_OperationGNUNET_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. More...
 
struct GNUNET_TESTBED_OperationGNUNET_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. More...
 
int GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology, const char *topology_string)
 Get a topology from a string input. More...
 
char * GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology)
 Returns the string corresponding to the given topology. More...
 
int GNUNET_TESTBED_underlay_construct_ (int num_peers, underlay_link_processor proc, void *cls,...)
 Function to construct an underlay topology. More...
 

Variables

static const char * topology_strings []
 A array of names representing topologies. More...
 

Detailed Description

topology-generation functions

Author
Christian Grothoff

Definition in file testbed_api_topology.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "testbed-api-topology", __VA_ARGS__)

Generic loggins shorthand.

Definition at line 36 of file testbed_api_topology.c.

Referenced by gen_topo_from_file(), GNUNET_TESTBED_overlay_configure_topology_va(), make_link(), and overlay_link_completed().

◆ DEFAULT_RETRY_CNT

#define DEFAULT_RETRY_CNT   3

Default number of retires.

Definition at line 43 of file testbed_api_topology.c.

Referenced by GNUNET_TESTBED_overlay_configure_topology_va().

Function Documentation

◆ overlay_link_completed()

static void overlay_link_completed ( void *  cls,
struct GNUNET_TESTBED_Operation op,
const char *  emsg 
)
static

Callback to be called when an overlay_link operation complete.

Parameters
clselement of the link_op array which points to the corresponding operation
opthe operation that has been finished
emsgerror message in case the operation has failed; will be NULL if operation has executed successfully.

Definition at line 344 of file testbed_api_topology.c.

References OverlayLink::A, OverlayLink::B, TopologyContextOverlay::comp_cb, TopologyContextOverlay::comp_cb_cls, GNUNET_assert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_new, GNUNET_TESTBED_operation_done(), GNUNET_TESTBED_overlay_connect(), RetryListEntry::link, LOG, TopologyContextOverlay::ncompleted, TopologyContextOverlay::nfailures, TopologyContextOverlay::nlinks, TopologyContextOverlay::nsuccess, OverlayLink::op, TopologyContextOverlay::op_cls, TopologyContext::overlay, TopologyContextOverlay::peers, TopologyContextOverlay::retry_cnt, retry_entry(), TopologyContextOverlay::rl_head, TopologyContextOverlay::rl_tail, OverlayLink::tc, TopologyContext::type, and TopologyContext::u.

Referenced by opstart_overlay_configure_topology().

347 {
348  struct OverlayLink *link = cls;
349  struct TopologyContext *tc;
350  struct TopologyContextOverlay *overlay;
351  struct RetryListEntry *retry_entry;
352 
353  GNUNET_assert (op == link->op);
355  link->op = NULL;
356  tc = link->tc;
357  GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type);
358  overlay = &tc->u.overlay;
359  if (NULL != emsg)
360  {
361  overlay->nfailures++;
362  if (0 != overlay->retry_cnt)
363  {
365  "Error while establishing a link: %s -- Retrying\n",
366  emsg);
367  retry_entry = GNUNET_new (struct RetryListEntry);
368  retry_entry->link = link;
370  overlay->rl_tail,
371  retry_entry);
372  }
373  }
374  else
375  overlay->nsuccess++;
376  overlay->ncompleted++;
377  if (overlay->ncompleted < overlay->nlinks)
378  return;
379  if ((0 != overlay->retry_cnt) && (NULL != overlay->rl_head))
380  {
381  overlay->retry_cnt--;
382  overlay->ncompleted = 0;
383  overlay->nlinks = 0;
384  while (NULL != (retry_entry = overlay->rl_head))
385  {
386  link = retry_entry->link;
387  link->op =
390  link,
391  overlay->peers[link->A],
392  overlay->peers[link->B]);
393  overlay->nlinks++;
395  overlay->rl_tail,
396  retry_entry);
397  GNUNET_free (retry_entry);
398  }
399  return;
400  }
401  if (NULL != overlay->comp_cb)
402  {
403  overlay->comp_cb (overlay->comp_cb_cls,
404  overlay->nsuccess,
405  overlay->nfailures);
406  }
407 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
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.
unsigned int nsuccess
Total successfully established overlay connections.
static int retry_entry(void *cls, const struct GNUNET_HashCode *key, void *entry)
Add entries to the message queue.
Definition: fs_download.c:746
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
#define LOG(kind,...)
Generic loggins shorthand.
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 RetryListEntry * rl_tail
DLL tail for retry list.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:418
unsigned int ncompleted
How many links have been completed.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void * op_cls
The operation closure.
enum TopologyContext::@70 type
The type of this context.
struct GNUNET_TESTBED_Peer ** peers
The array of peers.
GNUNET_TESTBED_TopologyCompletionCallback comp_cb
topology generation completion callback
unsigned int retry_cnt
How many retries to do before we give up.
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...
Definition: testbed_api.c:2044
unsigned int nfailures
Total failed overlay connections.
unsigned int nlinks
Number of links to try.
union TopologyContext::@71 u
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
void * comp_cb_cls
The closure for the above callback.
struct RetryListEntry * rl_head
DLL head for retry list.
struct OverlayLink * link
The link to be retired.
Context information for overlay topologies.
Context information for topology operations.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ opstart_overlay_configure_topology()

static void opstart_overlay_configure_topology ( void *  cls)
static

Function called when a overlay connect operation is ready.

Parameters
clsthe Topology context

Definition at line 416 of file testbed_api_topology.c.

References OverlayLink::A, OverlayLink::B, GNUNET_assert, GNUNET_TESTBED_overlay_connect(), TopologyContextOverlay::link_array, TopologyContext::link_array_size, TopologyContextOverlay::nlinks, OverlayLink::op, TopologyContextOverlay::op_cls, TopologyContext::overlay, overlay_link_completed(), p, TopologyContextOverlay::peers, OverlayLink::tc, TopologyContext::type, and TopologyContext::u.

Referenced by GNUNET_TESTBED_overlay_configure_topology_va().

417 {
418  struct TopologyContext *tc = cls;
419  struct TopologyContextOverlay *overlay;
420  unsigned int p;
421 
422  GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type);
423  overlay = &tc->u.overlay;
424  overlay->nlinks = tc->link_array_size;
425  for (p = 0; p < tc->link_array_size; p++)
426  {
427  overlay->link_array[p].op =
430  &overlay->link_array[p],
431  overlay->peers[overlay->link_array[p].A],
432  overlay->peers[overlay->link_array[p].B]);
433  }
434 }
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.
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
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.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:418
unsigned int link_array_size
The size of the link array.
void * op_cls
The operation closure.
enum TopologyContext::@70 type
The type of this context.
struct GNUNET_TESTBED_Peer ** peers
The array of peers.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
unsigned int nlinks
Number of links to try.
union TopologyContext::@71 u
struct OverlayLink * link_array
An array of links; this array is of size link_array_size.
Context information for overlay topologies.
Context information for topology operations.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ oprelease_overlay_configure_topology()

static void oprelease_overlay_configure_topology ( void *  cls)
static

Callback which will be called when overlay connect operation is released.

Parameters
clsthe Topology context

Definition at line 443 of file testbed_api_topology.c.

References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_TESTBED_operation_done(), TopologyContextOverlay::link_array, TopologyContext::link_array_size, OverlayLink::op, TopologyContext::overlay, p, retry_entry(), TopologyContextOverlay::rl_head, TopologyContextOverlay::rl_tail, OverlayLink::tc, TopologyContext::type, and TopologyContext::u.

Referenced by GNUNET_TESTBED_overlay_configure_topology_va().

444 {
445  struct TopologyContext *tc = cls;
446  struct TopologyContextOverlay *overlay;
447  struct RetryListEntry *retry_entry;
448  unsigned int p;
449 
450  GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type);
451  overlay = &tc->u.overlay;
452  while (NULL != (retry_entry = overlay->rl_head))
453  {
454  GNUNET_CONTAINER_DLL_remove (overlay->rl_head, overlay->rl_tail,
455  retry_entry);
456  GNUNET_free (retry_entry);
457  }
458  if (NULL != overlay->link_array)
459  {
460  for (p = 0; p < tc->link_array_size; p++)
461  if (NULL != overlay->link_array[p].op)
463  GNUNET_free (overlay->link_array);
464  }
465  GNUNET_free (tc);
466 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static int retry_entry(void *cls, const struct GNUNET_HashCode *key, void *entry)
Add entries to the message queue.
Definition: fs_download.c:746
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
struct RetryListEntry * rl_tail
DLL tail for retry list.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:418
unsigned int link_array_size
The size of the link array.
enum TopologyContext::@70 type
The type of this context.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
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...
Definition: testbed_api.c:2044
union TopologyContext::@71 u
struct RetryListEntry * rl_head
DLL head for retry list.
struct OverlayLink * link_array
An array of links; this array is of size link_array_size.
Context information for overlay topologies.
Context information for topology operations.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_link()

static void make_link ( unsigned int  offset,
uint32_t  A,
uint32_t  B,
struct TopologyContext tc 
)
static

Populates the OverlayLink structure.

Parameters
offsetthe offset of the link array to use
Athe peer A. Should be different from B
Bthe peer B. Should be different from A
tcthe TopologyContext
Returns

Definition at line 479 of file testbed_api_topology.c.

References OverlayLink::A, UnderlayLink::A, OverlayLink::B, UnderlayLink::B, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, TopologyContextOverlay::link_array, TopologyContextUnderlay::link_array, LOG, OverlayLink::op, TopologyContext::overlay, OverlayLink::tc, TopologyContext::type, TopologyContext::u, and TopologyContext::underlay.

Referenced by gen_topo_2dtorus(), gen_topo_clique(), gen_topo_from_file(), gen_topo_line(), gen_topo_random(), gen_topo_ring(), gen_topo_scale_free(), and gen_topo_star().

483 {
484  GNUNET_assert (A != B);
485  switch (tc->type)
486  {
487  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
488  {
489  struct TopologyContextOverlay *overlay;
490  struct OverlayLink *olink;
491 
492  overlay = &tc->u.overlay;
493  GNUNET_assert (offset < tc->link_array_size);
494  olink = &overlay->link_array[offset];
495  LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %u to %u\n", B, A);
496  olink->A = A;
497  olink->B = B;
498  olink->op = NULL;
499  olink->tc = tc;
500  }
501  break;
502 
503  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
504  {
505  struct TopologyContextUnderlay *underlay;
506  struct UnderlayLink *ulink;
507 
508  underlay = &tc->u.underlay;
509  GNUNET_assert (offset < tc->link_array_size);
510  ulink = &underlay->link_array[offset];
511  ulink->A = A;
512  ulink->B = B;
513  }
514  break;
515  }
516 }
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
#define LOG(kind,...)
Generic loggins shorthand.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:418
struct UnderlayLink * link_array
The link array.
enum TopologyContext::@70 type
The type of this context.
Topology context information for underlay topologies.
union TopologyContext::@71 u
struct TopologyContextUnderlay underlay
Topology context information for underlay topology.
struct OverlayLink * link_array
An array of links; this array is of size link_array_size.
Context information for overlay topologies.
Here is the caller graph for this function:

◆ gen_topo_line()

static void gen_topo_line ( struct TopologyContext tc)
static

Generates line topology.

Parameters
tcthe topology context

Definition at line 525 of file testbed_api_topology.c.

References GNUNET_new_array, TopologyContextOverlay::link_array, TopologyContextUnderlay::link_array, TopologyContext::link_array_size, make_link(), TopologyContext::num_peers, TopologyContext::overlay, TopologyContext::type, TopologyContext::u, and TopologyContext::underlay.

Referenced by gen_topo_ring(), GNUNET_TESTBED_overlay_configure_topology_va(), and GNUNET_TESTBED_underlay_construct_().

526 {
527  unsigned int cnt;
528 
529  tc->link_array_size = tc->num_peers - 1;
530  switch (tc->type)
531  {
532  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
533  {
534  struct TopologyContextOverlay *overlay;
535 
536  overlay = &tc->u.overlay;
537  overlay->link_array =
539  struct OverlayLink);
540  }
541  break;
542 
543  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
544  {
545  struct TopologyContextUnderlay *underlay;
546 
547  underlay = &tc->u.underlay;
548  underlay->link_array =
550  struct UnderlayLink);
551  }
552  break;
553  }
554  for (cnt = 0; cnt < (tc->link_array_size); cnt++)
555  make_link (cnt, cnt, cnt + 1, tc);
556 }
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
unsigned int num_peers
The number of peers.
struct UnderlayLink * link_array
The link array.
unsigned int link_array_size
The size of the link array.
enum TopologyContext::@70 type
The type of this context.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
Topology context information for underlay topologies.
union TopologyContext::@71 u
struct TopologyContextUnderlay underlay
Topology context information for underlay topology.
struct OverlayLink * link_array
An array of links; this array is of size link_array_size.
Context information for overlay topologies.
static void make_link(unsigned int offset, uint32_t A, uint32_t B, struct TopologyContext *tc)
Populates the OverlayLink structure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_topo_star()

static void gen_topo_star ( struct TopologyContext tc)
static

Generates star topology.

Parameters
tcthe topology context

Definition at line 565 of file testbed_api_topology.c.

References GNUNET_new_array, TopologyContextOverlay::link_array, TopologyContextUnderlay::link_array, TopologyContext::link_array_size, make_link(), TopologyContext::num_peers, TopologyContext::overlay, TopologyContext::type, TopologyContext::u, and TopologyContext::underlay.

Referenced by GNUNET_TESTBED_overlay_configure_topology_va(), and GNUNET_TESTBED_underlay_construct_().

566 {
567  unsigned int cnt;
568 
569  tc->link_array_size = tc->num_peers - 1;
570  switch (tc->type)
571  {
572  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
573  {
574  struct TopologyContextOverlay *overlay;
575 
576  overlay = &tc->u.overlay;
577  overlay->link_array =
579  struct OverlayLink);
580  }
581  break;
582 
583  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
584  {
585  struct TopologyContextUnderlay *underlay;
586 
587  underlay = &tc->u.underlay;
588  underlay->link_array =
590  struct UnderlayLink);
591  }
592  break;
593  }
594  for (cnt = tc->link_array_size; cnt; cnt--)
595  make_link (cnt - 1,
596  0,
597  cnt,
598  tc);
599 }
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
unsigned int num_peers
The number of peers.
struct UnderlayLink * link_array
The link array.
unsigned int link_array_size
The size of the link array.
enum TopologyContext::@70 type
The type of this context.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
Topology context information for underlay topologies.
union TopologyContext::@71 u
struct TopologyContextUnderlay underlay
Topology context information for underlay topology.
struct OverlayLink * link_array
An array of links; this array is of size link_array_size.
Context information for overlay topologies.
static void make_link(unsigned int offset, uint32_t A, uint32_t B, struct TopologyContext *tc)
Populates the OverlayLink structure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_topo_ring()

static void gen_topo_ring ( struct TopologyContext tc)
static

Generates ring topology.

Parameters
tcthe topology context

Definition at line 608 of file testbed_api_topology.c.

References gen_topo_line(), GNUNET_realloc, TopologyContextOverlay::link_array, TopologyContextUnderlay::link_array, TopologyContext::link_array_size, make_link(), TopologyContext::num_peers, TopologyContext::overlay, TopologyContext::type, TopologyContext::u, and TopologyContext::underlay.

Referenced by GNUNET_TESTBED_overlay_configure_topology_va(), and GNUNET_TESTBED_underlay_construct_().

609 {
610  gen_topo_line (tc);
611  tc->link_array_size++;
612  switch (tc->type)
613  {
614  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
615  {
616  struct TopologyContextOverlay *overlay;
617 
618  overlay = &tc->u.overlay;
619  overlay->link_array =
620  GNUNET_realloc (overlay->link_array, sizeof(struct OverlayLink)
621  * tc->link_array_size);
622  }
623  break;
624 
625  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
626  {
627  struct TopologyContextUnderlay *underlay;
628 
629  underlay = &tc->u.underlay;
630  underlay->link_array =
631  GNUNET_realloc (underlay->link_array, sizeof(struct UnderlayLink)
632  * tc->link_array_size);
633  }
634  break;
635  }
636  make_link (tc->link_array_size - 1, tc->num_peers - 1, 0, tc);
637 }
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
unsigned int num_peers
The number of peers.
struct UnderlayLink * link_array
The link array.
unsigned int link_array_size
The size of the link array.
static void gen_topo_line(struct TopologyContext *tc)
Generates line topology.
enum TopologyContext::@70 type
The type of this context.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
Topology context information for underlay topologies.
union TopologyContext::@71 u
struct TopologyContextUnderlay underlay
Topology context information for underlay topology.
struct OverlayLink * link_array
An array of links; this array is of size link_array_size.
Context information for overlay topologies.
static void make_link(unsigned int offset, uint32_t A, uint32_t B, struct TopologyContext *tc)
Populates the OverlayLink structure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_2dtorus_calc_links()

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.

Also returns the arrangment (number of rows and the length of each row)

Parameters
num_peersnumber of peers
rowsnumber of rows in the 2d torus. Can be NULL
rows_lenthe length of each row. This array will be allocated fresh. The caller should free it. Can be NULL
Returns
the number of links that are required to generate a 2d torus for the given number of peers

Definition at line 653 of file testbed_api_topology.c.

References GNUNET_free, and GNUNET_malloc.

Referenced by gen_topo_2dtorus().

655 {
656  double sq;
657  unsigned int sq_floor;
658  unsigned int _rows;
659  unsigned int *_rows_len;
660  unsigned int x;
661  unsigned int y;
662  unsigned int _num_peers;
663  unsigned int cnt;
664 
665  sq = sqrt (num_peers);
666  sq = floor (sq);
667  sq_floor = (unsigned int) sq;
668  _rows = (sq_floor + 1);
669  _rows_len = GNUNET_malloc (sizeof(unsigned int) * _rows);
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;
674  x = 0;
675  y = 0;
676  while (_num_peers < num_peers)
677  {
678  if (x < y)
679  _rows_len[_rows - 1] = ++x;
680  else
681  _rows_len[y++]++;
682  _num_peers++;
683  }
684  cnt += (x < 2) ? x : 2 * x;
685  cnt += (y < 2) ? y : 2 * y;
686  if (0 == _rows_len[_rows - 1])
687  _rows--;
688  if (NULL != rows)
689  *rows = _rows;
690  if (NULL != rows_len)
691  *rows_len = _rows_len;
692  else
693  GNUNET_free (_rows_len);
694  return cnt;
695 }
static unsigned int num_peers
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ gen_topo_2dtorus()

static void gen_topo_2dtorus ( struct TopologyContext tc)
static

Generates ring topology.

Parameters
tcthe topology context

Definition at line 704 of file testbed_api_topology.c.

References GNUNET_assert, GNUNET_free, GNUNET_malloc, GNUNET_TESTBED_2dtorus_calc_links(), TopologyContextOverlay::link_array, TopologyContextUnderlay::link_array, TopologyContext::link_array_size, make_link(), TopologyContext::num_peers, TopologyContext::overlay, TopologyContext::type, TopologyContext::u, and TopologyContext::underlay.

Referenced by GNUNET_TESTBED_overlay_configure_topology_va(), and GNUNET_TESTBED_underlay_construct_().

705 {
706  unsigned int rows;
707  unsigned int *rows_len;
708  unsigned int x;
709  unsigned int y;
710  unsigned int cnt;
711  unsigned int offset;
712 
713  tc->link_array_size =
714  GNUNET_TESTBED_2dtorus_calc_links (tc->num_peers, &rows, &rows_len);
715  switch (tc->type)
716  {
717  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
718  {
719  struct TopologyContextOverlay *overlay;
720 
721  overlay = &tc->u.overlay;
722  overlay->link_array =
723  GNUNET_malloc (sizeof(struct OverlayLink) * tc->link_array_size);
724  }
725  break;
726 
727  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
728  {
729  struct TopologyContextUnderlay *underlay;
730 
731  underlay = &tc->u.underlay;
732  underlay->link_array =
733  GNUNET_malloc (sizeof(struct UnderlayLink) * tc->link_array_size);
734  break;
735  }
736  }
737  cnt = 0;
738  offset = 0;
739  for (y = 0; y < rows; y++)
740  {
741  for (x = 0; x < rows_len[y] - 1; x++)
742  {
743  make_link (cnt, offset + x, offset + x + 1, tc);
744  cnt++;
745  }
746  if (0 == x)
747  break;
748  make_link (cnt, offset + x, offset, tc);
749  cnt++;
750  offset += rows_len[y];
751  }
752  for (x = 0; x < rows_len[0]; x++)
753  {
754  offset = 0;
755  for (y = 0; y < rows - 1; y++)
756  {
757  if (x >= rows_len[y + 1])
758  break;
759  GNUNET_assert (x < rows_len[y + 1]);
760  make_link (cnt, offset + x, offset + rows_len[y] + x, tc);
761  offset += rows_len[y];
762  cnt++;
763  }
764  if (0 == offset)
765  break;
766  make_link (cnt, offset + x, x, tc);
767  cnt++;
768  }
769  GNUNET_assert (cnt == tc->link_array_size);
770  GNUNET_free (rows_len);
771 }
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...
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
unsigned int num_peers
The number of peers.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct UnderlayLink * link_array
The link array.
unsigned int link_array_size
The size of the link array.
enum TopologyContext::@70 type
The type of this context.
Topology context information for underlay topologies.
union TopologyContext::@71 u
struct TopologyContextUnderlay underlay
Topology context information for underlay topology.
struct OverlayLink * link_array
An array of links; this array is of size link_array_size.
Context information for overlay topologies.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
static void make_link(unsigned int offset, uint32_t A, uint32_t B, struct TopologyContext *tc)
Populates the OverlayLink structure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_topo_random()

static void gen_topo_random ( struct TopologyContext tc,
unsigned int  links,
int  append 
)
static

Generates ring topology.

Parameters
tcthe topology context
linksthe number of random links to establish
appendGNUNET_YES to add links to existing link array; GNUNET_NO to create a new link array

Definition at line 783 of file testbed_api_topology.c.

References GNUNET_assert, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_malloc, GNUNET_realloc, GNUNET_YES, TopologyContextOverlay::link_array, TopologyContextUnderlay::link_array, TopologyContext::link_array_size, links, make_link(), TopologyContext::num_peers, TopologyContext::overlay, TopologyContext::type, TopologyContext::u, and TopologyContext::underlay.

Referenced by GNUNET_TESTBED_overlay_configure_topology_va(), and GNUNET_TESTBED_underlay_construct_().

786 {
787  unsigned int cnt;
788  unsigned int index;
789  uint32_t A_rand;
790  uint32_t B_rand;
791 
792  if (1 == tc->num_peers)
793  return;
794  if (GNUNET_YES == append)
795  {
796  index = tc->link_array_size;
797  tc->link_array_size += links;
798  }
799  else
800  {
801  index = 0;
802  tc->link_array_size = links;
803  }
804  switch (tc->type)
805  {
806  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
807  {
808  struct TopologyContextOverlay *overlay;
809 
810  overlay = &tc->u.overlay;
811  if (GNUNET_YES != append)
812  {
813  GNUNET_assert (NULL == overlay->link_array);
814  overlay->link_array =
815  GNUNET_malloc (sizeof(struct OverlayLink) * tc->link_array_size);
816  break;
817  }
818  GNUNET_assert ((0 < tc->link_array_size) && (NULL !=
819  overlay->link_array));
820  overlay->link_array =
821  GNUNET_realloc (overlay->link_array,
822  sizeof(struct OverlayLink) * tc->link_array_size);
823  break;
824  }
825 
826  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
827  {
828  struct TopologyContextUnderlay *underlay;
829 
830  underlay = &tc->u.underlay;
831  if (GNUNET_YES != append)
832  {
833  GNUNET_assert (NULL == underlay->link_array);
834  underlay->link_array =
835  GNUNET_malloc (sizeof(struct UnderlayLink) * tc->link_array_size);
836  break;
837  }
838  GNUNET_assert ((0 < tc->link_array_size) && (NULL !=
839  underlay->link_array));
840  underlay->link_array =
841  GNUNET_realloc (underlay->link_array,
842  sizeof(struct UnderlayLink) * tc->link_array_size);
843  break;
844  }
845  }
846  for (cnt = 0; cnt < links; cnt++)
847  {
848  do
849  {
850  A_rand =
852  B_rand =
854  }
855  while (A_rand == B_rand);
856  make_link (index + cnt, A_rand, B_rand, tc);
857  }
858 }
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
unsigned int num_peers
The number of peers.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct UnderlayLink * link_array
The link array.
unsigned int link_array_size
The size of the link array.
enum TopologyContext::@70 type
The type of this context.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
Topology context information for underlay topologies.
union TopologyContext::@71 u
struct TopologyContextUnderlay underlay
Topology context information for underlay topology.
static struct GNUNET_CONTAINER_MultiPeerMap * links
Map from PIDs to struct VirtualLink entries describing links CORE knows to exist. ...
#define GNUNET_YES
Definition: gnunet_common.h:77
struct OverlayLink * link_array
An array of links; this array is of size link_array_size.
Context information for overlay topologies.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_malloc(size)
Wrapper around malloc.
static void make_link(unsigned int offset, uint32_t A, uint32_t B, struct TopologyContext *tc)
Populates the OverlayLink structure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_topo_scale_free()

static void gen_topo_scale_free ( struct TopologyContext tc,
uint16_t  cap,
uint8_t  m 
)
static

Generates scale free network.

Its construction is described in:

"Emergence of Scaling in Random Networks." Science 286, 509-512, 1999.

Parameters
tcthe topology context
capmaximum allowed node degree
mnumber of edges to establish for a new node when it is added to the network

Definition at line 872 of file testbed_api_topology.c.

References GNUNET_assert, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_free, GNUNET_malloc, GNUNET_malloc_large, GNUNET_MAX, GNUNET_MIN, GNUNET_realloc, TopologyContextOverlay::link_array, TopologyContextUnderlay::link_array, TopologyContext::link_array_size, links, m, make_link(), TopologyContext::num_peers, TopologyContext::overlay, peer, TopologyContext::type, TopologyContext::u, and TopologyContext::underlay.

Referenced by GNUNET_TESTBED_overlay_configure_topology_va(), and GNUNET_TESTBED_underlay_construct_().

875 {
876  unsigned int *deg;
877  unsigned int *etab;
878  unsigned int *used;
879  unsigned int etaboff;
880  unsigned int cnt;
881  unsigned int cnt2;
882  unsigned int peer;
883  unsigned int random_peer;
884  unsigned int links;
885  unsigned int off;
886  unsigned int redo_threshold;
887 
888  etaboff = 0;
889  tc->link_array_size = tc->num_peers * m;
890  switch (tc->type)
891  {
892  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
893  {
894  struct TopologyContextOverlay *overlay;
895 
896  overlay = &tc->u.overlay;
897  overlay->link_array = GNUNET_malloc_large (sizeof(struct OverlayLink)
898  * tc->link_array_size);
899  }
900  break;
901 
902  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
903  {
904  struct TopologyContextUnderlay *underlay;
905 
906  underlay = &tc->u.underlay;
907  underlay->link_array = GNUNET_malloc_large (sizeof(struct UnderlayLink)
908  * tc->link_array_size);
909  }
910  break;
911  }
912  etab = GNUNET_malloc_large (sizeof(unsigned int) * 2 * tc->link_array_size);
913  deg = GNUNET_malloc (sizeof(unsigned int) * tc->num_peers);
914  used = GNUNET_malloc (sizeof(unsigned int) * m);
915  /* start by connecting peer 1 to peer 0 */
916  make_link (0, 0, 1, tc);
917  deg[0]++;
918  deg[1]++;
919  etab[etaboff++] = 0;
920  etab[etaboff++] = 1;
921  links = 1;
922  for (peer = 2; peer < tc->num_peers; peer++)
923  {
924  if (cap < deg[peer])
925  continue;
926  for (cnt = 0; cnt < GNUNET_MIN (peer, m); cnt++)
927  {
928  redo_threshold = 0;
929 redo:
931  random_peer = etab[off];
932  if (cap < deg[random_peer])
933  {
934  if (++redo_threshold > GNUNET_MAX (1, cap / 2))
935  {
936  redo_threshold = 0;
937  off = 0;
938  for (cnt2 = 0; cnt2 < etaboff; cnt2++)
939  {
940  if (random_peer == etab[cnt2])
941  {
942  off++;
943  continue;
944  }
945  etab[cnt2 - off] = etab[cnt2];
946  }
947  etaboff -= off;
948  }
949  goto redo;
950  }
951  for (cnt2 = 0; cnt2 < cnt; cnt2++)
952  if (random_peer == used[cnt2])
953  goto redo;
954  make_link (links + cnt, random_peer, peer, tc);
955  deg[random_peer]++;
956  deg[peer]++;
957  used[cnt] = random_peer;
958  }
959  for (cnt = 0; cnt < GNUNET_MIN (peer, m); cnt++)
960  {
961  etab[etaboff++] = used[cnt];
962  etab[etaboff++] = peer;
963  }
964  links += GNUNET_MIN (peer, m);
965  }
966  GNUNET_free (etab);
967  GNUNET_free (used);
968  GNUNET_free (deg);
969  GNUNET_assert (links <= tc->link_array_size);
970  tc->link_array_size = links;
971  switch (tc->type)
972  {
973  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
974  {
975  struct TopologyContextOverlay *overlay;
976 
977  overlay = &tc->u.overlay;
978  overlay->link_array =
979  GNUNET_realloc (overlay->link_array, sizeof(struct OverlayLink)
980  * tc->link_array_size);
981  }
982  break;
983 
984  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
985  {
986  struct TopologyContextUnderlay *underlay;
987 
988  underlay = &tc->u.underlay;
989  underlay->link_array =
990  GNUNET_realloc (underlay->link_array, sizeof(struct UnderlayLink)
991  * tc->link_array_size);
992  }
993  break;
994  }
995 }
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
unsigned int num_peers
The number of peers.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct UnderlayLink * link_array
The link array.
unsigned int link_array_size
The size of the link array.
#define GNUNET_malloc_large(size)
Wrapper around malloc.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
enum TopologyContext::@70 type
The type of this context.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
#define GNUNET_MAX(a, b)
Definition: gnunet_common.h:82
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:80
Topology context information for underlay topologies.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
union TopologyContext::@71 u
struct TopologyContextUnderlay underlay
Topology context information for underlay topology.
static struct GNUNET_CONTAINER_MultiPeerMap * links
Map from PIDs to struct VirtualLink entries describing links CORE knows to exist. ...
struct OverlayLink * link_array
An array of links; this array is of size link_array_size.
Context information for overlay topologies.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
static void make_link(unsigned int offset, uint32_t A, uint32_t B, struct TopologyContext *tc)
Populates the OverlayLink structure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_topo_from_file()

static void gen_topo_from_file ( struct TopologyContext tc,
const char *  filename 
)
static

Generates topology from the given file.

Parameters
tcthe topology context
filenamethe filename of the file containing topology data

We read the peer index

We read the other peer indices

Definition at line 1005 of file testbed_api_topology.c.

References _, buf, data, end, fs, GNUNET_DISK_file_size(), GNUNET_DISK_file_test(), GNUNET_DISK_fn_read(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_free_non_null, GNUNET_malloc, GNUNET_OK, GNUNET_realloc, GNUNET_SYSERR, GNUNET_YES, TopologyContextOverlay::link_array, TopologyContextUnderlay::link_array, TopologyContext::link_array_size, LOG, make_link(), TopologyContext::num_peers, TopologyContext::overlay, peer_id, state, status, TopologyContext::type, TopologyContext::u, and TopologyContext::underlay.

Referenced by GNUNET_TESTBED_overlay_configure_topology_va(), and GNUNET_TESTBED_underlay_construct_().

1007 {
1008  char *data;
1009  char *end;
1010  char *buf;
1011  uint64_t fs;
1012  uint64_t offset;
1013  unsigned long int peer_id;
1014  unsigned long int other_peer_id;
1015  enum ParseState
1016  {
1020  PEER_INDEX,
1021 
1025  OTHER_PEER_INDEX,
1026  } state;
1027  int status;
1028 
1029  status = GNUNET_SYSERR;
1031  {
1033  _ ("Topology file %s not found\n"),
1034  filename);
1035  return;
1036  }
1037  if (GNUNET_OK !=
1039  {
1041  _ ("Topology file %s has no data\n"),
1042  filename);
1043  return;
1044  }
1045  data = GNUNET_malloc (fs);
1046  if (fs != GNUNET_DISK_fn_read (filename, data, fs))
1047  {
1049  _ ("Topology file %s cannot be read\n"),
1050  filename);
1051  goto _exit;
1052  }
1053 
1054  offset = 0;
1055  peer_id = 0;
1056  state = PEER_INDEX;
1057  while (offset < fs)
1058  {
1059  if (0 != isspace ((unsigned char) data[offset]))
1060  {
1061  offset++;
1062  continue;
1063  }
1064  switch (state)
1065  {
1066  case PEER_INDEX:
1067  buf = strchr (&data[offset], ':');
1068  if (NULL == buf)
1069  {
1071  _ ("Failed to read peer index from toology file: %s"), filename);
1072  goto _exit;
1073  }
1074  *buf = '\0';
1075  errno = 0;
1076  peer_id = (unsigned int) strtoul (&data[offset], &end, 10);
1077  if (0 != errno)
1078  {
1080  _ ("Value in given topology file: %s out of range\n"), filename);
1081  goto _exit;
1082  }
1083  if (&data[offset] == end)
1084  {
1086  _ ("Failed to read peer index from topology file: %s"), filename);
1087  goto _exit;
1088  }
1089  if (tc->num_peers <= peer_id)
1090  {
1092  _ ("Topology file needs more peers than given ones\n"), filename);
1093  goto _exit;
1094  }
1095  state = OTHER_PEER_INDEX;
1096  offset += ((unsigned int) (buf - &data[offset])) + 1;
1097  break;
1098 
1099  case OTHER_PEER_INDEX:
1100  errno = 0;
1101  other_peer_id = (unsigned int) strtoul (&data[offset], &end, 10);
1102  if (0 != errno)
1103  {
1105  _ ("Value in given topology file: %s out of range\n"), filename);
1106  goto _exit;
1107  }
1108  if (&data[offset] == end)
1109  {
1111  _ ("Failed to read peer index from topology file: %s"), filename);
1112  goto _exit;
1113  }
1114  if (tc->num_peers <= other_peer_id)
1115  {
1117  _ ("Topology file needs more peers than given ones\n"), filename);
1118  goto _exit;
1119  }
1120  if (peer_id != other_peer_id)
1121  {
1122  tc->link_array_size++;
1123  switch (tc->type)
1124  {
1125  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1126  {
1127  struct TopologyContextOverlay *overlay;
1128 
1129  overlay = &tc->u.overlay;
1130  overlay->link_array =
1131  GNUNET_realloc (overlay->link_array,
1132  sizeof(struct OverlayLink) * tc->link_array_size);
1133  }
1134  break;
1135 
1136  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1137  {
1138  struct TopologyContextUnderlay *underlay;
1139 
1140  underlay = &tc->u.underlay;
1141  underlay->link_array =
1142  GNUNET_realloc (underlay->link_array,
1143  sizeof(struct UnderlayLink)
1144  * tc->link_array_size);
1145  }
1146  break;
1147  }
1148  offset += end - &data[offset];
1149  make_link (tc->link_array_size - 1, peer_id, other_peer_id, tc);
1150  }
1151  else
1153  _ ("Ignoring to connect peer %u to peer %u\n"),
1154  peer_id,
1155  other_peer_id);
1156  while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs))
1157  offset++;
1158  if ((offset < fs) &&
1159  ('\n' == data[offset]))
1160  state = PEER_INDEX;
1161  else if ((offset < fs) &&
1162  ('|' == data[offset]))
1163  {
1164  state = OTHER_PEER_INDEX;
1165  offset++;
1166  }
1167  break;
1168  }
1169  }
1170  status = GNUNET_OK;
1171 
1172 _exit:
1173  GNUNET_free (data);
1174  if (GNUNET_OK != status)
1175  {
1177  "Removing link data read from the file\n");
1178  tc->link_array_size = 0;
1179  switch (tc->type)
1180  {
1181  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1182  {
1183  struct TopologyContextOverlay *overlay;
1184 
1185  overlay = &tc->u.overlay;
1186  GNUNET_free_non_null (overlay->link_array);
1187  overlay->link_array = NULL;
1188  }
1189  break;
1190 
1191  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1192  {
1193  struct TopologyContextUnderlay *underlay;
1194 
1195  underlay = &tc->u.underlay;
1196  GNUNET_free_non_null (underlay->link_array);
1197  underlay->link_array = NULL;
1198  }
1199  break;
1200  }
1201  }
1202 }
int 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)...
Definition: disk.c:544
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
#define LOG(kind,...)
Generic loggins shorthand.
unsigned int num_peers
The number of peers.
struct UnderlayLink * link_array
The link array.
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
unsigned int link_array_size
The size of the link array.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
enum TopologyContext::@70 type
The type of this context.
enum State state
current state of profiling
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
uint16_t status
See PRISM_STATUS_*-constants.
static char buf[2048]
static char * filename
Topology context information for underlay topologies.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
union TopologyContext::@71 u
struct TopologyContextUnderlay underlay
Topology context information for underlay topology.
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:36
int 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).
Definition: disk.c:257
#define GNUNET_YES
Definition: gnunet_common.h:77
struct OverlayLink * link_array
An array of links; this array is of size link_array_size.
uint32_t data
The data value.
Context information for overlay topologies.
#define GNUNET_malloc(size)
Wrapper around malloc.
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:794
#define GNUNET_free(ptr)
Wrapper around free.
static void make_link(unsigned int offset, uint32_t A, uint32_t B, struct TopologyContext *tc)
Populates the OverlayLink structure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_topo_clique()

static void gen_topo_clique ( struct TopologyContext tc)
static

Generates clique topology.

Parameters
tcthe topology context

Definition at line 1211 of file testbed_api_topology.c.

References GNUNET_new_array, TopologyContextOverlay::link_array, TopologyContextUnderlay::link_array, TopologyContext::link_array_size, make_link(), TopologyContext::num_peers, TopologyContext::overlay, TopologyContext::type, TopologyContext::u, and TopologyContext::underlay.

Referenced by GNUNET_TESTBED_overlay_configure_topology_va(), and GNUNET_TESTBED_underlay_construct_().

1212 {
1213  unsigned int cnt;
1214  unsigned int offset;
1215  unsigned int neighbour;
1216 
1217  tc->link_array_size = tc->num_peers * (tc->num_peers - 1);
1218  switch (tc->type)
1219  {
1220  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1221  {
1222  struct TopologyContextOverlay *overlay;
1223 
1224  overlay = &tc->u.overlay;
1226  struct OverlayLink);
1227  }
1228  break;
1229 
1230  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1231  {
1232  struct TopologyContextUnderlay *underlay;
1233 
1234  underlay = &tc->u.underlay;
1235  underlay->link_array = GNUNET_new_array (tc->link_array_size,
1236  struct UnderlayLink);
1237  }
1238  }
1239  offset = 0;
1240  for (cnt = 0; cnt < tc->num_peers; cnt++)
1241  {
1242  for (neighbour = 0; neighbour < tc->num_peers; neighbour++)
1243  {
1244  if (neighbour == cnt)
1245  continue;
1246  make_link (offset, cnt, neighbour, tc);
1247  offset++;
1248  }
1249  }
1250 }
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
unsigned int num_peers
The number of peers.
struct UnderlayLink * link_array
The link array.
unsigned int link_array_size
The size of the link array.
enum TopologyContext::@70 type
The type of this context.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
Topology context information for underlay topologies.
union TopologyContext::@71 u
struct TopologyContextUnderlay underlay
Topology context information for underlay topology.
struct OverlayLink * link_array
An array of links; this array is of size link_array_size.
Context information for overlay topologies.
static void make_link(unsigned int offset, uint32_t A, uint32_t B, struct TopologyContext *tc)
Populates the OverlayLink structure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_topology_get_()

int GNUNET_TESTBED_topology_get_ ( enum GNUNET_TESTBED_TopologyOption topology,
const char *  topology_string 
)

Get a topology from a string input.

Parameters
topologywhere to write the retrieved topology
topology_stringThe string to attempt to get a configuration value from
Returns
GNUNET_YES if topology string matched a known topology, GNUNET_NO if not

Definition at line 1509 of file testbed_api_topology.c.

References GNUNET_assert, GNUNET_NO, GNUNET_TESTBED_TOPOLOGY_OPTION_END, GNUNET_YES, and topology_strings.

Referenced by GNUNET_TESTBED_run(), and run().

1511 {
1512  unsigned int cnt;
1513 
1514  for (cnt = 0; NULL != topology_strings[cnt]; cnt++)
1515  {
1516  if (0 == strcasecmp (topology_string, topology_strings[cnt]))
1517  {
1518  if (NULL != topology)
1521  (enum GNUNET_TESTBED_TopologyOption) cnt);
1522  return GNUNET_YES;
1523  }
1524  }
1525  return GNUNET_NO;
1526 }
GNUNET_TESTBED_TopologyOption
Topologies and topology options supported for testbeds.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
enum GNUNET_TESTBED_TopologyOption topology
The topology to generate.
The options should always end with this.
static const char * topology_strings[]
A array of names representing topologies.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the caller graph for this function:

◆ GNUNET_TESTBED_topology_to_str_()

char* GNUNET_TESTBED_topology_to_str_ ( enum GNUNET_TESTBED_TopologyOption  topology)

Returns the string corresponding to the given topology.

Parameters
topologythe topology
Returns
the string (freshly allocated) of given topology; NULL if topology cannot be expressed as a string

Definition at line 1537 of file testbed_api_topology.c.

References GNUNET_strdup, GNUNET_TESTBED_TOPOLOGY_OPTION_END, and topology_strings.

1538 {
1540  return NULL;
1542 }
enum GNUNET_TESTBED_TopologyOption topology
The topology to generate.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
The options should always end with this.
static const char * topology_strings[]
A array of names representing topologies.

◆ GNUNET_TESTBED_underlay_construct_()

int GNUNET_TESTBED_underlay_construct_ ( int  num_peers,
underlay_link_processor  proc,
void *  cls,
  ... 
)

Function to construct an underlay topology.

Parameters
num_peersthe number of peers for which the topology should be generated
procthe underlay link processor callback. Will be called for each underlay link generated unless a previous call to this callback returned GNUNET_SYSERR. Cannot be NULL.
clsclosure for proc
...variable arguments denoting the topology and its parameters. They should start with the type of topology to generate followed by their options.
Returns
GNUNET_OK if underlay link generation is successful; GNUNET_SYSERR upon error in generating the underlay or if any calls to the underlay link processor returned GNUNET_SYSERR

Definition at line 1562 of file testbed_api_topology.c.

References UnderlayLink::A, UnderlayLink::B, UnderlayLink::bandwidth, filename, gen_topo_2dtorus(), gen_topo_clique(), gen_topo_from_file(), gen_topo_line(), gen_topo_random(), gen_topo_ring(), gen_topo_scale_free(), gen_topo_star(), GNUNET_assert, GNUNET_free_non_null, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_TESTBED_TOPOLOGY_2D_TORUS, GNUNET_TESTBED_TOPOLOGY_CLIQUE, GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, GNUNET_TESTBED_TOPOLOGY_FROM_FILE, GNUNET_TESTBED_TOPOLOGY_LINE, GNUNET_TESTBED_TOPOLOGY_RING, GNUNET_TESTBED_TOPOLOGY_SCALE_FREE, GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD, GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING, GNUNET_TESTBED_TOPOLOGY_STAR, GNUNET_VA_ARG_ENUM, GNUNET_YES, UnderlayLink::latency, TopologyContextUnderlay::link_array, TopologyContext::link_array_size, UnderlayLink::loss, m, num_peers, TopologyContext::num_peers, ret, topology, TopologyContext::type, TopologyContext::u, and TopologyContext::underlay.

Referenced by run().

1566 {
1567  struct TopologyContext tc;
1568  struct TopologyContextUnderlay *underlay;
1569  struct UnderlayLink *ulink;
1570  va_list vargs;
1572  unsigned int cnt;
1573  int ret;
1574 
1575  GNUNET_assert (NULL != proc);
1576  ret = GNUNET_OK;
1577  memset (&tc, 0, sizeof(tc));
1578  tc.num_peers = num_peers;
1579  tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY;
1580  underlay = &tc.u.underlay;
1581  va_start (vargs, cls);
1583  switch (topology)
1584  {
1586  gen_topo_line (&tc);
1587  break;
1588 
1590  gen_topo_star (&tc);
1591  break;
1592 
1594  gen_topo_ring (&tc);
1595  break;
1596 
1598  gen_topo_clique (&tc);
1599  break;
1600 
1602  gen_topo_2dtorus (&tc);
1603  break;
1604 
1606  gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_NO);
1607  break;
1608 
1610  gen_topo_ring (&tc);
1611  gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES);
1612  break;
1613 
1615  gen_topo_2dtorus (&tc);
1616  gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES);
1617  break;
1618 
1620  {
1621  const char *filename;
1622  filename = va_arg (vargs, char *);
1623  GNUNET_assert (NULL != filename);
1624  gen_topo_from_file (&tc, filename);
1625  }
1626  break;
1627 
1629  {
1630  uint16_t cap;
1631  uint8_t m;
1632  cap = (uint16_t) va_arg (vargs, unsigned int);
1633  m = (uint8_t) va_arg (vargs, unsigned int);
1634  gen_topo_scale_free (&tc, cap, m);
1635  }
1636  break;
1637 
1638  default:
1639  GNUNET_assert (0);
1640  }
1641  va_end (vargs);
1642  for (cnt = 0; cnt < tc.link_array_size; cnt++)
1643  {
1644  ulink = &underlay->link_array[cnt];
1645  if (GNUNET_SYSERR == proc (cls,
1646  ulink->A,
1647  ulink->B,
1648  ulink->bandwidth,
1649  ulink->latency,
1650  ulink->loss))
1651  {
1652  ret = GNUNET_SYSERR;
1653  break;
1654  }
1655  }
1656  GNUNET_free_non_null (underlay->link_array);
1657  return ret;
1658 }
A clique (everyone connected to everyone else).
static void gen_topo_scale_free(struct TopologyContext *tc, uint16_t cap, uint8_t m)
Generates scale free network.
GNUNET_TESTBED_TopologyOption
Topologies and topology options supported for testbeds.
static void gen_topo_star(struct TopologyContext *tc)
Generates star topology.
static void gen_topo_clique(struct TopologyContext *tc)
Generates clique topology.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:418
struct UnderlayLink * link_array
The link array.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
enum GNUNET_TESTBED_TopologyOption topology
The topology to generate.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static void gen_topo_ring(struct TopologyContext *tc)
Generates ring topology.
static void gen_topo_line(struct TopologyContext *tc)
Generates line topology.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
Read a topology from a given file.
static char * filename
Topology context information for underlay topologies.
static void gen_topo_random(struct TopologyContext *tc, unsigned int links, int append)
Generates ring topology.
static void gen_topo_from_file(struct TopologyContext *tc, const char *filename)
Generates topology from the given file.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
Small-world network (2d torus plus random links).
static unsigned int num_peers
static void gen_topo_2dtorus(struct TopologyContext *tc)
Generates ring topology.
#define GNUNET_VA_ARG_ENUM(va, X)
wrap va_arg for enums
#define GNUNET_YES
Definition: gnunet_common.h:77
Context information for topology operations.
Small-world network (ring plus random links).
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ topology_strings

const char* topology_strings[]
static

A array of names representing topologies.

Should be in sync with enum GNUNET_TESTBED_TopologyOption

Definition at line 259 of file testbed_api_topology.c.

Referenced by GNUNET_TESTBED_topology_get_(), and GNUNET_TESTBED_topology_to_str_().