blob: a606100cf6f0bbc10eabf5189a74e3d5bb1f3891 [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>
15#include <vector>
16
17namespace nfdc {
18
19class Controller : public ndn::nfd::Controller
20{
21public:
22 struct Error : public std::runtime_error
23 {
24 Error(const std::string& what) : std::runtime_error(what) {}
25 };
26
27 explicit
28 Controller(ndn::Face& face);
29
30 ~Controller();
31
32 bool
33 dispatch(const std::string& cmd,
34 const char* cmdOptions[],
35 int nOptions);
36 /**
37 * \brief Create a new FIB entry if it doesn't exist
38 *
39 * cmd format:
40 * name
41 *
42 * @param cmdOptions add command without leading 'insert' component
43 */
44 void
45 fibInsert(const char* cmdOptions[]);
46 /**
47 * \brief Delete a FIB entry if it exists
48 *
49 * cmd format:
50 * name
51 *
52 * @param cmdOptions del command without leading 'delete' component
53 */
54 void
55 fibDelete(const char* cmdOptions[]);
56 /**
57 * \brief Adds a nexthop to an existing FIB entry
58 *
59 * If a nexthop of same FaceId exists on the FIB entry, its cost is updated.
60 * FaceId is the FaceId returned in NFD Face Management protocol.
61 * If FaceId is set to zero, it is implied as the face of the entity sending this command.
62 * cmd format:
63 * name faceId cost
64 *
65 * @param cmdOptions addNextHop command without leading 'add-nexthop' component
66 */
67 void
68 fibAddNextHop(const char* cmdOptions[], bool hasCost);
69 /**
70 * \brief Remove a nexthop from an existing FIB entry
71 *
72 * This command removes a nexthop from a FIB entry.
73 * Removing the last nexthop in a FIB entry will not automatically delete the FIB entry.
74 *
75 * cmd format:
76 * name faceId
77 *
78 * @param cmdOptions delNext command without leading 'remove-nexthop' component
79 */
80 void
81 fibRemoveNextHop(const char* cmdOptions[]);
82 /**
83 * \brief Sets a forwarding strategy for a namespace
84 *
85 * This command sets a forwarding strategy for a namespace.
86 *
87 * cmd format:
88 * name strategy
89 *
90 * @param cmdOptions setStrategy command without leading 'setStrategy' component
91 */
92 void
93 fibSetStrategy(const char* cmdOptions[]);
94
95 /**
96 * \brief create new face
97 *
98 * This command allows creation of UDP unicast and TCP faces only.
99 *
100 * cmd format:
101 * uri
102 *
103 * @param cmdOptions create command without leading 'create' component
104 */
105 void
106 faceCreate(const char* cmdOptions[]);
107 /**
108 * \brief destroy a face
109 *
110 * cmd format:
111 * faceId
112 *
113 * @param cmdOptions destroy command without leading 'destroy' component
114 */
115 void
116 faceDestroy(const char* cmdOptions[]);
117
118private:
119 void
120 onFibSuccess(const ndn::nfd::FibManagementOptions& fibOptions, const std::string& message);
121
122 void
123 onFaceSuccess(const ndn::nfd::FaceManagementOptions& faceOptions, const std::string& message);
124
125 void
126 onError(const std::string& error, const std::string& message);
127
128public:
129 const char* m_programName;
130};
131
132}// namespace nfdc
133
134#endif // NFD_TOOLS_NFDC_HPP
135