blob: e01850812346d55c5e8d9483dd584ddee74f9329 [file] [log] [blame]
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -07001/* -*- 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#include "helper/ndn-global-routing-helper.hpp"
Chavoosh Ghasemi6028c612018-09-17 13:04:33 -070021#include "helper/ndn-stack-helper.hpp"
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070022
23#include "model/ndn-global-router.hpp"
24#include "model/ndn-l3-protocol.hpp"
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -080025#include "model/ndn-net-device-transport.hpp"
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070026
27#include "ns3/channel.h"
28#include "ns3/net-device.h"
29#include "ns3/core-module.h"
30#include "ns3/network-module.h"
31#include "ns3/ndnSIM-module.h"
32#include "ns3/point-to-point-net-device.h"
33#include "ns3/point-to-point-module.h"
34#include "ns3/point-to-point-layout-module.h"
35
36#include "../tests-common.hpp"
37
Alexander Afanasyev929b17e2015-08-13 16:54:09 -070038#include <boost/filesystem.hpp>
39
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070040namespace ns3 {
41namespace ndn {
42
Alexander Afanasyev929b17e2015-08-13 16:54:09 -070043const boost::filesystem::path TEST_TOPO_TXT = boost::filesystem::path(TEST_CONFIG_PATH) / "topo.txt";
44
45class GlobalRoutingHelperFixture : public CleanupFixture
46{
47public:
48 GlobalRoutingHelperFixture()
49 {
50 boost::filesystem::create_directories(TEST_CONFIG_PATH);
51 }
52
53 ~GlobalRoutingHelperFixture()
54 {
55 boost::filesystem::remove(TEST_TOPO_TXT);
56 }
57};
58
59BOOST_FIXTURE_TEST_SUITE(HelperGlobalRoutingHelper, GlobalRoutingHelperFixture)
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070060
61BOOST_AUTO_TEST_CASE(CalculateRouteCase1)
62{
Alexander Afanasyev929b17e2015-08-13 16:54:09 -070063 ofstream file1(TEST_TOPO_TXT.string().c_str());
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070064 file1 << "router\n\n"
65 << "#node city y x mpi-partition\n"
66 << "A1 NA 1 1 1\n"
67 << "B1 NA 80 -40 1\n"
68 << "C1 NA 80 40 1\n\n"
69 << "link\n\n"
70 << "# from to capacity metric delay queue\n"
71 << "A1 B1 10Mbps 100 1ms 100\n"
72 << "A1 C1 10Mbps 50 1ms 100\n"
73 << "B1 C1 10Mbps 1 1ms 100\n";
74 file1.close();
75
76 AnnotatedTopologyReader topologyReader("");
Alexander Afanasyev929b17e2015-08-13 16:54:09 -070077 topologyReader.SetFileName(TEST_TOPO_TXT.string().c_str());
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070078 topologyReader.Read();
79
80 // Install NDN stack on all nodes
81 ndn::StackHelper ndnHelper;
82 ndnHelper.InstallAll();
83
84 topologyReader.ApplyOspfMetric();
85
86 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
87 BOOST_CHECK_NO_THROW(ndnGlobalRoutingHelper.InstallAll());
88
89 ndnGlobalRoutingHelper.AddOrigins("/test/prefix", Names::Find<Node>("C1"));
90 BOOST_CHECK_NO_THROW(ndn::GlobalRoutingHelper::CalculateRoutes());
91
92 auto ndn = Names::Find<Node>("A1")->GetObject<ndn::L3Protocol>();
93 for (const auto& entry : ndn->getForwarder()->getFib()) {
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070094 for (auto& nextHop : entry.getNextHops()) {
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -080095 auto& face = nextHop.getFace();
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -080096 auto transport = dynamic_cast<NetDeviceTransport*>(face.getTransport());
97 if (transport == nullptr)
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070098 continue;
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -080099 BOOST_CHECK_EQUAL(Names::FindName(transport->GetNetDevice()->GetChannel()->GetDevice(1)->GetNode()), "C1");
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700100 }
101 }
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700102}
103
104BOOST_AUTO_TEST_CASE(CalculateRouteCase2)
105{
Alexander Afanasyev929b17e2015-08-13 16:54:09 -0700106 ofstream file1(TEST_TOPO_TXT.string().c_str());
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700107 file1 << "router\n\n"
108 << "#node city y x mpi-partition\n"
109 << "A2 NA 1 1 1\n"
110 << "B2 NA 80 -40 1\n"
111 << "C2 NA 80 40 1\n\n"
112 << "link\n\n"
113 << "# from to capacity metric delay queue\n"
114 << "A2 B2 10Mbps 100 1ms 100\n"
115 << "A2 C2 10Mbps 500 1ms 100\n"
116 << "B2 C2 10Mbps 1 1ms 100\n";
117 file1.close();
118
119 AnnotatedTopologyReader topologyReader("");
Alexander Afanasyev929b17e2015-08-13 16:54:09 -0700120 topologyReader.SetFileName(TEST_TOPO_TXT.string().c_str());
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700121 topologyReader.Read();
122
123 // Install NDN stack on all nodes
124 ndn::StackHelper ndnHelper;
125 ndnHelper.InstallAll();
126
127 topologyReader.ApplyOspfMetric();
128
129 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
130 ndnGlobalRoutingHelper.InstallAll();
131
132 ndnGlobalRoutingHelper.AddOrigins("/prefix", Names::Find<Node>("C2"));
133 ndn::GlobalRoutingHelper::CalculateRoutes();
134
135 auto ndn = Names::Find<Node>("A2")->GetObject<ndn::L3Protocol>();
136 for (const auto& entry : ndn->getForwarder()->getFib()) {
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700137 for (auto& nextHop : entry.getNextHops()) {
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800138 auto& face = nextHop.getFace();
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800139 auto transport = dynamic_cast<NetDeviceTransport*>(face.getTransport());
140 if (transport == nullptr)
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700141 continue;
Spyridon Mastorakis5ea33222016-12-07 14:33:53 -0800142 BOOST_CHECK_EQUAL(Names::FindName(transport->GetNetDevice()->GetChannel()->GetDevice(1)->GetNode()), "B2");
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700143 }
144 }
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700145}
146
Chavoosh Ghasemi6028c612018-09-17 13:04:33 -0700147BOOST_AUTO_TEST_CASE(CalculateRoutesBasedOnLinkDelay)
148{
149 ofstream file1(TEST_TOPO_TXT.string().c_str());
150 file1 << "router\n\n"
151 << "#node city y x mpi-partition\n"
152 << "A3 NA 1 1 1\n"
153 << "B3 NA 80 -40 1\n"
154 << "C3 NA 80 40 1\n\n"
155 << "link\n\n"
156 << "# from to capacity metric delay queue\n"
157 << "A3 B3 10Mbps 1 1ms 100\n"
158 << "A3 C3 10Mbps 1 10ms 100\n"
159 << "B3 C3 10Mbps 1 1ms 100\n";
160 file1.close();
161
162 AnnotatedTopologyReader topologyReader("");
163 topologyReader.SetFileName(TEST_TOPO_TXT.string().c_str());
164 topologyReader.Read();
165
166 // Install NDN stack on all nodes
167 ndn::StackHelper ndnHelper;
168 ndnHelper.InstallAll();
169
170 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
171 ndnGlobalRoutingHelper.InstallAll();
172
173 ndnGlobalRoutingHelper.AddOrigins("/prefix", Names::Find<Node>("C3"));
174 ndn::StackHelper::SetLinkDelayAsFaceMetric(); // should be called right before routes calculation
175 ndn::GlobalRoutingHelper::CalculateRoutes();
176
177 auto ndn = Names::Find<Node>("A3")->GetObject<ndn::L3Protocol>();
178 for (const auto& entry : ndn->getForwarder()->getFib()) {
179 for (auto& nextHop : entry.getNextHops()) {
180 auto& face = nextHop.getFace();
181 auto transport = dynamic_cast<NetDeviceTransport*>(face.getTransport());
182 if (transport == nullptr)
183 continue;
184 BOOST_CHECK_EQUAL(Names::FindName(transport->GetNetDevice()->GetChannel()->GetDevice(1)->GetNode()), "B3");
185 }
186 }
187}
188
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700189BOOST_AUTO_TEST_SUITE_END()
190
191} // namespace ndn
192} // namespace ns3