Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 1 | /* -*- 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 Tian | 9101873 | 2016-08-17 16:24:47 -0700 | [diff] [blame] | 21 | #include "model/ndn-net-device-link-service.hpp" |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 22 | |
| 23 | #include "../tests-common.hpp" |
| 24 | |
| 25 | namespace ns3 { |
| 26 | namespace ndn { |
| 27 | |
Alexander Afanasyev | 91971b7 | 2015-08-13 16:53:37 -0700 | [diff] [blame] | 28 | BOOST_FIXTURE_TEST_SUITE(ModelNdnNetDeviceFace, ScenarioHelperWithCleanupFixture) |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | ac541b1 | 2016-09-12 19:45:53 -0700 | [diff] [blame] | 30 | class FixtureWithTracers : public ScenarioHelperWithCleanupFixture |
| 31 | { |
| 32 | public: |
| 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 | |
| 57 | public: |
| 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 | |
| 66 | BOOST_FIXTURE_TEST_CASE(Basic, FixtureWithTracers) |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 67 | { |
Alexander Afanasyev | 91971b7 | 2015-08-13 16:53:37 -0700 | [diff] [blame] | 68 | Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps")); |
| 69 | Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); |
| 70 | Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20")); |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 71 | |
Alexander Afanasyev | 91971b7 | 2015-08-13 16:53:37 -0700 | [diff] [blame] | 72 | createTopology({ |
| 73 | {"1", "2"}, |
Alexander Afanasyev | a9d889b | 2016-09-08 18:34:25 -0700 | [diff] [blame] | 74 | }, 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 Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 80 | |
Alexander Afanasyev | 91971b7 | 2015-08-13 16:53:37 -0700 | [diff] [blame] | 81 | addRoutes({ |
| 82 | {"1", "2", "/prefix", 1}, |
| 83 | }); |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 84 | |
Alexander Afanasyev | 91971b7 | 2015-08-13 16:53:37 -0700 | [diff] [blame] | 85 | 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 Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 93 | |
Alexander Afanasyev | ac541b1 | 2016-09-12 19:45:53 -0700 | [diff] [blame] | 94 | 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 Mastorakis | 1662253 | 2015-07-18 20:29:46 -0700 | [diff] [blame] | 104 | Simulator::Stop(Seconds(20.001)); |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 105 | Simulator::Run(); |
| 106 | |
Alexander Afanasyev | ac541b1 | 2016-09-12 19:45:53 -0700 | [diff] [blame] | 107 | BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nInInterests, 0); |
Xuxiang Tian | 9101873 | 2016-08-17 16:24:47 -0700 | [diff] [blame] | 108 | BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nOutInterests, 100); |
| 109 | BOOST_CHECK_EQUAL(getFace("1", "2")->getCounters().nInData, 100); |
Alexander Afanasyev | ac541b1 | 2016-09-12 19:45:53 -0700 | [diff] [blame] | 110 | 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 Mastorakis | 1662253 | 2015-07-18 20:29:46 -0700 | [diff] [blame] | 119 | |
Xuxiang Tian | 9101873 | 2016-08-17 16:24:47 -0700 | [diff] [blame] | 120 | BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInInterests, 100); |
Alexander Afanasyev | ac541b1 | 2016-09-12 19:45:53 -0700 | [diff] [blame] | 121 | BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nOutInterests, 0); |
| 122 | BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nInData, 0); |
Xuxiang Tian | 9101873 | 2016-08-17 16:24:47 -0700 | [diff] [blame] | 123 | BOOST_CHECK_EQUAL(getFace("2", "1")->getCounters().nOutData, 100); |
Alexander Afanasyev | ac541b1 | 2016-09-12 19:45:53 -0700 | [diff] [blame] | 124 | 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 Afanasyev | a9d889b | 2016-09-08 18:34:25 -0700 | [diff] [blame] | 132 | |
| 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 Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | BOOST_AUTO_TEST_SUITE_END() |
| 143 | |
| 144 | } // namespace ndn |
| 145 | } // namespace ns3 |