blob: dd191ad149f78cddc77d731e7628ffb20b11b612 [file] [log] [blame]
Steve DiBenedetto6d792d72014-03-15 19:01:36 -06001/* -*- 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 Afanasyevb1db7c62014-04-03 14:57:25 -07009#include "boost-test.hpp"
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060010
11namespace ndn {
12namespace nfd {
13
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070014BOOST_AUTO_TEST_SUITE(ManagementTestNfdFibEntry)
Steve DiBenedetto6d792d72014-03-15 19:01:36 -060015
16const uint8_t TestNextHopRecord[] =
17{
18 0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a, 0x01, 0xc8
19};
20
21const 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
28const uint8_t TestFibEntry[] =
29{
Alexander Afanasyev1c5a1a92014-03-21 13:32:36 -070030 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 DiBenedetto6d792d72014-03-15 19:01:36 -060034};
35
36BOOST_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
49BOOST_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
59BOOST_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
70BOOST_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
80BOOST_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 Afanasyev1c5a1a92014-03-21 13:32:36 -0700104 BOOST_CHECK_EQUAL_COLLECTIONS(TestFibEntry,
105 TestFibEntry + sizeof(TestFibEntry),
106 wire.begin(), wire.end());
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600107
108 // std::ofstream of("out.tmp");
109 // of.write((const char*)entry.wireEncode().wire(),
110 // entry.wireEncode().size());
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600111}
112
113BOOST_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 Afanasyev1c5a1a92014-03-21 13:32:36 -0700121 BOOST_CHECK_EQUAL(entry.getPrefix(), "/this/is/a/test");
122 BOOST_CHECK_EQUAL(entry.getNextHopRecords().size(), 4);
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600123
Alexander Afanasyev1c5a1a92014-03-21 13:32:36 -0700124 size_t value = 1;
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600125
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 Afanasyev1c5a1a92014-03-21 13:32:36 -0700132 ++value;
Steve DiBenedetto6d792d72014-03-15 19:01:36 -0600133 }
134}
135
136BOOST_AUTO_TEST_SUITE_END()
137
138} // namespace nfd
139} // namespace ndn