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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 | 65 |
66 // static | 66 // static |
67 TypeId | 67 TypeId |
68 ThreeGppHttpServer::GetTypeId () | 68 ThreeGppHttpServer::GetTypeId () |
69 { | 69 { |
70 static TypeId tid = TypeId ("ns3::ThreeGppHttpServer") | 70 static TypeId tid = TypeId ("ns3::ThreeGppHttpServer") |
71 .SetParent<Application> () | 71 .SetParent<Application> () |
72 .AddConstructor<ThreeGppHttpServer> () | 72 .AddConstructor<ThreeGppHttpServer> () |
73 .AddAttribute ("Variables", | 73 .AddAttribute ("Variables", |
74 "Pointer to random number generator.", | 74 "Variable collection, which is used to control e.g. processin
g and " |
| 75 "object generation delays.", |
75 PointerValue (), | 76 PointerValue (), |
76 MakePointerAccessor (&ThreeGppHttpServer::m_httpVariables), | 77 MakePointerAccessor (&ThreeGppHttpServer::m_httpVariables), |
77 MakePointerChecker<ThreeGppHttpVariables> ()) | 78 MakePointerChecker<ThreeGppHttpVariables> ()) |
78 .AddAttribute ("LocalAddress", | 79 .AddAttribute ("LocalAddress", |
79 "The local address of the server, " | 80 "The local address of the server, " |
80 "i.e., the address on which to bind the Rx socket.", | 81 "i.e., the address on which to bind the Rx socket.", |
81 AddressValue (), | 82 AddressValue (), |
82 MakeAddressAccessor (&ThreeGppHttpServer::m_localAddress), | 83 MakeAddressAccessor (&ThreeGppHttpServer::m_localAddress), |
83 MakeAddressChecker ()) | 84 MakeAddressChecker ()) |
84 .AddAttribute ("LocalPort", | 85 .AddAttribute ("LocalPort", |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return "NOT_STARTED"; | 169 return "NOT_STARTED"; |
169 break; | 170 break; |
170 case STARTED: | 171 case STARTED: |
171 return "STARTED"; | 172 return "STARTED"; |
172 break; | 173 break; |
173 case STOPPED: | 174 case STOPPED: |
174 return "STOPPED"; | 175 return "STOPPED"; |
175 break; | 176 break; |
176 default: | 177 default: |
177 NS_FATAL_ERROR ("Unknown state"); | 178 NS_FATAL_ERROR ("Unknown state"); |
| 179 return "FATAL_ERROR"; |
178 break; | 180 break; |
179 } | 181 } |
180 } | 182 } |
181 | 183 |
182 | 184 |
183 void | 185 void |
184 ThreeGppHttpServer::DoDispose () | 186 ThreeGppHttpServer::DoDispose () |
185 { | 187 { |
186 NS_LOG_FUNCTION (this); | 188 NS_LOG_FUNCTION (this); |
187 | 189 |
(...skipping 22 matching lines...) Expand all Loading... |
210 { | 212 { |
211 struct TypeId::AttributeInformation attrInfo = tcpSocketTid.GetAtt
ribute (i); | 213 struct TypeId::AttributeInformation attrInfo = tcpSocketTid.GetAtt
ribute (i); |
212 if (attrInfo.name == "SegmentSize") | 214 if (attrInfo.name == "SegmentSize") |
213 { | 215 { |
214 previousSocketMtu = attrInfo.initialValue; | 216 previousSocketMtu = attrInfo.initialValue; |
215 } | 217 } |
216 } | 218 } |
217 | 219 |
218 // Change the default MTU value for all TCP sockets. | 220 // Change the default MTU value for all TCP sockets. |
219 Config::SetDefault ("ns3::TcpSocket::SegmentSize", | 221 Config::SetDefault ("ns3::TcpSocket::SegmentSize", |
220 UintegerValue (m_mtuSize)); | 222 UintegerValue (m_mtuSize)); |
221 | 223 |
222 // Creating a TCP socket to connect to the server. | 224 // Creating a TCP socket to connect to the server. |
223 m_initialSocket = Socket::CreateSocket (GetNode (), | 225 m_initialSocket = Socket::CreateSocket (GetNode (), |
224 TcpSocketFactory::GetTypeId ()
); | 226 TcpSocketFactory::GetTypeId ()
); |
225 Config::SetDefault ("ns3::TcpSocket::SegmentSize", | 227 Config::SetDefault ("ns3::TcpSocket::SegmentSize", |
226 *previousSocketMtu); // Reset it back. | 228 *previousSocketMtu); // Reset it back. |
227 | 229 |
228 int ret; | 230 int ret; |
229 | 231 |
230 if (Ipv4Address::IsMatchingType (m_localAddress)) | 232 if (Ipv4Address::IsMatchingType (m_localAddress)) |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 } | 438 } |
437 else if (Inet6SocketAddress::IsMatchingType (from)) | 439 else if (Inet6SocketAddress::IsMatchingType (from)) |
438 { | 440 { |
439 NS_LOG_INFO (this << " A packet of " << packet->GetSize () << " bytes" | 441 NS_LOG_INFO (this << " A packet of " << packet->GetSize () << " bytes" |
440 << " received from " << Inet6SocketAddress::ConvertF
rom (from).GetIpv6 () | 442 << " received from " << Inet6SocketAddress::ConvertF
rom (from).GetIpv6 () |
441 << " port " << Inet6SocketAddress::ConvertFrom (from
).GetPort () | 443 << " port " << Inet6SocketAddress::ConvertFrom (from
).GetPort () |
442 << " / " << Inet6SocketAddress::ConvertFrom (from)); | 444 << " / " << Inet6SocketAddress::ConvertFrom (from)); |
443 } | 445 } |
444 #endif /* NS3_LOG_ENABLE */ | 446 #endif /* NS3_LOG_ENABLE */ |
445 | 447 |
446 // This will stop the simulation if ThreeGppHttpTag is not found in the pa
cket. | 448 // Check the header. No need to remove it, since it is not a "real" header
. |
447 ThreeGppHttpTag httpTag = ThreeGppHttpTag::ReadTagFromPacket (packet); | 449 ThreeGppHttpHeader httpHeader; |
| 450 packet->PeekHeader (httpHeader); |
448 | 451 |
449 // Fire trace sources. | 452 // Fire trace sources. |
450 m_rxTrace (packet, from); | 453 m_rxTrace (packet, from); |
451 m_rxDelayTrace (Simulator::Now () - httpTag.GetClientTs (), from); | 454 m_rxDelayTrace (Simulator::Now () - httpHeader.GetClientTs (), from); |
452 | 455 |
453 Time processingDelay; | 456 Time processingDelay; |
454 switch (httpTag.GetContentType ()) | 457 switch (httpHeader.GetContentType ()) |
455 { | 458 { |
456 case ThreeGppHttpTag::MAIN_OBJECT: | 459 case ThreeGppHttpHeader::MAIN_OBJECT: |
457 processingDelay = m_httpVariables->GetMainObjectGenerationDelay (); | 460 processingDelay = m_httpVariables->GetMainObjectGenerationDelay (); |
458 NS_LOG_INFO (this << " Will finish generating a main object" | 461 NS_LOG_INFO (this << " Will finish generating a main object" |
459 << " in " << processingDelay.GetSeconds () << " seco
nds."); | 462 << " in " << processingDelay.GetSeconds () << " seco
nds."); |
460 m_txBuffer->RecordNextServe (socket, | 463 m_txBuffer->RecordNextServe (socket, |
461 Simulator::Schedule (processingDelay, | 464 Simulator::Schedule (processingDelay, |
462 &ThreeGppHttpServer:
:ServeNewMainObject, | 465 &ThreeGppHttpServer:
:ServeNewMainObject, |
463 this, socket), | 466 this, socket), |
464 httpTag.GetClientTs ()); | 467 httpHeader.GetClientTs ()); |
465 break; | 468 break; |
466 | 469 |
467 case ThreeGppHttpTag::EMBEDDED_OBJECT: | 470 case ThreeGppHttpHeader::EMBEDDED_OBJECT: |
468 processingDelay = m_httpVariables->GetEmbeddedObjectGenerationDelay ()
; | 471 processingDelay = m_httpVariables->GetEmbeddedObjectGenerationDelay ()
; |
469 NS_LOG_INFO (this << " Will finish generating an embedded object" | 472 NS_LOG_INFO (this << " Will finish generating an embedded object" |
470 << " in " << processingDelay.GetSeconds () << " seco
nds."); | 473 << " in " << processingDelay.GetSeconds () << " seco
nds."); |
471 m_txBuffer->RecordNextServe (socket, | 474 m_txBuffer->RecordNextServe (socket, |
472 Simulator::Schedule (processingDelay, | 475 Simulator::Schedule (processingDelay, |
473 &ThreeGppHttpServer:
:ServeNewEmbeddedObject, | 476 &ThreeGppHttpServer:
:ServeNewEmbeddedObject, |
474 this, socket), | 477 this, socket), |
475 httpTag.GetClientTs ()); | 478 httpHeader.GetClientTs ()); |
476 break; | 479 break; |
477 | 480 |
478 default: | 481 default: |
479 NS_FATAL_ERROR ("Invalid packet."); | 482 NS_FATAL_ERROR ("Invalid packet."); |
480 break; | 483 break; |
481 } | 484 } |
482 | 485 |
483 } // end of `while ((packet = socket->RecvFrom (from)))` | 486 } // end of `while ((packet = socket->RecvFrom (from)))` |
484 | 487 |
485 } // end of `void ReceivedDataCallback (Ptr<Socket> socket)` | 488 } // end of `void ReceivedDataCallback (Ptr<Socket> socket)` |
486 | 489 |
487 | 490 |
488 void | 491 void |
489 ThreeGppHttpServer::SendCallback (Ptr<Socket> socket, uint32_t availableBufferSi
ze) | 492 ThreeGppHttpServer::SendCallback (Ptr<Socket> socket, uint32_t availableBufferSi
ze) |
490 { | 493 { |
491 NS_LOG_FUNCTION (this << socket << availableBufferSize); | 494 NS_LOG_FUNCTION (this << socket << availableBufferSize); |
492 | 495 |
493 if (!m_txBuffer->IsBufferEmpty (socket)) | 496 if (!m_txBuffer->IsBufferEmpty (socket)) |
494 { | 497 { |
495 const uint32_t txBufferSize = m_txBuffer->GetBufferSize (socket); | 498 const uint32_t txBufferSize = m_txBuffer->GetBufferSize (socket); |
496 const uint32_t actualSent = ServeFromTxBuffer (socket); | 499 const uint32_t actualSent = ServeFromTxBuffer (socket); |
497 | 500 |
498 #ifdef NS3_LOG_ENABLE | 501 #ifdef NS3_LOG_ENABLE |
499 // Some log messages. | 502 // Some log messages. |
500 if (actualSent < txBufferSize) | 503 if (actualSent < txBufferSize) |
501 { | 504 { |
502 switch (m_txBuffer->GetBufferContentType (socket)) | 505 switch (m_txBuffer->GetBufferContentType (socket)) |
503 { | 506 { |
504 case ThreeGppHttpTag::MAIN_OBJECT: | 507 case ThreeGppHttpHeader::MAIN_OBJECT: |
505 NS_LOG_INFO (this << " Transmission of main object is suspended" | 508 NS_LOG_INFO (this << " Transmission of main object is suspended" |
506 << " after " << actualSent << " bytes."); | 509 << " after " << actualSent << " bytes."); |
507 break; | 510 break; |
508 case ThreeGppHttpTag::EMBEDDED_OBJECT: | 511 case ThreeGppHttpHeader::EMBEDDED_OBJECT: |
509 NS_LOG_INFO (this << " Transmission of embedded object is suspende
d" | 512 NS_LOG_INFO (this << " Transmission of embedded object is suspende
d" |
510 << " after " << actualSent << " bytes."); | 513 << " after " << actualSent << " bytes."); |
511 break; | 514 break; |
512 default: | 515 default: |
513 NS_FATAL_ERROR ("Invalid Tx buffer content type."); | 516 NS_FATAL_ERROR ("Invalid Tx buffer content type."); |
514 break; | 517 break; |
515 } | 518 } |
516 } | 519 } |
517 else | 520 else |
518 { | 521 { |
519 switch (m_txBuffer->GetBufferContentType (socket)) | 522 switch (m_txBuffer->GetBufferContentType (socket)) |
520 { | 523 { |
521 case ThreeGppHttpTag::MAIN_OBJECT: | 524 case ThreeGppHttpHeader::MAIN_OBJECT: |
522 NS_LOG_INFO (this << " Finished sending a whole main object."); | 525 NS_LOG_INFO (this << " Finished sending a whole main object."); |
523 break; | 526 break; |
524 case ThreeGppHttpTag::EMBEDDED_OBJECT: | 527 case ThreeGppHttpHeader::EMBEDDED_OBJECT: |
525 NS_LOG_INFO (this << " Finished sending a whole embedded object.")
; | 528 NS_LOG_INFO (this << " Finished sending a whole embedded object.")
; |
526 break; | 529 break; |
527 default: | 530 default: |
528 NS_FATAL_ERROR ("Invalid Tx buffer content type."); | 531 NS_FATAL_ERROR ("Invalid Tx buffer content type."); |
529 break; | 532 break; |
530 } | 533 } |
531 } | 534 } |
532 #endif /* NS3_LOG_ENABLE */ | 535 #endif /* NS3_LOG_ENABLE */ |
533 | 536 |
534 // Mute compiler warnings. | 537 // Mute compiler warnings. |
535 NS_UNUSED (txBufferSize); | 538 NS_UNUSED (txBufferSize); |
536 NS_UNUSED (actualSent); | 539 NS_UNUSED (actualSent); |
537 | 540 |
538 } // end of `if (m_txBuffer->IsBufferEmpty (socket))` | 541 } // end of `if (m_txBuffer->IsBufferEmpty (socket))` |
539 | 542 |
540 } // end of `void SendCallback (Ptr<Socket> socket, uint32_t availableBufferSize
)` | 543 } // end of `void SendCallback (Ptr<Socket> socket, uint32_t availableBufferSize
)` |
541 | 544 |
542 | 545 |
543 void | 546 void |
544 ThreeGppHttpServer::ServeNewMainObject (Ptr<Socket> socket) | 547 ThreeGppHttpServer::ServeNewMainObject (Ptr<Socket> socket) |
545 { | 548 { |
546 NS_LOG_FUNCTION (this << socket); | 549 NS_LOG_FUNCTION (this << socket); |
547 | 550 |
548 const uint32_t objectSize = m_httpVariables->GetMainObjectSize (); | 551 const uint32_t objectSize = m_httpVariables->GetMainObjectSize (); |
549 NS_LOG_INFO (this << " Main object to be served is " | 552 NS_LOG_INFO (this << " Main object to be served is " |
550 << objectSize << " bytes."); | 553 << objectSize << " bytes."); |
551 m_mainObjectTrace (objectSize); | 554 m_mainObjectTrace (objectSize); |
552 m_txBuffer->WriteNewObject (socket, ThreeGppHttpTag::MAIN_OBJECT, | 555 m_txBuffer->WriteNewObject (socket, ThreeGppHttpHeader::MAIN_OBJECT, |
553 objectSize); | 556 objectSize); |
554 const uint32_t actualSent = ServeFromTxBuffer (socket); | 557 const uint32_t actualSent = ServeFromTxBuffer (socket); |
555 | 558 |
556 if (actualSent < objectSize) | 559 if (actualSent < objectSize) |
557 { | 560 { |
558 NS_LOG_INFO (this << " Transmission of main object is suspended" | 561 NS_LOG_INFO (this << " Transmission of main object is suspended" |
559 << " after " << actualSent << " bytes."); | 562 << " after " << actualSent << " bytes."); |
560 } | 563 } |
561 else | 564 else |
562 { | 565 { |
563 NS_LOG_INFO (this << " Finished sending a whole main object."); | 566 NS_LOG_INFO (this << " Finished sending a whole main object."); |
564 } | 567 } |
565 } | 568 } |
566 | 569 |
567 | 570 |
568 void | 571 void |
569 ThreeGppHttpServer::ServeNewEmbeddedObject (Ptr<Socket> socket) | 572 ThreeGppHttpServer::ServeNewEmbeddedObject (Ptr<Socket> socket) |
570 { | 573 { |
571 NS_LOG_FUNCTION (this << socket); | 574 NS_LOG_FUNCTION (this << socket); |
572 | 575 |
573 const uint32_t objectSize = m_httpVariables->GetEmbeddedObjectSize (); | 576 const uint32_t objectSize = m_httpVariables->GetEmbeddedObjectSize (); |
574 NS_LOG_INFO (this << " Embedded object to be served is " | 577 NS_LOG_INFO (this << " Embedded object to be served is " |
575 << objectSize << " bytes."); | 578 << objectSize << " bytes."); |
576 m_embeddedObjectTrace (objectSize); | 579 m_embeddedObjectTrace (objectSize); |
577 m_txBuffer->WriteNewObject (socket, ThreeGppHttpTag::EMBEDDED_OBJECT, | 580 m_txBuffer->WriteNewObject (socket, ThreeGppHttpHeader::EMBEDDED_OBJECT, |
578 objectSize); | 581 objectSize); |
579 const uint32_t actualSent = ServeFromTxBuffer (socket); | 582 const uint32_t actualSent = ServeFromTxBuffer (socket); |
580 | 583 |
581 if (actualSent < objectSize) | 584 if (actualSent < objectSize) |
582 { | 585 { |
583 NS_LOG_INFO (this << " Transmission of embedded object is suspended" | 586 NS_LOG_INFO (this << " Transmission of embedded object is suspended" |
584 << " after " << actualSent << " bytes."); | 587 << " after " << actualSent << " bytes."); |
585 } | 588 } |
586 else | 589 else |
587 { | 590 { |
588 NS_LOG_INFO (this << " Finished sending a whole embedded object."); | 591 NS_LOG_INFO (this << " Finished sending a whole embedded object."); |
589 } | 592 } |
590 } | 593 } |
591 | 594 |
592 | 595 |
593 uint32_t | 596 uint32_t |
594 ThreeGppHttpServer::ServeFromTxBuffer (Ptr<Socket> socket) | 597 ThreeGppHttpServer::ServeFromTxBuffer (Ptr<Socket> socket) |
595 { | 598 { |
596 NS_LOG_FUNCTION (this << socket); | 599 NS_LOG_FUNCTION (this << socket); |
597 | 600 |
598 if (m_txBuffer->IsBufferEmpty (socket)) | 601 if (m_txBuffer->IsBufferEmpty (socket)) |
599 { | 602 { |
600 NS_LOG_LOGIC (this << " Tx buffer is empty. Not sending anything."); | 603 NS_LOG_LOGIC (this << " Tx buffer is empty. Not sending anything."); |
601 return 0; | 604 return 0; |
602 } | 605 } |
| 606 bool firstPartOfObject = !m_txBuffer->HasTxedPartOfObject (socket); |
603 | 607 |
604 const uint32_t socketSize = socket->GetTxAvailable (); | 608 const uint32_t socketSize = socket->GetTxAvailable (); |
605 NS_LOG_DEBUG (this << " Socket has " << socketSize | 609 NS_LOG_DEBUG (this << " Socket has " << socketSize |
606 << " bytes available for Tx."); | 610 << " bytes available for Tx."); |
607 | 611 |
608 // Get the number of bytes remaining to be sent. | 612 // Get the number of bytes remaining to be sent. |
609 const uint32_t txBufferSize = m_txBuffer->GetBufferSize (socket); | 613 const uint32_t txBufferSize = m_txBuffer->GetBufferSize (socket); |
610 | 614 |
611 // Compute the size of actual content to be sent; has to fit into the socket. | 615 // Compute the size of actual content to be sent; has to fit into the socket. |
612 const uint32_t packetSize = std::min (txBufferSize, socketSize); | 616 // Note that header size is NOT counted as TxBuffer content. Header size is ov
erhead. |
613 Ptr<Packet> packet = Create<Packet> (packetSize); | 617 uint32_t contentSize = std::min (txBufferSize, socketSize - 22); |
614 | 618 Ptr<Packet> packet = Create<Packet> (contentSize); |
615 // Attaching tag. | 619 uint32_t packetSize = contentSize; |
616 ThreeGppHttpTag tag; | 620 |
617 tag.SetContentLength (txBufferSize); | 621 // If this is the first packet of an object, attach a header. |
618 tag.SetContentType (m_txBuffer->GetBufferContentType (socket)); | 622 if (firstPartOfObject) |
619 // Using the client TS value as per the corresponding request packet. | 623 { |
620 tag.SetClientTs (m_txBuffer->GetClientTs (socket)); | 624 // Create header. |
621 tag.SetServerTs (Simulator::Now ()); | 625 ThreeGppHttpHeader httpHeader; |
622 packet->AddByteTag (tag); | 626 httpHeader.SetContentLength (txBufferSize); |
623 | 627 httpHeader.SetContentType (m_txBuffer->GetBufferContentType (socket)); |
624 NS_LOG_INFO (this << " Created packet " << packet << " of " | 628 // Using the client TS value as per the corresponding request packet. |
625 << packetSize << " bytes." | 629 httpHeader.SetClientTs (m_txBuffer->GetClientTs (socket)); |
626 << " The corresponding request came " | 630 httpHeader.SetServerTs (Simulator::Now ()); |
627 << (Simulator::Now () - tag.GetClientTs ()).GetSeconds () | 631 packet->AddHeader (httpHeader); |
628 << "s ago."); | 632 packetSize += httpHeader.GetSerializedSize (); |
| 633 |
| 634 NS_LOG_INFO (this << " Created packet " << packet << " of " |
| 635 << packetSize << " bytes." |
| 636 << " The corresponding request came " |
| 637 << (Simulator::Now () - httpHeader.GetClientTs ()).GetSe
conds () |
| 638 << "s ago."); |
| 639 } |
| 640 else |
| 641 { |
| 642 NS_LOG_INFO (this << " Created packet " << packet << " of " |
| 643 << packetSize << " bytes to be appended to a previous pa
cket."); |
| 644 } |
629 | 645 |
630 // Send. | 646 // Send. |
631 const int actualBytes = socket->Send (packet); | 647 const int actualBytes = socket->Send (packet); |
632 NS_LOG_DEBUG (this << " Send() packet " << packet | 648 NS_LOG_DEBUG (this << " Send() packet " << packet |
633 << " of " << packetSize << " bytes," | 649 << " of " << packetSize << " bytes," |
634 << " return value= " << actualBytes << "."); | 650 << " return value= " << actualBytes << "."); |
635 m_txTrace (packet); | 651 m_txTrace (packet); |
636 | 652 |
637 if (actualBytes == static_cast<int> (packetSize)) | 653 if (actualBytes == static_cast<int> (packetSize)) |
638 { | 654 { |
639 // The packet goes through successfully. | 655 // The packet goes through successfully. |
640 m_txBuffer->DepleteBufferSize (socket, packetSize); | 656 m_txBuffer->DepleteBufferSize (socket, contentSize); |
641 NS_LOG_INFO (this << " Remaining object to be sent " | 657 NS_LOG_INFO (this << " Remaining object to be sent " |
642 << m_txBuffer->GetBufferSize (socket) << " bytes."); | 658 << m_txBuffer->GetBufferSize (socket) << " bytes."); |
643 return packetSize; | 659 return packetSize; |
644 } | 660 } |
645 else | 661 else |
646 { | 662 { |
647 NS_LOG_INFO (this << " Failed to send object," | 663 NS_LOG_INFO (this << " Failed to send object," |
648 << " GetErrNo= " << socket->GetErrno () << "," | 664 << " GetErrNo= " << socket->GetErrno () << "," |
649 << " suspending transmission" | 665 << " suspending transmission" |
650 << " and waiting for another Tx opportunity."); | 666 << " and waiting for another Tx opportunity."); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 void | 702 void |
687 ThreeGppHttpServerTxBuffer::AddSocket (Ptr<Socket> socket) | 703 ThreeGppHttpServerTxBuffer::AddSocket (Ptr<Socket> socket) |
688 { | 704 { |
689 NS_LOG_FUNCTION (this << socket); | 705 NS_LOG_FUNCTION (this << socket); |
690 | 706 |
691 NS_ASSERT_MSG (!IsSocketAvailable (socket), | 707 NS_ASSERT_MSG (!IsSocketAvailable (socket), |
692 this << " Cannot add socket " << socket | 708 this << " Cannot add socket " << socket |
693 << " because it has already been added before."); | 709 << " because it has already been added before."); |
694 | 710 |
695 TxBuffer_t txBuffer; | 711 TxBuffer_t txBuffer; |
696 txBuffer.txBufferContentType = ThreeGppHttpTag::NOT_SET; | 712 txBuffer.txBufferContentType = ThreeGppHttpHeader::NOT_SET; |
697 txBuffer.txBufferSize = 0; | 713 txBuffer.txBufferSize = 0; |
698 txBuffer.isClosing = false; | 714 txBuffer.isClosing = false; |
| 715 txBuffer.hasTxedPartOfObject = false; |
699 m_txBuffer.insert (std::pair<Ptr<Socket>, TxBuffer_t> (socket, txBuffer)); | 716 m_txBuffer.insert (std::pair<Ptr<Socket>, TxBuffer_t> (socket, txBuffer)); |
700 } | 717 } |
701 | 718 |
702 | 719 |
703 void | 720 void |
704 ThreeGppHttpServerTxBuffer::RemoveSocket (Ptr<Socket> socket) | 721 ThreeGppHttpServerTxBuffer::RemoveSocket (Ptr<Socket> socket) |
705 { | 722 { |
706 NS_LOG_FUNCTION (this << socket); | 723 NS_LOG_FUNCTION (this << socket); |
707 | 724 |
708 std::map<Ptr<Socket>, TxBuffer_t>::iterator it; | 725 std::map<Ptr<Socket>, TxBuffer_t>::iterator it; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 ThreeGppHttpServerTxBuffer::GetClientTs (Ptr<Socket> socket) const | 821 ThreeGppHttpServerTxBuffer::GetClientTs (Ptr<Socket> socket) const |
805 { | 822 { |
806 std::map<Ptr<Socket>, TxBuffer_t>::const_iterator it; | 823 std::map<Ptr<Socket>, TxBuffer_t>::const_iterator it; |
807 it = m_txBuffer.find (socket); | 824 it = m_txBuffer.find (socket); |
808 NS_ASSERT_MSG (it != m_txBuffer.end (), | 825 NS_ASSERT_MSG (it != m_txBuffer.end (), |
809 "Socket " << socket << " cannot be found."); | 826 "Socket " << socket << " cannot be found."); |
810 return it->second.clientTs; | 827 return it->second.clientTs; |
811 } | 828 } |
812 | 829 |
813 | 830 |
814 ThreeGppHttpTag::ContentType_t | 831 ThreeGppHttpHeader::ContentType_t |
815 ThreeGppHttpServerTxBuffer::GetBufferContentType (Ptr<Socket> socket) const | 832 ThreeGppHttpServerTxBuffer::GetBufferContentType (Ptr<Socket> socket) const |
816 { | 833 { |
817 std::map<Ptr<Socket>, TxBuffer_t>::const_iterator it; | 834 std::map<Ptr<Socket>, TxBuffer_t>::const_iterator it; |
818 it = m_txBuffer.find (socket); | 835 it = m_txBuffer.find (socket); |
819 NS_ASSERT_MSG (it != m_txBuffer.end (), | 836 NS_ASSERT_MSG (it != m_txBuffer.end (), |
820 "Socket " << socket << " cannot be found."); | 837 "Socket " << socket << " cannot be found."); |
821 return it->second.txBufferContentType; | 838 return it->second.txBufferContentType; |
822 } | 839 } |
823 | 840 |
824 | 841 |
825 uint32_t | 842 uint32_t |
826 ThreeGppHttpServerTxBuffer::GetBufferSize (Ptr<Socket> socket) const | 843 ThreeGppHttpServerTxBuffer::GetBufferSize (Ptr<Socket> socket) const |
827 { | 844 { |
828 std::map<Ptr<Socket>, TxBuffer_t>::const_iterator it; | 845 std::map<Ptr<Socket>, TxBuffer_t>::const_iterator it; |
829 it = m_txBuffer.find (socket); | 846 it = m_txBuffer.find (socket); |
830 NS_ASSERT_MSG (it != m_txBuffer.end (), | 847 NS_ASSERT_MSG (it != m_txBuffer.end (), |
831 "Socket " << socket << " cannot be found."); | 848 "Socket " << socket << " cannot be found."); |
832 return it->second.txBufferSize; | 849 return it->second.txBufferSize; |
833 } | 850 } |
834 | 851 |
835 | 852 |
| 853 bool |
| 854 ThreeGppHttpServerTxBuffer::HasTxedPartOfObject (Ptr<Socket> socket) const |
| 855 { |
| 856 std::map<Ptr<Socket>, TxBuffer_t>::const_iterator it; |
| 857 it = m_txBuffer.find (socket); |
| 858 NS_ASSERT_MSG (it != m_txBuffer.end (), |
| 859 "Socket " << socket << " cannot be found"); |
| 860 return it->second.hasTxedPartOfObject; |
| 861 } |
| 862 |
| 863 |
836 void | 864 void |
837 ThreeGppHttpServerTxBuffer::WriteNewObject (Ptr<Socket> socket, | 865 ThreeGppHttpServerTxBuffer::WriteNewObject (Ptr<Socket> socket, |
838 ThreeGppHttpTag::ContentType_t conte
ntType, | 866 ThreeGppHttpHeader::ContentType_t co
ntentType, |
839 uint32_t objectSize) | 867 uint32_t objectSize) |
840 { | 868 { |
841 NS_LOG_FUNCTION (this << socket << contentType << objectSize); | 869 NS_LOG_FUNCTION (this << socket << contentType << objectSize); |
842 | 870 |
843 NS_ASSERT_MSG (contentType != ThreeGppHttpTag::NOT_SET, | 871 NS_ASSERT_MSG (contentType != ThreeGppHttpHeader::NOT_SET, |
844 "Unable to write an object without a proper Content-Type."); | 872 "Unable to write an object without a proper Content-Type."); |
845 NS_ASSERT_MSG (objectSize > 0, | 873 NS_ASSERT_MSG (objectSize > 0, |
846 "Unable to write a zero-sized object."); | 874 "Unable to write a zero-sized object."); |
847 | 875 |
848 std::map<Ptr<Socket>, TxBuffer_t>::iterator it; | 876 std::map<Ptr<Socket>, TxBuffer_t>::iterator it; |
849 it = m_txBuffer.find (socket); | 877 it = m_txBuffer.find (socket); |
850 NS_ASSERT_MSG (it != m_txBuffer.end (), | 878 NS_ASSERT_MSG (it != m_txBuffer.end (), |
851 "Socket " << socket << " cannot be found."); | 879 "Socket " << socket << " cannot be found."); |
852 NS_ASSERT_MSG (it->second.txBufferSize == 0, | 880 NS_ASSERT_MSG (it->second.txBufferSize == 0, |
853 "Cannot write to Tx buffer of socket " << socket | 881 "Cannot write to Tx buffer of socket " << socket |
854 << " until the previous content has been completely sent."); | 882 << " until the previous content has been completely sent."); |
855 it->second.txBufferContentType = contentType; | 883 it->second.txBufferContentType = contentType; |
856 it->second.txBufferSize = objectSize; | 884 it->second.txBufferSize = objectSize; |
| 885 it->second.hasTxedPartOfObject = false; |
857 } | 886 } |
858 | 887 |
859 | 888 |
860 void | 889 void |
861 ThreeGppHttpServerTxBuffer::RecordNextServe (Ptr<Socket> socket, | 890 ThreeGppHttpServerTxBuffer::RecordNextServe (Ptr<Socket> socket, |
862 const EventId &eventId, | 891 const EventId &eventId, |
863 const Time &clientTs) | 892 const Time &clientTs) |
864 { | 893 { |
865 NS_LOG_FUNCTION (this << socket << clientTs.GetSeconds ()); | 894 NS_LOG_FUNCTION (this << socket << clientTs.GetSeconds ()); |
866 | 895 |
(...skipping 13 matching lines...) Expand all Loading... |
880 | 909 |
881 NS_ASSERT_MSG (amount > 0, "Unable to consume zero bytes."); | 910 NS_ASSERT_MSG (amount > 0, "Unable to consume zero bytes."); |
882 | 911 |
883 std::map<Ptr<Socket>, TxBuffer_t>::iterator it; | 912 std::map<Ptr<Socket>, TxBuffer_t>::iterator it; |
884 it = m_txBuffer.find (socket); | 913 it = m_txBuffer.find (socket); |
885 NS_ASSERT_MSG (it != m_txBuffer.end (), | 914 NS_ASSERT_MSG (it != m_txBuffer.end (), |
886 "Socket " << socket << " cannot be found."); | 915 "Socket " << socket << " cannot be found."); |
887 NS_ASSERT_MSG (it->second.txBufferSize >= amount, | 916 NS_ASSERT_MSG (it->second.txBufferSize >= amount, |
888 "The requested amount is larger than the current buffer size.")
; | 917 "The requested amount is larger than the current buffer size.")
; |
889 it->second.txBufferSize -= amount; | 918 it->second.txBufferSize -= amount; |
| 919 it->second.hasTxedPartOfObject = true; |
890 | 920 |
891 if (it->second.isClosing && (it->second.txBufferSize == 0)) | 921 if (it->second.isClosing && (it->second.txBufferSize == 0)) |
892 { | 922 { |
893 /* | 923 /* |
894 * The peer has earlier issued a close request and we have now waited | 924 * The peer has earlier issued a close request and we have now waited |
895 * until all the existing data are pushed into the socket. Now we close | 925 * until all the existing data are pushed into the socket. Now we close |
896 * the socket explicitly. | 926 * the socket explicitly. |
897 */ | 927 */ |
898 CloseSocket (socket); | 928 CloseSocket (socket); |
899 } | 929 } |
900 } | 930 } |
901 | 931 |
902 | 932 |
903 void | 933 void |
904 ThreeGppHttpServerTxBuffer::PrepareClose (Ptr<Socket> socket) | 934 ThreeGppHttpServerTxBuffer::PrepareClose (Ptr<Socket> socket) |
905 { | 935 { |
906 NS_LOG_FUNCTION (this << socket); | 936 NS_LOG_FUNCTION (this << socket); |
907 std::map<Ptr<Socket>, TxBuffer_t>::iterator it; | 937 std::map<Ptr<Socket>, TxBuffer_t>::iterator it; |
908 it = m_txBuffer.find (socket); | 938 it = m_txBuffer.find (socket); |
909 NS_ASSERT_MSG (it != m_txBuffer.end (), | 939 NS_ASSERT_MSG (it != m_txBuffer.end (), |
910 "Socket " << socket << " cannot be found."); | 940 "Socket " << socket << " cannot be found."); |
911 it->second.isClosing = true; | 941 it->second.isClosing = true; |
912 } | 942 } |
913 | 943 |
914 | 944 |
915 } // end of `namespace ns3` | 945 } // end of `namespace ns3` |
LEFT | RIGHT |