blob: 3dd44d6e93e16818b2bbdb51baaca25ec38c1b87 [file] [log] [blame]
Vince Lehmanc439d662015-04-27 10:56:00 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, 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"
25
26#include <boost/noncopyable.hpp>
27#include <ndn-cxx/face.hpp>
28#include <ndn-cxx/security/key-chain.hpp>
Muktadir R Chowdhury4c7caad2015-09-03 15:49:22 -050029#include <ndn-cxx/security/validator-null.hpp>
Vince Lehmanc439d662015-04-27 10:56:00 -050030
31#include <deque>
32#include <map>
33#include <stdexcept>
34
35#ifndef NLSR_TOOLS_NLSRC_HPP
36#define NLSR_TOOLS_NLSRC_HPP
37
38namespace nlsrc {
39
40class Nlsrc : boost::noncopyable
41{
42public:
43 explicit
44 Nlsrc(ndn::Face& face);
45
46 void
47 printUsage();
48
49 void
50 getStatus();
51
52 bool
53 dispatch(const std::string& cmd);
54
55private:
56 void
57 runNextStep();
58
59 /**
60 * \brief Adds a name prefix to be advertised in NLSR's Name LSA
61 *
62 * cmd format:
63 * name
64 *
65 */
66 void
67 advertiseName();
68
69 /**
70 * \brief Removes a name prefix from NLSR's Name LSA
71 *
72 * cmd format:
73 * name
74 *
75 */
76 void
77 withdrawName();
78
79 void
80 sendNamePrefixUpdate(const ndn::Name& name,
81 const ndn::Name::Component& verb,
82 const std::string& info);
83
84 void
85 onControlResponse(const std::string& info, const ndn::Data& data);
86
87private:
88 void
89 fetchAdjacencyLsas();
90
91 void
92 fetchCoordinateLsas();
93
94 void
95 fetchNameLsas();
96
97 template <class T>
98 void
99 fetchFromLsdb(const ndn::Name::Component& datasetType,
100 const std::function<void(const T&)>& recordLsa);
101
102 template <class T>
103 void
104 onFetchSuccess(const ndn::ConstBufferPtr& data,
105 const std::function<void(const T&)>& recordLsa);
106
107 void
108 onTimeout(uint32_t errorCode, const std::string& error);
109
110private:
111 std::string
112 getLsaInfoString(const nlsr::tlv::LsaInfo& info);
113
114 void
115 recordAdjacencyLsa(const nlsr::tlv::AdjacencyLsa& lsa);
116
117 void
118 recordCoordinateLsa(const nlsr::tlv::CoordinateLsa& lsa);
119
120 void
121 recordNameLsa(const nlsr::tlv::NameLsa& lsa);
122
123 void
124 printLsdb();
125
126public:
127 const char* programName;
128
129 // command parameters without leading 'cmd' component
130 const char* const* commandLineArguments;
131 int nOptions;
132
133private:
134 struct Router
135 {
136 std::string adjacencyLsaString;
137 std::string coordinateLsaString;
138 std::string nameLsaString;
139 };
140
141 Router&
142 getRouter(const nlsr::tlv::LsaInfo& info);
143
144 typedef std::map<const ndn::Name, Router> RouterMap;
145 RouterMap m_routers;
146
147private:
148 ndn::KeyChain m_keyChain;
149 ndn::Face& m_face;
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500150 ndn::security::ValidatorNull m_validator;
Vince Lehmanc439d662015-04-27 10:56:00 -0500151
152 std::deque<std::function<void()>> m_fetchSteps;
153
154 static const ndn::Name LOCALHOST_PREFIX;
155 static const ndn::Name LSDB_PREFIX;
156 static const ndn::Name NAME_UPDATE_PREFIX;
157
158 static const uint32_t ERROR_CODE_TIMEOUT;
159 static const uint32_t RESPONSE_CODE_SUCCESS;
160};
161
162} // namespace nlsrc
163
164#endif // NLSR_TOOLS_NLSRC_HPP