blob: a5c636875bc110476a122a2c379e2c77c9bcee63 [file] [log] [blame]
Vince Lehmanc439d662015-04-27 10:56:00 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
laqinfan35731852017-08-08 06:17:39 -05003 * Copyright (c) 2014-2018, 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/>.
20 **/
21
22#include "tlv/adjacency-lsa.hpp"
23#include "tlv/coordinate-lsa.hpp"
24#include "tlv/name-lsa.hpp"
laqinfan35731852017-08-08 06:17:39 -050025#include "tlv/routing-table-status.hpp"
26
Vince Lehmanc439d662015-04-27 10:56:00 -050027
28#include <boost/noncopyable.hpp>
29#include <ndn-cxx/face.hpp>
30#include <ndn-cxx/security/key-chain.hpp>
Muktadir R Chowdhury4c7caad2015-09-03 15:49:22 -050031#include <ndn-cxx/security/validator-null.hpp>
Vince Lehmanc439d662015-04-27 10:56:00 -050032
33#include <deque>
34#include <map>
35#include <stdexcept>
36
37#ifndef NLSR_TOOLS_NLSRC_HPP
38#define NLSR_TOOLS_NLSRC_HPP
39
40namespace nlsrc {
41
42class Nlsrc : boost::noncopyable
43{
44public:
45 explicit
46 Nlsrc(ndn::Face& face);
47
48 void
49 printUsage();
50
51 void
laqinfan35731852017-08-08 06:17:39 -050052 getStatus(const std::string& command);
Vince Lehmanc439d662015-04-27 10:56:00 -050053
54 bool
55 dispatch(const std::string& cmd);
56
57private:
58 void
59 runNextStep();
60
61 /**
62 * \brief Adds a name prefix to be advertised in NLSR's Name LSA
63 *
64 * cmd format:
65 * name
66 *
67 */
68 void
69 advertiseName();
70
71 /**
72 * \brief Removes a name prefix from NLSR's Name LSA
73 *
74 * cmd format:
75 * name
76 *
77 */
78 void
79 withdrawName();
80
81 void
82 sendNamePrefixUpdate(const ndn::Name& name,
83 const ndn::Name::Component& verb,
84 const std::string& info);
85
86 void
87 onControlResponse(const std::string& info, const ndn::Data& data);
88
89private:
90 void
91 fetchAdjacencyLsas();
92
93 void
laqinfan35731852017-08-08 06:17:39 -050094 fetchRtables();
95
96 void
97 fetchHRRtables();
98
99 void
Vince Lehmanc439d662015-04-27 10:56:00 -0500100 fetchCoordinateLsas();
101
102 void
103 fetchNameLsas();
104
105 template <class T>
106 void
107 fetchFromLsdb(const ndn::Name::Component& datasetType,
108 const std::function<void(const T&)>& recordLsa);
109
110 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
122private:
123 std::string
124 getLsaInfoString(const nlsr::tlv::LsaInfo& info);
125
laqinfan35731852017-08-08 06:17:39 -0500126 std::string
127 getDesString(const nlsr::tlv::Destination& des);
128
Vince Lehmanc439d662015-04-27 10:56:00 -0500129 void
130 recordAdjacencyLsa(const nlsr::tlv::AdjacencyLsa& lsa);
131
132 void
133 recordCoordinateLsa(const nlsr::tlv::CoordinateLsa& lsa);
134
135 void
136 recordNameLsa(const nlsr::tlv::NameLsa& lsa);
137
138 void
laqinfan35731852017-08-08 06:17:39 -0500139 recordRtable(const nlsr::tlv::RoutingTable& rts);
140
141 void
Vince Lehmanc439d662015-04-27 10:56:00 -0500142 printLsdb();
143
laqinfan35731852017-08-08 06:17:39 -0500144 void
145 printRT();
146
147 void
148 printAll();
149
Vince Lehmanc439d662015-04-27 10:56:00 -0500150public:
151 const char* programName;
152
153 // command parameters without leading 'cmd' component
154 const char* const* commandLineArguments;
155 int nOptions;
156
157private:
158 struct Router
159 {
160 std::string adjacencyLsaString;
161 std::string coordinateLsaString;
162 std::string nameLsaString;
laqinfan35731852017-08-08 06:17:39 -0500163 std::string rtString;
Vince Lehmanc439d662015-04-27 10:56:00 -0500164 };
165
166 Router&
laqinfan35731852017-08-08 06:17:39 -0500167 getRouterLsdb(const nlsr::tlv::LsaInfo& info);
168
169 Router&
170 getRouterRT(const nlsr::tlv::Destination& des);
Vince Lehmanc439d662015-04-27 10:56:00 -0500171
172 typedef std::map<const ndn::Name, Router> RouterMap;
173 RouterMap m_routers;
174
175private:
176 ndn::KeyChain m_keyChain;
177 ndn::Face& m_face;
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500178 ndn::security::ValidatorNull m_validator;
laqinfan35731852017-08-08 06:17:39 -0500179 std::string commandString;
Vince Lehmanc439d662015-04-27 10:56:00 -0500180
181 std::deque<std::function<void()>> m_fetchSteps;
182
183 static const ndn::Name LOCALHOST_PREFIX;
184 static const ndn::Name LSDB_PREFIX;
185 static const ndn::Name NAME_UPDATE_PREFIX;
186
laqinfan35731852017-08-08 06:17:39 -0500187 static const ndn::Name RT_PREFIX;
188
Vince Lehmanc439d662015-04-27 10:56:00 -0500189 static const uint32_t ERROR_CODE_TIMEOUT;
190 static const uint32_t RESPONSE_CODE_SUCCESS;
191};
192
193} // namespace nlsrc
194
195#endif // NLSR_TOOLS_NLSRC_HPP