Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c7df7d23a5fc32ddb6424d77592acf34d0640094
[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 0;
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   printf("gtnets_add_link: %d, %f, %f\n", id, bandwidth, latency);
21   return gtnets_sim->add_link(id, bandwidth, latency);
22 }
23
24 // adds a route between a source and a destination as an array of link indices
25 // (note that there is no gtnets_add_network_card(), as we discover them
26 // on the fly via calls to gtnets_add_route()
27 int gtnets_add_route(int src, int dst, int* links, int nlink){
28   int i;
29   printf("gtnets_add_route: %d, %d\n", src, dst);
30   for (i = 0; i < nlink; i++){
31     printf("%d: %d\n", i, *links++);
32   }
33   return gtnets_sim->add_route(src, dst, links, nlink);
34 }
35
36 // create a new flow on a route
37 // one can attach arbitrary metadata to a flow
38 int gtnets_create_flow(int src, int dst, long datasize, void* metadata){
39   printf("gtnets_create_flow: %d, %d, %d\n", src, dst, datasize);
40   return gtnets_sim->create_flow(src, dst, datasize, metadata);
41 }
42
43 // get the time (double) until a flow completes (the first such flow)
44 // if no flows exist, return -1.0
45 double gtnets_get_time_to_next_flow_completion(){
46   return gtnets_sim->get_time_to_next_flow_completion();
47 }
48
49 // run until a flow completes (returns that flow's metadata)
50 int gtnets_run_until_next_flow_completion(void ***metadata, int *number_of_flows){
51   return gtnets_sim->run_until_next_flow_completion(metadata, number_of_flows);
52 }
53
54 // run for a given time (double)
55 int gtnets_run(Time_t deltat){
56   gtnets_sim->run(deltat);
57   return 0;
58 }
59
60 // clean up
61 int gtnets_finalize(){
62   if (!gtnets_sim) return -1;
63   gtnets_sim->finalize();
64   delete gtnets_sim;
65   gtnets_sim = 0;
66   return 0;
67 }
68