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(int wsize){
26 DEBUG0("Using logging.");
27 xbt_assert0(!gtnets_sim, "gtnets already initialized");
30 INFO1("TCP window maximum size : %d", wsize);
31 gtnets_sim = new GTSim(wsize);
33 gtnets_sim = new GTSim(wsize);
39 // add a link (argument link is just an index starting at 0...
40 // add link 0, add link 1, etc.)
41 int gtnets_add_link(int id, double bandwidth, double latency){
42 return gtnets_sim->add_link(id, bandwidth, latency);
45 // add a route between a source and a destination as an array of link indices
46 // (note that there is no gtnets_add_network_card(), as we discover them
47 // on the fly via calls to gtnets_add_route()
48 int gtnets_add_route(int src, int dst, int* links, int nlink){
49 return gtnets_sim->add_route(src, dst, links, nlink);
53 int gtnets_add_router(int id){
54 return gtnets_sim->add_router(id);
57 // add a route between a source and a destination as an array of link indices
58 // (note that there is no gtnets_add_network_card(), as we discover them
59 // on the fly via calls to gtnets_add_route()
60 int gtnets_add_onehop_route(int src, int dst, int link){
61 return gtnets_sim->add_onehop_route(src, dst, link);
64 // create a new flow on a route
65 // one can attach arbitrary metadata to a flow
66 int gtnets_create_flow(int src, int dst, long datasize, void* metadata){
67 return gtnets_sim->create_flow(src, dst, datasize, metadata);
70 // get the time (double) until a flow completes (the first such flow)
71 // if no flows exist, return -1.0
72 double gtnets_get_time_to_next_flow_completion(){
77 if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
78 file.open ("/dev/null");
80 cout.rdbuf(file.rdbuf());
81 DEBUG0("Enable GTNetS library quite mode");
83 DEBUG0("Disable GTNetS library quite mode");
86 value = gtnets_sim->get_time_to_next_flow_completion();
88 if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
95 // run until a flow completes (returns that flow's metadata)
96 double gtnets_run_until_next_flow_completion(void ***metadata, int *number_of_flows){
101 if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
102 file.open ("/dev/null");
104 cout.rdbuf(file.rdbuf());
105 DEBUG0("Enable GTNetS library quite mode");
107 DEBUG0("Disable GTNetS library quite mode");
110 value = gtnets_sim->run_until_next_flow_completion(metadata, number_of_flows);
112 if (!XBT_LOG_ISENABLED(surf_network_gtnets_interface, xbt_log_priority_debug)) {
116 return (double) value;
119 // get the total received in bytes using the TCPServer object totRx field
120 double gtnets_get_flow_rx(void *metadata){
121 return gtnets_sim->gtnets_get_flow_rx(metadata);
125 // run for a given time (double)
126 int gtnets_run(Time_t deltat){
127 gtnets_sim->run(deltat);
132 int gtnets_finalize(){
133 if (!gtnets_sim) return -1;
140 void gtnets_print_topology(void){
141 gtnets_sim->print_topology();
145 void gtnets_set_jitter(double d){
146 gtnets_sim->set_jitter(d);
150 void gtnets_set_jitter_seed(int seed){
151 gtnets_sim->set_jitter_seed(seed);