Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 10 | #include "controller.hpp" |
Alexander Afanasyev | 884280c | 2014-03-07 09:40:39 +0000 | [diff] [blame^] | 11 | #include "../util/command-interest-generator.hpp" |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 12 | |
| 13 | namespace ndn { |
| 14 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 15 | namespace nfd { |
| 16 | |
| 17 | class FibManagementOptions; |
hilata | a99e37e | 2014-02-15 23:52:46 -0600 | [diff] [blame] | 18 | class FaceManagementOptions; |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 19 | |
| 20 | class Controller : public ndn::Controller |
| 21 | { |
| 22 | public: |
| 23 | typedef function<void(const FibManagementOptions&)> FibCommandSucceedCallback; |
hilata | a99e37e | 2014-02-15 23:52:46 -0600 | [diff] [blame] | 24 | typedef function<void(const FaceManagementOptions&)> FaceCommandSucceedCallback; |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * @brief Construct ndnd::Control object |
| 28 | */ |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 29 | Controller(Face& face); |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 30 | |
| 31 | virtual void |
| 32 | selfRegisterPrefix(const Name& prefixToRegister, |
| 33 | const SuccessCallback& onSuccess, |
| 34 | const FailCallback& onFail); |
| 35 | |
| 36 | virtual void |
Alexander Afanasyev | 884280c | 2014-03-07 09:40:39 +0000 | [diff] [blame^] | 37 | selfDeregisterPrefix(const Name& prefixToDeRegister, |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 38 | const SuccessCallback& onSuccess, |
| 39 | const FailCallback& onFail); |
| 40 | |
Alexander Afanasyev | 884280c | 2014-03-07 09:40:39 +0000 | [diff] [blame^] | 41 | /** |
| 42 | * \brief Adds a nexthop to an existing or new FIB entry |
| 43 | * |
| 44 | * If FIB entry for the specified prefix does not exist, it will be automatically created. |
| 45 | * |
| 46 | * \param prefix Prefix of the FIB entry |
| 47 | * \param faceId ID of the face which should be added as a next hop for prefix FIB entry. |
| 48 | * If a nexthop of same FaceId exists on the FIB entry, its cost is updated. |
| 49 | * If FaceId is set to zero, it is implied as the face of the entity sending |
| 50 | * this command. |
| 51 | * \param cost Cost that should be associated with the next hop |
| 52 | * \param onSuccess Callback that will be called when operation succeeds |
| 53 | * \param onFail Callback that will be called when operation fails |
| 54 | */ |
| 55 | void |
| 56 | fibAddNextHop(const Name& prefix, uint64_t faceId, int cost, |
| 57 | const SuccessCallback& onSuccess, |
| 58 | const FailCallback& onFail); |
| 59 | |
| 60 | /** |
| 61 | * \brief Remove a nexthop from FIB entry |
| 62 | * |
| 63 | * If after removal of the nexthop FIB entry has zero next hops, this FIB entry will |
| 64 | * be automatically deleted. |
| 65 | * |
| 66 | * \param prefix Prefix of the FIB entry |
| 67 | * \param faceId ID of the face which should be removed FIB entry. |
| 68 | * If FaceId is set to zero, it is implied as the face of the entity sending |
| 69 | * this command. |
| 70 | * \param onSuccess Callback that will be called when operation succeeds |
| 71 | * \param onFail Callback that will be called when operation fails |
| 72 | */ |
| 73 | void |
| 74 | fibRemoveNextHop(const Name& prefix, uint64_t faceId, |
| 75 | const SuccessCallback& onSuccess, |
| 76 | const FailCallback& onFail); |
| 77 | |
hilata | a99e37e | 2014-02-15 23:52:46 -0600 | [diff] [blame] | 78 | protected: |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 79 | void |
| 80 | startFibCommand(const std::string& command, |
| 81 | const FibManagementOptions& options, |
| 82 | const FibCommandSucceedCallback& onSuccess, |
| 83 | const FailCallback& onFailure); |
hilata | a99e37e | 2014-02-15 23:52:46 -0600 | [diff] [blame] | 84 | |
| 85 | void |
| 86 | startFaceCommand(const std::string& command, |
| 87 | const FaceManagementOptions& options, |
| 88 | const FaceCommandSucceedCallback& onSuccess, |
| 89 | const FailCallback& onFailure); |
| 90 | |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 91 | private: |
| 92 | void |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 93 | processFibCommandResponse(Data& data, |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 94 | const FibCommandSucceedCallback& onSuccess, |
| 95 | const FailCallback& onFail); |
hilata | a99e37e | 2014-02-15 23:52:46 -0600 | [diff] [blame] | 96 | |
| 97 | void |
| 98 | processFaceCommandResponse(Data& data, |
| 99 | const FaceCommandSucceedCallback& onSuccess, |
| 100 | const FailCallback& onFail); |
| 101 | |
| 102 | protected: |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 103 | Face& m_face; |
Alexander Afanasyev | 884280c | 2014-03-07 09:40:39 +0000 | [diff] [blame^] | 104 | CommandInterestGenerator m_commandInterestGenerator; |
Alexander Afanasyev | e289b53 | 2014-02-09 22:14:44 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | } // namespace nfd |
| 108 | } // namespace ndn |
| 109 | |
| 110 | #endif // NDN_MANAGEMENT_NFD_CONTROL_HPP |