Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 1 | Examples |
| 2 | ======== |
| 3 | |
| 4 | Simple scenario |
| 5 | --------------- |
| 6 | |
| 7 | The first example (``ccnx-simple.cc``) shows very basics of ndnSIM. In the simulated |
| 8 | topology there are 3 nodes, connected with point-to-point links, one |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 9 | NDN consumer, and one NDN producer: |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 10 | |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 11 | .. aafig:: |
| 12 | :aspect: 60 |
| 13 | :scale: 120 |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 14 | |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 15 | +----------+ +--------+ +----------+ |
| 16 | | | 1Mbps | | 1Mbps | | |
| 17 | | Consumer |<-------------->| Router |<-------------->| Producer | |
| 18 | | | 10ms | | 10ms | | |
| 19 | +----------+ +--------+ +----------+ |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 20 | |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 21 | Consumer is simulated using :ndnsim:`CcnxConsumerCbr` reference application and generates Interests towards the producer |
| 22 | with frequency of 10 Interests per second (see :doc:`applications`). |
| 23 | |
| 24 | Producer is simulated using :ndnsim:`CcnxProducer` class, which is used to satisfy all incoming Interests with virtual payload data (1024 bytes). |
| 25 | |
| 26 | FIB on every node is populated using default routes (see :doc:`helpers`). |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 27 | |
| 28 | The following code represents all that is necessary to run such a |
| 29 | simple scenario |
| 30 | |
| 31 | .. code-block:: c++ |
| 32 | |
| 33 | #include "ns3/core-module.h" |
| 34 | #include "ns3/network-module.h" |
| 35 | #include "ns3/point-to-point-module.h" |
| 36 | #include "ns3/ndnSIM-module.h" |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 37 | |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 38 | using namespace ns3; |
| 39 | |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 40 | int |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 41 | main (int argc, char *argv[]) |
| 42 | { |
| 43 | // setting default parameters for PointToPoint links and channels |
| 44 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
| 45 | Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms")); |
| 46 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20")); |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 47 | |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 48 | // Creating nodes |
| 49 | NodeContainer nodes; |
| 50 | nodes.Create (3); |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 51 | |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 52 | // Connecting nodes using two links |
| 53 | PointToPointHelper p2p; |
| 54 | p2p.Install (nodes.Get (0), nodes.Get (1)); |
| 55 | p2p.Install (nodes.Get (1), nodes.Get (2)); |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 56 | |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 57 | // Install CCNx stack on all nodes |
| 58 | CcnxStackHelper ccnxHelper; |
| 59 | ccnxHelper.SetDefaultRoutes (true); |
| 60 | ccnxHelper.InstallAll (); |
| 61 | |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 62 | // Installing applications |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 63 | |
| 64 | // Consumer |
| 65 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumerCbr"); |
| 66 | // Consumer will request /prefix/0, /prefix/1, ... |
| 67 | consumerHelper.SetPrefix ("/prefix"); |
| 68 | consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second |
| 69 | consumerHelper.Install (nodes.Get (0)); // first node |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 70 | |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 71 | // Producer |
| 72 | CcnxAppHelper producerHelper ("ns3::CcnxProducer"); |
| 73 | // Producer will reply to all requests starting with /prefix |
| 74 | producerHelper.SetPrefix ("/prefix"); |
| 75 | producerHelper.SetAttribute ("PayloadSize", StringValue("1024")); |
| 76 | producerHelper.Install (nodes.Get (2)); // last node |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 77 | |
| 78 | Simulator::Stop (Seconds (20.0)); |
| 79 | |
| 80 | Simulator::Run (); |
| 81 | Simulator::Destroy (); |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | If this code is placed into ``scratch/ccnx-simple.cc`` and NS-3 is compiled in debug mode, you can run and see progress of the |
| 87 | simulation using the following command (in optimized mode nothing will be printed out):: |
| 88 | |
| 89 | NS_LOG=CcnxConsumer:CcnxProducer ./waf --run=ccnx-simple |
| 90 | |
| 91 | |
| 92 | 9-node grid example |
| 93 | ------------------- |
| 94 | |
| 95 | This scenario (``ccnx-grid.cc``) simulates using a grid topology build with PointToPointGrid NS-3 module |
| 96 | |
| 97 | .. aafig:: |
| 98 | :aspect: 60 |
| 99 | :scale: 120 |
| 100 | |
| 101 | /--------\ /-\ /-\ |
| 102 | |Consumer|<---->| |<------->| | |
| 103 | \--------/ \-/ \-/ |
| 104 | ^ ^ ^ |
| 105 | | | | 1Mbps/10ms delay |
| 106 | v v v |
| 107 | /-\ /-\ /-\ |
| 108 | | |<-------->| |<------->| | |
| 109 | \-/ \-/ \-/ |
| 110 | ^ ^ ^ |
| 111 | | | | |
| 112 | v v v |
| 113 | /-\ /-\ /--------\ |
| 114 | | |<-------->| |<---->|Producer| |
| 115 | \-/ \-/ \--------/ |
| 116 | |
| 117 | |
| 118 | FIB is populated using :ndnsim:`CcnxGlobalRoutingHelper` (see :doc:`helpers`). |
| 119 | |
| 120 | Consumer is simulated using :ndnsim:`CcnxConsumerCbr` reference application and generates Interests towards the producer |
| 121 | with frequency of 10 Interests per second (see :doc:`applications`). |
| 122 | |
| 123 | Producer is simulated using :ndnsim:`CcnxProducer` class, which is used to satisfy all incoming Interests with virtual payload data (1024 bytes). |
| 124 | |
| 125 | |
| 126 | The following code represents all that is necessary to run such a |
| 127 | simple scenario |
| 128 | |
| 129 | .. code-block:: c++ |
| 130 | |
| 131 | #include "ns3/core-module.h" |
| 132 | #include "ns3/network-module.h" |
| 133 | #include "ns3/point-to-point-module.h" |
| 134 | #include "ns3/point-to-point-grid.h" |
| 135 | #include "ns3/ndnSIM-module.h" |
| 136 | |
| 137 | using namespace ns3; |
| 138 | |
| 139 | int |
| 140 | main (int argc, char *argv[]) |
| 141 | { |
| 142 | // Setting default parameters for PointToPoint links and channels |
| 143 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
| 144 | Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms")); |
| 145 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20")); |
| 146 | |
| 147 | // Creating 3x3 topology |
| 148 | PointToPointHelper p2p; |
| 149 | PointToPointGridHelper grid (3, 3, p2p); |
| 150 | grid.BoundingBox(100,100,200,200); |
| 151 | |
| 152 | // Install CCNx stack on all nodes |
| 153 | CcnxStackHelper ccnxHelper; |
| 154 | ccnxHelper.InstallAll (); |
| 155 | |
| 156 | // Installing global routing interface on all nodes |
| 157 | CcnxGlobalRoutingHelper ccnxGlobalRoutingHelper; |
| 158 | ccnxGlobalRoutingHelper.InstallAll (); |
| 159 | |
| 160 | // Getting containers for the consumer/producer |
| 161 | Ptr<Node> producer = grid.GetNode (nGrid-1, nGrid-1); |
| 162 | NodeContainer consumerNodes; |
| 163 | consumerNodes.Add (grid.GetNode (0,0)); |
| 164 | |
| 165 | // Install CCNx applications |
| 166 | std::string prefix = "/prefix"; |
| 167 | |
| 168 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumerCbr"); |
| 169 | consumerHelper.SetPrefix (prefix); |
| 170 | consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second |
| 171 | consumerHelper.Install (consumerNodes); |
| 172 | |
| 173 | CcnxAppHelper producerHelper ("ns3::CcnxProducer"); |
| 174 | producerHelper.SetPrefix (prefix); |
| 175 | producerHelper.SetAttribute ("PayloadSize", StringValue("1024")); |
| 176 | producerHelper.Install (producer); |
| 177 | |
| 178 | // Add /prefix origins to CcnxGlobalRouter |
| 179 | ccnxGlobalRoutingHelper.AddOrigins (prefix, producer); |
| 180 | |
| 181 | // Calculate and install FIBs |
| 182 | ccnxGlobalRoutingHelper.CalculateRoutes (); |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 183 | |
| 184 | Simulator::Stop (Seconds (20.0)); |
| 185 | |
| 186 | Simulator::Run (); |
| 187 | Simulator::Destroy (); |
| 188 | |
| 189 | return 0; |
| 190 | } |
| 191 | |
Alexander Afanasyev | 4d32516 | 2012-06-01 12:28:50 -0700 | [diff] [blame] | 192 | |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 193 | If this code is placed into ``scratch/ccnx-grid.cc`` and NS-3 is compiled in debug mode, you can run and see progress of the |
| 194 | simulation using the following command (in optimized mode nothing will be printed out):: |
| 195 | |
| 196 | NS_LOG=CcnxConsumer:CcnxProducer ./waf --run=ccnx-grid |
| 197 | |