Generate network topologies
authorRichard Whitehouse <github@richardwhiuk.com>
Sat, 16 Apr 2011 23:12:09 +0000 (00:12 +0100)
committerRichard Whitehouse <github@richardwhiuk.com>
Sat, 16 Apr 2011 23:12:09 +0000 (00:12 +0100)
src/simulation/generator.cc [new file with mode: 0644]
src/simulation/wscript
src/topology/model/topology.cc
src/topology/model/topology.h

diff --git a/src/simulation/generator.cc b/src/simulation/generator.cc
new file mode 100644 (file)
index 0000000..a540fa8
--- /dev/null
@@ -0,0 +1,79 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Richard Whitehouse <ns3@richardwhiuk.com>
+ */
+
+#include "ns3/core-module.h"
+#include "ns3/topology-module.h"
+
+#include <stdexcept>
+#include <iostream>
+#include <fstream>
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("MooseGenerator");
+
+int main (int argc, char *argv[])
+{
+
+try {
+
+       std::string type;
+       unsigned long size;
+       unsigned long hosts;
+       std::string file;
+
+       CommandLine cmd;                        // Allow CommandLine args
+       cmd.AddValue("file", "Output file", file);
+       cmd.AddValue("type", "Network Topology (cube|mesh|torus)", type);
+       cmd.AddValue("size", "Network size", size);
+       cmd.AddValue("hosts", "Hosts per switch", hosts);
+       cmd.Parse (argc, argv);
+
+       Topology t;
+
+       if(hosts == 0){
+               throw new std::runtime_error("Invalid number of hosts");
+       }
+
+       if(size < 2){
+               throw new std::runtime_error("Invalid network size");
+       }
+
+       if(type == "cube"){
+               t = CubeTopologyHelper::Create(hosts, size);
+       } else if(type == "mesh"){
+               t = MeshTopologyHelper::Create(hosts, size);
+       } else if(type == "torus"){
+               t = TorusTopologyHelper::Create(hosts, size);
+       } else {
+               throw new std::runtime_error("Unknown network topology type");
+       } 
+
+       std::ofstream stream(file.c_str(), std::ios_base::out | std::ios_base::trunc);
+
+       stream << t;
+
+} catch(std::runtime_error* e) {
+       std::cerr << e->what() << std::endl;
+       return 1;
+}
+
+return 0;
+
+}
+
index 5cb063be43bf05618ef2238d2dbdb93ef14272cb..3f614c42b9ed2783e54ea40a01f1705cadde4e51 100644 (file)
@@ -10,6 +10,12 @@ def build(bld):
     headers.module = 'simulation'
     headers.source = []        
 
+
+    obj = bld.create_ns3_program('generator', ['bridge', 'internet-stack'])
+
+    obj.source = 'generator.cc'
+
+
     obj = bld.create_ns3_program('simulation', ['bridge', 'internet-stack'])
 
     obj.source = 'simulation.cc'
index 7ffd858da7900d4cc3c82a8c3aac0102d4a33799..b2b8bcc18a80c1af6e0832e74b2e911ecd223769 100644 (file)
@@ -27,6 +27,21 @@ NS_LOG_COMPONENT_DEFINE ("Topology");
 
 namespace ns3 {
 
+std::ostream& operator<<(std::ostream& file, ns3::Topology t){
+       file << "ns-moose" << std::endl;
+       file << 1 << std::endl;
+       file << 1 << std::endl;
+       file << t.hosts << std::endl;
+       file << t.bridges << std::endl;
+       for(Topology::BridgeLinks::iterator it = t.bridgeLinks.begin(); it != t.bridgeLinks.end(); it ++){
+               file << it->first << '\t' << it->second << std::endl;
+       }
+       for(Topology::HostLinks::iterator it = t.hostLinks.begin(); it != t.hostLinks.end(); it ++){
+               file << (it->first + t.bridges) << '\t' << it->second << std::endl;
+       }
+       return file;
+}
+
 Topology::Topology(){
 
 }
index 11ef56ecaf4308a9a0fa62ce08c4632f4b404e25..2f6af0b1f8411126722e10eacf6cf29123453aa6 100644 (file)
@@ -60,6 +60,8 @@ public:
 
 };
 
+std::ostream& operator<<(std::ostream&, ns3::Topology);
+
 }
 
 #endif