blob: 5b7d20bb6d56628585fdaaf93a02a1592e5f53e1 [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/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 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
22#include "management/nfd-fib-entry.hpp"
23
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070024#include "boost-test.hpp"
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060025
26namespace ndn {
27namespace nfd {
28
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070029BOOST_AUTO_TEST_SUITE(ManagementTestNfdFibEntry)
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060030
31const uint8_t TestNextHopRecord[] =
32{
33 0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a, 0x01, 0xc8
34};
35
36const uint8_t TestFibEntryNoNextHops[] =
37{
38 0x80, 0x15, 0x07, 0x13, 0x08, 0x04, 0x74, 0x68, 0x69, 0x73,
39 0x08, 0x02, 0x69, 0x73, 0x08, 0x01, 0x61, 0x08, 0x04, 0x74,
40 0x65, 0x73, 0x74
41};
42
43const uint8_t TestFibEntry[] =
44{
Alexander Afanasyev1c5a1a92014-03-21 13:32:36 -070045 0x80, 0x38, 0x07, 0x13, 0x08, 0x04, 0x74, 0x68, 0x69, 0x73, 0x08, 0x02, 0x69, 0x73, 0x08, 0x01,
46 0x61, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a, 0x01, 0xc8, 0x81,
47 0x07, 0x69, 0x01, 0x14, 0x6a, 0x02, 0x01, 0x2c, 0x81, 0x07, 0x69, 0x01, 0x1e, 0x6a, 0x02, 0x01,
48 0x90, 0x81, 0x07, 0x69, 0x01, 0x28, 0x6a, 0x02, 0x01, 0xf4
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060049};
50
51BOOST_AUTO_TEST_CASE(TestNextHopRecordEncode)
52{
53 NextHopRecord record;
54 record.setFaceId(10);
55 record.setCost(200);
56
57 const Block& wire = record.wireEncode();
58 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestNextHopRecord,
59 TestNextHopRecord + sizeof(TestNextHopRecord),
60 wire.begin(), wire.end());
61
62}
63
64BOOST_AUTO_TEST_CASE(TestNextHopRecordDecode)
65{
66 NextHopRecord record;
67
68 BOOST_REQUIRE_NO_THROW(record.wireDecode(Block(TestNextHopRecord,
69 sizeof(TestNextHopRecord))));
70 BOOST_REQUIRE_EQUAL(record.getFaceId(), 10);
71 BOOST_REQUIRE_EQUAL(record.getCost(), 200);
72}
73
74BOOST_AUTO_TEST_CASE(TestFibEntryNoNextHopEncode)
75{
76 FibEntry entry;
77 entry.setPrefix("/this/is/a/test");
78
79 const Block& wire = entry.wireEncode();
80 BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFibEntryNoNextHops,
81 TestFibEntryNoNextHops + sizeof(TestFibEntryNoNextHops),
82 wire.begin(), wire.end());
83}
84
85BOOST_AUTO_TEST_CASE(TestFibEntryNoNextHopsDecode)
86{
87 FibEntry entry;
88 BOOST_REQUIRE_NO_THROW(entry.wireDecode(Block(TestFibEntryNoNextHops,
89 sizeof(TestFibEntryNoNextHops))));
90
91 BOOST_REQUIRE_EQUAL(entry.getPrefix(), "/this/is/a/test");
92 BOOST_REQUIRE(entry.getNextHopRecords().empty());
93}
94
95BOOST_AUTO_TEST_CASE(TestFibEntryEncode)
96{
97 FibEntry entry;
98 entry.setPrefix("/this/is/a/test");
99
100 std::list<NextHopRecord> records;
101
102 for (int i = 1; i < 4; i++)
103 {
104 NextHopRecord record;
105 record.setFaceId(i * 10);
106 record.setCost((i * 100) + 100);
107 records.push_back(record);
108 }
109
110 entry.setNextHopRecords(records.begin(), records.end());
111
112 NextHopRecord oneMore;
113 oneMore.setFaceId(40);
114 oneMore.setCost(500);
115
116 entry.addNextHopRecord(oneMore);
117
118 const Block& wire = entry.wireEncode();
Alexander Afanasyev1c5a1a92014-03-21 13:32:36 -0700119 BOOST_CHECK_EQUAL_COLLECTIONS(TestFibEntry,
120 TestFibEntry + sizeof(TestFibEntry),
121 wire.begin(), wire.end());
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600122
123 // std::ofstream of("out.tmp");
124 // of.write((const char*)entry.wireEncode().wire(),
125 // entry.wireEncode().size());
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600126}
127
128BOOST_AUTO_TEST_CASE(TestFibEntryDecode)
129{
130 FibEntry entry;
131 BOOST_REQUIRE_NO_THROW(entry.wireDecode(Block(TestFibEntry,
132 sizeof(TestFibEntry))));
133
134 std::list<NextHopRecord> records = entry.getNextHopRecords();
135
Alexander Afanasyev1c5a1a92014-03-21 13:32:36 -0700136 BOOST_CHECK_EQUAL(entry.getPrefix(), "/this/is/a/test");
137 BOOST_CHECK_EQUAL(entry.getNextHopRecords().size(), 4);
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600138
Alexander Afanasyev1c5a1a92014-03-21 13:32:36 -0700139 size_t value = 1;
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600140
141 for (std::list<NextHopRecord>::const_iterator i = records.begin();
142 i != records.end();
143 ++i)
144 {
145 BOOST_CHECK_EQUAL(i->getFaceId(), value * 10);
146 BOOST_CHECK_EQUAL(i->getCost(), (value * 100) + 100);
Alexander Afanasyev1c5a1a92014-03-21 13:32:36 -0700147 ++value;
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600148 }
149}
150
151BOOST_AUTO_TEST_SUITE_END()
152
153} // namespace nfd
154} // namespace ndn