blob: c4f1ebc1be8b5383afdf3e62a56f39789f78e12a [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-strategy-choice-helper.hpp"
21#include "helper/ndn-face-container.hpp"
22#include "model/ndn-net-device-face.hpp"
23
24#include "ns3/node-container.h"
25#include "ns3/point-to-point-net-device.h"
26#include "ns3/point-to-point-grid.h"
27#include "ns3/node.h"
28#include "ns3/core-module.h"
29#include "ns3/network-module.h"
30#include "ns3/point-to-point-module.h"
31#include "ns3/ndnSIM-module.h"
32
33#include "../tests-common.hpp"
34
35namespace ns3 {
36namespace ndn {
37
38BOOST_FIXTURE_TEST_SUITE(TestStrategyChoiceHelper, CleanupFixture)
39
40BOOST_AUTO_TEST_CASE(GridScenario)
41{
42 ofstream file("/tmp/topo3.txt");
43 file << "router\n\n"
44 << "#node city y x mpi-partition\n"
45 << "A3 NA 10 10 1\n"
46 << "B3 NA 20 10 1\n"
47 << "C3 NA 10 20 1\n"
48 << "D3 NA 20 20 1\n\n"
49 << "link\n\n"
50 << "# from to capacity metric delay queue\n"
51 << "A3 B3 10Mbps 100 1ms 500\n"
52 << "A3 C3 10Mbps 200 1ms 500\n"
53 << "B3 D3 10Mbps 100 1ms 500\n"
54 << "C3 D3 10Mbps 200 1ms 500\n";
55 file.close();
56
57 AnnotatedTopologyReader topologyReader("");
58 topologyReader.SetFileName("/tmp/topo3.txt");
59 topologyReader.Read();
60
61 // Install NDN stack on all nodes
62 ndn::StackHelper ndnHelper;
63 Ptr<FaceContainer> node_faceContainer = ndnHelper.InstallAll();
64 GlobalRoutingHelper ndnGlobalRoutingHelper;
65 ndnGlobalRoutingHelper.InstallAll();
66
67 // Install different forwarding strategies
68 StrategyChoiceHelper::Install(Names::Find<Node>("A3"), "/prefix",
69 "/localhost/nfd/strategy/broadcast");
70 StrategyChoiceHelper::Install(Names::Find<Node>("B3"), "/prefix",
71 "/localhost/nfd/strategy/best-route");
72 StrategyChoiceHelper::Install(Names::Find<Node>("C3"), "/prefix",
73 "/localhost/nfd/strategy/broadcast");
74 StrategyChoiceHelper::Install(Names::Find<Node>("D3"), "/prefix",
75 "/localhost/nfd/strategy/best-route");
76
77 AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
78 consumerHelper.SetPrefix("/prefix");
79 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
80 consumerHelper.Install(Names::Find<Node>("A3"));
81
82 AppHelper producerHelper("ns3::ndn::Producer");
83 producerHelper.SetPrefix("/prefix");
84 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
85 producerHelper.Install(Names::Find<Node>("D3"));
86
87 // Add /prefix origins to ndn::GlobalRouter
88 ndnGlobalRoutingHelper.AddOrigins("/prefix", Names::Find<Node>("D3"));
89
90 // Calculate and install FIBs
91 GlobalRoutingHelper::CalculateRoutes();
92
93 // Node0 is consumer which is connected to intermediate Node1 and Node2
94
95 FaceContainer::Iterator IntermediateNode1Face1Iterator = node_faceContainer->Begin() + 2; // Node1 with strategy broadcast
96 FaceContainer::Iterator IntermediateNode1Face2Iterator = node_faceContainer->Begin() + 3;
97
98 FaceContainer::Iterator IntermediateNode2Face1Iterator = node_faceContainer->Begin() + 4; // Node2 with strategy best route
99 FaceContainer::Iterator IntermediateNode2Face2Iterator = node_faceContainer->Begin() + 5;
100
101 FaceContainer::Iterator ProducerFaceIterator1 = node_faceContainer->Begin() + 6;
102 FaceContainer::Iterator ProducerFaceIterator2 = node_faceContainer->Begin() + 7;
103
104 auto Producer_netDeviceFace1 = std::dynamic_pointer_cast<NetDeviceFace>(node_faceContainer->Get(ProducerFaceIterator1));
105 auto Producer_netDeviceFace2 = std::dynamic_pointer_cast<NetDeviceFace>(node_faceContainer->Get(ProducerFaceIterator2));
106
107 auto IntermediateNode1_netDeviceFace1 = std::dynamic_pointer_cast<NetDeviceFace>(node_faceContainer->Get(IntermediateNode1Face1Iterator));
108 auto IntermediateNode1_netDeviceFace2 = std::dynamic_pointer_cast<NetDeviceFace>(node_faceContainer->Get(IntermediateNode1Face2Iterator));
109
110 auto IntermediateNode2_netDeviceFace1 = std::dynamic_pointer_cast<NetDeviceFace>(node_faceContainer->Get(IntermediateNode2Face1Iterator));
111 auto IntermediateNode2_netDeviceFace2 = std::dynamic_pointer_cast<NetDeviceFace>(node_faceContainer->Get(IntermediateNode2Face2Iterator));
112
113 Simulator::Stop(Seconds(5.0));
114 Simulator::Run();
115
116 ::ndn::nfd::FaceStatus producerFace1Status = Producer_netDeviceFace1->getFaceStatus();
117 ::ndn::nfd::FaceStatus producerFace2Status = Producer_netDeviceFace2->getFaceStatus();
118
119 ::ndn::nfd::FaceStatus IntermediateNode1Face1Status = IntermediateNode1_netDeviceFace1->getFaceStatus();
120 ::ndn::nfd::FaceStatus IntermediateNode1Face2Status = IntermediateNode1_netDeviceFace2->getFaceStatus();
121
122 ::ndn::nfd::FaceStatus IntermediateNode2Face1Status = IntermediateNode2_netDeviceFace1->getFaceStatus();
123 ::ndn::nfd::FaceStatus IntermediateNode2Face2Status = IntermediateNode2_netDeviceFace2->getFaceStatus();
124
125 BOOST_CHECK_EQUAL(producerFace1Status.getNInInterests(), 500);
126 BOOST_CHECK_EQUAL(producerFace2Status.getNInInterests(), 0);
127 BOOST_CHECK_EQUAL(IntermediateNode1Face1Status.getNInInterests(), 500);
128 BOOST_CHECK_EQUAL(IntermediateNode1Face2Status.getNInInterests(), 0);
129 BOOST_CHECK_EQUAL(IntermediateNode2Face1Status.getNInInterests(), 0);
130 BOOST_CHECK_EQUAL(IntermediateNode2Face2Status.getNInInterests(), 0);
131}
132
133BOOST_AUTO_TEST_SUITE_END()
134
135} // namespace ndn
136} // namespace ns3