Remove dependency on PointToPointNetDevice from MPI code
authorTom Henderson <tomh@tomh.org>
Fri, 11 Feb 2011 13:45:55 -0800
changeset 6817 81e054791774
parent 6816 53fc7da1cdb2
child 6818 2945366f648c
Remove dependency on PointToPointNetDevice from MPI code
src/devices/point-to-point/point-to-point-net-device.cc
src/devices/point-to-point/point-to-point-net-device.h
src/devices/point-to-point/wscript
src/mpi/mpi-interface.cc
src/mpi/mpi-net-device.cc
src/mpi/mpi-net-device.h
src/mpi/wscript
--- a/src/devices/point-to-point/point-to-point-net-device.cc	Fri Feb 11 13:45:24 2011 -0800
+++ b/src/devices/point-to-point/point-to-point-net-device.cc	Fri Feb 11 13:45:55 2011 -0800
@@ -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 @@
   return false;
 }
 
+void
+PointToPointNetDevice::DoMpiReceive (Ptr<Packet> p)
+{
+  Receive (p);
+}
+
 Address 
 PointToPointNetDevice::GetRemote (void) const
 {
--- a/src/devices/point-to-point/point-to-point-net-device.h	Fri Feb 11 13:45:24 2011 -0800
+++ b/src/devices/point-to-point/point-to-point-net-device.h	Fri Feb 11 13:45:55 2011 -0800
@@ -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 @@
  * 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 @@
   virtual void SetPromiscReceiveCallback (PromiscReceiveCallback cb);
   virtual bool SupportsSendFrom (void) const;
 
+protected:
+  void DoMpiReceive (Ptr<Packet> p);
+
 private:
 
   virtual void DoDispose (void);
--- a/src/devices/point-to-point/wscript	Fri Feb 11 13:45:24 2011 -0800
+++ b/src/devices/point-to-point/wscript	Fri Feb 11 13:45:55 2011 -0800
@@ -2,7 +2,7 @@
 
 
 def build(bld):
-    module = bld.create_ns3_module('point-to-point', ['internet'])
+    module = bld.create_ns3_module('point-to-point', ['internet', 'mpi'])
     module.source = [
         'point-to-point-net-device.cc',
         'point-to-point-channel.cc',
--- a/src/mpi/mpi-interface.cc	Fri Feb 11 13:45:24 2011 -0800
+++ b/src/mpi/mpi-interface.cc	Fri Feb 11 13:45:55 2011 -0800
@@ -24,10 +24,11 @@
 #include <list>
 
 #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 @@
       // Find the correct node/device to schedule receive event
       Ptr<Node> pNode = NodeList::GetNode (node);
       uint32_t nDevices = pNode->GetNDevices ();
-      Ptr<PointToPointNetDevice> pDev = 0;
+      Ptr<MpiNetDevice> pMpiDev;
       for (uint32_t i = 0; i < nDevices; ++i)
         {
           Ptr<NetDevice> pThisDev = pNode->GetDevice (i);
           if (pThisDev->GetIfIndex () == dev)
             {
-              pDev = DynamicCast<PointToPointNetDevice> (pThisDev);
+              pDev = DynamicCast<MpiNetDevice> (pThisDev);
               break;
             }
         }
@@ -250,8 +251,8 @@
 
       // 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,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/mpi/mpi-net-device.cc	Fri Feb 11 13:45:55 2011 -0800
@@ -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 <riley@ece.gatech.edu>
+ */
+
+#include "mpi-net-device.h"
+
+namespace ns3 {
+
+void
+MpiNetDevice::MpiReceive (Ptr<Packet> p)
+{
+  DoMpiReceive (p);
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/mpi/mpi-net-device.h	Fri Feb 11 13:45:55 2011 -0800
@@ -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 <riley@ece.gatech.edu>
+ */
+
+// 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<Packet> p);
+protected:
+  virtual void DoMpiReceive (Ptr<Packet> p) = 0;
+};
+
+} // namespace ns3
+
+#endif /* NS3_MPI_NET_DEVICE_H */
--- a/src/mpi/wscript	Fri Feb 11 13:45:24 2011 -0800
+++ b/src/mpi/wscript	Fri Feb 11 13:45:55 2011 -0800
@@ -10,6 +10,7 @@
   sim.source = [
       'distributed-simulator-impl.cc',
       'mpi-interface.cc',
+      'mpi-net-device.cc',
       ]
 
   headers = bld.new_task_gen('ns3header')
@@ -17,6 +18,7 @@
   headers.source = [
       'distributed-simulator-impl.h',
       'mpi-interface.h',
+      'mpi-net-device.h',
       ]
 
   if env['ENABLE_MPI']: