blob: 05459f316343a3437c41e177278fa7ebc0a70949 [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/**
Spyridon Mastorakis429634f2015-02-19 17:35:33 -08003 * Copyright (c) 2013-2015 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 {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080028namespace tests {
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060029
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080030BOOST_AUTO_TEST_SUITE(ManagementNfdFibEntry)
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060031
32const uint8_t TestNextHopRecord[] =
33{
34 0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a, 0x01, 0xc8
35};
36
37const 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
44const uint8_t TestFibEntry[] =
45{
Alexander Afanasyev1c5a1a92014-03-21 13:32:36 -070046 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 DiBenedetto6d792d72014-03-15 19:01:36 -060050};
51
52BOOST_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
65BOOST_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
75BOOST_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
86BOOST_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
96BOOST_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 Afanasyev1c5a1a92014-03-21 13:32:36 -0700120 BOOST_CHECK_EQUAL_COLLECTIONS(TestFibEntry,
121 TestFibEntry + sizeof(TestFibEntry),
122 wire.begin(), wire.end());
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600123
124 // std::ofstream of("out.tmp");
125 // of.write((const char*)entry.wireEncode().wire(),
126 // entry.wireEncode().size());
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600127}
128
129BOOST_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 Afanasyev1c5a1a92014-03-21 13:32:36 -0700137 BOOST_CHECK_EQUAL(entry.getPrefix(), "/this/is/a/test");
138 BOOST_CHECK_EQUAL(entry.getNextHopRecords().size(), 4);
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600139
Alexander Afanasyev1c5a1a92014-03-21 13:32:36 -0700140 size_t value = 1;
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600141
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 Afanasyev1c5a1a92014-03-21 13:32:36 -0700148 ++value;
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600149 }
150}
151
152BOOST_AUTO_TEST_SUITE_END()
153
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800154} // namespace tests
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600155} // namespace nfd
156} // namespace ndn