Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix another typo
[simgrid.git] / src / surf / gtnets / gtnets_interface.cc
1 /* Copyright (c) 2007-2011, 2014. The SimGrid Team.
2  * 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 #ifdef XBT_DEBUG
10         #undef XBT_DEBUG
11 #endif
12 #include "xbt/log.h"
13 #include "xbt/asserts.h"
14
15 static GTSim* gtnets_sim = 0;
16
17
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_gtnets_interface, surf_network_gtnets,
19                                 "Logging specific to the SURF network GTNetS interface");
20
21
22
23 // initialize the GTNetS interface and environment
24 int gtnets_initialize(int wsize){
25   XBT_DEBUG("Using logging.");
26   xbt_assert(!gtnets_sim, "gtnets already initialized");
27
28   if(wsize > 0){
29         XBT_INFO("TCP window maximum size : %d", wsize);
30         gtnets_sim = new GTSim(wsize);
31   }else{
32         gtnets_sim = new GTSim(wsize);
33   }
34
35   return 0;
36 }
37
38 // add a link (argument link is just an index starting at 0... 
39 // add link 0, add link 1, etc.)
40 int gtnets_add_link(int id, double bandwidth, double latency){
41   return gtnets_sim->add_link(id, bandwidth, latency);
42 }
43
44 // add a route between a source and a destination as an array of link indices
45 // (note that there is no gtnets_add_network_card(), as we discover them
46 // on the fly via calls to gtnets_add_route()
47 int gtnets_add_route(int src, int dst, int* links, int nlink){
48   return gtnets_sim->add_route(src, dst, links, nlink);
49 }
50
51 // add a router
52 int gtnets_add_router(int id){
53   return gtnets_sim->add_router(id);
54 }
55
56 // add a route between a source and a destination as an array of link indices
57 // (note that there is no gtnets_add_network_card(), as we discover them
58 // on the fly via calls to gtnets_add_route()
59 int gtnets_add_onehop_route(int src, int dst, int link){
60   return gtnets_sim->add_onehop_route(src, dst, link);
61 }
62
63 // create a new flow on a route
64 // one can attach arbitrary metadata to a flow
65 int gtnets_create_flow(int src, int dst, long datasize, void* metadata){
66   return gtnets_sim->create_flow(src, dst, datasize, metadata);
67 }
68
69 // get the time (double) until a flow completes (the first such flow)
70 // if no flows exist, return -1.0
71 double gtnets_get_time_to_next_flow_completion(){
72   ofstream file;
73   streambuf* sbuf;
74   double value;
75
76   if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
77           file.open ("/dev/null");
78           sbuf = cout.rdbuf();
79           cout.rdbuf(file.rdbuf());
80           XBT_DEBUG("Enable GTNetS library quite mode");
81   }else {
82           XBT_DEBUG("Disable GTNetS library quite mode");
83   }
84
85   value = gtnets_sim->get_time_to_next_flow_completion();
86
87   if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
88           cout.rdbuf(sbuf);
89           file.close();
90   }
91   return value;
92 }
93
94 // run until a flow completes (returns that flow's metadata)
95 double gtnets_run_until_next_flow_completion(void ***metadata, int *number_of_flows){
96   ofstream file;
97   streambuf* sbuf;
98   double value;
99
100   if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
101           file.open ("/dev/null");
102           sbuf = cout.rdbuf();
103           cout.rdbuf(file.rdbuf());
104           XBT_DEBUG("Enable GTNetS library quite mode");
105   }else {
106           XBT_DEBUG("Disable GTNetS library quite mode");
107   }
108
109   value = gtnets_sim->run_until_next_flow_completion(metadata, number_of_flows);
110
111   if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
112           cout.rdbuf(sbuf);
113           file.close();
114   }
115   return (double) value;
116 }
117
118 // get the total received in bytes using the TCPServer object totRx field
119 double gtnets_get_flow_rx(void *metadata){
120   return gtnets_sim->gtnets_get_flow_rx(metadata);
121 }
122
123
124 // run for a given time (double)
125 int gtnets_run(Time_t deltat){
126   ofstream file;
127   streambuf* sbuf;
128   double value;
129
130   if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
131           file.open ("/dev/null");
132           sbuf = cout.rdbuf();
133           cout.rdbuf(file.rdbuf());
134           XBT_DEBUG("Enable GTNetS library quite mode");
135   }else {
136           XBT_DEBUG("Disable GTNetS library quite mode");
137   }
138
139   gtnets_sim->run(deltat);
140
141
142   if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
143           cout.rdbuf(sbuf);
144           file.close();
145   }
146   return 0;
147 }
148
149 // clean up
150 int gtnets_finalize(){
151   if (!gtnets_sim) return -1;
152   delete gtnets_sim;
153   gtnets_sim = 0;
154   return 0;
155 }
156
157 // print topology
158 void gtnets_print_topology(void){
159   gtnets_sim->print_topology();
160 }
161
162 // set jitter
163 void gtnets_set_jitter(double d){
164   gtnets_sim->set_jitter(d);
165 }
166
167 // set jitter seed
168 void gtnets_set_jitter_seed(int seed){
169   gtnets_sim->set_jitter_seed(seed);
170 }
171
172