blob: b97565ba8180f266f0e3b27c1f5663d69ce6646d [file] [log] [blame]
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/ndnSIM-module.h"
using namespace ns3;
class PcapWriter
{
public:
PcapWriter (const std::string &file)
{
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);
}
private:
Ptr<PcapFileWrapper> m_pcap;
};
int
main (int argc, char *argv[])
{
// setting default parameters for PointToPoint links and channels
Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
Config::SetDefault ("ns3::NdnProducer::SignatureBits", StringValue ("1"));
// Creating nodes
NodeContainer nodes;
nodes.Create (3);
// Connecting nodes using two links
PointToPointHelper p2p;
p2p.Install (nodes.Get (0), nodes.Get (1));
p2p.Install (nodes.Get (1), nodes.Get (2));
// Install Ndn stack on all nodes
NdnStackHelper ndnHelper;
ndnHelper.SetDefaultRoutes (true);
ndnHelper.InstallAll ();
// Installing applications
// Consumer
NdnAppHelper consumerHelper ("ns3::NdnConsumerCbr");
// Consumer will request /prefix/0, /prefix/1, ...
consumerHelper.SetPrefix ("/prefix");
consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
consumerHelper.Install (nodes.Get (0)); // first node
// Producer
NdnAppHelper producerHelper ("ns3::NdnProducer");
// Producer will reply to all requests starting with /prefix
producerHelper.SetPrefix ("/prefix");
producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
producerHelper.Install (nodes.Get (2)); // last node
PcapWriter trace ("ndn-simple-trace.pcap");
Config::ConnectWithoutContext ("/NodeList/*/$ns3::NdnL3Protocol/FaceList/*/NdnTx",
MakeCallback (&PcapWriter::TracePacket, &trace));
Simulator::Stop (Seconds (20.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}