X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c8593c6dc8bdf1408a32cbae25fe1d9855debdbb..78e5edee4cb3845cedd7b603d611129cce6a14e9:/src/surf/gtnets/gtnets_simulator.cc diff --git a/src/surf/gtnets/gtnets_simulator.cc b/src/surf/gtnets/gtnets_simulator.cc index e915aa65f6..2acaf1477e 100644 --- a/src/surf/gtnets/gtnets_simulator.cc +++ b/src/surf/gtnets/gtnets_simulator.cc @@ -8,6 +8,15 @@ #include "gtnets_topology.h" #include #include +#ifdef DEBUG0 + #undef DEBUG0 +#endif +#include "xbt/log.h" +#include "xbt/asserts.h" + +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_gtnets_simulator, surf_network_gtnets, + "Logging specific to the SURF network GTNetS simulator"); + using namespace std; @@ -26,6 +35,7 @@ GTSim::GTSim(){ nflow_ = 0; sim_ = new Simulator(); topo_ = new GTNETS_Topology(); + uniform_jitter_ = NULL; sim_->verbose=false; // Set default values. @@ -79,21 +89,25 @@ GTSim::~GTSim(){ } int GTSim::add_router(int id){ - if (topo_->add_router(id) < 0){ - fprintf(stderr, "can't add router %d. already exists.\n", id); - return -1; - } + xbt_assert1(!(topo_->add_router(id) < 0), "can't add router %d. already exists", id); } //bandwidth: in bytes. //latency: in seconds. int GTSim::add_link(int id, double bandwidth, double latency){ double bw = bandwidth * 8; //Bandwidth in bits (used in GTNETS). - if (topo_->add_link(id) < 0){ - fprintf(stderr, "can't add link %d. already exists.\n", id); - return -1; - } + xbt_assert1(!(topo_->add_link(id) < 0),"Can't add link %d. already exists", id); + DEBUG3("Creating a new P2P, linkid %d, bandwidth %gl, latency %gl", id, bandwidth, latency); gtnets_links_[id] = new Linkp2p(bw, latency); + if(jitter_ > 0){ + DEBUG1("Using jitter %f", jitter_); + double min = -1*jitter_*latency; + double max = jitter_*latency; + if(uniform_jitter_ == NULL){ + uniform_jitter_ = new Uniform(min,max); + } + gtnets_links_[id]->Jitter((const Random &) *uniform_jitter_); + } return 0; } @@ -110,17 +124,14 @@ bool GTSim::link_include(int id){ } int GTSim::add_onehop_route(int src, int dst, int link){ - if (topo_->add_onehop_route(src, dst, link) < 0){ - fprintf(stderr, "Cannot add a route, src: %d, dst: %d, link: %d\n", - src, dst, link); - return -1; - } + xbt_assert3(!(topo_->add_onehop_route(src, dst, link) < 0), "Cannot add a route, src: %d, dst: %d, link: %d", src, dst, link); return 0; } // Generate the gtnets nodes according to topo_. void GTSim::add_nodes(){ static unsigned int address = IPAddr("192.168.0.1"); + IPAddr helper = IPAddr(); vector nodes = topo_->nodes(); vector::iterator it; int id; @@ -128,7 +139,8 @@ void GTSim::add_nodes(){ id = (*it)->id(); gtnets_nodes_[id] = new Node(); gtnets_nodes_[id]->SetIPAddr(address++); - // printf("In GTSim, add_node: %d\n", id); + DEBUG2("In GTSim, add_node: %d, with IPAddr %s", id, helper.ToDotted(address-1)); + } } @@ -147,6 +159,7 @@ void GTSim::node_connect(){ gtnets_nodes_[srcid]-> AddDuplexLink(gtnets_nodes_[dstid], *(gtnets_links_[linkid])); + DEBUG3("Setting DuplexLink, src %d, dst %d, linkid %d", srcid, dstid, linkid); } } } @@ -157,6 +170,10 @@ void GTSim::create_gtnets_topology(){ node_connect(); } +void GTSim::print_topology(){ + topo_->print_topology(); +} + // Add a route that includes more than one hop. All one hop // routes must have been added. When this function is called // for the first time, all gtnets nodes are generated. @@ -171,14 +188,8 @@ int GTSim::add_route(int src, int dst, int* links, int nlink){ int src_node = topo_->nodeid_from_hostid(src); int dst_node = topo_->nodeid_from_hostid(dst); - if (gtnets_nodes_.find(src_node) == gtnets_nodes_.end()){ - fprintf(stderr, "node %d not found\n", src_node); - return -1; - } - if (gtnets_nodes_.find(dst_node) == gtnets_nodes_.end()){ - fprintf(stderr, "node %d not found\n", dst_node); - return -1; - } + xbt_assert1(!(gtnets_nodes_.find(src_node) == gtnets_nodes_.end()), "Node %d not found", src_node); + xbt_assert1(!(gtnets_nodes_.find(dst_node) == gtnets_nodes_.end()), "Node %d not found", dst_node); Node* tmpsrc = gtnets_nodes_[src_node]; Node* tmpdst = gtnets_nodes_[dst_node]; @@ -187,19 +198,10 @@ int GTSim::add_route(int src, int dst, int* links, int nlink){ cur_node = src_node; for (int i = 0; i < nlink; i++){ - if (gtnets_nodes_.find(cur_node) == gtnets_nodes_.end()){ - fprintf(stderr, "node %d not found\n", cur_node); - return -1; - } + xbt_assert1(!(gtnets_nodes_.find(cur_node) == gtnets_nodes_.end()), "Node %d not found", cur_node); next_node = topo_->peer_node_id(links[i], cur_node); - if (next_node < 0){ - fprintf(stderr, "peer node not found\n"); - return -1; - } - if (gtnets_nodes_.find(next_node) == gtnets_nodes_.end()){ - fprintf(stderr, "node %d not found\n", next_node); - return -1; - } + xbt_assert0(!(next_node < 0), "Peer node not found"); + xbt_assert1(!(gtnets_nodes_.find(next_node) == gtnets_nodes_.end()), "Node %d not found", next_node); //add route Node* tmpcur = gtnets_nodes_[cur_node]; @@ -218,11 +220,7 @@ int GTSim::add_route(int src, int dst, int* links, int nlink){ cur_node = next_node; } - if (cur_node != dst_node){ - fprintf(stderr, "Route inconsistency, last: %d, dst: %d\n", - cur_node, dst_node); - return -1; - } + xbt_assert2(!(cur_node != dst_node), "Route inconsistency, last: %d, dst: %d",cur_node, dst_node); return 0; } @@ -238,15 +236,10 @@ int GTSim::create_flow(int src, int dst, long datasize, void* metadata){ } int src_node = topo_->nodeid_from_hostid(src); - if (src_node < 0){ - fprintf(stderr, "src %d not found\n"); - return -1; - } + xbt_assert1(!(src_node < 0), "Src %d not found", src_node); + int dst_node = topo_->nodeid_from_hostid(dst); - if (dst_node < 0){ - fprintf(stderr, "dst %d not found\n"); - return -1; - } + xbt_assert1(!(dst_node < 0), "Dst %d not found", dst_node); gtnets_servers_[nflow_] = (TCPServer*) gtnets_nodes_[dst_node]-> AddApplication(TCPServer(TCPReno())); @@ -314,6 +307,9 @@ int GTSim::run(double delta){ return 0; } +void GTSim::set_jitter(double d){ + jitter_ = d; +} void static tcp_sent_callback(void* action, double completion_time){ // Schedule the flow complete event.