model+test: Fixing tests and making sure all tests pass
Refs #1005 (http://redmine.named-data.net/)
diff --git a/examples/ndn-simple-with-pit-count-stats.cc b/examples/ndn-simple-with-pit-count-stats.cc
index d7983c9..725da66 100644
--- a/examples/ndn-simple-with-pit-count-stats.cc
+++ b/examples/ndn-simple-with-pit-count-stats.cc
@@ -108,7 +108,7 @@
consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
consumerHelper.Install (nodes.Get (0)); // first node
- // Producer
+ // // Producer
ndn::AppHelper producerHelper ("ns3::ndn::Producer");
// Producer will reply to all requests starting with /prefix
producerHelper.SetPrefix ("/prefix");
diff --git a/model/fw/ndn-forwarding-strategy.cc b/model/fw/ndn-forwarding-strategy.cc
index df417dd..2275a8c 100644
--- a/model/fw/ndn-forwarding-strategy.cc
+++ b/model/fw/ndn-forwarding-strategy.cc
@@ -145,6 +145,7 @@
ForwardingStrategy::OnInterest (Ptr<Face> inFace,
Ptr<Interest> interest)
{
+ NS_LOG_FUNCTION (inFace << interest->GetName ());
m_inInterests (interest, inFace);
Ptr<pit::Entry> pitEntry = m_pit->Lookup (*interest);
diff --git a/model/ndn-content-object.cc b/model/ndn-content-object.cc
index 7fcb459..582ebc9 100644
--- a/model/ndn-content-object.cc
+++ b/model/ndn-content-object.cc
@@ -51,12 +51,14 @@
ContentObject::SetName (Ptr<Name> name)
{
m_name = name;
+ m_wire = 0;
}
void
ContentObject::SetName (const Name &name)
{
m_name = Create<Name> (name);
+ m_wire = 0;
}
const Name&
@@ -77,6 +79,7 @@
ContentObject::SetTimestamp (const Time ×tamp)
{
m_timestamp = timestamp;
+ m_wire = 0;
}
Time
@@ -89,8 +92,10 @@
ContentObject::SetFreshness (const Time &freshness)
{
m_freshness = freshness;
+ m_wire = 0;
}
+
Time
ContentObject::GetFreshness () const
{
@@ -101,6 +106,7 @@
ContentObject::SetSignature (uint32_t signature)
{
m_signature = signature;
+ m_wire = 0;
}
uint32_t
@@ -120,6 +126,7 @@
ContentObject::SetPayload (Ptr<Packet> payload)
{
m_payload = payload;
+ m_wire = 0;
}
Ptr<const Packet>
diff --git a/model/ndn-interest.cc b/model/ndn-interest.cc
index bd8784e..ffcaa0d 100644
--- a/model/ndn-interest.cc
+++ b/model/ndn-interest.cc
@@ -134,6 +134,7 @@
Interest::SetPayload (Ptr<Packet> payload)
{
m_payload = payload;
+ m_wire = 0;
}
Ptr<const Packet>
diff --git a/test/ndnSIM-fib-entry.cc b/test/ndnSIM-fib-entry.cc
index 8eda994..c57cf4d 100644
--- a/test/ndnSIM-fib-entry.cc
+++ b/test/ndnSIM-fib-entry.cc
@@ -36,7 +36,7 @@
namespace ns3
{
-class Client : public ndn::App
+class FibEntryTestApp : public ndn::App
{
protected:
void
@@ -48,8 +48,8 @@
Ptr<ndn::fib::Entry> fibEntry = GetNode ()->GetObject<ndn::Fib> ()->Add (ndn::Name ("/"), m_face, 0);
fibEntry->UpdateStatus (m_face, ndn::fib::FaceMetric::NDN_FIB_GREEN);
- Simulator::Schedule (Seconds (0.5), &Client::SendPacket, this, std::string("/1"), 1);
- Simulator::Schedule (Seconds (4.0), &Client::SendPacket, this, std::string("/2"), 1);
+ Simulator::Schedule (Seconds (0.5), &FibEntryTestApp::SendPacket, this, std::string("/1"), 1);
+ Simulator::Schedule (Seconds (4.0), &FibEntryTestApp::SendPacket, this, std::string("/2"), 1);
}
void
@@ -62,7 +62,7 @@
void
SendPacket (const std::string &prefix, uint32_t nonce)
{
- Ptr<ndn::Interest> interest;
+ Ptr<ndn::Interest> interest = Create<ndn::Interest> ();
interest->SetName (Create<ndn::Name> (prefix));
interest->SetNonce (nonce);
interest->SetInterestLifetime (Seconds (0.5));
@@ -111,7 +111,7 @@
ndn::StackHelper::AddRoute (node, "/", 0, 0);
- Ptr<Client> app1 = CreateObject<Client> ();
+ Ptr<Application> app1 = CreateObject<FibEntryTestApp> ();
node->AddApplication (app1);
ndn::AppHelper sinkHelper ("ns3::ndn::Producer");
diff --git a/test/ndnSIM-pit.cc b/test/ndnSIM-pit.cc
index 4dbf7af..db94f6f 100644
--- a/test/ndnSIM-pit.cc
+++ b/test/ndnSIM-pit.cc
@@ -30,7 +30,7 @@
namespace ns3
{
-class Client : public ndn::App
+class PitTestClient : public ndn::App
{
protected:
void
@@ -42,10 +42,10 @@
Ptr<ndn::fib::Entry> fibEntry = GetNode ()->GetObject<ndn::Fib> ()->Add (ndn::Name ("/"), m_face, 0);
fibEntry->UpdateStatus (m_face, ndn::fib::FaceMetric::NDN_FIB_GREEN);
- Simulator::Schedule (Seconds (0.1), &Client::SendPacket, this, std::string("/1"), 1);
- Simulator::Schedule (Seconds (0.2), &Client::SendPacket, this, std::string("/2"), 1);
- Simulator::Schedule (Seconds (0.3), &Client::SendPacket, this, std::string("/3"), 1);
- Simulator::Schedule (Seconds (0.4), &Client::SendPacket, this, std::string("/1"), 2);
+ Simulator::Schedule (Seconds (0.1), &PitTestClient::SendPacket, this, std::string("/1"), 1);
+ Simulator::Schedule (Seconds (0.2), &PitTestClient::SendPacket, this, std::string("/2"), 1);
+ Simulator::Schedule (Seconds (0.3), &PitTestClient::SendPacket, this, std::string("/3"), 1);
+ Simulator::Schedule (Seconds (0.4), &PitTestClient::SendPacket, this, std::string("/1"), 2);
}
void
@@ -58,7 +58,7 @@
void
SendPacket (const std::string &prefix, uint32_t nonce)
{
- Ptr<ndn::Interest> interest;
+ Ptr<ndn::Interest> interest = Create<ndn::Interest> ();
interest->SetName (Create<ndn::Name> (prefix));
interest->SetNonce (nonce);
interest->SetInterestLifetime (Seconds (0.5));
@@ -118,7 +118,8 @@
ndn::StackHelper::AddRoute (node, "/", 0, 0);
- Ptr<Client> app1 = CreateObject<Client> ();
+ Ptr<Application> app1 = CreateObject<PitTestClient> ();
+ app1->SetStartTime (Seconds (0.0));
node->AddApplication (app1);
Simulator::Schedule (Seconds (0.0001), &PitTest::Test, this, node->GetObject<ndn::Fib> ());
@@ -135,7 +136,7 @@
Simulator::Schedule (Seconds (0.91), &PitTest::Check0, this, node->GetObject<ndn::Pit> ());
- Simulator::Stop (Seconds (1.0));
+ Simulator::Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
}
diff --git a/test/ndnSIM-serialization.cc b/test/ndnSIM-serialization.cc
index 7217d26..4ed2bda 100644
--- a/test/ndnSIM-serialization.cc
+++ b/test/ndnSIM-serialization.cc
@@ -24,6 +24,7 @@
#include "ndnSIM-serialization.h"
#include <boost/lexical_cast.hpp>
+#include "ns3/ndnSIM/model/wire/ndnsim.h"
using namespace std;
@@ -36,71 +37,70 @@
void
InterestSerializationTest::DoRun ()
{
- Interest source;
+ Ptr<Interest> source = Create<Interest> ();
- source.SetName (Create<Name> (boost::lexical_cast<Name> ("/test/test2")));
- NS_TEST_ASSERT_MSG_EQ (source.GetName (), boost::lexical_cast<Name> ("/test/test2"), "set/get name failed");
+ source->SetName (Create<Name> (boost::lexical_cast<Name> ("/test/test2")));
+ NS_TEST_ASSERT_MSG_EQ (source->GetName (), boost::lexical_cast<Name> ("/test/test2"), "set/get name failed");
- source.SetScope (2);
- NS_TEST_ASSERT_MSG_EQ (source.GetScope (), 2, "set/get scope failed");
+ source->SetScope (2);
+ NS_TEST_ASSERT_MSG_EQ (source->GetScope (), 2, "set/get scope failed");
- source.SetInterestLifetime (Seconds (100));
- NS_TEST_ASSERT_MSG_EQ (source.GetInterestLifetime (), Seconds (100), "set/get interest lifetime failed");
+ source->SetInterestLifetime (Seconds (100));
+ NS_TEST_ASSERT_MSG_EQ (source->GetInterestLifetime (), Seconds (100), "set/get interest lifetime failed");
- source.SetNonce (200);
- NS_TEST_ASSERT_MSG_EQ (source.GetNonce (), 200, "set/get nonce failed");
+ source->SetNonce (200);
+ NS_TEST_ASSERT_MSG_EQ (source->GetNonce (), 200, "set/get nonce failed");
- source.SetNack (10);
- NS_TEST_ASSERT_MSG_EQ (source.GetNack (), 10, "set/get NACK failed");
+ source->SetNack (10);
+ NS_TEST_ASSERT_MSG_EQ (source->GetNack (), 10, "set/get NACK failed");
- // Packet packet (0);
- // //serialization
- // packet.AddHeader (source);
-
- // //deserialization
- // Interest target;
- // packet.RemoveHeader (target);
+ NS_TEST_ASSERT_MSG_EQ (source->GetWire (), 0, "Wire should be empty");
+ NS_TEST_ASSERT_MSG_NE (source->GetPayload (), 0, "Payload should not be empty");
+
+ Ptr<Packet> packet = wire::ndnSIM::Interest::ToWire (source);
+
+ NS_TEST_ASSERT_MSG_NE (source->GetWire (), 0, "Wire should not be empty now");
+
+ Ptr<Interest> target = wire::ndnSIM::Interest::FromWire (packet);
- // NS_TEST_ASSERT_MSG_EQ (source.GetName () , target.GetName () , "source/target name failed");
- // NS_TEST_ASSERT_MSG_EQ (source.GetScope () , target.GetScope () , "source/target scope failed");
- // NS_TEST_ASSERT_MSG_EQ (source.GetInterestLifetime (), target.GetInterestLifetime (), "source/target interest lifetime failed");
- // NS_TEST_ASSERT_MSG_EQ (source.GetNonce () , target.GetNonce () , "source/target nonce failed");
- // NS_TEST_ASSERT_MSG_EQ (source.GetNack () , target.GetNack () , "source/target NACK failed");
+ NS_TEST_ASSERT_MSG_EQ (source->GetName () , target->GetName () , "source/target name failed");
+ NS_TEST_ASSERT_MSG_EQ (source->GetScope () , target->GetScope () , "source/target scope failed");
+ NS_TEST_ASSERT_MSG_EQ (source->GetInterestLifetime (), target->GetInterestLifetime (), "source/target interest lifetime failed");
+ NS_TEST_ASSERT_MSG_EQ (source->GetNonce () , target->GetNonce () , "source/target nonce failed");
+ NS_TEST_ASSERT_MSG_EQ (source->GetNack () , target->GetNack () , "source/target NACK failed");
}
void
ContentObjectSerializationTest::DoRun ()
{
- ContentObject source;
+ Ptr<ContentObject> source = Create<ContentObject> (Create<Packet> (1024));
- source.SetName (Create<Name> (boost::lexical_cast<Name> ("/test/test2/1")));
- NS_TEST_ASSERT_MSG_EQ (source.GetName (), boost::lexical_cast<Name> ("/test/test2/1"), "set/get name failed");
+ source->SetName (Create<Name> (boost::lexical_cast<Name> ("/test/test2/1")));
+ NS_TEST_ASSERT_MSG_EQ (source->GetName (), boost::lexical_cast<Name> ("/test/test2/1"), "set/get name failed");
- source.SetFreshness (Seconds (10));
- NS_TEST_ASSERT_MSG_EQ (source.GetFreshness (), Seconds (10), "set/get freshness failed");
+ source->SetFreshness (Seconds (10));
+ NS_TEST_ASSERT_MSG_EQ (source->GetFreshness (), Seconds (10), "set/get freshness failed");
- source.SetTimestamp (Seconds (100));
- NS_TEST_ASSERT_MSG_EQ (source.GetTimestamp (), Seconds (100), "set/get timestamp failed");
+ source->SetTimestamp (Seconds (100));
+ NS_TEST_ASSERT_MSG_EQ (source->GetTimestamp (), Seconds (100), "set/get timestamp failed");
- NS_TEST_ASSERT_MSG_EQ (source.GetSignature (), 0, "initialization of signature failed");
- // int size = source.GetSerializedSize ();
- // source.SetSignature (10);
- // NS_TEST_ASSERT_MSG_EQ (source.GetSignature (), 10, "set/get signature failed");
+ NS_TEST_ASSERT_MSG_EQ (source->GetSignature (), 0, "initialization of signature failed");
- // NS_TEST_ASSERT_MSG_EQ (source.GetSerializedSize (), static_cast<unsigned int> (size + 4), "Signature size should have increased by 4");
+ Ptr<Packet> packet = wire::ndnSIM::Data::ToWire (source);
+ int size = packet->GetSize ();
+
+ source->SetSignature (10);
+ NS_TEST_ASSERT_MSG_EQ (source->GetSignature (), 10, "set/get signature failed");
+
+ packet = wire::ndnSIM::Data::ToWire (source);
+ NS_TEST_ASSERT_MSG_EQ (packet->GetSize (), static_cast<unsigned int> (size + 4), "Signature size should have increased by 4");
+
+ Ptr<ContentObject> target = wire::ndnSIM::Data::FromWire (packet);
- // Packet packet (0);
- // //serialization
- // packet.AddHeader (source);
-
- // //deserialization
- // ContentObject target;
- // packet.RemoveHeader (target);
-
- // NS_TEST_ASSERT_MSG_EQ (source.GetName () , target.GetName () , "source/target name failed");
- // NS_TEST_ASSERT_MSG_EQ (source.GetFreshness (), target.GetFreshness (), "source/target freshness failed");
- // NS_TEST_ASSERT_MSG_EQ (source.GetTimestamp (), target.GetTimestamp (), "source/target timestamp failed");
- // NS_TEST_ASSERT_MSG_EQ (source.GetSignature (), target.GetSignature (), "source/target signature failed");
+ NS_TEST_ASSERT_MSG_EQ (source->GetName () , target->GetName () , "source/target name failed");
+ NS_TEST_ASSERT_MSG_EQ (source->GetFreshness (), target->GetFreshness (), "source/target freshness failed");
+ NS_TEST_ASSERT_MSG_EQ (source->GetTimestamp (), target->GetTimestamp (), "source/target timestamp failed");
+ NS_TEST_ASSERT_MSG_EQ (source->GetSignature (), target->GetSignature (), "source/target signature failed");
}
}
diff --git a/test/ndnSIM-tests.cc b/test/ndnSIM-tests.cc
index 688fca4..a23dd05 100644
--- a/test/ndnSIM-tests.cc
+++ b/test/ndnSIM-tests.cc
@@ -32,14 +32,14 @@
{
public:
NdnSimTestSuite ()
- : TestSuite ("ndnSIM-suite", UNIT)
+ : TestSuite ("ndnSIM", UNIT)
{
SetDataDir (NS_TEST_SOURCEDIR);
- AddTestCase (new InterestSerializationTest ());
- AddTestCase (new ContentObjectSerializationTest ());
- AddTestCase (new FibEntryTest ());
- // AddTestCase (new PitTest ());
+ AddTestCase (new InterestSerializationTest (), TestCase::QUICK);
+ AddTestCase (new ContentObjectSerializationTest (), TestCase::QUICK);
+ AddTestCase (new FibEntryTest (), TestCase::QUICK);
+ AddTestCase (new PitTest (), TestCase::QUICK);
}
};