move code around
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 04 May 2007 15:04:07 +0200
changeset 524 082ffdd8fbd7
parent 523 eb380b33ae24
child 525 4a6c58f0e327
move code around
SConstruct
src/applications/application-list.cc
src/applications/application-list.h
src/applications/application.cc
src/applications/application.h
src/applications/onoff-application.cc
src/applications/onoff-application.h
src/internet-node/arp-cache.cc
src/internet-node/arp-cache.h
src/internet-node/arp-header.cc
src/internet-node/arp-header.h
src/internet-node/arp-ipv4-interface.cc
src/internet-node/arp-ipv4-interface.h
src/internet-node/arp.cc
src/internet-node/arp.h
src/internet-node/ascii-trace.cc
src/internet-node/ascii-trace.h
src/internet-node/header-utils.cc
src/internet-node/header-utils.h
src/internet-node/i-arp-private.cc
src/internet-node/i-arp-private.h
src/internet-node/i-ipv4-impl.cc
src/internet-node/i-ipv4-impl.h
src/internet-node/i-ipv4-private.cc
src/internet-node/i-ipv4-private.h
src/internet-node/i-udp-impl.cc
src/internet-node/i-udp-impl.h
src/internet-node/internet-node.cc
src/internet-node/internet-node.h
src/internet-node/ipv4-checksum.cc
src/internet-node/ipv4-checksum.h
src/internet-node/ipv4-end-point-demux.cc
src/internet-node/ipv4-end-point-demux.h
src/internet-node/ipv4-end-point.cc
src/internet-node/ipv4-end-point.h
src/internet-node/ipv4-header.cc
src/internet-node/ipv4-header.h
src/internet-node/ipv4-interface.cc
src/internet-node/ipv4-interface.h
src/internet-node/ipv4-l4-demux.cc
src/internet-node/ipv4-l4-demux.h
src/internet-node/ipv4-l4-protocol.cc
src/internet-node/ipv4-l4-protocol.h
src/internet-node/ipv4-loopback-interface.cc
src/internet-node/ipv4-loopback-interface.h
src/internet-node/ipv4.cc
src/internet-node/ipv4.h
src/internet-node/l3-demux.cc
src/internet-node/l3-demux.h
src/internet-node/l3-protocol.cc
src/internet-node/l3-protocol.h
src/internet-node/pcap-trace.cc
src/internet-node/pcap-trace.h
src/internet-node/sgi-hashmap.h
src/internet-node/udp-header.cc
src/internet-node/udp-header.h
src/internet-node/udp-socket.cc
src/internet-node/udp-socket.h
src/internet-node/udp.cc
src/internet-node/udp.h
src/node/application-list.cc
src/node/application-list.h
src/node/application.cc
src/node/application.h
src/node/arp-cache.cc
src/node/arp-cache.h
src/node/arp-header.cc
src/node/arp-header.h
src/node/arp-ipv4-interface.cc
src/node/arp-ipv4-interface.h
src/node/arp.cc
src/node/arp.h
src/node/ascii-trace.cc
src/node/ascii-trace.h
src/node/header-utils.cc
src/node/header-utils.h
src/node/i-arp-private.cc
src/node/i-arp-private.h
src/node/i-ipv4-impl.cc
src/node/i-ipv4-impl.h
src/node/i-ipv4-private.cc
src/node/i-ipv4-private.h
src/node/i-udp-impl.cc
src/node/i-udp-impl.h
src/node/internet-node.cc
src/node/internet-node.h
src/node/ipv4-checksum.cc
src/node/ipv4-checksum.h
src/node/ipv4-end-point-demux.cc
src/node/ipv4-end-point-demux.h
src/node/ipv4-end-point.cc
src/node/ipv4-end-point.h
src/node/ipv4-header.cc
src/node/ipv4-header.h
src/node/ipv4-interface.cc
src/node/ipv4-interface.h
src/node/ipv4-l4-demux.cc
src/node/ipv4-l4-demux.h
src/node/ipv4-l4-protocol.cc
src/node/ipv4-l4-protocol.h
src/node/ipv4-loopback-interface.cc
src/node/ipv4-loopback-interface.h
src/node/ipv4.cc
src/node/ipv4.h
src/node/l3-demux.cc
src/node/l3-demux.h
src/node/l3-protocol.cc
src/node/l3-protocol.h
src/node/onoff-application.cc
src/node/onoff-application.h
src/node/pcap-trace.cc
src/node/pcap-trace.h
src/node/sgi-hashmap.h
src/node/udp-header.cc
src/node/udp-header.h
src/node/udp-socket.cc
src/node/udp-socket.h
src/node/udp.cc
src/node/udp.h
--- a/SConstruct	Fri May 04 14:03:12 2007 +0200
+++ b/SConstruct	Fri May 04 15:04:07 2007 +0200
@@ -192,62 +192,90 @@
 node.add_deps (['core', 'common', 'simulator'])
 node.add_sources ([
     'node.cc',
+    'ipv4-address.cc',
+    'net-device.cc',
+    'mac-address.cc',
+    'llc-snap-header.cc',
+    'ipv4-route.cc',
+    'queue.cc',
+    'drop-tail.cc',
+    'channel.cc',
+    'node-list.cc',
+    'socket.cc',
+    'i-udp.cc',
+    'i-ipv4.cc',
+    ])
+node.add_inst_headers ([
+    'node.h',
+    'ipv4-address.h',
+    'net-device.h',
+    'mac-address.h',
+    'ipv4-route.h',
+    'queue.h',
+    'drop-tail.h',
+    'llc-snap-header.h',
+    'channel.h',
+    'node-list.h',
+    'socket.h',
+    'i-udp.h',
+    'i-ipv4.h',
+    ])
+
+applications = build.Ns3Module ('applications', 'src/applications')
+ns3.add (applications)
+applications.add_deps (['node'])
+applications.add_sources ([
+    'application-list.cc',
+    'application.cc',
+    'onoff-application.cc',
+])
+applications.add_inst_headers ([
+    'application-list.h',
+    'application.h',
+    'onoff-application.h',
+])
+
+inode = build.Ns3Module ('internet-node', 'src/internet-node')
+ns3.add (inode)
+inode.add_deps (['node', 'applications'])
+inode.add_sources ([
+    'internet-node.cc',
     'l3-demux.cc',
     'l3-protocol.cc',
     'ipv4-l4-demux.cc',
     'ipv4-l4-protocol.cc',
-    'ipv4-address.cc',
-    'internet-node.cc',
-    'net-device.cc',
-    'mac-address.cc',
     'ipv4-header.cc',
     'udp-header.cc',
     'ipv4-checksum.cc',
-    'ipv4-route.cc',
     'ipv4-interface.cc',
     'ipv4.cc',
     'ipv4-end-point.cc',
     'udp.cc',
     'arp-header.cc',
-    'application.cc',
-    'application-list.cc',
-    'onoff-application.cc',
     'arp-cache.cc',
     'arp-ipv4-interface.cc',
     'arp.cc',
     'ipv4-loopback-interface.cc',
-    'llc-snap-header.cc',
     'header-utils.cc',
-    'queue.cc',
-    'drop-tail.cc',
-    'channel.cc',
-    'node-list.cc',
-    'ascii-trace.cc',
-    'socket.cc',
     'udp-socket.cc',
-    'pcap-trace.cc',
     'ipv4-end-point-demux.cc',
-    'i-udp.cc',
     'i-udp-impl.cc',
     'i-arp-private.cc',
-    'i-ipv4.cc',
     'i-ipv4-impl.cc',
     'i-ipv4-private.cc',
-    ])
-node.add_headers ([
+    'ascii-trace.cc',
+    'pcap-trace.cc',
+])
+inode.add_headers ([
     'ipv4-header.h',
     'udp-header.h',
     'ipv4-checksum.h',
-    'application.h',
-    'application-list.h',
-    'onoff-application.h',
     'arp-header.h',
     'arp-cache-cache.h',
     'arp.h',
     'ipv4-loopback-interface.h',
     'l3-demux.h',
     'header-utils.h',
-    'protocol.h',
     'queue.h',
     'arp-ipv4-interface.h',
     'udp-socket.h',
@@ -262,32 +290,18 @@
     'ipv4-l4-demux.h',
     'ipv4-end-point-demux.h',
     'ipv4-end-point.h',
-    ])
-node.add_inst_headers ([
-    'node.h',
-    'internet-node.h',
-    'ipv4-address.h',
-    'net-device.h',
-    'ipv4-interface.h',
-    'mac-address.h',
-    'ipv4-route.h',
-    'queue.h',
-    'drop-tail.h',
-    'llc-snap-header.h',
-    'arp-header.h',
     'ipv4-header.h',
     'udp-header.h',
-    'channel.h',
-    'node-list.h',
-    'application.h',
-    'application-list.h',
-    'onoff-application.h',
+    'ipv4-interface.h',
+    'sgi-hashmap.h'
+])
+inode.add_inst_headers ([
+    'internet-node.h',
     'ascii-trace.h',
-    'socket.h',
     'pcap-trace.h',
-    'i-udp.h',
-    'i-ipv4.h',
-    ])
+])
+
+
 
 p2p = build.Ns3Module ('p2p', 'src/devices/p2p')
 ns3.add (p2p)
@@ -380,13 +394,13 @@
 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_deps(['core', 'simulator', 'node', 'internet-node'])
 sample_simple.add_source('main-simple.cc')
 
 sample_sp2p = build.Ns3Module('sample-simple-p2p', 'samples')
 sample_sp2p.set_executable()
 #n3.add(sample_sp2p)
-sample_sp2p.add_deps(['core', 'simulator', 'node', 'p2p'])
+sample_sp2p.add_deps(['core', 'simulator', 'node', 'internet-node', 'p2p'])
 sample_sp2p.add_source('main-simple-p2p.cc')
 
 sample_default_value = build.Ns3Module('sample-default-value', 'samples')
@@ -399,7 +413,7 @@
 example_simple_p2p = build.Ns3Module('simple-p2p', 'examples')
 example_simple_p2p.set_executable()
 ns3.add(example_simple_p2p)
-example_simple_p2p.add_deps(['core', 'simulator', 'node', 'p2p'])
+example_simple_p2p.add_deps(['core', 'simulator', 'node', 'p2p', 'internet-node'])
 example_simple_p2p.add_source('simple-p2p.cc')
 
 ns3.generate_dependencies()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/application-list.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,88 @@
+// -*- Mode:NS3 -*-
+//
+// 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>
+//
+// Implement the application list capability for NS3 nodes
+// George F. Riley, Georgia Tech, Spring 2007
+
+#include "application.h"
+#include "application-list.h"
+#include "ns3/iid-manager.h"
+
+namespace ns3{
+
+const uint32_t ApplicationList::iid = IidManager::Allocate ("ApplicationList");
+
+ApplicationList::ApplicationList(Node* n)
+  : NsUnknown (ApplicationList::iid)
+{}
+
+void 
+ApplicationList::DoDispose (void)
+{
+  for (std::vector<Application*>::const_iterator i = m_apps.begin();
+       i != m_apps.end(); ++i)
+    {
+      Application *app = *i;
+      app->Dispose ();
+      app->Unref ();
+    }
+  m_apps.clear ();
+  NsUnknown::DoDispose ();
+}
+  
+ApplicationList::~ApplicationList()
+{}
+
+ApplicationList* ApplicationList::Copy(Node * n) const 
+{ // Copy this app list
+  ApplicationList* r = new ApplicationList(n);
+  return r;
+}
+
+void
+ApplicationList::Add(Application* a)
+{
+  a->Ref ();
+  m_apps.push_back(a);
+}
+
+void ApplicationList::SetNode(Node * n)
+{
+  // Set the node pointer in each application
+  for (std::vector<Application *>::const_iterator i = m_apps.begin();
+       i != m_apps.end(); ++i)
+    { // Set correct node pointer in each app
+      (*i)->SetNode(n);
+    }
+}
+  
+
+uint32_t ApplicationList::Count() const
+{
+  return m_apps.size();
+}
+
+Application* ApplicationList::Get(uint32_t i) const
+{ // Get the i'th application. Note, this is linear time in N
+  if (m_apps.empty()) return 0;        // List is empty
+  return m_apps[i];
+}
+  
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/application-list.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,63 @@
+// -*- Mode:NS3 -*-
+//
+// 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 applications associated with a node.
+// George F. Riley, Georgia Tech, Spring 2007
+
+#ifndef __APPLICATION_LIST_H__
+#define __APPLICATION_LIST_H__
+
+#include "application.h"
+#include "ns3/ns-unknown.h"
+#include <vector>
+
+namespace ns3 {
+
+class ApplicationList : public NsUnknown
+{
+public:
+  static const uint32_t iid;
+  ApplicationList(Node*);
+  // Copy constructor not needed, default one is correct
+  virtual ~ApplicationList();
+  // Inherited from Capabilty
+  virtual ApplicationList* Copy(Node*) const;
+  virtual void SetNode(Node *);              // Sets the node for all apps
+  virtual void Add(Application*);      // Add an already new'ed app
+  // Manage the list
+  template <typename T> T* AddCopy(const T& t)  // Add a new application
+  {
+    T* a = t.Copy();
+    m_apps.push_back(a);
+    return a;
+  }
+  void Remove(Application*);                // Application has finished
+  uint32_t Count() const;  // Number of applications
+  Application* Get(uint32_t i) const; // Get app by index
+  
+protected:
+  virtual void DoDispose (void);
+private:
+  std::vector<Application*> m_apps;
+};
+
+}//namespace ns3
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/application.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,195 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2006 Georgia Tech Research Corporation
+ *
+ * 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 for ns3 Application base class.
+// George F. Riley, Georgia Tech, Fall 2006
+
+#include "application.h"
+#include "ns3/node.h"
+#include "ns3/nstime.h"
+#include "ns3/random-variable.h"
+#include "ns3/simulator.h"
+
+using namespace std;
+
+namespace ns3 {
+
+// Application Methods
+
+// \brief Application Constructor
+Application::Application(Node * n) 
+    : m_node (n),
+      m_startVar(0), m_stopVar(0),
+      m_start(false), m_stop(false)
+{
+  m_node->Ref ();
+}
+
+Application::Application(const Application& o)
+    : m_node(0), m_startVar(0), m_stopVar(0),
+      m_start(false), m_stop(false)
+{ // Copy constructor
+  m_node = o.m_node;
+  m_node->Ref ();
+  // Copy the start and stop random variables if they exist
+  if (o.m_startVar) m_startVar = o.m_startVar->Copy();
+  if (o.m_stopVar)  m_stopVar  = o.m_stopVar->Copy();
+  if (o.m_start)    ScheduleStart();
+  if (o.m_stop)     ScheduleStop();
+}
+
+  
+// \brief Application Destructor
+Application::~Application()
+{}
+
+void
+Application::DoDispose (void)
+{
+  if (m_node != 0)
+    {
+      m_node->Unref ();
+      m_node = 0;
+    }
+  if (m_start) 
+    {
+      Simulator::Cancel(m_startEvent);
+      m_start = false;
+    }
+  if (m_stop) 
+    {
+      Simulator::Cancel(m_stopEvent);
+      m_stop = false;
+    }
+  delete m_startVar;
+  m_startVar = 0;
+  delete m_stopVar;
+  m_stopVar = 0;
+}
+  
+Application& Application::operator=(const Application& rhs)
+{
+  if (this == &rhs) return *this; // Self assignment
+  m_node->Unref ();
+  m_node = 0;
+  m_node = rhs.m_node;
+  m_node->Ref ();
+
+  delete m_startVar;
+  m_startVar = 0;
+  if (rhs.m_startVar) m_startVar = rhs.m_startVar->Copy();
+  
+  delete m_stopVar;
+  m_stopVar = 0;
+  if (rhs.m_stopVar) m_stopVar = rhs.m_stopVar->Copy();
+  
+  m_start = false;
+  if (rhs.m_start) ScheduleStart();
+  if (rhs.m_stop)  ScheduleStop();
+  return *this;
+}
+  
+   
+// \brief Specify application start time
+// The virtual method STartApp will be called at the time
+// specified by startTime.
+// \param Time to start application (absolute time, from start of simulation)
+void Application::Start(const Time& startTime)
+{
+  delete m_startVar;
+  m_startVar = new ConstantVariable(startTime.GetSeconds());
+  ScheduleStart();
+}
+
+void Application::Start(const RandomVariable& startVar)
+{ // Start at random time
+  delete m_startVar;
+  m_startVar = startVar.Copy();
+  ScheduleStart();
+}
+
+   
+// \brief Specify application stop time
+// The virtual method StopApp will be called at the time
+// specified by stopTime.
+// \param Time to stop application (absolute time, from start of simulation)
+void Application::Stop(const Time& stopTime)
+{
+  delete m_stopVar;
+  m_stopVar = new ConstantVariable(stopTime.GetSeconds());
+  ScheduleStop();
+}
+
+void Application::Stop(const RandomVariable& stopVar)
+{ // Stop at random time
+  delete m_stopVar;
+  m_stopVar = stopVar.Copy();
+  ScheduleStop();
+}
+
+// \brief Assign this application to a given node
+// Called by the application manager capability when adding
+// an application to a node.
+void Application::SetNode(Node * n)
+{
+  if (m_node != 0)
+    {
+      m_node->Unref ();
+    }
+  m_node = n;
+  m_node->Ref ();
+}
+  
+Node* Application::PeekNode() const
+{
+  return m_node;
+}
+
+// Protected methods
+// StartApp and StopApp will likely be overridden by application subclasses
+void Application::StartApplication()
+{ // Provide null functionality in case subclass is not interested
+}
+
+void Application::StopApplication()
+{ // Provide null functionality in case subclass is not interested
+}
+
+
+// Private helpers
+void Application::ScheduleStart()
+{
+  m_startEvent = Simulator::Schedule(Seconds(m_startVar->GetValue()) -
+                                     Simulator::Now(),
+                                     &Application::StartApplication, this);
+  m_start = true;
+}
+
+void Application::ScheduleStop()
+{
+  m_stopEvent = Simulator::Schedule(Seconds(m_stopVar->GetValue()) -
+                                     Simulator::Now(),
+                                     &Application::StopApplication, this);
+  m_stop = true;
+}
+
+} //namespace ns3
+      
+  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/application.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,138 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2006 Georgia Tech Research Corporation
+ *
+ * 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>
+ */
+
+#ifndef __APPLICATION_H__
+#define __APPLICATION_H__
+
+//
+// \brief The base class for all ns3 applicationes
+//
+// Class Application is the base class for all ns3 applications.
+// Applications are associated with individual nodes, and are created
+// using the AddApplication method in the ApplicationManager capability.
+// 
+// Conceptually, an application has zero or more Socket
+// objects associated with it, that are created using the Socket
+// creation API of the Kernel capability.  The Socket object
+// API is modeled after the
+// well-known BSD sockets interface, although it is somewhat 
+// simplified for use with ns3.  Further, any socket call that
+// would normally "block" in normal sockets will return immediately
+// in ns3.  A set of "upcalls" are defined that will be called when
+// the previous blocking call would normally exit.  THis is documented
+// in more detail Socket class in socket.h.
+// 
+// There is a second application class in ns3, called "ThreadedApplication"
+// that implements a true sockets interface, which should be used
+// when porting existing sockets code to ns3.  The true
+// sockets approach is significantly
+// less memory--efficient using private stacks for each defined application,
+// so that approach should be used with care.  The design and implementation
+// of the ThreadedApplication are still being discussed.
+
+#include "ns3/event-id.h"
+#include "ns3/nstime.h"
+#include "ns3/object.h"
+
+namespace ns3 {
+
+class Node;
+class RandomVariable;
+  
+class Application : public Object
+{
+public:
+  Application(Node *);
+  Application(const Application&);  // Copy constructor
+  Application& operator=(const Application&); // Assignment operator
+  virtual ~Application();
+  
+  virtual Application* Copy() const = 0; // All applications must provide
+  
+  // \brief Specify application start time
+  // Applications start at various times in the simulation scenario.
+  // The Start method specifies when the application should be
+  // started.  The application subclasses should override the
+  // private "StartApplication" method defined below, which is called at the
+  // time specified, to cause the application to begin.
+  // \param Start time for this application, relative to the
+  // current simulation time.
+  void Start(const Time&);
+
+  // \brief Same as above, but uses a random variable for start time
+  // The random variable returns the desired start time in units of
+  // Seconds.
+  
+void Start(const RandomVariable&);
+  
+  // \brief Specify application stop time
+  // Once an application has started, it is sometimes useful
+  // to stop the application.  The Stop method specifies when an
+  // application is to stop.  The application subclasses should override
+  // the private StopApplication method defined below, to cause the application
+  // to stop.
+  // \param Stop time for this application, relative to the
+  // current simulation time.
+  void Stop(const Time&);
+
+  // \brief Same as above, but uses a random variable for stop time
+  // The random variable returns the desired stop time in units of
+  // Seconds.
+  void Stop(const RandomVariable&);
+  
+  // \brief Attaches an application to a specific node
+  // Specifies which node object this application is associated with.
+  // \param Node object to associate with this application.
+  void SetNode(Node *);
+
+  // \brief Returns the pointer to the attached node.
+  Node* PeekNode() const;
+  
+  // Members
+  Node          * m_node;      // All applications have an associated node
+  RandomVariable* m_startVar;  // Random variable for start time
+  RandomVariable* m_stopVar;   // Random variable for stop time
+  EventId         m_startEvent;// Event identifier for start event
+  EventId         m_stopEvent; // Event identifier for the stop event
+  bool            m_start;     // True if start event scheduled
+  bool            m_stop;      // True if stop event scheduled
+  
+protected:
+  // \brief Application specific startup code
+  // The StartApplication method is called at the start time specifed by Start
+  // This method should be overridden by all or most application
+  // subclasses.
+  virtual void StartApplication();
+
+  // \brief Application specific shutdown code
+  // The StopApplication method is called at the stop time specifed by Stop
+  // This method should be overridden by all or most application
+  // subclasses.
+  virtual void StopApplication();
+
+  virtual void DoDispose (void);
+private:
+  // Helpers
+  void ScheduleStart();
+  void ScheduleStop();
+};
+
+} //namespace ns3
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/onoff-application.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,277 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+//
+// Copyright (c) 2006 Georgia Tech Research Corporation
+//
+// 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>
+//
+
+// ns3 - On/Off Data Source Application class
+// George F. Riley, Georgia Tech, Spring 2007
+// Adapted from ApplicationOnOff in GTNetS.
+
+#include "ns3/ipv4-address.h"
+#include "ns3/node.h"
+#include "ns3/nstime.h"
+#include "ns3/data-rate.h"
+#include "ns3/random-variable.h"
+#include "ns3/socket.h"
+#include "ns3/simulator.h"
+#include "ns3/i-udp.h"
+#include "onoff-application.h"
+
+using namespace std;
+
+namespace ns3 {
+
+// Defaults for rate/size
+DataRate OnOffApplication::g_defaultRate = DataRate(500000);
+uint32_t OnOffApplication::g_defaultSize = 512;
+
+// Constructors
+
+  OnOffApplication::OnOffApplication(Node * n, 
+                                     const Ipv4Address  rip,   // Remote IP addr
+                                     uint16_t       rport, // Remote port
+                                     const  RandomVariable& ontime,
+                                     const  RandomVariable& offtime,
+                                     DataRate  rate,
+                                     uint32_t size)
+    :  Application(n), 
+      m_socket(0),      // Socket allocated on Start
+      m_peerIP(rip),
+      m_peerPort(rport),
+      m_connected(false),
+      m_onTime(ontime.Copy()),
+      m_offTime(offtime.Copy()),
+      m_cbrRate(rate),
+      m_pktSize(size), 
+      m_residualBits(0),
+      m_lastStartTime((HighPrecision)0),
+      m_maxBytes(0xffffffff),
+      m_totBytes(0),
+      m_startStopScheduled(false),
+      m_sendScheduled(false)
+{
+}
+
+OnOffApplication::OnOffApplication(Node * n, const OnOffApplication& c)
+  : Application(n), 
+    m_socket(0),
+    m_peerIP(c.m_peerIP),
+    m_peerPort(c.m_peerPort),
+    m_connected(c.m_connected),
+    m_onTime(c.m_onTime->Copy()),
+    m_offTime(c.m_offTime->Copy()),
+    m_cbrRate(c.m_cbrRate),
+    m_pktSize(c.m_pktSize),
+    m_residualBits(c.m_residualBits),
+    m_lastStartTime(c.m_lastStartTime),
+    m_maxBytes(c.m_maxBytes),
+    m_totBytes(c.m_totBytes),
+    m_startStopScheduled(false),
+    m_sendScheduled(false)
+{
+}
+
+OnOffApplication::~OnOffApplication()
+{}
+
+void
+OnOffApplication::DoDispose (void)
+{
+  if (m_socket != 0)
+    {
+      m_socket->Unref ();
+      m_socket = 0;
+    }
+  delete m_onTime;
+  delete m_offTime;
+
+  m_onTime = 0;
+  m_offTime = 0;
+
+  // chain up
+  Application::DoDispose ();
+}
+
+#ifdef REMOVE_THIS
+// Handler Methods
+void OnOffApplication::Handle(Event* e, Time_t t)
+{
+  AppOOEvent* ev = (AppOOEvent*)e;
+  switch (ev->event) {
+    case AppOOEvent::SEND_PKT :
+      {
+        SendPkt(false);         // Send the packet
+        return;
+      }
+    case AppOOEvent::START_GEN :
+      {
+        DEBUG0((cout << "StartGen at " << Simulator::Now() << endl));
+        lastStartTime = Simulator::Now();
+        ScheduleNextTx();
+        Time_t onInterval = onTime->Value();
+        pendingOO->event = AppOOEvent::STOP_GEN;
+         // Schedule the stop event
+        Simulator::Schedule(pendingOO, onInterval, this);
+        return;
+      }
+    case AppOOEvent::STOP_GEN :
+      {
+        DEBUG0((cout << "StopGen at " << Simulator::Now() << endl));
+        if (totBytes < maxBytes)
+          { // Only schedule if not execeeded maxBytes
+            Time_t offInterval = offTime->Value();
+            pendingOO->event = AppOOEvent::START_GEN;
+            // Schedule the start event
+            Simulator::Schedule(pendingOO, offInterval, this);
+          }
+        if (pendingEvent)
+          {
+            // Calculate residual bits since last packet sent
+            residualBits += (uint32_t)(cbrRate*(Simulator::Now()-lastStartTime));
+            Simulator::Cancel(pendingEvent);
+            delete pendingEvent;
+            pendingEvent = 0;
+          }
+        return;
+      }
+  }
+  Application::Handle(e, t);  // May be application event
+}
+#endif
+
+// Application Methods
+void OnOffApplication::StartApplication()    // Called at time specified by Start
+{
+  // Create the socket if not already
+  if (!m_socket)
+    { // Create the socket using the specified layer 4 protocol
+#ifdef NOTYET
+      m_socket = PeekNode()->GetKernel()->CreateGenericSocket(*m_l4Proto);
+      m_socket->Bind();  // Choose any available port local port
+      m_socket->Connect(*m_peerIP, m_peerPort,
+                        MakeCallback(&OnOffApplication::ConnectionSucceeded,
+                                     this),
+                        MakeCallback(&OnOffApplication::ConnectionFailed,
+                                     this));
+#endif
+      
+      IUdp *udp = PeekNode ()->QueryInterface<IUdp> (IUdp::iid);
+      m_socket = udp->CreateSocket ();
+      udp->Unref ();
+      m_socket->Connect (m_peerIP, m_peerPort);
+    }
+  StopApplication();                         // Insure no pending event
+  // If we are not yet connected, there is nothing to do here
+  // The ConnectionComplete upcall will start timers at that time
+  //if (!m_connected) return;
+  ScheduleStartEvent();
+}
+
+void OnOffApplication::StopApplication()     // Called at time specified by Stop
+{
+  if (m_startStopScheduled)
+    { // Cancel the startStop event
+      Simulator::Cancel(m_startStopEvent);
+      m_startStopScheduled = false;
+    }
+  if (m_sendScheduled)
+    { // Cancel the pending send packet event
+      Simulator::Cancel(m_sendEvent);
+      m_sendScheduled = false;
+      // Calculate residual bits since last packet sent
+      Time delta(Simulator::Now() - m_lastStartTime);
+      m_residualBits += (uint32_t)(m_cbrRate.GetBitRate() * delta.GetSeconds());
+    }
+}
+
+OnOffApplication* OnOffApplication::Copy() const
+{
+  return new OnOffApplication(*this);
+}
+
+// Event handlers
+void OnOffApplication::StartSending()
+{
+  m_startStopScheduled = true;
+  ScheduleNextTx();  // Schedule the send packet event
+}
+
+void OnOffApplication::StopSending()
+{
+  m_startStopScheduled = true;
+  if (m_sendScheduled) Simulator::Cancel(m_sendEvent);
+}
+
+// Private helpers
+void OnOffApplication::ScheduleNextTx()
+{
+  if (m_totBytes < m_maxBytes)
+    {
+      uint32_t bits = m_pktSize * 8 - m_residualBits;
+      Time nextTime(Seconds (bits / 
+        static_cast<double>(m_cbrRate.GetBitRate()))); // Time till next packet
+      m_sendScheduled = true;
+      m_sendEvent = Simulator::Schedule(nextTime, &OnOffApplication::SendPacket, this);
+    }
+  else
+    { // All done, cancel any pending events
+      StopApplication();
+    }
+}
+
+void OnOffApplication::ScheduleStartEvent()
+{  // Schedules the event to start sending data (switch to the "On" state)
+  Time offInterval = Seconds(m_offTime->GetValue());
+  m_startStopEvent = Simulator::Schedule(offInterval, &OnOffApplication::StartSending, this);
+  m_startStopScheduled = true;
+}
+
+void OnOffApplication::ScheduleStopEvent()
+{  // Schedules the event to stop sending data (switch to "Off" state)
+  Time onInterval = Seconds(m_onTime->GetValue());
+  Simulator::Schedule(onInterval, &OnOffApplication::StopSending, this);
+  m_startStopScheduled = true;
+}
+
+  
+void OnOffApplication::SendPacket()
+{
+  NS_ASSERT (m_sendScheduled);
+  m_sendScheduled = false;
+  m_socket->Send(0, m_pktSize);
+#ifdef NOTYET
+  m_socket->Send(0, m_pktSize); // Send the packet
+#endif
+  m_totBytes += m_pktSize;
+  m_lastStartTime = Simulator::Now();
+  m_residualBits = 0;
+  ScheduleNextTx();
+}
+
+void OnOffApplication::ConnectionSucceeded(Socket*)
+{
+  m_connected = true;
+  ScheduleStartEvent();
+}
+  
+void OnOffApplication::ConnectionFailed(Socket*)
+{
+  cout << "OnOffApplication, Connection Failed" << endl;
+}
+
+} // Namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/applications/onoff-application.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,108 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+//
+// Copyright (c) 2006 Georgia Tech Research Corporation
+//
+// 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>
+//
+
+// ns3 - On/Off Data Source Application class
+// George F. Riley, Georgia Tech, Spring 2007
+// Adapted from ApplicationOnOff in GTNetS.
+
+// Define an on/off data source application class
+
+#ifndef __onoff_application_h__
+#define __onoff_application_h__
+
+#include "application.h"
+#include "ns3/event-id.h"
+
+namespace ns3 {
+
+class Ipv4Address;
+class RandomVariable;
+class Socket;
+class DataRate;
+
+class OnOffApplication : public Application {
+
+public:
+  OnOffApplication(Node * n,
+                   const Ipv4Address,  // Peer IP address
+                   uint16_t,           // Peer port
+                   const RandomVariable&,     // Random variable for On time
+                   const RandomVariable&,     // Random variable for Off time
+                   DataRate  = g_defaultRate,  // Data rate when on
+                   uint32_t = g_defaultSize);  // Size of packets
+
+  OnOffApplication(Node * n, const OnOffApplication&); // Copy constructor
+  virtual ~OnOffApplication();               // Destructor
+  virtual void StartApplication();    // Called at time specified by Start
+  virtual void StopApplication();     // Called at time specified by Stop
+  virtual OnOffApplication* Copy() const;// Make a copy of the application
+
+  // Event handlers
+  void StartSending();
+  void StopSending();
+  void SendPacket();
+
+  virtual void MaxBytes(uint32_t m) { m_maxBytes = m;}
+
+protected:
+  virtual void DoDispose (void);
+
+public: // Static methods
+  static void DefaultRate(uint64_t r) { g_defaultRate = r;}
+
+  static void DefaultSize(uint32_t s) { g_defaultSize = s;}
+
+public:
+  Socket        * m_socket;       // Associated socket
+  Ipv4Address     m_peerIP;       // Peer IP address
+  uint16_t        m_peerPort;     // Peer port
+  bool            m_connected;    // True if connected
+  RandomVariable* m_onTime;       // rng for On Time
+  RandomVariable* m_offTime;      // rng for Off Time
+  DataRate        m_cbrRate;      // Rate that data is generated
+  uint32_t        m_pktSize;      // Size of packets
+  uint32_t        m_residualBits; // Number of generated, but not sent, bits
+  Time            m_lastStartTime;// Time last packet sent
+  uint32_t        m_maxBytes;     // Limit total number of bytes sent
+  uint32_t        m_totBytes;     // Total bytes sent so far
+  bool            m_startStopScheduled; // True if start or stop event scheduled
+  EventId         m_startStopEvent;     // Event id for next start or stop event
+  bool            m_sendScheduled;// True of send event scheduled
+  EventId         m_sendEvent;    // Eventid of pending "send packet" event
+  bool            m_sending;      // True if currently in sending state
+  
+public:
+  static DataRate   g_defaultRate;  // Default sending rate when on
+  static uint32_t g_defaultSize;  // Default packet size
+
+private:
+  void ScheduleNextTx();
+  void ScheduleStartEvent();
+  void ScheduleStopEvent();
+  void ConnectionSucceeded(Socket*);
+  void ConnectionFailed(Socket*);
+  void Ignore(Socket*);
+protected:
+};
+
+} // namespace ns3
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/arp-cache.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,229 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2006 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#include "ns3/assert.h"
+
+#include "ns3/packet.h"
+#include "ns3/simulator.h"
+
+#include "arp-cache.h"
+#include "arp-header.h"
+
+namespace ns3 {
+
+ArpCache::ArpCache (NetDevice *device, Ipv4Interface *interface)
+  : m_device (device), 
+    m_interface (interface),
+    m_aliveTimeout (Seconds (120)),
+    m_deadTimeout (Seconds (100)),
+    m_waitReplyTimeout (Seconds (1))
+{
+  m_device->Ref ();
+}
+
+ArpCache::~ArpCache ()
+{
+  m_device->Unref ();
+  Flush ();
+}
+
+NetDevice *
+ArpCache::PeekDevice (void) const
+{
+  return m_device;
+}
+
+Ipv4Interface *
+ArpCache::GetInterface (void) const
+{
+  return m_interface;
+}
+
+void 
+ArpCache::SetAliveTimeout (Time aliveTimeout)
+{
+  m_aliveTimeout = aliveTimeout;
+}
+void 
+ArpCache::SetDeadTimeout (Time deadTimeout)
+{
+  m_deadTimeout = deadTimeout;
+}
+void 
+ArpCache::SetWaitReplyTimeout (Time waitReplyTimeout)
+{
+  m_waitReplyTimeout = waitReplyTimeout;
+}
+
+Time
+ArpCache::GetAliveTimeout (void) const
+{
+  return m_aliveTimeout;
+}
+Time
+ArpCache::GetDeadTimeout (void) const
+{
+  return m_deadTimeout;
+}
+Time
+ArpCache::GetWaitReplyTimeout (void) const
+{
+  return m_waitReplyTimeout;
+}
+
+void 
+ArpCache::Flush (void)
+{
+  for (CacheI i = m_arpCache.begin (); i != m_arpCache.end (); i++) 
+    {
+      delete (*i).second;
+    }
+  m_arpCache.erase (m_arpCache.begin (), m_arpCache.end ());
+}
+
+ArpCache::Entry *
+ArpCache::Lookup (Ipv4Address to)
+{
+  if (m_arpCache.find (to) != m_arpCache.end ()) 
+    {
+      ArpCache::Entry *entry = m_arpCache[to];
+      return entry;
+    }
+  return 0;
+}
+
+ArpCache::Entry *
+ArpCache::Add (Ipv4Address to)
+{
+  ArpCache::Entry *entry = new ArpCache::Entry (this);
+  m_arpCache[to] = entry;  
+  return entry;
+}
+
+ArpCache::Entry::Entry (ArpCache *arp)
+  : m_arp (arp),
+    m_state (ALIVE),
+    m_waiting ()
+{}
+
+
+bool 
+ArpCache::Entry::IsDead (void)
+{
+  return (m_state == DEAD)?true:false;
+}
+bool 
+ArpCache::Entry::IsAlive (void)
+{
+  return (m_state == ALIVE)?true:false;
+}
+bool
+ArpCache::Entry::IsWaitReply (void)
+{
+  return (m_state == WAIT_REPLY)?true:false;
+}
+
+
+void 
+ArpCache::Entry::MarkDead (void) 
+{
+  m_state = DEAD;
+  //NS_ASSERT (m_waiting != 0);
+  UpdateSeen ();
+}
+Packet 
+ArpCache::Entry::MarkAlive (MacAddress macAddress) 
+{
+  NS_ASSERT (m_state == WAIT_REPLY);
+  //NS_ASSERT (m_waiting != 0);
+  m_macAddress = macAddress;
+  m_state = ALIVE;
+  UpdateSeen ();
+  Packet waiting = m_waiting;
+  //m_waiting = 0;
+  return waiting;
+}
+
+Packet 
+ArpCache::Entry::UpdateWaitReply (Packet waiting)
+{
+  NS_ASSERT (m_state == WAIT_REPLY);
+  /* We are already waiting for an answer so
+   * we dump the previously waiting packet and
+   * replace it with this one.
+   */
+  Packet old = m_waiting;
+  m_waiting = waiting;
+  return old;
+}
+void 
+ArpCache::Entry::MarkWaitReply (Packet waiting)
+{
+  NS_ASSERT (m_state == ALIVE || m_state == DEAD);
+  //NS_ASSERT (m_waiting == 0);
+  m_state = WAIT_REPLY;
+  m_waiting = waiting;
+  UpdateSeen ();
+}
+
+MacAddress
+ArpCache::Entry::GetMacAddress (void)
+{
+  NS_ASSERT (m_state == ALIVE);
+  return m_macAddress;
+}
+bool 
+ArpCache::Entry::IsExpired (void)
+{
+  Time timeout;
+  switch (m_state) {
+  case ArpCache::Entry::WAIT_REPLY:
+    timeout = m_arp->GetWaitReplyTimeout ();
+    break;
+  case ArpCache::Entry::DEAD:
+    timeout = m_arp->GetDeadTimeout ();
+    break;
+  case ArpCache::Entry::ALIVE:
+    timeout = m_arp->GetAliveTimeout ();
+    break;
+  default:
+    NS_ASSERT (false);
+    timeout = Seconds (0);
+    /* NOTREACHED */
+    break;
+  }
+  Time delta = Simulator::Now () - m_lastSeen;
+  if (delta >= timeout) 
+    {
+      return true;
+    } 
+  else 
+    {
+      return false;
+    }
+}
+void 
+ArpCache::Entry::UpdateSeen (void)
+{
+  m_lastSeen = Simulator::Now ();
+}
+
+} // namespace ns3
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/arp-cache.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,105 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2006 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef ARP_CACHE_H
+#define ARP_CACHE_H
+
+#include <stdint.h>
+#include "ns3/packet.h"
+#include "ns3/nstime.h"
+#include "ns3/net-device.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/mac-address.h"
+#include "sgi-hashmap.h"
+
+namespace ns3 {
+
+class NetDevice;
+class Ipv4Interface;
+
+class ArpCache {
+public:
+  class Entry;
+
+  ArpCache (NetDevice *device, Ipv4Interface *interface);
+  ~ArpCache ();
+
+  NetDevice *PeekDevice (void) const;
+  Ipv4Interface *GetInterface (void) const;
+
+  void SetAliveTimeout (Time aliveTimeout);
+  void SetDeadTimeout (Time deadTimeout);
+  void SetWaitReplyTimeout (Time waitReplyTimeout);
+  Time GetAliveTimeout (void) const;
+  Time GetDeadTimeout (void) const;
+  Time GetWaitReplyTimeout (void) const;
+
+  
+  ArpCache::Entry *Lookup (Ipv4Address destination);
+  ArpCache::Entry *Add (Ipv4Address to);
+  void Flush (void);
+
+
+  class Entry {
+  public:
+    Entry (ArpCache *arp);
+
+    void MarkDead (void);
+    Packet MarkAlive (MacAddress macAddress);
+    void MarkWaitReply (Packet waiting);
+    Packet UpdateWaitReply (Packet waiting);
+    
+    bool IsDead (void);
+    bool IsAlive (void);
+    bool IsWaitReply (void);
+    
+    MacAddress GetMacAddress (void);
+    bool IsExpired (void);
+  private:
+    enum ArpCacheEntryState_e {
+      ALIVE,
+      WAIT_REPLY,
+      DEAD
+    };
+
+    void UpdateSeen (void);
+    ArpCache *m_arp;
+    ArpCacheEntryState_e m_state;
+    Time m_lastSeen;
+    MacAddress m_macAddress;
+    Packet m_waiting;
+  };
+
+private:
+  typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash> Cache;
+  typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash>::iterator CacheI;
+
+  NetDevice *m_device;
+  Ipv4Interface *m_interface;
+  Time m_aliveTimeout;
+  Time m_deadTimeout;
+  Time m_waitReplyTimeout;
+  Cache m_arpCache;
+};
+
+
+}; // namespace ns3
+
+#endif /* ARP_CACHE_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/arp-header.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,146 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#include "ns3/assert.h"
+#include "arp-header.h"
+#include "header-utils.h"
+
+namespace ns3 {
+
+ArpHeader::~ArpHeader ()
+{}
+
+void 
+ArpHeader::SetRequest (MacAddress sourceHardwareAddress,
+                       Ipv4Address sourceProtocolAddress,
+                       MacAddress destinationHardwareAddress,
+                       Ipv4Address destinationProtocolAddress)
+{
+  m_type = ARP_TYPE_REQUEST;
+  m_macSource = sourceHardwareAddress;
+  m_macDest = destinationHardwareAddress;
+  m_ipv4Source = sourceProtocolAddress;
+  m_ipv4Dest = destinationProtocolAddress;
+}
+void 
+ArpHeader::SetReply (MacAddress sourceHardwareAddress,
+                     Ipv4Address sourceProtocolAddress,
+                     MacAddress destinationHardwareAddress,
+                     Ipv4Address destinationProtocolAddress)
+{
+  m_type = ARP_TYPE_REPLY;
+  m_macSource = sourceHardwareAddress;
+  m_macDest = destinationHardwareAddress;
+  m_ipv4Source = sourceProtocolAddress;
+  m_ipv4Dest = destinationProtocolAddress;
+}
+bool 
+ArpHeader::IsRequest (void) const
+{
+  return (m_type == ARP_TYPE_REQUEST)?true:false;
+}
+bool 
+ArpHeader::IsReply (void) const
+{
+  return (m_type == ARP_TYPE_REPLY)?true:false;
+}
+MacAddress 
+ArpHeader::GetSourceHardwareAddress (void)
+{
+  return m_macSource;
+}
+MacAddress 
+ArpHeader::GetDestinationHardwareAddress (void)
+{
+  return m_macDest;
+}
+Ipv4Address 
+ArpHeader::GetSourceIpv4Address (void)
+{
+  return m_ipv4Source;
+}
+Ipv4Address 
+ArpHeader::GetDestinationIpv4Address (void)
+{
+  return m_ipv4Dest;
+}
+
+
+void 
+ArpHeader::PrintTo (std::ostream &os) const
+{
+  os << "(arp)";
+  if (IsRequest ()) 
+    {
+      os << " source mac: " << m_macSource
+          << " source ipv4: " << m_ipv4Source
+          << " dest ipv4: " << m_ipv4Dest;
+    } 
+  else 
+    {
+      NS_ASSERT (IsReply ());
+      os << " source mac: " << m_macSource
+          << " source ipv4: " << m_ipv4Source
+          << " dest mac: " << m_macDest
+          << " dest ipv4: " <<m_ipv4Dest;
+    }
+}
+uint32_t 
+ArpHeader::GetSerializedSize (void) const
+{
+  /* this is the size of an ARP payload. */
+  return 28;
+}
+
+void
+ArpHeader::SerializeTo (Buffer::Iterator start) const
+{
+  Buffer::Iterator i = start;
+  NS_ASSERT (m_macSource.GetLength () == m_macDest.GetLength ());
+
+  /* ethernet */
+  i.WriteHtonU16 (0x0001);
+  /* ipv4 */
+  i.WriteHtonU16 (0x0800);
+  i.WriteU8 (m_macSource.GetLength ());
+  i.WriteU8 (4);
+  i.WriteHtonU16 (m_type);
+  WriteTo (i, m_macSource);
+  WriteTo (i, m_ipv4Source);
+  WriteTo (i, m_macDest);
+  WriteTo (i, m_ipv4Dest);
+}
+uint32_t
+ArpHeader::DeserializeFrom (Buffer::Iterator start)
+{
+  Buffer::Iterator i = start;
+  i.Next (2+2);
+  uint32_t hardwareAddressLen = i.ReadU8 ();
+  i.Next (1);
+  m_type = i.ReadNtohU16 ();
+  ReadFrom (i, m_macSource, hardwareAddressLen);
+  ReadFrom (i, m_ipv4Source);
+  ReadFrom (i, m_macDest, hardwareAddressLen);
+  ReadFrom (i, m_ipv4Dest);
+  return GetSerializedSize ();
+}
+
+}; // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/arp-header.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,69 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#ifndef ARP_HEADER_H
+#define ARP_HEADER_H
+
+#include "ns3/header.h"
+#include "ns3/mac-address.h"
+#include "ns3/ipv4-address.h"
+
+namespace ns3 {
+
+class ArpHeader : public Header {
+ public:
+  virtual ~ArpHeader ();
+
+  void SetRequest (MacAddress sourceHardwareAddress,
+                   Ipv4Address sourceProtocolAddress,
+                   MacAddress destinationHardwareAddress,
+                   Ipv4Address destinationProtocolAddress);
+  void SetReply (MacAddress sourceHardwareAddress,
+                 Ipv4Address sourceProtocolAddress,
+                 MacAddress destinationHardwareAddress,
+                 Ipv4Address destinationProtocolAddress);
+  bool IsRequest (void) const;
+  bool IsReply (void) const;
+  MacAddress GetSourceHardwareAddress (void);
+  MacAddress GetDestinationHardwareAddress (void);
+  Ipv4Address GetSourceIpv4Address (void);
+  Ipv4Address GetDestinationIpv4Address (void);
+
+private:
+  virtual void PrintTo (std::ostream &os) const;
+  virtual uint32_t GetSerializedSize (void) const;
+  virtual void SerializeTo (Buffer::Iterator start) const;
+  virtual uint32_t DeserializeFrom (Buffer::Iterator start);
+
+  enum ArpType_e {
+    ARP_TYPE_REQUEST = 1,
+    ARP_TYPE_REPLY   = 2
+  };
+  uint16_t m_type;
+  MacAddress m_macSource;
+  MacAddress m_macDest;
+  Ipv4Address m_ipv4Source;
+  Ipv4Address m_ipv4Dest;
+};
+
+}; // namespace ns3
+
+#endif /* ARP_HEADER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/arp-ipv4-interface.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,80 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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
+ *
+ * Authors: 
+ *  Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
+ */
+
+#include "ns3/packet.h"
+#include "ns3/composite-trace-resolver.h"
+#include "ns3/node.h"
+#include "ns3/net-device.h"
+
+#include "arp-ipv4-interface.h"
+#include "i-arp-private.h"
+#include "ipv4.h"
+
+namespace ns3 {
+
+ArpIpv4Interface::ArpIpv4Interface (Node *node, NetDevice *device)
+  : Ipv4Interface (device),
+    m_node (node)
+{
+  m_node->Ref ();
+}
+ArpIpv4Interface::~ArpIpv4Interface ()
+{
+  m_node->Unref ();
+}
+
+TraceResolver *
+ArpIpv4Interface::DoCreateTraceResolver (TraceContext const &context)
+{
+  CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
+  if (PeekDevice () != 0)
+    {
+      resolver->Add ("netdevice",
+                     MakeCallback (&NetDevice::CreateTraceResolver, PeekDevice ()),
+                     ArpIpv4Interface::NETDEVICE);
+    }
+  
+  return resolver;
+}
+
+void 
+ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest)
+{
+  NS_ASSERT (PeekDevice () != 0);
+  if (PeekDevice ()->NeedsArp ())
+    {
+      IArpPrivate * arp = m_node->QueryInterface<IArpPrivate> (IArpPrivate::iid);
+      MacAddress hardwareDestination;
+      bool found = arp->Lookup (p, dest, PeekDevice (), &hardwareDestination);
+      if (found)
+        {
+          PeekDevice ()->Send (p, hardwareDestination, Ipv4::PROT_NUMBER);
+        }
+      arp->Unref ();
+    }
+  else
+    {
+      PeekDevice ()->Send (p, PeekDevice ()->GetBroadcast (), Ipv4::PROT_NUMBER);
+    }
+}
+
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/arp-ipv4-interface.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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
+ *
+ * Authors: 
+ *  Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
+ */
+#ifndef ARP_IPV4_INTERFACE_H
+#define ARP_IPV4_INTERFACE_H
+
+#include "ipv4-interface.h"
+
+namespace ns3 {
+
+class Node;
+
+/**
+ * \brief an Ipv4 Interface which uses ARP
+ *
+ * If you need to use ARP on top of a specific NetDevice, you
+ * can use this Ipv4Interface subclass to wrap it for the Ipv4 class
+ * when calling Ipv4::AddInterface.
+ */
+class ArpIpv4Interface : public Ipv4Interface
+{
+ public:
+  enum TraceType {
+    NETDEVICE,
+    ARP,
+  };
+  ArpIpv4Interface (Node *node, NetDevice *device);
+  virtual ~ArpIpv4Interface ();
+
+ private:
+  virtual void SendTo (Packet p, Ipv4Address dest);
+  virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context);
+  Node *m_node;
+};
+
+}//namespace ns3
+
+
+#endif /* ARP_IPV4_INTERFACE_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/arp.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,236 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2006 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#include "ns3/packet.h"
+#include "ns3/debug.h"
+#include "ns3/empty-trace-resolver.h"
+#include "ns3/node.h"
+#include "ns3/net-device.h"
+
+#include "arp.h"
+#include "arp-header.h"
+#include "arp-cache.h"
+#include "ipv4-interface.h"
+#include "i-ipv4-private.h"
+
+NS_DEBUG_COMPONENT_DEFINE ("Arp");
+
+namespace ns3 {
+
+const uint16_t Arp::PROT_NUMBER = 0x0806;
+
+Arp::Arp (Node *node)
+  : L3Protocol (PROT_NUMBER, 0/* XXX: correct version number ? */ ),
+    m_node (node)
+{
+  m_node->Ref ();
+}
+
+Arp::~Arp ()
+{
+  Dispose ();
+}
+
+void 
+Arp::DoDispose (void)
+{
+  for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++)
+    {
+      delete *i;
+    }
+  m_cacheList.clear ();
+  if (m_node != 0)
+    {
+      m_node->Unref ();
+      m_node = 0;
+    }
+  L3Protocol::DoDispose ();
+}
+
+TraceResolver *
+Arp::CreateTraceResolver (TraceContext const &context)
+{
+  return new EmptyTraceResolver (context);
+}
+
+ArpCache *
+Arp::FindCache (NetDevice *device)
+{
+  for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++)
+    {
+      if ((*i)->PeekDevice () == device)
+	{
+	  return *i;
+	}
+    }
+  IIpv4Private *ipv4 = m_node->QueryInterface<IIpv4Private> (IIpv4Private::iid);
+  Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device);
+  ipv4->Unref ();
+  ArpCache * cache = new ArpCache (device, interface);
+  NS_ASSERT (device->IsBroadcast ());
+  device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache));
+  m_cacheList.push_back (cache);
+  return cache;
+}
+
+void 
+Arp::Receive(Packet& packet, NetDevice *device)
+{
+  ArpCache *cache = FindCache (device);
+  ArpHeader arp;
+  packet.RemoveHeader (arp);
+  if (arp.IsRequest () && 
+      arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ()) 
+    {
+      NS_DEBUG ("node="<<m_node->GetId () <<", got request from " << 
+                arp.GetSourceIpv4Address () << " -- send reply");
+      SendArpReply (cache, arp.GetSourceIpv4Address (),
+                    arp.GetSourceHardwareAddress ());
+    } 
+  else if (arp.IsReply () &&
+           arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress ()) &&
+           arp.GetDestinationHardwareAddress ().IsEqual (device->GetAddress ())) 
+    {
+      Ipv4Address from = arp.GetSourceIpv4Address ();
+      ArpCache::Entry *entry = cache->Lookup (from);
+      if (entry != 0)
+        {
+          if (entry->IsWaitReply ()) 
+            {
+              NS_DEBUG ("node="<<m_node->GetId ()<<", got reply from " << 
+                        arp.GetSourceIpv4Address ()
+                     << " for waiting entry -- flush");
+              MacAddress from_mac = arp.GetSourceHardwareAddress ();
+              Packet waiting = entry->MarkAlive (from_mac);
+	      cache->GetInterface ()->Send (waiting, arp.GetSourceIpv4Address ());
+            } 
+          else 
+            {
+              // ignore this reply which might well be an attempt 
+              // at poisening my arp cache.
+              NS_DEBUG ("node="<<m_node->GetId ()<<", got reply from " << 
+                        arp.GetSourceIpv4Address () << 
+                        " for non-waiting entry -- drop");
+	      // XXX report packet as dropped.
+            }
+        } 
+      else 
+        {
+          NS_DEBUG ("node="<<m_node->GetId ()<<", got reply for unknown entry -- drop");
+	  // XXX report packet as dropped.
+        }
+    }
+}
+bool 
+Arp::Lookup (Packet &packet, Ipv4Address destination, 
+	     NetDevice *device,
+	     MacAddress *hardwareDestination)
+{
+  ArpCache *cache = FindCache (device);
+  ArpCache::Entry *entry = cache->Lookup (destination);
+  if (entry != 0)
+    {
+      if (entry->IsExpired ()) 
+        {
+          if (entry->IsDead ()) 
+            {
+              NS_DEBUG ("node="<<m_node->GetId ()<<
+                        ", dead entry for " << destination << " expired -- send arp request");
+              entry->MarkWaitReply (packet);
+              SendArpRequest (cache, destination);
+            } 
+          else if (entry->IsAlive ()) 
+            {
+              NS_DEBUG ("node="<<m_node->GetId ()<<
+                        ", alive entry for " << destination << " expired -- send arp request");
+              entry->MarkWaitReply (packet);
+              SendArpRequest (cache, destination);
+            } 
+          else if (entry->IsWaitReply ()) 
+            {
+              NS_DEBUG ("node="<<m_node->GetId ()<<
+                        ", wait reply for " << destination << " expired -- drop");
+              entry->MarkDead ();
+	      // XXX report packet as 'dropped'
+            }
+        } 
+      else 
+        {
+          if (entry->IsDead ()) 
+            {
+              NS_DEBUG ("node="<<m_node->GetId ()<<
+                        ", dead entry for " << destination << " valid -- drop");
+	      // XXX report packet as 'dropped'
+            } 
+          else if (entry->IsAlive ()) 
+            {
+              NS_DEBUG ("node="<<m_node->GetId ()<<
+                        ", alive entry for " << destination << " valid -- send");
+	      *hardwareDestination = entry->GetMacAddress ();
+              return true;
+            } 
+          else if (entry->IsWaitReply ()) 
+            {
+              NS_DEBUG ("node="<<m_node->GetId ()<<
+                        ", wait reply for " << destination << " valid -- drop previous");
+              Packet old = entry->UpdateWaitReply (packet);
+	      // XXX report 'old' packet as 'dropped'
+            }
+        }
+
+    }
+  else
+    {
+      // This is our first attempt to transmit data to this destination.
+      NS_DEBUG ("node="<<m_node->GetId ()<<
+                ", no entry for " << destination << " -- send arp request");
+      entry = cache->Add (destination);
+      entry->MarkWaitReply (packet);
+      SendArpRequest (cache, destination);
+    }
+  return false;
+}
+
+void
+Arp::SendArpRequest (ArpCache const *cache, Ipv4Address to)
+{
+  ArpHeader arp;
+  arp.SetRequest (cache->PeekDevice ()->GetAddress (),
+		  cache->GetInterface ()->GetAddress (), 
+                  cache->PeekDevice ()->GetBroadcast (),
+                  to);
+  Packet packet;
+  packet.AddHeader (arp);
+  cache->PeekDevice ()->Send (packet, cache->PeekDevice ()->GetBroadcast (), PROT_NUMBER);
+}
+
+void
+Arp::SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac)
+{
+  ArpHeader arp;
+  arp.SetReply (cache->PeekDevice ()->GetAddress (),
+                cache->GetInterface ()->GetAddress (),
+                toMac, toIp);
+  Packet packet;
+  packet.AddHeader (arp);
+  cache->PeekDevice ()->Send (packet, toMac, PROT_NUMBER);
+}
+
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/arp.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,66 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2006 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef ARP_H
+#define ARP_H
+
+#include <list>
+#include "ns3/ipv4-address.h"
+#include "ns3/mac-address.h"
+#include "l3-protocol.h"
+
+namespace ns3 {
+
+class ArpCache;
+class NetDevice;
+class Node;
+class Packet;
+class TraceResolver;
+class TraceContext;
+
+class Arp : public L3Protocol
+{
+public:
+  static const uint16_t PROT_NUMBER;
+
+  Arp (Node *node);
+  ~Arp ();
+
+  virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
+
+  virtual void Receive(Packet& p, NetDevice *device);
+  bool Lookup (Packet &p, Ipv4Address destination, 
+	       NetDevice *device,
+	       MacAddress *hardwareDestination);
+protected:
+  virtual void DoDispose (void);
+private:
+  typedef std::list<ArpCache *> CacheList;
+  ArpCache *FindCache (NetDevice *device);
+  void SendArpRequest (ArpCache const *cache, Ipv4Address to);
+  void SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac);
+  CacheList m_cacheList;
+  Node *m_node;
+};
+
+}//namespace ns3
+
+
+#endif /* ARP_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ascii-trace.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,136 @@
+/* -*-	Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#include "ascii-trace.h"
+
+#include "ns3/trace-context.h"
+#include "ns3/trace-root.h"
+#include "ns3/simulator.h"
+#include "ns3/node.h"
+#include "ns3/queue.h"
+#include "ns3/node-list.h"
+#include "ns3/llc-snap-header.h"
+
+#include "ipv4.h"
+#include "arp-header.h"
+#include "udp-header.h"
+#include "ipv4-header.h"
+
+namespace ns3 {
+
+AsciiTrace::AsciiTrace (std::string filename)
+{
+  m_os.open (filename.c_str ());
+}
+AsciiTrace::~AsciiTrace ()
+{
+  m_os.close ();
+}
+void
+AsciiTrace::TraceAllQueues (void)
+{
+  TraceRoot::Connect ("/nodes/*/ipv4/interfaces/*/netdevice/queue/*",
+                      MakeCallback (&AsciiTrace::LogDevQueue, this));
+}
+void
+AsciiTrace::TraceAllNetDeviceRx (void)
+{
+  TraceRoot::Connect ("/nodes/*/ipv4/interfaces/*/netdevice/rx",
+                      MakeCallback (&AsciiTrace::LogDevRx, this));
+}
+
+void
+AsciiTrace::PrintType (Packet const &packet)
+{
+  Packet p = packet;
+  LlcSnapHeader llc;
+  p.RemoveHeader (llc);
+  switch (llc.GetType ())
+    {
+    case 0x0800: {
+      Ipv4Header ipv4;
+      p.RemoveHeader (ipv4);
+      if (ipv4.GetProtocol () == 17)
+        {
+          UdpHeader udp;
+          p.RemoveHeader (udp);
+          m_os << "udp size=" << p.GetSize ();
+        }
+    } break;
+    case 0x0806: {
+      ArpHeader arp;
+      p.RemoveHeader (arp);
+      m_os << "arp ";
+      if (arp.IsRequest ())
+        {
+          m_os << "request";
+        }
+      else
+        {
+          m_os << "reply ";
+        }
+    } break;
+    }
+} 
+
+void 
+AsciiTrace::LogDevQueue (TraceContext const &context, Packet const &packet)
+{
+  enum Queue::TraceType type;
+  context.Get (type);
+  switch (type) 
+    {
+    case Queue::ENQUEUE:
+      m_os << "+ ";
+      break;
+    case Queue::DEQUEUE:
+      m_os << "- ";
+      break;
+    case Queue::DROP:
+      m_os << "d ";
+      break;
+    }
+  m_os << Simulator::Now ().GetSeconds () << " ";
+  NodeList::NodeIndex nodeIndex;
+  context.Get (nodeIndex);
+  m_os << "node=" << NodeList::PeekNode (nodeIndex)->GetId () << " ";
+  Ipv4::InterfaceIndex interfaceIndex;
+  context.Get (interfaceIndex);
+  m_os << "interface=" << interfaceIndex << " ";
+  m_os << "pkt-uid=" << packet.GetUid () << " ";
+  PrintType (packet);
+  m_os << std::endl;
+}
+void 
+AsciiTrace::LogDevRx (TraceContext const &context, Packet &p)
+{
+  m_os << "r " << Simulator::Now ().GetSeconds () << " ";
+  NodeList::NodeIndex nodeIndex;
+  context.Get (nodeIndex);
+  m_os << "node=" << NodeList::PeekNode (nodeIndex)->GetId () << " ";
+  Ipv4::InterfaceIndex interfaceIndex;
+  context.Get (interfaceIndex);
+  m_os << "interface=" << interfaceIndex << " ";
+  m_os << "pkt-uid=" << p.GetUid () << " ";
+  PrintType (p);
+  m_os << std::endl;  
+}
+
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ascii-trace.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,48 @@
+/* -*-	Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef ASCII_TRACE_H
+#define ASCII_TRACE_H
+
+#include <string>
+#include <fstream>
+
+namespace ns3 {
+
+class Packet;
+class TraceContext;
+
+class AsciiTrace 
+{
+public:
+  AsciiTrace (std::string filename);
+  ~AsciiTrace ();
+  void TraceAllQueues (void);
+  void TraceAllNetDeviceRx (void);
+private:
+  void PrintType (Packet const &p);
+  void LogDevQueue (TraceContext const &context, const Packet &p);
+  void LogDevRx (TraceContext const &context, Packet &p);
+  std::ofstream m_os;
+};
+
+}//namespace ns3
+
+#endif /* ASCII_TRACE_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/header-utils.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,49 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2006 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#include "header-utils.h"
+
+namespace ns3 {
+
+void WriteTo (Buffer::Iterator &i, Ipv4Address ad)
+{
+  i.WriteHtonU32 (ad.GetHostOrder ());
+}
+void WriteTo (Buffer::Iterator &i, MacAddress ad)
+{
+  uint8_t mac[MacAddress::MAX_LEN];
+  ad.Peek (mac);
+  i.Write (mac, ad.GetLength ());
+}
+
+void ReadFrom (Buffer::Iterator &i, Ipv4Address &ad)
+{
+  ad.SetHostOrder (i.ReadNtohU32 ());
+}
+void ReadFrom (Buffer::Iterator &i, MacAddress &ad, uint32_t len)
+{
+  uint8_t mac[MacAddress::MAX_LEN];
+  i.Read (mac, len);
+  ad.Set (mac, len);
+}
+
+
+
+}; // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/header-utils.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,38 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2006 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef HEADER_UTILS_H
+#define HEADER_UTILS_H
+
+#include "ns3/buffer.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/mac-address.h"
+
+namespace ns3 {
+
+void WriteTo (Buffer::Iterator &i, Ipv4Address ad);
+void WriteTo (Buffer::Iterator &i, MacAddress ad);
+
+void ReadFrom (Buffer::Iterator &i, Ipv4Address &ad);
+void ReadFrom (Buffer::Iterator &i, MacAddress &ad, uint32_t len);
+
+};
+
+#endif /* HEADER_UTILS_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/i-arp-private.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,58 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#include "i-arp-private.h"
+#include "ns3/iid-manager.h"
+#include "arp.h"
+#include "ns3/assert.h"
+
+namespace ns3 {
+
+const uint32_t IArpPrivate::iid = IidManager::Allocate ("IArpPrivate");
+
+IArpPrivate::IArpPrivate (Arp *arp)
+  : NsUnknown (IArpPrivate::iid),
+    m_arp (arp)
+{
+  m_arp->Ref ();
+}
+IArpPrivate::~IArpPrivate ()
+{
+  NS_ASSERT (m_arp == 0);
+}
+
+bool 
+IArpPrivate::Lookup (Packet &p, Ipv4Address destination, 
+		     NetDevice *device,
+		     MacAddress *hardwareDestination)
+{
+  return m_arp->Lookup (p, destination, device, hardwareDestination);
+}
+
+void
+IArpPrivate::DoDispose (void)
+{
+  m_arp->Unref ();
+  m_arp = 0;
+  NsUnknown::DoDispose ();
+}
+
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/i-arp-private.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,51 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef I_ARP_PRIVATE_H
+#define I_ARP_PRIVATE_H
+
+#include "ns3/ns-unknown.h"
+#include "ns3/ipv4-address.h"
+
+namespace ns3 {
+
+class NetDevice;
+class MacAddress;
+class Packet;
+class Arp;
+
+class IArpPrivate : public NsUnknown
+{
+public:
+  static const uint32_t iid;
+  IArpPrivate (Arp *arp);
+  virtual ~IArpPrivate ();
+  bool Lookup (Packet &p, Ipv4Address destination, 
+	       NetDevice *device,
+	       MacAddress *hardwareDestination);
+protected:
+  virtual void DoDispose (void);
+private:
+  Arp *m_arp;
+};
+
+} // namespace ns3
+
+#endif /* I_ARP_PRIVATE_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/i-ipv4-impl.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,144 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#include "i-ipv4-impl.h"
+#include "ipv4.h"
+#include "ns3/assert.h"
+
+namespace ns3 {
+
+IIpv4Impl::IIpv4Impl (Ipv4 *ipv4)
+  : m_ipv4 (ipv4)
+{
+  m_ipv4->Ref ();
+}
+IIpv4Impl::~IIpv4Impl ()
+{
+  NS_ASSERT (m_ipv4 == 0);
+}
+void 
+IIpv4Impl::DoDispose (void)
+{
+  m_ipv4->Unref ();
+  m_ipv4 = 0;
+}
+
+void 
+IIpv4Impl::AddHostRouteTo (Ipv4Address dest, 
+			   Ipv4Address nextHop, 
+			   uint32_t interface)
+{
+  m_ipv4->AddHostRouteTo (dest, nextHop, interface);
+}
+void 
+IIpv4Impl::AddHostRouteTo (Ipv4Address dest, 
+			   uint32_t interface)
+{
+  m_ipv4->AddHostRouteTo (dest, interface);
+}
+void 
+IIpv4Impl::AddNetworkRouteTo (Ipv4Address network, 
+			      Ipv4Mask networkMask, 
+			      Ipv4Address nextHop, 
+			      uint32_t interface)
+{
+  m_ipv4->AddNetworkRouteTo (network, networkMask, nextHop, interface);
+}
+void 
+IIpv4Impl::AddNetworkRouteTo (Ipv4Address network, 
+			      Ipv4Mask networkMask, 
+			      uint32_t interface)
+{
+  m_ipv4->AddNetworkRouteTo (network, networkMask, interface);
+}
+void 
+IIpv4Impl::SetDefaultRoute (Ipv4Address nextHop, 
+			    uint32_t interface)
+{
+  m_ipv4->SetDefaultRoute (nextHop, interface);
+}
+uint32_t 
+IIpv4Impl::GetNRoutes (void)
+{
+  return m_ipv4->GetNRoutes ();
+}
+Ipv4Route *
+IIpv4Impl::GetRoute (uint32_t i)
+{
+  return m_ipv4->GetRoute (i);
+}
+void 
+IIpv4Impl::RemoveRoute (uint32_t i)
+{
+  return m_ipv4->RemoveRoute (i);
+}
+uint32_t 
+IIpv4Impl::AddInterface (NetDevice *device)
+{
+  return m_ipv4->AddInterface (device);
+}
+uint32_t 
+IIpv4Impl::GetNInterfaces (void)
+{
+  return m_ipv4->GetNInterfaces ();
+}
+
+void 
+IIpv4Impl::SetAddress (uint32_t i, Ipv4Address address)
+{
+  m_ipv4->SetAddress (i, address);
+}
+void 
+IIpv4Impl::SetNetworkMask (uint32_t i, Ipv4Mask mask)
+{
+  m_ipv4->SetNetworkMask (i, mask);
+}
+Ipv4Mask 
+IIpv4Impl::GetNetworkMask (uint32_t i) const
+{
+  return m_ipv4->GetNetworkMask (i);
+}
+Ipv4Address 
+IIpv4Impl::GetAddress (uint32_t i) const
+{
+  return m_ipv4->GetAddress (i);
+}
+uint16_t 
+IIpv4Impl::GetMtu (uint32_t i) const
+{
+  return m_ipv4->GetMtu (i);
+}
+bool 
+IIpv4Impl::IsUp (uint32_t i) const
+{
+  return m_ipv4->IsUp (i);
+}
+void 
+IIpv4Impl::SetUp (uint32_t i)
+{
+  m_ipv4->SetUp (i);
+}
+void 
+IIpv4Impl::SetDown (uint32_t i)
+{
+  m_ipv4->SetDown (i);
+}
+
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/i-ipv4-impl.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,73 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef I_IPV4_IMPL_H
+#define I_IPV4_IMPL_H
+
+#include "ns3/i-ipv4.h"
+
+namespace ns3 {
+
+class Ipv4;
+
+class IIpv4Impl : public IIpv4
+{
+public:
+  IIpv4Impl (Ipv4 *ipv4);
+
+  virtual ~IIpv4Impl ();
+
+  virtual void AddHostRouteTo (Ipv4Address dest, 
+			       Ipv4Address nextHop, 
+			       uint32_t interface);
+  virtual void AddHostRouteTo (Ipv4Address dest, 
+			       uint32_t interface);
+  virtual void AddNetworkRouteTo (Ipv4Address network, 
+				  Ipv4Mask networkMask, 
+				  Ipv4Address nextHop, 
+				  uint32_t interface);
+  virtual void AddNetworkRouteTo (Ipv4Address network, 
+				  Ipv4Mask networkMask, 
+				  uint32_t interface);
+  virtual void SetDefaultRoute (Ipv4Address nextHop, 
+				uint32_t interface);
+  virtual uint32_t GetNRoutes (void);
+  virtual Ipv4Route *GetRoute (uint32_t i);
+  virtual void RemoveRoute (uint32_t i);
+  virtual uint32_t AddInterface (NetDevice *device);
+  virtual uint32_t GetNInterfaces (void);  
+
+  virtual void SetAddress (uint32_t i, Ipv4Address address);
+  virtual void SetNetworkMask (uint32_t i, Ipv4Mask mask);
+  virtual Ipv4Mask GetNetworkMask (uint32_t t) const;
+  virtual Ipv4Address GetAddress (uint32_t i) const;
+  virtual uint16_t GetMtu (uint32_t i) const;
+  virtual bool IsUp (uint32_t i) const;
+  virtual void SetUp (uint32_t i);
+  virtual void SetDown (uint32_t i);
+protected:
+  virtual void DoDispose (void);
+private:
+  Ipv4 *m_ipv4;
+};
+
+} // namespace ns3
+
+#endif /* I_IPV4_IMPL_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/i-ipv4-private.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,69 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#include "i-ipv4-private.h"
+#include "ipv4.h"
+#include "ns3/assert.h"
+#include "ns3/iid-manager.h"
+
+namespace ns3 {
+
+const uint32_t IIpv4Private::iid = IidManager::Allocate ("IIpv4Private");
+
+IIpv4Private::IIpv4Private (Ipv4 *ipv4)
+  : NsUnknown (IIpv4Private::iid),
+    m_ipv4 (ipv4)
+{
+  m_ipv4->Ref ();
+}
+IIpv4Private::~IIpv4Private ()
+{
+  NS_ASSERT (m_ipv4 == 0);
+}
+TraceResolver *
+IIpv4Private::CreateTraceResolver (TraceContext const &context)
+{
+  return m_ipv4->CreateTraceResolver (context);
+}
+void 
+IIpv4Private::Send (Packet const &packet, Ipv4Address source, 
+		    Ipv4Address destination, uint8_t protocol)
+{
+  m_ipv4->Send (packet, source, destination, protocol);
+}
+Ipv4Interface *
+IIpv4Private::FindInterfaceForDevice (NetDevice const*device)
+{
+  return m_ipv4->FindInterfaceForDevice (device);
+}
+void 
+IIpv4Private::Receive(Packet& p, NetDevice *device)
+{
+  m_ipv4->Receive (p, device);
+}
+void 
+IIpv4Private::DoDispose (void)
+{
+  m_ipv4->Unref ();
+  m_ipv4 = 0;
+  NsUnknown::DoDispose ();
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/i-ipv4-private.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,57 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef I_IPV4_PRIVATE_H
+#define I_IPV4_PRIVATE_H
+
+#include "ns3/ns-unknown.h"
+#include "ns3/ipv4-address.h"
+#include <stdint.h>
+
+namespace ns3 {
+
+class Packet;
+class Ipv4;
+class TraceContext;
+class TraceResolver;
+class Ipv4Interface;
+class NetDevice;
+
+class IIpv4Private : public NsUnknown
+{
+public:
+  static const uint32_t iid;
+  IIpv4Private (Ipv4 *ipv4);
+  virtual ~IIpv4Private ();
+
+  TraceResolver *CreateTraceResolver (TraceContext const &context);
+  void Send (Packet const &packet, Ipv4Address source, 
+	     Ipv4Address destination, uint8_t protocol);
+  Ipv4Interface *FindInterfaceForDevice (NetDevice const*device);
+  void Receive(Packet& p, NetDevice *device);
+protected:
+  virtual void DoDispose (void);
+private:
+  Ipv4 *m_ipv4;
+};
+
+} // namespace ns3
+
+#endif /* I_IPV4_PRIVATE_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/i-udp-impl.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,54 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#include "i-udp-impl.h"
+#include "udp.h"
+#include "ns3/assert.h"
+
+namespace ns3 {
+
+IUdpImpl::IUdpImpl (Udp *udp)
+  : m_udp (udp)
+{
+  m_udp->Ref ();
+}
+IUdpImpl::~IUdpImpl ()
+{
+  NS_ASSERT (m_udp == 0);
+}
+
+Socket *
+IUdpImpl::CreateSocket (void)
+{
+  return m_udp->CreateSocket ();
+}
+
+void 
+IUdpImpl::DoDispose (void)
+{
+  if (m_udp != 0)
+    {
+      m_udp->Unref ();
+      m_udp = 0;
+    }
+  IUdp::DoDispose ();
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/i-udp-impl.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,46 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef I_UDP_IMPL_H
+#define I_UDP_IMPL_H
+
+#include "ns3/i-udp.h"
+
+namespace ns3 {
+
+class Udp;
+
+class IUdpImpl : public IUdp
+{
+public:
+  IUdpImpl (Udp *udp);
+  virtual ~IUdpImpl ();
+
+  virtual Socket *CreateSocket (void);
+
+protected:
+  virtual void DoDispose (void);
+private:
+  Udp *m_udp;
+};
+
+} // namespace ns3
+
+#endif /* I_UDP_IMPL_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/internet-node.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,132 @@
+// -*- 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 the InternetNode class for ns3.
+// George F. Riley, Georgia Tech, Fall 2006
+
+#include "ns3/composite-trace-resolver.h"
+#include "ns3/application-list.h"
+#include "ns3/net-device.h"
+
+#include "l3-demux.h"
+#include "ipv4-l4-demux.h"
+#include "internet-node.h"
+#include "udp.h"
+#include "ipv4.h"
+#include "arp.h"
+#include "i-udp-impl.h"
+#include "i-arp-private.h"
+#include "i-ipv4-impl.h"
+#include "i-ipv4-private.h"
+
+namespace ns3 {
+
+
+InternetNode::InternetNode()
+{
+  Ipv4 *ipv4 = new Ipv4 (this);
+  Arp *arp = new Arp (this);
+  Udp *udp = new Udp (this);
+
+  ApplicationList *applicationList = new ApplicationList(this);
+  L3Demux *l3Demux = new L3Demux(this);
+  Ipv4L4Demux *ipv4L4Demux = new Ipv4L4Demux(this);
+
+  l3Demux->Insert (ipv4);
+  l3Demux->Insert (arp);
+  ipv4L4Demux->Insert (udp);
+
+  IUdpImpl *udpImpl = new IUdpImpl (udp);
+  IArpPrivate *arpPrivate = new IArpPrivate (arp);
+  IIpv4Impl *ipv4Impl = new IIpv4Impl (ipv4);
+  IIpv4Private *ipv4Private = new IIpv4Private (ipv4);
+
+  NsUnknown::AddInterface (ipv4Private);
+  NsUnknown::AddInterface (ipv4Impl);
+  NsUnknown::AddInterface (arpPrivate);
+  NsUnknown::AddInterface (udpImpl);
+  NsUnknown::AddInterface (applicationList);
+  NsUnknown::AddInterface (l3Demux);
+  NsUnknown::AddInterface (ipv4L4Demux);
+
+
+  applicationList->Unref ();
+  l3Demux->Unref ();
+  ipv4L4Demux->Unref ();
+  arp->Unref ();
+  ipv4->Unref ();
+  udp->Unref ();
+  udpImpl->Unref ();
+  arpPrivate->Unref ();
+  ipv4Impl->Unref ();
+  ipv4Private->Unref ();
+}
+
+InternetNode::~InternetNode ()
+{}
+
+void
+InternetNode::SetName (std::string name)
+{
+  m_name = name;
+}
+
+TraceResolver *
+InternetNode::CreateTraceResolver (TraceContext const &context)
+{
+  CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
+  IIpv4Private *ipv4 = QueryInterface<IIpv4Private> (IIpv4Private::iid);
+  resolver->Add ("ipv4",
+                 MakeCallback (&IIpv4Private::CreateTraceResolver, ipv4),
+                 InternetNode::IPV4);
+  ipv4->Unref ();
+
+  return resolver;
+}
+
+void 
+InternetNode::DoDispose()
+{
+  Node::DoDispose ();
+}
+
+void 
+InternetNode::DoAddDevice (NetDevice *device) const
+{
+  device->SetReceiveCallback (MakeCallback (&InternetNode::ReceiveFromDevice, this));
+}
+
+bool
+InternetNode::ReceiveFromDevice (NetDevice *device, const Packet &p, uint16_t protocolNumber) const
+{
+  L3Demux *demux = QueryInterface<L3Demux> (L3Demux::iid);
+  L3Protocol *target = demux->PeekProtocol (protocolNumber);
+  demux->Unref ();
+  if (target != 0) 
+    {
+      Packet packet = p;
+      target->Receive(packet, device);
+      return true;
+    }
+  return false;
+}
+
+
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/internet-node.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,57 @@
+// -*- 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>
+//
+// Define a basic "Internet" node, with a protocol stack (l3 and l4),
+// network device list, process list, and routing.
+
+#ifndef INTERNET_NODE_H
+#define INTERNET_NODE_H
+
+#include <list>
+#include <string>
+
+#include "ns3/node.h"
+
+namespace ns3 {
+
+class Packet;
+
+class InternetNode : public Node 
+{
+public:
+  enum TraceType {
+    IPV4,
+  };
+  InternetNode();
+  virtual ~InternetNode ();
+  virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
+
+  void SetName(std::string name);
+protected:
+  virtual void DoDispose(void);
+private:
+  virtual void DoAddDevice (NetDevice *device) const;
+  bool ReceiveFromDevice (NetDevice *device, const Packet &p, uint16_t protocolNumber) const;
+  std::string      m_name;
+};
+
+}//namespace ns3
+
+#endif /* INTERNET_NODE_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-checksum.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,53 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006,2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#include "ipv4-checksum.h"
+
+namespace ns3 {
+
+uint16_t 
+Ipv4ChecksumCalculate (uint16_t checksum, uint8_t *buffer, uint16_t size)
+{
+  /* see RFC 1071 to understand this code. */
+  uint32_t sum = checksum;
+  uint16_t *data = (uint16_t *) buffer;
+  for (uint16_t i = 0; i < (size/2); i++) {
+    sum += data[i];
+  }
+  if ((size % 2) != 0) {
+    uint8_t tmpBuf[2];
+    tmpBuf[0] = buffer[size-1];
+    tmpBuf[1] = 0;
+    data = (uint16_t *)tmpBuf;
+    sum += *data;
+  }
+  while (sum >> 16) {
+    sum = (sum & 0xffff) + (sum >> 16);
+  }
+  return sum;
+}
+
+uint16_t 
+Ipv4ChecksumComplete (uint16_t checksum)
+{
+  return ~checksum;
+}
+
+}; //namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-checksum.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,34 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006,2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef IPV4_CHECKSUM_H
+#define IPV4_CHECKSUM_H
+
+#include <stdint.h>
+
+namespace ns3 {
+
+uint16_t Ipv4ChecksumCalculate (uint16_t checksum, uint8_t *buffer, uint16_t size);
+
+uint16_t Ipv4ChecksumComplete (uint16_t checksum);
+
+}; //namespace ns3
+
+#endif /* IPV4_CHECKSUM_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-end-point-demux.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,218 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#include "ipv4-end-point-demux.h"
+#include "ipv4-end-point.h"
+
+namespace ns3{
+
+Ipv4EndPointDemux::Ipv4EndPointDemux ()
+  : m_ephemeral (1025)
+{}
+
+Ipv4EndPointDemux::~Ipv4EndPointDemux ()
+{
+  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
+    {
+      Ipv4EndPoint *endPoint = *i;
+      delete endPoint;
+    }
+  m_endPoints.clear ();
+}
+
+bool
+Ipv4EndPointDemux::LookupPortLocal (uint16_t port)
+{
+  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
+    {
+      if ((*i)->GetLocalPort  () == port) 
+        {
+          return true;
+        }
+    }
+  return false;
+}
+
+bool
+Ipv4EndPointDemux::LookupLocal (Ipv4Address addr, uint16_t port)
+{
+  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
+    {
+      if ((*i)->GetLocalPort () == port &&
+          (*i)->GetLocalAddress () == addr) 
+        {
+          return true;
+        }
+    }
+  return false;
+}
+
+Ipv4EndPoint *
+Ipv4EndPointDemux::Allocate (void)
+{
+  uint16_t port = AllocateEphemeralPort ();
+  if (port == 0) 
+    {
+      return 0;
+    }
+  Ipv4EndPoint *endPoint = new Ipv4EndPoint (Ipv4Address::GetAny (), port);
+  m_endPoints.push_back (endPoint);
+  return endPoint;
+}
+Ipv4EndPoint *
+Ipv4EndPointDemux::Allocate (Ipv4Address address)
+{
+  uint16_t port = AllocateEphemeralPort ();
+  if (port == 0) 
+    {
+      return 0;
+    }
+  Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port);
+  m_endPoints.push_back (endPoint);
+  return endPoint;
+}
+Ipv4EndPoint *
+Ipv4EndPointDemux::Allocate (uint16_t port)
+{
+  return Allocate (Ipv4Address::GetAny (), port);
+}
+Ipv4EndPoint *
+Ipv4EndPointDemux::Allocate (Ipv4Address address, uint16_t port)
+{
+  if (LookupLocal (address, port)) 
+    {
+      return 0;
+    }
+  Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port);
+  m_endPoints.push_back (endPoint);
+  return endPoint;
+}
+
+Ipv4EndPoint *
+Ipv4EndPointDemux::Allocate (Ipv4Address localAddress, uint16_t localPort,
+			     Ipv4Address peerAddress, uint16_t peerPort)
+{
+  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
+    {
+      if ((*i)->GetLocalPort () == localPort &&
+          (*i)->GetLocalAddress () == localAddress &&
+          (*i)->GetPeerPort () == peerPort &&
+          (*i)->GetPeerAddress () == peerAddress) 
+        {
+          /* no way we can allocate this end-point. */
+          return 0;
+        }
+    }
+  Ipv4EndPoint *endPoint = new Ipv4EndPoint (localAddress, localPort);
+  endPoint->SetPeer (peerAddress, peerPort);
+  m_endPoints.push_back (endPoint);
+  return endPoint;
+}
+
+void 
+Ipv4EndPointDemux::DeAllocate (Ipv4EndPoint *endPoint)
+{
+  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
+    {
+      if (*i == endPoint)
+        {
+          delete endPoint;
+          m_endPoints.erase (i);
+          break;
+        }
+    }
+}
+
+
+/*
+ * If we have an exact match, we return it.
+ * Otherwise, if we find a generic match, we return it.
+ * Otherwise, we return 0.
+ */
+Ipv4EndPoint *
+Ipv4EndPointDemux::Lookup (Ipv4Address daddr, uint16_t dport, 
+                              Ipv4Address saddr, uint16_t sport)
+{
+  uint32_t genericity = 3;
+  Ipv4EndPoint *generic = 0;
+  //TRACE ("lookup " << daddr << ":" << dport << " " << saddr << ":" << sport);
+  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
+    {
+#if 0
+      TRACE ("against " << 
+             (*i)->GetLocalAddress ()
+             << ":" << 
+             (*i)->GetLocalPort () 
+             << " " << 
+             (*i)->GetPeerAddress () 
+             << ":" 
+             << (*i)->GetPeerPort ());
+#endif
+      if ((*i)->GetLocalPort () != dport) 
+        {
+          continue;
+        }
+      if ((*i)->GetLocalAddress () == daddr &&
+          (*i)->GetPeerPort () == sport &&
+          (*i)->GetPeerAddress () == saddr) 
+        {
+          /* this is an exact match. */
+          return *i;
+        }
+      uint32_t tmp = 0;
+      if ((*i)->GetLocalAddress () == Ipv4Address::GetAny ()) 
+        {
+          tmp ++;
+        }
+      if ((*i)->GetPeerAddress () == Ipv4Address::GetAny ()) 
+        {
+          tmp ++;
+        }
+      if (tmp < genericity) 
+        {
+          generic = (*i);
+          genericity = tmp;
+        }
+    }
+  return generic;
+}
+
+uint16_t
+Ipv4EndPointDemux::AllocateEphemeralPort (void)
+{
+  uint16_t port = m_ephemeral;
+  do 
+    {
+      port++;
+      if (port > 5000) 
+        {
+          port = 1024;
+        }
+      if (!LookupPortLocal (port)) 
+        {
+          return port;
+        }
+  } while (port != m_ephemeral);
+  return 0;
+}
+
+} //namespace ns3
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-end-point-demux.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,67 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#ifndef IPV4_END_POINT_DEMUX_H
+#define IPV4_END_POINT_DEMUX_H
+
+#include <stdint.h>
+#include <list>
+#include "ns3/ipv4-address.h"
+
+namespace ns3 {
+
+class Ipv4EndPoint;
+
+class Ipv4EndPointDemux {
+public:
+  Ipv4EndPointDemux ();
+  ~Ipv4EndPointDemux ();
+
+  bool LookupPortLocal (uint16_t port);
+  bool LookupLocal (Ipv4Address addr, uint16_t port);
+  Ipv4EndPoint *Lookup (Ipv4Address daddr, 
+                        uint16_t dport, 
+                        Ipv4Address saddr, 
+                        uint16_t sport);
+
+  Ipv4EndPoint *Allocate (void);
+  Ipv4EndPoint *Allocate (Ipv4Address address);
+  Ipv4EndPoint *Allocate (uint16_t port);
+  Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port);
+  Ipv4EndPoint *Allocate (Ipv4Address localAddress, 
+                          uint16_t localPort,
+                          Ipv4Address peerAddress, 
+                          uint16_t peerPort);
+
+  void DeAllocate (Ipv4EndPoint *endPoint);
+
+ private:
+  uint16_t AllocateEphemeralPort (void);
+  typedef std::list<Ipv4EndPoint *> EndPoints;
+  typedef std::list<Ipv4EndPoint *>::iterator EndPointsI;
+
+  uint16_t m_ephemeral;
+  EndPoints m_endPoints;
+};
+
+} // namespace ns3
+
+#endif /* IPV4_END_POINTS_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-end-point.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,90 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#include "ipv4-end-point.h"
+
+namespace ns3 {
+
+Ipv4EndPoint::Ipv4EndPoint (Ipv4Address address, uint16_t port)
+  : m_localAddr (address), 
+    m_localPort (port),
+    m_peerAddr (Ipv4Address::GetAny ()),
+    m_peerPort (0)
+{}
+Ipv4EndPoint::~Ipv4EndPoint ()
+{
+  if (!m_destroyCallback.IsNull ())
+    {
+      m_destroyCallback ();
+    }
+}
+
+Ipv4Address 
+Ipv4EndPoint::GetLocalAddress (void)
+{
+  return m_localAddr;
+}
+uint16_t 
+Ipv4EndPoint::GetLocalPort (void)
+{
+  return m_localPort;
+}
+Ipv4Address 
+Ipv4EndPoint::GetPeerAddress (void)
+{
+  return m_peerAddr;
+}
+uint16_t 
+Ipv4EndPoint::GetPeerPort (void)
+{
+  return m_peerPort;
+}
+void 
+Ipv4EndPoint::SetPeer (Ipv4Address address, uint16_t port)
+{
+  m_peerAddr = address;
+  m_peerPort = port;
+}
+
+void 
+Ipv4EndPoint::SetRxCallback (Callback<void,const Packet &, Ipv4Address, uint16_t> callback)
+{
+  m_rxCallback = callback;
+}
+
+void 
+Ipv4EndPoint::SetDestroyCallback (Callback<void> callback)
+{
+  m_destroyCallback = callback;
+}
+
+void 
+Ipv4EndPoint::ForwardUp (const Packet &p, Ipv4Address saddr, uint16_t sport)
+{
+  if (!m_rxCallback.IsNull ())
+  {
+    m_rxCallback (p, saddr, sport);
+  }
+}
+
+
+
+}; // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-end-point.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,63 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#ifndef IPV4_END_POINT_H
+#define IPV4_END_POINT_H
+
+#include <stdint.h>
+#include "ns3/ipv4-address.h"
+#include "ns3/callback.h"
+
+namespace ns3 {
+
+class Header;
+class Packet;
+
+class Ipv4EndPoint {
+public:
+  Ipv4EndPoint (Ipv4Address address, uint16_t port);
+  ~Ipv4EndPoint ();
+
+  Ipv4Address GetLocalAddress (void);
+  uint16_t GetLocalPort (void);
+  Ipv4Address GetPeerAddress (void);
+  uint16_t GetPeerPort (void);
+
+  void SetPeer (Ipv4Address address, uint16_t port);
+
+  void SetRxCallback (Callback<void,const Packet &, Ipv4Address, uint16_t> callback);
+  void SetDestroyCallback (Callback<void> callback);
+
+  void ForwardUp (const Packet &p, Ipv4Address saddr, uint16_t sport);
+
+private:
+  Ipv4Address m_localAddr;
+  uint16_t m_localPort;
+  Ipv4Address m_peerAddr;
+  uint16_t m_peerPort;
+  Callback<void,const Packet &, Ipv4Address, uint16_t> m_rxCallback;
+  Callback<void> m_destroyCallback;
+};
+
+}; // namespace ns3
+
+
+#endif /* IPV4_END_POINT_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-header.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,308 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#include "ns3/assert.h"
+#include "ns3/debug.h"
+#include "ns3/header.h"
+#include "ipv4-header.h"
+
+NS_DEBUG_COMPONENT_DEFINE ("Ipv4Header");
+
+namespace ns3 {
+
+static uint16_t 
+UtilsNtoh16 (uint16_t v)
+{
+  uint16_t val;
+  uint8_t *array;
+  array = (uint8_t *)&v;
+  val = (array[0] << 8) | (array[1] << 0);
+  return val;
+}
+
+
+bool Ipv4Header::m_calcChecksum = false;
+
+Ipv4Header::Ipv4Header ()
+  : m_payloadSize (0),
+    m_identification (0),
+    m_tos (0),
+    m_ttl (0),
+    m_protocol (0),
+    m_flags (0),
+    m_fragmentOffset (0),
+    m_goodChecksum (true)
+{}
+Ipv4Header::~Ipv4Header ()
+{}
+
+void 
+Ipv4Header::EnableChecksums (void)
+{
+  m_calcChecksum = true;
+}
+
+void 
+Ipv4Header::SetPayloadSize (uint16_t size)
+{
+  m_payloadSize = size;
+}
+uint16_t 
+Ipv4Header::GetPayloadSize (void) const
+{
+  return m_payloadSize;
+}
+
+uint16_t 
+Ipv4Header::GetIdentification (void) const
+{
+  return m_identification;
+}
+void 
+Ipv4Header::SetIdentification (uint16_t identification)
+{
+  m_identification = identification;
+}
+
+
+
+void 
+Ipv4Header::SetTos (uint8_t tos)
+{
+  m_tos = tos;
+}
+uint8_t 
+Ipv4Header::GetTos (void) const
+{
+  return m_tos;
+}
+void 
+Ipv4Header::SetMoreFragments (void)
+{
+  m_flags |= MORE_FRAGMENTS;
+}
+void
+Ipv4Header::SetLastFragment (void)
+{
+  m_flags &= ~MORE_FRAGMENTS;
+}
+bool 
+Ipv4Header::IsLastFragment (void) const
+{
+  return !(m_flags & MORE_FRAGMENTS);
+}
+
+void 
+Ipv4Header::SetDontFragment (void)
+{
+  m_flags |= DONT_FRAGMENT;
+}
+void 
+Ipv4Header::SetMayFragment (void)
+{
+  m_flags &= ~DONT_FRAGMENT;
+}
+bool 
+Ipv4Header::IsDontFragment (void) const
+{
+  return (m_flags & DONT_FRAGMENT);
+}
+
+void 
+Ipv4Header::SetFragmentOffset (uint16_t offset)
+{
+  NS_ASSERT (!(offset & (~0x3fff)));
+  m_fragmentOffset = offset;
+}
+uint16_t 
+Ipv4Header::GetFragmentOffset (void) const
+{
+  NS_ASSERT (!(m_fragmentOffset & (~0x3fff)));
+  return m_fragmentOffset;
+}
+
+void 
+Ipv4Header::SetTtl (uint8_t ttl)
+{
+  m_ttl = ttl;
+}
+uint8_t 
+Ipv4Header::GetTtl (void) const
+{
+  return m_ttl;
+}
+  
+uint8_t 
+Ipv4Header::GetProtocol (void) const
+{
+  return m_protocol;
+}
+void 
+Ipv4Header::SetProtocol (uint8_t protocol)
+{
+  m_protocol = protocol;
+}
+
+void 
+Ipv4Header::SetSource (Ipv4Address source)
+{
+  m_source = source;
+}
+Ipv4Address
+Ipv4Header::GetSource (void) const
+{
+  return m_source;
+}
+
+void 
+Ipv4Header::SetDestination (Ipv4Address dst)
+{
+  m_destination = dst;
+}
+Ipv4Address
+Ipv4Header::GetDestination (void) const
+{
+  return m_destination;
+}
+
+
+bool
+Ipv4Header::IsChecksumOk (void) const
+{
+  return m_goodChecksum;
+}
+
+void 
+Ipv4Header::PrintTo (std::ostream &os) const
+{
+  // ipv4, right ?
+  os << "(ipv4)"
+     << " tos=" << (uint32_t)m_tos
+     << ", payload length=" << UtilsNtoh16 (m_payloadSize)
+     << ", id=" << m_identification
+     << ", " << (IsLastFragment ()?"last":"more")
+     << ", " << (IsDontFragment ()?"dont":"may")
+     << ", frag offset=" << m_fragmentOffset
+     << ", ttl=" << m_ttl
+     << ", protocol=" << m_protocol
+     << ", source=" << m_source
+     << ", destination=" << m_destination;
+}
+uint32_t 
+Ipv4Header::GetSerializedSize (void) const
+{
+  return 5 * 4;
+}
+
+void
+Ipv4Header::SerializeTo (Buffer::Iterator start) const
+{
+  Buffer::Iterator i = start;
+  
+  uint8_t verIhl = (4 << 4) | (5);
+  i.WriteU8 (verIhl);
+  i.WriteU8 (m_tos);
+  i.WriteHtonU16 (m_payloadSize + 5*4);
+  i.WriteHtonU16 (m_identification);
+  uint32_t fragmentOffset = m_fragmentOffset / 8;
+  uint8_t flagsFrag = (fragmentOffset >> 8) & 0x1f;
+  if (m_flags & DONT_FRAGMENT) 
+    {
+      flagsFrag |= (1<<6);
+    }
+  if (m_flags & MORE_FRAGMENTS) 
+    {
+      flagsFrag |= (1<<5);
+    }
+  i.WriteU8 (flagsFrag);
+  uint8_t frag = fragmentOffset & 0xff;
+  i.WriteU8 (frag);
+  i.WriteU8 (m_ttl);
+  i.WriteU8 (m_protocol);
+  i.WriteHtonU16 (0);
+  i.WriteHtonU32 (m_source.GetHostOrder ());
+  i.WriteHtonU32 (m_destination.GetHostOrder ());
+
+  if (m_calcChecksum) 
+    {
+#if 0
+      // XXX we need to add Buffer::Iterator::PeekData method
+      uint8_t *data = start.PeekData ();
+      uint16_t checksum = UtilsChecksumCalculate (0, data, GetSize ());
+      checksum = UtilsChecksumComplete (checksum);
+      NS_DEBUG ("checksum=" <<checksum);
+      i = start;
+      i.Next (10);
+      i.WriteU16 (checksum);
+#endif
+    }
+}
+uint32_t
+Ipv4Header::DeserializeFrom (Buffer::Iterator start)
+{
+  Buffer::Iterator i = start;
+  uint8_t verIhl = i.ReadU8 ();
+  uint8_t ihl = verIhl & 0x0f; 
+  uint16_t headerSize = ihl * 4;
+  NS_ASSERT ((verIhl >> 4) == 4);
+  m_tos = i.ReadU8 ();
+  uint16_t size = i.ReadNtohU16 ();
+  m_payloadSize = size - headerSize;
+  m_identification = i.ReadNtohU16 ();
+  uint8_t flags = i.ReadU8 ();
+  m_flags = 0;
+  if (flags & (1<<6)) 
+    {
+      m_flags |= DONT_FRAGMENT;
+    }
+  if (flags & (1<<5)) 
+    {
+      m_flags |= MORE_FRAGMENTS;
+    }
+  //XXXX I think we should clear some bits in fragmentOffset !
+  i.Prev ();
+  m_fragmentOffset = i.ReadNtohU16 ();
+  m_fragmentOffset *= 8;
+  m_ttl = i.ReadU8 ();
+  m_protocol = i.ReadU8 ();
+  i.Next (2); // checksum
+  m_source.SetHostOrder (i.ReadNtohU32 ());
+  m_destination.SetHostOrder (i.ReadNtohU32 ());
+
+  if (m_calcChecksum) 
+    {
+#if 0
+      uint8_t *data = start.PeekData ();
+      uint16_t localChecksum = UtilsChecksumCalculate (0, data, headerSize);
+      if (localChecksum == 0xffff) 
+        {
+          m_goodChecksum = true;
+        } 
+      else 
+        {
+          m_goodChecksum = false;
+        }
+#endif
+    }
+  return GetSerializedSize ();
+}
+
+}; // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-header.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,92 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#ifndef IPV4_HEADER_H
+#define IPV4_HEADER_H
+
+#include "ns3/header.h"
+#include "ns3/ipv4-address.h"
+
+namespace ns3 {
+
+class Ipv4Header : public Header {
+public:
+  Ipv4Header ();
+  virtual ~Ipv4Header ();
+
+  static void EnableChecksums (void);
+
+  void SetPayloadSize (uint16_t size);
+  void SetIdentification (uint16_t identification);
+  void SetTos (uint8_t);
+  void SetMoreFragments (void);
+  void SetLastFragment (void);
+  void SetDontFragment (void);
+  void SetMayFragment (void);
+  void SetFragmentOffset (uint16_t offset);
+  void SetTtl (uint8_t);
+  void SetProtocol (uint8_t);
+  void SetSource (Ipv4Address source);
+  void SetDestination (Ipv4Address destination);
+
+
+  uint16_t GetPayloadSize (void) const;
+  uint16_t GetIdentification (void) const;
+  uint8_t GetTos (void) const;
+  bool IsLastFragment (void) const;
+  bool IsDontFragment (void) const;
+  uint16_t GetFragmentOffset (void) const;
+  uint8_t GetTtl (void) const;
+  uint8_t GetProtocol (void) const;
+  Ipv4Address GetSource (void) const;
+  Ipv4Address GetDestination (void) const;
+  
+  bool IsChecksumOk (void) const;
+
+private:
+  virtual void PrintTo (std::ostream &os) const;
+  virtual uint32_t GetSerializedSize (void) const;
+  virtual void SerializeTo (Buffer::Iterator start) const;
+  virtual uint32_t DeserializeFrom (Buffer::Iterator start);
+
+  enum FlagsE {
+    DONT_FRAGMENT = (1<<0),
+    MORE_FRAGMENTS = (1<<1)
+  };
+
+  static bool m_calcChecksum;
+
+  uint16_t m_payloadSize;
+  uint16_t m_identification;
+  uint32_t m_tos : 8;
+  uint32_t m_ttl : 8;
+  uint32_t m_protocol : 8;
+  uint32_t m_flags : 3;
+  uint16_t m_fragmentOffset : 13;
+  Ipv4Address m_source;
+  Ipv4Address m_destination;
+  bool m_goodChecksum;
+};
+
+}; // namespace ns3
+
+
+#endif /* IPV4_HEADER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-interface.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,144 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006,2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#include "ipv4-interface.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/net-device.h"
+
+namespace ns3 {
+
+  /**
+   * By default, Ipv4 interface are created in the "down" state
+   * with ip address 192.168.0.1 and a matching mask. Before
+   * becoming useable, the user must invoke SetUp on them
+   * once the final Ipv4 address and mask has been set.
+   */
+Ipv4Interface::Ipv4Interface (NetDevice *nd) 
+  : m_netdevice (nd), 
+    m_ifup(false)
+{
+  if (m_netdevice != 0)
+    {
+      m_netdevice->Ref ();
+    }
+}
+
+Ipv4Interface::~Ipv4Interface ()
+{
+  if (m_netdevice != 0)
+    {
+      m_netdevice->Unref ();
+    }
+}
+
+NetDevice*
+Ipv4Interface::PeekDevice (void) const
+{
+  return m_netdevice;
+}
+
+TraceResolver *
+Ipv4Interface::CreateTraceResolver (TraceContext const &context)
+{
+  return DoCreateTraceResolver (context);
+}
+
+void 
+Ipv4Interface::SetAddress (Ipv4Address a)
+{
+  m_address = a;
+}
+void 
+Ipv4Interface::SetNetworkMask (Ipv4Mask mask)
+{
+  m_netmask = mask;
+}
+
+Ipv4Address
+Ipv4Interface::GetBroadcast (void) const
+{
+  uint32_t mask = m_netmask.GetHostOrder ();
+  uint32_t address = m_address.GetHostOrder ();
+  Ipv4Address broadcast = Ipv4Address (address | (~mask));
+  return broadcast;
+}
+Ipv4Mask 
+Ipv4Interface::GetNetworkMask (void) const
+{
+  return m_netmask;
+}
+Ipv4Address 
+Ipv4Interface::GetAddress (void) const
+{
+  return m_address;
+}
+
+uint16_t 
+Ipv4Interface::GetMtu (void) const
+{
+  if (m_netdevice == 0)
+    {
+      uint32_t mtu = (1<<16) - 1;
+      return mtu;
+    }
+  return m_netdevice->GetMtu ();
+}
+
+  /**
+   * These are IP interface states and may be distinct from 
+   * NetDevice states, such as found in real implementations
+   * (where the device may be down but IP interface state is still up).
+   */
+bool 
+Ipv4Interface::IsUp (void) const
+{
+  return m_ifup;
+}
+
+bool 
+Ipv4Interface::IsDown (void) const
+{
+  return !m_ifup;
+}
+
+void 
+Ipv4Interface::SetUp (void)
+{
+  m_ifup = true;
+}
+
+void 
+Ipv4Interface::SetDown (void)
+{
+  m_ifup = false;
+}
+
+// public wrapper on private virtual function
+void 
+Ipv4Interface::Send(Packet p, Ipv4Address dest)
+{
+  if (IsUp()) {
+    SendTo(p, dest);
+  }
+}
+
+}; // namespace ns3
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-interface.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,164 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006,2007 INRIA
+ * 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
+ *
+ * Authors: 
+ *  Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
+ *  Tom Henderson <tomh@tomh.org>
+ */
+#ifndef IPV4_INTERFACE_H
+#define IPV4_INTERFACE_H
+
+#include <list>
+#include "ns3/ipv4-address.h"
+
+namespace ns3 {
+
+class NetDevice;
+class Packet;
+class TraceResolver;
+class TraceContext;
+
+/**
+ * \brief The IPv4 representation of a network interface
+ *
+ * This class roughly corresponds to the struct in_device
+ * of Linux; the main purpose is to provide address-family
+ * specific information (addresses) about an interface.
+ *
+ * This class defines two APIs:
+ *  - the public API which is expected to be used by both 
+ *    the IPv4 layer and the user during forwarding and 
+ *    configuration.
+ *  - the private API which is expected to be implemented
+ *    by subclasses of this base class. One such subclass 
+ *    will be a Loopback interface which loops every
+ *    packet sent back to the ipv4 layer. Another such 
+ *    subclass typically contains the Ipv4 <-> MAC address
+ *    translation logic which will use most of the time the
+ *    ARP/RARP protocols.
+ *
+ * By default, Ipv4 interface are created in the "down" state
+ * with ip address 192.168.0.1 and a matching mask. Before
+ * becoming useable, the user must invoke SetUp on them
+ * once the final Ipv4 address and mask has been set.
+ *
+ * Subclasses must implement the two methods:
+ *   - Ipv4Interface::SendTo
+ *   - Ipv4Interface::DoCreateTraceResolver
+ */
+class Ipv4Interface 
+{
+public:
+  /**
+   * \param nd the NetDevice associated to this Ipv4Interface.
+   *           This value can be zero in which case the MTU
+   *           of this interface will be 2^(16-1).
+   */
+  Ipv4Interface (NetDevice *nd);
+  virtual ~Ipv4Interface();
+
+  /**
+   * \param context the trace context to use to construct the
+   *        TraceResolver to return
+   * \returns a TraceResolver which can resolve all traces
+   *          performed in this object. The caller must
+   *          delete the returned object.
+   *
+   * This method will delegate the work to the private DoCreateTraceResolver 
+   * method which is supposed to be implemented by subclasses.
+   */
+  TraceResolver *CreateTraceResolver (TraceContext const &context);
+  /**
+   * \returns the underlying NetDevice. This method can return
+   *          zero if this interface has no associated NetDevice.
+   */
+  NetDevice *PeekDevice (void) const;
+
+  /**
+   * \param a set the ipv4 address of this interface.
+   */
+  void SetAddress (Ipv4Address a);
+  /**
+   * \param mask set the ipv4 netmask of this interface.
+   */
+  void SetNetworkMask (Ipv4Mask mask);
+
+  /**
+   * \returns the broadcast ipv4 address associated to this interface
+   */
+  Ipv4Address GetBroadcast (void) const;
+  /**
+   * \returns the ipv4 netmask of this interface
+   */
+  Ipv4Mask GetNetworkMask (void) const;
+  /**
+   * \returns the ipv4 address of this interface
+   */
+  Ipv4Address GetAddress (void) const;
+
+  /**
+   * This function a pass-through to NetDevice GetMtu, modulo
+   * the  LLC/SNAP header i.e., ipv4MTU = NetDeviceMtu - LLCSNAPSIZE
+   * \returns the Maximum Transmission Unit associated to this interface.
+   */
+  uint16_t GetMtu (void) const;
+
+  /**
+   * These are IP interface states and may be distinct from 
+   * NetDevice states, such as found in real implementations
+   * (where the device may be down but IP interface state is still up).
+   */
+  /**
+   * \returns true if this interface is enabled, false otherwise.
+   */
+  bool IsUp (void) const;
+  /**
+   * \returns true if this interface is disabled, false otherwise.
+   */
+  bool IsDown (void) const;
+  /**
+   * Enable this interface
+   */
+  void SetUp (void);
+  /**
+   * Disable this interface
+   */
+  void SetDown (void);
+
+  /**
+   * \param p packet to send
+   * \param dest next hop address of packet.
+   *
+   * This method will eventually call the private
+   * SendTo method which must be implemented by subclasses.
+   */ 
+  void Send(Packet p, Ipv4Address dest);
+
+
+ private:
+  virtual void SendTo (Packet p, Ipv4Address dest) = 0;
+  virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0;
+  NetDevice* m_netdevice;
+  bool m_ifup;
+  Ipv4Address m_address;
+  Ipv4Mask m_netmask;
+};
+
+}; // namespace ns3
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-l4-demux.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,106 @@
+// -*- 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>
+//
+
+// Define the layer 4 demultiplexer object for ns3.
+// George F. Riley, Georgia Tech, Fall 2006
+
+#include <sstream>
+#include "ns3/composite-trace-resolver.h"
+#include "ns3/iid-manager.h"
+#include "ns3/node.h"
+#include "ipv4-l4-demux.h"
+#include "ipv4-l4-protocol.h"
+
+namespace ns3 {
+
+const uint32_t Ipv4L4Demux::iid = IidManager::Allocate ("Ipv4L4Demux");
+
+Ipv4L4Demux::Ipv4L4Demux (Node *node)
+  : NsUnknown (Ipv4L4Demux::iid),
+    m_node (node)
+{
+  m_node->Ref ();
+}
+
+Ipv4L4Demux::~Ipv4L4Demux()
+{}
+
+void
+Ipv4L4Demux::DoDispose (void)
+{
+  for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
+    {
+      (*i)->Dispose ();
+      (*i)->Unref ();
+    }
+  m_protocols.clear ();
+  if (m_node != 0)
+    {
+      m_node->Unref ();
+      m_node = 0;
+    }
+  NsUnknown::DoDispose ();
+}
+
+TraceResolver *
+Ipv4L4Demux::CreateTraceResolver (TraceContext const &context)
+{
+  CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
+  for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
+    {
+      Ipv4L4Protocol *protocol = *i;
+      std::string protValue;
+      std::ostringstream oss (protValue);
+      oss << (*i)->GetProtocolNumber ();
+      Ipv4L4ProtocolTraceType protocolNumber = (*i)->GetProtocolNumber ();
+      resolver->Add (protValue,
+                     MakeCallback (&Ipv4L4Protocol::CreateTraceResolver, protocol),
+                     protocolNumber);
+    }
+  return resolver;
+}
+void
+Ipv4L4Demux::Insert(Ipv4L4Protocol *protocol)
+{
+  protocol->Ref ();
+  m_protocols.push_back (protocol);
+}
+Ipv4L4Protocol* 
+Ipv4L4Demux::PeekProtocol(int protocolNumber)
+{
+  for (L4List_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
+    {
+      if ((*i)->GetProtocolNumber () == protocolNumber)
+	{
+	  return *i;
+	}
+    }
+  return 0;
+}
+void
+Ipv4L4Demux::Erase(Ipv4L4Protocol*protocol)
+{
+  m_protocols.remove (protocol);
+}
+
+
+
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-l4-demux.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,93 @@
+// -*- 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>
+//
+
+// Define the layer 4 demultiplexer object for ns3.
+// George F. Riley, Georgia Tech, Fall 2006
+
+#ifndef IPV4_L4_DEMUX_H
+#define IPV4_L4_DEMUX_H
+
+#include <list>
+#include "ns3/ns-unknown.h"
+
+namespace ns3 {
+
+class Ipv4L4Protocol;
+class Node;
+class TraceResolver;
+class TraceContext;
+
+/**
+ * \brief L4 Ipv4 Demux
+ */
+class Ipv4L4Demux : public NsUnknown
+{
+public:
+  static const uint32_t iid;
+  typedef int Ipv4L4ProtocolTraceType;
+  Ipv4L4Demux (Node *node);
+  virtual ~Ipv4L4Demux();
+
+  /**
+   * \param context the trace context to use to construct the
+   *        TraceResolver to return
+   * \returns a TraceResolver which can resolve all traces
+   *          performed in this object. The caller must
+   *          delete the returned object.
+   */
+  TraceResolver *CreateTraceResolver (TraceContext const &context);
+  /**
+   * \param protocol a template for the protocol to add to this L4 Demux.
+   * \returns the L4Protocol effectively added.
+   *
+   * Invoke Copy on the input template to get a copy of the input
+   * protocol which can be used on the Node on which this L4 Demux 
+   * is running. The new L4Protocol is registered internally as
+   * a working L4 Protocol and returned from this method.
+   * The caller does not get ownership of the returned pointer.
+   */
+  void Insert(Ipv4L4Protocol *protocol);
+  /**
+   * \param protocolNumber number of protocol to lookup
+   *        in this L4 Demux
+   * \returns a matching L4 Protocol
+   *
+   * This method is typically called by lower layers
+   * to forward packets up the stack to the right protocol.
+   * It is also called from InternetNode::GetUdp for example.
+   */
+  Ipv4L4Protocol* PeekProtocol(int protocolNumber);
+  /**
+   * \param protocol protocol to remove from this demux.
+   *
+   * The input value to this method should be the value
+   * returned from the Ipv4L4Protocol::Insert method.
+   */
+  void Erase(Ipv4L4Protocol*protocol);
+private:
+  virtual void DoDispose (void);
+  typedef std::list<Ipv4L4Protocol*> L4List_t;
+  L4List_t m_protocols;
+  Node *m_node;
+};
+
+} //namespace ns3
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-l4-protocol.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,54 @@
+// -*- 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>
+//
+
+// NS3 - Layer 4 Protocol base class
+// George F. Riley, Georgia Tech, Spring 2007
+
+#include "ipv4-l4-protocol.h"
+
+namespace ns3 {
+
+
+Ipv4L4Protocol::Ipv4L4Protocol(int protocolNumber, int version)
+  : m_protocolNumber (protocolNumber),
+    m_version (version)
+{}
+Ipv4L4Protocol::~Ipv4L4Protocol ()
+{}
+
+int 
+Ipv4L4Protocol::GetProtocolNumber (void) const
+{
+  return m_protocolNumber;
+}
+int 
+Ipv4L4Protocol::GetVersion() const
+{
+  return m_version;
+}
+
+void 
+Ipv4L4Protocol::DoDispose (void)
+{
+  Object::DoDispose ();
+}
+
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-l4-protocol.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,85 @@
+// -*- 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>
+//
+
+// NS3 - Layer 4 Protocol base class
+// George F. Riley, Georgia Tech, Spring 2007
+
+#ifndef IPV4_L4_PROTOCOL_H
+#define IPV4_L4_PROTOCOL_H
+
+#include "ns3/object.h"
+
+namespace ns3 {
+
+class Node;
+class Packet;
+class Ipv4Address;
+class TraceResolver;
+class TraceContext;
+
+/**
+ * \brief L4 Protocol base class 
+ *
+ * All subclasses must implement:
+ *   - Ipv4L4Protocol::Copy
+ *   - Ipv4L4Protocol::CreateTraceResolver
+ *
+ * If you want to implement a new L4 protocol, all you have to do is
+ * implement a subclass of this base class and add it to an L4Demux.
+ */  
+class Ipv4L4Protocol : public Object
+{
+public:
+  Ipv4L4Protocol(int protocolNumber, int version);
+  virtual ~Ipv4L4Protocol ();
+
+  /**
+   * \returns the protocol number of this protocol.
+   */
+  int GetProtocolNumber (void) const;
+  /**
+   * \returns the version number of this protocol.
+   */
+  int GetVersion() const;
+
+  virtual TraceResolver *CreateTraceResolver (TraceContext const &context) = 0;
+
+  /**
+   * \param p packet to forward up
+   * \param source source address of packet received
+   * \param destination address of packet received
+   * 
+   * Called from lower-level layers to send the packet up
+   * in the stack. 
+   */
+  virtual void Receive(Packet& p, 
+                       Ipv4Address const &source,
+                       Ipv4Address const &destination) = 0;
+protected:
+  virtual void DoDispose (void);
+private:
+  int m_protocolNumber;
+  int m_version;
+};
+
+} // Namespace ns3
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-loopback-interface.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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
+ *
+ * Authors: 
+ *  Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
+ */
+#include "ns3/empty-trace-resolver.h"
+#include "ns3/net-device.h"
+#include "ns3/node.h"
+#include "ipv4-loopback-interface.h"
+#include "i-ipv4-private.h"
+
+namespace ns3 {
+
+Ipv4LoopbackInterface::Ipv4LoopbackInterface (Node *node)
+  : Ipv4Interface (0),
+    m_node (node)
+{
+  m_node->Ref ();
+}
+Ipv4LoopbackInterface::~Ipv4LoopbackInterface ()
+{
+  m_node->Unref ();
+}
+
+TraceResolver *
+Ipv4LoopbackInterface::DoCreateTraceResolver (TraceContext const &context)
+{
+  return new EmptyTraceResolver (context);
+}
+
+void 
+Ipv4LoopbackInterface::SendTo (Packet packet, Ipv4Address dest)
+{
+  IIpv4Private *ipv4 = m_node->QueryInterface<IIpv4Private> (IIpv4Private::iid);
+  ipv4->Receive (packet, PeekDevice ());
+  ipv4->Unref ();
+}
+
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4-loopback-interface.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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
+ *
+ * Authors: 
+ *  Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
+ */
+#ifndef IPV4_LOOPBACK_INTERFACE_H
+#define IPV4_LOOPBACK_INTERFACE_H
+
+#include "ipv4-interface.h"
+
+namespace ns3 {
+
+class Node;
+
+class Ipv4LoopbackInterface : public Ipv4Interface 
+{
+ public:
+  Ipv4LoopbackInterface (Node *node);
+  virtual ~Ipv4LoopbackInterface ();
+
+ private:
+  virtual void SendTo (Packet p, Ipv4Address dest);
+  virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context);
+
+  Node *m_node;
+};
+
+}//namespace ns3
+
+
+#endif /* IPV4_LOOPBACK_INTERFACE_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,570 @@
+// -*- 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>
+//
+
+#include "ns3/packet.h"
+#include "ns3/debug.h"
+#include "ns3/composite-trace-resolver.h"
+#include "ns3/array-trace-resolver.h"
+#include "ns3/callback.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/ipv4-route.h"
+#include "ns3/node.h"
+
+#include "ipv4.h"
+#include "ipv4-l4-protocol.h"
+#include "ipv4-header.h"
+#include "ipv4-interface.h"
+#include "ipv4-loopback-interface.h"
+#include "arp-ipv4-interface.h"
+#include "ipv4-l4-demux.h"
+
+NS_DEBUG_COMPONENT_DEFINE ("Ipv4");
+
+namespace ns3 {
+
+const uint16_t Ipv4::PROT_NUMBER = 0x0800;
+
+Ipv4::Ipv4(Node *node)
+  : L3Protocol (PROT_NUMBER, 4),
+    m_nInterfaces (0),
+    m_defaultTtl (64),
+    m_identification (0),
+    m_defaultRoute (0),
+    m_node (node)
+{
+  SetupLoopback ();
+  m_node->Ref ();
+}
+Ipv4::~Ipv4 ()
+{
+  DoDispose ();
+}
+
+void 
+Ipv4::DoDispose (void)
+{
+  for (Ipv4InterfaceList::iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
+    {
+      delete (*i);
+    }
+  m_interfaces.clear ();
+  for (HostRoutesI i = m_hostRoutes.begin (); 
+       i != m_hostRoutes.end (); 
+       i = m_hostRoutes.erase (i)) 
+    {
+      delete (*i);
+    }
+  for (NetworkRoutesI j = m_networkRoutes.begin (); 
+       j != m_networkRoutes.end (); 
+       j = m_networkRoutes.erase (j)) 
+    {
+      delete (*j);
+    }
+  if (m_defaultRoute != 0)
+    {
+      delete m_defaultRoute;
+      m_defaultRoute = 0;
+    }
+  if (m_node != 0)
+    {
+      m_node->Unref ();
+      m_node = 0;
+    }
+  L3Protocol::DoDispose ();
+}
+
+void
+Ipv4::SetupLoopback (void)
+{
+  Ipv4LoopbackInterface * interface = new Ipv4LoopbackInterface (m_node);
+  interface->SetAddress (Ipv4Address::GetLoopback ());
+  interface->SetNetworkMask (Ipv4Mask::GetLoopback ());
+  uint32_t index = AddIpv4Interface (interface);
+  AddHostRouteTo (Ipv4Address::GetLoopback (), index);
+  interface->SetUp ();
+}
+
+TraceResolver *
+Ipv4::CreateTraceResolver (TraceContext const &context)
+{
+  CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
+  resolver->Add ("tx", m_txTrace, Ipv4::TX);
+  resolver->Add ("rx", m_rxTrace, Ipv4::RX);
+  resolver->Add ("drop", m_dropTrace, Ipv4::DROP);
+  resolver->Add ("interfaces", 
+                 MakeCallback (&Ipv4::InterfacesCreateTraceResolver, this), 
+                 Ipv4::INTERFACES);
+  return resolver;
+}
+
+TraceResolver *
+Ipv4::InterfacesCreateTraceResolver (TraceContext const &context) const
+{
+  ArrayTraceResolver<Ipv4Interface> *resolver = 
+    new ArrayTraceResolver<Ipv4Interface> 
+    (context,
+     MakeCallback (&Ipv4::GetNInterfaces, this),
+     MakeCallback (&Ipv4::GetInterface, this));
+  return resolver;
+}
+
+void 
+Ipv4::SetDefaultTtl (uint8_t ttl)
+{
+  m_defaultTtl = ttl;
+}
+    
+
+void 
+Ipv4::AddHostRouteTo (Ipv4Address dest, 
+                      Ipv4Address nextHop, 
+                      uint32_t interface)
+{
+  Ipv4Route *route = new Ipv4Route ();
+  *route = Ipv4Route::CreateHostRouteTo (dest, nextHop, interface);
+  m_hostRoutes.push_back (route);
+}
+void 
+Ipv4::AddHostRouteTo (Ipv4Address dest, 
+				uint32_t interface)
+{
+  Ipv4Route *route = new Ipv4Route ();
+  *route = Ipv4Route::CreateHostRouteTo (dest, interface);
+  m_hostRoutes.push_back (route);
+}
+void 
+Ipv4::AddNetworkRouteTo (Ipv4Address network, 
+				   Ipv4Mask networkMask, 
+				   Ipv4Address nextHop, 
+				   uint32_t interface)
+{
+  Ipv4Route *route = new Ipv4Route ();
+  *route = Ipv4Route::CreateNetworkRouteTo (network,
+                                            networkMask,
+                                            nextHop,
+                                            interface);
+  m_networkRoutes.push_back (route);
+}
+void 
+Ipv4::AddNetworkRouteTo (Ipv4Address network, 
+				   Ipv4Mask networkMask, 
+				   uint32_t interface)
+{
+  Ipv4Route *route = new Ipv4Route ();
+  *route = Ipv4Route::CreateNetworkRouteTo (network,
+                                            networkMask,
+                                            interface);
+  m_networkRoutes.push_back (route);
+}
+void 
+Ipv4::SetDefaultRoute (Ipv4Address nextHop, 
+				 uint32_t interface)
+{
+  Ipv4Route *route = new Ipv4Route ();
+  *route = Ipv4Route::CreateDefaultRoute (nextHop, interface);
+  delete m_defaultRoute;
+  m_defaultRoute = route;
+}
+
+Ipv4Route *
+Ipv4::Lookup (Ipv4Address dest)
+{
+  for (HostRoutesCI i = m_hostRoutes.begin (); 
+       i != m_hostRoutes.end (); 
+       i++) 
+    {
+      NS_ASSERT ((*i)->IsHost ());
+      if ((*i)->GetDest ().IsEqual (dest)) 
+        {
+          return (*i);
+        }
+    }
+  for (NetworkRoutesI j = m_networkRoutes.begin (); 
+       j != m_networkRoutes.end (); 
+       j++) 
+    {
+      NS_ASSERT ((*j)->IsNetwork ());
+      Ipv4Mask mask = (*j)->GetDestNetworkMask ();
+      Ipv4Address entry = (*j)->GetDestNetwork ();
+      if (mask.IsMatch (dest, entry)) 
+        {
+          return (*j);
+        }
+    }
+  if (m_defaultRoute != 0) 
+    {
+      NS_ASSERT (m_defaultRoute->IsDefault ());
+      return m_defaultRoute;
+    }
+  return 0;
+}
+
+uint32_t 
+Ipv4::GetNRoutes (void)
+{
+  uint32_t n = 0;
+  if (m_defaultRoute != 0)
+    {
+      n++;
+    }
+  n += m_hostRoutes.size ();
+  n += m_networkRoutes.size ();
+  return n;
+}
+Ipv4Route *
+Ipv4::GetRoute (uint32_t index)
+{
+  if (index == 0 && m_defaultRoute != 0)
+    {
+      return m_defaultRoute;
+    }
+  if (index > 0 && m_defaultRoute != 0)
+    {
+      index--;
+    }
+  if (index < m_hostRoutes.size ())
+    {
+      uint32_t tmp = 0;
+      for (HostRoutesCI i = m_hostRoutes.begin (); 
+           i != m_hostRoutes.end (); 
+           i++) 
+        {
+          if (tmp  == index)
+            {
+              return *i;
+            }
+          tmp++;
+        }
+    }
+  index -= m_hostRoutes.size ();
+  uint32_t tmp = 0;
+  for (NetworkRoutesI j = m_networkRoutes.begin (); 
+       j != m_networkRoutes.end (); 
+       j++) 
+    {
+      if (tmp == index)
+        {
+          return *j;
+        }
+      tmp++;
+    }
+  NS_ASSERT (false);
+  // quiet compiler.
+  return 0;
+}
+void 
+Ipv4::RemoveRoute (uint32_t index)
+{
+  if (index == 0 && m_defaultRoute != 0)
+    {
+      delete m_defaultRoute;
+      m_defaultRoute = 0;
+    }
+  if (index > 0 && m_defaultRoute != 0)
+    {
+      index--;
+    }
+  if (index < m_hostRoutes.size ())
+    {
+      uint32_t tmp = 0;
+      for (HostRoutesI i = m_hostRoutes.begin (); 
+           i != m_hostRoutes.end (); 
+           i++) 
+        {
+          if (tmp  == index)
+            {
+              delete *i;
+              m_hostRoutes.erase (i);
+              return;
+            }
+          tmp++;
+        }
+    }
+  index -= m_hostRoutes.size ();
+  uint32_t tmp = 0;
+  for (NetworkRoutesI j = m_networkRoutes.begin (); 
+       j != m_networkRoutes.end (); 
+       j++) 
+    {
+      if (tmp == index)
+        {
+          delete *j;
+          m_networkRoutes.erase (j);
+          return;
+        }
+      tmp++;
+    }
+  NS_ASSERT (false);
+}
+
+
+uint32_t 
+Ipv4::AddInterface (NetDevice *device)
+{
+  Ipv4Interface *interface = new ArpIpv4Interface (m_node, device);
+  return AddIpv4Interface (interface);
+}
+uint32_t 
+Ipv4::AddIpv4Interface (Ipv4Interface *interface)
+{
+  uint32_t index = m_nInterfaces;
+  m_interfaces.push_back (interface);
+  m_nInterfaces++;
+  return index;
+}
+Ipv4Interface *
+Ipv4::GetInterface (uint32_t index) const
+{
+  uint32_t tmp = 0;
+  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
+    {
+      if (index == tmp) 
+	{
+	  return *i;
+	}
+      tmp++;
+    }
+  return 0;
+}
+uint32_t 
+Ipv4::GetNInterfaces (void) const
+{
+  return m_nInterfaces;
+}
+
+Ipv4Interface *
+Ipv4::FindInterfaceForDevice (NetDevice const*device)
+{
+  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
+    {
+      if ((*i)->PeekDevice () == device)
+        {
+          return *i;
+        }
+    }
+  return 0;
+}  
+
+void 
+Ipv4::Receive(Packet& packet, NetDevice *device)
+{
+  uint32_t index = 0;
+  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
+    {
+      if ((*i)->PeekDevice () == device)
+        {
+          m_rxTrace (packet, index);
+          break;
+        }
+      index++;
+    }
+  Ipv4Header ipHeader;
+  packet.RemoveHeader (ipHeader);
+
+  if (!ipHeader.IsChecksumOk ()) 
+    {
+      return;
+    }
+
+  if (Forwarding (packet, ipHeader, device)) 
+    {
+      return;
+    }
+
+  ForwardUp (packet, ipHeader);
+}
+
+void 
+Ipv4::Send (Packet const &packet, 
+            Ipv4Address source, 
+            Ipv4Address destination,
+            uint8_t protocol)
+{
+  Ipv4Header ipHeader;
+
+  ipHeader.SetSource (source);
+  ipHeader.SetDestination (destination);
+  ipHeader.SetProtocol (protocol);
+  ipHeader.SetPayloadSize (packet.GetSize ());
+  ipHeader.SetTtl (m_defaultTtl);
+  ipHeader.SetMayFragment ();
+  ipHeader.SetIdentification (m_identification);
+
+  m_identification ++;
+
+  // XXX Note here that in most ipv4 stacks in the world,
+  // the route calculation for an outgoing packet is not
+  // done in the ip layer. It is done within the application
+  // socket when the first packet is sent to avoid this
+  // costly lookup on a per-packet basis.
+  // That would require us to get the route from the packet,
+  // most likely with a packet tag. The higher layers do not
+  // do this yet for us.
+  Ipv4Route *route = Lookup (ipHeader.GetDestination ());
+  if (route == 0) 
+    {
+      NS_DEBUG ("not for me -- forwarding but no route to host. drop.");
+      m_dropTrace (packet);
+      return;
+    }
+
+  SendRealOut (packet, ipHeader, *route);
+}
+
+void
+Ipv4::SendRealOut (Packet const &p, Ipv4Header const &ip, Ipv4Route const &route)
+{
+  Packet packet = p;
+  packet.AddHeader (ip);
+  Ipv4Interface *outInterface = GetInterface (route.GetInterface ());
+  NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ());
+  m_txTrace (packet, route.GetInterface ());
+  if (route.IsGateway ()) 
+    {
+      outInterface->Send (packet, route.GetGateway ());
+    } 
+  else 
+    {
+      outInterface->Send (packet, ip.GetDestination ());
+    }
+}
+
+
+bool
+Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device)
+{
+  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
+       i != m_interfaces.end (); i++) 
+    {
+      if ((*i)->GetAddress ().IsEqual (ipHeader.GetDestination ())) 
+        {
+          NS_DEBUG ("for me 1");
+          return false;
+        }
+    }
+  
+  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
+       i != m_interfaces.end (); i++) 
+    {
+      Ipv4Interface *interface = *i;
+      if (interface->PeekDevice () == device)
+	{
+	  if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ())) 
+	    {
+	      NS_DEBUG ("for me 2");
+	      return false;
+	    }
+	  break;
+	}
+    }
+      
+  if (ipHeader.GetDestination ().IsEqual (Ipv4Address::GetBroadcast ())) 
+    {
+      NS_DEBUG ("for me 3");
+      return false;
+    }
+  if (ipHeader.GetDestination ().IsEqual (Ipv4Address::GetAny ())) 
+    {
+      NS_DEBUG ("for me 4");
+      return false;
+    }
+  if (ipHeader.GetTtl () == 1) 
+    {
+      // Should send ttl expired here
+      // XXX
+      NS_DEBUG ("not for me -- ttl expired. drop.");
+      m_dropTrace (packet);
+      return true;
+    }
+  ipHeader.SetTtl (ipHeader.GetTtl () - 1);
+  Ipv4Route *route = Lookup (ipHeader.GetDestination ());
+  if (route == 0) 
+    {
+      NS_DEBUG ("not for me -- forwarding but no route to host. drop.");
+      m_dropTrace (packet);
+      return true;
+    }
+  NS_DEBUG ("not for me -- forwarding.");
+  SendRealOut (packet, ipHeader, *route);
+  return true;
+}
+
+
+void
+Ipv4::ForwardUp (Packet p, Ipv4Header const&ip)
+{
+  Ipv4L4Demux *demux = m_node->QueryInterface<Ipv4L4Demux> (Ipv4L4Demux::iid);
+  Ipv4L4Protocol *protocol = demux->PeekProtocol (ip.GetProtocol ());
+  demux->Unref ();
+  protocol->Receive (p, ip.GetSource (), ip.GetDestination ());
+}
+
+void 
+Ipv4::SetAddress (uint32_t i, Ipv4Address address)
+{
+  Ipv4Interface *interface = GetInterface (i);
+  interface->SetAddress (address);
+}
+void 
+Ipv4::SetNetworkMask (uint32_t i, Ipv4Mask mask)
+{
+  Ipv4Interface *interface = GetInterface (i);
+  interface->SetNetworkMask (mask);
+}
+Ipv4Mask 
+Ipv4::GetNetworkMask (uint32_t i) const
+{
+  Ipv4Interface *interface = GetInterface (i);
+  return interface->GetNetworkMask ();
+}
+Ipv4Address 
+Ipv4::GetAddress (uint32_t i) const
+{
+  Ipv4Interface *interface = GetInterface (i);
+  return interface->GetAddress ();
+}
+uint16_t 
+Ipv4::GetMtu (uint32_t i) const
+{
+  Ipv4Interface *interface = GetInterface (i);
+  return interface->GetMtu ();
+}
+bool 
+Ipv4::IsUp (uint32_t i) const
+{
+  Ipv4Interface *interface = GetInterface (i);
+  return interface->IsUp ();
+}
+void 
+Ipv4::SetUp (uint32_t i)
+{
+  Ipv4Interface *interface = GetInterface (i);
+  interface->SetUp ();
+}
+void 
+Ipv4::SetDown (uint32_t i)
+{
+  Ipv4Interface *interface = GetInterface (i);
+  interface->SetDown ();
+}
+
+
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/ipv4.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,251 @@
+// -*- 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>
+//
+
+#ifndef IPV4_H
+#define IPV4_H
+
+#include <list>
+#include <stdint.h>
+#include "ns3/callback-trace-source.h"
+#include "ns3/array-trace-resolver.h"
+#include "ns3/ipv4-address.h"
+#include "l3-protocol.h"
+
+namespace ns3 {
+
+class Packet;
+class NetDevice;
+class Ipv4Interface;
+class Ipv4Address;
+class Ipv4Header;
+class Ipv4Route;
+class Node;
+class TraceResolver;
+class TraceContext;
+
+
+/**
+ * ::Send is always defined in subclasses.
+ */
+class Ipv4 : public L3Protocol 
+{
+public:
+  static const uint16_t PROT_NUMBER;
+
+  enum TraceType {
+    TX,
+    RX,
+    DROP,
+    INTERFACES,
+  };
+  typedef ArrayTraceResolver<Ipv4Interface>::Index InterfaceIndex;
+
+  Ipv4(Node *node);
+  virtual ~Ipv4 ();
+
+  /**
+   * \param context the trace context to use to construct the
+   *        TraceResolver to return
+   * \returns a TraceResolver which can resolve all traces
+   *          performed in this object. The caller must
+   *          delete the returned object.
+   */
+  virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
+
+  /**
+   * \param ttl default ttl to use
+   *
+   * When we need to send an ipv4 packet, we use this default
+   * ttl value.
+   */
+  void SetDefaultTtl (uint8_t ttl);
+    
+  /**
+   * \param dest destination address
+   * \param nextHop address of next hop.
+   * \param interface interface of next hop.
+   *
+   * add route to host dest through host nextHop 
+   * on interface.
+   */
+  void AddHostRouteTo (Ipv4Address dest, 
+                       Ipv4Address nextHop, 
+                       uint32_t interface);
+  /**
+   * \param dest destination address
+   * \param interface of next hop
+   *
+   * add route to host dest on interface.
+   */
+  void AddHostRouteTo (Ipv4Address dest, 
+                       uint32_t interface);
+
+  /**
+   * \param network destination network
+   * \param networkMask netmask of destination network
+   * \param nextHop address of next hop
+   * \param interface interface of next hop
+   * 
+   * add route to network dest with netmask 
+   * through host nextHop on interface
+   */
+  void AddNetworkRouteTo (Ipv4Address network, 
+                          Ipv4Mask networkMask, 
+                          Ipv4Address nextHop, 
+                          uint32_t interface);
+
+  /**
+   * \param network destination network
+   * \param networkMask netmask of destination network
+   * \param interface interface of next hop
+   *
+   * add route to network dest with netmask 
+   * on interface
+   */
+  void AddNetworkRouteTo (Ipv4Address network, 
+                          Ipv4Mask networkMask, 
+                          uint32_t interface);
+  /**
+   * \param nextHop address of default next hop
+   * \param interface interface of default next hop.
+   * 
+   * set the default route to host nextHop on
+   * interface. 
+   */
+  void SetDefaultRoute (Ipv4Address nextHop, 
+                        uint32_t interface);
+
+  /**
+   * \param dest destination address
+   * \returns the route to the destination address
+   *
+   * Lookup the route for this destination address.
+   */
+  Ipv4Route *Lookup (Ipv4Address dest);
+
+  /**
+   * \returns the number of entries in the routing table.
+   */
+  uint32_t GetNRoutes (void);
+  /**
+   * \param i index of route to return
+   * \returns the route whose index is i
+   */
+  Ipv4Route *GetRoute (uint32_t i);
+  /**
+   * \param i index of route to remove from routing table.
+   */
+  void RemoveRoute (uint32_t i);
+  
+  /**
+   * \param interface interface to add to the list of ipv4 interfaces
+   * which can be used as output interfaces during packet forwarding.
+   * \returns the index of the interface added.
+   *
+   * Once an interface has been added, it can never be removed: if you want
+   * to disable it, you can invoke Ipv4Interface::SetDown which will
+   * make sure that it is never used during packet forwarding.
+   */
+  uint32_t AddInterface (NetDevice *device);
+  /**
+   * \param i index of interface to return
+   * \returns the requested interface
+   */
+  Ipv4Interface * GetInterface (uint32_t i) const;
+  /**
+   * \returns the number of interfaces added by the user.
+   */
+  uint32_t GetNInterfaces (void) const;
+  /**
+   * \param device the device to match
+   * \returns the matching interface, zero if not found.
+   *
+   * Try to find an Ipv4Interface whose NetDevice is equal to
+   * the input NetDevice.
+   */
+  Ipv4Interface *FindInterfaceForDevice (NetDevice const*device);
+  
+
+  /**
+   * Lower layer calls this method after calling L3Demux::Lookup
+   * The ARP subclass needs to know from which NetDevice this
+   * packet is coming to:
+   *    - implement a per-NetDevice ARP cache
+   *    - send back arp replies on the right device
+   */
+  virtual void Receive(Packet& p, NetDevice *device);
+
+  /**
+   * \param packet packet to send
+   * \param source source address of packet
+   * \param destination address of packet
+   * \param protocol number of packet
+   *
+   * Higher-level layers call this method to send a packet
+   * down the stack to the MAC and PHY layers.
+   */
+  void Send (Packet const &packet, Ipv4Address source, 
+	     Ipv4Address destination, uint8_t protocol);
+
+  void SetAddress (uint32_t i, Ipv4Address address);
+  void SetNetworkMask (uint32_t i, Ipv4Mask mask);
+  Ipv4Mask GetNetworkMask (uint32_t t) const;
+  Ipv4Address GetAddress (uint32_t i) const;
+  uint16_t GetMtu (uint32_t i) const;
+  bool IsUp (uint32_t i) const;
+  void SetUp (uint32_t i);
+  void SetDown (uint32_t i);
+
+
+protected:
+  virtual void DoDispose (void);
+private:
+  void SendRealOut (Packet const &packet, Ipv4Header const &ip, Ipv4Route const &route);
+  bool Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device);
+  void ForwardUp (Packet p, Ipv4Header const&ip);
+  uint32_t AddIpv4Interface (Ipv4Interface *interface);
+  void SetupLoopback (void);
+  TraceResolver *InterfacesCreateTraceResolver (TraceContext const &context) const;
+
+  typedef std::list<Ipv4Interface*> Ipv4InterfaceList;
+  typedef std::list<Ipv4Route *> HostRoutes;
+  typedef std::list<Ipv4Route *>::const_iterator HostRoutesCI;
+  typedef std::list<Ipv4Route *>::iterator HostRoutesI;
+  typedef std::list<Ipv4Route *> NetworkRoutes;
+  typedef std::list<Ipv4Route *>::const_iterator NetworkRoutesCI;
+  typedef std::list<Ipv4Route *>::iterator NetworkRoutesI;
+
+  Ipv4InterfaceList m_interfaces;
+  uint32_t m_nInterfaces;
+  uint8_t m_defaultTtl;
+  uint16_t m_identification;
+  HostRoutes m_hostRoutes;
+  NetworkRoutes m_networkRoutes;
+  Ipv4Route *m_defaultRoute;
+  Node *m_node;
+  CallbackTraceSource<Packet const &, uint32_t> m_txTrace;
+  CallbackTraceSource<Packet const &, uint32_t> m_rxTrace;
+  CallbackTraceSource<Packet const &> m_dropTrace;
+};
+
+} // Namespace ns3
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/l3-demux.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,94 @@
+// -*- 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>
+//
+// Implement the L3Protocols capability for ns3.
+// George F. Riley, Georgia Tech, Fall 2006
+#include <sstream>
+#include <string>
+#include "ns3/composite-trace-resolver.h"
+#include "ns3/iid-manager.h"
+#include "ns3/node.h"
+#include "l3-demux.h"
+#include "l3-protocol.h"
+
+namespace ns3 {
+
+const uint32_t L3Demux::iid = IidManager::Allocate ("L3Demux");
+
+L3Demux::L3Demux (Node *node)
+  : NsUnknown (L3Demux::iid),
+    m_node (node)
+{
+  m_node->Ref ();
+}
+
+L3Demux::~L3Demux()
+{}
+
+void
+L3Demux::DoDispose (void)
+{
+  for (L3Map_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
+    {
+      i->second->Dispose ();
+      i->second->Unref ();
+    }
+  m_protocols.clear ();
+  if (m_node != 0)
+    {
+      m_node->Unref ();
+      m_node = 0;
+    }
+  NsUnknown::DoDispose ();
+}
+
+TraceResolver *
+L3Demux::CreateTraceResolver (TraceContext const &context) const
+{
+  CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
+  for (L3Map_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
+    {
+      std::string protValue;
+      std::ostringstream oss (protValue);
+      oss << i->second->GetProtocolNumber ();
+      ProtocolTraceType context = i->second->GetProtocolNumber ();
+      resolver->Add (protValue, 
+                     MakeCallback (&L3Protocol::CreateTraceResolver, i->second),
+                     context);
+    }
+  return resolver;
+}
+  
+void L3Demux::Insert(L3Protocol *p)
+{
+  p->Ref ();
+  m_protocols.insert(L3Map_t::value_type(p->GetProtocolNumber (), p));
+}
+
+L3Protocol* 
+L3Demux::PeekProtocol (int p)
+{ // Look up a protocol by protocol number
+  L3Map_t::iterator i = m_protocols.find(p);
+  if (i == m_protocols.end()) return 0;  // Not found
+  return i->second; // Return the protocol
+}
+
+} //namespace ns3  
+  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/l3-demux.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,99 @@
+// -*- 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>
+//
+// Define the L3Protocols capability for ns3.
+// George F. Riley, Georgia Tech, Fall 2006
+
+// This object manages the different layer 3 protocols for any ns3
+// node that has this capability.  
+
+#ifndef L3_DEMUX_H
+#define L3_DEMUX_H
+
+#include <map>
+#include "ns3/ns-unknown.h"
+
+namespace ns3 {
+
+class L3Protocol;
+class Node;
+class TraceResolver;
+class TraceContext;
+
+/**
+ * \brief L3 Demux 
+ */
+class L3Demux : public NsUnknown
+{
+public:
+  static const uint32_t iid;
+  typedef int ProtocolTraceType;
+  L3Demux(Node *node);
+  virtual ~L3Demux();
+
+  /**
+   * \param context the trace context to use to construct the
+   *        TraceResolver to return
+   * \returns a TraceResolver which can resolve all traces
+   *          performed in this object. The caller must
+   *          delete the returned object.
+   */
+  TraceResolver *CreateTraceResolver (TraceContext const &context) const;
+
+
+  /**
+   * \param protocol a template for the protocol to add to this L3 Demux.
+   *
+   * Invoke Copy on the input template to get a copy of the input
+   * protocol which can be used on the Node on which this L3 Demux 
+   * is running. The new L3Protocol is registered internally as
+   * a working L3 Protocol and returned from this method.
+   * The caller does not get ownership of the returned pointer.
+   */
+  void Insert(ns3::L3Protocol * protocol);
+  /**
+   * \param protocolNumber number of protocol to lookup
+   *        in this L4 Demux
+   * \returns a matching L3 Protocol
+   *
+   * This method is typically called by lower layers
+   * to forward packets up the stack to the right protocol.
+   * It is also called from InternetNode::GetIpv4 for example.
+   */
+  ns3::L3Protocol* PeekProtocol (int protocolNumber);
+  /**
+   * \param protocol protocol to remove from this demux.
+   *
+   * The input value to this method should be the value
+   * returned from the L3Protocol::Insert method.
+   */
+  void Erase(ns3::L3Protocol*protocol);
+protected:
+  virtual void DoDispose (void);
+private:
+  typedef std::map<int, ns3::L3Protocol*> L3Map_t;
+
+  Node *m_node;
+  L3Map_t m_protocols;
+};
+
+} //namespace ns3
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/l3-protocol.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,54 @@
+// -*- 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>
+//
+
+// NS3 - Layer 3 Protocol base class
+// George F. Riley, Georgia Tech, Spring 2007
+
+#include "l3-protocol.h"
+
+
+namespace ns3 {
+
+L3Protocol::L3Protocol(int protocolNumber, int version)
+    : m_protocolNumber (protocolNumber),
+      m_version (version)
+{}
+L3Protocol::~L3Protocol ()
+{}
+
+int 
+L3Protocol::GetProtocolNumber (void) const
+{
+  return m_protocolNumber;
+}
+int 
+L3Protocol::GetVersion() const
+{
+  return m_version;
+}
+
+void
+L3Protocol::DoDispose (void)
+{
+  Object::DoDispose ();
+}
+
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/l3-protocol.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,68 @@
+// -*- 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>
+//
+
+// NS3 - Layer 3 Protocol base class
+// George F. Riley, Georgia Tech, Spring 2007
+
+#ifndef L3_PROTOCOL_H
+#define L3_PROTOCOL_H
+
+#include "ns3/object.h"
+
+namespace ns3 {
+
+class Packet;
+class NetDevice;
+class Node;
+class TraceResolver;
+class TraceContext;
+
+/**
+ * ::Send is always defined in subclasses.
+ */
+class L3Protocol : public Object {
+public:
+  L3Protocol(int protocolNumber, int version);
+  virtual ~L3Protocol ();
+    
+  int GetProtocolNumber (void) const;
+  int GetVersion() const;
+
+  virtual TraceResolver *CreateTraceResolver (TraceContext const &context) = 0;
+  /**
+   * Lower layer calls this method after calling L3Demux::Lookup
+   * The ARP subclass needs to know from which NetDevice this
+   * packet is coming to:
+   *    - implement a per-NetDevice ARP cache
+   *    - send back arp replies on the right device
+   */
+  virtual void Receive(Packet& p, NetDevice *device) = 0;
+
+protected:
+  virtual void DoDispose (void);
+private:
+  int m_protocolNumber;
+  int m_version;
+};
+
+} // Namespace ns3
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/pcap-trace.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,93 @@
+/* -*-	Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#include "pcap-trace.h"
+
+#include <sstream>
+
+#include "ns3/trace-root.h"
+#include "ns3/trace-context.h"
+#include "ns3/callback.h"
+#include "ns3/pcap-writer.h"
+#include "ns3/node-list.h"
+#include "ns3/node.h"
+
+#include "ipv4.h"
+
+
+namespace ns3 {
+
+
+PcapTrace::PcapTrace (std::string filename)
+  : m_filename (filename)
+{}
+PcapTrace::~PcapTrace ()
+{
+  for (std::vector<Trace>::iterator i = m_traces.begin ();
+       i != m_traces.end (); i++)
+    {
+      delete i->writer;
+    }
+}
+
+void 
+PcapTrace::TraceAllIp (void)
+{
+  TraceRoot::Connect ("/nodes/*/ipv4/(tx|rx)",
+		      MakeCallback (&PcapTrace::LogIp, this));
+}
+
+PcapWriter *
+PcapTrace::GetStream (uint32_t nodeId, uint32_t interfaceId)
+{
+  for (std::vector<Trace>::iterator i = m_traces.begin ();
+       i != m_traces.end (); i++)
+    {
+      if (i->nodeId == nodeId &&
+	  i->interfaceId == interfaceId)
+	{
+	  return i->writer;
+	}
+    }
+  PcapTrace::Trace trace;
+  trace.nodeId = nodeId;
+  trace.interfaceId = interfaceId;
+  trace.writer = new PcapWriter ();
+  std::ostringstream oss;
+  oss << m_filename << "-" << nodeId << "-" << interfaceId;
+  std::string filename = oss.str ();
+  trace.writer->Open (filename);
+  trace.writer->WriteIpHeader ();
+  m_traces.push_back (trace);
+  return trace.writer;
+}
+
+void 
+PcapTrace::LogIp (TraceContext const &context, Packet const &p, uint32_t interfaceIndex)
+{
+  NodeList::NodeIndex nodeIndex;
+  context.Get (nodeIndex);
+  uint32_t nodeId = NodeList::PeekNode (nodeIndex)->GetId ();
+  PcapWriter *writer = GetStream (nodeId, interfaceIndex);
+  writer->WritePacket (p);
+}
+
+
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/pcap-trace.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,54 @@
+/* -*-	Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef PCAP_TRACE_H
+#define PCAP_TRACE_H
+
+#include <string>
+#include <vector>
+
+namespace ns3 {
+
+class Packet;
+class TraceContext;
+class PcapWriter;
+
+class PcapTrace 
+{
+public:
+  PcapTrace (std::string filename);
+  ~PcapTrace ();
+
+  void TraceAllIp (void);
+private:
+  PcapWriter *GetStream (uint32_t nodeId, uint32_t interfaceId);
+  void LogIp (TraceContext const &context, Packet const &p, uint32_t interfaceIndex);
+  std::string m_filename;
+  struct Trace {
+    uint32_t nodeId;
+    uint32_t interfaceId;
+    PcapWriter *writer;
+  };
+  std::vector<Trace> m_traces;
+};
+
+}//namespace ns3
+
+#endif /* PCAP_TRACE_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/sgi-hashmap.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,32 @@
+/* This code snippet was ripped out of the gcc 
+ * documentation and slightly modified to work
+ * with gcc 4.x
+ */
+#ifndef SGI_HASHMAP_H
+#define SGI_HASHMAP_H
+
+/* To use gcc extensions.
+ */
+#ifdef __GNUC__
+  #if __GNUC__ < 3
+     #include <hash_map.h>
+namespace sgi { using ::hash_map; }; // inherit globals
+  #else 
+     #if __GNUC__ < 4
+       #include <ext/hash_map>
+       #if __GNUC_MINOR__ == 0
+namespace sgi = std;         // GCC 3.0
+       #else
+namespace sgi = ::__gnu_cxx;       // GCC 3.1 and later
+       #endif
+     #else  // gcc 4.x and later
+       #include <ext/hash_map>
+       namespace sgi = ::__gnu_cxx;
+     #endif
+  #endif
+#else      // ...  there are other compilers, right?
+namespace sgi = std;
+#endif
+
+
+#endif /* SGI_HASHMAP_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/udp-header.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,149 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#include "udp-header.h"
+#include "ipv4-checksum.h"
+
+namespace ns3 {
+
+bool UdpHeader::m_calcChecksum = false;
+
+/* The magic values below are used only for debugging.
+ * They can be used to easily detect memory corruption
+ * problems so you can see the patterns in memory.
+ */
+UdpHeader::UdpHeader ()
+  : m_sourcePort (0xfffd),
+    m_destinationPort (0xfffd),
+    m_payloadSize (0xfffd),
+    m_initialChecksum (0)
+{}
+UdpHeader::~UdpHeader ()
+{
+  m_sourcePort = 0xfffe;
+  m_destinationPort = 0xfffe;
+  m_payloadSize = 0xfffe;
+}
+
+void 
+UdpHeader::EnableChecksums (void)
+{
+  m_calcChecksum = true;
+}
+
+void 
+UdpHeader::SetDestination (uint16_t port)
+{
+  m_destinationPort = port;
+}
+void 
+UdpHeader::SetSource (uint16_t port)
+{
+  m_sourcePort = port;
+}
+uint16_t 
+UdpHeader::GetSource (void) const
+{
+  return m_sourcePort;
+}
+uint16_t 
+UdpHeader::GetDestination (void) const
+{
+  return m_destinationPort;
+}
+void 
+UdpHeader::SetPayloadSize (uint16_t size)
+{
+  m_payloadSize = size;
+}
+void 
+UdpHeader::InitializeChecksum (Ipv4Address source, 
+                              Ipv4Address destination,
+                              uint8_t protocol)
+{
+  uint8_t buf[12];
+  source.Serialize (buf);
+  destination.Serialize (buf+4);
+  buf[8] = 0;
+  buf[9] = protocol;
+  uint16_t udpLength = m_payloadSize + GetSize ();
+  buf[10] = udpLength >> 8;
+  buf[11] = udpLength & 0xff;
+
+  m_initialChecksum = Ipv4ChecksumCalculate (0, buf, 12);
+}
+
+
+
+void 
+UdpHeader::PrintTo (std::ostream &os) const
+{
+  os << "(udp)"
+     << ", port source=" << m_sourcePort
+     << ", port destination=" << m_destinationPort
+     << ", length=" << m_payloadSize;
+}
+
+uint32_t 
+UdpHeader::GetSerializedSize (void) const
+{
+  return 8;
+}
+
+void
+UdpHeader::SerializeTo (Buffer::Iterator start) const
+{
+  Buffer::Iterator i = start;
+  i.WriteHtonU16 (m_sourcePort);
+  i.WriteHtonU16 (m_destinationPort);
+  i.WriteHtonU16 (m_payloadSize + GetSize ());
+  i.WriteU16 (0);
+
+  if (m_calcChecksum) 
+    {
+#if 0
+      //XXXX
+      uint16_t checksum = Ipv4ChecksumCalculate (m_initialChecksum, 
+                                                  buffer->PeekData (), 
+                                                  GetSize () + m_payloadSize);
+      checksum = Ipv4ChecksumComplete (checksum);
+      i = buffer->Begin ();
+      i.Next (6);
+      i.WriteU16 (checksum);
+#endif
+    }
+}
+uint32_t
+UdpHeader::DeserializeFrom (Buffer::Iterator start)
+{
+  Buffer::Iterator i = start;
+  m_sourcePort = i.ReadNtohU16 ();
+  m_destinationPort = i.ReadNtohU16 ();
+  m_payloadSize = i.ReadNtohU16 () - GetSize ();
+  if (m_calcChecksum) 
+    {
+      // XXX verify checksum.
+    }
+  return GetSerializedSize ();
+}
+
+
+}; // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/udp-header.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,65 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#ifndef UDP_HEADER_H
+#define UDP_HEADER_H
+
+#include <stdint.h>
+#include "ns3/header.h"
+#include "ns3/ipv4-address.h"
+
+namespace ns3 {
+
+class UdpHeader : public Header {
+public:
+  UdpHeader ();
+  virtual ~UdpHeader ();
+
+  static void EnableChecksums (void);
+
+  void SetDestination (uint16_t port);
+  void SetSource (uint16_t port);
+  uint16_t GetSource (void) const;
+  uint16_t GetDestination (void) const;
+
+  void SetPayloadSize (uint16_t size);
+
+  void InitializeChecksum (Ipv4Address source, 
+                           Ipv4Address destination,
+                           uint8_t protocol);
+
+private:
+  virtual void PrintTo (std::ostream &os) const;
+  virtual uint32_t GetSerializedSize (void) const;
+  virtual void SerializeTo (Buffer::Iterator start) const;
+  virtual uint32_t DeserializeFrom (Buffer::Iterator start);
+
+  uint16_t m_sourcePort;
+  uint16_t m_destinationPort;
+  uint16_t m_payloadSize;
+  uint16_t m_initialChecksum;
+
+  static bool m_calcChecksum;
+};
+
+}; // namespace ns3
+
+#endif /* UDP_HEADER */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/udp-socket.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,278 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#include "ns3/node.h"
+#include "udp-socket.h"
+#include "udp.h"
+#include "ipv4-end-point.h"
+#include "ipv4-l4-demux.h"
+
+namespace ns3 {
+
+UdpSocket::UdpSocket (Node *node, Udp *udp)
+  : m_endPoint (0),
+    m_node (node),
+    m_udp (udp),
+    m_errno (ENOTERROR),
+    m_shutdownSend (false),
+    m_shutdownRecv (false),
+    m_connected (false)
+{
+  m_udp->Ref ();
+  m_node->Ref ();
+}
+UdpSocket::~UdpSocket ()
+{
+  if (m_node != 0)
+    {
+      m_node->Unref ();
+      m_node = 0;
+    }
+  if (m_endPoint != 0)
+    {
+      NS_ASSERT (m_udp != 0);
+      /**
+       * Note that this piece of code is a bit tricky:
+       * when DeAllocate is called, it will call into
+       * Ipv4EndPointDemux::Deallocate which triggers
+       * a delete of the associated endPoint which triggers
+       * in turn a call to the method ::Destroy below
+       * will will zero the m_endPoint field.
+       */
+      NS_ASSERT (m_endPoint != 0);
+      m_udp->DeAllocate (m_endPoint);
+      NS_ASSERT (m_endPoint == 0);
+    }
+  if (m_udp != 0)
+    {
+      m_udp->Unref ();
+      m_udp = 0;
+    }
+}
+
+Node *
+UdpSocket::PeekNode (void) const
+{
+  return m_node;
+}
+
+void 
+UdpSocket::Destroy (void)
+{
+  if (m_node != 0)
+    {
+      m_node->Unref ();
+      m_node = 0;
+    }
+  m_endPoint = 0;
+  if (m_udp != 0)
+    {
+      m_udp->Unref ();
+      m_udp = 0;
+    }
+}
+int
+UdpSocket::FinishBind (void)
+{
+  m_endPoint->SetRxCallback (MakeCallback (&UdpSocket::ForwardUp, this));
+  m_endPoint->SetDestroyCallback (MakeCallback (&UdpSocket::Destroy, this));
+  if (m_endPoint == 0)
+    {
+      return -1;
+    }
+  return 0;
+}
+
+int
+UdpSocket::Bind (void)
+{
+  m_endPoint = m_udp->Allocate ();
+  return FinishBind ();
+}
+int 
+UdpSocket::Bind (Ipv4Address address)
+{
+  m_endPoint = m_udp->Allocate (address);
+  return FinishBind ();
+}
+int 
+UdpSocket::Bind (uint16_t port)
+{
+  m_endPoint = m_udp->Allocate (port);
+  return FinishBind ();
+}
+int 
+UdpSocket::Bind (Ipv4Address address, uint16_t port)
+{
+  m_endPoint = m_udp->Allocate (address, port);
+  return FinishBind ();
+}
+
+enum Socket::SocketErrno
+UdpSocket::GetErrno (void) const
+{
+  return m_errno;
+}
+int 
+UdpSocket::ShutdownSend (void)
+{
+  m_shutdownSend = true;
+  return 0;
+}
+int 
+UdpSocket::ShutdownRecv (void)
+{
+  m_shutdownRecv = false;
+  return 0;
+}
+
+void 
+UdpSocket::DoClose(ns3::Callback<void, Socket*> closeCompleted)
+{
+  // XXX: we should set the close state and check it in all API methods.
+  if (!closeCompleted.IsNull ())
+    {
+      closeCompleted (this);
+    }
+}
+void 
+UdpSocket::DoConnect(const Ipv4Address & address,
+                     uint16_t portNumber,
+                     ns3::Callback<void, Socket*> connectionSucceeded,
+                     ns3::Callback<void, Socket*> connectionFailed,
+                     ns3::Callback<void, Socket*> halfClose)
+{
+  m_defaultAddress = address;
+  m_defaultPort = portNumber;
+  if (!connectionSucceeded.IsNull ())
+    {
+      connectionSucceeded (this);
+    }
+  m_connected = true;
+}
+int
+UdpSocket::DoAccept(ns3::Callback<bool, Socket*, const Ipv4Address&, uint16_t> connectionRequest,
+                    ns3::Callback<void, Socket*, const Ipv4Address&, uint16_t> newConnectionCreated,
+                    ns3::Callback<void, Socket*> closeRequested)
+{
+  // calling accept on a udp socket is a programming error.
+  m_errno = EOPNOTSUPP;
+  return -1;
+}
+int 
+UdpSocket::DoSend (const uint8_t* buffer,
+                   uint32_t size,
+                   ns3::Callback<void, Socket*, uint32_t> dataSent)
+{
+  if (!m_connected)
+    {
+      m_errno = ENOTCONN;
+      return -1;
+    }
+  Packet p;
+  if (buffer == 0)
+    {
+      p = Packet (size);
+    }
+  else
+    {
+      p = Packet (buffer, size);
+    }
+  return DoSendPacketTo (p, m_defaultAddress, m_defaultPort, dataSent);
+}
+int
+UdpSocket::DoSendPacketTo (const Packet &p, Ipv4Address daddr, uint16_t dport,
+                           ns3::Callback<void, Socket*, uint32_t> dataSent)
+{
+  if (m_endPoint == 0)
+    {
+      if (Bind () == -1)
+	{
+          NS_ASSERT (m_endPoint == 0);
+	  return -1;
+	}
+      NS_ASSERT (m_endPoint != 0);
+    }
+  if (m_shutdownSend)
+    {
+      m_errno = ESHUTDOWN;
+      return -1;
+    }
+  m_udp->Send (p, m_endPoint->GetLocalAddress (), daddr,
+		   m_endPoint->GetLocalPort (), dport);
+  if (!dataSent.IsNull ())
+    {
+      dataSent (this, p.GetSize ());
+    }
+  return 0;
+}
+int 
+UdpSocket::DoSendTo(const Ipv4Address &address,
+                    uint16_t port,
+                    const uint8_t *buffer,
+                    uint32_t size,
+                    ns3::Callback<void, Socket*, uint32_t> dataSent)
+{
+  if (m_connected)
+    {
+      m_errno = EISCONN;
+      return -1;
+    }
+  Packet p;
+  if (buffer == 0)
+    {
+      p = Packet (size);
+    }
+  else
+    {
+      p = Packet (buffer, size);
+    }
+  return DoSendPacketTo (p, address, port, dataSent);
+}
+void 
+UdpSocket::DoRecv(ns3::Callback<void, Socket*, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> callback)
+{
+  m_rxCallback = callback;
+}
+void 
+UdpSocket::DoRecvDummy(ns3::Callback<void, Socket*, uint32_t,const Ipv4Address&, uint16_t> callback)
+{
+  m_dummyRxCallback = callback;
+}
+
+void 
+UdpSocket::ForwardUp (const Packet &packet, Ipv4Address saddr, uint16_t sport)
+{
+  if (m_shutdownRecv)
+    {
+      return;
+    }
+  Packet p = packet;
+  if (!m_dummyRxCallback.IsNull ())
+    {
+      m_dummyRxCallback (this, p.GetSize (), saddr, sport);
+    }
+  if (!m_rxCallback.IsNull ())
+    {
+      m_rxCallback (this, p.PeekData (), p.GetSize (), saddr, sport);
+    }
+}
+
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/udp-socket.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,98 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef UDP_SOCKET_H
+#define UDP_SOCKET_H
+
+#include <stdint.h>
+#include "ns3/callback.h"
+#include "ns3/socket.h"
+
+namespace ns3 {
+
+class Ipv4EndPoint;
+class Node;
+class Packet;
+class Udp;
+
+class UdpSocket : public Socket
+{
+public:
+  /**
+   * Create an unbound udp socket.
+   */
+  UdpSocket (Node *node, Udp *udp);
+  virtual ~UdpSocket ();
+
+  virtual enum SocketErrno GetErrno (void) const;
+  virtual Node *PeekNode (void) const;
+  virtual int Bind (void);
+  virtual int Bind (Ipv4Address address);
+  virtual int Bind (uint16_t port); 
+  virtual int Bind (Ipv4Address address, uint16_t port);
+  virtual int ShutdownSend (void);
+  virtual int ShutdownRecv (void);
+
+private:
+  virtual void DoClose(ns3::Callback<void, Socket*> closeCompleted);
+  virtual void DoConnect(const Ipv4Address & address,
+			 uint16_t portNumber,
+			 ns3::Callback<void, Socket*> connectionSucceeded,
+			 ns3::Callback<void, Socket*> connectionFailed,
+			 ns3::Callback<void, Socket*> halfClose);
+  virtual int DoAccept(ns3::Callback<bool, Socket*, const Ipv4Address&, uint16_t> connectionRequest,
+		       ns3::Callback<void, Socket*, const Ipv4Address&, uint16_t> newConnectionCreated,
+		       ns3::Callback<void, Socket*> closeRequested);
+  virtual int DoSend (const uint8_t* buffer,
+                    uint32_t size,
+                    ns3::Callback<void, Socket*, uint32_t> dataSent);
+  virtual int DoSendTo(const Ipv4Address &address,
+                      uint16_t port,
+                      const uint8_t *buffer,
+                      uint32_t size,
+                      ns3::Callback<void, Socket*, uint32_t> dataSent);
+  virtual void DoRecv(ns3::Callback<void, Socket*, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t>);
+  virtual void DoRecvDummy(ns3::Callback<void, Socket*, uint32_t,const Ipv4Address&, uint16_t>);
+
+private:
+  friend class Udp;
+  // invoked by Udp class
+  int FinishBind (void);
+  void ForwardUp (const Packet &p, Ipv4Address saddr, uint16_t sport);
+  void Destroy (void);
+  int DoSendPacketTo (const Packet &p, Ipv4Address daddr, uint16_t dport,
+		      ns3::Callback<void, Socket*, uint32_t> dataSent);
+
+  Ipv4EndPoint *m_endPoint;
+  Node *m_node;
+  Udp *m_udp;
+  Ipv4Address m_defaultAddress;
+  uint16_t m_defaultPort;
+  Callback<void,Socket*,uint32_t,const Ipv4Address &,uint16_t> m_dummyRxCallback;
+  Callback<void,Socket*,uint8_t const*,uint32_t,const Ipv4Address &,uint16_t> m_rxCallback;
+  enum SocketErrno m_errno;
+  bool m_shutdownSend;
+  bool m_shutdownRecv;
+  bool m_connected;
+};
+
+}//namespace ns3
+
+#endif /* UDP_SOCKET_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/udp.cc	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,155 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#include "ns3/assert.h"
+#include "ns3/packet.h"
+#include "ns3/empty-trace-resolver.h"
+#include "ns3/node.h"
+
+#include "udp.h"
+#include "udp-header.h"
+#include "ipv4-end-point-demux.h"
+#include "ipv4-end-point.h"
+#include "ipv4.h"
+#include "i-ipv4-private.h"
+#include "l3-demux.h"
+#include "udp-socket.h"
+
+namespace ns3 {
+
+/* see http://www.iana.org/assignments/protocol-numbers */
+const uint8_t Udp::PROT_NUMBER = 17;
+
+Udp::Udp (Node *node)
+  : Ipv4L4Protocol (PROT_NUMBER, 2),
+    m_node (node),
+    m_endPoints (new Ipv4EndPointDemux ())
+{
+  m_node->Ref ();
+}
+
+Udp::~Udp ()
+{}
+
+TraceResolver *
+Udp::CreateTraceResolver (TraceContext const &context)
+{
+  return new EmptyTraceResolver (context);
+}
+
+void
+Udp::DoDispose (void)
+{
+  if (m_endPoints != 0)
+    {
+      delete m_endPoints;
+      m_endPoints = 0;
+    }
+  if (m_node != 0)
+    {
+      m_node->Unref ();
+      m_node = 0;
+    }
+  Ipv4L4Protocol::DoDispose ();
+}
+
+Socket *
+Udp::CreateSocket (void)
+{
+  return new UdpSocket (m_node, this);
+}
+
+Ipv4EndPoint *
+Udp::Allocate (void)
+{
+  return m_endPoints->Allocate ();
+}
+Ipv4EndPoint *
+Udp::Allocate (Ipv4Address address)
+{
+  return m_endPoints->Allocate (address);
+}
+Ipv4EndPoint *
+Udp::Allocate (uint16_t port)
+{
+  return m_endPoints->Allocate (port);
+}
+Ipv4EndPoint *
+Udp::Allocate (Ipv4Address address, uint16_t port)
+{
+  return m_endPoints->Allocate (address, port);
+}
+Ipv4EndPoint *
+Udp::Allocate (Ipv4Address localAddress, uint16_t localPort,
+               Ipv4Address peerAddress, uint16_t peerPort)
+{
+  return m_endPoints->Allocate (localAddress, localPort,
+                                peerAddress, peerPort);
+}
+
+void 
+Udp::DeAllocate (Ipv4EndPoint *endPoint)
+{
+  m_endPoints->DeAllocate (endPoint);
+}
+
+void 
+Udp::Receive(Packet& packet, 
+             Ipv4Address const &source,
+             Ipv4Address const &destination)
+{
+  UdpHeader udpHeader;
+  packet.RemoveHeader (udpHeader);
+  Ipv4EndPoint *endPoint = m_endPoints->Lookup (destination, udpHeader.GetDestination (),
+                                                source, udpHeader.GetSource ());
+  if (endPoint == 0)
+    {
+      return;
+    }
+  endPoint->ForwardUp (packet, source, udpHeader.GetSource ());
+}
+
+void
+Udp::Send (Packet packet, 
+           Ipv4Address saddr, Ipv4Address daddr, 
+           uint16_t sport, uint16_t dport)
+{
+  UdpHeader udpHeader;
+  udpHeader.SetDestination (dport);
+  udpHeader.SetSource (sport);
+  udpHeader.SetPayloadSize (packet.GetSize ());
+  udpHeader.InitializeChecksum (saddr,
+                               daddr,
+                               PROT_NUMBER);
+
+  packet.AddHeader (udpHeader);
+
+  IIpv4Private *ipv4 = m_node->QueryInterface<IIpv4Private> (IIpv4Private::iid);
+  if (ipv4 != 0)
+    {
+      ipv4->Send (packet, saddr, daddr, PROT_NUMBER);
+      ipv4->Unref ();
+    }
+}
+
+
+}; // namespace ns3
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/internet-node/udp.h	Fri May 04 15:04:07 2007 +0200
@@ -0,0 +1,76 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006,2007 INRIA
+ * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#ifndef UDP_H
+#define UDP_H
+
+#include <stdint.h>
+
+#include "ns3/packet.h"
+#include "ns3/ipv4-address.h"
+#include "ipv4-end-point-demux.h"
+#include "ipv4-l4-protocol.h"
+
+namespace ns3 {
+
+class Node;
+class TraceResolver;
+class TraceContext;
+class Socket;
+
+class Udp : public Ipv4L4Protocol {
+public:
+  static const uint8_t PROT_NUMBER;
+
+  Udp (Node *node);
+  virtual ~Udp ();
+
+  virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
+
+  Socket *CreateSocket (void);
+
+  Ipv4EndPoint *Allocate (void);
+  Ipv4EndPoint *Allocate (Ipv4Address address);
+  Ipv4EndPoint *Allocate (uint16_t port);
+  Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port);
+  Ipv4EndPoint *Allocate (Ipv4Address localAddress, uint16_t localPort,
+                         Ipv4Address peerAddress, uint16_t peerPort);
+
+  void DeAllocate (Ipv4EndPoint *endPoint);
+
+  // called by UdpSocket.
+  void Send (Packet packet,
+             Ipv4Address saddr, Ipv4Address daddr, 
+             uint16_t sport, uint16_t dport);
+  // inherited from Ipv4L4Protocol
+  virtual void Receive(Packet& p, 
+                       Ipv4Address const &source,
+                       Ipv4Address const &destination);
+protected:
+  virtual void DoDispose (void);
+private:
+  Node *m_node;
+  Ipv4EndPointDemux *m_endPoints;
+};
+
+}; // namespace ns3
+
+#endif /* UDP_H */
--- a/src/node/application-list.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-// -*- Mode:NS3 -*-
-//
-// 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>
-//
-// Implement the application list capability for NS3 nodes
-// George F. Riley, Georgia Tech, Spring 2007
-
-#include "application.h"
-#include "application-list.h"
-#include "ns3/iid-manager.h"
-
-namespace ns3{
-
-const uint32_t ApplicationList::iid = IidManager::Allocate ("ApplicationList");
-
-ApplicationList::ApplicationList(Node* n)
-  : NsUnknown (ApplicationList::iid)
-{}
-
-void 
-ApplicationList::DoDispose (void)
-{
-  for (std::vector<Application*>::const_iterator i = m_apps.begin();
-       i != m_apps.end(); ++i)
-    {
-      Application *app = *i;
-      app->Dispose ();
-      app->Unref ();
-    }
-  m_apps.clear ();
-  NsUnknown::DoDispose ();
-}
-  
-ApplicationList::~ApplicationList()
-{}
-
-ApplicationList* ApplicationList::Copy(Node * n) const 
-{ // Copy this app list
-  ApplicationList* r = new ApplicationList(n);
-  return r;
-}
-
-void
-ApplicationList::Add(Application* a)
-{
-  a->Ref ();
-  m_apps.push_back(a);
-}
-
-void ApplicationList::SetNode(Node * n)
-{
-  // Set the node pointer in each application
-  for (std::vector<Application *>::const_iterator i = m_apps.begin();
-       i != m_apps.end(); ++i)
-    { // Set correct node pointer in each app
-      (*i)->SetNode(n);
-    }
-}
-  
-
-uint32_t ApplicationList::Count() const
-{
-  return m_apps.size();
-}
-
-Application* ApplicationList::Get(uint32_t i) const
-{ // Get the i'th application. Note, this is linear time in N
-  if (m_apps.empty()) return 0;        // List is empty
-  return m_apps[i];
-}
-  
-}//namespace ns3
--- a/src/node/application-list.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-// -*- Mode:NS3 -*-
-//
-// 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 applications associated with a node.
-// George F. Riley, Georgia Tech, Spring 2007
-
-#ifndef __APPLICATION_LIST_H__
-#define __APPLICATION_LIST_H__
-
-#include "application.h"
-#include "ns3/ns-unknown.h"
-#include <vector>
-
-namespace ns3 {
-
-class ApplicationList : public NsUnknown
-{
-public:
-  static const uint32_t iid;
-  ApplicationList(Node*);
-  // Copy constructor not needed, default one is correct
-  virtual ~ApplicationList();
-  // Inherited from Capabilty
-  virtual ApplicationList* Copy(Node*) const;
-  virtual void SetNode(Node *);              // Sets the node for all apps
-  virtual void Add(Application*);      // Add an already new'ed app
-  // Manage the list
-  template <typename T> T* AddCopy(const T& t)  // Add a new application
-  {
-    T* a = t.Copy();
-    m_apps.push_back(a);
-    return a;
-  }
-  void Remove(Application*);                // Application has finished
-  uint32_t Count() const;  // Number of applications
-  Application* Get(uint32_t i) const; // Get app by index
-  
-protected:
-  virtual void DoDispose (void);
-private:
-  std::vector<Application*> m_apps;
-};
-
-}//namespace ns3
-#endif
-
--- a/src/node/application.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,195 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2006 Georgia Tech Research Corporation
- *
- * 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 for ns3 Application base class.
-// George F. Riley, Georgia Tech, Fall 2006
-
-#include "application.h"
-#include "node.h"
-#include "ns3/nstime.h"
-#include "ns3/random-variable.h"
-#include "ns3/simulator.h"
-
-using namespace std;
-
-namespace ns3 {
-
-// Application Methods
-
-// \brief Application Constructor
-Application::Application(Node * n) 
-    : m_node (n),
-      m_startVar(0), m_stopVar(0),
-      m_start(false), m_stop(false)
-{
-  m_node->Ref ();
-}
-
-Application::Application(const Application& o)
-    : m_node(0), m_startVar(0), m_stopVar(0),
-      m_start(false), m_stop(false)
-{ // Copy constructor
-  m_node = o.m_node;
-  m_node->Ref ();
-  // Copy the start and stop random variables if they exist
-  if (o.m_startVar) m_startVar = o.m_startVar->Copy();
-  if (o.m_stopVar)  m_stopVar  = o.m_stopVar->Copy();
-  if (o.m_start)    ScheduleStart();
-  if (o.m_stop)     ScheduleStop();
-}
-
-  
-// \brief Application Destructor
-Application::~Application()
-{}
-
-void
-Application::DoDispose (void)
-{
-  if (m_node != 0)
-    {
-      m_node->Unref ();
-      m_node = 0;
-    }
-  if (m_start) 
-    {
-      Simulator::Cancel(m_startEvent);
-      m_start = false;
-    }
-  if (m_stop) 
-    {
-      Simulator::Cancel(m_stopEvent);
-      m_stop = false;
-    }
-  delete m_startVar;
-  m_startVar = 0;
-  delete m_stopVar;
-  m_stopVar = 0;
-}
-  
-Application& Application::operator=(const Application& rhs)
-{
-  if (this == &rhs) return *this; // Self assignment
-  m_node->Unref ();
-  m_node = 0;
-  m_node = rhs.m_node;
-  m_node->Ref ();
-
-  delete m_startVar;
-  m_startVar = 0;
-  if (rhs.m_startVar) m_startVar = rhs.m_startVar->Copy();
-  
-  delete m_stopVar;
-  m_stopVar = 0;
-  if (rhs.m_stopVar) m_stopVar = rhs.m_stopVar->Copy();
-  
-  m_start = false;
-  if (rhs.m_start) ScheduleStart();
-  if (rhs.m_stop)  ScheduleStop();
-  return *this;
-}
-  
-   
-// \brief Specify application start time
-// The virtual method STartApp will be called at the time
-// specified by startTime.
-// \param Time to start application (absolute time, from start of simulation)
-void Application::Start(const Time& startTime)
-{
-  delete m_startVar;
-  m_startVar = new ConstantVariable(startTime.GetSeconds());
-  ScheduleStart();
-}
-
-void Application::Start(const RandomVariable& startVar)
-{ // Start at random time
-  delete m_startVar;
-  m_startVar = startVar.Copy();
-  ScheduleStart();
-}
-
-   
-// \brief Specify application stop time
-// The virtual method StopApp will be called at the time
-// specified by stopTime.
-// \param Time to stop application (absolute time, from start of simulation)
-void Application::Stop(const Time& stopTime)
-{
-  delete m_stopVar;
-  m_stopVar = new ConstantVariable(stopTime.GetSeconds());
-  ScheduleStop();
-}
-
-void Application::Stop(const RandomVariable& stopVar)
-{ // Stop at random time
-  delete m_stopVar;
-  m_stopVar = stopVar.Copy();
-  ScheduleStop();
-}
-
-// \brief Assign this application to a given node
-// Called by the application manager capability when adding
-// an application to a node.
-void Application::SetNode(Node * n)
-{
-  if (m_node != 0)
-    {
-      m_node->Unref ();
-    }
-  m_node = n;
-  m_node->Ref ();
-}
-  
-Node* Application::PeekNode() const
-{
-  return m_node;
-}
-
-// Protected methods
-// StartApp and StopApp will likely be overridden by application subclasses
-void Application::StartApplication()
-{ // Provide null functionality in case subclass is not interested
-}
-
-void Application::StopApplication()
-{ // Provide null functionality in case subclass is not interested
-}
-
-
-// Private helpers
-void Application::ScheduleStart()
-{
-  m_startEvent = Simulator::Schedule(Seconds(m_startVar->GetValue()) -
-                                     Simulator::Now(),
-                                     &Application::StartApplication, this);
-  m_start = true;
-}
-
-void Application::ScheduleStop()
-{
-  m_stopEvent = Simulator::Schedule(Seconds(m_stopVar->GetValue()) -
-                                     Simulator::Now(),
-                                     &Application::StopApplication, this);
-  m_stop = true;
-}
-
-} //namespace ns3
-      
-  
--- a/src/node/application.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,138 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2006 Georgia Tech Research Corporation
- *
- * 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>
- */
-
-#ifndef __APPLICATION_H__
-#define __APPLICATION_H__
-
-//
-// \brief The base class for all ns3 applicationes
-//
-// Class Application is the base class for all ns3 applications.
-// Applications are associated with individual nodes, and are created
-// using the AddApplication method in the ApplicationManager capability.
-// 
-// Conceptually, an application has zero or more Socket
-// objects associated with it, that are created using the Socket
-// creation API of the Kernel capability.  The Socket object
-// API is modeled after the
-// well-known BSD sockets interface, although it is somewhat 
-// simplified for use with ns3.  Further, any socket call that
-// would normally "block" in normal sockets will return immediately
-// in ns3.  A set of "upcalls" are defined that will be called when
-// the previous blocking call would normally exit.  THis is documented
-// in more detail Socket class in socket.h.
-// 
-// There is a second application class in ns3, called "ThreadedApplication"
-// that implements a true sockets interface, which should be used
-// when porting existing sockets code to ns3.  The true
-// sockets approach is significantly
-// less memory--efficient using private stacks for each defined application,
-// so that approach should be used with care.  The design and implementation
-// of the ThreadedApplication are still being discussed.
-
-#include "ns3/event-id.h"
-#include "ns3/nstime.h"
-#include "ns3/object.h"
-
-namespace ns3 {
-
-class Node;
-class RandomVariable;
-  
-class Application : public Object
-{
-public:
-  Application(Node *);
-  Application(const Application&);  // Copy constructor
-  Application& operator=(const Application&); // Assignment operator
-  virtual ~Application();
-  
-  virtual Application* Copy() const = 0; // All applications must provide
-  
-  // \brief Specify application start time
-  // Applications start at various times in the simulation scenario.
-  // The Start method specifies when the application should be
-  // started.  The application subclasses should override the
-  // private "StartApplication" method defined below, which is called at the
-  // time specified, to cause the application to begin.
-  // \param Start time for this application, relative to the
-  // current simulation time.
-  void Start(const Time&);
-
-  // \brief Same as above, but uses a random variable for start time
-  // The random variable returns the desired start time in units of
-  // Seconds.
-  
-void Start(const RandomVariable&);
-  
-  // \brief Specify application stop time
-  // Once an application has started, it is sometimes useful
-  // to stop the application.  The Stop method specifies when an
-  // application is to stop.  The application subclasses should override
-  // the private StopApplication method defined below, to cause the application
-  // to stop.
-  // \param Stop time for this application, relative to the
-  // current simulation time.
-  void Stop(const Time&);
-
-  // \brief Same as above, but uses a random variable for stop time
-  // The random variable returns the desired stop time in units of
-  // Seconds.
-  void Stop(const RandomVariable&);
-  
-  // \brief Attaches an application to a specific node
-  // Specifies which node object this application is associated with.
-  // \param Node object to associate with this application.
-  void SetNode(Node *);
-
-  // \brief Returns the pointer to the attached node.
-  Node* PeekNode() const;
-  
-  // Members
-  Node          * m_node;      // All applications have an associated node
-  RandomVariable* m_startVar;  // Random variable for start time
-  RandomVariable* m_stopVar;   // Random variable for stop time
-  EventId         m_startEvent;// Event identifier for start event
-  EventId         m_stopEvent; // Event identifier for the stop event
-  bool            m_start;     // True if start event scheduled
-  bool            m_stop;      // True if stop event scheduled
-  
-protected:
-  // \brief Application specific startup code
-  // The StartApplication method is called at the start time specifed by Start
-  // This method should be overridden by all or most application
-  // subclasses.
-  virtual void StartApplication();
-
-  // \brief Application specific shutdown code
-  // The StopApplication method is called at the stop time specifed by Stop
-  // This method should be overridden by all or most application
-  // subclasses.
-  virtual void StopApplication();
-
-  virtual void DoDispose (void);
-private:
-  // Helpers
-  void ScheduleStart();
-  void ScheduleStop();
-};
-
-} //namespace ns3
-#endif
--- a/src/node/arp-cache.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,229 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2006 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#include "ns3/assert.h"
-
-#include "ns3/packet.h"
-#include "ns3/simulator.h"
-
-#include "arp-cache.h"
-#include "arp-header.h"
-
-namespace ns3 {
-
-ArpCache::ArpCache (NetDevice *device, Ipv4Interface *interface)
-  : m_device (device), 
-    m_interface (interface),
-    m_aliveTimeout (Seconds (120)),
-    m_deadTimeout (Seconds (100)),
-    m_waitReplyTimeout (Seconds (1))
-{
-  m_device->Ref ();
-}
-
-ArpCache::~ArpCache ()
-{
-  m_device->Unref ();
-  Flush ();
-}
-
-NetDevice *
-ArpCache::PeekDevice (void) const
-{
-  return m_device;
-}
-
-Ipv4Interface *
-ArpCache::GetInterface (void) const
-{
-  return m_interface;
-}
-
-void 
-ArpCache::SetAliveTimeout (Time aliveTimeout)
-{
-  m_aliveTimeout = aliveTimeout;
-}
-void 
-ArpCache::SetDeadTimeout (Time deadTimeout)
-{
-  m_deadTimeout = deadTimeout;
-}
-void 
-ArpCache::SetWaitReplyTimeout (Time waitReplyTimeout)
-{
-  m_waitReplyTimeout = waitReplyTimeout;
-}
-
-Time
-ArpCache::GetAliveTimeout (void) const
-{
-  return m_aliveTimeout;
-}
-Time
-ArpCache::GetDeadTimeout (void) const
-{
-  return m_deadTimeout;
-}
-Time
-ArpCache::GetWaitReplyTimeout (void) const
-{
-  return m_waitReplyTimeout;
-}
-
-void 
-ArpCache::Flush (void)
-{
-  for (CacheI i = m_arpCache.begin (); i != m_arpCache.end (); i++) 
-    {
-      delete (*i).second;
-    }
-  m_arpCache.erase (m_arpCache.begin (), m_arpCache.end ());
-}
-
-ArpCache::Entry *
-ArpCache::Lookup (Ipv4Address to)
-{
-  if (m_arpCache.find (to) != m_arpCache.end ()) 
-    {
-      ArpCache::Entry *entry = m_arpCache[to];
-      return entry;
-    }
-  return 0;
-}
-
-ArpCache::Entry *
-ArpCache::Add (Ipv4Address to)
-{
-  ArpCache::Entry *entry = new ArpCache::Entry (this);
-  m_arpCache[to] = entry;  
-  return entry;
-}
-
-ArpCache::Entry::Entry (ArpCache *arp)
-  : m_arp (arp),
-    m_state (ALIVE),
-    m_waiting ()
-{}
-
-
-bool 
-ArpCache::Entry::IsDead (void)
-{
-  return (m_state == DEAD)?true:false;
-}
-bool 
-ArpCache::Entry::IsAlive (void)
-{
-  return (m_state == ALIVE)?true:false;
-}
-bool
-ArpCache::Entry::IsWaitReply (void)
-{
-  return (m_state == WAIT_REPLY)?true:false;
-}
-
-
-void 
-ArpCache::Entry::MarkDead (void) 
-{
-  m_state = DEAD;
-  //NS_ASSERT (m_waiting != 0);
-  UpdateSeen ();
-}
-Packet 
-ArpCache::Entry::MarkAlive (MacAddress macAddress) 
-{
-  NS_ASSERT (m_state == WAIT_REPLY);
-  //NS_ASSERT (m_waiting != 0);
-  m_macAddress = macAddress;
-  m_state = ALIVE;
-  UpdateSeen ();
-  Packet waiting = m_waiting;
-  //m_waiting = 0;
-  return waiting;
-}
-
-Packet 
-ArpCache::Entry::UpdateWaitReply (Packet waiting)
-{
-  NS_ASSERT (m_state == WAIT_REPLY);
-  /* We are already waiting for an answer so
-   * we dump the previously waiting packet and
-   * replace it with this one.
-   */
-  Packet old = m_waiting;
-  m_waiting = waiting;
-  return old;
-}
-void 
-ArpCache::Entry::MarkWaitReply (Packet waiting)
-{
-  NS_ASSERT (m_state == ALIVE || m_state == DEAD);
-  //NS_ASSERT (m_waiting == 0);
-  m_state = WAIT_REPLY;
-  m_waiting = waiting;
-  UpdateSeen ();
-}
-
-MacAddress
-ArpCache::Entry::GetMacAddress (void)
-{
-  NS_ASSERT (m_state == ALIVE);
-  return m_macAddress;
-}
-bool 
-ArpCache::Entry::IsExpired (void)
-{
-  Time timeout;
-  switch (m_state) {
-  case ArpCache::Entry::WAIT_REPLY:
-    timeout = m_arp->GetWaitReplyTimeout ();
-    break;
-  case ArpCache::Entry::DEAD:
-    timeout = m_arp->GetDeadTimeout ();
-    break;
-  case ArpCache::Entry::ALIVE:
-    timeout = m_arp->GetAliveTimeout ();
-    break;
-  default:
-    NS_ASSERT (false);
-    timeout = Seconds (0);
-    /* NOTREACHED */
-    break;
-  }
-  Time delta = Simulator::Now () - m_lastSeen;
-  if (delta >= timeout) 
-    {
-      return true;
-    } 
-  else 
-    {
-      return false;
-    }
-}
-void 
-ArpCache::Entry::UpdateSeen (void)
-{
-  m_lastSeen = Simulator::Now ();
-}
-
-} // namespace ns3
-
--- a/src/node/arp-cache.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2006 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#ifndef ARP_CACHE_H
-#define ARP_CACHE_H
-
-#include <stdint.h>
-#include "ns3/packet.h"
-#include "ns3/nstime.h"
-#include "net-device.h"
-#include "ipv4-address.h"
-#include "mac-address.h"
-#include "sgi-hashmap.h"
-
-namespace ns3 {
-
-class NetDevice;
-class Ipv4Interface;
-
-class ArpCache {
-public:
-  class Entry;
-
-  ArpCache (NetDevice *device, Ipv4Interface *interface);
-  ~ArpCache ();
-
-  NetDevice *PeekDevice (void) const;
-  Ipv4Interface *GetInterface (void) const;
-
-  void SetAliveTimeout (Time aliveTimeout);
-  void SetDeadTimeout (Time deadTimeout);
-  void SetWaitReplyTimeout (Time waitReplyTimeout);
-  Time GetAliveTimeout (void) const;
-  Time GetDeadTimeout (void) const;
-  Time GetWaitReplyTimeout (void) const;
-
-  
-  ArpCache::Entry *Lookup (Ipv4Address destination);
-  ArpCache::Entry *Add (Ipv4Address to);
-  void Flush (void);
-
-
-  class Entry {
-  public:
-    Entry (ArpCache *arp);
-
-    void MarkDead (void);
-    Packet MarkAlive (MacAddress macAddress);
-    void MarkWaitReply (Packet waiting);
-    Packet UpdateWaitReply (Packet waiting);
-    
-    bool IsDead (void);
-    bool IsAlive (void);
-    bool IsWaitReply (void);
-    
-    MacAddress GetMacAddress (void);
-    bool IsExpired (void);
-  private:
-    enum ArpCacheEntryState_e {
-      ALIVE,
-      WAIT_REPLY,
-      DEAD
-    };
-
-    void UpdateSeen (void);
-    ArpCache *m_arp;
-    ArpCacheEntryState_e m_state;
-    Time m_lastSeen;
-    MacAddress m_macAddress;
-    Packet m_waiting;
-  };
-
-private:
-  typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash> Cache;
-  typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash>::iterator CacheI;
-
-  NetDevice *m_device;
-  Ipv4Interface *m_interface;
-  Time m_aliveTimeout;
-  Time m_deadTimeout;
-  Time m_waitReplyTimeout;
-  Cache m_arpCache;
-};
-
-
-}; // namespace ns3
-
-#endif /* ARP_CACHE_H */
--- a/src/node/arp-header.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,146 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#include "ns3/assert.h"
-#include "arp-header.h"
-#include "header-utils.h"
-
-namespace ns3 {
-
-ArpHeader::~ArpHeader ()
-{}
-
-void 
-ArpHeader::SetRequest (MacAddress sourceHardwareAddress,
-                       Ipv4Address sourceProtocolAddress,
-                       MacAddress destinationHardwareAddress,
-                       Ipv4Address destinationProtocolAddress)
-{
-  m_type = ARP_TYPE_REQUEST;
-  m_macSource = sourceHardwareAddress;
-  m_macDest = destinationHardwareAddress;
-  m_ipv4Source = sourceProtocolAddress;
-  m_ipv4Dest = destinationProtocolAddress;
-}
-void 
-ArpHeader::SetReply (MacAddress sourceHardwareAddress,
-                     Ipv4Address sourceProtocolAddress,
-                     MacAddress destinationHardwareAddress,
-                     Ipv4Address destinationProtocolAddress)
-{
-  m_type = ARP_TYPE_REPLY;
-  m_macSource = sourceHardwareAddress;
-  m_macDest = destinationHardwareAddress;
-  m_ipv4Source = sourceProtocolAddress;
-  m_ipv4Dest = destinationProtocolAddress;
-}
-bool 
-ArpHeader::IsRequest (void) const
-{
-  return (m_type == ARP_TYPE_REQUEST)?true:false;
-}
-bool 
-ArpHeader::IsReply (void) const
-{
-  return (m_type == ARP_TYPE_REPLY)?true:false;
-}
-MacAddress 
-ArpHeader::GetSourceHardwareAddress (void)
-{
-  return m_macSource;
-}
-MacAddress 
-ArpHeader::GetDestinationHardwareAddress (void)
-{
-  return m_macDest;
-}
-Ipv4Address 
-ArpHeader::GetSourceIpv4Address (void)
-{
-  return m_ipv4Source;
-}
-Ipv4Address 
-ArpHeader::GetDestinationIpv4Address (void)
-{
-  return m_ipv4Dest;
-}
-
-
-void 
-ArpHeader::PrintTo (std::ostream &os) const
-{
-  os << "(arp)";
-  if (IsRequest ()) 
-    {
-      os << " source mac: " << m_macSource
-          << " source ipv4: " << m_ipv4Source
-          << " dest ipv4: " << m_ipv4Dest;
-    } 
-  else 
-    {
-      NS_ASSERT (IsReply ());
-      os << " source mac: " << m_macSource
-          << " source ipv4: " << m_ipv4Source
-          << " dest mac: " << m_macDest
-          << " dest ipv4: " <<m_ipv4Dest;
-    }
-}
-uint32_t 
-ArpHeader::GetSerializedSize (void) const
-{
-  /* this is the size of an ARP payload. */
-  return 28;
-}
-
-void
-ArpHeader::SerializeTo (Buffer::Iterator start) const
-{
-  Buffer::Iterator i = start;
-  NS_ASSERT (m_macSource.GetLength () == m_macDest.GetLength ());
-
-  /* ethernet */
-  i.WriteHtonU16 (0x0001);
-  /* ipv4 */
-  i.WriteHtonU16 (0x0800);
-  i.WriteU8 (m_macSource.GetLength ());
-  i.WriteU8 (4);
-  i.WriteHtonU16 (m_type);
-  WriteTo (i, m_macSource);
-  WriteTo (i, m_ipv4Source);
-  WriteTo (i, m_macDest);
-  WriteTo (i, m_ipv4Dest);
-}
-uint32_t
-ArpHeader::DeserializeFrom (Buffer::Iterator start)
-{
-  Buffer::Iterator i = start;
-  i.Next (2+2);
-  uint32_t hardwareAddressLen = i.ReadU8 ();
-  i.Next (1);
-  m_type = i.ReadNtohU16 ();
-  ReadFrom (i, m_macSource, hardwareAddressLen);
-  ReadFrom (i, m_ipv4Source);
-  ReadFrom (i, m_macDest, hardwareAddressLen);
-  ReadFrom (i, m_ipv4Dest);
-  return GetSerializedSize ();
-}
-
-}; // namespace ns3
--- a/src/node/arp-header.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#ifndef ARP_HEADER_H
-#define ARP_HEADER_H
-
-#include "ns3/header.h"
-#include "mac-address.h"
-#include "ipv4-address.h"
-
-namespace ns3 {
-
-class ArpHeader : public Header {
- public:
-  virtual ~ArpHeader ();
-
-  void SetRequest (MacAddress sourceHardwareAddress,
-                   Ipv4Address sourceProtocolAddress,
-                   MacAddress destinationHardwareAddress,
-                   Ipv4Address destinationProtocolAddress);
-  void SetReply (MacAddress sourceHardwareAddress,
-                 Ipv4Address sourceProtocolAddress,
-                 MacAddress destinationHardwareAddress,
-                 Ipv4Address destinationProtocolAddress);
-  bool IsRequest (void) const;
-  bool IsReply (void) const;
-  MacAddress GetSourceHardwareAddress (void);
-  MacAddress GetDestinationHardwareAddress (void);
-  Ipv4Address GetSourceIpv4Address (void);
-  Ipv4Address GetDestinationIpv4Address (void);
-
-private:
-  virtual void PrintTo (std::ostream &os) const;
-  virtual uint32_t GetSerializedSize (void) const;
-  virtual void SerializeTo (Buffer::Iterator start) const;
-  virtual uint32_t DeserializeFrom (Buffer::Iterator start);
-
-  enum ArpType_e {
-    ARP_TYPE_REQUEST = 1,
-    ARP_TYPE_REPLY   = 2
-  };
-  uint16_t m_type;
-  MacAddress m_macSource;
-  MacAddress m_macDest;
-  Ipv4Address m_ipv4Source;
-  Ipv4Address m_ipv4Dest;
-};
-
-}; // namespace ns3
-
-#endif /* ARP_HEADER_H */
--- a/src/node/arp-ipv4-interface.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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
- *
- * Authors: 
- *  Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
- */
-
-#include "ns3/packet.h"
-#include "ns3/composite-trace-resolver.h"
-
-#include "arp-ipv4-interface.h"
-#include "i-arp-private.h"
-#include "node.h"
-#include "net-device.h"
-#include "ipv4.h"
-
-namespace ns3 {
-
-ArpIpv4Interface::ArpIpv4Interface (Node *node, NetDevice *device)
-  : Ipv4Interface (device),
-    m_node (node)
-{
-  m_node->Ref ();
-}
-ArpIpv4Interface::~ArpIpv4Interface ()
-{
-  m_node->Unref ();
-}
-
-TraceResolver *
-ArpIpv4Interface::DoCreateTraceResolver (TraceContext const &context)
-{
-  CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
-  if (PeekDevice () != 0)
-    {
-      resolver->Add ("netdevice",
-                     MakeCallback (&NetDevice::CreateTraceResolver, PeekDevice ()),
-                     ArpIpv4Interface::NETDEVICE);
-    }
-  
-  return resolver;
-}
-
-void 
-ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest)
-{
-  NS_ASSERT (PeekDevice () != 0);
-  if (PeekDevice ()->NeedsArp ())
-    {
-      IArpPrivate * arp = m_node->QueryInterface<IArpPrivate> (IArpPrivate::iid);
-      MacAddress hardwareDestination;
-      bool found = arp->Lookup (p, dest, PeekDevice (), &hardwareDestination);
-      if (found)
-        {
-          PeekDevice ()->Send (p, hardwareDestination, Ipv4::PROT_NUMBER);
-        }
-      arp->Unref ();
-    }
-  else
-    {
-      PeekDevice ()->Send (p, PeekDevice ()->GetBroadcast (), Ipv4::PROT_NUMBER);
-    }
-}
-
-}//namespace ns3
--- a/src/node/arp-ipv4-interface.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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
- *
- * Authors: 
- *  Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
- */
-#ifndef ARP_IPV4_INTERFACE_H
-#define ARP_IPV4_INTERFACE_H
-
-#include "ipv4-interface.h"
-
-namespace ns3 {
-
-class Node;
-
-/**
- * \brief an Ipv4 Interface which uses ARP
- *
- * If you need to use ARP on top of a specific NetDevice, you
- * can use this Ipv4Interface subclass to wrap it for the Ipv4 class
- * when calling Ipv4::AddInterface.
- */
-class ArpIpv4Interface : public Ipv4Interface
-{
- public:
-  enum TraceType {
-    NETDEVICE,
-    ARP,
-  };
-  ArpIpv4Interface (Node *node, NetDevice *device);
-  virtual ~ArpIpv4Interface ();
-
- private:
-  virtual void SendTo (Packet p, Ipv4Address dest);
-  virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context);
-  Node *m_node;
-};
-
-}//namespace ns3
-
-
-#endif /* ARP_IPV4_INTERFACE_H */
--- a/src/node/arp.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,235 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2006 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#include "ns3/packet.h"
-#include "ns3/debug.h"
-#include "ns3/empty-trace-resolver.h"
-#include "arp.h"
-#include "arp-header.h"
-#include "arp-cache.h"
-#include "net-device.h"
-#include "ipv4-interface.h"
-#include "node.h"
-#include "i-ipv4-private.h"
-
-NS_DEBUG_COMPONENT_DEFINE ("Arp");
-
-namespace ns3 {
-
-const uint16_t Arp::PROT_NUMBER = 0x0806;
-
-Arp::Arp (Node *node)
-  : L3Protocol (PROT_NUMBER, 0/* XXX: correct version number ? */ ),
-    m_node (node)
-{
-  m_node->Ref ();
-}
-
-Arp::~Arp ()
-{
-  Dispose ();
-}
-
-void 
-Arp::DoDispose (void)
-{
-  for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++)
-    {
-      delete *i;
-    }
-  m_cacheList.clear ();
-  if (m_node != 0)
-    {
-      m_node->Unref ();
-      m_node = 0;
-    }
-  L3Protocol::DoDispose ();
-}
-
-TraceResolver *
-Arp::CreateTraceResolver (TraceContext const &context)
-{
-  return new EmptyTraceResolver (context);
-}
-
-ArpCache *
-Arp::FindCache (NetDevice *device)
-{
-  for (CacheList::const_iterator i = m_cacheList.begin (); i != m_cacheList.end (); i++)
-    {
-      if ((*i)->PeekDevice () == device)
-	{
-	  return *i;
-	}
-    }
-  IIpv4Private *ipv4 = m_node->QueryInterface<IIpv4Private> (IIpv4Private::iid);
-  Ipv4Interface *interface = ipv4->FindInterfaceForDevice (device);
-  ipv4->Unref ();
-  ArpCache * cache = new ArpCache (device, interface);
-  NS_ASSERT (device->IsBroadcast ());
-  device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache));
-  m_cacheList.push_back (cache);
-  return cache;
-}
-
-void 
-Arp::Receive(Packet& packet, NetDevice *device)
-{
-  ArpCache *cache = FindCache (device);
-  ArpHeader arp;
-  packet.RemoveHeader (arp);
-  if (arp.IsRequest () && 
-      arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ()) 
-    {
-      NS_DEBUG ("node="<<m_node->GetId () <<", got request from " << 
-                arp.GetSourceIpv4Address () << " -- send reply");
-      SendArpReply (cache, arp.GetSourceIpv4Address (),
-                    arp.GetSourceHardwareAddress ());
-    } 
-  else if (arp.IsReply () &&
-           arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress ()) &&
-           arp.GetDestinationHardwareAddress ().IsEqual (device->GetAddress ())) 
-    {
-      Ipv4Address from = arp.GetSourceIpv4Address ();
-      ArpCache::Entry *entry = cache->Lookup (from);
-      if (entry != 0)
-        {
-          if (entry->IsWaitReply ()) 
-            {
-              NS_DEBUG ("node="<<m_node->GetId ()<<", got reply from " << 
-                        arp.GetSourceIpv4Address ()
-                     << " for waiting entry -- flush");
-              MacAddress from_mac = arp.GetSourceHardwareAddress ();
-              Packet waiting = entry->MarkAlive (from_mac);
-	      cache->GetInterface ()->Send (waiting, arp.GetSourceIpv4Address ());
-            } 
-          else 
-            {
-              // ignore this reply which might well be an attempt 
-              // at poisening my arp cache.
-              NS_DEBUG ("node="<<m_node->GetId ()<<", got reply from " << 
-                        arp.GetSourceIpv4Address () << 
-                        " for non-waiting entry -- drop");
-	      // XXX report packet as dropped.
-            }
-        } 
-      else 
-        {
-          NS_DEBUG ("node="<<m_node->GetId ()<<", got reply for unknown entry -- drop");
-	  // XXX report packet as dropped.
-        }
-    }
-}
-bool 
-Arp::Lookup (Packet &packet, Ipv4Address destination, 
-	     NetDevice *device,
-	     MacAddress *hardwareDestination)
-{
-  ArpCache *cache = FindCache (device);
-  ArpCache::Entry *entry = cache->Lookup (destination);
-  if (entry != 0)
-    {
-      if (entry->IsExpired ()) 
-        {
-          if (entry->IsDead ()) 
-            {
-              NS_DEBUG ("node="<<m_node->GetId ()<<
-                        ", dead entry for " << destination << " expired -- send arp request");
-              entry->MarkWaitReply (packet);
-              SendArpRequest (cache, destination);
-            } 
-          else if (entry->IsAlive ()) 
-            {
-              NS_DEBUG ("node="<<m_node->GetId ()<<
-                        ", alive entry for " << destination << " expired -- send arp request");
-              entry->MarkWaitReply (packet);
-              SendArpRequest (cache, destination);
-            } 
-          else if (entry->IsWaitReply ()) 
-            {
-              NS_DEBUG ("node="<<m_node->GetId ()<<
-                        ", wait reply for " << destination << " expired -- drop");
-              entry->MarkDead ();
-	      // XXX report packet as 'dropped'
-            }
-        } 
-      else 
-        {
-          if (entry->IsDead ()) 
-            {
-              NS_DEBUG ("node="<<m_node->GetId ()<<
-                        ", dead entry for " << destination << " valid -- drop");
-	      // XXX report packet as 'dropped'
-            } 
-          else if (entry->IsAlive ()) 
-            {
-              NS_DEBUG ("node="<<m_node->GetId ()<<
-                        ", alive entry for " << destination << " valid -- send");
-	      *hardwareDestination = entry->GetMacAddress ();
-              return true;
-            } 
-          else if (entry->IsWaitReply ()) 
-            {
-              NS_DEBUG ("node="<<m_node->GetId ()<<
-                        ", wait reply for " << destination << " valid -- drop previous");
-              Packet old = entry->UpdateWaitReply (packet);
-	      // XXX report 'old' packet as 'dropped'
-            }
-        }
-
-    }
-  else
-    {
-      // This is our first attempt to transmit data to this destination.
-      NS_DEBUG ("node="<<m_node->GetId ()<<
-                ", no entry for " << destination << " -- send arp request");
-      entry = cache->Add (destination);
-      entry->MarkWaitReply (packet);
-      SendArpRequest (cache, destination);
-    }
-  return false;
-}
-
-void
-Arp::SendArpRequest (ArpCache const *cache, Ipv4Address to)
-{
-  ArpHeader arp;
-  arp.SetRequest (cache->PeekDevice ()->GetAddress (),
-		  cache->GetInterface ()->GetAddress (), 
-                  cache->PeekDevice ()->GetBroadcast (),
-                  to);
-  Packet packet;
-  packet.AddHeader (arp);
-  cache->PeekDevice ()->Send (packet, cache->PeekDevice ()->GetBroadcast (), PROT_NUMBER);
-}
-
-void
-Arp::SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac)
-{
-  ArpHeader arp;
-  arp.SetReply (cache->PeekDevice ()->GetAddress (),
-                cache->GetInterface ()->GetAddress (),
-                toMac, toIp);
-  Packet packet;
-  packet.AddHeader (arp);
-  cache->PeekDevice ()->Send (packet, toMac, PROT_NUMBER);
-}
-
-}//namespace ns3
--- a/src/node/arp.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2006 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#ifndef ARP_H
-#define ARP_H
-
-#include <list>
-#include "ipv4-address.h"
-#include "mac-address.h"
-#include "l3-protocol.h"
-
-namespace ns3 {
-
-class ArpCache;
-class NetDevice;
-class Node;
-class Packet;
-class TraceResolver;
-class TraceContext;
-
-class Arp : public L3Protocol
-{
-public:
-  static const uint16_t PROT_NUMBER;
-
-  Arp (Node *node);
-  ~Arp ();
-
-  virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
-
-  virtual void Receive(Packet& p, NetDevice *device);
-  bool Lookup (Packet &p, Ipv4Address destination, 
-	       NetDevice *device,
-	       MacAddress *hardwareDestination);
-protected:
-  virtual void DoDispose (void);
-private:
-  typedef std::list<ArpCache *> CacheList;
-  ArpCache *FindCache (NetDevice *device);
-  void SendArpRequest (ArpCache const *cache, Ipv4Address to);
-  void SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac);
-  CacheList m_cacheList;
-  Node *m_node;
-};
-
-}//namespace ns3
-
-
-#endif /* ARP_H */
--- a/src/node/ascii-trace.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +0,0 @@
-/* -*-	Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#include "ascii-trace.h"
-
-#include "ns3/trace-context.h"
-#include "ns3/trace-root.h"
-#include "ns3/simulator.h"
-
-#include "node.h"
-#include "ipv4.h"
-#include "queue.h"
-#include "llc-snap-header.h"
-#include "arp-header.h"
-#include "udp-header.h"
-#include "ipv4-header.h"
-#include "node-list.h"
-
-namespace ns3 {
-
-AsciiTrace::AsciiTrace (std::string filename)
-{
-  m_os.open (filename.c_str ());
-}
-AsciiTrace::~AsciiTrace ()
-{
-  m_os.close ();
-}
-void
-AsciiTrace::TraceAllQueues (void)
-{
-  TraceRoot::Connect ("/nodes/*/ipv4/interfaces/*/netdevice/queue/*",
-                      MakeCallback (&AsciiTrace::LogDevQueue, this));
-}
-void
-AsciiTrace::TraceAllNetDeviceRx (void)
-{
-  TraceRoot::Connect ("/nodes/*/ipv4/interfaces/*/netdevice/rx",
-                      MakeCallback (&AsciiTrace::LogDevRx, this));
-}
-
-void
-AsciiTrace::PrintType (Packet const &packet)
-{
-  Packet p = packet;
-  LlcSnapHeader llc;
-  p.RemoveHeader (llc);
-  switch (llc.GetType ())
-    {
-    case 0x0800: {
-      Ipv4Header ipv4;
-      p.RemoveHeader (ipv4);
-      if (ipv4.GetProtocol () == 17)
-        {
-          UdpHeader udp;
-          p.RemoveHeader (udp);
-          m_os << "udp size=" << p.GetSize ();
-        }
-    } break;
-    case 0x0806: {
-      ArpHeader arp;
-      p.RemoveHeader (arp);
-      m_os << "arp ";
-      if (arp.IsRequest ())
-        {
-          m_os << "request";
-        }
-      else
-        {
-          m_os << "reply ";
-        }
-    } break;
-    }
-} 
-
-void 
-AsciiTrace::LogDevQueue (TraceContext const &context, Packet const &packet)
-{
-  enum Queue::TraceType type;
-  context.Get (type);
-  switch (type) 
-    {
-    case Queue::ENQUEUE:
-      m_os << "+ ";
-      break;
-    case Queue::DEQUEUE:
-      m_os << "- ";
-      break;
-    case Queue::DROP:
-      m_os << "d ";
-      break;
-    }
-  m_os << Simulator::Now ().GetSeconds () << " ";
-  NodeList::NodeIndex nodeIndex;
-  context.Get (nodeIndex);
-  m_os << "node=" << NodeList::PeekNode (nodeIndex)->GetId () << " ";
-  Ipv4::InterfaceIndex interfaceIndex;
-  context.Get (interfaceIndex);
-  m_os << "interface=" << interfaceIndex << " ";
-  m_os << "pkt-uid=" << packet.GetUid () << " ";
-  PrintType (packet);
-  m_os << std::endl;
-}
-void 
-AsciiTrace::LogDevRx (TraceContext const &context, Packet &p)
-{
-  m_os << "r " << Simulator::Now ().GetSeconds () << " ";
-  NodeList::NodeIndex nodeIndex;
-  context.Get (nodeIndex);
-  m_os << "node=" << NodeList::PeekNode (nodeIndex)->GetId () << " ";
-  Ipv4::InterfaceIndex interfaceIndex;
-  context.Get (interfaceIndex);
-  m_os << "interface=" << interfaceIndex << " ";
-  m_os << "pkt-uid=" << p.GetUid () << " ";
-  PrintType (p);
-  m_os << std::endl;  
-}
-
-}//namespace ns3
--- a/src/node/ascii-trace.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-/* -*-	Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#ifndef ASCII_TRACE_H
-#define ASCII_TRACE_H
-
-#include <string>
-#include <fstream>
-
-namespace ns3 {
-
-class Packet;
-class TraceContext;
-
-class AsciiTrace 
-{
-public:
-  AsciiTrace (std::string filename);
-  ~AsciiTrace ();
-  void TraceAllQueues (void);
-  void TraceAllNetDeviceRx (void);
-private:
-  void PrintType (Packet const &p);
-  void LogDevQueue (TraceContext const &context, const Packet &p);
-  void LogDevRx (TraceContext const &context, Packet &p);
-  std::ofstream m_os;
-};
-
-}//namespace ns3
-
-#endif /* ASCII_TRACE_H */
--- a/src/node/header-utils.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2006 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#include "header-utils.h"
-
-namespace ns3 {
-
-void WriteTo (Buffer::Iterator &i, Ipv4Address ad)
-{
-  i.WriteHtonU32 (ad.GetHostOrder ());
-}
-void WriteTo (Buffer::Iterator &i, MacAddress ad)
-{
-  uint8_t mac[MacAddress::MAX_LEN];
-  ad.Peek (mac);
-  i.Write (mac, ad.GetLength ());
-}
-
-void ReadFrom (Buffer::Iterator &i, Ipv4Address &ad)
-{
-  ad.SetHostOrder (i.ReadNtohU32 ());
-}
-void ReadFrom (Buffer::Iterator &i, MacAddress &ad, uint32_t len)
-{
-  uint8_t mac[MacAddress::MAX_LEN];
-  i.Read (mac, len);
-  ad.Set (mac, len);
-}
-
-
-
-}; // namespace ns3
--- a/src/node/header-utils.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2006 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#ifndef HEADER_UTILS_H
-#define HEADER_UTILS_H
-
-#include "ns3/buffer.h"
-#include "ipv4-address.h"
-#include "mac-address.h"
-
-namespace ns3 {
-
-void WriteTo (Buffer::Iterator &i, Ipv4Address ad);
-void WriteTo (Buffer::Iterator &i, MacAddress ad);
-
-void ReadFrom (Buffer::Iterator &i, Ipv4Address &ad);
-void ReadFrom (Buffer::Iterator &i, MacAddress &ad, uint32_t len);
-
-};
-
-#endif /* HEADER_UTILS_H */
--- a/src/node/i-arp-private.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#include "i-arp-private.h"
-#include "ns3/iid-manager.h"
-#include "arp.h"
-#include "ns3/assert.h"
-
-namespace ns3 {
-
-const uint32_t IArpPrivate::iid = IidManager::Allocate ("IArpPrivate");
-
-IArpPrivate::IArpPrivate (Arp *arp)
-  : NsUnknown (IArpPrivate::iid),
-    m_arp (arp)
-{
-  m_arp->Ref ();
-}
-IArpPrivate::~IArpPrivate ()
-{
-  NS_ASSERT (m_arp == 0);
-}
-
-bool 
-IArpPrivate::Lookup (Packet &p, Ipv4Address destination, 
-		     NetDevice *device,
-		     MacAddress *hardwareDestination)
-{
-  return m_arp->Lookup (p, destination, device, hardwareDestination);
-}
-
-void
-IArpPrivate::DoDispose (void)
-{
-  m_arp->Unref ();
-  m_arp = 0;
-  NsUnknown::DoDispose ();
-}
-
-
-} // namespace ns3
--- a/src/node/i-arp-private.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#ifndef I_ARP_PRIVATE_H
-#define I_ARP_PRIVATE_H
-
-#include "ns3/ns-unknown.h"
-#include "ipv4-address.h"
-
-namespace ns3 {
-
-class NetDevice;
-class MacAddress;
-class Packet;
-class Arp;
-
-class IArpPrivate : public NsUnknown
-{
-public:
-  static const uint32_t iid;
-  IArpPrivate (Arp *arp);
-  virtual ~IArpPrivate ();
-  bool Lookup (Packet &p, Ipv4Address destination, 
-	       NetDevice *device,
-	       MacAddress *hardwareDestination);
-protected:
-  virtual void DoDispose (void);
-private:
-  Arp *m_arp;
-};
-
-} // namespace ns3
-
-#endif /* I_ARP_PRIVATE_H */
--- a/src/node/i-ipv4-impl.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,144 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#include "i-ipv4-impl.h"
-#include "ipv4.h"
-#include "ns3/assert.h"
-
-namespace ns3 {
-
-IIpv4Impl::IIpv4Impl (Ipv4 *ipv4)
-  : m_ipv4 (ipv4)
-{
-  m_ipv4->Ref ();
-}
-IIpv4Impl::~IIpv4Impl ()
-{
-  NS_ASSERT (m_ipv4 == 0);
-}
-void 
-IIpv4Impl::DoDispose (void)
-{
-  m_ipv4->Unref ();
-  m_ipv4 = 0;
-}
-
-void 
-IIpv4Impl::AddHostRouteTo (Ipv4Address dest, 
-			   Ipv4Address nextHop, 
-			   uint32_t interface)
-{
-  m_ipv4->AddHostRouteTo (dest, nextHop, interface);
-}
-void 
-IIpv4Impl::AddHostRouteTo (Ipv4Address dest, 
-			   uint32_t interface)
-{
-  m_ipv4->AddHostRouteTo (dest, interface);
-}
-void 
-IIpv4Impl::AddNetworkRouteTo (Ipv4Address network, 
-			      Ipv4Mask networkMask, 
-			      Ipv4Address nextHop, 
-			      uint32_t interface)
-{
-  m_ipv4->AddNetworkRouteTo (network, networkMask, nextHop, interface);
-}
-void 
-IIpv4Impl::AddNetworkRouteTo (Ipv4Address network, 
-			      Ipv4Mask networkMask, 
-			      uint32_t interface)
-{
-  m_ipv4->AddNetworkRouteTo (network, networkMask, interface);
-}
-void 
-IIpv4Impl::SetDefaultRoute (Ipv4Address nextHop, 
-			    uint32_t interface)
-{
-  m_ipv4->SetDefaultRoute (nextHop, interface);
-}
-uint32_t 
-IIpv4Impl::GetNRoutes (void)
-{
-  return m_ipv4->GetNRoutes ();
-}
-Ipv4Route *
-IIpv4Impl::GetRoute (uint32_t i)
-{
-  return m_ipv4->GetRoute (i);
-}
-void 
-IIpv4Impl::RemoveRoute (uint32_t i)
-{
-  return m_ipv4->RemoveRoute (i);
-}
-uint32_t 
-IIpv4Impl::AddInterface (NetDevice *device)
-{
-  return m_ipv4->AddInterface (device);
-}
-uint32_t 
-IIpv4Impl::GetNInterfaces (void)
-{
-  return m_ipv4->GetNInterfaces ();
-}
-
-void 
-IIpv4Impl::SetAddress (uint32_t i, Ipv4Address address)
-{
-  m_ipv4->SetAddress (i, address);
-}
-void 
-IIpv4Impl::SetNetworkMask (uint32_t i, Ipv4Mask mask)
-{
-  m_ipv4->SetNetworkMask (i, mask);
-}
-Ipv4Mask 
-IIpv4Impl::GetNetworkMask (uint32_t i) const
-{
-  return m_ipv4->GetNetworkMask (i);
-}
-Ipv4Address 
-IIpv4Impl::GetAddress (uint32_t i) const
-{
-  return m_ipv4->GetAddress (i);
-}
-uint16_t 
-IIpv4Impl::GetMtu (uint32_t i) const
-{
-  return m_ipv4->GetMtu (i);
-}
-bool 
-IIpv4Impl::IsUp (uint32_t i) const
-{
-  return m_ipv4->IsUp (i);
-}
-void 
-IIpv4Impl::SetUp (uint32_t i)
-{
-  m_ipv4->SetUp (i);
-}
-void 
-IIpv4Impl::SetDown (uint32_t i)
-{
-  m_ipv4->SetDown (i);
-}
-
-}//namespace ns3
--- a/src/node/i-ipv4-impl.h	Fri May 04 14:03:12 2007 +0200
+++ /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) 2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#ifndef I_IPV4_IMPL_H
-#define I_IPV4_IMPL_H
-
-#include "i-ipv4.h"
-
-namespace ns3 {
-
-class Ipv4;
-
-class IIpv4Impl : public IIpv4
-{
-public:
-  IIpv4Impl (Ipv4 *ipv4);
-
-  virtual ~IIpv4Impl ();
-
-  virtual void AddHostRouteTo (Ipv4Address dest, 
-			       Ipv4Address nextHop, 
-			       uint32_t interface);
-  virtual void AddHostRouteTo (Ipv4Address dest, 
-			       uint32_t interface);
-  virtual void AddNetworkRouteTo (Ipv4Address network, 
-				  Ipv4Mask networkMask, 
-				  Ipv4Address nextHop, 
-				  uint32_t interface);
-  virtual void AddNetworkRouteTo (Ipv4Address network, 
-				  Ipv4Mask networkMask, 
-				  uint32_t interface);
-  virtual void SetDefaultRoute (Ipv4Address nextHop, 
-				uint32_t interface);
-  virtual uint32_t GetNRoutes (void);
-  virtual Ipv4Route *GetRoute (uint32_t i);
-  virtual void RemoveRoute (uint32_t i);
-  virtual uint32_t AddInterface (NetDevice *device);
-  virtual uint32_t GetNInterfaces (void);  
-
-  virtual void SetAddress (uint32_t i, Ipv4Address address);
-  virtual void SetNetworkMask (uint32_t i, Ipv4Mask mask);
-  virtual Ipv4Mask GetNetworkMask (uint32_t t) const;
-  virtual Ipv4Address GetAddress (uint32_t i) const;
-  virtual uint16_t GetMtu (uint32_t i) const;
-  virtual bool IsUp (uint32_t i) const;
-  virtual void SetUp (uint32_t i);
-  virtual void SetDown (uint32_t i);
-protected:
-  virtual void DoDispose (void);
-private:
-  Ipv4 *m_ipv4;
-};
-
-} // namespace ns3
-
-#endif /* I_IPV4_IMPL_H */
--- a/src/node/i-ipv4-private.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#include "i-ipv4-private.h"
-#include "ipv4.h"
-#include "ns3/assert.h"
-#include "ns3/iid-manager.h"
-
-namespace ns3 {
-
-const uint32_t IIpv4Private::iid = IidManager::Allocate ("IIpv4Private");
-
-IIpv4Private::IIpv4Private (Ipv4 *ipv4)
-  : NsUnknown (IIpv4Private::iid),
-    m_ipv4 (ipv4)
-{
-  m_ipv4->Ref ();
-}
-IIpv4Private::~IIpv4Private ()
-{
-  NS_ASSERT (m_ipv4 == 0);
-}
-TraceResolver *
-IIpv4Private::CreateTraceResolver (TraceContext const &context)
-{
-  return m_ipv4->CreateTraceResolver (context);
-}
-void 
-IIpv4Private::Send (Packet const &packet, Ipv4Address source, 
-		    Ipv4Address destination, uint8_t protocol)
-{
-  m_ipv4->Send (packet, source, destination, protocol);
-}
-Ipv4Interface *
-IIpv4Private::FindInterfaceForDevice (NetDevice const*device)
-{
-  return m_ipv4->FindInterfaceForDevice (device);
-}
-void 
-IIpv4Private::Receive(Packet& p, NetDevice *device)
-{
-  m_ipv4->Receive (p, device);
-}
-void 
-IIpv4Private::DoDispose (void)
-{
-  m_ipv4->Unref ();
-  m_ipv4 = 0;
-  NsUnknown::DoDispose ();
-}
-
-} // namespace ns3
--- a/src/node/i-ipv4-private.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#ifndef I_IPV4_PRIVATE_H
-#define I_IPV4_PRIVATE_H
-
-#include "ns3/ns-unknown.h"
-#include "ns3/ipv4-address.h"
-#include <stdint.h>
-
-namespace ns3 {
-
-class Packet;
-class Ipv4;
-class TraceContext;
-class TraceResolver;
-class Ipv4Interface;
-class NetDevice;
-
-class IIpv4Private : public NsUnknown
-{
-public:
-  static const uint32_t iid;
-  IIpv4Private (Ipv4 *ipv4);
-  virtual ~IIpv4Private ();
-
-  TraceResolver *CreateTraceResolver (TraceContext const &context);
-  void Send (Packet const &packet, Ipv4Address source, 
-	     Ipv4Address destination, uint8_t protocol);
-  Ipv4Interface *FindInterfaceForDevice (NetDevice const*device);
-  void Receive(Packet& p, NetDevice *device);
-protected:
-  virtual void DoDispose (void);
-private:
-  Ipv4 *m_ipv4;
-};
-
-} // namespace ns3
-
-#endif /* I_IPV4_PRIVATE_H */
--- a/src/node/i-udp-impl.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#include "i-udp-impl.h"
-#include "udp.h"
-#include "ns3/assert.h"
-
-namespace ns3 {
-
-IUdpImpl::IUdpImpl (Udp *udp)
-  : m_udp (udp)
-{
-  m_udp->Ref ();
-}
-IUdpImpl::~IUdpImpl ()
-{
-  NS_ASSERT (m_udp == 0);
-}
-
-Socket *
-IUdpImpl::CreateSocket (void)
-{
-  return m_udp->CreateSocket ();
-}
-
-void 
-IUdpImpl::DoDispose (void)
-{
-  if (m_udp != 0)
-    {
-      m_udp->Unref ();
-      m_udp = 0;
-    }
-  IUdp::DoDispose ();
-}
-
-} // namespace ns3
--- a/src/node/i-udp-impl.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#ifndef I_UDP_IMPL_H
-#define I_UDP_IMPL_H
-
-#include "i-udp.h"
-
-namespace ns3 {
-
-class Udp;
-
-class IUdpImpl : public IUdp
-{
-public:
-  IUdpImpl (Udp *udp);
-  virtual ~IUdpImpl ();
-
-  virtual Socket *CreateSocket (void);
-
-protected:
-  virtual void DoDispose (void);
-private:
-  Udp *m_udp;
-};
-
-} // namespace ns3
-
-#endif /* I_UDP_IMPL_H */
--- a/src/node/internet-node.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,132 +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 the InternetNode class for ns3.
-// George F. Riley, Georgia Tech, Fall 2006
-
-#include "ns3/composite-trace-resolver.h"
-
-#include "application-list.h"
-#include "l3-demux.h"
-#include "ipv4-l4-demux.h"
-#include "internet-node.h"
-#include "udp.h"
-#include "ipv4.h"
-#include "arp.h"
-#include "net-device.h"
-#include "i-udp-impl.h"
-#include "i-arp-private.h"
-#include "i-ipv4-impl.h"
-#include "i-ipv4-private.h"
-
-namespace ns3 {
-
-
-InternetNode::InternetNode()
-{
-  Ipv4 *ipv4 = new Ipv4 (this);
-  Arp *arp = new Arp (this);
-  Udp *udp = new Udp (this);
-
-  ApplicationList *applicationList = new ApplicationList(this);
-  L3Demux *l3Demux = new L3Demux(this);
-  Ipv4L4Demux *ipv4L4Demux = new Ipv4L4Demux(this);
-
-  l3Demux->Insert (ipv4);
-  l3Demux->Insert (arp);
-  ipv4L4Demux->Insert (udp);
-
-  IUdpImpl *udpImpl = new IUdpImpl (udp);
-  IArpPrivate *arpPrivate = new IArpPrivate (arp);
-  IIpv4Impl *ipv4Impl = new IIpv4Impl (ipv4);
-  IIpv4Private *ipv4Private = new IIpv4Private (ipv4);
-
-  NsUnknown::AddInterface (ipv4Private);
-  NsUnknown::AddInterface (ipv4Impl);
-  NsUnknown::AddInterface (arpPrivate);
-  NsUnknown::AddInterface (udpImpl);
-  NsUnknown::AddInterface (applicationList);
-  NsUnknown::AddInterface (l3Demux);
-  NsUnknown::AddInterface (ipv4L4Demux);
-
-
-  applicationList->Unref ();
-  l3Demux->Unref ();
-  ipv4L4Demux->Unref ();
-  arp->Unref ();
-  ipv4->Unref ();
-  udp->Unref ();
-  udpImpl->Unref ();
-  arpPrivate->Unref ();
-  ipv4Impl->Unref ();
-  ipv4Private->Unref ();
-}
-
-InternetNode::~InternetNode ()
-{}
-
-void
-InternetNode::SetName (std::string name)
-{
-  m_name = name;
-}
-
-TraceResolver *
-InternetNode::CreateTraceResolver (TraceContext const &context)
-{
-  CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
-  IIpv4Private *ipv4 = QueryInterface<IIpv4Private> (IIpv4Private::iid);
-  resolver->Add ("ipv4",
-                 MakeCallback (&IIpv4Private::CreateTraceResolver, ipv4),
-                 InternetNode::IPV4);
-  ipv4->Unref ();
-
-  return resolver;
-}
-
-void 
-InternetNode::DoDispose()
-{
-  Node::DoDispose ();
-}
-
-void 
-InternetNode::DoAddDevice (NetDevice *device) const
-{
-  device->SetReceiveCallback (MakeCallback (&InternetNode::ReceiveFromDevice, this));
-}
-
-bool
-InternetNode::ReceiveFromDevice (NetDevice *device, const Packet &p, uint16_t protocolNumber) const
-{
-  L3Demux *demux = QueryInterface<L3Demux> (L3Demux::iid);
-  L3Protocol *target = demux->PeekProtocol (protocolNumber);
-  demux->Unref ();
-  if (target != 0) 
-    {
-      Packet packet = p;
-      target->Receive(packet, device);
-      return true;
-    }
-  return false;
-}
-
-
-}//namespace ns3
--- a/src/node/internet-node.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +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>
-//
-// Define a basic "Internet" node, with a protocol stack (l3 and l4),
-// network device list, process list, and routing.
-
-#ifndef INTERNET_NODE_H
-#define INTERNET_NODE_H
-
-#include <list>
-#include <string>
-
-#include "node.h"
-
-namespace ns3 {
-
-class Packet;
-
-class InternetNode : public Node 
-{
-public:
-  enum TraceType {
-    IPV4,
-  };
-  InternetNode();
-  virtual ~InternetNode ();
-  virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
-
-  void SetName(std::string name);
-protected:
-  virtual void DoDispose(void);
-private:
-  virtual void DoAddDevice (NetDevice *device) const;
-  bool ReceiveFromDevice (NetDevice *device, const Packet &p, uint16_t protocolNumber) const;
-  std::string      m_name;
-};
-
-}//namespace ns3
-
-#endif /* INTERNET_NODE_H */
--- a/src/node/ipv4-checksum.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005,2006,2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#include "ipv4-checksum.h"
-
-namespace ns3 {
-
-uint16_t 
-Ipv4ChecksumCalculate (uint16_t checksum, uint8_t *buffer, uint16_t size)
-{
-  /* see RFC 1071 to understand this code. */
-  uint32_t sum = checksum;
-  uint16_t *data = (uint16_t *) buffer;
-  for (uint16_t i = 0; i < (size/2); i++) {
-    sum += data[i];
-  }
-  if ((size % 2) != 0) {
-    uint8_t tmpBuf[2];
-    tmpBuf[0] = buffer[size-1];
-    tmpBuf[1] = 0;
-    data = (uint16_t *)tmpBuf;
-    sum += *data;
-  }
-  while (sum >> 16) {
-    sum = (sum & 0xffff) + (sum >> 16);
-  }
-  return sum;
-}
-
-uint16_t 
-Ipv4ChecksumComplete (uint16_t checksum)
-{
-  return ~checksum;
-}
-
-}; //namespace ns3
--- a/src/node/ipv4-checksum.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005,2006,2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#ifndef IPV4_CHECKSUM_H
-#define IPV4_CHECKSUM_H
-
-#include <stdint.h>
-
-namespace ns3 {
-
-uint16_t Ipv4ChecksumCalculate (uint16_t checksum, uint8_t *buffer, uint16_t size);
-
-uint16_t Ipv4ChecksumComplete (uint16_t checksum);
-
-}; //namespace ns3
-
-#endif /* IPV4_CHECKSUM_H */
--- a/src/node/ipv4-end-point-demux.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,218 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#include "ipv4-end-point-demux.h"
-#include "ipv4-end-point.h"
-
-namespace ns3{
-
-Ipv4EndPointDemux::Ipv4EndPointDemux ()
-  : m_ephemeral (1025)
-{}
-
-Ipv4EndPointDemux::~Ipv4EndPointDemux ()
-{
-  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
-    {
-      Ipv4EndPoint *endPoint = *i;
-      delete endPoint;
-    }
-  m_endPoints.clear ();
-}
-
-bool
-Ipv4EndPointDemux::LookupPortLocal (uint16_t port)
-{
-  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
-    {
-      if ((*i)->GetLocalPort  () == port) 
-        {
-          return true;
-        }
-    }
-  return false;
-}
-
-bool
-Ipv4EndPointDemux::LookupLocal (Ipv4Address addr, uint16_t port)
-{
-  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
-    {
-      if ((*i)->GetLocalPort () == port &&
-          (*i)->GetLocalAddress () == addr) 
-        {
-          return true;
-        }
-    }
-  return false;
-}
-
-Ipv4EndPoint *
-Ipv4EndPointDemux::Allocate (void)
-{
-  uint16_t port = AllocateEphemeralPort ();
-  if (port == 0) 
-    {
-      return 0;
-    }
-  Ipv4EndPoint *endPoint = new Ipv4EndPoint (Ipv4Address::GetAny (), port);
-  m_endPoints.push_back (endPoint);
-  return endPoint;
-}
-Ipv4EndPoint *
-Ipv4EndPointDemux::Allocate (Ipv4Address address)
-{
-  uint16_t port = AllocateEphemeralPort ();
-  if (port == 0) 
-    {
-      return 0;
-    }
-  Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port);
-  m_endPoints.push_back (endPoint);
-  return endPoint;
-}
-Ipv4EndPoint *
-Ipv4EndPointDemux::Allocate (uint16_t port)
-{
-  return Allocate (Ipv4Address::GetAny (), port);
-}
-Ipv4EndPoint *
-Ipv4EndPointDemux::Allocate (Ipv4Address address, uint16_t port)
-{
-  if (LookupLocal (address, port)) 
-    {
-      return 0;
-    }
-  Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port);
-  m_endPoints.push_back (endPoint);
-  return endPoint;
-}
-
-Ipv4EndPoint *
-Ipv4EndPointDemux::Allocate (Ipv4Address localAddress, uint16_t localPort,
-			     Ipv4Address peerAddress, uint16_t peerPort)
-{
-  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
-    {
-      if ((*i)->GetLocalPort () == localPort &&
-          (*i)->GetLocalAddress () == localAddress &&
-          (*i)->GetPeerPort () == peerPort &&
-          (*i)->GetPeerAddress () == peerAddress) 
-        {
-          /* no way we can allocate this end-point. */
-          return 0;
-        }
-    }
-  Ipv4EndPoint *endPoint = new Ipv4EndPoint (localAddress, localPort);
-  endPoint->SetPeer (peerAddress, peerPort);
-  m_endPoints.push_back (endPoint);
-  return endPoint;
-}
-
-void 
-Ipv4EndPointDemux::DeAllocate (Ipv4EndPoint *endPoint)
-{
-  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
-    {
-      if (*i == endPoint)
-        {
-          delete endPoint;
-          m_endPoints.erase (i);
-          break;
-        }
-    }
-}
-
-
-/*
- * If we have an exact match, we return it.
- * Otherwise, if we find a generic match, we return it.
- * Otherwise, we return 0.
- */
-Ipv4EndPoint *
-Ipv4EndPointDemux::Lookup (Ipv4Address daddr, uint16_t dport, 
-                              Ipv4Address saddr, uint16_t sport)
-{
-  uint32_t genericity = 3;
-  Ipv4EndPoint *generic = 0;
-  //TRACE ("lookup " << daddr << ":" << dport << " " << saddr << ":" << sport);
-  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
-    {
-#if 0
-      TRACE ("against " << 
-             (*i)->GetLocalAddress ()
-             << ":" << 
-             (*i)->GetLocalPort () 
-             << " " << 
-             (*i)->GetPeerAddress () 
-             << ":" 
-             << (*i)->GetPeerPort ());
-#endif
-      if ((*i)->GetLocalPort () != dport) 
-        {
-          continue;
-        }
-      if ((*i)->GetLocalAddress () == daddr &&
-          (*i)->GetPeerPort () == sport &&
-          (*i)->GetPeerAddress () == saddr) 
-        {
-          /* this is an exact match. */
-          return *i;
-        }
-      uint32_t tmp = 0;
-      if ((*i)->GetLocalAddress () == Ipv4Address::GetAny ()) 
-        {
-          tmp ++;
-        }
-      if ((*i)->GetPeerAddress () == Ipv4Address::GetAny ()) 
-        {
-          tmp ++;
-        }
-      if (tmp < genericity) 
-        {
-          generic = (*i);
-          genericity = tmp;
-        }
-    }
-  return generic;
-}
-
-uint16_t
-Ipv4EndPointDemux::AllocateEphemeralPort (void)
-{
-  uint16_t port = m_ephemeral;
-  do 
-    {
-      port++;
-      if (port > 5000) 
-        {
-          port = 1024;
-        }
-      if (!LookupPortLocal (port)) 
-        {
-          return port;
-        }
-  } while (port != m_ephemeral);
-  return 0;
-}
-
-} //namespace ns3
-
--- a/src/node/ipv4-end-point-demux.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#ifndef IPV4_END_POINT_DEMUX_H
-#define IPV4_END_POINT_DEMUX_H
-
-#include <stdint.h>
-#include <list>
-#include "ipv4-address.h"
-
-namespace ns3 {
-
-class Ipv4EndPoint;
-
-class Ipv4EndPointDemux {
-public:
-  Ipv4EndPointDemux ();
-  ~Ipv4EndPointDemux ();
-
-  bool LookupPortLocal (uint16_t port);
-  bool LookupLocal (Ipv4Address addr, uint16_t port);
-  Ipv4EndPoint *Lookup (Ipv4Address daddr, 
-                        uint16_t dport, 
-                        Ipv4Address saddr, 
-                        uint16_t sport);
-
-  Ipv4EndPoint *Allocate (void);
-  Ipv4EndPoint *Allocate (Ipv4Address address);
-  Ipv4EndPoint *Allocate (uint16_t port);
-  Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port);
-  Ipv4EndPoint *Allocate (Ipv4Address localAddress, 
-                          uint16_t localPort,
-                          Ipv4Address peerAddress, 
-                          uint16_t peerPort);
-
-  void DeAllocate (Ipv4EndPoint *endPoint);
-
- private:
-  uint16_t AllocateEphemeralPort (void);
-  typedef std::list<Ipv4EndPoint *> EndPoints;
-  typedef std::list<Ipv4EndPoint *>::iterator EndPointsI;
-
-  uint16_t m_ephemeral;
-  EndPoints m_endPoints;
-};
-
-} // namespace ns3
-
-#endif /* IPV4_END_POINTS_H */
--- a/src/node/ipv4-end-point.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#include "ipv4-end-point.h"
-
-namespace ns3 {
-
-Ipv4EndPoint::Ipv4EndPoint (Ipv4Address address, uint16_t port)
-  : m_localAddr (address), 
-    m_localPort (port),
-    m_peerAddr (Ipv4Address::GetAny ()),
-    m_peerPort (0)
-{}
-Ipv4EndPoint::~Ipv4EndPoint ()
-{
-  if (!m_destroyCallback.IsNull ())
-    {
-      m_destroyCallback ();
-    }
-}
-
-Ipv4Address 
-Ipv4EndPoint::GetLocalAddress (void)
-{
-  return m_localAddr;
-}
-uint16_t 
-Ipv4EndPoint::GetLocalPort (void)
-{
-  return m_localPort;
-}
-Ipv4Address 
-Ipv4EndPoint::GetPeerAddress (void)
-{
-  return m_peerAddr;
-}
-uint16_t 
-Ipv4EndPoint::GetPeerPort (void)
-{
-  return m_peerPort;
-}
-void 
-Ipv4EndPoint::SetPeer (Ipv4Address address, uint16_t port)
-{
-  m_peerAddr = address;
-  m_peerPort = port;
-}
-
-void 
-Ipv4EndPoint::SetRxCallback (Callback<void,const Packet &, Ipv4Address, uint16_t> callback)
-{
-  m_rxCallback = callback;
-}
-
-void 
-Ipv4EndPoint::SetDestroyCallback (Callback<void> callback)
-{
-  m_destroyCallback = callback;
-}
-
-void 
-Ipv4EndPoint::ForwardUp (const Packet &p, Ipv4Address saddr, uint16_t sport)
-{
-  if (!m_rxCallback.IsNull ())
-  {
-    m_rxCallback (p, saddr, sport);
-  }
-}
-
-
-
-}; // namespace ns3
--- a/src/node/ipv4-end-point.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#ifndef IPV4_END_POINT_H
-#define IPV4_END_POINT_H
-
-#include <stdint.h>
-#include "ipv4-address.h"
-#include "ns3/callback.h"
-
-namespace ns3 {
-
-class Header;
-class Packet;
-
-class Ipv4EndPoint {
-public:
-  Ipv4EndPoint (Ipv4Address address, uint16_t port);
-  ~Ipv4EndPoint ();
-
-  Ipv4Address GetLocalAddress (void);
-  uint16_t GetLocalPort (void);
-  Ipv4Address GetPeerAddress (void);
-  uint16_t GetPeerPort (void);
-
-  void SetPeer (Ipv4Address address, uint16_t port);
-
-  void SetRxCallback (Callback<void,const Packet &, Ipv4Address, uint16_t> callback);
-  void SetDestroyCallback (Callback<void> callback);
-
-  void ForwardUp (const Packet &p, Ipv4Address saddr, uint16_t sport);
-
-private:
-  Ipv4Address m_localAddr;
-  uint16_t m_localPort;
-  Ipv4Address m_peerAddr;
-  uint16_t m_peerPort;
-  Callback<void,const Packet &, Ipv4Address, uint16_t> m_rxCallback;
-  Callback<void> m_destroyCallback;
-};
-
-}; // namespace ns3
-
-
-#endif /* IPV4_END_POINT_H */
--- a/src/node/ipv4-header.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,308 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#include "ns3/assert.h"
-#include "ns3/debug.h"
-#include "ns3/header.h"
-#include "ipv4-header.h"
-
-NS_DEBUG_COMPONENT_DEFINE ("Ipv4Header");
-
-namespace ns3 {
-
-static uint16_t 
-UtilsNtoh16 (uint16_t v)
-{
-  uint16_t val;
-  uint8_t *array;
-  array = (uint8_t *)&v;
-  val = (array[0] << 8) | (array[1] << 0);
-  return val;
-}
-
-
-bool Ipv4Header::m_calcChecksum = false;
-
-Ipv4Header::Ipv4Header ()
-  : m_payloadSize (0),
-    m_identification (0),
-    m_tos (0),
-    m_ttl (0),
-    m_protocol (0),
-    m_flags (0),
-    m_fragmentOffset (0),
-    m_goodChecksum (true)
-{}
-Ipv4Header::~Ipv4Header ()
-{}
-
-void 
-Ipv4Header::EnableChecksums (void)
-{
-  m_calcChecksum = true;
-}
-
-void 
-Ipv4Header::SetPayloadSize (uint16_t size)
-{
-  m_payloadSize = size;
-}
-uint16_t 
-Ipv4Header::GetPayloadSize (void) const
-{
-  return m_payloadSize;
-}
-
-uint16_t 
-Ipv4Header::GetIdentification (void) const
-{
-  return m_identification;
-}
-void 
-Ipv4Header::SetIdentification (uint16_t identification)
-{
-  m_identification = identification;
-}
-
-
-
-void 
-Ipv4Header::SetTos (uint8_t tos)
-{
-  m_tos = tos;
-}
-uint8_t 
-Ipv4Header::GetTos (void) const
-{
-  return m_tos;
-}
-void 
-Ipv4Header::SetMoreFragments (void)
-{
-  m_flags |= MORE_FRAGMENTS;
-}
-void
-Ipv4Header::SetLastFragment (void)
-{
-  m_flags &= ~MORE_FRAGMENTS;
-}
-bool 
-Ipv4Header::IsLastFragment (void) const
-{
-  return !(m_flags & MORE_FRAGMENTS);
-}
-
-void 
-Ipv4Header::SetDontFragment (void)
-{
-  m_flags |= DONT_FRAGMENT;
-}
-void 
-Ipv4Header::SetMayFragment (void)
-{
-  m_flags &= ~DONT_FRAGMENT;
-}
-bool 
-Ipv4Header::IsDontFragment (void) const
-{
-  return (m_flags & DONT_FRAGMENT);
-}
-
-void 
-Ipv4Header::SetFragmentOffset (uint16_t offset)
-{
-  NS_ASSERT (!(offset & (~0x3fff)));
-  m_fragmentOffset = offset;
-}
-uint16_t 
-Ipv4Header::GetFragmentOffset (void) const
-{
-  NS_ASSERT (!(m_fragmentOffset & (~0x3fff)));
-  return m_fragmentOffset;
-}
-
-void 
-Ipv4Header::SetTtl (uint8_t ttl)
-{
-  m_ttl = ttl;
-}
-uint8_t 
-Ipv4Header::GetTtl (void) const
-{
-  return m_ttl;
-}
-  
-uint8_t 
-Ipv4Header::GetProtocol (void) const
-{
-  return m_protocol;
-}
-void 
-Ipv4Header::SetProtocol (uint8_t protocol)
-{
-  m_protocol = protocol;
-}
-
-void 
-Ipv4Header::SetSource (Ipv4Address source)
-{
-  m_source = source;
-}
-Ipv4Address
-Ipv4Header::GetSource (void) const
-{
-  return m_source;
-}
-
-void 
-Ipv4Header::SetDestination (Ipv4Address dst)
-{
-  m_destination = dst;
-}
-Ipv4Address
-Ipv4Header::GetDestination (void) const
-{
-  return m_destination;
-}
-
-
-bool
-Ipv4Header::IsChecksumOk (void) const
-{
-  return m_goodChecksum;
-}
-
-void 
-Ipv4Header::PrintTo (std::ostream &os) const
-{
-  // ipv4, right ?
-  os << "(ipv4)"
-     << " tos=" << (uint32_t)m_tos
-     << ", payload length=" << UtilsNtoh16 (m_payloadSize)
-     << ", id=" << m_identification
-     << ", " << (IsLastFragment ()?"last":"more")
-     << ", " << (IsDontFragment ()?"dont":"may")
-     << ", frag offset=" << m_fragmentOffset
-     << ", ttl=" << m_ttl
-     << ", protocol=" << m_protocol
-     << ", source=" << m_source
-     << ", destination=" << m_destination;
-}
-uint32_t 
-Ipv4Header::GetSerializedSize (void) const
-{
-  return 5 * 4;
-}
-
-void
-Ipv4Header::SerializeTo (Buffer::Iterator start) const
-{
-  Buffer::Iterator i = start;
-  
-  uint8_t verIhl = (4 << 4) | (5);
-  i.WriteU8 (verIhl);
-  i.WriteU8 (m_tos);
-  i.WriteHtonU16 (m_payloadSize + 5*4);
-  i.WriteHtonU16 (m_identification);
-  uint32_t fragmentOffset = m_fragmentOffset / 8;
-  uint8_t flagsFrag = (fragmentOffset >> 8) & 0x1f;
-  if (m_flags & DONT_FRAGMENT) 
-    {
-      flagsFrag |= (1<<6);
-    }
-  if (m_flags & MORE_FRAGMENTS) 
-    {
-      flagsFrag |= (1<<5);
-    }
-  i.WriteU8 (flagsFrag);
-  uint8_t frag = fragmentOffset & 0xff;
-  i.WriteU8 (frag);
-  i.WriteU8 (m_ttl);
-  i.WriteU8 (m_protocol);
-  i.WriteHtonU16 (0);
-  i.WriteHtonU32 (m_source.GetHostOrder ());
-  i.WriteHtonU32 (m_destination.GetHostOrder ());
-
-  if (m_calcChecksum) 
-    {
-#if 0
-      // XXX we need to add Buffer::Iterator::PeekData method
-      uint8_t *data = start.PeekData ();
-      uint16_t checksum = UtilsChecksumCalculate (0, data, GetSize ());
-      checksum = UtilsChecksumComplete (checksum);
-      NS_DEBUG ("checksum=" <<checksum);
-      i = start;
-      i.Next (10);
-      i.WriteU16 (checksum);
-#endif
-    }
-}
-uint32_t
-Ipv4Header::DeserializeFrom (Buffer::Iterator start)
-{
-  Buffer::Iterator i = start;
-  uint8_t verIhl = i.ReadU8 ();
-  uint8_t ihl = verIhl & 0x0f; 
-  uint16_t headerSize = ihl * 4;
-  NS_ASSERT ((verIhl >> 4) == 4);
-  m_tos = i.ReadU8 ();
-  uint16_t size = i.ReadNtohU16 ();
-  m_payloadSize = size - headerSize;
-  m_identification = i.ReadNtohU16 ();
-  uint8_t flags = i.ReadU8 ();
-  m_flags = 0;
-  if (flags & (1<<6)) 
-    {
-      m_flags |= DONT_FRAGMENT;
-    }
-  if (flags & (1<<5)) 
-    {
-      m_flags |= MORE_FRAGMENTS;
-    }
-  //XXXX I think we should clear some bits in fragmentOffset !
-  i.Prev ();
-  m_fragmentOffset = i.ReadNtohU16 ();
-  m_fragmentOffset *= 8;
-  m_ttl = i.ReadU8 ();
-  m_protocol = i.ReadU8 ();
-  i.Next (2); // checksum
-  m_source.SetHostOrder (i.ReadNtohU32 ());
-  m_destination.SetHostOrder (i.ReadNtohU32 ());
-
-  if (m_calcChecksum) 
-    {
-#if 0
-      uint8_t *data = start.PeekData ();
-      uint16_t localChecksum = UtilsChecksumCalculate (0, data, headerSize);
-      if (localChecksum == 0xffff) 
-        {
-          m_goodChecksum = true;
-        } 
-      else 
-        {
-          m_goodChecksum = false;
-        }
-#endif
-    }
-  return GetSerializedSize ();
-}
-
-}; // namespace ns3
--- a/src/node/ipv4-header.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,92 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#ifndef IPV4_HEADER_H
-#define IPV4_HEADER_H
-
-#include "ns3/header.h"
-#include "ipv4-address.h"
-
-namespace ns3 {
-
-class Ipv4Header : public Header {
-public:
-  Ipv4Header ();
-  virtual ~Ipv4Header ();
-
-  static void EnableChecksums (void);
-
-  void SetPayloadSize (uint16_t size);
-  void SetIdentification (uint16_t identification);
-  void SetTos (uint8_t);
-  void SetMoreFragments (void);
-  void SetLastFragment (void);
-  void SetDontFragment (void);
-  void SetMayFragment (void);
-  void SetFragmentOffset (uint16_t offset);
-  void SetTtl (uint8_t);
-  void SetProtocol (uint8_t);
-  void SetSource (Ipv4Address source);
-  void SetDestination (Ipv4Address destination);
-
-
-  uint16_t GetPayloadSize (void) const;
-  uint16_t GetIdentification (void) const;
-  uint8_t GetTos (void) const;
-  bool IsLastFragment (void) const;
-  bool IsDontFragment (void) const;
-  uint16_t GetFragmentOffset (void) const;
-  uint8_t GetTtl (void) const;
-  uint8_t GetProtocol (void) const;
-  Ipv4Address GetSource (void) const;
-  Ipv4Address GetDestination (void) const;
-  
-  bool IsChecksumOk (void) const;
-
-private:
-  virtual void PrintTo (std::ostream &os) const;
-  virtual uint32_t GetSerializedSize (void) const;
-  virtual void SerializeTo (Buffer::Iterator start) const;
-  virtual uint32_t DeserializeFrom (Buffer::Iterator start);
-
-  enum FlagsE {
-    DONT_FRAGMENT = (1<<0),
-    MORE_FRAGMENTS = (1<<1)
-  };
-
-  static bool m_calcChecksum;
-
-  uint16_t m_payloadSize;
-  uint16_t m_identification;
-  uint32_t m_tos : 8;
-  uint32_t m_ttl : 8;
-  uint32_t m_protocol : 8;
-  uint32_t m_flags : 3;
-  uint16_t m_fragmentOffset : 13;
-  Ipv4Address m_source;
-  Ipv4Address m_destination;
-  bool m_goodChecksum;
-};
-
-}; // namespace ns3
-
-
-#endif /* IPV4_HEADER_H */
--- a/src/node/ipv4-interface.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,144 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005,2006,2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#include "ipv4-interface.h"
-#include "ipv4-address.h"
-#include "net-device.h"
-
-namespace ns3 {
-
-  /**
-   * By default, Ipv4 interface are created in the "down" state
-   * with ip address 192.168.0.1 and a matching mask. Before
-   * becoming useable, the user must invoke SetUp on them
-   * once the final Ipv4 address and mask has been set.
-   */
-Ipv4Interface::Ipv4Interface (NetDevice *nd) 
-  : m_netdevice (nd), 
-    m_ifup(false)
-{
-  if (m_netdevice != 0)
-    {
-      m_netdevice->Ref ();
-    }
-}
-
-Ipv4Interface::~Ipv4Interface ()
-{
-  if (m_netdevice != 0)
-    {
-      m_netdevice->Unref ();
-    }
-}
-
-NetDevice*
-Ipv4Interface::PeekDevice (void) const
-{
-  return m_netdevice;
-}
-
-TraceResolver *
-Ipv4Interface::CreateTraceResolver (TraceContext const &context)
-{
-  return DoCreateTraceResolver (context);
-}
-
-void 
-Ipv4Interface::SetAddress (Ipv4Address a)
-{
-  m_address = a;
-}
-void 
-Ipv4Interface::SetNetworkMask (Ipv4Mask mask)
-{
-  m_netmask = mask;
-}
-
-Ipv4Address
-Ipv4Interface::GetBroadcast (void) const
-{
-  uint32_t mask = m_netmask.GetHostOrder ();
-  uint32_t address = m_address.GetHostOrder ();
-  Ipv4Address broadcast = Ipv4Address (address | (~mask));
-  return broadcast;
-}
-Ipv4Mask 
-Ipv4Interface::GetNetworkMask (void) const
-{
-  return m_netmask;
-}
-Ipv4Address 
-Ipv4Interface::GetAddress (void) const
-{
-  return m_address;
-}
-
-uint16_t 
-Ipv4Interface::GetMtu (void) const
-{
-  if (m_netdevice == 0)
-    {
-      uint32_t mtu = (1<<16) - 1;
-      return mtu;
-    }
-  return m_netdevice->GetMtu ();
-}
-
-  /**
-   * These are IP interface states and may be distinct from 
-   * NetDevice states, such as found in real implementations
-   * (where the device may be down but IP interface state is still up).
-   */
-bool 
-Ipv4Interface::IsUp (void) const
-{
-  return m_ifup;
-}
-
-bool 
-Ipv4Interface::IsDown (void) const
-{
-  return !m_ifup;
-}
-
-void 
-Ipv4Interface::SetUp (void)
-{
-  m_ifup = true;
-}
-
-void 
-Ipv4Interface::SetDown (void)
-{
-  m_ifup = false;
-}
-
-// public wrapper on private virtual function
-void 
-Ipv4Interface::Send(Packet p, Ipv4Address dest)
-{
-  if (IsUp()) {
-    SendTo(p, dest);
-  }
-}
-
-}; // namespace ns3
-
--- a/src/node/ipv4-interface.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,164 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005,2006,2007 INRIA
- * 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
- *
- * Authors: 
- *  Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
- *  Tom Henderson <tomh@tomh.org>
- */
-#ifndef IPV4_INTERFACE_H
-#define IPV4_INTERFACE_H
-
-#include <list>
-#include "ipv4-address.h"
-
-namespace ns3 {
-
-class NetDevice;
-class Packet;
-class TraceResolver;
-class TraceContext;
-
-/**
- * \brief The IPv4 representation of a network interface
- *
- * This class roughly corresponds to the struct in_device
- * of Linux; the main purpose is to provide address-family
- * specific information (addresses) about an interface.
- *
- * This class defines two APIs:
- *  - the public API which is expected to be used by both 
- *    the IPv4 layer and the user during forwarding and 
- *    configuration.
- *  - the private API which is expected to be implemented
- *    by subclasses of this base class. One such subclass 
- *    will be a Loopback interface which loops every
- *    packet sent back to the ipv4 layer. Another such 
- *    subclass typically contains the Ipv4 <-> MAC address
- *    translation logic which will use most of the time the
- *    ARP/RARP protocols.
- *
- * By default, Ipv4 interface are created in the "down" state
- * with ip address 192.168.0.1 and a matching mask. Before
- * becoming useable, the user must invoke SetUp on them
- * once the final Ipv4 address and mask has been set.
- *
- * Subclasses must implement the two methods:
- *   - Ipv4Interface::SendTo
- *   - Ipv4Interface::DoCreateTraceResolver
- */
-class Ipv4Interface 
-{
-public:
-  /**
-   * \param nd the NetDevice associated to this Ipv4Interface.
-   *           This value can be zero in which case the MTU
-   *           of this interface will be 2^(16-1).
-   */
-  Ipv4Interface (NetDevice *nd);
-  virtual ~Ipv4Interface();
-
-  /**
-   * \param context the trace context to use to construct the
-   *        TraceResolver to return
-   * \returns a TraceResolver which can resolve all traces
-   *          performed in this object. The caller must
-   *          delete the returned object.
-   *
-   * This method will delegate the work to the private DoCreateTraceResolver 
-   * method which is supposed to be implemented by subclasses.
-   */
-  TraceResolver *CreateTraceResolver (TraceContext const &context);
-  /**
-   * \returns the underlying NetDevice. This method can return
-   *          zero if this interface has no associated NetDevice.
-   */
-  NetDevice *PeekDevice (void) const;
-
-  /**
-   * \param a set the ipv4 address of this interface.
-   */
-  void SetAddress (Ipv4Address a);
-  /**
-   * \param mask set the ipv4 netmask of this interface.
-   */
-  void SetNetworkMask (Ipv4Mask mask);
-
-  /**
-   * \returns the broadcast ipv4 address associated to this interface
-   */
-  Ipv4Address GetBroadcast (void) const;
-  /**
-   * \returns the ipv4 netmask of this interface
-   */
-  Ipv4Mask GetNetworkMask (void) const;
-  /**
-   * \returns the ipv4 address of this interface
-   */
-  Ipv4Address GetAddress (void) const;
-
-  /**
-   * This function a pass-through to NetDevice GetMtu, modulo
-   * the  LLC/SNAP header i.e., ipv4MTU = NetDeviceMtu - LLCSNAPSIZE
-   * \returns the Maximum Transmission Unit associated to this interface.
-   */
-  uint16_t GetMtu (void) const;
-
-  /**
-   * These are IP interface states and may be distinct from 
-   * NetDevice states, such as found in real implementations
-   * (where the device may be down but IP interface state is still up).
-   */
-  /**
-   * \returns true if this interface is enabled, false otherwise.
-   */
-  bool IsUp (void) const;
-  /**
-   * \returns true if this interface is disabled, false otherwise.
-   */
-  bool IsDown (void) const;
-  /**
-   * Enable this interface
-   */
-  void SetUp (void);
-  /**
-   * Disable this interface
-   */
-  void SetDown (void);
-
-  /**
-   * \param p packet to send
-   * \param dest next hop address of packet.
-   *
-   * This method will eventually call the private
-   * SendTo method which must be implemented by subclasses.
-   */ 
-  void Send(Packet p, Ipv4Address dest);
-
-
- private:
-  virtual void SendTo (Packet p, Ipv4Address dest) = 0;
-  virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0;
-  NetDevice* m_netdevice;
-  bool m_ifup;
-  Ipv4Address m_address;
-  Ipv4Mask m_netmask;
-};
-
-}; // namespace ns3
-
-#endif
--- a/src/node/ipv4-l4-demux.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,106 +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>
-//
-
-// Define the layer 4 demultiplexer object for ns3.
-// George F. Riley, Georgia Tech, Fall 2006
-
-#include <sstream>
-#include "ns3/composite-trace-resolver.h"
-#include "ns3/iid-manager.h"
-#include "ipv4-l4-demux.h"
-#include "ipv4-l4-protocol.h"
-#include "node.h"
-
-namespace ns3 {
-
-const uint32_t Ipv4L4Demux::iid = IidManager::Allocate ("Ipv4L4Demux");
-
-Ipv4L4Demux::Ipv4L4Demux (Node *node)
-  : NsUnknown (Ipv4L4Demux::iid),
-    m_node (node)
-{
-  m_node->Ref ();
-}
-
-Ipv4L4Demux::~Ipv4L4Demux()
-{}
-
-void
-Ipv4L4Demux::DoDispose (void)
-{
-  for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
-    {
-      (*i)->Dispose ();
-      (*i)->Unref ();
-    }
-  m_protocols.clear ();
-  if (m_node != 0)
-    {
-      m_node->Unref ();
-      m_node = 0;
-    }
-  NsUnknown::DoDispose ();
-}
-
-TraceResolver *
-Ipv4L4Demux::CreateTraceResolver (TraceContext const &context)
-{
-  CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
-  for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
-    {
-      Ipv4L4Protocol *protocol = *i;
-      std::string protValue;
-      std::ostringstream oss (protValue);
-      oss << (*i)->GetProtocolNumber ();
-      Ipv4L4ProtocolTraceType protocolNumber = (*i)->GetProtocolNumber ();
-      resolver->Add (protValue,
-                     MakeCallback (&Ipv4L4Protocol::CreateTraceResolver, protocol),
-                     protocolNumber);
-    }
-  return resolver;
-}
-void
-Ipv4L4Demux::Insert(Ipv4L4Protocol *protocol)
-{
-  protocol->Ref ();
-  m_protocols.push_back (protocol);
-}
-Ipv4L4Protocol* 
-Ipv4L4Demux::PeekProtocol(int protocolNumber)
-{
-  for (L4List_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
-    {
-      if ((*i)->GetProtocolNumber () == protocolNumber)
-	{
-	  return *i;
-	}
-    }
-  return 0;
-}
-void
-Ipv4L4Demux::Erase(Ipv4L4Protocol*protocol)
-{
-  m_protocols.remove (protocol);
-}
-
-
-
-}//namespace ns3
--- a/src/node/ipv4-l4-demux.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,93 +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>
-//
-
-// Define the layer 4 demultiplexer object for ns3.
-// George F. Riley, Georgia Tech, Fall 2006
-
-#ifndef IPV4_L4_DEMUX_H
-#define IPV4_L4_DEMUX_H
-
-#include <list>
-#include "ns3/ns-unknown.h"
-
-namespace ns3 {
-
-class Ipv4L4Protocol;
-class Node;
-class TraceResolver;
-class TraceContext;
-
-/**
- * \brief L4 Ipv4 Demux
- */
-class Ipv4L4Demux : public NsUnknown
-{
-public:
-  static const uint32_t iid;
-  typedef int Ipv4L4ProtocolTraceType;
-  Ipv4L4Demux (Node *node);
-  virtual ~Ipv4L4Demux();
-
-  /**
-   * \param context the trace context to use to construct the
-   *        TraceResolver to return
-   * \returns a TraceResolver which can resolve all traces
-   *          performed in this object. The caller must
-   *          delete the returned object.
-   */
-  TraceResolver *CreateTraceResolver (TraceContext const &context);
-  /**
-   * \param protocol a template for the protocol to add to this L4 Demux.
-   * \returns the L4Protocol effectively added.
-   *
-   * Invoke Copy on the input template to get a copy of the input
-   * protocol which can be used on the Node on which this L4 Demux 
-   * is running. The new L4Protocol is registered internally as
-   * a working L4 Protocol and returned from this method.
-   * The caller does not get ownership of the returned pointer.
-   */
-  void Insert(Ipv4L4Protocol *protocol);
-  /**
-   * \param protocolNumber number of protocol to lookup
-   *        in this L4 Demux
-   * \returns a matching L4 Protocol
-   *
-   * This method is typically called by lower layers
-   * to forward packets up the stack to the right protocol.
-   * It is also called from InternetNode::GetUdp for example.
-   */
-  Ipv4L4Protocol* PeekProtocol(int protocolNumber);
-  /**
-   * \param protocol protocol to remove from this demux.
-   *
-   * The input value to this method should be the value
-   * returned from the Ipv4L4Protocol::Insert method.
-   */
-  void Erase(Ipv4L4Protocol*protocol);
-private:
-  virtual void DoDispose (void);
-  typedef std::list<Ipv4L4Protocol*> L4List_t;
-  L4List_t m_protocols;
-  Node *m_node;
-};
-
-} //namespace ns3
-#endif
--- a/src/node/ipv4-l4-protocol.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +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>
-//
-
-// NS3 - Layer 4 Protocol base class
-// George F. Riley, Georgia Tech, Spring 2007
-
-#include "ipv4-l4-protocol.h"
-
-namespace ns3 {
-
-
-Ipv4L4Protocol::Ipv4L4Protocol(int protocolNumber, int version)
-  : m_protocolNumber (protocolNumber),
-    m_version (version)
-{}
-Ipv4L4Protocol::~Ipv4L4Protocol ()
-{}
-
-int 
-Ipv4L4Protocol::GetProtocolNumber (void) const
-{
-  return m_protocolNumber;
-}
-int 
-Ipv4L4Protocol::GetVersion() const
-{
-  return m_version;
-}
-
-void 
-Ipv4L4Protocol::DoDispose (void)
-{
-  Object::DoDispose ();
-}
-
-}//namespace ns3
--- a/src/node/ipv4-l4-protocol.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +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>
-//
-
-// NS3 - Layer 4 Protocol base class
-// George F. Riley, Georgia Tech, Spring 2007
-
-#ifndef IPV4_L4_PROTOCOL_H
-#define IPV4_L4_PROTOCOL_H
-
-#include "ns3/object.h"
-
-namespace ns3 {
-
-class Node;
-class Packet;
-class Ipv4Address;
-class TraceResolver;
-class TraceContext;
-
-/**
- * \brief L4 Protocol base class 
- *
- * All subclasses must implement:
- *   - Ipv4L4Protocol::Copy
- *   - Ipv4L4Protocol::CreateTraceResolver
- *
- * If you want to implement a new L4 protocol, all you have to do is
- * implement a subclass of this base class and add it to an L4Demux.
- */  
-class Ipv4L4Protocol : public Object
-{
-public:
-  Ipv4L4Protocol(int protocolNumber, int version);
-  virtual ~Ipv4L4Protocol ();
-
-  /**
-   * \returns the protocol number of this protocol.
-   */
-  int GetProtocolNumber (void) const;
-  /**
-   * \returns the version number of this protocol.
-   */
-  int GetVersion() const;
-
-  virtual TraceResolver *CreateTraceResolver (TraceContext const &context) = 0;
-
-  /**
-   * \param p packet to forward up
-   * \param source source address of packet received
-   * \param destination address of packet received
-   * 
-   * Called from lower-level layers to send the packet up
-   * in the stack. 
-   */
-  virtual void Receive(Packet& p, 
-                       Ipv4Address const &source,
-                       Ipv4Address const &destination) = 0;
-protected:
-  virtual void DoDispose (void);
-private:
-  int m_protocolNumber;
-  int m_version;
-};
-
-} // Namespace ns3
-
-#endif
--- a/src/node/ipv4-loopback-interface.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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
- *
- * Authors: 
- *  Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
- */
-#include "ns3/empty-trace-resolver.h"
-#include "ipv4-loopback-interface.h"
-#include "net-device.h"
-#include "node.h"
-#include "i-ipv4-private.h"
-
-namespace ns3 {
-
-Ipv4LoopbackInterface::Ipv4LoopbackInterface (Node *node)
-  : Ipv4Interface (0),
-    m_node (node)
-{
-  m_node->Ref ();
-}
-Ipv4LoopbackInterface::~Ipv4LoopbackInterface ()
-{
-  m_node->Unref ();
-}
-
-TraceResolver *
-Ipv4LoopbackInterface::DoCreateTraceResolver (TraceContext const &context)
-{
-  return new EmptyTraceResolver (context);
-}
-
-void 
-Ipv4LoopbackInterface::SendTo (Packet packet, Ipv4Address dest)
-{
-  IIpv4Private *ipv4 = m_node->QueryInterface<IIpv4Private> (IIpv4Private::iid);
-  ipv4->Receive (packet, PeekDevice ());
-  ipv4->Unref ();
-}
-
-}//namespace ns3
--- a/src/node/ipv4-loopback-interface.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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
- *
- * Authors: 
- *  Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
- */
-#ifndef IPV4_LOOPBACK_INTERFACE_H
-#define IPV4_LOOPBACK_INTERFACE_H
-
-#include "ipv4-interface.h"
-
-namespace ns3 {
-
-class Node;
-
-class Ipv4LoopbackInterface : public Ipv4Interface 
-{
- public:
-  Ipv4LoopbackInterface (Node *node);
-  virtual ~Ipv4LoopbackInterface ();
-
- private:
-  virtual void SendTo (Packet p, Ipv4Address dest);
-  virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context);
-
-  Node *m_node;
-};
-
-}//namespace ns3
-
-
-#endif /* IPV4_LOOPBACK_INTERFACE_H */
--- a/src/node/ipv4.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,571 +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>
-//
-
-#include "ns3/packet.h"
-#include "ns3/debug.h"
-#include "ns3/composite-trace-resolver.h"
-#include "ns3/array-trace-resolver.h"
-#include "ns3/callback.h"
-
-#include "ipv4.h"
-#include "ipv4-l4-protocol.h"
-#include "ipv4-address.h"
-#include "ipv4-header.h"
-#include "ipv4-interface.h"
-#include "ipv4-route.h"
-#include "ipv4-loopback-interface.h"
-#include "arp-ipv4-interface.h"
-// the two following headers are needed for Ipv4::ForwardUp
-#include "node.h"
-#include "ipv4-l4-demux.h"
-
-NS_DEBUG_COMPONENT_DEFINE ("Ipv4");
-
-namespace ns3 {
-
-const uint16_t Ipv4::PROT_NUMBER = 0x0800;
-
-Ipv4::Ipv4(Node *node)
-  : L3Protocol (PROT_NUMBER, 4),
-    m_nInterfaces (0),
-    m_defaultTtl (64),
-    m_identification (0),
-    m_defaultRoute (0),
-    m_node (node)
-{
-  SetupLoopback ();
-  m_node->Ref ();
-}
-Ipv4::~Ipv4 ()
-{
-  DoDispose ();
-}
-
-void 
-Ipv4::DoDispose (void)
-{
-  for (Ipv4InterfaceList::iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
-    {
-      delete (*i);
-    }
-  m_interfaces.clear ();
-  for (HostRoutesI i = m_hostRoutes.begin (); 
-       i != m_hostRoutes.end (); 
-       i = m_hostRoutes.erase (i)) 
-    {
-      delete (*i);
-    }
-  for (NetworkRoutesI j = m_networkRoutes.begin (); 
-       j != m_networkRoutes.end (); 
-       j = m_networkRoutes.erase (j)) 
-    {
-      delete (*j);
-    }
-  if (m_defaultRoute != 0)
-    {
-      delete m_defaultRoute;
-      m_defaultRoute = 0;
-    }
-  if (m_node != 0)
-    {
-      m_node->Unref ();
-      m_node = 0;
-    }
-  L3Protocol::DoDispose ();
-}
-
-void
-Ipv4::SetupLoopback (void)
-{
-  Ipv4LoopbackInterface * interface = new Ipv4LoopbackInterface (m_node);
-  interface->SetAddress (Ipv4Address::GetLoopback ());
-  interface->SetNetworkMask (Ipv4Mask::GetLoopback ());
-  uint32_t index = AddIpv4Interface (interface);
-  AddHostRouteTo (Ipv4Address::GetLoopback (), index);
-  interface->SetUp ();
-}
-
-TraceResolver *
-Ipv4::CreateTraceResolver (TraceContext const &context)
-{
-  CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
-  resolver->Add ("tx", m_txTrace, Ipv4::TX);
-  resolver->Add ("rx", m_rxTrace, Ipv4::RX);
-  resolver->Add ("drop", m_dropTrace, Ipv4::DROP);
-  resolver->Add ("interfaces", 
-                 MakeCallback (&Ipv4::InterfacesCreateTraceResolver, this), 
-                 Ipv4::INTERFACES);
-  return resolver;
-}
-
-TraceResolver *
-Ipv4::InterfacesCreateTraceResolver (TraceContext const &context) const
-{
-  ArrayTraceResolver<Ipv4Interface> *resolver = 
-    new ArrayTraceResolver<Ipv4Interface> 
-    (context,
-     MakeCallback (&Ipv4::GetNInterfaces, this),
-     MakeCallback (&Ipv4::GetInterface, this));
-  return resolver;
-}
-
-void 
-Ipv4::SetDefaultTtl (uint8_t ttl)
-{
-  m_defaultTtl = ttl;
-}
-    
-
-void 
-Ipv4::AddHostRouteTo (Ipv4Address dest, 
-                      Ipv4Address nextHop, 
-                      uint32_t interface)
-{
-  Ipv4Route *route = new Ipv4Route ();
-  *route = Ipv4Route::CreateHostRouteTo (dest, nextHop, interface);
-  m_hostRoutes.push_back (route);
-}
-void 
-Ipv4::AddHostRouteTo (Ipv4Address dest, 
-				uint32_t interface)
-{
-  Ipv4Route *route = new Ipv4Route ();
-  *route = Ipv4Route::CreateHostRouteTo (dest, interface);
-  m_hostRoutes.push_back (route);
-}
-void 
-Ipv4::AddNetworkRouteTo (Ipv4Address network, 
-				   Ipv4Mask networkMask, 
-				   Ipv4Address nextHop, 
-				   uint32_t interface)
-{
-  Ipv4Route *route = new Ipv4Route ();
-  *route = Ipv4Route::CreateNetworkRouteTo (network,
-                                            networkMask,
-                                            nextHop,
-                                            interface);
-  m_networkRoutes.push_back (route);
-}
-void 
-Ipv4::AddNetworkRouteTo (Ipv4Address network, 
-				   Ipv4Mask networkMask, 
-				   uint32_t interface)
-{
-  Ipv4Route *route = new Ipv4Route ();
-  *route = Ipv4Route::CreateNetworkRouteTo (network,
-                                            networkMask,
-                                            interface);
-  m_networkRoutes.push_back (route);
-}
-void 
-Ipv4::SetDefaultRoute (Ipv4Address nextHop, 
-				 uint32_t interface)
-{
-  Ipv4Route *route = new Ipv4Route ();
-  *route = Ipv4Route::CreateDefaultRoute (nextHop, interface);
-  delete m_defaultRoute;
-  m_defaultRoute = route;
-}
-
-Ipv4Route *
-Ipv4::Lookup (Ipv4Address dest)
-{
-  for (HostRoutesCI i = m_hostRoutes.begin (); 
-       i != m_hostRoutes.end (); 
-       i++) 
-    {
-      NS_ASSERT ((*i)->IsHost ());
-      if ((*i)->GetDest ().IsEqual (dest)) 
-        {
-          return (*i);
-        }
-    }
-  for (NetworkRoutesI j = m_networkRoutes.begin (); 
-       j != m_networkRoutes.end (); 
-       j++) 
-    {
-      NS_ASSERT ((*j)->IsNetwork ());
-      Ipv4Mask mask = (*j)->GetDestNetworkMask ();
-      Ipv4Address entry = (*j)->GetDestNetwork ();
-      if (mask.IsMatch (dest, entry)) 
-        {
-          return (*j);
-        }
-    }
-  if (m_defaultRoute != 0) 
-    {
-      NS_ASSERT (m_defaultRoute->IsDefault ());
-      return m_defaultRoute;
-    }
-  return 0;
-}
-
-uint32_t 
-Ipv4::GetNRoutes (void)
-{
-  uint32_t n = 0;
-  if (m_defaultRoute != 0)
-    {
-      n++;
-    }
-  n += m_hostRoutes.size ();
-  n += m_networkRoutes.size ();
-  return n;
-}
-Ipv4Route *
-Ipv4::GetRoute (uint32_t index)
-{
-  if (index == 0 && m_defaultRoute != 0)
-    {
-      return m_defaultRoute;
-    }
-  if (index > 0 && m_defaultRoute != 0)
-    {
-      index--;
-    }
-  if (index < m_hostRoutes.size ())
-    {
-      uint32_t tmp = 0;
-      for (HostRoutesCI i = m_hostRoutes.begin (); 
-           i != m_hostRoutes.end (); 
-           i++) 
-        {
-          if (tmp  == index)
-            {
-              return *i;
-            }
-          tmp++;
-        }
-    }
-  index -= m_hostRoutes.size ();
-  uint32_t tmp = 0;
-  for (NetworkRoutesI j = m_networkRoutes.begin (); 
-       j != m_networkRoutes.end (); 
-       j++) 
-    {
-      if (tmp == index)
-        {
-          return *j;
-        }
-      tmp++;
-    }
-  NS_ASSERT (false);
-  // quiet compiler.
-  return 0;
-}
-void 
-Ipv4::RemoveRoute (uint32_t index)
-{
-  if (index == 0 && m_defaultRoute != 0)
-    {
-      delete m_defaultRoute;
-      m_defaultRoute = 0;
-    }
-  if (index > 0 && m_defaultRoute != 0)
-    {
-      index--;
-    }
-  if (index < m_hostRoutes.size ())
-    {
-      uint32_t tmp = 0;
-      for (HostRoutesI i = m_hostRoutes.begin (); 
-           i != m_hostRoutes.end (); 
-           i++) 
-        {
-          if (tmp  == index)
-            {
-              delete *i;
-              m_hostRoutes.erase (i);
-              return;
-            }
-          tmp++;
-        }
-    }
-  index -= m_hostRoutes.size ();
-  uint32_t tmp = 0;
-  for (NetworkRoutesI j = m_networkRoutes.begin (); 
-       j != m_networkRoutes.end (); 
-       j++) 
-    {
-      if (tmp == index)
-        {
-          delete *j;
-          m_networkRoutes.erase (j);
-          return;
-        }
-      tmp++;
-    }
-  NS_ASSERT (false);
-}
-
-
-uint32_t 
-Ipv4::AddInterface (NetDevice *device)
-{
-  Ipv4Interface *interface = new ArpIpv4Interface (m_node, device);
-  return AddIpv4Interface (interface);
-}
-uint32_t 
-Ipv4::AddIpv4Interface (Ipv4Interface *interface)
-{
-  uint32_t index = m_nInterfaces;
-  m_interfaces.push_back (interface);
-  m_nInterfaces++;
-  return index;
-}
-Ipv4Interface *
-Ipv4::GetInterface (uint32_t index) const
-{
-  uint32_t tmp = 0;
-  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
-    {
-      if (index == tmp) 
-	{
-	  return *i;
-	}
-      tmp++;
-    }
-  return 0;
-}
-uint32_t 
-Ipv4::GetNInterfaces (void) const
-{
-  return m_nInterfaces;
-}
-
-Ipv4Interface *
-Ipv4::FindInterfaceForDevice (NetDevice const*device)
-{
-  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
-    {
-      if ((*i)->PeekDevice () == device)
-        {
-          return *i;
-        }
-    }
-  return 0;
-}  
-
-void 
-Ipv4::Receive(Packet& packet, NetDevice *device)
-{
-  uint32_t index = 0;
-  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
-    {
-      if ((*i)->PeekDevice () == device)
-        {
-          m_rxTrace (packet, index);
-          break;
-        }
-      index++;
-    }
-  Ipv4Header ipHeader;
-  packet.RemoveHeader (ipHeader);
-
-  if (!ipHeader.IsChecksumOk ()) 
-    {
-      return;
-    }
-
-  if (Forwarding (packet, ipHeader, device)) 
-    {
-      return;
-    }
-
-  ForwardUp (packet, ipHeader);
-}
-
-void 
-Ipv4::Send (Packet const &packet, 
-            Ipv4Address source, 
-            Ipv4Address destination,
-            uint8_t protocol)
-{
-  Ipv4Header ipHeader;
-
-  ipHeader.SetSource (source);
-  ipHeader.SetDestination (destination);
-  ipHeader.SetProtocol (protocol);
-  ipHeader.SetPayloadSize (packet.GetSize ());
-  ipHeader.SetTtl (m_defaultTtl);
-  ipHeader.SetMayFragment ();
-  ipHeader.SetIdentification (m_identification);
-
-  m_identification ++;
-
-  // XXX Note here that in most ipv4 stacks in the world,
-  // the route calculation for an outgoing packet is not
-  // done in the ip layer. It is done within the application
-  // socket when the first packet is sent to avoid this
-  // costly lookup on a per-packet basis.
-  // That would require us to get the route from the packet,
-  // most likely with a packet tag. The higher layers do not
-  // do this yet for us.
-  Ipv4Route *route = Lookup (ipHeader.GetDestination ());
-  if (route == 0) 
-    {
-      NS_DEBUG ("not for me -- forwarding but no route to host. drop.");
-      m_dropTrace (packet);
-      return;
-    }
-
-  SendRealOut (packet, ipHeader, *route);
-}
-
-void
-Ipv4::SendRealOut (Packet const &p, Ipv4Header const &ip, Ipv4Route const &route)
-{
-  Packet packet = p;
-  packet.AddHeader (ip);
-  Ipv4Interface *outInterface = GetInterface (route.GetInterface ());
-  NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ());
-  m_txTrace (packet, route.GetInterface ());
-  if (route.IsGateway ()) 
-    {
-      outInterface->Send (packet, route.GetGateway ());
-    } 
-  else 
-    {
-      outInterface->Send (packet, ip.GetDestination ());
-    }
-}
-
-
-bool
-Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device)
-{
-  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
-       i != m_interfaces.end (); i++) 
-    {
-      if ((*i)->GetAddress ().IsEqual (ipHeader.GetDestination ())) 
-        {
-          NS_DEBUG ("for me 1");
-          return false;
-        }
-    }
-  
-  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
-       i != m_interfaces.end (); i++) 
-    {
-      Ipv4Interface *interface = *i;
-      if (interface->PeekDevice () == device)
-	{
-	  if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ())) 
-	    {
-	      NS_DEBUG ("for me 2");
-	      return false;
-	    }
-	  break;
-	}
-    }
-      
-  if (ipHeader.GetDestination ().IsEqual (Ipv4Address::GetBroadcast ())) 
-    {
-      NS_DEBUG ("for me 3");
-      return false;
-    }
-  if (ipHeader.GetDestination ().IsEqual (Ipv4Address::GetAny ())) 
-    {
-      NS_DEBUG ("for me 4");
-      return false;
-    }
-  if (ipHeader.GetTtl () == 1) 
-    {
-      // Should send ttl expired here
-      // XXX
-      NS_DEBUG ("not for me -- ttl expired. drop.");
-      m_dropTrace (packet);
-      return true;
-    }
-  ipHeader.SetTtl (ipHeader.GetTtl () - 1);
-  Ipv4Route *route = Lookup (ipHeader.GetDestination ());
-  if (route == 0) 
-    {
-      NS_DEBUG ("not for me -- forwarding but no route to host. drop.");
-      m_dropTrace (packet);
-      return true;
-    }
-  NS_DEBUG ("not for me -- forwarding.");
-  SendRealOut (packet, ipHeader, *route);
-  return true;
-}
-
-
-void
-Ipv4::ForwardUp (Packet p, Ipv4Header const&ip)
-{
-  Ipv4L4Demux *demux = m_node->QueryInterface<Ipv4L4Demux> (Ipv4L4Demux::iid);
-  Ipv4L4Protocol *protocol = demux->PeekProtocol (ip.GetProtocol ());
-  demux->Unref ();
-  protocol->Receive (p, ip.GetSource (), ip.GetDestination ());
-}
-
-void 
-Ipv4::SetAddress (uint32_t i, Ipv4Address address)
-{
-  Ipv4Interface *interface = GetInterface (i);
-  interface->SetAddress (address);
-}
-void 
-Ipv4::SetNetworkMask (uint32_t i, Ipv4Mask mask)
-{
-  Ipv4Interface *interface = GetInterface (i);
-  interface->SetNetworkMask (mask);
-}
-Ipv4Mask 
-Ipv4::GetNetworkMask (uint32_t i) const
-{
-  Ipv4Interface *interface = GetInterface (i);
-  return interface->GetNetworkMask ();
-}
-Ipv4Address 
-Ipv4::GetAddress (uint32_t i) const
-{
-  Ipv4Interface *interface = GetInterface (i);
-  return interface->GetAddress ();
-}
-uint16_t 
-Ipv4::GetMtu (uint32_t i) const
-{
-  Ipv4Interface *interface = GetInterface (i);
-  return interface->GetMtu ();
-}
-bool 
-Ipv4::IsUp (uint32_t i) const
-{
-  Ipv4Interface *interface = GetInterface (i);
-  return interface->IsUp ();
-}
-void 
-Ipv4::SetUp (uint32_t i)
-{
-  Ipv4Interface *interface = GetInterface (i);
-  interface->SetUp ();
-}
-void 
-Ipv4::SetDown (uint32_t i)
-{
-  Ipv4Interface *interface = GetInterface (i);
-  interface->SetDown ();
-}
-
-
-}//namespace ns3
--- a/src/node/ipv4.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,251 +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>
-//
-
-#ifndef IPV4_H
-#define IPV4_H
-
-#include <list>
-#include <stdint.h>
-#include "ns3/callback-trace-source.h"
-#include "ns3/array-trace-resolver.h"
-#include "ipv4-address.h"
-#include "l3-protocol.h"
-
-namespace ns3 {
-
-class Packet;
-class NetDevice;
-class Ipv4Interface;
-class Ipv4Address;
-class Ipv4Header;
-class Ipv4Route;
-class Node;
-class TraceResolver;
-class TraceContext;
-
-
-/**
- * ::Send is always defined in subclasses.
- */
-class Ipv4 : public L3Protocol 
-{
-public:
-  static const uint16_t PROT_NUMBER;
-
-  enum TraceType {
-    TX,
-    RX,
-    DROP,
-    INTERFACES,
-  };
-  typedef ArrayTraceResolver<Ipv4Interface>::Index InterfaceIndex;
-
-  Ipv4(Node *node);
-  virtual ~Ipv4 ();
-
-  /**
-   * \param context the trace context to use to construct the
-   *        TraceResolver to return
-   * \returns a TraceResolver which can resolve all traces
-   *          performed in this object. The caller must
-   *          delete the returned object.
-   */
-  virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
-
-  /**
-   * \param ttl default ttl to use
-   *
-   * When we need to send an ipv4 packet, we use this default
-   * ttl value.
-   */
-  void SetDefaultTtl (uint8_t ttl);
-    
-  /**
-   * \param dest destination address
-   * \param nextHop address of next hop.
-   * \param interface interface of next hop.
-   *
-   * add route to host dest through host nextHop 
-   * on interface.
-   */
-  void AddHostRouteTo (Ipv4Address dest, 
-                       Ipv4Address nextHop, 
-                       uint32_t interface);
-  /**
-   * \param dest destination address
-   * \param interface of next hop
-   *
-   * add route to host dest on interface.
-   */
-  void AddHostRouteTo (Ipv4Address dest, 
-                       uint32_t interface);
-
-  /**
-   * \param network destination network
-   * \param networkMask netmask of destination network
-   * \param nextHop address of next hop
-   * \param interface interface of next hop
-   * 
-   * add route to network dest with netmask 
-   * through host nextHop on interface
-   */
-  void AddNetworkRouteTo (Ipv4Address network, 
-                          Ipv4Mask networkMask, 
-                          Ipv4Address nextHop, 
-                          uint32_t interface);
-
-  /**
-   * \param network destination network
-   * \param networkMask netmask of destination network
-   * \param interface interface of next hop
-   *
-   * add route to network dest with netmask 
-   * on interface
-   */
-  void AddNetworkRouteTo (Ipv4Address network, 
-                          Ipv4Mask networkMask, 
-                          uint32_t interface);
-  /**
-   * \param nextHop address of default next hop
-   * \param interface interface of default next hop.
-   * 
-   * set the default route to host nextHop on
-   * interface. 
-   */
-  void SetDefaultRoute (Ipv4Address nextHop, 
-                        uint32_t interface);
-
-  /**
-   * \param dest destination address
-   * \returns the route to the destination address
-   *
-   * Lookup the route for this destination address.
-   */
-  Ipv4Route *Lookup (Ipv4Address dest);
-
-  /**
-   * \returns the number of entries in the routing table.
-   */
-  uint32_t GetNRoutes (void);
-  /**
-   * \param i index of route to return
-   * \returns the route whose index is i
-   */
-  Ipv4Route *GetRoute (uint32_t i);
-  /**
-   * \param i index of route to remove from routing table.
-   */
-  void RemoveRoute (uint32_t i);
-  
-  /**
-   * \param interface interface to add to the list of ipv4 interfaces
-   * which can be used as output interfaces during packet forwarding.
-   * \returns the index of the interface added.
-   *
-   * Once an interface has been added, it can never be removed: if you want
-   * to disable it, you can invoke Ipv4Interface::SetDown which will
-   * make sure that it is never used during packet forwarding.
-   */
-  uint32_t AddInterface (NetDevice *device);
-  /**
-   * \param i index of interface to return
-   * \returns the requested interface
-   */
-  Ipv4Interface * GetInterface (uint32_t i) const;
-  /**
-   * \returns the number of interfaces added by the user.
-   */
-  uint32_t GetNInterfaces (void) const;
-  /**
-   * \param device the device to match
-   * \returns the matching interface, zero if not found.
-   *
-   * Try to find an Ipv4Interface whose NetDevice is equal to
-   * the input NetDevice.
-   */
-  Ipv4Interface *FindInterfaceForDevice (NetDevice const*device);
-  
-
-  /**
-   * Lower layer calls this method after calling L3Demux::Lookup
-   * The ARP subclass needs to know from which NetDevice this
-   * packet is coming to:
-   *    - implement a per-NetDevice ARP cache
-   *    - send back arp replies on the right device
-   */
-  virtual void Receive(Packet& p, NetDevice *device);
-
-  /**
-   * \param packet packet to send
-   * \param source source address of packet
-   * \param destination address of packet
-   * \param protocol number of packet
-   *
-   * Higher-level layers call this method to send a packet
-   * down the stack to the MAC and PHY layers.
-   */
-  void Send (Packet const &packet, Ipv4Address source, 
-	     Ipv4Address destination, uint8_t protocol);
-
-  void SetAddress (uint32_t i, Ipv4Address address);
-  void SetNetworkMask (uint32_t i, Ipv4Mask mask);
-  Ipv4Mask GetNetworkMask (uint32_t t) const;
-  Ipv4Address GetAddress (uint32_t i) const;
-  uint16_t GetMtu (uint32_t i) const;
-  bool IsUp (uint32_t i) const;
-  void SetUp (uint32_t i);
-  void SetDown (uint32_t i);
-
-
-protected:
-  virtual void DoDispose (void);
-private:
-  void SendRealOut (Packet const &packet, Ipv4Header const &ip, Ipv4Route const &route);
-  bool Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice *device);
-  void ForwardUp (Packet p, Ipv4Header const&ip);
-  uint32_t AddIpv4Interface (Ipv4Interface *interface);
-  void SetupLoopback (void);
-  TraceResolver *InterfacesCreateTraceResolver (TraceContext const &context) const;
-
-  typedef std::list<Ipv4Interface*> Ipv4InterfaceList;
-  typedef std::list<Ipv4Route *> HostRoutes;
-  typedef std::list<Ipv4Route *>::const_iterator HostRoutesCI;
-  typedef std::list<Ipv4Route *>::iterator HostRoutesI;
-  typedef std::list<Ipv4Route *> NetworkRoutes;
-  typedef std::list<Ipv4Route *>::const_iterator NetworkRoutesCI;
-  typedef std::list<Ipv4Route *>::iterator NetworkRoutesI;
-
-  Ipv4InterfaceList m_interfaces;
-  uint32_t m_nInterfaces;
-  uint8_t m_defaultTtl;
-  uint16_t m_identification;
-  HostRoutes m_hostRoutes;
-  NetworkRoutes m_networkRoutes;
-  Ipv4Route *m_defaultRoute;
-  Node *m_node;
-  CallbackTraceSource<Packet const &, uint32_t> m_txTrace;
-  CallbackTraceSource<Packet const &, uint32_t> m_rxTrace;
-  CallbackTraceSource<Packet const &> m_dropTrace;
-};
-
-} // Namespace ns3
-
-#endif
--- a/src/node/l3-demux.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,94 +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>
-//
-// Implement the L3Protocols capability for ns3.
-// George F. Riley, Georgia Tech, Fall 2006
-#include <sstream>
-#include <string>
-#include "ns3/composite-trace-resolver.h"
-#include "ns3/iid-manager.h"
-#include "l3-demux.h"
-#include "l3-protocol.h"
-#include "node.h"
-
-namespace ns3 {
-
-const uint32_t L3Demux::iid = IidManager::Allocate ("L3Demux");
-
-L3Demux::L3Demux (Node *node)
-  : NsUnknown (L3Demux::iid),
-    m_node (node)
-{
-  m_node->Ref ();
-}
-
-L3Demux::~L3Demux()
-{}
-
-void
-L3Demux::DoDispose (void)
-{
-  for (L3Map_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
-    {
-      i->second->Dispose ();
-      i->second->Unref ();
-    }
-  m_protocols.clear ();
-  if (m_node != 0)
-    {
-      m_node->Unref ();
-      m_node = 0;
-    }
-  NsUnknown::DoDispose ();
-}
-
-TraceResolver *
-L3Demux::CreateTraceResolver (TraceContext const &context) const
-{
-  CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
-  for (L3Map_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
-    {
-      std::string protValue;
-      std::ostringstream oss (protValue);
-      oss << i->second->GetProtocolNumber ();
-      ProtocolTraceType context = i->second->GetProtocolNumber ();
-      resolver->Add (protValue, 
-                     MakeCallback (&L3Protocol::CreateTraceResolver, i->second),
-                     context);
-    }
-  return resolver;
-}
-  
-void L3Demux::Insert(L3Protocol *p)
-{
-  p->Ref ();
-  m_protocols.insert(L3Map_t::value_type(p->GetProtocolNumber (), p));
-}
-
-L3Protocol* 
-L3Demux::PeekProtocol (int p)
-{ // Look up a protocol by protocol number
-  L3Map_t::iterator i = m_protocols.find(p);
-  if (i == m_protocols.end()) return 0;  // Not found
-  return i->second; // Return the protocol
-}
-
-} //namespace ns3  
-  
--- a/src/node/l3-demux.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,99 +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>
-//
-// Define the L3Protocols capability for ns3.
-// George F. Riley, Georgia Tech, Fall 2006
-
-// This object manages the different layer 3 protocols for any ns3
-// node that has this capability.  
-
-#ifndef L3_DEMUX_H
-#define L3_DEMUX_H
-
-#include <map>
-#include "ns3/ns-unknown.h"
-
-namespace ns3 {
-
-class L3Protocol;
-class Node;
-class TraceResolver;
-class TraceContext;
-
-/**
- * \brief L3 Demux 
- */
-class L3Demux : public NsUnknown
-{
-public:
-  static const uint32_t iid;
-  typedef int ProtocolTraceType;
-  L3Demux(Node *node);
-  virtual ~L3Demux();
-
-  /**
-   * \param context the trace context to use to construct the
-   *        TraceResolver to return
-   * \returns a TraceResolver which can resolve all traces
-   *          performed in this object. The caller must
-   *          delete the returned object.
-   */
-  TraceResolver *CreateTraceResolver (TraceContext const &context) const;
-
-
-  /**
-   * \param protocol a template for the protocol to add to this L3 Demux.
-   *
-   * Invoke Copy on the input template to get a copy of the input
-   * protocol which can be used on the Node on which this L3 Demux 
-   * is running. The new L3Protocol is registered internally as
-   * a working L3 Protocol and returned from this method.
-   * The caller does not get ownership of the returned pointer.
-   */
-  void Insert(ns3::L3Protocol * protocol);
-  /**
-   * \param protocolNumber number of protocol to lookup
-   *        in this L4 Demux
-   * \returns a matching L3 Protocol
-   *
-   * This method is typically called by lower layers
-   * to forward packets up the stack to the right protocol.
-   * It is also called from InternetNode::GetIpv4 for example.
-   */
-  ns3::L3Protocol* PeekProtocol (int protocolNumber);
-  /**
-   * \param protocol protocol to remove from this demux.
-   *
-   * The input value to this method should be the value
-   * returned from the L3Protocol::Insert method.
-   */
-  void Erase(ns3::L3Protocol*protocol);
-protected:
-  virtual void DoDispose (void);
-private:
-  typedef std::map<int, ns3::L3Protocol*> L3Map_t;
-
-  Node *m_node;
-  L3Map_t m_protocols;
-};
-
-} //namespace ns3
-#endif
-
--- a/src/node/l3-protocol.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +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>
-//
-
-// NS3 - Layer 3 Protocol base class
-// George F. Riley, Georgia Tech, Spring 2007
-
-#include "l3-protocol.h"
-
-
-namespace ns3 {
-
-L3Protocol::L3Protocol(int protocolNumber, int version)
-    : m_protocolNumber (protocolNumber),
-      m_version (version)
-{}
-L3Protocol::~L3Protocol ()
-{}
-
-int 
-L3Protocol::GetProtocolNumber (void) const
-{
-  return m_protocolNumber;
-}
-int 
-L3Protocol::GetVersion() const
-{
-  return m_version;
-}
-
-void
-L3Protocol::DoDispose (void)
-{
-  Object::DoDispose ();
-}
-
-}//namespace ns3
--- a/src/node/l3-protocol.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +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>
-//
-
-// NS3 - Layer 3 Protocol base class
-// George F. Riley, Georgia Tech, Spring 2007
-
-#ifndef L3_PROTOCOL_H
-#define L3_PROTOCOL_H
-
-#include "ns3/object.h"
-
-namespace ns3 {
-
-class Packet;
-class NetDevice;
-class Node;
-class TraceResolver;
-class TraceContext;
-
-/**
- * ::Send is always defined in subclasses.
- */
-class L3Protocol : public Object {
-public:
-  L3Protocol(int protocolNumber, int version);
-  virtual ~L3Protocol ();
-    
-  int GetProtocolNumber (void) const;
-  int GetVersion() const;
-
-  virtual TraceResolver *CreateTraceResolver (TraceContext const &context) = 0;
-  /**
-   * Lower layer calls this method after calling L3Demux::Lookup
-   * The ARP subclass needs to know from which NetDevice this
-   * packet is coming to:
-   *    - implement a per-NetDevice ARP cache
-   *    - send back arp replies on the right device
-   */
-  virtual void Receive(Packet& p, NetDevice *device) = 0;
-
-protected:
-  virtual void DoDispose (void);
-private:
-  int m_protocolNumber;
-  int m_version;
-};
-
-} // Namespace ns3
-
-#endif
--- a/src/node/onoff-application.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,277 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-//
-// Copyright (c) 2006 Georgia Tech Research Corporation
-//
-// 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>
-//
-
-// ns3 - On/Off Data Source Application class
-// George F. Riley, Georgia Tech, Spring 2007
-// Adapted from ApplicationOnOff in GTNetS.
-
-#include "ipv4-address.h"
-#include "node.h"
-#include "ns3/nstime.h"
-#include "ns3/data-rate.h"
-#include "onoff-application.h"
-#include "ns3/random-variable.h"
-#include "socket.h"
-#include "ns3/simulator.h"
-#include "i-udp.h"
-
-using namespace std;
-
-namespace ns3 {
-
-// Defaults for rate/size
-DataRate OnOffApplication::g_defaultRate = DataRate(500000);
-uint32_t OnOffApplication::g_defaultSize = 512;
-
-// Constructors
-
-  OnOffApplication::OnOffApplication(Node * n, 
-                                     const Ipv4Address  rip,   // Remote IP addr
-                                     uint16_t       rport, // Remote port
-                                     const  RandomVariable& ontime,
-                                     const  RandomVariable& offtime,
-                                     DataRate  rate,
-                                     uint32_t size)
-    :  Application(n), 
-      m_socket(0),      // Socket allocated on Start
-      m_peerIP(rip),
-      m_peerPort(rport),
-      m_connected(false),
-      m_onTime(ontime.Copy()),
-      m_offTime(offtime.Copy()),
-      m_cbrRate(rate),
-      m_pktSize(size), 
-      m_residualBits(0),
-      m_lastStartTime((HighPrecision)0),
-      m_maxBytes(0xffffffff),
-      m_totBytes(0),
-      m_startStopScheduled(false),
-      m_sendScheduled(false)
-{
-}
-
-OnOffApplication::OnOffApplication(Node * n, const OnOffApplication& c)
-  : Application(n), 
-    m_socket(0),
-    m_peerIP(c.m_peerIP),
-    m_peerPort(c.m_peerPort),
-    m_connected(c.m_connected),
-    m_onTime(c.m_onTime->Copy()),
-    m_offTime(c.m_offTime->Copy()),
-    m_cbrRate(c.m_cbrRate),
-    m_pktSize(c.m_pktSize),
-    m_residualBits(c.m_residualBits),
-    m_lastStartTime(c.m_lastStartTime),
-    m_maxBytes(c.m_maxBytes),
-    m_totBytes(c.m_totBytes),
-    m_startStopScheduled(false),
-    m_sendScheduled(false)
-{
-}
-
-OnOffApplication::~OnOffApplication()
-{}
-
-void
-OnOffApplication::DoDispose (void)
-{
-  if (m_socket != 0)
-    {
-      m_socket->Unref ();
-      m_socket = 0;
-    }
-  delete m_onTime;
-  delete m_offTime;
-
-  m_onTime = 0;
-  m_offTime = 0;
-
-  // chain up
-  Application::DoDispose ();
-}
-
-#ifdef REMOVE_THIS
-// Handler Methods
-void OnOffApplication::Handle(Event* e, Time_t t)
-{
-  AppOOEvent* ev = (AppOOEvent*)e;
-  switch (ev->event) {
-    case AppOOEvent::SEND_PKT :
-      {
-        SendPkt(false);         // Send the packet
-        return;
-      }
-    case AppOOEvent::START_GEN :
-      {
-        DEBUG0((cout << "StartGen at " << Simulator::Now() << endl));
-        lastStartTime = Simulator::Now();
-        ScheduleNextTx();
-        Time_t onInterval = onTime->Value();
-        pendingOO->event = AppOOEvent::STOP_GEN;
-         // Schedule the stop event
-        Simulator::Schedule(pendingOO, onInterval, this);
-        return;
-      }
-    case AppOOEvent::STOP_GEN :
-      {
-        DEBUG0((cout << "StopGen at " << Simulator::Now() << endl));
-        if (totBytes < maxBytes)
-          { // Only schedule if not execeeded maxBytes
-            Time_t offInterval = offTime->Value();
-            pendingOO->event = AppOOEvent::START_GEN;
-            // Schedule the start event
-            Simulator::Schedule(pendingOO, offInterval, this);
-          }
-        if (pendingEvent)
-          {
-            // Calculate residual bits since last packet sent
-            residualBits += (uint32_t)(cbrRate*(Simulator::Now()-lastStartTime));
-            Simulator::Cancel(pendingEvent);
-            delete pendingEvent;
-            pendingEvent = 0;
-          }
-        return;
-      }
-  }
-  Application::Handle(e, t);  // May be application event
-}
-#endif
-
-// Application Methods
-void OnOffApplication::StartApplication()    // Called at time specified by Start
-{
-  // Create the socket if not already
-  if (!m_socket)
-    { // Create the socket using the specified layer 4 protocol
-#ifdef NOTYET
-      m_socket = PeekNode()->GetKernel()->CreateGenericSocket(*m_l4Proto);
-      m_socket->Bind();  // Choose any available port local port
-      m_socket->Connect(*m_peerIP, m_peerPort,
-                        MakeCallback(&OnOffApplication::ConnectionSucceeded,
-                                     this),
-                        MakeCallback(&OnOffApplication::ConnectionFailed,
-                                     this));
-#endif
-      
-      IUdp *udp = PeekNode ()->QueryInterface<IUdp> (IUdp::iid);
-      m_socket = udp->CreateSocket ();
-      udp->Unref ();
-      m_socket->Connect (m_peerIP, m_peerPort);
-    }
-  StopApplication();                         // Insure no pending event
-  // If we are not yet connected, there is nothing to do here
-  // The ConnectionComplete upcall will start timers at that time
-  //if (!m_connected) return;
-  ScheduleStartEvent();
-}
-
-void OnOffApplication::StopApplication()     // Called at time specified by Stop
-{
-  if (m_startStopScheduled)
-    { // Cancel the startStop event
-      Simulator::Cancel(m_startStopEvent);
-      m_startStopScheduled = false;
-    }
-  if (m_sendScheduled)
-    { // Cancel the pending send packet event
-      Simulator::Cancel(m_sendEvent);
-      m_sendScheduled = false;
-      // Calculate residual bits since last packet sent
-      Time delta(Simulator::Now() - m_lastStartTime);
-      m_residualBits += (uint32_t)(m_cbrRate.GetBitRate() * delta.GetSeconds());
-    }
-}
-
-OnOffApplication* OnOffApplication::Copy() const
-{
-  return new OnOffApplication(*this);
-}
-
-// Event handlers
-void OnOffApplication::StartSending()
-{
-  m_startStopScheduled = true;
-  ScheduleNextTx();  // Schedule the send packet event
-}
-
-void OnOffApplication::StopSending()
-{
-  m_startStopScheduled = true;
-  if (m_sendScheduled) Simulator::Cancel(m_sendEvent);
-}
-
-// Private helpers
-void OnOffApplication::ScheduleNextTx()
-{
-  if (m_totBytes < m_maxBytes)
-    {
-      uint32_t bits = m_pktSize * 8 - m_residualBits;
-      Time nextTime(Seconds (bits / 
-        static_cast<double>(m_cbrRate.GetBitRate()))); // Time till next packet
-      m_sendScheduled = true;
-      m_sendEvent = Simulator::Schedule(nextTime, &OnOffApplication::SendPacket, this);
-    }
-  else
-    { // All done, cancel any pending events
-      StopApplication();
-    }
-}
-
-void OnOffApplication::ScheduleStartEvent()
-{  // Schedules the event to start sending data (switch to the "On" state)
-  Time offInterval = Seconds(m_offTime->GetValue());
-  m_startStopEvent = Simulator::Schedule(offInterval, &OnOffApplication::StartSending, this);
-  m_startStopScheduled = true;
-}
-
-void OnOffApplication::ScheduleStopEvent()
-{  // Schedules the event to stop sending data (switch to "Off" state)
-  Time onInterval = Seconds(m_onTime->GetValue());
-  Simulator::Schedule(onInterval, &OnOffApplication::StopSending, this);
-  m_startStopScheduled = true;
-}
-
-  
-void OnOffApplication::SendPacket()
-{
-  NS_ASSERT (m_sendScheduled);
-  m_sendScheduled = false;
-  m_socket->Send(0, m_pktSize);
-#ifdef NOTYET
-  m_socket->Send(0, m_pktSize); // Send the packet
-#endif
-  m_totBytes += m_pktSize;
-  m_lastStartTime = Simulator::Now();
-  m_residualBits = 0;
-  ScheduleNextTx();
-}
-
-void OnOffApplication::ConnectionSucceeded(Socket*)
-{
-  m_connected = true;
-  ScheduleStartEvent();
-}
-  
-void OnOffApplication::ConnectionFailed(Socket*)
-{
-  cout << "OnOffApplication, Connection Failed" << endl;
-}
-
-} // Namespace ns3
--- a/src/node/onoff-application.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,108 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-//
-// Copyright (c) 2006 Georgia Tech Research Corporation
-//
-// 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>
-//
-
-// ns3 - On/Off Data Source Application class
-// George F. Riley, Georgia Tech, Spring 2007
-// Adapted from ApplicationOnOff in GTNetS.
-
-// Define an on/off data source application class
-
-#ifndef __onoff_application_h__
-#define __onoff_application_h__
-
-#include "application.h"
-#include "ns3/event-id.h"
-
-namespace ns3 {
-
-class Ipv4Address;
-class RandomVariable;
-class Socket;
-class DataRate;
-
-class OnOffApplication : public Application {
-
-public:
-  OnOffApplication(Node * n,
-                   const Ipv4Address,  // Peer IP address
-                   uint16_t,           // Peer port
-                   const RandomVariable&,     // Random variable for On time
-                   const RandomVariable&,     // Random variable for Off time
-                   DataRate  = g_defaultRate,  // Data rate when on
-                   uint32_t = g_defaultSize);  // Size of packets
-
-  OnOffApplication(Node * n, const OnOffApplication&); // Copy constructor
-  virtual ~OnOffApplication();               // Destructor
-  virtual void StartApplication();    // Called at time specified by Start
-  virtual void StopApplication();     // Called at time specified by Stop
-  virtual OnOffApplication* Copy() const;// Make a copy of the application
-
-  // Event handlers
-  void StartSending();
-  void StopSending();
-  void SendPacket();
-
-  virtual void MaxBytes(uint32_t m) { m_maxBytes = m;}
-
-protected:
-  virtual void DoDispose (void);
-
-public: // Static methods
-  static void DefaultRate(uint64_t r) { g_defaultRate = r;}
-
-  static void DefaultSize(uint32_t s) { g_defaultSize = s;}
-
-public:
-  Socket        * m_socket;       // Associated socket
-  Ipv4Address     m_peerIP;       // Peer IP address
-  uint16_t        m_peerPort;     // Peer port
-  bool            m_connected;    // True if connected
-  RandomVariable* m_onTime;       // rng for On Time
-  RandomVariable* m_offTime;      // rng for Off Time
-  DataRate        m_cbrRate;      // Rate that data is generated
-  uint32_t        m_pktSize;      // Size of packets
-  uint32_t        m_residualBits; // Number of generated, but not sent, bits
-  Time            m_lastStartTime;// Time last packet sent
-  uint32_t        m_maxBytes;     // Limit total number of bytes sent
-  uint32_t        m_totBytes;     // Total bytes sent so far
-  bool            m_startStopScheduled; // True if start or stop event scheduled
-  EventId         m_startStopEvent;     // Event id for next start or stop event
-  bool            m_sendScheduled;// True of send event scheduled
-  EventId         m_sendEvent;    // Eventid of pending "send packet" event
-  bool            m_sending;      // True if currently in sending state
-  
-public:
-  static DataRate   g_defaultRate;  // Default sending rate when on
-  static uint32_t g_defaultSize;  // Default packet size
-
-private:
-  void ScheduleNextTx();
-  void ScheduleStartEvent();
-  void ScheduleStopEvent();
-  void ConnectionSucceeded(Socket*);
-  void ConnectionFailed(Socket*);
-  void Ignore(Socket*);
-protected:
-};
-
-} // namespace ns3
-
-#endif
-
--- a/src/node/pcap-trace.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,93 +0,0 @@
-/* -*-	Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#include "pcap-trace.h"
-
-#include <sstream>
-
-#include "ns3/trace-root.h"
-#include "ns3/trace-context.h"
-#include "ns3/callback.h"
-#include "ns3/pcap-writer.h"
-
-#include "ipv4.h"
-#include "node-list.h"
-#include "node.h"
-
-
-namespace ns3 {
-
-
-PcapTrace::PcapTrace (std::string filename)
-  : m_filename (filename)
-{}
-PcapTrace::~PcapTrace ()
-{
-  for (std::vector<Trace>::iterator i = m_traces.begin ();
-       i != m_traces.end (); i++)
-    {
-      delete i->writer;
-    }
-}
-
-void 
-PcapTrace::TraceAllIp (void)
-{
-  TraceRoot::Connect ("/nodes/*/ipv4/(tx|rx)",
-		      MakeCallback (&PcapTrace::LogIp, this));
-}
-
-PcapWriter *
-PcapTrace::GetStream (uint32_t nodeId, uint32_t interfaceId)
-{
-  for (std::vector<Trace>::iterator i = m_traces.begin ();
-       i != m_traces.end (); i++)
-    {
-      if (i->nodeId == nodeId &&
-	  i->interfaceId == interfaceId)
-	{
-	  return i->writer;
-	}
-    }
-  PcapTrace::Trace trace;
-  trace.nodeId = nodeId;
-  trace.interfaceId = interfaceId;
-  trace.writer = new PcapWriter ();
-  std::ostringstream oss;
-  oss << m_filename << "-" << nodeId << "-" << interfaceId;
-  std::string filename = oss.str ();
-  trace.writer->Open (filename);
-  trace.writer->WriteIpHeader ();
-  m_traces.push_back (trace);
-  return trace.writer;
-}
-
-void 
-PcapTrace::LogIp (TraceContext const &context, Packet const &p, uint32_t interfaceIndex)
-{
-  NodeList::NodeIndex nodeIndex;
-  context.Get (nodeIndex);
-  uint32_t nodeId = NodeList::PeekNode (nodeIndex)->GetId ();
-  PcapWriter *writer = GetStream (nodeId, interfaceIndex);
-  writer->WritePacket (p);
-}
-
-
-}//namespace ns3
--- a/src/node/pcap-trace.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/* -*-	Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#ifndef PCAP_TRACE_H
-#define PCAP_TRACE_H
-
-#include <string>
-#include <vector>
-
-namespace ns3 {
-
-class Packet;
-class TraceContext;
-class PcapWriter;
-
-class PcapTrace 
-{
-public:
-  PcapTrace (std::string filename);
-  ~PcapTrace ();
-
-  void TraceAllIp (void);
-private:
-  PcapWriter *GetStream (uint32_t nodeId, uint32_t interfaceId);
-  void LogIp (TraceContext const &context, Packet const &p, uint32_t interfaceIndex);
-  std::string m_filename;
-  struct Trace {
-    uint32_t nodeId;
-    uint32_t interfaceId;
-    PcapWriter *writer;
-  };
-  std::vector<Trace> m_traces;
-};
-
-}//namespace ns3
-
-#endif /* PCAP_TRACE_H */
--- a/src/node/sgi-hashmap.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-/* This code snippet was ripped out of the gcc 
- * documentation and slightly modified to work
- * with gcc 4.x
- */
-#ifndef SGI_HASHMAP_H
-#define SGI_HASHMAP_H
-
-/* To use gcc extensions.
- */
-#ifdef __GNUC__
-  #if __GNUC__ < 3
-     #include <hash_map.h>
-namespace sgi { using ::hash_map; }; // inherit globals
-  #else 
-     #if __GNUC__ < 4
-       #include <ext/hash_map>
-       #if __GNUC_MINOR__ == 0
-namespace sgi = std;         // GCC 3.0
-       #else
-namespace sgi = ::__gnu_cxx;       // GCC 3.1 and later
-       #endif
-     #else  // gcc 4.x and later
-       #include <ext/hash_map>
-       namespace sgi = ::__gnu_cxx;
-     #endif
-  #endif
-#else      // ...  there are other compilers, right?
-namespace sgi = std;
-#endif
-
-
-#endif /* SGI_HASHMAP_H */
--- a/src/node/udp-header.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,149 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#include "udp-header.h"
-#include "ipv4-checksum.h"
-
-namespace ns3 {
-
-bool UdpHeader::m_calcChecksum = false;
-
-/* The magic values below are used only for debugging.
- * They can be used to easily detect memory corruption
- * problems so you can see the patterns in memory.
- */
-UdpHeader::UdpHeader ()
-  : m_sourcePort (0xfffd),
-    m_destinationPort (0xfffd),
-    m_payloadSize (0xfffd),
-    m_initialChecksum (0)
-{}
-UdpHeader::~UdpHeader ()
-{
-  m_sourcePort = 0xfffe;
-  m_destinationPort = 0xfffe;
-  m_payloadSize = 0xfffe;
-}
-
-void 
-UdpHeader::EnableChecksums (void)
-{
-  m_calcChecksum = true;
-}
-
-void 
-UdpHeader::SetDestination (uint16_t port)
-{
-  m_destinationPort = port;
-}
-void 
-UdpHeader::SetSource (uint16_t port)
-{
-  m_sourcePort = port;
-}
-uint16_t 
-UdpHeader::GetSource (void) const
-{
-  return m_sourcePort;
-}
-uint16_t 
-UdpHeader::GetDestination (void) const
-{
-  return m_destinationPort;
-}
-void 
-UdpHeader::SetPayloadSize (uint16_t size)
-{
-  m_payloadSize = size;
-}
-void 
-UdpHeader::InitializeChecksum (Ipv4Address source, 
-                              Ipv4Address destination,
-                              uint8_t protocol)
-{
-  uint8_t buf[12];
-  source.Serialize (buf);
-  destination.Serialize (buf+4);
-  buf[8] = 0;
-  buf[9] = protocol;
-  uint16_t udpLength = m_payloadSize + GetSize ();
-  buf[10] = udpLength >> 8;
-  buf[11] = udpLength & 0xff;
-
-  m_initialChecksum = Ipv4ChecksumCalculate (0, buf, 12);
-}
-
-
-
-void 
-UdpHeader::PrintTo (std::ostream &os) const
-{
-  os << "(udp)"
-     << ", port source=" << m_sourcePort
-     << ", port destination=" << m_destinationPort
-     << ", length=" << m_payloadSize;
-}
-
-uint32_t 
-UdpHeader::GetSerializedSize (void) const
-{
-  return 8;
-}
-
-void
-UdpHeader::SerializeTo (Buffer::Iterator start) const
-{
-  Buffer::Iterator i = start;
-  i.WriteHtonU16 (m_sourcePort);
-  i.WriteHtonU16 (m_destinationPort);
-  i.WriteHtonU16 (m_payloadSize + GetSize ());
-  i.WriteU16 (0);
-
-  if (m_calcChecksum) 
-    {
-#if 0
-      //XXXX
-      uint16_t checksum = Ipv4ChecksumCalculate (m_initialChecksum, 
-                                                  buffer->PeekData (), 
-                                                  GetSize () + m_payloadSize);
-      checksum = Ipv4ChecksumComplete (checksum);
-      i = buffer->Begin ();
-      i.Next (6);
-      i.WriteU16 (checksum);
-#endif
-    }
-}
-uint32_t
-UdpHeader::DeserializeFrom (Buffer::Iterator start)
-{
-  Buffer::Iterator i = start;
-  m_sourcePort = i.ReadNtohU16 ();
-  m_destinationPort = i.ReadNtohU16 ();
-  m_payloadSize = i.ReadNtohU16 () - GetSize ();
-  if (m_calcChecksum) 
-    {
-      // XXX verify checksum.
-    }
-  return GetSerializedSize ();
-}
-
-
-}; // namespace ns3
--- a/src/node/udp-header.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#ifndef UDP_HEADER_H
-#define UDP_HEADER_H
-
-#include <stdint.h>
-#include "ns3/header.h"
-#include "ipv4-address.h"
-
-namespace ns3 {
-
-class UdpHeader : public Header {
-public:
-  UdpHeader ();
-  virtual ~UdpHeader ();
-
-  static void EnableChecksums (void);
-
-  void SetDestination (uint16_t port);
-  void SetSource (uint16_t port);
-  uint16_t GetSource (void) const;
-  uint16_t GetDestination (void) const;
-
-  void SetPayloadSize (uint16_t size);
-
-  void InitializeChecksum (Ipv4Address source, 
-                           Ipv4Address destination,
-                           uint8_t protocol);
-
-private:
-  virtual void PrintTo (std::ostream &os) const;
-  virtual uint32_t GetSerializedSize (void) const;
-  virtual void SerializeTo (Buffer::Iterator start) const;
-  virtual uint32_t DeserializeFrom (Buffer::Iterator start);
-
-  uint16_t m_sourcePort;
-  uint16_t m_destinationPort;
-  uint16_t m_payloadSize;
-  uint16_t m_initialChecksum;
-
-  static bool m_calcChecksum;
-};
-
-}; // namespace ns3
-
-#endif /* UDP_HEADER */
--- a/src/node/udp-socket.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,278 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#include "udp-socket.h"
-#include "udp.h"
-#include "ipv4-end-point.h"
-#include "node.h"
-#include "ipv4-l4-demux.h"
-
-namespace ns3 {
-
-UdpSocket::UdpSocket (Node *node, Udp *udp)
-  : m_endPoint (0),
-    m_node (node),
-    m_udp (udp),
-    m_errno (ENOTERROR),
-    m_shutdownSend (false),
-    m_shutdownRecv (false),
-    m_connected (false)
-{
-  m_udp->Ref ();
-  m_node->Ref ();
-}
-UdpSocket::~UdpSocket ()
-{
-  if (m_node != 0)
-    {
-      m_node->Unref ();
-      m_node = 0;
-    }
-  if (m_endPoint != 0)
-    {
-      NS_ASSERT (m_udp != 0);
-      /**
-       * Note that this piece of code is a bit tricky:
-       * when DeAllocate is called, it will call into
-       * Ipv4EndPointDemux::Deallocate which triggers
-       * a delete of the associated endPoint which triggers
-       * in turn a call to the method ::Destroy below
-       * will will zero the m_endPoint field.
-       */
-      NS_ASSERT (m_endPoint != 0);
-      m_udp->DeAllocate (m_endPoint);
-      NS_ASSERT (m_endPoint == 0);
-    }
-  if (m_udp != 0)
-    {
-      m_udp->Unref ();
-      m_udp = 0;
-    }
-}
-
-Node *
-UdpSocket::PeekNode (void) const
-{
-  return m_node;
-}
-
-void 
-UdpSocket::Destroy (void)
-{
-  if (m_node != 0)
-    {
-      m_node->Unref ();
-      m_node = 0;
-    }
-  m_endPoint = 0;
-  if (m_udp != 0)
-    {
-      m_udp->Unref ();
-      m_udp = 0;
-    }
-}
-int
-UdpSocket::FinishBind (void)
-{
-  m_endPoint->SetRxCallback (MakeCallback (&UdpSocket::ForwardUp, this));
-  m_endPoint->SetDestroyCallback (MakeCallback (&UdpSocket::Destroy, this));
-  if (m_endPoint == 0)
-    {
-      return -1;
-    }
-  return 0;
-}
-
-int
-UdpSocket::Bind (void)
-{
-  m_endPoint = m_udp->Allocate ();
-  return FinishBind ();
-}
-int 
-UdpSocket::Bind (Ipv4Address address)
-{
-  m_endPoint = m_udp->Allocate (address);
-  return FinishBind ();
-}
-int 
-UdpSocket::Bind (uint16_t port)
-{
-  m_endPoint = m_udp->Allocate (port);
-  return FinishBind ();
-}
-int 
-UdpSocket::Bind (Ipv4Address address, uint16_t port)
-{
-  m_endPoint = m_udp->Allocate (address, port);
-  return FinishBind ();
-}
-
-enum Socket::SocketErrno
-UdpSocket::GetErrno (void) const
-{
-  return m_errno;
-}
-int 
-UdpSocket::ShutdownSend (void)
-{
-  m_shutdownSend = true;
-  return 0;
-}
-int 
-UdpSocket::ShutdownRecv (void)
-{
-  m_shutdownRecv = false;
-  return 0;
-}
-
-void 
-UdpSocket::DoClose(ns3::Callback<void, Socket*> closeCompleted)
-{
-  // XXX: we should set the close state and check it in all API methods.
-  if (!closeCompleted.IsNull ())
-    {
-      closeCompleted (this);
-    }
-}
-void 
-UdpSocket::DoConnect(const Ipv4Address & address,
-                     uint16_t portNumber,
-                     ns3::Callback<void, Socket*> connectionSucceeded,
-                     ns3::Callback<void, Socket*> connectionFailed,
-                     ns3::Callback<void, Socket*> halfClose)
-{
-  m_defaultAddress = address;
-  m_defaultPort = portNumber;
-  if (!connectionSucceeded.IsNull ())
-    {
-      connectionSucceeded (this);
-    }
-  m_connected = true;
-}
-int
-UdpSocket::DoAccept(ns3::Callback<bool, Socket*, const Ipv4Address&, uint16_t> connectionRequest,
-                    ns3::Callback<void, Socket*, const Ipv4Address&, uint16_t> newConnectionCreated,
-                    ns3::Callback<void, Socket*> closeRequested)
-{
-  // calling accept on a udp socket is a programming error.
-  m_errno = EOPNOTSUPP;
-  return -1;
-}
-int 
-UdpSocket::DoSend (const uint8_t* buffer,
-                   uint32_t size,
-                   ns3::Callback<void, Socket*, uint32_t> dataSent)
-{
-  if (!m_connected)
-    {
-      m_errno = ENOTCONN;
-      return -1;
-    }
-  Packet p;
-  if (buffer == 0)
-    {
-      p = Packet (size);
-    }
-  else
-    {
-      p = Packet (buffer, size);
-    }
-  return DoSendPacketTo (p, m_defaultAddress, m_defaultPort, dataSent);
-}
-int
-UdpSocket::DoSendPacketTo (const Packet &p, Ipv4Address daddr, uint16_t dport,
-                           ns3::Callback<void, Socket*, uint32_t> dataSent)
-{
-  if (m_endPoint == 0)
-    {
-      if (Bind () == -1)
-	{
-          NS_ASSERT (m_endPoint == 0);
-	  return -1;
-	}
-      NS_ASSERT (m_endPoint != 0);
-    }
-  if (m_shutdownSend)
-    {
-      m_errno = ESHUTDOWN;
-      return -1;
-    }
-  m_udp->Send (p, m_endPoint->GetLocalAddress (), daddr,
-		   m_endPoint->GetLocalPort (), dport);
-  if (!dataSent.IsNull ())
-    {
-      dataSent (this, p.GetSize ());
-    }
-  return 0;
-}
-int 
-UdpSocket::DoSendTo(const Ipv4Address &address,
-                    uint16_t port,
-                    const uint8_t *buffer,
-                    uint32_t size,
-                    ns3::Callback<void, Socket*, uint32_t> dataSent)
-{
-  if (m_connected)
-    {
-      m_errno = EISCONN;
-      return -1;
-    }
-  Packet p;
-  if (buffer == 0)
-    {
-      p = Packet (size);
-    }
-  else
-    {
-      p = Packet (buffer, size);
-    }
-  return DoSendPacketTo (p, address, port, dataSent);
-}
-void 
-UdpSocket::DoRecv(ns3::Callback<void, Socket*, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t> callback)
-{
-  m_rxCallback = callback;
-}
-void 
-UdpSocket::DoRecvDummy(ns3::Callback<void, Socket*, uint32_t,const Ipv4Address&, uint16_t> callback)
-{
-  m_dummyRxCallback = callback;
-}
-
-void 
-UdpSocket::ForwardUp (const Packet &packet, Ipv4Address saddr, uint16_t sport)
-{
-  if (m_shutdownRecv)
-    {
-      return;
-    }
-  Packet p = packet;
-  if (!m_dummyRxCallback.IsNull ())
-    {
-      m_dummyRxCallback (this, p.GetSize (), saddr, sport);
-    }
-  if (!m_rxCallback.IsNull ())
-    {
-      m_rxCallback (this, p.PeekData (), p.GetSize (), saddr, sport);
-    }
-}
-
-}//namespace ns3
--- a/src/node/udp-socket.h	Fri May 04 14:03:12 2007 +0200
+++ /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) 2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#ifndef UDP_SOCKET_H
-#define UDP_SOCKET_H
-
-#include <stdint.h>
-#include "ns3/callback.h"
-#include "socket.h"
-
-namespace ns3 {
-
-class Ipv4EndPoint;
-class Node;
-class Packet;
-class Udp;
-
-class UdpSocket : public Socket
-{
-public:
-  /**
-   * Create an unbound udp socket.
-   */
-  UdpSocket (Node *node, Udp *udp);
-  virtual ~UdpSocket ();
-
-  virtual enum SocketErrno GetErrno (void) const;
-  virtual Node *PeekNode (void) const;
-  virtual int Bind (void);
-  virtual int Bind (Ipv4Address address);
-  virtual int Bind (uint16_t port); 
-  virtual int Bind (Ipv4Address address, uint16_t port);
-  virtual int ShutdownSend (void);
-  virtual int ShutdownRecv (void);
-
-private:
-  virtual void DoClose(ns3::Callback<void, Socket*> closeCompleted);
-  virtual void DoConnect(const Ipv4Address & address,
-			 uint16_t portNumber,
-			 ns3::Callback<void, Socket*> connectionSucceeded,
-			 ns3::Callback<void, Socket*> connectionFailed,
-			 ns3::Callback<void, Socket*> halfClose);
-  virtual int DoAccept(ns3::Callback<bool, Socket*, const Ipv4Address&, uint16_t> connectionRequest,
-		       ns3::Callback<void, Socket*, const Ipv4Address&, uint16_t> newConnectionCreated,
-		       ns3::Callback<void, Socket*> closeRequested);
-  virtual int DoSend (const uint8_t* buffer,
-                    uint32_t size,
-                    ns3::Callback<void, Socket*, uint32_t> dataSent);
-  virtual int DoSendTo(const Ipv4Address &address,
-                      uint16_t port,
-                      const uint8_t *buffer,
-                      uint32_t size,
-                      ns3::Callback<void, Socket*, uint32_t> dataSent);
-  virtual void DoRecv(ns3::Callback<void, Socket*, const uint8_t*, uint32_t,const Ipv4Address&, uint16_t>);
-  virtual void DoRecvDummy(ns3::Callback<void, Socket*, uint32_t,const Ipv4Address&, uint16_t>);
-
-private:
-  friend class Udp;
-  // invoked by Udp class
-  int FinishBind (void);
-  void ForwardUp (const Packet &p, Ipv4Address saddr, uint16_t sport);
-  void Destroy (void);
-  int DoSendPacketTo (const Packet &p, Ipv4Address daddr, uint16_t dport,
-		      ns3::Callback<void, Socket*, uint32_t> dataSent);
-
-  Ipv4EndPoint *m_endPoint;
-  Node *m_node;
-  Udp *m_udp;
-  Ipv4Address m_defaultAddress;
-  uint16_t m_defaultPort;
-  Callback<void,Socket*,uint32_t,const Ipv4Address &,uint16_t> m_dummyRxCallback;
-  Callback<void,Socket*,uint8_t const*,uint32_t,const Ipv4Address &,uint16_t> m_rxCallback;
-  enum SocketErrno m_errno;
-  bool m_shutdownSend;
-  bool m_shutdownRecv;
-  bool m_connected;
-};
-
-}//namespace ns3
-
-#endif /* UDP_SOCKET_H */
--- a/src/node/udp.cc	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,155 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#include "ns3/assert.h"
-#include "ns3/packet.h"
-#include "ns3/empty-trace-resolver.h"
-
-#include "udp.h"
-#include "udp-header.h"
-#include "ipv4-end-point-demux.h"
-#include "ipv4-end-point.h"
-#include "node.h"
-#include "ipv4.h"
-#include "i-ipv4-private.h"
-#include "l3-demux.h"
-#include "udp-socket.h"
-
-namespace ns3 {
-
-/* see http://www.iana.org/assignments/protocol-numbers */
-const uint8_t Udp::PROT_NUMBER = 17;
-
-Udp::Udp (Node *node)
-  : Ipv4L4Protocol (PROT_NUMBER, 2),
-    m_node (node),
-    m_endPoints (new Ipv4EndPointDemux ())
-{
-  m_node->Ref ();
-}
-
-Udp::~Udp ()
-{}
-
-TraceResolver *
-Udp::CreateTraceResolver (TraceContext const &context)
-{
-  return new EmptyTraceResolver (context);
-}
-
-void
-Udp::DoDispose (void)
-{
-  if (m_endPoints != 0)
-    {
-      delete m_endPoints;
-      m_endPoints = 0;
-    }
-  if (m_node != 0)
-    {
-      m_node->Unref ();
-      m_node = 0;
-    }
-  Ipv4L4Protocol::DoDispose ();
-}
-
-Socket *
-Udp::CreateSocket (void)
-{
-  return new UdpSocket (m_node, this);
-}
-
-Ipv4EndPoint *
-Udp::Allocate (void)
-{
-  return m_endPoints->Allocate ();
-}
-Ipv4EndPoint *
-Udp::Allocate (Ipv4Address address)
-{
-  return m_endPoints->Allocate (address);
-}
-Ipv4EndPoint *
-Udp::Allocate (uint16_t port)
-{
-  return m_endPoints->Allocate (port);
-}
-Ipv4EndPoint *
-Udp::Allocate (Ipv4Address address, uint16_t port)
-{
-  return m_endPoints->Allocate (address, port);
-}
-Ipv4EndPoint *
-Udp::Allocate (Ipv4Address localAddress, uint16_t localPort,
-               Ipv4Address peerAddress, uint16_t peerPort)
-{
-  return m_endPoints->Allocate (localAddress, localPort,
-                                peerAddress, peerPort);
-}
-
-void 
-Udp::DeAllocate (Ipv4EndPoint *endPoint)
-{
-  m_endPoints->DeAllocate (endPoint);
-}
-
-void 
-Udp::Receive(Packet& packet, 
-             Ipv4Address const &source,
-             Ipv4Address const &destination)
-{
-  UdpHeader udpHeader;
-  packet.RemoveHeader (udpHeader);
-  Ipv4EndPoint *endPoint = m_endPoints->Lookup (destination, udpHeader.GetDestination (),
-                                                source, udpHeader.GetSource ());
-  if (endPoint == 0)
-    {
-      return;
-    }
-  endPoint->ForwardUp (packet, source, udpHeader.GetSource ());
-}
-
-void
-Udp::Send (Packet packet, 
-           Ipv4Address saddr, Ipv4Address daddr, 
-           uint16_t sport, uint16_t dport)
-{
-  UdpHeader udpHeader;
-  udpHeader.SetDestination (dport);
-  udpHeader.SetSource (sport);
-  udpHeader.SetPayloadSize (packet.GetSize ());
-  udpHeader.InitializeChecksum (saddr,
-                               daddr,
-                               PROT_NUMBER);
-
-  packet.AddHeader (udpHeader);
-
-  IIpv4Private *ipv4 = m_node->QueryInterface<IIpv4Private> (IIpv4Private::iid);
-  if (ipv4 != 0)
-    {
-      ipv4->Send (packet, saddr, daddr, PROT_NUMBER);
-      ipv4->Unref ();
-    }
-}
-
-
-}; // namespace ns3
-
--- a/src/node/udp.h	Fri May 04 14:03:12 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005,2006,2007 INRIA
- * 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#ifndef UDP_H
-#define UDP_H
-
-#include <stdint.h>
-
-#include "ns3/packet.h"
-#include "ipv4-address.h"
-#include "ipv4-end-point-demux.h"
-#include "ipv4-l4-protocol.h"
-
-namespace ns3 {
-
-class Node;
-class TraceResolver;
-class TraceContext;
-class Socket;
-
-class Udp : public Ipv4L4Protocol {
-public:
-  static const uint8_t PROT_NUMBER;
-
-  Udp (Node *node);
-  virtual ~Udp ();
-
-  virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
-
-  Socket *CreateSocket (void);
-
-  Ipv4EndPoint *Allocate (void);
-  Ipv4EndPoint *Allocate (Ipv4Address address);
-  Ipv4EndPoint *Allocate (uint16_t port);
-  Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port);
-  Ipv4EndPoint *Allocate (Ipv4Address localAddress, uint16_t localPort,
-                         Ipv4Address peerAddress, uint16_t peerPort);
-
-  void DeAllocate (Ipv4EndPoint *endPoint);
-
-  // called by UdpSocket.
-  void Send (Packet packet,
-             Ipv4Address saddr, Ipv4Address daddr, 
-             uint16_t sport, uint16_t dport);
-  // inherited from Ipv4L4Protocol
-  virtual void Receive(Packet& p, 
-                       Ipv4Address const &source,
-                       Ipv4Address const &destination);
-protected:
-  virtual void DoDispose (void);
-private:
-  Node *m_node;
-  Ipv4EndPointDemux *m_endPoints;
-};
-
-}; // namespace ns3
-
-#endif /* UDP_H */