From 8cd99af142c00422b4849a1ad80e30b64faf42e0 Mon Sep 17 00:00:00 2001 From: ZakariaHelalArzoo Date: Sat, 27 Mar 2021 11:52:48 +0000 Subject: [PATCH] point-to-point: (fixes #236) add packet payload comparison to the test --- .../test/point-to-point-test.cc | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/point-to-point/test/point-to-point-test.cc b/src/point-to-point/test/point-to-point-test.cc index f6221e0fd..c8c1111db 100644 --- a/src/point-to-point/test/point-to-point-test.cc +++ b/src/point-to-point/test/point-to-point-test.cc @@ -25,6 +25,8 @@ #include "ns3/point-to-point-channel.h" #include "ns3/net-device-queue-interface.h" +#include + using namespace ns3; /** @@ -47,12 +49,27 @@ public: virtual void DoRun (void); private: + + Ptr m_recvdPacket; //!< received packet /** * \brief Send one packet to the device specified * - * \param device NetDevice to send to + * \param device NetDevice to send to. + * \param buffer Payload content of the packet. + * \param size Size of the payload. */ - void SendOnePacket (Ptr device); + void SendOnePacket (Ptr device, uint8_t const *buffer, uint32_t size); + /** + * \brief Callback function which sets the recvdPacket parameter + * + * \param dev The receiving device. + * \param pkt The received packet. + * \param mode The protocol mode used. + * \param sender The sender address. + * + * \return A boolean indicating packet handled properly. + */ + bool RxPacket (Ptr dev, Ptr pkt, uint16_t mode, const Address &sender); }; PointToPointTest::PointToPointTest () @@ -61,12 +78,19 @@ PointToPointTest::PointToPointTest () } void -PointToPointTest::SendOnePacket (Ptr device) +PointToPointTest::SendOnePacket (Ptr device, uint8_t const *buffer, uint32_t size) { - Ptr p = Create (); + Ptr p = Create (buffer, size); device->Send (p, device->GetBroadcast (), 0x800); } +bool +PointToPointTest::RxPacket (Ptr dev, Ptr pkt, uint16_t mode, const Address &sender) +{ + m_recvdPacket = pkt; + return true; +} + void PointToPointTest::DoRun (void) @@ -86,11 +110,23 @@ PointToPointTest::DoRun (void) a->AddDevice (devA); b->AddDevice (devB); - - Simulator::Schedule (Seconds (1.0), &PointToPointTest::SendOnePacket, this, devA); + + devB->SetReceiveCallback (MakeCallback (&PointToPointTest::RxPacket, + this)); + uint8_t txBuffer [] = "\"Can you tell me where my country lies?\" \\ said the unifaun to his true love's eyes. \\ \"It lies with me!\" cried the Queen of Maybe \\ - for her merchandise, he traded in his prize."; + size_t txBufferSize = sizeof(txBuffer); + + Simulator::Schedule (Seconds (1.0), &PointToPointTest::SendOnePacket, this, devA, txBuffer, txBufferSize); Simulator::Run (); + NS_TEST_EXPECT_MSG_EQ (m_recvdPacket->GetSize (), txBufferSize, "trivial"); + + uint8_t rxBuffer [1500]; // As large as the P2P MTU size, assuming that the user didn't change it. + + m_recvdPacket->CopyData (rxBuffer, txBufferSize); + NS_TEST_EXPECT_MSG_EQ (memcmp (rxBuffer, txBuffer, txBufferSize), 0, "trivial"); + Simulator::Destroy (); }