From: Richard Whitehouse Date: Mon, 14 Mar 2011 13:30:27 +0000 (+0000) Subject: Separated Topology into separate module X-Git-Url: https://git.richardwhiuk.com/?a=commitdiff_plain;h=a1617499c1593bce1ba5c3d480dca20fcfe32e7b;p=ns-moose.git Separated Topology into separate module --- diff --git a/code/src/helper/moose-helper.h b/code/src/helper/moose-helper.h index cb52017..2b26d70 100644 --- a/code/src/helper/moose-helper.h +++ b/code/src/helper/moose-helper.h @@ -21,6 +21,7 @@ #ifndef MOOSE_HELPER_H #define MOOSE_HELPER_H +#include "ns3/topology.h" #include "ns3/node.h" #include "ns3/moose-bridge-net-device.h" #include "ns3/moose-bridge-helper.h" @@ -52,41 +53,6 @@ public: typedef boost::graph_traits< graph_t >::vertex_descriptor vertex_descriptor; typedef boost::graph_traits< graph_t >::edge_descriptor edge_descriptor; - struct Topology { - - public: - long bridges; - long hosts; - typedef std::map HostLinks; - typedef std::pair BridgeLink; - - struct BridgeLinkCompare { - // we don't care about ordering inside a pair, but we do care about pair order - - bool operator()( BridgeLink const &lhs, BridgeLink const &rhs) { - if(lhs.first < lhs.first){ - if(rhs.first < rhs.second){ - return (lhs.first < rhs.first) ? true : (lhs.second < rhs.second); - } else { - return (lhs.first < rhs.second) ? true : (lhs.second < rhs.first); - } - } else { - if(rhs.first < rhs.second){ - return (lhs.second < rhs.first) ? true : (lhs.first < rhs.second); - } else { - return (lhs.second < rhs.second) ? true : (lhs.first < rhs.first); - } - } - } - }; - - typedef std::set BridgeLinks; - - HostLinks hostLinks; - BridgeLinks bridgeLinks; - - }; - struct Network { Topology t; diff --git a/code/src/topology/model/topology.cc b/code/src/topology/model/topology.cc new file mode 100644 index 0000000..09941a0 --- /dev/null +++ b/code/src/topology/model/topology.cc @@ -0,0 +1,45 @@ +/* -*- 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 "topology.h" +#include "ns3/log.h" + +NS_LOG_COMPONENT_DEFINE ("MooseHelper"); + +namespace ns3 { + +bool Topology::BridgeLinkCompare::operator()( BridgeLink const &lhs, BridgeLink const &rhs) { + if(lhs.first < lhs.first){ + if(rhs.first < rhs.second){ + return (lhs.first < rhs.first) ? true : (lhs.second < rhs.second); + } else { + return (lhs.first < rhs.second) ? true : (lhs.second < rhs.first); + } + } else { + if(rhs.first < rhs.second){ + return (lhs.second < rhs.first) ? true : (lhs.first < rhs.second); + } else { + return (lhs.second < rhs.second) ? true : (lhs.first < rhs.first); + } + } +} + + +} diff --git a/code/src/topology/model/topology.h b/code/src/topology/model/topology.h new file mode 100644 index 0000000..af65141 --- /dev/null +++ b/code/src/topology/model/topology.h @@ -0,0 +1,60 @@ +/* -*- 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_H +#define TOPOLOGY_H + +#include +#include + +namespace ns3 { + +/** + * \ingroup topology + * + * \brief Represents a topology + */ + +struct Topology { + +public: + long bridges; + long hosts; + typedef std::map HostLinks; + typedef std::pair BridgeLink; + + struct BridgeLinkCompare { + // we don't care about ordering inside a pair, but we do care about pair order + + bool operator()( BridgeLink const &lhs, BridgeLink const &rhs); + + }; + + typedef std::set BridgeLinks; + + HostLinks hostLinks; + BridgeLinks bridgeLinks; + +}; + +} + +#endif + diff --git a/code/src/topology/wscript b/code/src/topology/wscript new file mode 100644 index 0000000..5ebd5a7 --- /dev/null +++ b/code/src/topology/wscript @@ -0,0 +1,13 @@ +## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- + +def build(bld): + obj = bld.create_ns3_module('topology', ['node']) + obj.source = [ + 'model/topology.cc' + ] + headers = bld.new_task_gen('ns3header') + headers.module = 'topology' + headers.source = [ + 'model/topology.h' + ] + diff --git a/code/src/wscript b/code/src/wscript index 0805d82..c536721 100644 --- a/code/src/wscript +++ b/code/src/wscript @@ -66,6 +66,7 @@ all_modules = ( 'contrib/topology-read', 'contrib/energy', 'tools/visualizer', + 'topology', 'simulation' )