blob: 02d5f9a6b10df39f3cd79db8936ffd16ca8d75e0 [file] [log] [blame]
hilata198cadb2014-02-15 23:46:19 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef NFD_TOOLS_NFDC_HPP
8#define NFD_TOOLS_NFDC_HPP
9
10#include <ndn-cpp-dev/face.hpp>
11#include <ndn-cpp-dev/management/controller.hpp>
12#include <ndn-cpp-dev/management/nfd-controller.hpp>
hilata198cadb2014-02-15 23:46:19 -060013#include <vector>
14
15namespace nfdc {
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070016
17using namespace ndn::nfd;
18
19class Nfdc
hilata198cadb2014-02-15 23:46:19 -060020{
21public:
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070022 class Error : public std::runtime_error
hilata198cadb2014-02-15 23:46:19 -060023 {
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070024 public:
25 explicit
26 Error(const std::string& what)
27 : std::runtime_error(what)
28 {
29 }
hilata198cadb2014-02-15 23:46:19 -060030 };
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070031
hilata198cadb2014-02-15 23:46:19 -060032 explicit
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070033 Nfdc(ndn::Face& face);
34
35 ~Nfdc();
36
hilata198cadb2014-02-15 23:46:19 -060037 bool
38 dispatch(const std::string& cmd,
39 const char* cmdOptions[],
40 int nOptions);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070041
hilata198cadb2014-02-15 23:46:19 -060042 /**
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070043 * \brief Adds a nexthop to a FIB entry.
hilatadc947ec2014-03-10 12:48:31 -050044 *
45 * If the FIB entry does not exist, it is inserted automatically
hilata198cadb2014-02-15 23:46:19 -060046 *
47 * cmd format:
48 * name
49 *
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070050 * \param cmdOptions Add next hop command parameters without leading 'add-nexthop' component
hilata198cadb2014-02-15 23:46:19 -060051 */
52 void
hilata198cadb2014-02-15 23:46:19 -060053 fibAddNextHop(const char* cmdOptions[], bool hasCost);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070054
hilata198cadb2014-02-15 23:46:19 -060055 /**
hilatadc947ec2014-03-10 12:48:31 -050056 * \brief Removes a nexthop from an existing FIB entry
hilata198cadb2014-02-15 23:46:19 -060057 *
hilatadc947ec2014-03-10 12:48:31 -050058 * If the last nexthop record in a FIB entry is removed, the FIB entry is also deleted
hilata198cadb2014-02-15 23:46:19 -060059 *
60 * cmd format:
61 * name faceId
62 *
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070063 * \param cmdOptions Remove next hop command parameters without leading
64 * 'remove-nexthop' component
hilata198cadb2014-02-15 23:46:19 -060065 */
66 void
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070067 fibRemoveNextHop(const char* cmdOptions[]);
68
hilata198cadb2014-02-15 23:46:19 -060069 /**
70 * \brief create new face
71 *
hilatadc947ec2014-03-10 12:48:31 -050072 * This command allows creation of UDP unicast and TCP faces only.
hilata198cadb2014-02-15 23:46:19 -060073 *
74 * cmd format:
75 * uri
76 *
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070077 * \param cmdOptions Create face command parameters without leading 'create' component
hilata198cadb2014-02-15 23:46:19 -060078 */
79 void
80 faceCreate(const char* cmdOptions[]);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070081
hilata198cadb2014-02-15 23:46:19 -060082 /**
83 * \brief destroy a face
84 *
85 * cmd format:
86 * faceId
87 *
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070088 * \param cmdOptions Destroy face command parameters without leading 'destroy' component
hilata198cadb2014-02-15 23:46:19 -060089 */
90 void
91 faceDestroy(const char* cmdOptions[]);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070092
hilata141eaae2014-03-13 19:54:47 -050093 /**
94 * \brief Set the strategy for a namespace
95 *
96 *
97 * cmd format:
98 * name strategy
99 *
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700100 * \param cmdOptions Set strategy choice command parameters without leading
101 * 'set-strategy' component
hilata141eaae2014-03-13 19:54:47 -0500102 */
103 void
104 strategyChoiceSet(const char* cmdOptions[]);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700105
hilata141eaae2014-03-13 19:54:47 -0500106 /**
107 * \brief Unset the strategy for a namespace
108 *
109 *
110 * cmd format:
111 * name strategy
112 *
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700113 * \param cmdOptions Unset strategy choice command parameters without leading
114 * 'unset-strategy' component
hilata141eaae2014-03-13 19:54:47 -0500115 */
116 void
117 strategyChoiceUnset(const char* cmdOptions[]);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700118
hilata198cadb2014-02-15 23:46:19 -0600119private:
120 void
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700121 onSuccess(const ControlParameters& parameters,
122 const std::string& message);
hilata198cadb2014-02-15 23:46:19 -0600123
124 void
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700125 onError(uint32_t code, const std::string& error, const std::string& message);
126
hilata198cadb2014-02-15 23:46:19 -0600127public:
128 const char* m_programName;
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700129
130private:
131 Controller m_controller;
hilata198cadb2014-02-15 23:46:19 -0600132};
133
hilata141eaae2014-03-13 19:54:47 -0500134} // namespace nfdc
hilata198cadb2014-02-15 23:46:19 -0600135
136#endif // NFD_TOOLS_NFDC_HPP