GNUnet  0.10.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 349 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().

352 {
353  struct OverlayLink *link = cls;
354  struct TopologyContext *tc;
355  struct TopologyContextOverlay *overlay;
356  struct RetryListEntry *retry_entry;
357 
358  GNUNET_assert (op == link->op);
360  link->op = NULL;
361  tc = link->tc;
362  GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type);
363  overlay = &tc->u.overlay;
364  if (NULL != emsg)
365  {
366  overlay->nfailures++;
367  if (0 != overlay->retry_cnt)
368  {
370  "Error while establishing a link: %s -- Retrying\n",
371  emsg);
372  retry_entry = GNUNET_new (struct RetryListEntry);
373  retry_entry->link = link;
375  overlay->rl_tail,
376  retry_entry);
377  }
378  }
379  else
380  overlay->nsuccess++;
381  overlay->ncompleted++;
382  if (overlay->ncompleted < overlay->nlinks)
383  return;
384  if ((0 != overlay->retry_cnt) && (NULL != overlay->rl_head))
385  {
386  overlay->retry_cnt--;
387  overlay->ncompleted = 0;
388  overlay->nlinks = 0;
389  while (NULL != (retry_entry = overlay->rl_head))
390  {
391  link = retry_entry->link;
392  link->op =
395  link,
396  overlay->peers[link->A],
397  overlay->peers[link->B]);
398  overlay->nlinks++;
400  overlay->rl_tail,
401  retry_entry);
402  GNUNET_free (retry_entry);
403  }
404  return;
405  }
406  if (NULL != overlay->comp_cb)
407  {
408  overlay->comp_cb (overlay->comp_cb_cls,
409  overlay->nsuccess,
410  overlay->nfailures);
411  }
412 }
#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:747
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:417
enum TopologyContext::@73 type
The type of this context.
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.
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:2046
unsigned int nfailures
Total failed overlay connections.
unsigned int nlinks
Number of links to try.
#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.
union TopologyContext::@74 u
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 422 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().

423 {
424  struct TopologyContext *tc = cls;
425  struct TopologyContextOverlay *overlay;
426  unsigned int p;
427 
428  GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type);
429  overlay = &tc->u.overlay;
430  overlay->nlinks = tc->link_array_size;
431  for (p = 0; p < tc->link_array_size; p++)
432  {
433  overlay->link_array[p].op =
436  &overlay->link_array[p],
437  overlay->peers[overlay->link_array[p].A],
438  overlay->peers[overlay->link_array[p].B]);
439  }
440 }
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:417
enum TopologyContext::@73 type
The type of this context.
unsigned int link_array_size
The size of the link array.
void * op_cls
The operation closure.
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.
struct OverlayLink * link_array
An array of links; this array is of size link_array_size.
union TopologyContext::@74 u
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 449 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().

450 {
451  struct TopologyContext *tc = cls;
452  struct TopologyContextOverlay *overlay;
453  struct RetryListEntry *retry_entry;
454  unsigned int p;
455 
456  GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type);
457  overlay = &tc->u.overlay;
458  while (NULL != (retry_entry = overlay->rl_head))
459  {
460  GNUNET_CONTAINER_DLL_remove (overlay->rl_head, overlay->rl_tail, retry_entry);
461  GNUNET_free (retry_entry);
462  }
463  if (NULL != overlay->link_array)
464  {
465  for (p = 0; p < tc->link_array_size; p++)
466  if (NULL != overlay->link_array[p].op)
468  GNUNET_free (overlay->link_array);
469  }
470  GNUNET_free (tc);
471 }
#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:747
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:417
enum TopologyContext::@73 type
The type of this context.
unsigned int link_array_size
The size of the link array.
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:2046
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.
union TopologyContext::@74 u
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 484 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().

488 {
489  GNUNET_assert (A != B);
490  switch (tc->type)
491  {
492  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
493  {
494  struct TopologyContextOverlay *overlay;
495  struct OverlayLink *olink;
496 
497  overlay = &tc->u.overlay;
498  GNUNET_assert (offset < tc->link_array_size);
499  olink = &overlay->link_array[offset];
500  LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %u to %u\n", B, A);
501  olink->A = A;
502  olink->B = B;
503  olink->op = NULL;
504  olink->tc = tc;
505  }
506  break;
507  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
508  {
509  struct TopologyContextUnderlay *underlay;
510  struct UnderlayLink *ulink;
511 
512  underlay = &tc->u.underlay;
513  GNUNET_assert (offset < tc->link_array_size);
514  ulink = &underlay->link_array[offset];
515  ulink->A = A;
516  ulink->B = B;
517  }
518  break;
519  }
520 }
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:417
struct UnderlayLink * link_array
The link array.
enum TopologyContext::@73 type
The type of this context.
Topology context information for underlay topologies.
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.
union TopologyContext::@74 u
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 529 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_().

530 {
531  unsigned int cnt;
532 
533  tc->link_array_size = tc->num_peers - 1;
534  switch (tc->type)
535  {
536  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
537  {
538  struct TopologyContextOverlay *overlay;
539 
540  overlay = &tc->u.overlay;
541  overlay->link_array =
543  struct OverlayLink);
544  }
545  break;
546  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
547  {
548  struct TopologyContextUnderlay *underlay;
549 
550  underlay = &tc->u.underlay;
551  underlay->link_array =
553  struct UnderlayLink);
554  }
555  break;
556  }
557  for (cnt = 0; cnt < (tc->link_array_size); cnt++)
558  make_link (cnt, cnt, cnt + 1, tc);
559 }
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
unsigned int num_peers
The number of peers.
struct UnderlayLink * link_array
The link array.
enum TopologyContext::@73 type
The type of this context.
unsigned int link_array_size
The size of the link array.
#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.
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.
union TopologyContext::@74 u
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 568 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_().

569 {
570  unsigned int cnt;
571 
572  tc->link_array_size = tc->num_peers - 1;
573  switch (tc->type)
574  {
575  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
576  {
577  struct TopologyContextOverlay *overlay;
578 
579  overlay = &tc->u.overlay;
580  overlay->link_array =
582  struct OverlayLink);
583  }
584  break;
585  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
586  {
587  struct TopologyContextUnderlay *underlay;
588 
589  underlay = &tc->u.underlay;
590  underlay->link_array =
592  struct UnderlayLink);
593  }
594  break;
595  }
596  for (cnt = tc->link_array_size; cnt; cnt--)
597  make_link (cnt - 1,
598  0,
599  cnt,
600  tc);
601 }
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
unsigned int num_peers
The number of peers.
struct UnderlayLink * link_array
The link array.
enum TopologyContext::@73 type
The type of this context.
unsigned int link_array_size
The size of the link array.
#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.
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.
union TopologyContext::@74 u
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 610 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_().

611 {
612  gen_topo_line (tc);
613  tc->link_array_size++;
614  switch (tc->type)
615  {
616  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
617  {
618  struct TopologyContextOverlay *overlay;
619 
620  overlay = &tc->u.overlay;
621  overlay->link_array =
622  GNUNET_realloc (overlay->link_array, sizeof (struct OverlayLink) *
623  tc->link_array_size);
624  }
625  break;
626  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
627  {
628  struct TopologyContextUnderlay *underlay;
629 
630  underlay = &tc->u.underlay;
631  underlay->link_array =
632  GNUNET_realloc (underlay->link_array, sizeof (struct UnderlayLink) *
633  tc->link_array_size);
634  }
635  break;
636  }
637  make_link (tc->link_array_size - 1, tc->num_peers - 1, 0, tc);
638 }
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
unsigned int num_peers
The number of peers.
struct UnderlayLink * link_array
The link array.
enum TopologyContext::@73 type
The type of this context.
unsigned int link_array_size
The size of the link array.
static void gen_topo_line(struct TopologyContext *tc)
Generates line topology.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
Topology context information for underlay topologies.
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.
union TopologyContext::@74 u
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 654 of file testbed_api_topology.c.

References GNUNET_free, and GNUNET_malloc.

Referenced by gen_topo_2dtorus().

656 {
657  double sq;
658  unsigned int sq_floor;
659  unsigned int _rows;
660  unsigned int *_rows_len;
661  unsigned int x;
662  unsigned int y;
663  unsigned int _num_peers;
664  unsigned int cnt;
665 
666  sq = sqrt (num_peers);
667  sq = floor (sq);
668  sq_floor = (unsigned int) sq;
669  _rows = (sq_floor + 1);
670  _rows_len = GNUNET_malloc (sizeof (unsigned int) * _rows);
671  for (y = 0; y < _rows - 1; y++)
672  _rows_len[y] = sq_floor;
673  _num_peers = sq_floor * sq_floor;
674  cnt = (_num_peers < 2) ? _num_peers : 2 * _num_peers;
675  x = 0;
676  y = 0;
677  while (_num_peers < num_peers)
678  {
679  if (x < y)
680  _rows_len[_rows - 1] = ++x;
681  else
682  _rows_len[y++]++;
683  _num_peers++;
684  }
685  cnt += (x < 2) ? x : 2 * x;
686  cnt += (y < 2) ? y : 2 * y;
687  if (0 == _rows_len[_rows - 1])
688  _rows--;
689  if (NULL != rows)
690  *rows = _rows;
691  if (NULL != rows_len)
692  *rows_len = _rows_len;
693  else
694  GNUNET_free (_rows_len);
695  return cnt;
696 }
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 705 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_().

706 {
707  unsigned int rows;
708  unsigned int *rows_len;
709  unsigned int x;
710  unsigned int y;
711  unsigned int cnt;
712  unsigned int offset;
713 
714  tc->link_array_size =
715  GNUNET_TESTBED_2dtorus_calc_links (tc->num_peers, &rows, &rows_len);
716  switch (tc->type)
717  {
718  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
719  {
720  struct TopologyContextOverlay *overlay;
721 
722  overlay = &tc->u.overlay;
723  overlay->link_array =
724  GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size);
725  }
726  break;
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.
enum TopologyContext::@73 type
The type of this context.
unsigned int link_array_size
The size of the link array.
Topology context information for underlay topologies.
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.
union TopologyContext::@74 u
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 != overlay->link_array));
819  overlay->link_array =
820  GNUNET_realloc (overlay->link_array,
821  sizeof (struct OverlayLink) * tc->link_array_size);
822  break;
823  }
824  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
825  {
826  struct TopologyContextUnderlay *underlay;
827 
828  underlay = &tc->u.underlay;
829  if (GNUNET_YES != append)
830  {
831  GNUNET_assert (NULL == underlay->link_array);
832  underlay->link_array =
833  GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size);
834  break;
835  }
836  GNUNET_assert ((0 < tc->link_array_size) && (NULL != underlay->link_array));
837  underlay->link_array =
838  GNUNET_realloc (underlay->link_array,
839  sizeof (struct UnderlayLink) * tc->link_array_size);
840  break;
841  }
842  }
843  for (cnt = 0; cnt < links; cnt++)
844  {
845  do
846  {
847  A_rand =
849  B_rand =
851  }
852  while (A_rand == B_rand);
853  make_link (index+cnt, A_rand, B_rand, tc);
854  }
855 }
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.
enum TopologyContext::@73 type
The type of this context.
unsigned int link_array_size
The size of the link array.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
Topology context information for underlay topologies.
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:80
struct OverlayLink * link_array
An array of links; this array is of size link_array_size.
union TopologyContext::@74 u
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 869 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_().

872 {
873  unsigned int *deg;
874  unsigned int *etab;
875  unsigned int *used;
876  unsigned int etaboff;
877  unsigned int cnt;
878  unsigned int cnt2;
879  unsigned int peer;
880  unsigned int random_peer;
881  unsigned int links;
882  unsigned int off;
883  unsigned int redo_threshold;
884 
885  etaboff = 0;
886  tc->link_array_size = tc->num_peers * m;
887  switch (tc->type)
888  {
889  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
890  {
891  struct TopologyContextOverlay *overlay;
892 
893  overlay = &tc->u.overlay;
894  overlay->link_array = GNUNET_malloc_large (sizeof (struct OverlayLink) *
895  tc->link_array_size);
896  }
897  break;
898  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
899  {
900  struct TopologyContextUnderlay *underlay;
901 
902  underlay = &tc->u.underlay;
903  underlay->link_array = GNUNET_malloc_large (sizeof (struct UnderlayLink) *
904  tc->link_array_size);
905  }
906  break;
907  }
908  etab = GNUNET_malloc_large (sizeof (unsigned int) * 2 * tc->link_array_size);
909  deg = GNUNET_malloc (sizeof (unsigned int) * tc->num_peers);
910  used = GNUNET_malloc (sizeof (unsigned int) * m);
911  /* start by connecting peer 1 to peer 0 */
912  make_link (0, 0, 1, tc);
913  deg[0]++;
914  deg[1]++;
915  etab[etaboff++] = 0;
916  etab[etaboff++] = 1;
917  links = 1;
918  for (peer = 2; peer < tc->num_peers; peer++)
919  {
920  if (cap < deg[peer])
921  continue;
922  for (cnt = 0; cnt < GNUNET_MIN (peer, m); cnt++)
923  {
924  redo_threshold = 0;
925  redo:
927  random_peer = etab[off];
928  if (cap < deg[random_peer])
929  {
930  if (++redo_threshold > GNUNET_MAX (1, cap / 2))
931  {
932  redo_threshold = 0;
933  off = 0;
934  for (cnt2 = 0; cnt2 < etaboff; cnt2++)
935  {
936  if (random_peer == etab[cnt2])
937  {
938  off++;
939  continue;
940  }
941  etab[cnt2 - off] = etab[cnt2];
942  }
943  etaboff -= off;
944  }
945  goto redo;
946  }
947  for (cnt2 = 0; cnt2 < cnt; cnt2++)
948  if (random_peer == used[cnt2])
949  goto redo;
950  make_link (links + cnt, random_peer, peer, tc);
951  deg[random_peer]++;
952  deg[peer]++;
953  used[cnt] = random_peer;
954  }
955  for (cnt = 0; cnt < GNUNET_MIN (peer, m); cnt++)
956  {
957  etab[etaboff++] = used[cnt];
958  etab[etaboff++] = peer;
959  }
960  links += GNUNET_MIN (peer, m);
961  }
962  GNUNET_free (etab);
963  GNUNET_free (used);
964  GNUNET_free (deg);
965  GNUNET_assert (links <= tc->link_array_size);
966  tc->link_array_size = links;
967  switch (tc->type)
968  {
969  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
970  {
971  struct TopologyContextOverlay *overlay;
972 
973  overlay = &tc->u.overlay;
974  overlay->link_array =
975  GNUNET_realloc (overlay->link_array, sizeof (struct OverlayLink) * tc->link_array_size);
976  }
977  break;
978  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
979  {
980  struct TopologyContextUnderlay *underlay;
981 
982  underlay = &tc->u.underlay;
983  underlay->link_array =
984  GNUNET_realloc (underlay->link_array, sizeof (struct UnderlayLink) * tc->link_array_size);
985  }
986  break;
987  }
988 }
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.
enum TopologyContext::@73 type
The type of this context.
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:99
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
#define GNUNET_MAX(a, b)
Definition: gnunet_common.h:85
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:83
Topology context information for underlay topologies.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
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.
union TopologyContext::@74 u
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 998 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_().

1000 {
1001  char *data;
1002  char *end;
1003  char *buf;
1004  uint64_t fs;
1005  uint64_t offset;
1006  unsigned long int peer_id;
1007  unsigned long int other_peer_id;
1008  enum ParseState
1009  {
1010 
1014  PEER_INDEX,
1015 
1019  OTHER_PEER_INDEX,
1020 
1021  } state;
1022  int status;
1023 
1024  status = GNUNET_SYSERR;
1026  {
1028  _("Topology file %s not found\n"),
1029  filename);
1030  return;
1031  }
1032  if (GNUNET_OK !=
1034  {
1036  _("Topology file %s has no data\n"),
1037  filename);
1038  return;
1039  }
1040  data = GNUNET_malloc (fs);
1041  if (fs != GNUNET_DISK_fn_read (filename, data, fs))
1042  {
1044  _("Topology file %s cannot be read\n"),
1045  filename);
1046  goto _exit;
1047  }
1048 
1049  offset = 0;
1050  peer_id = 0;
1051  state = PEER_INDEX;
1052  while (offset < fs)
1053  {
1054  if (0 != isspace ((unsigned char) data[offset]))
1055  {
1056  offset++;
1057  continue;
1058  }
1059  switch (state)
1060  {
1061  case PEER_INDEX:
1062  buf = strchr (&data[offset], ':');
1063  if (NULL == buf)
1064  {
1066  _("Failed to read peer index from toology file: %s"), filename);
1067  goto _exit;
1068  }
1069  *buf = '\0';
1070  errno = 0;
1071  peer_id = (unsigned int) strtoul (&data[offset], &end, 10);
1072  if (0 != errno)
1073  {
1075  _("Value in given topology file: %s out of range\n"), filename);
1076  goto _exit;
1077  }
1078  if (&data[offset] == end)
1079  {
1081  _("Failed to read peer index from topology file: %s"), filename);
1082  goto _exit;
1083  }
1084  if (tc->num_peers <= peer_id)
1085  {
1087  _("Topology file needs more peers than given ones\n"), filename);
1088  goto _exit;
1089  }
1090  state = OTHER_PEER_INDEX;
1091  offset += ((unsigned int) (buf - &data[offset])) + 1;
1092  break;
1093  case OTHER_PEER_INDEX:
1094  errno = 0;
1095  other_peer_id = (unsigned int) strtoul (&data[offset], &end, 10);
1096  if (0 != errno)
1097  {
1099  _("Value in given topology file: %s out of range\n"), filename);
1100  goto _exit;
1101  }
1102  if (&data[offset] == end)
1103  {
1105  _("Failed to read peer index from topology file: %s"), filename);
1106  goto _exit;
1107  }
1108  if (tc->num_peers <= other_peer_id)
1109  {
1111  _("Topology file needs more peers than given ones\n"), filename);
1112  goto _exit;
1113  }
1114  if (peer_id != other_peer_id)
1115  {
1116  tc->link_array_size++;
1117  switch (tc->type)
1118  {
1119  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1120  {
1121  struct TopologyContextOverlay *overlay;
1122 
1123  overlay = &tc->u.overlay;
1124  overlay->link_array =
1125  GNUNET_realloc (overlay->link_array,
1126  sizeof (struct OverlayLink) * tc->link_array_size);
1127  }
1128  break;
1129  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1130  {
1131  struct TopologyContextUnderlay *underlay;
1132 
1133  underlay = &tc->u.underlay;
1134  underlay->link_array =
1135  GNUNET_realloc (underlay->link_array,
1136  sizeof (struct UnderlayLink) * tc->link_array_size);
1137  }
1138  break;
1139  }
1140  offset += end - &data[offset];
1141  make_link (tc->link_array_size - 1, peer_id, other_peer_id, tc);
1142  }
1143  else
1145  _("Ignoring to connect peer %u to peer %u\n"),
1146  peer_id,
1147  other_peer_id);
1148  while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs))
1149  offset++;
1150  if ( (offset < fs) &&
1151  ('\n' == data[offset]) )
1152  state = PEER_INDEX;
1153  else if ( (offset < fs) &&
1154  ('|' == data[offset]) )
1155  {
1156  state = OTHER_PEER_INDEX;
1157  offset++;
1158  }
1159  break;
1160  }
1161  }
1162  status = GNUNET_OK;
1163 
1164 _exit:
1165  GNUNET_free (data);
1166  if (GNUNET_OK != status)
1167  {
1169  "Removing link data read from the file\n");
1170  tc->link_array_size = 0;
1171  switch (tc->type)
1172  {
1173  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1174  {
1175  struct TopologyContextOverlay *overlay;
1176 
1177  overlay = &tc->u.overlay;
1178  GNUNET_free_non_null (overlay->link_array);
1179  overlay->link_array = NULL;
1180  }
1181  break;
1182  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1183  {
1184  struct TopologyContextUnderlay *underlay;
1185 
1186  underlay = &tc->u.underlay;
1187  GNUNET_free_non_null (underlay->link_array);
1188  underlay->link_array = NULL;
1189  }
1190  break;
1191  }
1192  }
1193 }
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:669
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.
enum TopologyContext::@73 type
The type of this context.
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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:208
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:79
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:289
#define GNUNET_YES
Definition: gnunet_common.h:80
struct OverlayLink * link_array
An array of links; this array is of size link_array_size.
union TopologyContext::@74 u
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:1019
#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 1202 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_().

1203 {
1204  unsigned int cnt;
1205  unsigned int offset;
1206  unsigned int neighbour;
1207 
1208  tc->link_array_size = tc->num_peers * (tc->num_peers - 1);
1209  switch (tc->type)
1210  {
1211  case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1212  {
1213  struct TopologyContextOverlay *overlay;
1214 
1215  overlay = &tc->u.overlay;
1217  struct OverlayLink);
1218  }
1219  break;
1220  case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1221  {
1222  struct TopologyContextUnderlay *underlay;
1223 
1224  underlay = &tc->u.underlay;
1225  underlay->link_array = GNUNET_new_array (tc->link_array_size,
1226  struct UnderlayLink);
1227  }
1228  }
1229  offset = 0;
1230  for (cnt = 0; cnt < tc->num_peers; cnt++)
1231  {
1232  for (neighbour = 0; neighbour < tc->num_peers; neighbour++)
1233  {
1234  if (neighbour == cnt)
1235  continue;
1236  make_link (offset, cnt, neighbour, tc);
1237  offset++;
1238  }
1239  }
1240 }
struct TopologyContextOverlay overlay
Topology context information for overlay topology.
unsigned int num_peers
The number of peers.
struct UnderlayLink * link_array
The link array.
enum TopologyContext::@73 type
The type of this context.
unsigned int link_array_size
The size of the link array.
#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.
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.
union TopologyContext::@74 u
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 1485 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().

1487 {
1488  unsigned int cnt;
1489 
1490  for (cnt = 0; NULL != topology_strings[cnt]; cnt++)
1491  {
1492  if (0 == strcasecmp (topology_string, topology_strings[cnt]))
1493  {
1494  if (NULL != topology)
1497  return GNUNET_YES;
1498  }
1499  }
1500  return GNUNET_NO;
1501 }
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:81
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:80
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 1512 of file testbed_api_topology.c.

References GNUNET_strdup, GNUNET_TESTBED_TOPOLOGY_OPTION_END, and topology_strings.

1513 {
1515  return NULL;
1517 }
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 1537 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().

1541 {
1542  struct TopologyContext tc;
1543  struct TopologyContextUnderlay *underlay;
1544  struct UnderlayLink *ulink;
1545  va_list vargs;
1547  unsigned int cnt;
1548  int ret;
1549 
1550  GNUNET_assert (NULL != proc);
1551  ret = GNUNET_OK;
1552  memset (&tc, 0, sizeof (tc));
1553  tc.num_peers = num_peers;
1554  tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY;
1555  underlay = &tc.u.underlay;
1556  va_start (vargs, cls);
1558  switch (topology)
1559  {
1561  gen_topo_line (&tc);
1562  break;
1564  gen_topo_star (&tc);
1565  break;
1567  gen_topo_ring (&tc);
1568  break;
1570  gen_topo_clique (&tc);
1571  break;
1573  gen_topo_2dtorus (&tc);
1574  break;
1576  gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_NO);
1577  break;
1579  gen_topo_ring (&tc);
1580  gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES);
1581  break;
1583  gen_topo_2dtorus (&tc);
1584  gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES);
1585  break;
1587  {
1588  const char *filename;
1589  filename = va_arg (vargs, char *);
1590  GNUNET_assert (NULL != filename);
1591  gen_topo_from_file (&tc, filename);
1592  }
1593  break;
1595  {
1596  uint16_t cap;
1597  uint8_t m;
1598  cap = (uint16_t) va_arg (vargs, unsigned int);
1599  m = (uint8_t) va_arg (vargs, unsigned int);
1600  gen_topo_scale_free (&tc, cap, m);
1601  }
1602  break;
1603  default:
1604  GNUNET_assert (0);
1605  }
1606  va_end (vargs);
1607  for (cnt = 0; cnt < tc.link_array_size; cnt++)
1608  {
1609  ulink = &underlay->link_array[cnt];
1610  if (GNUNET_SYSERR == proc (cls,
1611  ulink->A,
1612  ulink->B,
1613  ulink->bandwidth,
1614  ulink->latency,
1615  ulink->loss))
1616  {
1617  ret = GNUNET_SYSERR;
1618  break;
1619  }
1620  }
1621  GNUNET_free_non_null (underlay->link_array);
1622  return ret;
1623 }
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:417
struct UnderlayLink * link_array
The link array.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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 int ret
Final status code.
Definition: gnunet-arm.c:89
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:99
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:79
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:80
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 263 of file testbed_api_topology.c.

Referenced by GNUNET_TESTBED_topology_get_(), and GNUNET_TESTBED_topology_to_str_().