--- a/bindings/python/wscript Tue Mar 29 19:02:31 2011 +0100
+++ b/bindings/python/wscript Tue Mar 29 19:05:15 2011 +0100
@@ -57,7 +57,7 @@
choices=c,
help=("Type of Python bindings to build %r. "
"Warning: the modular bindings are still experimental." % (c,)),
- default="monolithic",
+ default="modular",
dest='bindings_type')
opt.add_option('--disable-python',
help=("Don't build Python bindings."),
--- a/src/olsr/model/olsr-header.cc Tue Mar 29 19:02:31 2011 +0100
+++ b/src/olsr/model/olsr-header.cc Tue Mar 29 19:05:15 2011 +0100
@@ -501,293 +501,3 @@
}} // namespace olsr, ns3
-#include "ns3/test.h"
-#include "ns3/packet.h"
-
-namespace ns3 {
-
-class OlsrEmfTestCase : public TestCase {
-public:
- OlsrEmfTestCase ();
- virtual void DoRun (void);
-};
-
-OlsrEmfTestCase::OlsrEmfTestCase ()
- : TestCase ("Check Emf olsr time conversion")
-{}
-void
-OlsrEmfTestCase::DoRun (void)
-{
- for (int time = 1; time <= 30; time++)
- {
- uint8_t emf = olsr::SecondsToEmf (time);
- double seconds = olsr::EmfToSeconds (emf);
- NS_TEST_ASSERT_MSG_EQ((seconds < 0 || fabs (seconds - time) > 0.1), false,
- "XXX");
- }
-}
-
-
-class OlsrMidTestCase : public TestCase {
-public:
- OlsrMidTestCase ();
- virtual void DoRun (void);
-};
-
-OlsrMidTestCase::OlsrMidTestCase ()
- : TestCase ("Check Mid olsr messages")
-{}
-void
-OlsrMidTestCase::DoRun (void)
-{
- Packet packet;
-
- {
- olsr::PacketHeader hdr;
- olsr::MessageHeader msg1;
- olsr::MessageHeader::Mid &mid1 = msg1.GetMid ();
- olsr::MessageHeader msg2;
- olsr::MessageHeader::Mid &mid2 = msg2.GetMid ();
-
- // MID message #1
- {
- std::vector<Ipv4Address> &addresses = mid1.interfaceAddresses;
- addresses.clear ();
- addresses.push_back (Ipv4Address ("1.2.3.4"));
- addresses.push_back (Ipv4Address ("1.2.3.5"));
- }
-
- msg1.SetTimeToLive (255);
- msg1.SetOriginatorAddress (Ipv4Address ("11.22.33.44"));
- msg1.SetVTime (Seconds (9));
- msg1.SetMessageSequenceNumber (7);
-
- // MID message #2
- {
- std::vector<Ipv4Address> &addresses = mid2.interfaceAddresses;
- addresses.clear ();
- addresses.push_back (Ipv4Address ("2.2.3.4"));
- addresses.push_back (Ipv4Address ("2.2.3.5"));
- }
-
- msg2.SetTimeToLive (254);
- msg2.SetOriginatorAddress (Ipv4Address ("12.22.33.44"));
- msg2.SetVTime (Seconds (10));
- msg2.SetMessageType (olsr::MessageHeader::MID_MESSAGE);
- msg2.SetMessageSequenceNumber (7);
-
- // Build an OLSR packet header
- hdr.SetPacketLength (hdr.GetSerializedSize () + msg1.GetSerializedSize () + msg2.GetSerializedSize ());
- hdr.SetPacketSequenceNumber (123);
-
-
- // Now add all the headers in the correct order
- packet.AddHeader (msg2);
- packet.AddHeader (msg1);
- packet.AddHeader (hdr);
- }
-
- {
- olsr::PacketHeader hdr;
- packet.RemoveHeader (hdr);
- NS_TEST_ASSERT_MSG_EQ (hdr.GetPacketSequenceNumber (), 123, "XXX");
- uint32_t sizeLeft = hdr.GetPacketLength () - hdr.GetSerializedSize ();
- {
- olsr::MessageHeader msg1;
-
- packet.RemoveHeader (msg1);
-
- NS_TEST_ASSERT_MSG_EQ (msg1.GetTimeToLive (), 255, "XXX");
- NS_TEST_ASSERT_MSG_EQ (msg1.GetOriginatorAddress (), Ipv4Address ("11.22.33.44"), "XXX");
- NS_TEST_ASSERT_MSG_EQ (msg1.GetVTime (), Seconds (9), "XXX");
- NS_TEST_ASSERT_MSG_EQ (msg1.GetMessageType (), olsr::MessageHeader::MID_MESSAGE, "XXX");
- NS_TEST_ASSERT_MSG_EQ (msg1.GetMessageSequenceNumber (), 7, "XXX");
-
- olsr::MessageHeader::Mid &mid1 = msg1.GetMid ();
- NS_TEST_ASSERT_MSG_EQ (mid1.interfaceAddresses.size (), 2, "XXX");
- NS_TEST_ASSERT_MSG_EQ (*mid1.interfaceAddresses.begin (), Ipv4Address ("1.2.3.4"), "XXX");
-
- sizeLeft -= msg1.GetSerializedSize ();
- NS_TEST_ASSERT_MSG_EQ((sizeLeft > 0), true, "XXX");
- }
- {
- // now read the second message
- olsr::MessageHeader msg2;
-
- packet.RemoveHeader (msg2);
-
- NS_TEST_ASSERT_MSG_EQ (msg2.GetTimeToLive (), 254, "XXX");
- NS_TEST_ASSERT_MSG_EQ (msg2.GetOriginatorAddress (), Ipv4Address ("12.22.33.44"), "XXX");
- NS_TEST_ASSERT_MSG_EQ (msg2.GetVTime (), Seconds (10), "XXX");
- NS_TEST_ASSERT_MSG_EQ (msg2.GetMessageType (), olsr::MessageHeader::MID_MESSAGE, "XXX");
- NS_TEST_ASSERT_MSG_EQ (msg2.GetMessageSequenceNumber (), 7, "XXX");
-
- olsr::MessageHeader::Mid mid2 = msg2.GetMid ();
- NS_TEST_ASSERT_MSG_EQ (mid2.interfaceAddresses.size (), 2, "XXX");
- NS_TEST_ASSERT_MSG_EQ (*mid2.interfaceAddresses.begin (), Ipv4Address ("2.2.3.4"), "XXX");
-
- sizeLeft -= msg2.GetSerializedSize ();
- NS_TEST_ASSERT_MSG_EQ (sizeLeft, 0, "XXX");
- }
- }
-}
-
-
-class OlsrHelloTestCase : public TestCase {
-public:
- OlsrHelloTestCase ();
- virtual void DoRun (void);
-};
-
-OlsrHelloTestCase::OlsrHelloTestCase ()
- : TestCase ("Check Hello olsr messages")
-{}
-void
-OlsrHelloTestCase::DoRun (void)
-{
- Packet packet;
- olsr::MessageHeader msgIn;
- olsr::MessageHeader::Hello &helloIn = msgIn.GetHello ();
-
- helloIn.SetHTime (Seconds (7));
- helloIn.willingness = 66;
-
- {
- olsr::MessageHeader::Hello::LinkMessage lm1;
- lm1.linkCode = 2;
- lm1.neighborInterfaceAddresses.push_back (Ipv4Address ("1.2.3.4"));
- lm1.neighborInterfaceAddresses.push_back (Ipv4Address ("1.2.3.5"));
- helloIn.linkMessages.push_back (lm1);
-
- olsr::MessageHeader::Hello::LinkMessage lm2;
- lm2.linkCode = 3;
- lm2.neighborInterfaceAddresses.push_back (Ipv4Address ("2.2.3.4"));
- lm2.neighborInterfaceAddresses.push_back (Ipv4Address ("2.2.3.5"));
- helloIn.linkMessages.push_back (lm2);
- }
-
- packet.AddHeader (msgIn);
-
- olsr::MessageHeader msgOut;
- packet.RemoveHeader (msgOut);
- olsr::MessageHeader::Hello &helloOut = msgOut.GetHello ();
-
- NS_TEST_ASSERT_MSG_EQ (helloOut.GetHTime (), Seconds (7), "XXX");
- NS_TEST_ASSERT_MSG_EQ (helloOut.willingness, 66, "XXX");
- NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages.size (), 2, "XXX");
-
- NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[0].linkCode, 2, "XXX");
- NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[0].neighborInterfaceAddresses[0],
- Ipv4Address ("1.2.3.4"), "XXX");
- NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[0].neighborInterfaceAddresses[1],
- Ipv4Address ("1.2.3.5"), "XXX");
-
- NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[1].linkCode, 3, "XXX");
- NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[1].neighborInterfaceAddresses[0],
- Ipv4Address ("2.2.3.4"), "XXX");
- NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[1].neighborInterfaceAddresses[1],
- Ipv4Address ("2.2.3.5"), "XXX");
-
- NS_TEST_ASSERT_MSG_EQ (packet.GetSize (), 0, "All bytes in packet were not read");
-
-}
-
-class OlsrTcTestCase : public TestCase {
-public:
- OlsrTcTestCase ();
- virtual void DoRun (void);
-};
-
-OlsrTcTestCase::OlsrTcTestCase ()
- : TestCase ("Check Tc olsr messages")
-{}
-void
-OlsrTcTestCase::DoRun (void)
-{
- Packet packet;
- olsr::MessageHeader msgIn;
- olsr::MessageHeader::Tc &tcIn = msgIn.GetTc ();
-
- tcIn.ansn = 0x1234;
- tcIn.neighborAddresses.push_back (Ipv4Address ("1.2.3.4"));
- tcIn.neighborAddresses.push_back (Ipv4Address ("1.2.3.5"));
- packet.AddHeader (msgIn);
-
- olsr::MessageHeader msgOut;
- packet.RemoveHeader (msgOut);
- olsr::MessageHeader::Tc &tcOut = msgOut.GetTc ();
-
- NS_TEST_ASSERT_MSG_EQ (tcOut.ansn, 0x1234, "XXX");
- NS_TEST_ASSERT_MSG_EQ (tcOut.neighborAddresses.size (), 2, "XXX");
-
- NS_TEST_ASSERT_MSG_EQ (tcOut.neighborAddresses[0],
- Ipv4Address ("1.2.3.4"), "XXX");
- NS_TEST_ASSERT_MSG_EQ (tcOut.neighborAddresses[1],
- Ipv4Address ("1.2.3.5"), "XXX");
-
- NS_TEST_ASSERT_MSG_EQ (packet.GetSize (), 0, "XXX");
-
-}
-
-class OlsrHnaTestCase : public TestCase {
-public:
- OlsrHnaTestCase ();
- virtual void DoRun (void);
-};
-
-OlsrHnaTestCase::OlsrHnaTestCase ()
- : TestCase ("Check Hna olsr messages")
-{}
-
-void
-OlsrHnaTestCase::DoRun (void)
-{
- Packet packet;
- olsr::MessageHeader msgIn;
- olsr::MessageHeader::Hna &hnaIn = msgIn.GetHna ();
-
- hnaIn.associations.push_back ((olsr::MessageHeader::Hna::Association)
- { Ipv4Address ("1.2.3.4"), Ipv4Mask ("255.255.255.0")});
- hnaIn.associations.push_back ((olsr::MessageHeader::Hna::Association)
- {Ipv4Address ("1.2.3.5"), Ipv4Mask ("255.255.0.0")});
- packet.AddHeader (msgIn);
-
- olsr::MessageHeader msgOut;
- packet.RemoveHeader (msgOut);
- olsr::MessageHeader::Hna &hnaOut = msgOut.GetHna ();
-
- NS_TEST_ASSERT_MSG_EQ (hnaOut.associations.size (), 2, "XXX");
-
- NS_TEST_ASSERT_MSG_EQ (hnaOut.associations[0].address,
- Ipv4Address ("1.2.3.4"), "XXX");
- NS_TEST_ASSERT_MSG_EQ (hnaOut.associations[0].mask,
- Ipv4Mask ("255.255.255.0"), "XXX");
-
- NS_TEST_ASSERT_MSG_EQ (hnaOut.associations[1].address,
- Ipv4Address ("1.2.3.5"), "XXX");
- NS_TEST_ASSERT_MSG_EQ (hnaOut.associations[1].mask,
- Ipv4Mask ("255.255.0.0"), "XXX");
-
- NS_TEST_ASSERT_MSG_EQ (packet.GetSize (), 0, "All bytes in packet were not read");
-
-}
-
-
-static class OlsrTestSuite : public TestSuite
-{
-public:
- OlsrTestSuite ();
-} g_olsrTestSuite;
-
-OlsrTestSuite::OlsrTestSuite()
- : TestSuite("routing-olsr-header", UNIT)
-{
- AddTestCase(new OlsrHnaTestCase());
- AddTestCase(new OlsrTcTestCase());
- AddTestCase(new OlsrHelloTestCase());
- AddTestCase(new OlsrMidTestCase());
- AddTestCase(new OlsrEmfTestCase());
-}
-
-} // namespace ns3
-
--- a/src/olsr/model/olsr-routing-protocol.cc Tue Mar 29 19:02:31 2011 +0100
+++ b/src/olsr/model/olsr-routing-protocol.cc Tue Mar 29 19:05:15 2011 +0100
@@ -3294,133 +3294,6 @@
}
return retval;
}
-OlsrMprTestCase::OlsrMprTestCase ()
- : TestCase ("Check OLSR MPR computing mechanism")
-{
-}
-OlsrMprTestCase::~OlsrMprTestCase ()
-{
-}
-void
-OlsrMprTestCase::DoRun ()
-{
- Ptr<RoutingProtocol> protocol = CreateObject<RoutingProtocol> ();
- protocol->m_mainAddress = Ipv4Address ("10.0.0.1");
- OlsrState & state = protocol->m_state;
-
- /*
- * 1 -- 2
- * | |
- * 3 -- 4
- *
- * Node 1 must select only one MPR (2 or 3, doesn't matter)
- */
- NeighborTuple neigbor;
- neigbor.status = NeighborTuple::STATUS_SYM;
- neigbor.willingness = OLSR_WILL_DEFAULT;
- neigbor.neighborMainAddr = Ipv4Address ("10.0.0.2");
- protocol->m_state.InsertNeighborTuple (neigbor);
- neigbor.neighborMainAddr = Ipv4Address ("10.0.0.3");
- protocol->m_state.InsertNeighborTuple (neigbor);
- TwoHopNeighborTuple tuple;
- tuple.expirationTime = Seconds (3600);
- tuple.neighborMainAddr = Ipv4Address ("10.0.0.2");
- tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.4");
- protocol->m_state.InsertTwoHopNeighborTuple (tuple);
- tuple.neighborMainAddr = Ipv4Address ("10.0.0.3");
- tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.4");
- protocol->m_state.InsertTwoHopNeighborTuple (tuple);
-
- protocol->MprComputation ();
- NS_TEST_EXPECT_MSG_EQ (state.GetMprSet ().size (), 1 , "An only address must be chosen.");
- /*
- * 1 -- 2 -- 5
- * | |
- * 3 -- 4
- *
- * Node 1 must select node 2 as MPR.
- */
- tuple.neighborMainAddr = Ipv4Address ("10.0.0.2");
- tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.5");
- protocol->m_state.InsertTwoHopNeighborTuple (tuple);
-
- protocol->MprComputation ();
- MprSet mpr = state.GetMprSet ();
- NS_TEST_EXPECT_MSG_EQ (mpr.size (), 1 , "An only address must be chosen.");
- NS_TEST_EXPECT_MSG_EQ ((mpr.find ("10.0.0.2") != mpr.end ()), true, "Node 1 must select node 2 as MPR");
- /*
- * 1 -- 2 -- 5
- * | |
- * 3 -- 4
- * |
- * 6
- *
- * Node 1 must select nodes 2 and 3 as MPRs.
- */
- tuple.neighborMainAddr = Ipv4Address ("10.0.0.3");
- tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.6");
- protocol->m_state.InsertTwoHopNeighborTuple (tuple);
-
- protocol->MprComputation ();
- mpr = state.GetMprSet ();
- NS_TEST_EXPECT_MSG_EQ (mpr.size (), 2 , "An only address must be chosen.");
- NS_TEST_EXPECT_MSG_EQ ((mpr.find ("10.0.0.2") != mpr.end ()), true, "Node 1 must select node 2 as MPR");
- NS_TEST_EXPECT_MSG_EQ ((mpr.find ("10.0.0.3") != mpr.end ()), true, "Node 1 must select node 3 as MPR");
- /*
- * 7 (OLSR_WILL_ALWAYS)
- * |
- * 1 -- 2 -- 5
- * | |
- * 3 -- 4
- * |
- * 6
- *
- * Node 1 must select nodes 2, 3 and 7 (since it is WILL_ALWAYS) as MPRs.
- */
- neigbor.willingness = OLSR_WILL_ALWAYS;
- neigbor.neighborMainAddr = Ipv4Address ("10.0.0.7");
- protocol->m_state.InsertNeighborTuple (neigbor);
-
- protocol->MprComputation ();
- mpr = state.GetMprSet ();
- NS_TEST_EXPECT_MSG_EQ (mpr.size (), 3 , "An only address must be chosen.");
- NS_TEST_EXPECT_MSG_EQ ((mpr.find ("10.0.0.7") != mpr.end ()), true, "Node 1 must select node 7 as MPR");
- /*
- * 7 <- WILL_ALWAYS
- * |
- * 9 -- 8 -- 1 -- 2 -- 5
- * | |
- * ^ 3 -- 4
- * | |
- * WILL_NEVER 6
- *
- * Node 1 must select nodes 2, 3 and 7 (since it is WILL_ALWAYS) as MPRs.
- * Node 1 must NOT select node 8 as MPR since it is WILL_NEVER
- */
- neigbor.willingness = OLSR_WILL_NEVER;
- neigbor.neighborMainAddr = Ipv4Address ("10.0.0.8");
- protocol->m_state.InsertNeighborTuple (neigbor);
- tuple.neighborMainAddr = Ipv4Address ("10.0.0.8");
- tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.9");
- protocol->m_state.InsertTwoHopNeighborTuple (tuple);
-
- protocol->MprComputation ();
- mpr = state.GetMprSet ();
- NS_TEST_EXPECT_MSG_EQ (mpr.size (), 3 , "An only address must be chosen.");
- NS_TEST_EXPECT_MSG_EQ ((mpr.find ("10.0.0.9") == mpr.end ()), true, "Node 1 must NOT select node 8 as MPR");
-}
-
-static class OlsrProtocolTestSuite : public TestSuite
-{
-public:
- OlsrProtocolTestSuite ();
-} g_olsrProtocolTestSuite;
-
-OlsrProtocolTestSuite::OlsrProtocolTestSuite()
- : TestSuite("routing-olsr", UNIT)
-{
- AddTestCase (new OlsrMprTestCase ());
-}
bool
RoutingProtocol::IsMyOwnAddress (const Ipv4Address & a) const
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/olsr/test/olsr-header-test-suite.cc Tue Mar 29 19:05:15 2011 +0100
@@ -0,0 +1,311 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 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>
+ */
+
+#include "ns3/test.h"
+#include "ns3/olsr-header.h"
+#include "ns3/packet.h"
+
+namespace ns3 {
+
+class OlsrEmfTestCase : public TestCase {
+public:
+ OlsrEmfTestCase ();
+ virtual void DoRun (void);
+};
+
+OlsrEmfTestCase::OlsrEmfTestCase ()
+ : TestCase ("Check Emf olsr time conversion")
+{}
+void
+OlsrEmfTestCase::DoRun (void)
+{
+ for (int time = 1; time <= 30; time++)
+ {
+ uint8_t emf = olsr::SecondsToEmf (time);
+ double seconds = olsr::EmfToSeconds (emf);
+ NS_TEST_ASSERT_MSG_EQ((seconds < 0 || fabs (seconds - time) > 0.1), false,
+ "XXX");
+ }
+}
+
+
+class OlsrMidTestCase : public TestCase {
+public:
+ OlsrMidTestCase ();
+ virtual void DoRun (void);
+};
+
+OlsrMidTestCase::OlsrMidTestCase ()
+ : TestCase ("Check Mid olsr messages")
+{}
+void
+OlsrMidTestCase::DoRun (void)
+{
+ Packet packet;
+
+ {
+ olsr::PacketHeader hdr;
+ olsr::MessageHeader msg1;
+ olsr::MessageHeader::Mid &mid1 = msg1.GetMid ();
+ olsr::MessageHeader msg2;
+ olsr::MessageHeader::Mid &mid2 = msg2.GetMid ();
+
+ // MID message #1
+ {
+ std::vector<Ipv4Address> &addresses = mid1.interfaceAddresses;
+ addresses.clear ();
+ addresses.push_back (Ipv4Address ("1.2.3.4"));
+ addresses.push_back (Ipv4Address ("1.2.3.5"));
+ }
+
+ msg1.SetTimeToLive (255);
+ msg1.SetOriginatorAddress (Ipv4Address ("11.22.33.44"));
+ msg1.SetVTime (Seconds (9));
+ msg1.SetMessageSequenceNumber (7);
+
+ // MID message #2
+ {
+ std::vector<Ipv4Address> &addresses = mid2.interfaceAddresses;
+ addresses.clear ();
+ addresses.push_back (Ipv4Address ("2.2.3.4"));
+ addresses.push_back (Ipv4Address ("2.2.3.5"));
+ }
+
+ msg2.SetTimeToLive (254);
+ msg2.SetOriginatorAddress (Ipv4Address ("12.22.33.44"));
+ msg2.SetVTime (Seconds (10));
+ msg2.SetMessageType (olsr::MessageHeader::MID_MESSAGE);
+ msg2.SetMessageSequenceNumber (7);
+
+ // Build an OLSR packet header
+ hdr.SetPacketLength (hdr.GetSerializedSize () + msg1.GetSerializedSize () + msg2.GetSerializedSize ());
+ hdr.SetPacketSequenceNumber (123);
+
+
+ // Now add all the headers in the correct order
+ packet.AddHeader (msg2);
+ packet.AddHeader (msg1);
+ packet.AddHeader (hdr);
+ }
+
+ {
+ olsr::PacketHeader hdr;
+ packet.RemoveHeader (hdr);
+ NS_TEST_ASSERT_MSG_EQ (hdr.GetPacketSequenceNumber (), 123, "XXX");
+ uint32_t sizeLeft = hdr.GetPacketLength () - hdr.GetSerializedSize ();
+ {
+ olsr::MessageHeader msg1;
+
+ packet.RemoveHeader (msg1);
+
+ NS_TEST_ASSERT_MSG_EQ (msg1.GetTimeToLive (), 255, "XXX");
+ NS_TEST_ASSERT_MSG_EQ (msg1.GetOriginatorAddress (), Ipv4Address ("11.22.33.44"), "XXX");
+ NS_TEST_ASSERT_MSG_EQ (msg1.GetVTime (), Seconds (9), "XXX");
+ NS_TEST_ASSERT_MSG_EQ (msg1.GetMessageType (), olsr::MessageHeader::MID_MESSAGE, "XXX");
+ NS_TEST_ASSERT_MSG_EQ (msg1.GetMessageSequenceNumber (), 7, "XXX");
+
+ olsr::MessageHeader::Mid &mid1 = msg1.GetMid ();
+ NS_TEST_ASSERT_MSG_EQ (mid1.interfaceAddresses.size (), 2, "XXX");
+ NS_TEST_ASSERT_MSG_EQ (*mid1.interfaceAddresses.begin (), Ipv4Address ("1.2.3.4"), "XXX");
+
+ sizeLeft -= msg1.GetSerializedSize ();
+ NS_TEST_ASSERT_MSG_EQ((sizeLeft > 0), true, "XXX");
+ }
+ {
+ // now read the second message
+ olsr::MessageHeader msg2;
+
+ packet.RemoveHeader (msg2);
+
+ NS_TEST_ASSERT_MSG_EQ (msg2.GetTimeToLive (), 254, "XXX");
+ NS_TEST_ASSERT_MSG_EQ (msg2.GetOriginatorAddress (), Ipv4Address ("12.22.33.44"), "XXX");
+ NS_TEST_ASSERT_MSG_EQ (msg2.GetVTime (), Seconds (10), "XXX");
+ NS_TEST_ASSERT_MSG_EQ (msg2.GetMessageType (), olsr::MessageHeader::MID_MESSAGE, "XXX");
+ NS_TEST_ASSERT_MSG_EQ (msg2.GetMessageSequenceNumber (), 7, "XXX");
+
+ olsr::MessageHeader::Mid mid2 = msg2.GetMid ();
+ NS_TEST_ASSERT_MSG_EQ (mid2.interfaceAddresses.size (), 2, "XXX");
+ NS_TEST_ASSERT_MSG_EQ (*mid2.interfaceAddresses.begin (), Ipv4Address ("2.2.3.4"), "XXX");
+
+ sizeLeft -= msg2.GetSerializedSize ();
+ NS_TEST_ASSERT_MSG_EQ (sizeLeft, 0, "XXX");
+ }
+ }
+}
+
+
+class OlsrHelloTestCase : public TestCase {
+public:
+ OlsrHelloTestCase ();
+ virtual void DoRun (void);
+};
+
+OlsrHelloTestCase::OlsrHelloTestCase ()
+ : TestCase ("Check Hello olsr messages")
+{}
+void
+OlsrHelloTestCase::DoRun (void)
+{
+ Packet packet;
+ olsr::MessageHeader msgIn;
+ olsr::MessageHeader::Hello &helloIn = msgIn.GetHello ();
+
+ helloIn.SetHTime (Seconds (7));
+ helloIn.willingness = 66;
+
+ {
+ olsr::MessageHeader::Hello::LinkMessage lm1;
+ lm1.linkCode = 2;
+ lm1.neighborInterfaceAddresses.push_back (Ipv4Address ("1.2.3.4"));
+ lm1.neighborInterfaceAddresses.push_back (Ipv4Address ("1.2.3.5"));
+ helloIn.linkMessages.push_back (lm1);
+
+ olsr::MessageHeader::Hello::LinkMessage lm2;
+ lm2.linkCode = 3;
+ lm2.neighborInterfaceAddresses.push_back (Ipv4Address ("2.2.3.4"));
+ lm2.neighborInterfaceAddresses.push_back (Ipv4Address ("2.2.3.5"));
+ helloIn.linkMessages.push_back (lm2);
+ }
+
+ packet.AddHeader (msgIn);
+
+ olsr::MessageHeader msgOut;
+ packet.RemoveHeader (msgOut);
+ olsr::MessageHeader::Hello &helloOut = msgOut.GetHello ();
+
+ NS_TEST_ASSERT_MSG_EQ (helloOut.GetHTime (), Seconds (7), "XXX");
+ NS_TEST_ASSERT_MSG_EQ (helloOut.willingness, 66, "XXX");
+ NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages.size (), 2, "XXX");
+
+ NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[0].linkCode, 2, "XXX");
+ NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[0].neighborInterfaceAddresses[0],
+ Ipv4Address ("1.2.3.4"), "XXX");
+ NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[0].neighborInterfaceAddresses[1],
+ Ipv4Address ("1.2.3.5"), "XXX");
+
+ NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[1].linkCode, 3, "XXX");
+ NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[1].neighborInterfaceAddresses[0],
+ Ipv4Address ("2.2.3.4"), "XXX");
+ NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[1].neighborInterfaceAddresses[1],
+ Ipv4Address ("2.2.3.5"), "XXX");
+
+ NS_TEST_ASSERT_MSG_EQ (packet.GetSize (), 0, "All bytes in packet were not read");
+
+}
+
+class OlsrTcTestCase : public TestCase {
+public:
+ OlsrTcTestCase ();
+ virtual void DoRun (void);
+};
+
+OlsrTcTestCase::OlsrTcTestCase ()
+ : TestCase ("Check Tc olsr messages")
+{}
+void
+OlsrTcTestCase::DoRun (void)
+{
+ Packet packet;
+ olsr::MessageHeader msgIn;
+ olsr::MessageHeader::Tc &tcIn = msgIn.GetTc ();
+
+ tcIn.ansn = 0x1234;
+ tcIn.neighborAddresses.push_back (Ipv4Address ("1.2.3.4"));
+ tcIn.neighborAddresses.push_back (Ipv4Address ("1.2.3.5"));
+ packet.AddHeader (msgIn);
+
+ olsr::MessageHeader msgOut;
+ packet.RemoveHeader (msgOut);
+ olsr::MessageHeader::Tc &tcOut = msgOut.GetTc ();
+
+ NS_TEST_ASSERT_MSG_EQ (tcOut.ansn, 0x1234, "XXX");
+ NS_TEST_ASSERT_MSG_EQ (tcOut.neighborAddresses.size (), 2, "XXX");
+
+ NS_TEST_ASSERT_MSG_EQ (tcOut.neighborAddresses[0],
+ Ipv4Address ("1.2.3.4"), "XXX");
+ NS_TEST_ASSERT_MSG_EQ (tcOut.neighborAddresses[1],
+ Ipv4Address ("1.2.3.5"), "XXX");
+
+ NS_TEST_ASSERT_MSG_EQ (packet.GetSize (), 0, "XXX");
+
+}
+
+class OlsrHnaTestCase : public TestCase {
+public:
+ OlsrHnaTestCase ();
+ virtual void DoRun (void);
+};
+
+OlsrHnaTestCase::OlsrHnaTestCase ()
+ : TestCase ("Check Hna olsr messages")
+{}
+
+void
+OlsrHnaTestCase::DoRun (void)
+{
+ Packet packet;
+ olsr::MessageHeader msgIn;
+ olsr::MessageHeader::Hna &hnaIn = msgIn.GetHna ();
+
+ hnaIn.associations.push_back ((olsr::MessageHeader::Hna::Association)
+ { Ipv4Address ("1.2.3.4"), Ipv4Mask ("255.255.255.0")});
+ hnaIn.associations.push_back ((olsr::MessageHeader::Hna::Association)
+ {Ipv4Address ("1.2.3.5"), Ipv4Mask ("255.255.0.0")});
+ packet.AddHeader (msgIn);
+
+ olsr::MessageHeader msgOut;
+ packet.RemoveHeader (msgOut);
+ olsr::MessageHeader::Hna &hnaOut = msgOut.GetHna ();
+
+ NS_TEST_ASSERT_MSG_EQ (hnaOut.associations.size (), 2, "XXX");
+
+ NS_TEST_ASSERT_MSG_EQ (hnaOut.associations[0].address,
+ Ipv4Address ("1.2.3.4"), "XXX");
+ NS_TEST_ASSERT_MSG_EQ (hnaOut.associations[0].mask,
+ Ipv4Mask ("255.255.255.0"), "XXX");
+
+ NS_TEST_ASSERT_MSG_EQ (hnaOut.associations[1].address,
+ Ipv4Address ("1.2.3.5"), "XXX");
+ NS_TEST_ASSERT_MSG_EQ (hnaOut.associations[1].mask,
+ Ipv4Mask ("255.255.0.0"), "XXX");
+
+ NS_TEST_ASSERT_MSG_EQ (packet.GetSize (), 0, "All bytes in packet were not read");
+
+}
+
+
+static class OlsrTestSuite : public TestSuite
+{
+public:
+ OlsrTestSuite ();
+} g_olsrTestSuite;
+
+OlsrTestSuite::OlsrTestSuite()
+ : TestSuite("routing-olsr-header", UNIT)
+{
+ AddTestCase(new OlsrHnaTestCase());
+ AddTestCase(new OlsrTcTestCase());
+ AddTestCase(new OlsrHelloTestCase());
+ AddTestCase(new OlsrMidTestCase());
+ AddTestCase(new OlsrEmfTestCase());
+}
+
+} // namespace ns3
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/olsr/test/olsr-routing-protocol-test-suite.cc Tue Mar 29 19:05:15 2011 +0100
@@ -0,0 +1,173 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2004 Francisco J. Ros
+ * Copyright (c) 2007 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
+ *
+ * Authors: Francisco J. Ros <fjrm@dif.um.es>
+ * Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
+ */
+
+#include "ns3/test.h"
+#include "ns3/olsr-routing-protocol.h"
+#include "ns3/ipv4-header.h"
+
+/********** Willingness **********/
+
+/// Willingness for forwarding packets from other nodes: never.
+#define OLSR_WILL_NEVER 0
+/// Willingness for forwarding packets from other nodes: low.
+#define OLSR_WILL_LOW 1
+/// Willingness for forwarding packets from other nodes: medium.
+#define OLSR_WILL_DEFAULT 3
+/// Willingness for forwarding packets from other nodes: high.
+#define OLSR_WILL_HIGH 6
+/// Willingness for forwarding packets from other nodes: always.
+#define OLSR_WILL_ALWAYS 7
+
+namespace ns3 {
+namespace olsr {
+
+OlsrMprTestCase::OlsrMprTestCase ()
+ : TestCase ("Check OLSR MPR computing mechanism")
+{
+}
+OlsrMprTestCase::~OlsrMprTestCase ()
+{
+}
+void
+OlsrMprTestCase::DoRun ()
+{
+ Ptr<RoutingProtocol> protocol = CreateObject<RoutingProtocol> ();
+ protocol->m_mainAddress = Ipv4Address ("10.0.0.1");
+ OlsrState & state = protocol->m_state;
+
+ /*
+ * 1 -- 2
+ * | |
+ * 3 -- 4
+ *
+ * Node 1 must select only one MPR (2 or 3, doesn't matter)
+ */
+ NeighborTuple neigbor;
+ neigbor.status = NeighborTuple::STATUS_SYM;
+ neigbor.willingness = OLSR_WILL_DEFAULT;
+ neigbor.neighborMainAddr = Ipv4Address ("10.0.0.2");
+ protocol->m_state.InsertNeighborTuple (neigbor);
+ neigbor.neighborMainAddr = Ipv4Address ("10.0.0.3");
+ protocol->m_state.InsertNeighborTuple (neigbor);
+ TwoHopNeighborTuple tuple;
+ tuple.expirationTime = Seconds (3600);
+ tuple.neighborMainAddr = Ipv4Address ("10.0.0.2");
+ tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.4");
+ protocol->m_state.InsertTwoHopNeighborTuple (tuple);
+ tuple.neighborMainAddr = Ipv4Address ("10.0.0.3");
+ tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.4");
+ protocol->m_state.InsertTwoHopNeighborTuple (tuple);
+
+ protocol->MprComputation ();
+ NS_TEST_EXPECT_MSG_EQ (state.GetMprSet ().size (), 1 , "An only address must be chosen.");
+ /*
+ * 1 -- 2 -- 5
+ * | |
+ * 3 -- 4
+ *
+ * Node 1 must select node 2 as MPR.
+ */
+ tuple.neighborMainAddr = Ipv4Address ("10.0.0.2");
+ tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.5");
+ protocol->m_state.InsertTwoHopNeighborTuple (tuple);
+
+ protocol->MprComputation ();
+ MprSet mpr = state.GetMprSet ();
+ NS_TEST_EXPECT_MSG_EQ (mpr.size (), 1 , "An only address must be chosen.");
+ NS_TEST_EXPECT_MSG_EQ ((mpr.find ("10.0.0.2") != mpr.end ()), true, "Node 1 must select node 2 as MPR");
+ /*
+ * 1 -- 2 -- 5
+ * | |
+ * 3 -- 4
+ * |
+ * 6
+ *
+ * Node 1 must select nodes 2 and 3 as MPRs.
+ */
+ tuple.neighborMainAddr = Ipv4Address ("10.0.0.3");
+ tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.6");
+ protocol->m_state.InsertTwoHopNeighborTuple (tuple);
+
+ protocol->MprComputation ();
+ mpr = state.GetMprSet ();
+ NS_TEST_EXPECT_MSG_EQ (mpr.size (), 2 , "An only address must be chosen.");
+ NS_TEST_EXPECT_MSG_EQ ((mpr.find ("10.0.0.2") != mpr.end ()), true, "Node 1 must select node 2 as MPR");
+ NS_TEST_EXPECT_MSG_EQ ((mpr.find ("10.0.0.3") != mpr.end ()), true, "Node 1 must select node 3 as MPR");
+ /*
+ * 7 (OLSR_WILL_ALWAYS)
+ * |
+ * 1 -- 2 -- 5
+ * | |
+ * 3 -- 4
+ * |
+ * 6
+ *
+ * Node 1 must select nodes 2, 3 and 7 (since it is WILL_ALWAYS) as MPRs.
+ */
+ neigbor.willingness = OLSR_WILL_ALWAYS;
+ neigbor.neighborMainAddr = Ipv4Address ("10.0.0.7");
+ protocol->m_state.InsertNeighborTuple (neigbor);
+
+ protocol->MprComputation ();
+ mpr = state.GetMprSet ();
+ NS_TEST_EXPECT_MSG_EQ (mpr.size (), 3 , "An only address must be chosen.");
+ NS_TEST_EXPECT_MSG_EQ ((mpr.find ("10.0.0.7") != mpr.end ()), true, "Node 1 must select node 7 as MPR");
+ /*
+ * 7 <- WILL_ALWAYS
+ * |
+ * 9 -- 8 -- 1 -- 2 -- 5
+ * | |
+ * ^ 3 -- 4
+ * | |
+ * WILL_NEVER 6
+ *
+ * Node 1 must select nodes 2, 3 and 7 (since it is WILL_ALWAYS) as MPRs.
+ * Node 1 must NOT select node 8 as MPR since it is WILL_NEVER
+ */
+ neigbor.willingness = OLSR_WILL_NEVER;
+ neigbor.neighborMainAddr = Ipv4Address ("10.0.0.8");
+ protocol->m_state.InsertNeighborTuple (neigbor);
+ tuple.neighborMainAddr = Ipv4Address ("10.0.0.8");
+ tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.9");
+ protocol->m_state.InsertTwoHopNeighborTuple (tuple);
+
+ protocol->MprComputation ();
+ mpr = state.GetMprSet ();
+ NS_TEST_EXPECT_MSG_EQ (mpr.size (), 3 , "An only address must be chosen.");
+ NS_TEST_EXPECT_MSG_EQ ((mpr.find ("10.0.0.9") == mpr.end ()), true, "Node 1 must NOT select node 8 as MPR");
+}
+
+static class OlsrProtocolTestSuite : public TestSuite
+{
+public:
+ OlsrProtocolTestSuite ();
+} g_olsrProtocolTestSuite;
+
+OlsrProtocolTestSuite::OlsrProtocolTestSuite()
+ : TestSuite("routing-olsr", UNIT)
+{
+ AddTestCase (new OlsrMprTestCase ());
+}
+
+}} // namespace olsr, ns3
+
+
--- a/src/olsr/wscript Tue Mar 29 19:02:31 2011 +0100
+++ b/src/olsr/wscript Tue Mar 29 19:05:15 2011 +0100
@@ -12,10 +12,12 @@
module_test = bld.create_ns3_module_test_library('olsr')
module_test.source = [
- 'test/regression-test-suite.cc',
+ 'test/bug780-test.cc',
'test/hello-regression-test.cc',
+ 'test/olsr-header-test-suite.cc',
+ 'test/regression-test-suite.cc',
+ 'test/olsr-routing-protocol-test-suite.cc',
'test/tc-regression-test.cc',
- 'test/bug780-test.cc',
]
headers = bld.new_task_gen('ns3header')
--- a/src/point-to-point/model/point-to-point-test.cc Tue Mar 29 19:02:31 2011 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,72 +0,0 @@
-#include "ns3/test.h"
-#include "ns3/drop-tail-queue.h"
-#include "ns3/simulator.h"
-#include "point-to-point-net-device.h"
-#include "point-to-point-channel.h"
-
-namespace ns3 {
-
-class PointToPointTest : public TestCase
-{
-public:
- PointToPointTest ();
-
- virtual void DoRun (void);
-
-private:
- void SendOnePacket (Ptr<PointToPointNetDevice> device);
-};
-
-PointToPointTest::PointToPointTest ()
- : TestCase ("PointToPoint")
-{}
-
-void
-PointToPointTest::SendOnePacket (Ptr<PointToPointNetDevice> device)
-{
- Ptr<Packet> p = Create<Packet> ();
- device->Send (p, device->GetBroadcast (), 0x800);
-}
-
-
-void
-PointToPointTest::DoRun (void)
-{
- Ptr<Node> a = CreateObject<Node> ();
- Ptr<Node> b = CreateObject<Node> ();
- Ptr<PointToPointNetDevice> devA = CreateObject<PointToPointNetDevice> ();
- Ptr<PointToPointNetDevice> devB = CreateObject<PointToPointNetDevice> ();
- Ptr<PointToPointChannel> channel = CreateObject<PointToPointChannel> ();
-
- devA->Attach (channel);
- devA->SetAddress (Mac48Address::Allocate ());
- devA->SetQueue (CreateObject<DropTailQueue> ());
- devB->Attach (channel);
- devB->SetAddress (Mac48Address::Allocate ());
- devB->SetQueue (CreateObject<DropTailQueue> ());
-
- a->AddDevice (devA);
- b->AddDevice (devB);
-
- Simulator::Schedule (Seconds (1.0), &PointToPointTest::SendOnePacket, this, devA);
-
- Simulator::Run ();
-
- Simulator::Destroy ();
-}
-//-----------------------------------------------------------------------------
-class PointToPointTestSuite : public TestSuite
-{
-public:
- PointToPointTestSuite ();
-};
-
-PointToPointTestSuite::PointToPointTestSuite ()
- : TestSuite ("devices-point-to-point", UNIT)
-{
- AddTestCase (new PointToPointTest);
-}
-
-static PointToPointTestSuite g_pointToPointTestSuite;
-
-} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/point-to-point/test/point-to-point-test.cc Tue Mar 29 19:05:15 2011 +0100
@@ -0,0 +1,72 @@
+#include "ns3/test.h"
+#include "ns3/drop-tail-queue.h"
+#include "ns3/simulator.h"
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/point-to-point-channel.h"
+
+namespace ns3 {
+
+class PointToPointTest : public TestCase
+{
+public:
+ PointToPointTest ();
+
+ virtual void DoRun (void);
+
+private:
+ void SendOnePacket (Ptr<PointToPointNetDevice> device);
+};
+
+PointToPointTest::PointToPointTest ()
+ : TestCase ("PointToPoint")
+{}
+
+void
+PointToPointTest::SendOnePacket (Ptr<PointToPointNetDevice> device)
+{
+ Ptr<Packet> p = Create<Packet> ();
+ device->Send (p, device->GetBroadcast (), 0x800);
+}
+
+
+void
+PointToPointTest::DoRun (void)
+{
+ Ptr<Node> a = CreateObject<Node> ();
+ Ptr<Node> b = CreateObject<Node> ();
+ Ptr<PointToPointNetDevice> devA = CreateObject<PointToPointNetDevice> ();
+ Ptr<PointToPointNetDevice> devB = CreateObject<PointToPointNetDevice> ();
+ Ptr<PointToPointChannel> channel = CreateObject<PointToPointChannel> ();
+
+ devA->Attach (channel);
+ devA->SetAddress (Mac48Address::Allocate ());
+ devA->SetQueue (CreateObject<DropTailQueue> ());
+ devB->Attach (channel);
+ devB->SetAddress (Mac48Address::Allocate ());
+ devB->SetQueue (CreateObject<DropTailQueue> ());
+
+ a->AddDevice (devA);
+ b->AddDevice (devB);
+
+ Simulator::Schedule (Seconds (1.0), &PointToPointTest::SendOnePacket, this, devA);
+
+ Simulator::Run ();
+
+ Simulator::Destroy ();
+}
+//-----------------------------------------------------------------------------
+class PointToPointTestSuite : public TestSuite
+{
+public:
+ PointToPointTestSuite ();
+};
+
+PointToPointTestSuite::PointToPointTestSuite ()
+ : TestSuite ("devices-point-to-point", UNIT)
+{
+ AddTestCase (new PointToPointTest);
+}
+
+static PointToPointTestSuite g_pointToPointTestSuite;
+
+} // namespace ns3
--- a/src/point-to-point/wscript Tue Mar 29 19:02:31 2011 +0100
+++ b/src/point-to-point/wscript Tue Mar 29 19:05:15 2011 +0100
@@ -7,10 +7,15 @@
'model/point-to-point-net-device.cc',
'model/point-to-point-channel.cc',
'model/point-to-point-remote-channel.cc',
- 'model/point-to-point-test.cc',
'model/ppp-header.cc',
'helper/point-to-point-helper.cc',
]
+
+ module_test = bld.create_ns3_module_test_library('point-to-point')
+ module_test.source = [
+ 'test/point-to-point-test.cc',
+ ]
+
headers = bld.new_task_gen('ns3header')
headers.module = 'point-to-point'
headers.source = [
--- a/src/tools/model/event-garbage-collector.cc Tue Mar 29 19:02:31 2011 +0100
+++ b/src/tools/model/event-garbage-collector.cc Tue Mar 29 19:05:15 2011 +0100
@@ -87,69 +87,3 @@
} // namespace ns3
-#include "ns3/test.h"
-
-namespace ns3 {
-
-class EventGarbageCollectorTestCase : public TestCase
-{
- int m_counter;
- EventGarbageCollector *m_events;
-
- void EventGarbageCollectorCallback ();
-
-public:
-
- EventGarbageCollectorTestCase ();
- virtual ~EventGarbageCollectorTestCase ();
- virtual void DoRun (void);
-};
-
-EventGarbageCollectorTestCase::EventGarbageCollectorTestCase ()
- : TestCase ("EventGarbageCollector"), m_counter (0), m_events (0)
-{}
-
-EventGarbageCollectorTestCase::~EventGarbageCollectorTestCase ()
-{}
-
-void
-EventGarbageCollectorTestCase::EventGarbageCollectorCallback ()
-{
- m_counter++;
- if (m_counter == 50)
- {
- // this should cause the remaining (50) events to be cancelled
- delete m_events;
- m_events = 0;
- }
-}
-
-void EventGarbageCollectorTestCase::DoRun (void)
-{
- m_events = new EventGarbageCollector ();
-
- for (int n = 0; n < 100; n++)
- {
- m_events->Track (Simulator::Schedule
- (Simulator::Now (),
- &EventGarbageCollectorTestCase::EventGarbageCollectorCallback,
- this));
- }
- Simulator::Run ();
- NS_TEST_EXPECT_MSG_EQ (m_events, 0, "");
- NS_TEST_EXPECT_MSG_EQ (m_counter, 50, "");
- Simulator::Destroy ();
-}
-
-static class EventGarbageCollectorTestSuite : public TestSuite
-{
-public:
- EventGarbageCollectorTestSuite ()
- : TestSuite ("event-garbage-collector", UNIT)
- {
- AddTestCase (new EventGarbageCollectorTestCase ());
- }
-} g_eventGarbageCollectorTests;
-
-}
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/tools/test/event-garbage-collector-test-suite.cc Tue Mar 29 19:05:15 2011 +0100
@@ -0,0 +1,87 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 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>
+ */
+
+#include "ns3/test.h"
+#include "ns3/event-garbage-collector.h"
+
+namespace ns3 {
+
+class EventGarbageCollectorTestCase : public TestCase
+{
+ int m_counter;
+ EventGarbageCollector *m_events;
+
+ void EventGarbageCollectorCallback ();
+
+public:
+
+ EventGarbageCollectorTestCase ();
+ virtual ~EventGarbageCollectorTestCase ();
+ virtual void DoRun (void);
+};
+
+EventGarbageCollectorTestCase::EventGarbageCollectorTestCase ()
+ : TestCase ("EventGarbageCollector"), m_counter (0), m_events (0)
+{}
+
+EventGarbageCollectorTestCase::~EventGarbageCollectorTestCase ()
+{}
+
+void
+EventGarbageCollectorTestCase::EventGarbageCollectorCallback ()
+{
+ m_counter++;
+ if (m_counter == 50)
+ {
+ // this should cause the remaining (50) events to be cancelled
+ delete m_events;
+ m_events = 0;
+ }
+}
+
+void EventGarbageCollectorTestCase::DoRun (void)
+{
+ m_events = new EventGarbageCollector ();
+
+ for (int n = 0; n < 100; n++)
+ {
+ m_events->Track (Simulator::Schedule
+ (Simulator::Now (),
+ &EventGarbageCollectorTestCase::EventGarbageCollectorCallback,
+ this));
+ }
+ Simulator::Run ();
+ NS_TEST_EXPECT_MSG_EQ (m_events, 0, "");
+ NS_TEST_EXPECT_MSG_EQ (m_counter, 50, "");
+ Simulator::Destroy ();
+}
+
+static class EventGarbageCollectorTestSuite : public TestSuite
+{
+public:
+ EventGarbageCollectorTestSuite ()
+ : TestSuite ("event-garbage-collector", UNIT)
+ {
+ AddTestCase (new EventGarbageCollectorTestCase ());
+ }
+} g_eventGarbageCollectorTests;
+
+}
+
--- a/src/tools/wscript Tue Mar 29 19:02:31 2011 +0100
+++ b/src/tools/wscript Tue Mar 29 19:05:15 2011 +0100
@@ -8,6 +8,11 @@
'model/gnuplot.cc',
'model/delay-jitter-estimation.cc',
]
+
+ module_test = bld.create_ns3_module_test_library('tools')
+ module_test.source = [
+ 'test/event-garbage-collector-test-suite.cc',
+ ]
headers = bld.new_task_gen('ns3header')
headers.module = 'tools'
--- a/src/topology-read/model/rocketfuel-topology-reader.cc Tue Mar 29 19:02:31 2011 +0100
+++ b/src/topology-read/model/rocketfuel-topology-reader.cc Tue Mar 29 19:05:15 2011 +0100
@@ -410,73 +410,3 @@
} /* namespace ns3 */
-//-----------------------------------------------------------------------------
-// Unit tests
-//-----------------------------------------------------------------------------
-
-#include "ns3/log.h"
-#include "ns3/abort.h"
-#include "ns3/attribute.h"
-#include "ns3/object-factory.h"
-#include "ns3/object-factory.h"
-#include "ns3/simulator.h"
-#include "ns3/test.h"
-
-namespace ns3 {
-
-class RocketfuelTopologyReaderTest: public TestCase
-{
-public:
- RocketfuelTopologyReaderTest ();
-private:
- virtual void DoRun (void);
-};
-
-RocketfuelTopologyReaderTest::RocketfuelTopologyReaderTest ()
- : TestCase ("RocketfuelTopologyReaderTest")
-{}
-
-
-void
-RocketfuelTopologyReaderTest::DoRun (void)
-{
- Ptr<RocketfuelTopologyReader> inFile;
- NodeContainer nodes;
-
- std::string input ("./src/topology-read/examples/RocketFuel_toposample_1239_weights.txt");
-
- inFile = CreateObject<RocketfuelTopologyReader> ();
- inFile->SetFileName(input);
-
- if (inFile != 0)
- {
- nodes = inFile->Read ();
- }
-
- NS_TEST_ASSERT_MSG_NE (nodes.GetN (), 0, "Problems reading node information the topology file..");
-
- NS_TEST_ASSERT_MSG_NE (inFile->LinksSize (), 0, "Problems reading the topology file.");
-
- NS_LOG_INFO ("Rocketfuel topology created with " << nodes.GetN () << " nodes and " <<
- inFile->LinksSize () << " links (from " << input << ")");
-
- NS_TEST_EXPECT_MSG_EQ (nodes.GetN (),315, "noes");
- NS_TEST_EXPECT_MSG_EQ (inFile->LinksSize (),972, "links");
- Simulator::Destroy ();
-}
-
-static class RocketfuelTopologyReaderTestSuite : public TestSuite
-{
-public:
- RocketfuelTopologyReaderTestSuite ();
-private:
-} g_rocketfueltopologyreaderTests;
-
-RocketfuelTopologyReaderTestSuite::RocketfuelTopologyReaderTestSuite ()
- : TestSuite ("rocketfuel-topology-reader", UNIT)
-{
- AddTestCase (new RocketfuelTopologyReaderTest ());
-}
-
-
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/topology-read/test/rocketfuel-topology-reader-test-suite.cc Tue Mar 29 19:05:15 2011 +0100
@@ -0,0 +1,95 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 Hajime Tazaki
+ *
+ * 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: Hajime Tazaki (tazaki@sfc.wide.ad.jp)
+ */
+
+//-----------------------------------------------------------------------------
+// Unit tests
+//-----------------------------------------------------------------------------
+
+#include "ns3/test.h"
+#include "ns3/rocketfuel-topology-reader.h"
+#include "ns3/log.h"
+#include "ns3/abort.h"
+#include "ns3/attribute.h"
+#include "ns3/object-factory.h"
+#include "ns3/object-factory.h"
+#include "ns3/simulator.h"
+
+namespace ns3 {
+
+NS_LOG_COMPONENT_DEFINE ("RocketfuelTopologyReader");
+
+NS_OBJECT_ENSURE_REGISTERED (RocketfuelTopologyReader);
+
+class RocketfuelTopologyReaderTest: public TestCase
+{
+public:
+ RocketfuelTopologyReaderTest ();
+private:
+ virtual void DoRun (void);
+};
+
+RocketfuelTopologyReaderTest::RocketfuelTopologyReaderTest ()
+ : TestCase ("RocketfuelTopologyReaderTest")
+{}
+
+
+void
+RocketfuelTopologyReaderTest::DoRun (void)
+{
+ Ptr<RocketfuelTopologyReader> inFile;
+ NodeContainer nodes;
+
+ std::string input ("./src/topology-read/examples/RocketFuel_toposample_1239_weights.txt");
+
+ inFile = CreateObject<RocketfuelTopologyReader> ();
+ inFile->SetFileName(input);
+
+ if (inFile != 0)
+ {
+ nodes = inFile->Read ();
+ }
+
+ NS_TEST_ASSERT_MSG_NE (nodes.GetN (), 0, "Problems reading node information the topology file..");
+
+ NS_TEST_ASSERT_MSG_NE (inFile->LinksSize (), 0, "Problems reading the topology file.");
+
+ NS_LOG_INFO ("Rocketfuel topology created with " << nodes.GetN () << " nodes and " <<
+ inFile->LinksSize () << " links (from " << input << ")");
+
+ NS_TEST_EXPECT_MSG_EQ (nodes.GetN (),315, "noes");
+ NS_TEST_EXPECT_MSG_EQ (inFile->LinksSize (),972, "links");
+ Simulator::Destroy ();
+}
+
+static class RocketfuelTopologyReaderTestSuite : public TestSuite
+{
+public:
+ RocketfuelTopologyReaderTestSuite ();
+private:
+} g_rocketfueltopologyreaderTests;
+
+RocketfuelTopologyReaderTestSuite::RocketfuelTopologyReaderTestSuite ()
+ : TestSuite ("rocketfuel-topology-reader", UNIT)
+{
+ AddTestCase (new RocketfuelTopologyReaderTest ());
+}
+
+
+}
--- a/src/topology-read/wscript Tue Mar 29 19:02:31 2011 +0100
+++ b/src/topology-read/wscript Tue Mar 29 19:05:15 2011 +0100
@@ -9,6 +9,12 @@
'model/rocketfuel-topology-reader.cc',
'helper/topology-reader-helper.cc',
]
+
+ module_test = bld.create_ns3_module_test_library('topology-read')
+ module_test.source = [
+ 'test/rocketfuel-topology-reader-test-suite.cc',
+ ]
+
headers = bld.new_task_gen('ns3header')
headers.module = 'topology-read'
headers.source = [