8#include "ns3/packet-tag-list.h"
59 TypeId(
"ATestTagBase").
SetParent<
Tag>().SetGroupName(
"Network").HideFromDocumentation()
69 int result = (int)m_data;
95 std::ostringstream
oss;
96 oss <<
"anon::ATestTag<" <<
N <<
">";
99 .SetGroupName(
"Network")
100 .HideFromDocumentation()
112 return N +
sizeof(m_data);
137 void Print(std::ostream& os)
const override
139 os <<
N <<
"(" << m_data <<
")";
157#define LARGE_TAG_BUFFER_SIZE 64
189 .SetGroupName(
"Network")
190 .HideFromDocumentation()
208 for (uint8_t
i = 0;
i < (m_size - 1); ++
i)
217 for (uint8_t
i = 0;
i < (m_size - 1); ++
i)
224 void Print(std::ostream& os)
const override
226 os <<
"(" << (uint16_t)m_size <<
")";
259 .SetGroupName(
"Network")
260 .HideFromDocumentation()
287 std::ostringstream
oss;
288 oss <<
"anon::ATestHeader<" <<
N <<
">";
291 .SetGroupName(
"Network")
292 .HideFromDocumentation()
319 uint8_t v =
iter.ReadU8();
328 void Print(std::ostream& os)
const override
363 .SetGroupName(
"Network")
364 .HideFromDocumentation()
391 std::ostringstream
oss;
392 oss <<
"anon::ATestTrailer<" <<
N <<
">";
395 .SetGroupName(
"Network")
396 .HideFromDocumentation()
425 uint8_t v =
iter.ReadU8();
434 void Print(std::ostream& os)
const override
492#define E(name, start, end) name, start, end
495#define E_DATA(name, start, end, data) name, start, end, data
498#define CHECK(p, n, ...) DoCheck(p, n, __VA_ARGS__)
501#define CHECK_DATA(p, n, ...) DoCheckData(p, n, __VA_ARGS__)
513 void DoRun()
override;
558 std::ostringstream
oss;
559 oss <<
"anon::ATestTag<" << e.
n <<
">";
596 std::ostringstream
oss;
597 oss <<
"anon::ATestTag<" << e.
n <<
">";
619 packet->AddAtEnd(
pkt1);
620 packet->AddAtEnd(
pkt2);
624 auto buf =
new uint8_t[packet->GetSize()];
625 packet->CopyData(buf, packet->GetSize());
627 std::string
msg = std::string(
reinterpret_cast<const char*
>(buf), packet->GetSize());
635 CHECK(p, 1,
E(1, 0, 1000));
640 CHECK(p, 2,
E(1, 0, 1000),
E(2, 0, 1000));
651 CHECK(&
c0, 2,
E(1, 0, 1000),
E(10, 0, 1000));
660 CHECK(
frag0, 3,
E(1, 0, 10),
E(2, 0, 10),
E(3, 0, 10));
662 CHECK(
frag1, 3,
E(1, 0, 90),
E(2, 0, 90),
E(4, 0, 90));
664 CHECK(
frag2, 3,
E(1, 0, 900),
E(2, 0, 900),
E(5, 0, 900));
676 CHECK(
frag0, 3,
E(1, 0, 10),
E(2, 0, 10),
E(3, 0, 10));
697 CHECK(p, 1,
E(20, 0, 1000));
698 frag0 = p->CreateFragment(10, 90);
699 CHECK(p, 1,
E(20, 0, 1000));
712 tmp->RemoveHeader(
h);
723 tmp->RemoveTrailer(
t);
734 tmp->RemoveAtStart(120);
750 tmp->RemoveAtStart(1000);
773 copy.AddPacketTag(
c);
778 copy.RemovePacketTag(b);
798 p1->AddPacketTag(a1);
799 p1->AddPacketTag(
b1);
800 p1->AddPacketTag(
c1);
835 CHECK(
p1, 3,
E(10, 0, 1000),
E(11, 0, 1000),
E(12, 0, 1000));
860 tmp->RemoveAtStart(1);
874 tmp->RemoveAtStart(50);
886 tmp->RemoveAtEnd(50);
898 tmp->RemoveAtStart(50);
910 tmp->RemoveAtEnd(50);
922 tmp->RemoveAtEnd(50);
924 tmp->AddPaddingAtEnd(50);
936 tmp->RemoveAtEnd(50);
938 tmp->AddPaddingAtEnd(50);
946 tmp->AddPacketTag(
a);
963 void DoRun()
override;
1016 msg <<
": ref " <<
t.GetTypeId().GetName() <<
" = " <<
expect);
1021#define MAKE_TEST_TAGS \
1022 ATestTag<1> t1(1); \
1023 ATestTag<2> t2(1); \
1024 ATestTag<3> t3(1); \
1025 ATestTag<4> t4(1); \
1026 ATestTag<5> t5(1); \
1027 ATestTag<6> t6(1); \
1028 ATestTag<7> t7(1); \
1029 constexpr int TAG_LAST [[maybe_unused]] = 7;
1047 const int reps = 10000;
1049 int start = clock();
1050 for (
int i = 0;
i <
reps; ++
i)
1055 int delta = stop - start;
1058 std::cout <<
GetName() <<
"remove time: " <<
msg <<
": " << std::setw(8) << delta
1059 <<
" ticks to remove " <<
reps <<
" times" << std::endl;
1067 const int reps = 100000;
1070 int start = clock();
1071 for (
int i = 0;
i <
reps; ++
i)
1077 int delta = stop - start;
1080 std::cout <<
GetName() <<
"add/remove time: " << std::setw(8) << delta
1081 <<
" ticks to add+remove " <<
reps <<
" times" << std::endl;
1089 std::cout <<
GetName() <<
"begin" << std::endl;
1104 std::cout <<
GetName() <<
"check Peek (missing tag) returns false" << std::endl;
1111 std::cout <<
GetName() <<
"check copy and assignment" << std::endl;
1130#define RemoveCheck(n) \
1131 PacketTagList p##n = ref; \
1132 p##n.Remove(t##n); \
1133 CheckRefList(ref, "remove " #n " orig"); \
1134 CheckRefList(p##n, "remove " #n " copy", n);
1138 std::cout <<
GetName() <<
"check removal of each tag" << std::endl;
1150 std::cout <<
GetName() <<
"check removal doesn't disturb merge " << std::endl;
1165 const char*
msg =
"post merge, short chain";
1177 std::cout <<
GetName() <<
"check replacing each tag" << std::endl;
1179#define ReplaceCheck(n) \
1182 PacketTagList p##n = ref; \
1183 p##n.Replace(t##n); \
1184 CheckRefList(ref, "replace " #n " orig"); \
1185 CheckRef(p##n, t##n, "replace " #n " copy"); \
1199 std::cout <<
GetName() <<
"add+remove timing" << std::endl;
1200 int flm = std::numeric_limits<int>::max();
1210 std::cout <<
GetName() <<
"min add+remove time: " << std::setw(8) <<
flm <<
" ticks"
1213 std::cout <<
GetName() <<
"remove timing" << std::endl;
1215 std::vector<int>
rmn(
TAG_LAST + 1, std::numeric_limits<int>::max());
1254 std::cout <<
GetName() <<
"min remove time: t" <<
j <<
": " << std::setw(8) <<
rmn[
j]
1255 <<
" ticks" << std::endl;
Packet Tag list unit tests.
void CheckRefList(const PacketTagList &ref, const char *msg, int miss=0)
Checks against a reference PacketTagList.
~PacketTagListTest() override
int AddRemoveTime(const bool verbose=false)
Prints the remove time.
void DoRun() override
Implementation to actually run this TestCase.
void CheckRef(const PacketTagList &ref, ATestTagBase &t, const char *msg, bool miss=false)
Checks against a reference PacketTagList.
int RemoveTime(const PacketTagList &ref, ATestTagBase &t, const char *msg=nullptr)
Prints the remove time.
void DoCheckData(Ptr< const Packet > p, uint32_t n,...)
Checks the packet and its data.
void DoRun() override
Implementation to actually run this TestCase.
void DoCheck(Ptr< const Packet > p, uint32_t n,...)
Checks the packet.
Template class for Large Test tags.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
static TypeId GetTypeId()
Register this type.
uint8_t m_size
Packet size.
void Serialize(TagBuffer buf) const override
void Print(std::ostream &os) const override
uint32_t GetSerializedSize() const override
std::vector< uint8_t > m_data
Tag data.
void Deserialize(TagBuffer buf) override
Base class for Test tags.
bool m_error
Error in the Tag.
static TypeId GetTypeId()
Register this type.
int GetData() const
Get the tag data.
ATestTagBase(uint8_t data)
Constructor.
Template class for Test tags.
ATestTag(uint8_t data)
Constructor.
void Serialize(TagBuffer buf) const override
static TypeId GetTypeId()
Register this type.
void Print(std::ostream &os) const override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void Deserialize(TagBuffer buf) override
uint32_t GetSerializedSize() const override
Base class for Test trailers.
bool m_error
Error in the Trailer.
static TypeId GetTypeId()
Register this type.
Template class for Test trailers.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void Print(std::ostream &os) const override
uint32_t GetSerializedSize() const override
static TypeId GetTypeId()
Register this type.
uint32_t Deserialize(Buffer::Iterator iter) override
void Serialize(Buffer::Iterator iter) const override
iterator in a Buffer instance
Identifies a byte tag and a set of bytes within a packet to which the tag applies.
Iterator over the set of byte tags in a packet.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
void RemoveAllPacketTags()
Remove all packet tags.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
List of the packet tags stored in a packet.
bool Remove(Tag &tag)
Remove (the first instance of) tag from the list.
void Add(const Tag &tag) const
Add a tag to the head of this branch.
Smart pointer class similar to boost::intrusive_ptr.
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
TAG_BUFFER_INLINE uint8_t ReadU8()
tag a set of bytes in a packet
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
std::string GetName() const
Protocol trailer serialization and deserialization.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report 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.
#define LARGE_TAG_BUFFER_SIZE
static PacketTestSuite g_packetTestSuite
Static variable for test initialization.
#define E_DATA(name, start, end, data)
#define E(name, start, end)
#define CHECK_DATA(p, n,...)
Struct to hold the expected data in the packet.
uint8_t data
Optional data.
Expected(uint32_t n_, uint32_t start_, uint32_t end_, uint8_t data_)
Constructor.
uint32_t n
Number of elements.
Expected(uint32_t n_, uint32_t start_, uint32_t end_)
Constructor.