A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
mpi-test-fixtures.cc
Go to the documentation of this file.
1
/*
2
* Copyright 2018. Lawrence Livermore National Security, LLC.
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Steven Smith <smith84@llnl.gov>
18
*/
19
20
#include "
mpi-test-fixtures.h
"
21
22
#include "ns3/address.h"
23
#include "ns3/inet-socket-address.h"
24
#include "ns3/inet6-socket-address.h"
25
#include "ns3/packet.h"
26
#include "ns3/ptr.h"
27
#include "ns3/simulator.h"
28
29
#include <mpi.h>
30
31
namespace
ns3
32
{
33
34
unsigned
long
SinkTracer::m_sinkCount
= 0;
35
unsigned
long
SinkTracer::m_line
= 0;
36
int
SinkTracer::m_worldRank
= -1;
37
int
SinkTracer::m_worldSize
= -1;
38
39
void
40
SinkTracer::Init
()
41
{
42
m_sinkCount
= 0;
43
m_line
= 0;
44
MPI_Comm_rank(MPI_COMM_WORLD, &
m_worldRank
);
45
MPI_Comm_size(MPI_COMM_WORLD, &
m_worldSize
);
46
}
47
48
void
49
SinkTracer::SinkTrace
(
const
ns3::Ptr<const ns3::Packet>
packet,
50
const
ns3::Address
& srcAddress,
51
const
ns3::Address
& destAddress)
52
{
53
m_sinkCount
++;
54
}
55
56
void
57
SinkTracer::Verify
(
unsigned
long
expectedCount)
58
{
59
unsigned
long
globalCount;
60
61
#ifdef NS3_MPI
62
MPI_Reduce(&
m_sinkCount
, &globalCount, 1, MPI_UNSIGNED_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
63
#else
64
globalCount =
m_sinkCount
;
65
#endif
66
67
if
(expectedCount == globalCount)
68
{
69
RANK0COUT
(
"PASSED\n"
);
70
}
71
else
72
{
73
RANK0COUT
(
"FAILED Observed sink traces ("
<< globalCount <<
") not equal to expected ("
74
<< expectedCount <<
")\n"
);
75
}
76
}
77
78
std::string
79
SinkTracer::FormatAddress
(
const
ns3::Address
address
)
80
{
81
std::stringstream ss;
82
83
if
(
InetSocketAddress::IsMatchingType
(
address
))
84
{
85
ss <<
InetSocketAddress::ConvertFrom
(
address
).
GetIpv4
() <<
":"
86
<<
InetSocketAddress::ConvertFrom
(
address
).
GetPort
();
87
}
88
else
if
(
Inet6SocketAddress::IsMatchingType
(
address
))
89
{
90
ss <<
Inet6SocketAddress::ConvertFrom
(
address
).
GetIpv6
() <<
":"
91
<<
Inet6SocketAddress::ConvertFrom
(
address
).
GetPort
();
92
}
93
return
ss.str();
94
}
95
96
}
// namespace ns3
ns3::Address
a polymophic address class
Definition:
address.h:101
ns3::Inet6SocketAddress::ConvertFrom
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
Definition:
inet6-socket-address.cc:117
ns3::Inet6SocketAddress::GetPort
uint16_t GetPort() const
Get the port.
Definition:
inet6-socket-address.cc:66
ns3::Inet6SocketAddress::IsMatchingType
static bool IsMatchingType(const Address &addr)
If the address match.
Definition:
inet6-socket-address.cc:94
ns3::Inet6SocketAddress::GetIpv6
Ipv6Address GetIpv6() const
Get the IPv6 address.
Definition:
inet6-socket-address.cc:80
ns3::InetSocketAddress::GetPort
uint16_t GetPort() const
Definition:
inet-socket-address.cc:71
ns3::InetSocketAddress::IsMatchingType
static bool IsMatchingType(const Address &address)
Definition:
inet-socket-address.cc:113
ns3::InetSocketAddress::GetIpv4
Ipv4Address GetIpv4() const
Definition:
inet-socket-address.cc:78
ns3::InetSocketAddress::ConvertFrom
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Definition:
inet-socket-address.cc:137
ns3::Ptr< const ns3::Packet >
ns3::SinkTracer::SinkTrace
static void SinkTrace(const ns3::Ptr< const ns3::Packet > packet, const ns3::Address &srcAddress, const ns3::Address &destAddress)
PacketSink receive trace callback.
Definition:
mpi-test-fixtures.cc:49
ns3::SinkTracer::m_worldRank
static int m_worldRank
MPI CommWorld rank.
Definition:
mpi-test-fixtures.h:157
ns3::SinkTracer::Verify
static void Verify(unsigned long expectedCount)
Verify the sink trace count observed matches the expected count.
Definition:
mpi-test-fixtures.cc:57
ns3::SinkTracer::m_worldSize
static int m_worldSize
MPI CommWorld size.
Definition:
mpi-test-fixtures.h:158
ns3::SinkTracer::m_line
static unsigned long m_line
Current output line number for ordering output.
Definition:
mpi-test-fixtures.h:156
ns3::SinkTracer::Init
static void Init()
PacketSink Init.
Definition:
mpi-test-fixtures.cc:40
ns3::SinkTracer::m_sinkCount
static unsigned long m_sinkCount
Running sum of number of SinkTrace calls observed.
Definition:
mpi-test-fixtures.h:155
ns3::SinkTracer::FormatAddress
static std::string FormatAddress(const ns3::Address address)
Get the source address and port, as a formatted string.
Definition:
mpi-test-fixtures.cc:79
RANK0COUT
#define RANK0COUT(x)
Write to std::cout only from rank 0.
Definition:
mpi-test-fixtures.h:60
mpi-test-fixtures.h
Common methods for MPI examples.
first.address
address
Definition:
first.py:47
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
mpi
examples
mpi-test-fixtures.cc
Generated on Sun Mar 3 2024 17:11:05 for ns-3 by
1.9.1