blob: 1cbc49ce622b55f6171ad7be0c14d795df2c25de [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
Steve DiBenedettod030cfc2014-03-10 20:04:47 -060035 virtual
36 ~FibManager();
37
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070038 void
39 onFibRequest(const Interest& request);
40
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070041private:
42
43 void
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070044 onValidatedFibRequest(const shared_ptr<const Interest>& request);
45
46 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080047 insertEntry(const FibManagementOptions& options,
48 ControlResponse& response);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070049
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070050
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070051 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080052 deleteEntry(const FibManagementOptions& options,
53 ControlResponse& response);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070054
55 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080056 addNextHop(const FibManagementOptions& options,
57 ControlResponse& response);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070058
59 void
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080060 removeNextHop(const FibManagementOptions& options,
61 ControlResponse& response);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070062
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070063 bool
64 extractOptions(const Interest& request,
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080065 FibManagementOptions& extractedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070066
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070067private:
68
69 Fib& m_managedFib;
70 function<shared_ptr<Face>(FaceId)> m_getFace;
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070071 std::map<Name, shared_ptr<fw::Strategy> > m_namespaceToStrategyMap;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070072
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070073 typedef function<void(FibManager*,
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080074 const FibManagementOptions&,
75 ControlResponse&)> VerbProcessor;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070076
77 typedef std::map<Name::Component, VerbProcessor> VerbDispatchTable;
78
79 typedef std::pair<Name::Component, VerbProcessor> VerbAndProcessor;
80
81
82 const VerbDispatchTable m_verbDispatch;
83
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070084 static const Name COMMAND_PREFIX; // /localhost/nfd/fib
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070085
Steve DiBenedetto80ddc212014-02-01 22:23:56 -070086 // number of components in an invalid, but not malformed, unsigned command.
87 // (/localhost/nfd/fib + verb + options) = 5
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070088 static const size_t COMMAND_UNSIGNED_NCOMPS;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070089
Steve DiBenedetto80ddc212014-02-01 22:23:56 -070090 // number of components in a valid signed Interest.
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070091 // UNSIGNED_NCOMPS + 4 command Interest components = 9
92 static const size_t COMMAND_SIGNED_NCOMPS;
Steve DiBenedetto80ddc212014-02-01 22:23:56 -070093
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070094 static const VerbAndProcessor COMMAND_VERBS[];
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070095
96};
97
98} // namespace nfd
99
100#endif // NFD_MGMT_FIB_MANAGER_HPP