Removed useless class from Internet tests

This commit is contained in:
Tommaso Pecorella
2013-11-30 12:38:22 +01:00
parent 649862bd07
commit de5acedb80
7 changed files with 24 additions and 398 deletions

View File

@@ -18,7 +18,7 @@
* Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
*/
#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<Packet> p, uint16_t protocol,
Mac48Address to, Mac48Address from,
Ptr<ErrorNetDevice> sender)
Ptr<SimpleNetDevice> sender)
{
NS_LOG_FUNCTION (p << protocol << to << from << sender);
for (std::vector<Ptr<ErrorNetDevice> >::const_iterator i = m_devices.begin (); i != m_devices.end (); ++i)
for (std::vector<Ptr<SimpleNetDevice> >::const_iterator i = m_devices.begin (); i != m_devices.end (); ++i)
{
Ptr<ErrorNetDevice> tmp = *i;
Ptr<SimpleNetDevice> tmp = *i;
if (tmp == sender)
{
continue;
@@ -76,20 +76,20 @@ ErrorChannel::Send (Ptr<Packet> 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<ErrorNetDevice> device)
ErrorChannel::Add (Ptr<SimpleNetDevice> 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)

View File

@@ -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<Packet> p, uint16_t protocol, Mac48Address to, Mac48Address from,
Ptr<ErrorNetDevice> sender);
Ptr<SimpleNetDevice> sender);
void Add (Ptr<ErrorNetDevice> device);
void Add (Ptr<SimpleNetDevice> device);
// inherited from ns3::Channel
virtual uint32_t GetNDevices (void) const;
@@ -63,7 +63,7 @@ public:
void SetJumpingMode(bool mode);
private:
std::vector<Ptr<ErrorNetDevice> > m_devices;
std::vector<Ptr<SimpleNetDevice> > m_devices;
Time jumpingTime;
uint8_t jumpingState;
bool jumping;

View File

@@ -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 <tommaso.pecorella@unifi.it>
*/
#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<NetDevice> ()
.AddConstructor<ErrorNetDevice> ()
.AddAttribute ("ReceiveErrorModel",
"The receiver error model used to simulate packet loss",
PointerValue (),
MakePointerAccessor (&ErrorNetDevice::m_receiveErrorModel),
MakePointerChecker<ErrorModel> ())
.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> 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<ErrorChannel> channel)
{
m_channel = channel;
m_channel->Add (this);
}
void
ErrorNetDevice::SetReceiveErrorModel (Ptr<ErrorModel> em)
{
m_receiveErrorModel = em;
}
void
ErrorNetDevice::SetIfIndex(const uint32_t index)
{
m_ifIndex = index;
}
uint32_t
ErrorNetDevice::GetIfIndex(void) const
{
return m_ifIndex;
}
Ptr<Channel>
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<void> 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> 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> 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<Node>
ErrorNetDevice::GetNode (void) const
{
return m_node;
}
void
ErrorNetDevice::SetNode (Ptr<Node> 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

View File

@@ -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 <tommaso.pecorella@unifi.it>
*/
#ifndef ERROR_NET_DEVICE_H
#define ERROR_NET_DEVICE_H
#include "ns3/net-device.h"
#include "ns3/mac48-address.h"
#include <stdint.h>
#include <string>
#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> packet, uint16_t protocol, Mac48Address to, Mac48Address from);
void SetChannel (Ptr<ErrorChannel> 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<ErrorModel> em);
// inherited from NetDevice base class.
virtual void SetIfIndex(const uint32_t index);
virtual uint32_t GetIfIndex(void) const;
virtual Ptr<Channel> 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<void> 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> packet, const Address& dest, uint16_t protocolNumber);
virtual bool SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
virtual Ptr<Node> GetNode (void) const;
virtual void SetNode (Ptr<Node> 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<ErrorChannel> m_channel;
NetDevice::ReceiveCallback m_rxCallback;
NetDevice::PromiscReceiveCallback m_promiscCallback;
Ptr<Node> m_node;
uint16_t m_mtu;
uint32_t m_ifIndex;
Mac48Address m_address;
Ptr<ErrorModel> 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<Ptr<const Packet> > m_phyRxDropTrace;
};
} // namespace ns3
#endif /* Error_NET_DEVICE_H */

View File

@@ -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<Node> serverNode = CreateObject<Node> ();
AddInternetStack (serverNode);
Ptr<ErrorNetDevice> serverDev;
Ptr<SimpleNetDevice> serverDev;
Ptr<BinaryErrorModel> serverDevErrorModel = CreateObject<BinaryErrorModel> ();
{
serverDev = CreateObject<ErrorNetDevice> ();
serverDev = CreateObject<SimpleNetDevice> ();
serverDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
serverDev->SetMtu(1500);
serverDev->SetReceiveErrorModel(serverDevErrorModel);
@@ -284,10 +284,10 @@ Ipv4FragmentationTest::DoRun (void)
// Sender Node
Ptr<Node> clientNode = CreateObject<Node> ();
AddInternetStack (clientNode);
Ptr<ErrorNetDevice> clientDev;
Ptr<SimpleNetDevice> clientDev;
Ptr<BinaryErrorModel> clientDevErrorModel = CreateObject<BinaryErrorModel> ();
{
clientDev = CreateObject<ErrorNetDevice> ();
clientDev = CreateObject<SimpleNetDevice> ();
clientDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
clientDev->SetMtu(1000);
clientDev->SetReceiveErrorModel(clientDevErrorModel);

View File

@@ -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<Node> serverNode = CreateObject<Node> ();
AddInternetStack (serverNode);
Ptr<ErrorNetDevice> serverDev;
Ptr<SimpleNetDevice> serverDev;
Ptr<BinaryErrorModel> serverDevErrorModel = CreateObject<BinaryErrorModel> ();
{
serverDev = CreateObject<ErrorNetDevice> ();
serverDev = CreateObject<SimpleNetDevice> ();
serverDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
serverDev->SetMtu (1500);
serverDev->SetReceiveErrorModel (serverDevErrorModel);
@@ -290,10 +290,10 @@ Ipv6FragmentationTest::DoRun (void)
// Sender Node
Ptr<Node> clientNode = CreateObject<Node> ();
AddInternetStack (clientNode);
Ptr<ErrorNetDevice> clientDev;
Ptr<SimpleNetDevice> clientDev;
Ptr<BinaryErrorModel> clientDevErrorModel = CreateObject<BinaryErrorModel> ();
{
clientDev = CreateObject<ErrorNetDevice> ();
clientDev = CreateObject<SimpleNetDevice> ();
clientDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
clientDev->SetMtu (1000);
clientDev->SetReceiveErrorModel (clientDevErrorModel);

View File

@@ -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',