--- a/src/common/packet-history.cc Thu Jun 07 12:17:25 2007 +0200
+++ b/src/common/packet-history.cc Thu Jun 07 12:25:40 2007 +0200
@@ -35,6 +35,7 @@
uint32_t PacketHistory::m_maxSize = 0;
uint16_t PacketHistory::m_chunkUid = 0;
PacketHistory::DataFreeList PacketHistory::m_freeList;
+bool g_optOne = false;
void
PacketHistory::Enable (void)
@@ -42,6 +43,12 @@
m_enable = true;
}
+void
+PacketHistory::SetOptOne (bool optOne)
+{
+ g_optOne = optOne;
+}
+
void
PacketHistory::ReserveCopy (uint32_t size)
{
@@ -279,6 +286,71 @@
}
void
+PacketHistory::AppendValueExtra (uint32_t value, uint8_t *buffer)
+{
+ if (value < 0x200000)
+ {
+ uint8_t byte = value & (~0x80);
+ buffer[0] = 0x80 | byte;
+ value >>= 7;
+ byte = value & (~0x80);
+ buffer[1] = 0x80 | byte;
+ value >>= 7;
+ byte = value & (~0x80);
+ buffer[2] = value;
+ return;
+ }
+ if (value < 0x10000000)
+ {
+ uint8_t byte = value & (~0x80);
+ buffer[0] = 0x80 | byte;
+ value >>= 7;
+ byte = value & (~0x80);
+ buffer[1] = 0x80 | byte;
+ value >>= 7;
+ byte = value & (~0x80);
+ buffer[2] = 0x80 | byte;
+ value >>= 7;
+ buffer[3] = value;
+ return;
+ }
+ {
+ uint8_t byte = value & (~0x80);
+ buffer[0] = 0x80 | byte;
+ value >>= 7;
+ byte = value & (~0x80);
+ buffer[1] = 0x80 | byte;
+ value >>= 7;
+ byte = value & (~0x80);
+ buffer[2] = 0x80 | byte;
+ value >>= 7;
+ byte = value & (~0x80);
+ buffer[3] = 0x80 | byte;
+ value >>= 7;
+ buffer[4] = value;
+ }
+}
+
+void
+PacketHistory::AppendValue (uint32_t value, uint8_t *buffer)
+{
+ if (value < 0x80)
+ {
+ buffer[0] = value;
+ return;
+ }
+ if (value < 0x4000)
+ {
+ uint8_t byte = value & (~0x80);
+ buffer[0] = 0x80 | byte;
+ value >>= 7;
+ buffer[1] = value;
+ return;
+ }
+ AppendValueExtra (value, buffer);
+}
+
+void
PacketHistory::UpdateTail (uint16_t written)
{
if (m_head == 0xffff)
@@ -331,6 +403,35 @@
PacketHistory::AddSmall (const struct PacketHistory::SmallItem *item)
{
NS_ASSERT (m_data != 0);
+ if (g_optOne)
+ {
+ uint32_t typeUidSize = GetUleb128Size (item->typeUid);
+ uint32_t sizeSize = GetUleb128Size (item->size);
+ uint32_t n = typeUidSize + sizeSize + 2 + 2 + 2;
+ restart:
+ if (m_used + n <= m_data->m_size &&
+ (m_head == 0xffff ||
+ m_data->m_count == 1 ||
+ m_used == m_data->m_dirtyEnd))
+ {
+ uint8_t *buffer = &m_data->m_data[m_used];
+ Append16 (item->next, buffer);
+ buffer += 2;
+ Append16 (item->prev, buffer);
+ buffer += 2;
+ AppendValue (item->typeUid, buffer);
+ buffer += typeUidSize;
+ AppendValue (item->size, buffer);
+ buffer += sizeSize;
+ Append16 (item->chunkUid, buffer);
+ }
+ else
+ {
+ ReserveCopy (n);
+ goto restart;
+ }
+ return n;
+ }
append:
uint8_t *start = &m_data->m_data[m_used];
uint8_t *end = &m_data->m_data[m_data->m_size];
--- a/src/common/packet-history.h Thu Jun 07 12:17:25 2007 +0200
+++ b/src/common/packet-history.h Thu Jun 07 12:25:40 2007 +0200
@@ -27,10 +27,6 @@
#include "ns3/assert.h"
#include "packet-printer.h"
-namespace {
-class ItemList;
-}
-
namespace ns3 {
class Chunk;
@@ -39,6 +35,7 @@
class PacketHistory {
public:
static void Enable (void);
+ static void SetOptOne (bool optOne);
inline PacketHistory (uint32_t uid, uint32_t size);
inline PacketHistory (PacketHistory const &o);
@@ -64,6 +61,8 @@
void PrintDefault (std::ostream &os, Buffer buffer) const;
void Print (std::ostream &os, Buffer buffer, PacketPrinter const &printer) const;
+ static void PrintStats (void);
+
private:
/**
head -(next)-> tail
@@ -113,6 +112,8 @@
inline bool TryToAppendFast (uint32_t value, uint8_t **pBuffer, uint8_t *end);
inline bool TryToAppend32 (uint32_t value, uint8_t **pBuffer, uint8_t *end);
inline bool TryToAppend16 (uint16_t value, uint8_t **pBuffer, uint8_t *end);
+ void AppendValue (uint32_t value, uint8_t *buffer);
+ void AppendValueExtra (uint32_t value, uint8_t *buffer);
inline void Reserve (uint32_t n);
void ReserveCopy (uint32_t n);
uint32_t DoPrint (struct PacketHistory::SmallItem *item, uint32_t current,
--- a/utils/bench-packets.cc Thu Jun 07 12:17:25 2007 +0200
+++ b/utils/bench-packets.cc Thu Jun 07 12:25:40 2007 +0200
@@ -179,7 +179,7 @@
char const *nAscii = argv[0] + strlen ("--n=");
n = atoi (nAscii);
}
- if (strncmp ("--enable-history", argv[0], strlen ("--enable-metadata")) == 0)
+ if (strncmp ("--enable-metadata", argv[0], strlen ("--enable-metadata")) == 0)
{
Packet::EnableMetadata ();
}