From de5acedb80da45a9c774cfd16751c5d22fefbd3e Mon Sep 17 00:00:00 2001 From: Tommaso Pecorella Date: Sat, 30 Nov 2013 12:38:22 +0100 Subject: [PATCH] Removed useless class from Internet tests --- src/internet/test/error-channel.cc | 16 +- src/internet/test/error-channel.h | 12 +- src/internet/test/error-net-device.cc | 256 ------------------- src/internet/test/error-net-device.h | 117 --------- src/internet/test/ipv4-fragmentation-test.cc | 10 +- src/internet/test/ipv6-fragmentation-test.cc | 10 +- src/internet/wscript | 1 - 7 files changed, 24 insertions(+), 398 deletions(-) delete mode 100644 src/internet/test/error-net-device.cc delete mode 100644 src/internet/test/error-net-device.h diff --git a/src/internet/test/error-channel.cc b/src/internet/test/error-channel.cc index 69d4107b7..e4227a45f 100644 --- a/src/internet/test/error-channel.cc +++ b/src/internet/test/error-channel.cc @@ -18,7 +18,7 @@ * Author: Tommaso Pecorella */ #include "error-channel.h" -#include "error-net-device.h" +#include "ns3/simple-net-device.h" #include "ns3/simulator.h" #include "ns3/packet.h" #include "ns3/node.h" @@ -63,12 +63,12 @@ ErrorChannel::SetJumpingMode(bool mode) void ErrorChannel::Send (Ptr p, uint16_t protocol, Mac48Address to, Mac48Address from, - Ptr sender) + Ptr sender) { NS_LOG_FUNCTION (p << protocol << to << from << sender); - for (std::vector >::const_iterator i = m_devices.begin (); i != m_devices.end (); ++i) + for (std::vector >::const_iterator i = m_devices.begin (); i != m_devices.end (); ++i) { - Ptr tmp = *i; + Ptr tmp = *i; if (tmp == sender) { continue; @@ -76,20 +76,20 @@ ErrorChannel::Send (Ptr p, uint16_t protocol, if( !jumping || jumpingState%2 ) { Simulator::ScheduleWithContext (tmp->GetNode ()->GetId (), Seconds (0), - &ErrorNetDevice::Receive, tmp, p->Copy (), protocol, to, from); + &SimpleNetDevice::Receive, tmp, p->Copy (), protocol, to, from); jumpingState++; } else { Simulator::ScheduleWithContext (tmp->GetNode ()->GetId (), jumpingTime, - &ErrorNetDevice::Receive, tmp, p->Copy (), protocol, to, from); + &SimpleNetDevice::Receive, tmp, p->Copy (), protocol, to, from); jumpingState++; } } } void -ErrorChannel::Add (Ptr device) +ErrorChannel::Add (Ptr device) { m_devices.push_back (device); } @@ -105,7 +105,7 @@ ErrorChannel::GetDevice (uint32_t i) const return m_devices[i]; } -NS_OBJECT_ENSURE_REGISTERED (ErrorModel) +NS_OBJECT_ENSURE_REGISTERED (BinaryErrorModel) ; TypeId BinaryErrorModel::GetTypeId (void) diff --git a/src/internet/test/error-channel.h b/src/internet/test/error-channel.h index ae41dad3b..18457f38c 100644 --- a/src/internet/test/error-channel.h +++ b/src/internet/test/error-channel.h @@ -20,7 +20,7 @@ #ifndef ERROR_CHANNEL_H #define ERROR_CHANNEL_H -#include "ns3/channel.h" +#include "ns3/simple-channel.h" #include "ns3/error-model.h" #include "ns3/mac48-address.h" #include "ns3/nstime.h" @@ -28,23 +28,23 @@ namespace ns3 { -class ErrorNetDevice; +class SimpleNetDevice; class Packet; /** * \ingroup channel * \brief A Error channel, introducing deterministic delays on even/odd packets. Used for testing */ -class ErrorChannel : public Channel +class ErrorChannel : public SimpleChannel { public: static TypeId GetTypeId (void); ErrorChannel (); void Send (Ptr p, uint16_t protocol, Mac48Address to, Mac48Address from, - Ptr sender); + Ptr sender); - void Add (Ptr device); + void Add (Ptr device); // inherited from ns3::Channel virtual uint32_t GetNDevices (void) const; @@ -63,7 +63,7 @@ public: void SetJumpingMode(bool mode); private: - std::vector > m_devices; + std::vector > m_devices; Time jumpingTime; uint8_t jumpingState; bool jumping; diff --git a/src/internet/test/error-net-device.cc b/src/internet/test/error-net-device.cc deleted file mode 100644 index 649f7aaf6..000000000 --- a/src/internet/test/error-net-device.cc +++ /dev/null @@ -1,256 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2011 Universita' di Firenze, Italy - * - * 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: Tommaso Pecorella - */ -#include "error-net-device.h" -#include "error-channel.h" -#include "ns3/node.h" -#include "ns3/packet.h" -#include "ns3/log.h" -#include "ns3/pointer.h" -#include "ns3/error-model.h" -#include "ns3/trace-source-accessor.h" - -NS_LOG_COMPONENT_DEFINE ("ErrorNetDevice"); - -namespace ns3 { - -NS_OBJECT_ENSURE_REGISTERED (ErrorNetDevice) - ; - -TypeId -ErrorNetDevice::GetTypeId (void) -{ - static TypeId tid = TypeId ("ns3::ErrorNetDevice") - .SetParent () - .AddConstructor () - .AddAttribute ("ReceiveErrorModel", - "The receiver error model used to simulate packet loss", - PointerValue (), - MakePointerAccessor (&ErrorNetDevice::m_receiveErrorModel), - MakePointerChecker ()) - .AddTraceSource ("PhyRxDrop", - "Trace source indicating a packet has been dropped by the device during reception", - MakeTraceSourceAccessor (&ErrorNetDevice::m_phyRxDropTrace)) - ; - return tid; -} - -ErrorNetDevice::ErrorNetDevice () - : m_channel (0), - m_node (0), - m_mtu (0xffff), - m_ifIndex (0) -{} - -void -ErrorNetDevice::Receive (Ptr packet, uint16_t protocol, - Mac48Address to, Mac48Address from) -{ - NS_LOG_FUNCTION (packet << protocol << to << from << *packet); - NetDevice::PacketType packetType; - - if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) ) - { - m_phyRxDropTrace (packet); - return; - } - - if (to == m_address) - { - packetType = NetDevice::PACKET_HOST; - } - else if (to.IsBroadcast ()) - { - packetType = NetDevice::PACKET_HOST; - } - else if (to.IsGroup ()) - { - packetType = NetDevice::PACKET_MULTICAST; - } - else - { - packetType = NetDevice::PACKET_OTHERHOST; - } - m_rxCallback (this, packet, protocol, from); - if (!m_promiscCallback.IsNull ()) - { - m_promiscCallback (this, packet, protocol, from, to, packetType); - } -} - -void -ErrorNetDevice::SetChannel (Ptr channel) -{ - m_channel = channel; - m_channel->Add (this); -} - -void -ErrorNetDevice::SetReceiveErrorModel (Ptr em) -{ - m_receiveErrorModel = em; -} - -void -ErrorNetDevice::SetIfIndex(const uint32_t index) -{ - m_ifIndex = index; -} -uint32_t -ErrorNetDevice::GetIfIndex(void) const -{ - return m_ifIndex; -} -Ptr -ErrorNetDevice::GetChannel (void) const -{ - return m_channel; -} -void -ErrorNetDevice::SetAddress (Address address) -{ - m_address = Mac48Address::ConvertFrom(address); -} -Address -ErrorNetDevice::GetAddress (void) const -{ - // - // Implicit conversion from Mac48Address to Address - // - return m_address; -} -bool -ErrorNetDevice::SetMtu (const uint16_t mtu) -{ - m_mtu = mtu; - return true; -} -uint16_t -ErrorNetDevice::GetMtu (void) const -{ - return m_mtu; -} -bool -ErrorNetDevice::IsLinkUp (void) const -{ - return true; -} -void -ErrorNetDevice::AddLinkChangeCallback (Callback callback) -{} -bool -ErrorNetDevice::IsBroadcast (void) const -{ - return true; -} -Address -ErrorNetDevice::GetBroadcast (void) const -{ - return Mac48Address ("ff:ff:ff:ff:ff:ff"); -} -bool -ErrorNetDevice::IsMulticast (void) const -{ - return false; -} -Address -ErrorNetDevice::GetMulticast (Ipv4Address multicastGroup) const -{ - return Mac48Address::GetMulticast (multicastGroup); -} - -Address ErrorNetDevice::GetMulticast (Ipv6Address addr) const -{ - return Mac48Address::GetMulticast (addr); -} - -bool -ErrorNetDevice::IsPointToPoint (void) const -{ - return false; -} - -bool -ErrorNetDevice::IsBridge (void) const -{ - return false; -} - -bool -ErrorNetDevice::Send(Ptr packet, const Address& dest, uint16_t protocolNumber) -{ - NS_LOG_FUNCTION (packet << dest << protocolNumber << *packet); - Mac48Address to = Mac48Address::ConvertFrom (dest); - m_channel->Send (packet, protocolNumber, to, m_address, this); - return true; -} -bool -ErrorNetDevice::SendFrom(Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber) -{ - NS_LOG_FUNCTION (packet << source << dest << protocolNumber << *packet); - Mac48Address to = Mac48Address::ConvertFrom (dest); - Mac48Address from = Mac48Address::ConvertFrom (source); - m_channel->Send (packet, protocolNumber, to, from, this); - return true; -} - -Ptr -ErrorNetDevice::GetNode (void) const -{ - return m_node; -} -void -ErrorNetDevice::SetNode (Ptr node) -{ - m_node = node; -} -bool -ErrorNetDevice::NeedsArp (void) const -{ - return false; -} -void -ErrorNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb) -{ - m_rxCallback = cb; -} - -void -ErrorNetDevice::DoDispose (void) -{ - m_channel = 0; - m_node = 0; - m_receiveErrorModel = 0; - NetDevice::DoDispose (); -} - - -void -ErrorNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb) -{ - m_promiscCallback = cb; -} - -bool -ErrorNetDevice::SupportsSendFrom (void) const -{ - return true; -} - -} // namespace ns3 diff --git a/src/internet/test/error-net-device.h b/src/internet/test/error-net-device.h deleted file mode 100644 index bc8206bbc..000000000 --- a/src/internet/test/error-net-device.h +++ /dev/null @@ -1,117 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2011 Universita' di Firenze, Italy - * - * 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: Tommaso Pecorella - */ -#ifndef ERROR_NET_DEVICE_H -#define ERROR_NET_DEVICE_H - -#include "ns3/net-device.h" -#include "ns3/mac48-address.h" -#include -#include -#include "ns3/traced-callback.h" - -namespace ns3 { - -class ErrorChannel; -class Node; -class ErrorModel; - -/** - * \ingroup netdevice - * - * This device does not have a helper and assumes 48-bit mac addressing; - * the default address assigned to each device is zero, so you must - * assign a real address to use it. There is also the possibility to - * add an ErrorModel if you want to force losses on the device. - * - * \brief Error net device for Error things and testing - */ -class ErrorNetDevice : public NetDevice -{ -public: - static TypeId GetTypeId (void); - ErrorNetDevice (); - - void Receive (Ptr packet, uint16_t protocol, Mac48Address to, Mac48Address from); - void SetChannel (Ptr channel); - - /** - * Attach a receive ErrorModel to the ErrorNetDevice. - * - * The ErrorNetDevice may optionally include an ErrorModel in - * the packet receive chain. - * - * \see ErrorModel - * \param em Ptr to the ErrorModel. - */ - void SetReceiveErrorModel(Ptr em); - - // inherited from NetDevice base class. - virtual void SetIfIndex(const uint32_t index); - virtual uint32_t GetIfIndex(void) const; - virtual Ptr GetChannel (void) const; - virtual void SetAddress (Address address); - virtual Address GetAddress (void) const; - virtual bool SetMtu (const uint16_t mtu); - virtual uint16_t GetMtu (void) const; - virtual bool IsLinkUp (void) const; - virtual void AddLinkChangeCallback (Callback callback); - virtual bool IsBroadcast (void) const; - virtual Address GetBroadcast (void) const; - virtual bool IsMulticast (void) const; - virtual Address GetMulticast (Ipv4Address multicastGroup) const; - virtual bool IsPointToPoint (void) const; - virtual bool IsBridge (void) const; - virtual bool Send(Ptr packet, const Address& dest, uint16_t protocolNumber); - virtual bool SendFrom(Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber); - virtual Ptr GetNode (void) const; - virtual void SetNode (Ptr node); - virtual bool NeedsArp (void) const; - virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb); - - virtual Address GetMulticast (Ipv6Address addr) const; - - virtual void SetPromiscReceiveCallback (PromiscReceiveCallback cb); - virtual bool SupportsSendFrom (void) const; - -protected: - virtual void DoDispose (void); -private: - Ptr m_channel; - NetDevice::ReceiveCallback m_rxCallback; - NetDevice::PromiscReceiveCallback m_promiscCallback; - Ptr m_node; - uint16_t m_mtu; - uint32_t m_ifIndex; - Mac48Address m_address; - Ptr m_receiveErrorModel; - /** - * The trace source fired when the phy layer drops a packet it has received - * due to the error model being active. Although ErrorNetDevice doesn't - * really have a Phy model, we choose this trace source name for alignment - * with other trace sources. - * - * \see class CallBackTraceSource - */ - TracedCallback > m_phyRxDropTrace; -}; - -} // namespace ns3 - -#endif /* Error_NET_DEVICE_H */ diff --git a/src/internet/test/ipv4-fragmentation-test.cc b/src/internet/test/ipv4-fragmentation-test.cc index 153df7e27..9d5fef453 100644 --- a/src/internet/test/ipv4-fragmentation-test.cc +++ b/src/internet/test/ipv4-fragmentation-test.cc @@ -29,7 +29,7 @@ #include "ns3/udp-socket-factory.h" #include "ns3/simulator.h" #include "error-channel.h" -#include "error-net-device.h" +#include "ns3/simple-net-device.h" #include "ns3/drop-tail-queue.h" #include "ns3/socket.h" #include "ns3/udp-socket.h" @@ -264,10 +264,10 @@ Ipv4FragmentationTest::DoRun (void) // Receiver Node Ptr serverNode = CreateObject (); AddInternetStack (serverNode); - Ptr serverDev; + Ptr serverDev; Ptr serverDevErrorModel = CreateObject (); { - serverDev = CreateObject (); + serverDev = CreateObject (); serverDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ())); serverDev->SetMtu(1500); serverDev->SetReceiveErrorModel(serverDevErrorModel); @@ -284,10 +284,10 @@ Ipv4FragmentationTest::DoRun (void) // Sender Node Ptr clientNode = CreateObject (); AddInternetStack (clientNode); - Ptr clientDev; + Ptr clientDev; Ptr clientDevErrorModel = CreateObject (); { - clientDev = CreateObject (); + clientDev = CreateObject (); clientDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ())); clientDev->SetMtu(1000); clientDev->SetReceiveErrorModel(clientDevErrorModel); diff --git a/src/internet/test/ipv6-fragmentation-test.cc b/src/internet/test/ipv6-fragmentation-test.cc index 2c76e0c12..9c9a35a5b 100644 --- a/src/internet/test/ipv6-fragmentation-test.cc +++ b/src/internet/test/ipv6-fragmentation-test.cc @@ -31,7 +31,7 @@ #include "ns3/udp-socket-factory.h" #include "ns3/simulator.h" #include "error-channel.h" -#include "error-net-device.h" +#include "ns3/simple-net-device.h" #include "ns3/drop-tail-queue.h" #include "ns3/socket.h" #include "ns3/udp-socket.h" @@ -270,10 +270,10 @@ Ipv6FragmentationTest::DoRun (void) // Receiver Node Ptr serverNode = CreateObject (); AddInternetStack (serverNode); - Ptr serverDev; + Ptr serverDev; Ptr serverDevErrorModel = CreateObject (); { - serverDev = CreateObject (); + serverDev = CreateObject (); serverDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ())); serverDev->SetMtu (1500); serverDev->SetReceiveErrorModel (serverDevErrorModel); @@ -290,10 +290,10 @@ Ipv6FragmentationTest::DoRun (void) // Sender Node Ptr clientNode = CreateObject (); AddInternetStack (clientNode); - Ptr clientDev; + Ptr clientDev; Ptr clientDevErrorModel = CreateObject (); { - clientDev = CreateObject (); + clientDev = CreateObject (); clientDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ())); clientDev->SetMtu (1000); clientDev->SetReceiveErrorModel (clientDevErrorModel); diff --git a/src/internet/wscript b/src/internet/wscript index 8376db7e7..9c180220f 100644 --- a/src/internet/wscript +++ b/src/internet/wscript @@ -206,7 +206,6 @@ def build(bld): 'test/ipv4-fragmentation-test.cc', 'test/ipv4-forwarding-test.cc', 'test/error-channel.cc', - 'test/error-net-device.cc', 'test/ipv4-test.cc', 'test/ipv6-extension-header-test-suite.cc', 'test/ipv6-list-routing-test-suite.cc',