Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Junxiao Shi | 1688ded | 2015-03-29 10:09:26 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). |
| 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. |
| 13 | * |
| 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | /** |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 26 | * Copyright (c) 2014, Regents of the University of California, |
| 27 | * Arizona Board of Regents, |
| 28 | * Colorado State University, |
| 29 | * University Pierre & Marie Curie, Sorbonne University, |
| 30 | * Washington University in St. Louis, |
| 31 | * Beijing Institute of Technology, |
| 32 | * The University of Memphis |
| 33 | * |
| 34 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 35 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 36 | * |
| 37 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 38 | * of the GNU General Public License as published by the Free Software Foundation, |
| 39 | * either version 3 of the License, or (at your option) any later version. |
| 40 | * |
| 41 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 42 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 43 | * PURPOSE. See the GNU General Public License for more details. |
| 44 | * |
| 45 | * You should have received a copy of the GNU General Public License along with |
| 46 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 47 | * |
| 48 | * @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu> |
| 49 | */ |
| 50 | |
Junxiao Shi | 1753afb | 2015-04-17 20:59:50 -0700 | [diff] [blame] | 51 | #include "core/version.hpp" |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 52 | #include "core/common.hpp" |
| 53 | |
| 54 | #include <ndn-cxx/util/io.hpp> |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 55 | |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 56 | namespace ndn { |
| 57 | namespace peek { |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 58 | |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 59 | class NdnPeek : boost::noncopyable |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 60 | { |
| 61 | public: |
| 62 | explicit |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 63 | NdnPeek(char* programName) |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 64 | : isVerbose(false) |
| 65 | , mustBeFresh(false) |
| 66 | , wantRightmostChild(false) |
| 67 | , wantPayloadOnly(false) |
| 68 | , m_programName(programName) |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 69 | , m_minSuffixComponents(-1) |
| 70 | , m_maxSuffixComponents(-1) |
| 71 | , m_interestLifetime(-1) |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 72 | , m_timeout(-1) |
| 73 | , m_prefixName("") |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 74 | , m_didReceiveData(false) |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 75 | { |
| 76 | } |
| 77 | |
| 78 | void |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 79 | usage(std::ostream& os ,const boost::program_options::options_description& options) const |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 80 | { |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 81 | os << "Usage: " << m_programName << " [options] ndn:/name\n" |
| 82 | " Fetch one data item matching the name prefix and write it to standard output\n" |
| 83 | "\n" |
| 84 | << options; |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void |
| 88 | setMinSuffixComponents(int minSuffixComponents) |
| 89 | { |
| 90 | if (minSuffixComponents < 0) |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 91 | throw std::out_of_range("'minSuffixComponents' must be a non-negative integer"); |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 92 | |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 93 | m_minSuffixComponents = minSuffixComponents; |
| 94 | } |
| 95 | |
| 96 | void |
| 97 | setMaxSuffixComponents(int maxSuffixComponents) |
| 98 | { |
| 99 | if (maxSuffixComponents < 0) |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 100 | throw std::out_of_range("'maxSuffixComponents' must be a non-negative integer"); |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 101 | |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 102 | m_maxSuffixComponents = maxSuffixComponents; |
| 103 | } |
| 104 | |
| 105 | void |
| 106 | setInterestLifetime(int interestLifetime) |
| 107 | { |
| 108 | if (interestLifetime < 0) |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 109 | throw std::out_of_range("'lifetime' must be a non-negative integer"); |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 110 | |
| 111 | m_interestLifetime = time::milliseconds(interestLifetime); |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | void |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 115 | setTimeout(int timeout) |
| 116 | { |
| 117 | if (timeout < 0) |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 118 | throw std::out_of_range("'timeout' must be a non-negative integer"); |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 119 | |
| 120 | m_timeout = time::milliseconds(timeout); |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | void |
Teng Liang | 799390a | 2016-03-12 23:14:29 -0700 | [diff] [blame^] | 124 | setLink(const std::string& file) |
| 125 | { |
| 126 | m_link = io::load<Link>(file); |
| 127 | if (m_link == nullptr) |
| 128 | throw std::runtime_error(file + " is either nonreadable or nonparseable"); |
| 129 | } |
| 130 | |
| 131 | void |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 132 | setPrefixName(const std::string& prefixName) |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 133 | { |
| 134 | m_prefixName = prefixName; |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 137 | time::milliseconds |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 138 | getDefaultInterestLifetime() |
| 139 | { |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 140 | return time::seconds(4); |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 143 | Interest |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 144 | createInterestPacket() |
| 145 | { |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 146 | Name interestName(m_prefixName); |
| 147 | Interest interestPacket(interestName); |
| 148 | |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 149 | if (mustBeFresh) |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 150 | interestPacket.setMustBeFresh(true); |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 151 | |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 152 | if (wantRightmostChild) |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 153 | interestPacket.setChildSelector(1); |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 154 | |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 155 | if (m_minSuffixComponents >= 0) |
| 156 | interestPacket.setMinSuffixComponents(m_minSuffixComponents); |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 157 | |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 158 | if (m_maxSuffixComponents >= 0) |
| 159 | interestPacket.setMaxSuffixComponents(m_maxSuffixComponents); |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 160 | |
| 161 | if (m_interestLifetime < time::milliseconds::zero()) |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 162 | interestPacket.setInterestLifetime(getDefaultInterestLifetime()); |
| 163 | else |
| 164 | interestPacket.setInterestLifetime(m_interestLifetime); |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 165 | |
Teng Liang | 799390a | 2016-03-12 23:14:29 -0700 | [diff] [blame^] | 166 | if (m_link != nullptr) |
| 167 | interestPacket.setLink(m_link->wireEncode()); |
| 168 | |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 169 | if (isVerbose) { |
Junxiao Shi | e02fb52 | 2015-10-18 08:45:09 -0700 | [diff] [blame] | 170 | std::cerr << "INTEREST: " << interestPacket << std::endl; |
| 171 | } |
| 172 | |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 173 | return interestPacket; |
| 174 | } |
| 175 | |
| 176 | void |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 177 | onData(const Interest& interest, Data& data) |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 178 | { |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 179 | m_didReceiveData = true; |
Junxiao Shi | e02fb52 | 2015-10-18 08:45:09 -0700 | [diff] [blame] | 180 | |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 181 | if (isVerbose) { |
Junxiao Shi | e02fb52 | 2015-10-18 08:45:09 -0700 | [diff] [blame] | 182 | std::cerr << "DATA, RTT: " |
| 183 | << time::duration_cast<time::milliseconds>(time::steady_clock::now() - m_expressInterestTime).count() |
| 184 | << "ms" << std::endl; |
| 185 | } |
| 186 | |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 187 | if (wantPayloadOnly) { |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 188 | const Block& block = data.getContent(); |
| 189 | std::cout.write(reinterpret_cast<const char*>(block.value()), block.value_size()); |
| 190 | } |
| 191 | else { |
| 192 | const Block& block = data.wireEncode(); |
| 193 | std::cout.write(reinterpret_cast<const char*>(block.wire()), block.size()); |
| 194 | } |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | void |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 198 | onTimeout(const Interest& interest) |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 199 | { |
| 200 | } |
| 201 | |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 202 | int |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 203 | run() |
| 204 | { |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 205 | try { |
| 206 | m_face.expressInterest(createInterestPacket(), |
| 207 | bind(&NdnPeek::onData, this, _1, _2), |
| 208 | bind(&NdnPeek::onTimeout, this, _1)); |
Junxiao Shi | e02fb52 | 2015-10-18 08:45:09 -0700 | [diff] [blame] | 209 | m_expressInterestTime = time::steady_clock::now(); |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 210 | if (m_timeout < time::milliseconds::zero()) { |
Junxiao Shi | e02fb52 | 2015-10-18 08:45:09 -0700 | [diff] [blame] | 211 | m_timeout = m_interestLifetime < time::milliseconds::zero() ? |
| 212 | getDefaultInterestLifetime() : m_interestLifetime; |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 213 | } |
Junxiao Shi | e02fb52 | 2015-10-18 08:45:09 -0700 | [diff] [blame] | 214 | m_face.processEvents(m_timeout); |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 215 | } |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 216 | catch (const std::exception& e) { |
Junxiao Shi | e02fb52 | 2015-10-18 08:45:09 -0700 | [diff] [blame] | 217 | std::cerr << "ERROR: " << e.what() << std::endl; |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 218 | return 1; |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 219 | } |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 220 | |
| 221 | if (isVerbose && !m_didReceiveData) { |
Junxiao Shi | e02fb52 | 2015-10-18 08:45:09 -0700 | [diff] [blame] | 222 | std::cerr << "TIMEOUT" << std::endl; |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 223 | return 3; |
Junxiao Shi | e02fb52 | 2015-10-18 08:45:09 -0700 | [diff] [blame] | 224 | } |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 225 | |
| 226 | return 0; |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 229 | public: |
| 230 | bool isVerbose; |
| 231 | bool mustBeFresh; |
| 232 | bool wantRightmostChild; |
| 233 | bool wantPayloadOnly; |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 234 | |
| 235 | private: |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 236 | std::string m_programName; |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 237 | int m_minSuffixComponents; |
| 238 | int m_maxSuffixComponents; |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 239 | time::milliseconds m_interestLifetime; |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 240 | time::milliseconds m_timeout; |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 241 | std::string m_prefixName; |
Junxiao Shi | e02fb52 | 2015-10-18 08:45:09 -0700 | [diff] [blame] | 242 | time::steady_clock::TimePoint m_expressInterestTime; |
Teng Liang | 799390a | 2016-03-12 23:14:29 -0700 | [diff] [blame^] | 243 | shared_ptr<Link> m_link; |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 244 | bool m_didReceiveData; |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 245 | Face m_face; |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 246 | }; |
| 247 | |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 248 | int |
| 249 | main(int argc, char* argv[]) |
| 250 | { |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 251 | NdnPeek program(argv[0]); |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 252 | |
| 253 | namespace po = boost::program_options; |
| 254 | |
| 255 | po::options_description visibleOptDesc("Allowed options"); |
| 256 | visibleOptDesc.add_options() |
| 257 | ("help,h", "print help and exit") |
| 258 | ("version,V", "print version and exit") |
| 259 | ("fresh,f", po::bool_switch(&program.mustBeFresh), |
| 260 | "set MustBeFresh") |
| 261 | ("rightmost,r", po::bool_switch(&program.wantRightmostChild), |
| 262 | "set ChildSelector to rightmost") |
| 263 | ("minsuffix,m", po::value<int>()->notifier(bind(&NdnPeek::setMinSuffixComponents, &program, _1)), |
| 264 | "set MinSuffixComponents") |
| 265 | ("maxsuffix,M", po::value<int>()->notifier(bind(&NdnPeek::setMaxSuffixComponents, &program, _1)), |
| 266 | "set MaxSuffixComponents") |
| 267 | ("lifetime,l", po::value<int>()->notifier(bind(&NdnPeek::setInterestLifetime, &program, _1)), |
| 268 | "set InterestLifetime (in milliseconds)") |
| 269 | ("payload,p", po::bool_switch(&program.wantPayloadOnly), |
| 270 | "print payload only, instead of full packet") |
| 271 | ("timeout,w", po::value<int>()->notifier(bind(&NdnPeek::setTimeout, &program, _1)), |
| 272 | "set timeout (in milliseconds)") |
| 273 | ("verbose,v", po::bool_switch(&program.isVerbose), |
| 274 | "turn on verbose output") |
Teng Liang | 799390a | 2016-03-12 23:14:29 -0700 | [diff] [blame^] | 275 | ("link-file", po::value<std::string>()->notifier(bind(&NdnPeek::setLink, &program, _1)), |
| 276 | "set Link from a file") |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 277 | ; |
| 278 | |
| 279 | po::options_description hiddenOptDesc("Hidden options"); |
| 280 | hiddenOptDesc.add_options() |
| 281 | ("prefix", po::value<std::string>(), "Interest name"); |
| 282 | |
| 283 | po::options_description optDesc("Allowed options"); |
| 284 | optDesc.add(visibleOptDesc).add(hiddenOptDesc); |
| 285 | |
| 286 | po::positional_options_description optPos; |
| 287 | optPos.add("prefix", -1); |
| 288 | |
| 289 | try { |
| 290 | po::variables_map vm; |
| 291 | po::store(po::command_line_parser(argc, argv).options(optDesc).positional(optPos).run(), vm); |
| 292 | po::notify(vm); |
| 293 | |
| 294 | if (vm.count("help") > 0) { |
| 295 | program.usage(std::cout, visibleOptDesc); |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | if (vm.count("version") > 0) { |
Junxiao Shi | 1753afb | 2015-04-17 20:59:50 -0700 | [diff] [blame] | 300 | std::cout << "ndnpeek " << tools::VERSION << std::endl; |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 301 | return 0; |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | if (vm.count("prefix") > 0) { |
| 305 | std::string prefixName = vm["prefix"].as<std::string>(); |
| 306 | program.setPrefixName(prefixName); |
| 307 | } |
| 308 | else { |
| 309 | throw std::runtime_error("Required argument 'prefix' is missing"); |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 310 | } |
| 311 | } |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 312 | catch (const std::exception& e) { |
| 313 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 314 | program.usage(std::cerr, visibleOptDesc); |
| 315 | return 2; |
| 316 | } |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 317 | |
Teng Liang | d4ab87f | 2016-03-08 18:50:47 -0700 | [diff] [blame] | 318 | return program.run(); |
Junxiao Shi | 2ac79d9 | 2015-03-23 11:16:18 -0700 | [diff] [blame] | 319 | } |
Junxiao Shi | 0c75f99 | 2015-03-24 21:39:47 -0700 | [diff] [blame] | 320 | |
| 321 | } // namespace peek |
| 322 | } // namespace ndn |
| 323 | |
| 324 | int |
| 325 | main(int argc, char** argv) |
| 326 | { |
| 327 | return ndn::peek::main(argc, argv); |
| 328 | } |