blob: 869d4431e69a97e7db942d85001b22b0d9d8bdde [file] [log] [blame]
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -08001/* -*- 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 Mastorakis5ea33222016-12-07 14:33:53 -080026#include "ns3/ndnSIM/model/ndn-net-device-transport.hpp"
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -080027
28namespace ns3 {
29
30int
31main(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"));
Alexander Afanasyev77f84c62018-10-08 13:37:42 -040036 Config::SetDefault("ns3::QueueBase::MaxSize", StringValue("20p"));
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -080037
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 Mastorakisb0b22412016-12-07 14:33:46 -080085 cout << nextHop.getFace();
86 auto& face = nextHop.getFace();
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -080087 auto transport = dynamic_cast<ndn::NetDeviceTransport*>(face.getTransport());
88 if (transport == nullptr) {
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -080089 continue;
Alexander Afanasyev50ea1a32016-09-08 15:44:08 -070090 }
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -080091
92 cout << " towards ";
93
94 if (!isFirst)
95 cout << ", ";
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -080096 cout << Names::FindName(transport->GetNetDevice()->GetChannel()->GetDevice(1)->GetNode());
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -080097 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
118int
119main(int argc, char* argv[])
120{
121 return ns3::main(argc, argv);
122}