aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/hicn/transport/interfaces/socket_consumer.h
blob: 536d2fde35f89b82bc6f56528c8ec5e53fc4b62c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
 * Copyright (c) 2017-2019 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <hicn/transport/interfaces/socket.h>

#include <hicn/transport/protocols/cbr.h>
#include <hicn/transport/protocols/protocol.h>
#include <hicn/transport/protocols/raaqm.h>
#include <hicn/transport/protocols/rtc.h>
#include <hicn/transport/protocols/vegas.h>

#include <hicn/transport/utils/event_thread.h>
#include <hicn/transport/utils/sharable_vector.h>

#define CONSUMER_FINISHED 0
#define CONSUMER_BUSY 1
#define CONSUMER_RUNNING 2

namespace transport {

namespace interface {

class ConsumerSocket : public BaseSocket {
  friend class protocol::TransportProtocol;
  friend class protocol::VegasTransportProtocol;
  friend class protocol::RaaqmTransportProtocol;
  friend class protocol::CbrTransportProtocol;

 public:
  explicit ConsumerSocket(int protocol);
  explicit ConsumerSocket(int protocol, asio::io_service &io_service);

  ~ConsumerSocket();

  void connect() override;

  int consume(const Name &name, utils::SharableVector<uint8_t> &receive_buffer);

  int asyncConsume(
      const Name &name,
      std::shared_ptr<utils::SharableVector<uint8_t>> receive_buffer);

  void asyncSendInterest(Interest::Ptr &&interest,
                         Portal::ConsumerCallback *callback);

  void stop();

  void resume();

  asio::io_service &getIoService() override;

  int setSocketOption(int socket_option_key,
                      uint32_t socket_option_value) override;

  int setSocketOption(int socket_option_key,
                      double socket_option_value) override;

  int setSocketOption(int socket_option_key, bool socket_option_value) override;

  int setSocketOption(int socket_option_key, Name socket_option_value) override;

  int setSocketOption(int socket_option_key,
                      std::list<Prefix> socket_option_value) override;

  int setSocketOption(
      int socket_option_key,
      ProducerContentObjectCallback socket_option_value) override;

  int setSocketOption(
      int socket_option_key,
      ConsumerContentObjectVerificationCallback socket_option_value) override;

  int setSocketOption(
      int socket_option_key,
      ConsumerContentObjectCallback socket_option_value) override;

  int setSocketOption(int socket_option_key,
                      ConsumerInterestCallback socket_option_value) override;

  int setSocketOption(int socket_option_key,
                      ProducerInterestCallback socket_option_value) override;

  int setSocketOption(int socket_option_key,
                      ConsumerContentCallback socket_option_value) override;

  int setSocketOption(int socket_option_key,
                      ConsumerManifestCallback socket_option_value) override;

  int setSocketOption(int socket_option_key,
                      IcnObserver *socket_option_value) override;

  int setSocketOption(int socket_option_key,
                      HashAlgorithm socket_option_value) override;

  int setSocketOption(int socket_option_key,
                      utils::CryptoSuite crypto_suite) override;

  int setSocketOption(int socket_option_key,
                      const utils::Identity &crypto_suite) override;

  int setSocketOption(int socket_option_key,
                      const std::string &socket_option_value) override;

  int setSocketOption(int socket_option_key,
                      ConsumerTimerCallback socket_option_value) override;

  int setSocketOption(int socket_option_key,
                      ProducerContentCallback socket_option_value) override;

  int getSocketOption(int socket_option_key,
                      uint32_t &socket_option_value) override;

  int getSocketOption(int socket_option_key,
                      double &socket_option_value) override;

  int getSocketOption(int socket_option_key,
                      bool &socket_option_value) override;

  int getSocketOption(int socket_option_key,
                      Name &socket_option_value) override;

  int getSocketOption(int socket_option_key,
                      std::list<Prefix> &socket_option_value) override;

  int getSocketOption(
      int socket_option_key,
      ProducerContentObjectCallback &socket_option_value) override;

  int getSocketOption(
      int socket_option_key,
      ConsumerContentObjectVerificationCallback &socket_option_value) override;

  int getSocketOption(
      int socket_option_key,
      ConsumerContentObjectCallback &socket_option_value) override;

  int getSocketOption(int socket_option_key,
                      ConsumerInterestCallback &socket_option_value) override;

  int getSocketOption(int socket_option_key,
                      ProducerInterestCallback &socket_option_value) override;

  int getSocketOption(int socket_option_key,
                      ConsumerContentCallback &socket_option_value) override;

  int getSocketOption(int socket_option_key,
                      ConsumerManifestCallback &socket_option_value) override;

  int getSocketOption(int socket_option_key,
                      std::shared_ptr<Portal> &socket_option_value) override;

  int getSocketOption(int socket_option_key,
                      IcnObserver **socket_option_value) override;

  int getSocketOption(int socket_option_key,
                      HashAlgorithm &socket_option_value) override;

  int getSocketOption(int socket_option_key,
                      utils::CryptoSuite &crypto_suite) override;

  int getSocketOption(int socket_option_key,
                      utils::Identity &crypto_suite) override;

  int getSocketOption(int socket_option_key,
                      std::string &socket_option_value) override;

  int getSocketOption(int socket_option_key,
                      ConsumerTimerCallback &socket_option_value) override;

  int getSocketOption(int socket_option_key,
                      ProducerContentCallback &socket_option_value) override;

 protected:
  std::shared_ptr<TransportProtocol> transport_protocol_;

 private:
  // context inner state variables
  asio::io_service internal_io_service_;
  asio::io_service &io_service_;

  std::shared_ptr<Portal> portal_;

  utils::EventThread async_downloader_;

  Name network_name_;

  int interest_lifetime_;

  double min_window_size_;
  double max_window_size_;
  double current_window_size_;
  uint32_t max_retransmissions_;
  size_t output_buffer_size_;
  size_t input_buffer_size_;

  // RAAQM Parameters

  double minimum_drop_probability_;
  unsigned int sample_number_;
  double gamma_;
  double beta_;
  double drop_factor_;

  // Rate estimation parameters
  double rate_estimation_alpha_;
  IcnObserver *rate_estimation_observer_;
  int rate_estimation_batching_parameter_;
  int rate_estimation_choice_;

  bool is_async_;

  utils::Verifier verifier_;
  PARCKeyId *key_id_;
  bool verify_signature_;

  std::shared_ptr<utils::SharableVector<uint8_t>> content_buffer_;

  ConsumerInterestCallback on_interest_retransmission_;
  ConsumerInterestCallback on_interest_output_;
  ConsumerInterestCallback on_interest_timeout_;
  ConsumerInterestCallback on_interest_satisfied_;

  ConsumerContentObjectCallback on_content_object_input_;
  ConsumerContentObjectVerificationCallback on_content_object_verification_;

  ConsumerContentObjectCallback on_content_object_;
  ConsumerManifestCallback on_manifest_;

  ConsumerContentCallback on_payload_retrieved_;

  ConsumerTimerCallback on_timer_expires_;

  // Virtual download for traffic generator

  bool virtual_download_;
  bool rtt_stats_;

  Time t0_;
  Time t1_;
  asio::steady_timer timer_;
  uint32_t timer_interval_milliseconds_;
};

}  // namespace interface

}  // end namespace transport