blob: fa05d954d3e3ce096c74f184b77afc2aa90e6fb8 [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/coordinate-lsa.hpp"
23
24#include "../boost-test.hpp"
25
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
35 0x85, 0x2b,
36 // LsaInfo
37 0x80, 0x11, 0x81, 0x08, 0x07, 0x06, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x82, 0x01,
38 0x80, 0x8b, 0x02, 0x27, 0x10,
39 // HyperbolicRadius
40 0x87, 0x0a, 0x86, 0x08, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0xfa, 0x3f,
41 // HyperbolicAngle
42 0x88, 0x0a, 0x86, 0x08, 0x7b, 0x14, 0xae, 0x47, 0xe1, 0x7a, 0xfc, 0x3f
43};
44
45BOOST_AUTO_TEST_CASE(CoordinateLsaEncode)
46{
47 CoordinateLsa coordinateLsa;
48
49 LsaInfo lsaInfo;
50 lsaInfo.setOriginRouter("test");
51 lsaInfo.setSequenceNumber(128);
52 lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
53 coordinateLsa.setLsaInfo(lsaInfo);
54
55 coordinateLsa.setHyperbolicRadius(1.65);
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060056 std::vector<double> angles;
57 angles.push_back(1.78);
58 coordinateLsa.setHyperbolicAngle(angles);
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080059
60 const ndn::Block& wire = coordinateLsa.wireEncode();
61
62 BOOST_REQUIRE_EQUAL_COLLECTIONS(CoordinateLsaData,
63 CoordinateLsaData + sizeof(CoordinateLsaData),
64 wire.begin(), wire.end());
65}
66
67BOOST_AUTO_TEST_CASE(CoordinateLsaDecode)
68{
69 CoordinateLsa coordinateLsa;
70
71 coordinateLsa.wireDecode(ndn::Block(CoordinateLsaData, sizeof(CoordinateLsaData)));
72
73 BOOST_REQUIRE_EQUAL(coordinateLsa.getLsaInfo().getOriginRouter(), "test");
74 BOOST_REQUIRE_EQUAL(coordinateLsa.getLsaInfo().getSequenceNumber(), 128);
75 BOOST_REQUIRE_EQUAL(coordinateLsa.getLsaInfo().getExpirationPeriod(),
76 ndn::time::milliseconds(10000));
77 BOOST_REQUIRE_EQUAL(coordinateLsa.getHyperbolicRadius(), 1.65);
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060078 std::vector<double> angles = {1.78};
79 BOOST_REQUIRE(coordinateLsa.getHyperbolicAngle() == angles);
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080080}
81
82BOOST_AUTO_TEST_CASE(CoordinateLsaOutputStream)
83{
84 CoordinateLsa coordinateLsa;
85
86 LsaInfo lsaInfo;
87 lsaInfo.setOriginRouter("test");
88 lsaInfo.setSequenceNumber(128);
89 lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
90 coordinateLsa.setLsaInfo(lsaInfo);
91
92 coordinateLsa.setHyperbolicRadius(1.65);
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060093 std::vector<double> angles = {1.78};
94 coordinateLsa.setHyperbolicAngle(angles);
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080095
96 std::ostringstream os;
97 os << coordinateLsa;
98
99 BOOST_CHECK_EQUAL(os.str(), "CoordinateLsa("
100 "LsaInfo(OriginRouter: /test, "
101 "SequenceNumber: 128, "
102 "ExpirationPeriod: 10000 milliseconds), "
103 "HyperbolicRadius: 1.65, "
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600104 "HyperbolicAngles: 1.78)");
105
106 angles.push_back(3.21);
107 coordinateLsa.setHyperbolicAngle(angles);
108
109 std::ostringstream os2;
110 os2 << coordinateLsa;
111
112 BOOST_CHECK_EQUAL(os2.str(), "CoordinateLsa("
113 "LsaInfo(OriginRouter: /test, "
114 "SequenceNumber: 128, "
115 "ExpirationPeriod: 10000 milliseconds), "
116 "HyperbolicRadius: 1.65, "
117 "HyperbolicAngles: 1.78, 3.21)");
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800118}
119
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600120
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800121BOOST_AUTO_TEST_SUITE_END()
122
123} // namespace test
124} // namespace tlv
125} // namespace nlsr