GNUnet  0.20.0
testbed_api_topology.h File Reference

header for intra library exported functions More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef int(* underlay_link_processor) (void *cls, unsigned int A, unsigned int B, unsigned int bandwidth, unsigned int latency, unsigned int loss)
 Functions of this type are called to process underlay link. More...
 

Functions

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...
 
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...
 

Detailed Description

header for intra library exported functions

Author
Sree Harsha Totakura sreeh.nosp@m.arsh.nosp@m.a@tot.nosp@m.akur.nosp@m.a.in

Definition in file testbed_api_topology.h.

Typedef Documentation

◆ underlay_link_processor

typedef int(* underlay_link_processor) (void *cls, unsigned int A, unsigned int B, unsigned int bandwidth, unsigned int latency, unsigned int loss)

Functions of this type are called to process underlay link.

Parameters
clsclosure
Aoffset of first peer
Boffset of second peer
bandwidththe bandwidth of the link in bytes per second
latencythe latency of link in milliseconds
lossthe percentage of messages dropped on the link
Returns
GNUNET_OK to continue processing; GNUNET_SYSERR to abort

Definition at line 83 of file testbed_api_topology.h.

Function Documentation

◆ 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 arrangement (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 641 of file testbed_api_topology.c.

643 {
644  double sq;
645  unsigned int sq_floor;
646  unsigned int _rows;
647  unsigned int *_rows_len;
648  unsigned int x;
649  unsigned int y;
650  unsigned int _num_peers;
651  unsigned int cnt;
652 
653  sq = sqrt (num_peers);
654  sq = floor (sq);
655  sq_floor = (unsigned int) sq;
656  _rows = (sq_floor + 1);
657  _rows_len = GNUNET_malloc (sizeof(unsigned int) * _rows);
658  for (y = 0; y < _rows - 1; y++)
659  _rows_len[y] = sq_floor;
660  _num_peers = sq_floor * sq_floor;
661  cnt = (_num_peers < 2) ? _num_peers : 2 * _num_peers;
662  x = 0;
663  y = 0;
664  while (_num_peers < num_peers)
665  {
666  if (x < y)
667  _rows_len[_rows - 1] = ++x;
668  else
669  _rows_len[y++]++;
670  _num_peers++;
671  }
672  cnt += (x < 2) ? x : 2 * x;
673  cnt += (y < 2) ? y : 2 * y;
674  if (0 == _rows_len[_rows - 1])
675  _rows--;
676  if (NULL != rows)
677  *rows = _rows;
678  if (NULL != rows_len)
679  *rows_len = _rows_len;
680  else
681  GNUNET_free (_rows_len);
682  return cnt;
683 }
static unsigned int num_peers
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_free, GNUNET_malloc, consensus-simulation::int, and num_peers.

Referenced by gen_topo_2dtorus().

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 1446 of file testbed_api_topology.c.

1448 {
1449  unsigned int cnt;
1450 
1451  for (cnt = 0; NULL != topology_strings[cnt]; cnt++)
1452  {
1453  if (0 == strcasecmp (topology_string, topology_strings[cnt]))
1454  {
1455  if (NULL != topology)
1458  (enum GNUNET_TESTBED_TopologyOption) cnt);
1459  return GNUNET_YES;
1460  }
1461  }
1462  return GNUNET_NO;
1463 }
enum GNUNET_TESTBED_TopologyOption topology
The topology to generate.
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
GNUNET_TESTBED_TopologyOption
Topologies and topology options supported for testbeds.
@ GNUNET_TESTBED_TOPOLOGY_OPTION_END
The options should always end with this.
static const char * topology_strings[]
A array of names representing topologies.

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

Referenced by GNUNET_TESTBED_run(), and run().

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 1474 of file testbed_api_topology.c.

1475 {
1477  return NULL;
1479 }
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

References GNUNET_strdup, GNUNET_TESTBED_TOPOLOGY_OPTION_END, topology, and topology_strings.

◆ 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. These arguments should always end with GNUNET_TESTBED_TOPOLOGY_OPTION_END option
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
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 1499 of file testbed_api_topology.c.

1503 {
1504  struct TopologyContext tc;
1505  struct TopologyContextUnderlay *underlay;
1506  struct UnderlayLink *ulink;
1507  va_list vargs;
1509  unsigned int cnt;
1510  int ret;
1511 
1512  GNUNET_assert (NULL != proc);
1513  ret = GNUNET_OK;
1514  memset (&tc, 0, sizeof(tc));
1515  tc.num_peers = num_peers;
1516  tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY;
1517  underlay = &tc.u.underlay;
1518  va_start (vargs, cls);
1520  switch (topology)
1521  {
1523  gen_topo_line (&tc);
1524  break;
1525 
1527  gen_topo_star (&tc);
1528  break;
1529 
1531  gen_topo_ring (&tc);
1532  break;
1533 
1535  gen_topo_clique (&tc);
1536  break;
1537 
1539  gen_topo_2dtorus (&tc);
1540  break;
1541 
1543  gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_NO);
1544  break;
1545 
1547  gen_topo_ring (&tc);
1548  gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES);
1549  break;
1550 
1552  gen_topo_2dtorus (&tc);
1553  gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES);
1554  break;
1555 
1557  {
1558  const char *filename;
1559  filename = va_arg (vargs, char *);
1560  GNUNET_assert (NULL != filename);
1562  }
1563  break;
1564 
1566  {
1567  uint16_t cap;
1568  uint8_t m;
1569  cap = (uint16_t) va_arg (vargs, unsigned int);
1570  m = (uint8_t) va_arg (vargs, unsigned int);
1571  gen_topo_scale_free (&tc, cap, m);
1572  }
1573  break;
1574 
1575  default:
1576  GNUNET_assert (0);
1577  }
1578  va_end (vargs);
1579  for (cnt = 0; cnt < tc.link_array_size; cnt++)
1580  {
1581  ulink = &underlay->link_array[cnt];
1582  if (GNUNET_SYSERR == proc (cls,
1583  ulink->A,
1584  ulink->B,
1585  ulink->bandwidth,
1586  ulink->latency,
1587  ulink->loss))
1588  {
1589  ret = GNUNET_SYSERR;
1590  break;
1591  }
1592  }
1593  GNUNET_free (underlay->link_array);
1594  return ret;
1595 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static char * filename
#define GNUNET_VA_ARG_ENUM(va, X)
wrap va_arg for enums
@ GNUNET_OK
@ GNUNET_SYSERR
@ GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD
Small-world network (2d torus plus random links).
@ GNUNET_TESTBED_TOPOLOGY_FROM_FILE
Read a topology from a given file.
@ GNUNET_TESTBED_TOPOLOGY_RING
Ring topology.
@ GNUNET_TESTBED_TOPOLOGY_CLIQUE
A clique (everyone connected to everyone else).
@ GNUNET_TESTBED_TOPOLOGY_SCALE_FREE
Scale free topology.
@ GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI
Random graph.
@ GNUNET_TESTBED_TOPOLOGY_STAR
Star topology.
@ GNUNET_TESTBED_TOPOLOGY_2D_TORUS
2-d torus.
@ GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING
Small-world network (ring plus random links).
@ GNUNET_TESTBED_TOPOLOGY_LINE
Straight line topology.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:431
Topology context information for underlay topologies.
struct UnderlayLink * link_array
The link array.
Context information for topology operations.
static void gen_topo_scale_free(struct TopologyContext *tc, uint16_t cap, uint8_t m)
Generates scale free network.
static void gen_topo_line(struct TopologyContext *tc)
Generates line topology.
static void gen_topo_star(struct TopologyContext *tc)
Generates star topology.
static void gen_topo_from_file(struct TopologyContext *tc, const char *filename)
Generates topology from the given file.
static void gen_topo_clique(struct TopologyContext *tc)
Generates clique topology.
static void gen_topo_random(struct TopologyContext *tc, unsigned int links, int append)
Generates ring topology.
static void gen_topo_2dtorus(struct TopologyContext *tc)
Generates ring topology.
static void gen_topo_ring(struct TopologyContext *tc)
Generates ring topology.

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, 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, UnderlayLink::loss, m, num_peers, ret, tc, and topology.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function: