Alexander Afanasyev | afe47fe | 2015-01-06 18:29:39 -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. |
| 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 | // ndn-triangle-calculate-routes.cpp |
| 21 | |
| 22 | #include "ns3/core-module.h" |
| 23 | #include "ns3/network-module.h" |
| 24 | #include "ns3/ndnSIM-module.h" |
| 25 | |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 26 | #include "ns3/ndnSIM/model/ndn-net-device-transport.hpp" |
Alexander Afanasyev | afe47fe | 2015-01-06 18:29:39 -0800 | [diff] [blame] | 27 | |
| 28 | namespace ns3 { |
| 29 | |
| 30 | int |
| 31 | main(int argc, char* argv[]) |
| 32 | { |
| 33 | // setting default parameters for PointToPoint links and channels |
| 34 | Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps")); |
| 35 | Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); |
| 36 | Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20")); |
| 37 | |
| 38 | // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize |
| 39 | CommandLine cmd; |
| 40 | cmd.Parse(argc, argv); |
| 41 | |
| 42 | ofstream file1("/tmp/topo1.txt"); |
| 43 | file1 << "router\n\n" |
| 44 | << "#node city y x mpi-partition\n" |
| 45 | << "A1 NA 1 1 1\n" |
| 46 | << "B1 NA 80 -40 1\n" |
| 47 | << "C1 NA 80 40 1\n" |
| 48 | << "A2 NA 1 1 1\n" |
| 49 | << "B2 NA 80 -40 1\n" |
| 50 | << "C2 NA 80 40 1\n\n" |
| 51 | << "link\n\n" |
| 52 | << "# from to capacity metric delay queue\n" |
| 53 | << "A1 B1 10Mbps 100 1ms 100\n" |
| 54 | << "A1 C1 10Mbps 50 1ms 100\n" |
| 55 | << "B1 C1 10Mbps 1 1ms 100\n" |
| 56 | << "A2 B2 10Mbps 50 1ms 100\n" |
| 57 | << "A2 C2 10Mbps 100 1ms 100\n" |
| 58 | << "B2 C2 10Mbps 1 1ms 100\n"; |
| 59 | file1.close(); |
| 60 | |
| 61 | AnnotatedTopologyReader topologyReader(""); |
| 62 | topologyReader.SetFileName("/tmp/topo1.txt"); |
| 63 | topologyReader.Read(); |
| 64 | |
| 65 | // Install NDN stack on all nodes |
| 66 | ndn::StackHelper ndnHelper; |
| 67 | ndnHelper.InstallAll(); |
| 68 | |
| 69 | topologyReader.ApplyOspfMetric(); |
| 70 | |
| 71 | ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; |
| 72 | ndnGlobalRoutingHelper.InstallAll(); |
| 73 | |
| 74 | ndnGlobalRoutingHelper.AddOrigins("/test/prefix", Names::Find<Node>("C1")); |
| 75 | ndnGlobalRoutingHelper.AddOrigins("/test/prefix", Names::Find<Node>("C2")); |
| 76 | ndn::GlobalRoutingHelper::CalculateRoutes(); |
| 77 | |
| 78 | auto printFib = [](Ptr<Node> node) { |
| 79 | auto ndn = node->GetObject<ndn::L3Protocol>(); |
| 80 | for (const auto& entry : ndn->getForwarder()->getFib()) { |
| 81 | cout << entry.getPrefix() << " ("; |
| 82 | |
| 83 | bool isFirst = true; |
| 84 | for (auto& nextHop : entry.getNextHops()) { |
Spyridon Mastorakis | b0b2241 | 2016-12-07 14:33:46 -0800 | [diff] [blame] | 85 | cout << nextHop.getFace(); |
| 86 | auto& face = nextHop.getFace(); |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 87 | auto transport = dynamic_cast<ndn::NetDeviceTransport*>(face.getTransport()); |
| 88 | if (transport == nullptr) { |
Alexander Afanasyev | afe47fe | 2015-01-06 18:29:39 -0800 | [diff] [blame] | 89 | continue; |
Alexander Afanasyev | 50ea1a3 | 2016-09-08 15:44:08 -0700 | [diff] [blame] | 90 | } |
Alexander Afanasyev | afe47fe | 2015-01-06 18:29:39 -0800 | [diff] [blame] | 91 | |
| 92 | cout << " towards "; |
| 93 | |
| 94 | if (!isFirst) |
| 95 | cout << ", "; |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 96 | cout << Names::FindName(transport->GetNetDevice()->GetChannel()->GetDevice(1)->GetNode()); |
Alexander Afanasyev | afe47fe | 2015-01-06 18:29:39 -0800 | [diff] [blame] | 97 | isFirst = false; |
| 98 | } |
| 99 | cout << ")" << endl; |
| 100 | } |
| 101 | }; |
| 102 | |
| 103 | cout << "FIB content on node A1" << endl; |
| 104 | printFib(Names::Find<Node>("A1")); |
| 105 | |
| 106 | cout << "FIB content on node A2" << endl; |
| 107 | printFib(Names::Find<Node>("A2")); |
| 108 | |
| 109 | Simulator::Stop(Seconds(20.0)); |
| 110 | Simulator::Run(); |
| 111 | Simulator::Destroy(); |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | } // namespace ns3 |
| 117 | |
| 118 | int |
| 119 | main(int argc, char* argv[]) |
| 120 | { |
| 121 | return ns3::main(argc, argv); |
| 122 | } |