Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2016 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
| 7 | * |
| 8 | * ndnSIM is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
| 19 | |
| 20 | #include "ns3/core-module.h" |
| 21 | #include "ns3/network-module.h" |
| 22 | #include "ns3/point-to-point-module.h" |
| 23 | #include "ns3/ndnSIM-module.h" |
| 24 | |
| 25 | /** |
| 26 | * This scenario simulates a very simple network topology: |
| 27 | * |
| 28 | * |
| 29 | * |
| 30 | * ----------------------------- (Producer) |
| 31 | * / | |
| 32 | * / | |
| 33 | * (Consumer) ------ (Non-Producer-Region Router) ----- (Produer-Region-Network Router) |
| 34 | * | |
| 35 | * | |
| 36 | * ( ) |
| 37 | * |
| 38 | * |
| 39 | * |
| 40 | * |
| 41 | * Consumer sends interest with Link object attatched. Non-Producer-Region Router will |
| 42 | * forward the interest based on Forwarding Hint(dalegationName in Link object) toward |
| 43 | * delegationName direction because the router is not in |
| 44 | * ProducerRegion. Producer-Region-Network checks incomming interests and finds out the |
| 45 | * interest has reached ProducerRegion, thus the router will forward the incoming interest |
| 46 | * based on interestName. |
| 47 | * |
| 48 | * For every received interest, producer replies with a data packet, containing 1024 bytes |
| 49 | * of virtual payload. |
| 50 | * |
| 51 | * To run scenario and see what is happening, use the following command: |
| 52 | * |
| 53 | * NS_LOG=nfd.Forwarder=logic ./waf --run=ndn-simple-for-nrt-helper |
| 54 | */ |
| 55 | |
| 56 | namespace ns3 { |
| 57 | |
| 58 | int |
| 59 | main(int argc, char* argv[]) |
| 60 | { |
| 61 | // setting default parameters for PointToPoint links and channels |
| 62 | Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps")); |
| 63 | Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); |
Alexander Afanasyev | f007a99 | 2022-05-05 15:57:08 -0400 | [diff] [blame^] | 64 | Config::SetDefault("ns3::DropTailQueue<Packet>::MaxSize", StringValue("20p")); |
Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 65 | |
| 66 | // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize |
| 67 | CommandLine cmd; |
| 68 | cmd.Parse(argc, argv); |
| 69 | |
| 70 | // Creating nodes |
| 71 | Ptr<Node> consumer = CreateObject<Node>(); |
| 72 | Ptr<Node> intRouter = CreateObject<Node>(); |
| 73 | NodeContainer uclaRegion; |
| 74 | uclaRegion.Create(3); |
| 75 | |
| 76 | // Connecting nodes using two links |
| 77 | PointToPointHelper p2p; |
| 78 | p2p.Install(consumer, intRouter); |
| 79 | p2p.Install(intRouter, uclaRegion.Get(0)); |
| 80 | p2p.Install(intRouter, uclaRegion.Get(1)); |
| 81 | p2p.Install(uclaRegion.Get(0), uclaRegion.Get(1)); |
| 82 | p2p.Install(uclaRegion.Get(1), uclaRegion.Get(2)); |
| 83 | |
| 84 | // Install NDN stack on all nodes |
| 85 | ndn::StackHelper ndnHelper; |
| 86 | ndnHelper.SetDefaultRoutes(true); |
| 87 | ndnHelper.InstallAll(); |
| 88 | |
| 89 | // Install Routes Manually |
| 90 | ndn::FibHelper::AddRoute(intRouter, ndn::Name("/ucla"), uclaRegion.Get(1), 1); |
| 91 | |
| 92 | // Configure NetworkRegionTable |
| 93 | ndn::NetworkRegionTableHelper::AddRegionName(uclaRegion, ndn::Name("/ucla")); |
| 94 | |
| 95 | // Installing applications |
| 96 | |
| 97 | // Consumer |
| 98 | ndn::AppHelper requesterHelper("RequesterApp"); |
| 99 | requesterHelper.SetAttribute("Name", StringValue("/ndnSIM/someData")); |
| 100 | requesterHelper.SetAttribute("Delegation", StringValue("/ucla1")); |
| 101 | requesterHelper.Install(consumer).Start(Seconds(1)); |
| 102 | |
| 103 | requesterHelper.SetAttribute("Name", StringValue("/ndnSIM/anotherData")); |
| 104 | requesterHelper.Install(consumer).Start(Seconds(2)); |
| 105 | |
| 106 | requesterHelper.SetAttribute("Name", StringValue("/ndnSIM/yetAnotherData")); |
| 107 | requesterHelper.SetAttribute("Delegation", StringValue("/non-existing")); |
| 108 | requesterHelper.Install(consumer).Start(Seconds(3)); |
| 109 | |
| 110 | // Producer |
| 111 | ndn::AppHelper producerHelper("ns3::ndn::Producer"); |
| 112 | producerHelper.SetPrefix("/ndnSIM"); |
| 113 | producerHelper.SetAttribute("PayloadSize", StringValue("1024")); |
| 114 | producerHelper.Install(uclaRegion.Get(0)); |
| 115 | |
| 116 | Simulator::Stop(Seconds(20.0)); |
| 117 | |
| 118 | Simulator::Run(); |
| 119 | Simulator::Destroy(); |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | } // namespace ns3 |
| 125 | |
| 126 | int |
| 127 | main(int argc, char* argv[]) |
| 128 | { |
| 129 | return ns3::main(argc, argv); |
| 130 | } |