blob: f6de05f80ac71976a008461e802315f8f198c1a1 [file] [log] [blame]
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080011 */
12
Alexander Afanasyeve289b532014-02-09 22:14:44 -080013#ifndef NDN_MANAGEMENT_NDND_CONTROLLER_HPP
14#define NDN_MANAGEMENT_NDND_CONTROLLER_HPP
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080015
Alexander Afanasyeve289b532014-02-09 22:14:44 -080016#include "controller.hpp"
17
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080018namespace ndn {
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080019namespace ndnd {
20
21class FaceInstance;
22class ForwardingEntry;
23
24/*
25 * @brief Class implementing Face and Prefix management operations for ndnd-tlv
26 *
27 * ndnd::Control should be used when connecting to ndnd-tlv daemon
28 */
Alexander Afanasyeve289b532014-02-09 22:14:44 -080029class Controller : public ndn::Controller
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080030{
31public:
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080032 typedef function<void(const ForwardingEntry&)> PrefixOperationSucceedCallback;
33 typedef function<void(const FaceInstance&)> FaceOperationSucceedCallback;
34
35 /**
36 * @brief Construct ndnd::Control object
37 */
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080038 Controller(Face& face);
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080039
Alexander Afanasyeve289b532014-02-09 22:14:44 -080040 virtual void
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080041 selfRegisterPrefix(const Name& prefixToRegister,
42 const SuccessCallback& onSuccess,
43 const FailCallback& onFail);
44
Alexander Afanasyeve289b532014-02-09 22:14:44 -080045 virtual void
Yingdi Yue66bf2a2014-04-28 17:07:36 -070046 selfRegisterPrefix(const Name& prefixToRegister,
47 const SuccessCallback& onSuccess,
48 const FailCallback& onFail,
49 const IdentityCertificate& certificate)
50 {
51 selfRegisterPrefix(prefixToRegister, onSuccess, onFail);
52 }
53
54 virtual void
55 selfRegisterPrefix(const Name& prefixToRegister,
56 const SuccessCallback& onSuccess,
57 const FailCallback& onFail,
58 const Name& identity)
59 {
60 selfRegisterPrefix(prefixToRegister, onSuccess, onFail);
61 }
62
63 virtual void
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080064 selfDeregisterPrefix(const Name& prefixToRegister,
65 const SuccessCallback& onSuccess,
66 const FailCallback& onFail);
67
Yingdi Yue66bf2a2014-04-28 17:07:36 -070068 virtual void
69 selfDeregisterPrefix(const Name& prefixToRegister,
70 const SuccessCallback& onSuccess,
71 const FailCallback& onFail,
72 const IdentityCertificate& certificate)
73 {
74 selfDeregisterPrefix(prefixToRegister, onSuccess, onFail);
75 }
76
77 virtual void
78 selfDeregisterPrefix(const Name& prefixToRegister,
79 const SuccessCallback& onSuccess,
80 const FailCallback& onFail,
81 const Name& identity)
82 {
83 selfDeregisterPrefix(prefixToRegister, onSuccess, onFail);
84 }
85
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080086protected:
87 void
88 startFaceAction(const FaceInstance& entry,
89 const FaceOperationSucceedCallback& onSuccess,
90 const FailCallback& onFailure);
91
92 void
93 startPrefixAction(const ForwardingEntry& entry,
94 const PrefixOperationSucceedCallback& onSuccess,
95 const FailCallback& onFailure);
96
97private:
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070098 void
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080099 onNdnidFetched(const Interest& interest, Data& data);
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -0800100
101 void
102 recordSelfRegisteredFaceId(const ForwardingEntry& entry,
103 const SuccessCallback& onSuccess);
104
105 void
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800106 processFaceActionResponse(Data& data,
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -0800107 const FaceOperationSucceedCallback& onSuccess,
108 const FailCallback& onFail);
109
110 void
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800111 processPrefixActionResponse(Data& data,
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -0800112 const PrefixOperationSucceedCallback& onSuccess,
113 const FailCallback& onFail);
114
115private:
Alexander Afanasyev0222fba2014-02-09 23:16:02 -0800116 Face& m_face;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -0800117 Block m_ndndId;
118 int64_t m_faceId; // internal face ID (needed for prefix de-registration)
119
120 struct FilterRequest
121 {
122 FilterRequest(const Name& prefixToRegister,
123 const SuccessCallback& onSuccess,
124 const FailCallback& onFailure)
125 : m_prefixToRegister(prefixToRegister)
126 , m_onSuccess(onSuccess)
127 , m_onFailure(onFailure)
128 {
129 }
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -0700130
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -0800131 Name m_prefixToRegister;
132 SuccessCallback m_onSuccess;
133 FailCallback m_onFailure;
134 };
135
136 typedef std::list<FilterRequest> FilterRequestList;
137 FilterRequestList m_filterRequests;
138};
139
140} // namespace ndnd
141} // namespace ndn
142
Alexander Afanasyeve289b532014-02-09 22:14:44 -0800143#endif // NDN_MANAGEMENT_NDND_CONTROLLER_HPP