From ea343befaf53bdbf2dfc28e7fc06c23c53c14acf Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 12 Feb 2007 13:06:05 +0100 Subject: [PATCH] add Ipv4 and Udp node capabilities, rework Copy methods to include an extra Node * argument --- SConstruct | 5 +- src/node/internet-node.cc | 27 +++------ src/node/internet-node.h | 4 ++ .../{capability.cc => ipv4-l3-protocol.cc} | 37 +++++++++--- src/node/{capability.h => ipv4-l3-protocol.h} | 32 +++++----- src/node/ipv4-l4-demux.cc | 21 ++++--- src/node/ipv4-l4-demux.h | 7 ++- src/node/ipv4-l4-protocol.h | 2 +- src/node/ipv4.cc | 24 +++----- src/node/ipv4.h | 10 ++-- src/node/l3-demux.cc | 26 +++++---- src/node/l3-demux.h | 7 ++- src/node/l3-protocol.cc | 4 -- src/node/l3-protocol.h | 4 +- src/node/net-device-list.h | 4 +- src/node/node.cc | 12 ++++ src/node/node.h | 4 ++ src/node/udp-ipv4-l4-protocol.cc | 58 +++++++++++++++++++ src/node/udp-ipv4-l4-protocol.h | 58 +++++++++++++++++++ src/node/udp-socket.cc | 7 +-- src/node/udp.cc | 24 ++------ src/node/udp.h | 12 ++-- 22 files changed, 256 insertions(+), 133 deletions(-) rename src/node/{capability.cc => ipv4-l3-protocol.cc} (57%) rename src/node/{capability.h => ipv4-l3-protocol.h} (64%) create mode 100644 src/node/udp-ipv4-l4-protocol.cc create mode 100644 src/node/udp-ipv4-l4-protocol.h diff --git a/SConstruct b/SConstruct index 445b04251..caee3c4b5 100644 --- a/SConstruct +++ b/SConstruct @@ -144,10 +144,12 @@ ns3.add (node) 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_headers ([ ]) node.add_inst_headers ([ 'node.h', - 'capability.h', 'l3-demux.h', 'l3-protocol.h', 'ipv4-l4-demux.h', diff --git a/src/node/internet-node.cc b/src/node/internet-node.cc index bcfdd682f..fde1b1fc5 100644 --- a/src/node/internet-node.cc +++ b/src/node/internet-node.cc @@ -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 @@ InternetNode::InternetNode() { // 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; } diff --git a/src/node/internet-node.h b/src/node/internet-node.h index 2dc6c94a3..2f8be8840 100644 --- a/src/node/internet-node.h +++ b/src/node/internet-node.h @@ -41,12 +41,16 @@ public: 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 diff --git a/src/node/capability.cc b/src/node/ipv4-l3-protocol.cc similarity index 57% rename from src/node/capability.cc rename to src/node/ipv4-l3-protocol.cc index 81718e732..9cd5f5e2c 100644 --- a/src/node/capability.cc +++ b/src/node/ipv4-l3-protocol.cc @@ -16,18 +16,41 @@ // 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 +// Author: George F. Riley // -// Define the base class for all node capabilities. -// George F. Riley, Georgia Tech, Fall 2006 -#include "capability.h" +// 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 { -Capability::~Capability () +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 - - diff --git a/src/node/capability.h b/src/node/ipv4-l3-protocol.h similarity index 64% rename from src/node/capability.h rename to src/node/ipv4-l3-protocol.h index 4c1409286..90388446f 100644 --- a/src/node/capability.h +++ b/src/node/ipv4-l3-protocol.h @@ -16,28 +16,32 @@ // 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 +// Author: George F. Riley // -// Define the base class for all node capabilities. -// George F. Riley, Georgia Tech, Fall 2006 -#ifndef CAPABILITY_H -#define CAPABILITY_H +// NS3 - Layer 3 Protocol base class +// George F. Riley, Georgia Tech, Spring 2007 -// 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. +#ifndef IPV4_L3_PROTOCOL_H +#define IPV4_L3_PROTOCOL_H + +#include "l3-protocol.h" namespace ns3 { -class Node; - -class Capability +class Ipv4L3Protocol : public L3Protocol { public: - virtual ~Capability(); - virtual Capability* Copy() const = 0; + 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 + + +#endif /* IPV4_L3_PROTOCOL_H */ diff --git a/src/node/ipv4-l4-demux.cc b/src/node/ipv4-l4-demux.cc index de9a184f2..45be841e9 100644 --- a/src/node/ipv4-l4-demux.cc +++ b/src/node/ipv4-l4-demux.cc @@ -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; } diff --git a/src/node/ipv4-l4-demux.h b/src/node/ipv4-l4-demux.h index 195ee13f6..497c56858 100644 --- a/src/node/ipv4-l4-demux.h +++ b/src/node/ipv4-l4-demux.h @@ -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 L4List_t; L4List_t m_protocols; + Node *m_node; }; } //namespace ns3 diff --git a/src/node/ipv4-l4-protocol.h b/src/node/ipv4-l4-protocol.h index 3751b3632..58c1a5ce5 100644 --- a/src/node/ipv4-l4-protocol.h +++ b/src/node/ipv4-l4-protocol.h @@ -40,7 +40,7 @@ public: 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. diff --git a/src/node/ipv4.cc b/src/node/ipv4.cc index fdee45d72..8ba04ecd4 100644 --- a/src/node/ipv4.cc +++ b/src/node/ipv4.cc @@ -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::GetNInterfaces (void) const 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) diff --git a/src/node/ipv4.h b/src/node/ipv4.h index 935e0da04..b8556498e 100644 --- a/src/node/ipv4.h +++ b/src/node/ipv4.h @@ -24,7 +24,6 @@ #include #include -#include "l3-protocol.h" #include "ipv4-address.h" namespace ns3 { @@ -41,10 +40,9 @@ class Node; /** * ::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 @@ public: 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 @@ public: * - 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); diff --git a/src/node/l3-demux.cc b/src/node/l3-demux.cc index ef4274c22..1d7172bde 100644 --- a/src/node/l3-demux.cc +++ b/src/node/l3-demux.cc @@ -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 @@ L3Demux::~L3Demux() 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) - { - Insert(*i->second); - } -} -L3Demux* L3Demux::Copy() const -{ // Return a copy of this protocol manager - return new L3Demux(*this); +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) + { + copy->Insert(*i->second); + } + + 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; } diff --git a/src/node/l3-demux.h b/src/node/l3-demux.h index c1e7576ec..9a8b07cd9 100644 --- a/src/node/l3-demux.h +++ b/src/node/l3-demux.h @@ -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 @@ public: private: typedef std::map L3Map_t; + Node *m_node; L3Map_t m_protocols; }; diff --git a/src/node/l3-protocol.cc b/src/node/l3-protocol.cc index f4f7da6ae..241647bb9 100644 --- a/src/node/l3-protocol.cc +++ b/src/node/l3-protocol.cc @@ -31,10 +31,6 @@ L3Protocol::L3Protocol(int protocolNumber, int version) : m_protocolNumber (protocolNumber), m_version (version) {} -L3Protocol::L3Protocol (L3Protocol const &o) - : m_protocolNumber (o.m_protocolNumber), - m_version (o.m_version) -{} L3Protocol::~L3Protocol () {} diff --git a/src/node/l3-protocol.h b/src/node/l3-protocol.h index 8148b3c73..eebb08a5e 100644 --- a/src/node/l3-protocol.h +++ b/src/node/l3-protocol.h @@ -29,6 +29,7 @@ namespace ns3 { class Packet; class NetDevice; +class Node; /** @@ -37,13 +38,12 @@ class NetDevice; 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 diff --git a/src/node/net-device-list.h b/src/node/net-device-list.h index dfa4f4332..7adf4fb1e 100644 --- a/src/node/net-device-list.h +++ b/src/node/net-device-list.h @@ -25,19 +25,17 @@ #define NET_DEVICE_LIST_H #include -#include "capability.h" namespace ns3{ class NetDevice; -class NetDeviceList : public Capability { +class NetDeviceList { public: typedef std::vector::iterator Iterator; NetDeviceList(); ~NetDeviceList(); - NetDeviceList* Copy() const; // Manage the list NetDevice* Add(const NetDevice&); // Add a new netdevice NetDeviceList::Iterator Begin () const; diff --git a/src/node/node.cc b/src/node/node.cc index fe0d383c9..c96233d61 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -62,5 +62,17 @@ Node::GetNetDeviceList() const return 0; } +Ipv4 * +Node::GetIpv4 (void) const +{ + return 0; +} +Udp * +Node::GetUdp (void) const +{ + return 0; +} + + }//namespace ns3 diff --git a/src/node/node.h b/src/node/node.h index 59e129656..35283b287 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -96,6 +96,8 @@ namespace ns3 { class L3Demux; class Ipv4L4Demux; class NetDeviceList; +class Ipv4; +class Udp; class Node { public: @@ -118,6 +120,8 @@ public: 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 diff --git a/src/node/udp-ipv4-l4-protocol.cc b/src/node/udp-ipv4-l4-protocol.cc new file mode 100644 index 000000000..d8e04a6dd --- /dev/null +++ b/src/node/udp-ipv4-l4-protocol.cc @@ -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 +// + +// 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 diff --git a/src/node/udp-ipv4-l4-protocol.h b/src/node/udp-ipv4-l4-protocol.h new file mode 100644 index 000000000..071b3cf26 --- /dev/null +++ b/src/node/udp-ipv4-l4-protocol.h @@ -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 +// + +// 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 +#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 */ diff --git a/src/node/udp-socket.cc b/src/node/udp-socket.cc index e8950a2b4..2ac0b4681 100644 --- a/src/node/udp-socket.cc +++ b/src/node/udp-socket.cc @@ -161,12 +161,7 @@ UdpSocket::ForwardUp (Packet &p, Ipv4Address saddr, uint16_t sport) Udp * UdpSocket::GetUdp (void) const { - if (m_node->GetIpv4L4Demux () != 0) - { - // udp protocol number - return static_cast (m_node->GetIpv4L4Demux ()->Lookup (17)); - } - return 0; + return m_node->GetUdp (); } }//namespace ns3 diff --git a/src/node/udp.cc b/src/node/udp.cc index 9b3127174..db8434a1f 100644 --- a/src/node/udp.cc +++ b/src/node/udp.cc @@ -36,17 +36,9 @@ namespace ns3 { 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 ()) {} -Udp::Udp (Udp const &o) - : Ipv4L4Protocol (UDP_PROTOCOL, 2), - m_node (o.m_node), - m_endPoints (new Ipv4EndPointDemux ()) -{ - // we do not copy the udp endpoints on purpose. -} Udp::~Udp () { @@ -82,9 +74,9 @@ Udp::Allocate (Ipv4Address localAddress, uint16_t localPort, } Udp* -Udp::Copy() const +Udp::Copy(Node *node) const { - return new Udp (*this); + return new Udp (node); } void @@ -121,14 +113,10 @@ Udp::Send (Packet packet, packet.Add (udpHeader); - // Send to ipv4 layer. - if (m_node->GetL3Demux () != 0 ) + Ipv4 *ipv4 = m_node->GetIpv4 (); + if (ipv4 != 0) { - Ipv4 *ipv4 = static_cast (m_node->GetL3Demux ()->Lookup (0x0800)); - if (ipv4 != 0) - { - ipv4->Send (packet, saddr, daddr, UDP_PROTOCOL); - } + ipv4->Send (packet, saddr, daddr, UDP_PROTOCOL); } } diff --git a/src/node/udp.h b/src/node/udp.h index 9b1bfc9fb..f11877528 100644 --- a/src/node/udp.h +++ b/src/node/udp.h @@ -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 @@ namespace ns3 { 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 @@ public: 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;