Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | feae557 | 2017-01-13 12:06:26 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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 | |
| 24 | #include "../boost-test.hpp" |
| 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 |
| 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 | |
| 45 | BOOST_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 Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame^] | 56 | std::vector<double> angles; |
| 57 | angles.push_back(1.78); |
| 58 | coordinateLsa.setHyperbolicAngle(angles); |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 59 | |
| 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 | |
| 67 | BOOST_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 Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame^] | 78 | std::vector<double> angles = {1.78}; |
| 79 | BOOST_REQUIRE(coordinateLsa.getHyperbolicAngle() == angles); |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | BOOST_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 Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame^] | 93 | std::vector<double> angles = {1.78}; |
| 94 | coordinateLsa.setHyperbolicAngle(angles); |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 95 | |
| 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 Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame^] | 104 | "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 Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame^] | 120 | |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 121 | BOOST_AUTO_TEST_SUITE_END() |
| 122 | |
| 123 | } // namespace test |
| 124 | } // namespace tlv |
| 125 | } // namespace nlsr |