Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Added one.
[simgrid.git] / src / surf / gtnets / gtnets_interface.cc
1
2 #include "gtnets_simulator.h"
3 #include "gtnets_interface.h"
4
5 static GTSim* gtnets_sim = 0;
6
7 // initialize the GTNetS interface and environment
8 int gtnets_initialize(){
9   if (gtnets_sim){
10     fprintf(stderr, "gtnets already initialized.\n");
11     return -1;
12   }
13   gtnets_sim = new GTSim();
14   return 1;
15 }
16
17 // adds a link (argument link is just an index starting at 0... 
18 // add link 0, add link 1, etc.)
19 int gtnets_add_link(int id, double bandwidth, double latency){
20   return gtnets_sim->add_link(id, bandwidth, latency);
21 }
22
23 // adds a route between a source and a destination as an array of link indices
24 // (note that there is no gtnets_add_network_card(), as we discover them
25 // on the fly via calls to gtnets_add_route()
26 int gtnets_add_route(int src, int dst, int* links, int nlink){
27   return gtnets_sim->add_route(src, dst, links, nlink);
28 }
29
30 // create a new flow on a route
31 // one can attach arbitrary metadata to a flow
32 int gtnets_create_flow(int src, int dst, long datasize, void* metadata){
33   return gtnets_sim->create_flow(src, dst, datasize, metadata);
34 }
35
36 // get the time (double) until a flow completes (the first such flow)
37 // if no flows exist, return -1.0
38 double gtnets_get_time_to_next_flow_completion(){
39   return gtnets_sim->get_time_to_next_flow_completion();
40 }
41
42 // run until a flow completes (returns that flow's metadata)
43 int gtnets_run_until_next_flow_completion(void ***metadata, int *number_of_flows){
44   return gtnets_sim->run_until_next_flow_completion(metadata, number_of_flows);
45 }
46
47 // run for a given time (double)
48 int gtnets_run(Time_t deltat){
49   gtnets_sim->run(deltat);
50 }
51
52 // clean up
53 void gtnets_finalize(){
54   if (!gtnets_sim) return;
55   gtnets_sim->finalize();
56   delete gtnets_sim;
57   gtnets_sim = 0;
58 }
59