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<<
">";
156 start.WriteU8 (N, N);
162 for (
int i = 0; i < N; i++)
164 if (
start.ReadU8 () != N)
193 bool IsOk (
void)
const;
247 virtual void Print (std::ostream &os)
const;
262 std::ostringstream oss;
263 oss <<
"ns3::HistoryTrailer<"<<N<<
">";
294 start.WriteU8 (N, N);
301 for (
int i = 0; i < N; i++)
303 if (
start.ReadU8 () != N)
329 void CheckHistory (
Ptr<Packet> p, uint32_t n, ...);
330 virtual void DoRun (
void);
352 std::list<int> expected;
355 for (uint32_t j = 0; j < n; j++)
357 int v = va_arg (ap,
int);
358 expected.push_back (v);
367 if (item.
isFragment || item.
type == PacketMetadata::Item::PAYLOAD)
372 if (item.
type == PacketMetadata::Item::HEADER)
375 HistoryHeaderBase *header =
dynamic_cast<HistoryHeaderBase *
> (constructor ());
380 header->Deserialize (item.
current);
381 if (!header->IsOk ())
388 else if (item.
type == PacketMetadata::Item::TRAILER)
391 HistoryTrailerBase *trailer =
dynamic_cast<HistoryTrailerBase *
> (constructor ());
396 trailer->Deserialize (item.
current);
397 if (!trailer->IsOk ())
407 for (std::list<int>::iterator i = got.begin (),
408 j = expected.begin ();
409 i != got.end (); i++, j++)
419 std::ostringstream failure;
420 failure <<
"PacketMetadata error. Got:\"";
421 for (std::list<int>::iterator i = got.begin ();
422 i != got.end (); i++)
424 failure << *i <<
", ";
426 failure <<
"\", expected: \"";
427 for (std::list<int>::iterator j = expected.begin ();
428 j != expected.end (); j++)
430 failure << *j <<
", ";
436 #define ADD_HEADER(p, n) \
438 HistoryHeader<n> header; \
439 p->AddHeader (header); \
441 #define ADD_TRAILER(p, n) \
443 HistoryTrailer<n> trailer; \
444 p->AddTrailer (trailer); \
446 #define REM_HEADER(p, n) \
448 HistoryHeader<n> header; \
449 p->RemoveHeader (header); \
451 #define REM_TRAILER(p, n) \
453 HistoryTrailer<n> trailer; \
454 p->RemoveTrailer (trailer); \
456 #define CHECK_HISTORY(p, ...) \
458 CheckHistory (p, __VA_ARGS__); \
459 uint32_t size = p->GetSerializedSize (); \
460 uint8_t* buffer = new uint8_t[size]; \
461 p->Serialize (buffer, size); \
462 Ptr<Packet> otherPacket = Create<Packet> (buffer, size, true); \
464 CheckHistory (otherPacket, __VA_ARGS__); \
478 PacketMetadata::Enable ();
483 p = Create<Packet> (10);
488 p = Create<Packet> (10);
501 p = Create<Packet> (10);
509 p = Create<Packet> (10);
518 p = Create<Packet> (10);
527 p = Create<Packet> (10);
552 3, 3, 2, 1, 10, 4, 5);
580 p = Create<Packet> (10);
587 p = Create<Packet> (10);
597 p = Create<Packet> (10);
616 p = Create<Packet> (40);
636 p3 = Create<Packet> (50);
654 p3 = Create<Packet> (40);
665 p = Create<Packet> (0);
668 p3 = Create<Packet> (0);
680 p = Create<Packet> (2000);
683 p = Create<Packet> ();
691 p = Create<Packet> ();
697 p = Create<Packet> ();
703 p = Create<Packet> ();
708 p = Create<Packet> (10);
715 p = Create<Packet> (0);
720 p = Create<Packet> (0);
725 p = Create<Packet> (0);
730 p = Create<Packet> (0);
737 p = Create<Packet> (0);
744 p = Create<Packet> (0);
751 p = Create<Packet> (0);
758 p = Create<Packet> (0);
765 p = Create<Packet> (0);
772 p = Create<Packet> (16383);
773 p = Create<Packet> (16384);
778 p = Create<Packet> (40);
788 p = Create<Packet> (1000);
798 p = Create<Packet> (1510);
808 p = Create<Packet> (1000);
818 p = Create<Packet> (200);
824 p = Create<Packet> ();
826 p1 = Create<Packet> ();
831 p = Create<Packet> (500);
840 p = Create<Packet> (500);
851 p = Create<Packet> (500);
862 p = Create<Packet> (
reinterpret_cast<const uint8_t*
> (
"hello world"), 11);
895 uint8_t *buf =
new uint8_t[p3->
GetSize ()];
897 std::string msg = std::string (
reinterpret_cast<const char *
>(buf),
900 NS_TEST_EXPECT_MSG_EQ (msg, std::string (
"hello world"),
"Could not find original data in received packet");
Base trailer-type class to check the proper trailer concatenation.
void ReportError(void)
Signal that an error has been found in deserialization.
bool IsOk(void) const
Checks if the header has deserialization errors.
bool m_ok
True if no error is signalled.
static TypeId GetTypeId(void)
Get the type ID.
Template trailer-type class to check the proper trailer concatenation.
virtual void Serialize(Buffer::Iterator start) const
static TypeId GetTypeId(void)
Get the type ID.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
virtual uint32_t Deserialize(Buffer::Iterator start)
virtual void Print(std::ostream &os) const
virtual uint32_t GetSerializedSize(void) const
iterator in a Buffer instance
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
void RemoveAtEnd(uint32_t size)
Remove size bytes from the end of the current packet.
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
PacketMetadata::ItemIterator BeginItem(void) const
Returns an iterator which points to the first 'item' stored in this buffer.
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Protocol trailer serialization and deserialization.
a unique identifier for an interface.
Callback< ObjectBase * > GetConstructor(void) const
Get the constructor callback.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Every class exported by the ns3 library is enclosed in the ns3 namespace.