19 #include "ns3/header.h"
20 #include "ns3/packet-metadata.h"
21 #include "ns3/packet.h"
23 #include "ns3/trailer.h"
68 HistoryHeaderBase::GetTypeId()
74 HistoryHeaderBase::HistoryHeaderBase()
110 void Print(std::ostream& os)
const override;
126 std::ostringstream oss;
127 oss <<
"ns3::HistoryHeader<" << N <<
">";
165 for (
int i = 0; i < N; i++)
167 if (
start.ReadU8() != N)
252 void Print(std::ostream& os)
const override;
267 std::ostringstream oss;
268 oss <<
"ns3::HistoryTrailer<" << N <<
">";
308 for (
int i = 0; i < N; i++)
310 if (
start.ReadU8() != N)
338 void DoRun()
override;
361 std::list<int> expected;
364 for (uint32_t j = 0; j < n; j++)
366 int v = va_arg(ap,
int);
367 expected.push_back(v);
376 if (item.
isFragment || item.
type == PacketMetadata::Item::PAYLOAD)
381 if (item.
type == PacketMetadata::Item::HEADER)
384 auto header =
dynamic_cast<HistoryHeaderBase*
>(constructor());
385 if (header ==
nullptr)
389 header->Deserialize(item.
current);
397 else if (item.
type == PacketMetadata::Item::TRAILER)
400 auto trailer =
dynamic_cast<HistoryTrailerBase*
>(constructor());
401 if (trailer ==
nullptr)
405 trailer->Deserialize(item.
current);
406 if (!trailer->IsOk())
416 for (
auto i = got.begin(), j = expected.begin(); i != got.end(); i++, j++)
426 std::ostringstream failure;
427 failure <<
"PacketMetadata error. Got:\"";
428 for (
auto i = got.begin(); i != got.end(); i++)
430 failure << *i <<
", ";
432 failure <<
"\", expected: \"";
433 for (
auto j = expected.begin(); j != expected.end(); j++)
435 failure << *j <<
", ";
441 #define ADD_HEADER(p, n) \
443 HistoryHeader<n> header; \
444 p->AddHeader(header); \
446 #define ADD_TRAILER(p, n) \
448 HistoryTrailer<n> trailer; \
449 p->AddTrailer(trailer); \
451 #define REM_HEADER(p, n) \
453 HistoryHeader<n> header; \
454 p->RemoveHeader(header); \
456 #define REM_TRAILER(p, n) \
458 HistoryTrailer<n> trailer; \
459 p->RemoveTrailer(trailer); \
461 #define CHECK_HISTORY(p, ...) \
463 CheckHistory(p, __VA_ARGS__); \
464 uint32_t size = p->GetSerializedSize(); \
465 uint8_t* buffer = new uint8_t[size]; \
466 p->Serialize(buffer, size); \
467 Ptr<Packet> otherPacket = Create<Packet>(buffer, size, true); \
469 CheckHistory(otherPacket, __VA_ARGS__); \
482 PacketMetadata::Enable();
487 p = Create<Packet>(10);
491 p = Create<Packet>(10);
501 p = Create<Packet>(10);
508 p = Create<Packet>(10);
516 p = Create<Packet>(10);
525 p = Create<Packet>(10);
564 p = Create<Packet>(10);
571 p = Create<Packet>(10);
581 p = Create<Packet>(10);
600 p = Create<Packet>(40);
620 p3 = Create<Packet>(50);
638 p3 = Create<Packet>(40);
649 p = Create<Packet>(0);
652 p3 = Create<Packet>(0);
663 p = Create<Packet>(2000);
666 p = Create<Packet>();
674 p = Create<Packet>();
680 p = Create<Packet>();
686 p = Create<Packet>();
691 p = Create<Packet>(10);
698 p = Create<Packet>(0);
703 p = Create<Packet>(0);
708 p = Create<Packet>(0);
713 p = Create<Packet>(0);
720 p = Create<Packet>(0);
727 p = Create<Packet>(0);
734 p = Create<Packet>(0);
741 p = Create<Packet>(0);
748 p = Create<Packet>(0);
755 p = Create<Packet>(16383);
756 p = Create<Packet>(16384);
760 p = Create<Packet>(40);
769 p = Create<Packet>(1000);
778 p = Create<Packet>(1510);
788 p = Create<Packet>(1000);
798 p = Create<Packet>(200);
804 p = Create<Packet>();
806 p1 = Create<Packet>();
811 p = Create<Packet>(500);
820 p = Create<Packet>(500);
831 p = Create<Packet>(500);
842 p = Create<Packet>(
reinterpret_cast<const uint8_t*
>(
"hello world"), 11);
875 auto buf =
new uint8_t[p3->
GetSize()];
877 std::string msg = std::string(
reinterpret_cast<const char*
>(buf), p3->
GetSize());
880 std::string(
"hello world"),
881 "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
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
PacketMetadata::ItemIterator BeginItem() const
Returns an iterator which points to the first 'item' stored in this buffer.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
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.
Ptr< Packet > Copy() const
performs a COW copy of the packet.
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
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() 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.