From 0da8f5c7632bb2be45a0f19d82d3c6335facf2da Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 1 May 2007 11:54:21 +0200 Subject: [PATCH] merge Packet API changes needed for Packet pretty printing. --- SConstruct | 2 + samples/main-packet.cc | 12 ++-- src/common/chunk.cc | 60 ++++++++++++++++++++ src/common/chunk.h | 84 +++++++++++++++++++++++++++ src/common/header.cc | 38 ------------- src/common/header.h | 49 +--------------- src/common/packet.cc | 81 ++++++--------------------- src/common/packet.h | 109 +++++++++++++++++++++++------------- src/common/trailer.cc | 38 ------------- src/common/trailer.h | 49 +--------------- src/node/arp-header.cc | 5 +- src/node/arp-header.h | 2 +- src/node/arp.cc | 7 +-- src/node/ascii-trace.cc | 12 ++-- src/node/ipv4-header.cc | 5 +- src/node/ipv4-header.h | 2 +- src/node/ipv4.cc | 5 +- src/node/llc-snap-header.cc | 5 +- src/node/llc-snap-header.h | 2 +- src/node/net-device.cc | 5 +- src/node/udp-header.cc | 5 +- src/node/udp-header.h | 2 +- src/node/udp.cc | 5 +- 23 files changed, 270 insertions(+), 314 deletions(-) create mode 100644 src/common/chunk.cc create mode 100644 src/common/chunk.h diff --git a/SConstruct b/SConstruct index 89ce1c537..7d9593a5c 100644 --- a/SConstruct +++ b/SConstruct @@ -137,6 +137,7 @@ common.add_deps(['core', 'simulator']) ns3.add(common) common.add_sources([ 'buffer.cc', + 'chunk.cc', 'header.cc', 'trailer.cc', 'packet.cc', @@ -155,6 +156,7 @@ common.add_headers ([ ]) common.add_inst_headers([ 'buffer.h', + 'chunk.h', 'header.h', 'trailer.h', 'tags.h', diff --git a/samples/main-packet.cc b/samples/main-packet.cc index 1dd4411f6..01b46097c 100644 --- a/samples/main-packet.cc +++ b/samples/main-packet.cc @@ -17,7 +17,7 @@ public: private: virtual void PrintTo (std::ostream &os) const; virtual void SerializeTo (Buffer::Iterator start) const; - virtual void DeserializeFrom (Buffer::Iterator start); + virtual uint32_t DeserializeFrom (Buffer::Iterator start); virtual uint32_t GetSerializedSize (void) const; uint16_t m_data; @@ -37,17 +37,18 @@ MyHeader::GetSerializedSize (void) const { return 2; } -void +void MyHeader::SerializeTo (Buffer::Iterator start) const { // serialize in head of buffer start.WriteHtonU16 (m_data); } -void +uint32_t MyHeader::DeserializeFrom (Buffer::Iterator start) { // deserialize from head of buffer m_data = start.ReadNtohU16 (); + return GetSerializedSize (); } void @@ -74,8 +75,7 @@ static void Receive (Packet p) { MyHeader my; - p.Peek (my); - p.Remove (my); + p.RemoveHeader (my); std::cout << "received data=" << my.GetData () << std::endl; struct MyTag myTag; p.PeekTag (myTag); @@ -88,7 +88,7 @@ int main (int argc, char *argv[]) MyHeader my; my.SetData (2); std::cout << "send data=2" << std::endl; - p.Add (my); + p.AddHeader (my); struct MyTag myTag; myTag.m_streamId = 5; p.AddTag (myTag); diff --git a/src/common/chunk.cc b/src/common/chunk.cc new file mode 100644 index 000000000..34c6cbce6 --- /dev/null +++ b/src/common/chunk.cc @@ -0,0 +1,60 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005 INRIA + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + */ + +#include "chunk.h" +#include "ns3/assert.h" + +namespace ns3 { + +Chunk::Chunk () +{} + +Chunk::~Chunk () +{} + +void +Chunk::Print (std::ostream &os) const +{ + PrintTo (os); +} +uint32_t +Chunk::GetSize (void) const +{ + return GetSerializedSize (); +} +void +Chunk::Serialize (Buffer::Iterator start) const +{ + SerializeTo (start); +} +uint32_t +Chunk::Deserialize (Buffer::Iterator start) +{ + uint32_t deserialized = DeserializeFrom (start); + return deserialized; +} +std::ostream& operator<< (std::ostream& os, Chunk const& chunk) +{ + chunk.Print (os); + return os; +} + +}; // namespace ns3 diff --git a/src/common/chunk.h b/src/common/chunk.h new file mode 100644 index 000000000..d2c638938 --- /dev/null +++ b/src/common/chunk.h @@ -0,0 +1,84 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005 INRIA + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + */ + +#ifndef CHUNK_H +#define CHUNK_H + +#include +#include +#include "buffer.h" + +namespace ns3 { + +/** + * \brief Protocol header and trailer serialization and deserialization. + * + * Every Protocol header or trailer which needs to be inserted and removed + * from a Packet instance must derive from this abstract base class + * and implement the private pure virtual methods listed below: + * - ns3::Chunk::SerializeTo + * - ns3::Chunk::DeserializeFrom + * - ns3::Chunk::GetSerializedSize + * - ns3::Chunk::PrintTo + */ +class Chunk { +public: + Chunk (); + virtual ~Chunk (); + + void Print (std::ostream &os) const; + uint32_t GetSize (void) const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); +private: + /** + * \param os the std output stream in which this + * protocol header must print itself. + */ + virtual void PrintTo (std::ostream &os) const = 0; + + /** + * \returns the size of the serialized Header. + */ + virtual uint32_t GetSerializedSize (void) const = 0; + + /** + * \param i the buffer iterator in which the protocol header + * must serialize itself. If this is a trailer, the index + * identifies the end of the buffer. If this is a header, + * the index identifies the start of the buffer. + */ + virtual void SerializeTo (Buffer::Iterator i) const = 0; + /** + * \param i the buffer iterator from which the protocol header must + * deserialize itself. If this is a trailer, the index + * identifies the end of the buffer. If this is a header, + * the index identifies the start of the buffer. + * \returns the number of bytes read from the buffer + */ + virtual uint32_t DeserializeFrom (Buffer::Iterator i) = 0; +}; + +std::ostream& operator<< (std::ostream& os, Chunk const& chunk); + +}; // namespace ns3 + +#endif /* CHUNK_H */ diff --git a/src/common/header.cc b/src/common/header.cc index 2a3a31d94..dae8acb4b 100644 --- a/src/common/header.cc +++ b/src/common/header.cc @@ -20,48 +20,10 @@ */ #include "header.h" -#include "ns3/assert.h" namespace ns3 { -Header::Header () - : m_isDeserialized (false) -{} - Header::~Header () {} -void -Header::Print (std::ostream &os) const -{ - PrintTo (os); -} -uint32_t -Header::GetSize (void) const -{ - return GetSerializedSize (); -} -void -Header::Serialize (Buffer::Iterator start) const -{ - SerializeTo (start); -} -void -Header::Deserialize (Buffer::Iterator start) -{ - DeserializeFrom (start); - m_isDeserialized = true; -} -bool -Header::IsDeserialized (void) const -{ - return m_isDeserialized; -} - -std::ostream& operator<< (std::ostream& os, Header const& header) -{ - header.Print (os); - return os; -} - }; // namespace ns3 diff --git a/src/common/header.h b/src/common/header.h index fe93c8037..a1f7c14bb 100644 --- a/src/common/header.h +++ b/src/common/header.h @@ -22,60 +22,15 @@ #ifndef HEADER_H #define HEADER_H -#include -#include -#include "buffer.h" +#include "chunk.h" namespace ns3 { -/** - * \brief Protocol header serialization and deserialization. - * - * Every Protocol header which needs to be inserted and removed - * from a Packet instance must derive from this abstract base class - * and implement the private pure virtual methods listed below: - * - ns3::Header::SerializeTo - * - ns3::Header::DeserializeFrom - * - ns3::Header::GetSerializedSize - * - ns3::Header::PrintTo - */ -class Header { +class Header : public Chunk { public: - Header (); virtual ~Header (); - - void Print (std::ostream &os) const; - uint32_t GetSize (void) const; - void Serialize (Buffer::Iterator start) const; - void Deserialize (Buffer::Iterator start); - bool IsDeserialized (void) const; -private: - bool m_isDeserialized; - /** - * \param os the std output stream in which this - * protocol header must print itself. - */ - virtual void PrintTo (std::ostream &os) const = 0; - - /** - * \returns the size of the serialized Header. - */ - virtual uint32_t GetSerializedSize (void) const = 0; - - /** - * \param start the buffer iterator in which the protocol header - * must serialize itself. - */ - virtual void SerializeTo (Buffer::Iterator start) const = 0; - /** - * \param start the buffer iterator from which the protocol header must - * deserialize itself. - */ - virtual void DeserializeFrom (Buffer::Iterator start) = 0; }; -std::ostream& operator<< (std::ostream& os, Header const& header); - }; // namespace ns3 #endif /* HEADER_H */ diff --git a/src/common/packet.cc b/src/common/packet.cc index 6067e9640..459cdae39 100644 --- a/src/common/packet.cc +++ b/src/common/packet.cc @@ -23,26 +23,26 @@ namespace ns3 { -uint32_t Packet::m_global_uid = 0; +uint32_t Packet::m_globalUid = 0; Packet::Packet () : m_buffer (), - m_uid (m_global_uid) + m_uid (m_globalUid) { - m_global_uid++; + m_globalUid++; } Packet::Packet (uint32_t size) : m_buffer (size), - m_uid (m_global_uid) + m_uid (m_globalUid) { - m_global_uid++; + m_globalUid++; } Packet::Packet (uint8_t const*buffer, uint32_t size) : m_buffer (), - m_uid (m_global_uid) + m_uid (m_globalUid) { - m_global_uid++; + m_globalUid++; m_buffer.AddAtStart (size); Buffer::Iterator i = m_buffer.Begin (); i.Write (buffer, size); @@ -57,8 +57,8 @@ Packet::Packet (Buffer buffer, Tags tags, uint32_t uid) Packet Packet::CreateFragment (uint32_t start, uint32_t length) const { - Buffer tmp = m_buffer.CreateFragment (start, length); - return Packet (tmp, m_tags, m_uid); + Buffer buffer = m_buffer.CreateFragment (start, length); + return Packet (buffer, m_tags, m_uid); } uint32_t @@ -67,46 +67,6 @@ Packet::GetSize (void) const return m_buffer.GetSize (); } -void -Packet::Add (Header const &header) -{ - m_buffer.AddAtStart (header.GetSize ()); - header.Serialize (m_buffer.Begin ()); -} -void -Packet::Peek (Header &header) -{ - header.Deserialize (m_buffer.Begin ()); -} -void -Packet::Remove (Header const &header) -{ - NS_ASSERT (header.IsDeserialized ()); - m_buffer.RemoveAtStart (header.GetSize ()); -} -void -Packet::Add (Trailer const &trailer) -{ - m_buffer.AddAtEnd (trailer.GetSize ()); - Buffer::Iterator start = m_buffer.End (); - start.Prev (trailer.GetSize ()); - trailer.Serialize (start); -} -void -Packet::Peek (Trailer &trailer) -{ - Buffer::Iterator start = m_buffer.End (); - start.Prev (trailer.GetSize ()); - trailer.Deserialize (start); -} -void -Packet::Remove (Trailer const &trailer) -{ - NS_ASSERT (trailer.IsDeserialized ()); - m_buffer.RemoveAtEnd (trailer.GetSize ()); -} - - void Packet::AddAtEnd (Packet packet) { @@ -120,23 +80,10 @@ Packet::AddAtEnd (Packet packet) * other packet into the current packet. */ } -void -Packet::AddAtEnd (Packet packet, uint32_t start, uint32_t size) +void +Packet::AddPaddingAtEnd (uint32_t size) { - NS_ASSERT (packet.GetSize () <= start + size); - Buffer src = packet.m_buffer; - m_buffer.AddAtEnd (src.GetSize ()); - Buffer::Iterator destStart = m_buffer.End (); - destStart.Prev (size); - Buffer::Iterator srcStart = src.Begin (); - srcStart.Next (start); - Buffer::Iterator srcEnd = srcStart; - srcEnd.Next (size); - destStart.Write (srcStart, srcEnd); - /** - * XXX: we might need to merge the tag list of the - * other packet into the current packet. - */ + m_buffer.AddAtEnd (size); } void Packet::RemoveAtEnd (uint32_t size) @@ -167,4 +114,8 @@ Packet::GetUid (void) const return m_uid; } +void +Packet::Print (std::ostream &os) const +{} + }; // namespace ns3 diff --git a/src/common/packet.h b/src/common/packet.h index 917945bdf..2ccccd97f 100644 --- a/src/common/packet.h +++ b/src/common/packet.h @@ -27,6 +27,7 @@ #include "trailer.h" #include "tags.h" #include "ns3/callback.h" +#include "ns3/assert.h" namespace ns3 { @@ -128,54 +129,42 @@ public: uint32_t GetSize (void) const; /** * Add header to this packet. This method invokes the - * ns3::Header::serializeTo method to request the header to serialize - * itself in the packet buffer. + * ns3::Chunk::GetSerializedSize and ns3::Chunk::SerializeTo + * methods to reserve space in the buffer and request the + * header to serialize itself in the packet buffer. * * \param header a reference to the header to add to this packet. */ - void Add (Header const &header); + template + void AddHeader (T const &header); /** - * Deserialize header from this packet. This method invokes the - * ns3::Header::deserializeFrom method to request the header to deserialize - * itself from the packet buffer. This method does not remove - * the data from the buffer. It merely reads it. - * - * \param header a reference to the header to deserialize from the buffer - */ - void Peek (Header &header); - /** - * Remove a deserialized header from the internal buffer. - * This method removes the bytes read by Packet::peek from - * the packet buffer. + * Deserialize and remove the header from the internal buffer. + * This method invokes ns3::Chunk::DeserializeFrom. * * \param header a reference to the header to remove from the internal buffer. + * \returns the number of bytes removed from the packet. */ - void Remove (Header const &header); + template + uint32_t RemoveHeader (T &header); /** * Add trailer to this packet. This method invokes the - * ns3::Trailer::serializeTo method to request the trailer to serialize - * itself in the packet buffer. + * ns3::Chunk::GetSerializedSize and ns3::Trailer::serializeTo + * methods to reserve space in the buffer and request the trailer + * to serialize itself in the packet buffer. * * \param trailer a reference to the trailer to add to this packet. */ - void Add (Trailer const &trailer); - /** - * Deserialize trailer from this packet. This method invokes the - * ns3::Trailer::deserializeFrom method to request the trailer to deserialize - * itself from the packet buffer. This method does not remove - * the data from the buffer. It merely reads it. - * - * \param trailer a reference to the trailer to deserialize from the buffer - */ - void Peek (Trailer &trailer); + template + void AddTrailer (T const &trailer); /** * Remove a deserialized trailer from the internal buffer. - * This method removes the bytes read by Packet::peek from - * the packet buffer. + * This method invokes the ns3::Chunk::DeserializeFrom method. * * \param trailer a reference to the trailer to remove from the internal buffer. + * \returns the number of bytes removed from the end of the packet. */ - void Remove (Trailer const &trailer); + template + uint32_t RemoveTrailer (T &trailer); /** * Attach a tag to this packet. The tag is fully copied * in a packet-specific internal buffer. This operation @@ -226,15 +215,9 @@ public: */ void AddAtEnd (Packet packet); /** - * Concatenate the fragment of the input packet identified - * by the offset and size parameters at the end of the current - * packet. This does not alter the uid of either packet. - * - * \param packet to concatenate - * \param offset offset of fragment to copy from the start of the input packet - * \param size size of fragment of input packet to copy. + * \param size number of padding bytes to add. */ - void AddAtEnd (Packet packet, uint32_t offset, uint32_t size); + void AddPaddingAtEnd (uint32_t size); /** * Remove size bytes from the end of the current packet * It is safe to remove more bytes that what is present in @@ -268,12 +251,14 @@ public: * identifies this packet. */ uint32_t GetUid (void) const; + + void Print (std::ostream &os) const; private: Packet (Buffer buffer, Tags tags, uint32_t uid); Buffer m_buffer; Tags m_tags; uint32_t m_uid; - static uint32_t m_global_uid; + static uint32_t m_globalUid; }; }; // namespace ns3 @@ -286,6 +271,50 @@ private: namespace ns3 { +template +void +Packet::AddHeader (T const &header) +{ + NS_ASSERT_MSG (dynamic_cast
(&header) != 0, + "Must pass Header subclass to Packet::AddHeader"); + uint32_t size = header.GetSize (); + m_buffer.AddAtStart (size); + header.Serialize (m_buffer.Begin ()); +} +template +uint32_t +Packet::RemoveHeader (T &header) +{ + NS_ASSERT_MSG (dynamic_cast
(&header) != 0, + "Must pass Header subclass to Packet::RemoveHeader"); + uint32_t deserialized = header.Deserialize (m_buffer.Begin ()); + m_buffer.RemoveAtStart (deserialized); + return deserialized; +} +template +void +Packet::AddTrailer (T const &trailer) +{ + NS_ASSERT_MSG (dynamic_cast (&trailer) != 0, + "Must pass Trailer subclass to Packet::AddTrailer"); + uint32_t size = trailer.GetSize (); + m_buffer.AddAtEnd (size); + Buffer::Iterator start = m_buffer.End (); + start.Prev (size); + trailer.Serialize (start); +} +template +uint32_t +Packet::RemoveTrailer (T &trailer) +{ + NS_ASSERT_MSG (dynamic_cast (&trailer) != 0, + "Must pass Trailer subclass to Packet::RemoveTrailer"); + uint32_t deserialized = trailer.Deserialize (m_buffer.End ()); + m_buffer.RemoveAtEnd (deserialized); + return deserialized; +} + + template void Packet::AddTag (T const& tag) { diff --git a/src/common/trailer.cc b/src/common/trailer.cc index a00918819..8026d2b92 100644 --- a/src/common/trailer.cc +++ b/src/common/trailer.cc @@ -20,48 +20,10 @@ */ #include "trailer.h" -#include "ns3/assert.h" namespace ns3 { -Trailer::Trailer () - : m_isDeserialized (false) -{} - Trailer::~Trailer () {} -void -Trailer::Print (std::ostream &os) const -{ - PrintTo (os); -} -uint32_t -Trailer::GetSize (void) const -{ - return GetSerializedSize (); -} -void -Trailer::Serialize (Buffer::Iterator start) const -{ - SerializeTo (start); -} -void -Trailer::Deserialize (Buffer::Iterator start) -{ - DeserializeFrom (start); - m_isDeserialized = true; -} -bool -Trailer::IsDeserialized (void) const -{ - return m_isDeserialized; -} - -std::ostream& operator<< (std::ostream& os, Trailer const& trailer) -{ - trailer.Print (os); - return os; -} - }; // namespace ns3 diff --git a/src/common/trailer.h b/src/common/trailer.h index a8bb7acb3..ce363eebc 100644 --- a/src/common/trailer.h +++ b/src/common/trailer.h @@ -22,60 +22,15 @@ #ifndef TRAILER_H #define TRAILER_H -#include -#include -#include "buffer.h" +#include "chunk.h" namespace ns3 { -/** - * \brief Protocol trailer serialization and deserialization. - * - * Every Protocol trailer which needs to be inserted and removed - * from a Packet instance must derive from this abstract base class - * and implement the private pure virtual methods listed below: - * - ns3::Trailer::SerializeTo - * - ns3::Trailer::DeserializeFrom - * - ns3::Trailer::GetSerializedSize - * - ns3::Trailer::PrintTo - */ -class Trailer { +class Trailer : public Chunk { public: - Trailer (); virtual ~Trailer (); - - void Print (std::ostream &os) const; - uint32_t GetSize (void) const; - void Serialize (Buffer::Iterator start) const; - void Deserialize (Buffer::Iterator start); - bool IsDeserialized (void) const; -private: - bool m_isDeserialized; - /** - * \param os the std output stream in which this - * protocol trailer must print itself. - */ - virtual void PrintTo (std::ostream &os) const = 0; - - /** - * \returns the size of the serialized Trailer. - */ - virtual uint32_t GetSerializedSize (void) const = 0; - - /** - * \param start the buffer iterator in which the protocol trailer - * must serialize itself. - */ - virtual void SerializeTo (Buffer::Iterator start) const = 0; - /** - * \param start the buffer iterator from which the protocol trailer must - * deserialize itself. - */ - virtual void DeserializeFrom (Buffer::Iterator start) = 0; }; -std::ostream& operator<< (std::ostream& os, Trailer const& trailer); - }; // namespace ns3 #endif /* TRAILER_H */ diff --git a/src/node/arp-header.cc b/src/node/arp-header.cc index b86f50a2b..3554681ee 100644 --- a/src/node/arp-header.cc +++ b/src/node/arp-header.cc @@ -110,7 +110,7 @@ ArpHeader::GetSerializedSize (void) const return 28; } -void +void ArpHeader::SerializeTo (Buffer::Iterator start) const { Buffer::Iterator i = start; @@ -128,7 +128,7 @@ ArpHeader::SerializeTo (Buffer::Iterator start) const WriteTo (i, m_macDest); WriteTo (i, m_ipv4Dest); } -void +uint32_t ArpHeader::DeserializeFrom (Buffer::Iterator start) { Buffer::Iterator i = start; @@ -140,6 +140,7 @@ ArpHeader::DeserializeFrom (Buffer::Iterator start) ReadFrom (i, m_ipv4Source); ReadFrom (i, m_macDest, hardwareAddressLen); ReadFrom (i, m_ipv4Dest); + return GetSerializedSize (); } }; // namespace ns3 diff --git a/src/node/arp-header.h b/src/node/arp-header.h index aad1c38eb..588b8bc24 100644 --- a/src/node/arp-header.h +++ b/src/node/arp-header.h @@ -51,7 +51,7 @@ private: virtual void PrintTo (std::ostream &os) const; virtual uint32_t GetSerializedSize (void) const; virtual void SerializeTo (Buffer::Iterator start) const; - virtual void DeserializeFrom (Buffer::Iterator start); + virtual uint32_t DeserializeFrom (Buffer::Iterator start); enum ArpType_e { ARP_TYPE_REQUEST = 1, diff --git a/src/node/arp.cc b/src/node/arp.cc index d405f0c6e..3f4c50c06 100644 --- a/src/node/arp.cc +++ b/src/node/arp.cc @@ -83,8 +83,7 @@ Arp::Receive(Packet& packet, NetDevice &device) { ArpCache *cache = FindCache (&device); ArpHeader arp; - packet.Peek (arp); - packet.Remove (arp); + packet.RemoveHeader (arp); if (arp.IsRequest () && arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ()) { @@ -206,7 +205,7 @@ Arp::SendArpRequest (ArpCache const *cache, Ipv4Address to) cache->GetDevice ()->GetBroadcast (), to); Packet packet; - packet.Add (arp); + packet.AddHeader (arp); cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), PROT_NUMBER); } @@ -218,7 +217,7 @@ Arp::SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac) cache->GetInterface ()->GetAddress (), toMac, toIp); Packet packet; - packet.Add (arp); + packet.AddHeader (arp); cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER); } diff --git a/src/node/ascii-trace.cc b/src/node/ascii-trace.cc index f0c985e1a..8b0c9ef2e 100644 --- a/src/node/ascii-trace.cc +++ b/src/node/ascii-trace.cc @@ -61,26 +61,22 @@ AsciiTrace::PrintType (Packet const &packet) { Packet p = packet; LlcSnapHeader llc; - p.Peek (llc); - p.Remove (llc); + p.RemoveHeader (llc); switch (llc.GetType ()) { case 0x0800: { Ipv4Header ipv4; - p.Peek (ipv4); - p.Remove (ipv4); + p.RemoveHeader (ipv4); if (ipv4.GetProtocol () == 17) { UdpHeader udp; - p.Peek (udp); - p.Remove (udp); + p.RemoveHeader (udp); m_os << "udp size=" << p.GetSize (); } } break; case 0x0806: { ArpHeader arp; - p.Peek (arp); - p.Remove (arp); + p.RemoveHeader (arp); m_os << "arp "; if (arp.IsRequest ()) { diff --git a/src/node/ipv4-header.cc b/src/node/ipv4-header.cc index 205e0e479..15be05cab 100644 --- a/src/node/ipv4-header.cc +++ b/src/node/ipv4-header.cc @@ -212,7 +212,7 @@ Ipv4Header::GetSerializedSize (void) const return 5 * 4; } -void +void Ipv4Header::SerializeTo (Buffer::Iterator start) const { Buffer::Iterator i = start; @@ -255,7 +255,7 @@ Ipv4Header::SerializeTo (Buffer::Iterator start) const #endif } } -void +uint32_t Ipv4Header::DeserializeFrom (Buffer::Iterator start) { Buffer::Iterator i = start; @@ -302,6 +302,7 @@ Ipv4Header::DeserializeFrom (Buffer::Iterator start) } #endif } + return GetSerializedSize (); } }; // namespace ns3 diff --git a/src/node/ipv4-header.h b/src/node/ipv4-header.h index c657d4e04..a09863491 100644 --- a/src/node/ipv4-header.h +++ b/src/node/ipv4-header.h @@ -65,7 +65,7 @@ private: virtual void PrintTo (std::ostream &os) const; virtual uint32_t GetSerializedSize (void) const; virtual void SerializeTo (Buffer::Iterator start) const; - virtual void DeserializeFrom (Buffer::Iterator start); + virtual uint32_t DeserializeFrom (Buffer::Iterator start); enum FlagsE { DONT_FRAGMENT = (1<<0), diff --git a/src/node/ipv4.cc b/src/node/ipv4.cc index da112396b..05d22e96b 100644 --- a/src/node/ipv4.cc +++ b/src/node/ipv4.cc @@ -367,8 +367,7 @@ Ipv4::Receive(Packet& packet, NetDevice &device) index++; } Ipv4Header ipHeader; - packet.Peek (ipHeader); - packet.Remove (ipHeader); + packet.RemoveHeader (ipHeader); if (!ipHeader.IsChecksumOk ()) { @@ -424,7 +423,7 @@ void Ipv4::SendRealOut (Packet const &p, Ipv4Header const &ip, Ipv4Route const &route) { Packet packet = p; - packet.Add (ip); + packet.AddHeader (ip); Ipv4Interface *outInterface = GetInterface (route.GetInterface ()); NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ()); m_txTrace (packet, route.GetInterface ()); diff --git a/src/node/llc-snap-header.cc b/src/node/llc-snap-header.cc index 81998f594..6f4b2295f 100644 --- a/src/node/llc-snap-header.cc +++ b/src/node/llc-snap-header.cc @@ -57,7 +57,7 @@ LlcSnapHeader::PrintTo (std::ostream &os) const os.setf (std::ios::dec, std::ios::basefield); } -void +void LlcSnapHeader::SerializeTo (Buffer::Iterator start) const { Buffer::Iterator i = start; @@ -65,12 +65,13 @@ LlcSnapHeader::SerializeTo (Buffer::Iterator start) const i.Write (buf, 6); i.WriteHtonU16 (m_etherType); } -void +uint32_t LlcSnapHeader::DeserializeFrom (Buffer::Iterator start) { Buffer::Iterator i = start; i.Next (5+1); m_etherType = i.ReadNtohU16 (); + return GetSerializedSize (); } diff --git a/src/node/llc-snap-header.h b/src/node/llc-snap-header.h index f95c38cc0..5b7457ad6 100644 --- a/src/node/llc-snap-header.h +++ b/src/node/llc-snap-header.h @@ -40,7 +40,7 @@ private: virtual void PrintTo (std::ostream &os) const; virtual uint32_t GetSerializedSize (void) const; virtual void SerializeTo (Buffer::Iterator start) const; - virtual void DeserializeFrom (Buffer::Iterator start); + virtual uint32_t DeserializeFrom (Buffer::Iterator start); uint16_t m_etherType; }; diff --git a/src/node/net-device.cc b/src/node/net-device.cc index 5801e6035..d520ff7ce 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -152,7 +152,7 @@ NetDevice::Send(Packet& p, const MacAddress& dest, uint16_t protocolNumber) { LlcSnapHeader llc; llc.SetType (protocolNumber); - p.Add (llc); + p.AddHeader (llc); return SendTo(p, dest); } else @@ -179,8 +179,7 @@ NetDevice::ForwardUp (Packet& packet) { bool retval = false; LlcSnapHeader llc; - packet.Peek (llc); - packet.Remove (llc); + packet.RemoveHeader (llc); if (!m_receiveCallback.IsNull ()) { retval = m_receiveCallback (this, packet, llc.GetType ()); diff --git a/src/node/udp-header.cc b/src/node/udp-header.cc index a7c80a6c0..38a7fa7d8 100644 --- a/src/node/udp-header.cc +++ b/src/node/udp-header.cc @@ -108,7 +108,7 @@ UdpHeader::GetSerializedSize (void) const return 8; } -void +void UdpHeader::SerializeTo (Buffer::Iterator start) const { Buffer::Iterator i = start; @@ -131,7 +131,7 @@ UdpHeader::SerializeTo (Buffer::Iterator start) const #endif } } -void +uint32_t UdpHeader::DeserializeFrom (Buffer::Iterator start) { Buffer::Iterator i = start; @@ -142,6 +142,7 @@ UdpHeader::DeserializeFrom (Buffer::Iterator start) { // XXX verify checksum. } + return GetSerializedSize (); } diff --git a/src/node/udp-header.h b/src/node/udp-header.h index d60b597fe..cbb36d2e9 100644 --- a/src/node/udp-header.h +++ b/src/node/udp-header.h @@ -50,7 +50,7 @@ private: virtual void PrintTo (std::ostream &os) const; virtual uint32_t GetSerializedSize (void) const; virtual void SerializeTo (Buffer::Iterator start) const; - virtual void DeserializeFrom (Buffer::Iterator start); + virtual uint32_t DeserializeFrom (Buffer::Iterator start); uint16_t m_sourcePort; uint16_t m_destinationPort; diff --git a/src/node/udp.cc b/src/node/udp.cc index 0f6f6faea..0a14e8dd7 100644 --- a/src/node/udp.cc +++ b/src/node/udp.cc @@ -100,8 +100,7 @@ Udp::Receive(Packet& packet, Ipv4Address const &destination) { UdpHeader udpHeader; - packet.Peek (udpHeader); - packet.Remove (udpHeader); + packet.RemoveHeader (udpHeader); UdpEndPoint *endPoint = m_endPoints->Lookup (destination, udpHeader.GetDestination (), source, udpHeader.GetSource ()); if (endPoint == 0) @@ -126,7 +125,7 @@ Udp::Send (Packet packet, daddr, PROT_NUMBER); - packet.Add (udpHeader); + packet.AddHeader (udpHeader); Ipv4 *ipv4 = m_node->GetIpv4 (); if (ipv4 != 0)