A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
loopback.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2010 IITP RAS
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Authors: Pavel Boyko <boyko@iitp.ru>
19
*/
20
21
#include "
loopback.h
"
22
#include "ns3/simulator.h"
23
#include "ns3/mobility-helper.h"
24
#include "ns3/double.h"
25
#include "ns3/uinteger.h"
26
#include "ns3/string.h"
27
#include "ns3/boolean.h"
28
#include "ns3/yans-wifi-helper.h"
29
#include "ns3/internet-stack-helper.h"
30
#include "ns3/ipv4-address-helper.h"
31
#include "ns3/abort.h"
32
#include "ns3/udp-echo-helper.h"
33
#include "ns3/mobility-model.h"
34
#include "ns3/pcap-file.h"
35
#include "ns3/aodv-helper.h"
36
#include "ns3/v4ping.h"
37
#include "ns3/nqos-wifi-mac-helper.h"
38
#include "ns3/config.h"
39
#include "ns3/constant-position-mobility-model.h"
40
#include "ns3/names.h"
41
#include <sstream>
42
43
namespace
ns3
44
{
45
namespace
aodv
46
{
47
48
static
uint32_t
g_count
(0);
49
50
static
void
51
PingRtt
(std::string context,
Time
rtt)
52
{
53
g_count
++;
54
}
55
56
void
57
LoopbackTestCase::DoRun
()
58
{
59
NodeContainer
nodes;
60
nodes.
Create
(1);
61
Ptr<MobilityModel>
m = CreateObject<ConstantPositionMobilityModel> ();
62
m->
SetPosition
(
Vector
(0, 0, 0));
63
nodes.
Get
(0)->
AggregateObject
(m);
64
// Setup WiFi
65
NqosWifiMacHelper
wifiMac =
NqosWifiMacHelper::Default
();
66
wifiMac.
SetType
(
"ns3::AdhocWifiMac"
);
67
YansWifiPhyHelper
wifiPhy =
YansWifiPhyHelper::Default
();
68
YansWifiChannelHelper
wifiChannel =
YansWifiChannelHelper::Default
();
69
wifiPhy.
SetChannel
(wifiChannel.
Create
());
70
WifiHelper
wifi =
WifiHelper::Default
();
71
wifi.
SetRemoteStationManager
(
"ns3::ConstantRateWifiManager"
,
"DataMode"
,
StringValue
(
"OfdmRate6Mbps"
),
"RtsCtsThreshold"
,
StringValue
(
"2200"
));
72
NetDeviceContainer
devices = wifi.
Install
(wifiPhy, wifiMac, nodes);
73
74
// Setup TCP/IP & AODV
75
AodvHelper
aodv;
// Use default parameters here
76
InternetStackHelper
internetStack;
77
internetStack.
SetRoutingHelper
(aodv);
78
internetStack.
Install
(nodes);
79
Ipv4AddressHelper
address;
80
address.
SetBase
(
"10.1.1.0"
,
"255.255.255.0"
);
81
Ipv4InterfaceContainer
interfaces = address.
Assign
(devices);
82
83
// Setup ping
84
Ptr<V4Ping>
ping = CreateObject<V4Ping> ();
85
ping->SetAttribute (
"Remote"
,
Ipv4AddressValue
(
Ipv4Address::GetLoopback
()));
86
nodes.
Get
(0)->
AddApplication
(ping);
87
ping->SetStartTime (
Seconds
(0));
88
ping->SetStopTime (
Seconds
(4));
89
Names::Add
(
"ping"
, ping);
90
Config::Connect
(
"/Names/ping/Rtt"
,
MakeCallback
(&
PingRtt
));
91
92
// Run
93
Simulator::Stop
(
Seconds
(5));
94
Simulator::Run
();
95
Simulator::Destroy
();
96
97
// Check that 4 packets delivered
98
NS_TEST_ASSERT_MSG_EQ
(
g_count
, 4,
"Exactly 4 ping replies must be delivered."
);
99
}
100
101
}
102
}
src
aodv
test
loopback.cc
Generated on Tue Oct 9 2012 16:45:32 for ns-3 by
1.8.1.2