blob: 7723974d2cd883c619bd18ecee1a3f6feb2dd5ab [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Steve DiBenedetto6d792d72014-03-15 19:01:36 -06002/**
Junxiao Shi7357ef22016-09-07 02:39:37 +00003 * Copyright (c) 2013-2016 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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 DiBenedetto6d792d72014-03-15 19:01:36 -060020 */
21
Junxiao Shi7357ef22016-09-07 02:39:37 +000022#include "mgmt/nfd/fib-entry.hpp"
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060023
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070024#include "boost-test.hpp"
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060025
26namespace ndn {
27namespace nfd {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080028namespace tests {
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060029
Junxiao Shi7357ef22016-09-07 02:39:37 +000030BOOST_AUTO_TEST_SUITE(Mgmt)
31BOOST_AUTO_TEST_SUITE(Nfd)
32BOOST_AUTO_TEST_SUITE(TestFibEntry)
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060033
34const uint8_t TestNextHopRecord[] =
35{
36 0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a, 0x01, 0xc8
37};
38
39const 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
46const uint8_t TestFibEntry[] =
47{
Alexander Afanasyev1c5a1a92014-03-21 13:32:36 -070048 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 DiBenedetto6d792d72014-03-15 19:01:36 -060052};
53
54BOOST_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
67BOOST_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
77BOOST_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
88BOOST_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
98BOOST_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 Afanasyev1c5a1a92014-03-21 13:32:36 -0700122 BOOST_CHECK_EQUAL_COLLECTIONS(TestFibEntry,
123 TestFibEntry + sizeof(TestFibEntry),
124 wire.begin(), wire.end());
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600125
126 // std::ofstream of("out.tmp");
127 // of.write((const char*)entry.wireEncode().wire(),
128 // entry.wireEncode().size());
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600129}
130
131BOOST_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 Afanasyev1c5a1a92014-03-21 13:32:36 -0700139 BOOST_CHECK_EQUAL(entry.getPrefix(), "/this/is/a/test");
140 BOOST_CHECK_EQUAL(entry.getNextHopRecords().size(), 4);
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600141
Alexander Afanasyev1c5a1a92014-03-21 13:32:36 -0700142 size_t value = 1;
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600143
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 Afanasyev1c5a1a92014-03-21 13:32:36 -0700150 ++value;
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600151 }
152}
153
Junxiao Shi7357ef22016-09-07 02:39:37 +0000154BOOST_AUTO_TEST_SUITE_END() // TestFibEntry
155BOOST_AUTO_TEST_SUITE_END() // Nfd
156BOOST_AUTO_TEST_SUITE_END() // Mgmt
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600157
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800158} // namespace tests
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600159} // namespace nfd
160} // namespace ndn