blob: fa131fbdadeaf35e7a73252a553019667b27247d [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>
13#include <ndn-cpp-dev/management/nfd-fib-management-options.hpp>
14#include <ndn-cpp-dev/management/nfd-face-management-options.hpp>
hilata141eaae2014-03-13 19:54:47 -050015#include <ndn-cpp-dev/management/nfd-strategy-choice-options.hpp>
hilata198cadb2014-02-15 23:46:19 -060016#include <vector>
17
18namespace nfdc {
19
20class Controller : public ndn::nfd::Controller
21{
22public:
23 struct Error : public std::runtime_error
24 {
25 Error(const std::string& what) : std::runtime_error(what) {}
26 };
27
28 explicit
29 Controller(ndn::Face& face);
30
31 ~Controller();
32
33 bool
34 dispatch(const std::string& cmd,
35 const char* cmdOptions[],
36 int nOptions);
37 /**
hilatadc947ec2014-03-10 12:48:31 -050038 * \brief Adds a nexthop to a FIB entry.
39 *
40 * If the FIB entry does not exist, it is inserted automatically
hilata198cadb2014-02-15 23:46:19 -060041 *
42 * cmd format:
43 * name
44 *
45 * @param cmdOptions add command without leading 'insert' component
46 */
47 void
hilata198cadb2014-02-15 23:46:19 -060048 fibAddNextHop(const char* cmdOptions[], bool hasCost);
49 /**
hilatadc947ec2014-03-10 12:48:31 -050050 * \brief Removes a nexthop from an existing FIB entry
hilata198cadb2014-02-15 23:46:19 -060051 *
hilatadc947ec2014-03-10 12:48:31 -050052 * If the last nexthop record in a FIB entry is removed, the FIB entry is also deleted
hilata198cadb2014-02-15 23:46:19 -060053 *
54 * cmd format:
55 * name faceId
56 *
57 * @param cmdOptions delNext command without leading 'remove-nexthop' component
58 */
59 void
hilata141eaae2014-03-13 19:54:47 -050060 fibRemoveNextHop(const char* cmdOptions[]);
hilata198cadb2014-02-15 23:46:19 -060061 /**
62 * \brief create new face
63 *
hilatadc947ec2014-03-10 12:48:31 -050064 * This command allows creation of UDP unicast and TCP faces only.
hilata198cadb2014-02-15 23:46:19 -060065 *
66 * cmd format:
67 * uri
68 *
69 * @param cmdOptions create command without leading 'create' component
70 */
71 void
72 faceCreate(const char* cmdOptions[]);
73 /**
74 * \brief destroy a face
75 *
76 * cmd format:
77 * faceId
78 *
79 * @param cmdOptions destroy command without leading 'destroy' component
80 */
81 void
82 faceDestroy(const char* cmdOptions[]);
hilata141eaae2014-03-13 19:54:47 -050083 /**
84 * \brief Set the strategy for a namespace
85 *
86 *
87 * cmd format:
88 * name strategy
89 *
90 * @param cmdOptions Set command without leading 'Unset' component
91 */
92 void
93 strategyChoiceSet(const char* cmdOptions[]);
94 /**
95 * \brief Unset the strategy for a namespace
96 *
97 *
98 * cmd format:
99 * name strategy
100 *
101 * @param cmdOptions Unset command without leading 'Unset' component
102 */
103 void
104 strategyChoiceUnset(const char* cmdOptions[]);
105
hilata198cadb2014-02-15 23:46:19 -0600106private:
107 void
hilata141eaae2014-03-13 19:54:47 -0500108 onFibSuccess(const ndn::nfd::FibManagementOptions& fibOptions,
109 const std::string& message);
hilata198cadb2014-02-15 23:46:19 -0600110
111 void
hilata141eaae2014-03-13 19:54:47 -0500112 onFaceSuccess(const ndn::nfd::FaceManagementOptions& faceOptions,
113 const std::string& message);
hilata198cadb2014-02-15 23:46:19 -0600114
115 void
hilata141eaae2014-03-13 19:54:47 -0500116 onSetStrategySuccess(const ndn::nfd::StrategyChoiceOptions& resp,
117 const std::string& message);
118 void
hilata198cadb2014-02-15 23:46:19 -0600119 onError(const std::string& error, const std::string& message);
120
121public:
122 const char* m_programName;
123};
124
hilata141eaae2014-03-13 19:54:47 -0500125} // namespace nfdc
hilata198cadb2014-02-15 23:46:19 -0600126
127#endif // NFD_TOOLS_NFDC_HPP
128