- update default values, eliminate obsolete ones
[oweals/gnunet.git] / src / testbed / testbed_api_topology.c
1 /*
2       This file is part of GNUnet
3       (C) 2008--2013 Christian Grothoff (and other contributing authors)
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 3, or (at your
8       option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18       Boston, MA 02111-1307, USA.
19  */
20
21 /**
22  * @file testbed/testbed_api_topology.c
23  * @brief topology-generation functions
24  * @author Christian Grothoff
25  */
26 #include "platform.h"
27 #include "gnunet_testbed_service.h"
28 #include "testbed_api.h"
29 #include "testbed_api_peers.h"
30 #include "testbed_api_operations.h"
31 #include "testbed_api_topology.h"
32
33 /**
34  * Generic loggins shorthand
35  */
36 #define LOG(kind,...)                                           \
37   GNUNET_log_from (kind, "testbed-api-topology", __VA_ARGS__)
38
39
40 /**
41  * Default number of retires
42  */
43 #define DEFAULT_RETRY_CNT 3
44
45
46 /**
47  * Context information for topology operations
48  */
49 struct TopologyContext;
50
51
52 /**
53  * Representation of an overlay link
54  */
55 struct OverlayLink
56 {
57
58   /**
59    * An operation corresponding to this link
60    */
61   struct GNUNET_TESTBED_Operation *op;
62
63   /**
64    * The topology context this link is a part of
65    */
66   struct TopologyContext *tc;
67
68   /**
69    * position of peer A's handle in peers array
70    */
71   uint32_t A;
72
73   /**
74    * position of peer B's handle in peers array
75    */
76   uint32_t B;
77
78 };
79
80
81 /**
82  * Representation of an underlay link
83  */
84 struct UnderlayLink
85 {
86   /**
87    * position of peer A's handle in peers array
88    */
89   uint32_t A;
90
91   /**
92    * position of peer B's handle in peers array
93    */
94   uint32_t B;
95
96   /**
97    * Bandwidth of the link in bytes per second
98    */
99   uint32_t bandwidth;
100
101   /**
102    * Latency of the link in milliseconds
103    */
104   uint32_t latency;
105
106   /**
107    * Loss in the link in percentage of message dropped
108    */
109   uint32_t loss;
110 };
111
112
113 struct RetryListEntry
114 {
115   /**
116    * the next pointer for the DLL
117    */
118   struct RetryListEntry *next;
119
120   /**
121    * the prev pointer for the DLL
122    */
123   struct RetryListEntry *prev;
124
125   /**
126    * The link to be retired
127    */
128   struct OverlayLink *link;
129 };
130
131
132 /**
133  * Context information for overlay topologies
134  */
135 struct TopologyContextOverlay
136 {
137   /**
138    * The array of peers
139    */
140   struct GNUNET_TESTBED_Peer **peers;
141
142   /**
143    * An array of links; this array is of size link_array_size
144    */
145   struct OverlayLink *link_array;
146
147   /**
148    * The operation closure
149    */
150   void *op_cls;
151
152   /**
153    * topology generation completion callback
154    */
155   GNUNET_TESTBED_TopologyCompletionCallback comp_cb;
156
157   /**
158    * The closure for the above callback
159    */
160   void *comp_cb_cls;
161
162   /**
163    * DLL head for retry list
164    */
165   struct RetryListEntry *rl_head;
166
167   /**
168    * DLL tail for retry list
169    */
170   struct RetryListEntry *rl_tail;
171
172   /**
173    * How many retries to do before we give up
174    */
175   unsigned int retry_cnt;
176
177   /**
178    * Number of links to try
179    */
180   unsigned int nlinks;
181
182   /**
183    * How many links have been completed
184    */
185   unsigned int ncompleted;
186
187   /**
188    * Total successfully established overlay connections
189    */
190   unsigned int nsuccess;
191
192   /**
193    * Total failed overlay connections
194    */
195   unsigned int nfailures;
196 };
197
198
199 /**
200  * Topology context information for underlay topologies
201  */
202 struct TopologyContextUnderlay
203 {
204   /**
205    * The link array
206    */
207   struct UnderlayLink *link_array;
208 };
209
210
211 /**
212  * Context information for topology operations
213  */
214 struct TopologyContext
215 {
216   /**
217    * The type of this context
218    */
219   enum {
220     
221     /**
222      * Type for underlay topology
223      */
224     TOPOLOGYCONTEXT_TYPE_UNDERLAY = 0,
225     
226     /**
227      * Type for overlay topology
228      */
229     TOPOLOGYCONTEXT_TYPE_OVERLAY
230
231   } type;
232
233   union {
234
235     /**
236      * Topology context information for overlay topology
237      */
238     struct TopologyContextOverlay overlay;
239
240     /**
241      * Topology context information for underlay topology
242      */
243     struct TopologyContextUnderlay underlay;
244   } u;
245
246   /**
247    * The number of peers
248    */
249   unsigned int num_peers;
250
251   /**
252    * The size of the link array
253    */
254   unsigned int link_array_size;
255
256 };
257
258
259 /**
260  * A array of names representing topologies. Should be in sync with enum
261  * GNUNET_TESTBED_TopologyOption
262  */
263 const char *topology_strings[] = {
264
265     /**
266      * A clique (everyone connected to everyone else).  No options. If there are N
267      * peers this topology results in (N * (N -1)) connections.
268      */
269   "CLIQUE",
270
271     /**
272      * Small-world network (2d torus plus random links).  Followed
273      * by the number of random links to add (unsigned int).
274      */
275   "SMALL_WORLD",
276
277     /**
278      * Small-world network (ring plus random links).  Followed
279      * by the number of random links to add (unsigned int).
280      */
281   "SMALL_WORLD_RING",
282
283     /**
284      * Ring topology.  No options.
285      */
286   "RING",
287
288     /**
289      * 2-d torus.  No options.
290      */
291   "2D_TORUS",
292
293     /**
294      * Random graph.  Followed by the number of random links to be established
295      * (unsigned int)
296      */
297   "RANDOM",                     // GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI
298
299     /**
300      * Certain percentage of peers are unable to communicate directly
301      * replicating NAT conditions.  Followed by the fraction of
302      * NAT'ed peers (float).
303      */
304   "INTERNAT",
305
306     /**
307      * Scale free topology. Followed by the maximum number of links a node can
308      * have (unsigned int); and the number of links a new node should have when
309      * it is added to the network (unsigned int)
310      */
311   "SCALE_FREE",
312
313     /**
314      * Straight line topology.  No options.
315      */
316   "LINE",
317
318     /**
319      * Read a topology from a given file.  Followed by the name of the file (const char *).
320      */
321   "FROM_FILE",
322
323     /**
324      * All peers are disconnected.  No options.
325      */
326   "NONE",
327
328     /**
329      * End of strings
330      */
331   NULL
332 };
333
334
335 /**
336  * Callback to be called when an overlay_link operation complete
337  *
338  * @param cls element of the link_op array which points to the corresponding operation
339  * @param op the operation that has been finished
340  * @param emsg error message in case the operation has failed; will be NULL if
341  *          operation has executed successfully.
342  */
343 static void
344 overlay_link_completed (void *cls, struct GNUNET_TESTBED_Operation *op,
345                         const char *emsg)
346 {
347   struct OverlayLink *link = cls;
348   struct TopologyContext *tc;
349   struct TopologyContextOverlay *overlay;
350   struct RetryListEntry *retry_entry;
351
352   GNUNET_assert (op == link->op);
353   GNUNET_TESTBED_operation_done (op);
354   link->op = NULL;
355   tc = link->tc;
356   GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type);
357   overlay = &tc->u.overlay;
358   if (NULL != emsg)
359   {
360     overlay->nfailures++;
361     if (0 != overlay->retry_cnt)
362     {
363       LOG (GNUNET_ERROR_TYPE_WARNING,
364            "Error while establishing a link: %s -- Retrying\n", emsg);
365       retry_entry = GNUNET_new (struct RetryListEntry);
366       retry_entry->link = link;
367       GNUNET_CONTAINER_DLL_insert_tail (overlay->rl_head, overlay->rl_tail, retry_entry);
368     }
369   }
370   else
371     overlay->nsuccess++;
372   overlay->ncompleted++;
373   if (overlay->ncompleted < overlay->nlinks)
374     return;
375   if ((0 != overlay->retry_cnt) && (NULL != overlay->rl_head))
376   {
377     overlay->retry_cnt--;
378     overlay->ncompleted = 0;
379     overlay->nlinks = 0;
380     while (NULL != (retry_entry = overlay->rl_head))
381     {
382       link = retry_entry->link;
383       link->op =
384           GNUNET_TESTBED_overlay_connect (overlay->op_cls, &overlay_link_completed,
385                                           link, overlay->peers[link->A],
386                                           overlay->peers[link->B]);
387       overlay->nlinks++;
388       GNUNET_CONTAINER_DLL_remove (overlay->rl_head, overlay->rl_tail, retry_entry);
389       GNUNET_free (retry_entry);
390     }
391     return;
392   }
393   if (NULL != overlay->comp_cb)
394   {
395     overlay->comp_cb (overlay->comp_cb_cls, overlay->nsuccess, overlay->nfailures);
396   }
397 }
398
399
400
401 /**
402  * Function called when a overlay connect operation is ready
403  *
404  * @param cls the Topology context
405  */
406 static void
407 opstart_overlay_configure_topology (void *cls)
408 {
409   struct TopologyContext *tc = cls;
410   struct TopologyContextOverlay *overlay;
411   unsigned int p;
412
413   GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type);
414   overlay = &tc->u.overlay;
415   overlay->nlinks = tc->link_array_size;
416   for (p = 0; p < tc->link_array_size; p++)
417   {
418     overlay->link_array[p].op =
419         GNUNET_TESTBED_overlay_connect (overlay->op_cls, &overlay_link_completed,
420                                         &overlay->link_array[p],
421                                         overlay->peers[overlay->link_array[p].A],
422                                         overlay->peers[overlay->link_array[p].B]);
423   }
424 }
425
426
427 /**
428  * Callback which will be called when overlay connect operation is released
429  *
430  * @param cls the Topology context
431  */
432 static void
433 oprelease_overlay_configure_topology (void *cls)
434 {
435   struct TopologyContext *tc = cls;
436   struct TopologyContextOverlay *overlay;
437   struct RetryListEntry *retry_entry;
438   unsigned int p;
439
440   GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type);
441   overlay = &tc->u.overlay;
442   while (NULL != (retry_entry = overlay->rl_head))
443   {
444     GNUNET_CONTAINER_DLL_remove (overlay->rl_head, overlay->rl_tail, retry_entry);
445     GNUNET_free (retry_entry);
446   }
447   if (NULL != overlay->link_array)
448   {
449     for (p = 0; p < tc->link_array_size; p++)
450       if (NULL != overlay->link_array[p].op)
451         GNUNET_TESTBED_operation_done (overlay->link_array[p].op);
452     GNUNET_free (overlay->link_array);
453   }
454   GNUNET_free (tc);
455 }
456
457
458 /**
459  * Populates the OverlayLink structure.
460  *
461  * @param offset the offset of the link array to use
462  * @param A the peer A. Should be different from B
463  * @param B the peer B. Should be different from A
464  * @param tc the TopologyContext
465  * @return
466  */
467 static void
468 make_link (unsigned int offset, uint32_t A, uint32_t B,
469            struct TopologyContext *tc)
470 {
471   GNUNET_assert (A != B);
472   switch (tc->type)
473   {
474   case TOPOLOGYCONTEXT_TYPE_OVERLAY:
475     {
476       struct TopologyContextOverlay *overlay;
477       struct OverlayLink *olink;
478       
479       overlay = &tc->u.overlay;
480       GNUNET_assert (offset < tc->link_array_size);
481       olink = &overlay->link_array[offset];
482       LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %u to %u\n", B, A);
483       olink->A = A;
484       olink->B = B;
485       olink->op = NULL;
486       olink->tc = tc;
487     }
488     break;
489   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
490     {
491       struct TopologyContextUnderlay *underlay;
492       struct UnderlayLink *ulink;
493       
494       underlay = &tc->u.underlay;
495       GNUNET_assert (offset < tc->link_array_size);
496       ulink = &underlay->link_array[offset];
497       ulink->A = A;
498       ulink->B = B;
499     }
500     break;
501   }
502 }
503
504
505 /**
506  * Generates line topology
507  *
508  * @param tc the topology context
509  */
510 static void
511 gen_topo_line (struct TopologyContext *tc)
512 {
513   unsigned int cnt;
514
515   tc->link_array_size = tc->num_peers - 1;
516   switch (tc->type)
517   {
518   case TOPOLOGYCONTEXT_TYPE_OVERLAY:
519     {
520       struct TopologyContextOverlay *overlay;
521       
522       overlay = &tc->u.overlay;
523       overlay->link_array =
524           GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size);
525     }
526     break;
527   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
528     {
529       struct TopologyContextUnderlay *underlay;
530       
531       underlay = &tc->u.underlay;
532       underlay->link_array =
533           GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size);
534     }
535     break;
536   }
537   for (cnt = 0; cnt < (tc->link_array_size); cnt++)
538     make_link (cnt, cnt, cnt + 1, tc);
539 }
540
541
542 /**
543  * Generates ring topology
544  *
545  * @param tc the topology context
546  */
547 static void
548 gen_topo_ring (struct TopologyContext *tc)
549 {
550   gen_topo_line (tc);
551   tc->link_array_size++;
552   switch (tc->type)
553   {
554   case TOPOLOGYCONTEXT_TYPE_OVERLAY:
555     {
556       struct TopologyContextOverlay *overlay;
557
558       overlay = &tc->u.overlay;
559       overlay->link_array =
560           GNUNET_realloc (overlay->link_array, sizeof (struct OverlayLink) *
561                           tc->link_array_size);
562     }
563     break;
564   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
565     {
566       struct TopologyContextUnderlay *underlay;
567       
568       underlay = &tc->u.underlay;
569       underlay->link_array =
570           GNUNET_realloc (underlay->link_array, sizeof (struct UnderlayLink) *
571       tc->link_array_size);
572     }
573     break;
574   }
575   make_link (tc->link_array_size - 1, tc->num_peers - 1, 0, tc);
576 }
577
578
579 /**
580  * Returns the number of links that are required to generate a 2d torus for the
581  * given number of peers. Also returns the arrangment (number of rows and the
582  * length of each row)
583  *
584  * @param num_peers number of peers
585  * @param rows number of rows in the 2d torus. Can be NULL
586  * @param rows_len the length of each row. This array will be allocated
587  *          fresh. The caller should free it. Can be NULL
588  * @return the number of links that are required to generate a 2d torus for the
589  *           given number of peers
590  */
591 unsigned int
592 GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows,
593                                    unsigned int **rows_len)
594 {
595   double sq;
596   unsigned int sq_floor;
597   unsigned int _rows;
598   unsigned int *_rows_len;
599   unsigned int x;
600   unsigned int y;
601   unsigned int _num_peers;
602   unsigned int cnt;
603
604   sq = sqrt (num_peers);
605   sq = floor (sq);
606   sq_floor = (unsigned int) sq;
607   _rows = (sq_floor + 1);
608   _rows_len = GNUNET_malloc (sizeof (unsigned int) * _rows);
609   for (y = 0; y < _rows - 1; y++)
610     _rows_len[y] = sq_floor;
611   _num_peers = sq_floor * sq_floor;
612   cnt = (_num_peers < 2) ? _num_peers : 2 * _num_peers;
613   x = 0;
614   y = 0;
615   while (_num_peers < num_peers)
616   {
617     if (x < y)
618       _rows_len[_rows - 1] = ++x;
619     else
620       _rows_len[y++]++;
621     _num_peers++;
622   }
623   cnt += (x < 2) ? x : 2 * x;
624   cnt += (y < 2) ? y : 2 * y;
625   if (0 == _rows_len[_rows - 1])
626     _rows--;
627   if (NULL != rows)
628     *rows = _rows;
629   if (NULL != rows_len)
630     *rows_len = _rows_len;
631   else
632     GNUNET_free (_rows_len);
633   return cnt;
634 }
635
636
637 /**
638  * Generates ring topology
639  *
640  * @param tc the topology context
641  */
642 static void
643 gen_topo_2dtorus (struct TopologyContext *tc)
644 {
645   unsigned int rows;
646   unsigned int *rows_len;
647   unsigned int x;
648   unsigned int y;
649   unsigned int cnt;
650   unsigned int offset;
651
652   tc->link_array_size =
653       GNUNET_TESTBED_2dtorus_calc_links (tc->num_peers, &rows, &rows_len);
654   switch (tc->type)
655   {
656   case TOPOLOGYCONTEXT_TYPE_OVERLAY:
657     {
658       struct TopologyContextOverlay *overlay;
659       
660       overlay = &tc->u.overlay;
661       overlay->link_array =
662           GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size);
663     }
664     break;
665   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
666     {
667       struct TopologyContextUnderlay *underlay;
668
669       underlay = &tc->u.underlay;
670       underlay->link_array =
671           GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size);
672       break;
673     }
674   }
675   cnt = 0;
676   offset = 0;
677   for (y = 0; y < rows; y++)
678   {
679     for (x = 0; x < rows_len[y] - 1; x++)
680     {
681       make_link (cnt, offset + x, offset + x + 1, tc);
682       cnt++;
683     }
684     if (0 == x)
685       break;
686     make_link (cnt, offset + x, offset, tc);
687     cnt++;
688     offset += rows_len[y];
689   }
690   for (x = 0; x < rows_len[0]; x++)
691   {
692     offset = 0;
693     for (y = 0; y < rows - 1; y++)
694     {
695       if (x >= rows_len[y + 1])
696         break;
697       GNUNET_assert (x < rows_len[y + 1]);
698       make_link (cnt, offset + x, offset + rows_len[y] + x, tc);
699       offset += rows_len[y];
700       cnt++;
701     }
702     if (0 == offset)
703       break;
704     make_link (cnt, offset + x, x, tc);
705     cnt++;
706   }
707   GNUNET_assert (cnt == tc->link_array_size);
708   GNUNET_free (rows_len);
709 }
710
711
712 /**
713  * Generates ring topology
714  *
715  * @param tc the topology context
716  * @param links the number of random links to establish
717  * @param append GNUNET_YES to add links to existing link array; GNUNET_NO to
718  *          create a new link array
719  */
720 static void
721 gen_topo_random (struct TopologyContext *tc, unsigned int links, int append)
722 {
723   unsigned int cnt;
724   unsigned int index;
725   uint32_t A_rand;
726   uint32_t B_rand;
727
728   if (1 == tc->num_peers)
729     return;
730   if (GNUNET_YES == append)
731   {
732     index = tc->link_array_size;
733     tc->link_array_size += links;
734   }
735   else
736   {
737     index = 0;
738     tc->link_array_size = links;
739   }
740   switch (tc->type)
741   {
742   case TOPOLOGYCONTEXT_TYPE_OVERLAY:
743     {
744       struct TopologyContextOverlay *overlay;
745
746       overlay = &tc->u.overlay;
747       if (GNUNET_YES != append)
748       {
749         GNUNET_assert (NULL == overlay->link_array);
750         overlay->link_array =
751             GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size);
752         break;
753       }
754       GNUNET_assert ((0 < tc->link_array_size) && (NULL != overlay->link_array));
755       overlay->link_array =
756           GNUNET_realloc (overlay->link_array,
757                           sizeof (struct OverlayLink) * tc->link_array_size);
758       break;
759     }
760   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
761     {
762       struct TopologyContextUnderlay *underlay;
763
764       underlay = &tc->u.underlay;
765       if (GNUNET_YES != append)
766       {
767         GNUNET_assert (NULL == underlay->link_array);
768         underlay->link_array =
769             GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size);
770         break;
771       }
772       GNUNET_assert ((0 < tc->link_array_size) && (NULL != underlay->link_array));
773       underlay->link_array =
774           GNUNET_realloc (underlay->link_array,
775                           sizeof (struct UnderlayLink) * tc->link_array_size);
776       break;
777     }
778   }
779   for (cnt = 0; cnt < links; cnt++)
780   {
781     do
782     {
783       A_rand =
784           GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers);
785       B_rand =
786           GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers);
787     }
788     while (A_rand == B_rand);
789     make_link (index+cnt, A_rand, B_rand, tc);
790   }
791 }
792
793
794 /**
795  * Generates scale free network. Its construction is described in:
796  *
797  * "Emergence of Scaling in Random Networks." Science 286, 509-512, 1999.
798  *
799  * @param tc the topology context
800  * @param cap maximum allowed node degree
801  * @param m number of edges to establish for a new node when it is added to the
802  *   network
803  */
804 static void
805 gen_topo_scale_free (struct TopologyContext *tc, uint16_t cap, uint8_t m)
806 {
807   unsigned int *deg;
808   unsigned int *etab;
809   unsigned int *used;
810   unsigned int etaboff;
811   unsigned int cnt;
812   unsigned int cnt2;
813   unsigned int peer;
814   unsigned int random_peer;
815   unsigned int links;
816   unsigned int off;
817   unsigned int redo_threshold;
818
819   etaboff = 0;
820   tc->link_array_size = tc->num_peers * m;
821   switch (tc->type)
822   {
823   case TOPOLOGYCONTEXT_TYPE_OVERLAY:
824     {
825       struct TopologyContextOverlay *overlay;
826
827       overlay = &tc->u.overlay;
828       overlay->link_array = GNUNET_malloc_large (sizeof (struct OverlayLink) *
829                                                  tc->link_array_size);
830     }
831     break;
832   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
833     {
834       struct TopologyContextUnderlay *underlay;
835
836       underlay = &tc->u.underlay;
837       underlay->link_array = GNUNET_malloc_large (sizeof (struct UnderlayLink) *
838                                                   tc->link_array_size);
839     }
840     break;
841   }
842   etab = GNUNET_malloc_large (sizeof (unsigned int) * 2 * tc->link_array_size);
843   deg = GNUNET_malloc (sizeof (unsigned int) * tc->num_peers);
844   used = GNUNET_malloc (sizeof (unsigned int) * m);
845   /* start by connecting peer 1 to peer 0 */
846   make_link (0, 0, 1, tc);
847   deg[0]++;
848   deg[1]++;
849   etab[etaboff++] = 0;
850   etab[etaboff++] = 1;
851   links = 1;
852   for (peer = 2; peer < tc->num_peers; peer++)
853   {
854     if (cap < deg[peer])
855       continue;
856     for (cnt = 0; cnt < GNUNET_MIN (peer, m); cnt++)
857     {
858       redo_threshold = 0;
859     redo:
860       off = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, etaboff);
861       random_peer = etab[off];
862       if (cap < deg[random_peer])
863       {
864         if (++redo_threshold > GNUNET_MAX (1, cap / 2))
865         {
866           redo_threshold = 0;
867           off = 0;
868           for (cnt2 = 0; cnt2 < etaboff; cnt2++)
869           {
870             if (random_peer == etab[cnt2])
871             {
872               off++;
873               continue;
874             }
875             etab[cnt2 - off] = etab[cnt2];
876           }
877           etaboff -= off;
878         }
879         goto redo;
880       }
881       for (cnt2 = 0; cnt2 < cnt; cnt2++)
882         if (random_peer == used[cnt2])
883           goto redo;
884       make_link (links + cnt, random_peer, peer, tc);
885       deg[random_peer]++;
886       deg[peer]++;
887       used[cnt] = random_peer;
888     }
889     for (cnt = 0; cnt < GNUNET_MIN (peer, m); cnt++)
890     {
891       etab[etaboff++] = used[cnt];
892       etab[etaboff++] = peer;
893     }
894     links += GNUNET_MIN (peer, m);
895   }
896   GNUNET_free (etab);
897   GNUNET_free (used);
898   GNUNET_free (deg);
899   GNUNET_assert (links <= tc->link_array_size);
900   tc->link_array_size = links;
901   switch (tc->type)
902   {
903   case TOPOLOGYCONTEXT_TYPE_OVERLAY:
904     {
905       struct TopologyContextOverlay *overlay;
906       
907       overlay = &tc->u.overlay;
908       overlay->link_array = 
909           GNUNET_realloc (overlay->link_array, sizeof (struct OverlayLink) * tc->link_array_size);
910     }
911     break;
912   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
913     {
914       struct TopologyContextUnderlay *underlay;
915
916       underlay = &tc->u.underlay;
917       underlay->link_array =
918           GNUNET_realloc (underlay->link_array, sizeof (struct UnderlayLink) * tc->link_array_size);
919     }
920     break;
921   }
922 }
923
924
925 /**
926  * Generates topology from the given file
927  *
928  * @param tc the topology context
929  * @param filename the filename of the file containing topology data
930  */
931 static void
932 gen_topo_from_file (struct TopologyContext *tc, const char *filename)
933 {
934   char *data;
935   char *end;
936   char *buf;
937   uint64_t fs;
938   uint64_t offset;
939   unsigned long int peer_id;
940   unsigned long int other_peer_id;
941   enum ParseState
942   {
943
944     /**
945      * We read the peer index
946      */
947     PEER_INDEX,
948
949     /**
950      * We read the other peer indices
951      */
952     OTHER_PEER_INDEX,
953
954   } state;
955   int status;
956
957   status = GNUNET_SYSERR;
958   if (GNUNET_YES != GNUNET_DISK_file_test (filename))
959   {
960     LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s not found\n"), filename);
961     return;
962   }
963   if (GNUNET_OK !=
964       GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
965   {
966     LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s has no data\n"),
967          filename);
968     return;
969   }
970   data = GNUNET_malloc (fs);
971   if (fs != GNUNET_DISK_fn_read (filename, data, fs))
972   {
973     LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s cannot be read\n"),
974          filename);
975     goto _exit;
976   }
977
978   offset = 0;
979   peer_id = 0;
980   state = PEER_INDEX;
981   while (offset < fs)
982   {
983     if (0 != isspace (data[offset]))
984     {
985       offset++;
986       continue;
987     }
988     switch (state)
989     {
990     case PEER_INDEX:
991       buf = strchr (&data[offset], ':');
992       if (NULL == buf)
993       {
994         LOG (GNUNET_ERROR_TYPE_ERROR,
995              _("Failed to read peer index from toology file: %s"), filename);
996         goto _exit;
997       }
998       *buf = '\0';
999       errno = 0;
1000       peer_id = (unsigned int) strtoul (&data[offset], &end, 10);
1001       if (0 != errno)
1002       {
1003         LOG (GNUNET_ERROR_TYPE_ERROR,
1004              _("Value in given topology file: %s out of range\n"), filename);
1005         goto _exit;
1006       }
1007       if (&data[offset] == end)
1008       {
1009         LOG (GNUNET_ERROR_TYPE_ERROR,
1010              _("Failed to read peer index from topology file: %s"), filename);
1011         goto _exit;
1012       }
1013       if (tc->num_peers <= peer_id)
1014       {
1015         LOG (GNUNET_ERROR_TYPE_ERROR,
1016              _("Topology file needs more peers than given ones\n"), filename);
1017         goto _exit;
1018       }
1019       state = OTHER_PEER_INDEX;
1020       offset += ((unsigned int) (buf - &data[offset])) + 1;
1021       break;
1022     case OTHER_PEER_INDEX:
1023       errno = 0;
1024       other_peer_id = (unsigned int) strtoul (&data[offset], &end, 10);
1025       if (0 != errno)
1026       {
1027         LOG (GNUNET_ERROR_TYPE_ERROR,
1028              _("Value in given topology file: %s out of range\n"), filename);
1029         goto _exit;
1030       }
1031       if (&data[offset] == end)
1032       {
1033         LOG (GNUNET_ERROR_TYPE_ERROR,
1034              _("Failed to read peer index from topology file: %s"), filename);
1035         goto _exit;
1036       }
1037       if (tc->num_peers <= other_peer_id)
1038       {
1039         LOG (GNUNET_ERROR_TYPE_ERROR,
1040              _("Topology file needs more peers than given ones\n"), filename);
1041         goto _exit;
1042       }
1043       if (peer_id != other_peer_id)
1044       {
1045         tc->link_array_size++;
1046         switch (tc->type)
1047         {
1048         case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1049           {
1050             struct TopologyContextOverlay *overlay;
1051             
1052             overlay = &tc->u.overlay;
1053             overlay->link_array = 
1054                 GNUNET_realloc (overlay->link_array,
1055                                 sizeof (struct OverlayLink) * tc->link_array_size);
1056           }
1057           break;
1058         case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1059           {
1060             struct TopologyContextUnderlay *underlay;
1061             
1062             underlay = &tc->u.underlay;
1063             underlay->link_array =
1064                 GNUNET_realloc (underlay->link_array,
1065                                 sizeof (struct UnderlayLink) * tc->link_array_size);
1066           }
1067           break;
1068         }
1069         offset += end - &data[offset];
1070         make_link (tc->link_array_size - 1, peer_id, other_peer_id, tc);
1071       }
1072       else
1073         LOG (GNUNET_ERROR_TYPE_WARNING,
1074              _("Ignoring to connect peer %u to peer %u\n"), peer_id,
1075              other_peer_id);
1076       while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs))
1077         offset++;
1078       if ('\n' == data[offset])
1079         state = PEER_INDEX;
1080       else if ('|' == data[offset])
1081       {
1082         state = OTHER_PEER_INDEX;
1083         offset++;
1084       }
1085       break;
1086     }
1087   }
1088   status = GNUNET_OK;
1089
1090 _exit:
1091   GNUNET_free (data);
1092   if (GNUNET_OK != status)
1093   {
1094     LOG (GNUNET_ERROR_TYPE_WARNING, "Removing link data read from the file\n");
1095     tc->link_array_size = 0;
1096     switch (tc->type)
1097     {
1098     case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1099       {
1100         struct TopologyContextOverlay *overlay;
1101         
1102         overlay = &tc->u.overlay;
1103         GNUNET_free_non_null (overlay->link_array);
1104         overlay->link_array = NULL;
1105       }
1106       break;
1107     case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1108       {
1109         struct TopologyContextUnderlay *underlay;
1110         
1111         underlay = &tc->u.underlay;
1112         GNUNET_free_non_null (underlay->link_array);
1113         underlay->link_array = NULL;
1114       }
1115       break;
1116     }
1117   }
1118 }
1119
1120
1121 /**
1122  * Generates clique topology
1123  *
1124  * @param tc the topology context
1125  */
1126 static void
1127 gen_topo_clique (struct TopologyContext *tc)
1128 {
1129   unsigned int cnt;
1130   unsigned int offset;
1131   unsigned int neighbour;
1132   
1133   tc->link_array_size = tc->num_peers * (tc->num_peers - 1);
1134   switch (tc->type)
1135   {
1136   case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1137     {
1138       struct TopologyContextOverlay *overlay;
1139
1140       overlay = &tc->u.overlay;
1141       overlay->link_array = GNUNET_malloc (sizeof (struct OverlayLink) *
1142                                            tc->link_array_size);
1143     }
1144     break;
1145   case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1146     {
1147       struct TopologyContextUnderlay *underlay;
1148
1149       underlay = &tc->u.underlay;
1150       underlay->link_array = GNUNET_malloc (sizeof (struct UnderlayLink) *
1151                                             tc->link_array_size);
1152     }
1153   }
1154   offset = 0;
1155   for (cnt = 0; cnt < tc->num_peers; cnt++)
1156   {
1157     for (neighbour = 0; neighbour < tc->num_peers; neighbour++)
1158     {
1159       if (neighbour == cnt)
1160         continue;
1161       make_link (offset, cnt, neighbour, tc);
1162       offset++;
1163     }
1164   }
1165 }
1166
1167
1168 /**
1169  * Configure overall network topology to have a particular shape.
1170  *
1171  * @param op_cls closure argument to give with the operation event
1172  * @param num_peers number of peers in 'peers'
1173  * @param peers array of 'num_peers' with the peers to configure
1174  * @param topo desired underlay topology to use
1175  * @param ap topology-specific options
1176  * @return handle to the operation, NULL if configuring the topology
1177  *         is not allowed at this time
1178  */
1179 struct GNUNET_TESTBED_Operation *
1180 GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
1181                                                unsigned int num_peers,
1182                                                struct GNUNET_TESTBED_Peer
1183                                                **peers,
1184                                                enum
1185                                                GNUNET_TESTBED_TopologyOption
1186                                                topo, va_list ap)
1187 {
1188   GNUNET_break (0);
1189   return NULL;
1190 }
1191
1192
1193 /**
1194  * Configure overall network topology to have a particular shape.
1195  *
1196  * @param op_cls closure argument to give with the operation event
1197  * @param num_peers number of peers in 'peers'
1198  * @param peers array of 'num_peers' with the peers to configure
1199  * @param topo desired underlay topology to use
1200  * @param ... topology-specific options
1201  * @return handle to the operation, NULL if configuring the topology
1202  *         is not allowed at this time
1203  */
1204 struct GNUNET_TESTBED_Operation *
1205 GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
1206                                             unsigned int num_peers,
1207                                             struct GNUNET_TESTBED_Peer **peers,
1208                                             enum GNUNET_TESTBED_TopologyOption
1209                                             topo, ...)
1210 {
1211   GNUNET_break (0);
1212   return NULL;
1213 }
1214
1215
1216 /**
1217  * All peers must have been started before calling this function.
1218  * This function then connects the given peers in the P2P overlay
1219  * using the given topology.
1220  *
1221  * @param op_cls closure argument to give with the peer connect operation events
1222  *          generated through this function
1223  * @param num_peers number of peers in 'peers'
1224  * @param peers array of 'num_peers' with the peers to configure
1225  * @param max_connections the maximums number of overlay connections that will
1226  *          be made to achieve the given topology
1227  * @param comp_cb the completion callback to call when the topology generation
1228  *          is completed
1229  * @param comp_cb_cls closure for the above completion callback
1230  * @param topo desired underlay topology to use
1231  * @param va topology-specific options
1232  * @return handle to the operation, NULL if connecting these
1233  *         peers is fundamentally not possible at this time (peers
1234  *         not running or underlay disallows) or if num_peers is less than 2
1235  */
1236 struct GNUNET_TESTBED_Operation *
1237 GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
1238                                               unsigned int num_peers,
1239                                               struct GNUNET_TESTBED_Peer **peers,
1240                                               unsigned int *max_connections,
1241                                               GNUNET_TESTBED_TopologyCompletionCallback
1242                                               comp_cb,
1243                                               void *comp_cb_cls,
1244                                               enum GNUNET_TESTBED_TopologyOption topo,
1245                                               va_list va)
1246 {
1247   struct TopologyContext *tc;
1248   struct TopologyContextOverlay *overlay;
1249   struct GNUNET_TESTBED_Operation *op;
1250   struct GNUNET_TESTBED_Controller *c;
1251   enum GNUNET_TESTBED_TopologyOption secondary_option;
1252
1253   if (num_peers < 2)
1254     return NULL;
1255   c = peers[0]->controller;
1256   tc = GNUNET_new (struct TopologyContext);
1257   tc->type = TOPOLOGYCONTEXT_TYPE_OVERLAY;
1258   overlay = &tc->u.overlay;
1259   overlay->peers = peers;
1260   tc->num_peers = num_peers;
1261   overlay->op_cls = op_cls;
1262   overlay->retry_cnt = DEFAULT_RETRY_CNT;
1263   overlay->comp_cb = comp_cb;
1264   overlay->comp_cb_cls = comp_cb_cls;
1265   switch (topo)
1266   {
1267   case GNUNET_TESTBED_TOPOLOGY_LINE:
1268     gen_topo_line (tc);
1269     break;
1270   case GNUNET_TESTBED_TOPOLOGY_RING:
1271     gen_topo_ring (tc);
1272     break;
1273   case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
1274     gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_NO);
1275     break;
1276   case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
1277     gen_topo_ring (tc);
1278     gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_YES);
1279     break;
1280   case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
1281     gen_topo_clique (tc);
1282     break;
1283   case GNUNET_TESTBED_TOPOLOGY_2D_TORUS:
1284     gen_topo_2dtorus (tc);
1285     break;
1286   case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
1287     gen_topo_2dtorus (tc);
1288     gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_YES);
1289
1290     break;
1291   case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
1292     {
1293       uint16_t cap;
1294       uint8_t m;
1295
1296       cap = (uint16_t) va_arg (va, unsigned int);
1297       m = (uint8_t) va_arg (va, unsigned int);
1298       gen_topo_scale_free (tc, cap, m);
1299     }
1300     break;
1301   case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
1302   {
1303     const char *filename;
1304
1305     filename = va_arg (va, const char *);
1306
1307     GNUNET_assert (NULL != filename);
1308     gen_topo_from_file (tc, filename);
1309   }
1310     break;
1311   default:
1312     GNUNET_break (0);
1313     GNUNET_free (tc);
1314     return NULL;
1315   }
1316   do
1317   {
1318     secondary_option = va_arg (va, enum GNUNET_TESTBED_TopologyOption);
1319
1320     switch (secondary_option)
1321     {
1322     case GNUNET_TESTBED_TOPOLOGY_RETRY_CNT:
1323       overlay->retry_cnt =  va_arg (va, unsigned int);
1324       break;
1325     case GNUNET_TESTBED_TOPOLOGY_OPTION_END:
1326       break;
1327     default:
1328       GNUNET_break (0);         /* Should not use any other option apart from
1329                                  * the ones handled here */
1330       GNUNET_free_non_null (overlay->link_array);
1331       GNUNET_free (tc);
1332       return NULL;
1333     }
1334   }
1335   while (GNUNET_TESTBED_TOPOLOGY_OPTION_END != secondary_option);
1336   op = GNUNET_TESTBED_operation_create_ (tc,
1337                                          &opstart_overlay_configure_topology,
1338                                          &oprelease_overlay_configure_topology);
1339   GNUNET_TESTBED_operation_queue_insert_
1340       (c->opq_parallel_topology_config_operations, op);
1341   GNUNET_TESTBED_operation_begin_wait_ (op);
1342   LOG (GNUNET_ERROR_TYPE_DEBUG, "Generated %u connections\n",
1343        tc->link_array_size);
1344   if (NULL != max_connections)
1345     *max_connections = tc->link_array_size;
1346   return op;
1347 }
1348
1349
1350 /**
1351  * All peers must have been started before calling this function.
1352  * This function then connects the given peers in the P2P overlay
1353  * using the given topology.
1354  *
1355  * @param op_cls closure argument to give with the peer connect operation events
1356  *          generated through this function
1357  * @param num_peers number of peers in 'peers'
1358  * @param peers array of 'num_peers' with the peers to configure
1359  * @param max_connections the maximums number of overlay connections that will
1360  *          be made to achieve the given topology
1361  * @param comp_cb the completion callback to call when the topology generation
1362  *          is completed
1363  * @param comp_cb_cls closure for the above completion callback
1364  * @param topo desired underlay topology to use
1365  * @param ... topology-specific options
1366  * @return handle to the operation, NULL if connecting these
1367  *         peers is fundamentally not possible at this time (peers
1368  *         not running or underlay disallows) or if num_peers is less than 2
1369  */
1370 struct GNUNET_TESTBED_Operation *
1371 GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
1372                                            unsigned int num_peers,
1373                                            struct GNUNET_TESTBED_Peer **peers,
1374                                            unsigned int *max_connections,
1375                                            GNUNET_TESTBED_TopologyCompletionCallback
1376                                            comp_cb,
1377                                            void *comp_cb_cls,
1378                                            enum GNUNET_TESTBED_TopologyOption topo,
1379                                            ...)
1380 {
1381   struct GNUNET_TESTBED_Operation *op;
1382   va_list vargs;
1383
1384   GNUNET_assert (topo < GNUNET_TESTBED_TOPOLOGY_OPTION_END);
1385   va_start (vargs, topo);
1386   op = GNUNET_TESTBED_overlay_configure_topology_va (op_cls, num_peers, peers,
1387                                                      max_connections,
1388                                                      comp_cb, comp_cb_cls,
1389                                                      topo,
1390                                                      vargs);
1391   va_end (vargs);
1392   return op;
1393 }
1394
1395
1396 /**
1397  * Get a topology from a string input.
1398  *
1399  * @param topology where to write the retrieved topology
1400  * @param topology_string The string to attempt to
1401  *        get a configuration value from
1402  * @return GNUNET_YES if topology string matched a
1403  *         known topology, GNUNET_NO if not
1404  */
1405 int
1406 GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology,
1407                               const char *topology_string)
1408 {
1409   unsigned int cnt;
1410
1411   for (cnt = 0; NULL != topology_strings[cnt]; cnt++)
1412   {
1413     if (0 == strcasecmp (topology_string, topology_strings[cnt]))
1414     {
1415       if (NULL != topology)
1416         *topology = (enum GNUNET_TESTBED_TopologyOption) cnt;
1417       return GNUNET_YES;
1418     }
1419   }
1420   return GNUNET_NO;
1421 }
1422
1423
1424 /**
1425  * Returns the string corresponding to the given topology
1426  *
1427  * @param topology the topology
1428  * @return the string (freshly allocated) of given topology; NULL if topology cannot be
1429  *           expressed as a string
1430  */
1431 char *
1432 GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology)
1433 {
1434   if (GNUNET_TESTBED_TOPOLOGY_OPTION_END <= topology)
1435     return NULL;
1436   return GNUNET_strdup (topology_strings[topology]);
1437 }
1438
1439
1440 /**
1441  * Function to construct an underlay topology
1442  *
1443  * @param num_peers the number of peers for which the topology should be
1444  *          generated
1445  * @param proc the underlay link processor callback.  Will be called for each
1446  *          underlay link generated unless a previous call to this callback
1447  *          returned GNUNET_SYSERR.  Cannot be NULL.
1448  * @param cls closure for proc
1449  * @param ... variable arguments denoting the topology and its parameters.  They
1450  *          should start with the type of topology to generate followed by their
1451  *          options.
1452  * @return GNUNET_OK if underlay link generation is successful; GNUNET_SYSERR
1453  *          upon error in generating the underlay or if any calls to the
1454  *          underlay link processor returned GNUNET_SYSERR
1455  */
1456 int
1457 GNUNET_TESTBED_underlay_construct_ (int num_peers,
1458                                     underlay_link_processor proc,
1459                                     void *cls,
1460                                     ...)
1461 {
1462   struct TopologyContext tc;
1463   struct TopologyContextUnderlay *underlay;
1464   struct UnderlayLink *ulink;
1465   va_list vargs;
1466   enum GNUNET_TESTBED_TopologyOption topology;
1467   unsigned int cnt;
1468   int ret;
1469   
1470   GNUNET_assert (NULL != proc);
1471   ret = GNUNET_OK;
1472   memset (&tc, 0, sizeof (tc));
1473   tc.num_peers = num_peers;
1474   tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY;
1475   underlay = &tc.u.underlay;
1476   va_start (vargs, cls);
1477   topology = va_arg (vargs, enum GNUNET_TESTBED_TopologyOption);
1478   switch (topology)
1479   {
1480   case GNUNET_TESTBED_TOPOLOGY_LINE:
1481     gen_topo_line (&tc);
1482     break;
1483   case GNUNET_TESTBED_TOPOLOGY_RING:
1484     gen_topo_ring (&tc);
1485     break;
1486   case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
1487     gen_topo_clique (&tc);
1488     break;
1489   case GNUNET_TESTBED_TOPOLOGY_2D_TORUS:
1490     gen_topo_2dtorus (&tc);
1491     break;
1492   case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
1493     gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_NO);
1494     break;
1495   case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
1496     gen_topo_ring (&tc);
1497     gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES);
1498     break;
1499   case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
1500     gen_topo_2dtorus (&tc);
1501     gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES);
1502     break;
1503   case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
1504     {
1505       const char *filename;
1506       filename = va_arg (vargs, char *);
1507       GNUNET_assert (NULL != filename);
1508       gen_topo_from_file (&tc, filename);
1509     }
1510     break;
1511   case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
1512     {
1513       uint16_t cap;
1514       uint8_t m;
1515       cap = (uint16_t) va_arg (vargs, unsigned int);
1516       m = (uint8_t) va_arg (vargs, unsigned int);
1517       gen_topo_scale_free (&tc, cap, m);
1518     }
1519     break;
1520   default:
1521     GNUNET_assert (0);
1522   }
1523   va_end (vargs);
1524   for (cnt = 0; cnt < tc.link_array_size; cnt++)
1525   {
1526     ulink = &underlay->link_array[cnt];
1527     if (GNUNET_SYSERR == proc (cls,
1528                                ulink->A,
1529                                ulink->B,
1530                                ulink->bandwidth,
1531                                ulink->latency,
1532                                ulink->loss))
1533     {
1534       ret = GNUNET_SYSERR;
1535       break;
1536     }
1537   }
1538   GNUNET_free_non_null (underlay->link_array);
1539   return ret;
1540 }
1541
1542 /* end of testbed_api_topology.c */