blob: 43b410e6e7c8c778f0dbf35c7618043bc4ae4a57 [file] [log] [blame]
Steve DiBenedetto042bfe92014-01-30 15:05:08 -07001/* -*- 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_MGMT_FIB_MANAGER_HPP
8#define NFD_MGMT_FIB_MANAGER_HPP
9
10#include "common.hpp"
11#include "face/face.hpp"
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070012#include "mgmt/app-face.hpp"
13#include "fw/strategy.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070014#include "mgmt/manager-base.hpp"
15
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080016#include <ndn-cpp-dev/management/nfd-fib-management-options.hpp>
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070017
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070018namespace nfd {
19
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080020using ndn::nfd::FibManagementOptions;
21
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070022class Forwarder;
23class Fib;
24
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070025const std::string FIB_PRIVILEGE = "fib"; // config file privilege name
26
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070027class FibManager : public ManagerBase
28{
29public:
30
Steve DiBenedetto3970c892014-01-31 23:31:13 -070031 FibManager(Fib& fib,
32 function<shared_ptr<Face>(FaceId)> getFace,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070033 shared_ptr<InternalFace> face);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070034
35 void
36 onFibRequest(const Interest& request);
37
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070038private:
39
40 void
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070041 onValidatedFibRequest(const shared_ptr<const Interest>& request);
42
43 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080044 insertEntry(const FibManagementOptions& options,
45 ControlResponse& response);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070046
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070047
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070048 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080049 deleteEntry(const FibManagementOptions& options,
50 ControlResponse& response);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070051
52 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080053 addNextHop(const FibManagementOptions& options,
54 ControlResponse& response);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070055
56 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080057 removeNextHop(const FibManagementOptions& options,
58 ControlResponse& response);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070059
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070060 bool
61 extractOptions(const Interest& request,
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080062 FibManagementOptions& extractedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070063
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070064private:
65
66 Fib& m_managedFib;
67 function<shared_ptr<Face>(FaceId)> m_getFace;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070068 std::map<Name, shared_ptr<fw::Strategy> > m_namespaceToStrategyMap;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070069
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070070 typedef function<void(FibManager*,
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080071 const FibManagementOptions&,
72 ControlResponse&)> VerbProcessor;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070073
74 typedef std::map<Name::Component, VerbProcessor> VerbDispatchTable;
75
76 typedef std::pair<Name::Component, VerbProcessor> VerbAndProcessor;
77
78
79 const VerbDispatchTable m_verbDispatch;
80
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070081 static const Name COMMAND_PREFIX; // /localhost/nfd/fib
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070082
Steve DiBenedetto80ddc212014-02-01 22:23:56 -070083 // number of components in an invalid, but not malformed, unsigned command.
84 // (/localhost/nfd/fib + verb + options) = 5
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070085 static const size_t COMMAND_UNSIGNED_NCOMPS;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070086
Steve DiBenedetto80ddc212014-02-01 22:23:56 -070087 // number of components in a valid signed Interest.
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070088 // UNSIGNED_NCOMPS + 4 command Interest components = 9
89 static const size_t COMMAND_SIGNED_NCOMPS;
Steve DiBenedetto80ddc212014-02-01 22:23:56 -070090
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070091 static const VerbAndProcessor COMMAND_VERBS[];
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070092
93};
94
95} // namespace nfd
96
97#endif // NFD_MGMT_FIB_MANAGER_HPP