Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 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. |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 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. |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 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 | **/ |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 19 | |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 20 | // ndn-congestion-alt-topo-plugin.cpp |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 21 | |
| 22 | #include "ns3/core-module.h" |
| 23 | #include "ns3/network-module.h" |
| 24 | #include "ns3/ndnSIM-module.h" |
| 25 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 26 | namespace ns3 { |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * |
| 30 | * /------\ 0 0 /------\ |
| 31 | * | c1 |<-----+ +----->| p1 | |
| 32 | * \------/ \ / \------/ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 33 | * \ /-----\ / |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 34 | * /------\ 0 \ +==>| r12 |<==+ / 0 /------\ |
| 35 | * | c2 |<--+ \ / \-----/ \ / +-->| p2 | |
| 36 | * \------/ \ \ | | / / \------/ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 37 | * \ | | 1Mbps links | | / |
| 38 | * \ 1 v0 v5 1v 2v 3 / |
| 39 | * +->/------\ /------\<-+ |
| 40 | * 2| r1 |<===============>| r2 |4 |
| 41 | * +->\------/4 0\------/<-+ |
| 42 | * / 3^ ^5 \ |
| 43 | * / | | \ |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 44 | * /------\ 0 / / \ \ 0 /------\ |
| 45 | * | c3 |<--+ / \ +-->| p3 | |
| 46 | * \------/ / \ \------/ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 47 | * / "All consumer-router and" \ |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 48 | * /------\ 0 / "router-producer links are" \ 0 /------\ |
| 49 | * | c4 |<-----+ "10Mbps" +---->| p4 | |
| 50 | * \------/ \------/ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 51 | * |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 52 | * "Numbers near nodes denote face IDs. Face ID is assigned based on the order of link" |
| 53 | * "definitions in the topology file" |
| 54 | * |
| 55 | * To run scenario and see what is happening, use the following command: |
| 56 | * |
| 57 | * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-alt-topo-plugin |
| 58 | */ |
| 59 | |
| 60 | int |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 61 | main(int argc, char* argv[]) |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 62 | { |
| 63 | CommandLine cmd; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 64 | cmd.Parse(argc, argv); |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 65 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 66 | AnnotatedTopologyReader topologyReader("", 1); |
| 67 | topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-11-node-two-bottlenecks.txt"); |
| 68 | topologyReader.Read(); |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 69 | |
Alexander Afanasyev | 9fb2e3d | 2013-03-30 21:11:07 -0700 | [diff] [blame] | 70 | // Install NDN stack on all nodes |
| 71 | ndn::StackHelper ndnHelper; |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 72 | ndnHelper.SetContentStoreChoice(false); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 73 | ndnHelper.SetContentStore("ns3::ndn::cs::Lru", "MaxSize", |
| 74 | "1"); // ! Attention ! If set to 0, then MaxSize is infinite |
| 75 | ndnHelper.InstallAll(); |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 76 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 77 | // Set BestRoute strategy |
| 78 | ndn::StrategyChoiceHelper::InstallAll("/", "/localhost/nfd/strategy/best-route"); |
| 79 | |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 80 | // Getting containers for the consumer/producer |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 81 | Ptr<Node> consumers[4] = {Names::Find<Node>("c1"), Names::Find<Node>("c2"), |
| 82 | Names::Find<Node>("c3"), Names::Find<Node>("c4")}; |
| 83 | Ptr<Node> producers[4] = {Names::Find<Node>("p1"), Names::Find<Node>("p2"), |
| 84 | Names::Find<Node>("p3"), Names::Find<Node>("p4")}; |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 85 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | if (consumers[0] == 0 || consumers[1] == 0 || consumers[2] == 0 || consumers[3] == 0 |
| 87 | || producers[0] == 0 || producers[1] == 0 || producers[2] == 0 || producers[3] == 0) { |
| 88 | NS_FATAL_ERROR("Error in topology: one nodes c1, c2, c3, c4, p1, p2, p3, or p4 is missing"); |
| 89 | } |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 90 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 91 | for (int i = 0; i < 4; i++) { |
| 92 | std::string prefix = "/data/" + Names::FindName(producers[i]); |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 93 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 94 | ///////////////////////////////////////////////////////////////////////////////// |
| 95 | // install consumer app on consumer node c_i to request data from producer p_i // |
| 96 | ///////////////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 97 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 98 | ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
| 99 | consumerHelper.SetAttribute("Frequency", StringValue("10")); // 100 interests a second |
| 100 | |
| 101 | consumerHelper.SetPrefix(prefix); |
| 102 | ApplicationContainer consumer = consumerHelper.Install(consumers[i]); |
| 103 | consumer.Start(Seconds(i)); // start consumers at 0s, 1s, 2s, 3s |
| 104 | consumer.Stop(Seconds(19 - i)); // stop consumers at 19s, 18s, 17s, 16s |
| 105 | |
| 106 | /////////////////////////////////////////////// |
| 107 | // install producer app on producer node p_i // |
| 108 | /////////////////////////////////////////////// |
| 109 | |
| 110 | ndn::AppHelper producerHelper("ns3::ndn::Producer"); |
| 111 | producerHelper.SetAttribute("PayloadSize", StringValue("1024")); |
| 112 | |
| 113 | // install producer that will satisfy Interests in /dst1 namespace |
| 114 | producerHelper.SetPrefix(prefix); |
| 115 | ApplicationContainer producer = producerHelper.Install(producers[i]); |
| 116 | // when Start/Stop time is not specified, the application is running throughout the simulation |
| 117 | } |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 118 | |
| 119 | // Manually configure FIB routes |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 120 | ndn::FibHelper::AddRoute("c1", "/data", "n1", 1); // link to n1 |
| 121 | ndn::FibHelper::AddRoute("c2", "/data", "n1", 1); // link to n1 |
| 122 | ndn::FibHelper::AddRoute("c3", "/data", "n1", 1); // link to n1 |
| 123 | ndn::FibHelper::AddRoute("c4", "/data", "n1", 1); // link to n1 |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 124 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 125 | ndn::FibHelper::AddRoute("n1", "/data", "n2", 1); // link to n2 |
| 126 | ndn::FibHelper::AddRoute("n1", "/data", "n12", 2); // link to n12 |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 127 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 128 | ndn::FibHelper::AddRoute("n12", "/data", "n2", 1); // link to n2 |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 129 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 130 | ndn::FibHelper::AddRoute("n2", "/data/p1", "p1", 1); // link to p1 |
| 131 | ndn::FibHelper::AddRoute("n2", "/data/p2", "p2", 1); // link to p2 |
| 132 | ndn::FibHelper::AddRoute("n2", "/data/p3", "p3", 1); // link to p3 |
| 133 | ndn::FibHelper::AddRoute("n2", "/data/p4", "p4", 1); // link to p4 |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 134 | |
| 135 | // Schedule simulation time and run the simulation |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 136 | Simulator::Stop(Seconds(20.0)); |
| 137 | Simulator::Run(); |
| 138 | Simulator::Destroy(); |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 139 | |
| 140 | return 0; |
| 141 | } |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 142 | |
| 143 | |
| 144 | } // namespace ns3 |
| 145 | |
| 146 | int |
| 147 | main(int argc, char* argv[]) |
| 148 | { |
| 149 | return ns3::main(argc, argv); |
| 150 | } |