blob: cb7f37bc83d883dd7d58bd4ab1069ca5b0a51629 [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
7#ifndef NDN_MANAGEMENT_NFD_CONTROL_HPP
8#define NDN_MANAGEMENT_NFD_CONTROL_HPP
9
Alexander Afanasyeve289b532014-02-09 22:14:44 -080010#include "controller.hpp"
Alexander Afanasyev884280c2014-03-07 09:40:39 +000011#include "../util/command-interest-generator.hpp"
Alexander Afanasyeve289b532014-02-09 22:14:44 -080012
13namespace ndn {
14
Alexander Afanasyeve289b532014-02-09 22:14:44 -080015namespace nfd {
16
17class FibManagementOptions;
hilataa99e37e2014-02-15 23:52:46 -060018class FaceManagementOptions;
hilata7d160f22014-03-13 19:51:42 -050019class StrategyChoiceOptions;
20
Alexander Afanasyeve289b532014-02-09 22:14:44 -080021class Controller : public ndn::Controller
22{
23public:
24 typedef function<void(const FibManagementOptions&)> FibCommandSucceedCallback;
hilataa99e37e2014-02-15 23:52:46 -060025 typedef function<void(const FaceManagementOptions&)> FaceCommandSucceedCallback;
hilata7d160f22014-03-13 19:51:42 -050026 typedef function<void(const StrategyChoiceOptions&)> StrategyChoiceCommandSucceedCallback;
27
Alexander Afanasyeve289b532014-02-09 22:14:44 -080028 /**
29 * @brief Construct ndnd::Control object
30 */
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080031 Controller(Face& face);
Alexander Afanasyeve289b532014-02-09 22:14:44 -080032
33 virtual void
34 selfRegisterPrefix(const Name& prefixToRegister,
35 const SuccessCallback& onSuccess,
36 const FailCallback& onFail);
37
38 virtual void
Alexander Afanasyev884280c2014-03-07 09:40:39 +000039 selfDeregisterPrefix(const Name& prefixToDeRegister,
Alexander Afanasyeve289b532014-02-09 22:14:44 -080040 const SuccessCallback& onSuccess,
41 const FailCallback& onFail);
42
Alexander Afanasyev884280c2014-03-07 09:40:39 +000043 /**
44 * \brief Adds a nexthop to an existing or new FIB entry
45 *
46 * If FIB entry for the specified prefix does not exist, it will be automatically created.
47 *
48 * \param prefix Prefix of the FIB entry
49 * \param faceId ID of the face which should be added as a next hop for prefix FIB entry.
50 * If a nexthop of same FaceId exists on the FIB entry, its cost is updated.
51 * If FaceId is set to zero, it is implied as the face of the entity sending
52 * this command.
53 * \param cost Cost that should be associated with the next hop
54 * \param onSuccess Callback that will be called when operation succeeds
55 * \param onFail Callback that will be called when operation fails
56 */
57 void
58 fibAddNextHop(const Name& prefix, uint64_t faceId, int cost,
Obaid6e7f5f12014-03-11 14:46:10 -050059 const FibCommandSucceedCallback& onSuccess,
60 const FailCallback& onFail);
Alexander Afanasyev884280c2014-03-07 09:40:39 +000061
62 /**
63 * \brief Remove a nexthop from FIB entry
64 *
65 * If after removal of the nexthop FIB entry has zero next hops, this FIB entry will
66 * be automatically deleted.
67 *
68 * \param prefix Prefix of the FIB entry
69 * \param faceId ID of the face which should be removed FIB entry.
70 * If FaceId is set to zero, it is implied as the face of the entity sending
71 * this command.
72 * \param onSuccess Callback that will be called when operation succeeds
73 * \param onFail Callback that will be called when operation fails
74 */
75 void
76 fibRemoveNextHop(const Name& prefix, uint64_t faceId,
Obaid6e7f5f12014-03-11 14:46:10 -050077 const FibCommandSucceedCallback& onSuccess,
78 const FailCallback& onFail);
Alexander Afanasyev884280c2014-03-07 09:40:39 +000079
hilataa99e37e2014-02-15 23:52:46 -060080protected:
Alexander Afanasyeve289b532014-02-09 22:14:44 -080081 void
82 startFibCommand(const std::string& command,
83 const FibManagementOptions& options,
84 const FibCommandSucceedCallback& onSuccess,
85 const FailCallback& onFailure);
hilataa99e37e2014-02-15 23:52:46 -060086
87 void
88 startFaceCommand(const std::string& command,
89 const FaceManagementOptions& options,
90 const FaceCommandSucceedCallback& onSuccess,
91 const FailCallback& onFailure);
92
hilata7d160f22014-03-13 19:51:42 -050093 void
94 startStrategyChoiceCommand(const std::string& command,
95 const StrategyChoiceOptions& options,
96 const StrategyChoiceCommandSucceedCallback& onSuccess,
97 const FailCallback& onFailure);
98
Alexander Afanasyeve289b532014-02-09 22:14:44 -080099private:
100 void
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800101 processFibCommandResponse(Data& data,
Alexander Afanasyeve289b532014-02-09 22:14:44 -0800102 const FibCommandSucceedCallback& onSuccess,
103 const FailCallback& onFail);
hilataa99e37e2014-02-15 23:52:46 -0600104
105 void
106 processFaceCommandResponse(Data& data,
107 const FaceCommandSucceedCallback& onSuccess,
108 const FailCallback& onFail);
109
hilata7d160f22014-03-13 19:51:42 -0500110 void
111 processStrategyChoiceCommandResponse(Data& data,
112 const StrategyChoiceCommandSucceedCallback& onSuccess,
113 const FailCallback& onFail);
114
hilataa99e37e2014-02-15 23:52:46 -0600115protected:
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800116 Face& m_face;
Alexander Afanasyev884280c2014-03-07 09:40:39 +0000117 CommandInterestGenerator m_commandInterestGenerator;
Alexander Afanasyeve289b532014-02-09 22:14:44 -0800118};
119
120} // namespace nfd
121} // namespace ndn
122
123#endif // NDN_MANAGEMENT_NFD_CONTROL_HPP