Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
content_object.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 namespace transport {
23 
24 namespace core {
25 
26 // This class is used just to transfer buffer pointers
27 // without making a copy, as std::vector<> would do
28 
29 class ContentObject : public Packet {
30  public:
31  using Ptr = std::shared_ptr<ContentObject>;
33 
34  ContentObject(Packet::Format format = HF_INET6_TCP,
35  std::size_t additional_header_size = 0);
36 
37  ContentObject(const Name &name, Packet::Format format = HF_INET6_TCP,
38  std::size_t additional_header_size = 0);
39 
40  ContentObject(const Name &name, hicn_format_t format,
41  std::size_t additional_header_size, const uint8_t *payload,
42  std::size_t payload_size);
43 
44  template <typename... Args>
45  ContentObject(CopyBufferOp op, Args &&... args)
46  : Packet(op, std::forward<Args>(args)...) {
47  if (hicn_data_get_name(format_, packet_start_, name_.getStructReference()) <
48  0) {
50  }
51  }
52 
53  template <typename... Args>
54  ContentObject(WrapBufferOp op, Args &&... args)
55  : Packet(op, std::forward<Args>(args)...) {
56  if (hicn_data_get_name(format_, packet_start_, name_.getStructReference()) <
57  0) {
59  }
60  }
61 
62  template <typename... Args>
63  ContentObject(CreateOp op, Args &&... args)
64  : Packet(op, std::forward<Args>(args)...) {
65  if (hicn_data_get_name(format_, packet_start_, name_.getStructReference()) <
66  0) {
68  }
69  }
70 
71  ContentObject(const ContentObject &content_object);
72 
73  ContentObject &operator=(const ContentObject &other);
74 
75  ContentObject(ContentObject &&content_object);
76 
77  ~ContentObject();
78 
79  const Name &getName() const override;
80 
81  Name &getWritableName() override;
82 
83  void setName(const Name &name) override;
84 
85  uint32_t getPathLabel() const;
86 
87  ContentObject &setPathLabel(uint32_t path_label);
88 
89  void setLocator(const ip_address_t &ip_address) override;
90 
91  ip_address_t getLocator() const override;
92 
93  void setLifetime(uint32_t lifetime) override;
94 
95  uint32_t getLifetime() const override;
96 
97  auto shared_from_this() { return utils::shared_from(this); }
98 
99  private:
100  void resetForHash() override;
101 };
102 
103 } // end namespace core
104 
105 } // end namespace transport
transport::core::Packet
Definition: packet.h:51
hicn_header_t
Definition: header.h:91
transport::core::Name
Definition: name.h:45
ip_address_t
Definition: ip_address.h:68
transport::core::ContentObject
Definition: content_object.h:29
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
Definition: forwarder_config.h:32