From 5d59dfa2268dac02b2698846e2ef6b94ca5a73d3 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 25 Feb 2011 09:31:08 -0800 Subject: [PATCH] Remove dependency on PointToPointNetDevice from MPI code; organize MPI model/ directory --- .../point-to-point-net-device.cc | 7 +++ .../point-to-point-net-device.h | 6 ++- src/devices/point-to-point/wscript | 2 +- .../{ => model}/distributed-simulator-impl.cc | 0 .../{ => model}/distributed-simulator-impl.h | 0 src/mpi/{ => model}/mpi-interface.cc | 11 ++-- src/mpi/{ => model}/mpi-interface.h | 0 src/mpi/model/mpi-net-device.cc | 29 +++++++++++ src/mpi/model/mpi-net-device.h | 50 +++++++++++++++++++ src/mpi/wscript | 12 +++-- 10 files changed, 105 insertions(+), 12 deletions(-) rename src/mpi/{ => model}/distributed-simulator-impl.cc (100%) rename src/mpi/{ => model}/distributed-simulator-impl.h (100%) rename src/mpi/{ => model}/mpi-interface.cc (96%) rename src/mpi/{ => model}/mpi-interface.h (100%) create mode 100644 src/mpi/model/mpi-net-device.cc create mode 100644 src/mpi/model/mpi-net-device.h diff --git a/src/devices/point-to-point/point-to-point-net-device.cc b/src/devices/point-to-point/point-to-point-net-device.cc index bd75e0f9b..2e6a99ff3 100644 --- a/src/devices/point-to-point/point-to-point-net-device.cc +++ b/src/devices/point-to-point/point-to-point-net-device.cc @@ -25,6 +25,7 @@ #include "ns3/trace-source-accessor.h" #include "ns3/uinteger.h" #include "ns3/pointer.h" +#include "ns3/mpi-interface.h" #include "point-to-point-net-device.h" #include "point-to-point-channel.h" #include "ppp-header.h" @@ -561,6 +562,12 @@ PointToPointNetDevice::SupportsSendFrom (void) const return false; } +void +PointToPointNetDevice::DoMpiReceive (Ptr p) +{ + Receive (p); +} + Address PointToPointNetDevice::GetRemote (void) const { diff --git a/src/devices/point-to-point/point-to-point-net-device.h b/src/devices/point-to-point/point-to-point-net-device.h index db8dd6bc2..ccfadbf2d 100644 --- a/src/devices/point-to-point/point-to-point-net-device.h +++ b/src/devices/point-to-point/point-to-point-net-device.h @@ -30,6 +30,7 @@ #include "ns3/data-rate.h" #include "ns3/ptr.h" #include "ns3/mac48-address.h" +#include "ns3/mpi-net-device.h" namespace ns3 { @@ -49,7 +50,7 @@ class ErrorModel; * include a queue, data rate, and interframe transmission gap (the * propagation delay is set in the PointToPointChannel). */ -class PointToPointNetDevice : public NetDevice +class PointToPointNetDevice : public NetDevice, public MpiNetDevice { public: static TypeId GetTypeId (void); @@ -179,6 +180,9 @@ public: virtual void SetPromiscReceiveCallback (PromiscReceiveCallback cb); virtual bool SupportsSendFrom (void) const; +protected: + void DoMpiReceive (Ptr p); + private: virtual void DoDispose (void); diff --git a/src/devices/point-to-point/wscript b/src/devices/point-to-point/wscript index ca340f9ef..e738b3b41 100644 --- a/src/devices/point-to-point/wscript +++ b/src/devices/point-to-point/wscript @@ -2,7 +2,7 @@ def build(bld): - module = bld.create_ns3_module('point-to-point', ['network']) + module = bld.create_ns3_module('point-to-point', ['network', 'mpi']) module.source = [ 'point-to-point-net-device.cc', 'point-to-point-channel.cc', diff --git a/src/mpi/distributed-simulator-impl.cc b/src/mpi/model/distributed-simulator-impl.cc similarity index 100% rename from src/mpi/distributed-simulator-impl.cc rename to src/mpi/model/distributed-simulator-impl.cc diff --git a/src/mpi/distributed-simulator-impl.h b/src/mpi/model/distributed-simulator-impl.h similarity index 100% rename from src/mpi/distributed-simulator-impl.h rename to src/mpi/model/distributed-simulator-impl.h diff --git a/src/mpi/mpi-interface.cc b/src/mpi/model/mpi-interface.cc similarity index 96% rename from src/mpi/mpi-interface.cc rename to src/mpi/model/mpi-interface.cc index 368ee1474..8d0d7e450 100644 --- a/src/mpi/mpi-interface.cc +++ b/src/mpi/model/mpi-interface.cc @@ -24,10 +24,11 @@ #include #include "mpi-interface.h" +#include "mpi-net-device.h" #include "ns3/node.h" #include "ns3/node-list.h" -#include "ns3/point-to-point-net-device.h" +#include "ns3/net-device.h" #include "ns3/simulator.h" #include "ns3/simulator-impl.h" #include "ns3/nstime.h" @@ -235,13 +236,13 @@ MpiInterface::ReceiveMessages () // Find the correct node/device to schedule receive event Ptr pNode = NodeList::GetNode (node); uint32_t nDevices = pNode->GetNDevices (); - Ptr pDev = 0; + Ptr pMpiDev; for (uint32_t i = 0; i < nDevices; ++i) { Ptr pThisDev = pNode->GetDevice (i); if (pThisDev->GetIfIndex () == dev) { - pDev = DynamicCast (pThisDev); + pDev = DynamicCast (pThisDev); break; } } @@ -250,8 +251,8 @@ MpiInterface::ReceiveMessages () // Schedule the rx event Simulator::ScheduleWithContext (pNode->GetId (), rxTime - Simulator::Now (), - &PointToPointNetDevice::Receive, - pDev, p); + &MpiNetDevice::Receive, + pMpiDev, p); // Re-queue the next read MPI_Irecv (m_pRxBuffers[index], MAX_MPI_MSG_SIZE, MPI_CHAR, MPI_ANY_SOURCE, 0, diff --git a/src/mpi/mpi-interface.h b/src/mpi/model/mpi-interface.h similarity index 100% rename from src/mpi/mpi-interface.h rename to src/mpi/model/mpi-interface.h diff --git a/src/mpi/model/mpi-net-device.cc b/src/mpi/model/mpi-net-device.cc new file mode 100644 index 000000000..2e46456a9 --- /dev/null +++ b/src/mpi/model/mpi-net-device.cc @@ -0,0 +1,29 @@ +/* -*- 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: George Riley + */ + +#include "mpi-net-device.h" + +namespace ns3 { + +void +MpiNetDevice::MpiReceive (Ptr p) +{ + DoMpiReceive (p); +} + +} // namespace ns3 diff --git a/src/mpi/model/mpi-net-device.h b/src/mpi/model/mpi-net-device.h new file mode 100644 index 000000000..cb7fe5941 --- /dev/null +++ b/src/mpi/model/mpi-net-device.h @@ -0,0 +1,50 @@ +/* -*- 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: George Riley + */ + +// Provides a mixin interface to allow MPI-compatible NetDevices to inherit + +#ifndef NS3_MPI_NET_DEVICE_H +#define NS3_MPI_NET_DEVICE_H + +#include "ns3/packet.h" + +namespace ns3 { + +/** + * Class to mixin to a NetDevice if it supports MPI capability + * + * Subclass must implement DoMpiReceive to direct it to the device's + * normal Receive() method. + */ +class MpiNetDevice +{ +public: + /** + * + * Receive a packet + * + * \param p Ptr to the received packet. + */ + void MpiReceive (Ptr p); +protected: + virtual void DoMpiReceive (Ptr p) = 0; +}; + +} // namespace ns3 + +#endif /* NS3_MPI_NET_DEVICE_H */ diff --git a/src/mpi/wscript b/src/mpi/wscript index f1a54fdfa..d2f4b09c5 100644 --- a/src/mpi/wscript +++ b/src/mpi/wscript @@ -6,17 +6,19 @@ import Options def build(bld): env = bld.env_of_name('default') - sim = bld.create_ns3_module('mpi', ['core']) + sim = bld.create_ns3_module('mpi', ['core', 'network']) sim.source = [ - 'distributed-simulator-impl.cc', - 'mpi-interface.cc', + 'model/distributed-simulator-impl.cc', + 'model/mpi-interface.cc', + 'model/mpi-net-device.cc', ] headers = bld.new_task_gen('ns3header') headers.module = 'mpi' headers.source = [ - 'distributed-simulator-impl.h', - 'mpi-interface.h', + 'model/distributed-simulator-impl.h', + 'model/mpi-interface.h', + 'model/mpi-net-device.h', ] if env['ENABLE_MPI']: