From 9980eb3fb9b6d7699cc07f70afd0b58abce55365 Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Mon, 14 Mar 2011 14:36:15 +0000 Subject: [PATCH] Added torus topology --- code/src/topology/helper/torus.cc | 84 +++++++++++++++++++++++++++++++ code/src/topology/helper/torus.h | 39 ++++++++++++++ code/src/topology/wscript | 6 ++- 3 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 code/src/topology/helper/torus.cc create mode 100644 code/src/topology/helper/torus.h diff --git a/code/src/topology/helper/torus.cc b/code/src/topology/helper/torus.cc new file mode 100644 index 0000000..fc82140 --- /dev/null +++ b/code/src/topology/helper/torus.cc @@ -0,0 +1,84 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2008,2009 IITP RAS + * + * 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 + */ + +#include "torus.h" +#include "ns3/log.h" + +NS_LOG_COMPONENT_DEFINE ("Torus_Topology_Helper"); + +namespace ns3 { + +Topology Torus_Topology_Helper::Create(long hosts, long size){ + + Topology t; + + t.bridges = size * size * size; + + t.hosts = t.bridges * hosts; + + long i; long j; long k; + + for(i = 0; i < t.bridges; ++i){ + for(j = 0; j < hosts; ++j){ + t.hostLinks[(i*hosts) + j] = i; + } + } + + if(size > 1){ + + for(i = 0; i < size; ++i){ + for(j = 0; j < size; ++j){ + for(k = 0; k < size; ++k){ + // Three links + + // number of node = (i * size * size) + (j * size) + k + + long me = (i * size * size) + (j * size) + k; + + if((k + 1) < size){ + t.bridgeLinks.insert(std::make_pair(me, ((i * size * size) + (j * size) + k + 1) )); + } else { + t.bridgeLinks.insert(std::make_pair(me, ((i * size * size) + (j * size) ) )); + } + + if((j + 1) < size){ + t.bridgeLinks.insert(std::make_pair(me, ((i * size * size) + ((j + 1) * size) + k) )); + } else { + t.bridgeLinks.insert(std::make_pair(me, (i * size * size) + k) ); + } + + if((i + 1) < size){ + t.bridgeLinks.insert(std::make_pair(me, (((i + 1) * size * size) + (j * size) + k) )); + } else { + t.bridgeLinks.insert(std::make_pair(me, ((j * size) + k) )); + } + } + } + } + + } + + return t; + +} + + +} + diff --git a/code/src/topology/helper/torus.h b/code/src/topology/helper/torus.h new file mode 100644 index 0000000..2f00d9f --- /dev/null +++ b/code/src/topology/helper/torus.h @@ -0,0 +1,39 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2008,2009 IITP RAS + * + * 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 + */ + +#ifndef TOPOLOGY_TORUS_H +#define TOPOLOGY_TORUS_H + +#include "ns3/topology.h" + +namespace ns3 { + +class Torus_Topology_Helper { + +public: + + Topology Create(long hosts, long size); + +}; + +} + +#endif + diff --git a/code/src/topology/wscript b/code/src/topology/wscript index 6ea3ee6..2306f2d 100644 --- a/code/src/topology/wscript +++ b/code/src/topology/wscript @@ -4,12 +4,14 @@ def build(bld): obj = bld.create_ns3_module('topology', ['node']) obj.source = [ 'model/topology.cc', - 'helper/cube.cc' + 'helper/cube.cc', + 'helper/torus.cc' ] headers = bld.new_task_gen('ns3header') headers.module = 'topology' headers.source = [ 'model/topology.h', - 'helper/cube.h' + 'helper/cube.h', + 'helper/torus.h' ] -- 2.34.1