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)
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);
582 p = Create<Packet> (10);
589 p = Create<Packet> (10);
599 p = Create<Packet> (10);
618 p = Create<Packet> (40);
638 p3 = Create<Packet> (50);
656 p3 = Create<Packet> (40);
667 p = Create<Packet> (0);
670 p3 = Create<Packet> (0);
682 p = Create<Packet> (2000);
685 p = Create<Packet> ();
693 p = Create<Packet> ();
699 p = Create<Packet> ();
705 p = Create<Packet> ();
710 p = Create<Packet> (10);
717 p = Create<Packet> (0);
722 p = Create<Packet> (0);
727 p = Create<Packet> (0);
732 p = Create<Packet> (0);
739 p = Create<Packet> (0);
746 p = Create<Packet> (0);
753 p = Create<Packet> (0);
760 p = Create<Packet> (0);
767 p = Create<Packet> (0);
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);
810 p = Create<Packet> (1000);
820 p = Create<Packet> (200);
826 p = Create<Packet> ();
828 p1 = Create<Packet> ();
833 p = Create<Packet> (500);
842 p = Create<Packet> (500);
853 p = Create<Packet> (500);
864 p = Create<Packet> (
reinterpret_cast<const uint8_t*
> (
"hello world"), 11);
897 uint8_t *buf =
new uint8_t[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");
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_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
#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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.