blob: c33afdb0d0290389dffb50b7b4bc4dfa96789853 [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
Xuxiang Tian91018732016-08-17 16:24:47 -070021#include "model/ndn-net-device-link-service.hpp"
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070022
23#include "../tests-common.hpp"
24
25namespace ns3 {
26namespace ndn {
27
Alexander Afanasyev91971b72015-08-13 16:53:37 -070028BOOST_FIXTURE_TEST_SUITE(ModelNdnNetDeviceFace, ScenarioHelperWithCleanupFixture)
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070029
Alexander Afanasyevac541b12016-09-12 19:45:53 -070030class FixtureWithTracers : public ScenarioHelperWithCleanupFixture
31{
32public:
33 void
34 InInterests(const Interest&, const Face& face)
35 {
36 nInInterests[boost::lexical_cast<std::string>(face)] += 1;
37 }
38
39 void
40 OutInterests(const Interest&, const Face& face)
41 {
42 nOutInterests[boost::lexical_cast<std::string>(face)] += 1;
43 }
44
45 void
46 InData(const Data&, const Face& face)
47 {
48 nInData[boost::lexical_cast<std::string>(face)] += 1;
49 }
50
51 void
52 OutData(const Data&, const Face& face)
53 {
54 nOutData[boost::lexical_cast<std::string>(face)] += 1;
55 }
56
57public:
58 std::map<std::string, uint32_t> nInInterests;
59 std::map<std::string, uint32_t> nOutInterests;
60 std::map<std::string, uint32_t> nInData;
61 std::map<std::string, uint32_t> nOutData;
62
63 // TODO add NACKs
64};
65
66BOOST_FIXTURE_TEST_CASE(Basic, FixtureWithTracers)
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070067{
Alexander Afanasyev91971b72015-08-13 16:53:37 -070068 Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps"));
69 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
70 Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070071
Alexander Afanasyev91971b72015-08-13 16:53:37 -070072 createTopology({
73 {"1", "2"},
Alexander Afanasyeva9d889b2016-09-08 18:34:25 -070074 }, false);
75
76 getNetDevice("1", "2")->SetAttribute("Address", StringValue("00:00:00:ff:ff:01"));
77 getNetDevice("2", "1")->SetAttribute("Address", StringValue("00:00:00:ff:ff:02"));
78
79 getStackHelper().InstallAll();
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070080
Alexander Afanasyev91971b72015-08-13 16:53:37 -070081 addRoutes({
82 {"1", "2", "/prefix", 1},
83 });
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070084
Alexander Afanasyev91971b72015-08-13 16:53:37 -070085 addApps({
86 {"1", "ns3::ndn::ConsumerCbr",
87 {{"Prefix", "/prefix"}, {"Frequency", "10"}},
88 "0s", "9.99s"},
89 {"2", "ns3::ndn::Producer",
90 {{"Prefix", "/prefix"}, {"PayloadSize", "1024"}},
91 "0s", "100s"}
92 });
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070093
Alexander Afanasyevac541b12016-09-12 19:45:53 -070094 Config::ConnectWithoutContext("/NodeList/*/$ns3::ndn::L3Protocol/InInterests", MakeCallback(&FixtureWithTracers::InInterests, this));
95 Config::ConnectWithoutContext("/NodeList/*/$ns3::ndn::L3Protocol/OutInterests", MakeCallback(&FixtureWithTracers::OutInterests, this));
96
97 Config::ConnectWithoutContext("/NodeList/*/$ns3::ndn::L3Protocol/InData", MakeCallback(&FixtureWithTracers::InData, this));
98 Config::ConnectWithoutContext("/NodeList/*/$ns3::ndn::L3Protocol/OutData", MakeCallback(&FixtureWithTracers::OutData, this));
99
100 // TODO: implement Nack testing
101 // Config::Connect("/NodeList/*/InNacks", ...);
102 // Config::Connect("/NodeList/*/OutNacks", ...);
103
Spyridon Mastorakis16622532015-07-18 20:29:46 -0700104 Simulator::Stop(Seconds(20.001));
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700105 Simulator::Run();
106
Alexander Afanasyevac541b12016-09-12 19:45:53 -0700107 BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nInInterests, 0);
Xuxiang Tian91018732016-08-17 16:24:47 -0700108 BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nOutInterests, 100);
109 BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nInData, 100);
Alexander Afanasyevac541b12016-09-12 19:45:53 -0700110 BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nOutData, 0);
111 BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nInNacks, 0);
112 BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nOutNacks, 0);
113
114 BOOST_CHECK_EQUAL(nInInterests [boost::lexical_cast<std::string>(*getFace("1", "2"))], 0);
115 BOOST_CHECK_EQUAL(nOutInterests[boost::lexical_cast<std::string>(*getFace("1", "2"))], 100);
116 BOOST_CHECK_EQUAL(nInData [boost::lexical_cast<std::string>(*getFace("1", "2"))], 100);
117 BOOST_CHECK_EQUAL(nOutData [boost::lexical_cast<std::string>(*getFace("1", "2"))], 0);
118 // TODO add nacks
Spyridon Mastorakis16622532015-07-18 20:29:46 -0700119
Xuxiang Tian91018732016-08-17 16:24:47 -0700120 BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInInterests, 100);
Alexander Afanasyevac541b12016-09-12 19:45:53 -0700121 BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nOutInterests, 0);
122 BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInData, 0);
Xuxiang Tian91018732016-08-17 16:24:47 -0700123 BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nOutData, 100);
Alexander Afanasyevac541b12016-09-12 19:45:53 -0700124 BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInNacks, 0);
125 BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nOutNacks, 0);
126
127 BOOST_CHECK_EQUAL(nInInterests [boost::lexical_cast<std::string>(*getFace("2", "1"))], 100);
128 BOOST_CHECK_EQUAL(nOutInterests[boost::lexical_cast<std::string>(*getFace("2", "1"))], 0);
129 BOOST_CHECK_EQUAL(nInData [boost::lexical_cast<std::string>(*getFace("2", "1"))], 0);
130 BOOST_CHECK_EQUAL(nOutData [boost::lexical_cast<std::string>(*getFace("2", "1"))], 100);
131 // TODO add nacks
Alexander Afanasyeva9d889b2016-09-08 18:34:25 -0700132
133 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(*getFace("1", "2")), "netdev://[00:00:00:ff:ff:01]");
134 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(*getFace("2", "1")), "netdev://[00:00:00:ff:ff:02]");
135
136 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(getFace("1", "2")->getLocalUri()), "netdev://[00:00:00:ff:ff:01]");
137 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(getFace("1", "2")->getRemoteUri()), "netdev://[00:00:00:ff:ff:02]");
138 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(getFace("2", "1")->getLocalUri()), "netdev://[00:00:00:ff:ff:02]");
139 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(getFace("2", "1")->getRemoteUri()), "netdev://[00:00:00:ff:ff:01]");
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700140}
141
142BOOST_AUTO_TEST_SUITE_END()
143
144} // namespace ndn
145} // namespace ns3