Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
interest.h
1 /*
2  * Copyright (c) 2017-2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <hicn/transport/core/name.h>
19 #include <hicn/transport/core/packet.h>
20 #include <hicn/transport/utils/shared_ptr_utils.h>
21 
22 #include <set>
23 
24 namespace transport {
25 
26 namespace core {
27 
28 const uint32_t MAX_AGGREGATED_INTEREST = 128;
29 
30 class Interest
31  : public Packet /*, public std::enable_shared_from_this<Interest>*/ {
32  private:
33  struct InterestManifestHeader {
34  /* This can be 16 bits, but we use 32 bits for alignment */
35  uint32_t n_suffixes;
36  /* Followed by the list of prefixes to ask */
37  /* ... */
38  };
39 
40  public:
41  using Ptr = std::shared_ptr<Interest>;
42 
43  Interest(Packet::Format format = HF_INET6_TCP,
44  std::size_t additional_header_size = 0);
45 
46  Interest(const Name &interest_name, Packet::Format format = HF_INET6_TCP,
47  std::size_t additional_header_size = 0);
48 
49  Interest(MemBuf &&buffer);
50 
51  template <typename... Args>
52  Interest(CopyBufferOp op, Args &&... args)
53  : Packet(op, std::forward<Args>(args)...) {
54  if (hicn_interest_get_name(format_, packet_start_,
55  name_.getStructReference()) < 0) {
57  }
58  }
59 
60  template <typename... Args>
61  Interest(WrapBufferOp op, Args &&... args)
62  : Packet(op, std::forward<Args>(args)...) {
63  if (hicn_interest_get_name(format_, packet_start_,
64  name_.getStructReference()) < 0) {
66  }
67  }
68 
69  template <typename... Args>
70  Interest(CreateOp op, Args &&... args)
71  : Packet(op, std::forward<Args>(args)...) {}
72 
73  /* Move constructor */
74  Interest(Interest &&other_interest);
75 
76  /* Copy constructor */
77  Interest(const Interest &other_interest);
78 
79  /* Assginemnt operator */
80  Interest &operator=(const Interest &other);
81 
82  ~Interest();
83 
84  const Name &getName() const override;
85 
86  Name &getWritableName() override;
87 
88  void setName(const Name &name) override;
89 
90  void setLocator(const ip_address_t &ip_address) override;
91 
92  ip_address_t getLocator() const override;
93 
94  void setLifetime(uint32_t lifetime) override;
95 
96  uint32_t getLifetime() const override;
97 
98  bool hasManifest();
99 
100  void appendSuffix(std::uint32_t suffix);
101 
102  void encodeSuffixes();
103 
104  uint32_t *firstSuffix();
105 
106  uint32_t numberOfSuffixes();
107 
108  auto shared_from_this() { return utils::shared_from(this); }
109 
110  private:
111  void resetForHash() override;
112  std::set<uint32_t> suffix_set_;
113 };
114 
115 } // end namespace core
116 
117 } // end namespace transport
transport::core::Packet
Definition: packet.h:51
transport::core::Name
Definition: name.h:45
ip_address_t
Definition: ip_address.h:68
errors::MalformedPacketException
Definition: malformed_packet_exception.h:22
transport::core::Packet::Packet
Packet(Format format=HF_INET6_TCP, std::size_t additional_header_size=0)
transport::core::Interest
Definition: interest.h:30
transport
Definition: forwarder_config.h:32
utils::MemBuf::MemBuf
MemBuf() noexcept