blob: 319f9958ef0ae7b85c78b2c91a09ea987dcbeb26 [file] [log] [blame]
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -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
Alexander Afanasyeve289b532014-02-09 22:14:44 -08007#ifndef NDN_MANAGEMENT_NDND_CONTROLLER_HPP
8#define NDN_MANAGEMENT_NDND_CONTROLLER_HPP
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -08009
10#include "../common.hpp"
Alexander Afanasyeve289b532014-02-09 22:14:44 -080011#include "controller.hpp"
12
13#include "../name.hpp"
14#include "../interest.hpp"
15#include "../data.hpp"
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080016
17namespace ndn {
18
19class Node;
20
21namespace ndnd {
22
23class FaceInstance;
24class ForwardingEntry;
25
26/*
27 * @brief Class implementing Face and Prefix management operations for ndnd-tlv
28 *
29 * ndnd::Control should be used when connecting to ndnd-tlv daemon
30 */
Alexander Afanasyeve289b532014-02-09 22:14:44 -080031class Controller : public ndn::Controller
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080032{
33public:
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080034 typedef function<void(const ForwardingEntry&)> PrefixOperationSucceedCallback;
35 typedef function<void(const FaceInstance&)> FaceOperationSucceedCallback;
36
37 /**
38 * @brief Construct ndnd::Control object
39 */
Alexander Afanasyeve289b532014-02-09 22:14:44 -080040 Controller(Node& face);
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080041
Alexander Afanasyeve289b532014-02-09 22:14:44 -080042 virtual void
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080043 selfRegisterPrefix(const Name& prefixToRegister,
44 const SuccessCallback& onSuccess,
45 const FailCallback& onFail);
46
Alexander Afanasyeve289b532014-02-09 22:14:44 -080047 virtual void
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080048 selfDeregisterPrefix(const Name& prefixToRegister,
49 const SuccessCallback& onSuccess,
50 const FailCallback& onFail);
51
52protected:
53 void
54 startFaceAction(const FaceInstance& entry,
55 const FaceOperationSucceedCallback& onSuccess,
56 const FailCallback& onFailure);
57
58 void
59 startPrefixAction(const ForwardingEntry& entry,
60 const PrefixOperationSucceedCallback& onSuccess,
61 const FailCallback& onFailure);
62
63private:
64 void
65 onNdnidFetched(const shared_ptr<const Interest>& interest,
66 const shared_ptr<Data>& data);
67
68
69 void
70 recordSelfRegisteredFaceId(const ForwardingEntry& entry,
71 const SuccessCallback& onSuccess);
72
73 void
74 processFaceActionResponse(const shared_ptr<Data>& data,
75 const FaceOperationSucceedCallback& onSuccess,
76 const FailCallback& onFail);
77
78 void
79 processPrefixActionResponse(const shared_ptr<Data>& data,
80 const PrefixOperationSucceedCallback& onSuccess,
81 const FailCallback& onFail);
82
83private:
84 Node& m_face;
85 Block m_ndndId;
86 int64_t m_faceId; // internal face ID (needed for prefix de-registration)
87
88 struct FilterRequest
89 {
90 FilterRequest(const Name& prefixToRegister,
91 const SuccessCallback& onSuccess,
92 const FailCallback& onFailure)
93 : m_prefixToRegister(prefixToRegister)
94 , m_onSuccess(onSuccess)
95 , m_onFailure(onFailure)
96 {
97 }
98
99 Name m_prefixToRegister;
100 SuccessCallback m_onSuccess;
101 FailCallback m_onFailure;
102 };
103
104 typedef std::list<FilterRequest> FilterRequestList;
105 FilterRequestList m_filterRequests;
106};
107
108} // namespace ndnd
109} // namespace ndn
110
Alexander Afanasyeve289b532014-02-09 22:14:44 -0800111#endif // NDN_MANAGEMENT_NDND_CONTROLLER_HPP