From: Richard Whitehouse Date: Wed, 11 May 2011 14:32:36 +0000 (+0100) Subject: Allow multiple values for representing topology size in generation, comma separated... X-Git-Url: https://git.richardwhiuk.com/?a=commitdiff_plain;h=d014627f15c474f1f2572012c283ec9fd6e99235;p=ns-moose.git Allow multiple values for representing topology size in generation, comma separated. Used in tree for branch factor and depth --- diff --git a/src/simulation/generator.cc b/src/simulation/generator.cc index d909199..a42ab07 100644 --- a/src/simulation/generator.cc +++ b/src/simulation/generator.cc @@ -27,13 +27,24 @@ using namespace ns3; NS_LOG_COMPONENT_DEFINE ("MooseGenerator"); +std::vector &split(std::string ints, char delim, std::vector &elems){ + std::istringstream ss(ints); + std::string item; unsigned int i; + while(std::getline(ss, item, delim)){ + std::istringstream is(item); + is >> i; + elems.push_back(i); + } + return elems; +} + int main (int argc, char *argv[]) { try { std::string type; - unsigned long size = 0; + std::string size; unsigned long hosts = 0; std::string file; @@ -50,18 +61,21 @@ try { throw new std::runtime_error("Invalid number of hosts"); } - if(size < 2){ - throw new std::runtime_error("Invalid network size"); - } + std::vector sizes; + split(size, ',', sizes); if(type == "cube"){ - t = CubeTopologyHelper::Create(hosts, size); + if(sizes.size() != 1) throw new std::runtime_error("Invalid size of network"); + t = CubeTopologyHelper::Create(hosts, sizes[0]); } else if(type == "mesh"){ - t = MeshTopologyHelper::Create(hosts, size); + if(sizes.size() != 1) throw new std::runtime_error("Invalid size of network"); + t = MeshTopologyHelper::Create(hosts, sizes[0]); } else if(type == "torus"){ - t = TorusTopologyHelper::Create(hosts, size); + if(sizes.size() != 1) throw new std::runtime_error("Invalid size of network"); + t = TorusTopologyHelper::Create(hosts, sizes[0]); } else if(type == "tree"){ - t = TreeTopologyHelper::Create(hosts, size); + if(sizes.size() != 2) throw new std::runtime_error("Invalid size of network"); + t = TreeTopologyHelper::Create(hosts, sizes[0], sizes[1]); } else { throw new std::runtime_error("Unknown network topology type"); } diff --git a/src/topology/helper/tree.cc b/src/topology/helper/tree.cc index 87d065c..3e04390 100644 --- a/src/topology/helper/tree.cc +++ b/src/topology/helper/tree.cc @@ -25,26 +25,37 @@ NS_LOG_COMPONENT_DEFINE ("TreeTopologyHelper"); namespace ns3 { -Topology TreeTopologyHelper::Create(long hosts, long size){ +Topology TreeTopologyHelper::Create(long hosts, long branch, long depth){ Topology t; - t.bridges = size + 1; + long level = 1; + long bridges = 1; - t.hosts = size * hosts; + t.bridges = 0; - long i; long j; long k; + while(level < depth){ - for(i = 0; i < size; ++i){ - for(j = 0; j < hosts; ++j){ - t.hostLinks[(i*hosts) + j] = i + 1; + for(long i = 0; i < bridges; ++i){ + for(long j = 0; j < branch; ++j){ + t.bridgeLinks.insert(std::make_pair( t.bridges + i , t.bridges + bridges + i*bridges + j )); + } } + + t.bridges += bridges; + level ++; + bridges = bridges * branch; } - for(i = 0; i < size; ++i){ - t.bridgeLinks.insert(std::make_pair(0,i+1)); + for(long k = 0; k < bridges; ++k){ + for(long l = 0; l < hosts; ++l){ + t.hostLinks[(k*hosts) + l] = t.bridges + k; + } } + t.bridges += bridges; + t.hosts = bridges * hosts; + return t; } diff --git a/src/topology/helper/tree.h b/src/topology/helper/tree.h index 4726ce3..373326a 100644 --- a/src/topology/helper/tree.h +++ b/src/topology/helper/tree.h @@ -29,7 +29,7 @@ class TreeTopologyHelper { public: - Topology static Create(long hosts, long size); + Topology static Create(long hosts, long width, long depth); };