Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
prefix.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 
20 namespace transport {
21 
22 namespace core {
23 
24 class Prefix {
25  public:
26  Prefix();
27 
28  Prefix(const char *prefix);
29 
30  Prefix(const std::string &prefix);
31 
32  Prefix(std::string &&prefix);
33 
34  Prefix(std::string &prefix, uint16_t prefix_length);
35 
36  Prefix(const core::Name &content_name, uint16_t prefix_length);
37 
38  std::unique_ptr<Sockaddr> toSockaddr() const;
39 
40  uint16_t getPrefixLength() const;
41 
42  Prefix &setPrefixLength(uint16_t prefix_length);
43 
44  std::string getNetwork() const;
45 
46  int contains(const ip_address_t &content_name) const;
47 
48  int contains(const core::Name &content_name) const;
49 
50  Name getName() const;
51 
52  Name getRandomName() const;
53 
54  Name getName(const core::Name &mask, const core::Name &components,
55  const core::Name &content_name) const;
56 
57  Name mapName(const core::Name &content_name) const;
58 
59  Prefix &setNetwork(std::string &network);
60 
61  int getAddressFamily() const;
62 
63  Prefix &setAddressFamily(int address_family);
64 
65  Name makeRandomName() const;
66 
67  const ip_prefix_t &toIpPrefixStruct() const;
68 
69  private:
70  static bool checkPrefixLengthAndAddressFamily(uint16_t prefix_length,
71  int family);
72 
73  void buildPrefix(std::string &prefix, uint16_t prefix_length, int family);
74 
75  ip_prefix_t ip_prefix_;
76 };
77 
78 } // end namespace core
79 
80 } // end namespace transport
transport::core::Name
Definition: name.h:45
ip_address_t
Definition: ip_address.h:68
ip_prefix_t
Definition: ip_address.h:103
transport
Definition: forwarder_config.h:32
transport::core::Prefix
Definition: prefix.h:24