8#include "ns3/packet-tag-list.h" 
   59            TypeId(
"ATestTagBase").
SetParent<
Tag>().SetGroupName(
"Network").HideFromDocumentation()
 
 
 
   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;
 
 
  540    std::vector<Expected> expected;
 
  548        expected.emplace_back(N, start, end);
 
  554    while (i.
HasNext() && j < expected.size())
 
  558        std::ostringstream oss;
 
  559        oss << 
"anon::ATestTag<" << e.
n << 
">";
 
 
  577    std::vector<Expected> expected;
 
  585        int data = va_arg(ap, 
int);
 
  586        expected.emplace_back(N, start, end, 
data);
 
  592    while (i.
HasNext() && j < expected.size())
 
  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));
 
  637    CHECK(copy, 1, 
E(1, 0, 1000));
 
  640    CHECK(p, 2, 
E(1, 0, 1000), 
E(2, 0, 1000));
 
  641    CHECK(copy, 1, 
E(1, 0, 1000));
 
  647        CHECK(&c0, 1, 
E(1, 0, 1000));
 
  648        CHECK(&c1, 1, 
E(1, 0, 1000));
 
  649        CHECK(copy, 1, 
E(1, 0, 1000));
 
  651        CHECK(&c0, 2, 
E(1, 0, 1000), 
E(10, 0, 1000));
 
  652        CHECK(&c1, 1, 
E(1, 0, 1000));
 
  653        CHECK(copy, 1, 
E(1, 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));
 
  666    frag1->AddAtEnd(frag2);
 
  676    CHECK(frag0, 3, 
E(1, 0, 10), 
E(2, 0, 10), 
E(3, 0, 10));
 
  677    frag0->AddAtEnd(frag1);
 
  697    CHECK(p, 1, 
E(20, 0, 1000));
 
  698    frag0 = p->CreateFragment(10, 90);
 
  699    CHECK(p, 1, 
E(20, 0, 1000));
 
  700    CHECK(frag0, 1, 
E(20, 0, 90));
 
  703    CHECK(frag0, 1, 
E(20, 10, 100));
 
  708        CHECK(tmp, 1, 
E(20, 0, 100));
 
  710        CHECK(tmp, 1, 
E(20, 10, 110));
 
  712        tmp->RemoveHeader(h);
 
  713        CHECK(tmp, 1, 
E(20, 0, 100));
 
  715        CHECK(tmp, 1, 
E(20, 10, 110));
 
  719        CHECK(tmp, 1, 
E(20, 0, 100));
 
  721        CHECK(tmp, 1, 
E(20, 0, 100));
 
  723        tmp->RemoveTrailer(t);
 
  724        CHECK(tmp, 1, 
E(20, 0, 100));
 
  726        CHECK(tmp, 1, 
E(20, 0, 100));
 
  733        CHECK(tmp, 1, 
E(20, 0, 156));
 
  734        tmp->RemoveAtStart(120);
 
  735        CHECK(tmp, 1, 
E(20, 0, 36));
 
  738        CHECK(a, 1, 
E(20, 0, 36));
 
  744        CHECK(tmp, 0, 
E(20, 0, 0));
 
  749        CHECK(tmp, 1, 
E(20, 0, 1000));
 
  750        tmp->RemoveAtStart(1000);
 
  751        CHECK(tmp, 0, 
E(0, 0, 0));
 
  754        CHECK(a, 1, 
E(10, 0, 10));
 
  756        CHECK(tmp, 1, 
E(10, 0, 10));
 
  798        p1->AddPacketTag(a1);
 
  799        p1->AddPacketTag(b1);
 
  800        p1->AddPacketTag(c1);
 
  802        uint32_t serializedSize = p1->GetSerializedSize();
 
  803        auto buffer = 
new uint8_t[serializedSize + 16];
 
  804        p1->Serialize(buffer, serializedSize);
 
  835        CHECK(p1, 3, 
E(10, 0, 1000), 
E(11, 0, 1000), 
E(12, 0, 1000));
 
  837        uint32_t serializedSize = p1->GetSerializedSize();
 
  838        auto buffer = 
new uint8_t[serializedSize];
 
  839        p1->Serialize(buffer, serializedSize);
 
  857        CHECK(tmp, 1, 
E(20, 0, 1000));
 
  859        CHECK(tmp, 1, 
E(20, 2, 1002));
 
  860        tmp->RemoveAtStart(1);
 
  861        CHECK(tmp, 1, 
E(20, 1, 1001));
 
  864    CHECK (tmp, 1, 
E (20, 1, 1001));
 
  873        CHECK(tmp, 1, 
E(25, 0, 100));
 
  874        tmp->RemoveAtStart(50);
 
  875        CHECK(tmp, 1, 
E(25, 0, 50));
 
  877        CHECK(tmp, 1, 
E(25, 50, 100));
 
  885        CHECK(tmp, 1, 
E(25, 0, 100));
 
  886        tmp->RemoveAtEnd(50);
 
  887        CHECK(tmp, 1, 
E(25, 0, 50));
 
  889        CHECK(tmp, 1, 
E(25, 0, 50));
 
  897        CHECK(tmp, 1, 
E(25, 0, 100));
 
  898        tmp->RemoveAtStart(50);
 
  899        CHECK(tmp, 1, 
E(25, 0, 50));
 
  901        CHECK(tmp, 1, 
E(25, 25, 75));
 
  909        CHECK(tmp, 1, 
E(25, 0, 100));
 
  910        tmp->RemoveAtEnd(50);
 
  911        CHECK(tmp, 1, 
E(25, 0, 50));
 
  913        CHECK(tmp, 1, 
E(25, 0, 50));
 
  921        CHECK(tmp, 1, 
E(25, 0, 100));
 
  922        tmp->RemoveAtEnd(50);
 
  923        CHECK(tmp, 1, 
E(25, 0, 50));
 
  924        tmp->AddPaddingAtEnd(50);
 
  925        CHECK(tmp, 1, 
E(25, 0, 50));
 
  935        CHECK(tmp, 1, 
E(25, 0, 100));
 
  936        tmp->RemoveAtEnd(50);
 
  937        CHECK(tmp, 1, 
E(25, 0, 50));
 
  938        tmp->AddPaddingAtEnd(50);
 
  939        CHECK(tmp, 1, 
E(25, 0, 50));
 
  946        tmp->AddPacketTag(a);
 
 
  963    void DoRun() 
override;
 
 
 1010    bool found = ref.
Peek(t); 
 
 
 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;
 
 1048    std::vector<PacketTagList> ptv(reps, ref);
 
 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();
 
 1201        const int nIterations = 100;
 
 1202        for (
int i = 0; i < nIterations; ++i)
 
 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());
 
 1216        for (
int i = 0; i < nIterations; ++i)
 
 1218            for (
int j = 1; j <= TAG_LAST; ++j)
 
 1252        for (
int j = TAG_LAST; j > 0; --j)
 
 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
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
void WriteU8(uint8_t data)
void Prev()
go backward by one byte
Identifies a byte tag and a set of bytes within a packet to which the tag applies.
uint32_t GetEnd() const
The index is an offset from the start of the packet.
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
uint32_t GetStart() const
The index is an offset from the start of the packet.
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.
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
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.
bool Peek(Tag &tag) const
Find a tag and return its value.
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.
TestCase(const TestCase &)=delete
std::string GetName() const
@ UNIT
This test suite implements a Unit Test.
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Protocol trailer serialization and deserialization.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
std::string GetName() const
Get the name.
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.