blob: 1c886aa3b14295172ff4ce270f1fccb5d8449a8a [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
21#include "model/ndn-net-device-face.hpp"
22#include "model/ndn-l3-protocol.hpp"
23#include "model/ndn-ns3.hpp"
24#include "NFD/daemon/face/face-counters.hpp"
25
26#include <ndn-cxx/management/nfd-face-status.hpp>
27
28#include "ns3/net-device.h"
29#include "ns3/log.h"
30#include "ns3/packet.h"
31#include "ns3/node.h"
32#include "ns3/pointer.h"
33#include "ns3/point-to-point-net-device.h"
34#include "ns3/channel.h"
35#include "ndn-face-container.hpp"
36#include "ns3/node-container.h"
37
38#include "ns3/core-module.h"
39#include "ns3/network-module.h"
40#include "ns3/point-to-point-module.h"
41#include "ns3/ndnSIM-module.h"
42
43#include "../tests-common.hpp"
44
45namespace ns3 {
46namespace ndn {
47
48BOOST_FIXTURE_TEST_SUITE(ModelNdnNetDeviceFace, CleanupFixture)
49
50BOOST_AUTO_TEST_CASE(SendInterest)
51{
52 NodeContainer nodes;
53 nodes.Create(2);
54 PointToPointHelper p2p;
55 p2p.Install(nodes.Get(0), nodes.Get(1));
56
57 StackHelper ndnHelper;
58 ndnHelper.SetDefaultRoutes(true);
59
60 Ptr<FaceContainer> node0_faceContainer = ndnHelper.InstallAll();
61
62 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
63 consumerHelper.SetPrefix("/prefix");
64 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
65 consumerHelper.Install(nodes.Get(0));
66
67 ndn::AppHelper producerHelper("ns3::ndn::Producer");
68 producerHelper.SetPrefix("/prefix");
69 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
70 producerHelper.Install(nodes.Get(1));
71
72 FaceContainer::Iterator node1Face_iterator = node0_faceContainer->Begin() + 1;
73
74 auto node1_netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(node0_faceContainer->Get(node1Face_iterator));
75
Spyridon Mastorakis16622532015-07-18 20:29:46 -070076 Simulator::Stop(Seconds(20.001));
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070077 Simulator::Run();
78
79 ::ndn::nfd::FaceStatus faceStatus = node1_netDeviceFace->getFaceStatus();
80 BOOST_CHECK_EQUAL(faceStatus.getNInInterests(), 2000);
Spyridon Mastorakis16622532015-07-18 20:29:46 -070081
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070082 Simulator::Destroy();
83}
84
85BOOST_AUTO_TEST_CASE(SendData)
86{
87
88 NodeContainer nodes;
89 nodes.Create(2);
90 PointToPointHelper p2p;
91 p2p.Install(nodes.Get(0), nodes.Get(1));
92
93
94 StackHelper ndnHelper;
95 ndnHelper.SetDefaultRoutes(true);
96
97 Ptr<FaceContainer> node0_faceContainer = ndnHelper.InstallAll();
98
99 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
100 consumerHelper.SetPrefix("/prefix");
101 consumerHelper.SetAttribute("Frequency", StringValue("10"));
102 consumerHelper.Install(nodes.Get(0));
103
104 ndn::AppHelper producerHelper("ns3::ndn::Producer");
105 producerHelper.SetPrefix("/prefix");
106 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
107 producerHelper.Install(nodes.Get(1));
108
109 FaceContainer::Iterator node0Face_iterator = node0_faceContainer->Begin();
110 FaceContainer::Iterator node1Face_iterator = node0_faceContainer->Begin() + 1;
111
112 auto node0_netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(node0_faceContainer->Get(node0Face_iterator));
113 auto node1_netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(node0_faceContainer->Get(node1Face_iterator));
114
115 auto interest = std::make_shared<ndn::Interest>("/prefix");
116 UniformVariable rand(0, std::numeric_limits<uint32_t>::max());
117 interest->setNonce(rand.GetValue());
118 interest->setInterestLifetime(ndn::time::seconds(1));
119
120 auto data = std::make_shared<ndn::Data>(interest->getName());
121 data->setFreshnessPeriod(ndn::time::milliseconds(1000));
122 data->setContent(std::make_shared< ::ndn::Buffer>(1024));
123 ndn::StackHelper::getKeyChain().sign(*data);
124
125 node1_netDeviceFace->sendData(*data);
126
127 Simulator::Stop(Seconds(20.0));
128 Simulator::Run();
129
130 ::ndn::nfd::FaceStatus node0faceStatus = node0_netDeviceFace->getFaceStatus();
131 ::ndn::nfd::FaceStatus node1faceStatus = node1_netDeviceFace->getFaceStatus();
132 BOOST_CHECK_EQUAL(node1faceStatus.getNOutDatas(), 201);
133 Simulator::Destroy();
134}
135
136BOOST_AUTO_TEST_SUITE_END()
137
138} // namespace ndn
139} // namespace ns3