Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011-2012 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | // ndn-congestion-alt-topo-plugin.cc |
| 22 | |
| 23 | #include "ns3/core-module.h" |
| 24 | #include "ns3/network-module.h" |
| 25 | #include "ns3/ndnSIM-module.h" |
| 26 | |
| 27 | using namespace ns3; |
| 28 | |
| 29 | /** |
| 30 | * |
| 31 | * /------\ 0 0 /------\ |
| 32 | * | c1 |<-----+ +----->| p1 | |
| 33 | * \------/ \ / \------/ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 34 | * \ /-----\ / |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 35 | * /------\ 0 \ +==>| r12 |<==+ / 0 /------\ |
| 36 | * | c2 |<--+ \ / \-----/ \ / +-->| p2 | |
| 37 | * \------/ \ \ | | / / \------/ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 38 | * \ | | 1Mbps links | | / |
| 39 | * \ 1 v0 v5 1v 2v 3 / |
| 40 | * +->/------\ /------\<-+ |
| 41 | * 2| r1 |<===============>| r2 |4 |
| 42 | * +->\------/4 0\------/<-+ |
| 43 | * / 3^ ^5 \ |
| 44 | * / | | \ |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 45 | * /------\ 0 / / \ \ 0 /------\ |
| 46 | * | c3 |<--+ / \ +-->| p3 | |
| 47 | * \------/ / \ \------/ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 48 | * / "All consumer-router and" \ |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 49 | * /------\ 0 / "router-producer links are" \ 0 /------\ |
| 50 | * | c4 |<-----+ "10Mbps" +---->| p4 | |
| 51 | * \------/ \------/ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 52 | * |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 53 | * "Numbers near nodes denote face IDs. Face ID is assigned based on the order of link" |
| 54 | * "definitions in the topology file" |
| 55 | * |
| 56 | * To run scenario and see what is happening, use the following command: |
| 57 | * |
| 58 | * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-alt-topo-plugin |
| 59 | */ |
| 60 | |
| 61 | int |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 62 | main(int argc, char* argv[]) |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 63 | { |
| 64 | CommandLine cmd; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 65 | cmd.Parse(argc, argv); |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 66 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 67 | AnnotatedTopologyReader topologyReader("", 1); |
| 68 | topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-11-node-two-bottlenecks.txt"); |
| 69 | topologyReader.Read(); |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 70 | |
Alexander Afanasyev | 9fb2e3d | 2013-03-30 21:11:07 -0700 | [diff] [blame] | 71 | // Install NDN stack on all nodes |
| 72 | ndn::StackHelper ndnHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 73 | ndnHelper.SetForwardingStrategy("ns3::ndn::fw::CustomStrategy"); |
| 74 | ndnHelper.SetContentStore("ns3::ndn::cs::Lru", "MaxSize", |
| 75 | "1"); // ! Attention ! If set to 0, then MaxSize is infinite |
| 76 | ndnHelper.InstallAll(); |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 77 | |
| 78 | // Getting containers for the consumer/producer |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 79 | Ptr<Node> consumers[4] = {Names::Find<Node>("c1"), Names::Find<Node>("c2"), |
| 80 | Names::Find<Node>("c3"), Names::Find<Node>("c4")}; |
| 81 | Ptr<Node> producers[4] = {Names::Find<Node>("p1"), Names::Find<Node>("p2"), |
| 82 | Names::Find<Node>("p3"), Names::Find<Node>("p4")}; |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 83 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 84 | if (consumers[0] == 0 || consumers[1] == 0 || consumers[2] == 0 || consumers[3] == 0 |
| 85 | || producers[0] == 0 || producers[1] == 0 || producers[2] == 0 || producers[3] == 0) { |
| 86 | NS_FATAL_ERROR("Error in topology: one nodes c1, c2, c3, c4, p1, p2, p3, or p4 is missing"); |
| 87 | } |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 88 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 89 | for (int i = 0; i < 4; i++) { |
| 90 | std::string prefix = "/data/" + Names::FindName(producers[i]); |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 91 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 92 | ///////////////////////////////////////////////////////////////////////////////// |
| 93 | // install consumer app on consumer node c_i to request data from producer p_i // |
| 94 | ///////////////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 95 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 96 | ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
| 97 | consumerHelper.SetAttribute("Frequency", StringValue("10")); // 100 interests a second |
| 98 | |
| 99 | consumerHelper.SetPrefix(prefix); |
| 100 | ApplicationContainer consumer = consumerHelper.Install(consumers[i]); |
| 101 | consumer.Start(Seconds(i)); // start consumers at 0s, 1s, 2s, 3s |
| 102 | consumer.Stop(Seconds(19 - i)); // stop consumers at 19s, 18s, 17s, 16s |
| 103 | |
| 104 | /////////////////////////////////////////////// |
| 105 | // install producer app on producer node p_i // |
| 106 | /////////////////////////////////////////////// |
| 107 | |
| 108 | ndn::AppHelper producerHelper("ns3::ndn::Producer"); |
| 109 | producerHelper.SetAttribute("PayloadSize", StringValue("1024")); |
| 110 | |
| 111 | // install producer that will satisfy Interests in /dst1 namespace |
| 112 | producerHelper.SetPrefix(prefix); |
| 113 | ApplicationContainer producer = producerHelper.Install(producers[i]); |
| 114 | // when Start/Stop time is not specified, the application is running throughout the simulation |
| 115 | } |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 116 | |
| 117 | // Manually configure FIB routes |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 118 | ndn::StackHelper::AddRoute("c1", "/data", "n1", 1); // link to n1 |
| 119 | ndn::StackHelper::AddRoute("c2", "/data", "n1", 1); // link to n1 |
| 120 | ndn::StackHelper::AddRoute("c3", "/data", "n1", 1); // link to n1 |
| 121 | ndn::StackHelper::AddRoute("c4", "/data", "n1", 1); // link to n1 |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 122 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 123 | ndn::StackHelper::AddRoute("n1", "/data", "n2", 1); // link to n2 |
| 124 | ndn::StackHelper::AddRoute("n1", "/data", "n12", 2); // link to n12 |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 125 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 126 | ndn::StackHelper::AddRoute("n12", "/data", "n2", 1); // link to n2 |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 127 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 128 | ndn::StackHelper::AddRoute("n2", "/data/p1", "p1", 1); // link to p1 |
| 129 | ndn::StackHelper::AddRoute("n2", "/data/p2", "p2", 1); // link to p2 |
| 130 | ndn::StackHelper::AddRoute("n2", "/data/p3", "p3", 1); // link to p3 |
| 131 | ndn::StackHelper::AddRoute("n2", "/data/p4", "p4", 1); // link to p4 |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 132 | |
| 133 | // Schedule simulation time and run the simulation |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 134 | Simulator::Stop(Seconds(20.0)); |
| 135 | Simulator::Run(); |
| 136 | Simulator::Destroy(); |
Alexander Afanasyev | e97c607 | 2012-11-21 23:51:12 -0800 | [diff] [blame] | 137 | |
| 138 | return 0; |
| 139 | } |