examples: Fixing error in ndn-simple-with-pcap
closes #24
diff --git a/docs/source/examples.rst b/docs/source/examples.rst
index 47d4a65..e32ba85 100644
--- a/docs/source/examples.rst
+++ b/docs/source/examples.rst
@@ -46,7 +46,6 @@
NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple
-
.. _9-node-grid-example:
9-node grid example
@@ -289,3 +288,23 @@
:ref:`Custom applications`
+Simple scenario with pcap dump
+------------------------------
+
+The following example (``ndn-simple-with-pcap.cc``) demonstrates how to dump all simulated traffic
+in pcap-formatted data, which can be used for later analysis by conventional tools, like tcpdump and wireshark.
+
+.. literalinclude:: ../../examples/ndn-simple-with-pcap.cc
+ :language: c++
+ :linenos:
+ :lines: 20-
+ :emphasize-lines: 7-29,70-72
+
+If this code is placed into ``scratch/ndn-simple-with-pcap.cc`` and NS-3 is compiled in debug mode, you can run and see progress of the
+simulation using the following command (in optimized mode nothing will be printed out)::
+
+ NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple-with-pcap
+
+This will generate ``ndn-simple-trace.pcap``, which can be fed to tcpdump::
+
+ tcpdump -r ndn-simple-trace.pcap
diff --git a/examples/ndn-simple-with-pcap.cc b/examples/ndn-simple-with-pcap.cc
index ea2f318..03f3ef4 100644
--- a/examples/ndn-simple-with-pcap.cc
+++ b/examples/ndn-simple-with-pcap.cc
@@ -1,4 +1,23 @@
-
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2012 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+// ndn-simple-with-pcap.cc
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/point-to-point-module.h"
@@ -14,13 +33,13 @@
PcapHelper helper;
m_pcap = helper.CreateFile (file, std::ios::out, PcapHelper::DLT_PPP);
}
-
+
void
TracePacket (Ptr<const Packet> packet)
{
static PppHeader pppHeader;
pppHeader.SetProtocol (0x0077);
-
+
m_pcap->Write (Simulator::Now (), pppHeader, packet);
}
@@ -37,8 +56,6 @@
Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
- Config::SetDefault ("ns3::ndn::Producer::SignatureBits", StringValue ("1"));
-
// Creating nodes
NodeContainer nodes;
nodes.Create (3);
@@ -72,7 +89,7 @@
PcapWriter trace ("ndn-simple-trace.pcap");
Config::ConnectWithoutContext ("/NodeList/*/$ns3::ndn::L3Protocol/FaceList/*/NdnTx",
MakeCallback (&PcapWriter::TracePacket, &trace));
-
+
Simulator::Stop (Seconds (20.0));
Simulator::Run ();
diff --git a/examples/wscript b/examples/wscript
index b21629e..b33cbf3 100644
--- a/examples/wscript
+++ b/examples/wscript
@@ -50,3 +50,6 @@
obj = bld.create_ns3_program('ndn-simple-with-cs-lfu', ['ndnSIM'])
obj.source = 'ndn-simple-with-cs-lfu.cc'
+
+ obj = bld.create_ns3_program('ndn-simple-with-pcap', ['ndnSIM'])
+ obj.source = 'ndn-simple-with-pcap.cc'