49#include "ns3/boolean.h"
50#include "ns3/data-rate.h"
51#include "ns3/error-model.h"
52#include "ns3/internet-stack-helper.h"
53#include "ns3/ipv4-address-helper.h"
54#include "ns3/ipv4-interface-container.h"
55#include "ns3/ipv6-address-helper.h"
56#include "ns3/ipv6-interface-container.h"
58#include "ns3/neighbor-cache-helper.h"
59#include "ns3/node-container.h"
60#include "ns3/nstime.h"
62#include "ns3/simple-net-device-helper.h"
63#include "ns3/simple-net-device.h"
64#include "ns3/simulator.h"
66#include "ns3/uinteger.h"
203 void DoRun()
override;
288 device0->SetMtu(
m_mtu);
290 device1->SetMtu(
m_mtu);
306 ipv4AddrHelper.
SetBase(
"10.0.0.0",
"255.255.255.0");
375 "Rtt sample not within 0.0001 ms of expected value of 20.0013 ms");
385 "Rtt sample not within 0.0001 ms of expected value of 20.0017 ms");
403 "configured interval didn't match the observed interval");
412 if (reason == Ping::DropReason::DROP_TIMEOUT)
418 NS_LOG_DEBUG(
"Destination host is unreachable " << seq);
422 NS_LOG_DEBUG(
"Destination network not reachable " << seq);
435 "Report transmit count does not equal expected");
441 "Report receive count does not equal expected");
447 "Report lost count does not equal expected");
454 "Report application not stopped at expected time");
522 netDev->SetReceiveErrorModel(errorModel);
547 "Traced Tx events do not equal expected");
553 "Traced Rtt events do not equal expected");
580 "1. Unlimited pings, no losses, StopApplication () with no packets in flight IPv4",
582 testcase1v4->SetStartTime(
Seconds(1));
583 testcase1v4->SetStopTime(
Seconds(5.5));
584 testcase1v4->SetCount(0);
585 testcase1v4->CheckReportTransmitted(5);
586 testcase1v4->CheckReportReceived(5);
587 testcase1v4->CheckTraceTx(5);
588 testcase1v4->SetDestinationAddress(
Ipv4Address(
"10.0.0.2"));
592 "1. Unlimited pings, no losses, StopApplication () with no packets in flight IPv6",
594 testcase1v6->SetStartTime(
Seconds(1));
595 testcase1v6->SetStopTime(
Seconds(5.5));
596 testcase1v6->SetCount(0);
597 testcase1v6->CheckReportTransmitted(5);
598 testcase1v6->CheckReportReceived(5);
599 testcase1v6->CheckTraceTx(5);
600 testcase1v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:2"));
612 "2. Unlimited pings, no losses, StopApplication () with 1 packet in flight IPv4",
614 testcase2v4->SetStartTime(
Seconds(1));
615 testcase2v4->SetStopTime(
Seconds(1.0001));
616 testcase2v4->SetSimulatorStopTime(
Seconds(5));
617 testcase2v4->CheckReportTransmitted(1);
618 testcase2v4->CheckReportReceived(0);
619 testcase1v4->SetDestinationAddress(
Ipv4Address(
"10.0.0.2"));
623 "2. Unlimited pings, no losses, StopApplication () with 1 packet in flight IPv6",
625 testcase2v6->SetStartTime(
Seconds(1));
626 testcase2v6->SetStopTime(
Seconds(1.0001));
627 testcase2v6->SetSimulatorStopTime(
Seconds(5));
628 testcase2v6->CheckReportTransmitted(1);
629 testcase2v6->CheckReportReceived(0);
630 testcase2v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:2"));
648 auto testcase3v4 =
new PingTestCase(
"3. Test for operation of count attribute and exit "
649 "time after all pings were received, IPv4",
651 testcase3v4->SetStartTime(
Seconds(1));
652 testcase3v4->SetStopTime(
Seconds(5));
653 testcase3v4->SetCount(count);
654 testcase3v4->SetSimulatorStopTime(
Seconds(6));
655 testcase3v4->CheckReportTransmitted(2);
656 testcase3v4->CheckReportReceived(2);
658 testcase3v4->CheckTraceTx(expectedTx);
659 testcase3v4->SetDestinationAddress(
Ipv4Address(
"10.0.0.2"));
662 auto testcase3v6 =
new PingTestCase(
"3. Test for operation of count attribute and exit "
663 "time after all pings were received, IPv6",
665 testcase3v6->SetStartTime(
Seconds(1));
666 testcase3v6->SetStopTime(
Seconds(5));
667 testcase3v6->SetCount(count);
668 testcase3v6->SetSimulatorStopTime(
Seconds(6));
669 testcase3v6->CheckReportTransmitted(2);
670 testcase3v6->CheckReportReceived(2);
672 testcase3v6->CheckTraceTx(expectedTx);
673 testcase3v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:2"));
688 testcase4v4->SetStartTime(
Seconds(1));
689 testcase4v4->SetStopTime(
Seconds(5));
690 testcase4v4->SetInterval(interval);
691 testcase4v4->SetSimulatorStopTime(
Seconds(6));
692 testcase4v4->CheckReportTransmitted(2);
693 testcase4v4->CheckReportReceived(2);
694 testcase4v4->SetDestinationAddress(
Ipv4Address(
"10.0.0.2"));
699 testcase4v6->SetStartTime(
Seconds(1));
700 testcase4v6->SetStopTime(
Seconds(5));
701 testcase4v6->SetInterval(interval);
702 testcase4v6->SetSimulatorStopTime(
Seconds(6));
703 testcase4v6->CheckReportTransmitted(2);
704 testcase4v6->CheckReportReceived(2);
705 testcase4v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:2"));
727 testcase5v4->SetStartTime(
Seconds(1));
728 testcase5v4->SetStopTime(
Seconds(5.5));
729 testcase5v4->SetDestinationAddress(
Ipv4Address(
"1.2.3.4"));
730 testcase5v4->CheckReportTransmitted(5);
731 testcase5v4->CheckReportReceived(0);
732 testcase5v4->CheckReportLoss(100);
737 testcase5v6->SetStartTime(
Seconds(1));
738 testcase5v6->SetStopTime(
Seconds(5.5));
739 testcase5v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:3"));
740 testcase5v6->CheckReportTransmitted(5);
741 testcase5v6->CheckReportReceived(0);
742 testcase5v6->CheckReportLoss(100);
760 testcase6v4->SetStartTime(
Seconds(1));
761 testcase6v4->SetStopTime(
Seconds(5.5));
763 testcase6v4->CheckReportTransmitted(5);
764 testcase6v4->CheckReportReceived(5);
765 testcase6v4->CheckReportLoss(0);
769 new PingTestCase(
"6. Test for behavior of ping to all-nodes multicast IPv6 address",
771 testcase6v6->SetStartTime(
Seconds(1));
772 testcase6v6->SetStopTime(
Seconds(5.5));
774 testcase6v6->CheckReportTransmitted(5);
775 testcase6v6->CheckReportReceived(5);
776 testcase6v6->CheckReportLoss(0);
793 "7. Test behavior of first reply lost in a count-limited configuration, IPv4",
795 std::list<uint32_t> dropList{0};
796 testcase7v4->SetDropList(dropList);
797 testcase7v4->SetStartTime(
Seconds(1));
798 testcase7v4->SetCount(3);
799 testcase7v4->SetStopTime(
Seconds(5));
800 testcase7v4->CheckTraceTx(3);
801 testcase7v4->CheckTraceRtt(2);
802 testcase7v4->CheckReportTransmitted(3);
803 testcase7v4->CheckReportReceived(2);
804 testcase7v4->CheckReportLoss(33);
809 "7. Test behavior of first reply lost in a count-limited configuration, IPv6",
811 testcase7v6->SetDropList(dropList);
812 testcase7v6->SetStartTime(
Seconds(1));
813 testcase7v6->SetCount(3);
814 testcase7v6->SetStopTime(
Seconds(5));
815 testcase7v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:2"));
816 testcase7v6->CheckTraceTx(3);
817 testcase7v6->CheckTraceRtt(2);
818 testcase7v6->CheckReportTransmitted(3);
819 testcase7v6->CheckReportReceived(2);
820 testcase7v6->CheckReportLoss(33);
838 "8. Test behavior of second reply lost in a count-limited configuration, IPv4",
840 std::list<uint32_t> dropList2{1};
841 testcase8v4->SetDropList(dropList2);
842 testcase8v4->SetStartTime(
Seconds(1));
843 testcase8v4->SetCount(3);
844 testcase8v4->SetStopTime(
Seconds(5));
845 testcase8v4->CheckTraceTx(3);
846 testcase8v4->CheckTraceRtt(2);
847 testcase8v4->CheckReportTransmitted(3);
848 testcase8v4->CheckReportReceived(2);
849 testcase8v4->CheckReportLoss(33);
854 "8. Test behavior of second reply lost in a count-limited configuration, IPv6",
856 testcase8v6->SetDropList(dropList2);
857 testcase8v6->SetStartTime(
Seconds(1));
858 testcase8v6->SetCount(3);
859 testcase8v6->SetStopTime(
Seconds(5));
860 testcase8v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:2"));
861 testcase8v6->CheckTraceTx(3);
862 testcase8v6->CheckTraceRtt(2);
863 testcase8v6->CheckReportTransmitted(3);
864 testcase8v6->CheckReportReceived(2);
865 testcase8v6->CheckReportLoss(33);
883 "9. Test behavior of last reply lost in a count-limited configuration, IPv4",
885 std::list<uint32_t> dropList3{2};
886 testcase9v4->SetDropList(dropList3);
887 testcase9v4->SetStartTime(
Seconds(1));
888 testcase9v4->SetCount(3);
889 testcase9v4->SetStopTime(
Seconds(5));
890 testcase9v4->CheckTraceTx(3);
891 testcase9v4->CheckTraceRtt(2);
892 testcase9v4->CheckReportTransmitted(3);
893 testcase9v4->CheckReportReceived(2);
894 testcase9v4->CheckReportLoss(33);
899 "9. Test behavior of last reply lost in a count-limited configuration, IPv6",
901 testcase9v6->SetDropList(dropList3);
902 testcase9v6->SetStartTime(
Seconds(1));
903 testcase9v6->SetCount(3);
904 testcase9v6->SetStopTime(
Seconds(5));
905 testcase9v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:2"));
906 testcase9v6->CheckTraceTx(3);
907 testcase9v6->CheckTraceRtt(2);
908 testcase9v6->CheckReportTransmitted(3);
909 testcase9v6->CheckReportReceived(2);
910 testcase9v6->CheckReportLoss(33);
Time m_interpacketInterval
Time between pings.
bool m_checkReportTime
Set to true to check the Time.
Time m_simulatorStopTime
Simulator stop time.
void RttTraceSink(uint16_t seq, Time rttSample)
Trace RTT events.
uint32_t m_sizeAttribute
Size of pings.
uint16_t m_expectedReportLoss
Expected reported Loss.
uint32_t m_countTraceRtt
Rtt trace counter.
uint32_t m_expectedReportTx
Expected reported Tx.
void SetStartTime(Time startTime)
Set the PING start time.
void SetStopTime(Time stopTime)
Set the PING stop time.
PingTestCase(std::string name, bool useIpv6)
Constructor.
uint32_t m_expectedTraceRtt
Expected Rtt trace sink calls.
void CheckReportTime(Time expectedTime)
Enable the check on average RTT.
void SetSimulatorStopTime(Time stopTime)
Set the Simulation stop time.
bool m_checkTraceTx
Set to true to check the Tx number.
void TxTraceSink(uint16_t seq, Ptr< Packet > p)
Trace TX events.
Ipv6InterfaceContainer m_ipv6Interfaces
The IPv6 interfaces.
uint32_t m_countTraceTx
Tx trace counter.
Time m_lastTx
Last ping Tx time.
void SetCount(uint32_t count)
Set the number of pings to send.
bool m_checkReportTransmitted
Set to true to check the Tx number.
Time m_expectedReportTime
Expected reported time.
void CheckReportTransmitted(uint32_t expectedReportTx)
Enable the check on Tx pings.
NodeContainer m_nodes
The simulation nodes.
bool m_checkReportLoss
Set to true to check the Loss number.
bool m_useIpv6
Use IPv6 (true) or IPv4 (false)
void ReportTraceSink(const Ping::PingReport &report)
Trace Report generation events.
void CheckReportLoss(uint16_t expectedReportLoss)
Enable the check on Lost pings.
bool m_checkReportReceived
Set to true to check the Rx number.
void DoRun() override
Implementation to actually run this TestCase.
Address m_destination
Destination address.
Time m_stopTime
Stop time.
void CheckTraceRtt(uint32_t expectedRtt)
Enable the check on Rtt event count in Rtt trace source.
uint32_t m_expectedTraceTx
Expected Tx trace sink calls.
bool m_checkTraceRtt
Set to true to check the Rtt number.
void SetInterval(Time interval)
Set the interval of pings.
void CheckReportReceived(uint32_t expectedReportRx)
Enable the check on Rx pings.
void DropTraceSink(uint16_t seq, Ping::DropReason reason)
Trace Drop events.
NetDeviceContainer m_devices
The NetDevices.
Ipv4InterfaceContainer m_ipv4Interfaces
The IPv4 interfaces.
uint32_t m_expectedReportRx
Expected reported Rx.
Time m_startTime
Start time.
void SetDestinationAddress(Address address)
Set the destination address (either IPv4 or IPv6).
void DoSetup() override
Implementation to do any local setup required for this TestCase.
std::list< uint32_t > m_dropList
Drop first reply (true)
uint32_t m_countAttribute
Number of pings to send.
void SetSize(uint32_t size)
Set the size of pings.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
void SetDropList(const std::list< uint32_t > &dropList)
Set the packet drop list on the Ping node's interface.
void CheckTraceTx(uint32_t expectedTx)
Enable the check on Tx pings counted in Tx trace source.
a polymophic address class
AttributeValue implementation for Address.
AttributeValue implementation for Boolean.
Class for representing data rates.
AttributeValue implementation for DataRate.
An implementation of the ICMPv6 protocol.
aggregate IP/TCP/UDP functionality to existing Nodes.
void SetIpv4StackInstall(bool enable)
Enable/disable IPv4 stack install.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void SetIpv6StackInstall(bool enable)
Enable/disable IPv6 stack install.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv4 addresses are stored in host order in this class.
static Ipv4Address ConvertFrom(const Address &address)
static Ipv4Address GetBroadcast()
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Helper class to auto-assign global IPv6 unicast addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Describes an IPv6 address.
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
static Ipv6Address GetAllNodesMulticast()
Get the "all nodes multicast" address.
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
Keep track of a set of IPv6 interfaces.
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
IPv6 layer implementation.
Describes an IPv6 prefix.
A helper class to populate neighbor cache.
void PopulateNeighborCache()
Populate neighbor ARP and NDISC caches for all devices.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
DropReason
Reason why a ping was dropped.
@ DROP_NET_UNREACHABLE
Received ICMP Destination Network Unreachable.
@ DROP_HOST_UNREACHABLE
Received ICMP Destination Host Unreachable.
Smart pointer class similar to boost::intrusive_ptr.
build a set of SimpleNetDevice objects
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
void SetChannel(std::string type, Ts &&... args)
Each net device must have a channel to pass packets through.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
AttributeValue implementation for Time.
Hold an unsigned integer type.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
#define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg)
Test that an actual value is greater than or equal to a limit and report and abort if not.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
static PingTestSuite pingTestSuite
Static variable for test initialization.
constexpr bool USEIPV6_TRUE
constexpr bool USEIPV6_FALSE
A ping report provides all of the data that is typically output to the terminal when the application ...
uint16_t m_loss
Percentage of lost packets (decimal value 0-100)
uint32_t m_received
Number of echo replies received.
double m_rttMin
rtt min value
uint32_t m_transmitted
Number of echo requests sent.
double m_rttMax
rtt max value