blob: 23a640619d74dba7bf5276a23e7480e168fc7648 [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
76 Simulator::Stop(Seconds(20.0));
77 Simulator::Run();
78
79 ::ndn::nfd::FaceStatus faceStatus = node1_netDeviceFace->getFaceStatus();
80 BOOST_CHECK_EQUAL(faceStatus.getNInInterests(), 2000);
81 Simulator::Destroy();
82}
83
84BOOST_AUTO_TEST_CASE(SendData)
85{
86
87 NodeContainer nodes;
88 nodes.Create(2);
89 PointToPointHelper p2p;
90 p2p.Install(nodes.Get(0), nodes.Get(1));
91
92
93 StackHelper ndnHelper;
94 ndnHelper.SetDefaultRoutes(true);
95
96 Ptr<FaceContainer> node0_faceContainer = ndnHelper.InstallAll();
97
98 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
99 consumerHelper.SetPrefix("/prefix");
100 consumerHelper.SetAttribute("Frequency", StringValue("10"));
101 consumerHelper.Install(nodes.Get(0));
102
103 ndn::AppHelper producerHelper("ns3::ndn::Producer");
104 producerHelper.SetPrefix("/prefix");
105 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
106 producerHelper.Install(nodes.Get(1));
107
108 FaceContainer::Iterator node0Face_iterator = node0_faceContainer->Begin();
109 FaceContainer::Iterator node1Face_iterator = node0_faceContainer->Begin() + 1;
110
111 auto node0_netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(node0_faceContainer->Get(node0Face_iterator));
112 auto node1_netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(node0_faceContainer->Get(node1Face_iterator));
113
114 auto interest = std::make_shared<ndn::Interest>("/prefix");
115 UniformVariable rand(0, std::numeric_limits<uint32_t>::max());
116 interest->setNonce(rand.GetValue());
117 interest->setInterestLifetime(ndn::time::seconds(1));
118
119 auto data = std::make_shared<ndn::Data>(interest->getName());
120 data->setFreshnessPeriod(ndn::time::milliseconds(1000));
121 data->setContent(std::make_shared< ::ndn::Buffer>(1024));
122 ndn::StackHelper::getKeyChain().sign(*data);
123
124 node1_netDeviceFace->sendData(*data);
125
126 Simulator::Stop(Seconds(20.0));
127 Simulator::Run();
128
129 ::ndn::nfd::FaceStatus node0faceStatus = node0_netDeviceFace->getFaceStatus();
130 ::ndn::nfd::FaceStatus node1faceStatus = node1_netDeviceFace->getFaceStatus();
131 BOOST_CHECK_EQUAL(node1faceStatus.getNOutDatas(), 201);
132 Simulator::Destroy();
133}
134
135BOOST_AUTO_TEST_SUITE_END()
136
137} // namespace ndn
138} // namespace ns3