blob: b97565ba8180f266f0e3b27c1f5663d69ce6646d [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
40 Config::SetDefault ("ns3::NdnProducer::SignatureBits", StringValue ("1"));
41
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
51 // Install Ndn stack on all nodes
52 NdnStackHelper ndnHelper;
53 ndnHelper.SetDefaultRoutes (true);
54 ndnHelper.InstallAll ();
55
56 // Installing applications
57
58 // Consumer
59 NdnAppHelper consumerHelper ("ns3::NdnConsumerCbr");
60 // 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
66 NdnAppHelper producerHelper ("ns3::NdnProducer");
67 // 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");
73 Config::ConnectWithoutContext ("/NodeList/*/$ns3::NdnL3Protocol/FaceList/*/NdnTx",
74 MakeCallback (&PcapWriter::TracePacket, &trace));
75
76 Simulator::Stop (Seconds (20.0));
77
78 Simulator::Run ();
79 Simulator::Destroy ();
80
81 return 0;
82}
83