testbed_api_topology.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2008--2013 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file testbed/testbed_api_topology.h
  18. * @brief header for intra library exported functions
  19. * @author Sree Harsha Totakura <sreeharsha@totakura.in>
  20. */
  21. #ifndef TESTBED_API_TOPOLOGY_H
  22. #define TESTBED_API_TOPOLOGY_H
  23. /**
  24. * Returns the number of links that are required to generate a 2d torus for the
  25. * given number of peers. Also returns the arrangment (number of rows and the
  26. * length of each row)
  27. *
  28. * @param num_peers number of peers
  29. * @param rows number of rows in the 2d torus. Can be NULL.
  30. * @param rows_len the length of each row. This array will be allocated
  31. * fresh. The caller should free it. Can be NULL.
  32. */
  33. unsigned int
  34. GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows,
  35. unsigned int **rows_len);
  36. /**
  37. * Get a topology from a string input.
  38. *
  39. * @param topology where to write the retrieved topology
  40. * @param topology_string The string to attempt to
  41. * get a configuration value from
  42. * @return GNUNET_YES if topology string matched a
  43. * known topology, GNUNET_NO if not
  44. */
  45. int
  46. GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology,
  47. const char *topology_string);
  48. /**
  49. * Returns the string corresponding to the given topology
  50. *
  51. * @param topology the topology
  52. * @return the string (freshly allocated) of given topology; NULL if topology cannot be
  53. * expressed as a string
  54. */
  55. char *
  56. GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology);
  57. /**
  58. * Functions of this type are called to process underlay link
  59. *
  60. * @param cls closure
  61. * @param A offset of first peer
  62. * @param B offset of second peer
  63. * @param bandwidth the bandwidth of the link in bytes per second
  64. * @param latency the latency of link in milliseconds
  65. * @param loss the percentage of messages dropped on the link
  66. * @return GNUNET_OK to continue processing; GNUNET_SYSERR to abort
  67. */
  68. typedef int (*underlay_link_processor) (void *cls,
  69. unsigned int A,
  70. unsigned int B,
  71. unsigned int bandwidth,
  72. unsigned int latency,
  73. unsigned int loss);
  74. /**
  75. * Function to construct an underlay topology
  76. *
  77. * @param num_peers the number of peers for which the topology should be
  78. * generated
  79. * @param proc the underlay link processor callback. Will be called for each
  80. * underlay link generated unless a previous call to this callback
  81. * returned GNUNET_SYSERR. Cannot be NULL.
  82. * @param cls closure for proc
  83. * @param ... variable arguments denoting the topology and its parameters. They
  84. * should start with the type of topology to generate followed by their
  85. * options. These arguments should *always* end with
  86. * GNUNET_TESTBED_TOPOLOGY_OPTION_END option
  87. * @return GNUNET_OK if underlay link generation is successful; GNUNET_SYSERR
  88. * upon error in generating the underlay or if any calls to the
  89. * underlay link processor returned GNUNET_SYSERR
  90. */
  91. int
  92. GNUNET_TESTBED_underlay_construct_ (int num_peers,
  93. underlay_link_processor proc,
  94. void *cls,
  95. ...);
  96. #endif
  97. /* end of testbed_api_topology.h */