blob: a179e2cbed5cabab6567f5cc69b65241222a7588 [file] [log] [blame]
Jiewen Tan7a56d1c2015-01-26 23:26:51 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonfeae5572017-01-13 12:06:26 -06003 * Copyright (c) 2014-2017, The University of Memphis,
Jiewen Tan7a56d1c2015-01-26 23:26:51 -08004 * Regents of the University of California,
5 * Arizona Board of Regents.
6 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 **/
21
22#include "tlv/lsa-info.hpp"
23
24#include "../boost-test.hpp"
25
26namespace nlsr {
Nick Gordon727d4832017-10-13 18:04:25 -050027namespace tlv {
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080028namespace test {
29
30BOOST_AUTO_TEST_SUITE(TlvTestLsaInfo)
31
32const uint8_t LsaInfoData[] =
33{
34 // Header
35 0x80, 0x21,
36 // OriginRouter
37 0x81, 0x18, 0x07, 0x16, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x03, 0x6c, 0x73,
38 0x61, 0x08, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x08, 0x03, 0x74, 0x6c, 0x76,
39 // SequenceNumber
40 0x82, 0x01, 0x80,
41 // ExpirationPeriod
42 0x8b, 0x02, 0x27, 0x10
43};
44
45const uint8_t LsaInfoDataInfiniteExpirationPeriod[] =
46{
47 // Header
48 0x80, 0x1d,
49 // OriginRouter
50 0x81, 0x18, 0x07, 0x16, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x03, 0x6c, 0x73,
51 0x61, 0x08, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x08, 0x03, 0x74, 0x6c, 0x76,
52 // SequenceNumber
53 0x82, 0x1, 0x80
54};
55
56BOOST_AUTO_TEST_CASE(LsaInfoEncode)
57{
58 LsaInfo lsaInfo;
59 lsaInfo.setOriginRouter("/test/lsa/info/tlv");
60 lsaInfo.setSequenceNumber(128);
61 lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
62
63 const ndn::Block& wire = lsaInfo.wireEncode();
64
65 BOOST_REQUIRE_EQUAL_COLLECTIONS(LsaInfoData,
66 LsaInfoData + sizeof(LsaInfoData),
67 wire.begin(), wire.end());
68}
69
70BOOST_AUTO_TEST_CASE(LsaInfoDecode)
71{
72 LsaInfo lsaInfo;
73
74 lsaInfo.wireDecode(ndn::Block(LsaInfoData, sizeof(LsaInfoData)));
75
76 ndn::Name originRouter("/test/lsa/info/tlv");
77 BOOST_REQUIRE_EQUAL(lsaInfo.getOriginRouter(), originRouter);
78 BOOST_REQUIRE_EQUAL(lsaInfo.getSequenceNumber(), 128);
79 BOOST_REQUIRE_EQUAL(lsaInfo.getExpirationPeriod(), ndn::time::milliseconds(10000));
80 BOOST_REQUIRE_EQUAL(lsaInfo.hasInfiniteExpirationPeriod(), false);
81}
82
83BOOST_AUTO_TEST_CASE(LsaInfoInfiniteExpirationPeriodEncode)
84{
85 LsaInfo lsaInfo;
86 lsaInfo.setOriginRouter("/test/lsa/info/tlv");
87 lsaInfo.setSequenceNumber(128);
88 lsaInfo.setExpirationPeriod(LsaInfo::INFINITE_EXPIRATION_PERIOD);
89
90 const ndn::Block& wire = lsaInfo.wireEncode();
91
92 BOOST_REQUIRE_EQUAL_COLLECTIONS(LsaInfoDataInfiniteExpirationPeriod,
93 LsaInfoDataInfiniteExpirationPeriod +
94 sizeof(LsaInfoDataInfiniteExpirationPeriod),
95 wire.begin(), wire.end());
96}
97
98BOOST_AUTO_TEST_CASE(LsaInfoInfiniteExpirationPeriodDecode)
99{
100 LsaInfo lsaInfo;
101
102 lsaInfo.wireDecode(ndn::Block(LsaInfoDataInfiniteExpirationPeriod,
103 sizeof(LsaInfoDataInfiniteExpirationPeriod)));
104
105 ndn::Name originRouter("/test/lsa/info/tlv");
106 BOOST_REQUIRE_EQUAL(lsaInfo.getOriginRouter(), originRouter);
107 BOOST_REQUIRE_EQUAL(lsaInfo.getSequenceNumber(), 128);
108 BOOST_REQUIRE_EQUAL(lsaInfo.getExpirationPeriod(), LsaInfo::INFINITE_EXPIRATION_PERIOD);
109 BOOST_REQUIRE_EQUAL(lsaInfo.hasInfiniteExpirationPeriod(), true);
110}
111
112BOOST_AUTO_TEST_CASE(LsaInfoOutputStream)
113{
114 LsaInfo lsaInfo;
115 lsaInfo.setOriginRouter("/test/lsa/info/tlv");
116 lsaInfo.setSequenceNumber(128);
117 lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
118
119 std::ostringstream os;
120 os << lsaInfo;
121
122 BOOST_CHECK_EQUAL(os.str(), "LsaInfo(OriginRouter: /test/lsa/info/tlv, SequenceNumber: 128, "
123 "ExpirationPeriod: 10000 milliseconds)");
124}
125
Jiewen Tana0497d82015-02-02 21:59:18 -0800126BOOST_AUTO_TEST_CASE(LsaInfoMake)
127{
Nick Gordon727d4832017-10-13 18:04:25 -0500128 Lsa lsa;
Jiewen Tana0497d82015-02-02 21:59:18 -0800129 lsa.setOrigRouter("/test/lsa/info/tlv");
130 lsa.setLsSeqNo(128);
131 lsa.setExpirationTimePoint(ndn::time::system_clock::now());
132
133 std::shared_ptr<LsaInfo> lsaInfo = makeLsaInfo(lsa);
134 BOOST_CHECK_EQUAL(lsaInfo->getOriginRouter(), lsa.getOrigRouter());
135 BOOST_CHECK_EQUAL(lsaInfo->getSequenceNumber(), lsa.getLsSeqNo());
136 BOOST_CHECK_LE(lsaInfo->getExpirationPeriod(), ndn::time::milliseconds(0));
137}
138
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800139BOOST_AUTO_TEST_SUITE_END()
140
141} // namespace test
142} // namespace tlv
143} // namespace nlsr