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