From e4166af2948d109e4cc0292e7b7216171ff800ba Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sat, 17 Feb 2007 09:28:02 +0100 Subject: [PATCH] remove Ipv4L3Protocol class. --- SConstruct | 4 +-- src/node/arp-ipv4-interface.cc | 3 +- src/node/internet-node.cc | 12 +++----- src/node/internet-node.h | 1 - src/node/ipv4-l3-protocol.cc | 56 ---------------------------------- src/node/ipv4-l3-protocol.h | 47 ---------------------------- src/node/ipv4.cc | 5 ++- src/node/ipv4.h | 10 ++++-- 8 files changed, 18 insertions(+), 120 deletions(-) delete mode 100644 src/node/ipv4-l3-protocol.cc delete mode 100644 src/node/ipv4-l3-protocol.h diff --git a/SConstruct b/SConstruct index 83d17ce55..3c4a42dba 100644 --- a/SConstruct +++ b/SConstruct @@ -169,7 +169,6 @@ node.add_sources ([ 'drop-tail.cc', 'l3-demux.cc', 'l3-protocol.cc', - 'ipv4-l3-protocol.cc', 'ipv4-l4-demux.cc', 'ipv4-l4-protocol.cc', 'udp-ipv4-l4-protocol.cc', @@ -206,14 +205,12 @@ node.add_headers ([ 'udp.h', 'ipv4-l4-protocol.h', 'udp-ipv4-l4-protocol.h', - 'ipv4-l3-protocol.h', 'arp-l3-protocol.h', 'arp-header.h', 'arp-cache-cache.h', 'arp.h', 'ipv4-loopback-interface.h', 'l3-demux.h', - 'l3-protocol.h', 'ipv4-l4-demux.h', 'net-device-list.h', 'llc-snap-header.h', @@ -233,6 +230,7 @@ node.add_inst_headers ([ 'ipv4-interface.h', 'mac-address.h', 'ipv4.h', + 'l3-protocol.h', 'ipv4-route.h', ]) diff --git a/src/node/arp-ipv4-interface.cc b/src/node/arp-ipv4-interface.cc index 391903e7a..3287d7dd6 100644 --- a/src/node/arp-ipv4-interface.cc +++ b/src/node/arp-ipv4-interface.cc @@ -26,6 +26,7 @@ #include "arp.h" #include "node.h" #include "net-device.h" +#include "ipv4.h" namespace ns3 { @@ -44,7 +45,7 @@ ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest) bool found = arp->Lookup (p, dest, GetDevice (), &hardwareDestination); if (found) { - GetDevice ()->Send (p, hardwareDestination, 0x0800 /* XXX */); + GetDevice ()->Send (p, hardwareDestination, Ipv4::PROT_NUMBER); } } diff --git a/src/node/internet-node.cc b/src/node/internet-node.cc index 4909f1035..43c1ffab1 100644 --- a/src/node/internet-node.cc +++ b/src/node/internet-node.cc @@ -23,7 +23,6 @@ #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" @@ -42,9 +41,8 @@ InternetNode::InternetNode() m_l3Demux = new L3Demux(this); m_ipv4L4Demux = new Ipv4L4Demux(this); m_udp = new Udp (this); - m_ipv4 = new Ipv4 (this); m_arp = new Arp (this); - m_l3Demux->Insert (Ipv4L3Protocol (this)); + m_l3Demux->Insert (Ipv4 (this)); m_l3Demux->Insert (ArpL3Protocol (this)); m_ipv4L4Demux->Insert (UdpIpv4L4Protocol (this)); SetupLoopback (); @@ -56,7 +54,6 @@ InternetNode::InternetNode (InternetNode const &o) m_l3Demux = o.m_l3Demux->Copy (this); m_ipv4L4Demux = o.m_ipv4L4Demux->Copy (this); m_udp = o.m_udp->Copy (this); - m_ipv4 = o.m_ipv4->Copy (this); m_arp = o.m_arp->Copy (this); SetupLoopback (); } @@ -67,7 +64,6 @@ InternetNode::~InternetNode () delete m_l3Demux; delete m_ipv4L4Demux; delete m_udp; - delete m_ipv4; delete m_arp; } @@ -77,8 +73,8 @@ InternetNode::SetupLoopback (void) Ipv4LoopbackInterface * interface = new Ipv4LoopbackInterface (this); interface->SetAddress (Ipv4Address::GetLoopback ()); interface->SetNetworkMask (Ipv4Mask::GetLoopback ()); - uint32_t index = m_ipv4->AddInterface (interface); - m_ipv4->AddHostRouteTo (Ipv4Address::GetLoopback (), index); + uint32_t index = GetIpv4 ()->AddInterface (interface); + GetIpv4 ()->AddHostRouteTo (Ipv4Address::GetLoopback (), index); interface->SetUp (); } @@ -112,7 +108,7 @@ InternetNode::GetIpv4L4Demux() const Ipv4 * InternetNode::GetIpv4 (void) const { - return m_ipv4; + return static_cast (m_l3Demux->Lookup (Ipv4::PROT_NUMBER)); } Udp * InternetNode::GetUdp (void) const diff --git a/src/node/internet-node.h b/src/node/internet-node.h index a8fe8f696..b6e2d29cb 100644 --- a/src/node/internet-node.h +++ b/src/node/internet-node.h @@ -52,7 +52,6 @@ private: NetDeviceList* m_netDevices; L3Demux* m_l3Demux; Ipv4L4Demux* m_ipv4L4Demux; - Ipv4 * m_ipv4; Udp * m_udp; Arp * m_arp; }; diff --git a/src/node/ipv4-l3-protocol.cc b/src/node/ipv4-l3-protocol.cc deleted file mode 100644 index 9cd5f5e2c..000000000 --- a/src/node/ipv4-l3-protocol.cc +++ /dev/null @@ -1,56 +0,0 @@ -// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// All rights reserved. -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License version 2 as -// published by the Free Software Foundation; -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// Author: George F. Riley -// - -// 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 diff --git a/src/node/ipv4-l3-protocol.h b/src/node/ipv4-l3-protocol.h deleted file mode 100644 index 90388446f..000000000 --- a/src/node/ipv4-l3-protocol.h +++ /dev/null @@ -1,47 +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 -// - -// 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 */ diff --git a/src/node/ipv4.cc b/src/node/ipv4.cc index 83947b3db..d996467f7 100644 --- a/src/node/ipv4.cc +++ b/src/node/ipv4.cc @@ -36,8 +36,11 @@ NS_DEBUG_COMPONENT_DEFINE ("Ipv4"); namespace ns3 { +const uint16_t Ipv4::PROT_NUMBER = 0x0800; + Ipv4::Ipv4(Node *node) - : m_nInterfaces (0), + : L3Protocol (PROT_NUMBER, 4), + m_nInterfaces (0), m_defaultTtl (64), m_identification (0), m_defaultRoute (0), diff --git a/src/node/ipv4.h b/src/node/ipv4.h index ff7f86523..59fced43c 100644 --- a/src/node/ipv4.h +++ b/src/node/ipv4.h @@ -25,6 +25,7 @@ #include #include #include "ipv4-address.h" +#include "l3-protocol.h" namespace ns3 { @@ -40,8 +41,11 @@ class Node; /** * ::Send is always defined in subclasses. */ -class Ipv4 { +class Ipv4 : public L3Protocol +{ public: + static const uint16_t PROT_NUMBER; + Ipv4(Node *node); virtual ~Ipv4 (); @@ -88,7 +92,7 @@ public: Ipv4Interface *FindInterfaceForDevice (NetDevice const*device); - Ipv4* Copy(Node *node) const; + virtual Ipv4* Copy(Node *node) const; /** * Lower layer calls this method after calling L3Demux::Lookup * The ARP subclass needs to know from which NetDevice this @@ -96,7 +100,7 @@ public: * - implement a per-NetDevice ARP cache * - send back arp replies on the right device */ - void Receive(Packet& p, NetDevice &device); + virtual void Receive(Packet& p, NetDevice &device); void Send (Packet const &packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol);