A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
three-gpp-http-client-server-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Magister Solutions
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Budiarto Herman <budiarto.herman@magister.fi>
7 *
8 */
9
10#include <ns3/basic-data-calculators.h>
11#include <ns3/config.h>
12#include <ns3/error-model.h>
13#include <ns3/integer.h>
14#include <ns3/internet-stack-helper.h>
15#include <ns3/ipv4-address-helper.h>
16#include <ns3/ipv6-address-helper.h>
17#include <ns3/log.h>
18#include <ns3/mac48-address.h>
19#include <ns3/node.h>
20#include <ns3/nstime.h>
21#include <ns3/packet.h>
22#include <ns3/ptr.h>
23#include <ns3/simple-channel.h>
24#include <ns3/simple-net-device.h>
25#include <ns3/tcp-congestion-ops.h>
26#include <ns3/tcp-l4-protocol.h>
27#include <ns3/test.h>
28#include <ns3/three-gpp-http-client.h>
29#include <ns3/three-gpp-http-header.h>
30#include <ns3/three-gpp-http-helper.h>
31#include <ns3/three-gpp-http-server.h>
32
33#include <list>
34#include <sstream>
35
36NS_LOG_COMPONENT_DEFINE("ThreeGppHttpClientServerTest");
37
38using namespace ns3;
39
40// HTTP OBJECT TEST CASE //////////////////////////////////////////////////////
41
42/**
43 * \ingroup http
44 * \ingroup applications-test
45 * \ingroup tests
46 * A test class which verifies that each HTTP object sent is also received the
47 * same size.
48 *
49 * The test uses a minimalist scenario of one HTTP server and one HTTP client,
50 * connected through a SimpleChannel. The simulation runs until 3 web pages
51 * have been successfully downloaded by the client.
52 *
53 * The test also collects some statistical information from the simulation for
54 * informational or debugging purpose. This can be seen by enabling LOG_INFO.
55 */
57{
58 public:
59 /**
60 * \param name A textual label to briefly describe the test.
61 * \param rngRun Run index to be used, intended to affect the values produced
62 * by random number generators throughout the test.
63 * \param tcpType Type of TCP algorithm to be used by the connection between
64 * the client and the server. Must be a child type of
65 * ns3::TcpSocketFactory.
66 * \param channelDelay Transmission delay between the client and the server
67 * (and vice versa) which is due to the channel.
68 * \param bitErrorRate The probability of transmission error between the
69 * client and the server (and vice versa) in the unit of
70 * bits.
71 * \param mtuSize Maximum transmission unit (in bytes) to be used by the
72 * server model.
73 * \param useIpv6 If true, IPv6 will be used to address both client and
74 * server. Otherwise, IPv4 will be used.
75 */
76 ThreeGppHttpObjectTestCase(const std::string& name,
77 uint32_t rngRun,
78 const TypeId& tcpType,
79 const Time& channelDelay,
80 double bitErrorRate,
81 uint32_t mtuSize,
82 bool useIpv6);
83
84 private:
85 /**
86 * Creates a Node, complete with a TCP/IP stack and address assignment.
87 * #m_tcpType determines the TCP algorithm installed at the TCP stack.
88 * #m_useIpv6 determines whether to use IPv4 addressing or IPv6 addressing.
89 *
90 * \param[in] channel Pointer to a channel which the node's device will be
91 * attached to.
92 * \param[out] assignedAddress The resulting address of the node.
93 * \return Pointer to the newly created node.
94 */
96
97 // Inherited from TestCase base class.
98 void DoRun() override;
99 void DoTeardown() override;
100
101 /**
102 * \internal
103 * Internal class used by ThreeGppHttpObjectTestCase. Keep track of the number
104 * of object and bytes that have been sent and received in the simulation by
105 * listening to the relevant trace sources.
106 */
108 {
109 public:
110 /// Creates a new instance with all counters begin at zero.
112 /**
113 * Shall be invoked when a whole object has been transmitted.
114 * \param size Size of the whole object (in bytes).
115 */
116 void ObjectSent(uint32_t size);
117 /**
118 * Shall be invoked when an object part has been received.
119 * \param size Size of the object part (in bytes). This amount will be
120 * accumulated until ObjectReceived() is invoked.
121 */
122 void PartReceived(uint32_t size);
123 /**
124 * Shall be invoked after all parts of a complete object have been
125 * received.
126 * \param[out] txSize Size of the whole object (in bytes) when it was
127 * transmitted.
128 * \param[out] rxSize Size of the whole object (in bytes) received.
129 * \return True if this receive operation has a matching transmission
130 * operation (ObjectSent()), otherwise false. Both arguments are
131 * guaranteed to be replaced with initialized values if the return
132 * value is true.
133 */
134 bool ObjectReceived(uint32_t& txSize, uint32_t& rxSize);
135 /// \return True if zero object is currently tracked.
136 bool IsEmpty() const;
137 /// \return Number of whole objects that have been received so far.
138 uint16_t GetNumOfObjectsReceived() const;
139
140 private:
141 /**
142 * Each entry is the size (in bytes) of object transmitted. A new entry is
143 * pushed to the back when a new object is transmitted. The frontmost entry
144 * is then removed when a whole object is received, i.e., it's logically a
145 * first-in-first-out queue data structure.
146 */
147 std::list<uint32_t> m_objectsSize;
148 /// The accumulated size (in bytes) of parts of a whole object.
150 /// Number of whole objects that have been received so far.
152 };
153
154 // The following defines one tracker for each HTTP object type.
155 ThreeGppHttpObjectTracker m_requestObjectTracker; ///< Tracker of request objects.
156 ThreeGppHttpObjectTracker m_mainObjectTracker; ///< Tracker of main objects.
157 ThreeGppHttpObjectTracker m_embeddedObjectTracker; ///< Tracker of embedded objects.
158
159 // CALLBACK TO TRACE SOURCES.
160
161 /**
162 * Connected with `TxMainObjectRequest` trace source of the client.
163 * Updates #m_requestObjectTracker.
164 * \param packet The packet of main object sent.
165 */
167 /**
168 * Connected with `TxEmbeddedObjectRequest` trace source of the client.
169 * Updates #m_requestObjectTracker.
170 * \param packet The packet of embedded object sent.
171 */
173 /**
174 * Connected with `Rx` trace source of the server.
175 * Updates #m_requestObjectTracker and perform some tests on the packet and
176 * the size of the object.
177 * \param packet The packet received.
178 * \param from The address where the packet originates from.
179 */
180 void ServerRxCallback(Ptr<const Packet> packet, const Address& from);
181 /**
182 * Connected with `MainObject` trace source of the server.
183 * Updates #m_mainObjectTracker.
184 * \param size Size of the generated main object (in bytes).
185 */
187 /**
188 * Connected with `RxMainObjectPacket` trace source of the client.
189 * Updates #m_mainObjectTracker and perform some tests on the packet.
190 * \param packet The packet received.
191 */
193 /**
194 * Connected with `RxMainObject` trace source of the client. Updates
195 * #m_mainObjectTracker and perform some tests on the size of the object.
196 * \param httpClient Pointer to the application.
197 * \param packet Full packet received by application.
198 */
200 Ptr<const Packet> packet);
201 /**
202 * Connected with `EmbeddedObject` trace source of the server.
203 * Updates #m_embeddedObjectTracker.
204 * \param size Size of the generated embedded object (in bytes).
205 */
207 /**
208 * Connected with `RxEmbeddedObjectPacket` trace source of the client.
209 * Updates #m_embeddedObjectTracker and perform some tests on the packet.
210 * \param packet The packet received.
211 */
213 /**
214 * Connected with `RxEmbeddedObject` trace source of the client. Updates
215 * #m_embeddedObjectTracker and perform some tests on the size of the object.
216 * \param httpClient Pointer to the application.
217 * \param packet Full packet received by application.
218 */
220 Ptr<const Packet> packet);
221 /**
222 * Connected with `StateTransition` trace source of the client.
223 * Increments #m_numOfPagesReceived when the client enters READING state.
224 * \param oldState The name of the previous state.
225 * \param newState The name of the current state.
226 */
227 void ClientStateTransitionCallback(const std::string& oldState, const std::string& newState);
228 /**
229 * Connected with `RxDelay` trace source of the client.
230 * Updates the statistics in #m_delayCalculator.
231 * \param delay The packet one-trip delay time.
232 * \param from The address of the device where the packet originates from.
233 */
234 void ClientRxDelayCallback(const Time& delay, const Address& from);
235 /**
236 * Connected with `RxRtt` trace source of the client.
237 * Updates the statistics in #m_rttCalculator.
238 * \param rtt The packet round trip delay time.
239 * \param from The address of the device where the packet originates from.
240 */
241 void ClientRxRttCallback(const Time& rtt, const Address& from);
242 /**
243 * Connected with `PhyRxDrop` trace source of both the client's and server's
244 * devices. Increments #m_numOfPacketDrops.
245 * \param packet Pointer to the packet being dropped.
246 */
248 /**
249 * Dummy event
250 */
251 void ProgressCallback();
252
253 // THE PARAMETERS OF THE TEST CASE.
254
255 uint32_t m_rngRun; ///< Determines the set of random values generated.
256 TypeId m_tcpType; ///< TCP algorithm used.
257 Time m_channelDelay; ///< %Time needed by a packet to propagate.
258 uint32_t m_mtuSize; ///< Maximum transmission unit (in bytes).
259 bool m_useIpv6; ///< Whether to use IPv6 or IPv4.
260
261 // OTHER MEMBER VARIABLES.
262
263 /// Receive error model to be attached to the devices of both directions.
265 /// Begins with 0. Simulation stops if this reaches 3.
267 /// Number of packets dropped because of #m_errorModel.
269 /// Installs TCP/IP stack on the nodes.
271 /// Assigns IPv4 addresses to the nodes.
273 /// Assigns IPv6 addresses to the nodes.
275 /// Keeps statistical information of one-trip delays (in seconds).
277 /// Keeps statistical information of round-trip delays (in seconds).
279
280}; // end of `class HttpClientServerTestCase`
281
283 uint32_t rngRun,
284 const TypeId& tcpType,
285 const Time& channelDelay,
286 double bitErrorRate,
287 uint32_t mtuSize,
288 bool useIpv6)
289 : TestCase(name),
290 m_rngRun(rngRun),
291 m_tcpType(tcpType),
292 m_channelDelay(channelDelay),
293 m_mtuSize(mtuSize),
294 m_useIpv6(useIpv6),
295 m_numOfPagesReceived(0),
296 m_numOfPacketDrops(0)
297{
298 NS_LOG_FUNCTION(this << GetName());
299
300 // NS_ASSERT (tcpType.IsChildOf (TypeId::LookupByName ("ns3::TcpSocketBase")));
301 NS_ASSERT(channelDelay.IsPositive());
302
304 m_errorModel->SetRate(bitErrorRate);
306
308 Ipv4Mask("255.0.0.0"),
309 Ipv4Address("0.0.0.1"));
311
314}
315
318 Address& assignedAddress)
319{
320 NS_LOG_FUNCTION(this << channel);
321
323 dev->SetAddress(Mac48Address::Allocate());
324 dev->SetChannel(channel);
325 dev->SetReceiveErrorModel(m_errorModel);
326
328 node->AddDevice(dev);
330
331 // Assign IP address according to the selected Ip version.
332 if (m_useIpv6)
333 {
335 NS_ASSERT(ipv6Ifs.GetN() == 1);
336 assignedAddress = ipv6Ifs.GetAddress(0, 0);
337 }
338 else
339 {
341 NS_ASSERT(ipv4Ifs.GetN() == 1);
342 assignedAddress = ipv4Ifs.GetAddress(0, 0);
343 }
344
345 NS_LOG_DEBUG(this << " node is assigned to " << assignedAddress << ".");
346
347 // Set the TCP algorithm.
348 Ptr<TcpL4Protocol> tcp = node->GetObject<TcpL4Protocol>();
349 tcp->SetAttribute("SocketType", TypeIdValue(m_tcpType));
350
351 // Connect with the trace source that informs about packet drop due to error.
352 dev->TraceConnectWithoutContext(
353 "PhyRxDrop",
355
356 return node;
357}
358
359void
361{
362 NS_LOG_FUNCTION(this << GetName());
364 NS_LOG_INFO(this << " Running test case " << GetName());
365
366 /*
367 * Create topology:
368 *
369 * Server Node Client Node
370 * +-----------------+ +-----------------+
371 * | HTTP Server | | HTTP Client |
372 * | Application | | Application |
373 * +-----------------+ +-----------------+
374 * | TCP | | TCP |
375 * +-----------------+ +-----------------+
376 * | IPv4/v6 | | IPv4/v6 |
377 * +-----------------+ +-----------------+
378 * | Simple NetDev | | Simple NetDev |
379 * +-----------------+ +-----------------+
380 * | |
381 * | |
382 * +----------------------------+
383 * Simple Channel
384 */
385
386 // Channel.
388 channel->SetAttribute("Delay", TimeValue(m_channelDelay));
389
390 // Server node.
391 Address serverAddress;
392 Ptr<Node> serverNode = CreateSimpleInternetNode(channel, serverAddress);
393 ThreeGppHttpServerHelper serverHelper(serverAddress);
394 ApplicationContainer serverApplications = serverHelper.Install(serverNode);
395 NS_TEST_ASSERT_MSG_EQ(serverApplications.GetN(),
396 1,
397 "Invalid number of HTTP servers has been installed");
398 Ptr<ThreeGppHttpServer> httpServer = serverApplications.Get(0)->GetObject<ThreeGppHttpServer>();
399 NS_TEST_ASSERT_MSG_NE(httpServer,
400 nullptr,
401 "HTTP server installation fails to produce a proper type");
402 httpServer->SetMtuSize(m_mtuSize);
403
404 // Client node.
405 Address clientAddress;
406 Ptr<Node> clientNode = CreateSimpleInternetNode(channel, clientAddress);
407 ThreeGppHttpClientHelper clientHelper(serverAddress);
408 ApplicationContainer clientApplications = clientHelper.Install(clientNode);
409 NS_TEST_ASSERT_MSG_EQ(clientApplications.GetN(),
410 1,
411 "Invalid number of HTTP clients has been installed");
412 Ptr<ThreeGppHttpClient> httpClient = clientApplications.Get(0)->GetObject<ThreeGppHttpClient>();
413 NS_TEST_ASSERT_MSG_NE(httpClient,
414 nullptr,
415 "HTTP client installation fails to produce a proper type");
416
417 // Uplink (requests) trace sources.
418 bool traceSourceConnected = httpClient->TraceConnectWithoutContext(
419 "TxMainObjectRequest",
421 NS_ASSERT(traceSourceConnected);
422 traceSourceConnected = httpClient->TraceConnectWithoutContext(
423 "TxEmbeddedObjectRequest",
425 NS_ASSERT(traceSourceConnected);
426 traceSourceConnected = httpServer->TraceConnectWithoutContext(
427 "Rx",
429 NS_ASSERT(traceSourceConnected);
430
431 // Downlink (main objects) trace sources.
432 traceSourceConnected = httpServer->TraceConnectWithoutContext(
433 "MainObject",
435 NS_ASSERT(traceSourceConnected);
436 traceSourceConnected = httpClient->TraceConnectWithoutContext(
437 "RxMainObjectPacket",
439 NS_ASSERT(traceSourceConnected);
440 traceSourceConnected = httpClient->TraceConnectWithoutContext(
441 "RxMainObject",
443 NS_ASSERT(traceSourceConnected);
444
445 // Downlink (embedded objects) trace sources.
446 traceSourceConnected = httpServer->TraceConnectWithoutContext(
447 "EmbeddedObject",
449 NS_ASSERT(traceSourceConnected);
450
451 traceSourceConnected = httpClient->TraceConnectWithoutContext(
452 "RxEmbeddedObjectPacket",
454 NS_ASSERT(traceSourceConnected);
455
456 traceSourceConnected = httpClient->TraceConnectWithoutContext(
457 "RxEmbeddedObject",
459 NS_ASSERT(traceSourceConnected);
460
461 // Other trace sources.
462 traceSourceConnected = httpClient->TraceConnectWithoutContext(
463 "StateTransition",
465 NS_ASSERT(traceSourceConnected);
466 traceSourceConnected = httpClient->TraceConnectWithoutContext(
467 "RxDelay",
469 NS_ASSERT(traceSourceConnected);
470 traceSourceConnected = httpClient->TraceConnectWithoutContext(
471 "RxRtt",
473 NS_ASSERT(traceSourceConnected);
474
476
477 /*
478 * Here we don't set the simulation stop time. During the run, the simulation
479 * will stop immediately after the client has completely received the third
480 * web page.
481 */
483
484 // Dump some statistical information about the simulation.
485 NS_LOG_INFO(this << " Total request objects received: "
486 << m_requestObjectTracker.GetNumOfObjectsReceived() << " object(s).");
487 NS_LOG_INFO(this << " Total main objects received: "
488 << m_mainObjectTracker.GetNumOfObjectsReceived() << " object(s).");
489 NS_LOG_INFO(this << " Total embedded objects received: "
491 NS_LOG_INFO(this << " One-trip delays:"
492 << " average=" << m_delayCalculator->getMean() << " min="
493 << m_delayCalculator->getMin() << " max=" << m_delayCalculator->getMax());
494 NS_LOG_INFO(this << " Round-trip delays:"
495 << " average=" << m_rttCalculator->getMean() << " min="
496 << m_rttCalculator->getMin() << " max=" << m_rttCalculator->getMax());
497 NS_LOG_INFO(this << " Number of packets dropped by the devices: " << m_numOfPacketDrops
498 << " packet(s).");
499
500 // Some post-simulation tests.
501 NS_TEST_EXPECT_MSG_EQ(m_numOfPagesReceived, 3, "Unexpected number of web pages processed.");
503 true,
504 "Tracker of request objects detected irrelevant packet(s).");
506 true,
507 "Tracker of main objects detected irrelevant packet(s).");
509 true,
510 "Tracker of embedded objects detected irrelevant packet(s).");
511
513
514} // end of `void HttpClientServerTestCase::DoRun ()`
515
516void
521
523 : m_rxBuffer(0),
524 m_numOfObjectsReceived(0)
525{
526 NS_LOG_FUNCTION(this);
527}
528
529void
531{
532 NS_LOG_FUNCTION(this << size);
533 m_objectsSize.push_back(size);
534}
535
536void
542
543bool
545 uint32_t& rxSize)
546{
547 NS_LOG_FUNCTION(this);
548
549 if (m_objectsSize.empty())
550 {
551 return false;
552 }
553
554 // Set output values.
555 txSize = m_objectsSize.front();
556 rxSize = m_rxBuffer;
557
558 // Reset counters.
559 m_objectsSize.pop_front();
560 m_rxBuffer = 0;
561 m_numOfObjectsReceived++;
562
563 return true;
564}
565
566bool
568{
569 return (m_objectsSize.empty() && (m_rxBuffer == 0));
570}
571
572uint16_t
577
578void
580{
581 NS_LOG_FUNCTION(this << packet << packet->GetSize());
582 m_requestObjectTracker.ObjectSent(packet->GetSize());
583}
584
585void
587{
588 NS_LOG_FUNCTION(this << packet << packet->GetSize());
589 m_requestObjectTracker.ObjectSent(packet->GetSize());
590}
591
592void
594{
595 NS_LOG_FUNCTION(this << packet << packet->GetSize() << from);
596
597 // Check the header in packet
598 Ptr<Packet> copy = packet->Copy();
599 ThreeGppHttpHeader httpHeader;
600 NS_TEST_ASSERT_MSG_EQ(copy->RemoveHeader(httpHeader),
601 22,
602 "Error finding ThreeGppHttpHeader in a packet received by the server");
604 Seconds(0.0),
605 "Request object's client TS is unexpectedly non-positive");
606
607 m_requestObjectTracker.PartReceived(packet->GetSize());
608
609 /*
610 * Request objects are assumed to be small and to not typically split. So we
611 * immediately follow by concluding the receive of a whole request object.
612 */
613 uint32_t txSize = 0;
614 uint32_t rxSize = 0;
615 bool isSent = m_requestObjectTracker.ObjectReceived(txSize, rxSize);
616 NS_TEST_ASSERT_MSG_EQ(isSent, true, "Server receives one too many request object");
618 rxSize,
619 "Transmitted size and received size of request object differ");
620}
621
622void
628
629void
631{
632 NS_LOG_FUNCTION(this << packet << packet->GetSize());
633 m_mainObjectTracker.PartReceived(packet->GetSize());
634}
635
636void
638 Ptr<const Packet> packet)
639{
640 NS_LOG_FUNCTION(this << httpClient << httpClient->GetNode()->GetId());
641
642 // Verify the header in the packet.
643 Ptr<Packet> copy = packet->Copy();
644 ThreeGppHttpHeader httpHeader;
645 NS_TEST_ASSERT_MSG_EQ(copy->RemoveHeader(httpHeader),
646 22,
647 "Error finding ThreeGppHttpHeader in a packet received by the server");
650 "Invalid content type in the received packet");
652 Seconds(0.0),
653 "Main object's client TS is unexpectedly non-positive");
655 Seconds(0.0),
656 "Main object's server TS is unexpectedly non-positive");
657
658 uint32_t txSize = 0;
659 uint32_t rxSize = 0;
660 bool isSent = m_mainObjectTracker.ObjectReceived(txSize, rxSize);
661 NS_TEST_ASSERT_MSG_EQ(isSent, true, "Client receives one too many main object");
663 rxSize,
664 "Transmitted size and received size of main object differ");
666 rxSize,
667 "Actual main object packet size and received size of main object differ");
668}
669
670void
676
677void
683
684void
686 Ptr<const Packet> packet)
687{
688 NS_LOG_FUNCTION(this << httpClient << httpClient->GetNode()->GetId());
689
690 // Verify the header in the packet.
691 Ptr<Packet> copy = packet->Copy();
692 ThreeGppHttpHeader httpHeader;
693 NS_TEST_ASSERT_MSG_EQ(copy->RemoveHeader(httpHeader),
694 22,
695 "Error finding ThreeGppHttpHeader in a packet received by the server");
698 "Invalid content type in the received packet");
700 Seconds(0.0),
701 "Embedded object's client TS is unexpectedly non-positive");
703 Seconds(0.0),
704 "Embedded object's server TS is unexpectedly non-positive");
705
706 uint32_t txSize = 0;
707 uint32_t rxSize = 0;
708 bool isSent = m_embeddedObjectTracker.ObjectReceived(txSize, rxSize);
709 NS_TEST_ASSERT_MSG_EQ(isSent, true, "Client receives one too many embedded object");
711 rxSize,
712 "Transmitted size and received size of embedded object differ");
714 httpHeader.GetContentLength(),
715 rxSize,
716 "Actual embedded object packet size and received size of embedded object differ");
717}
718
719void
721 const std::string& newState)
722{
723 NS_LOG_FUNCTION(this << oldState << newState);
724
725 if (newState == "READING")
726 {
728
729 if (m_numOfPagesReceived >= 3)
730 {
731 // We have processed 3 web pages and that should be enough for this test.
732 NS_LOG_LOGIC(this << " Test is stopping now.");
734 }
735 }
736}
737
738void
744
745void
747{
748 NS_LOG_FUNCTION(this << delay.As(Time::S) << from);
749 m_delayCalculator->Update(delay.GetSeconds());
750}
751
752void
754{
755 NS_LOG_FUNCTION(this << rtt.As(Time::S) << from);
756 m_rttCalculator->Update(rtt.GetSeconds());
757}
758
759void
761{
762 NS_LOG_FUNCTION(this << packet << packet->GetSize());
764}
765
766// TEST SUITE /////////////////////////////////////////////////////////////////
767
768/**
769 * \ingroup http
770 * \ingroup applications-test
771 * \ingroup tests
772 * A test class for running several system tests which validate the web
773 * browsing traffic model.
774 *
775 * The tests cover the combinations of the following parameters:
776 * - the use of NewReno (ns-3's default)
777 * - various lengths of channel delay: 3 ms, 30 ms, and 300 ms;
778 * - the existence of transmission error;
779 * - different MTU (maximum transmission unit) sizes;
780 * - IPv4 and IPv6; and
781 * - the use of different set of random numbers.
782 *
783 * The _fullness_ parameter specified when running the test framework will
784 * determine the number of test cases created by this test suite.
785 */
787{
788 public:
789 /// Instantiate the test suite.
791 : TestSuite("applications-three-gpp-http-client-server", Type::SYSTEM)
792 {
793 // LogComponentEnable ("ThreeGppHttpClientServerTest", LOG_INFO);
794 // LogComponentEnable ("ThreeGppHttpClient", LOG_INFO);
795 // LogComponentEnable ("ThreeGppHttpServer", LOG_INFO);
796 // LogComponentEnableAll (LOG_PREFIX_ALL);
797
798 Time channelDelay[] = {MilliSeconds(3), MilliSeconds(30), MilliSeconds(300)};
799 double bitErrorRate[] = {0.0, 5.0e-6};
800 uint32_t mtuSize[] = {536, 1460};
801
802 uint32_t run = 1;
803 while (run <= 100)
804 {
805 for (uint32_t i1 = 0; i1 < 3; i1++)
806 {
807 for (uint32_t i2 = 0; i2 < 2; i2++)
808 {
809 for (uint32_t i3 = 0; i3 < 2; i3++)
810 {
811 AddHttpObjectTestCase(run++,
812 channelDelay[i1],
813 bitErrorRate[i2],
814 mtuSize[i3],
815 false);
816 AddHttpObjectTestCase(run++,
817 channelDelay[i1],
818 bitErrorRate[i2],
819 mtuSize[i3],
820 true);
821 }
822 }
823 }
824 }
825 }
826
827 private:
828 /**
829 * Creates a test case with the given parameters.
830 *
831 * \param rngRun Run index to be used, intended to affect the values produced
832 * by random number generators throughout the test.
833 * \param channelDelay Transmission delay between the client and the server
834 * (and vice versa) which is due to the channel.
835 * \param bitErrorRate The probability of transmission error between the
836 * client and the server (and vice versa) in the unit of
837 * bits.
838 * \param mtuSize Maximum transmission unit (in bytes) to be used by the
839 * server model.
840 * \param useIpv6 If true, IPv6 will be used to address both client and
841 * server. Otherwise, IPv4 will be used.
842 */
844 const Time& channelDelay,
845 double bitErrorRate,
846 uint32_t mtuSize,
847 bool useIpv6)
848 {
849 std::ostringstream name;
850 name << "Run #" << rngRun;
851 name << " delay=" << channelDelay.As(Time::MS);
852 name << " ber=" << bitErrorRate;
853 name << " mtu=" << mtuSize;
854
855 if (useIpv6)
856 {
857 name << " IPv6";
858 }
859 else
860 {
861 name << " IPv4";
862 }
863
864 // Assign higher fullness for tests with higher RngRun.
865 TestCase::Duration testDuration = TestCase::Duration::QUICK;
866 if (rngRun > 20)
867 {
868 testDuration = TestCase::Duration::EXTENSIVE;
869 }
870 if (rngRun > 50)
871 {
872 testDuration = TestCase::Duration::TAKES_FOREVER;
873 }
874
875 AddTestCase(new ThreeGppHttpObjectTestCase(name.str(),
876 rngRun,
878 channelDelay,
879 bitErrorRate,
880 mtuSize,
881 useIpv6),
882 testDuration);
883 }
884
885}; // end of class `ThreeGppHttpClientServerTestSuite`
886
887/// The global instance of the `three-gpp-http-client-server` system test.
A test class for running several system tests which validate the web browsing traffic model.
void AddHttpObjectTestCase(uint32_t rngRun, const Time &channelDelay, double bitErrorRate, uint32_t mtuSize, bool useIpv6)
Creates a test case with the given parameters.
ThreeGppHttpClientServerTestSuite()
Instantiate the test suite.
ThreeGppHttpObjectTracker()
Creates a new instance with all counters begin at zero.
void PartReceived(uint32_t size)
Shall be invoked when an object part has been received.
void ObjectSent(uint32_t size)
Shall be invoked when a whole object has been transmitted.
bool ObjectReceived(uint32_t &txSize, uint32_t &rxSize)
Shall be invoked after all parts of a complete object have been received.
uint32_t m_rxBuffer
The accumulated size (in bytes) of parts of a whole object.
uint16_t m_numOfObjectsReceived
Number of whole objects that have been received so far.
std::list< uint32_t > m_objectsSize
Each entry is the size (in bytes) of object transmitted.
A test class which verifies that each HTTP object sent is also received the same size.
ThreeGppHttpObjectTracker m_embeddedObjectTracker
Tracker of embedded objects.
void DeviceDropCallback(Ptr< const Packet > packet)
Connected with PhyRxDrop trace source of both the client's and server's devices.
InternetStackHelper m_internetStackHelper
Installs TCP/IP stack on the nodes.
void ClientRxDelayCallback(const Time &delay, const Address &from)
Connected with RxDelay trace source of the client.
ThreeGppHttpObjectTestCase(const std::string &name, uint32_t rngRun, const TypeId &tcpType, const Time &channelDelay, double bitErrorRate, uint32_t mtuSize, bool useIpv6)
void ClientTxEmbeddedObjectRequestCallback(Ptr< const Packet > packet)
Connected with TxEmbeddedObjectRequest trace source of the client.
void ClientTxMainObjectRequestCallback(Ptr< const Packet > packet)
Connected with TxMainObjectRequest trace source of the client.
void ClientRxEmbeddedObjectCallback(Ptr< const ThreeGppHttpClient > httpClient, Ptr< const Packet > packet)
Connected with RxEmbeddedObject trace source of the client.
uint16_t m_numOfPagesReceived
Begins with 0. Simulation stops if this reaches 3.
void DoRun() override
Implementation to actually run this TestCase.
Ipv4AddressHelper m_ipv4AddressHelper
Assigns IPv4 addresses to the nodes.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
uint32_t m_mtuSize
Maximum transmission unit (in bytes).
void ServerRxCallback(Ptr< const Packet > packet, const Address &from)
Connected with Rx trace source of the server.
void ClientRxMainObjectPacketCallback(Ptr< const Packet > packet)
Connected with RxMainObjectPacket trace source of the client.
void ClientRxMainObjectCallback(Ptr< const ThreeGppHttpClient > httpClient, Ptr< const Packet > packet)
Connected with RxMainObject trace source of the client.
void ClientRxEmbeddedObjectPacketCallback(Ptr< const Packet > packet)
Connected with RxEmbeddedObjectPacket trace source of the client.
Ptr< Node > CreateSimpleInternetNode(Ptr< SimpleChannel > channel, Address &assignedAddress)
Creates a Node, complete with a TCP/IP stack and address assignment.
Ptr< MinMaxAvgTotalCalculator< double > > m_rttCalculator
Keeps statistical information of round-trip delays (in seconds).
void ClientStateTransitionCallback(const std::string &oldState, const std::string &newState)
Connected with StateTransition trace source of the client.
ThreeGppHttpObjectTracker m_requestObjectTracker
Tracker of request objects.
Time m_channelDelay
Time needed by a packet to propagate.
uint32_t m_rngRun
Determines the set of random values generated.
void ServerEmbeddedObjectCallback(uint32_t size)
Connected with EmbeddedObject trace source of the server.
uint16_t m_numOfPacketDrops
Number of packets dropped because of m_errorModel.
Ipv6AddressHelper m_ipv6AddressHelper
Assigns IPv6 addresses to the nodes.
Ptr< MinMaxAvgTotalCalculator< double > > m_delayCalculator
Keeps statistical information of one-trip delays (in seconds).
void ClientRxRttCallback(const Time &rtt, const Address &from)
Connected with RxRtt trace source of the client.
bool m_useIpv6
Whether to use IPv6 or IPv4.
Ptr< RateErrorModel > m_errorModel
Receive error model to be attached to the devices of both directions.
void ServerMainObjectCallback(uint32_t size)
Connected with MainObject trace source of the server.
ThreeGppHttpObjectTracker m_mainObjectTracker
Tracker of main objects.
a polymophic address class
Definition address.h:90
holds a vector of ns3::Application pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
uint32_t GetN() const
Get the number of Ptr<Application> stored in this container.
ApplicationContainer Install(NodeContainer c)
Install an application on each node of the input container configured with all the attributes set wit...
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
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.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
a class to represent an Ipv4 address mask
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.
Keep track of a set of IPv6 interfaces.
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
Describes an IPv6 prefix.
static Mac48Address Allocate()
Allocate a new Mac48Address.
holds a vector of ns3::NetDevice pointers
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
TCP socket creation and multiplexing/demultiplexing.
static TypeId GetTypeId()
Get the type ID.
encapsulates test code
Definition test.h:1050
Duration
How long the test takes to execute.
Definition test.h:1054
std::string GetName() const
Definition test.cc:367
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Helper to make it easier to instantiate an ThreeGppHttpClient on a set of nodes.
Model application which simulates the traffic of a web browser.
Header used by web browsing applications to transmit information about content type,...
@ EMBEDDED_OBJECT
Integer equivalent = 2.
@ MAIN_OBJECT
Integer equivalent = 1.
ContentType_t GetContentType() const
Helper to make it easier to instantiate an ThreeGppHttpServer on a set of nodes.
Model application which simulates the traffic of a web server.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
bool IsPositive() const
Exactly equivalent to t >= 0.
Definition nstime.h:322
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:404
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
@ MS
millisecond
Definition nstime.h:106
@ S
second
Definition nstime.h:105
a unique identifier for an interface.
Definition type-id.h:48
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
void SetGlobal(std::string name, const AttributeValue &value)
Definition config.cc:929
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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.
Definition test.h:134
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition test.h:241
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
Definition test.h:554
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
Definition test.h:864
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
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...
Definition callback.h:684
static ThreeGppHttpClientServerTestSuite g_httpClientServerTestSuiteInstance
The global instance of the three-gpp-http-client-server system test.