blob: 76d4a6b02453507d997f36c2a3ed0bc3a2a18454 [file] [log] [blame]
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Steve DiBenedetto6d792d72014-03-15 19:01:36 -06002/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * 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 DiBenedetto6d792d72014-03-15 19:01:36 -060011 */
12
13#include "management/nfd-fib-entry.hpp"
14
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070015#include "boost-test.hpp"
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060016
17namespace ndn {
18namespace nfd {
19
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070020BOOST_AUTO_TEST_SUITE(ManagementTestNfdFibEntry)
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060021
22const uint8_t TestNextHopRecord[] =
23{
24 0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a, 0x01, 0xc8
25};
26
27const 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
34const uint8_t TestFibEntry[] =
35{
Alexander Afanasyev1c5a1a92014-03-21 13:32:36 -070036 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 DiBenedetto6d792d72014-03-15 19:01:36 -060040};
41
42BOOST_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
55BOOST_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
65BOOST_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
76BOOST_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
86BOOST_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 Afanasyev1c5a1a92014-03-21 13:32:36 -0700110 BOOST_CHECK_EQUAL_COLLECTIONS(TestFibEntry,
111 TestFibEntry + sizeof(TestFibEntry),
112 wire.begin(), wire.end());
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600113
114 // std::ofstream of("out.tmp");
115 // of.write((const char*)entry.wireEncode().wire(),
116 // entry.wireEncode().size());
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600117}
118
119BOOST_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 Afanasyev1c5a1a92014-03-21 13:32:36 -0700127 BOOST_CHECK_EQUAL(entry.getPrefix(), "/this/is/a/test");
128 BOOST_CHECK_EQUAL(entry.getNextHopRecords().size(), 4);
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600129
Alexander Afanasyev1c5a1a92014-03-21 13:32:36 -0700130 size_t value = 1;
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600131
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 Afanasyev1c5a1a92014-03-21 13:32:36 -0700138 ++value;
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600139 }
140}
141
142BOOST_AUTO_TEST_SUITE_END()
143
144} // namespace nfd
145} // namespace ndn