blob: b2b8138bd235fce6ff8ac6d0eea914ff9e2674aa [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
26#include "model/ndn-net-device-face.hpp"
27
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"));
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()) {
85 cout << *nextHop.getFace();
86 auto face = dynamic_pointer_cast<ndn::NetDeviceFace>(nextHop.getFace());
87 if (face == nullptr)
88 continue;
89
90 cout << " towards ";
91
92 if (!isFirst)
93 cout << ", ";
94 cout << Names::FindName(face->GetNetDevice()->GetChannel()->GetDevice(1)->GetNode());
95 isFirst = false;
96 }
97 cout << ")" << endl;
98 }
99 };
100
101 cout << "FIB content on node A1" << endl;
102 printFib(Names::Find<Node>("A1"));
103
104 cout << "FIB content on node A2" << endl;
105 printFib(Names::Find<Node>("A2"));
106
107 Simulator::Stop(Seconds(20.0));
108 Simulator::Run();
109 Simulator::Destroy();
110
111 return 0;
112}
113
114} // namespace ns3
115
116int
117main(int argc, char* argv[])
118{
119 return ns3::main(argc, argv);
120}