Merge remote-tracking branch 'git.irl/master'
diff --git a/examples/ccnx-pcap-example.cc b/examples/ccnx-pcap-example.cc
new file mode 100644
index 0000000..f3f9fc8
--- /dev/null
+++ b/examples/ccnx-pcap-example.cc
@@ -0,0 +1,110 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#include <ctime>
+#include <sstream>
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/internet-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/applications-module.h"
+#include "ns3/ipv4-static-routing-helper.h"
+#include "ns3/ipv4-list-routing-helper.h"
+#include "ns3/annotated-topology-reader.h"
+#include <list>
+//#include "ns3/visualizer-module.h"
+#include "ns3/ccnx-consumer-helper.h"
+#include "ns3/ccnx-stack-helper.h"
+
+using namespace ns3;
+using namespace std;
+
+NS_LOG_COMPONENT_DEFINE ("CcnxPcapExample");
+
+int main (int argc, char *argv[])
+{
+    Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("10Mbps"));
+    Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("1ms"));
+    
+    NodeContainer c;
+    c.Create (2);
+    
+    NodeContainer n1 = NodeContainer (c.Get (0), c.Get (1));
+    
+    PointToPointHelper p2p;
+    NetDeviceContainer ndc1 = p2p.Install (n1);
+    
+//    CcnxStackHelper ccnx;
+//    Ptr<CcnxFaceContainer> cf = ccnx.Install (c);
+
+    //Ipv4AddressHelper ipv4;
+    //ipv4.SetBase ("192.168.1.0", "255.255.255.0");
+    //Ipv4InterfaceContainer i1 = ipv4.Assign (ndc1);
+    
+    CcnxInterestHeader header;
+    Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
+    (*testname) ("test") ("test2");
+    header.SetName (testname);
+    header.SetNonce (1);
+
+    Packet packet (0);
+    packet.AddHeader (header);
+    
+    Ptr<Node> nd = c.Get(0);
+    Ptr<PointToPointNetDevice> device = nd->GetDevice(nd->GetNDevices()-1)->GetObject<PointToPointNetDevice> ();
+    
+   
+    
+    Ptr<CcnxNameComponents> testname2 = Create<CcnxNameComponents> ();
+    (*testname2) ("test3") ("test4");
+    header.SetName (testname2);
+    header.SetNonce (2);
+    Packet packet2 (0);
+    packet2.AddHeader (header);
+    
+    
+    p2p.EnablePcapAll("pcap-example.pcap");
+    
+    Simulator::Stop (Seconds (20));
+    
+    //NS_LOG_INFO ("Run Simulation.");
+    NS_LOG_INFO("Size1 = " << packet.GetSize());
+    NS_LOG_INFO("Size2 = " << packet2.GetSize());
+    device->Send(packet.Copy(),device->GetBroadcast(),0x7777);
+    NS_LOG_INFO(device->IsLinkUp());
+    device->Send(packet2.Copy(),device->GetBroadcast(),0x7777);
+    NS_LOG_INFO(device->IsLinkUp());
+    device->Send(packet2.Copy(),device->GetBroadcast(),0x7777);
+    NS_LOG_INFO(device->IsLinkUp());
+    device->Send(packet2.Copy(),device->GetBroadcast(),0x7777);
+    device->Send(packet2.Copy(),device->GetBroadcast(),0x7777);
+    device->Send(packet2.Copy(),device->GetBroadcast(),0x7777);
+    device->Send(packet2.Copy(),device->GetBroadcast(),0x7777);
+    device->Send(packet2.Copy(),device->GetBroadcast(),0x7777);
+    device->Send(packet2.Copy(),device->GetBroadcast(),0x7777);
+    device->Send(packet2.Copy(),device->GetBroadcast(),0x7777);
+    device->Send(packet2.Copy(),device->GetBroadcast(),0x7777);
+    device->Send(packet2.Copy(),device->GetBroadcast(),0x7777);
+    NS_LOG_INFO ("Run Simulation.");
+    Simulator::Run ();
+    Simulator::Destroy ();
+    NS_LOG_INFO ("Done.");
+}
diff --git a/test/basic-regression-test.cc b/test/basic-regression-test.cc
new file mode 100644
index 0000000..b4625bb
--- /dev/null
+++ b/test/basic-regression-test.cc
@@ -0,0 +1,185 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#include "ns3/test.h"
+#include "ns3/annotated-topology-reader.h"
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/uinteger.h"
+#include "ns3/random-variable.h"
+#include <limits> 
+#include "ns3/ccnx-header-helper.h"
+#include "ns3/header.h"
+#include "ns3/ccnx-name-components.h"
+#include "ns3/nstime.h"
+#include "ns3/buffer.h"
+#include "ns3/log.h"
+
+#include <ctime>
+#include <sstream>
+
+#include "ns3/internet-stack-helper.h"
+#include "ns3/ipv4-list-routing-helper.h"
+#include "ns3/ipv4-static-routing-helper.h"
+#include "ns3/point-to-point-helper.h"
+#include "ns3/application.h"
+#include "ns3/ipv4-static-routing-helper.h"
+#include "ns3/ipv4-list-routing-helper.h"
+#include "ns3/annotated-topology-reader.h"
+#include <list>
+
+
+using namespace ns3;
+using namespace std;
+
+NS_LOG_COMPONENT_DEFINE ("CcnxBasicRegressionTest");
+
+class BasicRegressionTest : public TestCase
+{
+public:
+    
+    BasicRegressionTest ();
+    virtual ~BasicRegressionTest ();
+    
+private:
+    virtual void DoRun (void);
+};
+
+BasicRegressionTest::BasicRegressionTest ()
+: TestCase ("Basic regression test")
+{
+}
+
+BasicRegressionTest::~BasicRegressionTest ()
+{
+}
+
+void
+BasicRegressionTest::DoRun(void)
+{
+    //string input ("/Users/iliamo/ns3-abstract-ndn/ns-3.11/src/NDNabstraction/examples/simpletopology.txt");
+    
+    // Set up command line parameters used to control the experiment.
+    //CommandLine cmd;
+    //cmd.AddValue ("input", "Name of the input file.",
+    //              input);
+    //cmd.Parse (argc, argv);
+    
+    
+    // ------------------------------------------------------------
+    // -- Read topology data.
+    // --------------------------------------------
+    
+    string input = NS_TEST_SOURCEDIR;
+    input += "/testtopology.txt";
+    
+    Ptr<AnnotatedTopologyReader> reader = CreateObject<AnnotatedTopologyReader> ();
+    reader->SetFileName (input);
+    
+    NodeContainer nodes;
+    if (reader != 0)
+    {
+        nodes = reader->Read ();
+    }
+    else
+    {
+        NS_TEST_ASSERT_MSG_EQ (true, false, "file not found");
+    }
+    
+    NS_TEST_ASSERT_MSG_EQ (7, reader->LinksSize (), "link count is wrong");
+    
+    
+    // ------------------------------------------------------------
+    // -- Create nodes and network stacks
+    // --------------------------------------------
+    NS_LOG_INFO ("creating internet stack");
+    InternetStackHelper stack;
+    
+    
+    //routing
+    /*Ipv4StaticRoutingHelper staticRouting;
+    Ipv4ListRoutingHelper listRH;
+    listRH.Add (staticRouting, 0);
+    stack.SetRoutingHelper (listRH);  // has effect on the next Install ()
+    stack.Install (nodes);
+    
+    NS_LOG_INFO ("creating ip4 addresses");
+    Ipv4AddressHelper address;
+    address.SetBase ("10.0.0.0", "255.255.255.252");*/
+    
+    int totlinks = reader->LinksSize ();
+    
+    
+    /// applying settings
+    NS_LOG_INFO ("creating node containers");
+    NodeContainer* nc = new NodeContainer[totlinks];
+    TopologyReader::ConstLinksIterator iter;
+    int i = 0;
+    for ( iter = reader->LinksBegin (); iter != reader->LinksEnd (); iter++, i++ )
+    {
+        nc[i] = NodeContainer (iter->GetFromNode (), iter->GetToNode ());
+    }
+    
+    NetDeviceContainer* ndc = new NetDeviceContainer[totlinks];
+    reader->ApplySettings(ndc,nc);
+    /// settings applied
+    
+    
+    
+    
+    // it creates little subnets, one for each couple of nodes.
+    /*NS_LOG_INFO ("creating ipv4 interfaces");
+    Ipv4InterfaceContainer* ipic = new Ipv4InterfaceContainer[totlinks];
+    for (int i = 0; i < totlinks; i++)
+    {
+        ipic[i] = address.Assign (ndc[i]);
+        address.NewNetwork ();
+    }
+    
+    // ------------------------------------------------------------
+    // -- Run the simulation
+    // --------------------------------------------
+    NS_LOG_INFO ("Run Simulation.");
+    Simulator::Stop (Seconds (20));
+    Simulator::Run ();
+    Simulator::Destroy ();
+    
+    delete[] ipic;
+    delete[] ndc;
+    delete[] nc;
+    
+    NS_LOG_INFO ("Done.");
+    
+    */
+}
+
+class BasicRegressionTestSuite : public TestSuite
+{
+public:
+    BasicRegressionTestSuite ();
+};
+
+BasicRegressionTestSuite::BasicRegressionTestSuite ()
+: TestSuite ("ccnx-basic-regression-test-suite", UNIT)
+{
+    SetDataDir (NS_TEST_SOURCEDIR);
+    AddTestCase (new BasicRegressionTest);
+}
+
+static BasicRegressionTestSuite suite;
diff --git a/test/content-object-test.cc b/test/content-object-test.cc
new file mode 100644
index 0000000..eff1304
--- /dev/null
+++ b/test/content-object-test.cc
@@ -0,0 +1,110 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#include "ns3/test.h"
+#include "ns3/annotated-topology-reader.h"
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/uinteger.h"
+#include "ns3/random-variable.h"
+#include <limits> 
+#include "ns3/ccnx-header-helper.h"
+#include "ns3/header.h"
+#include "ns3/ccnx-name-components.h"
+#include "ns3/nstime.h"
+#include "ns3/buffer.h"
+#include "ns3/log.h"
+#include "ns3/ccnx-content-object-header.h"
+#include <iostream>
+#include <fstream>
+#include <sstream>
+
+using namespace ns3;
+using namespace std;
+
+NS_LOG_COMPONENT_DEFINE ("ContentObjectTest");
+
+class ContentObjectTest : public TestCase
+{
+public:
+    ContentObjectTest ();
+    virtual ~ContentObjectTest ();
+    
+private:
+    virtual void DoRun (void);
+};
+
+ContentObjectTest::ContentObjectTest ()
+: TestCase ("Content Obejct Serialization Test")
+{
+}
+
+ContentObjectTest::~ContentObjectTest ()
+{
+}
+
+void
+ContentObjectTest::DoRun(void)
+{
+    Packet::EnablePrinting ();
+	Packet::EnableChecking (); 
+    Packet packet (10);
+	
+    CcnxContentObjectHeader header;
+	CcnxContentObjectTail   trailer;
+	
+    Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
+    (*testname) ("iwant")("icecream");
+    header.SetName(testname);
+    
+	NS_LOG_INFO ("Source: \n" << header << trailer);
+    
+	packet.AddHeader (header);
+	packet.AddTrailer (trailer);
+    
+	// NS_LOG_INFO ("Deserialized packet: \n" << packet);
+    
+	NS_LOG_INFO ("Removing and deserializing individual headers");
+	
+    CcnxContentObjectHeader targetHeader;
+	CcnxContentObjectTail   targetTrailer;
+    
+	packet.RemoveHeader (targetHeader);
+	packet.RemoveTrailer (targetTrailer);
+    
+    
+    NS_TEST_ASSERT_MSG_EQ (targetHeader.GetName(), *testname, "Content Object name deserialization failed");
+    
+    NS_TEST_ASSERT_MSG_EQ (packet.GetSize(), 10, "Content Object size inequality");
+}
+
+class ContentObjectTestSuite : public TestSuite
+{
+public:
+    ContentObjectTestSuite ();
+};
+
+ContentObjectTestSuite::ContentObjectTestSuite ()
+: TestSuite ("content-object-test-suite", UNIT)
+{
+    SetDataDir (NS_TEST_SOURCEDIR);
+    AddTestCase (new ContentObjectTest);
+}
+
+static ContentObjectTestSuite suite;
diff --git a/test/interest-header-serialization-test.cc b/test/interest-header-serialization-test.cc
index dbdf0c3..62d83a4 100644
--- a/test/interest-header-serialization-test.cc
+++ b/test/interest-header-serialization-test.cc
@@ -43,15 +43,9 @@
 class InterestHeaderSerializationTest : public TestCase
 {
 public:
-    //static const uint32_t N_RUNS = 5;
-    //static const uint32_t N_BINS = 50;
-    //static const uint32_t N_MEASUREMENTS = 1000000;
-    
     InterestHeaderSerializationTest ();
     virtual ~InterestHeaderSerializationTest ();
     
-    //double ChiSquaredTest (UniformVariable &u);
-    
 private:
     virtual void DoRun (void);
 };
@@ -68,20 +62,8 @@
 void
 InterestHeaderSerializationTest::DoRun(void)
 {
-    //ReportStart();
-    //SetVerbose(true);
-    std::ostringstream msgStream;
-    msgStream << "Preved!";
+    Packet packet (0);
     
-    //NS_TEST_EXPECT_MSG_NE (true,false, "DIRECTORY = " <<NS_TEST_SOURCEDIR);
-    
-    /*ReportTestFailure ("DIRECTORY = ",  NS_TEST_SOURCEDIR, 
-                            "", "", 
-                            "", 0);*/
-    string str = NS_TEST_SOURCEDIR;
-    //str += "/hahaha";
-    //CreateDataDirFilename(str);
-    NS_LOG_INFO ("Test started");
     uint32_t randomNonce = UniformVariable().GetInteger(1, std::numeric_limits<uint32_t>::max ());
     Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
     (*testname) ("test") ("test2");
@@ -104,23 +86,14 @@
     interestHeader.SetMaxSuffixComponents(maxSuffixComponents);
     interestHeader.SetMinSuffixComponents(minSuffixComponents);
 
-    uint32_t size = interestHeader.GetSerializedSize();
-    //uint32_t size = 5;
-    NS_TEST_ASSERT_MSG_EQ (false, true, "GetSize = " << size);
-    Buffer buf(size);
-    Buffer::Iterator iter = buf.Begin ();
-    //interestHeader.
-    interestHeader.Serialize(iter);
-
-    iter = buf.Begin ();
+    //serialization
+    packet.AddHeader (interestHeader);
+	
+	//deserialization
     CcnxInterestHeader target;
-    target.Deserialize(iter);
+	packet.RemoveHeader (target);
+
     
-    /*if(target.GetNonce() == randomNonce)
-    {
-        
-        ReportCaseFailure();
-    }*/
     NS_TEST_ASSERT_MSG_EQ (target.GetNonce(), randomNonce, "Interest Header nonce deserialization failed");
     
     NS_TEST_ASSERT_MSG_EQ (target.GetName(), *testname, "Interest Header name deserialization failed");
diff --git a/test/testtopology.txt b/test/testtopology.txt
new file mode 100644
index 0000000..8e39d06
--- /dev/null
+++ b/test/testtopology.txt
@@ -0,0 +1,8 @@
+7   7
+1   3   10000   1   80  120
+2   3   10000   1   110 150
+3   4   1000    1   40  30
+3   5   1000    50  55  50
+4   5   1000    1   10  20
+5   6   10000   1   15  35
+5   7   10000   50  25  45