blob: 31ac2f20ad091d357e99f837e45c25450a8e0c1e [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-link-control-helper.hpp"
21#include "model/ndn-l3-protocol.hpp"
22#include "model/ndn-net-device-face.hpp"
23#include "model/ndn-app-face.hpp"
24#include "NFD/daemon/fw/forwarder.hpp"
25
26#include <ndn-cxx/management/nfd-face-status.hpp>
27
28#include "ns3/assert.h"
29#include "ns3/names.h"
30#include "ns3/point-to-point-net-device.h"
31#include "ns3/point-to-point-channel.h"
32#include "ns3/channel.h"
33#include "ns3/log.h"
34#include "ns3/error-model.h"
35#include "ns3/string.h"
36#include "ns3/boolean.h"
37#include "ns3/double.h"
38#include "ns3/pointer.h"
39
40#include "ns3/core-module.h"
41#include "ns3/network-module.h"
42#include "ns3/point-to-point-module.h"
43#include "ns3/ndnSIM-module.h"
44
45#include "../tests-common.hpp"
46
47namespace ns3 {
48namespace ndn {
49
50BOOST_FIXTURE_TEST_SUITE(HelperNdnLinkControlHelper, CleanupFixture)
51
52BOOST_AUTO_TEST_CASE(FailLink)
53{
54 NodeContainer nodes;
55 nodes.Create(2);
56
57 PointToPointHelper p2p;
58 p2p.Install(nodes.Get(0), nodes.Get(1));
59
60 StackHelper ndnHelper;
61 ndnHelper.SetDefaultRoutes(true);
62
63 Ptr<FaceContainer> node0_faceContainer = ndnHelper.InstallAll();
64
65 AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
66
67 consumerHelper.SetPrefix("/prefix");
68 consumerHelper.SetAttribute("Frequency", StringValue("1"));
69 ApplicationContainer consumerAppContainer = consumerHelper.Install(nodes.Get(0));
70
71 AppHelper producerHelper("ns3::ndn::Producer");
72
73 producerHelper.SetPrefix("/prefix");
74 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
75 ApplicationContainer producerAppContainer = producerHelper.Install(nodes.Get(1));
76
77 FaceContainer::Iterator node2Face_it = node0_faceContainer->Begin() + 1;
78
79 auto node1_netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(node0_faceContainer->Get(node2Face_it));
80
81 Simulator::Schedule(Seconds(0.0), ndn::LinkControlHelper::FailLink, nodes.Get(0), nodes.Get(1));
82 Simulator::Schedule(Seconds(5.0), ndn::LinkControlHelper::UpLink, nodes.Get(0), nodes.Get(1));
83 Simulator::Stop(Seconds(10.0));
84
85 Simulator::Run();
86
87 ::ndn::nfd::FaceStatus faceStatus = node1_netDeviceFace->getFaceStatus();
88 BOOST_CHECK_EQUAL(faceStatus.getNInInterests(), 5);
89}
90
91BOOST_AUTO_TEST_SUITE_END()
92
93} // namespace ndn
94} // namespace ns3