Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, The University of Memphis, |
| 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 "publisher/lsa-publisher.hpp" |
| 23 | #include "tlv/adjacency.hpp" |
| 24 | #include "tlv/adjacency-lsa.hpp" |
| 25 | #include "tlv/tlv-nlsr.hpp" |
| 26 | |
| 27 | #include "publisher-fixture.hpp" |
| 28 | #include "../boost-test.hpp" |
| 29 | |
| 30 | namespace nlsr { |
| 31 | namespace test { |
| 32 | |
| 33 | BOOST_FIXTURE_TEST_SUITE(PublisherTestLsaPublisher, PublisherFixture) |
| 34 | |
| 35 | BOOST_AUTO_TEST_CASE(AdjacencyLsaPublisherBasic) |
| 36 | { |
| 37 | // Adjacency LSA for RouterA |
| 38 | AdjLsa routerALsa; |
| 39 | routerALsa.setOrigRouter("/RouterA"); |
| 40 | addAdjacency(routerALsa, "/RouterA/adjacency1", "udp://face-1", 10); |
| 41 | lsdb.installAdjLsa(routerALsa); |
| 42 | |
| 43 | // Adjacency LSA for RouterB |
| 44 | AdjLsa routerBLsa; |
| 45 | routerBLsa.setOrigRouter("/RouterB"); |
| 46 | routerBLsa.setLsSeqNo(5); |
| 47 | addAdjacency(routerBLsa, "/RouterB/adjacency1", "udp://face-1", 10); |
| 48 | addAdjacency(routerBLsa, "/RouterB/adjacency2", "udp://face-2", 20); |
| 49 | addAdjacency(routerBLsa, "/RouterB/adjacency3", "udp://face-3", 30); |
| 50 | lsdb.installAdjLsa(routerBLsa); |
| 51 | |
| 52 | AdjacencyLsaPublisher publisher(lsdb, *face, "/RouterA", keyChain); |
| 53 | |
| 54 | publisher.publish(); |
| 55 | face->processEvents(ndn::time::milliseconds(1)); |
| 56 | |
| 57 | BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1); |
| 58 | ndn::Block parser = face->sentDatas[0].getContent(); |
| 59 | parser.parse(); |
| 60 | |
| 61 | // Check RouterB LSA |
| 62 | ndn::Block::element_const_iterator it = parser.elements_begin(); |
| 63 | checkTlvAdjLsa(*it, routerBLsa); |
| 64 | |
| 65 | // Check RouterA LSA |
| 66 | it++; |
| 67 | checkTlvAdjLsa(*it, routerALsa); |
| 68 | } |
| 69 | |
| 70 | BOOST_AUTO_TEST_CASE(CoordinateLsaBasic) |
| 71 | { |
| 72 | CoordinateLsa routerALsa = createCoordinateLsa("/RouterA", 10.0, 20.0); |
| 73 | lsdb.installCoordinateLsa(routerALsa); |
| 74 | |
| 75 | CoordinateLsa routerBLsa = createCoordinateLsa("/RouterB", 123.45, 543.21); |
| 76 | lsdb.installCoordinateLsa(routerBLsa); |
| 77 | |
| 78 | CoordinateLsa routerCLsa = createCoordinateLsa("/RouterC", 0.01, 0.02); |
| 79 | lsdb.installCoordinateLsa(routerCLsa); |
| 80 | |
| 81 | CoordinateLsaPublisher publisher(lsdb, *face, "/RouterA", keyChain); |
| 82 | |
| 83 | publisher.publish(); |
| 84 | face->processEvents(ndn::time::milliseconds(1)); |
| 85 | |
| 86 | BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1); |
| 87 | ndn::Block parser = face->sentDatas[0].getContent(); |
| 88 | parser.parse(); |
| 89 | |
| 90 | // Check RouterC LSA |
| 91 | ndn::Block::element_const_iterator it = parser.elements_begin(); |
| 92 | checkTlvCoordinateLsa(*it, routerCLsa); |
| 93 | |
| 94 | // Check RouterB LSA |
| 95 | ++it; |
| 96 | checkTlvCoordinateLsa(*it, routerBLsa); |
| 97 | |
| 98 | // Check RouterA LSA |
| 99 | ++it; |
| 100 | checkTlvCoordinateLsa(*it, routerALsa); |
| 101 | } |
| 102 | |
| 103 | BOOST_AUTO_TEST_CASE(NameLsaBasic) |
| 104 | { |
| 105 | // Name LSA for RouterA |
| 106 | NameLsa routerALsa; |
| 107 | routerALsa.setOrigRouter("/RouterA"); |
| 108 | routerALsa.addName("/RouterA/name1"); |
| 109 | lsdb.installNameLsa(routerALsa); |
| 110 | |
| 111 | // Name LSA for RouterB |
| 112 | NameLsa routerBLsa; |
| 113 | routerBLsa.setOrigRouter("/RouterB"); |
| 114 | routerBLsa.addName("/RouterB/name1"); |
| 115 | routerBLsa.addName("/RouterB/name2"); |
| 116 | routerBLsa.addName("/RouterB/name3"); |
| 117 | lsdb.installNameLsa(routerBLsa); |
| 118 | |
| 119 | NameLsaPublisher publisher(lsdb, *face, "/RouterA", keyChain); |
| 120 | |
| 121 | publisher.publish(); |
| 122 | face->processEvents(ndn::time::milliseconds(1)); |
| 123 | |
| 124 | BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1); |
| 125 | ndn::Block parser = face->sentDatas[0].getContent(); |
| 126 | parser.parse(); |
| 127 | |
| 128 | // Check RouterB LSA |
| 129 | ndn::Block::element_const_iterator it = parser.elements_begin(); |
| 130 | checkTlvNameLsa(*it, routerBLsa); |
| 131 | |
| 132 | // Check RouterA LSA |
| 133 | it++; |
| 134 | checkTlvNameLsa(*it, routerALsa); |
| 135 | } |
| 136 | |
| 137 | BOOST_AUTO_TEST_SUITE_END() |
| 138 | |
| 139 | } // namespace test |
| 140 | } // namespace nlsr |