1 /* Copyright (c) 2007-2011, 2014. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "gtnets_simulator.h"
8 #include "gtnets_interface.h"
13 #include "xbt/asserts.h"
15 static GTSim* gtnets_sim = 0;
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_gtnets_interface, surf_network_gtnets,
19 "Logging specific to the SURF network GTNetS interface");
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");
29 XBT_INFO("TCP window maximum size : %d", wsize);
30 gtnets_sim = new GTSim(wsize);
32 gtnets_sim = new GTSim(wsize);
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);
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);
52 int gtnets_add_router(int id){
53 return gtnets_sim->add_router(id);
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);
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);
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(){
76 if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
77 file.open ("/dev/null");
79 cout.rdbuf(file.rdbuf());
80 XBT_DEBUG("Enable GTNetS library quite mode");
82 XBT_DEBUG("Disable GTNetS library quite mode");
85 value = gtnets_sim->get_time_to_next_flow_completion();
87 if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
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){
100 if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
101 file.open ("/dev/null");
103 cout.rdbuf(file.rdbuf());
104 XBT_DEBUG("Enable GTNetS library quite mode");
106 XBT_DEBUG("Disable GTNetS library quite mode");
109 value = gtnets_sim->run_until_next_flow_completion(metadata, number_of_flows);
111 if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
115 return (double) value;
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);
124 // run for a given time (double)
125 int gtnets_run(Time_t deltat){
130 if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
131 file.open ("/dev/null");
133 cout.rdbuf(file.rdbuf());
134 XBT_DEBUG("Enable GTNetS library quite mode");
136 XBT_DEBUG("Disable GTNetS library quite mode");
139 gtnets_sim->run(deltat);
142 if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
150 int gtnets_finalize(){
151 if (!gtnets_sim) return -1;
158 void gtnets_print_topology(void){
159 gtnets_sim->print_topology();
163 void gtnets_set_jitter(double d){
164 gtnets_sim->set_jitter(d);
168 void gtnets_set_jitter_seed(int seed){
169 gtnets_sim->set_jitter_seed(seed);