change default pretty printing output format, add doc to metadata data structures
--- a/src/common/packet-metadata.cc Wed Jun 27 20:51:07 2007 +0200
+++ b/src/common/packet-metadata.cc Thu Jun 28 11:07:38 2007 +0200
@@ -953,13 +953,14 @@
// payload.
printer.PrintPayload (os, extraItem.packetUid, item->size,
extraItem.fragmentStart,
- extraItem.fragmentEnd);
+ item->size - extraItem.fragmentEnd);
}
else if (extraItem.fragmentStart != 0 ||
extraItem.fragmentEnd != item->size)
{
printer.PrintChunkFragment (uid, os, extraItem.packetUid, item->size,
- extraItem.fragmentStart, extraItem.fragmentEnd);
+ extraItem.fragmentStart,
+ item->size - extraItem.fragmentEnd);
}
else if (PacketPrinter::IsHeader (uid))
{
--- a/src/common/packet-metadata.h Wed Jun 27 20:51:07 2007 +0200
+++ b/src/common/packet-metadata.h Thu Jun 28 11:07:38 2007 +0200
@@ -66,27 +66,71 @@
static void PrintStats (void);
private:
- /**
- head -(next)-> tail
- ^ |
- \---(prev)---|
- */
struct Data {
+ /* number of references to this struct Data instance. */
uint16_t m_count;
+ /* size (in bytes) of m_data buffer below */
uint16_t m_size;
+ /* max of the m_used field over all objects which
+ * reference this struct Data instance */
uint16_t m_dirtyEnd;
+ /* variable-sized buffer of bytes */
uint8_t m_data[10];
};
+ /* Note that since the next and prev fields are 16 bit integers
+ and since the value 0xffff is reserved to identify the
+ fact that the end or the start of the list is reached,
+ only a limited number of elements can be stored in
+ a m_data byte buffer.
+ */
struct SmallItem {
+ /* offset (in bytes) from start of m_data buffer
+ to next element in linked list. value is 0xffff
+ if next element does not exist.
+ */
uint16_t next;
+ /* offset (in bytes) from start of m_data buffer
+ to previous element in linked list. value is 0xffff
+ if previous element does not exist.
+ */
uint16_t prev;
+ /* the high 31 bits of this field identify the
+ type of the header or trailer represented by
+ this item: the value zero represents payload.
+ If the low bit of this uid is one, an ExtraItem
+ structure follows this SmallItem structure.
+ */
uint32_t typeUid;
+ /* the size (in bytes) of the header or trailer represented
+ by this element.
+ */
uint32_t size;
+ /* this field tries to uniquely identify each header or
+ trailer _instance_ while the typeUid field uniquely
+ identifies each header or trailer _type_. This field
+ is used to test whether two items are equal in the sense
+ that they represent the same header or trailer instance.
+ That equality test is based on the typeUid and chunkUid
+ fields so, the likelyhood that two header instances
+ share the same chunkUid _and_ typeUid is very small
+ unless they are really representations of the same header
+ instance.
+ */
uint16_t chunkUid;
};
struct ExtraItem {
+ /* offset (in bytes) from start of original header to
+ the start of the fragment still present.
+ */
uint32_t fragmentStart;
+ /* offset (in bytes) from start of original header to
+ the end of the fragment still present.
+ */
uint32_t fragmentEnd;
+ /* the packetUid of the packet in which this header or trailer
+ was first added. It could be different from the m_packetUid
+ field if the user has aggregated multiple packets into one.
+ */
uint32_t packetUid;
};
@@ -138,6 +182,11 @@
static uint16_t m_chunkUid;
struct Data *m_data;
+ /**
+ head -(next)-> tail
+ ^ |
+ \---(prev)---|
+ */
uint16_t m_head;
uint16_t m_tail;
uint16_t m_used;
--- a/src/common/packet-printer.cc Wed Jun 27 20:51:07 2007 +0200
+++ b/src/common/packet-printer.cc Thu Jun 28 11:07:38 2007 +0200
@@ -78,7 +78,7 @@
static PacketPrinter tmp;
tmp.PrintForward ();
tmp.AddPayloadPrinter (MakeCallback (&PacketPrinter::DoDefaultPrintPayload));
- tmp.SetSeparator ("\n");
+ tmp.SetSeparator (" ");
return &tmp;
}
@@ -158,9 +158,15 @@
uint32_t size,
struct PacketPrinter::FragmentInformation info)
{
- os << "data ";
- os << "[" << info.start << ":" << info.end << "] -> "
- << "[0:" << size << "]";
+ os << "DATA ("
+ << "length " << size - (info.end + info.start);
+ if (info.start != 0 || info.end != 0)
+ {
+ os << " "
+ << "trim_start " << info.start << " "
+ << "trim_end " << info.end;
+ }
+ os << ")";
}
void
@@ -180,9 +186,14 @@
std::string &name,
struct PacketPrinter::FragmentInformation info)
{
- os << name << " ";
- os << "[" << info.start << ":" << info.end << "] -> "
- << "[0:" << size << "]";
+ NS_ASSERT (info.start != 0 || info.end != 0);
+ os << name << " "
+ << "("
+ << "length " << size - (info.end + info.start) << " "
+ << "trim_start " << info.start << " "
+ << "trim_end " << info.end
+ << ")"
+ ;
}
void
--- a/src/common/packet-printer.h Wed Jun 27 20:51:07 2007 +0200
+++ b/src/common/packet-printer.h Thu Jun 28 11:07:38 2007 +0200
@@ -43,9 +43,19 @@
class PacketPrinter
{
public:
+ /**
+ * \brief indicates how many bytes were trimmed from a header
+ * or a trailer.
+ */
struct FragmentInformation
{
+ /**
+ * The number of bytes trimmed from the start of the header or the trailer.
+ */
uint32_t start;
+ /**
+ * The number of bytes trimmed from the end of the header or the trailer.
+ */
uint32_t end;
};
/**
@@ -297,6 +307,7 @@
void
PacketPrinter::DoDefaultPrint (std::ostream &os, uint32_t packetUid, uint32_t size, const T *chunk)
{
+ os << chunk->GetName () << " ";
chunk->Print (os);
}
--- a/src/internet-node/ipv4-header.cc Wed Jun 27 20:51:07 2007 +0200
+++ b/src/internet-node/ipv4-header.cc Thu Jun 28 11:07:38 2007 +0200
@@ -28,17 +28,6 @@
namespace ns3 {
-static uint16_t
-UtilsNtoh16 (uint16_t v)
-{
- uint16_t val;
- uint8_t *array;
- array = (uint8_t *)&v;
- val = (array[0] << 8) | (array[1] << 0);
- return val;
-}
-
-
bool Ipv4Header::m_calcChecksum = false;
Ipv4Header::Ipv4Header ()
@@ -193,24 +182,45 @@
std::string
Ipv4Header::DoGetName (void) const
{
- return "Ipv4";
+ return "IPV4";
}
void
Ipv4Header::PrintTo (std::ostream &os) const
{
// ipv4, right ?
- os << "(ipv4)"
- << " tos=" << (uint32_t)m_tos
- << ", payload length=" << UtilsNtoh16 (m_payloadSize)
- << ", id=" << m_identification
- << ", " << (IsLastFragment ()?"last":"more")
- << ", " << (IsDontFragment ()?"dont":"may")
- << ", frag offset=" << m_fragmentOffset
- << ", ttl=" << m_ttl
- << ", protocol=" << m_protocol
- << ", source=" << m_source
- << ", destination=" << m_destination;
+ std::string flags;
+ if (m_flags == 0)
+ {
+ flags = "none";
+ }
+ else if (m_flags & MORE_FRAGMENTS &&
+ m_flags & DONT_FRAGMENT)
+ {
+ flags = "MF|DF";
+ }
+ else if (m_flags & DONT_FRAGMENT)
+ {
+ flags = "DF";
+ }
+ else if (m_flags & MORE_FRAGMENTS)
+ {
+ flags = "MF";
+ }
+ else
+ {
+ flags = "XX";
+ }
+ os << "("
+ << "tos 0x" << std::hex << m_tos << std::dec << " "
+ << "ttl " << m_ttl << " "
+ << "id " << m_identification << " "
+ << "offset " << m_fragmentOffset << " "
+ << "flags [" << flags << "] "
+ << "length: " << (m_payloadSize + 5 * 4)
+ << ") "
+ << m_source << " > " << m_destination
+ ;
}
uint32_t
Ipv4Header::GetSerializedSize (void) const
--- a/src/internet-node/udp-header.cc Wed Jun 27 20:51:07 2007 +0200
+++ b/src/internet-node/udp-header.cc Thu Jun 28 11:07:38 2007 +0200
@@ -94,16 +94,17 @@
std::string
UdpHeader::DoGetName (void) const
{
- return "Udp";
+ return "UDP";
}
void
UdpHeader::PrintTo (std::ostream &os) const
{
- os << "(udp)"
- << ", port source=" << m_sourcePort
- << ", port destination=" << m_destinationPort
- << ", length=" << m_payloadSize;
+ os << "("
+ << "length: " << m_payloadSize + GetSize ()
+ << ") "
+ << m_sourcePort << " > " << m_destinationPort
+ ;
}
uint32_t
--- a/src/node/llc-snap-header.cc Wed Jun 27 20:51:07 2007 +0200
+++ b/src/node/llc-snap-header.cc Thu Jun 28 11:07:38 2007 +0200
@@ -50,17 +50,17 @@
std::string
LlcSnapHeader::DoGetName (void) const
{
- return "LlcSnap";
+ return "LLCSNAP";
}
void
LlcSnapHeader::PrintTo (std::ostream &os) const
{
- os << "(mac)"
- << " EtherType: ";
+ os << "(type 0x";
os.setf (std::ios::hex, std::ios::basefield);
os << m_etherType;
os.setf (std::ios::dec, std::ios::basefield);
+ os << ")";
}
void