--- a/src/mesh/model/mesh-information-element-vector.cc Mon Mar 28 15:09:39 2011 -0700
+++ b/src/mesh/model/mesh-information-element-vector.cc Mon Mar 28 16:43:20 2011 -0700
@@ -21,7 +21,6 @@
#include "mesh-information-element-vector.h"
#include "ns3/packet.h"
#include <algorithm>
-#include "ns3/test.h"
#include "ns3/hwmp-protocol.h"
// All information elements:
#include "ns3/ie-dot11s-beacon-timing.h"
@@ -93,126 +92,4 @@
}
-// Unit tests
-//-----------------------------------------------------------------------------
-/// Built-in self test for MeshInformationElementVector and all IE
-struct MeshInformationElementVectorBist : public TestCase
-{
- MeshInformationElementVectorBist () :
- TestCase ("Serializarion test for all mesh information elements")
- {
- };
- void DoRun ();
-};
-
-void
-MeshInformationElementVectorBist::DoRun ()
-{
- MeshInformationElementVector vector;
- {
- //Mesh ID test
- Ptr<dot11s::IeMeshId> meshId = Create<dot11s::IeMeshId> ("qwerty");
- vector.AddInformationElement (meshId);
- }
- {
- Ptr<dot11s::IeConfiguration> config = Create<dot11s::IeConfiguration> ();
- vector.AddInformationElement (config);
- }
- {
- Ptr<dot11s::IeLinkMetricReport> report = Create<dot11s::IeLinkMetricReport> (123456);
- vector.AddInformationElement (report);
- }
- {
- Ptr<dot11s::IePeerManagement> peerMan1 = Create<dot11s::IePeerManagement> ();
- peerMan1->SetPeerOpen (1);
- Ptr<dot11s::IePeerManagement> peerMan2 = Create<dot11s::IePeerManagement> ();
- peerMan2->SetPeerConfirm (1, 2);
- Ptr<dot11s::IePeerManagement> peerMan3 = Create<dot11s::IePeerManagement> ();
- peerMan3->SetPeerClose (1, 2, dot11s::REASON11S_MESH_CAPABILITY_POLICY_VIOLATION);
- vector.AddInformationElement (peerMan1);
- vector.AddInformationElement (peerMan2);
- vector.AddInformationElement (peerMan3);
- }
- {
- Ptr<dot11s::IeBeaconTiming> beaconTiming = Create<dot11s::IeBeaconTiming> ();
- beaconTiming->AddNeighboursTimingElementUnit (1, Seconds (1.0), Seconds (4.0));
- beaconTiming->AddNeighboursTimingElementUnit (2, Seconds (2.0), Seconds (3.0));
- beaconTiming->AddNeighboursTimingElementUnit (3, Seconds (3.0), Seconds (2.0));
- beaconTiming->AddNeighboursTimingElementUnit (4, Seconds (4.0), Seconds (1.0));
- vector.AddInformationElement (beaconTiming);
- }
- {
- Ptr<dot11s::IeRann> rann = Create<dot11s::IeRann> ();
- rann->SetFlags (1);
- rann->SetHopcount (2);
- rann->SetTTL (4);
- rann->DecrementTtl ();
- NS_TEST_ASSERT_MSG_EQ (rann->GetTtl (), 3, "SetTtl works");
- rann->SetOriginatorAddress (Mac48Address ("11:22:33:44:55:66"));
- rann->SetDestSeqNumber (5);
- rann->SetMetric (6);
- rann->IncrementMetric (2);
- NS_TEST_ASSERT_MSG_EQ (rann->GetMetric (), 8, "SetMetric works");
- vector.AddInformationElement (rann);
- }
- {
- Ptr<dot11s::IePreq> preq = Create<dot11s::IePreq> ();
- preq->SetHopcount (0);
- preq->SetTTL (1);
- preq->SetPreqID (2);
- preq->SetOriginatorAddress (Mac48Address ("11:22:33:44:55:66"));
- preq->SetOriginatorSeqNumber (3);
- preq->SetLifetime (4);
- preq->AddDestinationAddressElement (false, false, Mac48Address ("11:11:11:11:11:11"), 5);
- preq->AddDestinationAddressElement (false, false, Mac48Address ("22:22:22:22:22:22"), 6);
- vector.AddInformationElement (preq);
- }
- {
- Ptr<dot11s::IePrep> prep = Create<dot11s::IePrep> ();
- prep->SetFlags (12);
- prep->SetHopcount (11);
- prep->SetTtl (10);
- prep->SetDestinationAddress (Mac48Address ("11:22:33:44:55:66"));
- prep->SetDestinationSeqNumber (123);
- prep->SetLifetime (5000);
- prep->SetMetric (4321);
- prep->SetOriginatorAddress (Mac48Address ("33:00:22:00:11:00"));
- prep->SetOriginatorSeqNumber (666);
- vector.AddInformationElement (prep);
- }
- {
- Ptr<dot11s::IePerr> perr = Create<dot11s::IePerr> ();
- dot11s::HwmpProtocol::FailedDestination dest;
- dest.destination = Mac48Address ("11:22:33:44:55:66");
- dest.seqnum = 1;
- perr->AddAddressUnit (dest);
- dest.destination = Mac48Address ("10:20:30:40:50:60");
- dest.seqnum = 2;
- perr->AddAddressUnit (dest);
- dest.destination = Mac48Address ("01:02:03:04:05:06");
- dest.seqnum = 3;
- perr->AddAddressUnit (dest);
- vector.AddInformationElement (perr);
- }
- Ptr<Packet> packet = Create<Packet> ();
- packet->AddHeader (vector);
- MeshInformationElementVector resultVector;
- packet->RemoveHeader (resultVector);
- NS_TEST_ASSERT_MSG_EQ (vector, resultVector, "Roundtrip serialization of all known information elements works");
-}
-
-class MeshTestSuite : public TestSuite
-{
-public:
- MeshTestSuite ();
-};
-
-MeshTestSuite::MeshTestSuite ()
- : TestSuite ("devices-mesh", UNIT)
-{
- AddTestCase (new MeshInformationElementVectorBist);
-}
-
-static MeshTestSuite g_meshTestSuite;
-
} //namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/mesh/test/mesh-information-element-vector-test-suite.cc Mon Mar 28 16:43:20 2011 -0700
@@ -0,0 +1,159 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 IITP RAS
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Pavel Boyko <boyko@iitp.ru>
+ */
+
+#include "ns3/test.h"
+#include "ns3/mesh-information-element-vector.h"
+// All information elements:
+#include "ns3/ie-dot11s-beacon-timing.h"
+#include "ns3/ie-dot11s-configuration.h"
+#include "ns3/ie-dot11s-id.h"
+#include "ns3/ie-dot11s-metric-report.h"
+#include "ns3/ie-dot11s-peer-management.h"
+#include "ns3/ie-dot11s-peering-protocol.h"
+#include "ns3/ie-dot11s-perr.h"
+#include "ns3/ie-dot11s-prep.h"
+#include "ns3/ie-dot11s-preq.h"
+#include "ns3/ie-dot11s-rann.h"
+
+namespace ns3 {
+
+// Unit tests
+//-----------------------------------------------------------------------------
+/// Built-in self test for MeshInformationElementVector and all IE
+struct MeshInformationElementVectorBist : public TestCase
+{
+ MeshInformationElementVectorBist () :
+ TestCase ("Serializarion test for all mesh information elements")
+ {
+ };
+ void DoRun ();
+};
+
+void
+MeshInformationElementVectorBist::DoRun ()
+{
+ MeshInformationElementVector vector;
+ {
+ //Mesh ID test
+ Ptr<dot11s::IeMeshId> meshId = Create<dot11s::IeMeshId> ("qwerty");
+ vector.AddInformationElement (meshId);
+ }
+ {
+ Ptr<dot11s::IeConfiguration> config = Create<dot11s::IeConfiguration> ();
+ vector.AddInformationElement (config);
+ }
+ {
+ Ptr<dot11s::IeLinkMetricReport> report = Create<dot11s::IeLinkMetricReport> (123456);
+ vector.AddInformationElement (report);
+ }
+ {
+ Ptr<dot11s::IePeerManagement> peerMan1 = Create<dot11s::IePeerManagement> ();
+ peerMan1->SetPeerOpen (1);
+ Ptr<dot11s::IePeerManagement> peerMan2 = Create<dot11s::IePeerManagement> ();
+ peerMan2->SetPeerConfirm (1, 2);
+ Ptr<dot11s::IePeerManagement> peerMan3 = Create<dot11s::IePeerManagement> ();
+ peerMan3->SetPeerClose (1, 2, dot11s::REASON11S_MESH_CAPABILITY_POLICY_VIOLATION);
+ vector.AddInformationElement (peerMan1);
+ vector.AddInformationElement (peerMan2);
+ vector.AddInformationElement (peerMan3);
+ }
+ {
+ Ptr<dot11s::IeBeaconTiming> beaconTiming = Create<dot11s::IeBeaconTiming> ();
+ beaconTiming->AddNeighboursTimingElementUnit (1, Seconds (1.0), Seconds (4.0));
+ beaconTiming->AddNeighboursTimingElementUnit (2, Seconds (2.0), Seconds (3.0));
+ beaconTiming->AddNeighboursTimingElementUnit (3, Seconds (3.0), Seconds (2.0));
+ beaconTiming->AddNeighboursTimingElementUnit (4, Seconds (4.0), Seconds (1.0));
+ vector.AddInformationElement (beaconTiming);
+ }
+ {
+ Ptr<dot11s::IeRann> rann = Create<dot11s::IeRann> ();
+ rann->SetFlags (1);
+ rann->SetHopcount (2);
+ rann->SetTTL (4);
+ rann->DecrementTtl ();
+ NS_TEST_ASSERT_MSG_EQ (rann->GetTtl (), 3, "SetTtl works");
+ rann->SetOriginatorAddress (Mac48Address ("11:22:33:44:55:66"));
+ rann->SetDestSeqNumber (5);
+ rann->SetMetric (6);
+ rann->IncrementMetric (2);
+ NS_TEST_ASSERT_MSG_EQ (rann->GetMetric (), 8, "SetMetric works");
+ vector.AddInformationElement (rann);
+ }
+ {
+ Ptr<dot11s::IePreq> preq = Create<dot11s::IePreq> ();
+ preq->SetHopcount (0);
+ preq->SetTTL (1);
+ preq->SetPreqID (2);
+ preq->SetOriginatorAddress (Mac48Address ("11:22:33:44:55:66"));
+ preq->SetOriginatorSeqNumber (3);
+ preq->SetLifetime (4);
+ preq->AddDestinationAddressElement (false, false, Mac48Address ("11:11:11:11:11:11"), 5);
+ preq->AddDestinationAddressElement (false, false, Mac48Address ("22:22:22:22:22:22"), 6);
+ vector.AddInformationElement (preq);
+ }
+ {
+ Ptr<dot11s::IePrep> prep = Create<dot11s::IePrep> ();
+ prep->SetFlags (12);
+ prep->SetHopcount (11);
+ prep->SetTtl (10);
+ prep->SetDestinationAddress (Mac48Address ("11:22:33:44:55:66"));
+ prep->SetDestinationSeqNumber (123);
+ prep->SetLifetime (5000);
+ prep->SetMetric (4321);
+ prep->SetOriginatorAddress (Mac48Address ("33:00:22:00:11:00"));
+ prep->SetOriginatorSeqNumber (666);
+ vector.AddInformationElement (prep);
+ }
+ {
+ Ptr<dot11s::IePerr> perr = Create<dot11s::IePerr> ();
+ dot11s::HwmpProtocol::FailedDestination dest;
+ dest.destination = Mac48Address ("11:22:33:44:55:66");
+ dest.seqnum = 1;
+ perr->AddAddressUnit (dest);
+ dest.destination = Mac48Address ("10:20:30:40:50:60");
+ dest.seqnum = 2;
+ perr->AddAddressUnit (dest);
+ dest.destination = Mac48Address ("01:02:03:04:05:06");
+ dest.seqnum = 3;
+ perr->AddAddressUnit (dest);
+ vector.AddInformationElement (perr);
+ }
+ Ptr<Packet> packet = Create<Packet> ();
+ packet->AddHeader (vector);
+ MeshInformationElementVector resultVector;
+ packet->RemoveHeader (resultVector);
+ NS_TEST_ASSERT_MSG_EQ (vector, resultVector, "Roundtrip serialization of all known information elements works");
+}
+
+class MeshTestSuite : public TestSuite
+{
+public:
+ MeshTestSuite ();
+};
+
+MeshTestSuite::MeshTestSuite ()
+ : TestSuite ("devices-mesh", UNIT)
+{
+ AddTestCase (new MeshInformationElementVectorBist);
+}
+
+static MeshTestSuite g_meshTestSuite;
+
+} //namespace ns3
--- a/src/mesh/wscript Mon Mar 28 15:09:39 2011 -0700
+++ b/src/mesh/wscript Mon Mar 28 16:43:20 2011 -0700
@@ -40,6 +40,7 @@
obj_test = bld.create_ns3_module_test_library('mesh')
obj_test.source = [
+ 'test/mesh-information-element-vector-test-suite.cc',
'test/dot11s/dot11s-test-suite.cc',
'test/dot11s/pmp-regression.cc',
'test/dot11s/hwmp-reactive-regression.cc',
--- a/src/network/model/packet.cc Mon Mar 28 15:09:39 2011 -0700
+++ b/src/network/model/packet.cc Mon Mar 28 16:43:20 2011 -0700
@@ -21,7 +21,6 @@
#include "ns3/assert.h"
#include "ns3/log.h"
#include "ns3/simulator.h"
-#include "ns3/test.h"
#include <string>
#include <stdarg.h>
@@ -897,431 +896,4 @@
return os;
}
-//-----------------------------------------------------------------------------
-// Unit tests
-//-----------------------------------------------------------------------------
-namespace {
-
-class ATestTagBase : public Tag
-{
-public:
- ATestTagBase () : m_error (false) {}
- bool m_error;
-};
-
-template <int N>
-class ATestTag : public ATestTagBase
-{
-public:
- static TypeId GetTypeId (void) {
- std::ostringstream oss;
- oss << "anon::ATestTag<" << N << ">";
- static TypeId tid = TypeId (oss.str ().c_str ())
- .SetParent<Tag> ()
- .AddConstructor<ATestTag<N> > ()
- .HideFromDocumentation ()
- ;
- return tid;
- }
- virtual TypeId GetInstanceTypeId (void) const {
- return GetTypeId ();
- }
- virtual uint32_t GetSerializedSize (void) const {
- return N;
- }
- virtual void Serialize (TagBuffer buf) const {
- for (uint32_t i = 0; i < N; ++i)
- {
- buf.WriteU8 (N);
- }
- }
- virtual void Deserialize (TagBuffer buf) {
- for (uint32_t i = 0; i < N; ++i)
- {
- uint8_t v = buf.ReadU8 ();
- if (v != N)
- {
- m_error = true;
- }
- }
- }
- virtual void Print (std::ostream &os) const {
- os << N;
- }
- ATestTag ()
- : ATestTagBase () {}
-};
-
-class ATestHeaderBase : public Header
-{
-public:
- ATestHeaderBase () : Header (), m_error (false) {}
- bool m_error;
-};
-
-template <int N>
-class ATestHeader : public ATestHeaderBase
-{
-public:
- static TypeId GetTypeId (void) {
- std::ostringstream oss;
- oss << "anon::ATestHeader<" << N << ">";
- static TypeId tid = TypeId (oss.str ().c_str ())
- .SetParent<Header> ()
- .AddConstructor<ATestHeader<N> > ()
- .HideFromDocumentation ()
- ;
- return tid;
- }
- virtual TypeId GetInstanceTypeId (void) const {
- return GetTypeId ();
- }
- virtual uint32_t GetSerializedSize (void) const {
- return N;
- }
- virtual void Serialize (Buffer::Iterator iter) const {
- for (uint32_t i = 0; i < N; ++i)
- {
- iter.WriteU8 (N);
- }
- }
- virtual uint32_t Deserialize (Buffer::Iterator iter) {
- for (uint32_t i = 0; i < N; ++i)
- {
- uint8_t v = iter.ReadU8 ();
- if (v != N)
- {
- m_error = true;
- }
- }
- return N;
- }
- virtual void Print (std::ostream &os) const {
- }
- ATestHeader ()
- : ATestHeaderBase () {}
-
-};
-
-class ATestTrailerBase : public Trailer
-{
-public:
- ATestTrailerBase () : Trailer (), m_error (false) {}
- bool m_error;
-};
-
-template <int N>
-class ATestTrailer : public ATestTrailerBase
-{
-public:
- static TypeId GetTypeId (void) {
- std::ostringstream oss;
- oss << "anon::ATestTrailer<" << N << ">";
- static TypeId tid = TypeId (oss.str ().c_str ())
- .SetParent<Header> ()
- .AddConstructor<ATestTrailer<N> > ()
- .HideFromDocumentation ()
- ;
- return tid;
- }
- virtual TypeId GetInstanceTypeId (void) const {
- return GetTypeId ();
- }
- virtual uint32_t GetSerializedSize (void) const {
- return N;
- }
- virtual void Serialize (Buffer::Iterator iter) const {
- iter.Prev (N);
- for (uint32_t i = 0; i < N; ++i)
- {
- iter.WriteU8 (N);
- }
- }
- virtual uint32_t Deserialize (Buffer::Iterator iter) {
- iter.Prev (N);
- for (uint32_t i = 0; i < N; ++i)
- {
- uint8_t v = iter.ReadU8 ();
- if (v != N)
- {
- m_error = true;
- }
- }
- return N;
- }
- virtual void Print (std::ostream &os) const {
- }
- ATestTrailer ()
- : ATestTrailerBase () {}
-
-};
-
-
-struct Expected
-{
- Expected (uint32_t n_, uint32_t start_, uint32_t end_)
- : n (n_), start (start_), end (end_) {}
-
- uint32_t n;
- uint32_t start;
- uint32_t end;
-};
-
-}
-
-// tag name, start, end
-#define E(a,b,c) a,b,c
-
-#define CHECK(p, n, ...) \
- DoCheck (p, __FILE__, __LINE__, n, __VA_ARGS__)
-
-class PacketTest : public TestCase
-{
-public:
- PacketTest ();
- virtual void DoRun (void);
-private:
- void DoCheck (Ptr<const Packet> p, const char *file, int line, uint32_t n, ...);
-};
-
-
-PacketTest::PacketTest ()
- : TestCase ("Packet") {
-}
-
-void
-PacketTest::DoCheck (Ptr<const Packet> p, const char *file, int line, uint32_t n, ...)
-{
- std::vector<struct Expected> expected;
- va_list ap;
- va_start (ap, n);
- for (uint32_t k = 0; k < n; ++k)
- {
- uint32_t N = va_arg (ap, uint32_t);
- uint32_t start = va_arg (ap, uint32_t);
- uint32_t end = va_arg (ap, uint32_t);
- expected.push_back (Expected (N, start, end));
- }
- va_end (ap);
-
- ByteTagIterator i = p->GetByteTagIterator ();
- uint32_t j = 0;
- while (i.HasNext () && j < expected.size ())
- {
- ByteTagIterator::Item item = i.Next ();
- struct Expected e = expected[j];
- std::ostringstream oss;
- oss << "anon::ATestTag<" << e.n << ">";
- NS_TEST_EXPECT_MSG_EQ_INTERNAL (item.GetTypeId ().GetName (), oss.str (), "trivial", file, line);
- NS_TEST_EXPECT_MSG_EQ_INTERNAL (item.GetStart (), e.start, "trivial", file, line);
- NS_TEST_EXPECT_MSG_EQ_INTERNAL (item.GetEnd (), e.end, "trivial", file, line);
- ATestTagBase *tag = dynamic_cast<ATestTagBase *> (item.GetTypeId ().GetConstructor () ());
- NS_TEST_EXPECT_MSG_NE (tag, 0, "trivial");
- item.GetTag (*tag);
- NS_TEST_EXPECT_MSG_EQ (tag->m_error, false, "trivial");
- delete tag;
- j++;
- }
- NS_TEST_EXPECT_MSG_EQ (i.HasNext (), false, "Nothing left");
- NS_TEST_EXPECT_MSG_EQ (j, expected.size (), "Size match");
-}
-
-void
-PacketTest::DoRun (void)
-{
- Ptr<Packet> pkt1 = Create<Packet> (reinterpret_cast<const uint8_t*> ("hello"), 5);
- Ptr<Packet> pkt2 = Create<Packet> (reinterpret_cast<const uint8_t*> (" world"), 6);
- Ptr<Packet> packet = Create<Packet> ();
- packet->AddAtEnd (pkt1);
- packet->AddAtEnd (pkt2);
-
- NS_TEST_EXPECT_MSG_EQ (packet->GetSize (), 11, "trivial");
-
- uint8_t *buf = new uint8_t[packet->GetSize ()];
- packet->CopyData (buf, packet->GetSize ());
-
- std::string msg = std::string (reinterpret_cast<const char *>(buf),
- packet->GetSize ());
- delete [] buf;
-
- NS_TEST_EXPECT_MSG_EQ (msg, "hello world", "trivial");
-
-
- Ptr<const Packet> p = Create<Packet> (1000);
-
- p->AddByteTag (ATestTag<1> ());
- CHECK (p, 1, E (1, 0, 1000));
- Ptr<const Packet> copy = p->Copy ();
- CHECK (copy, 1, E (1, 0, 1000));
-
- p->AddByteTag (ATestTag<2> ());
- CHECK (p, 2, E (1, 0, 1000), E(2, 0, 1000));
- CHECK (copy, 1, E (1, 0, 1000));
-
- {
- Packet c0 = *copy;
- Packet c1 = *copy;
- c0 = c1;
- CHECK (&c0, 1, E (1, 0, 1000));
- CHECK (&c1, 1, E (1, 0, 1000));
- CHECK (copy, 1, E (1, 0, 1000));
- c0.AddByteTag (ATestTag<10> ());
- CHECK (&c0, 2, E (1, 0, 1000), E (10, 0, 1000));
- CHECK (&c1, 1, E (1, 0, 1000));
- CHECK (copy, 1, E (1, 0, 1000));
- }
-
- Ptr<Packet> frag0 = p->CreateFragment (0, 10);
- Ptr<Packet> frag1 = p->CreateFragment (10, 90);
- Ptr<const Packet> frag2 = p->CreateFragment (100, 900);
- frag0->AddByteTag (ATestTag<3> ());
- CHECK (frag0, 3, E (1, 0, 10), E(2, 0, 10), E (3, 0, 10));
- frag1->AddByteTag (ATestTag<4> ());
- CHECK (frag1, 3, E (1, 0, 90), E(2, 0, 90), E (4, 0, 90));
- frag2->AddByteTag (ATestTag<5> ());
- CHECK (frag2, 3, E (1, 0, 900), E(2, 0, 900), E (5, 0, 900));
-
- frag1->AddAtEnd (frag2);
- CHECK (frag1, 6, E (1, 0, 90), E(2, 0, 90), E (4, 0, 90), E (1, 90, 990), E(2, 90, 990), E (5, 90, 990));
-
- CHECK (frag0, 3, E (1, 0, 10), E(2, 0, 10), E (3, 0, 10));
- frag0->AddAtEnd (frag1);
- CHECK (frag0, 9,
- E (1, 0, 10), E(2, 0, 10), E (3, 0, 10),
- E (1, 10, 100), E(2, 10, 100), E (4, 10, 100),
- E (1, 100, 1000), E(2, 100, 1000), E (5, 100, 1000));
-
-
- // force caching a buffer of the right size.
- frag0 = Create<Packet> (1000);
- frag0->AddHeader (ATestHeader<10> ());
- frag0 = 0;
-
- p = Create<Packet> (1000);
- p->AddByteTag (ATestTag<20> ());
- CHECK (p, 1, E (20, 0, 1000));
- frag0 = p->CreateFragment (10, 90);
- CHECK (p, 1, E (20, 0, 1000));
- CHECK (frag0, 1, E (20, 0, 90));
- p = 0;
- frag0->AddHeader (ATestHeader<10> ());
- CHECK (frag0, 1, E (20, 10, 100));
-
- {
- Ptr<Packet> tmp = Create<Packet> (100);
- tmp->AddByteTag (ATestTag<20> ());
- CHECK (tmp, 1, E (20, 0, 100));
- tmp->AddHeader (ATestHeader<10> ());
- CHECK (tmp, 1, E (20, 10, 110));
- ATestHeader<10> h;
- tmp->RemoveHeader (h);
- CHECK (tmp, 1, E (20, 0, 100));
- tmp->AddHeader (ATestHeader<10> ());
- CHECK (tmp, 1, E (20, 10, 110));
-
- tmp = Create<Packet> (100);
- tmp->AddByteTag (ATestTag<20> ());
- CHECK (tmp, 1, E (20, 0, 100));
- tmp->AddTrailer (ATestTrailer<10> ());
- CHECK (tmp, 1, E (20, 0, 100));
- ATestTrailer<10> t;
- tmp->RemoveTrailer (t);
- CHECK (tmp, 1, E (20, 0, 100));
- tmp->AddTrailer (ATestTrailer<10> ());
- CHECK (tmp, 1, E (20, 0, 100));
-
- }
-
- {
- Ptr<Packet> tmp = Create<Packet> (0);
- tmp->AddHeader (ATestHeader<156> ());
- tmp->AddByteTag (ATestTag<20> ());
- CHECK (tmp, 1, E (20, 0, 156));
- tmp->RemoveAtStart (120);
- CHECK (tmp, 1, E (20, 0, 36));
- Ptr<Packet> a = Create<Packet> (0);
- a->AddAtEnd (tmp);
- CHECK (a, 1, E (20, 0, 36));
- }
-
- {
- Ptr<Packet> tmp = Create<Packet> (0);
- tmp->AddByteTag (ATestTag<20> ());
- CHECK (tmp, 0, E (20, 0, 0));
- }
- {
- Ptr<Packet> tmp = Create<Packet> (1000);
- tmp->AddByteTag (ATestTag<20> ());
- CHECK (tmp, 1, E (20, 0, 1000));
- tmp->RemoveAtStart (1000);
- CHECK (tmp, 0, E (0,0,0));
- Ptr<Packet> a = Create<Packet> (10);
- a->AddByteTag (ATestTag<10> ());
- CHECK (a, 1, E (10, 0, 10));
- tmp->AddAtEnd (a);
- CHECK (tmp, 1, E (10, 0, 10));
- }
-
- {
- Packet p;
- ATestTag<10> a;
- p.AddPacketTag (a);
- NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (a), true, "trivial");
- ATestTag<11> b;
- p.AddPacketTag (b);
- NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (b), true, "trivial");
- NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (a), true, "trivial");
- Packet copy = p;
- NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (b), true, "trivial");
- NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (a), true, "trivial");
- ATestTag<12> c;
- NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (c), false, "trivial");
- copy.AddPacketTag (c);
- NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (c), true, "trivial");
- NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (b), true, "trivial");
- NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (a), true, "trivial");
- NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (c), false, "trivial");
- copy.RemovePacketTag (b);
- NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (b), false, "trivial");
- NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (b), true, "trivial");
- p.RemovePacketTag (a);
- NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (a), false, "trivial");
- NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (a), true, "trivial");
- NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (c), false, "trivial");
- NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (c), true, "trivial");
- p.RemoveAllPacketTags ();
- NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (b), false, "trivial");
- }
-
- {
- // bug 572
- Ptr<Packet> tmp = Create<Packet> (1000);
- tmp->AddByteTag (ATestTag<20> ());
- CHECK (tmp, 1, E (20, 0, 1000));
- tmp->AddHeader (ATestHeader<2> ());
- CHECK (tmp, 1, E (20, 2, 1002));
- tmp->RemoveAtStart (1);
- CHECK (tmp, 1, E (20, 1, 1001));
-#if 0
- tmp->PeekData ();
- CHECK (tmp, 1, E (20, 1, 1001));
-#endif
- }
-}
-//-----------------------------------------------------------------------------
-class PacketTestSuite : public TestSuite
-{
-public:
- PacketTestSuite ();
-};
-
-PacketTestSuite::PacketTestSuite ()
- : TestSuite ("packet", UNIT)
-{
- AddTestCase (new PacketTest);
-}
-
-static PacketTestSuite g_packetTestSuite;
-
-
} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/network/test/drop-tail-queue-test-suite.cc Mon Mar 28 16:43:20 2011 -0700
@@ -0,0 +1,89 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "ns3/test.h"
+#include "ns3/drop-tail-queue.h"
+#include "ns3/uinteger.h"
+
+namespace ns3 {
+
+class DropTailQueueTestCase : public TestCase
+{
+public:
+ DropTailQueueTestCase ();
+ virtual void DoRun (void);
+};
+
+DropTailQueueTestCase::DropTailQueueTestCase ()
+ : TestCase ("Sanity check on the drop tail queue implementation")
+{}
+void
+DropTailQueueTestCase::DoRun (void)
+{
+ Ptr<DropTailQueue> queue = CreateObject<DropTailQueue> ();
+ NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MaxPackets", UintegerValue (3)), true,
+ "Verify that we can actually set the attribute");
+
+ Ptr<Packet> p1, p2, p3, p4;
+ p1 = Create<Packet> ();
+ p2 = Create<Packet> ();
+ p3 = Create<Packet> ();
+ p4 = Create<Packet> ();
+
+ NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 0, "There should be no packets in there");
+ queue->Enqueue (p1);
+ NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 1, "There should be one packet in there");
+ queue->Enqueue (p2);
+ NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 2, "There should be two packets in there");
+ queue->Enqueue (p3);
+ NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be three packets in there");
+ queue->Enqueue (p4); // will be dropped
+ NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be still three packets in there");
+
+ Ptr<Packet> p;
+
+ p = queue->Dequeue ();
+ NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the first packet");
+ NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 2, "There should be two packets in there");
+ NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p1->GetUid (), "was this the first packet ?");
+
+ p = queue->Dequeue ();
+ NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the second packet");
+ NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 1, "There should be one packet in there");
+ NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p2->GetUid (), "Was this the second packet ?");
+
+ p = queue->Dequeue ();
+ NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the third packet");
+ NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 0, "There should be no packets in there");
+ NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p3->GetUid (), "Was this the third packet ?");
+
+ p = queue->Dequeue ();
+ NS_TEST_EXPECT_MSG_EQ ((p == 0), true, "There are really no packets in there");
+}
+
+static class DropTailQueueTestSuite : public TestSuite
+{
+public:
+ DropTailQueueTestSuite ()
+ : TestSuite ("drop-tail-queue", UNIT)
+ {
+ AddTestCase (new DropTailQueueTestCase ());
+ }
+} g_dropTailQueueTestSuite;
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/network/test/packet-test-suite.cc Mon Mar 28 16:43:20 2011 -0700
@@ -0,0 +1,454 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#include "ns3/packet.h"
+#include "ns3/test.h"
+#include <string>
+#include <stdarg.h>
+
+namespace ns3 {
+
+//-----------------------------------------------------------------------------
+// Unit tests
+//-----------------------------------------------------------------------------
+namespace {
+
+class ATestTagBase : public Tag
+{
+public:
+ ATestTagBase () : m_error (false) {}
+ bool m_error;
+};
+
+template <int N>
+class ATestTag : public ATestTagBase
+{
+public:
+ static TypeId GetTypeId (void) {
+ std::ostringstream oss;
+ oss << "anon::ATestTag<" << N << ">";
+ static TypeId tid = TypeId (oss.str ().c_str ())
+ .SetParent<Tag> ()
+ .AddConstructor<ATestTag<N> > ()
+ .HideFromDocumentation ()
+ ;
+ return tid;
+ }
+ virtual TypeId GetInstanceTypeId (void) const {
+ return GetTypeId ();
+ }
+ virtual uint32_t GetSerializedSize (void) const {
+ return N;
+ }
+ virtual void Serialize (TagBuffer buf) const {
+ for (uint32_t i = 0; i < N; ++i)
+ {
+ buf.WriteU8 (N);
+ }
+ }
+ virtual void Deserialize (TagBuffer buf) {
+ for (uint32_t i = 0; i < N; ++i)
+ {
+ uint8_t v = buf.ReadU8 ();
+ if (v != N)
+ {
+ m_error = true;
+ }
+ }
+ }
+ virtual void Print (std::ostream &os) const {
+ os << N;
+ }
+ ATestTag ()
+ : ATestTagBase () {}
+};
+
+class ATestHeaderBase : public Header
+{
+public:
+ ATestHeaderBase () : Header (), m_error (false) {}
+ bool m_error;
+};
+
+template <int N>
+class ATestHeader : public ATestHeaderBase
+{
+public:
+ static TypeId GetTypeId (void) {
+ std::ostringstream oss;
+ oss << "anon::ATestHeader<" << N << ">";
+ static TypeId tid = TypeId (oss.str ().c_str ())
+ .SetParent<Header> ()
+ .AddConstructor<ATestHeader<N> > ()
+ .HideFromDocumentation ()
+ ;
+ return tid;
+ }
+ virtual TypeId GetInstanceTypeId (void) const {
+ return GetTypeId ();
+ }
+ virtual uint32_t GetSerializedSize (void) const {
+ return N;
+ }
+ virtual void Serialize (Buffer::Iterator iter) const {
+ for (uint32_t i = 0; i < N; ++i)
+ {
+ iter.WriteU8 (N);
+ }
+ }
+ virtual uint32_t Deserialize (Buffer::Iterator iter) {
+ for (uint32_t i = 0; i < N; ++i)
+ {
+ uint8_t v = iter.ReadU8 ();
+ if (v != N)
+ {
+ m_error = true;
+ }
+ }
+ return N;
+ }
+ virtual void Print (std::ostream &os) const {
+ }
+ ATestHeader ()
+ : ATestHeaderBase () {}
+
+};
+
+class ATestTrailerBase : public Trailer
+{
+public:
+ ATestTrailerBase () : Trailer (), m_error (false) {}
+ bool m_error;
+};
+
+template <int N>
+class ATestTrailer : public ATestTrailerBase
+{
+public:
+ static TypeId GetTypeId (void) {
+ std::ostringstream oss;
+ oss << "anon::ATestTrailer<" << N << ">";
+ static TypeId tid = TypeId (oss.str ().c_str ())
+ .SetParent<Header> ()
+ .AddConstructor<ATestTrailer<N> > ()
+ .HideFromDocumentation ()
+ ;
+ return tid;
+ }
+ virtual TypeId GetInstanceTypeId (void) const {
+ return GetTypeId ();
+ }
+ virtual uint32_t GetSerializedSize (void) const {
+ return N;
+ }
+ virtual void Serialize (Buffer::Iterator iter) const {
+ iter.Prev (N);
+ for (uint32_t i = 0; i < N; ++i)
+ {
+ iter.WriteU8 (N);
+ }
+ }
+ virtual uint32_t Deserialize (Buffer::Iterator iter) {
+ iter.Prev (N);
+ for (uint32_t i = 0; i < N; ++i)
+ {
+ uint8_t v = iter.ReadU8 ();
+ if (v != N)
+ {
+ m_error = true;
+ }
+ }
+ return N;
+ }
+ virtual void Print (std::ostream &os) const {
+ }
+ ATestTrailer ()
+ : ATestTrailerBase () {}
+
+};
+
+
+struct Expected
+{
+ Expected (uint32_t n_, uint32_t start_, uint32_t end_)
+ : n (n_), start (start_), end (end_) {}
+
+ uint32_t n;
+ uint32_t start;
+ uint32_t end;
+};
+
+}
+
+// tag name, start, end
+#define E(a,b,c) a,b,c
+
+#define CHECK(p, n, ...) \
+ DoCheck (p, __FILE__, __LINE__, n, __VA_ARGS__)
+
+class PacketTest : public TestCase
+{
+public:
+ PacketTest ();
+ virtual void DoRun (void);
+private:
+ void DoCheck (Ptr<const Packet> p, const char *file, int line, uint32_t n, ...);
+};
+
+
+PacketTest::PacketTest ()
+ : TestCase ("Packet") {
+}
+
+void
+PacketTest::DoCheck (Ptr<const Packet> p, const char *file, int line, uint32_t n, ...)
+{
+ std::vector<struct Expected> expected;
+ va_list ap;
+ va_start (ap, n);
+ for (uint32_t k = 0; k < n; ++k)
+ {
+ uint32_t N = va_arg (ap, uint32_t);
+ uint32_t start = va_arg (ap, uint32_t);
+ uint32_t end = va_arg (ap, uint32_t);
+ expected.push_back (Expected (N, start, end));
+ }
+ va_end (ap);
+
+ ByteTagIterator i = p->GetByteTagIterator ();
+ uint32_t j = 0;
+ while (i.HasNext () && j < expected.size ())
+ {
+ ByteTagIterator::Item item = i.Next ();
+ struct Expected e = expected[j];
+ std::ostringstream oss;
+ oss << "anon::ATestTag<" << e.n << ">";
+ NS_TEST_EXPECT_MSG_EQ_INTERNAL (item.GetTypeId ().GetName (), oss.str (), "trivial", file, line);
+ NS_TEST_EXPECT_MSG_EQ_INTERNAL (item.GetStart (), e.start, "trivial", file, line);
+ NS_TEST_EXPECT_MSG_EQ_INTERNAL (item.GetEnd (), e.end, "trivial", file, line);
+ ATestTagBase *tag = dynamic_cast<ATestTagBase *> (item.GetTypeId ().GetConstructor () ());
+ NS_TEST_EXPECT_MSG_NE (tag, 0, "trivial");
+ item.GetTag (*tag);
+ NS_TEST_EXPECT_MSG_EQ (tag->m_error, false, "trivial");
+ delete tag;
+ j++;
+ }
+ NS_TEST_EXPECT_MSG_EQ (i.HasNext (), false, "Nothing left");
+ NS_TEST_EXPECT_MSG_EQ (j, expected.size (), "Size match");
+}
+
+void
+PacketTest::DoRun (void)
+{
+ Ptr<Packet> pkt1 = Create<Packet> (reinterpret_cast<const uint8_t*> ("hello"), 5);
+ Ptr<Packet> pkt2 = Create<Packet> (reinterpret_cast<const uint8_t*> (" world"), 6);
+ Ptr<Packet> packet = Create<Packet> ();
+ packet->AddAtEnd (pkt1);
+ packet->AddAtEnd (pkt2);
+
+ NS_TEST_EXPECT_MSG_EQ (packet->GetSize (), 11, "trivial");
+
+ uint8_t *buf = new uint8_t[packet->GetSize ()];
+ packet->CopyData (buf, packet->GetSize ());
+
+ std::string msg = std::string (reinterpret_cast<const char *>(buf),
+ packet->GetSize ());
+ delete [] buf;
+
+ NS_TEST_EXPECT_MSG_EQ (msg, "hello world", "trivial");
+
+
+ Ptr<const Packet> p = Create<Packet> (1000);
+
+ p->AddByteTag (ATestTag<1> ());
+ CHECK (p, 1, E (1, 0, 1000));
+ Ptr<const Packet> copy = p->Copy ();
+ CHECK (copy, 1, E (1, 0, 1000));
+
+ p->AddByteTag (ATestTag<2> ());
+ CHECK (p, 2, E (1, 0, 1000), E(2, 0, 1000));
+ CHECK (copy, 1, E (1, 0, 1000));
+
+ {
+ Packet c0 = *copy;
+ Packet c1 = *copy;
+ c0 = c1;
+ CHECK (&c0, 1, E (1, 0, 1000));
+ CHECK (&c1, 1, E (1, 0, 1000));
+ CHECK (copy, 1, E (1, 0, 1000));
+ c0.AddByteTag (ATestTag<10> ());
+ CHECK (&c0, 2, E (1, 0, 1000), E (10, 0, 1000));
+ CHECK (&c1, 1, E (1, 0, 1000));
+ CHECK (copy, 1, E (1, 0, 1000));
+ }
+
+ Ptr<Packet> frag0 = p->CreateFragment (0, 10);
+ Ptr<Packet> frag1 = p->CreateFragment (10, 90);
+ Ptr<const Packet> frag2 = p->CreateFragment (100, 900);
+ frag0->AddByteTag (ATestTag<3> ());
+ CHECK (frag0, 3, E (1, 0, 10), E(2, 0, 10), E (3, 0, 10));
+ frag1->AddByteTag (ATestTag<4> ());
+ CHECK (frag1, 3, E (1, 0, 90), E(2, 0, 90), E (4, 0, 90));
+ frag2->AddByteTag (ATestTag<5> ());
+ CHECK (frag2, 3, E (1, 0, 900), E(2, 0, 900), E (5, 0, 900));
+
+ frag1->AddAtEnd (frag2);
+ CHECK (frag1, 6, E (1, 0, 90), E(2, 0, 90), E (4, 0, 90), E (1, 90, 990), E(2, 90, 990), E (5, 90, 990));
+
+ CHECK (frag0, 3, E (1, 0, 10), E(2, 0, 10), E (3, 0, 10));
+ frag0->AddAtEnd (frag1);
+ CHECK (frag0, 9,
+ E (1, 0, 10), E(2, 0, 10), E (3, 0, 10),
+ E (1, 10, 100), E(2, 10, 100), E (4, 10, 100),
+ E (1, 100, 1000), E(2, 100, 1000), E (5, 100, 1000));
+
+
+ // force caching a buffer of the right size.
+ frag0 = Create<Packet> (1000);
+ frag0->AddHeader (ATestHeader<10> ());
+ frag0 = 0;
+
+ p = Create<Packet> (1000);
+ p->AddByteTag (ATestTag<20> ());
+ CHECK (p, 1, E (20, 0, 1000));
+ frag0 = p->CreateFragment (10, 90);
+ CHECK (p, 1, E (20, 0, 1000));
+ CHECK (frag0, 1, E (20, 0, 90));
+ p = 0;
+ frag0->AddHeader (ATestHeader<10> ());
+ CHECK (frag0, 1, E (20, 10, 100));
+
+ {
+ Ptr<Packet> tmp = Create<Packet> (100);
+ tmp->AddByteTag (ATestTag<20> ());
+ CHECK (tmp, 1, E (20, 0, 100));
+ tmp->AddHeader (ATestHeader<10> ());
+ CHECK (tmp, 1, E (20, 10, 110));
+ ATestHeader<10> h;
+ tmp->RemoveHeader (h);
+ CHECK (tmp, 1, E (20, 0, 100));
+ tmp->AddHeader (ATestHeader<10> ());
+ CHECK (tmp, 1, E (20, 10, 110));
+
+ tmp = Create<Packet> (100);
+ tmp->AddByteTag (ATestTag<20> ());
+ CHECK (tmp, 1, E (20, 0, 100));
+ tmp->AddTrailer (ATestTrailer<10> ());
+ CHECK (tmp, 1, E (20, 0, 100));
+ ATestTrailer<10> t;
+ tmp->RemoveTrailer (t);
+ CHECK (tmp, 1, E (20, 0, 100));
+ tmp->AddTrailer (ATestTrailer<10> ());
+ CHECK (tmp, 1, E (20, 0, 100));
+
+ }
+
+ {
+ Ptr<Packet> tmp = Create<Packet> (0);
+ tmp->AddHeader (ATestHeader<156> ());
+ tmp->AddByteTag (ATestTag<20> ());
+ CHECK (tmp, 1, E (20, 0, 156));
+ tmp->RemoveAtStart (120);
+ CHECK (tmp, 1, E (20, 0, 36));
+ Ptr<Packet> a = Create<Packet> (0);
+ a->AddAtEnd (tmp);
+ CHECK (a, 1, E (20, 0, 36));
+ }
+
+ {
+ Ptr<Packet> tmp = Create<Packet> (0);
+ tmp->AddByteTag (ATestTag<20> ());
+ CHECK (tmp, 0, E (20, 0, 0));
+ }
+ {
+ Ptr<Packet> tmp = Create<Packet> (1000);
+ tmp->AddByteTag (ATestTag<20> ());
+ CHECK (tmp, 1, E (20, 0, 1000));
+ tmp->RemoveAtStart (1000);
+ CHECK (tmp, 0, E (0,0,0));
+ Ptr<Packet> a = Create<Packet> (10);
+ a->AddByteTag (ATestTag<10> ());
+ CHECK (a, 1, E (10, 0, 10));
+ tmp->AddAtEnd (a);
+ CHECK (tmp, 1, E (10, 0, 10));
+ }
+
+ {
+ Packet p;
+ ATestTag<10> a;
+ p.AddPacketTag (a);
+ NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (a), true, "trivial");
+ ATestTag<11> b;
+ p.AddPacketTag (b);
+ NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (b), true, "trivial");
+ NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (a), true, "trivial");
+ Packet copy = p;
+ NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (b), true, "trivial");
+ NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (a), true, "trivial");
+ ATestTag<12> c;
+ NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (c), false, "trivial");
+ copy.AddPacketTag (c);
+ NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (c), true, "trivial");
+ NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (b), true, "trivial");
+ NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (a), true, "trivial");
+ NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (c), false, "trivial");
+ copy.RemovePacketTag (b);
+ NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (b), false, "trivial");
+ NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (b), true, "trivial");
+ p.RemovePacketTag (a);
+ NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (a), false, "trivial");
+ NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (a), true, "trivial");
+ NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (c), false, "trivial");
+ NS_TEST_EXPECT_MSG_EQ (copy.PeekPacketTag (c), true, "trivial");
+ p.RemoveAllPacketTags ();
+ NS_TEST_EXPECT_MSG_EQ (p.PeekPacketTag (b), false, "trivial");
+ }
+
+ {
+ // bug 572
+ Ptr<Packet> tmp = Create<Packet> (1000);
+ tmp->AddByteTag (ATestTag<20> ());
+ CHECK (tmp, 1, E (20, 0, 1000));
+ tmp->AddHeader (ATestHeader<2> ());
+ CHECK (tmp, 1, E (20, 2, 1002));
+ tmp->RemoveAtStart (1);
+ CHECK (tmp, 1, E (20, 1, 1001));
+#if 0
+ tmp->PeekData ();
+ CHECK (tmp, 1, E (20, 1, 1001));
+#endif
+ }
+}
+//-----------------------------------------------------------------------------
+class PacketTestSuite : public TestSuite
+{
+public:
+ PacketTestSuite ();
+};
+
+PacketTestSuite::PacketTestSuite ()
+ : TestSuite ("packet", UNIT)
+{
+ AddTestCase (new PacketTest);
+}
+
+static PacketTestSuite g_packetTestSuite;
+
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/network/test/sequence-number-test-suite.cc Mon Mar 28 16:43:20 2011 -0700
@@ -0,0 +1,193 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+//
+// Copyright (c) 2008-2010 INESC Porto
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation;
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt> <gjcarneiro@gmail.com>
+//
+
+#include "ns3/sequence-number.h"
+#include "ns3/test.h"
+#include "ns3/object.h"
+#include "ns3/traced-value.h"
+#include "ns3/trace-source-accessor.h"
+
+namespace ns3 {
+
+class SequenceNumberTestObj : public Object
+{
+ TracedValue<SequenceNumber32> m_testTracedSequenceNumber;
+
+
+public:
+
+ SequenceNumberTestObj ()
+ {
+ m_testTracedSequenceNumber = SequenceNumber32 (0);
+ }
+
+ static TypeId GetTypeId (void)
+ {
+ static TypeId tid = TypeId("ns3::SequenceNumberTestObj")
+ .SetParent<Object> ()
+ .AddTraceSource ("TestTracedSequenceNumber",
+ "A traceable sequence number",
+ MakeTraceSourceAccessor (&SequenceNumberTestObj::m_testTracedSequenceNumber))
+ .AddConstructor<SequenceNumberTestObj> ()
+ ;
+ return tid;
+ }
+
+ TypeId GetInstanceTypeId (void) const
+ {
+ return GetTypeId ();
+ }
+
+ void IncSequenceNumber ()
+ {
+ m_testTracedSequenceNumber += 1;
+ }
+
+
+};
+
+class SequenceNumberTestCase : public TestCase
+{
+ SequenceNumber32 m_oldval;
+ SequenceNumber32 m_newval;
+
+ void SequenceNumberTracer (SequenceNumber32 oldval, SequenceNumber32 newval);
+
+public:
+
+ SequenceNumberTestCase ();
+ virtual ~SequenceNumberTestCase ();
+ virtual void DoRun (void);
+};
+
+SequenceNumberTestCase::SequenceNumberTestCase ()
+ : TestCase ("SequenceNumber")
+{
+ m_oldval = 0;
+ m_newval = 0;
+}
+
+SequenceNumberTestCase::~SequenceNumberTestCase ()
+{}
+
+void
+SequenceNumberTestCase::SequenceNumberTracer (SequenceNumber32 oldval, SequenceNumber32 newval)
+{
+ m_oldval = oldval;
+ m_newval = newval;
+}
+
+void SequenceNumberTestCase::DoRun (void)
+{
+#define NS_TEST_ASSERT_EQUAL(a,b) NS_TEST_ASSERT_MSG_EQ(a,b, "foo")
+#define NS_TEST_ASSERT(a) NS_TEST_ASSERT_MSG_EQ(bool(a), true, "foo")
+
+ {
+ SequenceNumber32 num1 (3), num2 (5);
+ uint32_t value;
+
+ value = (num1 + num2).GetValue ();
+ NS_TEST_ASSERT_EQUAL (value, 8);
+
+ num1 += num2.GetValue ();
+ NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (8));
+
+ ++num1;
+ NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (9));
+
+ --num1;
+ NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (8));
+
+ num1++;
+ NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (9));
+
+ num1--;
+ NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (8));
+
+ }
+
+ {
+ SequenceNumber16 num1 (60900), num2 (5), num3 (10000);
+
+ NS_TEST_ASSERT (num1 == num1);
+
+ NS_TEST_ASSERT (num2 != num1);
+
+ NS_TEST_ASSERT (num3 > num2);
+ NS_TEST_ASSERT (num3 >= num2);
+ NS_TEST_ASSERT (num1 < num3);
+ NS_TEST_ASSERT (num1 <= num3);
+
+ NS_TEST_ASSERT (num1 < num2);
+ NS_TEST_ASSERT (num1 <= num2);
+ NS_TEST_ASSERT (num2 > num1);
+ NS_TEST_ASSERT (num2 >= num1);
+
+ NS_TEST_ASSERT (num1+num2 > num1);
+ NS_TEST_ASSERT (num1+num2 >= num1);
+ NS_TEST_ASSERT (num1 < num1+num2);
+ NS_TEST_ASSERT (num1 <= num1+num2);
+
+ NS_TEST_ASSERT (num1 < num1+num3);
+ NS_TEST_ASSERT (num1 <= num1+num3);
+ NS_TEST_ASSERT (num1+num3 > num1);
+ NS_TEST_ASSERT (num1+num3 >= num1);
+ }
+
+ {
+ NS_TEST_ASSERT_EQUAL ((SequenceNumber16 (1000) + SequenceNumber16 (6000)) - SequenceNumber16 (1000), 6000);
+ NS_TEST_ASSERT_EQUAL ((SequenceNumber16 (60000) + SequenceNumber16 (6000)) - SequenceNumber16 (60000), 6000);
+ NS_TEST_ASSERT_EQUAL (SequenceNumber16 (1000) - SequenceNumber16 (6000), -5000);
+ NS_TEST_ASSERT_EQUAL ((SequenceNumber16 (60000) + SequenceNumber16 (1000)) - SequenceNumber16 (65000), -4000);
+ }
+
+ {
+ SequenceNumber32 num1 (3);
+
+ NS_TEST_ASSERT_EQUAL (num1 + 10, SequenceNumber32 (13));
+ num1 += -1;
+ NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (2));
+
+ NS_TEST_ASSERT_EQUAL (num1 - (num1 - 100), 100);
+ }
+
+ {
+ Ptr<SequenceNumberTestObj> obj = CreateObject<SequenceNumberTestObj> ();
+ obj->TraceConnectWithoutContext ("TestTracedSequenceNumber", MakeCallback (&SequenceNumberTestCase::SequenceNumberTracer, this));
+ obj->IncSequenceNumber ();
+ NS_TEST_ASSERT_EQUAL (m_oldval, SequenceNumber32 (0));
+ NS_TEST_ASSERT_EQUAL (m_newval, SequenceNumber32 (1));
+ obj->Dispose ();
+ }
+
+}
+
+static class SequenceNumberTestSuite : public TestSuite
+{
+public:
+ SequenceNumberTestSuite ()
+ : TestSuite ("SequenceNumber", UNIT)
+ {
+ AddTestCase (new SequenceNumberTestCase ());
+ }
+} g_seqNumTests;
+
+}
+
--- a/src/network/utils/drop-tail-queue.cc Mon Mar 28 15:09:39 2011 -0700
+++ b/src/network/utils/drop-tail-queue.cc Mon Mar 28 16:43:20 2011 -0700
@@ -152,72 +152,3 @@
} // namespace ns3
-#include "ns3/test.h"
-
-namespace ns3 {
-
-class DropTailQueueTestCase : public TestCase
-{
-public:
- DropTailQueueTestCase ();
- virtual void DoRun (void);
-};
-
-DropTailQueueTestCase::DropTailQueueTestCase ()
- : TestCase ("Sanity check on the drop tail queue implementation")
-{}
-void
-DropTailQueueTestCase::DoRun (void)
-{
- Ptr<DropTailQueue> queue = CreateObject<DropTailQueue> ();
- NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MaxPackets", UintegerValue (3)), true,
- "Verify that we can actually set the attribute");
-
- Ptr<Packet> p1, p2, p3, p4;
- p1 = Create<Packet> ();
- p2 = Create<Packet> ();
- p3 = Create<Packet> ();
- p4 = Create<Packet> ();
-
- NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 0, "There should be no packets in there");
- queue->Enqueue (p1);
- NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 1, "There should be one packet in there");
- queue->Enqueue (p2);
- NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 2, "There should be two packets in there");
- queue->Enqueue (p3);
- NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be three packets in there");
- queue->Enqueue (p4); // will be dropped
- NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be still three packets in there");
-
- Ptr<Packet> p;
-
- p = queue->Dequeue ();
- NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the first packet");
- NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 2, "There should be two packets in there");
- NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p1->GetUid (), "was this the first packet ?");
-
- p = queue->Dequeue ();
- NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the second packet");
- NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 1, "There should be one packet in there");
- NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p2->GetUid (), "Was this the second packet ?");
-
- p = queue->Dequeue ();
- NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the third packet");
- NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 0, "There should be no packets in there");
- NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p3->GetUid (), "Was this the third packet ?");
-
- p = queue->Dequeue ();
- NS_TEST_EXPECT_MSG_EQ ((p == 0), true, "There are really no packets in there");
-}
-
-static class DropTailQueueTestSuite : public TestSuite
-{
-public:
- DropTailQueueTestSuite ()
- : TestSuite ("drop-tail-queue", UNIT)
- {
- AddTestCase (new DropTailQueueTestCase ());
- }
-} g_dropTailQueueTestSuite;
-
-} // namespace ns3
--- a/src/network/utils/sequence-number.cc Mon Mar 28 15:09:39 2011 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,193 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-//
-// Copyright (c) 2008-2010 INESC Porto
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as
-// published by the Free Software Foundation;
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt> <gjcarneiro@gmail.com>
-//
-
-#include "sequence-number.h"
-#include "ns3/test.h"
-#include "ns3/object.h"
-#include "ns3/traced-value.h"
-#include "ns3/trace-source-accessor.h"
-
-namespace ns3 {
-
-class SequenceNumberTestObj : public Object
-{
- TracedValue<SequenceNumber32> m_testTracedSequenceNumber;
-
-
-public:
-
- SequenceNumberTestObj ()
- {
- m_testTracedSequenceNumber = SequenceNumber32 (0);
- }
-
- static TypeId GetTypeId (void)
- {
- static TypeId tid = TypeId("ns3::SequenceNumberTestObj")
- .SetParent<Object> ()
- .AddTraceSource ("TestTracedSequenceNumber",
- "A traceable sequence number",
- MakeTraceSourceAccessor (&SequenceNumberTestObj::m_testTracedSequenceNumber))
- .AddConstructor<SequenceNumberTestObj> ()
- ;
- return tid;
- }
-
- TypeId GetInstanceTypeId (void) const
- {
- return GetTypeId ();
- }
-
- void IncSequenceNumber ()
- {
- m_testTracedSequenceNumber += 1;
- }
-
-
-};
-
-class SequenceNumberTestCase : public TestCase
-{
- SequenceNumber32 m_oldval;
- SequenceNumber32 m_newval;
-
- void SequenceNumberTracer (SequenceNumber32 oldval, SequenceNumber32 newval);
-
-public:
-
- SequenceNumberTestCase ();
- virtual ~SequenceNumberTestCase ();
- virtual void DoRun (void);
-};
-
-SequenceNumberTestCase::SequenceNumberTestCase ()
- : TestCase ("SequenceNumber")
-{
- m_oldval = 0;
- m_newval = 0;
-}
-
-SequenceNumberTestCase::~SequenceNumberTestCase ()
-{}
-
-void
-SequenceNumberTestCase::SequenceNumberTracer (SequenceNumber32 oldval, SequenceNumber32 newval)
-{
- m_oldval = oldval;
- m_newval = newval;
-}
-
-void SequenceNumberTestCase::DoRun (void)
-{
-#define NS_TEST_ASSERT_EQUAL(a,b) NS_TEST_ASSERT_MSG_EQ(a,b, "foo")
-#define NS_TEST_ASSERT(a) NS_TEST_ASSERT_MSG_EQ(bool(a), true, "foo")
-
- {
- SequenceNumber32 num1 (3), num2 (5);
- uint32_t value;
-
- value = (num1 + num2).GetValue ();
- NS_TEST_ASSERT_EQUAL (value, 8);
-
- num1 += num2.GetValue ();
- NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (8));
-
- ++num1;
- NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (9));
-
- --num1;
- NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (8));
-
- num1++;
- NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (9));
-
- num1--;
- NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (8));
-
- }
-
- {
- SequenceNumber16 num1 (60900), num2 (5), num3 (10000);
-
- NS_TEST_ASSERT (num1 == num1);
-
- NS_TEST_ASSERT (num2 != num1);
-
- NS_TEST_ASSERT (num3 > num2);
- NS_TEST_ASSERT (num3 >= num2);
- NS_TEST_ASSERT (num1 < num3);
- NS_TEST_ASSERT (num1 <= num3);
-
- NS_TEST_ASSERT (num1 < num2);
- NS_TEST_ASSERT (num1 <= num2);
- NS_TEST_ASSERT (num2 > num1);
- NS_TEST_ASSERT (num2 >= num1);
-
- NS_TEST_ASSERT (num1+num2 > num1);
- NS_TEST_ASSERT (num1+num2 >= num1);
- NS_TEST_ASSERT (num1 < num1+num2);
- NS_TEST_ASSERT (num1 <= num1+num2);
-
- NS_TEST_ASSERT (num1 < num1+num3);
- NS_TEST_ASSERT (num1 <= num1+num3);
- NS_TEST_ASSERT (num1+num3 > num1);
- NS_TEST_ASSERT (num1+num3 >= num1);
- }
-
- {
- NS_TEST_ASSERT_EQUAL ((SequenceNumber16 (1000) + SequenceNumber16 (6000)) - SequenceNumber16 (1000), 6000);
- NS_TEST_ASSERT_EQUAL ((SequenceNumber16 (60000) + SequenceNumber16 (6000)) - SequenceNumber16 (60000), 6000);
- NS_TEST_ASSERT_EQUAL (SequenceNumber16 (1000) - SequenceNumber16 (6000), -5000);
- NS_TEST_ASSERT_EQUAL ((SequenceNumber16 (60000) + SequenceNumber16 (1000)) - SequenceNumber16 (65000), -4000);
- }
-
- {
- SequenceNumber32 num1 (3);
-
- NS_TEST_ASSERT_EQUAL (num1 + 10, SequenceNumber32 (13));
- num1 += -1;
- NS_TEST_ASSERT_EQUAL (num1, SequenceNumber32 (2));
-
- NS_TEST_ASSERT_EQUAL (num1 - (num1 - 100), 100);
- }
-
- {
- Ptr<SequenceNumberTestObj> obj = CreateObject<SequenceNumberTestObj> ();
- obj->TraceConnectWithoutContext ("TestTracedSequenceNumber", MakeCallback (&SequenceNumberTestCase::SequenceNumberTracer, this));
- obj->IncSequenceNumber ();
- NS_TEST_ASSERT_EQUAL (m_oldval, SequenceNumber32 (0));
- NS_TEST_ASSERT_EQUAL (m_newval, SequenceNumber32 (1));
- obj->Dispose ();
- }
-
-}
-
-static class SequenceNumberTestSuite : public TestSuite
-{
-public:
- SequenceNumberTestSuite ()
- : TestSuite ("SequenceNumber", UNIT)
- {
- AddTestCase (new SequenceNumberTestCase ());
- }
-} g_seqNumTests;
-
-}
-
--- a/src/network/wscript Mon Mar 28 15:09:39 2011 -0700
+++ b/src/network/wscript Mon Mar 28 16:43:20 2011 -0700
@@ -47,7 +47,6 @@
'utils/pcap-file-wrapper.cc',
'utils/queue.cc',
'utils/radiotap-header.cc',
- 'utils/sequence-number.cc',
'utils/simple-channel.cc',
'utils/simple-net-device.cc',
'helper/application-container.cc',
@@ -60,9 +59,12 @@
network_test = bld.create_ns3_module_test_library('network')
network_test.source = [
'test/buffer-test.cc',
+ 'test/drop-tail-queue-test-suite.cc',
'test/packetbb-test-suite.cc',
+ 'test/packet-test-suite.cc',
'test/packet-metadata-test.cc',
'test/pcap-file-test-suite.cc',
+ 'test/sequence-number-test-suite.cc',
]
headers = bld.new_task_gen('ns3header')