FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
nat_static.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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 #ifndef __VOM_NAT_STATIC_H__
17 #define __VOM_NAT_STATIC_H__
18 
19 #include "vom/route.hpp"
20 #include "vom/singular_db.hpp"
21 #include "vom/types.hpp"
22 
23 namespace VOM {
24 /**
25  * A entry in the ARP termination table of a Bridge Domain
26  */
27 class nat_static : public object_base
28 {
29 public:
30  /**
31  * The key for a NAT static mapping.
32  * So far only model the address only case. The address
33  * is the outside.
34  */
35  typedef std::pair<route::table_id_t, boost::asio::ip::address> key_t;
36 
37  /**
38  * Construct an NAT Static binding with the outside address in default
39  * table
40  */
42  const boost::asio::ip::address& outside);
43 
44  /**
45  * Construct an NAT Static binding with the outside address in
46  * route-domain specified
47  */
48  nat_static(const route_domain& rd,
49  const boost::asio::ip::address& inside,
50  const boost::asio::ip::address& outside);
51 
52  /**
53  * Copy Construct
54  */
55  nat_static(const nat_static& r);
56 
57  /**
58  * Destructor
59  */
60  ~nat_static();
61 
62  /**
63  * Comparison operator - for UT
64  */
65  bool operator==(const nat_static& n) const;
66 
67  /**
68  * Return the object's key
69  */
70  const key_t key() const;
71 
72  /**
73  * Return the matching 'singular instance'
74  */
75  std::shared_ptr<nat_static> singular() const;
76 
77  /**
78  * Find the instnace of the bridge_domain domain in the OM
79  */
80  static std::shared_ptr<nat_static> find(const key_t& key);
81 
82  /**
83  * Dump all bridge_domain-doamin into the stream provided
84  */
85  static void dump(std::ostream& os);
86 
87  /**
88  * replay the object to create it in hardware
89  */
90  void replay(void);
91 
92  /**
93  * Convert to string for debugging
94  */
95  std::string to_string() const;
96 
97 private:
98  /**
99  * Class definition for listeners to OM events
100  */
102  {
103  public:
104  event_handler();
105  virtual ~event_handler() = default;
106 
107  /**
108  * Handle a populate event
109  */
110  void handle_populate(const client_db::key_t& key);
111 
112  /**
113  * Handle a replay event
114  */
115  void handle_replay();
116 
117  /**
118  * Show the object in the Singular DB
119  */
120  void show(std::ostream& os);
121 
122  /**
123  * Get the sortable Id of the listener
124  */
125  dependency_t order() const;
126  };
127 
128  /**
129  * event_handler to register with OM
130  */
131  static event_handler m_evh;
132 
133  /**
134  * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
135  */
136  void update(const nat_static& obj);
137 
138  /**
139  * Find or add the instnace of the bridge_domain domain in the OM
140  */
141  static std::shared_ptr<nat_static> find_or_add(const nat_static& temp);
142 
143  /*
144  * It's the VPPHW class that updates the objects in HW
145  */
146  friend class OM;
147 
148  /**
149  * It's the singular_db class that calls replay()
150  */
151  friend class singular_db<key_t, nat_static>;
152 
153  /**
154  * Sweep/reap the object if still stale
155  */
156  void sweep(void);
157 
158  /**
159  * HW configuration for the result of creating the bridge_domain
160  */
161  HW::item<bool> m_hw;
162 
163  /**
164  * The table-ID the outside address resides in
165  */
166  std::shared_ptr<route_domain> m_rd;
167 
168  /**
169  * The 'inside' IP address, could be v4 or v6
170  */
171  const boost::asio::ip::address m_inside;
172 
173  /**
174  * The 'outside' IP address
175  */
176  const boost::asio::ip::address m_outside;
177 
178  /**
179  * A map of all NAT statics
180  */
181  static singular_db<key_t, nat_static> m_db;
182 };
183 
184 std::ostream& operator<<(std::ostream& os, const nat_static::key_t& key);
185 };
186 
187 /*
188  * fd.io coding-style-patch-verification: OFF
189  *
190  * Local Variables:
191  * eval: (c-set-style "mozilla")
192  * End:
193  */
194 
195 #endif
VOM::HW::item< bool >
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::dependency_t
dependency_t
There needs to be a strict order in which object types are read from VPP (at boot time) and replayed ...
Definition: types.hpp:43
VOM::OM
The interface to writing objects into VPP OM.
Definition: om.hpp:140
types.hpp
VOM::inspect::command_handler
inspect command handler Handler
Definition: inspect.hpp:54
VOM::nat_static::operator==
bool operator==(const nat_static &n) const
Comparison operator - for UT.
Definition: nat_static.cpp:66
VOM::OM::listener
Class definition for listeners to OM events.
Definition: om.hpp:284
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1089
key
typedef key
Definition: ipsec_types.api:91
VOM::nat_static::singular
std::shared_ptr< nat_static > singular() const
Return the matching 'singular instance'.
Definition: nat_static.cpp:141
VOM::nat_static
A entry in the ARP termination table of a Bridge Domain.
Definition: nat_static.hpp:27
VOM::nat_static::dump
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
Definition: nat_static.cpp:147
VOM::nat_static::~nat_static
~nat_static()
Destructor.
Definition: nat_static.cpp:51
route.hpp
VOM::client_db::key_t
const typedef std::string key_t
In the opflex world each entity is known by a URI which can be converted into a string.
Definition: client_db.hpp:51
address
manual_print typedef address
Definition: ip_types.api:96
VOM::operator<<
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
Definition: acl_binding.cpp:201
VOM::nat_static::nat_static
nat_static(const boost::asio::ip::address &inside, const boost::asio::ip::address &outside)
Construct an NAT Static binding with the outside address in default table.
Definition: nat_static.cpp:24
VOM::nat_static::find
static std::shared_ptr< nat_static > find(const key_t &key)
Find the instnace of the bridge_domain domain in the OM.
Definition: nat_static.cpp:135
singular_db.hpp
VOM::nat_static::key
const key_t key() const
Return the object's key.
Definition: nat_static.cpp:60
VOM::route_domain
A route-domain is a VRF.
Definition: route_domain.hpp:31
VOM::singular_db
A Database to store the unique 'singular' instances of a single object type.
Definition: singular_db.hpp:33
VOM::nat_static::key_t
std::pair< route::table_id_t, boost::asio::ip::address > key_t
The key for a NAT static mapping.
Definition: nat_static.hpp:35
VOM::nat_static::replay
void replay(void)
replay the object to create it in hardware
Definition: nat_static.cpp:87
show
void show(char *chroot_path, int verbose)
Definition: svmtool.c:104
event_handler
void event_handler(void *tls_async)
Definition: tls_async.c:334
VOM::object_base
A base class for all object_base in the VPP object_base-Model.
Definition: object_base.hpp:29
VOM::nat_static::to_string
std::string to_string() const
Convert to string for debugging.
Definition: nat_static.cpp:118
string
const char *const string
Definition: cJSON.h:172