Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [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 | /** |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 8 | * |
| 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include "management/nfd-fib-entry.hpp" |
| 14 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 15 | #include "boost-test.hpp" |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 16 | |
| 17 | namespace ndn { |
| 18 | namespace nfd { |
| 19 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 20 | BOOST_AUTO_TEST_SUITE(ManagementTestNfdFibEntry) |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 21 | |
| 22 | const uint8_t TestNextHopRecord[] = |
| 23 | { |
| 24 | 0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a, 0x01, 0xc8 |
| 25 | }; |
| 26 | |
| 27 | const uint8_t TestFibEntryNoNextHops[] = |
| 28 | { |
| 29 | 0x80, 0x15, 0x07, 0x13, 0x08, 0x04, 0x74, 0x68, 0x69, 0x73, |
| 30 | 0x08, 0x02, 0x69, 0x73, 0x08, 0x01, 0x61, 0x08, 0x04, 0x74, |
| 31 | 0x65, 0x73, 0x74 |
| 32 | }; |
| 33 | |
| 34 | const uint8_t TestFibEntry[] = |
| 35 | { |
Alexander Afanasyev | 1c5a1a9 | 2014-03-21 13:32:36 -0700 | [diff] [blame] | 36 | 0x80, 0x38, 0x07, 0x13, 0x08, 0x04, 0x74, 0x68, 0x69, 0x73, 0x08, 0x02, 0x69, 0x73, 0x08, 0x01, |
| 37 | 0x61, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a, 0x01, 0xc8, 0x81, |
| 38 | 0x07, 0x69, 0x01, 0x14, 0x6a, 0x02, 0x01, 0x2c, 0x81, 0x07, 0x69, 0x01, 0x1e, 0x6a, 0x02, 0x01, |
| 39 | 0x90, 0x81, 0x07, 0x69, 0x01, 0x28, 0x6a, 0x02, 0x01, 0xf4 |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | BOOST_AUTO_TEST_CASE(TestNextHopRecordEncode) |
| 43 | { |
| 44 | NextHopRecord record; |
| 45 | record.setFaceId(10); |
| 46 | record.setCost(200); |
| 47 | |
| 48 | const Block& wire = record.wireEncode(); |
| 49 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestNextHopRecord, |
| 50 | TestNextHopRecord + sizeof(TestNextHopRecord), |
| 51 | wire.begin(), wire.end()); |
| 52 | |
| 53 | } |
| 54 | |
| 55 | BOOST_AUTO_TEST_CASE(TestNextHopRecordDecode) |
| 56 | { |
| 57 | NextHopRecord record; |
| 58 | |
| 59 | BOOST_REQUIRE_NO_THROW(record.wireDecode(Block(TestNextHopRecord, |
| 60 | sizeof(TestNextHopRecord)))); |
| 61 | BOOST_REQUIRE_EQUAL(record.getFaceId(), 10); |
| 62 | BOOST_REQUIRE_EQUAL(record.getCost(), 200); |
| 63 | } |
| 64 | |
| 65 | BOOST_AUTO_TEST_CASE(TestFibEntryNoNextHopEncode) |
| 66 | { |
| 67 | FibEntry entry; |
| 68 | entry.setPrefix("/this/is/a/test"); |
| 69 | |
| 70 | const Block& wire = entry.wireEncode(); |
| 71 | BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibEntryNoNextHops, |
| 72 | TestFibEntryNoNextHops + sizeof(TestFibEntryNoNextHops), |
| 73 | wire.begin(), wire.end()); |
| 74 | } |
| 75 | |
| 76 | BOOST_AUTO_TEST_CASE(TestFibEntryNoNextHopsDecode) |
| 77 | { |
| 78 | FibEntry entry; |
| 79 | BOOST_REQUIRE_NO_THROW(entry.wireDecode(Block(TestFibEntryNoNextHops, |
| 80 | sizeof(TestFibEntryNoNextHops)))); |
| 81 | |
| 82 | BOOST_REQUIRE_EQUAL(entry.getPrefix(), "/this/is/a/test"); |
| 83 | BOOST_REQUIRE(entry.getNextHopRecords().empty()); |
| 84 | } |
| 85 | |
| 86 | BOOST_AUTO_TEST_CASE(TestFibEntryEncode) |
| 87 | { |
| 88 | FibEntry entry; |
| 89 | entry.setPrefix("/this/is/a/test"); |
| 90 | |
| 91 | std::list<NextHopRecord> records; |
| 92 | |
| 93 | for (int i = 1; i < 4; i++) |
| 94 | { |
| 95 | NextHopRecord record; |
| 96 | record.setFaceId(i * 10); |
| 97 | record.setCost((i * 100) + 100); |
| 98 | records.push_back(record); |
| 99 | } |
| 100 | |
| 101 | entry.setNextHopRecords(records.begin(), records.end()); |
| 102 | |
| 103 | NextHopRecord oneMore; |
| 104 | oneMore.setFaceId(40); |
| 105 | oneMore.setCost(500); |
| 106 | |
| 107 | entry.addNextHopRecord(oneMore); |
| 108 | |
| 109 | const Block& wire = entry.wireEncode(); |
Alexander Afanasyev | 1c5a1a9 | 2014-03-21 13:32:36 -0700 | [diff] [blame] | 110 | BOOST_CHECK_EQUAL_COLLECTIONS(TestFibEntry, |
| 111 | TestFibEntry + sizeof(TestFibEntry), |
| 112 | wire.begin(), wire.end()); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 113 | |
| 114 | // std::ofstream of("out.tmp"); |
| 115 | // of.write((const char*)entry.wireEncode().wire(), |
| 116 | // entry.wireEncode().size()); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | BOOST_AUTO_TEST_CASE(TestFibEntryDecode) |
| 120 | { |
| 121 | FibEntry entry; |
| 122 | BOOST_REQUIRE_NO_THROW(entry.wireDecode(Block(TestFibEntry, |
| 123 | sizeof(TestFibEntry)))); |
| 124 | |
| 125 | std::list<NextHopRecord> records = entry.getNextHopRecords(); |
| 126 | |
Alexander Afanasyev | 1c5a1a9 | 2014-03-21 13:32:36 -0700 | [diff] [blame] | 127 | BOOST_CHECK_EQUAL(entry.getPrefix(), "/this/is/a/test"); |
| 128 | BOOST_CHECK_EQUAL(entry.getNextHopRecords().size(), 4); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 129 | |
Alexander Afanasyev | 1c5a1a9 | 2014-03-21 13:32:36 -0700 | [diff] [blame] | 130 | size_t value = 1; |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 131 | |
| 132 | for (std::list<NextHopRecord>::const_iterator i = records.begin(); |
| 133 | i != records.end(); |
| 134 | ++i) |
| 135 | { |
| 136 | BOOST_CHECK_EQUAL(i->getFaceId(), value * 10); |
| 137 | BOOST_CHECK_EQUAL(i->getCost(), (value * 100) + 100); |
Alexander Afanasyev | 1c5a1a9 | 2014-03-21 13:32:36 -0700 | [diff] [blame] | 138 | ++value; |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
| 142 | BOOST_AUTO_TEST_SUITE_END() |
| 143 | |
| 144 | } // namespace nfd |
| 145 | } // namespace ndn |