merge with trunk
commit
03ca60cd50
|
@ -188,6 +188,7 @@ common.add_sources([
|
|||
'chunk.cc',
|
||||
'header.cc',
|
||||
'trailer.cc',
|
||||
'packet-printer.cc',
|
||||
'packet-history.cc',
|
||||
'packet.cc',
|
||||
'tags.cc',
|
||||
|
@ -210,6 +211,7 @@ common.add_inst_headers([
|
|||
'trailer.h',
|
||||
'tags.h',
|
||||
'packet.h',
|
||||
'packet-printer.h',
|
||||
'packet-history.h',
|
||||
'uv-trace-source.h',
|
||||
'sv-trace-source.h',
|
||||
|
|
|
@ -15,6 +15,7 @@ public:
|
|||
void SetData (uint16_t data);
|
||||
uint16_t GetData (void) const;
|
||||
private:
|
||||
virtual std::string DoGetName (void) const;
|
||||
virtual void PrintTo (std::ostream &os) const;
|
||||
virtual void SerializeTo (Buffer::Iterator start) const;
|
||||
virtual uint32_t DeserializeFrom (Buffer::Iterator start);
|
||||
|
@ -27,6 +28,11 @@ MyHeader::MyHeader ()
|
|||
{}
|
||||
MyHeader::~MyHeader ()
|
||||
{}
|
||||
std::string
|
||||
MyHeader::DoGetName (void) const
|
||||
{
|
||||
return "MyHeader";
|
||||
}
|
||||
void
|
||||
MyHeader::PrintTo (std::ostream &os) const
|
||||
{
|
||||
|
|
|
@ -655,6 +655,14 @@ BufferTest::RunTests (void)
|
|||
i.Prev (1);
|
||||
i.WriteU8 (1, 1);
|
||||
|
||||
buffer = Buffer (6);
|
||||
buffer.AddAtStart (3);
|
||||
buffer.RemoveAtEnd (8);
|
||||
buffer.AddAtEnd (4);
|
||||
i = buffer.End ();
|
||||
i.Prev (4);
|
||||
i.WriteU8 (1, 4);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
|
|
@ -320,6 +320,8 @@ public:
|
|||
*/
|
||||
inline Buffer::Iterator End (void) const;
|
||||
|
||||
void TransformIntoRealBuffer (void) const;
|
||||
|
||||
inline Buffer (Buffer const &o);
|
||||
inline Buffer &operator = (Buffer const &o);
|
||||
inline Buffer ();
|
||||
|
@ -337,7 +339,6 @@ private:
|
|||
typedef std::vector<struct Buffer::BufferData*> BufferDataList;
|
||||
|
||||
inline uint8_t *GetStart (void) const;
|
||||
void TransformIntoRealBuffer (void) const;
|
||||
static void Recycle (struct Buffer::BufferData *data);
|
||||
static struct Buffer::BufferData *Create (void);
|
||||
static struct Buffer::BufferData *Allocate (uint32_t size, uint32_t start);
|
||||
|
@ -522,7 +523,8 @@ Buffer::Iterator::GetIndex (uint32_t n)
|
|||
NS_ASSERT (
|
||||
(m_current + n <= m_dataEnd) &&
|
||||
((m_current + n <= m_zeroStart) ||
|
||||
(m_current >= m_zeroEnd))
|
||||
(m_current >= m_zeroEnd) ||
|
||||
m_zeroStart == m_zeroEnd)
|
||||
);
|
||||
uint32_t index;
|
||||
if (m_current < m_zeroStart)
|
||||
|
@ -542,6 +544,8 @@ Buffer::Iterator::Write (Iterator start, Iterator end)
|
|||
{
|
||||
NS_ASSERT (start.m_data == end.m_data);
|
||||
NS_ASSERT (start.m_current <= end.m_current);
|
||||
NS_ASSERT (start.m_zeroStart == end.m_zeroStart);
|
||||
NS_ASSERT (start.m_zeroEnd == end.m_zeroEnd);
|
||||
NS_ASSERT (m_data != start.m_data);
|
||||
uint32_t size = end.m_current - start.m_current;
|
||||
uint8_t *src = start.m_data + start.GetIndex (size);
|
||||
|
|
|
@ -30,6 +30,11 @@ Chunk::Chunk ()
|
|||
Chunk::~Chunk ()
|
||||
{}
|
||||
|
||||
std::string
|
||||
Chunk::GetName (void) const
|
||||
{
|
||||
return DoGetName ();
|
||||
}
|
||||
void
|
||||
Chunk::Print (std::ostream &os) const
|
||||
{
|
||||
|
|
|
@ -33,11 +33,13 @@ public:
|
|||
Chunk ();
|
||||
virtual ~Chunk ();
|
||||
|
||||
std::string GetName (void) const;
|
||||
void Print (std::ostream &os) const;
|
||||
uint32_t GetSize (void) const;
|
||||
void Serialize (Buffer::Iterator start) const;
|
||||
uint32_t Deserialize (Buffer::Iterator start);
|
||||
private:
|
||||
virtual std::string DoGetName (void) const = 0;
|
||||
virtual void PrintTo (std::ostream &os) const = 0;
|
||||
virtual uint32_t GetSerializedSize (void) const = 0;
|
||||
virtual void SerializeTo (Buffer::Iterator i) const = 0;
|
||||
|
|
|
@ -41,6 +41,10 @@ class Header : public Chunk {
|
|||
public:
|
||||
virtual ~Header ();
|
||||
private:
|
||||
/**
|
||||
* \returns a user-readable name to identify this type of header.
|
||||
*/
|
||||
virtual std::string DoGetName (void) const = 0;
|
||||
/**
|
||||
* \param os the std output stream in which this
|
||||
* protocol header must print itself.
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -24,25 +24,17 @@
|
|||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include "ns3/callback.h"
|
||||
#include "packet-printer.h"
|
||||
|
||||
namespace {
|
||||
class ItemList;
|
||||
}
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Chunk;
|
||||
class Buffer;
|
||||
|
||||
class PacketPrinter
|
||||
{
|
||||
public:
|
||||
void PrintForward (void);
|
||||
void PrintBackward (void);
|
||||
template <typename T>
|
||||
void Add (Callback<void,std::ostream &, T> cb);
|
||||
|
||||
private:
|
||||
std::vector <std::pair<uint32_t,CallbackBase> > m_printers;
|
||||
bool m_forward;
|
||||
};
|
||||
|
||||
class PacketHistory {
|
||||
public:
|
||||
static void Enable (void);
|
||||
|
@ -69,13 +61,11 @@ public:
|
|||
void RemoveAtEnd (uint32_t end);
|
||||
|
||||
void PrintDefault (std::ostream &os, Buffer buffer) const;
|
||||
void PrintSimple (std::ostream &os, Buffer buffer) const;
|
||||
void PrintComplex (std::ostream &os, Buffer buffer) const;
|
||||
void Print (std::ostream &os, Buffer buffer, PacketPrinter printer) const;
|
||||
void Print (std::ostream &os, Buffer buffer, PacketPrinter const &printer) const;
|
||||
|
||||
private:
|
||||
enum CommandType {
|
||||
INIT_UID = 0,
|
||||
INIT = 0,
|
||||
ADD_HEADER = 1,
|
||||
REM_HEADER = 2,
|
||||
ADD_TRAILER = 3,
|
||||
|
@ -84,7 +74,6 @@ private:
|
|||
REM_AT_START = 6,
|
||||
REM_AT_END = 7,
|
||||
PADDING_AT_END = 9,
|
||||
INIT_SIZE = 10,
|
||||
LAST
|
||||
};
|
||||
struct CommandData {
|
||||
|
@ -95,14 +84,6 @@ private:
|
|||
};
|
||||
typedef std::vector<std::pair<uint32_t,uint32_t> > HeadersToPrint;
|
||||
typedef std::vector<std::pair<uint32_t,uint32_t> > TrailersToPrint;
|
||||
template <typename T>
|
||||
class ChunkUid {
|
||||
public:
|
||||
static const uint32_t GetUid (void);
|
||||
static Chunk *CreateStatic (void);
|
||||
};
|
||||
typedef std::vector<std::pair<uint32_t, Chunk *(*) (void)> > ChunkFactories;
|
||||
typedef std::vector<std::pair<uint32_t, Chunk *(*) (void)> >::iterator ChunkFactoriesI;
|
||||
typedef std::vector<struct CommandData *> DataFreeList;
|
||||
|
||||
PacketHistory ();
|
||||
|
@ -112,7 +93,6 @@ private:
|
|||
uint32_t GetReverseUleb128Size (uint8_t *buffer) const;
|
||||
void AppendValue (uint32_t value);
|
||||
uint32_t ReadForwardValue (uint8_t **pBuffer) const;
|
||||
uint32_t ReadReverseValue (uint8_t **pBuffer) const;
|
||||
uint32_t ReadValue (uint8_t *buffer, uint32_t *n) const;
|
||||
void AppendOneCommand (uint32_t type, uint32_t data);
|
||||
void AppendOneCommand (uint32_t type, uint32_t data0, uint32_t data1);
|
||||
|
@ -121,15 +101,15 @@ private:
|
|||
void RemoveHeader (uint32_t uid, Chunk const & header, uint32_t size);
|
||||
void AddTrailer (uint32_t uid, Chunk const & trailer, uint32_t size);
|
||||
void RemoveTrailer (uint32_t uid, Chunk const & trailer, uint32_t size);
|
||||
void PrintComplex (std::ostream &os, Buffer buffer, const PacketPrinter &printer) const;
|
||||
void BuildItemList (ItemList *list, uint8_t **buffer, uint32_t size, uint32_t n) const;
|
||||
|
||||
static struct PacketHistory::CommandData *Create (uint32_t size);
|
||||
static void Recycle (struct CommandData *data);
|
||||
static struct PacketHistory::CommandData *Allocate (uint32_t n);
|
||||
static void Deallocate (struct CommandData *data);
|
||||
static Chunk *CreateStatic (uint32_t uid);
|
||||
static uint32_t RegisterChunkFactory (Chunk *(*createStatic) (void));
|
||||
|
||||
static DataFreeList m_freeList;
|
||||
static ChunkFactories m_factories;
|
||||
static bool m_enable;
|
||||
static uint32_t m_maxSize;
|
||||
|
||||
|
@ -143,47 +123,30 @@ private:
|
|||
|
||||
namespace ns3 {
|
||||
|
||||
template <typename T>
|
||||
const uint32_t
|
||||
PacketHistory::ChunkUid<T>::GetUid (void)
|
||||
{
|
||||
static uint32_t uid =
|
||||
PacketHistory::RegisterChunkFactory (&PacketHistory::ChunkUid<T>::CreateStatic);
|
||||
return uid;
|
||||
}
|
||||
template <typename T>
|
||||
Chunk *
|
||||
PacketHistory::ChunkUid<T>::CreateStatic (void)
|
||||
{
|
||||
static T chunk = T ();
|
||||
return &chunk;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
PacketHistory::AddHeader (T const &header, uint32_t size)
|
||||
{
|
||||
AddHeader (ChunkUid<T>::GetUid (), header, size);
|
||||
AddHeader (PacketPrinter::GetUid<T> (), header, size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
PacketHistory::RemoveHeader (T const &header, uint32_t size)
|
||||
{
|
||||
RemoveHeader (ChunkUid<T>::GetUid (), header, size);
|
||||
RemoveHeader (PacketPrinter::GetUid<T> (), header, size);
|
||||
}
|
||||
template <typename T>
|
||||
void
|
||||
PacketHistory::AddTrailer (T const &trailer, uint32_t size)
|
||||
{
|
||||
AddTrailer (ChunkUid<T>::GetUid (), trailer, size);
|
||||
AddTrailer (PacketPrinter::GetUid<T> (), trailer, size);
|
||||
}
|
||||
template <typename T>
|
||||
void
|
||||
PacketHistory::RemoveTrailer (T const &trailer, uint32_t size)
|
||||
{
|
||||
RemoveTrailer (ChunkUid<T>::GetUid (), trailer, size);
|
||||
RemoveTrailer (PacketPrinter::GetUid<T> (), trailer, size);
|
||||
}
|
||||
|
||||
}; // namespace ns3
|
||||
|
|
|
@ -0,0 +1,190 @@
|
|||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 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 "packet-printer.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
PacketPrinter::PacketPrinter ()
|
||||
: m_forward (true)
|
||||
{}
|
||||
|
||||
void
|
||||
PacketPrinter::PrintForward (void)
|
||||
{
|
||||
m_forward = true;
|
||||
}
|
||||
void
|
||||
PacketPrinter::PrintBackward (void)
|
||||
{
|
||||
m_forward = false;
|
||||
}
|
||||
void
|
||||
PacketPrinter::AddPayloadPrinter (PayloadPrinter printer)
|
||||
{
|
||||
m_payloadPrinter = printer;
|
||||
}
|
||||
void
|
||||
PacketPrinter::AddDefaultPrinter (DefaultPrinter printer)
|
||||
{
|
||||
m_defaultPrinter = printer;
|
||||
}
|
||||
|
||||
PacketPrinter::RegisteredChunks *
|
||||
PacketPrinter::GetRegisteredChunks (void)
|
||||
{
|
||||
static RegisteredChunks registeredChunks;
|
||||
return ®isteredChunks;
|
||||
}
|
||||
|
||||
PacketPrinter
|
||||
PacketPrinter::GetDefault (void)
|
||||
{
|
||||
return *(PacketPrinter::PeekDefault ());
|
||||
}
|
||||
PacketPrinter *
|
||||
PacketPrinter::PeekDefault (void)
|
||||
{
|
||||
static PacketPrinter *tmp = PacketPrinter::CreateStaticDefault ();
|
||||
return tmp;
|
||||
}
|
||||
PacketPrinter *
|
||||
PacketPrinter::CreateStaticDefault (void)
|
||||
{
|
||||
static PacketPrinter tmp;
|
||||
return &tmp;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PacketPrinter::PrintChunk (uint32_t chunkUid,
|
||||
Buffer::Iterator start,
|
||||
std::ostream &os,
|
||||
uint32_t packetUid,
|
||||
uint32_t size) const
|
||||
{
|
||||
RegisteredChunks *registeredChunks = PacketPrinter::GetRegisteredChunks ();
|
||||
NS_ASSERT (chunkUid >= 1);
|
||||
for (PrinterList::const_iterator i = m_printerList.begin (); i != m_printerList.end (); i++)
|
||||
{
|
||||
if (i->m_chunkUid == chunkUid)
|
||||
{
|
||||
DoPrintCallback cb = (*registeredChunks)[chunkUid-1].first;
|
||||
cb (i->m_printer, start, os, packetUid, size);
|
||||
return;
|
||||
}
|
||||
}
|
||||
DoGetNameCallback cb = (*registeredChunks)[chunkUid-1].second;
|
||||
std::string name = cb ();
|
||||
struct PacketPrinter::FragmentInformation info;
|
||||
info.start = 0;
|
||||
info.end = size;
|
||||
m_defaultPrinter (os, packetUid, size, name, info);
|
||||
}
|
||||
void
|
||||
PacketPrinter::PrintChunkFragment (uint32_t chunkUid,
|
||||
std::ostream &os,
|
||||
uint32_t packetUid,
|
||||
uint32_t size,
|
||||
uint32_t fragmentStart,
|
||||
uint32_t fragmentEnd) const
|
||||
{
|
||||
RegisteredChunks *registeredChunks = PacketPrinter::GetRegisteredChunks ();
|
||||
NS_ASSERT (chunkUid >= 1);
|
||||
DoGetNameCallback cb = (*registeredChunks)[chunkUid-1].second;
|
||||
std::string name = cb ();
|
||||
struct PacketPrinter::FragmentInformation info;
|
||||
info.start = fragmentStart;
|
||||
info.end = fragmentEnd;
|
||||
for (PrinterList::const_iterator i = m_printerList.begin (); i != m_printerList.end (); i++)
|
||||
{
|
||||
if (i->m_chunkUid == chunkUid)
|
||||
{
|
||||
i->m_fragmentPrinter (os, packetUid, size, name, info);
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_defaultPrinter (os, packetUid, size, name, info);
|
||||
}
|
||||
void
|
||||
PacketPrinter::PrintPayload (std::ostream &os, uint32_t packetUid, uint32_t size,
|
||||
uint32_t fragmentStart, uint32_t fragmentEnd) const
|
||||
{
|
||||
struct PacketPrinter::FragmentInformation info;
|
||||
info.start = fragmentStart;
|
||||
info.end = fragmentEnd;
|
||||
m_payloadPrinter (os, packetUid, size, info);
|
||||
}
|
||||
|
||||
void
|
||||
PacketPrinter::DoDefaultPrintPayload (std::ostream & os,
|
||||
uint32_t packetUid,
|
||||
uint32_t size,
|
||||
struct PacketPrinter::FragmentInformation info)
|
||||
{
|
||||
os << "data ";
|
||||
os << "[" << info.start << ":" << info.end << "] -> "
|
||||
<< "[0:" << size << "]";
|
||||
os << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
PacketPrinter::DoDefaultPrintDefault (std::ostream & os,
|
||||
uint32_t packetUid,
|
||||
uint32_t size,
|
||||
std::string &name,
|
||||
struct PacketPrinter::FragmentInformation info)
|
||||
{
|
||||
NS_ASSERT_MSG (false, "This should never happen because we provide a printer for _all_ chunk types.");
|
||||
}
|
||||
|
||||
void
|
||||
PacketPrinter::DoDefaultPrintFragment (std::ostream & os,
|
||||
uint32_t packetUid,
|
||||
uint32_t size,
|
||||
std::string &name,
|
||||
struct PacketPrinter::FragmentInformation info)
|
||||
{
|
||||
os << name << " ";
|
||||
os << "[" << info.start << ":" << info.end << "] -> "
|
||||
<< "[0:" << size << "]";
|
||||
os << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
PacketPrinter::DoAddPrinter (uint32_t uid,
|
||||
Ptr<CallbackImplBase> printer,
|
||||
Callback<void,
|
||||
std::ostream &,
|
||||
uint32_t,
|
||||
uint32_t,
|
||||
std::string &,
|
||||
struct PacketPrinter::FragmentInformation> fragmentPrinter)
|
||||
{
|
||||
struct PacketPrinter::Printer p;
|
||||
p.m_chunkUid = uid;
|
||||
p.m_printer = printer;
|
||||
p.m_fragmentPrinter = fragmentPrinter;
|
||||
m_printerList.push_back (p);
|
||||
}
|
||||
|
||||
|
||||
} // namespace ns3
|
|
@ -0,0 +1,251 @@
|
|||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 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 PACKET_PRINTER_H
|
||||
#define PACKET_PRINTER_H
|
||||
|
||||
#include "ns3/callback.h"
|
||||
#include "ns3/ptr.h"
|
||||
#include "buffer.h"
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
class ItemList;
|
||||
}
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Chunk;
|
||||
|
||||
class PacketPrinter
|
||||
{
|
||||
public:
|
||||
struct FragmentInformation
|
||||
{
|
||||
uint32_t start;
|
||||
uint32_t end;
|
||||
};
|
||||
/**
|
||||
* \brief callback to print payload.
|
||||
*
|
||||
* Arguments: output stream, packet uid, size, fragment information
|
||||
*/
|
||||
typedef Callback<void,std::ostream &,uint32_t,uint32_t,struct PacketPrinter::FragmentInformation>
|
||||
PayloadPrinter;
|
||||
|
||||
/**
|
||||
* \brief callback to print fragmented chunks.
|
||||
*
|
||||
* Arguments: output stream, packet uid, size, header/trailer name, fragment information
|
||||
*/
|
||||
typedef Callback<void,std::ostream &,uint32_t,uint32_t,std::string &,struct PacketPrinter::FragmentInformation>
|
||||
ChunkFragmentPrinter;
|
||||
|
||||
/**
|
||||
* \brief callback to print chunks for which no specific callback was specified.
|
||||
*
|
||||
* Arguments: output stream, packet uid, size, header/trailer name, fragment information
|
||||
*/
|
||||
typedef Callback<void,std::ostream&,uint32_t,uint32_t,std::string&,struct PacketPrinter::FragmentInformation>
|
||||
DefaultPrinter;
|
||||
|
||||
PacketPrinter ();
|
||||
|
||||
/**
|
||||
* Print the content of the packet forward.
|
||||
*/
|
||||
void PrintForward (void);
|
||||
/**
|
||||
* Print the content of the packet backward.
|
||||
*/
|
||||
void PrintBackward (void);
|
||||
/**
|
||||
* \param printer printer for payload
|
||||
*/
|
||||
void AddPayloadPrinter (PayloadPrinter printer);
|
||||
/**
|
||||
* \param printer printer for the specified chunk
|
||||
* \param fragmentPrinter printer for a fragment of the specified chunk
|
||||
*/
|
||||
template <typename T>
|
||||
void AddPrinter (Callback<void,std::ostream &,uint32_t,uint32_t,const T *> printer,
|
||||
ChunkFragmentPrinter fragmentPrinter);
|
||||
/**
|
||||
* \param printer printer for a chunk for which no callback was specified explicitely
|
||||
*/
|
||||
void AddDefaultPrinter (DefaultPrinter printer);
|
||||
|
||||
private:
|
||||
friend class PacketHistory;
|
||||
friend class ItemList;
|
||||
struct Printer
|
||||
{
|
||||
uint32_t m_chunkUid;
|
||||
Ptr<CallbackImplBase> m_printer;
|
||||
Callback<void,std::ostream &,uint32_t,uint32_t,std::string &,struct PacketPrinter::FragmentInformation>
|
||||
m_fragmentPrinter;
|
||||
};
|
||||
typedef void (*DoPrintCallback) (Ptr<CallbackImplBase>, Buffer::Iterator, std::ostream &,
|
||||
uint32_t, uint32_t);
|
||||
typedef std::string (*DoGetNameCallback) (void);
|
||||
typedef std::vector<struct PacketPrinter::Printer> PrinterList;
|
||||
typedef std::vector<std::pair<DoPrintCallback,DoGetNameCallback> > RegisteredChunks;
|
||||
|
||||
|
||||
static PacketPrinter GetDefault (void);
|
||||
static PacketPrinter *PeekDefault (void);
|
||||
static PacketPrinter *CreateStaticDefault (void);
|
||||
static void DoDefaultPrintPayload (std::ostream & os,
|
||||
uint32_t packetUid,
|
||||
uint32_t size,
|
||||
struct PacketPrinter::FragmentInformation info);
|
||||
static void DoDefaultPrintDefault (std::ostream & os,
|
||||
uint32_t packetUid,
|
||||
uint32_t size,
|
||||
std::string &name,
|
||||
struct PacketPrinter::FragmentInformation info);
|
||||
template <typename T>
|
||||
static void DoDefaultPrint (std::ostream &os, uint32_t packetUid, uint32_t size, const T *chunk);
|
||||
static void DoDefaultPrintFragment (std::ostream & os,
|
||||
uint32_t packetUid,
|
||||
uint32_t size,
|
||||
std::string &name,
|
||||
struct PacketPrinter::FragmentInformation info);
|
||||
|
||||
template <typename T>
|
||||
static void DoPrint (Ptr<CallbackImplBase> callbackPrinter,
|
||||
Buffer::Iterator i,
|
||||
std::ostream &os,
|
||||
uint32_t packetUid,
|
||||
uint32_t size);
|
||||
template <typename T>
|
||||
static std::string DoGetName (void);
|
||||
template <typename T>
|
||||
static uint32_t GetUid (void);
|
||||
template <typename T>
|
||||
static uint32_t AllocateUid (void);
|
||||
static RegisteredChunks *GetRegisteredChunks (void);
|
||||
|
||||
|
||||
void PrintChunk (uint32_t uid,
|
||||
Buffer::Iterator i,
|
||||
std::ostream &os,
|
||||
uint32_t packetUid,
|
||||
uint32_t size) const;
|
||||
void PrintChunkFragment (uint32_t uid,
|
||||
std::ostream &os,
|
||||
uint32_t packetUid,
|
||||
uint32_t size,
|
||||
uint32_t fragmentStart,
|
||||
uint32_t fragmentEnd) const;
|
||||
void PrintPayload (std::ostream &os, uint32_t packetUid, uint32_t size,
|
||||
uint32_t fragmentStart, uint32_t fragmentEnd) const;
|
||||
void DoAddPrinter (uint32_t uid,
|
||||
Ptr<CallbackImplBase> printer,
|
||||
Callback<void,
|
||||
std::ostream &,
|
||||
uint32_t,
|
||||
uint32_t,
|
||||
std::string &,
|
||||
struct PacketPrinter::FragmentInformation> fragmentPrinter);
|
||||
|
||||
static PacketPrinter m_defaultPacketPrinter;
|
||||
PrinterList m_printerList;
|
||||
PayloadPrinter m_payloadPrinter;
|
||||
DefaultPrinter m_defaultPrinter;
|
||||
bool m_forward;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
PacketPrinter::AddPrinter (Callback<void,std::ostream &, uint32_t, uint32_t, const T *> printer,
|
||||
Callback<void,
|
||||
std::ostream &,
|
||||
uint32_t,
|
||||
uint32_t,
|
||||
std::string &,
|
||||
struct PacketPrinter::FragmentInformation> fragmentPrinter)
|
||||
{
|
||||
static uint32_t uid = PacketPrinter::GetUid<T> ();
|
||||
DoAddPrinter (uid, printer.GetImpl (), fragmentPrinter);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
PacketPrinter::DoPrint (Ptr<CallbackImplBase> printerCallback,
|
||||
Buffer::Iterator i,
|
||||
std::ostream &os,
|
||||
uint32_t packetUid,
|
||||
uint32_t size)
|
||||
{
|
||||
T chunk = T ();
|
||||
chunk.Deserialize (i);
|
||||
Callback<void,std::ostream&,uint32_t,uint32_t,const T*> callback;
|
||||
callback.Assign (printerCallback);
|
||||
callback (os, packetUid, size, &chunk);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string
|
||||
PacketPrinter::DoGetName (void)
|
||||
{
|
||||
T chunk = T ();
|
||||
return chunk.GetName ();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
uint32_t
|
||||
PacketPrinter::GetUid (void)
|
||||
{
|
||||
static uint32_t uid = PacketPrinter::AllocateUid<T> ();
|
||||
return uid;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
uint32_t
|
||||
PacketPrinter::AllocateUid (void)
|
||||
{
|
||||
RegisteredChunks *chunks = PacketPrinter::GetRegisteredChunks ();
|
||||
chunks->push_back (std::make_pair(&PacketPrinter::DoPrint<T>,
|
||||
&PacketPrinter::DoGetName<T>));
|
||||
uint32_t uid = chunks->size ();
|
||||
PacketPrinter::PeekDefault ()->DoAddPrinter (uid,
|
||||
MakeCallback (&PacketPrinter::DoDefaultPrint<T>).GetImpl (),
|
||||
MakeCallback (&PacketPrinter::DoDefaultPrintFragment));
|
||||
return uid;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void
|
||||
PacketPrinter::DoDefaultPrint (std::ostream &os, uint32_t packetUid, uint32_t size, const T *chunk)
|
||||
{
|
||||
chunk->Print (os);
|
||||
os << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* PACKET_PRINTER_H */
|
|
@ -19,6 +19,7 @@
|
|||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
#include "packet.h"
|
||||
#include "packet-printer.h"
|
||||
#include "ns3/assert.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
@ -62,7 +63,8 @@ Packet
|
|||
Packet::CreateFragment (uint32_t start, uint32_t length) const
|
||||
{
|
||||
Buffer buffer = m_buffer.CreateFragment (start, length);
|
||||
uint32_t end = buffer.GetSize () - (start + length);
|
||||
NS_ASSERT (m_buffer.GetSize () >= start + length);
|
||||
uint32_t end = m_buffer.GetSize () - (start + length);
|
||||
PacketHistory history = m_history.CreateFragment (start, end);
|
||||
return Packet (buffer, m_tags, history, m_uid);
|
||||
}
|
||||
|
@ -76,6 +78,9 @@ Packet::GetSize (void) const
|
|||
void
|
||||
Packet::AddAtEnd (Packet packet)
|
||||
{
|
||||
packet.m_buffer.TransformIntoRealBuffer ();
|
||||
m_buffer.TransformIntoRealBuffer ();
|
||||
|
||||
Buffer src = packet.m_buffer;
|
||||
m_buffer.AddAtEnd (src.GetSize ());
|
||||
Buffer::Iterator destStart = m_buffer.End ();
|
||||
|
@ -130,4 +135,10 @@ Packet::Print (std::ostream &os) const
|
|||
m_history.PrintDefault (os, m_buffer);
|
||||
}
|
||||
|
||||
void
|
||||
Packet::Print (std::ostream &os, const PacketPrinter &printer) const
|
||||
{
|
||||
m_history.Print (os, m_buffer, printer);
|
||||
}
|
||||
|
||||
}; // namespace ns3
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
|
||||
namespace ns3 {
|
||||
|
||||
class PacketPrinter;
|
||||
|
||||
/**
|
||||
* \brief network packets
|
||||
*
|
||||
|
@ -254,6 +256,7 @@ public:
|
|||
uint32_t GetUid (void) const;
|
||||
|
||||
void Print (std::ostream &os) const;
|
||||
void Print (std::ostream &os, const PacketPrinter &printer) const;
|
||||
private:
|
||||
Packet (Buffer buffer, Tags tags, PacketHistory history, uint32_t uid);
|
||||
Buffer m_buffer;
|
||||
|
@ -304,7 +307,6 @@ Packet::AddTrailer (T const &trailer)
|
|||
uint32_t size = trailer.GetSize ();
|
||||
m_buffer.AddAtEnd (size);
|
||||
Buffer::Iterator start = m_buffer.End ();
|
||||
start.Prev (size);
|
||||
trailer.Serialize (start);
|
||||
m_history.AddTrailer (trailer, size);
|
||||
}
|
||||
|
|
|
@ -41,6 +41,10 @@ class Trailer : public Chunk {
|
|||
public:
|
||||
virtual ~Trailer ();
|
||||
private:
|
||||
/**
|
||||
* \returns a user-readable name to identify this type of header.
|
||||
*/
|
||||
virtual std::string DoGetName (void) const = 0;
|
||||
/**
|
||||
* \param os the std output stream in which this
|
||||
* protocol trailer must print itself.
|
||||
|
|
|
@ -226,6 +226,7 @@ class CallbackBase {
|
|||
public:
|
||||
virtual ~CallbackBase () {}
|
||||
virtual CallbackImplBase *PeekImpl (void) const = 0;
|
||||
virtual Ptr<CallbackImplBase> GetImpl (void) const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -331,6 +332,19 @@ public:
|
|||
const Callback<R, T1,T2,T3,T4,T5> *goodType = static_cast<const Callback<R,T1,T2,T3,T4,T5> *> (&other);
|
||||
*this = *goodType;
|
||||
}
|
||||
void Assign (Ptr<CallbackImplBase> other) {
|
||||
CallbackImpl<R,T1,T2,T3,T4,T5> *impl = dynamic_cast<CallbackImpl<R,T1,T2,T3,T4,T5> *> (PeekPointer (other));
|
||||
if (other == 0)
|
||||
{
|
||||
NS_FATAL_ERROR ("Incompatible types. (feed to \"c++filt -t\")"
|
||||
" got=" << typeid (other).name () <<
|
||||
", expected=" << typeid (*impl).name ());
|
||||
}
|
||||
*this = Callback<R,T1,T2,T3,T4,T5> (impl);
|
||||
}
|
||||
virtual Ptr<CallbackImplBase>GetImpl (void) const {
|
||||
return m_impl;
|
||||
}
|
||||
private:
|
||||
virtual CallbackImpl<R,T1,T2,T3,T4,T5> *PeekImpl (void) const {
|
||||
return PeekPointer (m_impl);
|
||||
|
|
|
@ -83,6 +83,11 @@ ArpHeader::GetDestinationIpv4Address (void)
|
|||
return m_ipv4Dest;
|
||||
}
|
||||
|
||||
std::string
|
||||
ArpHeader::DoGetName (void) const
|
||||
{
|
||||
return "Arp";
|
||||
}
|
||||
|
||||
void
|
||||
ArpHeader::PrintTo (std::ostream &os) const
|
||||
|
|
|
@ -50,6 +50,7 @@ class ArpHeader : public Header {
|
|||
Ipv4Address GetDestinationIpv4Address (void);
|
||||
|
||||
private:
|
||||
virtual std::string DoGetName (void) const;
|
||||
/**
|
||||
* \param os
|
||||
*/
|
||||
|
|
|
@ -190,6 +190,12 @@ Ipv4Header::IsChecksumOk (void) const
|
|||
return m_goodChecksum;
|
||||
}
|
||||
|
||||
std::string
|
||||
Ipv4Header::DoGetName (void) const
|
||||
{
|
||||
return "Ipv4";
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4Header::PrintTo (std::ostream &os) const
|
||||
{
|
||||
|
|
|
@ -140,6 +140,7 @@ public:
|
|||
bool IsChecksumOk (void) const;
|
||||
|
||||
private:
|
||||
virtual std::string DoGetName (void) const;
|
||||
virtual void PrintTo (std::ostream &os) const;
|
||||
virtual uint32_t GetSerializedSize (void) const;
|
||||
virtual void SerializeTo (Buffer::Iterator start) const;
|
||||
|
|
|
@ -91,7 +91,11 @@ UdpHeader::InitializeChecksum (Ipv4Address source,
|
|||
m_initialChecksum = Ipv4ChecksumCalculate (0, buf, 12);
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
UdpHeader::DoGetName (void) const
|
||||
{
|
||||
return "Udp";
|
||||
}
|
||||
|
||||
void
|
||||
UdpHeader::PrintTo (std::ostream &os) const
|
||||
|
|
|
@ -81,6 +81,7 @@ public:
|
|||
uint8_t protocol);
|
||||
|
||||
private:
|
||||
virtual std::string DoGetName (void) const;
|
||||
virtual void PrintTo (std::ostream &os) const;
|
||||
virtual uint32_t GetSerializedSize (void) const;
|
||||
virtual void SerializeTo (Buffer::Iterator start) const;
|
||||
|
|
|
@ -47,6 +47,12 @@ LlcSnapHeader::GetSerializedSize (void) const
|
|||
return 1 + 1 + 1 + 3 + 2;
|
||||
}
|
||||
|
||||
std::string
|
||||
LlcSnapHeader::DoGetName (void) const
|
||||
{
|
||||
return "LlcSnap";
|
||||
}
|
||||
|
||||
void
|
||||
LlcSnapHeader::PrintTo (std::ostream &os) const
|
||||
{
|
||||
|
|
|
@ -37,6 +37,7 @@ class LlcSnapHeader : public Header {
|
|||
uint16_t GetType (void);
|
||||
|
||||
private:
|
||||
virtual std::string DoGetName (void) const;
|
||||
virtual void PrintTo (std::ostream &os) const;
|
||||
virtual uint32_t GetSerializedSize (void) const;
|
||||
virtual void SerializeTo (Buffer::Iterator start) const;
|
||||
|
|
Loading…
Reference in New Issue