Allow multiple values for representing topology size in generation, comma separated...
authorRichard Whitehouse <github@richardwhiuk.com>
Wed, 11 May 2011 14:32:36 +0000 (15:32 +0100)
committerRichard Whitehouse <github@richardwhiuk.com>
Wed, 11 May 2011 14:44:24 +0000 (15:44 +0100)
src/simulation/generator.cc
src/topology/helper/tree.cc
src/topology/helper/tree.h

index d9091996540878f7b596a742b018f196f145077a..a42ab07f1a6897e9d14a48ccad146ff372322fac 100644 (file)
@@ -27,13 +27,24 @@ using namespace ns3;
 
 NS_LOG_COMPONENT_DEFINE ("MooseGenerator");
 
+std::vector<unsigned int> &split(std::string ints, char delim, std::vector<unsigned int> &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<unsigned int> 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");
        } 
index 87d065c372ca48c4c5a03c6fc251e154e1a1af4b..3e04390aad77fd8e87d675526f2da44e4e9a87a2 100644 (file)
@@ -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<long,long>( 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<long,long>(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;
 
 }
index 4726ce373b8501407bfccadcbd8a6027152f86a9..373326a11d1e68a77d98a189458c4949eacd613f 100644 (file)
@@ -29,7 +29,7 @@ class TreeTopologyHelper {
        
 public:
 
-       Topology static Create(long hosts, long size);  
+       Topology static Create(long hosts, long width, long depth);     
 
 };