blob: 77eed91be116631ac80c6533efaee322e08d23e5 [file] [log] [blame]
Klaus Schneider38784302019-08-31 18:26:36 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2019 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"
21#include "helper/ndn-stack-helper.hpp"
22
23#include "model/ndn-global-router.hpp"
24#include "model/ndn-l3-protocol.hpp"
25#include "model/ndn-net-device-transport.hpp"
26
27#include "NFD/daemon/fw/best-route-strategy2.hpp"
28
29#include "ns3/channel.h"
30#include "ns3/net-device.h"
31#include "ns3/core-module.h"
32#include "ns3/network-module.h"
33#include "ns3/ndnSIM-module.h"
34#include "ns3/point-to-point-net-device.h"
35#include "ns3/point-to-point-module.h"
36#include "ns3/point-to-point-layout-module.h"
37
38#include "../tests-common.hpp"
39
40#include <boost/filesystem.hpp>
41
42namespace ns3 {
43namespace ndn {
44
45BOOST_FIXTURE_TEST_SUITE(HelperLfidRoutingHelper, CleanupFixture)
46
47BOOST_AUTO_TEST_CASE(CalculateRouteAbilene)
48{
49 AnnotatedTopologyReader topologyReader;
50 topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-abilene.txt");
51 topologyReader.Read();
52
53 // Install NDN stack on all nodes
54 ndn::StackHelper stackHelper{};
55 stackHelper.InstallAll();
56
57 // IMPORTANT: Has to be run after StackHelper!
58 topologyReader.ApplyOspfMetric();
59
60 const std::string prefix{"/prefix"};
61
62 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
63 BOOST_CHECK_NO_THROW(ndnGlobalRoutingHelper.InstallAll());
64
65// auto producer = Names::Find<Node>("producer");
66 const NodeContainer allNodes {topologyReader.GetNodes()};
67
68 // Make every node a producer for their prefix:
69 for (int i = 0; i < allNodes.size(); i++) {
70 ndnGlobalRoutingHelper.AddOrigins(prefix + std::to_string(i), allNodes.Get(i));
71 }
72 BOOST_CHECK_NO_THROW(ndn::GlobalRoutingHelper::CalculateLfidRoutes());
73
74 // IMPORTANT: Some strategy needs to be installed for test to work.
75 ndn::StrategyChoiceHelper str;
76 str.InstallAll<nfd::fw::BestRouteStrategy2>("/");
77
78 int numNexthops = 0;
79
80 // For all nodes
81 for (const auto& n : allNodes) {
82
83 // For all producer prefixes i
84 for (int i = 0; i < allNodes.size(); i++) {
85 if (n->GetId() == i) continue;
86
87 std::string prodPrefix = prefix + std::to_string(i);
88
89 const auto& fib = n->GetObject<ndn::L3Protocol>()->getForwarder()->getFib();
90 auto& e = fib.findLongestPrefixMatch(prodPrefix);
91
92 // Check that each node has at least 1 nexthop
93 BOOST_CHECK_GE(e.getNextHops().size(), 1);
94
95 for (const auto& nh : e.getNextHops()) {
96 // Get remote nodeId from face:
97 const auto& transport =
98 dynamic_cast<ndn::NetDeviceTransport*>(nh.getFace().getTransport());
99 BOOST_ASSERT(transport);
100
101 const auto& nd1 = transport->GetNetDevice()->GetObject<PointToPointNetDevice>();
102 BOOST_ASSERT(nd1);
103
104 const auto& ppChannel = DynamicCast<PointToPointChannel>(nd1->GetChannel());
105 BOOST_ASSERT(ppChannel);
106
107 auto nd2 = ppChannel->GetDevice(0);
108 // If node in channel is own node -> Switch to other node.
109 if (nd2->GetNode() == n) {
110 nd2 = ppChannel->GetDevice(1);
111 }
112
113 // Cost must be greater than 0.
114 BOOST_CHECK_GE(nh.getCost(), 1);
115 }
116
117 numNexthops += e.getNextHops().size();
118 }
119 }
120
121 BOOST_CHECK_EQUAL(numNexthops, 226);
122}
123
124
125BOOST_AUTO_TEST_SUITE_END()
126
127} // namespace ndn
128} // namespace ns3