blob: 3e0812094428a8982d2767a7bf02844cd87e3dd8 [file] [log] [blame]
Alexander Afanasyev4d325162012-06-01 12:28:50 -07001Examples
2========
3
4Simple scenario
5---------------
6
7The first example (``ccnx-simple.cc``) shows very basics of ndnSIM. In the simulated
8topology there are 3 nodes, connected with point-to-point links, one
9NDN consumer, and one NDN producer::
10
11 +----------+ 1Mbps +--------+ 1Mbps +----------+
12 | consumer | <------------> | router | <------------> | producer |
13 +----------+ 10ms +--------+ 10ms +----------+
14
15Consumer requests data from producer with frequency 10 interests per second
16(interests contain constantly increasing sequence number).
17
18For every received interest, producer replies with a data packet, containing
191024 bytes of virtual payload.
20
21The following code represents all that is necessary to run such a
22simple scenario
23
24.. code-block:: c++
25
26 #include "ns3/core-module.h"
27 #include "ns3/network-module.h"
28 #include "ns3/point-to-point-module.h"
29 #include "ns3/ndnSIM-module.h"
30
31 using namespace ns3;
32
33 int
34 main (int argc, char *argv[])
35 {
36 // setting default parameters for PointToPoint links and channels
37 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
38 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
39 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
40
41 // Creating nodes
42 NodeContainer nodes;
43 nodes.Create (3);
44
45 // Connecting nodes using two links
46 PointToPointHelper p2p;
47 p2p.Install (nodes.Get (0), nodes.Get (1));
48 p2p.Install (nodes.Get (1), nodes.Get (2));
49
50 // Install CCNx stack on all nodes
51 CcnxStackHelper ccnxHelper;
52 ccnxHelper.SetDefaultRoutes (true);
53 ccnxHelper.InstallAll ();
54
55 // Installing applications
56
57 // Consumer
58 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerCbr");
59 // Consumer will request /prefix/0, /prefix/1, ...
60 consumerHelper.SetPrefix ("/prefix");
61 consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
62 consumerHelper.Install (nodes.Get (0)); // first node
63
64 // Producer
65 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
66 // Producer will reply to all requests starting with /prefix
67 producerHelper.SetPrefix ("/prefix");
68 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
69 producerHelper.Install (nodes.Get (2)); // last node
70
71 Simulator::Stop (Seconds (20.0));
72
73 Simulator::Run ();
74 Simulator::Destroy ();
75
76 return 0;
77 }
78
79If NS-3 is compiled in debug mode, you can run and see progress of the
80simulation using the following command::
81
82 NS_LOG=CcnxConsumer:CcnxProducer ./waf --run=ccnx-simple