GetNetDevice method in PointToPointTopology class
authorTom Henderson <tomh@tomh.org>
Wed, 14 Nov 2007 20:50:53 -0800
changeset 1821 c6d74a0bce7f
parent 1820 736919bd4874
child 1822 056a2eb1e924
GetNetDevice method in PointToPointTopology class
src/devices/point-to-point/point-to-point-topology.cc
src/devices/point-to-point/point-to-point-topology.h
--- a/src/devices/point-to-point/point-to-point-topology.cc	Wed Nov 14 20:40:05 2007 -0800
+++ b/src/devices/point-to-point/point-to-point-topology.cc	Wed Nov 14 20:50:53 2007 -0800
@@ -62,6 +62,30 @@
   return channel;
 }
 
+Ptr<PointToPointNetDevice> 
+PointToPointTopology::GetNetDevice (Ptr<Node> n, Ptr<PointToPointChannel> chan)
+{
+  Ptr<PointToPointNetDevice> found = 0;
+
+  // The PointToPoint channel is used to find the relevant NetDevice
+  NS_ASSERT (chan->GetNDevices () == 2);
+  Ptr<PointToPointNetDevice> nd1 = chan->GetDevice (0);
+  Ptr<PointToPointNetDevice> nd2 = chan->GetDevice (1);
+  if ( nd1->GetNode ()->GetId () == n->GetId () ) 
+    {
+      found = nd1;
+    }
+  else if ( nd2->GetNode ()->GetId () == n->GetId () ) 
+    {
+      found = nd2;
+    }
+  else
+    {
+      NS_ASSERT (found);
+    }
+  return found;
+}
+
 void
 PointToPointTopology::AddIpv4Addresses(
   Ptr<const PointToPointChannel> chan,
--- a/src/devices/point-to-point/point-to-point-topology.h	Wed Nov 14 20:40:05 2007 -0800
+++ b/src/devices/point-to-point/point-to-point-topology.h	Wed Nov 14 20:50:53 2007 -0800
@@ -56,6 +56,17 @@
     Ptr<Node> n1, Ptr<Node> n2, const DataRate& dataRate, const Time& delay);
 
   /** 
+   * \param n Node
+   * \param chan PointToPointChannel connected to node n
+   * \return Pointer to the corresponding PointToPointNetDevice
+   * 
+   * Utility function to retrieve a PointToPointNetDevice pointer
+   * corresponding to the input parameters
+   */
+  static Ptr<PointToPointNetDevice> GetNetDevice(
+    Ptr<Node> n, Ptr<PointToPointChannel> chan);
+
+  /** 
    * \param chan PointToPointChannel to use
    * \param n1 Node
    * \param addr1 Ipv4 Address for n1