38#include "ns3/boolean.h"
39#include "ns3/data-rate.h"
40#include "ns3/error-model.h"
41#include "ns3/internet-stack-helper.h"
42#include "ns3/ipv4-address-helper.h"
43#include "ns3/ipv4-interface-container.h"
44#include "ns3/ipv6-address-helper.h"
45#include "ns3/ipv6-interface-container.h"
47#include "ns3/neighbor-cache-helper.h"
48#include "ns3/node-container.h"
49#include "ns3/nstime.h"
51#include "ns3/simple-net-device-helper.h"
52#include "ns3/simple-net-device.h"
53#include "ns3/simulator.h"
55#include "ns3/uinteger.h"
192 void DoRun()
override;
277 device0->SetMtu(
m_mtu);
279 device1->SetMtu(
m_mtu);
295 ipv4AddrHelper.
SetBase(
"10.0.0.0",
"255.255.255.0");
364 "Rtt sample not within 0.0001 ms of expected value of 20.0013 ms");
374 "Rtt sample not within 0.0001 ms of expected value of 20.0017 ms");
392 "configured interval didn't match the observed interval");
407 NS_LOG_DEBUG(
"Destination host is unreachable " << seq);
411 NS_LOG_DEBUG(
"Destination network not reachable " << seq);
424 "Report transmit count does not equal expected");
430 "Report receive count does not equal expected");
436 "Report lost count does not equal expected");
443 "Report application not stopped at expected time");
511 netDev->SetReceiveErrorModel(errorModel);
520 m_nodes.Get(0)->AddApplication(ping);
536 "Traced Tx events do not equal expected");
542 "Traced Rtt events do not equal expected");
569 "1. Unlimited pings, no losses, StopApplication () with no packets in flight IPv4",
571 testcase1v4->SetStartTime(
Seconds(1));
572 testcase1v4->SetStopTime(
Seconds(5.5));
573 testcase1v4->SetCount(0);
574 testcase1v4->CheckReportTransmitted(5);
575 testcase1v4->CheckReportReceived(5);
576 testcase1v4->CheckTraceTx(5);
577 testcase1v4->SetDestinationAddress(
Ipv4Address(
"10.0.0.2"));
581 "1. Unlimited pings, no losses, StopApplication () with no packets in flight IPv6",
583 testcase1v6->SetStartTime(
Seconds(1));
584 testcase1v6->SetStopTime(
Seconds(5.5));
585 testcase1v6->SetCount(0);
586 testcase1v6->CheckReportTransmitted(5);
587 testcase1v6->CheckReportReceived(5);
588 testcase1v6->CheckTraceTx(5);
589 testcase1v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:2"));
601 "2. Unlimited pings, no losses, StopApplication () with 1 packet in flight IPv4",
603 testcase2v4->SetStartTime(
Seconds(1));
604 testcase2v4->SetStopTime(
Seconds(1.0001));
605 testcase2v4->SetSimulatorStopTime(
Seconds(5));
606 testcase2v4->CheckReportTransmitted(1);
607 testcase2v4->CheckReportReceived(0);
608 testcase1v4->SetDestinationAddress(
Ipv4Address(
"10.0.0.2"));
612 "2. Unlimited pings, no losses, StopApplication () with 1 packet in flight IPv6",
614 testcase2v6->SetStartTime(
Seconds(1));
615 testcase2v6->SetStopTime(
Seconds(1.0001));
616 testcase2v6->SetSimulatorStopTime(
Seconds(5));
617 testcase2v6->CheckReportTransmitted(1);
618 testcase2v6->CheckReportReceived(0);
619 testcase2v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:2"));
637 auto testcase3v4 =
new PingTestCase(
"3. Test for operation of count attribute and exit "
638 "time after all pings were received, IPv4",
640 testcase3v4->SetStartTime(
Seconds(1));
641 testcase3v4->SetStopTime(
Seconds(5));
642 testcase3v4->SetCount(count);
643 testcase3v4->SetSimulatorStopTime(
Seconds(6));
644 testcase3v4->CheckReportTransmitted(2);
645 testcase3v4->CheckReportReceived(2);
647 testcase3v4->CheckTraceTx(expectedTx);
648 testcase3v4->SetDestinationAddress(
Ipv4Address(
"10.0.0.2"));
651 auto testcase3v6 =
new PingTestCase(
"3. Test for operation of count attribute and exit "
652 "time after all pings were received, IPv6",
654 testcase3v6->SetStartTime(
Seconds(1));
655 testcase3v6->SetStopTime(
Seconds(5));
656 testcase3v6->SetCount(count);
657 testcase3v6->SetSimulatorStopTime(
Seconds(6));
658 testcase3v6->CheckReportTransmitted(2);
659 testcase3v6->CheckReportReceived(2);
661 testcase3v6->CheckTraceTx(expectedTx);
662 testcase3v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:2"));
677 testcase4v4->SetStartTime(
Seconds(1));
678 testcase4v4->SetStopTime(
Seconds(5));
679 testcase4v4->SetInterval(interval);
680 testcase4v4->SetSimulatorStopTime(
Seconds(6));
681 testcase4v4->CheckReportTransmitted(2);
682 testcase4v4->CheckReportReceived(2);
683 testcase4v4->SetDestinationAddress(
Ipv4Address(
"10.0.0.2"));
688 testcase4v6->SetStartTime(
Seconds(1));
689 testcase4v6->SetStopTime(
Seconds(5));
690 testcase4v6->SetInterval(interval);
691 testcase4v6->SetSimulatorStopTime(
Seconds(6));
692 testcase4v6->CheckReportTransmitted(2);
693 testcase4v6->CheckReportReceived(2);
694 testcase4v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:2"));
716 testcase5v4->SetStartTime(
Seconds(1));
717 testcase5v4->SetStopTime(
Seconds(5.5));
718 testcase5v4->SetDestinationAddress(
Ipv4Address(
"1.2.3.4"));
719 testcase5v4->CheckReportTransmitted(5);
720 testcase5v4->CheckReportReceived(0);
721 testcase5v4->CheckReportLoss(100);
726 testcase5v6->SetStartTime(
Seconds(1));
727 testcase5v6->SetStopTime(
Seconds(5.5));
728 testcase5v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:3"));
729 testcase5v6->CheckReportTransmitted(5);
730 testcase5v6->CheckReportReceived(0);
731 testcase5v6->CheckReportLoss(100);
749 testcase6v4->SetStartTime(
Seconds(1));
750 testcase6v4->SetStopTime(
Seconds(5.5));
752 testcase6v4->CheckReportTransmitted(5);
753 testcase6v4->CheckReportReceived(5);
754 testcase6v4->CheckReportLoss(0);
758 new PingTestCase(
"6. Test for behavior of ping to all-nodes multicast IPv6 address",
760 testcase6v6->SetStartTime(
Seconds(1));
761 testcase6v6->SetStopTime(
Seconds(5.5));
763 testcase6v6->CheckReportTransmitted(5);
764 testcase6v6->CheckReportReceived(5);
765 testcase6v6->CheckReportLoss(0);
782 "7. Test behavior of first reply lost in a count-limited configuration, IPv4",
784 std::list<uint32_t> dropList{0};
785 testcase7v4->SetDropList(dropList);
786 testcase7v4->SetStartTime(
Seconds(1));
787 testcase7v4->SetCount(3);
788 testcase7v4->SetStopTime(
Seconds(5));
789 testcase7v4->CheckTraceTx(3);
790 testcase7v4->CheckTraceRtt(2);
791 testcase7v4->CheckReportTransmitted(3);
792 testcase7v4->CheckReportReceived(2);
793 testcase7v4->CheckReportLoss(33);
798 "7. Test behavior of first reply lost in a count-limited configuration, IPv6",
800 testcase7v6->SetDropList(dropList);
801 testcase7v6->SetStartTime(
Seconds(1));
802 testcase7v6->SetCount(3);
803 testcase7v6->SetStopTime(
Seconds(5));
804 testcase7v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:2"));
805 testcase7v6->CheckTraceTx(3);
806 testcase7v6->CheckTraceRtt(2);
807 testcase7v6->CheckReportTransmitted(3);
808 testcase7v6->CheckReportReceived(2);
809 testcase7v6->CheckReportLoss(33);
827 "8. Test behavior of second reply lost in a count-limited configuration, IPv4",
829 std::list<uint32_t> dropList2{1};
830 testcase8v4->SetDropList(dropList2);
831 testcase8v4->SetStartTime(
Seconds(1));
832 testcase8v4->SetCount(3);
833 testcase8v4->SetStopTime(
Seconds(5));
834 testcase8v4->CheckTraceTx(3);
835 testcase8v4->CheckTraceRtt(2);
836 testcase8v4->CheckReportTransmitted(3);
837 testcase8v4->CheckReportReceived(2);
838 testcase8v4->CheckReportLoss(33);
843 "8. Test behavior of second reply lost in a count-limited configuration, IPv6",
845 testcase8v6->SetDropList(dropList2);
846 testcase8v6->SetStartTime(
Seconds(1));
847 testcase8v6->SetCount(3);
848 testcase8v6->SetStopTime(
Seconds(5));
849 testcase8v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:2"));
850 testcase8v6->CheckTraceTx(3);
851 testcase8v6->CheckTraceRtt(2);
852 testcase8v6->CheckReportTransmitted(3);
853 testcase8v6->CheckReportReceived(2);
854 testcase8v6->CheckReportLoss(33);
872 "9. Test behavior of last reply lost in a count-limited configuration, IPv4",
874 std::list<uint32_t> dropList3{2};
875 testcase9v4->SetDropList(dropList3);
876 testcase9v4->SetStartTime(
Seconds(1));
877 testcase9v4->SetCount(3);
878 testcase9v4->SetStopTime(
Seconds(5));
879 testcase9v4->CheckTraceTx(3);
880 testcase9v4->CheckTraceRtt(2);
881 testcase9v4->CheckReportTransmitted(3);
882 testcase9v4->CheckReportReceived(2);
883 testcase9v4->CheckReportLoss(33);
888 "9. Test behavior of last reply lost in a count-limited configuration, IPv6",
890 testcase9v6->SetDropList(dropList3);
891 testcase9v6->SetStartTime(
Seconds(1));
892 testcase9v6->SetCount(3);
893 testcase9v6->SetStopTime(
Seconds(5));
894 testcase9v6->SetDestinationAddress(
Ipv6Address(
"2001:1::200:ff:fe00:2"));
895 testcase9v6->CheckTraceTx(3);
896 testcase9v6->CheckTraceRtt(2);
897 testcase9v6->CheckReportTransmitted(3);
898 testcase9v6->CheckReportReceived(2);
899 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
Class for representing data rates.
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.
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.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
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.
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
keep track of a set of node pointers.
DropReason
Reason why a ping was dropped.
@ DROP_TIMEOUT
Response timed out.
@ 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, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
TestCase(const TestCase &)=delete
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
static constexpr auto UNIT
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.
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 ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#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...
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
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