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

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