blob: 10b4fb25832e8320fdae9241afe4785921b7e29d [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"
Steve DiBenedetto6214e562014-03-15 16:27:04 -060015#include "mgmt/fib-enumeration-publisher.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070016
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080017#include <ndn-cpp-dev/management/nfd-fib-management-options.hpp>
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070018
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070019namespace nfd {
20
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080021using ndn::nfd::FibManagementOptions;
22
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070023class Forwarder;
24class Fib;
25
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070026const std::string FIB_PRIVILEGE = "fib"; // config file privilege name
27
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070028class FibManager : public ManagerBase
29{
30public:
31
Steve DiBenedetto3970c892014-01-31 23:31:13 -070032 FibManager(Fib& fib,
33 function<shared_ptr<Face>(FaceId)> getFace,
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070034 shared_ptr<InternalFace> face);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070035
Steve DiBenedettod030cfc2014-03-10 20:04:47 -060036 virtual
37 ~FibManager();
38
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070039 void
40 onFibRequest(const Interest& request);
41
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070042private:
43
44 void
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070045 onValidatedFibRequest(const shared_ptr<const Interest>& request);
46
47 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080048 insertEntry(const FibManagementOptions& options,
49 ControlResponse& response);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070050
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070051
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070052 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080053 deleteEntry(const FibManagementOptions& options,
54 ControlResponse& response);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070055
56 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080057 addNextHop(const FibManagementOptions& options,
58 ControlResponse& response);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070059
60 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080061 removeNextHop(const FibManagementOptions& options,
62 ControlResponse& response);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070063
Steve DiBenedetto6214e562014-03-15 16:27:04 -060064 void
65 listEntries(const Interest& request);
66
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070067 bool
68 extractOptions(const Interest& request,
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080069 FibManagementOptions& extractedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070070
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070071private:
72
73 Fib& m_managedFib;
74 function<shared_ptr<Face>(FaceId)> m_getFace;
Steve DiBenedetto6214e562014-03-15 16:27:04 -060075 FibEnumerationPublisher m_fibEnumerationPublisher;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070076
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070077 typedef function<void(FibManager*,
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080078 const FibManagementOptions&,
Steve DiBenedetto6214e562014-03-15 16:27:04 -060079 ControlResponse&)> SignedVerbProcessor;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070080
Steve DiBenedetto6214e562014-03-15 16:27:04 -060081 typedef std::map<Name::Component, SignedVerbProcessor> SignedVerbDispatchTable;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070082
Steve DiBenedetto6214e562014-03-15 16:27:04 -060083 typedef std::pair<Name::Component, SignedVerbProcessor> SignedVerbAndProcessor;
84
85 typedef function<void(FibManager*, const Interest&)> UnsignedVerbProcessor;
86
87 typedef std::map<Name::Component, UnsignedVerbProcessor> UnsignedVerbDispatchTable;
88 typedef std::pair<Name::Component, UnsignedVerbProcessor> UnsignedVerbAndProcessor;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070089
90
Steve DiBenedetto6214e562014-03-15 16:27:04 -060091 const SignedVerbDispatchTable m_signedVerbDispatch;
92 const UnsignedVerbDispatchTable m_unsignedVerbDispatch;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070093
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070094 static const Name COMMAND_PREFIX; // /localhost/nfd/fib
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070095
Steve DiBenedetto80ddc212014-02-01 22:23:56 -070096 // number of components in an invalid, but not malformed, unsigned command.
97 // (/localhost/nfd/fib + verb + options) = 5
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070098 static const size_t COMMAND_UNSIGNED_NCOMPS;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070099
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700100 // number of components in a valid signed Interest.
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700101 // UNSIGNED_NCOMPS + 4 command Interest components = 9
102 static const size_t COMMAND_SIGNED_NCOMPS;
Steve DiBenedetto80ddc212014-02-01 22:23:56 -0700103
Steve DiBenedetto6214e562014-03-15 16:27:04 -0600104 static const SignedVerbAndProcessor SIGNED_COMMAND_VERBS[];
105 static const UnsignedVerbAndProcessor UNSIGNED_COMMAND_VERBS[];
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700106
Steve DiBenedetto6214e562014-03-15 16:27:04 -0600107 static const Name LIST_COMMAND_PREFIX;
108 static const size_t LIST_COMMAND_NCOMPS;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700109};
110
111} // namespace nfd
112
113#endif // NFD_MGMT_FIB_MANAGER_HPP