Fix bug 1378 (UdpEchoClient::SetFill() does not set packet size correctly) (fix from jesse1013000@gmail.com)
authorTom Henderson <tomh@tomh.org>
Wed, 29 Feb 2012 19:36:28 -0800
changeset 7749 7458a10a17d1
parent 7748 1fbd1de4b24d
child 7750 fba4d5324510
child 8660 4263961772e9
Fix bug 1378 (UdpEchoClient::SetFill() does not set packet size correctly) (fix from jesse1013000@gmail.com)
RELEASE_NOTES
src/applications/model/udp-echo-client.cc
src/applications/test/udp-client-server-test.cc
--- a/RELEASE_NOTES	Tue Feb 28 12:05:16 2012 +0100
+++ b/RELEASE_NOTES	Wed Feb 29 19:36:28 2012 -0800
@@ -30,6 +30,7 @@
  - bug 1319 - Fix Ipv6RawSocketImpl Icmpv6 filter
  - bug 1318 - Asserts for IPv6 malformed packets
  - bug 1357 - IPv6 fragmentation fails due to checks about malformed extensions
+ - bug 1378 - UdpEchoClient::SetFill () does not set packet size correctly
 
 Known issues
 ------------
--- a/src/applications/model/udp-echo-client.cc	Tue Feb 28 12:05:16 2012 +0100
+++ b/src/applications/model/udp-echo-client.cc	Wed Feb 29 19:36:28 2012 -0800
@@ -236,6 +236,7 @@
   if (fillSize >= dataSize)
     {
       memcpy (m_data, fill, dataSize);
+      m_size = dataSize;
       return;
     }
 
--- a/src/applications/test/udp-client-server-test.cc	Tue Feb 28 12:05:16 2012 +0100
+++ b/src/applications/test/udp-client-server-test.cc	Wed Feb 29 19:36:28 2012 -0800
@@ -29,6 +29,7 @@
 #include "ns3/internet-stack-helper.h"
 #include "ns3/ipv4-address-helper.h"
 #include "ns3/udp-client-server-helper.h"
+#include "ns3/udp-echo-helper.h"
 #include "ns3/simple-net-device.h"
 #include "ns3/simple-channel.h"
 #include "ns3/test.h"
@@ -52,8 +53,8 @@
 
 };
 
-UdpClientServerTestCase::UdpClientServerTestCase () :
-  TestCase ("Test that all the udp packets generated by an udpClient application are correctly received by an udpServer application")
+UdpClientServerTestCase::UdpClientServerTestCase ()
+  : TestCase ("Test that all the udp packets generated by an udpClient application are correctly received by an udpServer application")
 {
 }
 
@@ -126,8 +127,8 @@
 
 };
 
-UdpTraceClientServerTestCase::UdpTraceClientServerTestCase () :
-  TestCase ("Test that all the udp packets generated by an udpTraceClient application are correctly received by an udpServer application")
+UdpTraceClientServerTestCase::UdpTraceClientServerTestCase ()
+  : TestCase ("Test that all the udp packets generated by an udpTraceClient application are correctly received by an udpServer application")
 {
 }
 
@@ -165,7 +166,7 @@
   apps.Start (Seconds (1.0));
   apps.Stop (Seconds (10.0));
 
-  uint32_t MaxPacketSize = 1400-28; // ip/udp header
+  uint32_t MaxPacketSize = 1400 - 28; // ip/udp header
   UdpTraceClientHelper client (i.GetAddress (1), port,"");
   client.SetAttribute ("MaxPacketSize", UintegerValue (MaxPacketSize));
   apps = client.Install (n.Get (0));
@@ -195,8 +196,8 @@
 
 };
 
-PacketLossCounterTestCase::PacketLossCounterTestCase () :
-  TestCase ("Test that all the PacketLossCounter class checks loss correctly in different cases")
+PacketLossCounterTestCase::PacketLossCounterTestCase ()
+  : TestCase ("Test that all the PacketLossCounter class checks loss correctly in different cases")
 {
 }
 
@@ -208,20 +209,20 @@
 {
   PacketLossCounter lossCounter (32);
   lossCounter.NotifyReceived (32); //out of order
-  for (uint32_t i=0; i<64; i++)
+  for (uint32_t i = 0; i < 64; i++)
     {
       lossCounter.NotifyReceived (i);
     }
 
   NS_TEST_ASSERT_MSG_EQ (lossCounter.GetLost (), 0, "Check that 0 packets are lost");
 
-  for (uint32_t i=65; i<128; i++) // drop (1) seqNum 64
+  for (uint32_t i = 65; i < 128; i++) // drop (1) seqNum 64
     {
       lossCounter.NotifyReceived (i);
     }
   NS_TEST_ASSERT_MSG_EQ (lossCounter.GetLost (), 1, "Check that 1 packet is lost");
 
-  for (uint32_t i=134; i<200; i++) // drop seqNum 128,129,130,131,132,133
+  for (uint32_t i = 134; i < 200; i++) // drop seqNum 128,129,130,131,132,133
     {
       lossCounter.NotifyReceived (i);
     }
@@ -236,7 +237,7 @@
   lossCounter.NotifyReceived (202);
   lossCounter.NotifyReceived (203);
   lossCounter.NotifyReceived (204);
-  for (uint32_t i=205; i<250; i++)
+  for (uint32_t i = 205; i < 250; i++)
     {
       lossCounter.NotifyReceived (i);
     }
@@ -248,24 +249,101 @@
   lossCounter.NotifyReceived (252);
   lossCounter.NotifyReceived (253);
   lossCounter.NotifyReceived (254);
-  for (uint32_t i=256; i<300; i++)
+  for (uint32_t i = 256; i < 300; i++)
     {
       lossCounter.NotifyReceived (i);
     }
   NS_TEST_ASSERT_MSG_EQ (lossCounter.GetLost (), 9, "Check that 9 (6+1+2) packet are lost");
 }
+
+/**
+ * Test fix for bug 1378
+ */
+
+class UdpEchoClientSetFillTestCase : public TestCase
+{
+public:
+  UdpEchoClientSetFillTestCase ();
+  virtual ~UdpEchoClientSetFillTestCase ();
+
+private:
+  virtual void DoRun (void);
+
+};
+
+UdpEchoClientSetFillTestCase::UdpEchoClientSetFillTestCase ()
+  : TestCase ("Test that the UdpEchoClient::SetFill class sets packet size (bug 1378)")
+{
+}
+
+UdpEchoClientSetFillTestCase::~UdpEchoClientSetFillTestCase ()
+{
+}
+
+void UdpEchoClientSetFillTestCase::DoRun (void)
+{
+  NodeContainer nodes;
+  nodes.Create (2);
+
+  InternetStackHelper internet;
+  internet.Install (nodes);
+
+  Ptr<SimpleNetDevice> txDev = CreateObject<SimpleNetDevice> ();
+  Ptr<SimpleNetDevice> rxDev = CreateObject<SimpleNetDevice> ();
+  nodes.Get (0)->AddDevice (txDev);
+  nodes.Get (1)->AddDevice (rxDev);
+  Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel> ();
+  rxDev->SetChannel (channel1);
+  txDev->SetChannel (channel1);
+  NetDeviceContainer d;
+  d.Add (txDev);
+  d.Add (rxDev);
+
+  Ipv4AddressHelper ipv4;
+
+  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+  Ipv4InterfaceContainer interfaces = ipv4.Assign (d);
+
+  uint16_t port = 5000;
+  UdpEchoServerHelper echoServer (port);
+  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
+  serverApps.Start (Seconds (1.0));
+  serverApps.Stop (Seconds (10.0));
+  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), port);
+  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
+  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
+  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
+
+  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
+
+  uint8_t arry[64];
+  uint8_t i;
+  for (i = 0; i < 64; i++)
+    {
+      arry[i] = i;
+    }
+  echoClient.SetFill (clientApps.Get (0), &(arry[0]), (uint32_t)64, (uint32_t)64);
+
+  clientApps.Start (Seconds (2.0));
+  clientApps.Stop (Seconds (10.0));
+
+  Simulator::Run ();
+  Simulator::Destroy ();
+}
+
 class UdpClientServerTestSuite : public TestSuite
 {
 public:
   UdpClientServerTestSuite ();
 };
 
-UdpClientServerTestSuite::UdpClientServerTestSuite () :
-  TestSuite ("udp-client-server", UNIT)
+UdpClientServerTestSuite::UdpClientServerTestSuite ()
+  : TestSuite ("udp-client-server", UNIT)
 {
   AddTestCase (new UdpTraceClientServerTestCase);
   AddTestCase (new UdpClientServerTestCase);
   AddTestCase (new PacketLossCounterTestCase);
+  AddTestCase (new UdpEchoClientSetFillTestCase);
 }
 
 static UdpClientServerTestSuite udpClientServerTestSuite;