Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
endpoint.h
1 /*
2  * Copyright (c) 2021 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/asio_wrapper.h>
19 
20 namespace transport {
21 
22 namespace core {
23 
24 const uint16_t INVALID_PORT = 0xffff;
25 
26 class Endpoint {
27  public:
28  Endpoint() : address_(), port_(INVALID_PORT) {}
29 
30  Endpoint(const Endpoint &other)
31  : address_(other.address_), port_(other.port_) {}
32 
33  Endpoint(Endpoint &&other)
34  : address_(std::move(other.address_)), port_(other.port_) {}
35 
36  Endpoint(std::string ip_address, uint32_t port)
37  : address_(asio::ip::address::from_string(ip_address)), port_(port) {}
38 
39  Endpoint(asio::ip::udp::endpoint endpoint)
40  : address_(endpoint.address()), port_(endpoint.port()) {}
41 
42  ~Endpoint() = default;
43 
44  Endpoint &operator=(const Endpoint &other) {
45  address_ = other.address_;
46  port_ = other.port_;
47  return *this;
48  }
49 
50  Endpoint &operator=(Endpoint &&other) {
51  address_ = std::move(other.address_);
52  port_ = std::move(other.port_);
53  return *this;
54  }
55 
56 #if 0
57  template <typename Ip, typename Port>
58  Endpoint(Ip &&ip_address, Port &&port)
59  : address_(std::forward<Ip &&>(ip_address)),
60  port_(std::forward<Port &&>(port)) {}
61 #endif
62 
63  asio::ip::address getAddress() { return address_; }
64  uint16_t getPort() { return port_; }
65 
66  void setAddress(uint32_t address) {
67  address_ = asio::ip::address(asio::ip::address_v4(address));
68  }
69 
70  void setPort(uint16_t port) { port_ = port; }
71 
72  private:
73  asio::ip::address address_;
74  uint16_t port_;
75 };
76 } // namespace core
77 } // namespace transport
transport::core::Endpoint
Definition: endpoint.h:26
transport
Definition: forwarder_config.h:32