Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2013 Magister Solutions | 3 * Copyright (c) 2013 Magister Solutions |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 | 58 |
59 | 59 |
60 // static | 60 // static |
61 TypeId | 61 TypeId |
62 ThreeGppHttpClient::GetTypeId () | 62 ThreeGppHttpClient::GetTypeId () |
63 { | 63 { |
64 static TypeId tid = TypeId ("ns3::ThreeGppHttpClient") | 64 static TypeId tid = TypeId ("ns3::ThreeGppHttpClient") |
65 .SetParent<Application> () | 65 .SetParent<Application> () |
66 .AddConstructor<ThreeGppHttpClient> () | 66 .AddConstructor<ThreeGppHttpClient> () |
67 .AddAttribute ("Variables", | 67 .AddAttribute ("Variables", |
68 "Pointer to random number generator.", | 68 "Variable collection, which is used to control e.g. timing an d HTTP request size.", |
69 PointerValue (), | 69 PointerValue (), |
70 MakePointerAccessor (&ThreeGppHttpClient::m_httpVariables), | 70 MakePointerAccessor (&ThreeGppHttpClient::m_httpVariables), |
71 MakePointerChecker<ThreeGppHttpVariables> ()) | 71 MakePointerChecker<ThreeGppHttpVariables> ()) |
72 .AddAttribute ("RemoteServerAddress", | 72 .AddAttribute ("RemoteServerAddress", |
73 "The address of the destination server.", | 73 "The address of the destination server.", |
74 AddressValue (), | 74 AddressValue (), |
75 MakeAddressAccessor (&ThreeGppHttpClient::m_remoteServerAddre ss), | 75 MakeAddressAccessor (&ThreeGppHttpClient::m_remoteServerAddre ss), |
76 MakeAddressChecker ()) | 76 MakeAddressChecker ()) |
77 .AddAttribute ("RemoteServerPort", | 77 .AddAttribute ("RemoteServerPort", |
78 "The destination port of the outbound packets.", | 78 "The destination port of the outbound packets.", |
79 UintegerValue (80), // the default HTTP port | 79 UintegerValue (80), // the default HTTP port |
80 MakeUintegerAccessor (&ThreeGppHttpClient::m_remoteServerPort ), | 80 MakeUintegerAccessor (&ThreeGppHttpClient::m_remoteServerPort ), |
81 MakeUintegerChecker<uint16_t> ()) | 81 MakeUintegerChecker<uint16_t> ()) |
82 .AddTraceSource ("ConnectionEstablished", | 82 .AddTraceSource ("ConnectionEstablished", |
83 "Connection to the destination web server has been establis hed.", | 83 "Connection to the destination web server has been establis hed.", |
84 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_connectionE stablishedTrace), | 84 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_connectionE stablishedTrace), |
85 "ns3::HttpClient::TracedCallback") | 85 "ns3::ThreeGppHttpClient::TracedCallback") |
86 .AddTraceSource ("ConnectionClosed", | 86 .AddTraceSource ("ConnectionClosed", |
87 "Connection to the destination web server is closed.", | 87 "Connection to the destination web server is closed.", |
88 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_connectionC losedTrace), | 88 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_connectionC losedTrace), |
89 "ns3::HttpClient::TracedCallback") | 89 "ns3::ThreeGppHttpClient::TracedCallback") |
90 .AddTraceSource ("Tx", | |
91 "General trace for sending a packet of any kind.", | |
92 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_txTrace), | |
93 "ns3::Packet::TracedCallback") | |
90 .AddTraceSource ("TxMainObjectRequest", | 94 .AddTraceSource ("TxMainObjectRequest", |
91 "Sent a request for a main object.", | 95 "Sent a request for a main object.", |
92 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_txMainObjec tRequestTrace), | 96 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_txMainObjec tRequestTrace), |
93 "ns3::Packet::TracedCallback") | 97 "ns3::Packet::TracedCallback") |
94 .AddTraceSource ("TxEmbeddedObjectRequest", | 98 .AddTraceSource ("TxEmbeddedObjectRequest", |
95 "Sent a request for an embedded object.", | 99 "Sent a request for an embedded object.", |
96 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_txEmbeddedO bjectRequestTrace), | 100 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_txEmbeddedO bjectRequestTrace), |
97 "ns3::Packet::TracedCallback") | 101 "ns3::Packet::TracedCallback") |
98 .AddTraceSource ("RxMainObjectPacket", | 102 .AddTraceSource ("RxMainObjectPacket", |
99 "A packet of main object has been received.", | 103 "A packet of main object has been received.", |
100 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_rxMainObjec tPacketTrace), | 104 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_rxMainObjec tPacketTrace), |
101 "ns3::Packet::TracedCallback") | 105 "ns3::Packet::TracedCallback") |
102 .AddTraceSource ("RxMainObject", | 106 .AddTraceSource ("RxMainObject", |
103 "Received a whole main object.", | 107 "Received a whole main object. Header is included.", |
104 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_rxMainObjec tTrace), | 108 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_rxMainObjec tTrace), |
105 "ns3::HttpClient::TracedCallback") | 109 "ns3::ThreeGppHttpClient::TracedCallback") |
106 .AddTraceSource ("RxEmbeddedObjectPacket", | 110 .AddTraceSource ("RxEmbeddedObjectPacket", |
107 "A packet of embedded object has been received.", | 111 "A packet of embedded object has been received.", |
108 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_rxEmbeddedO bjectPacketTrace), | 112 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_rxEmbeddedO bjectPacketTrace), |
109 "ns3::Packet::TracedCallback") | 113 "ns3::Packet::TracedCallback") |
110 .AddTraceSource ("RxEmbeddedObject", | 114 .AddTraceSource ("RxEmbeddedObject", |
111 "Received a whole embedded object.", | 115 "Received a whole embedded object. Header is included.", |
112 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_rxEmbeddedO bjectTrace), | 116 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_rxEmbeddedO bjectTrace), |
113 "ns3::HttpClient::TracedCallback") | 117 "ns3::ThreeGppHttpClient::TracedCallback") |
114 .AddTraceSource ("Rx", | 118 .AddTraceSource ("Rx", |
115 "General trace for receiving a packet of any kind.", | 119 "General trace for receiving a packet of any kind.", |
116 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_rxTrace), | 120 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_rxTrace), |
117 "ns3::Packet::PacketAddressTracedCallback") | 121 "ns3::Packet::PacketAddressTracedCallback") |
118 .AddTraceSource ("RxDelay", | 122 .AddTraceSource ("RxDelay", |
119 "General trace of delay for receiving a complete object.", | 123 "General trace of delay for receiving a complete object.", |
120 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_rxDelayTrac e), | 124 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_rxDelayTrac e), |
121 "ns3::Application::PacketDelayAddressCallback") | 125 "ns3::Application::PacketDelayAddressCallback") |
Tommaso Pecorella
2018/02/11 04:22:06
This doesn't exist. You renamed it "DelayAddressCa
| |
122 .AddTraceSource ("RxRtt", | 126 .AddTraceSource ("RxRtt", |
123 "General trace of round trip delay time for receiving a com plete object.", | 127 "General trace of round trip delay time for receiving a com plete object.", |
124 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_rxRttTrace) , | 128 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_rxRttTrace) , |
125 "ns3::Application::PacketDelayAddressCallback") | 129 "ns3::Application::PacketDelayAddressCallback") |
Tommaso Pecorella
2018/02/11 04:22:06
This doesn't exist. You renamed it "DelayAddressCa
| |
126 .AddTraceSource ("StateTransition", | 130 .AddTraceSource ("StateTransition", |
127 "Trace fired upon every HTTP client state transition.", | 131 "Trace fired upon every HTTP client state transition.", |
128 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_stateTransi tionTrace), | 132 MakeTraceSourceAccessor (&ThreeGppHttpClient::m_stateTransi tionTrace), |
129 "ns3::Application::StateTransitionCallback") | 133 "ns3::Application::StateTransitionCallback") |
130 ; | 134 ; |
131 return tid; | 135 return tid; |
132 } | 136 } |
133 | 137 |
134 | 138 |
135 Ptr<Socket> | 139 Ptr<Socket> |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 return "EXPECTING_EMBEDDED_OBJECT"; | 178 return "EXPECTING_EMBEDDED_OBJECT"; |
175 break; | 179 break; |
176 case READING: | 180 case READING: |
177 return "READING"; | 181 return "READING"; |
178 break; | 182 break; |
179 case STOPPED: | 183 case STOPPED: |
180 return "STOPPED"; | 184 return "STOPPED"; |
181 break; | 185 break; |
182 default: | 186 default: |
183 NS_FATAL_ERROR ("Unknown state"); | 187 NS_FATAL_ERROR ("Unknown state"); |
188 return "FATAL_ERROR"; | |
184 break; | 189 break; |
185 } | 190 } |
186 } | 191 } |
187 | 192 |
188 | 193 |
189 void | 194 void |
190 ThreeGppHttpClient::DoDispose () | 195 ThreeGppHttpClient::DoDispose () |
191 { | 196 { |
192 NS_LOG_FUNCTION (this); | 197 NS_LOG_FUNCTION (this); |
193 | 198 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 } | 259 } |
255 | 260 |
256 | 261 |
257 void | 262 void |
258 ThreeGppHttpClient::ConnectionFailedCallback (Ptr<Socket> socket) | 263 ThreeGppHttpClient::ConnectionFailedCallback (Ptr<Socket> socket) |
259 { | 264 { |
260 NS_LOG_FUNCTION (this << socket); | 265 NS_LOG_FUNCTION (this << socket); |
261 | 266 |
262 if (m_state == CONNECTING) | 267 if (m_state == CONNECTING) |
263 { | 268 { |
264 NS_FATAL_ERROR ("Client failed to connect" | 269 NS_FATAL_ERROR ("Client failed to connect" |
Tommaso Pecorella
2018/02/11 04:22:05
This shouldn't really abort the simulation. A fail
| |
265 << " to remote address " << m_remoteServerAddress | 270 << " to remote address " << m_remoteServerAddress |
266 << " port " << m_remoteServerPort << "."); | 271 << " port " << m_remoteServerPort << "."); |
267 } | 272 } |
268 else | 273 else |
269 { | 274 { |
270 NS_FATAL_ERROR ("Invalid state " << GetStateString () | 275 NS_FATAL_ERROR ("Invalid state " << GetStateString () |
271 << " for ConnectionFailed()."); | 276 << " for ConnectionFailed()."); |
272 } | 277 } |
273 } | 278 } |
274 | 279 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 } // end of `void OpenConnection ()` | 441 } // end of `void OpenConnection ()` |
437 | 442 |
438 | 443 |
439 void | 444 void |
440 ThreeGppHttpClient::RequestMainObject () | 445 ThreeGppHttpClient::RequestMainObject () |
441 { | 446 { |
442 NS_LOG_FUNCTION (this); | 447 NS_LOG_FUNCTION (this); |
443 | 448 |
444 if (m_state == CONNECTING || m_state == READING) | 449 if (m_state == CONNECTING || m_state == READING) |
445 { | 450 { |
446 ThreeGppHttpTag tag; | 451 ThreeGppHttpHeader header; |
447 tag.SetContentLength (0); // Request does not need any content length. | 452 header.SetContentLength (0); // Request does not need any content length. |
448 tag.SetContentType (ThreeGppHttpTag::MAIN_OBJECT); | 453 header.SetContentType (ThreeGppHttpHeader::MAIN_OBJECT); |
449 tag.SetClientTs (Simulator::Now ()); | 454 header.SetClientTs (Simulator::Now ()); |
450 | 455 |
451 const uint32_t requestSize = m_httpVariables->GetRequestSize (); | 456 const uint32_t requestSize = m_httpVariables->GetRequestSize (); |
452 Ptr<Packet> packet = Create<Packet> (requestSize); | 457 Ptr<Packet> packet = Create<Packet> (requestSize); |
453 packet->AddByteTag (tag); | 458 packet->AddHeader (header); |
454 const uint32_t packetSize = packet->GetSize (); | 459 const uint32_t packetSize = packet->GetSize (); |
455 NS_ASSERT_MSG (packetSize <= 536, // Hard-coded MTU size. | 460 NS_ASSERT_MSG (packetSize <= 536, // Hard-coded MTU size. |
Tommaso Pecorella
2018/02/11 04:22:05
Why this limitation ?
| |
456 "Packet size shall not be larger than MTU size."); | 461 "Packet size shall not be larger than MTU size."); |
457 | 462 |
458 m_txMainObjectRequestTrace (packet); | 463 m_txMainObjectRequestTrace (packet); |
464 m_txTrace (packet); | |
459 const int actualBytes = m_socket->Send (packet); | 465 const int actualBytes = m_socket->Send (packet); |
460 NS_LOG_DEBUG (this << " Send() packet " << packet | 466 NS_LOG_DEBUG (this << " Send() packet " << packet |
461 << " of " << packet->GetSize () << " bytes," | 467 << " of " << packet->GetSize () << " bytes," |
462 << " return value= " << actualBytes << "."); | 468 << " return value= " << actualBytes << "."); |
463 if (actualBytes != static_cast<int> (packetSize)) | 469 if (actualBytes != static_cast<int> (packetSize)) |
464 { | 470 { |
465 NS_LOG_ERROR (this << " Failed to send request for embedded object," | 471 NS_LOG_ERROR (this << " Failed to send request for embedded object," |
466 << " GetErrNo= " << m_socket->GetErrno () << "," | 472 << " GetErrNo= " << m_socket->GetErrno () << "," |
467 << " waiting for another Tx opportunity."); | 473 << " waiting for another Tx opportunity."); |
468 } | 474 } |
(...skipping 14 matching lines...) Expand all Loading... | |
483 void | 489 void |
484 ThreeGppHttpClient::RequestEmbeddedObject () | 490 ThreeGppHttpClient::RequestEmbeddedObject () |
485 { | 491 { |
486 NS_LOG_FUNCTION (this); | 492 NS_LOG_FUNCTION (this); |
487 | 493 |
488 if (m_state == CONNECTING || m_state == PARSING_MAIN_OBJECT | 494 if (m_state == CONNECTING || m_state == PARSING_MAIN_OBJECT |
489 || m_state == EXPECTING_EMBEDDED_OBJECT) | 495 || m_state == EXPECTING_EMBEDDED_OBJECT) |
490 { | 496 { |
491 if (m_embeddedObjectsToBeRequested > 0) | 497 if (m_embeddedObjectsToBeRequested > 0) |
492 { | 498 { |
493 ThreeGppHttpTag tag; | 499 ThreeGppHttpHeader header; |
494 tag.SetContentLength (0); // Request does not need any content length. | 500 header.SetContentLength (0); // Request does not need any content leng th. |
495 tag.SetContentType (ThreeGppHttpTag::EMBEDDED_OBJECT); | 501 header.SetContentType (ThreeGppHttpHeader::EMBEDDED_OBJECT); |
496 tag.SetClientTs (Simulator::Now ()); | 502 header.SetClientTs (Simulator::Now ()); |
497 | 503 |
498 const uint32_t requestSize = m_httpVariables->GetRequestSize (); | 504 const uint32_t requestSize = m_httpVariables->GetRequestSize (); |
499 Ptr<Packet> packet = Create<Packet> (requestSize); | 505 Ptr<Packet> packet = Create<Packet> (requestSize); |
500 packet->AddByteTag (tag); | 506 packet->AddHeader (header); |
501 const uint32_t packetSize = packet->GetSize (); | 507 const uint32_t packetSize = packet->GetSize (); |
502 NS_ASSERT_MSG (packetSize <= 536, // Hard-coded MTU size. | 508 NS_ASSERT_MSG (packetSize <= 536, // Hard-coded MTU size. |
Tommaso Pecorella
2018/02/11 04:22:05
Same comment as before.
| |
503 "Packet size shall not be larger than MTU size."); | 509 "Packet size shall not be larger than MTU size."); |
504 | 510 |
505 m_txEmbeddedObjectRequestTrace (packet); | 511 m_txEmbeddedObjectRequestTrace (packet); |
512 m_txTrace (packet); | |
506 const int actualBytes = m_socket->Send (packet); | 513 const int actualBytes = m_socket->Send (packet); |
507 NS_LOG_DEBUG (this << " Send() packet " << packet | 514 NS_LOG_DEBUG (this << " Send() packet " << packet |
508 << " of " << packet->GetSize () << " bytes," | 515 << " of " << packet->GetSize () << " bytes," |
509 << " return value= " << actualBytes << "."); | 516 << " return value= " << actualBytes << "."); |
510 | 517 |
511 if (actualBytes != static_cast<int> (packetSize)) | 518 if (actualBytes != static_cast<int> (packetSize)) |
512 { | 519 { |
513 NS_LOG_ERROR (this << " Failed to send request for embedded object ," | 520 NS_LOG_ERROR (this << " Failed to send request for embedded object ," |
514 << " GetErrNo= " << m_socket->GetErrno () << ", " | 521 << " GetErrNo= " << m_socket->GetErrno () << ", " |
515 << " waiting for another Tx opportunity."); | 522 << " waiting for another Tx opportunity."); |
(...skipping 21 matching lines...) Expand all Loading... | |
537 void | 544 void |
538 ThreeGppHttpClient::ReceiveMainObject (Ptr<Packet> packet, const Address &from) | 545 ThreeGppHttpClient::ReceiveMainObject (Ptr<Packet> packet, const Address &from) |
539 { | 546 { |
540 NS_LOG_FUNCTION (this << packet << from); | 547 NS_LOG_FUNCTION (this << packet << from); |
541 | 548 |
542 if (m_state == EXPECTING_MAIN_OBJECT) | 549 if (m_state == EXPECTING_MAIN_OBJECT) |
543 { | 550 { |
544 /* | 551 /* |
545 * In the following call to Receive(), #m_objectBytesToBeReceived *will* | 552 * In the following call to Receive(), #m_objectBytesToBeReceived *will* |
546 * be updated. #m_objectClientTs and #m_objectServerTs *may* be updated. | 553 * be updated. #m_objectClientTs and #m_objectServerTs *may* be updated. |
554 * ThreeGppHttpHeader will be removed from the packet, if it is the first | |
555 * packet of the object to be received; the header will be available in | |
556 * #m_constructedPacketHeader. | |
557 * #m_constructedPacket will also be updated. | |
547 */ | 558 */ |
548 Receive (packet); | 559 Receive (packet); |
549 m_rxMainObjectPacketTrace (packet); | 560 m_rxMainObjectPacketTrace (packet); |
550 | 561 |
551 if (m_objectBytesToBeReceived > 0) | 562 if (m_objectBytesToBeReceived > 0) |
552 { | 563 { |
553 /* | 564 /* |
554 * There are more packets of this main object, so just stay still | 565 * There are more packets of this main object, so just stay still |
555 * and wait until they arrive. | 566 * and wait until they arrive. |
556 */ | 567 */ |
557 NS_LOG_INFO (this << " " << m_objectBytesToBeReceived << " byte(s)" | 568 NS_LOG_INFO (this << " " << m_objectBytesToBeReceived << " byte(s)" |
558 << " remains from this chunk of main object."); | 569 << " remains from this chunk of main object."); |
559 } | 570 } |
560 else | 571 else |
561 { | 572 { |
562 /* | 573 /* |
563 * This is the last packet of this main object. Acknowledge the | 574 * This is the last packet of this main object. Acknowledge the |
564 * reception of a whole main object | 575 * reception of a whole main object |
565 */ | 576 */ |
566 NS_LOG_INFO (this << " Finished receiving a main object."); | 577 NS_LOG_INFO (this << " Finished receiving a main object."); |
567 m_rxMainObjectTrace (this); | 578 m_rxMainObjectTrace (this, m_constructedPacket); |
568 | 579 |
569 if (!m_objectServerTs.IsZero ()) | 580 if (!m_objectServerTs.IsZero ()) |
570 { | 581 { |
571 m_rxDelayTrace (Simulator::Now () - m_objectServerTs, from); | 582 m_rxDelayTrace (Simulator::Now () - m_objectServerTs, from); |
572 m_objectServerTs = MilliSeconds (0); // Reset back to zero. | 583 m_objectServerTs = MilliSeconds (0); // Reset back to zero. |
573 } | 584 } |
574 | 585 |
575 if (!m_objectClientTs.IsZero ()) | 586 if (!m_objectClientTs.IsZero ()) |
576 { | 587 { |
577 m_rxRttTrace (Simulator::Now () - m_objectClientTs, from); | 588 m_rxRttTrace (Simulator::Now () - m_objectClientTs, from); |
(...skipping 17 matching lines...) Expand all Loading... | |
595 void | 606 void |
596 ThreeGppHttpClient::ReceiveEmbeddedObject (Ptr<Packet> packet, const Address &fr om) | 607 ThreeGppHttpClient::ReceiveEmbeddedObject (Ptr<Packet> packet, const Address &fr om) |
597 { | 608 { |
598 NS_LOG_FUNCTION (this << packet << from); | 609 NS_LOG_FUNCTION (this << packet << from); |
599 | 610 |
600 if (m_state == EXPECTING_EMBEDDED_OBJECT) | 611 if (m_state == EXPECTING_EMBEDDED_OBJECT) |
601 { | 612 { |
602 /* | 613 /* |
603 * In the following call to Receive(), #m_objectBytesToBeReceived *will* | 614 * In the following call to Receive(), #m_objectBytesToBeReceived *will* |
604 * be updated. #m_objectClientTs and #m_objectServerTs *may* be updated. | 615 * be updated. #m_objectClientTs and #m_objectServerTs *may* be updated. |
616 * ThreeGppHttpHeader will be removed from the packet, if it is the first | |
617 * packet of the object to be received; the header will be available in | |
618 * #m_constructedPacket, which will also be updated. | |
605 */ | 619 */ |
606 Receive (packet); | 620 Receive (packet); |
607 m_rxEmbeddedObjectPacketTrace (packet); | 621 m_rxEmbeddedObjectPacketTrace (packet); |
608 | 622 |
609 if (m_objectBytesToBeReceived > 0) | 623 if (m_objectBytesToBeReceived > 0) |
610 { | 624 { |
611 /* | 625 /* |
612 * There are more packets of this embedded object, so just stay | 626 * There are more packets of this embedded object, so just stay |
613 * still and wait until they arrive. | 627 * still and wait until they arrive. |
614 */ | 628 */ |
615 NS_LOG_INFO (this << " " << m_objectBytesToBeReceived << " byte(s)" | 629 NS_LOG_INFO (this << " " << m_objectBytesToBeReceived << " byte(s)" |
616 << " remains from this chunk of embedded object"); | 630 << " remains from this chunk of embedded object"); |
617 } | 631 } |
618 else | 632 else |
619 { | 633 { |
620 /* | 634 /* |
621 * This is the last packet of this embedded object. Acknowledge | 635 * This is the last packet of this embedded object. Acknowledge |
622 * the reception of a whole embedded object | 636 * the reception of a whole embedded object |
623 */ | 637 */ |
624 NS_LOG_INFO (this << " Finished receiving an embedded object."); | 638 NS_LOG_INFO (this << " Finished receiving an embedded object."); |
625 m_rxEmbeddedObjectTrace (this); | 639 m_rxEmbeddedObjectTrace (this, m_constructedPacket); |
626 | 640 |
627 if (!m_objectServerTs.IsZero ()) | 641 if (!m_objectServerTs.IsZero ()) |
628 { | 642 { |
629 m_rxDelayTrace (Simulator::Now () - m_objectServerTs, from); | 643 m_rxDelayTrace (Simulator::Now () - m_objectServerTs, from); |
630 m_objectServerTs = MilliSeconds (0); // Reset back to zero. | 644 m_objectServerTs = MilliSeconds (0); // Reset back to zero. |
631 } | 645 } |
632 | 646 |
633 if (!m_objectClientTs.IsZero ()) | 647 if (!m_objectClientTs.IsZero ()) |
634 { | 648 { |
635 m_rxRttTrace (Simulator::Now () - m_objectClientTs, from); | 649 m_rxRttTrace (Simulator::Now () - m_objectClientTs, from); |
(...skipping 28 matching lines...) Expand all Loading... | |
664 } | 678 } |
665 | 679 |
666 } // end of `void ReceiveEmbeddedObject (Ptr<Packet> packet)` | 680 } // end of `void ReceiveEmbeddedObject (Ptr<Packet> packet)` |
667 | 681 |
668 | 682 |
669 void | 683 void |
670 ThreeGppHttpClient::Receive (Ptr<Packet> packet) | 684 ThreeGppHttpClient::Receive (Ptr<Packet> packet) |
671 { | 685 { |
672 NS_LOG_FUNCTION (this << packet); | 686 NS_LOG_FUNCTION (this << packet); |
673 | 687 |
674 // This will stop the simulation if ThreeGppHttpTag is not found in the packet . | 688 /* In a "real" HTTP message the message size is coded differently. The use of a header |
675 ThreeGppHttpTag httpTag = ThreeGppHttpTag::ReadTagFromPacket (packet); | |
676 | |
677 /* In a "real" HTTP message the message size is coded differently. The use of a tag | |
678 * is to avoid the burden of doing a real message parser. | 689 * is to avoid the burden of doing a real message parser. |
679 */ | 690 */ |
691 bool firstPacket = false; | |
680 | 692 |
681 if (m_objectBytesToBeReceived == 0) | 693 if (m_objectBytesToBeReceived == 0) |
682 { | 694 { |
683 // This is the first packet of the object. | 695 // This is the first packet of the object. |
684 m_objectBytesToBeReceived = httpTag.GetContentLength (); | 696 firstPacket = true; |
685 m_objectClientTs = httpTag.GetClientTs (); | 697 |
686 m_objectServerTs = httpTag.GetServerTs (); | 698 // Remove the header in order to calculate remaining data to be received. |
687 } | 699 ThreeGppHttpHeader httpHeader; |
688 | 700 packet->RemoveHeader (httpHeader); |
689 if (m_objectBytesToBeReceived < packet->GetSize ()) | 701 |
702 m_objectBytesToBeReceived = httpHeader.GetContentLength (); | |
703 m_objectClientTs = httpHeader.GetClientTs (); | |
704 m_objectServerTs = httpHeader.GetServerTs (); | |
705 | |
706 // Take a copy for constructed packet trace. Note that header is included. | |
707 m_constructedPacket = packet->Copy (); | |
708 m_constructedPacket->AddHeader (httpHeader); | |
709 } | |
710 uint32_t contentSize = packet->GetSize (); | |
711 | |
712 /* Note that the packet does not contain header at this point. | |
713 * The content is purely raw data, which was the only intended data to be rece ived. | |
714 */ | |
715 if (m_objectBytesToBeReceived < contentSize) | |
690 { | 716 { |
691 NS_LOG_WARN (this << " The received packet" | 717 NS_LOG_WARN (this << " The received packet" |
692 << " (" << packet->GetSize () << " bytes of content)" | 718 << " (" << contentSize << " bytes of content)" |
693 << " is larger than" | 719 << " is larger than" |
694 << " the content that we expected to receive" | 720 << " the content that we expected to receive" |
695 << " (" << m_objectBytesToBeReceived << " bytes)."); | 721 << " (" << m_objectBytesToBeReceived << " bytes)."); |
696 // Stop expecting any more packet of this object. | 722 // Stop expecting any more packet of this object. |
697 m_objectBytesToBeReceived = 0; | 723 m_objectBytesToBeReceived = 0; |
698 } | 724 m_constructedPacket = NULL; |
699 else | 725 } |
700 { | 726 else |
701 m_objectBytesToBeReceived -= packet->GetSize (); | 727 { |
728 m_objectBytesToBeReceived -= contentSize; | |
729 if (!firstPacket) | |
730 { | |
731 Ptr<Packet> packetCopy = packet->Copy (); | |
732 m_constructedPacket->AddAtEnd (packetCopy); | |
733 } | |
702 } | 734 } |
703 | 735 |
704 } // end of `void Receive (packet)` | 736 } // end of `void Receive (packet)` |
705 | 737 |
706 | 738 |
707 void | 739 void |
708 ThreeGppHttpClient::EnterParsingTime () | 740 ThreeGppHttpClient::EnterParsingTime () |
709 { | 741 { |
710 NS_LOG_FUNCTION (this); | 742 NS_LOG_FUNCTION (this); |
711 | 743 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
843 | 875 |
844 m_state = state; | 876 m_state = state; |
845 NS_LOG_INFO (this << " HttpClient " << oldState | 877 NS_LOG_INFO (this << " HttpClient " << oldState |
846 << " --> " << newState << "."); | 878 << " --> " << newState << "."); |
847 m_stateTransitionTrace (oldState, newState); | 879 m_stateTransitionTrace (oldState, newState); |
848 } | 880 } |
849 | 881 |
850 | 882 |
851 } // end of `namespace ns3` | 883 } // end of `namespace ns3` |
852 | 884 |
LEFT | RIGHT |