IceFlow NDN-based stream processing library written in C++
Loading...
Searching...
No Matches
iceflow.hpp
1/*
2 * Copyright 2024 The IceFlow Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 */
18
19#ifndef ICEFLOW_HPP
20#define ICEFLOW_HPP
21
22#include "congestion-reporter.hpp"
23#include "consumer.hpp"
24#include "dag-parser.hpp"
25#include "producer.hpp"
26
27#include "ndn-svs/security-options.hpp"
28#include "ndn-svs/svspubsub.hpp"
29
30#include <chrono>
31#include <iostream>
32#include <thread>
33#include <unordered_map>
34
35namespace iceflow {
36
37typedef std::function<void(const std::string &, std::vector<uint8_t>)>
38 ProducerCallback;
39typedef std::function<void(std::vector<uint8_t>, ProducerCallback)>
40 ProsumerCallback;
41
50class IceFlow {
51public:
56 IceFlow(DAGParser dagParser, const std::string &nodeName, ndn::Face &face);
57
58 IceFlow(DAGParser dagParser, const std::string &nodeName, ndn::Face &face,
59 std::shared_ptr<CongestionReporter> congestionReporter);
60
61 IceFlow(const std::string &dagFileName, const std::string &nodeName,
62 ndn::Face &face);
63
64 IceFlow(const std::string &dagFileName, const std::string &nodeName,
65 ndn::Face &face,
66 std::shared_ptr<CongestionReporter> congestionReporter);
67
68private:
69 IceFlow(
70 DAGParser dagParser, const std::string &nodeName, ndn::Face &face,
71 std::optional<std::shared_ptr<CongestionReporter>> congestionReporter);
72
73 IceFlow(
74 const std::string &dagFileName, const std::string &nodeName,
75 ndn::Face &face,
76 std::optional<std::shared_ptr<CongestionReporter>> congestionReporter);
77
78public:
79 void run();
80
81 void shutdown();
82
83 const std::string &getNodePrefix();
84
85 const std::string &getSyncPrefix();
86
87 void pushData(const std::string &downstreamEdgeName,
88 std::vector<uint8_t> payload);
89
90 void registerConsumerCallback(const std::string &upstreamEdgeName,
91 ConsumerCallback consumerCallback);
92
93 void registerProsumerCallback(const std::string &upstreamEdgeName,
94 ProsumerCallback prosumerCallback);
95
96 void repartitionConsumer(const std::string &upstreamEdgeName,
97 std::vector<uint32_t> partitions);
98
99 void repartitionProducer(const std::string &downstreamEdgeName,
100 uint64_t numberOfPartitions);
101
102 std::unordered_map<std::string, EdgeConsumptionStats> getConsumerStats();
103
104 std::unordered_map<std::string, EdgeProductionStats> getProducerStats();
105
106 void reportCongestion(const std::string &edgeName,
107 CongestionReason congestionReason);
108
109 std::vector<Edge> getDownstreamEdges();
110
111 std::optional<Edge> getDownstreamEdge(uint32_t index);
112
113 std::vector<Edge> getUpstreamEdges();
114
115 std::optional<Edge> getUpstreamEdge(uint32_t index);
116
117 nlohmann::json::object_t getApplicationConfiguration() {
118 return m_node.applicationConfiguration;
119 }
120
121 template <typename T>
122 std::optional<T> getApplicationParameter(const std::string &key) {
123 auto applicationConfiguration = getApplicationConfiguration();
124
125 if (!applicationConfiguration.contains(key)) {
126 return std::nullopt;
127 }
128
129 try {
130 auto value = applicationConfiguration.at(key).get<T>();
131 return std::optional(value);
132 } catch (...) {
133 return std::nullopt;
134 }
135 }
136
137private:
138 void
139 onMissingData(const std::vector<ndn::svs::MissingDataInfo> &missing_data);
140
141private:
142 ndn::KeyChain m_keyChain;
143 ndn::Face &m_face;
144
145 bool m_running = false;
146
147 std::shared_ptr<ndn::svs::SVSPubSub> m_svsPubSub;
148
149 std::string m_nodePrefix;
150 std::string m_syncPrefix;
151
152 std::unordered_map<std::string, IceflowProducer> m_iceflowProducers;
153
154 std::unordered_map<std::string, IceflowConsumer> m_iceflowConsumers;
155
156 std::optional<std::shared_ptr<CongestionReporter>> m_congestionReporter;
157
158 Node m_node;
159
160 std::vector<Edge> m_downstreamEdges;
161
162 std::vector<Edge> m_upstreamEdges;
163};
164
165} // namespace iceflow
166
167#endif // ICEFLOW_HPP
Definition dag-parser.hpp:74
Definition iceflow.hpp:50
IceFlow(DAGParser dagParser, const std::string &nodeName, ndn::Face &face)
Definition iceflow.cpp:37
Definition dag-parser.hpp:60