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. */
7 #include "gtnets_simulator.h"
8 #include "gtnets_interface.h"
10 static GTSim* gtnets_sim = 0;
12 // initialize the GTNetS interface and environment
13 int gtnets_initialize(){
15 fprintf(stderr, "gtnets already initialized.\n");
18 gtnets_sim = new GTSim();
22 // add a link (argument link is just an index starting at 0...
23 // add link 0, add link 1, etc.)
24 int gtnets_add_link(int id, double bandwidth, double latency){
25 return gtnets_sim->add_link(id, bandwidth, latency);
28 // add a route between a source and a destination as an array of link indices
29 // (note that there is no gtnets_add_network_card(), as we discover them
30 // on the fly via calls to gtnets_add_route()
31 int gtnets_add_route(int src, int dst, int* links, int nlink){
32 return gtnets_sim->add_route(src, dst, links, nlink);
36 int gtnets_add_router(int id){
37 return gtnets_sim->add_router(id);
40 // add a route between a source and a destination as an array of link indices
41 // (note that there is no gtnets_add_network_card(), as we discover them
42 // on the fly via calls to gtnets_add_route()
43 int gtnets_add_onehop_route(int src, int dst, int link){
44 return gtnets_sim->add_onehop_route(src, dst, link);
47 // create a new flow on a route
48 // one can attach arbitrary metadata to a flow
49 int gtnets_create_flow(int src, int dst, long datasize, void* metadata){
50 return gtnets_sim->create_flow(src, dst, datasize, metadata);
53 // get the time (double) until a flow completes (the first such flow)
54 // if no flows exist, return -1.0
55 double gtnets_get_time_to_next_flow_completion(){
56 return gtnets_sim->get_time_to_next_flow_completion();
59 // run until a flow completes (returns that flow's metadata)
60 int gtnets_run_until_next_flow_completion(void ***metadata, int *number_of_flows){
61 return gtnets_sim->run_until_next_flow_completion(metadata, number_of_flows);
64 // get the total received in bytes using the TCPServer object totRx field
65 double gtnets_get_flow_rx(void *metadata){
66 return gtnets_sim->gtnets_get_flow_rx(metadata);
70 // run for a given time (double)
71 int gtnets_run(Time_t deltat){
72 gtnets_sim->run(deltat);
77 int gtnets_finalize(){
78 if (!gtnets_sim) return -1;