make the sample code compile and link.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 12 Feb 2007 19:28:48 +0100
changeset 247 fb7375bb43d7
parent 246 612b3c16b24e
child 248 a912210e52ac
make the sample code compile and link.
SConstruct
samples/main-simple.cc
src/node/header-utils.cc
src/node/internet-node.cc
src/node/internet-node.h
src/node/net-device-list.cc
src/node/net-device-list.h
src/node/net-device.cc
src/node/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	Mon Feb 12 19:28:19 2007 +0100
+++ b/SConstruct	Mon Feb 12 19:28:48 2007 +0100
@@ -141,7 +141,7 @@
 
 node = build.Ns3Module ('node', 'src/node')
 ns3.add (node)
-node.add_deps (['core'])
+node.add_deps (['core', 'common', 'simulator'])
 node.add_sources ([
     'node.cc',
     'l3-demux.cc',
@@ -170,7 +170,11 @@
     'arp-ipv4-interface.cc',
     'arp.cc',
     'p2p-net-device.cc',
-    'p2p-channel.cc'
+    'p2p-channel.cc',
+    'ipv4-loopback-interface.cc',
+    'llc-snap-header.cc',
+    'header-utils.cc',
+    'net-device-list.cc'
     ])
 node.add_headers ([
     'ipv4-address.h',
@@ -188,20 +192,23 @@
     'arp-ipv4-interface.h',
     'arp.h',
     'p2p-net-device.h',
-    'p2p-channel.h'
-    ])
-node.add_inst_headers ([
-    'node.h',
+    'p2p-channel.h',
+    'ipv4-loopback-interface.h',
     'l3-demux.h',
     'l3-protocol.h',
     'ipv4-l4-demux.h',
     'net-device-list.h',
-    'internet-node.h',
     'net-device.h',
     'mac-address.h',
     'ipv4-route.h',
     'ipv4-interface.h',
     'udp-socket.h',
+    'llc-snap-header.h',
+    'header-utils.h',
+    ])
+node.add_inst_headers ([
+    'node.h',
+    'internet-node.h',
     ])
 
 
@@ -268,5 +275,12 @@
 sample_test.add_dep('core')
 sample_test.add_source('main-test.cc')
 
+sample_simple = build.Ns3Module('sample-simple', 'samples')
+sample_simple.set_executable()
+ns3.add(sample_simple)
+sample_simple.add_deps(['core', 'simulator', 'node'])
+sample_simple.add_source('main-simple.cc')
+
+
 
 ns3.generate_dependencies()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/samples/main-simple.cc	Mon Feb 12 19:28:48 2007 +0100
@@ -0,0 +1,17 @@
+#include "ns3/internet-node.h"
+#include "ns3/simulator.h"
+
+using namespace ns3;
+
+int main (int argc, char *argv[])
+{
+  InternetNode *a = new InternetNode ();
+
+  Simulator::Run ();
+
+  Simulator::Destroy ();
+
+  delete a;
+
+  return 0;
+}
--- a/src/node/header-utils.cc	Mon Feb 12 19:28:19 2007 +0100
+++ b/src/node/header-utils.cc	Mon Feb 12 19:28:48 2007 +0100
@@ -18,7 +18,7 @@
  *
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
-#include "chunk-utils.h"
+#include "header-utils.h"
 
 namespace ns3 {
 
@@ -30,7 +30,7 @@
 {
   uint8_t mac[MacAddress::MAX_LEN];
   ad.Peek (mac);
-  i.Write (mac, ad.GetLen ());
+  i.Write (mac, ad.GetLength ());
 }
 
 void ReadFrom (Buffer::Iterator &i, Ipv4Address &ad)
--- a/src/node/internet-node.cc	Mon Feb 12 19:28:19 2007 +0100
+++ b/src/node/internet-node.cc	Mon Feb 12 19:28:48 2007 +0100
@@ -31,6 +31,7 @@
 #include "arp.h"
 #include "udp-ipv4-l4-protocol.h"
 #include "arp-l3-protocol.h"
+#include "ipv4-loopback-interface.h"
 
 namespace ns3 {
 
@@ -46,6 +47,7 @@
   m_l3Demux->Insert (Ipv4L3Protocol (this));
   m_l3Demux->Insert (ArpL3Protocol (this));
   m_ipv4L4Demux->Insert (UdpIpv4L4Protocol (this));
+  SetupLoopback ();
 }
 
 InternetNode::InternetNode (InternetNode const &o)
@@ -56,6 +58,17 @@
   m_udp = o.m_udp->Copy (this);
   m_ipv4 = o.m_ipv4->Copy (this);
   m_arp = o.m_arp->Copy (this);
+  SetupLoopback ();
+}
+
+void
+InternetNode::SetupLoopback (void)
+{
+  Ipv4LoopbackInterface * interface = new Ipv4LoopbackInterface (this);
+  interface->SetAddress (Ipv4Address::GetLoopback ());
+  interface->SetNetworkMask (Ipv4Mask::GetLoopback ());
+  uint32_t index = m_ipv4->AddInterface (interface);
+  m_ipv4->AddHostRouteTo (Ipv4Address::GetLoopback (), index);
 }
 
 // Copy this node
@@ -85,4 +98,22 @@
   return m_ipv4L4Demux;
 }
 
+Ipv4 *
+InternetNode::GetIpv4 (void) const
+{
+  return m_ipv4;
+}
+Udp *
+InternetNode::GetUdp (void) const
+{
+  return m_udp;
+}
+
+Arp *
+InternetNode::GetArp (void) const
+{
+  return m_arp;
+}
+
+
 }//namespace ns3
--- a/src/node/internet-node.h	Mon Feb 12 19:28:19 2007 +0100
+++ b/src/node/internet-node.h	Mon Feb 12 19:28:48 2007 +0100
@@ -46,6 +46,7 @@
   virtual Arp *            GetArp (void) const;
 
 private:
+  void SetupLoopback (void);
   // Capabilities
   NetDeviceList*   m_netDevices;
   L3Demux*         m_l3Demux;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/node/net-device-list.cc	Mon Feb 12 19:28:48 2007 +0100
@@ -0,0 +1,50 @@
+// -*- 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>
+//
+// Manages the list of network device interfaces associated with a node.
+// George F. Riley, Georgia Tech, Spring 2007
+
+#include "net-device-list.h"
+
+namespace ns3 {
+
+NetDeviceList::NetDeviceList()
+{}
+NetDeviceList::~NetDeviceList()
+{
+  // XXX shall I delete each NetDevice ?
+}
+void
+NetDeviceList::Add(NetDevice *device)
+{
+  m_netdevices.push_back (device);
+}
+NetDeviceList::Iterator 
+NetDeviceList::Begin () const
+{
+  return m_netdevices.begin ();
+}
+NetDeviceList::Iterator 
+NetDeviceList::End () const
+{
+  return m_netdevices.end ();
+}
+
+}//namespace ns3
--- a/src/node/net-device-list.h	Mon Feb 12 19:28:19 2007 +0100
+++ b/src/node/net-device-list.h	Mon Feb 12 19:28:48 2007 +0100
@@ -1,4 +1,4 @@
-// -*- Mode:NS3 -*-
+// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
 //
 // Copyright (c) 2006 Georgia Tech Research Corporation
 // All rights reserved.
@@ -32,16 +32,16 @@
 
 class NetDeviceList {
 public:
-  typedef std::vector<NetDevice *>::iterator Iterator;
+  typedef std::vector<NetDevice *>::const_iterator Iterator;
 
   NetDeviceList();
   ~NetDeviceList();
   // Manage the list
-  NetDevice* Add(const NetDevice&);      // Add a new netdevice
+  void Add(NetDevice *device);
   NetDeviceList::Iterator Begin () const;
   NetDeviceList::Iterator End () const;
 public:
-  typedef std::vector<NetDevice *>::iterator NetDevices_t;
+  typedef std::vector<NetDevice *> NetDevices_t;
   NetDevices_t m_netdevices;
 };
 
--- a/src/node/net-device.cc	Mon Feb 12 19:28:19 2007 +0100
+++ b/src/node/net-device.cc	Mon Feb 12 19:28:48 2007 +0100
@@ -30,7 +30,7 @@
 
 namespace ns3 {
 
-NetDevice::NetDevice(Node& node, const MacAddress& addr) : 
+NetDevice::NetDevice(Node *node, const MacAddress& addr) : 
   m_node (node), 
   m_name(""), 
   m_ifIndex (0), 
@@ -40,8 +40,7 @@
   m_isBroadcast (false), 
   m_isMulticast (false), 
   m_isPointToPoint (false)
-{
-}
+{}
 
 MacAddress 
 NetDevice::GetAddress (void) const
@@ -172,9 +171,9 @@
   LlcSnapHeader llc;
   packet.Peek (llc);
   packet.Remove (llc);
-  if (GetNode().GetL3Demux() != 0)
+  if (GetNode()->GetL3Demux() != 0)
     {
-      L3Protocol *target = GetNode().GetL3Demux()->Lookup(llc.GetType ());
+      L3Protocol *target = GetNode()->GetL3Demux()->Lookup(llc.GetType ());
       if (target != 0) 
         {
           target->Receive(packet, *this);
@@ -204,7 +203,7 @@
     }
 }
 
-Node&
+Node *
 NetDevice::GetNode (void) const
 {
   return m_node;
--- a/src/node/net-device.h	Mon Feb 12 19:28:19 2007 +0100
+++ b/src/node/net-device.h	Mon Feb 12 19:28:48 2007 +0100
@@ -56,7 +56,7 @@
   /**
    * \param node base class node pointer of device's node 
    */
-  NetDevice(Node& node, const MacAddress& addr);
+  NetDevice(Node* node, const MacAddress& addr);
   virtual ~NetDevice() {}
   /**
    * \return the current MacAddress of this interface.
@@ -177,7 +177,7 @@
    * base class to print the nodeid for example, it can invoke
    * this method.
    */
-  Node& GetNode (void) const;
+  Node* GetNode (void) const;
 
   /**
    * \param p packet sent from below up to Network Device
@@ -204,7 +204,7 @@
    * MUST override this method.
    */
   virtual bool SendTo (Packet& p, const MacAddress& dest) = 0;
-  Node&         m_node;
+  Node*         m_node;
   std::string   m_name;
   uint16_t      m_ifIndex;
   MacAddress    m_address;
--- a/src/node/p2p-channel.cc	Mon Feb 12 19:28:19 2007 +0100
+++ b/src/node/p2p-channel.cc	Mon Feb 12 19:28:48 2007 +0100
@@ -37,8 +37,11 @@
 {
 }
 
+P2PChannel::~P2PChannel ()
+{}
+
 // Channels create compatible net devices
-P2PNetDevice* P2PChannel::CreateNetDevice(Node &node, MacAddress address)
+P2PNetDevice* P2PChannel::CreateNetDevice(Node *node, MacAddress address)
 {
   // Create a new point-to-point network device
   P2PNetDevice* nd = new P2PNetDevice(node, address);
--- a/src/node/p2p-channel.h	Mon Feb 12 19:28:19 2007 +0100
+++ b/src/node/p2p-channel.h	Mon Feb 12 19:28:48 2007 +0100
@@ -40,7 +40,7 @@
   P2PChannel(const Time& delay, double maxRate /* bits/s */);
   ~P2PChannel();
 
-  P2PNetDevice* CreateNetDevice(Node &node, MacAddress address);
+  P2PNetDevice* CreateNetDevice(Node *node, MacAddress address);
   void       RemoveNetDevice (NetDevice *device);
   void       Send (P2PNetDevice *device, Packet&p, double rate /* bits/s */);
 private:
--- a/src/node/p2p-net-device.cc	Mon Feb 12 19:28:19 2007 +0100
+++ b/src/node/p2p-net-device.cc	Mon Feb 12 19:28:48 2007 +0100
@@ -27,7 +27,7 @@
 
 namespace ns3 {
 
-P2PNetDevice::P2PNetDevice (Node &node, MacAddress const &addr)
+P2PNetDevice::P2PNetDevice (Node *node, MacAddress const &addr)
   : NetDevice (node, addr)
 {}
 
--- a/src/node/p2p-net-device.h	Mon Feb 12 19:28:19 2007 +0100
+++ b/src/node/p2p-net-device.h	Mon Feb 12 19:28:48 2007 +0100
@@ -33,7 +33,7 @@
 
 class P2PNetDevice : public NetDevice {
 public:
-  P2PNetDevice(Node &node, MacAddress const &addr);
+  P2PNetDevice(Node *node, MacAddress const &addr);
   virtual ~P2PNetDevice();
 
   void SetRate (double Rate);