Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 2 | /** |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 20 | */ |
| 21 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 22 | #include "mgmt/nfd/fib-entry.hpp" |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 23 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 24 | #include "boost-test.hpp" |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace nfd { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 28 | namespace tests { |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 29 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 30 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 31 | BOOST_AUTO_TEST_SUITE(Nfd) |
| 32 | BOOST_AUTO_TEST_SUITE(TestFibEntry) |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 33 | |
| 34 | const uint8_t TestNextHopRecord[] = |
| 35 | { |
| 36 | 0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a, 0x01, 0xc8 |
| 37 | }; |
| 38 | |
| 39 | const uint8_t TestFibEntryNoNextHops[] = |
| 40 | { |
| 41 | 0x80, 0x15, 0x07, 0x13, 0x08, 0x04, 0x74, 0x68, 0x69, 0x73, |
| 42 | 0x08, 0x02, 0x69, 0x73, 0x08, 0x01, 0x61, 0x08, 0x04, 0x74, |
| 43 | 0x65, 0x73, 0x74 |
| 44 | }; |
| 45 | |
| 46 | const uint8_t TestFibEntry[] = |
| 47 | { |
Alexander Afanasyev | 1c5a1a9 | 2014-03-21 13:32:36 -0700 | [diff] [blame] | 48 | 0x80, 0x38, 0x07, 0x13, 0x08, 0x04, 0x74, 0x68, 0x69, 0x73, 0x08, 0x02, 0x69, 0x73, 0x08, 0x01, |
| 49 | 0x61, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a, 0x01, 0xc8, 0x81, |
| 50 | 0x07, 0x69, 0x01, 0x14, 0x6a, 0x02, 0x01, 0x2c, 0x81, 0x07, 0x69, 0x01, 0x1e, 0x6a, 0x02, 0x01, |
| 51 | 0x90, 0x81, 0x07, 0x69, 0x01, 0x28, 0x6a, 0x02, 0x01, 0xf4 |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | BOOST_AUTO_TEST_CASE(TestNextHopRecordEncode) |
| 55 | { |
| 56 | NextHopRecord record; |
| 57 | record.setFaceId(10); |
| 58 | record.setCost(200); |
| 59 | |
| 60 | const Block& wire = record.wireEncode(); |
| 61 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestNextHopRecord, |
| 62 | TestNextHopRecord + sizeof(TestNextHopRecord), |
| 63 | wire.begin(), wire.end()); |
| 64 | |
| 65 | } |
| 66 | |
| 67 | BOOST_AUTO_TEST_CASE(TestNextHopRecordDecode) |
| 68 | { |
| 69 | NextHopRecord record; |
| 70 | |
| 71 | BOOST_REQUIRE_NO_THROW(record.wireDecode(Block(TestNextHopRecord, |
| 72 | sizeof(TestNextHopRecord)))); |
| 73 | BOOST_REQUIRE_EQUAL(record.getFaceId(), 10); |
| 74 | BOOST_REQUIRE_EQUAL(record.getCost(), 200); |
| 75 | } |
| 76 | |
| 77 | BOOST_AUTO_TEST_CASE(TestFibEntryNoNextHopEncode) |
| 78 | { |
| 79 | FibEntry entry; |
| 80 | entry.setPrefix("/this/is/a/test"); |
| 81 | |
| 82 | const Block& wire = entry.wireEncode(); |
| 83 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibEntryNoNextHops, |
| 84 | TestFibEntryNoNextHops + sizeof(TestFibEntryNoNextHops), |
| 85 | wire.begin(), wire.end()); |
| 86 | } |
| 87 | |
| 88 | BOOST_AUTO_TEST_CASE(TestFibEntryNoNextHopsDecode) |
| 89 | { |
| 90 | FibEntry entry; |
| 91 | BOOST_REQUIRE_NO_THROW(entry.wireDecode(Block(TestFibEntryNoNextHops, |
| 92 | sizeof(TestFibEntryNoNextHops)))); |
| 93 | |
| 94 | BOOST_REQUIRE_EQUAL(entry.getPrefix(), "/this/is/a/test"); |
| 95 | BOOST_REQUIRE(entry.getNextHopRecords().empty()); |
| 96 | } |
| 97 | |
| 98 | BOOST_AUTO_TEST_CASE(TestFibEntryEncode) |
| 99 | { |
| 100 | FibEntry entry; |
| 101 | entry.setPrefix("/this/is/a/test"); |
| 102 | |
| 103 | std::list<NextHopRecord> records; |
| 104 | |
| 105 | for (int i = 1; i < 4; i++) |
| 106 | { |
| 107 | NextHopRecord record; |
| 108 | record.setFaceId(i * 10); |
| 109 | record.setCost((i * 100) + 100); |
| 110 | records.push_back(record); |
| 111 | } |
| 112 | |
| 113 | entry.setNextHopRecords(records.begin(), records.end()); |
| 114 | |
| 115 | NextHopRecord oneMore; |
| 116 | oneMore.setFaceId(40); |
| 117 | oneMore.setCost(500); |
| 118 | |
| 119 | entry.addNextHopRecord(oneMore); |
| 120 | |
| 121 | const Block& wire = entry.wireEncode(); |
Alexander Afanasyev | 1c5a1a9 | 2014-03-21 13:32:36 -0700 | [diff] [blame] | 122 | BOOST_CHECK_EQUAL_COLLECTIONS(TestFibEntry, |
| 123 | TestFibEntry + sizeof(TestFibEntry), |
| 124 | wire.begin(), wire.end()); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 125 | |
| 126 | // std::ofstream of("out.tmp"); |
| 127 | // of.write((const char*)entry.wireEncode().wire(), |
| 128 | // entry.wireEncode().size()); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | BOOST_AUTO_TEST_CASE(TestFibEntryDecode) |
| 132 | { |
| 133 | FibEntry entry; |
| 134 | BOOST_REQUIRE_NO_THROW(entry.wireDecode(Block(TestFibEntry, |
| 135 | sizeof(TestFibEntry)))); |
| 136 | |
| 137 | std::list<NextHopRecord> records = entry.getNextHopRecords(); |
| 138 | |
Alexander Afanasyev | 1c5a1a9 | 2014-03-21 13:32:36 -0700 | [diff] [blame] | 139 | BOOST_CHECK_EQUAL(entry.getPrefix(), "/this/is/a/test"); |
| 140 | BOOST_CHECK_EQUAL(entry.getNextHopRecords().size(), 4); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 141 | |
Alexander Afanasyev | 1c5a1a9 | 2014-03-21 13:32:36 -0700 | [diff] [blame] | 142 | size_t value = 1; |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 143 | |
| 144 | for (std::list<NextHopRecord>::const_iterator i = records.begin(); |
| 145 | i != records.end(); |
| 146 | ++i) |
| 147 | { |
| 148 | BOOST_CHECK_EQUAL(i->getFaceId(), value * 10); |
| 149 | BOOST_CHECK_EQUAL(i->getCost(), (value * 100) + 100); |
Alexander Afanasyev | 1c5a1a9 | 2014-03-21 13:32:36 -0700 | [diff] [blame] | 150 | ++value; |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 154 | BOOST_AUTO_TEST_SUITE_END() // TestFibEntry |
| 155 | BOOST_AUTO_TEST_SUITE_END() // Nfd |
| 156 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 157 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 158 | } // namespace tests |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 159 | } // namespace nfd |
| 160 | } // namespace ndn |