blob: b6305b9481fc756b21151a4ade04fe72796402fc [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -05002/**
akmhoque3d06e792014-05-27 16:23:20 -05003 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * \author Ashlesh Gawande <agawande@memphis.edu>
21 *
22 **/
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050023#include "lsdb.hpp"
24#include "nlsr.hpp"
25#include "lsa.hpp"
26#include "name-prefix-list.hpp"
27#include <boost/test/unit_test.hpp>
akmhoquec7a79b22014-05-26 08:06:19 -050028#include <ndn-cxx/util/time.hpp>
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050029
30namespace nlsr {
31
32namespace test {
33
34BOOST_AUTO_TEST_SUITE(TestLsdb)
35
36BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists)
37{
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070038 INIT_LOGGERS("/tmp");
39
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050040 Nlsr nlsr1;
akmhoquec7a79b22014-05-26 08:06:19 -050041 ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050042 NamePrefixList npl1;
43
akmhoquefdbddb12014-05-02 18:35:19 -050044 std::string s1 = "name1";
45 std::string s2 = "name2";
46 std::string router1 = "router1/1";
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050047
48 npl1.insert(s1);
49 npl1.insert(s2);
50
akmhoque157b0a42014-05-13 00:26:37 -050051//For NameLsa lsType is name.
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050052//12 is seqNo, randomly generated.
53//1800 is the default life time.
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070054 NameLsa nlsa1(ndn::Name("/router1/1"), std::string("name"), 12, testTimePoint, npl1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050055
akmhoque31d1d4b2014-05-05 22:08:14 -050056 Lsdb lsdb1(nlsr1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050057
akmhoque31d1d4b2014-05-05 22:08:14 -050058 lsdb1.installNameLsa(nlsa1);
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070059 lsdb1.writeNameLsdbLog();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050060
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070061 BOOST_CHECK(lsdb1.doesLsaExist(ndn::Name("/router1/1/name"), std::string("name")));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050062
akmhoque31d1d4b2014-05-05 22:08:14 -050063 lsdb1.removeNameLsa(router1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050064
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070065 BOOST_CHECK_EQUAL(lsdb1.doesLsaExist(ndn::Name("/router1/1"), std::string("name")), false);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050066}
67
68BOOST_AUTO_TEST_SUITE_END()
69
70} //namespace test
71} //namespace nlsr