move p2p to new dir
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 22 Feb 2007 09:51:54 +0100
changeset 331 d75ee9d8efa4
parent 330 223a085b3adb
child 332 3e05be7e69e5
move p2p to new dir
SConstruct
src/devices/p2p/p2p-channel.cc
src/devices/p2p/p2p-channel.h
src/devices/p2p/p2p-net-device.cc
src/devices/p2p/p2p-net-device.h
src/node/p2p-channel.cc
src/node/p2p-channel.h
src/node/p2p-net-device.cc
src/node/p2p-net-device.h
--- a/SConstruct	Thu Feb 22 09:40:46 2007 +0100
+++ b/SConstruct	Thu Feb 22 09:51:54 2007 +0100
@@ -189,8 +189,6 @@
     'arp-cache.cc',
     'arp-ipv4-interface.cc',
     'arp.cc',
-    'p2p-net-device.cc',
-    'p2p-channel.cc',
     'ipv4-loopback-interface.cc',
     'llc-snap-header.cc',
     'header-utils.cc',
@@ -228,8 +226,6 @@
     'udp-socket.h',
     'ipv4-address.h',
     'net-device.h',
-    'p2p-net-device.h',
-    'p2p-channel.h',
     'arp-ipv4-interface.h',
     'ipv4-interface.h',
     'mac-address.h',
@@ -248,6 +244,18 @@
     'udp-header.h',
     ])
 
+p2p = build.Ns3Module ('p2p', 'src/devices/p2p')
+ns3.add (p2p)
+p2p.add_deps (['node'])
+p2p.add_sources ([
+    'p2p-net-device.cc',
+    'p2p-channel.cc',
+    ])
+p2p.add_inst_headers ([
+    'p2p-net-device.h',
+    'p2p-channel.h',
+    ])
+
 
 # utils
 run_tests = build.Ns3Module('run-tests', 'utils')
@@ -335,7 +343,7 @@
 sample_sp2p = build.Ns3Module('sample-simple-p2p', 'samples')
 sample_sp2p.set_executable()
 ns3.add(sample_sp2p)
-sample_sp2p.add_deps(['core', 'simulator', 'node'])
+sample_sp2p.add_deps(['core', 'simulator', 'node', 'p2p'])
 sample_sp2p.add_source('main-simple-p2p.cc')
 
 sample_simple_tcl = build.Ns3Module('sample-simple.tcl', 'samples')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/p2p/p2p-channel.cc	Thu Feb 22 09:51:54 2007 +0100
@@ -0,0 +1,98 @@
+// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-
+//
+// Copyright (c) 2006 Georgia Tech Research Corporation
+// All rights reserved.
+//
+// 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 F. Riley<riley@ece.gatech.edu>
+//
+
+// Implementation of simple point-to-point channel
+// George F. Riley, Georgia Tech, Spring 2007
+
+#include "ns3/simulator.h"
+#include "ns3/packet.h"
+#include "ns3/node.h"
+#include "p2p-channel.h"
+#include "p2p-net-device.h"
+
+namespace ns3 {
+
+P2PChannel::P2PChannel(const Time& delay, double maxRate) 
+  : m_nd1(0), m_nd2(0),
+    m_delay (delay),
+    m_maxRate (maxRate)
+{
+}
+
+P2PChannel::~P2PChannel ()
+{}
+
+// Channels create compatible net devices
+P2PNetDevice* P2PChannel::CreateNetDevice(Node *node, MacAddress address)
+{
+  // Create a new point-to-point network device
+  P2PNetDevice* nd = new P2PNetDevice(node, address);
+  nd->Connect (this);
+  // Add to list of peers
+  if (!m_nd1) m_nd1 = nd;
+  else m_nd2 = nd;
+  return nd;
+}
+
+void P2PChannel::RemoveNetDevice(NetDevice* nd)
+{
+  if (nd == m_nd1) m_nd1 = 0;
+  if (nd == m_nd2) m_nd2 = 0;
+  // Now if all removed, remove the channel as well
+  if (!m_nd1 && !m_nd2)
+    {
+      delete this;
+    }
+}
+
+void P2PChannel::Send(P2PNetDevice *device, Packet& p, double rate)
+{ // Schedule a receive event at receiver
+  // First calculate time in future
+  double maxRate;
+  if (rate < m_maxRate)
+    {
+      maxRate = rate;
+    } 
+  else
+    {
+      maxRate = m_maxRate;
+    }
+  Time txTime = Seconds (p.GetSize() * 8 / maxRate);
+  Time rxTime = m_delay + txTime;
+  P2PNetDevice *to, *from;
+  if (device == m_nd1)
+    {
+      from = m_nd1;
+      to = m_nd2;
+    }
+  else
+    {
+      from = m_nd2;
+      to = m_nd1;
+    }
+  // Schedule the receive event at receiver
+  Simulator::Schedule(rxTime, &P2PNetDevice::Receive, to, p);
+  // Schedule the link free event
+  Simulator::Schedule(txTime, &P2PNetDevice::TxComplete, from);
+
+}
+
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/p2p/p2p-channel.h	Thu Feb 22 09:51:54 2007 +0100
@@ -0,0 +1,56 @@
+// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-
+//
+// Copyright (c) 2006 Georgia Tech Research Corporation
+// All rights reserved.
+//
+// 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 F. Riley<riley@ece.gatech.edu>
+//
+
+// Definition of a simple point-to-point channel
+// George F. Riley, Georgia Tech, Spring 2007
+
+#ifndef P2P_CHANNEL_H
+#define P2P_CHANNEL_H
+
+#include "ns3/nstime.h"
+#include "ns3/mac-address.h"
+
+namespace ns3 {
+
+class P2PNetDevice;
+class NetDevice;
+class Node;
+class Packet;
+
+class P2PChannel  {
+public:
+  P2PChannel(const Time& delay, double maxRate /* bits/s */);
+  ~P2PChannel();
+
+  P2PNetDevice* CreateNetDevice(Node *node, MacAddress address);
+  void       RemoveNetDevice (NetDevice *device);
+  void       Send (P2PNetDevice *device, Packet&p, double rate /* bits/s */);
+private:
+  // The two endpoints of this channel
+  P2PNetDevice* m_nd1;
+  P2PNetDevice* m_nd2;
+  Time          m_delay;
+  double        m_maxRate;
+};
+
+}//namespace ns3
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/p2p/p2p-net-device.cc	Thu Feb 22 09:51:54 2007 +0100
@@ -0,0 +1,73 @@
+// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-
+//
+// Copyright (c) 2006 Georgia Tech Research Corporation
+// All rights reserved.
+//
+// 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 F. Riley<riley@ece.gatech.edu>
+//
+
+// Implementation of a point-to-point network device
+// George F. Riley, Georgia Tech, Spring 2007
+
+#include "p2p-net-device.h"
+#include "p2p-channel.h"
+
+namespace ns3 {
+
+P2PNetDevice::P2PNetDevice (Node *node, MacAddress const &addr)
+  : NetDevice (node, addr),
+    m_rate (1000000)
+{
+  SetMtu (2300);
+  EnableBroadcast (MacAddress ("ff:ff:ff:ff:ff:ff"));
+}
+
+P2PNetDevice::~P2PNetDevice()
+{ // Inform channel that we are destroyed
+  m_channel->RemoveNetDevice(this);
+}
+
+void 
+P2PNetDevice::SetRate (double rate)
+{
+  m_rate = rate;
+}
+
+void 
+P2PNetDevice::Connect (P2PChannel *channel)
+{
+  m_channel = channel;
+  NotifyLinkUp ();
+}
+
+bool 
+P2PNetDevice::SendTo (Packet& p, const MacAddress&)
+{
+  m_channel->Send (this, p, m_rate);
+  return true;
+}
+
+void
+P2PNetDevice::Receive(Packet p)
+{
+  ForwardUp (p);
+}
+
+void 
+P2PNetDevice::TxComplete (void)
+{}
+
+}//namespace ns3  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/p2p/p2p-net-device.h	Thu Feb 22 09:51:54 2007 +0100
@@ -0,0 +1,52 @@
+// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-
+//
+// Copyright (c) 2006 Georgia Tech Research Corporation
+// All rights reserved.
+//
+// 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 F. Riley<riley@ece.gatech.edu>
+//
+
+// Definition for a Point-to-Point network device
+// George F. Riley, Georgia Tech, Spring 2007
+
+#ifndef P2P_NET_DEVICE_H
+#define P2P_NET_DEVICE_H
+
+#include "ns3/net-device.h"
+
+namespace ns3 {
+
+class P2PChannel;
+
+class P2PNetDevice : public NetDevice {
+public:
+  P2PNetDevice(Node *node, MacAddress const &addr);
+  virtual ~P2PNetDevice();
+
+  void SetRate (double rate);
+  void Connect (P2PChannel *channel);
+  void Receive(Packet p);
+  void TxComplete (void);
+ private:
+  virtual bool SendTo (Packet& p, const MacAddress& dest);
+  double m_rate;
+  P2PChannel *m_channel;
+};
+
+}//namespace ns3
+
+#endif /* P2P_NET_DEVICE_H */
+
--- a/src/node/p2p-channel.cc	Thu Feb 22 09:40:46 2007 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,98 +0,0 @@
-// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-
-//
-// Copyright (c) 2006 Georgia Tech Research Corporation
-// All rights reserved.
-//
-// 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 F. Riley<riley@ece.gatech.edu>
-//
-
-// Implementation of simple point-to-point channel
-// George F. Riley, Georgia Tech, Spring 2007
-
-#include "ns3/simulator.h"
-#include "ns3/packet.h"
-#include "p2p-channel.h"
-#include "p2p-net-device.h"
-#include "node.h"
-
-namespace ns3 {
-
-P2PChannel::P2PChannel(const Time& delay, double maxRate) 
-  : m_nd1(0), m_nd2(0),
-    m_delay (delay),
-    m_maxRate (maxRate)
-{
-}
-
-P2PChannel::~P2PChannel ()
-{}
-
-// Channels create compatible net devices
-P2PNetDevice* P2PChannel::CreateNetDevice(Node *node, MacAddress address)
-{
-  // Create a new point-to-point network device
-  P2PNetDevice* nd = new P2PNetDevice(node, address);
-  nd->Connect (this);
-  // Add to list of peers
-  if (!m_nd1) m_nd1 = nd;
-  else m_nd2 = nd;
-  return nd;
-}
-
-void P2PChannel::RemoveNetDevice(NetDevice* nd)
-{
-  if (nd == m_nd1) m_nd1 = 0;
-  if (nd == m_nd2) m_nd2 = 0;
-  // Now if all removed, remove the channel as well
-  if (!m_nd1 && !m_nd2)
-    {
-      delete this;
-    }
-}
-
-void P2PChannel::Send(P2PNetDevice *device, Packet& p, double rate)
-{ // Schedule a receive event at receiver
-  // First calculate time in future
-  double maxRate;
-  if (rate < m_maxRate)
-    {
-      maxRate = rate;
-    } 
-  else
-    {
-      maxRate = m_maxRate;
-    }
-  Time txTime = Seconds (p.GetSize() * 8 / maxRate);
-  Time rxTime = m_delay + txTime;
-  P2PNetDevice *to, *from;
-  if (device == m_nd1)
-    {
-      from = m_nd1;
-      to = m_nd2;
-    }
-  else
-    {
-      from = m_nd2;
-      to = m_nd1;
-    }
-  // Schedule the receive event at receiver
-  Simulator::Schedule(rxTime, &P2PNetDevice::Receive, to, p);
-  // Schedule the link free event
-  Simulator::Schedule(txTime, &P2PNetDevice::TxComplete, from);
-
-}
-
-}//namespace ns3
--- a/src/node/p2p-channel.h	Thu Feb 22 09:40:46 2007 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-
-//
-// Copyright (c) 2006 Georgia Tech Research Corporation
-// All rights reserved.
-//
-// 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 F. Riley<riley@ece.gatech.edu>
-//
-
-// Definition of a simple point-to-point channel
-// George F. Riley, Georgia Tech, Spring 2007
-
-#ifndef P2P_CHANNEL_H
-#define P2P_CHANNEL_H
-
-#include "ns3/nstime.h"
-#include "mac-address.h"
-
-namespace ns3 {
-
-class P2PNetDevice;
-class NetDevice;
-class Node;
-class Packet;
-
-class P2PChannel  {
-public:
-  P2PChannel(const Time& delay, double maxRate /* bits/s */);
-  ~P2PChannel();
-
-  P2PNetDevice* CreateNetDevice(Node *node, MacAddress address);
-  void       RemoveNetDevice (NetDevice *device);
-  void       Send (P2PNetDevice *device, Packet&p, double rate /* bits/s */);
-private:
-  // The two endpoints of this channel
-  P2PNetDevice* m_nd1;
-  P2PNetDevice* m_nd2;
-  Time          m_delay;
-  double        m_maxRate;
-};
-
-}//namespace ns3
-
-#endif
--- a/src/node/p2p-net-device.cc	Thu Feb 22 09:40:46 2007 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-
-//
-// Copyright (c) 2006 Georgia Tech Research Corporation
-// All rights reserved.
-//
-// 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 F. Riley<riley@ece.gatech.edu>
-//
-
-// Implementation of a point-to-point network device
-// George F. Riley, Georgia Tech, Spring 2007
-
-#include "p2p-net-device.h"
-#include "p2p-channel.h"
-
-namespace ns3 {
-
-P2PNetDevice::P2PNetDevice (Node *node, MacAddress const &addr)
-  : NetDevice (node, addr),
-    m_rate (1000000)
-{
-  SetMtu (2300);
-  EnableBroadcast (MacAddress ("ff:ff:ff:ff:ff:ff"));
-}
-
-P2PNetDevice::~P2PNetDevice()
-{ // Inform channel that we are destroyed
-  m_channel->RemoveNetDevice(this);
-}
-
-void 
-P2PNetDevice::SetRate (double rate)
-{
-  m_rate = rate;
-}
-
-void 
-P2PNetDevice::Connect (P2PChannel *channel)
-{
-  m_channel = channel;
-  NotifyLinkUp ();
-}
-
-bool 
-P2PNetDevice::SendTo (Packet& p, const MacAddress&)
-{
-  m_channel->Send (this, p, m_rate);
-  return true;
-}
-
-void
-P2PNetDevice::Receive(Packet p)
-{
-  ForwardUp (p);
-}
-
-void 
-P2PNetDevice::TxComplete (void)
-{}
-
-}//namespace ns3  
--- a/src/node/p2p-net-device.h	Thu Feb 22 09:40:46 2007 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-
-//
-// Copyright (c) 2006 Georgia Tech Research Corporation
-// All rights reserved.
-//
-// 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 F. Riley<riley@ece.gatech.edu>
-//
-
-// Definition for a Point-to-Point network device
-// George F. Riley, Georgia Tech, Spring 2007
-
-#ifndef P2P_NET_DEVICE_H
-#define P2P_NET_DEVICE_H
-
-#include "net-device.h"
-
-namespace ns3 {
-
-class P2PChannel;
-
-class P2PNetDevice : public NetDevice {
-public:
-  P2PNetDevice(Node *node, MacAddress const &addr);
-  virtual ~P2PNetDevice();
-
-  void SetRate (double rate);
-  void Connect (P2PChannel *channel);
-  void Receive(Packet p);
-  void TxComplete (void);
- private:
-  virtual bool SendTo (Packet& p, const MacAddress& dest);
-  double m_rate;
-  P2PChannel *m_channel;
-};
-
-}//namespace ns3
-
-#endif /* P2P_NET_DEVICE_H */
-