GNUnet  0.10.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 645 of file testbed_api_topology.c.

References GNUNET_free, and GNUNET_malloc.

Referenced by gen_topo_2dtorus().

647 {
648  double sq;
649  unsigned int sq_floor;
650  unsigned int _rows;
651  unsigned int *_rows_len;
652  unsigned int x;
653  unsigned int y;
654  unsigned int _num_peers;
655  unsigned int cnt;
656 
657  sq = sqrt(num_peers);
658  sq = floor(sq);
659  sq_floor = (unsigned int)sq;
660  _rows = (sq_floor + 1);
661  _rows_len = GNUNET_malloc(sizeof(unsigned int) * _rows);
662  for (y = 0; y < _rows - 1; y++)
663  _rows_len[y] = sq_floor;
664  _num_peers = sq_floor * sq_floor;
665  cnt = (_num_peers < 2) ? _num_peers : 2 * _num_peers;
666  x = 0;
667  y = 0;
668  while (_num_peers < num_peers)
669  {
670  if (x < y)
671  _rows_len[_rows - 1] = ++x;
672  else
673  _rows_len[y++]++;
674  _num_peers++;
675  }
676  cnt += (x < 2) ? x : 2 * x;
677  cnt += (y < 2) ? y : 2 * y;
678  if (0 == _rows_len[_rows - 1])
679  _rows--;
680  if (NULL != rows)
681  *rows = _rows;
682  if (NULL != rows_len)
683  *rows_len = _rows_len;
684  else
685  GNUNET_free(_rows_len);
686  return cnt;
687 }
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 1493 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().

1495 {
1496  unsigned int cnt;
1497 
1498  for (cnt = 0; NULL != topology_strings[cnt]; cnt++)
1499  {
1500  if (0 == strcasecmp(topology_string, topology_strings[cnt]))
1501  {
1502  if (NULL != topology)
1505  return GNUNET_YES;
1506  }
1507  }
1508  return GNUNET_NO;
1509 }
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 1520 of file testbed_api_topology.c.

References GNUNET_strdup, GNUNET_TESTBED_TOPOLOGY_OPTION_END, and topology_strings.

1521 {
1523  return NULL;
1525 }
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 1545 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().

1549 {
1550  struct TopologyContext tc;
1551  struct TopologyContextUnderlay *underlay;
1552  struct UnderlayLink *ulink;
1553  va_list vargs;
1555  unsigned int cnt;
1556  int ret;
1557 
1558  GNUNET_assert(NULL != proc);
1559  ret = GNUNET_OK;
1560  memset(&tc, 0, sizeof(tc));
1561  tc.num_peers = num_peers;
1562  tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY;
1563  underlay = &tc.u.underlay;
1564  va_start(vargs, cls);
1566  switch (topology)
1567  {
1569  gen_topo_line(&tc);
1570  break;
1571 
1573  gen_topo_star(&tc);
1574  break;
1575 
1577  gen_topo_ring(&tc);
1578  break;
1579 
1581  gen_topo_clique(&tc);
1582  break;
1583 
1585  gen_topo_2dtorus(&tc);
1586  break;
1587 
1589  gen_topo_random(&tc, va_arg(vargs, unsigned int), GNUNET_NO);
1590  break;
1591 
1593  gen_topo_ring(&tc);
1594  gen_topo_random(&tc, va_arg(vargs, unsigned int), GNUNET_YES);
1595  break;
1596 
1598  gen_topo_2dtorus(&tc);
1599  gen_topo_random(&tc, va_arg(vargs, unsigned int), GNUNET_YES);
1600  break;
1601 
1603  {
1604  const char *filename;
1605  filename = va_arg(vargs, char *);
1606  GNUNET_assert(NULL != filename);
1607  gen_topo_from_file(&tc, filename);
1608  }
1609  break;
1610 
1612  {
1613  uint16_t cap;
1614  uint8_t m;
1615  cap = (uint16_t)va_arg(vargs, unsigned int);
1616  m = (uint8_t)va_arg(vargs, unsigned int);
1617  gen_topo_scale_free(&tc, cap, m);
1618  }
1619  break;
1620 
1621  default:
1622  GNUNET_assert(0);
1623  }
1624  va_end(vargs);
1625  for (cnt = 0; cnt < tc.link_array_size; cnt++)
1626  {
1627  ulink = &underlay->link_array[cnt];
1628  if (GNUNET_SYSERR == proc(cls,
1629  ulink->A,
1630  ulink->B,
1631  ulink->bandwidth,
1632  ulink->latency,
1633  ulink->loss))
1634  {
1635  ret = GNUNET_SYSERR;
1636  break;
1637  }
1638  }
1639  GNUNET_free_non_null(underlay->link_array);
1640  return ret;
1641 }
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:410
struct UnderlayLink * link_array
The link array.
#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 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: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: