blob: e05891c73b62bdccbc3fb292abe1e3bc7b69a8f9 [file] [log] [blame]
Vince Lehmanc439d662015-04-27 10:56:00 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Saurab Dulal7526cee2018-01-31 18:14:10 +00003 * Copyright (c) 2014-2019, 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,
Saurab Dulal7526cee2018-01-31 18:14:10 +000084 const std::string& info,
85 bool saveFlag);
Vince Lehmanc439d662015-04-27 10:56:00 -050086
87 void
88 onControlResponse(const std::string& info, const ndn::Data& data);
89
90private:
91 void
92 fetchAdjacencyLsas();
93
94 void
laqinfan35731852017-08-08 06:17:39 -050095 fetchRtables();
96
97 void
98 fetchHRRtables();
99
100 void
Vince Lehmanc439d662015-04-27 10:56:00 -0500101 fetchCoordinateLsas();
102
103 void
104 fetchNameLsas();
105
106 template <class T>
107 void
108 fetchFromLsdb(const ndn::Name::Component& datasetType,
109 const std::function<void(const T&)>& recordLsa);
110
111 template <class T>
112 void
laqinfan35731852017-08-08 06:17:39 -0500113 fetchFromRt(const std::function<void(const T&)>& recordLsa);
114
115 template <class T>
116 void
Vince Lehmanc439d662015-04-27 10:56:00 -0500117 onFetchSuccess(const ndn::ConstBufferPtr& data,
118 const std::function<void(const T&)>& recordLsa);
119
120 void
121 onTimeout(uint32_t errorCode, const std::string& error);
122
123private:
124 std::string
125 getLsaInfoString(const nlsr::tlv::LsaInfo& info);
126
127 void
128 recordAdjacencyLsa(const nlsr::tlv::AdjacencyLsa& lsa);
129
130 void
131 recordCoordinateLsa(const nlsr::tlv::CoordinateLsa& lsa);
132
133 void
134 recordNameLsa(const nlsr::tlv::NameLsa& lsa);
135
136 void
laqinfana073e2e2018-01-15 21:17:24 +0000137 recordRtable(const nlsr::tlv::RoutingTableStatus& rts);
laqinfan35731852017-08-08 06:17:39 -0500138
139 void
Vince Lehmanc439d662015-04-27 10:56:00 -0500140 printLsdb();
141
laqinfan35731852017-08-08 06:17:39 -0500142 void
143 printRT();
144
145 void
146 printAll();
147
Vince Lehmanc439d662015-04-27 10:56:00 -0500148public:
149 const char* programName;
150
151 // command parameters without leading 'cmd' component
152 const char* const* commandLineArguments;
153 int nOptions;
154
155private:
156 struct Router
157 {
158 std::string adjacencyLsaString;
159 std::string coordinateLsaString;
160 std::string nameLsaString;
161 };
162
163 Router&
laqinfan35731852017-08-08 06:17:39 -0500164 getRouterLsdb(const nlsr::tlv::LsaInfo& info);
165
Vince Lehmanc439d662015-04-27 10:56:00 -0500166 typedef std::map<const ndn::Name, Router> RouterMap;
167 RouterMap m_routers;
168
169private:
170 ndn::KeyChain m_keyChain;
171 ndn::Face& m_face;
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500172 ndn::security::ValidatorNull m_validator;
laqinfan35731852017-08-08 06:17:39 -0500173 std::string commandString;
laqinfana073e2e2018-01-15 21:17:24 +0000174 std::string m_rtString;
Vince Lehmanc439d662015-04-27 10:56:00 -0500175
176 std::deque<std::function<void()>> m_fetchSteps;
177
178 static const ndn::Name LOCALHOST_PREFIX;
179 static const ndn::Name LSDB_PREFIX;
180 static const ndn::Name NAME_UPDATE_PREFIX;
181
laqinfan35731852017-08-08 06:17:39 -0500182 static const ndn::Name RT_PREFIX;
183
Vince Lehmanc439d662015-04-27 10:56:00 -0500184 static const uint32_t ERROR_CODE_TIMEOUT;
185 static const uint32_t RESPONSE_CODE_SUCCESS;
Saurab Dulal7526cee2018-01-31 18:14:10 +0000186 static const uint32_t RESPONSE_CODE_SAVE_OR_DELETE;
187
Vince Lehmanc439d662015-04-27 10:56:00 -0500188};
189
190} // namespace nlsrc
191
192#endif // NLSR_TOOLS_NLSRC_HPP