blob: 225c708ac3ce17239c2a4722cec2a12433411be8 [file] [log] [blame]
Jiewen Tan7a56d1c2015-01-26 23:26:51 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Tianxing Ma9ea36392018-10-05 14:32:55 -05003 * Copyright (c) 2014-2019, 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/coordinate-lsa.hpp"
23
Davide Pesaventocb065f12019-12-27 01:03:34 -050024#include "tests/boost-test.hpp"
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080025
26namespace nlsr {
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060027namespace tlv {
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080028namespace test {
29
30BOOST_AUTO_TEST_SUITE(TlvTestCoordinateLsa)
31
32const uint8_t CoordinateLsaData[] =
33{
34 // Header
Tianxing Ma9ea36392018-10-05 14:32:55 -050035 0x85, 0x27,
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080036 // LsaInfo
37 0x80, 0x11, 0x81, 0x08, 0x07, 0x06, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x82, 0x01,
38 0x80, 0x8b, 0x02, 0x27, 0x10,
39 // HyperbolicRadius
Tianxing Ma9ea36392018-10-05 14:32:55 -050040 0x87, 0x08, 0x3f, 0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080041 // HyperbolicAngle
Tianxing Ma9ea36392018-10-05 14:32:55 -050042 0x88, 0x08, 0x3f, 0xfc, 0x7a, 0xe1, 0x47, 0xae, 0x14, 0x7b
43
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080044};
45
46BOOST_AUTO_TEST_CASE(CoordinateLsaEncode)
47{
48 CoordinateLsa coordinateLsa;
49
50 LsaInfo lsaInfo;
51 lsaInfo.setOriginRouter("test");
52 lsaInfo.setSequenceNumber(128);
53 lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
54 coordinateLsa.setLsaInfo(lsaInfo);
55
56 coordinateLsa.setHyperbolicRadius(1.65);
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060057 std::vector<double> angles;
58 angles.push_back(1.78);
59 coordinateLsa.setHyperbolicAngle(angles);
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080060
61 const ndn::Block& wire = coordinateLsa.wireEncode();
62
63 BOOST_REQUIRE_EQUAL_COLLECTIONS(CoordinateLsaData,
64 CoordinateLsaData + sizeof(CoordinateLsaData),
65 wire.begin(), wire.end());
66}
67
68BOOST_AUTO_TEST_CASE(CoordinateLsaDecode)
69{
70 CoordinateLsa coordinateLsa;
71
72 coordinateLsa.wireDecode(ndn::Block(CoordinateLsaData, sizeof(CoordinateLsaData)));
73
74 BOOST_REQUIRE_EQUAL(coordinateLsa.getLsaInfo().getOriginRouter(), "test");
75 BOOST_REQUIRE_EQUAL(coordinateLsa.getLsaInfo().getSequenceNumber(), 128);
76 BOOST_REQUIRE_EQUAL(coordinateLsa.getLsaInfo().getExpirationPeriod(),
77 ndn::time::milliseconds(10000));
78 BOOST_REQUIRE_EQUAL(coordinateLsa.getHyperbolicRadius(), 1.65);
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060079 std::vector<double> angles = {1.78};
80 BOOST_REQUIRE(coordinateLsa.getHyperbolicAngle() == angles);
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080081}
82
83BOOST_AUTO_TEST_CASE(CoordinateLsaOutputStream)
84{
85 CoordinateLsa coordinateLsa;
86
87 LsaInfo lsaInfo;
88 lsaInfo.setOriginRouter("test");
89 lsaInfo.setSequenceNumber(128);
90 lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
91 coordinateLsa.setLsaInfo(lsaInfo);
92
93 coordinateLsa.setHyperbolicRadius(1.65);
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060094 std::vector<double> angles = {1.78};
95 coordinateLsa.setHyperbolicAngle(angles);
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080096
97 std::ostringstream os;
98 os << coordinateLsa;
99
100 BOOST_CHECK_EQUAL(os.str(), "CoordinateLsa("
101 "LsaInfo(OriginRouter: /test, "
102 "SequenceNumber: 128, "
103 "ExpirationPeriod: 10000 milliseconds), "
104 "HyperbolicRadius: 1.65, "
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600105 "HyperbolicAngles: 1.78)");
106
107 angles.push_back(3.21);
108 coordinateLsa.setHyperbolicAngle(angles);
109
110 std::ostringstream os2;
111 os2 << coordinateLsa;
112
113 BOOST_CHECK_EQUAL(os2.str(), "CoordinateLsa("
114 "LsaInfo(OriginRouter: /test, "
115 "SequenceNumber: 128, "
116 "ExpirationPeriod: 10000 milliseconds), "
117 "HyperbolicRadius: 1.65, "
118 "HyperbolicAngles: 1.78, 3.21)");
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800119}
120
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600121
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800122BOOST_AUTO_TEST_SUITE_END()
123
124} // namespace test
125} // namespace tlv
126} // namespace nlsr