[olsr] Two basic trace based OLSR regression tests added together with reference traces

This commit is contained in:
Pavel Boyko
2009-11-20 13:06:15 +03:00
parent 38a472a5a0
commit 6c5dad7368
11 changed files with 452 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 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>
*/
#include "hello-regression-test.h"
#include "ns3/simulator.h"
#include "ns3/random-variable.h"
#include "ns3/double.h"
#include "ns3/uinteger.h"
#include "ns3/string.h"
#include "ns3/pcap-file.h"
#include "ns3/olsr-helper.h"
#include "ns3/internet-stack-helper.h"
#include "ns3/point-to-point-helper.h"
#include "ns3/ipv4-address-helper.h"
#include "ns3/abort.h"
/// Set to true to rewrite reference traces, leave false to run regression tests
const bool WRITE_VECTORS = false;
namespace ns3
{
namespace olsr
{
const char * const HelloRegressionTest::PREFIX = "olsr-hello-regression-test";
HelloRegressionTest::HelloRegressionTest() :
TestCase ("Test OLSR Hello messages generation"),
m_time (Seconds (5))
{
}
HelloRegressionTest::~HelloRegressionTest()
{
}
bool
HelloRegressionTest::DoRun ()
{
SeedManager::SetSeed(12345);
CreateNodes ();
Simulator::Stop (m_time);
Simulator::Run ();
Simulator::Destroy ();
if (!WRITE_VECTORS) CheckResults ();
return GetErrorStatus ();
}
void
HelloRegressionTest::CreateNodes ()
{
// create 2 nodes
NodeContainer c;
c.Create (2);
// install TCP/IP & OLSR
OlsrHelper olsr;
InternetStackHelper internet;
internet.SetRoutingHelper (olsr);
internet.Install (c);
// create p2p channel & devices
PointToPointHelper p2p;
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer nd = p2p.Install (c);
// setup IP addresses
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
ipv4.Assign (nd);
// setup PCAP traces
std::string prefix = (WRITE_VECTORS ? NS_TEST_SOURCEDIR : GetTempDir ()) + PREFIX;
p2p.EnablePcapAll (prefix);
}
void
HelloRegressionTest::CheckResults ()
{
for (uint32_t i = 0; i < 2; ++i)
{
std::ostringstream os1, os2;
// File naming conventions are hard-coded here.
os1 << NS_TEST_SOURCEDIR << PREFIX << "-" << i << "-1.pcap";
os2 << GetTempDir () << PREFIX << "-" << i << "-1.pcap";
uint32_t sec(0), usec(0);
bool diff = PcapFile::Diff (os1.str(), os2.str(), sec, usec);
NS_TEST_EXPECT_MSG_EQ (diff, false, "PCAP traces " << os1.str() << " and " << os2.str()
<< " differ starting from " << sec << " s " << usec << " us");
}
}
}
}

View File

@@ -0,0 +1,69 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 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 HELLOREGRESSIONTEST_H_
#define HELLOREGRESSIONTEST_H_
#include "ns3/test.h"
#include "ns3/nstime.h"
#include "ns3/node-container.h"
namespace ns3
{
namespace olsr
{
/**
* \ingroup olsr
* \brief Trivial (still useful) test of OLSR operation
*
* This test creates 2 stations with point-to-point link and runs OLSR without any extra traffic.
* It is expected that only HELLO messages will be sent.
*
* Expected trace (5 seconds):
\verbatim
1 2
|------>| HELLO (empty) src = 10.1.1.1
|<------| HELLO (empty) src = 10.1.1.2
|------>| HELLO (Link type: Asymmetric link, Neighbor address: 10.1.1.2) src = 10.1.1.1
|<------| HELLO (Link type: Asymmetric link, Neighbor address: 10.1.1.1) src = 10.1.1.2
|------>| HELLO (Link type: Symmetric link, Neighbor address: 10.1.1.2) src = 10.1.1.1
|<------| HELLO (Link type: Symmetric link, Neighbor address: 10.1.1.1) src = 10.1.1.2
\endverbatim
*/
class HelloRegressionTest : public TestCase
{
public:
HelloRegressionTest ();
~HelloRegressionTest ();
private:
/// Unique PCAP files prefix for this test
static const char * const PREFIX;
/// Total simulation time
const Time m_time;
/// Create & configure test network
void CreateNodes ();
/// Compare traces with reference ones
void CheckResults ();
/// Go
bool DoRun ();
};
}
}
#endif /* HELLOREGRESSIONTEST_H_ */

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,38 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 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>
*/
#include "hello-regression-test.h"
#include "tc-regression-test.h"
namespace ns3 {
namespace olsr {
class RegressionTestSuite : public TestSuite
{
public:
RegressionTestSuite () : TestSuite ("routing-olsr-regression", SYSTEM)
{
AddTestCase (new HelloRegressionTest);
AddTestCase (new TcRegressionTest);
}
} g_olsrRegressionTestSuite;
}
}

View File

@@ -0,0 +1,135 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 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>
*/
#include "tc-regression-test.h"
#include "ns3/simulator.h"
#include "ns3/random-variable.h"
#include "ns3/double.h"
#include "ns3/uinteger.h"
#include "ns3/string.h"
#include "ns3/pcap-file.h"
#include "ns3/olsr-helper.h"
#include "ns3/internet-stack-helper.h"
#include "ns3/point-to-point-helper.h"
#include "ns3/ipv4-address-helper.h"
#include "ns3/abort.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/mobility-helper.h"
#include "ns3/nqos-wifi-mac-helper.h"
/// Set to true to rewrite reference traces, leave false to run regression tests
const bool WRITE_VECTORS = false;
namespace ns3
{
namespace olsr
{
const char * const TcRegressionTest::PREFIX = "olsr-tc-regression-test";
TcRegressionTest::TcRegressionTest() :
TestCase ("Test OLSR Topology Control message generation"),
m_time (Seconds (20)),
m_step (120)
{
}
TcRegressionTest::~TcRegressionTest()
{
}
bool
TcRegressionTest::DoRun ()
{
SeedManager::SetSeed(12345);
CreateNodes ();
Simulator::Stop (m_time);
Simulator::Run ();
Simulator::Destroy ();
if (!WRITE_VECTORS) CheckResults ();
return GetErrorStatus ();
}
void
TcRegressionTest::CreateNodes ()
{
// create 3 nodes
NodeContainer c;
c.Create (3);
// place nodes in the chain
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (m_step),
"DeltaY", DoubleValue (0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (c);
// install TCP/IP & OLSR
OlsrHelper olsr;
InternetStackHelper internet;
internet.SetRoutingHelper (olsr);
internet.Install (c);
// create wifi channel & devices
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifiMac.SetType ("ns3::AdhocWifiMac");
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
WifiHelper wifi = WifiHelper::Default ();
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("wifia-6mbs"), "RtsCtsThreshold", StringValue ("2200"));
NetDeviceContainer nd = wifi.Install (wifiPhy, wifiMac, c);
// setup IP addresses
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
ipv4.Assign (nd);
// setup PCAP traces
std::string prefix = (WRITE_VECTORS ? NS_TEST_SOURCEDIR : GetTempDir ()) + PREFIX;
wifiPhy.EnablePcapAll (prefix);
}
void
TcRegressionTest::CheckResults ()
{
for (uint32_t i = 0; i < 3; ++i)
{
std::ostringstream os1, os2;
// File naming conventions are hard-coded here.
os1 << NS_TEST_SOURCEDIR << PREFIX << "-" << i << "-1.pcap";
os2 << GetTempDir () << PREFIX << "-" << i << "-1.pcap";
uint32_t sec(0), usec(0);
bool diff = PcapFile::Diff (os1.str(), os2.str(), sec, usec);
NS_TEST_EXPECT_MSG_EQ (diff, false, "PCAP traces " << os1.str() << " and " << os2.str()
<< " differ starting from " << sec << " s " << usec << " us");
}
}
}
}

View File

@@ -0,0 +1,96 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 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 TCREGRESSIONTEST_H_
#define TCREGRESSIONTEST_H_
#include "ns3/test.h"
#include "ns3/nstime.h"
#include "ns3/node-container.h"
namespace ns3
{
namespace olsr
{
/**
* \ingroup olsr
* \brief Less trivial test of OLSR Topology Control message generation
*
* This test creates 3 WiFi stations with chain topology and runs OLSR without any extra traffic.
* It is expected that only second station will send TC messages.
*
* Expected trace (20 seconds, note random b-cast jitter):
\verbatim
1 2 3
|<------|------>| HELLO (empty) src = 10.1.1.2
| |<------|------> HELLO (empty) src = 10.1.1.3
<------|------>| | HELLO (empty) src = 10.1.1.1
<------|------>| | HELLO (Link Type: Asymmetric, Neighbor: 10.1.1.2) src = 10.1.1.1
| |<------|------> HELLO (Link Type: Asymmetric, Neighbor: 10.1.1.2) src = 10.1.1.3
|<------|------>| HELLO (Link Type: Asymmetric, Neighbor: 10.1.1.3; Link Type: Asymmetric, Neighbor: 10.1.1.1) src = 10.1.1.2
|<------|------>| HELLO (Link Type: Asymmetric, Neighbor: 10.1.1.3; Link Type: Asymmetric, Neighbor: 10.1.1.1) src = 10.1.1.2
<------|------>| | HELLO (Link Type: Symmetric, Neighbor: 10.1.1.2) src = 10.1.1.1
| |<------|------> HELLO (Link Type: Symmetric, Neighbor: 10.1.1.2) src = 10.1.1.3
|<------|------>| HELLO (Link Type: Symmetric, Neighbor: 10.1.1.3; Link Type: Symmetric, Neighbor: 10.1.1.1) src = 10.1.1.2
<------|------>| | HELLO (Link Type: MPR Link, Neighbor: 10.1.1.2) src = 10.1.1.1
| |<------|------> HELLO (Link Type: MPR Link, Neighbor: 10.1.1.2) src = 10.1.1.3
|<------|------>| HELLO (Link Type: Symmetric, Neighbor: 10.1.1.3; Link Type: Symmetric, Neighbor: 10.1.1.1) src = 10.1.1.2
<------|------>| | HELLO (Link Type: MPR Link, Neighbor: 10.1.1.2) src = 10.1.1.1
| |<------|------> HELLO (Link Type: MPR Link, Neighbor: 10.1.1.2) src = 10.1.1.3
|<======|======>| TC (10.1.1.3; 10.1.1.1) + HELLO (Link Type: Symmetric, Neighbor: 10.1.1.3; Link Type: Symmetric, Neighbor: 10.1.1.1) src = 10.1.1.2
| |<------|------> HELLO (Link Type: MPR Link, Neighbor: 10.1.1.2) src = 10.1.1.3
<------|------>| | HELLO (Link Type: MPR Link, Neighbor: 10.1.1.2) src = 10.1.1.1
|<------|------>| HELLO (Link Type: Symmetric, Neighbor: 10.1.1.3; Link Type: Symmetric, Neighbor: 10.1.1.1) src = 10.1.1.2
<------|------>| | HELLO (Link Type: MPR Link, Neighbor: 10.1.1.2) src = 10.1.1.1
| |<------|------> HELLO (Link Type: MPR Link, Neighbor: 10.1.1.2) src = 10.1.1.3
<------|------>| | HELLO (Link Type: MPR Link, Neighbor: 10.1.1.2) src = 10.1.1.1
| |<------|------> HELLO (Link Type: MPR Link, Neighbor: 10.1.1.2) src = 10.1.1.3
|<------|------>| HELLO (Link Type: Symmetric, Neighbor: 10.1.1.3; Link Type: Symmetric, Neighbor: 10.1.1.1) src = 10.1.1.2
|<======|======>| TC (10.1.1.3; 10.1.1.1) src = 10.1.1.2
| |<------|------> HELLO (Link Type: MPR Link, Neighbor: 10.1.1.2) src = 10.1.1.3
<------|------>| | HELLO (Link Type: MPR Link, Neighbor: 10.1.1.2) src = 10.1.1.1
|<------|------>| HELLO (Link Type: Symmetric, Neighbor: 10.1.1.3; Link Type: Symmetric, Neighbor: 10.1.1.1) src = 10.1.1.2
<------|------>| | HELLO (Link Type: MPR Link, Neighbor: 10.1.1.2) src = 10.1.1.1
| |<------|------> HELLO (Link Type: MPR Link, Neighbor: 10.1.1.2) src = 10.1.1.3
|<------|------>| HELLO (Link Type: Symmetric, Neighbor: 10.1.1.3; Link Type: Symmetric, Neighbor: 10.1.1.1) src = 10.1.1.2
\endverbatim
*/
class TcRegressionTest : public TestCase
{
public:
TcRegressionTest();
~TcRegressionTest();
private:
/// Unique PCAP files prefix for this test
static const char * const PREFIX;
/// Total simulation time
const Time m_time;
/// Distance between nodes in meters, 0.8 of RX range is recommended
const double m_step;
/// Create & configure test network
void CreateNodes ();
/// Compare traces with reference ones
void CheckResults ();
/// Go
bool DoRun ();
};
}
}
#endif /* TCREGRESSIONTEST_H_ */

View File

@@ -7,6 +7,9 @@ def build(bld):
'olsr-header.cc',
'olsr-state.cc',
'olsr-routing-protocol.cc',
'test/regression-test-suite.cc',
'test/hello-regression-test.cc',
'test/tc-regression-test.cc',
]
headers = bld.new_task_gen('ns3header')