src/test/csma-system-test-suite.cc
author Mitch Watrous
Mon, 13 Aug 2012 16:08:13 -0700
changeset 8966 060dba23e9bb
parent 7256 b04ba6772f8c
child 9000 3ec20a64fd08
permissions -rw-r--r--
Replace src/application usage of RandomVariable with RandomVariableStream
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     2
/*
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     6
 *
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    10
 * GNU General Public License for more details.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    11
 *
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    15
 */
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    16
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    17
// This is not a test of CsmaNetDevice model behavior per-se, but
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    18
// instead is a roll up of several end-to-end examples in examples/csma
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    19
// directory, converted into system tests.  Writing a test suite
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    20
// to test Csma itself is for further study.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    21
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    22
#include <string>
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    23
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    24
#include "ns3/address.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    25
#include "ns3/application-container.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    26
#include "ns3/bridge-helper.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    27
#include "ns3/callback.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    28
#include "ns3/config.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    29
#include "ns3/csma-helper.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    30
#include "ns3/csma-star-helper.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    31
#include "ns3/inet-socket-address.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    32
#include "ns3/internet-stack-helper.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    33
#include "ns3/ipv4-address-helper.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    34
#include "ns3/ipv4-global-routing-helper.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    35
#include "ns3/ipv4-static-routing-helper.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    36
#include "ns3/node.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    37
#include "ns3/node-container.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    38
#include "ns3/on-off-helper.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    39
#include "ns3/packet.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    40
#include "ns3/packet-sink-helper.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    41
#include "ns3/packet-socket-helper.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    42
#include "ns3/packet-socket-address.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    43
#include "ns3/pointer.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    44
#include "ns3/simple-channel.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    45
#include "ns3/simulator.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    46
#include "ns3/string.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    47
#include "ns3/test.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    48
#include "ns3/uinteger.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    49
#include "ns3/v4ping-helper.h"
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    50
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    51
using namespace ns3;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    52
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    53
class CsmaBridgeTestCase : public TestCase
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    54
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    55
public:
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    56
  CsmaBridgeTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    57
  virtual ~CsmaBridgeTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    58
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    59
private:
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
    60
  virtual void DoRun (void);
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    61
  void SinkRx (Ptr<const Packet> p, const Address &ad);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    62
  uint32_t m_count;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    63
};
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    64
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    65
// Add some help text to this case to describe what it is intended to test
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    66
CsmaBridgeTestCase::CsmaBridgeTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    67
  : TestCase ("Bridge example for Carrier Sense Multiple Access (CSMA) networks"), m_count (0)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    68
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    69
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    70
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    71
CsmaBridgeTestCase::~CsmaBridgeTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    72
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    73
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    74
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    75
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    76
CsmaBridgeTestCase::SinkRx (Ptr<const Packet> p, const Address &ad)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    77
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    78
  m_count++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    79
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    80
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    81
// Network topology
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    82
//
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
    83
//        n0     n1
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    84
//        |      | 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    85
//       ----------
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    86
//       | Switch |
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    87
//       ----------
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    88
//        |      | 
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
    89
//        n2     n3
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    90
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    91
// - CBR/UDP test flow from n0 to n1; test that packets received on n1 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    92
//
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
    93
void
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    94
CsmaBridgeTestCase::DoRun (void)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    95
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    96
  NodeContainer terminals;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    97
  terminals.Create (4);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    98
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
    99
  NodeContainer csmaSwitch;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   100
  csmaSwitch.Create (1);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   101
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   102
  CsmaHelper csma;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   103
  csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   104
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   105
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   106
  NetDeviceContainer terminalDevices;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   107
  NetDeviceContainer switchDevices;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   108
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   109
  for (int i = 0; i < 4; i++)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   110
    {
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   111
      NetDeviceContainer link = csma.Install (NodeContainer (terminals.Get (i), csmaSwitch));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   112
      terminalDevices.Add (link.Get (0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   113
      switchDevices.Add (link.Get (1));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   114
    }
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   115
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   116
  // Create the bridge netdevice, which will do the packet switching
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   117
  Ptr<Node> switchNode = csmaSwitch.Get (0);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   118
  BridgeHelper bridge;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   119
  bridge.Install (switchNode, switchDevices);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   120
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   121
  InternetStackHelper internet;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   122
  internet.Install (terminals);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   123
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   124
  Ipv4AddressHelper ipv4;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   125
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   126
  ipv4.Assign (terminalDevices);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   127
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   128
  uint16_t port = 9;   // Discard port (RFC 863)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   129
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   130
  // Create the OnOff application to send UDP datagrams from n0 to n1.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   131
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   132
  // Make packets be sent about every DefaultPacketSize / DataRate = 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   133
  // 4096 bits / (5000 bits/second) = 0.82 second.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   134
  OnOffHelper onoff ("ns3::UdpSocketFactory", 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   135
                     Address (InetSocketAddress (Ipv4Address ("10.1.1.2"), port)));
8966
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   136
  onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   137
  onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   138
  onoff.SetAttribute ("DataRate", DataRateValue (DataRate (5000)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   139
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   140
  ApplicationContainer app = onoff.Install (terminals.Get (0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   141
  app.Start (Seconds (1.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   142
  app.Stop (Seconds (10.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   143
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   144
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   145
                         Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   146
  app = sink.Install (terminals.Get (1));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   147
  app.Start (Seconds (0.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   148
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   149
  // Trace receptions
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   150
  Config::ConnectWithoutContext ("/NodeList/1/ApplicationList/0/$ns3::PacketSink/Rx", MakeCallback (&CsmaBridgeTestCase::SinkRx, this));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   151
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   152
  Simulator::Run ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   153
  Simulator::Destroy ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   154
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   155
  // We should have sent and received 10 packets
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   156
  NS_TEST_ASSERT_MSG_EQ (m_count, 10, "Bridge should have passed 10 packets");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   157
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   158
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   159
class CsmaBroadcastTestCase : public TestCase
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   160
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   161
public:
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   162
  CsmaBroadcastTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   163
  virtual ~CsmaBroadcastTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   164
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   165
private:
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
   166
  virtual void DoRun (void);
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   167
  void SinkRxNode1 (Ptr<const Packet> p, const Address &ad);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   168
  void SinkRxNode2 (Ptr<const Packet> p, const Address &ad);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   169
  void DropEvent (Ptr<const Packet> p);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   170
  uint32_t m_countNode1;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   171
  uint32_t m_countNode2;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   172
  uint32_t m_drops;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   173
};
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   174
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   175
// Add some help text to this case to describe what it is intended to test
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   176
CsmaBroadcastTestCase::CsmaBroadcastTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   177
  : TestCase ("Broadcast example for Carrier Sense Multiple Access (CSMA) networks"), m_countNode1 (0), m_countNode2 (0), m_drops (0)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   178
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   179
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   180
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   181
CsmaBroadcastTestCase::~CsmaBroadcastTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   182
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   183
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   184
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   185
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   186
CsmaBroadcastTestCase::SinkRxNode1 (Ptr<const Packet> p, const Address &ad)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   187
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   188
  m_countNode1++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   189
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   190
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   191
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   192
CsmaBroadcastTestCase::SinkRxNode2 (Ptr<const Packet> p, const Address &ad)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   193
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   194
  m_countNode2++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   195
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   196
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   197
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   198
CsmaBroadcastTestCase::DropEvent (Ptr<const Packet> p)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   199
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   200
  m_drops++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   201
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   202
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   203
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   204
// Example of the sending of a datagram to a broadcast address
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   205
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   206
// Network topology
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   207
//     ==============
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   208
//       |          |
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
   209
//       n0    n1   n2
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
   210
//       |     |
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   211
//     ==========
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   212
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   213
//   n0 originates UDP broadcast to 255.255.255.255/discard port, which 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   214
//   is replicated and received on both n1 and n2
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   215
//
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
   216
void
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   217
CsmaBroadcastTestCase::DoRun (void)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   218
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   219
  NodeContainer c;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   220
  c.Create (3);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   221
  NodeContainer c0 = NodeContainer (c.Get (0), c.Get (1));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   222
  NodeContainer c1 = NodeContainer (c.Get (0), c.Get (2));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   223
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   224
  CsmaHelper csma;
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7191
diff changeset
   225
  csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7191
diff changeset
   226
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   227
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   228
  NetDeviceContainer n0 = csma.Install (c0);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   229
  NetDeviceContainer n1 = csma.Install (c1);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   230
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   231
  InternetStackHelper internet;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   232
  internet.Install (c);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   233
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   234
  Ipv4AddressHelper ipv4;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   235
  ipv4.SetBase ("10.1.0.0", "255.255.255.0");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   236
  ipv4.Assign (n0);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   237
  ipv4.SetBase ("192.168.1.0", "255.255.255.0");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   238
  ipv4.Assign (n1);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   239
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   240
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   241
  // RFC 863 discard port ("9") indicates packet should be thrown away
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   242
  // by the system.  We allow this silent discard to be overridden
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   243
  // by the PacketSink application.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   244
  uint16_t port = 9;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   245
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   246
  // Create the OnOff application to send UDP datagrams from n0.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   247
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   248
  // Make packets be sent about every DefaultPacketSize / DataRate = 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   249
  // 4096 bits / (5000 bits/second) = 0.82 second.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   250
  OnOffHelper onoff ("ns3::UdpSocketFactory", 
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
   251
                     Address (InetSocketAddress (Ipv4Address ("255.255.255.255"), port)));
8966
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   252
  onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   253
  onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   254
  onoff.SetAttribute ("DataRate", DataRateValue (DataRate (5000)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   255
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   256
  ApplicationContainer app = onoff.Install (c0.Get (0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   257
  // Start the application
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   258
  app.Start (Seconds (1.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   259
  app.Stop (Seconds (10.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   260
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   261
  // Create an optional packet sink to receive these packets
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   262
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
   263
                         Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   264
  app = sink.Install (c0.Get (1));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   265
  app.Add (sink.Install (c1.Get (1)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   266
  app.Start (Seconds (1.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   267
  app.Stop (Seconds (10.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   268
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   269
  // Trace receptions
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   270
  Config::ConnectWithoutContext ("/NodeList/1/ApplicationList/0/$ns3::PacketSink/Rx", MakeCallback (&CsmaBroadcastTestCase::SinkRxNode1, this));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   271
  Config::ConnectWithoutContext ("/NodeList/2/ApplicationList/0/$ns3::PacketSink/Rx", MakeCallback (&CsmaBroadcastTestCase::SinkRxNode2, this));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   272
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
   273
  Simulator::Run ();
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   274
  Simulator::Destroy ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   275
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   276
  // We should have sent and received 10 packets
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   277
  NS_TEST_ASSERT_MSG_EQ (m_countNode1, 10, "Node 1 should have received 10 packets");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   278
  NS_TEST_ASSERT_MSG_EQ (m_countNode2, 10, "Node 2 should have received 10 packets");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   279
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   280
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   281
class CsmaMulticastTestCase : public TestCase
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   282
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   283
public:
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   284
  CsmaMulticastTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   285
  virtual ~CsmaMulticastTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   286
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   287
private:
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
   288
  virtual void DoRun (void);
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   289
  void SinkRx (Ptr<const Packet> p, const Address &ad);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   290
  void DropEvent (Ptr<const Packet> p);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   291
  uint32_t m_count;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   292
  uint32_t m_drops;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   293
};
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   294
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   295
// Add some help text to this case to describe what it is intended to test
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   296
CsmaMulticastTestCase::CsmaMulticastTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   297
  : TestCase ("Multicast example for Carrier Sense Multiple Access (CSMA) networks"), m_count (0), m_drops (0)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   298
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   299
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   300
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   301
CsmaMulticastTestCase::~CsmaMulticastTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   302
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   303
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   304
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   305
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   306
CsmaMulticastTestCase::SinkRx (Ptr<const Packet> p, const Address& ad)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   307
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   308
  m_count++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   309
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   310
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   311
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   312
CsmaMulticastTestCase::DropEvent (Ptr<const Packet> p)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   313
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   314
  m_drops++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   315
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   316
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   317
// Network topology
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   318
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   319
//                     Lan1
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   320
//                 ===========
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   321
//                 |    |    | 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   322
//       n0   n1   n2   n3   n4
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   323
//       |    |    |
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   324
//       ===========
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   325
//           Lan0
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   326
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   327
// - Multicast source is at node n0;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   328
// - Multicast forwarded by node n2 onto LAN1;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   329
// - Nodes n0, n1, n2, n3, and n4 receive the multicast frame.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   330
// - Node n4 listens for the data 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   331
//
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
   332
void
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   333
CsmaMulticastTestCase::DoRun (void)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   334
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   335
  //
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
   336
  // Set up default values for the simulation.
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   337
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   338
  // Select DIX/Ethernet II-style encapsulation (no LLC/Snap header)
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
   339
  Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("Dix"));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   340
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   341
  NodeContainer c;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   342
  c.Create (5);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   343
  // We will later want two subcontainers of these nodes, for the two LANs
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   344
  NodeContainer c0 = NodeContainer (c.Get (0), c.Get (1), c.Get (2));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   345
  NodeContainer c1 = NodeContainer (c.Get (2), c.Get (3), c.Get (4));
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
   346
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   347
  CsmaHelper csma;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   348
  csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   349
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   350
 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   351
  // We will use these NetDevice containers later, for IP addressing
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   352
  NetDeviceContainer nd0 = csma.Install (c0);  // First LAN
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   353
  NetDeviceContainer nd1 = csma.Install (c1);  // Second LAN
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   354
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   355
  InternetStackHelper internet;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   356
  internet.Install (c);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   357
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   358
  Ipv4AddressHelper ipv4Addr;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   359
  ipv4Addr.SetBase ("10.1.1.0", "255.255.255.0");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   360
  ipv4Addr.Assign (nd0);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   361
  ipv4Addr.SetBase ("10.1.2.0", "255.255.255.0");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   362
  ipv4Addr.Assign (nd1);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   363
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   364
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   365
  // Now we can configure multicasting.  As described above, the multicast 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   366
  // source is at node zero, which we assigned the IP address of 10.1.1.1 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   367
  // earlier.  We need to define a multicast group to send packets to.  This
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   368
  // can be any multicast address from 224.0.0.0 through 239.255.255.255
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
   369
  // (avoiding the reserved routing protocol addresses).
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   370
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   371
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   372
  Ipv4Address multicastSource ("10.1.1.1");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   373
  Ipv4Address multicastGroup ("225.1.2.4");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   374
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   375
  // Now, we will set up multicast routing.  We need to do three things:
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   376
  // 1) Configure a (static) multicast route on node n2
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   377
  // 2) Set up a default multicast route on the sender n0 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   378
  // 3) Have node n4 join the multicast group
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   379
  // We have a helper that can help us with static multicast
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   380
  Ipv4StaticRoutingHelper multicast;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   381
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   382
  // 1) Configure a (static) multicast route on node n2 (multicastRouter)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   383
  Ptr<Node> multicastRouter = c.Get (2);  // The node in question
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   384
  Ptr<NetDevice> inputIf = nd0.Get (2);  // The input NetDevice
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   385
  NetDeviceContainer outputDevices;  // A container of output NetDevices
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   386
  outputDevices.Add (nd1.Get (0));  // (we only need one NetDevice here)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   387
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   388
  multicast.AddMulticastRoute (multicastRouter, multicastSource, 
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
   389
                               multicastGroup, inputIf, outputDevices);
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
   390
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   391
  // 2) Set up a default multicast route on the sender n0 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   392
  Ptr<Node> sender = c.Get (0);
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7191
diff changeset
   393
  Ptr<NetDevice> senderIf = nd0.Get (0);
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   394
  multicast.SetDefaultMulticastRoute (sender, senderIf);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   395
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   396
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   397
  // Create an OnOff application to send UDP datagrams from node zero to the
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   398
  // multicast group (node four will be listening).
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   399
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   400
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   401
  uint16_t multicastPort = 9;   // Discard port (RFC 863)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   402
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   403
  // Configure a multicast packet generator.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   404
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   405
  // Make packets be sent about every defaultPacketSize / dataRate = 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   406
  // 4096 bits / (5000 bits/second) = 0.82 second.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   407
  OnOffHelper onoff ("ns3::UdpSocketFactory", 
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
   408
                     Address (InetSocketAddress (multicastGroup, multicastPort)));
8966
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   409
  onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   410
  onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   411
  onoff.SetAttribute ("DataRate", DataRateValue (DataRate (5000)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   412
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   413
  ApplicationContainer srcC = onoff.Install (c0.Get (0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   414
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   415
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   416
  // Tell the application when to start and stop.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   417
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7191
diff changeset
   418
  srcC.Start (Seconds (1.));
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7191
diff changeset
   419
  srcC.Stop (Seconds (10.));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   420
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   421
  // Create an optional packet sink to receive these packets
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   422
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7191
diff changeset
   423
                         InetSocketAddress (Ipv4Address::GetAny (), multicastPort));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   424
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   425
  ApplicationContainer sinkC = sink.Install (c1.Get (2)); // Node n4 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   426
  // Start the sink
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   427
  sinkC.Start (Seconds (1.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   428
  sinkC.Stop (Seconds (10.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   429
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   430
  // Trace receptions
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   431
  Config::ConnectWithoutContext ("/NodeList/4/ApplicationList/0/$ns3::PacketSink/Rx", MakeCallback (&CsmaMulticastTestCase::SinkRx, this));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   432
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   433
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   434
  // Now, do the actual simulation.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   435
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   436
  Simulator::Run ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   437
  Simulator::Destroy ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   438
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   439
  // We should have sent and received 10 packets
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   440
  NS_TEST_ASSERT_MSG_EQ (m_count, 10, "Node 4 should have received 10 packets");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   441
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   442
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   443
class CsmaOneSubnetTestCase : public TestCase
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   444
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   445
public:
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   446
  CsmaOneSubnetTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   447
  virtual ~CsmaOneSubnetTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   448
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   449
private:
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
   450
  virtual void DoRun (void);
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   451
  void SinkRxNode0 (Ptr<const Packet> p, const Address &ad);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   452
  void SinkRxNode1 (Ptr<const Packet> p, const Address &ad);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   453
  void DropEvent (Ptr<const Packet> p);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   454
  uint32_t m_countNode0;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   455
  uint32_t m_countNode1;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   456
  uint32_t m_drops;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   457
};
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   458
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   459
// Add some help text to this case to describe what it is intended to test
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   460
CsmaOneSubnetTestCase::CsmaOneSubnetTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   461
  : TestCase ("One subnet example for Carrier Sense Multiple Access (CSMA) networks"), m_countNode0 (0), m_countNode1 (0), m_drops (0)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   462
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   463
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   464
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   465
CsmaOneSubnetTestCase::~CsmaOneSubnetTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   466
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   467
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   468
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   469
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   470
CsmaOneSubnetTestCase::SinkRxNode0 (Ptr<const Packet> p, const Address &ad)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   471
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   472
  m_countNode0++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   473
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   474
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   475
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   476
CsmaOneSubnetTestCase::SinkRxNode1 (Ptr<const Packet> p, const Address &ad)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   477
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   478
  m_countNode1++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   479
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   480
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   481
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   482
CsmaOneSubnetTestCase::DropEvent (Ptr<const Packet> p)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   483
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   484
  m_drops++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   485
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   486
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   487
// Network topology
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   488
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   489
//       n0    n1   n2   n3
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   490
//       |     |    |    |
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   491
//       =================
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   492
//              LAN
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   493
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   494
// - CBR/UDP flows from n0 to n1 and from n3 to n0
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   495
// - DropTail queues 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   496
//
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
   497
void
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   498
CsmaOneSubnetTestCase::DoRun (void)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   499
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   500
  NodeContainer nodes;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   501
  nodes.Create (4);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   502
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   503
  CsmaHelper csma;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   504
  csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   505
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   506
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   507
  // Now fill out the topology by creating the net devices required to connect
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   508
  // the nodes to the channels and hooking them up.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   509
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   510
  NetDeviceContainer devices = csma.Install (nodes);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   511
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   512
  InternetStackHelper internet;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   513
  internet.Install (nodes);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   514
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   515
  // We've got the "hardware" in place.  Now we need to add IP addresses.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   516
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   517
  Ipv4AddressHelper ipv4;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   518
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   519
  Ipv4InterfaceContainer interfaces = ipv4.Assign (devices);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   520
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   521
  uint16_t port = 9;   // Discard port (RFC 863)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   522
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   523
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   524
  // Create an OnOff application to send UDP datagrams from node zero
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   525
  // to node 1.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   526
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   527
  // Make packets be sent about every defaultPacketSize / dataRate = 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   528
  // 4096 bits / (5000 bits/second) = 0.82 second.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   529
  OnOffHelper onoff ("ns3::UdpSocketFactory", 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   530
                     Address (InetSocketAddress (interfaces.GetAddress (1), port)));
8966
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   531
  onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   532
  onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   533
  onoff.SetAttribute ("DataRate", DataRateValue (DataRate (5000)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   534
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   535
  ApplicationContainer app = onoff.Install (nodes.Get (0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   536
  // Start the application
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   537
  app.Start (Seconds (1.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   538
  app.Stop (Seconds (10.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   539
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   540
  // Create an optional packet sink to receive these packets
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   541
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
   542
                         Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   543
  app = sink.Install (nodes.Get (1));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   544
  app.Start (Seconds (0.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   545
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   546
  // 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   547
  // Create a similar flow from n3 to n0, starting at time 1.1 seconds
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   548
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   549
  onoff.SetAttribute ("Remote", 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   550
                      AddressValue (InetSocketAddress (interfaces.GetAddress (0), port)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   551
  app = onoff.Install (nodes.Get (3));
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7191
diff changeset
   552
  app.Start (Seconds (1.1));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   553
  app.Stop (Seconds (10.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   554
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   555
  app = sink.Install (nodes.Get (0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   556
  app.Start (Seconds (0.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   557
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   558
  // Trace receptions
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   559
  Config::ConnectWithoutContext ("/NodeList/0/ApplicationList/1/$ns3::PacketSink/Rx", MakeCallback (&CsmaOneSubnetTestCase::SinkRxNode0, this));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   560
  Config::ConnectWithoutContext ("/NodeList/1/ApplicationList/0/$ns3::PacketSink/Rx", MakeCallback (&CsmaOneSubnetTestCase::SinkRxNode1, this));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   561
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   562
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   563
  // Now, do the actual simulation.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   564
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   565
  Simulator::Run ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   566
  Simulator::Destroy ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   567
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   568
  // We should have sent and received 10 packets
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   569
  NS_TEST_ASSERT_MSG_EQ (m_countNode0, 10, "Node 0 should have received 10 packets");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   570
  NS_TEST_ASSERT_MSG_EQ (m_countNode1, 10, "Node 1 should have received 10 packets");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   571
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   572
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   573
class CsmaPacketSocketTestCase : public TestCase
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   574
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   575
public:
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   576
  CsmaPacketSocketTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   577
  virtual ~CsmaPacketSocketTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   578
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   579
private:
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
   580
  virtual void DoRun (void);
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   581
  void SinkRx (std::string path, Ptr<const Packet> p, const Address &address);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   582
  void DropEvent (Ptr<const Packet> p);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   583
  uint32_t m_count;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   584
  uint32_t m_drops;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   585
};
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   586
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   587
// Add some help text to this case to describe what it is intended to test
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   588
CsmaPacketSocketTestCase::CsmaPacketSocketTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   589
  : TestCase ("Packet socket example for Carrier Sense Multiple Access (CSMA) networks"), m_count (0), m_drops (0)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   590
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   591
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   592
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   593
CsmaPacketSocketTestCase::~CsmaPacketSocketTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   594
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   595
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   596
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   597
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   598
CsmaPacketSocketTestCase::SinkRx (std::string path, Ptr<const Packet> p, const Address& address)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   599
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   600
  m_count++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   601
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   602
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   603
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   604
CsmaPacketSocketTestCase::DropEvent (Ptr<const Packet> p)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   605
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   606
  m_drops++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   607
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   608
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   609
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   610
// Network topology
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   611
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   612
//       n0    n1   n2   n3
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   613
//       |     |    |    |
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   614
//     =====================
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   615
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   616
// - Packet socket flow from n0 to n1 and from node n3 to n0
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   617
// -- We will test reception at node n0
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   618
// - Default 512 byte packets generated by traffic generator
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   619
//
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
   620
void
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   621
CsmaPacketSocketTestCase::DoRun (void)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   622
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   623
  // Here, we will explicitly create four nodes.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   624
  NodeContainer nodes;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   625
  nodes.Create (4);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   626
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   627
  PacketSocketHelper packetSocket;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   628
  packetSocket.Install (nodes);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   629
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   630
  // create the shared medium used by all csma devices.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   631
  Ptr<CsmaChannel> channel = CreateObjectWithAttributes<CsmaChannel> (
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7191
diff changeset
   632
      "DataRate", DataRateValue (DataRate (5000000)),
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7191
diff changeset
   633
      "Delay", TimeValue (MilliSeconds (2)));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   634
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   635
  // use a helper function to connect our nodes to the shared channel.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   636
  CsmaHelper csma;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   637
  csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc"));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   638
  NetDeviceContainer devs = csma.Install (nodes, channel);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   639
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   640
  // Create the OnOff application to send raw datagrams
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   641
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   642
  // Make packets be sent about every DefaultPacketSize / DataRate = 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   643
  // 4096 bits / (5000 bits/second) = 0.82 second.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   644
  PacketSocketAddress socket;
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7191
diff changeset
   645
  socket.SetSingleDevice (devs.Get (0)->GetIfIndex ());
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   646
  socket.SetPhysicalAddress (devs.Get (1)->GetAddress ());
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   647
  socket.SetProtocol (2);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   648
  OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
8966
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   649
  onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   650
  onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   651
  onoff.SetAttribute ("DataRate", DataRateValue (DataRate (5000)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   652
  ApplicationContainer apps = onoff.Install (nodes.Get (0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   653
  apps.Start (Seconds (1.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   654
  apps.Stop (Seconds (10.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   655
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   656
  socket.SetSingleDevice (devs.Get (3)->GetIfIndex ());
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   657
  socket.SetPhysicalAddress (devs.Get (0)->GetAddress ());
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   658
  socket.SetProtocol (3);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   659
  onoff.SetAttribute ("Remote", AddressValue (socket));
8966
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   660
  onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   661
  apps = onoff.Install (nodes.Get (3));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   662
  apps.Start (Seconds (1.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   663
  apps.Stop (Seconds (10.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   664
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   665
  PacketSinkHelper sink = PacketSinkHelper ("ns3::PacketSocketFactory",
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   666
                                            socket);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   667
  apps = sink.Install (nodes.Get (0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   668
  apps.Start (Seconds (0.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   669
  apps.Stop (Seconds (20.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   670
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   671
  // Trace receptions
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   672
  Config::Connect ("/NodeList/0/ApplicationList/*/$ns3::PacketSink/Rx",
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   673
                   MakeCallback (&CsmaPacketSocketTestCase::SinkRx, this));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   674
 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   675
  Simulator::Run ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   676
  Simulator::Destroy ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   677
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   678
  // We should have received 10 packets on node 0
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   679
  NS_TEST_ASSERT_MSG_EQ (m_count, 10, "Node 0 should have received 10 packets");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   680
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   681
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   682
class CsmaPingTestCase : public TestCase
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   683
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   684
public:
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   685
  CsmaPingTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   686
  virtual ~CsmaPingTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   687
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   688
private:
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
   689
  virtual void DoRun (void);
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   690
  void SinkRx (Ptr<const Packet> p, const Address &ad);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   691
  void PingRtt (std::string context, Time rtt);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   692
  void DropEvent (Ptr<const Packet> p);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   693
  uint32_t m_countSinkRx;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   694
  uint32_t m_countPingRtt;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   695
  uint32_t m_drops;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   696
};
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   697
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   698
// Add some help text to this case to describe what it is intended to test
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   699
CsmaPingTestCase::CsmaPingTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   700
  : TestCase ("Ping example for Carrier Sense Multiple Access (CSMA) networks"), m_countSinkRx (0), m_countPingRtt (0), m_drops (0)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   701
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   702
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   703
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   704
CsmaPingTestCase::~CsmaPingTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   705
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   706
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   707
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   708
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   709
CsmaPingTestCase::SinkRx (Ptr<const Packet> p, const Address &ad)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   710
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   711
  m_countSinkRx++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   712
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   713
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   714
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   715
CsmaPingTestCase::PingRtt (std::string context, Time rtt)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   716
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   717
  m_countPingRtt++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   718
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   719
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   720
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   721
CsmaPingTestCase::DropEvent (Ptr<const Packet> p)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   722
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   723
  m_drops++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   724
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   725
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   726
// Network topology
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   727
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   728
//       n0    n1   n2   n3
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   729
//       |     |    |    |
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   730
//     =====================
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   731
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   732
//  node n0,n1,n3 pings to node n2
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   733
//  node n0 generates protocol 2 (IGMP) to node n3
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   734
//
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
   735
void
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   736
CsmaPingTestCase::DoRun (void)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   737
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   738
  // Here, we will explicitly create four nodes.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   739
  NodeContainer c;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   740
  c.Create (4);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   741
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   742
  // connect all our nodes to a shared channel.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   743
  CsmaHelper csma;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   744
  csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   745
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   746
  csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc"));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   747
  NetDeviceContainer devs = csma.Install (c);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   748
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   749
  // add an ip stack to all nodes.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   750
  InternetStackHelper ipStack;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   751
  ipStack.Install (c);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   752
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   753
  // assign ip addresses
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   754
  Ipv4AddressHelper ip;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   755
  ip.SetBase ("192.168.1.0", "255.255.255.0");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   756
  Ipv4InterfaceContainer addresses = ip.Assign (devs);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   757
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   758
  // Create the OnOff application to send UDP datagrams from n0 to n1.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   759
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   760
  // Make packets be sent about every DefaultPacketSize / DataRate = 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   761
  // 4096 bits / (5000 bits/second) = 0.82 second.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   762
  Config::SetDefault ("ns3::Ipv4RawSocketImpl::Protocol", StringValue ("2"));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   763
  InetSocketAddress dst = InetSocketAddress (addresses.GetAddress (3));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   764
  OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst);
8966
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   765
  onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   766
  onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   767
  onoff.SetAttribute ("DataRate", DataRateValue (DataRate (5000)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   768
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   769
  ApplicationContainer apps = onoff.Install (c.Get (0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   770
  apps.Start (Seconds (1.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   771
  apps.Stop (Seconds (10.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   772
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   773
  PacketSinkHelper sink = PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   774
  apps = sink.Install (c.Get (3));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   775
  apps.Start (Seconds (0.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   776
  apps.Stop (Seconds (11.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   777
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   778
  V4PingHelper ping = V4PingHelper (addresses.GetAddress (2));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   779
  NodeContainer pingers;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   780
  pingers.Add (c.Get (0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   781
  pingers.Add (c.Get (1));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   782
  pingers.Add (c.Get (3));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   783
  apps = ping.Install (pingers);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   784
  apps.Start (Seconds (2.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   785
  apps.Stop (Seconds (5.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   786
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   787
  // Trace receptions
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   788
  Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx", 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   789
                                 MakeCallback (&CsmaPingTestCase::SinkRx, this));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   790
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   791
  // Trace pings
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   792
  Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::V4Ping/Rtt",
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   793
                   MakeCallback (&CsmaPingTestCase::PingRtt, this));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   794
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   795
  Simulator::Run ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   796
  Simulator::Destroy ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   797
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   798
  // We should have sent and received 10 packets
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   799
  NS_TEST_ASSERT_MSG_EQ (m_countSinkRx, 10, "Node 3 should have received 10 packets");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   800
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   801
  // We should have 3 pingers that ping every second for 3 seconds.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   802
  NS_TEST_ASSERT_MSG_EQ (m_countPingRtt, 9, "Node 2 should have been pinged 9 times");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   803
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   804
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   805
class CsmaRawIpSocketTestCase : public TestCase
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   806
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   807
public:
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   808
  CsmaRawIpSocketTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   809
  virtual ~CsmaRawIpSocketTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   810
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   811
private:
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
   812
  virtual void DoRun (void);
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   813
  void SinkRx (Ptr<const Packet> p, const Address &ad);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   814
  void DropEvent (Ptr<const Packet> p);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   815
  uint32_t m_count;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   816
  uint32_t m_drops;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   817
};
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   818
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   819
// Add some help text to this case to describe what it is intended to test
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   820
CsmaRawIpSocketTestCase::CsmaRawIpSocketTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   821
  : TestCase ("Raw internet protocol socket example for Carrier Sense Multiple Access (CSMA) networks"), m_count (0), m_drops (0)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   822
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   823
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   824
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   825
CsmaRawIpSocketTestCase::~CsmaRawIpSocketTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   826
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   827
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   828
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   829
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   830
CsmaRawIpSocketTestCase::SinkRx (Ptr<const Packet> p, const Address &ad)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   831
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   832
  m_count++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   833
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   834
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   835
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   836
CsmaRawIpSocketTestCase::DropEvent (Ptr<const Packet> p)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   837
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   838
  m_drops++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   839
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   840
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   841
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   842
// Network topology
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   843
//    (sender)         (receiver)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   844
//       n0    n1   n2   n3
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   845
//       |     |    |    |
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   846
//     =====================
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   847
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   848
// Node n0 sends data to node n3 over a raw IP socket.  The protocol
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   849
// number used is 2.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   850
//
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
   851
void
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   852
CsmaRawIpSocketTestCase::DoRun (void)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   853
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   854
  // Here, we will explicitly create four nodes.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   855
  NodeContainer c;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   856
  c.Create (4);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   857
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   858
  // connect all our nodes to a shared channel.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   859
  CsmaHelper csma;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   860
  csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   861
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   862
  csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc"));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   863
  NetDeviceContainer devs = csma.Install (c);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   864
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   865
  // add an ip stack to all nodes.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   866
  InternetStackHelper ipStack;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   867
  ipStack.Install (c);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   868
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   869
  // assign ip addresses
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   870
  Ipv4AddressHelper ip;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   871
  ip.SetBase ("192.168.1.0", "255.255.255.0");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   872
  Ipv4InterfaceContainer addresses = ip.Assign (devs);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   873
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   874
  // IP protocol configuration
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   875
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   876
  // Make packets be sent about every DefaultPacketSize / DataRate = 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   877
  // 4096 bits / (5000 bits/second) = 0.82 second.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   878
  Config::SetDefault ("ns3::Ipv4RawSocketImpl::Protocol", StringValue ("2"));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   879
  InetSocketAddress dst = InetSocketAddress (addresses.GetAddress (3));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   880
  OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst);
8966
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   881
  onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   882
  onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   883
  onoff.SetAttribute ("DataRate", DataRateValue (DataRate (5000)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   884
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   885
  ApplicationContainer apps = onoff.Install (c.Get (0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   886
  apps.Start (Seconds (1.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   887
  apps.Stop (Seconds (10.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   888
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   889
  PacketSinkHelper sink = PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   890
  apps = sink.Install (c.Get (3));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   891
  apps.Start (Seconds (0.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   892
  apps.Stop (Seconds (12.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   893
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   894
  // Trace receptions
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   895
  Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx", 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   896
                                 MakeCallback (&CsmaRawIpSocketTestCase::SinkRx, this));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   897
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   898
  Simulator::Run ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   899
  Simulator::Destroy ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   900
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   901
  // We should have sent and received 10 packets
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   902
  NS_TEST_ASSERT_MSG_EQ (m_count, 10, "Node 3 should have received 10 packets");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   903
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   904
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   905
class CsmaStarTestCase : public TestCase
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   906
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   907
public:
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   908
  CsmaStarTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   909
  virtual ~CsmaStarTestCase ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   910
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   911
private:
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
   912
  virtual void DoRun (void);
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   913
  void SinkRx (Ptr<const Packet> p, const Address &ad);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   914
  void DropEvent (Ptr<const Packet> p);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   915
  uint32_t m_count;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   916
  uint32_t m_drops;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   917
};
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   918
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   919
// Add some help text to this case to describe what it is intended to test
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   920
CsmaStarTestCase::CsmaStarTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   921
  : TestCase ("Star example for Carrier Sense Multiple Access (CSMA) networks"), m_count (0), m_drops (0)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   922
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   923
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   924
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   925
CsmaStarTestCase::~CsmaStarTestCase ()
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   926
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   927
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   928
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   929
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   930
CsmaStarTestCase::SinkRx (Ptr<const Packet> p, const Address& ad)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   931
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   932
  m_count++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   933
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   934
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   935
void 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   936
CsmaStarTestCase::DropEvent (Ptr<const Packet> p)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   937
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   938
  m_drops++;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   939
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   940
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   941
// Network topology (default)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   942
//
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   943
//            n2     +          +     n3          .
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   944
//             | ... |\        /| ... |           .
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   945
//             ======= \      / =======           .
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   946
//              CSMA    \    /   CSMA             .
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   947
//                       \  /                     .
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   948
//            n1     +--- n0 ---+     n4          .
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   949
//             | ... |   /  \   | ... |           .
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   950
//             =======  /    \  =======           .
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   951
//              CSMA   /      \  CSMA             .
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   952
//                    /        \                  .
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   953
//            n6     +          +     n5          .
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   954
//             | ... |          | ... |           .
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   955
//             =======          =======           .
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   956
//              CSMA             CSMA             .
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   957
//
6775
0783f42a364b Make test cases not return bool valuesMake all TestSuite instances be static
Mitch Watrous <watrous@u.washington.edu>
parents: 6624
diff changeset
   958
void
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   959
CsmaStarTestCase::DoRun (void)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   960
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   961
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   962
  // Default number of nodes in the star.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   963
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   964
  uint32_t nSpokes = 7;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   965
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   966
  CsmaHelper csma;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   967
  csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   968
  csma.SetChannelAttribute ("Delay", StringValue ("1ms"));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   969
  CsmaStarHelper star (nSpokes, csma);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   970
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   971
  NodeContainer fillNodes;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   972
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   973
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   974
  // Just to be nasy, hang some more nodes off of the CSMA channel for each
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   975
  // spoke, so that there are a total of 16 nodes on each channel.  Stash
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   976
  // all of these new devices into a container.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   977
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   978
  NetDeviceContainer fillDevices;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   979
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   980
  uint32_t nFill = 14;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   981
  for (uint32_t i = 0; i < star.GetSpokeDevices ().GetN (); ++i)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   982
    {
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   983
      Ptr<Channel> channel = star.GetSpokeDevices ().Get (i)->GetChannel ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   984
      Ptr<CsmaChannel> csmaChannel = channel->GetObject<CsmaChannel> ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   985
      NodeContainer newNodes;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   986
      newNodes.Create (nFill);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   987
      fillNodes.Add (newNodes);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   988
      fillDevices.Add (csma.Install (newNodes, csmaChannel));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   989
    }
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   990
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   991
  InternetStackHelper internet;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   992
  star.InstallStack (internet);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   993
  internet.Install (fillNodes);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   994
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   995
  star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.0.0", "255.255.255.0"));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   996
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   997
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   998
  // We assigned addresses to the logical hub and the first "drop" of the 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
   999
  // CSMA network that acts as the spoke, but we also have a number of fill
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1000
  // devices (nFill) also hanging off the CSMA network.  We have got to 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1001
  // assign addresses to them as well.  We put all of the fill devices into
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1002
  // a single device container, so the first nFill devices are associated
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1003
  // with the channel connected to spokeDevices.Get (0), the second nFill
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1004
  // devices afe associated with the channel connected to spokeDevices.Get (1)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1005
  // etc.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1006
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1007
  Ipv4AddressHelper address;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1008
  for(uint32_t i = 0; i < star.SpokeCount (); ++i)
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
  1009
    {
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
  1010
      std::ostringstream subnet;
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
  1011
      subnet << "10.1." << i << ".0";
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1012
      address.SetBase (subnet.str ().c_str (), "255.255.255.0", "0.0.0.3");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1013
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
  1014
      for (uint32_t j = 0; j < nFill; ++j)
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
  1015
        {
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
  1016
          address.Assign (fillDevices.Get (i * nFill + j));
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
  1017
        }
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
  1018
    }
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1019
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1020
  //
7191
7b9f3eba908b test coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7008
diff changeset
  1021
  // Create a packet sink on the star "hub" to receive packets.
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1022
  // 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1023
  uint16_t port = 50000;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1024
  Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1025
  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1026
  ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ());
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1027
  hubApp.Start (Seconds (1.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1028
  hubApp.Stop (Seconds (10.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1029
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1030
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1031
  // Create OnOff applications to send TCP to the hub, one on each spoke node.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1032
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1033
  // Make packets be sent about every DefaultPacketSize / DataRate = 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1034
  // 4096 bits / (5000 bits/second) = 0.82 second.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1035
  OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
8966
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
  1036
  onOffHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
  1037
  onOffHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1038
  onOffHelper.SetAttribute ("DataRate", DataRateValue (DataRate (5000)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1039
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1040
  ApplicationContainer spokeApps;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1041
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1042
  for (uint32_t i = 0; i < star.SpokeCount (); ++i)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1043
    {
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1044
      AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i), port));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1045
      onOffHelper.SetAttribute ("Remote", remoteAddress);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1046
      spokeApps.Add (onOffHelper.Install (star.GetSpokeNode (i)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1047
    }
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1048
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1049
  spokeApps.Start (Seconds (1.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1050
  spokeApps.Stop (Seconds (10.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1051
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1052
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1053
  // Because we are evil, we also add OnOff applications to send TCP to the hub 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1054
  // from the fill devices on each CSMA link.  The first nFill nodes in the 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1055
  // fillNodes container are on the CSMA network talking to the zeroth device
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1056
  // on the hub node.  The next nFill nodes are on the CSMA network talking to
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1057
  // the first device on the hub node, etc.  So the ith fillNode is associated
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1058
  // with the hub address found on the (i / nFill)th device on the hub node.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1059
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1060
  ApplicationContainer fillApps;
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1061
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1062
  for (uint32_t i = 0; i < fillNodes.GetN (); ++i)
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1063
    {
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1064
      AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i / nFill), port));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1065
      onOffHelper.SetAttribute ("Remote", remoteAddress);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1066
      fillApps.Add (onOffHelper.Install (fillNodes.Get (i)));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1067
    }
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1068
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1069
  fillApps.Start (Seconds (1.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1070
  fillApps.Stop (Seconds (10.0));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1071
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1072
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1073
  // Turn on global static routing so we can actually be routed across the star.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1074
  //
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1075
  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1076
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1077
  // Trace receptions
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1078
  Config::ConnectWithoutContext ("/NodeList/0/ApplicationList/*/$ns3::PacketSink/Rx", 
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1079
                                 MakeCallback (&CsmaStarTestCase::SinkRx, this));
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1080
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1081
  Simulator::Run ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1082
  Simulator::Destroy ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1083
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1084
  // The hub node should have received 10 packets from the nFill + 1
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1085
  // nodes on each spoke.
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1086
  NS_TEST_ASSERT_MSG_EQ (m_count, 10 * ( nSpokes * (nFill + 1)), "Hub node did not receive the proper number of packets");
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1087
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1088
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1089
class CsmaSystemTestSuite : public TestSuite
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1090
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1091
public:
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1092
  CsmaSystemTestSuite ();
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1093
};
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1094
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1095
CsmaSystemTestSuite::CsmaSystemTestSuite ()
7008
82c66d5c01f7 Relabel all build verification tests (BVT) to be unit tests (UNIT)
Mitch Watrous <watrous@u.washington.edu>
parents: 6775
diff changeset
  1096
  : TestSuite ("csma-system", UNIT)
6624
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1097
{
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1098
  AddTestCase (new CsmaBridgeTestCase);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1099
  AddTestCase (new CsmaBroadcastTestCase);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1100
  AddTestCase (new CsmaMulticastTestCase);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1101
  AddTestCase (new CsmaOneSubnetTestCase);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1102
  AddTestCase (new CsmaPacketSocketTestCase);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1103
  AddTestCase (new CsmaPingTestCase);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1104
  AddTestCase (new CsmaRawIpSocketTestCase);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1105
  AddTestCase (new CsmaStarTestCase);
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1106
}
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1107
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1108
// Do not forget to allocate an instance of this TestSuite
a071889af159 Remove regression tests from waf
Mitch Watrous <watrous@u.washington.edu>
parents:
diff changeset
  1109
static CsmaSystemTestSuite csmaSystemTestSuite;