GNUnet  0.11.x
Typedefs | Functions
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 81 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 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.

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:

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