2 /* Copyright (c) 2007 Kayo Fujiwara. 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. */
8 #include "gtnets_simulator.h"
9 #include "gtnets_interface.h"
14 #include "xbt/asserts.h"
16 static GTSim* gtnets_sim = 0;
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_gtnets_interface, surf_network_gtnets,
20 "Logging specific to the SURF network GTNetS interface");
24 // initialize the GTNetS interface and environment
25 int gtnets_initialize(){
27 DEBUG0("Using logging.");
29 xbt_assert0(!gtnets_sim, "gtnets already initialized");
31 gtnets_sim = new GTSim();
35 // add a link (argument link is just an index starting at 0...
36 // add link 0, add link 1, etc.)
37 int gtnets_add_link(int id, double bandwidth, double latency){
38 return gtnets_sim->add_link(id, bandwidth, latency);
41 // add a route between a source and a destination as an array of link indices
42 // (note that there is no gtnets_add_network_card(), as we discover them
43 // on the fly via calls to gtnets_add_route()
44 int gtnets_add_route(int src, int dst, int* links, int nlink){
45 return gtnets_sim->add_route(src, dst, links, nlink);
49 int gtnets_add_router(int id){
50 return gtnets_sim->add_router(id);
53 // add a route between a source and a destination as an array of link indices
54 // (note that there is no gtnets_add_network_card(), as we discover them
55 // on the fly via calls to gtnets_add_route()
56 int gtnets_add_onehop_route(int src, int dst, int link){
57 return gtnets_sim->add_onehop_route(src, dst, link);
60 // create a new flow on a route
61 // one can attach arbitrary metadata to a flow
62 int gtnets_create_flow(int src, int dst, long datasize, void* metadata){
63 return gtnets_sim->create_flow(src, dst, datasize, metadata);
66 // get the time (double) until a flow completes (the first such flow)
67 // if no flows exist, return -1.0
68 double gtnets_get_time_to_next_flow_completion(){
73 if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
74 file.open ("/dev/null");
76 cout.rdbuf(file.rdbuf());
77 DEBUG0("Enable GTNetS library quite mode");
79 DEBUG0("Disable GTNetS library quite mode");
82 value = gtnets_sim->get_time_to_next_flow_completion();
84 if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
91 // run until a flow completes (returns that flow's metadata)
92 int gtnets_run_until_next_flow_completion(void ***metadata, int *number_of_flows){
97 if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
98 file.open ("/dev/null");
100 cout.rdbuf(file.rdbuf());
101 DEBUG0("Enable GTNetS library quite mode");
103 DEBUG0("Disable GTNetS library quite mode");
106 value = gtnets_sim->run_until_next_flow_completion(metadata, number_of_flows);
108 if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
115 // get the total received in bytes using the TCPServer object totRx field
116 double gtnets_get_flow_rx(void *metadata){
117 return gtnets_sim->gtnets_get_flow_rx(metadata);
121 // run for a given time (double)
122 int gtnets_run(Time_t deltat){
123 gtnets_sim->run(deltat);
128 int gtnets_finalize(){
129 if (!gtnets_sim) return -1;
136 void gtnets_print_topology(void){
137 gtnets_sim->print_topology();