9#include "ns3/packet-metadata.h"
10#include "ns3/packet.h"
12#include "ns3/trailer.h"
99 void Print(std::ostream& os)
const override;
115 std::ostringstream
oss;
116 oss <<
"ns3::HistoryHeader<" <<
N <<
">";
154 for (
int i = 0;
i <
N;
i++)
156 if (start.ReadU8() !=
N)
241 void Print(std::ostream& os)
const override;
256 std::ostringstream
oss;
257 oss <<
"ns3::HistoryTrailer<" <<
N <<
">";
297 for (
int i = 0;
i <
N;
i++)
299 if (start.ReadU8() !=
N)
327 void DoRun()
override;
367 got.push_back(
item.currentSize);
374 if (header ==
nullptr)
378 header->Deserialize(
item.current);
402 got.push_back(
item.currentSize);
415 std::ostringstream failure;
416 failure <<
"PacketMetadata error. Got:\"";
417 for (
auto i =
got.begin();
i !=
got.end();
i++)
419 failure << *
i <<
", ";
421 failure <<
"\", expected: \"";
424 failure << *
j <<
", ";
430#define ADD_HEADER(p, n) \
432 HistoryHeader<n> header; \
433 p->AddHeader(header); \
435#define ADD_TRAILER(p, n) \
437 HistoryTrailer<n> trailer; \
438 p->AddTrailer(trailer); \
440#define REM_HEADER(p, n) \
442 HistoryHeader<n> header; \
443 p->RemoveHeader(header); \
445#define REM_TRAILER(p, n) \
447 HistoryTrailer<n> trailer; \
448 p->RemoveTrailer(trailer); \
450#define CHECK_HISTORY(p, ...) \
452 CheckHistory(p, __VA_ARGS__); \
453 uint32_t size = p->GetSerializedSize(); \
454 uint8_t* buffer = new uint8_t[size]; \
455 p->Serialize(buffer, size); \
456 Ptr<Packet> otherPacket = Create<Packet>(buffer, size, true); \
458 CheckHistory(otherPacket, __VA_ARGS__); \
542 p1->RemoveAtStart(3);
544 p1->RemoveAtStart(1);
546 p1->RemoveAtStart(1);
550 p1->RemoveAtStart(1);
557 p->RemoveAtStart(8 + 10 + 8);
577 p->RemoveAtStart(12);
593 p1 = p->CreateFragment(0, 5);
594 p2 = p->CreateFragment(5, 5);
595 p3 = p->CreateFragment(10, 43);
606 p1 = p->CreateFragment(0, 5);
631 p1 =
p3->CreateFragment(0, 5);
632 p2 =
p3->CreateFragment(5, 5);
645 p1 =
p3->CreateFragment(0, 4);
646 p2 =
p3->CreateFragment(9, 1);
658 p1 = p->CreateFragment(0, 8);
659 p2 = p->CreateFragment(8, 7);
684 p->RemoveAtStart(8 + 10 + 8);
750 p2 = p->CreateFragment(5, 5);
751 p3 = p->CreateFragment(10, 30);
772 p1 = p->CreateFragment(0, 1500);
789 p1 = p->CreateFragment(0, 100);
790 p2 = p->CreateFragment(100, 100);
815 p->RemoveAtStart(10);
825 p1 = p->CreateFragment(0, 6);
826 p2 = p->CreateFragment(6, 535 - 6);
831 p =
Create<Packet>(
reinterpret_cast<const uint8_t*
>(
"hello world"), 11);
834 p1 = p->CreateFragment(0, 5);
836 p2 = p->CreateFragment(5, 8);
864 auto buf =
new uint8_t[
p3->GetSize()];
865 p3->CopyData(buf,
p3->GetSize());
866 std::string
msg = std::string(
reinterpret_cast<const char*
>(buf),
p3->GetSize());
869 std::string(
"hello world"),
870 "Could not find original data in received packet");
Base trailer-type class to check the proper trailer concatenation.
void ReportError()
Signal that an error has been found in deserialization.
bool m_ok
True if no error is signalled.
static TypeId GetTypeId()
Get the type ID.
bool IsOk() const
Checks if the header has deserialization errors.
Template trailer-type class to check the proper trailer concatenation.
uint32_t Deserialize(Buffer::Iterator start) override
static TypeId GetTypeId()
Get the type ID.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint32_t GetSerializedSize() const override
void Print(std::ostream &os) const override
void Serialize(Buffer::Iterator start) const override
iterator in a Buffer instance
Smart pointer class similar to boost::intrusive_ptr.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Protocol trailer serialization and deserialization.
a unique identifier for an interface.
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,...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
#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.