add Ipv4 and Udp node capabilities, rework Copy methods to include an extra Node * argument
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 12 Feb 2007 13:06:05 +0100
changeset 241 9004ab4cfe17
parent 240 7da682f99bf9
child 242 a44932709b47
add Ipv4 and Udp node capabilities, rework Copy methods to include an extra Node * argument
SConstruct
src/node/capability.cc
src/node/capability.h
src/node/internet-node.cc
src/node/internet-node.h
src/node/ipv4-l3-protocol.cc
src/node/ipv4-l3-protocol.h
src/node/ipv4-l4-demux.cc
src/node/ipv4-l4-demux.h
src/node/ipv4-l4-protocol.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/net-device-list.h
src/node/node.cc
src/node/node.h
src/node/udp-ipv4-l4-protocol.cc
src/node/udp-ipv4-l4-protocol.h
src/node/udp-socket.cc
src/node/udp.cc
src/node/udp.h
--- a/SConstruct	Sat Feb 10 11:29:44 2007 +0100
+++ b/SConstruct	Mon Feb 12 13:06:05 2007 +0100
@@ -144,10 +144,12 @@
 node.add_deps (['core'])
 node.add_sources ([
     'node.cc',
-    'capability.cc',
     'l3-demux.cc',
+    'l3-protocol.cc',
+    'ipv4-l3-protocol.cc',
     'ipv4-l4-demux.cc',
     'ipv4-l4-protocol.cc',
+    'udp-ipv4-l4-protocol.cc',
     'ipv4-address.cc',
     'internet-node.cc',
     'net-device.cc',
@@ -173,7 +175,6 @@
     ])
 node.add_inst_headers ([
     'node.h',
-    'capability.h',
     'l3-demux.h',
     'l3-protocol.h',
     'ipv4-l4-demux.h',
--- a/src/node/capability.cc	Sat Feb 10 11:29:44 2007 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +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 base class for all node capabilities.
-// George F. Riley, Georgia Tech, Fall 2006
-
-#include "capability.h"
-
-namespace ns3 {
-
-Capability::~Capability ()
-{}
-
-}//namespace ns3
-
-
--- a/src/node/capability.h	Sat Feb 10 11:29:44 2007 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +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 base class for all node capabilities.
-// George F. Riley, Georgia Tech, Fall 2006
-
-#ifndef CAPABILITY_H
-#define CAPABILITY_H
-
-// All capabilities must implement a copy method, to allow node subclasses
-// to have a pointer to any subclass of the capability and still copy
-// correctly.
-
-namespace ns3 {
-
-class Node;
-
-class Capability 
-{
-public:
-  virtual ~Capability();
-  virtual Capability* Copy() const = 0;
-};
-
-}//namespace ns3
-#endif
--- a/src/node/internet-node.cc	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/internet-node.cc	Mon Feb 12 13:06:05 2007 +0100
@@ -23,6 +23,7 @@
 
 #include "net-device-list.h"
 #include "l3-demux.h"
+#include "ipv4-l3-protocol.h"
 #include "ipv4-l4-demux.h"
 #include "internet-node.h"
 #include "udp.h"
@@ -34,31 +35,21 @@
 {
   // Instantiate the capabilities
   m_netDevices = new NetDeviceList();
-  m_l3Demux = new L3Demux();
-  m_ipv4L4Demux = new Ipv4L4Demux();
-  // add an ipv4 protocol handler.
-  Ipv4 ipv4;
-  m_l3Demux->Insert (ipv4);
+  m_l3Demux = new L3Demux(this);
+  m_ipv4L4Demux = new Ipv4L4Demux(this);
+  m_udp = new Udp (this);
+  m_ipv4 = new Ipv4 (this);
+  m_l3Demux->Insert (Ipv4L3Protocol (this));
   // add a udp protocol handler.
-  Udp udp = Udp (this);
-  m_ipv4L4Demux->Insert (udp);
-}
-
-InternetNode::InternetNode(const InternetNode& rhs)
-{ // Copy constructor
-  // Note we do not copy the contents of the process list or
-  // the interfaces list, as these are added later.
-  m_netDevices = new NetDeviceList();
-  // Make a copy of each capability
-  m_l3Demux  = rhs.GetL3Demux()->Copy();
-  m_ipv4L4Demux  = rhs.GetIpv4L4Demux()->Copy();
+  //m_ipv4L4Demux->Insert (udp);
 }
 
 // Copy this node
 InternetNode* 
 InternetNode::Copy() const
 {
-  return new InternetNode(*this);
+  //return new InternetNode(*this);
+  return 0;
 }
 
 
--- a/src/node/internet-node.h	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/internet-node.h	Mon Feb 12 13:06:05 2007 +0100
@@ -41,12 +41,16 @@
   virtual NetDeviceList*   GetNetDevices() const;
   virtual L3Demux*         GetL3Demux() const;
   virtual Ipv4L4Demux*     GetIpv4L4Demux() const;
+  virtual Ipv4 *           GetIpv4 (void) const;
+  virtual Udp *            GetUdp (void) const;
 
 private:
   // Capabilities
   NetDeviceList*   m_netDevices;
   L3Demux*         m_l3Demux;
   Ipv4L4Demux*     m_ipv4L4Demux;
+  Ipv4 *           m_ipv4;
+  Udp *            m_udp;
  };
 
 }//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/node/ipv4-l3-protocol.cc	Mon Feb 12 13:06:05 2007 +0100
@@ -0,0 +1,56 @@
+// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
+//
+// Copyright (c) 2006 Georgia Tech Research Corporation
+// All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation;
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+// Author: George F. Riley <riley@ece.gatech.edu>
+//
+
+// NS3 - Layer 3 Protocol base class
+// George F. Riley, Georgia Tech, Spring 2007
+
+#include "ipv4-l3-protocol.h"
+#include "ipv4.h"
+#include "node.h"
+
+namespace ns3 {
+
+Ipv4L3Protocol::Ipv4L3Protocol (Node *node)
+  : L3Protocol (0x0800, 4),
+    m_node (node)
+{}
+Ipv4L3Protocol::~Ipv4L3Protocol ()
+{}
+
+Ipv4L3Protocol *
+Ipv4L3Protocol::Copy (Node *node) const
+{
+  Ipv4L3Protocol *copy = new Ipv4L3Protocol (node);
+  return copy;
+}
+void 
+Ipv4L3Protocol::Receive(Packet& p, NetDevice &device)
+{
+  Ipv4 *ipv4 = m_node->GetIpv4 ();
+  if (ipv4 != 0)
+    {
+      ipv4->Receive (p, device);
+    }
+}
+
+
+
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/node/ipv4-l3-protocol.h	Mon Feb 12 13:06:05 2007 +0100
@@ -0,0 +1,47 @@
+// -*- 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 IPV4_L3_PROTOCOL_H
+#define IPV4_L3_PROTOCOL_H
+
+#include "l3-protocol.h"
+
+namespace ns3 {
+
+class Ipv4L3Protocol : public L3Protocol 
+{
+public:
+  Ipv4L3Protocol (Node *node);
+  virtual ~Ipv4L3Protocol ();
+
+  virtual Ipv4L3Protocol *Copy (Node *node) const;
+  virtual void Receive (Packet& p, NetDevice &device);
+private:
+  Node *m_node;
+};
+
+}//namespace ns3
+
+
+#endif /* IPV4_L3_PROTOCOL_H */
--- a/src/node/ipv4-l4-demux.cc	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/ipv4-l4-demux.cc	Mon Feb 12 13:06:05 2007 +0100
@@ -27,27 +27,26 @@
 
 namespace ns3 {
 
-Ipv4L4Demux::Ipv4L4Demux ()
+Ipv4L4Demux::Ipv4L4Demux (Node *node)
+  : m_node (node)
 {}
 
-Ipv4L4Demux::Ipv4L4Demux(Ipv4L4Demux const &o)
-{
-  for (L4List_t::const_iterator i = o.m_protocols.begin(); i != o.m_protocols.end(); ++i)
-    {
-      Insert(*(*i));
-    }
-}
 Ipv4L4Demux::~Ipv4L4Demux()
 {}
 Ipv4L4Demux* 
-Ipv4L4Demux::Copy() const
+Ipv4L4Demux::Copy(Node *node) const
 {
-  return new Ipv4L4Demux(*this);
+  Ipv4L4Demux * copy = new Ipv4L4Demux(node);
+  for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
+    {
+      copy->Insert(*(*i));
+    }
+  return copy;
 }
 Ipv4L4Protocol* 
 Ipv4L4Demux::Insert(const Ipv4L4Protocol&protocol)
 {
-  Ipv4L4Protocol* copy = protocol.Copy(); // Make a copy of the protocol
+  Ipv4L4Protocol* copy = protocol.Copy(m_node); // Make a copy of the protocol
   m_protocols.push_back (copy);
   return copy;
 }
--- a/src/node/ipv4-l4-demux.h	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/ipv4-l4-demux.h	Mon Feb 12 13:06:05 2007 +0100
@@ -31,19 +31,20 @@
 namespace ns3 {
 
 class Ipv4L4Protocol;
+class Node;
 
 class Ipv4L4Demux {
 public:
-  Ipv4L4Demux ();
-  Ipv4L4Demux(Ipv4L4Demux const&o);
+  Ipv4L4Demux (Node *node);
   virtual ~Ipv4L4Demux();
-  virtual Ipv4L4Demux* Copy() const;
+  Ipv4L4Demux* Copy(Node *node) const;
   Ipv4L4Protocol* Insert(const Ipv4L4Protocol&);
   Ipv4L4Protocol* Lookup(int protocolNumber);
   void        Erase(Ipv4L4Protocol*);
 private:
   typedef std::list<Ipv4L4Protocol*> L4List_t;
   L4List_t m_protocols;
+  Node *m_node;
 };
 
 } //namespace ns3
--- a/src/node/ipv4-l4-protocol.h	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/ipv4-l4-protocol.h	Mon Feb 12 13:06:05 2007 +0100
@@ -40,7 +40,7 @@
   int GetProtocolNumber (void) const;
   int GetVersion() const;
 
-  virtual Ipv4L4Protocol* Copy() const = 0;
+  virtual Ipv4L4Protocol* Copy(Node *node) const = 0;
   /**
    * Called from lower-level layers to send the packet up
    * in the stack. 
--- a/src/node/ipv4.cc	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/ipv4.cc	Mon Feb 12 13:06:05 2007 +0100
@@ -35,23 +35,13 @@
 
 namespace ns3 {
 
-Ipv4::Ipv4()
-  : L3Protocol (0x0800, 4),
-    m_nInterfaces (0),
+Ipv4::Ipv4(Node *node)
+  : m_nInterfaces (0),
     m_defaultTtl (64),
     m_identification (0),
-    m_defaultRoute (0)
+    m_defaultRoute (0),
+    m_node (node)
 {}
-Ipv4::Ipv4(Ipv4 const &o)
-  : L3Protocol (o),
-    m_nInterfaces (0),
-    m_defaultTtl (o.m_defaultTtl),
-    m_identification (o.m_identification),
-    m_defaultRoute (0)
-{
-  // We do not copy the list of interfaces or the routes
-  // purposedly.
-}
 Ipv4::~Ipv4 ()
 {
   // XXX I am not sure we are really allowed to do this here.
@@ -289,9 +279,11 @@
   
 
 Ipv4* 
-Ipv4::Copy() const
+Ipv4::Copy(Node *node) const
 {
-  return new Ipv4 (*this);
+  Ipv4 *ipv4 = new Ipv4 (node);
+  ipv4->SetDefaultTtl (m_defaultTtl);
+  return ipv4;
 }
 void 
 Ipv4::Receive(Packet& packet, NetDevice &device)
--- a/src/node/ipv4.h	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/ipv4.h	Mon Feb 12 13:06:05 2007 +0100
@@ -24,7 +24,6 @@
 
 #include <list>
 #include <stdint.h>
-#include "l3-protocol.h"
 #include "ipv4-address.h"
 
 namespace ns3 {
@@ -41,10 +40,9 @@
 /**
  * ::Send is always defined in subclasses.
  */
-class Ipv4 : public L3Protocol {
+class Ipv4 {
 public:
-  Ipv4();
-  Ipv4(Ipv4 const &o);
+  Ipv4(Node *node);
   virtual ~Ipv4 ();
 
   void SetDefaultTtl (uint8_t ttl);
@@ -89,7 +87,7 @@
   uint32_t GetNInterfaces (void) const;
   
 
-  virtual Ipv4* Copy() const;
+  Ipv4* Copy(Node *node) const;
   /**
    * Lower layer calls this method after calling L3Demux::Lookup
    * The ARP subclass needs to know from which NetDevice this
@@ -97,7 +95,7 @@
    *    - implement a per-NetDevice ARP cache
    *    - send back arp replies on the right device
    */
-  virtual void Receive(Packet& p, NetDevice &device);
+  void Receive(Packet& p, NetDevice &device);
 
   void Send (Packet const &packet, Ipv4Address source, 
 	     Ipv4Address destination, uint8_t protocol);
--- a/src/node/l3-demux.cc	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/l3-demux.cc	Mon Feb 12 13:06:05 2007 +0100
@@ -26,6 +26,10 @@
 
 namespace ns3 {
 
+L3Demux::L3Demux (Node *node)
+  : m_node (node)
+{}
+
 L3Demux::~L3Demux()
 { // Delete each protocol in the map
   for (L3Map_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
@@ -33,23 +37,21 @@
       delete i->second;
     }
 }
-
-L3Demux::L3Demux(const L3Demux& rhs)
-{ // Copy constructor, copy each protocol
-  for (L3Map_t::const_iterator i = rhs.m_protocols.begin(); i != rhs.m_protocols.end(); ++i)
+  
+L3Demux* L3Demux::Copy(Node *node) const
+{
+  L3Demux *copy = new L3Demux (node);
+  for (L3Map_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
     {
-      Insert(*i->second);
+      copy->Insert(*i->second);
     }
-}
-  
-L3Demux* L3Demux::Copy() const
-{ // Return a copy of this protocol manager
-  return new L3Demux(*this);
+
+  return copy;
 }
   
 L3Protocol* L3Demux::Insert(const L3Protocol& l3p)
 {
-  L3Protocol* l = l3p.Copy(); // Make a copy of the protocol
+  L3Protocol* l = l3p.Copy(m_node); // Make a copy of the protocol
   m_protocols.insert(L3Map_t::value_type(l3p.GetProtocolNumber (), l));
   return l;
 }
--- a/src/node/l3-demux.h	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/l3-demux.h	Mon Feb 12 13:06:05 2007 +0100
@@ -32,14 +32,14 @@
 namespace ns3 {
 
 class L3Protocol;
+class Node;
 
 class L3Demux
 {
 public:
-  L3Demux() {};
-  L3Demux(const L3Demux&);
+  L3Demux(Node *node);
   virtual ~L3Demux();
-  virtual L3Demux* Copy() const;
+  L3Demux* Copy(Node *node) const;
 
   // Insert a new protocol
   ns3::L3Protocol* Insert(const ns3::L3Protocol&);
@@ -50,6 +50,7 @@
 private:
   typedef std::map<int, ns3::L3Protocol*> L3Map_t;
 
+  Node *m_node;
   L3Map_t m_protocols;
 };
 
--- a/src/node/l3-protocol.cc	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/l3-protocol.cc	Mon Feb 12 13:06:05 2007 +0100
@@ -31,10 +31,6 @@
     : m_protocolNumber (protocolNumber),
       m_version (version)
 {}
-L3Protocol::L3Protocol (L3Protocol const &o)
-  : m_protocolNumber (o.m_protocolNumber),
-    m_version (o.m_version)
-{}
 L3Protocol::~L3Protocol ()
 {}
     
--- a/src/node/l3-protocol.h	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/l3-protocol.h	Mon Feb 12 13:06:05 2007 +0100
@@ -29,6 +29,7 @@
 
 class Packet;
 class NetDevice;
+class Node;
 
 
 /**
@@ -37,13 +38,12 @@
 class L3Protocol {
 public:
   L3Protocol(int protocolNumber, int version);
-  L3Protocol (L3Protocol const &o);
   virtual ~L3Protocol ();
     
   int GetProtocolNumber (void) const;
   int GetVersion() const;
 
-  virtual L3Protocol* Copy() const = 0;
+  virtual L3Protocol* Copy(Node *node) const = 0;
   /**
    * Lower layer calls this method after calling L3Demux::Lookup
    * The ARP subclass needs to know from which NetDevice this
--- a/src/node/net-device-list.h	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/net-device-list.h	Mon Feb 12 13:06:05 2007 +0100
@@ -25,19 +25,17 @@
 #define NET_DEVICE_LIST_H
 
 #include <vector>
-#include "capability.h"
 
 namespace ns3{
 
 class NetDevice;
 
-class NetDeviceList : public Capability {
+class NetDeviceList {
 public:
   typedef std::vector<NetDevice *>::iterator Iterator;
 
   NetDeviceList();
   ~NetDeviceList();
-  NetDeviceList* Copy() const;
   // Manage the list
   NetDevice* Add(const NetDevice&);      // Add a new netdevice
   NetDeviceList::Iterator Begin () const;
--- a/src/node/node.cc	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/node.cc	Mon Feb 12 13:06:05 2007 +0100
@@ -62,5 +62,17 @@
   return 0;
 }
 
+Ipv4 *
+Node::GetIpv4 (void) const
+{
+  return 0;
+}
+Udp *
+Node::GetUdp (void) const
+{
+  return 0;
+}
+
+
 
 }//namespace ns3
--- a/src/node/node.h	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/node.h	Mon Feb 12 13:06:05 2007 +0100
@@ -96,6 +96,8 @@
 class L3Demux;
 class Ipv4L4Demux;
 class NetDeviceList;
+class Ipv4;
+class Udp;
 
 class Node {
 public:
@@ -118,6 +120,8 @@
   virtual L3Demux*         GetL3Demux() const;
   virtual Ipv4L4Demux*     GetIpv4L4Demux() const;
   virtual NetDeviceList*   GetNetDeviceList() const;
+  virtual Ipv4 *           GetIpv4 (void) const;
+  virtual Udp *            GetUdp (void) const;
   
 private:
   Id_t         m_id;         // Node id for this node
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/node/udp-ipv4-l4-protocol.cc	Mon Feb 12 13:06:05 2007 +0100
@@ -0,0 +1,58 @@
+// -*- 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 "udp-ipv4-l4-protocol.h"
+#include "node.h"
+#include "udp.h"
+
+namespace ns3 {
+
+/* see http://www.iana.org/assignments/protocol-numbers */
+const uint8_t UdpIpv4L4Protocol::UDP_PROTOCOL = 17;
+
+
+UdpIpv4L4Protocol::UdpIpv4L4Protocol(Node *node)
+  : Ipv4L4Protocol (UDP_PROTOCOL, 2),
+    m_node (node)
+{}
+UdpIpv4L4Protocol::~UdpIpv4L4Protocol ()
+{}
+
+UdpIpv4L4Protocol*
+UdpIpv4L4Protocol::Copy(Node *node) const
+{
+  return new UdpIpv4L4Protocol (node);
+}
+void 
+UdpIpv4L4Protocol::Receive(Packet& p, 
+                           Ipv4Address const &source,
+                           Ipv4Address const &destination)
+{
+  if (m_node->GetUdp () != 0)
+    {
+      m_node->GetUdp ()->Receive (p, source, destination);
+    }
+}
+
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/node/udp-ipv4-l4-protocol.h	Mon Feb 12 13:06:05 2007 +0100
@@ -0,0 +1,58 @@
+// -*- 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 UDP_IPV4_L4_PROTOCOL_H
+#define UDP_IPV4_L4_PROTOCOL_H
+
+#include <stdint.h>
+#include "ipv4-l4-protocol.h"
+
+namespace ns3 {
+
+class Node;
+class Packet;
+class Ipv4Address;
+  
+class UdpIpv4L4Protocol : Ipv4L4Protocol {
+public:
+  UdpIpv4L4Protocol(Node *node);
+  virtual ~UdpIpv4L4Protocol ();
+
+  virtual UdpIpv4L4Protocol* Copy(Node *node) const;
+  /**
+   * Called from lower-level layers to send the packet up
+   * in the stack. 
+   */
+  virtual void Receive(Packet& p, 
+                       Ipv4Address const &source,
+                       Ipv4Address const &destination);
+
+ private:
+  Node *m_node;
+  static const uint8_t UDP_PROTOCOL;
+};
+
+} // Namespace ns3
+
+#endif /* UDP_IPV4_L4_PROTOCOL */
--- a/src/node/udp-socket.cc	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/udp-socket.cc	Mon Feb 12 13:06:05 2007 +0100
@@ -161,12 +161,7 @@
 Udp *
 UdpSocket::GetUdp (void) const
 {
-  if (m_node->GetIpv4L4Demux () != 0)
-    {
-      // udp protocol number
-      return static_cast<Udp *> (m_node->GetIpv4L4Demux ()->Lookup (17));
-    }
-  return 0;
+  return m_node->GetUdp ();
 }
 
 }//namespace ns3
--- a/src/node/udp.cc	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/udp.cc	Mon Feb 12 13:06:05 2007 +0100
@@ -36,17 +36,9 @@
 const uint8_t Udp::UDP_PROTOCOL = 17;
 
 Udp::Udp (Node *node)
-  : Ipv4L4Protocol (UDP_PROTOCOL, 2),
-    m_node (node),
+  : m_node (node),
     m_endPoints (new Ipv4EndPointDemux<UdpEndPoint> ())
 {}
-Udp::Udp (Udp const &o)
-  : Ipv4L4Protocol (UDP_PROTOCOL, 2),
-    m_node (o.m_node),
-    m_endPoints (new Ipv4EndPointDemux<UdpEndPoint> ())
-{
-  // we do not copy the udp endpoints on purpose.
-}
 
 Udp::~Udp ()
 {
@@ -82,9 +74,9 @@
 }
 
 Udp* 
-Udp::Copy() const
+Udp::Copy(Node *node) const
 {
-  return new Udp (*this);
+  return new Udp (node);
 }
 
 void 
@@ -121,14 +113,10 @@
 
   packet.Add (udpHeader);
 
-  // Send to ipv4 layer.
-  if (m_node->GetL3Demux () != 0 )
+  Ipv4 *ipv4 = m_node->GetIpv4 ();
+  if (ipv4 != 0)
     {
-      Ipv4 *ipv4 = static_cast<Ipv4 *> (m_node->GetL3Demux ()->Lookup (0x0800));
-      if (ipv4 != 0)
-        {
-          ipv4->Send (packet, saddr, daddr, UDP_PROTOCOL);
-        }
+      ipv4->Send (packet, saddr, daddr, UDP_PROTOCOL);
     }
 }
 
--- a/src/node/udp.h	Sat Feb 10 11:29:44 2007 +0100
+++ b/src/node/udp.h	Mon Feb 12 13:06:05 2007 +0100
@@ -26,7 +26,6 @@
 
 #include "ns3/packet.h"
 #include "ipv4-address.h"
-#include "ipv4-l4-protocol.h"
 #include "ipv4-end-point-demux.h"
 #include "udp-end-point.h"
 
@@ -34,10 +33,9 @@
 
 class Node;
 
-class Udp : public Ipv4L4Protocol {
+class Udp {
 public:
   Udp (Node *node);
-  Udp (Udp const &o);
   virtual ~Udp ();
 
   UdpEndPoint *Allocate (void);
@@ -52,10 +50,10 @@
              Ipv4Address saddr, Ipv4Address daddr, 
              uint16_t sport, uint16_t dport);
   // inherited from Ipv4L4Protocol
-  virtual Udp* Copy() const;
-  virtual void Receive(Packet& p, 
-                       Ipv4Address const &source,
-                       Ipv4Address const &destination);
+  Udp* Copy(Node *node) const;
+  void Receive(Packet& p, 
+               Ipv4Address const &source,
+               Ipv4Address const &destination);
  private:
   static const uint8_t UDP_PROTOCOL;
   Node *m_node;