blob: aa85656adef014414f829b104dc2403621c81dff [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;
Alexander Afanasyeve289b532014-02-09 22:14:44 -080019
20class Controller : public ndn::Controller
21{
22public:
23 typedef function<void(const FibManagementOptions&)> FibCommandSucceedCallback;
hilataa99e37e2014-02-15 23:52:46 -060024 typedef function<void(const FaceManagementOptions&)> FaceCommandSucceedCallback;
Alexander Afanasyeve289b532014-02-09 22:14:44 -080025
26 /**
27 * @brief Construct ndnd::Control object
28 */
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080029 Controller(Face& face);
Alexander Afanasyeve289b532014-02-09 22:14:44 -080030
31 virtual void
32 selfRegisterPrefix(const Name& prefixToRegister,
33 const SuccessCallback& onSuccess,
34 const FailCallback& onFail);
35
36 virtual void
Alexander Afanasyev884280c2014-03-07 09:40:39 +000037 selfDeregisterPrefix(const Name& prefixToDeRegister,
Alexander Afanasyeve289b532014-02-09 22:14:44 -080038 const SuccessCallback& onSuccess,
39 const FailCallback& onFail);
40
Alexander Afanasyev884280c2014-03-07 09:40:39 +000041 /**
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
hilataa99e37e2014-02-15 23:52:46 -060078protected:
Alexander Afanasyeve289b532014-02-09 22:14:44 -080079 void
80 startFibCommand(const std::string& command,
81 const FibManagementOptions& options,
82 const FibCommandSucceedCallback& onSuccess,
83 const FailCallback& onFailure);
hilataa99e37e2014-02-15 23:52:46 -060084
85 void
86 startFaceCommand(const std::string& command,
87 const FaceManagementOptions& options,
88 const FaceCommandSucceedCallback& onSuccess,
89 const FailCallback& onFailure);
90
Alexander Afanasyeve289b532014-02-09 22:14:44 -080091private:
92 void
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080093 processFibCommandResponse(Data& data,
Alexander Afanasyeve289b532014-02-09 22:14:44 -080094 const FibCommandSucceedCallback& onSuccess,
95 const FailCallback& onFail);
hilataa99e37e2014-02-15 23:52:46 -060096
97 void
98 processFaceCommandResponse(Data& data,
99 const FaceCommandSucceedCallback& onSuccess,
100 const FailCallback& onFail);
101
102protected:
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800103 Face& m_face;
Alexander Afanasyev884280c2014-03-07 09:40:39 +0000104 CommandInterestGenerator m_commandInterestGenerator;
Alexander Afanasyeve289b532014-02-09 22:14:44 -0800105};
106
107} // namespace nfd
108} // namespace ndn
109
110#endif // NDN_MANAGEMENT_NFD_CONTROL_HPP