blob: 318c8244903955132da53b7f3db5f082143f4b8c [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"
21
22#include "model/ndn-global-router.hpp"
23#include "model/ndn-l3-protocol.hpp"
24#include "model/ndn-face.hpp"
25#include "model/ndn-net-device-face.hpp"
26
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
38namespace ns3 {
39namespace ndn {
40
41BOOST_FIXTURE_TEST_SUITE(HelperGlobalRoutingHelper, CleanupFixture)
42
43BOOST_AUTO_TEST_CASE(CalculateRouteCase1)
44{
45 ofstream file1("/tmp/topo1.txt");
46 file1 << "router\n\n"
47 << "#node city y x mpi-partition\n"
48 << "A1 NA 1 1 1\n"
49 << "B1 NA 80 -40 1\n"
50 << "C1 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 file1.close();
57
58 AnnotatedTopologyReader topologyReader("");
59 topologyReader.SetFileName("/tmp/topo1.txt");
60 topologyReader.Read();
61
62 // Install NDN stack on all nodes
63 ndn::StackHelper ndnHelper;
64 ndnHelper.InstallAll();
65
66 topologyReader.ApplyOspfMetric();
67
68 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
69 BOOST_CHECK_NO_THROW(ndnGlobalRoutingHelper.InstallAll());
70
71 ndnGlobalRoutingHelper.AddOrigins("/test/prefix", Names::Find<Node>("C1"));
72 BOOST_CHECK_NO_THROW(ndn::GlobalRoutingHelper::CalculateRoutes());
73
74 auto ndn = Names::Find<Node>("A1")->GetObject<ndn::L3Protocol>();
75 for (const auto& entry : ndn->getForwarder()->getFib()) {
76 bool isFirst = true;
77 for (auto& nextHop : entry.getNextHops()) {
78 auto face = dynamic_pointer_cast<ndn::NetDeviceFace>(nextHop.getFace());
79 if (face == nullptr)
80 continue;
81 BOOST_CHECK_EQUAL(Names::FindName(face->GetNetDevice()->GetChannel()->GetDevice(1)->GetNode()), "C1");
82 isFirst = false;
83 }
84 }
85
86 Simulator::Stop(Seconds(20.0));
87 Simulator::Run();
88}
89
90BOOST_AUTO_TEST_CASE(CalculateRouteCase2)
91{
92 ofstream file1("/tmp/topo2.txt");
93 file1 << "router\n\n"
94 << "#node city y x mpi-partition\n"
95 << "A2 NA 1 1 1\n"
96 << "B2 NA 80 -40 1\n"
97 << "C2 NA 80 40 1\n\n"
98 << "link\n\n"
99 << "# from to capacity metric delay queue\n"
100 << "A2 B2 10Mbps 100 1ms 100\n"
101 << "A2 C2 10Mbps 500 1ms 100\n"
102 << "B2 C2 10Mbps 1 1ms 100\n";
103 file1.close();
104
105 AnnotatedTopologyReader topologyReader("");
106 topologyReader.SetFileName("/tmp/topo2.txt");
107 topologyReader.Read();
108
109 // Install NDN stack on all nodes
110 ndn::StackHelper ndnHelper;
111 ndnHelper.InstallAll();
112
113 topologyReader.ApplyOspfMetric();
114
115 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
116 ndnGlobalRoutingHelper.InstallAll();
117
118 ndnGlobalRoutingHelper.AddOrigins("/prefix", Names::Find<Node>("C2"));
119 ndn::GlobalRoutingHelper::CalculateRoutes();
120
121 auto ndn = Names::Find<Node>("A2")->GetObject<ndn::L3Protocol>();
122 for (const auto& entry : ndn->getForwarder()->getFib()) {
123 bool isFirst = true;
124 for (auto& nextHop : entry.getNextHops()) {
125 auto face = dynamic_pointer_cast<ndn::NetDeviceFace>(nextHop.getFace());
126 if (face == nullptr)
127 continue;
128 BOOST_CHECK_EQUAL(Names::FindName(face->GetNetDevice()->GetChannel()->GetDevice(1)->GetNode()), "B2");
129 isFirst = false;
130 }
131 }
132
133 Simulator::Stop(Seconds(20.0));
134 Simulator::Run();
135}
136
137BOOST_AUTO_TEST_SUITE_END()
138
139} // namespace ndn
140} // namespace ns3