X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/9b67f9757c2b3384bb3c0e8ef256fbdf6c2e7821..342fcbf918c2e2e7d1a9e149722362b518d0ba9b:/src/surf/gtnets/gtnets_simulator.cc diff --git a/src/surf/gtnets/gtnets_simulator.cc b/src/surf/gtnets/gtnets_simulator.cc index eac36f447b..d0f1967718 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; @@ -15,6 +24,7 @@ static vector meta_flows; static int* meta_nflow; static int meta_flg = 0; + void static tcp_sent_callback(void* action, double completion_time); // Constructor. @@ -25,7 +35,10 @@ GTSim::GTSim(){ nflow_ = 0; sim_ = new Simulator(); topo_ = new GTNETS_Topology(); + jitter_ = 0; + jitter_seed_ = 10; + sim_->verbose=false; // Set default values. TCP::DefaultAdvWin(wsize); TCP::DefaultSegSize(1000); @@ -46,6 +59,13 @@ GTSim::~GTSim(){ while (!gtnets_links_.empty()) gtnets_links_.erase(gtnets_links_.begin()); + map::iterator it2; + for (it2 = uniform_jitter_generator_.begin(); it2 != uniform_jitter_generator_.end(); it2++){ + delete it2->second; + } + while (!uniform_jitter_generator_.empty()) + uniform_jitter_generator_.erase(uniform_jitter_generator_.begin()); + map::iterator it3; for (it3 = gtnets_nodes_.begin(); it3 != gtnets_nodes_.end(); it3++){ delete it3->second; @@ -77,21 +97,28 @@ 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){ + DEBUG2("Using jitter %f, and seed %u", jitter_, jitter_seed_); + double min = -1*jitter_*latency; + double max = jitter_*latency; + //initialize the random seed only once, when adding the first link + if(uniform_jitter_generator_.empty()){ + Random::GlobalSeed(jitter_seed_ , jitter_seed_+1, jitter_seed_+2, + jitter_seed_+3, jitter_seed_+4, jitter_seed_+5); + } + uniform_jitter_generator_[id] = new Uniform(min,max); + gtnets_links_[id]->Jitter((const Random &) *(uniform_jitter_generator_[id])); + } return 0; } @@ -108,17 +135,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; @@ -126,7 +150,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)); + } } @@ -145,6 +170,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); } } } @@ -155,13 +181,16 @@ 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. int GTSim::add_route(int src, int dst, int* links, int nlink){ if (is_topology_ == 0){ create_gtnets_topology(); - // topo_->print_topology(); is_topology_ = 1; } @@ -170,14 +199,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]; @@ -186,19 +209,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]; @@ -217,11 +231,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; } @@ -233,30 +243,26 @@ int GTSim::create_flow(int src, int dst, long datasize, void* metadata){ //generate it here. if (is_topology_ == 0){ create_gtnets_topology(); - // topo_->print_topology(); is_topology_ = 1; } 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]-> + gtnets_servers_[nflow_] = (TCPServer*) gtnets_nodes_[dst_node]-> AddApplication(TCPServer(TCPReno())); - gtnets_servers_[nflow_]->BindAndListen(80); + gtnets_servers_[nflow_]->BindAndListen(1000+nflow_); gtnets_clients_[nflow_] = (TCPSend*)gtnets_nodes_[src_node]-> AddApplication(TCPSend(metadata, gtnets_nodes_[dst_node]->GetIPAddr(), - 80, Constant(datasize), TCPReno())); + 1000+nflow_, Constant(datasize), TCPReno())); gtnets_clients_[nflow_]->SetSendCallBack(tcp_sent_callback); gtnets_clients_[nflow_]->Start(0); + + gtnets_action_to_flow_[metadata] = nflow_; nflow_++; return 0; @@ -266,14 +272,19 @@ Time_t GTSim::get_time_to_next_flow_completion(){ int status; Time_t t1; int pfds[2]; + int soon_pid=-1; meta_flg=0; + + //remain needs to be updated in the future + Count_t remain; pipe(pfds); t1 = 0; - if (fork() != 0){ + + if ( (soon_pid=fork()) != 0){ read(pfds[0], &t1, sizeof(Time_t)); - waitpid(-1, &status, 0); + waitpid(soon_pid, &status, 0); }else{ Time_t t; t = sim_->RunUntilNextCompletion(); @@ -284,7 +295,13 @@ Time_t GTSim::get_time_to_next_flow_completion(){ return t1; } +double GTSim::gtnets_get_flow_rx(void *metadata){ + int flow_id = gtnets_action_to_flow_[metadata]; + return gtnets_servers_[flow_id]->GetTotRx(); +} + int GTSim::run_until_next_flow_completion(void ***metadata, int *number_of_flows){ + meta_flows.clear(); meta_nflow = number_of_flows; meta_flg = 1; @@ -301,6 +318,14 @@ int GTSim::run(double delta){ return 0; } +void GTSim::set_jitter(double d){ + xbt_assert1(((0 <= d)&&(d <= 1)), "The jitter value must be within interval [0.0;1.0], got %f", d); + jitter_ = d; +} + +void GTSim::set_jitter_seed(int s){ + jitter_seed_ = s; +} void static tcp_sent_callback(void* action, double completion_time){ // Schedule the flow complete event. @@ -314,3 +339,4 @@ void static tcp_sent_callback(void* action, double completion_time){ } } +