blob: c3ee7f15e516c6dbc3f223e2d681f916c6f16ae4 [file] [log] [blame]
Vince Lehmanc439d662015-04-27 10:56:00 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande0421bc62020-05-08 20:42:19 -07002/*
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -08003 * Copyright (c) 2014-2020, The University of Memphis,
Vince Lehmanc439d662015-04-27 10:56:00 -05004 * 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/>.
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070020 */
Vince Lehmanc439d662015-04-27 10:56:00 -050021
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080022#include "lsa/adj-lsa.hpp"
23#include "lsa/coordinate-lsa.hpp"
24#include "lsa/name-lsa.hpp"
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070025#include "route/routing-table.hpp"
laqinfan35731852017-08-08 06:17:39 -050026
Vince Lehmanc439d662015-04-27 10:56:00 -050027#include <boost/noncopyable.hpp>
28#include <ndn-cxx/face.hpp>
29#include <ndn-cxx/security/key-chain.hpp>
Muktadir R Chowdhury4c7caad2015-09-03 15:49:22 -050030#include <ndn-cxx/security/validator-null.hpp>
Vince Lehmanc439d662015-04-27 10:56:00 -050031
32#include <deque>
33#include <map>
34#include <stdexcept>
35
36#ifndef NLSR_TOOLS_NLSRC_HPP
37#define NLSR_TOOLS_NLSRC_HPP
38
39namespace nlsrc {
40
41class Nlsrc : boost::noncopyable
42{
43public:
44 explicit
45 Nlsrc(ndn::Face& face);
46
47 void
48 printUsage();
49
50 void
laqinfan35731852017-08-08 06:17:39 -050051 getStatus(const std::string& command);
Vince Lehmanc439d662015-04-27 10:56:00 -050052
53 bool
54 dispatch(const std::string& cmd);
55
56private:
57 void
58 runNextStep();
59
60 /**
61 * \brief Adds a name prefix to be advertised in NLSR's Name LSA
62 *
63 * cmd format:
64 * name
65 *
66 */
67 void
68 advertiseName();
69
70 /**
71 * \brief Removes a name prefix from NLSR's Name LSA
72 *
73 * cmd format:
74 * name
75 *
76 */
77 void
78 withdrawName();
79
80 void
81 sendNamePrefixUpdate(const ndn::Name& name,
82 const ndn::Name::Component& verb,
Saurab Dulal7526cee2018-01-31 18:14:10 +000083 const std::string& info,
84 bool saveFlag);
Vince Lehmanc439d662015-04-27 10:56:00 -050085
86 void
87 onControlResponse(const std::string& info, const ndn::Data& data);
88
89private:
90 void
91 fetchAdjacencyLsas();
92
93 void
94 fetchCoordinateLsas();
95
96 void
97 fetchNameLsas();
98
99 template <class T>
100 void
101 fetchFromLsdb(const ndn::Name::Component& datasetType,
102 const std::function<void(const T&)>& recordLsa);
103
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700104 void
105 recordLsa(const nlsr::Lsa& lsa);
106
107 void
108 fetchRtables();
109
Vince Lehmanc439d662015-04-27 10:56:00 -0500110 template <class T>
111 void
laqinfan35731852017-08-08 06:17:39 -0500112 fetchFromRt(const std::function<void(const T&)>& recordLsa);
113
114 template <class T>
115 void
Vince Lehmanc439d662015-04-27 10:56:00 -0500116 onFetchSuccess(const ndn::ConstBufferPtr& data,
117 const std::function<void(const T&)>& recordLsa);
118
119 void
120 onTimeout(uint32_t errorCode, const std::string& error);
121
Vince Lehmanc439d662015-04-27 10:56:00 -0500122 void
Ashlesh Gawande0421bc62020-05-08 20:42:19 -0700123 recordRtable(const nlsr::RoutingTableStatus& rts);
laqinfan35731852017-08-08 06:17:39 -0500124
125 void
Vince Lehmanc439d662015-04-27 10:56:00 -0500126 printLsdb();
127
laqinfan35731852017-08-08 06:17:39 -0500128 void
129 printRT();
130
131 void
132 printAll();
133
Vince Lehmanc439d662015-04-27 10:56:00 -0500134public:
135 const char* programName;
136
137 // command parameters without leading 'cmd' component
138 const char* const* commandLineArguments;
139 int nOptions;
140
141private:
142 struct Router
143 {
144 std::string adjacencyLsaString;
145 std::string coordinateLsaString;
146 std::string nameLsaString;
147 };
148
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800149 std::map<ndn::Name, Router> m_routers;
Vince Lehmanc439d662015-04-27 10:56:00 -0500150
151private:
152 ndn::KeyChain m_keyChain;
153 ndn::Face& m_face;
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500154 ndn::security::ValidatorNull m_validator;
laqinfan35731852017-08-08 06:17:39 -0500155 std::string commandString;
laqinfana073e2e2018-01-15 21:17:24 +0000156 std::string m_rtString;
Vince Lehmanc439d662015-04-27 10:56:00 -0500157
158 std::deque<std::function<void()>> m_fetchSteps;
159
160 static const ndn::Name LOCALHOST_PREFIX;
161 static const ndn::Name LSDB_PREFIX;
162 static const ndn::Name NAME_UPDATE_PREFIX;
163
laqinfan35731852017-08-08 06:17:39 -0500164 static const ndn::Name RT_PREFIX;
165
Vince Lehmanc439d662015-04-27 10:56:00 -0500166 static const uint32_t ERROR_CODE_TIMEOUT;
167 static const uint32_t RESPONSE_CODE_SUCCESS;
Saurab Dulal7526cee2018-01-31 18:14:10 +0000168 static const uint32_t RESPONSE_CODE_SAVE_OR_DELETE;
Vince Lehmanc439d662015-04-27 10:56:00 -0500169};
170
171} // namespace nlsrc
172
173#endif // NLSR_TOOLS_NLSRC_HPP