blob: f3ab11648ac110c519e90351e0bf38542011000b [file] [log] [blame]
Alexander Afanasyeve289b532014-02-09 22:14:44 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * See COPYING for copyright and distribution information.
5 */
6
Alexander Afanasyev26c24d22014-03-20 09:31:21 -07007#ifndef NDN_MANAGEMENT_NFD_CONTROLLER_HPP
8#define NDN_MANAGEMENT_NFD_CONTROLLER_HPP
Alexander Afanasyeve289b532014-02-09 22:14:44 -08009
Alexander Afanasyeve289b532014-02-09 22:14:44 -080010#include "controller.hpp"
Junxiao Shibc19b372014-03-23 16:59:25 -070011#include "nfd-control-parameters.hpp"
Alexander Afanasyev884280c2014-03-07 09:40:39 +000012#include "../util/command-interest-generator.hpp"
Alexander Afanasyeve289b532014-02-09 22:14:44 -080013
14namespace ndn {
15
Alexander Afanasyeve289b532014-02-09 22:14:44 -080016namespace nfd {
17
Alexander Afanasyeve289b532014-02-09 22:14:44 -080018class Controller : public ndn::Controller
19{
20public:
21 typedef function<void(const FibManagementOptions&)> FibCommandSucceedCallback;
hilataa99e37e2014-02-15 23:52:46 -060022 typedef function<void(const FaceManagementOptions&)> FaceCommandSucceedCallback;
hilata7d160f22014-03-13 19:51:42 -050023 typedef function<void(const StrategyChoiceOptions&)> StrategyChoiceCommandSucceedCallback;
Junxiao Shibc19b372014-03-23 16:59:25 -070024
Alexander Afanasyeve289b532014-02-09 22:14:44 -080025 /**
26 * @brief Construct ndnd::Control object
27 */
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080028 Controller(Face& face);
Alexander Afanasyeve289b532014-02-09 22:14:44 -080029
30 virtual void
31 selfRegisterPrefix(const Name& prefixToRegister,
32 const SuccessCallback& onSuccess,
33 const FailCallback& onFail);
34
35 virtual void
Alexander Afanasyev884280c2014-03-07 09:40:39 +000036 selfDeregisterPrefix(const Name& prefixToDeRegister,
Alexander Afanasyeve289b532014-02-09 22:14:44 -080037 const SuccessCallback& onSuccess,
38 const FailCallback& onFail);
39
Alexander Afanasyev884280c2014-03-07 09:40:39 +000040 /**
41 * \brief Adds a nexthop to an existing or new FIB entry
42 *
43 * If FIB entry for the specified prefix does not exist, it will be automatically created.
44 *
45 * \param prefix Prefix of the FIB entry
46 * \param faceId ID of the face which should be added as a next hop for prefix FIB entry.
47 * If a nexthop of same FaceId exists on the FIB entry, its cost is updated.
48 * If FaceId is set to zero, it is implied as the face of the entity sending
49 * this command.
50 * \param cost Cost that should be associated with the next hop
51 * \param onSuccess Callback that will be called when operation succeeds
52 * \param onFail Callback that will be called when operation fails
53 */
54 void
55 fibAddNextHop(const Name& prefix, uint64_t faceId, int cost,
Obaid6e7f5f12014-03-11 14:46:10 -050056 const FibCommandSucceedCallback& onSuccess,
57 const FailCallback& onFail);
Alexander Afanasyev884280c2014-03-07 09:40:39 +000058
59 /**
60 * \brief Remove a nexthop from FIB entry
61 *
62 * If after removal of the nexthop FIB entry has zero next hops, this FIB entry will
63 * be automatically deleted.
64 *
65 * \param prefix Prefix of the FIB entry
66 * \param faceId ID of the face which should be removed FIB entry.
67 * If FaceId is set to zero, it is implied as the face of the entity sending
68 * this command.
69 * \param onSuccess Callback that will be called when operation succeeds
70 * \param onFail Callback that will be called when operation fails
71 */
72 void
73 fibRemoveNextHop(const Name& prefix, uint64_t faceId,
Obaid6e7f5f12014-03-11 14:46:10 -050074 const FibCommandSucceedCallback& onSuccess,
75 const FailCallback& onFail);
Alexander Afanasyev884280c2014-03-07 09:40:39 +000076
hilataa99e37e2014-02-15 23:52:46 -060077protected:
Alexander Afanasyeve289b532014-02-09 22:14:44 -080078 void
79 startFibCommand(const std::string& command,
80 const FibManagementOptions& options,
81 const FibCommandSucceedCallback& onSuccess,
82 const FailCallback& onFailure);
hilataa99e37e2014-02-15 23:52:46 -060083
84 void
85 startFaceCommand(const std::string& command,
86 const FaceManagementOptions& options,
87 const FaceCommandSucceedCallback& onSuccess,
88 const FailCallback& onFailure);
89
hilata7d160f22014-03-13 19:51:42 -050090 void
91 startStrategyChoiceCommand(const std::string& command,
92 const StrategyChoiceOptions& options,
93 const StrategyChoiceCommandSucceedCallback& onSuccess,
94 const FailCallback& onFailure);
Junxiao Shibc19b372014-03-23 16:59:25 -070095
Alexander Afanasyeve289b532014-02-09 22:14:44 -080096private:
97 void
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080098 processFibCommandResponse(Data& data,
Alexander Afanasyeve289b532014-02-09 22:14:44 -080099 const FibCommandSucceedCallback& onSuccess,
100 const FailCallback& onFail);
hilataa99e37e2014-02-15 23:52:46 -0600101
102 void
103 processFaceCommandResponse(Data& data,
104 const FaceCommandSucceedCallback& onSuccess,
105 const FailCallback& onFail);
106
hilata7d160f22014-03-13 19:51:42 -0500107 void
108 processStrategyChoiceCommandResponse(Data& data,
109 const StrategyChoiceCommandSucceedCallback& onSuccess,
110 const FailCallback& onFail);
111
hilataa99e37e2014-02-15 23:52:46 -0600112protected:
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800113 Face& m_face;
Alexander Afanasyev884280c2014-03-07 09:40:39 +0000114 CommandInterestGenerator m_commandInterestGenerator;
Alexander Afanasyeve289b532014-02-09 22:14:44 -0800115};
116
117} // namespace nfd
118} // namespace ndn
119
Alexander Afanasyev26c24d22014-03-20 09:31:21 -0700120#endif // NDN_MANAGEMENT_NFD_CONTROLLER_HPP