src/olsr/test/hello-regression-test.cc
author Josh Pelkey <jpelkey@gatech.edu>
Fri, 13 May 2011 14:58:13 -0400
changeset 7184 a15feb312428
parent 6852 8f1a53d3f6ca
child 7256 b04ba6772f8c
permissions -rw-r--r--
olsr coding style changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5763
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     2
/*
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     3
 * Copyright (c) 2009 IITP RAS
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     4
 *
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     8
 *
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    12
 * GNU General Public License for more details.
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    13
 *
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    17
 *
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    18
 * Authors: Pavel Boyko <boyko@iitp.ru>
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    19
 */
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    20
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    21
#include "hello-regression-test.h"
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    22
#include "ns3/simulator.h"
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    23
#include "ns3/random-variable.h"
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    24
#include "ns3/double.h"
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    25
#include "ns3/uinteger.h"
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    26
#include "ns3/string.h"
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    27
#include "ns3/pcap-file.h"
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    28
#include "ns3/olsr-helper.h"
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    29
#include "ns3/internet-stack-helper.h"
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    30
#include "ns3/point-to-point-helper.h"
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    31
#include "ns3/ipv4-address-helper.h"
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    32
#include "ns3/abort.h"
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    33
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    34
/// Set to true to rewrite reference traces, leave false to run regression tests
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    35
const bool WRITE_VECTORS = false;
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    36
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    37
namespace ns3
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    38
{
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    39
namespace olsr
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    40
{
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    41
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    42
const char * const HelloRegressionTest::PREFIX = "olsr-hello-regression-test";
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    43
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    44
HelloRegressionTest::HelloRegressionTest() : 
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    45
  TestCase ("Test OLSR Hello messages generation"),
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    46
  m_time (Seconds (5))
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    47
{
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    48
}
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    49
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    50
HelloRegressionTest::~HelloRegressionTest()
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    51
{
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    52
}
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    53
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 5763
diff changeset
    54
void
5763
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    55
HelloRegressionTest::DoRun ()
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    56
{
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    57
  SeedManager::SetSeed(12345);
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    58
  CreateNodes ();
7184
a15feb312428 olsr coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6852
diff changeset
    59
5763
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    60
  Simulator::Stop (m_time);
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    61
  Simulator::Run ();
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    62
  Simulator::Destroy ();
7184
a15feb312428 olsr coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6852
diff changeset
    63
a15feb312428 olsr coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6852
diff changeset
    64
  if (!WRITE_VECTORS) CheckResults ();
5763
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    65
}
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    66
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    67
void
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    68
HelloRegressionTest::CreateNodes ()
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    69
{
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    70
  // create 2 nodes
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    71
  NodeContainer c;
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    72
  c.Create (2);
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    73
  // install TCP/IP & OLSR
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    74
  OlsrHelper olsr;
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    75
  InternetStackHelper internet;
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    76
  internet.SetRoutingHelper (olsr);
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    77
  internet.Install (c);
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    78
  // create p2p channel & devices
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    79
  PointToPointHelper p2p;
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    80
  p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    81
  p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    82
  NetDeviceContainer nd = p2p.Install (c);
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    83
  // setup IP addresses
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    84
  Ipv4AddressHelper ipv4;
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    85
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    86
  ipv4.Assign (nd);
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    87
  // setup PCAP traces
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    88
  std::string prefix = (WRITE_VECTORS ? NS_TEST_SOURCEDIR : GetTempDir ()) + PREFIX;
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    89
  p2p.EnablePcapAll (prefix);
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    90
}
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    91
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    92
void
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    93
HelloRegressionTest::CheckResults ()
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    94
{
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    95
  for (uint32_t i = 0; i < 2; ++i)
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    96
    {
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    97
      std::ostringstream os1, os2;
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    98
      // File naming conventions are hard-coded here.
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    99
      os1 << NS_TEST_SOURCEDIR << PREFIX << "-" << i << "-1.pcap";
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   100
      os2 << GetTempDir () << PREFIX << "-" << i << "-1.pcap";
7184
a15feb312428 olsr coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6852
diff changeset
   101
5763
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   102
      uint32_t sec(0), usec(0);
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   103
      bool diff = PcapFile::Diff (os1.str(), os2.str(), sec, usec);
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   104
      NS_TEST_EXPECT_MSG_EQ (diff, false, "PCAP traces " << os1.str() << " and " << os2.str() 
7184
a15feb312428 olsr coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6852
diff changeset
   105
                                                         << " differ starting from " << sec << " s " << usec << " us");
5763
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   106
    }
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   107
}
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   108
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   109
}
04848ede4d04 [olsr] Two basic trace based OLSR regression tests added together with reference traces
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   110
}