Add simulation framework for Moose Networks
authorRichard Whitehouse <github@richardwhiuk.com>
Sat, 19 Feb 2011 23:28:25 +0000 (23:28 +0000)
committerRichard Whitehouse <github@richardwhiuk.com>
Sat, 19 Feb 2011 23:28:25 +0000 (23:28 +0000)
code/src/simulation/simulation.cc [new file with mode: 0644]
code/src/simulation/wscript [new file with mode: 0644]
code/src/wscript

diff --git a/code/src/simulation/simulation.cc b/code/src/simulation/simulation.cc
new file mode 100644 (file)
index 0000000..016a670
--- /dev/null
@@ -0,0 +1,100 @@
+/* -*- 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>
+ */
+
+// Topology
+//
+//   n0       n1
+//   |        |
+//  ------------      ------------
+//  | Switch 0 |------| Switch 2 |
+//  ------------      ------------
+//       |                  |
+//  ------------      ------------
+//  | Switch 1 |------| Switch 3 |
+//  ------------      ------------
+//       |
+//       n2
+//
+// - 100 Mb/s
+// - CBR/UDP flows from n0 to n1 and then from n0 to n2
+// - DropTail queues
+
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/core-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/bridge-module.h"
+
+#include <iostream>
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("MooseSimulation");
+
+int main (int argc, char *argv[])
+{
+
+  CommandLine cmd;                     // Allow CommandLine args
+  cmd.Parse (argc, argv);
+
+  // Moose Helper
+
+  MooseHelper moose;
+
+  // Setup Network
+
+  MooseHelper::Network n;
+
+  NS_LOG_INFO ("Configure Topology.");
+
+  n.t.bridges = 4;
+  n.t.hosts = 3;
+
+  // Link hosts to bridges
+
+  n.t.hostLinks[0] = 0;
+  n.t.hostLinks[1] = 0;
+  n.t.hostLinks[2] = 1; 
+
+  // Link the two bridges together
+  n.t.bridgeLinks.insert(std::make_pair<long,long>(0,1));
+  n.t.bridgeLinks.insert(std::make_pair<long,long>(0,2));
+  n.t.bridgeLinks.insert(std::make_pair<long,long>(1,3));
+  n.t.bridgeLinks.insert(std::make_pair<long,long>(2,3));
+
+  // Create Network
+
+  moose.Create(n);
+
+  // TODO: Apps
+
+  // Tracing
+
+  NS_LOG_INFO ("Configure Tracing.");
+
+  AsciiTraceHelper ascii;
+  moose.csma.EnableAsciiAll (ascii.CreateFileStream ("moose-bridge.tr"));
+
+  NS_LOG_INFO ("Run Simulation.");
+  Simulator::Run ();
+  Simulator::Destroy ();
+  NS_LOG_INFO ("Done.");
+
+}
+
diff --git a/code/src/simulation/wscript b/code/src/simulation/wscript
new file mode 100644 (file)
index 0000000..5cb063b
--- /dev/null
@@ -0,0 +1,16 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+
+    mod = bld.create_ns3_module('simulation')
+    mod.source = [
+        ]
+
+    headers = bld.new_task_gen('ns3header')
+    headers.module = 'simulation'
+    headers.source = []        
+
+    obj = bld.create_ns3_program('simulation', ['bridge', 'internet-stack'])
+
+    obj.source = 'simulation.cc'
+
index f7f405ba9ed185ad584b13e965b2435ee09519ff..0805d82cf680a414c475f3077d1751999ef9e5cc 100644 (file)
@@ -66,6 +66,7 @@ all_modules = (
     'contrib/topology-read',
     'contrib/energy',
     'tools/visualizer',
+    'simulation'
     )
 
 def set_options(opt):