blob: ea2f3188731bec87d1ce956af184d46dcd33aac9 [file] [log] [blame]
Alexander Afanasyev4aac5572012-08-09 10:49:55 -07001
2#include "ns3/core-module.h"
3#include "ns3/network-module.h"
4#include "ns3/point-to-point-module.h"
5#include "ns3/ndnSIM-module.h"
6
7using namespace ns3;
8
9class PcapWriter
10{
11public:
12 PcapWriter (const std::string &file)
13 {
14 PcapHelper helper;
15 m_pcap = helper.CreateFile (file, std::ios::out, PcapHelper::DLT_PPP);
16 }
17
18 void
19 TracePacket (Ptr<const Packet> packet)
20 {
21 static PppHeader pppHeader;
22 pppHeader.SetProtocol (0x0077);
23
24 m_pcap->Write (Simulator::Now (), pppHeader, packet);
25 }
26
27private:
28 Ptr<PcapFileWrapper> m_pcap;
29};
30
31
32int
33main (int argc, char *argv[])
34{
35 // setting default parameters for PointToPoint links and channels
36 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
37 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
38 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
39
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070040 Config::SetDefault ("ns3::ndn::Producer::SignatureBits", StringValue ("1"));
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070041
42 // Creating nodes
43 NodeContainer nodes;
44 nodes.Create (3);
45
46 // Connecting nodes using two links
47 PointToPointHelper p2p;
48 p2p.Install (nodes.Get (0), nodes.Get (1));
49 p2p.Install (nodes.Get (1), nodes.Get (2));
50
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070051 // Install NDN stack on all nodes
52 ndn::StackHelper ndnHelper;
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070053 ndnHelper.SetDefaultRoutes (true);
54 ndnHelper.InstallAll ();
55
56 // Installing applications
57
58 // Consumer
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070059 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070060 // Consumer will request /prefix/0, /prefix/1, ...
61 consumerHelper.SetPrefix ("/prefix");
62 consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
63 consumerHelper.Install (nodes.Get (0)); // first node
64
65 // Producer
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070066 ndn::AppHelper producerHelper ("ns3::ndn::Producer");
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070067 // Producer will reply to all requests starting with /prefix
68 producerHelper.SetPrefix ("/prefix");
69 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
70 producerHelper.Install (nodes.Get (2)); // last node
71
72 PcapWriter trace ("ndn-simple-trace.pcap");
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070073 Config::ConnectWithoutContext ("/NodeList/*/$ns3::ndn::L3Protocol/FaceList/*/NdnTx",
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070074 MakeCallback (&PcapWriter::TracePacket, &trace));
75
76 Simulator::Stop (Seconds (20.0));
77
78 Simulator::Run ();
79 Simulator::Destroy ();
80
81 return 0;
82}
83