blob: cc5a1f61eade832da4ccc12f6121c96d3cf37a8c [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
126 void
127 recordAdjacencyLsa(const nlsr::tlv::AdjacencyLsa& lsa);
128
129 void
130 recordCoordinateLsa(const nlsr::tlv::CoordinateLsa& lsa);
131
132 void
133 recordNameLsa(const nlsr::tlv::NameLsa& lsa);
134
135 void
laqinfana073e2e2018-01-15 21:17:24 +0000136 recordRtable(const nlsr::tlv::RoutingTableStatus& rts);
laqinfan35731852017-08-08 06:17:39 -0500137
138 void
Vince Lehmanc439d662015-04-27 10:56:00 -0500139 printLsdb();
140
laqinfan35731852017-08-08 06:17:39 -0500141 void
142 printRT();
143
144 void
145 printAll();
146
Vince Lehmanc439d662015-04-27 10:56:00 -0500147public:
148 const char* programName;
149
150 // command parameters without leading 'cmd' component
151 const char* const* commandLineArguments;
152 int nOptions;
153
154private:
155 struct Router
156 {
157 std::string adjacencyLsaString;
158 std::string coordinateLsaString;
159 std::string nameLsaString;
160 };
161
162 Router&
laqinfan35731852017-08-08 06:17:39 -0500163 getRouterLsdb(const nlsr::tlv::LsaInfo& info);
164
Vince Lehmanc439d662015-04-27 10:56:00 -0500165 typedef std::map<const ndn::Name, Router> RouterMap;
166 RouterMap m_routers;
167
168private:
169 ndn::KeyChain m_keyChain;
170 ndn::Face& m_face;
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500171 ndn::security::ValidatorNull m_validator;
laqinfan35731852017-08-08 06:17:39 -0500172 std::string commandString;
laqinfana073e2e2018-01-15 21:17:24 +0000173 std::string m_rtString;
Vince Lehmanc439d662015-04-27 10:56:00 -0500174
175 std::deque<std::function<void()>> m_fetchSteps;
176
177 static const ndn::Name LOCALHOST_PREFIX;
178 static const ndn::Name LSDB_PREFIX;
179 static const ndn::Name NAME_UPDATE_PREFIX;
180
laqinfan35731852017-08-08 06:17:39 -0500181 static const ndn::Name RT_PREFIX;
182
Vince Lehmanc439d662015-04-27 10:56:00 -0500183 static const uint32_t ERROR_CODE_TIMEOUT;
184 static const uint32_t RESPONSE_CODE_SUCCESS;
185};
186
187} // namespace nlsrc
188
189#endif // NLSR_TOOLS_NLSRC_HPP