Merge tag 'ns-3.38' into unison

ns-3.38 release
This commit is contained in:
F5
2023-11-14 15:58:35 +08:00
1315 changed files with 42965 additions and 20428 deletions

View File

@@ -87,3 +87,7 @@ if(${NS3_MONOLIB})
add_dependencies(timeTraceReport ${lib-ns3-monolib})
endif()
endif()
if(${NS3_FETCH_OPTIONAL_COMPONENTS})
add_dependency_to_optional_modules_dependencies()
endif()

View File

@@ -132,7 +132,7 @@ operator<<(std::ostream& os, const Angles& a)
double incl;
std::string unit;
if (a.m_printDeg)
if (Angles::m_printDeg)
{
azim = RadiansToDegrees(a.m_azimuth);
incl = RadiansToDegrees(a.m_inclination);

View File

@@ -120,7 +120,7 @@ class Angles
/**
* This constructor allows to specify azimuth and inclination.
* Inclination must be in [0, M_PI], while azimuth is
* automatically notmalized in [-M_PI, M_PI)
* automatically normalized in [-M_PI, M_PI)
*
* \param azimuth the azimuth angle in radians
* \param inclination the inclination angle in radians
@@ -209,7 +209,7 @@ class Angles
*
* Note: while an arbitrary value for the azimuth angle is valid
* and can be wrapped in [-M_PI, M_PI), an inclination angle outside
* the [0, M_PI] range can be ambiguos and is thus not valid.
* the [0, M_PI] range can be ambiguous and is thus not valid.
*/
void NormalizeAngles();

View File

@@ -36,7 +36,7 @@ NS_OBJECT_ENSURE_REGISTERED(PhasedArrayModel);
std::ostream&
operator<<(std::ostream& os, const PhasedArrayModel::ComplexVector& cv)
{
size_t N = cv.size();
size_t N = cv.GetSize();
// empty
if (N == 0)
@@ -63,7 +63,6 @@ PhasedArrayModel::PhasedArrayModel()
PhasedArrayModel::~PhasedArrayModel()
{
m_beamformingVector.clear();
}
TypeId
@@ -85,8 +84,8 @@ void
PhasedArrayModel::SetBeamformingVector(const ComplexVector& beamformingVector)
{
NS_LOG_FUNCTION(this << beamformingVector);
NS_ASSERT_MSG(beamformingVector.size() == GetNumberOfElements(),
beamformingVector.size() << " != " << GetNumberOfElements());
NS_ASSERT_MSG(beamformingVector.GetSize() == GetNumberOfElements(),
beamformingVector.GetSize() << " != " << GetNumberOfElements());
m_beamformingVector = beamformingVector;
m_isBfVectorValid = true;
}
@@ -101,30 +100,17 @@ PhasedArrayModel::GetBeamformingVector() const
return m_beamformingVector;
}
double
PhasedArrayModel::ComputeNorm(const ComplexVector& vector)
{
double norm = 0;
for (uint64_t i = 0; i < vector.size(); i++)
{
norm += std::norm(vector[i]);
}
return std::sqrt(norm);
}
PhasedArrayModel::ComplexVector
PhasedArrayModel::GetBeamformingVector(Angles a) const
{
NS_LOG_FUNCTION(this << a);
ComplexVector beamformingVector = GetSteeringVector(a);
double norm = ComputeNorm(beamformingVector);
double normRes = norm(beamformingVector);
for (uint64_t i = 0; i < beamformingVector.size(); i++)
for (size_t i = 0; i < GetNumberOfElements(); i++)
{
beamformingVector[i] = std::conj(beamformingVector[i]) / norm;
beamformingVector[i] = std::conj(beamformingVector[i]) / normRes;
}
return beamformingVector;
@@ -133,9 +119,8 @@ PhasedArrayModel::GetBeamformingVector(Angles a) const
PhasedArrayModel::ComplexVector
PhasedArrayModel::GetSteeringVector(Angles a) const
{
ComplexVector steeringVector;
steeringVector.resize(GetNumberOfElements());
for (uint64_t i = 0; i < GetNumberOfElements(); i++)
ComplexVector steeringVector(GetNumberOfElements());
for (size_t i = 0; i < GetNumberOfElements(); i++)
{
Vector loc = GetElementLocation(i);
double phase = -2 * M_PI *

View File

@@ -20,6 +20,7 @@
#include <ns3/angles.h>
#include <ns3/antenna-model.h>
#include <ns3/matrix-array.h>
#include <ns3/object.h>
#include <complex>
@@ -51,8 +52,24 @@ class PhasedArrayModel : public Object
*/
static TypeId GetTypeId();
typedef std::vector<std::complex<double>>
ComplexVector; //!< type definition for complex vectors
//!< type definition for complex vectors
using ComplexVector = ComplexMatrixArray; //!< the underlying Valarray
/**
* \brief Computes the Frobenius norm of the complex vector
*
* \param complexVector on which to calculate Frobenius norm
* \return the Frobenius norm of the complex vector
*/
double norm(const ComplexVector& complexVector) const
{
double norm = 0;
for (size_t i = 0; i < complexVector.GetSize(); i++)
{
norm += std::norm(complexVector[i]);
}
return std::sqrt(norm);
}
/**
* Returns the horizontal and vertical components of the antenna element field
@@ -76,7 +93,7 @@ class PhasedArrayModel : public Object
* Returns the number of antenna elements
* \return the number of antenna elements
*/
virtual uint64_t GetNumberOfElements() const = 0;
virtual size_t GetNumberOfElements() const = 0;
/**
* Sets the beamforming vector to be used

View File

@@ -25,11 +25,9 @@ namespace ns3
{
/**
*
* \brief Antenna model based on a parabolic approximation of the main lobe radiation pattern.
*
* This class implements the parabolic model as described in 3GPP TR 38.901 v15.0.0
*
*/
class ThreeGppAntennaModel : public AntennaModel
{
@@ -65,8 +63,8 @@ class ThreeGppAntennaModel : public AntennaModel
double GetSlaV() const;
/**
* Get the naximum attenuation of the antenna element.
* \return the naximum attenuation in dB
* Get the maximum attenuation of the antenna element.
* \return the maximum attenuation in dB
*/
double GetMaxAttenuation() const;

View File

@@ -249,7 +249,7 @@ UniformPlanarArray::GetElementLocation(uint64_t index) const
return loc;
}
uint64_t
size_t
UniformPlanarArray::GetNumberOfElements() const
{
return m_numRows * m_numColumns;

View File

@@ -81,7 +81,7 @@ class UniformPlanarArray : public PhasedArrayModel
* Returns the number of antenna elements
* \return the number of antenna elements
*/
uint64_t GetNumberOfElements() const override;
size_t GetNumberOfElements() const override;
private:
/**

View File

@@ -66,7 +66,7 @@ class CosineAntennaModelTestCase : public TestCase
* \param b Horizontal and Vertical Beamwidth
* \param o Orientation
* \param g MaxGain
* \param expectedGainDb Expeted antenna gain
* \param expectedGainDb Expected antenna gain
* \param cond Test condition
*/
CosineAntennaModelTestCase(Angles a,

View File

@@ -129,7 +129,7 @@ RadiansToDegreesTestCase::DoRun()
/**
* \ingroup tests
*
* \brief TestSuite: degree to radians (and viceversa) conversions
* \brief TestSuite: degree to radians (and vice-versa) conversions
*/
class DegreesRadiansTestSuite : public TestSuite
{

View File

@@ -45,7 +45,7 @@ class IsotropicAntennaModelTestCase : public TestCase
/**
* Constructor
* \param a Antenna angle
* \param expectedGainDb Expeted antenna gain
* \param expectedGainDb Expected antenna gain
*/
IsotropicAntennaModelTestCase(Angles a, double expectedGainDb);

View File

@@ -66,7 +66,7 @@ class ParabolicAntennaModelTestCase : public TestCase
* \param b Beamwidth
* \param o Orientation
* \param g MaxGain
* \param expectedGainDb Expeted antenna gain
* \param expectedGainDb Expected antenna gain
* \param cond Test condition
*/
ParabolicAntennaModelTestCase(Angles a,

View File

@@ -153,14 +153,16 @@ UniformPlanarArrayTestCase::ComputeGain(Ptr<UniformPlanarArray> a)
{
// compute gain
PhasedArrayModel::ComplexVector sv = a->GetSteeringVector(m_direction);
NS_TEST_EXPECT_MSG_EQ(sv.size(), a->GetNumberOfElements(), "steering vector of wrong size");
NS_TEST_EXPECT_MSG_EQ(sv.GetSize(), a->GetNumberOfElements(), "steering vector of wrong size");
PhasedArrayModel::ComplexVector bf = a->GetBeamformingVector(m_direction);
NS_TEST_EXPECT_MSG_EQ(bf.size(), a->GetNumberOfElements(), "beamforming vector of wrong size");
NS_TEST_EXPECT_MSG_EQ(bf.GetSize(),
a->GetNumberOfElements(),
"beamforming vector of wrong size");
std::pair<double, double> fp = a->GetElementFieldPattern(m_direction);
// scalar product dot (sv, bf)
std::complex<double> prod{0};
for (size_t i = 0; i < sv.size(); i++)
for (size_t i = 0; i < sv.GetSize(); i++)
{
prod += sv[i] * bf[i];
}

View File

@@ -24,8 +24,8 @@
#include "ns3/internet-module.h"
#include "ns3/mobility-module.h"
#include "ns3/network-module.h"
#include "ns3/ping-helper.h"
#include "ns3/point-to-point-module.h"
#include "ns3/v4ping-helper.h"
#include "ns3/yans-wifi-helper.h"
#include <cmath>
@@ -46,8 +46,8 @@ using namespace ns3;
*
* When 1/3 of simulation time has elapsed, one of the nodes is moved out of
* range, thereby breaking the topology. By default, this will result in
* only 34 of 100 pings being received. If the step size is reduced
* to cover the gap, then all pings can be received.
* stopping ping replies reception after sequence number 33. If the step size is reduced
* to cover the gap, then also the following pings can be received.
*/
class AodvExample
{
@@ -234,15 +234,15 @@ AodvExample::InstallInternetStack()
{
Ptr<OutputStreamWrapper> routingStream =
Create<OutputStreamWrapper>("aodv.routes", std::ios::out);
aodv.PrintRoutingTableAllAt(Seconds(8), routingStream);
Ipv4RoutingHelper::PrintRoutingTableAllAt(Seconds(8), routingStream);
}
}
void
AodvExample::InstallApplications()
{
V4PingHelper ping(interfaces.GetAddress(size - 1));
ping.SetAttribute("Verbose", BooleanValue(true));
PingHelper ping(interfaces.GetAddress(size - 1));
ping.SetAttribute("VerboseMode", EnumValue(Ping::VerboseMode::VERBOSE));
ApplicationContainer p = ping.Install(nodes.Get(0));
p.Start(Seconds(0));

View File

@@ -43,7 +43,7 @@ IdCache::IsDuplicate(Ipv4Address addr, uint32_t id)
return true;
}
}
struct UniqueId uniqueId = {addr, id, m_lifetime + Simulator::Now()};
UniqueId uniqueId = {addr, id, m_lifetime + Simulator::Now()};
m_idCache.push_back(uniqueId);
return false;
}

View File

@@ -79,7 +79,7 @@ class IdCache
/**
* Return lifetime for existing entries in cache
* \returns thhe lifetime
* \returns the lifetime
*/
Time GetLifeTime() const
{

View File

@@ -108,6 +108,7 @@ class TypeHeader : public Header
/**
* \brief Stream output operator
* \param os output stream
* \param h the TypeHeader
* \return updated stream
*/
std::ostream& operator<<(std::ostream& os, const TypeHeader& h);

View File

@@ -260,7 +260,6 @@ class RoutingProtocol : public Ipv4RoutingProtocol
///< originated route discovery.
bool m_enableHello; ///< Indicates whether a hello messages enable
bool m_enableBroadcast; ///< Indicates whether a a broadcast data packets forwarding enable
//\}
/// IP protocol
Ptr<Ipv4> m_ipv4;
@@ -377,8 +376,10 @@ class RoutingProtocol : public Ipv4RoutingProtocol
*/
Ptr<Ipv4Route> LoopbackRoute(const Ipv4Header& header, Ptr<NetDevice> oif) const;
///\name Receive control packets
//\{
/**
* \name Receive control packets
* @{
*/
/**
* Receive and process control packet
* \param socket input socket
@@ -410,10 +411,12 @@ class RoutingProtocol : public Ipv4RoutingProtocol
*/
/// Receive from node with address src
void RecvError(Ptr<Packet> p, Ipv4Address src);
//\}
/** @} */
///\name Send
//\{
/**
* \name Send
* @{
*/
/** Forward packet from route request queue
* \param dst destination address
* \param route route to use
@@ -459,7 +462,7 @@ class RoutingProtocol : public Ipv4RoutingProtocol
* \param origin originating node IP address
*/
void SendRerrWhenNoRouteToForward(Ipv4Address dst, uint32_t dstSeqNo, Ipv4Address origin);
/// @}
/** @} */
/**
* Send packet to destination socket

View File

@@ -33,13 +33,13 @@ namespace aodv
{
/**
* \ingroup aodv
* \defgroup aodv-test AODV module tests
* \ingroup aodv
* \ingroup tests
*/
/**
* \ingroup aodv-test
* \ingroup tests
*
* \brief Unit test for id cache
*/
@@ -111,7 +111,6 @@ IdCacheTest::CheckTimeout3()
/**
* \ingroup aodv-test
* \ingroup tests
*
* \brief Id Cache Test Suite
*/

View File

@@ -45,7 +45,6 @@ using namespace ns3;
/**
* \ingroup aodv-test
* \ingroup tests
*
* \brief AODV regression test suite
*/
@@ -69,7 +68,6 @@ class AodvRegressionTestSuite : public TestSuite
/**
* \ingroup aodv-test
* \ingroup tests
*
* \brief Chain Regression Test
*/

View File

@@ -30,7 +30,6 @@ namespace aodv
/**
* \ingroup aodv-test
* \ingroup tests
*
* \brief Unit test for neighbors
*/
@@ -136,7 +135,6 @@ NeighborTest::DoRun()
/**
* \ingroup aodv-test
* \ingroup tests
*
* \brief Type header test case
*/
@@ -164,7 +162,6 @@ struct TypeHeaderTest : public TestCase
/**
* \ingroup aodv-test
* \ingroup tests
*
* \brief Unit test for RREQ
*/
@@ -224,7 +221,6 @@ struct RreqHeaderTest : public TestCase
/**
* \ingroup aodv-test
* \ingroup tests
*
* \brief Unit test for RREP
*/
@@ -282,7 +278,6 @@ struct RrepHeaderTest : public TestCase
/**
* \ingroup aodv-test
* \ingroup tests
*
* \brief Unit test for RREP-ACK
*/
@@ -307,7 +302,6 @@ struct RrepAckHeaderTest : public TestCase
/**
* \ingroup aodv-test
* \ingroup tests
*
* \brief Unit test for RERR
*/
@@ -342,7 +336,6 @@ struct RerrHeaderTest : public TestCase
/**
* \ingroup aodv-test
* \ingroup tests
*
* \brief Unit test for AODV routing table entry
*/
@@ -559,7 +552,6 @@ AodvRqueueTest::CheckTimeout()
/**
* \ingroup aodv-test
* \ingroup tests
*
* \brief Unit test for AODV routing table entry
*/
@@ -653,7 +645,6 @@ struct AodvRtableEntryTest : public TestCase
/**
* \ingroup aodv-test
* \ingroup tests
*
* \brief Unit test for AODV routing table
*/
@@ -741,7 +732,6 @@ struct AodvRtableTest : public TestCase
/**
* \ingroup aodv-test
* \ingroup tests
*
* \brief AODV test suite
*/

View File

@@ -74,7 +74,7 @@ class LoopbackTestCase : public TestCase
* Echo data function
* \param socket The socket to echo data
*/
void EchoData(Ptr<Socket> socket);
void EchoData(Ptr<Socket> socket) const;
public:
LoopbackTestCase();
@@ -98,7 +98,7 @@ LoopbackTestCase::ReceivePkt(Ptr<Socket> socket)
}
void
LoopbackTestCase::EchoData(Ptr<Socket> socket)
LoopbackTestCase::EchoData(Ptr<Socket> socket) const
{
Address from;
Ptr<Packet> receivedPacket = socket->RecvFrom(std::numeric_limits<uint32_t>::max(), 0, from);
@@ -191,7 +191,6 @@ LoopbackTestCase::DoRun()
/**
* \ingroup aodv-test
* \ingroup tests
*
* \brief AODV Loopback test suite
*/

View File

@@ -50,11 +50,12 @@ UdpClient::GetTypeId()
.SetParent<Application>()
.SetGroupName("Applications")
.AddConstructor<UdpClient>()
.AddAttribute("MaxPackets",
"The maximum number of packets the application will send",
UintegerValue(100),
MakeUintegerAccessor(&UdpClient::m_count),
MakeUintegerChecker<uint32_t>())
.AddAttribute(
"MaxPackets",
"The maximum number of packets the application will send (zero means infinite)",
UintegerValue(100),
MakeUintegerAccessor(&UdpClient::m_count),
MakeUintegerChecker<uint32_t>())
.AddAttribute("Interval",
"The time to wait between packets",
TimeValue(Seconds(1.0)),
@@ -223,7 +224,7 @@ UdpClient::Send()
}
#endif // NS3_LOG_ENABLE
if (m_sent < m_count)
if (m_sent < m_count || m_count == 0)
{
m_sendEvent = Simulator::Schedule(m_interval, &UdpClient::Send, this);
}

View File

@@ -44,11 +44,12 @@ UdpEchoClient::GetTypeId()
.SetParent<Application>()
.SetGroupName("Applications")
.AddConstructor<UdpEchoClient>()
.AddAttribute("MaxPackets",
"The maximum number of packets the application will send",
UintegerValue(100),
MakeUintegerAccessor(&UdpEchoClient::m_count),
MakeUintegerChecker<uint32_t>())
.AddAttribute(
"MaxPackets",
"The maximum number of packets the application will send (zero means infinite)",
UintegerValue(100),
MakeUintegerAccessor(&UdpEchoClient::m_count),
MakeUintegerChecker<uint32_t>())
.AddAttribute("Interval",
"The time to wait between packets",
TimeValue(Seconds(1.0)),
@@ -391,7 +392,7 @@ UdpEchoClient::Send()
<< Inet6SocketAddress::ConvertFrom(m_peerAddress).GetPort());
}
if (m_sent < m_count)
if (m_sent < m_count || m_count == 0)
{
ScheduleTransmit(m_interval);
}

View File

@@ -48,16 +48,18 @@ NS_OBJECT_ENSURE_REGISTERED(UdpTraceClient);
/**
* \brief Default trace to send
*/
struct UdpTraceClient::TraceEntry UdpTraceClient::g_defaultEntries[] = {{0, 534, 'I'},
{40, 1542, 'P'},
{120, 134, 'B'},
{80, 390, 'B'},
{240, 765, 'P'},
{160, 407, 'B'},
{200, 504, 'B'},
{360, 903, 'P'},
{280, 421, 'B'},
{320, 587, 'B'}};
struct UdpTraceClient::TraceEntry UdpTraceClient::g_defaultEntries[] = {
{0, 534, 'I'},
{40, 1542, 'P'},
{120, 134, 'B'},
{80, 390, 'B'},
{240, 765, 'P'},
{160, 407, 'B'},
{200, 504, 'B'},
{360, 903, 'P'},
{280, 421, 'B'},
{320, 587, 'B'},
};
TypeId
UdpTraceClient::GetTypeId()
@@ -149,7 +151,7 @@ void
UdpTraceClient::SetTraceFile(std::string traceFile)
{
NS_LOG_FUNCTION(this << traceFile);
if (traceFile == "")
if (traceFile.empty())
{
LoadDefaultTrace();
}
@@ -229,9 +231,9 @@ UdpTraceClient::LoadDefaultTrace()
{
NS_LOG_FUNCTION(this);
uint32_t prevTime = 0;
for (uint32_t i = 0; i < (sizeof(g_defaultEntries) / sizeof(struct TraceEntry)); i++)
for (uint32_t i = 0; i < (sizeof(g_defaultEntries) / sizeof(TraceEntry)); i++)
{
struct TraceEntry entry = g_defaultEntries[i];
TraceEntry entry = g_defaultEntries[i];
if (entry.frameType == 'B')
{
entry.timeToSend = 0;

View File

@@ -165,9 +165,9 @@ class UdpTraceClient : public Application
uint16_t m_peerPort; //!< Remote peer port
EventId m_sendEvent; //!< Event to send the next packet
std::vector<struct TraceEntry> m_entries; //!< Entries in the trace to send
uint32_t m_currentEntry; //!< Current entry index
static struct TraceEntry g_defaultEntries[]; //!< Default trace to send
std::vector<TraceEntry> m_entries; //!< Entries in the trace to send
uint32_t m_currentEntry; //!< Current entry index
static TraceEntry g_defaultEntries[]; //!< Default trace to send
uint16_t m_maxPacketSize; //!< Maximum packet size to send (including the SeqTsHeader)
bool m_traceLoop; //!< Loop through the trace file
};

View File

@@ -173,8 +173,8 @@ class BulkSendSeqTsSizeTestCase : public TestCase
uint64_t m_received{0}; //!< number of bytes received
uint64_t m_seqTxCounter{0}; //!< Counter for Sequences on Tx
uint64_t m_seqRxCounter{0}; //!< Counter for Sequences on Rx
Time m_lastTxTs{Seconds(0)}; //!< Last recored timestamp on Tx
Time m_lastRxTs{Seconds(0)}; //!< Last recored timestamp on Rx
Time m_lastTxTs{Seconds(0)}; //!< Last recorded timestamp on Tx
Time m_lastRxTs{Seconds(0)}; //!< Last recorded timestamp on Rx
};
BulkSendSeqTsSizeTestCase::BulkSendSeqTsSizeTestCase()

View File

@@ -330,13 +330,13 @@ UdpEchoClientSetFillTestCase::DoRun()
ApplicationContainer clientApps = echoClient.Install(nodes.Get(0));
uint8_t arry[64];
uint8_t array[64];
uint8_t i;
for (i = 0; i < 64; i++)
{
arry[i] = i;
array[i] = i;
}
echoClient.SetFill(clientApps.Get(0), &(arry[0]), (uint32_t)64, (uint32_t)64);
echoClient.SetFill(clientApps.Get(0), &(array[0]), (uint32_t)64, (uint32_t)64);
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(10.0));

View File

@@ -16,7 +16,7 @@
// Network topology
//
// bridge1 The node named bridge1 (node 5 in the nodelist)
// ------------------ has three CMSA net devices that are bridged
// ------------------ has three CSMA net devices that are bridged
// CSMA CSMA CSMA together using a BridgeNetDevice.
// | | |
// | | | The bridge node talks over three CSMA channels
@@ -34,7 +34,7 @@
// | | |
// | | |
// CSMA CSMA CSMA The node named bridge2 (node 6 in the nodelist)
// ------------------ has three CMSA net devices that are bridged
// ------------------ has three CSMA net devices that are bridged
// bridge2 together using a BridgeNetDevice.
//
// Or, more abstractly, recognizing that bridge 1 and bridge 2 are nodes
@@ -238,4 +238,6 @@ main(int argc, char* argv[])
Simulator::Run();
Simulator::Destroy();
NS_LOG_INFO("Done.");
return 0;
}

View File

@@ -167,4 +167,6 @@ main(int argc, char* argv[])
Simulator::Run();
Simulator::Destroy();
NS_LOG_INFO("Done.");
return 0;
}

View File

@@ -96,8 +96,7 @@ def main(argv):
port = 9 # Discard port(RFC 863)
inet_sock_address = ns.network.InetSocketAddress(ns.network.Ipv4Address("10.1.1.2"), port)
onoff = ns.applications.OnOffHelper("ns3::UdpSocketFactory",
ns.network.Address(ns.addressFromInetSocketAddress(inet_sock_address)))
onoff = ns.applications.OnOffHelper("ns3::UdpSocketFactory", inet_sock_address.ConvertTo())
onoff.SetConstantRate (ns.network.DataRate ("500kb/s"))
app = onoff.Install(ns.network.NodeContainer(terminals.Get(0)))
@@ -107,8 +106,7 @@ def main(argv):
# Create an optional packet sink to receive these packets
inet_address = ns.network.InetSocketAddress(ns.network.Ipv4Address.GetAny(), port)
sink = ns.applications.PacketSinkHelper("ns3::UdpSocketFactory",
ns.network.Address(ns.addressFromInetSocketAddress(inet_address)))
sink = ns.applications.PacketSinkHelper("ns3::UdpSocketFactory", inet_address.ConvertTo())
app = sink.Install(ns.network.NodeContainer(terminals.Get(1)))
app.Start(ns.core.Seconds(0.0))
@@ -117,7 +115,7 @@ def main(argv):
#
inet_address = ns.network.InetSocketAddress(ns.network.Ipv4Address("10.1.1.1"), port)
onoff.SetAttribute("Remote",
ns.network.AddressValue(ns.addressFromInetSocketAddress(inet_address)))
ns.network.AddressValue(inet_address.ConvertTo()))
app = onoff.Install(ns.network.NodeContainer(terminals.Get(3)))
app.Start(ns.core.Seconds(1.1))
app.Stop(ns.core.Seconds(10.0))

View File

@@ -18,8 +18,10 @@ find_external_library(
if((NOT
brite_FOUND)
OR (NOT
${brite_FOUND})
AND (NOT
${brite_FOUND})
AND (NOT
${NS3_FETCH_OPTIONAL_COMPONENTS})
)
message(
${HIGHLIGHTED_STATUS}
@@ -28,6 +30,12 @@ if((NOT
return()
endif()
if(${NS3_FETCH_OPTIONAL_COMPONENTS})
set(brite_LIBRARIES
brite
)
endif()
# Only process module if include folder and library have been found
include_directories(${brite_INCLUDE_DIRS})
set(NS3_BRITE

View File

@@ -14,6 +14,8 @@
*
*/
#include "Brite.h"
#include "ns3/applications-module.h"
#include "ns3/brite-module.h"
#include "ns3/core-module.h"

View File

@@ -14,6 +14,8 @@
*
*/
#include "Brite.h"
#include "ns3/applications-module.h"
#include "ns3/brite-module.h"
#include "ns3/core-module.h"

View File

@@ -15,7 +15,7 @@ BeginModel
EndModel
BeginOutput #**Atleast one of these options should have value 1**
BeginOutput #**At least one of these options should have value 1**
BRITE = 1 #0 = Do not save as BRITE, 1 = save as BRITE.
OTTER = 0 #0 = Do not visualize with Otter, 1 = Visualize
EndOutput

View File

@@ -17,7 +17,7 @@ BeginModel
BWMax = 1024.0
EndModel
BeginOutput #**Atleast one of these options should have value 1**
BeginOutput #**At least one of these options should have value 1**
BRITE = 1 #0 = Do not save as BRITE, 1 = save as BRITE.
OTTER = 0 #0 = Do not visualize with Otter, 1 = Visualize
EndOutput

View File

@@ -16,7 +16,7 @@ EndModel
BeginOutput #**Atleast one of these options should have value 1**
BeginOutput #**At least one of these options should have value 1**
BRITE = 1 #0 = Do not save as BRITE, 1 = save as BRITE.
OTTER = 0 #0 = Do not visualize with Otter, 1 = Visualize
EndOutput

View File

@@ -16,7 +16,7 @@ EndModel
BeginOutput #**Atleast one of these options should have value 1**
BeginOutput #**At least one of these options should have value 1**
BRITE = 1 #0 = Do not save as BRITE, 1 = save as BRITE.
OTTER = 0 #0 = Do not visualize with Otter, 1 = Visualize
EndOutput

View File

@@ -16,7 +16,7 @@ EndModel
BeginOutput #**Atleast one of these options should have value 1**
BeginOutput #**At least one of these options should have value 1**
BRITE = 1 #0 = Do not save as BRITE, 1 = save as BRITE.
OTTER = 1 #0 = Do not visualize with Otter, 1 = Visualize
EndOutput

View File

@@ -16,7 +16,7 @@ EndModel
BeginOutput #**Atleast one of these options should have value 1**
BeginOutput #**At least one of these options should have value 1**
BRITE = 1 #0 = Do not save as BRITE, 1 = save as BRITE.
OTTER = 0 #0 = Do not visualize with Otter, 1 = Visualize
EndOutput

View File

@@ -19,7 +19,7 @@ EndModel
BeginOutput #**Atleast one of these options should have value 1**
BeginOutput #**At least one of these options should have value 1**
BRITE = 1 #0 = Do not save as BRITE, 1 = save as BRITE.
OTTER = 1 #0 = Do not visualize with Otter, 1 = Visualize
EndOutput

View File

@@ -19,7 +19,7 @@ EndModel
BeginOutput #**Atleast one of these options should have value 1**
BeginOutput #**At least one of these options should have value 1**
BRITE = 1 #0 = Do not save as BRITE, 1 = save as BRITE.
OTTER = 0 #0 = Do not visualize with Otter, 1 = Visualize
EndOutput

View File

@@ -19,7 +19,7 @@ EndModel
BeginOutput #**Atleast one of these options should have value 1**
BeginOutput #**At least one of these options should have value 1**
BRITE = 1 #0 = Do not save as BRITE, 1 = save as BRITE.
OTTER = 0 #0 = Do not visualize with Otter, 1 = Visualize
EndOutput

View File

@@ -19,7 +19,7 @@ EndModel
BeginOutput #**Atleast one of these options should have value 1**
BeginOutput #**At least one of these options should have value 1**
BRITE = 1 #0 = Do not save as BRITE, 1 = save as BRITE.
OTTER = 0 #0 = Do not visualize with Otter, 1 = Visualize
EndOutput

View File

@@ -43,7 +43,7 @@ BeginModel
BWMax = -1.0
EndModel
BeginOutput #**Atleast one of these options should have value 1**
BeginOutput #**At least one of these options should have value 1**
BRITE = 1 #0 = Do not save as BRITE, 1 = save as BRITE.
OTTER = 0 #0 = Do not visualize with Otter, 1 = Visualize
EndOutput

View File

@@ -16,6 +16,8 @@
#include "brite-topology-helper.h"
#include "Brite.h"
#include "ns3/abort.h"
#include "ns3/data-rate.h"
#include "ns3/ipv4-address-helper.h"

View File

@@ -28,8 +28,12 @@
#include <string>
#include <vector>
// located in BRITE source directory
#include "Brite.h"
// These are in #include <Brite.h>,
// here we just need a forward declaration.
namespace brite
{
struct Topology;
};
namespace ns3
{

View File

@@ -151,8 +151,8 @@ The shadowing is modeled according to a log-normal distribution with variable st
The model considers that the mean of the shadowing loss in dB is always 0. For the variance, the model considers three possible values of standard deviation, in detail:
* outdoor (``m_shadowingSigmaOutdoor``, defaul value of 7 dB) :math:`\rightarrow X_\mathrm{O} \sim N(\mu_\mathrm{O}, \sigma_\mathrm{O}^2)`.
* indoor (``m_shadowingSigmaIndoor``, defaul value of 10 dB) :math:`\rightarrow X_\mathrm{I} \sim N(\mu_\mathrm{I}, \sigma_\mathrm{I}^2)`.
* outdoor (``m_shadowingSigmaOutdoor``, default value of 7 dB) :math:`\rightarrow X_\mathrm{O} \sim N(\mu_\mathrm{O}, \sigma_\mathrm{O}^2)`.
* indoor (``m_shadowingSigmaIndoor``, default value of 10 dB) :math:`\rightarrow X_\mathrm{I} \sim N(\mu_\mathrm{I}, \sigma_\mathrm{I}^2)`.
* external walls penetration (``m_shadowingSigmaExtWalls``, default value 5 dB) :math:`\rightarrow X_\mathrm{W} \sim N(\mu_\mathrm{W}, \sigma_\mathrm{W}^2)`
The simulator generates a shadowing value per each active link according to nodes' position the first time the link is used for transmitting. In case of transmissions from outdoor nodes to indoor ones, and vice-versa, the standard deviation (:math:`\sigma_\mathrm{IO}`) has to be calculated as the square root of the sum of the quadratic values of the standard deviatio in case of outdoor nodes and the one for the external walls penetration. This is due to the fact that that the components producing the shadowing are independent of each other; therefore, the variance of a distribution resulting from the sum of two independent normal ones is the sum of the variances.

View File

@@ -30,13 +30,13 @@ As an example, let's create a residential 10 x 20 x 10 building::
double y_max = 20.0;
double z_min = 0.0;
double z_max = 10.0;
Ptr<Building> b = CreateObject <Building> ();
b->SetBoundaries (Box (x_min, x_max, y_min, y_max, z_min, z_max));
b->SetBuildingType (Building::Residential);
b->SetExtWallsType (Building::ConcreteWithWindows);
b->SetNFloors (3);
b->SetNRoomsX (3);
b->SetNRoomsY (2);
Ptr<Building> b = CreateObject<Building>();
b->SetBoundaries(Box(x_min, x_max, y_min, y_max, z_min, z_max));
b->SetBuildingType(Building::Residential);
b->SetExtWallsType(Building::ConcreteWithWindows);
b->SetNFloors(3);
b->SetNRoomsX(3);
b->SetNRoomsY(2);
This building has three floors and an internal 3 x 2 grid of rooms of equal size.
@@ -45,19 +45,19 @@ create a set of buildings with identical characteristics placed on a
rectangular grid. Here's an example of how to use it::
Ptr<GridBuildingAllocator> gridBuildingAllocator;
gridBuildingAllocator = CreateObject<GridBuildingAllocator> ();
gridBuildingAllocator->SetAttribute ("GridWidth", UintegerValue (3));
gridBuildingAllocator->SetAttribute ("LengthX", DoubleValue (7));
gridBuildingAllocator->SetAttribute ("LengthY", DoubleValue (13));
gridBuildingAllocator->SetAttribute ("DeltaX", DoubleValue (3));
gridBuildingAllocator->SetAttribute ("DeltaY", DoubleValue (3));
gridBuildingAllocator->SetAttribute ("Height", DoubleValue (6));
gridBuildingAllocator->SetBuildingAttribute ("NRoomsX", UintegerValue (2));
gridBuildingAllocator->SetBuildingAttribute ("NRoomsY", UintegerValue (4));
gridBuildingAllocator->SetBuildingAttribute ("NFloors", UintegerValue (2));
gridBuildingAllocator->SetAttribute ("MinX", DoubleValue (0));
gridBuildingAllocator->SetAttribute ("MinY", DoubleValue (0));
gridBuildingAllocator->Create (6);
gridBuildingAllocator = CreateObject<GridBuildingAllocator>();
gridBuildingAllocator->SetAttribute("GridWidth", UintegerValue(3));
gridBuildingAllocator->SetAttribute("LengthX", DoubleValue(7));
gridBuildingAllocator->SetAttribute("LengthY", DoubleValue(13));
gridBuildingAllocator->SetAttribute("DeltaX", DoubleValue(3));
gridBuildingAllocator->SetAttribute("DeltaY", DoubleValue(3));
gridBuildingAllocator->SetAttribute("Height", DoubleValue(6));
gridBuildingAllocator->SetBuildingAttribute("NRoomsX", UintegerValue(2));
gridBuildingAllocator->SetBuildingAttribute("NRoomsY", UintegerValue(4));
gridBuildingAllocator->SetBuildingAttribute("NFloors", UintegerValue(2));
gridBuildingAllocator->SetAttribute("MinX", DoubleValue(0));
gridBuildingAllocator->SetAttribute("MinY", DoubleValue(0));
gridBuildingAllocator->Create(6);
This will create a 3x2 grid of 6 buildings, each 7 x 13 x 6 m with 2 x
@@ -74,10 +74,10 @@ use them with the buildings model you need an additional call to
the information on their position w.r.t. the buildings. Here is an example::
MobilityHelper mobility;
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
ueNodes.Create (2);
mobility.Install (ueNodes);
BuildingsHelper::Install (ueNodes);
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
ueNodes.Create(2);
mobility.Install(ueNodes);
BuildingsHelper::Install(ueNodes);
It is to be noted that any mobility model can be used. However, the
user is advised to make sure that the behavior of the mobility model
@@ -120,18 +120,18 @@ Any legacy ns-3 positioning method can be used to place node in the
simulation. The important additional step is to For example, you can
place nodes manually like this::
Ptr<ConstantPositionMobilityModel> mm0 = enbNodes.Get (0)->GetObject<ConstantPositionMobilityModel> ();
Ptr<ConstantPositionMobilityModel> mm1 = enbNodes.Get (1)->GetObject<ConstantPositionMobilityModel> ();
mm0->SetPosition (Vector (5.0, 5.0, 1.5));
mm1->SetPosition (Vector (30.0, 40.0, 1.5));
Ptr<ConstantPositionMobilityModel> mm0 = enbNodes.Get(0)->GetObject<ConstantPositionMobilityModel>();
Ptr<ConstantPositionMobilityModel> mm1 = enbNodes.Get(1)->GetObject<ConstantPositionMobilityModel>();
mm0->SetPosition(Vector(5.0, 5.0, 1.5));
mm1->SetPosition(Vector(30.0, 40.0, 1.5));
MobilityHelper mobility;
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
ueNodes.Create (2);
mobility.Install (ueNodes);
BuildingsHelper::Install (ueNodes);
mm0->SetPosition (Vector (5.0, 5.0, 1.5));
mm1->SetPosition (Vector (30.0, 40.0, 1.5));
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
ueNodes.Create(2);
mobility.Install(ueNodes);
BuildingsHelper::Install(ueNodes);
mm0->SetPosition(Vector(5.0, 5.0, 1.5));
mm1->SetPosition(Vector(30.0, 40.0, 1.5));
Alternatively, you could use any existing PositionAllocator
class. The coordinates of the node will determine whether it is placed
@@ -220,9 +220,9 @@ The ``BuildingMobilityLossModel`` parameter configurable with the ns3 attribute
The ``BuildingPropagationLossModel`` class has the following configurable parameters configurable with the attribute system:
* ``Frequency``: reference frequency (default 2160 MHz), note that by setting the frequency the wavelength is set accordingly automatically and viceversa).
* ``Frequency``: reference frequency (default 2160 MHz), note that by setting the frequency the wavelength is set accordingly automatically and vice-versa).
* ``Lambda``: the wavelength (0.139 meters, considering the above frequency).
* ``ShadowSigmaOutdoor``: the standard deviation of the shadowing for outdoor nodes (defaul 7.0).
* ``ShadowSigmaOutdoor``: the standard deviation of the shadowing for outdoor nodes (default 7.0).
* ``ShadowSigmaIndoor``: the standard deviation of the shadowing for indoor nodes (default 8.0).
* ``ShadowSigmaExtWalls``: the standard deviation of the shadowing due to external walls penetration for outdoor to indoor communications (default 5.0).
* ``RooftopLevel``: the level of the rooftop of the building in meters (default 20 meters).

View File

@@ -95,4 +95,6 @@ main(int argc, char* argv[])
}
Simulator::Destroy();
return 0;
}

View File

@@ -98,7 +98,7 @@ PrintPosition(Ptr<Node> node)
/**
* Print the buildings list in a format that can be used by Gnuplot to draw them.
*
* \param filename The ouput filename.
* \param filename The output filename.
*/
void
PrintGnuplottableBuildingListToFile(std::string filename)
@@ -279,4 +279,6 @@ main(int argc, char* argv[])
Simulator::Run();
g_timeSeries.close();
Simulator::Destroy();
return 0;
}

View File

@@ -31,7 +31,7 @@ NS_LOG_COMPONENT_DEFINE("OutdoorRandomWalkExample");
/**
* Print the buildings list in a format that can be used by Gnuplot to draw them.
*
* \param filename The ouput filename.
* \param filename The output filename.
*/
void
PrintGnuplottableBuildingListToFile(std::string filename)
@@ -131,4 +131,6 @@ main(int argc, char* argv[])
Simulator::Stop(Seconds(1e4));
Simulator::Run();
Simulator::Destroy();
return 0;
}

View File

@@ -137,7 +137,7 @@ class BuildingContainer
* Buildings can be retrieved from the container in two ways. First,
* directly by an index into the container, and second, using an iterator.
* This method is used in the direct method and is used to retrieve the
* indexed Ptr<Appliation>.
* indexed Ptr<Application>.
*
* \code
* uint32_t nBuildings = container.GetN ();

View File

@@ -162,7 +162,7 @@ class RandomRoomPositionAllocator : public PositionAllocator
private:
/**
* Room informations
* Room information
*/
struct RoomInfo
{

View File

@@ -55,13 +55,13 @@ class BuildingListPriv : public Object
*/
uint32_t Add(Ptr<Building> building);
/**
* Returns an interator to the start of the list.
* Returns an iterator to the start of the list.
*
* \returns iterator to the begin of the container.
*/
BuildingList::Iterator Begin() const;
/**
* Returns an interator to the end of the list.
* Returns an iterator to the end of the list.
*
* \returns iterator to the end of the container.
*/

View File

@@ -105,7 +105,7 @@ BuildingsChannelConditionModel::GetChannelCondition(Ptr<const MobilityModel> a,
{
cond->SetO2iCondition(ChannelCondition::O2iConditionValue::O2I);
NS_LOG_DEBUG("a is indoor and b outdoor or viceversa");
NS_LOG_DEBUG("a is indoor and b outdoor or vice-versa");
cond->SetLosCondition(ChannelCondition::LosConditionValue::NLOS);
}

View File

@@ -174,7 +174,7 @@ HybridBuildingsPropagationLossModel::GetLoss(Ptr<MobilityModel> a, Ptr<MobilityM
}
else
{
// Over the rooftop tranmission -> Okumura Hata
// Over the rooftop transmission -> Okumura Hata
loss = OkumuraHata(a, b);
NS_LOG_INFO(this << " O-O (>1000): above rooftop -> OH : " << loss);
}

View File

@@ -124,7 +124,7 @@ class RandomWalk2dOutdoorMobilityModel : public MobilityModel
ConstantVelocityHelper m_helper; //!< helper for this object
EventId m_event; //!< stored event ID
enum Mode m_mode; //!< whether in time or distance mode
Mode m_mode; //!< whether in time or distance mode
double m_modeDistance; //!< Change direction and speed after this distance
Time m_modeTime; //!< Change current direction and speed after this delay
Ptr<RandomVariableStream> m_speed; //!< rv for picking speed

View File

@@ -59,14 +59,14 @@ class BuildingsChannelConditionModelTestCase : public TestCase
/**
* Struct containing the parameters for each test
*/
typedef struct
struct TestVector
{
Vector m_positionA; //!< the position of the first node
Vector m_positionB; //!< the position of the second node
ChannelCondition::LosConditionValue m_losCond; //!< the correct channel condition
} TestVector;
};
TestVectors<TestVector> m_testVectors; //!< array containg all the test vectors
TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
};
BuildingsChannelConditionModelTestCase::BuildingsChannelConditionModelTestCase()

View File

@@ -55,7 +55,7 @@ class BuildingsPathlossTestCase : public TestCase
* \param freq Communication frequency
* \param m1 First MobilityModel Index
* \param m2 Second MobilityModel Index
* \param env Enviroment type
* \param env Environment type
* \param city City size
* \param refValue Theoretical loss
* \param name Test name
@@ -81,7 +81,7 @@ class BuildingsPathlossTestCase : public TestCase
double m_freq; //!< Communication frequency
uint16_t m_mobilityModelIndex1; //!< First MobilityModel Index
uint16_t m_mobilityModelIndex2; //!< Second MobilityModel Index
EnvironmentType m_env; //!< Enviroment type
EnvironmentType m_env; //!< Environment type
CitySize m_city; //!< City size
double m_lossRef; //!< Theoretical loss
};

View File

@@ -68,15 +68,15 @@ class ThreeGppV2vBuildingsChCondModelTestCase : public TestCase
/**
* Struct containing the parameters for each test
*/
typedef struct
struct TestVector
{
Vector m_positionA; //!< the position of the first node
Vector m_positionB; //!< the position of the second node
ChannelCondition::LosConditionValue m_losCond; //!< the correct channel condition
TypeId m_typeId; //!< the type ID of the channel condition model to be used
} TestVector;
};
TestVectors<TestVector> m_testVectors; //!< array containg all the test vectors
TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
};
ThreeGppV2vBuildingsChCondModelTestCase::ThreeGppV2vBuildingsChCondModelTestCase()
@@ -221,13 +221,13 @@ class ThreeGppV2vUrbanLosNlosvChCondModelTestCase : public TestCase
/**
* Struct containing the parameters for each test
*/
typedef struct
struct TestVector
{
Vector m_positionA; //!< the position of the first node
Vector m_positionB; //!< the position of the second node
double m_pLos; //!< LOS probability
TypeId m_typeId; //!< the type ID of the channel condition model to be used
} TestVector;
};
TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
Ptr<ThreeGppV2vUrbanChannelConditionModel> m_condModel; //!< the channel condition model
@@ -386,13 +386,13 @@ class ThreeGppV2vHighwayLosNlosvChCondModelTestCase : public TestCase
/**
* Struct containing the parameters for each test
*/
typedef struct
struct TestVector
{
Vector m_positionA; //!< the position of the first node
Vector m_positionB; //!< the position of the second node
double m_pLos; //!< LOS probability
TypeId m_typeId; //!< the type ID of the channel condition model to be used
} TestVector;
};
TestVectors<TestVector> m_testVectors; //!< array containing all the test vectors
Ptr<ThreeGppV2vHighwayChannelConditionModel> m_condModel; //!< the channel condition model

View File

@@ -23,6 +23,8 @@ if((NOT
click_FOUND)
AND (NOT
${click_FOUND})
AND (NOT
${NS3_FETCH_OPTIONAL_COMPONENTS})
)
message(
${HIGHLIGHTED_STATUS}
@@ -31,6 +33,13 @@ if((NOT
return()
endif()
if(${NS3_FETCH_OPTIONAL_COMPONENTS})
set(click_LIBRARIES
click
nsclick
)
endif()
include_directories(${click_INCLUDE_DIRS})
set(NS3_CLICK
"ON"

View File

@@ -142,9 +142,9 @@ class in your simulation script. For instance:
.. sourcecode:: cpp
ClickInternetStackHelper click;
click.SetClickFile (myNodeContainer, "nsclick-simple-lan.click");
click.SetRoutingTableElement (myNodeContainer, "u/rt");
click.Install (myNodeContainer);
click.SetClickFile(myNodeContainer, "nsclick-simple-lan.click");
click.SetRoutingTableElement(myNodeContainer, "u/rt");
click.Install(myNodeContainer);
The example scripts inside ``src/click/examples/`` demonstrate the use of Click based nodes
in different scenarios. The helper source can be found inside ``src/click/helper/click-internet-stack-helper.{h,cc}``

View File

@@ -29,6 +29,7 @@
#include "ns3/random-variable-stream.h"
#include "ns3/simulator.h"
#include <click/simclick.h>
#include <cstdarg>
#include <cstdlib>
#include <map>
@@ -817,7 +818,7 @@ simclick_sim_command(simclick_node_t* simnode, int cmd, ...)
// Try to fill the buffer with up to size bytes.
// If this is not enough space, write the required buffer size into
// the size variable and return an error code.
// Otherwise return the bytes actually writte into the buffer in size.
// Otherwise return the bytes actually written into the buffer in size.
// Append key/value pair, separated by \0.
std::map<std::string, std::string> defines = clickInstance->GetDefines();

View File

@@ -26,19 +26,18 @@
#include "ns3/packet.h"
#include "ns3/test.h"
#include <sys/time.h>
#include <sys/types.h>
#ifdef NS3_CLICK
#include <click/simclick.h>
#endif
#include <map>
#include <string>
#include <sys/time.h>
#include <sys/types.h>
class ClickTrivialTest;
class ClickIfidFromNameTest;
class ClickIpMacAddressFromNameTest;
// These are in #include <click/simclick.h>,
// here we just need a forward declaration.
struct simclick_node;
typedef struct simclick_node simclick_node_t;
namespace ns3
{

View File

@@ -113,4 +113,6 @@ main(int argc, char* argv[])
Simulator::Run();
Simulator::Destroy();
return 0;
}

View File

@@ -73,7 +73,7 @@ AttributeIterator::GetCurrentPath(std::string attr) const
{
oss << "/" << m_currentPath[i];
}
if (attr != "")
if (!attr.empty())
{
oss << "/" << attr;
}

View File

@@ -154,14 +154,14 @@ ConfigStore::~ConfigStore()
}
void
ConfigStore::SetMode(enum Mode mode)
ConfigStore::SetMode(Mode mode)
{
NS_LOG_FUNCTION(this << mode);
m_mode = mode;
}
void
ConfigStore::SetFileFormat(enum FileFormat format)
ConfigStore::SetFileFormat(FileFormat format)
{
NS_LOG_FUNCTION(this << format);
m_fileFormat = format;

View File

@@ -96,12 +96,12 @@ class ConfigStore : public ObjectBase
* Set the mode of operation
* \param mode mode of operation
*/
void SetMode(enum Mode mode);
void SetMode(Mode mode);
/**
* Set the file format
* \param format the file format
*/
void SetFileFormat(enum FileFormat format);
void SetFileFormat(FileFormat format);
/**
* Set the filename
* \param filename the file name
@@ -123,11 +123,11 @@ class ConfigStore : public ObjectBase
void ConfigureAttributes();
private:
enum Mode m_mode; ///< store mode
enum FileFormat m_fileFormat; ///< store format
bool m_saveDeprecated; ///< save deprecated attributes
std::string m_filename; ///< store file name
FileConfig* m_file; ///< configuration file
Mode m_mode; ///< store mode
FileFormat m_fileFormat; ///< store format
bool m_saveDeprecated; ///< save deprecated attributes
std::string m_filename; ///< store file name
FileConfig* m_file; ///< configuration file
};
/**

View File

@@ -36,9 +36,7 @@ enum
struct ModelNode
{
/**
* \enum node type
* \brief node type structure
*
*/
enum
{

View File

@@ -38,7 +38,6 @@ enum
struct ModelTypeid
{
/**
* \enum node type
* \brief Whether the node represents an attribute or TypeId
*/
enum

View File

@@ -29,6 +29,7 @@
#include "ns3/string.h"
#include <libxml/encoding.h>
#include <libxml/xmlreader.h>
#include <libxml/xmlwriter.h>
namespace ns3
@@ -46,7 +47,7 @@ void
XmlConfigSave::SetFilename(std::string filename)
{
NS_LOG_FUNCTION(filename);
if (filename == "")
if (filename.empty())
{
return;
}

View File

@@ -22,10 +22,13 @@
#include "file-config.h"
#include <libxml/xmlreader.h>
#include <libxml/xmlwriter.h>
#include <string>
// These are in #include <libxml/xmlwriter.h>,
// here we just need a forward declaration.
typedef struct _xmlTextWriter xmlTextWriter;
typedef xmlTextWriter* xmlTextWriterPtr;
namespace ns3
{

View File

@@ -163,12 +163,12 @@ set(source_files
model/watchdog.cc
model/synchronizer.cc
model/make-event.cc
model/environment-variable.cc
model/log.cc
model/breakpoint.cc
model/type-id.cc
model/attribute-construction-list.cc
model/object-base.cc
model/ref-count-base.cc
model/object.cc
model/test.cc
model/random-variable-stream.cc
@@ -209,6 +209,7 @@ set(source_files
model/trickle-timer.cc
model/realtime-simulator-impl.cc
model/wall-clock-synchronizer.cc
model/matrix-array.cc
)
# Define core lib headers
@@ -247,6 +248,7 @@ set(header_files
model/fatal-error.h
model/fatal-impl.h
model/fd-reader.h
model/environment-variable.h
model/global-value.h
model/hash-fnv.h
model/hash-function.h
@@ -279,7 +281,6 @@ set(header_files
model/priority-queue-scheduler.h
model/ptr.h
model/random-variable-stream.h
model/ref-count-base.h
model/rng-seed-manager.h
model/rng-stream.h
model/scheduler.h
@@ -310,9 +311,12 @@ set(header_files
model/unused.h
model/valgrind.h
model/vector.h
model/warnings.h
model/watchdog.h
model/realtime-simulator-impl.h
model/wall-clock-synchronizer.h
model/val-array.h
model/matrix-array.h
)
set(test_sources
@@ -324,6 +328,7 @@ set(test_sources
test/callback-test-suite.cc
test/command-line-test-suite.cc
test/config-test-suite.cc
test/environment-variable-test-suite.cc
test/event-garbage-collector-test-suite.cc
test/global-value-test-suite.cc
test/hash-test-suite.cc
@@ -337,6 +342,7 @@ set(test_sources
test/ptr-test-suite.cc
test/sample-test-suite.cc
test/simulator-test-suite.cc
test/splitstring-test-suite.cc
test/threaded-test-suite.cc
test/time-test-suite.cc
test/timer-test-suite.cc
@@ -346,6 +352,8 @@ set(test_sources
test/type-id-test-suite.cc
test/type-traits-test-suite.cc
test/watchdog-test-suite.cc
test/val-array-test-suite.cc
test/matrix-array-test-suite.cc
)
# Build core lib

View File

@@ -81,3 +81,19 @@
* \defgroup core-tests Core module tests
* TestSuites for the Core module
*/
/**
* \ingroup core
* \defgroup system System Services
*
* System-independent interfaces to operating system services:
* environment variables, files system, threading, wall clock time.
*
* Services provided:
*
* - Environment variables
* - File and directory paths.
* - Thread primitives: threads, conditional waits, mutex, critical sections.
* - Asynchronous input from a file descriptor.
* - Wall clock time.
*/

View File

@@ -0,0 +1,189 @@
/*
* Copyright (c) 2022 Lawrence Livermore National Laboratory
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
*/
// This file supplies Doxygen documentation only.
// It should *NOT* be included in the build.
/**
* \ingroup system
* \defgroup core-environ Environment Variables
*/
/**
* \ingroup core-environ
* \brief Initialize an ns3::Attribute
*
* Sets a new default \pname{value} for an Attribute.
* This is invoked if the ns3::Object being constructed has an Attribute
* matching \pname{name}, and that Attribute didn't appear in the
* ns3::AttributeConstructionList argument to ns3::ObjectBase::ConstructSelf.
* The ns3::AttributeConstructionList is typically createad by an ns3::ObjectFactory
* and populated by ns3::ObjectFactory::Set.
*
* All objects with an Attribute matching \pname{name} will be matched,
* so name collisions could wreak havoc.
*
* <dl class="params">
* <dt>%Parameters</dt>
* <dd>
* <table class="params">
* <tr>
* <td class="paramname">name</td>
* <td>The name of the Attribute to set.</td>
* </tr>
* <tr>
* <td class="paramname">value</td>
* <td>The value to set the Attribute to.</td>
* </tr>
* <tr>
* <td class="paramname">;</td>
* <td>Multiple \pname{name}=\pname{value} pairs should be delimited by ';'</td>
* </tr>
* </table>
* </dd>
* </dl>
*
* Referenced by ns3::ObjectBase::ConstructSelf.
*/
const char* NS_ATTRIBUTE_DEFAULT = "name=value[;...]";
/**
* \ingroup core-environ
* \brief Write the ns3::CommandLine::Usage message, in Doxygen format,
* to the referenced location.
*
* Set the directory where ns3::CommandLine instances should write their Usage
* message, used when building documentation.
*
* This is used primarily by the documentation builds, which execute each
* registered example to gather their ns3::CommandLine::Usage information.
* This wouldn't normally be useful to users.
*
* <dl class="params">
* <dt>%Parameters</dt>
* <dd>
* <table class="params">
* <tr>
* <td class="paramname">path</td>
* <td> The directory where ns3::CommandLine should write its Usage message.</td>
* </tr>
* </table>
* </dd>
* </dl>
*
* Referenced by ns3::CommandLine::PrintDoxygenUsage.
*/
const char* NS_COMMANDLINE_INTROSPECTION = "path";
/**
* \ingroup core-environ
* \brief Initialize a ns3::GlobalValue.
*
* Initialize the ns3::GlobalValue \pname{name} from \pname{value}.
*
* This overrides the initial value set in the corresponding
* ns3::GlobalValue constructor.
*
* <dl class="params">
* <dt>%Parameters</dt>
* <dd>
* <table class="params">
* <tr>
* <td class="paramname">name</td>
* <td>The name of the ns3::GlobalValue to set.</td>
* </tr>
* <tr>
* <td class="paramname">value</td>
* <td>The value to set the ns3::GlobalValue to.</td>
* </tr>
* <tr>
* <td class="paramname">;</td>
* <td>Multiple \pname{name}=\pname{value} pairs should be delimited by ';'</td>
* </tr>
* </table>
* </dd>
* </dl>
*
* Referenced by ns3::GlobalValue::InitializeFromEnv.
*/
const char* NS_GLOBAL_VALUE = "name=value[;...]";
/**
* \ingroup core-environ
* \brief Control which logging components are enabled.
*
* Enable logging from specific \pname{component}s, with specified \pname{option}s.
* See the \ref logging module, or the Logging chapter
* in the manual for details on what symbols can be used for specifying
* log level and prefix options.
*
* <dl class="params">
* <dt>%Parameters</dt>
* <dd>
* <table class="params">
* <tr>
* <td class="paramname">component</td>
* <td>The logging component to enable.</td>
* </tr>
* <tr>
* <td class="paramname">option</td>
* <td>Log level and or prefix to enable. Multiple options should be delimited with '|'</td>
* </tr>
* <tr>
* <td class="paramname">:</td>
* <td>Multiple logging components can be enabled simultaneously, delimited by ':'</td>
* </tr>
* </table>
* </dd>
* </dl>
*
* Referenced by ns3::PrintList, ns3::LogComponent::EnvVarCheck and
* ns3::CheckEnvironmentVariables(), all in \ref log.cc.
*/
const char* NS_LOG = "component=option[|option...][:...]";
/**
* \ingroup core-environ
* \brief Where to make temporary directories.
*
* The absolute path where ns-3 should make temporary directories.
*
* See ns3::SystemPath::MakeTemporaryDirectoryName for details on how this environment
* variable is used to create a temporary directory, and how that directory
* will be named.
*
* <dl class="params">
* <dt>%Parameters</dt>
* <dd>
* <table class="params">
* <tr>
* <td class="paramname">path</td>
* <td>The absolute path in which to create the temporary directory.</td>
* </tr>
* </table>
* </dd>
* </dl>
*
* Referenced by ns3::SystemPath::MakeTemporaryDirectoryName.
*
* @{
*/
const char* TMP = "path";
const char* TEMP = "path";
/**@}*/

View File

@@ -1,4 +1,5 @@
set(base_examples
assert-example
command-line-example
fatal-example
hash-example
@@ -55,3 +56,10 @@ build_lib_example(
LIBRARIES_TO_LINK ${libcore}
${libflow-monitor}
)
build_lib_example(
NAME log-example
SOURCE_FILES log-example.cc
LIBRARIES_TO_LINK ${libcore}
${libnetwork}
)

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007 Georgia Tech Research Corporation
* Copyright (c) 2023 Lawrence Livermore National Laboratory
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -14,31 +14,34 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: George Riley <riley@ece.gatech.edu>
* Adapted from original code in object.h by:
* Authors: Gustavo Carneiro <gjcarneiro@gmail.com>,
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
*/
#include "ref-count-base.h"
#include "log.h"
/**
* \file
* \ingroup ptr
* ns3::RefCountBase implementation.
* \deprecated See \ref ns3::SimpleRefCount
* \ingroup core-examples
* \ingroup assert
* Example program illustrating the use of NS_ASSERT_MSG()
*/
namespace ns3
{
#include "ns3/core-module.h"
NS_LOG_COMPONENT_DEFINE("RefCountBase");
#include <iostream>
RefCountBase::~RefCountBase()
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("AssertExample");
int
main(int argc, char** argv)
{
NS_LOG_FUNCTION(this);
CommandLine cmd;
cmd.Parse(argc, argv);
std::cout << "NS_ASSERT_MSG example\n"
<< " if an argument is given this example will assert.\n";
NS_ASSERT_MSG(argc == 1, "An argument was given, so we assert");
return 0;
}
} // namespace ns3

View File

@@ -49,7 +49,7 @@ std::string g_cbArg = "cbArg default";
* \returns \c true.
*/
bool
SetCbArg(std::string val)
SetCbArg(const std::string& val)
{
g_cbArg = val;
return true;

View File

@@ -82,13 +82,16 @@ RunSingleSample(std::string mode, Ptr<EmpiricalRandomVariable> erv)
* \param value The value to print.
* \param count The number of times that value has been sampled.
* \param n The total number of random values sampled.
* \param sum The sum of the counts seen up to \p value, used to show
* the CDF for \p value.
*/
void
PrintStatsLine(const double value, const long count, const long n)
PrintStatsLine(const double value, const long count, const long n, const long sum)
{
std::cout << std::fixed << std::setprecision(3) << std::setw(10) << std::right << value
<< std::setw(10) << std::right << count << std::setw(10) << std::right
<< count / static_cast<double>(n) * 100.0 << std::endl;
<< count / static_cast<double>(n) * 100.0 << std::setw(10) << std::right
<< sum / static_cast<double>(n) * 100.0 << std::endl;
}
/**
@@ -136,21 +139,21 @@ RunBothModes(std::string mode, Ptr<EmpiricalRandomVariable> erv, long n)
long sum = 0;
double weighted = 0;
std::cout << std::endl;
std::cout << " Value Counts %" << std::endl;
std::cout << "---------- -------- --------" << std::endl;
std::cout << " Value Counts % % CDF" << std::endl;
std::cout << "---------- -------- -------- --------" << std::endl;
for (auto c : counts)
{
long count = c.second;
double value = c.first;
sum += count;
weighted += value * count;
PrintStatsLine(value, count, n);
PrintStatsLine(value, count, n, sum);
}
PrintSummary(sum, n, weighted, 8.75);
PrintSummary(sum, n, weighted, 0.8);
std::cout << "Interpolating " << mode << std::endl;
erv->SetInterpolate(true);
Histogram h(0.5);
Histogram h(0.1);
for (long i = 0; i < n; ++i)
{
h.AddValue(erv->GetValue());
@@ -161,8 +164,8 @@ RunBothModes(std::string mode, Ptr<EmpiricalRandomVariable> erv, long n)
sum = 0;
weighted = 0;
std::cout << std::endl;
std::cout << " Bin Start Counts %" << std::endl;
std::cout << "---------- -------- --------" << std::endl;
std::cout << " Bin Start Counts % % CDF" << std::endl;
std::cout << "---------- -------- -------- --------" << std::endl;
for (uint32_t i = 0; i < h.GetNBins(); ++i)
{
long count = h.GetBinCount(i);
@@ -170,9 +173,9 @@ RunBothModes(std::string mode, Ptr<EmpiricalRandomVariable> erv, long n)
double value = start + h.GetBinWidth(i) / 2.;
sum += count;
weighted += count * value;
PrintStatsLine(start, count, n);
PrintStatsLine(start, count, n, sum);
}
PrintSummary(sum, n, weighted, 6.25);
PrintSummary(sum, n, weighted, 0.760);
}
int
@@ -203,10 +206,15 @@ main(int argc, char* argv[])
// Create the ERV in sampling mode
Ptr<EmpiricalRandomVariable> erv = CreateObject<EmpiricalRandomVariable>();
erv->SetInterpolate(false);
erv->CDF(0.0, 0.0);
erv->CDF(5.0, 0.25);
erv->CDF(10.0, 1.0);
// // Expectation for bin
erv->CDF(0.0, 0.0 / 15.0); // 0
erv->CDF(0.2, 1.0 / 15.0); // 0.2 1/15 = 2/150
erv->CDF(0.4, 3.0 / 15.0); // 0.4 2/15 = 8/150
erv->CDF(0.6, 4.0 / 15.0); // 0.6 1/15 = 6/150
erv->CDF(0.8, 7.0 / 15.0); // 0.8 3/15 = 24/150
erv->CDF(1.0, 9.0 / 15.0); // 1.0 2/15 = 20/150
erv->CDF(1.0, 15.0 / 15.0); // 1.0 6/15 = 60/150 <avg> = 120/150 = 0.8
if (single)
{

View File

@@ -137,7 +137,7 @@ class Collider
* \param [in] hash Hash function.
* \param [in] bits Which hash length to use.
*/
Collider(const std::string name, Hasher hash, const enum Bits bits)
Collider(const std::string name, Hasher hash, const Bits bits)
: m_name(name),
m_hash(hash),
m_bits(bits)
@@ -245,7 +245,7 @@ class Collider
}
/** Hash function. */
enum Bits m_bits;
Bits m_bits;
/** Hashed dictionary of first instance of each hash. */
typedef std::map<uint64_t, std::string> hashdict_t;
@@ -291,7 +291,7 @@ class Dictionary
*/
void Add(const std::string phrase)
{
if (phrase.size() == 0)
if (phrase.empty())
{
return;
}
@@ -437,7 +437,7 @@ class DictFiles
* \param [in] file The word file to add.
* \return \c true If the file is new to the list.
*/
bool Add(const std::string file)
bool Add(const std::string& file)
{
if (std::find(m_files.begin(), m_files.end(), file) == m_files.end())
{
@@ -460,7 +460,7 @@ class DictFiles
*/
void ReadInto(Dictionary& dict)
{
if (m_files.size() == 0)
if (m_files.empty())
{
Add(GetDefault());
}
@@ -545,4 +545,5 @@ main(int argc, char* argv[])
dict.Time();
} // if (timing)
return 0;
} // main

View File

@@ -23,17 +23,21 @@
#include <iostream>
/**
* \file
* \defgroup length-examples Demonstrates usage of the ns3::Length class
* \ingroup core-examples
* \ingroup length
*/
/**
* \file
* \ingroup length-examples
* Demonstrates usage of the ns3::Length class
*/
using namespace ns3;
/**
* \ingroup core-examples
* \ingroup length
* \ingroup length-examples
* \brief Demonstrates the use of ns3::Length constructors.
*/
void
@@ -55,8 +59,7 @@ Constructors()
}
/**
* \ingroup core-examples
* \ingroup length
* \ingroup length-examples
* \brief Demonstrates the use of ns3::Length conversions.
*/
void
@@ -75,8 +78,7 @@ Conversions()
}
/**
* \ingroup core-examples
* \ingroup length
* \ingroup length-examples
* \brief Demonstrates the use of ns3::Length arithmetic operators.
*/
void
@@ -103,8 +105,7 @@ ArithmeticOperators()
}
/**
* \ingroup core-examples
* \ingroup length
* \ingroup length-examples
* \brief Demonstrates the use of ns3::Length equality operators.
*/
void
@@ -141,8 +142,7 @@ EqualityOperators()
}
/**
* \ingroup core-examples
* \ingroup length
* \ingroup length-examples
* \brief Demonstrates the use of ns3::Length multiplications and divisions.
*/
void

View File

@@ -0,0 +1,135 @@
/*
* Copyright (c) 2023 Lawrence Livermore National Laboratory
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
*/
/**
* \file
* \ingroup core-examples
* \ingroup logging
* Example program illustrating the various logging functions.
*/
/** File-local context string */
#define NS_LOG_APPEND_CONTEXT \
{ \
std::clog << "(local context) "; \
}
#include "ns3/core-module.h"
#include "ns3/network-module.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("LogExample");
/**
* Unnamed namespace for log-example.cc
*/
namespace
{
/** A free function with logging. */
void
FreeEvent()
{
NS_LOG_FUNCTION_NOARGS();
NS_LOG_ERROR("FreeEvent: error msg");
NS_LOG_WARN("FreeEvent: warning msg");
NS_LOG_DEBUG("FreeEvent: debug msg");
NS_LOG_INFO("FreeEvent: info msg");
NS_LOG_LOGIC("FreeEvent: logic msg");
}
/** Simple object to aggregate to a node.
* This helps demonstrate the logging node prefix.
*/
class MyEventObject : public Object
{
public:
/**
* \brief Get the type ID.
* \return the object TypeId
*/
static TypeId GetTypeId()
{
static TypeId tid =
TypeId("MyEventObject").SetParent<Object>().AddConstructor<MyEventObject>();
return tid;
}
/** Constructor. */
MyEventObject()
{
NS_LOG_FUNCTION(this);
}
/** Destructor. */
~MyEventObject() override
{
NS_LOG_FUNCTION(this);
}
/** Class member function with logging. */
void Event()
{
NS_LOG_FUNCTION(this);
NS_LOG_ERROR("MyEventObject:Event: error msg");
NS_LOG_WARN("MyEventObject:Event: warning msg");
NS_LOG_DEBUG("MyEventObject:Event: debug msg");
NS_LOG_INFO("MyEventObject:Event: info msg");
NS_LOG_LOGIC("MyEventObject:Event: logic msg");
}
}; // MyEventObject
NS_OBJECT_ENSURE_REGISTERED(MyEventObject);
} // Unnamed namespace
int
main(int argc, char** argv)
{
CommandLine cmd;
cmd.Parse(argc, argv);
NS_LOG_UNCOND("Creating a Node");
auto node = CreateObject<Node>();
NS_LOG_UNCOND("Creating MyEventObject");
auto myObj = CreateObject<MyEventObject>();
NS_LOG_UNCOND("Aggregating MyEventObject to Node");
node->AggregateObject(myObj);
NS_LOG_UNCOND("Scheduling the MyEventObject::Event with node context");
Simulator::ScheduleWithContext(node->GetId(), Seconds(3), &MyEventObject::Event, &(*myObj));
NS_LOG_UNCOND("Scheduling FreeEvent");
Simulator::Schedule(Seconds(5), FreeEvent);
NS_LOG_UNCOND("Starting run...");
Simulator::Run();
NS_LOG_UNCOND("... run complete");
Simulator::Destroy();
NS_LOG_UNCOND("Goodbye");
return 0;
}

View File

@@ -25,6 +25,8 @@
#include "ns3/string.h"
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
/**
@@ -116,15 +118,17 @@ main(int argc, char* argv[])
unsigned int probes = 1000000;
double precision = 0.01;
GnuplotCollection gnuplots("main-random-variables.pdf");
const std::string plotFile{"main-random-variables"};
GnuplotCollection gnuplots(plotFile + ".pdf");
gnuplots.SetTerminal("pdf enhanced");
{
std::cout << "UniformRandomVariable......." << std::flush;
Gnuplot plot;
plot.SetTitle("UniformRandomVariable");
plot.AppendExtra("set yrange [0:]");
Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable>();
auto x = CreateObject<UniformRandomVariable>();
x->SetAttribute("Min", DoubleValue(0.0));
x->SetAttribute("Max", DoubleValue(1.0));
@@ -132,29 +136,31 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("1.0", "0 <= x && x <= 1 ? 1.0 : 0"));
gnuplots.AddPlot(plot);
std::cout << "done" << std::endl;
}
{
std::cout << "ExponentialRandomVariable..." << std::flush;
Gnuplot plot;
plot.SetTitle("ExponentialRandomVariable");
plot.AppendExtra("set xrange [0:8]");
plot.AppendExtra("set xrange [0:4]");
plot.AppendExtra("ExpDist(x,l) = 1/l * exp(-1/l * x)");
Ptr<ExponentialRandomVariable> x1 = CreateObject<ExponentialRandomVariable>();
auto x1 = CreateObject<ExponentialRandomVariable>();
x1->SetAttribute("Mean", DoubleValue(0.5));
plot.AddDataset(Histogram(x1, probes, precision, "ExponentialRandomVariable m=0.5"));
plot.AddDataset(Gnuplot2dFunction("ExponentialDistribution mean 0.5", "ExpDist(x, 0.5)"));
Ptr<ExponentialRandomVariable> x2 = CreateObject<ExponentialRandomVariable>();
auto x2 = CreateObject<ExponentialRandomVariable>();
x2->SetAttribute("Mean", DoubleValue(1.0));
plot.AddDataset(Histogram(x2, probes, precision, "ExponentialRandomVariable m=1"));
plot.AddDataset(Gnuplot2dFunction("ExponentialDistribution mean 1.0", "ExpDist(x, 1.0)"));
Ptr<ExponentialRandomVariable> x3 = CreateObject<ExponentialRandomVariable>();
auto x3 = CreateObject<ExponentialRandomVariable>();
x3->SetAttribute("Mean", DoubleValue(1.5));
plot.AddDataset(Histogram(x3, probes, precision, "ExponentialRandomVariable m=1.5"));
@@ -162,28 +168,30 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("ExponentialDistribution mean 1.5", "ExpDist(x, 1.5)"));
gnuplots.AddPlot(plot);
std::cout << "done" << std::endl;
}
{
std::cout << "ParetoRandomVariable........" << std::flush;
Gnuplot plot;
plot.SetTitle("ParetoRandomVariable");
plot.AppendExtra("set xrange [0:2]");
plot.AppendExtra("set xrange [0:4]");
Ptr<ParetoRandomVariable> x1 = CreateObject<ParetoRandomVariable>();
auto x1 = CreateObject<ParetoRandomVariable>();
x1->SetAttribute("Scale", DoubleValue(1.0));
x1->SetAttribute("Shape", DoubleValue(1.5));
plot.AddDataset(
Histogram(x1, probes, precision, "ParetoRandomVariable scale=1.0 shape=1.5"));
Ptr<ParetoRandomVariable> x2 = CreateObject<ParetoRandomVariable>();
auto x2 = CreateObject<ParetoRandomVariable>();
x2->SetAttribute("Scale", DoubleValue(1.0));
x2->SetAttribute("Shape", DoubleValue(2.0));
plot.AddDataset(
Histogram(x2, probes, precision, "ParetoRandomVariable scale=1.0 shape=2.0"));
Ptr<ParetoRandomVariable> x3 = CreateObject<ParetoRandomVariable>();
auto x3 = CreateObject<ParetoRandomVariable>();
x3->SetAttribute("Scale", DoubleValue(1.0));
x3->SetAttribute("Shape", DoubleValue(2.5));
@@ -191,28 +199,30 @@ main(int argc, char* argv[])
Histogram(x3, probes, precision, "ParetoRandomVariable scale=1.0 shape=2.5"));
gnuplots.AddPlot(plot);
std::cout << "done" << std::endl;
}
{
std::cout << "WeibullRandomVariable......." << std::flush;
Gnuplot plot;
plot.SetTitle("WeibullRandomVariable");
plot.AppendExtra("set xrange [0:3]");
plot.AppendExtra("set xrange [0:4]");
Ptr<WeibullRandomVariable> x1 = CreateObject<WeibullRandomVariable>();
auto x1 = CreateObject<WeibullRandomVariable>();
x1->SetAttribute("Scale", DoubleValue(1.0));
x1->SetAttribute("Shape", DoubleValue(1.0));
plot.AddDataset(
Histogram(x1, probes, precision, "WeibullRandomVariable scale=1.0 shape=1.0"));
Ptr<WeibullRandomVariable> x2 = CreateObject<WeibullRandomVariable>();
auto x2 = CreateObject<WeibullRandomVariable>();
x2->SetAttribute("Scale", DoubleValue(1.0));
x2->SetAttribute("Shape", DoubleValue(2.0));
plot.AddDataset(
Histogram(x2, probes, precision, "WeibullRandomVariable scale=1.0 shape=2.0"));
Ptr<WeibullRandomVariable> x3 = CreateObject<WeibullRandomVariable>();
auto x3 = CreateObject<WeibullRandomVariable>();
x3->SetAttribute("Scale", DoubleValue(1.0));
x3->SetAttribute("Shape", DoubleValue(3.0));
@@ -220,16 +230,18 @@ main(int argc, char* argv[])
Histogram(x3, probes, precision, "WeibullRandomVariable scale=1.0 shape=3.0"));
gnuplots.AddPlot(plot);
std::cout << "done" << std::endl;
}
{
std::cout << "NormalRandomVariable........" << std::flush;
Gnuplot plot;
plot.SetTitle("NormalRandomVariable");
plot.AppendExtra("set xrange [-3:3]");
plot.AppendExtra("set xrange [-4:4]");
plot.AppendExtra(
"NormalDist(x,m,s) = 1 / (s * sqrt(2*pi)) * exp(-1.0 / 2.0 * ((x-m) / s)**2)");
Ptr<NormalRandomVariable> x1 = CreateObject<NormalRandomVariable>();
auto x1 = CreateObject<NormalRandomVariable>();
x1->SetAttribute("Mean", DoubleValue(0.0));
x1->SetAttribute("Variance", DoubleValue(1.0));
@@ -238,7 +250,7 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("NormalDist {/Symbol m}=0.0 {/Symbol s}=1.0",
"NormalDist(x,0.0,1.0)"));
Ptr<NormalRandomVariable> x2 = CreateObject<NormalRandomVariable>();
auto x2 = CreateObject<NormalRandomVariable>();
x2->SetAttribute("Mean", DoubleValue(0.0));
x2->SetAttribute("Variance", DoubleValue(2.0));
@@ -247,7 +259,7 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("NormalDist {/Symbol m}=0.0 {/Symbol s}=sqrt(2.0)",
"NormalDist(x,0.0,sqrt(2.0))"));
Ptr<NormalRandomVariable> x3 = CreateObject<NormalRandomVariable>();
auto x3 = CreateObject<NormalRandomVariable>();
x3->SetAttribute("Mean", DoubleValue(0.0));
x3->SetAttribute("Variance", DoubleValue(3.0));
@@ -257,55 +269,61 @@ main(int argc, char* argv[])
"NormalDist(x,0.0,sqrt(3.0))"));
gnuplots.AddPlot(plot);
std::cout << "done" << std::endl;
}
/** \todo Turn this plot back on once its distribution has been finished. */
/*
{
Gnuplot plot;
plot.SetTitle ("EmpiricalRandomVariable");
plot.AppendExtra ("set xrange [*:*]");
std::cout << "EmpiricalVariable..........." << std::flush;
Gnuplot plot;
plot.SetTitle("EmpiricalRandomVariable");
plot.AppendExtra("set xrange [*:*]");
EmpiricalRandomVariable emp1;
emp1.CDF (0.0, 0.0 / 15.0);
emp1.CDF (0.2, 1.0 / 15.0);
emp1.CDF (0.4, 3.0 / 15.0);
emp1.CDF (0.6, 6.0 / 15.0);
emp1.CDF (0.8, 10.0 / 15.0);
emp1.CDF (1.0, 15.0 / 15.0);
auto x = CreateObject<EmpiricalRandomVariable>();
x->CDF(0.0, 0.0 / 15.0);
x->CDF(0.2, 1.0 / 15.0);
x->CDF(0.4, 3.0 / 15.0);
x->CDF(0.6, 6.0 / 15.0);
x->CDF(0.8, 10.0 / 15.0);
x->CDF(1.0, 15.0 / 15.0);
plot.AddDataset ( Histogram (emp1, probes, precision,
"EmpiricalRandomVariable (Stairs)") );
plot.AddDataset(
Histogram(x, probes, precision, "EmpiricalRandomVariable (Sampling)", true));
gnuplots.AddPlot (plot);
x->SetInterpolate(true);
plot.AppendExtra("set y2range [0:*]");
auto d2 = Histogram(x, probes, precision, "EmpiricalRandomVariable (Interpolate)");
d2.SetExtra(" axis x1y2");
plot.AddDataset(d2);
gnuplots.AddPlot(plot);
std::cout << "done" << std::endl;
}
*/
/** \todo Turn this plot back on once its distribution has been finished. */
/*
{
Gnuplot plot;
plot.SetTitle ("DeterministicRandomVariable");
plot.AppendExtra ("set xrange [*:*]");
std::cout << "DeterministicVariable......." << std::flush;
Gnuplot plot;
plot.SetTitle("DeterministicRandomVariable");
plot.AppendExtra("set xrange [*:*]");
double values[] = { 0.0, 0.2, 0.2, 0.4, 0.2, 0.6, 0.8, 0.8, 1.0 };
DeterministicRandomVariable det1 (values, sizeof(values) / sizeof(values[0]));
auto x1 = CreateObject<DeterministicRandomVariable>();
double values[] = {0.0, 0.2, 0.2, 0.4, 0.2, 0.6, 0.8, 0.8, 1.0};
x1->SetValueArray(values, sizeof(values) / sizeof(values[0]));
plot.AddDataset ( Histogram (det1, probes, precision,
"DeterministicRandomVariable", true) );
plot.AddDataset(Histogram(x1, probes, precision, "DeterministicRandomVariable", true));
gnuplots.AddPlot (plot);
gnuplots.AddPlot(plot);
std::cout << "done" << std::endl;
}
*/
{
std::cout << "LogNormalRandomVariable....." << std::flush;
Gnuplot plot;
plot.SetTitle("LogNormalRandomVariable");
plot.AppendExtra("set xrange [0:3]");
plot.AppendExtra("set xrange [0:4]");
plot.AppendExtra("LogNormalDist(x,m,s) = 1.0/x * NormalDist(log(x), m, s)");
Ptr<LogNormalRandomVariable> x1 = CreateObject<LogNormalRandomVariable>();
auto x1 = CreateObject<LogNormalRandomVariable>();
x1->SetAttribute("Mu", DoubleValue(0.0));
x1->SetAttribute("Sigma", DoubleValue(1.0));
@@ -314,13 +332,13 @@ main(int argc, char* argv[])
plot.AddDataset(
Gnuplot2dFunction("LogNormalDist(x, 0.0, 1.0)", "LogNormalDist(x, 0.0, 1.0)"));
Ptr<LogNormalRandomVariable> x2 = CreateObject<LogNormalRandomVariable>();
auto x2 = CreateObject<LogNormalRandomVariable>();
x2->SetAttribute("Mu", DoubleValue(0.0));
x2->SetAttribute("Sigma", DoubleValue(0.5));
plot.AddDataset(Histogram(x2, probes, precision, "LogNormalRandomVariable m=0.0 s=0.5"));
Ptr<LogNormalRandomVariable> x3 = CreateObject<LogNormalRandomVariable>();
auto x3 = CreateObject<LogNormalRandomVariable>();
x3->SetAttribute("Mu", DoubleValue(0.0));
x3->SetAttribute("Sigma", DoubleValue(0.25));
@@ -329,13 +347,13 @@ main(int argc, char* argv[])
plot.AddDataset(
Gnuplot2dFunction("LogNormalDist(x, 0.0, 0.25)", "LogNormalDist(x, 0.0, 0.25)"));
Ptr<LogNormalRandomVariable> x4 = CreateObject<LogNormalRandomVariable>();
auto x4 = CreateObject<LogNormalRandomVariable>();
x4->SetAttribute("Mu", DoubleValue(0.0));
x4->SetAttribute("Sigma", DoubleValue(0.125));
plot.AddDataset(Histogram(x4, probes, precision, "LogNormalRandomVariable m=0.0 s=0.125"));
Ptr<LogNormalRandomVariable> x5 = CreateObject<LogNormalRandomVariable>();
auto x5 = CreateObject<LogNormalRandomVariable>();
x5->SetAttribute("Mu", DoubleValue(0.0));
x5->SetAttribute("Sigma", DoubleValue(2.0));
@@ -344,21 +362,23 @@ main(int argc, char* argv[])
plot.AddDataset(
Gnuplot2dFunction("LogNormalDist(x, 0.0, 2.0)", "LogNormalDist(x, 0.0, 2.0)"));
Ptr<LogNormalRandomVariable> x6 = CreateObject<LogNormalRandomVariable>();
auto x6 = CreateObject<LogNormalRandomVariable>();
x6->SetAttribute("Mu", DoubleValue(0.0));
x6->SetAttribute("Sigma", DoubleValue(2.5));
plot.AddDataset(Histogram(x6, probes, precision, "LogNormalRandomVariable m=0.0 s=2.5"));
gnuplots.AddPlot(plot);
std::cout << "done" << std::endl;
}
{
std::cout << "TriangularRandomVariable...." << std::flush;
Gnuplot plot;
plot.SetTitle("TriangularRandomVariable");
plot.AppendExtra("set xrange [*:*]");
Ptr<TriangularRandomVariable> x1 = CreateObject<TriangularRandomVariable>();
auto x1 = CreateObject<TriangularRandomVariable>();
x1->SetAttribute("Min", DoubleValue(0.0));
x1->SetAttribute("Max", DoubleValue(1.0));
x1->SetAttribute("Mean", DoubleValue(0.5));
@@ -366,7 +386,7 @@ main(int argc, char* argv[])
plot.AddDataset(
Histogram(x1, probes, precision, "TriangularRandomVariable [0.0 .. 1.0) m=0.5"));
Ptr<TriangularRandomVariable> x2 = CreateObject<TriangularRandomVariable>();
auto x2 = CreateObject<TriangularRandomVariable>();
x2->SetAttribute("Min", DoubleValue(0.0));
x2->SetAttribute("Max", DoubleValue(1.0));
x2->SetAttribute("Mean", DoubleValue(0.4));
@@ -374,7 +394,7 @@ main(int argc, char* argv[])
plot.AddDataset(
Histogram(x2, probes, precision, "TriangularRandomVariable [0.0 .. 1.0) m=0.4"));
Ptr<TriangularRandomVariable> x3 = CreateObject<TriangularRandomVariable>();
auto x3 = CreateObject<TriangularRandomVariable>();
x3->SetAttribute("Min", DoubleValue(0.0));
x3->SetAttribute("Max", DoubleValue(1.0));
x3->SetAttribute("Mean", DoubleValue(0.65));
@@ -383,9 +403,11 @@ main(int argc, char* argv[])
Histogram(x3, probes, precision, "TriangularRandomVariable [0.0 .. 1.0) m=0.65"));
gnuplots.AddPlot(plot);
std::cout << "done" << std::endl;
}
{
std::cout << "GammaRandomVariable........." << std::flush;
Gnuplot plot;
plot.SetTitle("GammaRandomVariable");
plot.AppendExtra("set xrange [0:10]");
@@ -396,7 +418,7 @@ main(int argc, char* argv[])
"set label 1 '{/Symbol g}(x,{/Symbol a},{/Symbol b}) = x^{/Symbol a-1} e^{-x {/Symbol "
"b}^{-1}} ( {/Symbol b}^{/Symbol a} {/Symbol G}({/Symbol a}) )^{-1}' at 0.7, 0.9");
Ptr<GammaRandomVariable> x1 = CreateObject<GammaRandomVariable>();
auto x1 = CreateObject<GammaRandomVariable>();
x1->SetAttribute("Alpha", DoubleValue(1.0));
x1->SetAttribute("Beta", DoubleValue(1.0));
@@ -404,7 +426,7 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("{/Symbol g}(x, 1.0, 1.0)", "GammaDist(x, 1.0, 1.0)"));
Ptr<GammaRandomVariable> x2 = CreateObject<GammaRandomVariable>();
auto x2 = CreateObject<GammaRandomVariable>();
x2->SetAttribute("Alpha", DoubleValue(1.5));
x2->SetAttribute("Beta", DoubleValue(1.0));
@@ -412,7 +434,7 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("{/Symbol g}(x, 1.5, 1.0)", "GammaDist(x, 1.5, 1.0)"));
Ptr<GammaRandomVariable> x3 = CreateObject<GammaRandomVariable>();
auto x3 = CreateObject<GammaRandomVariable>();
x3->SetAttribute("Alpha", DoubleValue(2.0));
x3->SetAttribute("Beta", DoubleValue(1.0));
@@ -420,7 +442,7 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("{/Symbol g}(x, 2.0, 1.0)", "GammaDist(x, 2.0, 1.0)"));
Ptr<GammaRandomVariable> x4 = CreateObject<GammaRandomVariable>();
auto x4 = CreateObject<GammaRandomVariable>();
x4->SetAttribute("Alpha", DoubleValue(4.0));
x4->SetAttribute("Beta", DoubleValue(1.0));
@@ -428,7 +450,7 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("{/Symbol g}(x, 4.0, 1.0)", "GammaDist(x, 4.0, 1.0)"));
Ptr<GammaRandomVariable> x5 = CreateObject<GammaRandomVariable>();
auto x5 = CreateObject<GammaRandomVariable>();
x5->SetAttribute("Alpha", DoubleValue(2.0));
x5->SetAttribute("Beta", DoubleValue(2.0));
@@ -436,7 +458,7 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("{/Symbol g}(x, 2.0, 2.0)", "GammaDist(x, 2.0, 2.0)"));
Ptr<GammaRandomVariable> x6 = CreateObject<GammaRandomVariable>();
auto x6 = CreateObject<GammaRandomVariable>();
x6->SetAttribute("Alpha", DoubleValue(2.5));
x6->SetAttribute("Beta", DoubleValue(3.0));
@@ -444,7 +466,7 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("{/Symbol g}(x, 2.5, 3.0)", "GammaDist(x, 2.5, 3.0)"));
Ptr<GammaRandomVariable> x7 = CreateObject<GammaRandomVariable>();
auto x7 = CreateObject<GammaRandomVariable>();
x7->SetAttribute("Alpha", DoubleValue(2.5));
x7->SetAttribute("Beta", DoubleValue(4.5));
@@ -453,9 +475,11 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("{/Symbol g}(x, 2.5, 4.5)", "GammaDist(x, 2.5, 4.5)"));
gnuplots.AddPlot(plot);
std::cout << "done" << std::endl;
}
{
std::cout << "ErlangRandomVariable........" << std::flush;
Gnuplot plot;
plot.SetTitle("ErlangRandomVariable");
plot.AppendExtra("set xrange [0:10]");
@@ -464,7 +488,7 @@ main(int argc, char* argv[])
plot.AppendExtra("set label 1 'Erlang(x,k,{/Symbol l}) = x^{k-1} e^{-x {/Symbol l}^{-1}} ( "
"{/Symbol l}^k (k-1)! )^{-1}' at 0.7, 0.9");
Ptr<ErlangRandomVariable> x1 = CreateObject<ErlangRandomVariable>();
auto x1 = CreateObject<ErlangRandomVariable>();
x1->SetAttribute("K", IntegerValue(1));
x1->SetAttribute("Lambda", DoubleValue(1.0));
@@ -473,7 +497,7 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("Erlang(x, 1, 1.0)", "ErlangDist(x, 1, 1.0)"));
Ptr<ErlangRandomVariable> x2 = CreateObject<ErlangRandomVariable>();
auto x2 = CreateObject<ErlangRandomVariable>();
x2->SetAttribute("K", IntegerValue(2));
x2->SetAttribute("Lambda", DoubleValue(1.0));
@@ -482,7 +506,7 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("Erlang(x, 2, 1.0)", "ErlangDist(x, 2, 1.0)"));
Ptr<ErlangRandomVariable> x3 = CreateObject<ErlangRandomVariable>();
auto x3 = CreateObject<ErlangRandomVariable>();
x3->SetAttribute("K", IntegerValue(3));
x3->SetAttribute("Lambda", DoubleValue(1.0));
@@ -491,7 +515,7 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("Erlang(x, 3, 1.0)", "ErlangDist(x, 3, 1.0)"));
Ptr<ErlangRandomVariable> x4 = CreateObject<ErlangRandomVariable>();
auto x4 = CreateObject<ErlangRandomVariable>();
x4->SetAttribute("K", IntegerValue(5));
x4->SetAttribute("Lambda", DoubleValue(1.0));
@@ -500,7 +524,7 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("Erlang(x, 5, 1.0)", "ErlangDist(x, 5, 1.0)"));
Ptr<ErlangRandomVariable> x5 = CreateObject<ErlangRandomVariable>();
auto x5 = CreateObject<ErlangRandomVariable>();
x5->SetAttribute("K", IntegerValue(2));
x5->SetAttribute("Lambda", DoubleValue(2.0));
@@ -509,7 +533,7 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("Erlang(x, 2, 2.0)", "ErlangDist(x, 2, 2.0)"));
Ptr<ErlangRandomVariable> x6 = CreateObject<ErlangRandomVariable>();
auto x6 = CreateObject<ErlangRandomVariable>();
x6->SetAttribute("K", IntegerValue(2));
x6->SetAttribute("Lambda", DoubleValue(3.0));
@@ -518,7 +542,7 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("Erlang(x, 2, 3.0)", "ErlangDist(x, 2, 3.0)"));
Ptr<ErlangRandomVariable> x7 = CreateObject<ErlangRandomVariable>();
auto x7 = CreateObject<ErlangRandomVariable>();
x7->SetAttribute("K", IntegerValue(2));
x7->SetAttribute("Lambda", DoubleValue(5.0));
@@ -528,9 +552,30 @@ main(int argc, char* argv[])
plot.AddDataset(Gnuplot2dFunction("Erlang(x, 2, 5.0)", "ErlangDist(x, 2, 5.0)"));
gnuplots.AddPlot(plot);
std::cout << "done" << std::endl;
}
gnuplots.GenerateOutput(std::cout);
{
std::string gnuFile = plotFile + ".plt";
std::cout << "Writing Gnuplot file: " << gnuFile << "..." << std::flush;
std::ofstream gnuStream(gnuFile);
gnuplots.GenerateOutput(gnuStream);
gnuStream.close();
std::cout << "done\nGenerating " << plotFile << ".pdf..." << std::flush;
std::string shellcmd = "gnuplot " + gnuFile;
int returnValue = std::system(shellcmd.c_str());
if (returnValue)
{
std::cout << std::endl
<< "Error: shell command failed with " << returnValue << "; no pdf generated."
<< std::endl;
}
else
{
std::cout << "done" << std::endl;
}
}
return 0;
}

View File

@@ -158,4 +158,6 @@ main(int argc, char* argv[])
{
test();
}
return 0;
}

View File

@@ -126,10 +126,12 @@ main(int argc, char* argv[])
LogComponentEnable("RandomVariableStream", LOG_LEVEL_ALL);
LogComponentEnableAll(LOG_PREFIX_TIME);
std::map<std::string, Time::Unit> resolutionMap = {{"Time::US", Time::US},
{"Time::NS", Time::NS},
{"Time::PS", Time::PS},
{"Time::FS", Time::FS}};
std::map<std::string, Time::Unit> resolutionMap = {
{"Time::US", Time::US},
{"Time::NS", Time::NS},
{"Time::PS", Time::PS},
{"Time::FS", Time::FS},
};
CommandLine cmd(__FILE__);
cmd.AddValue("replaceTimePrinter", "replace time printing function", replaceTimePrinter);
@@ -162,4 +164,6 @@ main(int argc, char* argv[])
Simulator::Run();
Simulator::Destroy();
return 0;
}

View File

@@ -68,4 +68,6 @@ main(int argc, char* argv[])
Ptr<UniformRandomVariable> uv = CreateObject<UniformRandomVariable>();
std::cout << uv->GetValue() << std::endl;
return 0;
}

View File

@@ -68,4 +68,6 @@ main(int argc, char* argv[])
Ptr<UniformRandomVariable> uv = CreateObject<UniformRandomVariable>();
std::cout << uv->GetValue() << std::endl;
return 0;
}

View File

@@ -124,4 +124,6 @@ main(int argc, char* argv[])
Simulator::Run();
Simulator::Destroy();
return 0;
}

View File

@@ -47,7 +47,7 @@ ns.cppyy.cppdef("""
{
public:
/** Start model execution by scheduling a HandleEvent. */
void Start (void);
void Start ();
private:
/**
@@ -59,7 +59,7 @@ ns.cppyy.cppdef("""
};
void
MyModel::Start (void)
MyModel::Start ()
{
Simulator::Schedule (Seconds (10.0),
&MyModel::HandleEvent,
@@ -92,7 +92,7 @@ ns.cppyy.cppdef("""
return MakeEvent(&RandomFunctionCpp, model);
}
void CancelledFunctionCpp(void) {
void CancelledFunctionCpp() {
CPyCppyy::Eval("CancelledEvent()");
}

View File

@@ -18,7 +18,7 @@
#include "ns3/core-module.h"
/**
* \defgroup string-value-formatting
* \defgroup string-value-formatting StringValue parsing tests
* Check that StringValue parses complex values correctly.
*/
@@ -203,4 +203,6 @@ main(int argc, char* argv[])
NS_ASSERT_MSG(val.Get() == 30, "Minimum not set to 30");
uniformStream->GetAttribute("Max", val);
NS_ASSERT_MSG(val.Get() == 60, "Maximum not set to 60");
return 0;
}

View File

@@ -329,7 +329,7 @@ CsvReader::ParseLine(const std::string& line)
start_col = end_col;
}
m_blankRow = (m_columns.size() == 1) && (m_columns[0] == "");
m_blankRow = (m_columns.size() == 1) && (m_columns[0].empty());
NS_LOG_LOGIC("blank row: " << m_blankRow);
}

View File

@@ -68,7 +68,7 @@
{ \
if (!(condition)) \
{ \
std::cerr << "assert failed. cond=\"" << #condition << "\", "; \
std::cerr << "NS_ASSERT failed, cond=\"" << #condition << "\", "; \
NS_FATAL_ERROR_NO_MSG(); \
} \
} while (false)
@@ -88,13 +88,17 @@
{ \
if (!(condition)) \
{ \
std::cerr << "assert failed. cond=\"" << #condition << "\", "; \
std::cerr << "NS_ASSERT failed, cond=\"" << #condition << "\", "; \
NS_FATAL_ERROR(message); \
} \
} while (false)
#else /* NS3_ASSERT_ENABLE */
// NOTE: The no-op macros are not inserted into the final code.
// However, the use of sizeof() allows the compiler to silently check if the condition is
// syntactically valid.
#define NS_ASSERT(condition) \
do \
{ \

View File

@@ -54,7 +54,7 @@ AttributeConstructionList::Add(std::string name,
}
}
// store the new value.
struct Item attr;
Item attr;
attr.checker = checker;
attr.value = value;
attr.name = name;

View File

@@ -228,7 +228,7 @@ template <class A, template <class...> class C = std::list>
Ptr<const AttributeChecker> MakeAttributeContainerChecker(Ptr<const AttributeChecker> itemchecker);
/**
* Make unitialized AttributeContainerChecker using explicit types.
* Make uninitialized AttributeContainerChecker using explicit types.
* @tparam A AttributeValue type in container.
* @tparam C Container type returned by Get.
* \return AttributeContainerChecker.

View File

@@ -111,7 +111,12 @@ MakeSimpleAttributeChecker(std::string name, std::string underlying)
std::string GetValueTypeName() const override
{
return m_type;
if (m_type.rfind("ns3::", 0) == 0)
{
// m_type already starts with "ns3::"
return m_type;
}
return "ns3::" + m_type;
}
bool HasUnderlyingTypeInformation() const override

View File

@@ -55,7 +55,7 @@ class EventImpl;
* `(ts / m_width) % m_nBuckets`. This class automatically adjusts
* the number of buckets to keep the average occupancy around 2.
* Buckets themselves are implemented as a `std::list<>`, and events are
* kept sorted withing the buckets.
* kept sorted within the buckets.
*
* \par Time Complexity
*

View File

@@ -441,6 +441,9 @@ class CallbackBase
template <typename R, typename... UArgs>
class Callback : public CallbackBase
{
template <typename ROther, typename... UArgsOther>
friend class Callback;
public:
Callback()
{
@@ -464,18 +467,17 @@ class Callback : public CallbackBase
* \param [in] bargs The values of the bound arguments
*/
template <typename... BArgs>
Callback(const CallbackBase& cb, BArgs... bargs)
Callback(const Callback<R, BArgs..., UArgs...>& cb, BArgs... bargs)
{
auto cbDerived =
static_cast<const CallbackImpl<R, BArgs..., UArgs...>*>(PeekPointer(cb.GetImpl()));
auto f = cb.DoPeekImpl()->GetFunction();
std::function<R(BArgs..., UArgs...)> f(cbDerived->GetFunction());
CallbackComponentVector components(cbDerived->GetComponents());
CallbackComponentVector components(cb.DoPeekImpl()->GetComponents());
components.insert(components.end(), {std::make_shared<CallbackComponent<BArgs>>(bargs)...});
m_impl = Create<CallbackImpl<R, UArgs...>>(
[f, bargs...](UArgs... uargs) -> R { return f(bargs..., uargs...); },
[f, bargs...](auto&&... uargs) -> R {
return f(bargs..., std::forward<decltype(uargs)>(uargs)...);
},
components);
}
@@ -508,7 +510,9 @@ class Callback : public CallbackBase
std::make_shared<CallbackComponent<BArgs>>(bargs)...});
m_impl = Create<CallbackImpl<R, UArgs...>>(
[f, bargs...](UArgs... uargs) -> R { return f(bargs..., uargs...); },
[f, bargs...](auto&&... uargs) -> R {
return f(bargs..., std::forward<decltype(uargs)>(uargs)...);
},
components);
}
@@ -525,11 +529,23 @@ class Callback : public CallbackBase
* The integer sequence is 0..N-1, where N is the number of arguments left unbound.
*/
template <std::size_t... INDEX, typename... BoundArgs>
auto BindImpl(std::index_sequence<INDEX...> seq, BoundArgs... bargs)
auto BindImpl(std::index_sequence<INDEX...> seq, BoundArgs&&... bargs)
{
return Callback<R, std::tuple_element_t<sizeof...(bargs) + INDEX, std::tuple<UArgs...>>...>(
*this,
bargs...);
Callback<R, std::tuple_element_t<sizeof...(bargs) + INDEX, std::tuple<UArgs...>>...> cb;
const auto f = DoPeekImpl()->GetFunction();
CallbackComponentVector components(DoPeekImpl()->GetComponents());
components.insert(components.end(),
{std::make_shared<CallbackComponent<BoundArgs>>(bargs)...});
cb.m_impl = Create<std::remove_pointer_t<decltype(cb.DoPeekImpl())>>(
[f, bargs...](auto&&... uargs) mutable {
return f(bargs..., std::forward<decltype(uargs)>(uargs)...);
},
components);
return cb;
}
public:
@@ -541,7 +557,7 @@ class Callback : public CallbackBase
* \return The bound callback
*/
template <typename... BoundArgs>
auto Bind(BoundArgs... bargs)
auto Bind(BoundArgs&&... bargs)
{
static_assert(sizeof...(UArgs) > 0);
return BindImpl(std::make_index_sequence<sizeof...(UArgs) - sizeof...(BoundArgs)>{},
@@ -749,9 +765,9 @@ MakeNullCallback()
*/
template <typename R, typename... Args, typename... BArgs>
auto
MakeBoundCallback(R (*fnPtr)(Args...), BArgs... bargs)
MakeBoundCallback(R (*fnPtr)(Args...), BArgs&&... bargs)
{
return Callback<R, Args...>(fnPtr).Bind(bargs...);
return Callback<R, Args...>(fnPtr).Bind(std::forward<BArgs>(bargs)...);
}
/**

View File

@@ -21,6 +21,7 @@
#include "config.h"
#include "des-metrics.h"
#include "environment-variable.h"
#include "global-value.h"
#include "log.h"
#include "string.h"
@@ -33,7 +34,7 @@
#include <algorithm> // transform
#include <cctype> // tolower
#include <cstdlib> // exit, getenv
#include <cstdlib> // exit
#include <cstring> // strlen
#include <iomanip> // setw, boolalpha
#include <set>
@@ -198,7 +199,7 @@ CommandLine::Parse(std::vector<std::string> args)
m_nonOptionCount = 0;
if (args.size() > 0)
if (!args.empty())
{
args.erase(args.begin()); // discard the program name
@@ -385,8 +386,9 @@ CommandLine::PrintHelp(std::ostream& os) const
// Hack to show just the declared non-options
Items nonOptions(m_nonOptions.begin(), m_nonOptions.begin() + m_NNonOptions);
os << m_shortName << (m_options.size() ? " [Program Options]" : "")
<< (nonOptions.size() ? " [Program Arguments]" : "") << " [General Arguments]" << std::endl;
os << m_shortName << (!m_options.empty() ? " [Program Options]" : "")
<< (!nonOptions.empty() ? " [Program Arguments]" : "") << " [General Arguments]"
<< std::endl;
if (!m_usage.empty())
{
@@ -461,13 +463,13 @@ CommandLine::PrintDoxygenUsage() const
{
NS_LOG_FUNCTION(this);
const char* envVar = std::getenv("NS_COMMANDLINE_INTROSPECTION");
if (envVar == nullptr || std::strlen(envVar) == 0)
auto [found, path] = EnvironmentVariable::Get("NS_COMMANDLINE_INTROSPECTION");
if (!found)
{
return;
}
if (m_shortName.size() == 0)
if (m_shortName.empty())
{
NS_FATAL_ERROR("No file name on example-to-run; forgot to use CommandLine var (__FILE__)?");
return;
@@ -476,7 +478,7 @@ CommandLine::PrintDoxygenUsage() const
// Hack to show just the declared non-options
Items nonOptions(m_nonOptions.begin(), m_nonOptions.begin() + m_NNonOptions);
std::string outf = SystemPath::Append(std::string(envVar), m_shortName + ".command-line");
std::string outf = SystemPath::Append(path, m_shortName + ".command-line");
NS_LOG_INFO("Writing CommandLine doxy to " << outf);
@@ -484,8 +486,8 @@ CommandLine::PrintDoxygenUsage() const
os << "/**\n \\file " << m_shortName << ".cc\n"
<< "<h3>Usage</h3>\n"
<< "<code>$ ./ns3 run \"" << m_shortName << (m_options.size() ? " [Program Options]" : "")
<< (nonOptions.size() ? " [Program Arguments]" : "") << "\"</code>\n";
<< "<code>$ ./ns3 run \"" << m_shortName << (!m_options.empty() ? " [Program Options]" : "")
<< (!nonOptions.empty() ? " [Program Arguments]" : "") << "\"</code>\n";
if (!m_usage.empty())
{
@@ -691,7 +693,7 @@ CommandLine::HandleArgument(const std::string& name, const std::string& value) c
auto errorExit = [this, name, value]() {
std::cerr << "Invalid command-line argument: --" << name;
if (value != "")
if (!value.empty())
{
std::cerr << "=" << value;
}
@@ -723,7 +725,7 @@ CommandLine::HandleArgument(const std::string& name, const std::string& value) c
bool
CommandLine::CallbackItem::HasDefault() const
{
return m_default != "";
return !m_default.empty();
}
std::string
@@ -759,7 +761,7 @@ CommandLine::AddValue(const std::string& name,
void
CommandLine::AddValue(const std::string& name,
const std::string& help,
ns3::Callback<bool, std::string> callback,
ns3::Callback<bool, const std::string&> callback,
const std::string& defaultValue /* = "" */)
{

View File

@@ -322,7 +322,7 @@ class CommandLine
*/
void AddValue(const std::string& name,
const std::string& help,
ns3::Callback<bool, std::string> callback,
ns3::Callback<bool, const std::string&> callback,
const std::string& defaultValue = "");
/**
@@ -533,7 +533,7 @@ class CommandLine
bool HasDefault() const override;
std::string GetDefault() const override;
ns3::Callback<bool, std::string> m_callback; /**< The Callback */
ns3::Callback<bool, const std::string&> m_callback; /**< The Callback */
std::string m_default; /**< The default value, as a string, if it exists. */
}; // class CallbackItem
@@ -777,7 +777,7 @@ template <typename T>
bool
CommandLine::UserItem<T>::HasDefault() const
{
return (m_default.size() > 0);
return !m_default.empty();
}
template <typename T>

Some files were not shown because too many files have changed in this diff Show More