A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
mpi-test-fixtures.cc
Go to the documentation of this file.
1
/*
2
* Copyright 2018. Lawrence Livermore National Security, LLC.
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Steven Smith <smith84@llnl.gov>
7
*/
8
9
#include "
mpi-test-fixtures.h
"
10
11
#include "ns3/address.h"
12
#include "ns3/inet-socket-address.h"
13
#include "ns3/inet6-socket-address.h"
14
#include "ns3/packet.h"
15
#include "ns3/ptr.h"
16
#include "ns3/simulator.h"
17
18
#include <mpi.h>
19
20
namespace
ns3
21
{
22
23
unsigned
long
SinkTracer::m_sinkCount
= 0;
24
unsigned
long
SinkTracer::m_line
= 0;
25
int
SinkTracer::m_worldRank
= -1;
26
int
SinkTracer::m_worldSize
= -1;
27
28
void
29
SinkTracer::Init
()
30
{
31
m_sinkCount
= 0;
32
m_line
= 0;
33
MPI_Comm_rank(MPI_COMM_WORLD, &
m_worldRank
);
34
MPI_Comm_size(MPI_COMM_WORLD, &
m_worldSize
);
35
}
36
37
void
38
SinkTracer::SinkTrace
(
const
ns3::Ptr<const ns3::Packet>
packet,
39
const
ns3::Address
& srcAddress,
40
const
ns3::Address
& destAddress)
41
{
42
m_sinkCount
++;
43
}
44
45
void
46
SinkTracer::Verify
(
unsigned
long
expectedCount)
47
{
48
unsigned
long
globalCount;
49
50
#ifdef NS3_MPI
51
MPI_Reduce(&
m_sinkCount
, &globalCount, 1, MPI_UNSIGNED_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
52
#else
53
globalCount =
m_sinkCount
;
54
#endif
55
56
if
(expectedCount == globalCount)
57
{
58
RANK0COUT
(
"PASSED\n"
);
59
}
60
else
61
{
62
RANK0COUT
(
"FAILED Observed sink traces ("
<< globalCount <<
") not equal to expected ("
63
<< expectedCount <<
")\n"
);
64
}
65
}
66
67
std::string
68
SinkTracer::FormatAddress
(
const
ns3::Address
address)
69
{
70
std::stringstream ss;
71
72
if
(
InetSocketAddress::IsMatchingType
(address))
73
{
74
ss <<
InetSocketAddress::ConvertFrom
(address).
GetIpv4
() <<
":"
75
<<
InetSocketAddress::ConvertFrom
(address).
GetPort
();
76
}
77
else
if
(
Inet6SocketAddress::IsMatchingType
(address))
78
{
79
ss <<
Inet6SocketAddress::ConvertFrom
(address).
GetIpv6
() <<
":"
80
<<
Inet6SocketAddress::ConvertFrom
(address).
GetPort
();
81
}
82
return
ss.str();
83
}
84
85
}
// namespace ns3
ns3::Address
a polymophic address class
Definition
address.h:90
ns3::Inet6SocketAddress::ConvertFrom
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
Definition
inet6-socket-address.cc:106
ns3::Inet6SocketAddress::GetPort
uint16_t GetPort() const
Get the port.
Definition
inet6-socket-address.cc:55
ns3::Inet6SocketAddress::IsMatchingType
static bool IsMatchingType(const Address &addr)
If the address match.
Definition
inet6-socket-address.cc:83
ns3::Inet6SocketAddress::GetIpv6
Ipv6Address GetIpv6() const
Get the IPv6 address.
Definition
inet6-socket-address.cc:69
ns3::InetSocketAddress::GetPort
uint16_t GetPort() const
Definition
inet-socket-address.cc:55
ns3::InetSocketAddress::IsMatchingType
static bool IsMatchingType(const Address &address)
Definition
inet-socket-address.cc:83
ns3::InetSocketAddress::GetIpv4
Ipv4Address GetIpv4() const
Definition
inet-socket-address.cc:62
ns3::InetSocketAddress::ConvertFrom
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Definition
inet-socket-address.cc:106
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
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:38
ns3::SinkTracer::m_worldRank
static int m_worldRank
MPI CommWorld rank.
Definition
mpi-test-fixtures.h:146
ns3::SinkTracer::Verify
static void Verify(unsigned long expectedCount)
Verify the sink trace count observed matches the expected count.
Definition
mpi-test-fixtures.cc:46
ns3::SinkTracer::m_worldSize
static int m_worldSize
MPI CommWorld size.
Definition
mpi-test-fixtures.h:147
ns3::SinkTracer::m_line
static unsigned long m_line
Current output line number for ordering output.
Definition
mpi-test-fixtures.h:145
ns3::SinkTracer::Init
static void Init()
PacketSink Init.
Definition
mpi-test-fixtures.cc:29
ns3::SinkTracer::m_sinkCount
static unsigned long m_sinkCount
Running sum of number of SinkTrace calls observed.
Definition
mpi-test-fixtures.h:144
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:68
RANK0COUT
#define RANK0COUT(x)
Write to std::cout only from rank 0.
Definition
mpi-test-fixtures.h:49
mpi-test-fixtures.h
Common methods for MPI examples.
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
mpi
examples
mpi-test-fixtures.cc
Generated on Fri Nov 8 2024 13:59:04 for ns-3 by
1.11.0