24 #include "ns3/header.h" 
   25 #include "ns3/trailer.h" 
   26 #include "ns3/packet.h" 
   27 #include "ns3/packet-metadata.h" 
   48   static TypeId GetTypeId (
void);
 
   54   bool IsOk (
void) 
const;
 
   59   void ReportError (
void);
 
   65 HistoryHeaderBase::GetTypeId (
void)
 
   73 HistoryHeaderBase::HistoryHeaderBase ()
 
  109   virtual void Print (std::ostream &os) 
const;
 
  125   std::ostringstream oss;
 
  126   oss << 
"ns3::HistoryHeader<"<<N<<
">";
 
  128     .SetParent<HistoryHeaderBase> ()
 
  162   for (
int i = 0; i < N; i++)
 
  193   bool IsOk (
void) 
const;
 
  247   virtual void Print (std::ostream &os) 
const;
 
  262   std::ostringstream oss;
 
  263   oss << 
"ns3::HistoryTrailer<"<<N<<
">";
 
  265     .SetParent<HistoryTrailerBase> ()
 
  301   for (
int i = 0; i < N; i++)
 
  331   void CheckHistory (
Ptr<Packet> p, 
const char *
file, 
int line, uint32_t n, ...);
 
  332   virtual void DoRun (
void);
 
  354   std::list<int> expected;
 
  357   for (uint32_t j = 0; j < n; j++)
 
  359       int v = va_arg (ap, 
int);
 
  360       expected.push_back (v);
 
  369       if (item.
isFragment || item.
type == PacketMetadata::Item::PAYLOAD)
 
  374       if (item.
type == PacketMetadata::Item::HEADER)
 
  377           HistoryHeaderBase *header = 
dynamic_cast<HistoryHeaderBase *
> (constructor ());
 
  382           header->Deserialize (item.
current);
 
  383           if (!header->IsOk ())
 
  390       else if (item.
type == PacketMetadata::Item::TRAILER)
 
  393           HistoryTrailerBase *trailer = 
dynamic_cast<HistoryTrailerBase *
> (constructor ());
 
  398           trailer->Deserialize (item.
current);
 
  399           if (!trailer->IsOk ())
 
  409   for (std::list<int>::iterator i = got.begin (),
 
  410        j = expected.begin ();
 
  411        i != got.end (); i++, j++)
 
  421   std::ostringstream failure;
 
  422   failure << 
"PacketMetadata error. Got:\"";
 
  423   for (std::list<int>::iterator i = got.begin (); 
 
  424        i != got.end (); i++)
 
  426       failure << *i << 
", ";
 
  428   failure << 
"\", expected: \"";
 
  429   for (std::list<int>::iterator j = expected.begin ();
 
  430        j != expected.end (); j++)
 
  432       failure << *j << 
", ";
 
  438 #define ADD_HEADER(p, n)                                           \ 
  440     HistoryHeader<n> header;                                       \ 
  441     p->AddHeader (header);                                         \ 
  443 #define ADD_TRAILER(p, n)                                          \ 
  445     HistoryTrailer<n> trailer;                                     \ 
  446     p->AddTrailer (trailer);                                       \ 
  448 #define REM_HEADER(p, n)                                           \ 
  450     HistoryHeader<n> header;                                       \ 
  451     p->RemoveHeader (header);                                      \ 
  453 #define REM_TRAILER(p, n)                                          \ 
  455     HistoryTrailer<n> trailer;                                     \ 
  456     p->RemoveTrailer (trailer);                                    \ 
  458 #define CHECK_HISTORY(p, ...)                                      \ 
  460     CheckHistory (p, __FILE__, __LINE__, __VA_ARGS__);             \ 
  461     uint32_t size = p->GetSerializedSize ();                       \ 
  462     uint8_t* buffer = new uint8_t[size];                           \ 
  463     p->Serialize (buffer, size);                                   \ 
  464     Ptr<Packet> otherPacket = Create<Packet> (buffer, size, true); \ 
  466     CheckHistory (otherPacket, __FILE__, __LINE__, __VA_ARGS__);   \ 
  480   PacketMetadata::Enable ();
 
  485   p = Create<Packet> (10);
 
  490   p = Create<Packet> (10);
 
  503   p = Create<Packet> (10);
 
  511   p = Create<Packet> (10);
 
  520   p = Create<Packet> (10);
 
  529   p = Create<Packet> (10);
 
  554                  3, 3, 2, 1, 10, 4, 5);
 
  567   p1->RemoveAtStart (3);
 
  570   p1->RemoveAtStart (1);
 
  573   p1->RemoveAtStart (1);
 
  579   p1->RemoveAtStart (1);
 
  582   p = Create<Packet> (10);
 
  586   p->RemoveAtStart (8+10+8);
 
  589   p = Create<Packet> (10);
 
  595   p->RemoveAtStart (5);
 
  599   p = Create<Packet> (10);
 
  606   p->RemoveAtStart (12);
 
  618   p = Create<Packet> (40);
 
  622   p1 = p->CreateFragment (0, 5);
 
  635   p1 = p->CreateFragment (0, 5);
 
  638   p3 = Create<Packet> (50);
 
  650   p1->RemoveAtEnd (60);
 
  656   p3 = Create<Packet> (40);
 
  660   p1 = p3->CreateFragment (0, 5);
 
  667   p = Create<Packet> (0);
 
  670   p3 = Create<Packet> (0);
 
  674   p1 = p3->CreateFragment (0, 4);
 
  682   p = Create<Packet> (2000);
 
  685   p = Create<Packet> ();
 
  688   p1 = p->CreateFragment (0, 8);
 
  693   p = Create<Packet> ();
 
  699   p = Create<Packet> ();
 
  705   p = Create<Packet> ();
 
  710   p = Create<Packet> (10);
 
  714   p->RemoveAtStart (8+10+8);
 
  717   p = Create<Packet> (0);
 
  722   p = Create<Packet> (0);
 
  727   p = Create<Packet> (0);
 
  729   p->RemoveAtStart (8);
 
  732   p = Create<Packet> (0);
 
  739   p = Create<Packet> (0);
 
  746   p = Create<Packet> (0);
 
  750   p->RemoveAtStart (8);
 
  753   p = Create<Packet> (0);
 
  760   p = Create<Packet> (0);
 
  767   p = Create<Packet> (0);
 
  771   p->RemoveAtStart (8);
 
  774   p = Create<Packet> (16383);
 
  775   p = Create<Packet> (16384);
 
  780   p = Create<Packet> (40);
 
  790   p = Create<Packet> (1000);
 
  800   p = Create<Packet> (1510);
 
  805   p1 = p->CreateFragment (0, 1500);
 
  810   p = Create<Packet> (1000);
 
  820   p = Create<Packet> (200);
 
  822   p1 = p->CreateFragment (0, 100);
 
  823   p2 = p->CreateFragment (100, 100);
 
  826   p = Create<Packet> ();
 
  828   p1 = Create<Packet> ();
 
  833   p = Create<Packet> (500);
 
  842   p = Create<Packet> (500);
 
  848   p->RemoveAtStart (10);
 
  853   p = Create<Packet> (500);
 
  858   p1 = p->CreateFragment (0,6);
 
  859   p2 = p->CreateFragment (6,535-6);
 
  864   p = Create<Packet> (
reinterpret_cast<const uint8_t*
> (
"hello world"), 11);
 
  867   p1 = p->CreateFragment (0, 5);
 
  869   p2 = p->CreateFragment (5, 8);
 
  897   uint8_t *buf = 
new uint8_t[p3->GetSize ()];
 
  898   p3->CopyData (buf, p3->GetSize ());
 
  899   std::string msg = std::string (reinterpret_cast<const char *>(buf),
 
  902   NS_TEST_EXPECT_MSG_EQ (msg, std::string (
"hello world"), 
"Could not find original data in received packet");
 
TypeId AddConstructor(void)
Record in this TypeId the fact that the default constructor is accessible. 
 
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
 
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not. 
 
virtual void Serialize(Buffer::Iterator start) const 
 
Template trailer-type class to check the proper trailer concatenation. 
 
#define NS_TEST_ASSERT_MSG_EQ_INTERNAL(actual, limit, msg, file, line)
Test that an actual and expected (limit) value are equal and report and abort if not. 
 
iterator in a Buffer instance 
 
Callback< ObjectBase * > GetConstructor(void) const 
Get the constructor callback. 
 
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const 
Create a new packet which contains a fragment of the original packet. 
 
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet. 
 
void Prev(void)
go backward by one byte 
 
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite. 
 
virtual uint32_t Deserialize(Buffer::Iterator start)
 
virtual TypeId GetInstanceTypeId(void) const 
Get the most derived TypeId for this Object. 
 
Protocol trailer serialization and deserialization. 
 
Every class exported by the ns3 library is enclosed in the ns3 namespace. 
 
PacketMetadata::ItemIterator BeginItem(void) const 
Returns an iterator which points to the first 'item' stored in this buffer. 
 
void ReportError(void)
Signal that an error has been found in deserialization. 
 
virtual uint32_t GetSerializedSize(void) const 
 
bool IsOk(void) const 
Checks if the header has deserialization errors. 
 
void WriteU8(uint8_t data)
 
virtual void Print(std::ostream &os) const 
 
static TypeId GetTypeId(void)
Get the type ID. 
 
Base trailer-type class to check the proper trailer concatenation. 
 
a unique identifier for an interface. 
 
TypeId SetParent(TypeId tid)
Set the parent TypeId. 
 
bool m_ok
True if no error is signalled. 
 
static TypeId GetTypeId(void)
Get the type ID.