Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Tianxing Ma | 9ea3639 | 2018-10-05 14:32:55 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, The University of Memphis, |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 4 | * 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 Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame^] | 24 | #include "tests/boost-test.hpp" |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 25 | |
| 26 | namespace nlsr { |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 27 | namespace tlv { |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 28 | namespace test { |
| 29 | |
| 30 | BOOST_AUTO_TEST_SUITE(TlvTestCoordinateLsa) |
| 31 | |
| 32 | const uint8_t CoordinateLsaData[] = |
| 33 | { |
| 34 | // Header |
Tianxing Ma | 9ea3639 | 2018-10-05 14:32:55 -0500 | [diff] [blame] | 35 | 0x85, 0x27, |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 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 |
Tianxing Ma | 9ea3639 | 2018-10-05 14:32:55 -0500 | [diff] [blame] | 40 | 0x87, 0x08, 0x3f, 0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 41 | // HyperbolicAngle |
Tianxing Ma | 9ea3639 | 2018-10-05 14:32:55 -0500 | [diff] [blame] | 42 | 0x88, 0x08, 0x3f, 0xfc, 0x7a, 0xe1, 0x47, 0xae, 0x14, 0x7b |
| 43 | |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | BOOST_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 Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 57 | std::vector<double> angles; |
| 58 | angles.push_back(1.78); |
| 59 | coordinateLsa.setHyperbolicAngle(angles); |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 60 | |
| 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 | |
| 68 | BOOST_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 Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 79 | std::vector<double> angles = {1.78}; |
| 80 | BOOST_REQUIRE(coordinateLsa.getHyperbolicAngle() == angles); |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | BOOST_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 Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 94 | std::vector<double> angles = {1.78}; |
| 95 | coordinateLsa.setHyperbolicAngle(angles); |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 96 | |
| 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 Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 105 | "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 Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 121 | |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 122 | BOOST_AUTO_TEST_SUITE_END() |
| 123 | |
| 124 | } // namespace test |
| 125 | } // namespace tlv |
| 126 | } // namespace nlsr |