diff --git a/src/common/packet.cc b/src/common/packet.cc index 7301f1198..a9b95f66f 100644 --- a/src/common/packet.cc +++ b/src/common/packet.cc @@ -199,6 +199,13 @@ Packet::RemoveHeader (Header &header) m_metadata.RemoveHeader (header, deserialized); return deserialized; } +uint32_t +Packet::PeekHeader (Header &header) +{ + NS_LOG_FUNCTION (this << &header); + uint32_t deserialized = header.Deserialize (m_buffer.Begin ()); + return deserialized; +} void Packet::AddTrailer (const Trailer &trailer) { @@ -224,6 +231,13 @@ Packet::RemoveTrailer (Trailer &trailer) m_metadata.RemoveTrailer (trailer, deserialized); return deserialized; } +uint32_t +Packet::PeekTrailer (Trailer &trailer) +{ + NS_LOG_FUNCTION (this << &trailer); + uint32_t deserialized = trailer.Deserialize (m_buffer.End ()); + return deserialized; +} void Packet::AddAtEnd (Ptr packet) diff --git a/src/common/packet.h b/src/common/packet.h index f7bb58329..b51f9c3ab 100644 --- a/src/common/packet.h +++ b/src/common/packet.h @@ -187,7 +187,7 @@ public: uint32_t GetSize (void) const; /** * Add header to this packet. This method invokes the - * GetSerializedSize and Serialize + * Header::GetSerializedSize and Header::Serialize * methods to reserve space in the buffer and request the * header to serialize itself in the packet buffer. * @@ -196,15 +196,23 @@ public: void AddHeader (const Header & header); /** * Deserialize and remove the header from the internal buffer. - * This method invokes Deserialize. + * This method invokes Header::Deserialize. * * \param header a reference to the header to remove from the internal buffer. * \returns the number of bytes removed from the packet. */ uint32_t RemoveHeader (Header &header); + /** + * Deserialize but does _not_ remove the header from the internal buffer. + * This method invokes Header::Deserialize. + * + * \param header a reference to the header to read from the internal buffer. + * \returns the number of bytes read from the packet. + */ + uint32_t PeekHeader (Header &header); /** * Add trailer to this packet. This method invokes the - * GetSerializedSize and Serialize + * Trailer::GetSerializedSize and Trailer::Serialize * methods to reserve space in the buffer and request the trailer * to serialize itself in the packet buffer. * @@ -219,6 +227,14 @@ public: * \returns the number of bytes removed from the end of the packet. */ uint32_t RemoveTrailer (Trailer &trailer); + /** + * Deserialize but does _not_ remove a trailer from the internal buffer. + * This method invokes the Trailer::Deserialize method. + * + * \param trailer a reference to the trailer to read from the internal buffer. + * \returns the number of bytes read from the end of the packet. + */ + uint32_t PeekTrailer (Trailer &trailer); /** * \param os output stream in which the data should be printed. * diff --git a/src/internet-stack/tcp-l4-protocol.cc b/src/internet-stack/tcp-l4-protocol.cc index 6ca747e80..f0e9c0b9b 100644 --- a/src/internet-stack/tcp-l4-protocol.cc +++ b/src/internet-stack/tcp-l4-protocol.cc @@ -449,13 +449,8 @@ TcpL4Protocol::Receive (Ptr packet, { tcpHeader.EnableChecksums(); } - /* XXX very dirty but needs this to AddHeader again because of checksum */ - tcpHeader.SetLength(5); /* XXX TCP without options */ - tcpHeader.SetPayloadSize(packet->GetSize() - tcpHeader.GetSerializedSize()); - tcpHeader.InitializeChecksum(source, destination, PROT_NUMBER); - //these two do a peek, so that the packet can be forwarded up - packet->RemoveHeader (tcpHeader); + packet->PeekHeader (tcpHeader); NS_LOG_LOGIC("TcpL4Protocol " << this << " receiving seq " << tcpHeader.GetSequenceNumber() @@ -469,7 +464,6 @@ TcpL4Protocol::Receive (Ptr packet, return; } - packet->AddHeader (tcpHeader); NS_LOG_LOGIC ("TcpL4Protocol "<Lookup (destination, tcpHeader.GetDestinationPort (),