blob: 6d4ab1a34180ad331791713dbbb339ee748bf0ed [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-fib-helper.hpp"
21#include "model/ndn-net-device-face.hpp"
22
23#include "ns3/node-container.h"
24#include "ns3/point-to-point-net-device.h"
25#include "ns3/node.h"
26#include "ns3/core-module.h"
27#include "ns3/network-module.h"
28#include "ns3/point-to-point-module.h"
29#include "ns3/ndnSIM-module.h"
30
31#include "../tests-common.hpp"
32
33namespace ns3 {
34namespace ndn {
35
36BOOST_FIXTURE_TEST_SUITE(HelperNdnFibHelper, CleanupFixture)
37
38BOOST_AUTO_TEST_CASE(AddRoute)
39{
40 NodeContainer nodes;
41 nodes.Create(2);
42
43 PointToPointHelper p2p;
44 p2p.Install(nodes.Get(0), nodes.Get(1));
45
46 StackHelper ndnHelper;
47 Ptr<FaceContainer> node0_faceContainer = ndnHelper.InstallAll();
48
49 ndn::FibHelper::AddRoute(nodes.Get(0), "/prefix/1", nodes.Get(1), 1);
50 // Installing applications
51 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
52 consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
53
54 ndn::AppHelper producerHelper("ns3::ndn::Producer");
55 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
56
57 consumerHelper.SetPrefix("/prefix/1");
58 consumerHelper.Install(nodes.Get(0));
59
60 producerHelper.SetPrefix("/prefix/1");
61 producerHelper.Install(nodes.Get(1));
62
63 FaceContainer::Iterator node1Face_iterator = node0_faceContainer->Begin() + 1;
64
65 auto node1_netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(node0_faceContainer->Get(node1Face_iterator));
66
67 Simulator::Stop(Seconds(20.0));
68 Simulator::Run();
69
70 ::ndn::nfd::FaceStatus faceStatus = node1_netDeviceFace->getFaceStatus();
71 BOOST_CHECK_EQUAL(faceStatus.getNInInterests(), 200);
72}
73
74BOOST_AUTO_TEST_SUITE_END()
75
76} // namespace ndn
77} // namespace ns3