Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove gtnets verbose output.
[simgrid.git] / src / surf / gtnets / gtnets_interface.cc
1 /*      $Id$     */
2 /* Copyright (c) 2007 Kayo Fujiwara. All rights reserved.                  */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "gtnets_simulator.h"
8 #include "gtnets_interface.h"
9
10 static GTSim* gtnets_sim = 0;
11
12 // initialize the GTNetS interface and environment
13 int gtnets_initialize(){
14   if (gtnets_sim){
15     fprintf(stderr, "gtnets already initialized.\n");
16     return -1;
17   }
18   gtnets_sim = new GTSim();
19   return 0;
20 }
21
22 // add a link (argument link is just an index starting at 0... 
23 // add link 0, add link 1, etc.)
24 int gtnets_add_link(int id, double bandwidth, double latency){
25   return gtnets_sim->add_link(id, bandwidth, latency);
26 }
27
28 // add a route between a source and a destination as an array of link indices
29 // (note that there is no gtnets_add_network_card(), as we discover them
30 // on the fly via calls to gtnets_add_route()
31 int gtnets_add_route(int src, int dst, int* links, int nlink){
32   return gtnets_sim->add_route(src, dst, links, nlink);
33 }
34
35 // add a router
36 int gtnets_add_router(int id){
37   return gtnets_sim->add_router(id);
38 }
39
40 // add a route between a source and a destination as an array of link indices
41 // (note that there is no gtnets_add_network_card(), as we discover them
42 // on the fly via calls to gtnets_add_route()
43 int gtnets_add_onehop_route(int src, int dst, int link){
44   return gtnets_sim->add_onehop_route(src, dst, link);
45 }
46
47 // create a new flow on a route
48 // one can attach arbitrary metadata to a flow
49 int gtnets_create_flow(int src, int dst, long datasize, void* metadata){
50   return gtnets_sim->create_flow(src, dst, datasize, metadata);
51 }
52
53 // get the time (double) until a flow completes (the first such flow)
54 // if no flows exist, return -1.0
55 double gtnets_get_time_to_next_flow_completion(){
56   ofstream file;
57   double value;
58   file.open ("/dev/null");
59   streambuf* sbuf = cout.rdbuf();
60   cout.rdbuf(file.rdbuf());
61
62   value = gtnets_sim->get_time_to_next_flow_completion();
63
64   cout.rdbuf(sbuf);
65
66   return value;
67 }
68
69 // run until a flow completes (returns that flow's metadata)
70 int gtnets_run_until_next_flow_completion(void ***metadata, int *number_of_flows){
71   ofstream file;
72   double value;
73   file.open ("/dev/null");
74   streambuf* sbuf = cout.rdbuf();
75   cout.rdbuf(file.rdbuf());
76
77   value = gtnets_sim->run_until_next_flow_completion(metadata, number_of_flows);
78
79   cout.rdbuf(sbuf);
80
81   return value;
82 }
83
84 // get the total received in bytes using the TCPServer object totRx field
85 double gtnets_get_flow_rx(void *metadata){
86   return gtnets_sim->gtnets_get_flow_rx(metadata);
87 }
88
89
90 // run for a given time (double)
91 int gtnets_run(Time_t deltat){
92   gtnets_sim->run(deltat);
93   return 0;
94 }
95
96 // clean up
97 int gtnets_finalize(){
98   if (!gtnets_sim) return -1;
99   delete gtnets_sim;
100   gtnets_sim = 0;
101   return 0;
102 }
103