Bug 1941 - [aodv] Remove unnecessary dependency on Application module

This commit is contained in:
Tommaso Pecorella
2015-07-03 18:12:25 +02:00
parent 3c4d250b4b
commit 435859a64b
12 changed files with 192 additions and 96 deletions

View File

@@ -37,11 +37,14 @@ namespace aodv
// Tests
//-----------------------------------------------------------------------------
/// Unit test for id cache
struct IdCacheTest : public TestCase
class IdCacheTest : public TestCase
{
public:
IdCacheTest () : TestCase ("Id Cache"), cache (Seconds (10))
{}
virtual void DoRun ();
private:
void CheckTimeout1 ();
void CheckTimeout2 ();
void CheckTimeout3 ();
@@ -93,7 +96,7 @@ IdCacheTest::CheckTimeout3 ()
class IdCacheTestSuite : public TestSuite
{
public:
IdCacheTestSuite () : TestSuite ("routing-id-cache", UNIT)
IdCacheTestSuite () : TestSuite ("aodv-routing-id-cache", UNIT)
{
AddTestCase (new IdCacheTest, TestCase::QUICK);
}

View File

@@ -20,7 +20,6 @@
#include "aodv-regression.h"
#include "bug-772.h"
#include "loopback.h"
#include "ns3/simulator.h"
#include "ns3/mobility-helper.h"
@@ -32,19 +31,18 @@
#include "ns3/internet-stack-helper.h"
#include "ns3/ipv4-address-helper.h"
#include "ns3/abort.h"
#include "ns3/udp-echo-helper.h"
#include "ns3/mobility-model.h"
#include "ns3/pcap-file.h"
#include "ns3/aodv-helper.h"
#include "ns3/v4ping-helper.h"
#include "ns3/nqos-wifi-mac-helper.h"
#include "ns3/config.h"
#include "ns3/pcap-test.h"
#include "ns3/rng-seed-manager.h"
#include "ns3/icmpv4.h"
#include <sstream>
using namespace ns3;
using namespace aodv;
//-----------------------------------------------------------------------------
// Test suite
//-----------------------------------------------------------------------------
@@ -56,17 +54,12 @@ public:
SetDataDir (NS_TEST_SOURCEDIR);
// General RREQ-RREP-RRER test case
AddTestCase (new ChainRegressionTest ("aodv-chain-regression-test"), TestCase::QUICK);
/// \internal
/// \bugid{606} test case, should crash if bug is not fixed
// \bugid{606} test case, should crash if bug is not fixed
AddTestCase (new ChainRegressionTest ("bug-606-test", Seconds (10), 3, Seconds (1)), TestCase::QUICK);
/// \internal
/// \bugid{772} UDP test case
// \bugid{772} UDP test case
AddTestCase (new Bug772ChainTest ("udp-chain-test", "ns3::UdpSocketFactory", Seconds (3), 10), TestCase::QUICK);
/// \internal
/// \bugid{772} TCP test case
// \bugid{772} TCP test case
AddTestCase (new Bug772ChainTest ("tcp-chain-test", "ns3::TcpSocketFactory", Seconds (3), 10), TestCase::QUICK);
// Ping loopback test case
AddTestCase (new LoopbackTestCase (), TestCase::QUICK);
}
} g_aodvRegressionTestSuite;
@@ -81,7 +74,8 @@ ChainRegressionTest::ChainRegressionTest (const char * const prefix, Time t, uin
m_time (t),
m_size (size),
m_step (120),
m_arpAliveTimeout (arpAliveTimeout)
m_arpAliveTimeout (arpAliveTimeout),
m_seq (0)
{
}
@@ -90,6 +84,35 @@ ChainRegressionTest::~ChainRegressionTest ()
delete m_nodes;
}
void
ChainRegressionTest::SendPing ()
{
if (Simulator::Now () >= m_time)
{
return;
}
Ptr<Packet> p = Create<Packet> ();
Icmpv4Echo echo;
echo.SetSequenceNumber (m_seq);
m_seq++;
echo.SetIdentifier (0);
Ptr<Packet> dataPacket = Create<Packet> (56);
echo.SetData (dataPacket);
p->AddHeader (echo);
Icmpv4Header header;
header.SetType (Icmpv4Header::ECHO);
header.SetCode (0);
if (Node::ChecksumEnabled ())
{
header.EnableChecksum ();
}
p->AddHeader (header);
m_socket->Send (p, 0);
Simulator::Schedule (Seconds (1), &ChainRegressionTest::SendPing, this);
}
void
ChainRegressionTest::DoRun ()
{
@@ -173,11 +196,14 @@ ChainRegressionTest::CreateDevices ()
Ipv4InterfaceContainer interfaces = address.Assign (devices);
// 3. Setup ping
V4PingHelper ping (interfaces.GetAddress (m_size - 1));
ping.SetAttribute ("Verbose", BooleanValue (false)); // don't need verbose ping in regression test
ApplicationContainer p = ping.Install (m_nodes->Get (0));
p.Start (Seconds (0));
p.Stop (m_time);
m_socket = Socket::CreateSocket (m_nodes->Get (0), TypeId::LookupByName ("ns3::Ipv4RawSocketFactory"));
m_socket->SetAttribute ("Protocol", UintegerValue (1)); // icmp
InetSocketAddress src = InetSocketAddress (Ipv4Address::GetAny (), 0);
m_socket->Bind (src);
InetSocketAddress dst = InetSocketAddress (interfaces.GetAddress (m_size - 1), 0);
m_socket->Connect (dst);
SendPing ();
// 4. write PCAP
wifiPhy.EnablePcapAll (CreateTempDirFilename (m_prefix));

View File

@@ -23,6 +23,7 @@
#include "ns3/test.h"
#include "ns3/nstime.h"
#include "ns3/socket.h"
#include "ns3/node-container.h"
using namespace ns3;
@@ -177,6 +178,10 @@ private:
const double m_step;
/// ARP alive timeout
const Time m_arpAliveTimeout;
/// Socket
Ptr<Socket> m_socket;
/// Sequence number
uint16_t m_seq;
/// Create test topology
void CreateNodes ();
@@ -186,6 +191,8 @@ private:
void CheckResults ();
/// Go
void DoRun ();
/// Send one ping
void SendPing ();
};
#endif /* AODV_REGRESSION_H */

View File

@@ -33,17 +33,14 @@
#include "ns3/internet-stack-helper.h"
#include "ns3/ipv4-address-helper.h"
#include "ns3/abort.h"
#include "ns3/udp-echo-helper.h"
#include "ns3/mobility-model.h"
#include "ns3/pcap-file.h"
#include "ns3/aodv-helper.h"
#include "ns3/v4ping-helper.h"
#include "ns3/nqos-wifi-mac-helper.h"
#include "ns3/config.h"
#include "ns3/on-off-helper.h"
#include "ns3/inet-socket-address.h"
#include "ns3/data-rate.h"
#include "ns3/packet-sink-helper.h"
#include "ns3/pcap-test.h"
#include <sstream>
@@ -59,8 +56,8 @@ Bug772ChainTest::Bug772ChainTest (const char * const prefix, const char * const
m_proto (proto),
m_time (t),
m_size (size),
m_step (120)
{
m_step (120),
m_port (9){
}
Bug772ChainTest::~Bug772ChainTest ()
@@ -68,6 +65,17 @@ Bug772ChainTest::~Bug772ChainTest ()
delete m_nodes;
}
void
Bug772ChainTest::SendData (Ptr<Socket> socket)
{
if (Simulator::Now () < m_time)
{
socket->Send (Create<Packet> (1000));
Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0.125),
&Bug772ChainTest::SendData, this, socket);
}
}
void
Bug772ChainTest::DoRun ()
{
@@ -144,16 +152,17 @@ Bug772ChainTest::CreateDevices ()
Ipv4InterfaceContainer interfaces = address.Assign (devices);
// 3. Setup UDP source and sink
uint16_t port = 9; // Discard port (RFC 863)
OnOffHelper onoff (m_proto, Address (InetSocketAddress (interfaces.GetAddress (m_size-1), port)));
onoff.SetConstantRate (DataRate (64000));
onoff.SetAttribute ("PacketSize", UintegerValue (1000));
ApplicationContainer app = onoff.Install (m_nodes->Get (0));
app.Start (Seconds (1.0));
app.Stop (m_time);
PacketSinkHelper sink (m_proto, Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
app = sink.Install (m_nodes->Get (m_size - 1));
app.Start (Seconds (0.0));
m_sendSocket = Socket::CreateSocket (m_nodes->Get (0), TypeId::LookupByName (m_proto));
m_sendSocket->Bind ();
m_sendSocket->Connect (InetSocketAddress (interfaces.GetAddress (m_size-1), m_port));
m_sendSocket->SetAllowBroadcast (true);
Simulator::ScheduleWithContext (m_sendSocket->GetNode ()->GetId (), Seconds (1.0),
&Bug772ChainTest::SendData, this, m_sendSocket);
m_recvSocket = Socket::CreateSocket (m_nodes->Get (m_size - 1), TypeId::LookupByName (m_proto));
m_recvSocket->Bind (InetSocketAddress (Ipv4Address::GetAny (), m_port));
m_recvSocket->Listen ();
m_recvSocket->ShutdownSend ();
// 4. write PCAP on the first and last nodes only
wifiPhy.EnablePcap (CreateTempDirFilename (m_prefix), devices.Get (0));

View File

@@ -24,6 +24,7 @@
#include "ns3/test.h"
#include "ns3/nstime.h"
#include "ns3/node-container.h"
#include "ns3/socket.h"
using namespace ns3;
@@ -62,6 +63,8 @@ private:
const uint32_t m_size;
/// Chain step, meters
const double m_step;
/// port number
const uint16_t m_port;
/// Create test topology
void CreateNodes ();
@@ -71,6 +74,17 @@ private:
void CheckResults ();
/// Go
void DoRun ();
/// Receiving socket
Ptr<Socket> m_recvSocket;
/// Transmitting socket
Ptr<Socket> m_sendSocket;
/**
* Send data
* \param socket the sending socket
*/
void SendData (Ptr<Socket> socket);
};
#endif /* BUG_772_H */

View File

@@ -18,8 +18,10 @@
* Authors: Pavel Boyko <boyko@iitp.ru>
*/
#include "loopback.h"
#include "ns3/test.h"
#include "ns3/simulator.h"
#include "ns3/socket-factory.h"
#include "ns3/udp-socket-factory.h"
#include "ns3/mobility-helper.h"
#include "ns3/double.h"
#include "ns3/uinteger.h"
@@ -45,12 +47,66 @@ namespace ns3
namespace aodv
{
static uint32_t g_count (0);
static void
PingRtt (std::string context, Time rtt)
/**
* \ingroup aodv
*
* \brief AODV loopback UDP echo test case
*/
class LoopbackTestCase : public TestCase
{
g_count++;
uint32_t m_count; //!< number of packet received;
Ptr<Socket> m_txSocket;
Ptr<Socket> m_echoSocket;
Ptr<Socket> m_rxSocket;
uint16_t m_echoSendPort;
uint16_t m_echoReplyPort;
void SendData (Ptr<Socket> socket);
void ReceivePkt (Ptr<Socket> socket);
void EchoData (Ptr<Socket> socket);
public:
LoopbackTestCase ();
void DoRun ();
};
LoopbackTestCase::LoopbackTestCase () :
TestCase ("UDP Echo 127.0.0.1 test"), m_count (0)
{
m_echoSendPort = 1233;
m_echoReplyPort = 1234;
}
void LoopbackTestCase::ReceivePkt (Ptr<Socket> socket)
{
Ptr<Packet> receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max (), 0);
m_count ++;
}
void
LoopbackTestCase::EchoData (Ptr<Socket> socket)
{
Address from;
Ptr<Packet> receivedPacket = socket->RecvFrom (std::numeric_limits<uint32_t>::max (), 0, from);
Ipv4Address src = InetSocketAddress::ConvertFrom (from).GetIpv4 ();
Address to = InetSocketAddress (src, m_echoReplyPort);
receivedPacket->RemoveAllPacketTags ();
receivedPacket->RemoveAllByteTags ();
socket->SendTo (receivedPacket, 0, to);
}
void
LoopbackTestCase::SendData (Ptr<Socket> socket)
{
Address realTo = InetSocketAddress (Ipv4Address::GetLoopback (), m_echoSendPort);
socket->SendTo (Create<Packet> (123), 0, realTo);
Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (1.0),
&LoopbackTestCase::SendData, this, socket);
}
void
@@ -80,23 +136,49 @@ LoopbackTestCase::DoRun ()
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces = address.Assign (devices);
// Setup ping
Ptr<V4Ping> ping = CreateObject<V4Ping> ();
ping->SetAttribute ("Remote", Ipv4AddressValue (Ipv4Address::GetLoopback ()));
nodes.Get (0)->AddApplication (ping);
ping->SetStartTime (Seconds (0));
ping->SetStopTime (Seconds (4));
Names::Add ("ping", ping);
Config::Connect ("/Names/ping/Rtt", MakeCallback (&PingRtt));
// Setup echos
Ptr<SocketFactory> socketFactory = nodes.Get (0)->GetObject<UdpSocketFactory> ();
m_rxSocket = socketFactory->CreateSocket ();
m_rxSocket->Bind (InetSocketAddress (Ipv4Address::GetLoopback (), m_echoReplyPort));
m_rxSocket->SetRecvCallback (MakeCallback (&LoopbackTestCase::ReceivePkt, this));
m_echoSocket = socketFactory->CreateSocket ();
m_echoSocket->Bind (InetSocketAddress (Ipv4Address::GetLoopback (), m_echoSendPort));
m_echoSocket->SetRecvCallback (MakeCallback (&LoopbackTestCase::EchoData, this));
m_txSocket = socketFactory->CreateSocket ();
Simulator::ScheduleWithContext (m_txSocket->GetNode ()->GetId (), Seconds (1.0),
&LoopbackTestCase::SendData, this, m_txSocket);
// Run
Simulator::Stop (Seconds (5));
Simulator::Run ();
m_txSocket->Close ();
m_echoSocket->Close ();
m_rxSocket->Close ();
Simulator::Destroy ();
// Check that 4 packets delivered
NS_TEST_ASSERT_MSG_EQ (g_count, 4, "Exactly 4 ping replies must be delivered.");
NS_TEST_ASSERT_MSG_EQ (m_count, 4, "Exactly 4 echo replies must be delivered.");
}
//-----------------------------------------------------------------------------
// Test suite
//-----------------------------------------------------------------------------
class AodvLoopbackTestSuite : public TestSuite
{
public:
AodvLoopbackTestSuite () : TestSuite ("routing-aodv-loopback", SYSTEM)
{
SetDataDir (NS_TEST_SOURCEDIR);
// UDP Echo loopback test case
AddTestCase (new LoopbackTestCase (), TestCase::QUICK);
}
} g_aodvLoopbackTestSuite;
}
}

View File

@@ -1,45 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2010 IITP RAS
*
* 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
*
* Authors: Pavel Boyko <boyko@iitp.ru>
*/
#ifndef AODV_LOOPBACK_H
#define AODV_LOOPBACK_H
#include "ns3/test.h"
#include <string>
namespace ns3
{
namespace aodv
{
/**
* \ingroup aodv
*
* \brief AODV ping 127.0.0.1 test case
*/
struct LoopbackTestCase : public TestCase
{
LoopbackTestCase () : TestCase ("Ping 127.0.0.1 test") {}
/// Run test
void DoRun ();
};
}
}
#endif /* AODV_LOOPBACK_H */

View File

@@ -1,7 +1,7 @@
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
def build(bld):
module = bld.create_ns3_module('aodv', ['internet', 'wifi', 'applications'])
module = bld.create_ns3_module('aodv', ['internet', 'wifi'])
module.includes = '.'
module.source = [
'model/aodv-id-cache.cc',