merge Packet API changes needed for Packet pretty printing.
--- a/SConstruct Tue May 01 11:38:30 2007 +0200
+++ b/SConstruct Tue May 01 11:54:21 2007 +0200
@@ -137,6 +137,7 @@
ns3.add(common)
common.add_sources([
'buffer.cc',
+ 'chunk.cc',
'header.cc',
'trailer.cc',
'packet.cc',
@@ -155,6 +156,7 @@
])
common.add_inst_headers([
'buffer.h',
+ 'chunk.h',
'header.h',
'trailer.h',
'tags.h',
--- a/samples/main-packet.cc Tue May 01 11:38:30 2007 +0200
+++ b/samples/main-packet.cc Tue May 01 11:54:21 2007 +0200
@@ -17,7 +17,7 @@
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 @@
{
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 @@
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 @@
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);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/common/chunk.cc Tue May 01 11:54:21 2007 +0200
@@ -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 <mathieu.lacage@sophia.inria.fr>
+ */
+
+#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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/common/chunk.h Tue May 01 11:54:21 2007 +0200
@@ -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 <mathieu.lacage@sophia.inria.fr>
+ */
+
+#ifndef CHUNK_H
+#define CHUNK_H
+
+#include <stdint.h>
+#include <ostream>
+#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 */
--- a/src/common/header.cc Tue May 01 11:38:30 2007 +0200
+++ b/src/common/header.cc Tue May 01 11:54:21 2007 +0200
@@ -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
--- a/src/common/header.h Tue May 01 11:38:30 2007 +0200
+++ b/src/common/header.h Tue May 01 11:54:21 2007 +0200
@@ -22,60 +22,15 @@
#ifndef HEADER_H
#define HEADER_H
-#include <stdint.h>
-#include <ostream>
-#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 */
--- a/src/common/packet.cc Tue May 01 11:38:30 2007 +0200
+++ b/src/common/packet.cc Tue May 01 11:54:21 2007 +0200
@@ -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::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
@@ -68,46 +68,6 @@
}
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)
{
Buffer src = packet.m_buffer;
@@ -120,23 +80,10 @@
* 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 @@
return m_uid;
}
+void
+Packet::Print (std::ostream &os) const
+{}
+
}; // namespace ns3
--- a/src/common/packet.h Tue May 01 11:38:30 2007 +0200
+++ b/src/common/packet.h Tue May 01 11:54:21 2007 +0200
@@ -27,6 +27,7 @@
#include "trailer.h"
#include "tags.h"
#include "ns3/callback.h"
+#include "ns3/assert.h"
namespace ns3 {
@@ -128,54 +129,42 @@
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 <typename T>
+ 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 <typename T>
+ 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 <typename T>
+ 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 <typename T>
+ 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 @@
*/
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 @@
* 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
@@ -287,6 +272,50 @@
namespace ns3 {
template <typename T>
+void
+Packet::AddHeader (T const &header)
+{
+ NS_ASSERT_MSG (dynamic_cast<Header const *> (&header) != 0,
+ "Must pass Header subclass to Packet::AddHeader");
+ uint32_t size = header.GetSize ();
+ m_buffer.AddAtStart (size);
+ header.Serialize (m_buffer.Begin ());
+}
+template <typename T>
+uint32_t
+Packet::RemoveHeader (T &header)
+{
+ NS_ASSERT_MSG (dynamic_cast<Header const *> (&header) != 0,
+ "Must pass Header subclass to Packet::RemoveHeader");
+ uint32_t deserialized = header.Deserialize (m_buffer.Begin ());
+ m_buffer.RemoveAtStart (deserialized);
+ return deserialized;
+}
+template <typename T>
+void
+Packet::AddTrailer (T const &trailer)
+{
+ NS_ASSERT_MSG (dynamic_cast<Trailer const *> (&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 <typename T>
+uint32_t
+Packet::RemoveTrailer (T &trailer)
+{
+ NS_ASSERT_MSG (dynamic_cast<Trailer const *> (&trailer) != 0,
+ "Must pass Trailer subclass to Packet::RemoveTrailer");
+ uint32_t deserialized = trailer.Deserialize (m_buffer.End ());
+ m_buffer.RemoveAtEnd (deserialized);
+ return deserialized;
+}
+
+
+template <typename T>
void Packet::AddTag (T const& tag)
{
m_tags.Add (tag);
--- a/src/common/trailer.cc Tue May 01 11:38:30 2007 +0200
+++ b/src/common/trailer.cc Tue May 01 11:54:21 2007 +0200
@@ -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
--- a/src/common/trailer.h Tue May 01 11:38:30 2007 +0200
+++ b/src/common/trailer.h Tue May 01 11:54:21 2007 +0200
@@ -22,60 +22,15 @@
#ifndef TRAILER_H
#define TRAILER_H
-#include <stdint.h>
-#include <ostream>
-#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 */
--- a/src/node/arp-header.cc Tue May 01 11:38:30 2007 +0200
+++ b/src/node/arp-header.cc Tue May 01 11:54:21 2007 +0200
@@ -110,7 +110,7 @@
return 28;
}
-void
+void
ArpHeader::SerializeTo (Buffer::Iterator start) const
{
Buffer::Iterator i = start;
@@ -128,7 +128,7 @@
WriteTo (i, m_macDest);
WriteTo (i, m_ipv4Dest);
}
-void
+uint32_t
ArpHeader::DeserializeFrom (Buffer::Iterator start)
{
Buffer::Iterator i = start;
@@ -140,6 +140,7 @@
ReadFrom (i, m_ipv4Source);
ReadFrom (i, m_macDest, hardwareAddressLen);
ReadFrom (i, m_ipv4Dest);
+ return GetSerializedSize ();
}
}; // namespace ns3
--- a/src/node/arp-header.h Tue May 01 11:38:30 2007 +0200
+++ b/src/node/arp-header.h Tue May 01 11:54:21 2007 +0200
@@ -51,7 +51,7 @@
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,
--- a/src/node/arp.cc Tue May 01 11:38:30 2007 +0200
+++ b/src/node/arp.cc Tue May 01 11:54:21 2007 +0200
@@ -83,8 +83,7 @@
{
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 @@
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 @@
cache->GetInterface ()->GetAddress (),
toMac, toIp);
Packet packet;
- packet.Add (arp);
+ packet.AddHeader (arp);
cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER);
}
--- a/src/node/ascii-trace.cc Tue May 01 11:38:30 2007 +0200
+++ b/src/node/ascii-trace.cc Tue May 01 11:54:21 2007 +0200
@@ -61,26 +61,22 @@
{
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 ())
{
--- a/src/node/ipv4-header.cc Tue May 01 11:38:30 2007 +0200
+++ b/src/node/ipv4-header.cc Tue May 01 11:54:21 2007 +0200
@@ -212,7 +212,7 @@
return 5 * 4;
}
-void
+void
Ipv4Header::SerializeTo (Buffer::Iterator start) const
{
Buffer::Iterator i = start;
@@ -255,7 +255,7 @@
#endif
}
}
-void
+uint32_t
Ipv4Header::DeserializeFrom (Buffer::Iterator start)
{
Buffer::Iterator i = start;
@@ -302,6 +302,7 @@
}
#endif
}
+ return GetSerializedSize ();
}
}; // namespace ns3
--- a/src/node/ipv4-header.h Tue May 01 11:38:30 2007 +0200
+++ b/src/node/ipv4-header.h Tue May 01 11:54:21 2007 +0200
@@ -65,7 +65,7 @@
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),
--- a/src/node/ipv4.cc Tue May 01 11:38:30 2007 +0200
+++ b/src/node/ipv4.cc Tue May 01 11:54:21 2007 +0200
@@ -367,8 +367,7 @@
index++;
}
Ipv4Header ipHeader;
- packet.Peek (ipHeader);
- packet.Remove (ipHeader);
+ packet.RemoveHeader (ipHeader);
if (!ipHeader.IsChecksumOk ())
{
@@ -424,7 +423,7 @@
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 ());
--- a/src/node/llc-snap-header.cc Tue May 01 11:38:30 2007 +0200
+++ b/src/node/llc-snap-header.cc Tue May 01 11:54:21 2007 +0200
@@ -57,7 +57,7 @@
os.setf (std::ios::dec, std::ios::basefield);
}
-void
+void
LlcSnapHeader::SerializeTo (Buffer::Iterator start) const
{
Buffer::Iterator i = start;
@@ -65,12 +65,13 @@
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 ();
}
--- a/src/node/llc-snap-header.h Tue May 01 11:38:30 2007 +0200
+++ b/src/node/llc-snap-header.h Tue May 01 11:54:21 2007 +0200
@@ -40,7 +40,7 @@
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;
};
--- a/src/node/net-device.cc Tue May 01 11:38:30 2007 +0200
+++ b/src/node/net-device.cc Tue May 01 11:54:21 2007 +0200
@@ -152,7 +152,7 @@
{
LlcSnapHeader llc;
llc.SetType (protocolNumber);
- p.Add (llc);
+ p.AddHeader (llc);
return SendTo(p, dest);
}
else
@@ -179,8 +179,7 @@
{
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 ());
--- a/src/node/udp-header.cc Tue May 01 11:38:30 2007 +0200
+++ b/src/node/udp-header.cc Tue May 01 11:54:21 2007 +0200
@@ -108,7 +108,7 @@
return 8;
}
-void
+void
UdpHeader::SerializeTo (Buffer::Iterator start) const
{
Buffer::Iterator i = start;
@@ -131,7 +131,7 @@
#endif
}
}
-void
+uint32_t
UdpHeader::DeserializeFrom (Buffer::Iterator start)
{
Buffer::Iterator i = start;
@@ -142,6 +142,7 @@
{
// XXX verify checksum.
}
+ return GetSerializedSize ();
}
--- a/src/node/udp-header.h Tue May 01 11:38:30 2007 +0200
+++ b/src/node/udp-header.h Tue May 01 11:54:21 2007 +0200
@@ -50,7 +50,7 @@
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;
--- a/src/node/udp.cc Tue May 01 11:38:30 2007 +0200
+++ b/src/node/udp.cc Tue May 01 11:54:21 2007 +0200
@@ -100,8 +100,7 @@
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 @@
daddr,
PROT_NUMBER);
- packet.Add (udpHeader);
+ packet.AddHeader (udpHeader);
Ipv4 *ipv4 = m_node->GetIpv4 ();
if (ipv4 != 0)