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 | /** |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2013-2015 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 | |
| 22 | #include "management/nfd-fib-entry.hpp" |
| 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 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame^] | 30 | BOOST_AUTO_TEST_SUITE(ManagementNfdFibEntry) |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 31 | |
| 32 | const uint8_t TestNextHopRecord[] = |
| 33 | { |
| 34 | 0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a, 0x01, 0xc8 |
| 35 | }; |
| 36 | |
| 37 | const uint8_t TestFibEntryNoNextHops[] = |
| 38 | { |
| 39 | 0x80, 0x15, 0x07, 0x13, 0x08, 0x04, 0x74, 0x68, 0x69, 0x73, |
| 40 | 0x08, 0x02, 0x69, 0x73, 0x08, 0x01, 0x61, 0x08, 0x04, 0x74, |
| 41 | 0x65, 0x73, 0x74 |
| 42 | }; |
| 43 | |
| 44 | const uint8_t TestFibEntry[] = |
| 45 | { |
Alexander Afanasyev | 1c5a1a9 | 2014-03-21 13:32:36 -0700 | [diff] [blame] | 46 | 0x80, 0x38, 0x07, 0x13, 0x08, 0x04, 0x74, 0x68, 0x69, 0x73, 0x08, 0x02, 0x69, 0x73, 0x08, 0x01, |
| 47 | 0x61, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a, 0x01, 0xc8, 0x81, |
| 48 | 0x07, 0x69, 0x01, 0x14, 0x6a, 0x02, 0x01, 0x2c, 0x81, 0x07, 0x69, 0x01, 0x1e, 0x6a, 0x02, 0x01, |
| 49 | 0x90, 0x81, 0x07, 0x69, 0x01, 0x28, 0x6a, 0x02, 0x01, 0xf4 |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | BOOST_AUTO_TEST_CASE(TestNextHopRecordEncode) |
| 53 | { |
| 54 | NextHopRecord record; |
| 55 | record.setFaceId(10); |
| 56 | record.setCost(200); |
| 57 | |
| 58 | const Block& wire = record.wireEncode(); |
| 59 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestNextHopRecord, |
| 60 | TestNextHopRecord + sizeof(TestNextHopRecord), |
| 61 | wire.begin(), wire.end()); |
| 62 | |
| 63 | } |
| 64 | |
| 65 | BOOST_AUTO_TEST_CASE(TestNextHopRecordDecode) |
| 66 | { |
| 67 | NextHopRecord record; |
| 68 | |
| 69 | BOOST_REQUIRE_NO_THROW(record.wireDecode(Block(TestNextHopRecord, |
| 70 | sizeof(TestNextHopRecord)))); |
| 71 | BOOST_REQUIRE_EQUAL(record.getFaceId(), 10); |
| 72 | BOOST_REQUIRE_EQUAL(record.getCost(), 200); |
| 73 | } |
| 74 | |
| 75 | BOOST_AUTO_TEST_CASE(TestFibEntryNoNextHopEncode) |
| 76 | { |
| 77 | FibEntry entry; |
| 78 | entry.setPrefix("/this/is/a/test"); |
| 79 | |
| 80 | const Block& wire = entry.wireEncode(); |
| 81 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibEntryNoNextHops, |
| 82 | TestFibEntryNoNextHops + sizeof(TestFibEntryNoNextHops), |
| 83 | wire.begin(), wire.end()); |
| 84 | } |
| 85 | |
| 86 | BOOST_AUTO_TEST_CASE(TestFibEntryNoNextHopsDecode) |
| 87 | { |
| 88 | FibEntry entry; |
| 89 | BOOST_REQUIRE_NO_THROW(entry.wireDecode(Block(TestFibEntryNoNextHops, |
| 90 | sizeof(TestFibEntryNoNextHops)))); |
| 91 | |
| 92 | BOOST_REQUIRE_EQUAL(entry.getPrefix(), "/this/is/a/test"); |
| 93 | BOOST_REQUIRE(entry.getNextHopRecords().empty()); |
| 94 | } |
| 95 | |
| 96 | BOOST_AUTO_TEST_CASE(TestFibEntryEncode) |
| 97 | { |
| 98 | FibEntry entry; |
| 99 | entry.setPrefix("/this/is/a/test"); |
| 100 | |
| 101 | std::list<NextHopRecord> records; |
| 102 | |
| 103 | for (int i = 1; i < 4; i++) |
| 104 | { |
| 105 | NextHopRecord record; |
| 106 | record.setFaceId(i * 10); |
| 107 | record.setCost((i * 100) + 100); |
| 108 | records.push_back(record); |
| 109 | } |
| 110 | |
| 111 | entry.setNextHopRecords(records.begin(), records.end()); |
| 112 | |
| 113 | NextHopRecord oneMore; |
| 114 | oneMore.setFaceId(40); |
| 115 | oneMore.setCost(500); |
| 116 | |
| 117 | entry.addNextHopRecord(oneMore); |
| 118 | |
| 119 | const Block& wire = entry.wireEncode(); |
Alexander Afanasyev | 1c5a1a9 | 2014-03-21 13:32:36 -0700 | [diff] [blame] | 120 | BOOST_CHECK_EQUAL_COLLECTIONS(TestFibEntry, |
| 121 | TestFibEntry + sizeof(TestFibEntry), |
| 122 | wire.begin(), wire.end()); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 123 | |
| 124 | // std::ofstream of("out.tmp"); |
| 125 | // of.write((const char*)entry.wireEncode().wire(), |
| 126 | // entry.wireEncode().size()); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | BOOST_AUTO_TEST_CASE(TestFibEntryDecode) |
| 130 | { |
| 131 | FibEntry entry; |
| 132 | BOOST_REQUIRE_NO_THROW(entry.wireDecode(Block(TestFibEntry, |
| 133 | sizeof(TestFibEntry)))); |
| 134 | |
| 135 | std::list<NextHopRecord> records = entry.getNextHopRecords(); |
| 136 | |
Alexander Afanasyev | 1c5a1a9 | 2014-03-21 13:32:36 -0700 | [diff] [blame] | 137 | BOOST_CHECK_EQUAL(entry.getPrefix(), "/this/is/a/test"); |
| 138 | BOOST_CHECK_EQUAL(entry.getNextHopRecords().size(), 4); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 139 | |
Alexander Afanasyev | 1c5a1a9 | 2014-03-21 13:32:36 -0700 | [diff] [blame] | 140 | size_t value = 1; |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 141 | |
| 142 | for (std::list<NextHopRecord>::const_iterator i = records.begin(); |
| 143 | i != records.end(); |
| 144 | ++i) |
| 145 | { |
| 146 | BOOST_CHECK_EQUAL(i->getFaceId(), value * 10); |
| 147 | BOOST_CHECK_EQUAL(i->getCost(), (value * 100) + 100); |
Alexander Afanasyev | 1c5a1a9 | 2014-03-21 13:32:36 -0700 | [diff] [blame] | 148 | ++value; |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
| 152 | BOOST_AUTO_TEST_SUITE_END() |
| 153 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame^] | 154 | } // namespace tests |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 155 | } // namespace nfd |
| 156 | } // namespace ndn |