[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25027 - gnunet/src/testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25027 - gnunet/src/testbed |
Date: |
Fri, 16 Nov 2012 18:32:37 +0100 |
Author: harsha
Date: 2012-11-16 18:32:37 +0100 (Fri, 16 Nov 2012)
New Revision: 25027
Added:
gnunet/src/testbed/testbed_api_topology.h
Modified:
gnunet/src/testbed/Makefile.am
gnunet/src/testbed/testbed_api_testbed.c
gnunet/src/testbed/testbed_api_topology.c
Log:
- de-duplication
Modified: gnunet/src/testbed/Makefile.am
===================================================================
--- gnunet/src/testbed/Makefile.am 2012-11-16 17:32:14 UTC (rev 25026)
+++ gnunet/src/testbed/Makefile.am 2012-11-16 17:32:37 UTC (rev 25027)
@@ -65,7 +65,7 @@
testbed_api_statistics.c \
testbed_api_testbed.c \
testbed_api_test.c \
- testbed_api_topology.c
+ testbed_api_topology.c testbed_api_topology.h
libgnunettestbed_la_LIBADD = $(XLIB) \
$(top_builddir)/src/core/libgnunetcore.la \
$(top_builddir)/src/statistics/libgnunetstatistics.la \
Modified: gnunet/src/testbed/testbed_api_testbed.c
===================================================================
--- gnunet/src/testbed/testbed_api_testbed.c 2012-11-16 17:32:14 UTC (rev
25026)
+++ gnunet/src/testbed/testbed_api_testbed.c 2012-11-16 17:32:37 UTC (rev
25027)
@@ -29,6 +29,7 @@
#include "gnunet_testbed_service.h"
#include "testbed_api_peers.h"
#include "testbed_api_hosts.h"
+#include "testbed_api_topology.h"
/**
* Generic loggins shorthand
@@ -672,38 +673,8 @@
}
else if (0 == strcasecmp (topology, "2D_TORUS"))
{
- double sq;
- unsigned int sq_floor;
- unsigned int rows;
- unsigned int *rows_len;
- unsigned int x;
- unsigned int y;
- unsigned int n;
-
rc->topology = GNUNET_TESTBED_TOPOLOGY_2D_TORUS;
- sq = sqrt ((double) num_peers);
- sq = floor (sq);
- sq_floor = (unsigned int) sq;
- rows = (sq_floor + 1);
- rows_len = GNUNET_malloc (sizeof (unsigned int) * rows);
- for (y = 0; y < rows - 1; y++)
- rows_len[y] = sq_floor;
- n = sq_floor * sq_floor;
- GNUNET_assert (n <= num_peers);
- rc->num_oc = 2 * n;
- x = 0;
- y = 0;
- while (n < num_peers)
- {
- if (x < y)
- rows_len[rows - 1] = ++x;
- else
- rows_len[y++]++;
- n++;
- }
- rc->num_oc += (x < 2) ? x : 2 * x;
- rc->num_oc += (y < 2) ? y : 2 * y;
- GNUNET_free (rows_len);
+ rc->num_oc = GNUNET_TESTBED_2dtorus_calc_links (num_peers, NULL, NULL);
}
else
LOG (GNUNET_ERROR_TYPE_WARNING,
Modified: gnunet/src/testbed/testbed_api_topology.c
===================================================================
--- gnunet/src/testbed/testbed_api_topology.c 2012-11-16 17:32:14 UTC (rev
25026)
+++ gnunet/src/testbed/testbed_api_topology.c 2012-11-16 17:32:37 UTC (rev
25027)
@@ -28,6 +28,7 @@
#include "testbed_api.h"
#include "testbed_api_peers.h"
#include "testbed_api_operations.h"
+#include "testbed_api_topology.h"
/**
* Generic loggins shorthand
@@ -232,49 +233,81 @@
/**
- * Generates ring topology
+ * 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)
*
- * @param tc the topology context
+ * @param num_peers number of peers
+ * @param rows number of rows in the 2d torus. Can be NULL
+ * @param rows_len the length of each row. This array will be allocated
+ * fresh. The caller should free it. Can be NULL
*/
-static void
-gen_topo_2dtorus (struct TopologyContext *tc)
+unsigned int
+GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers,
+ unsigned int *rows,
+ unsigned int **rows_len)
{
double sq;
unsigned int sq_floor;
- unsigned int rows;
- unsigned int *rows_len;
+ unsigned int _rows;
+ unsigned int *_rows_len;
unsigned int x;
unsigned int y;
- unsigned int num_peers;
+ unsigned int _num_peers;
unsigned int cnt;
- unsigned int offset;
-
- sq = sqrt (tc->num_peers);
+
+ sq = sqrt (num_peers);
sq = floor (sq);
sq_floor = (unsigned int) sq;
- rows = (sq_floor + 1);
- rows_len = GNUNET_malloc (sizeof (unsigned int) * rows);
- for (y = 0; y < rows - 1; y++)
- rows_len[y] = sq_floor;
- num_peers = sq_floor * sq_floor;
- GNUNET_assert (num_peers <= tc->num_peers);
- tc->link_array_size = 2 * num_peers;
+ _rows = (sq_floor + 1);
+ _rows_len = GNUNET_malloc (sizeof (unsigned int) * _rows);
+ for (y = 0; y < _rows - 1; y++)
+ _rows_len[y] = sq_floor;
+ _num_peers = sq_floor * sq_floor;
+ cnt = 2 * _num_peers;
x = 0;
y = 0;
- while (num_peers < tc->num_peers)
+ while (_num_peers < num_peers)
{
if (x < y)
- rows_len[rows - 1] = ++x;
+ _rows_len[_rows - 1] = ++x;
else
- rows_len[y++]++;
- num_peers++;
+ _rows_len[y++]++;
+ _num_peers++;
}
- tc->link_array_size += (x < 2) ? x : 2 * x;
- tc->link_array_size += (y < 2) ? y : 2 * y;
+ cnt += (x < 2) ? x : 2 * x;
+ cnt += (y < 2) ? y : 2 * y;
+ if (0 == _rows_len[_rows - 1])
+ _rows--;
+ if (NULL != rows)
+ *rows = _rows;
+ if (NULL != rows_len)
+ *rows_len = _rows_len;
+ else
+ GNUNET_free (_rows_len);
+ return cnt;
+}
+
+
+/**
+ * Generates ring topology
+ *
+ * @param tc the topology context
+ */
+static void
+gen_topo_2dtorus (struct TopologyContext *tc)
+{
+ unsigned int rows;
+ unsigned int *rows_len;
+ unsigned int x;
+ unsigned int y;
+ unsigned int cnt;
+ unsigned int offset;
+
+ tc->link_array_size = GNUNET_TESTBED_2dtorus_calc_links (tc->num_peers,
&rows,
+ &rows_len);
tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink) *
tc->link_array_size);
- if (0 == rows_len[rows - 1])
- rows--;
cnt = 0;
offset = 0;
for (y = 0; y < rows; y++)
Added: gnunet/src/testbed/testbed_api_topology.h
===================================================================
--- gnunet/src/testbed/testbed_api_topology.h (rev 0)
+++ gnunet/src/testbed/testbed_api_topology.h 2012-11-16 17:32:37 UTC (rev
25027)
@@ -0,0 +1,47 @@
+/*
+ This file is part of GNUnet
+ (C) 2008--2012 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * @file testbed/testbed_api_topology.h
+ * @brief header for intra library exported functions
+ * @author Sree Harsha Totakura <address@hidden>
+ */
+
+#ifndef TESTBED_API_TOPOLOGY_H
+#define TESTBED_API_TOPOLOGY_H
+
+/**
+ * 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)
+ *
+ * @param num_peers number of peers
+ * @param rows number of rows in the 2d torus. Can be NULL.
+ * @param rows_len the length of each row. This array will be allocated
+ * fresh. The caller should free it. Can be NULL.
+ */
+unsigned int
+GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers,
+ unsigned int *rows,
+ unsigned int **rows_len);
+
+#endif
+/* end of testbed_api_topology.h */
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25027 - gnunet/src/testbed,
gnunet <=