FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
vxlan_tunnel.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_VXLAN_TUNNEL_H__
17 #define __VOM_VXLAN_TUNNEL_H__
18 
19 #include "vom/hw.hpp"
20 #include "vom/inspect.hpp"
21 #include "vom/interface.hpp"
22 #include "vom/object_base.hpp"
23 #include "vom/om.hpp"
24 #include "vom/prefix.hpp"
25 #include "vom/route_domain.hpp"
26 #include "vom/singular_db.hpp"
27 
28 namespace VOM {
29 /**
30  * A representation of a VXLAN Tunnel in VPP
31  */
32 class vxlan_tunnel : public interface
33 {
34 public:
35  /**
36  * Combaintion of attributes that are a unique key
37  * for a VXLAN tunnel
38  */
39  struct endpoint_t
40  {
41  /**
42  * Default constructor
43  */
44  endpoint_t();
45  /**
46  * Constructor taking endpoint values
47  */
50  uint32_t vni);
51 
52  /**
53  * Comparison operator
54  */
55  bool operator==(const endpoint_t& o) const;
56 
57  /**
58  * Debug print function
59  */
60  std::string to_string() const;
61 
62  /**
63  * The src IP address of the endpoint
64  */
66 
67  /**
68  * The destination IP address of the endpoint
69  */
71 
72  /**
73  * The VNI of the endpoint
74  */
75  uint32_t vni;
76  };
77 
78  /**
79  * mode for the tunnel
80  */
81  struct mode_t : public enum_base<mode_t>
82  {
83  ~mode_t() = default;
84  const static mode_t STANDARD;
85  const static mode_t GBP_L2;
86  const static mode_t GBP_L3;
87  const static mode_t GPE;
88 
89  private:
90  mode_t(int v, const std::string s);
91  mode_t() = default;
92  };
93 
94  /**
95  * Construct a new object matching the desried state
96  */
99  uint32_t vni,
100  const mode_t& mode = mode_t::STANDARD);
103  uint32_t vni,
104  const interface& mcast_itf,
105  const mode_t& mode = mode_t::STANDARD);
108  uint32_t vni,
109  const route_domain& rd,
110  const mode_t& mode = mode_t::STANDARD);
111 
112  /*
113  * Destructor
114  */
115  ~vxlan_tunnel();
116 
117  /**
118  * Copy constructor
119  */
120  vxlan_tunnel(const vxlan_tunnel& o);
121 
122  /**
123  * comparison operator
124  */
125  bool operator==(const vxlan_tunnel& vx) const;
126 
127  /**
128  * Return the matching 'singular instance'
129  */
130  std::shared_ptr<vxlan_tunnel> singular() const;
131 
132  /**
133  * Debug rpint function
134  */
135  virtual std::string to_string() const;
136 
137  /**
138  * Return VPP's handle to this object
139  */
140  const handle_t& handle() const;
141 
142  /**
143  * Fond the singular instance of the interface in the DB by key
144  */
145  static std::shared_ptr<vxlan_tunnel> find(const interface::key_t& k);
146 
147 private:
148  /**
149  * Class definition for listeners to OM events
150  */
152  {
153  public:
154  event_handler();
155  virtual ~event_handler() = default;
156 
157  /**
158  * Handle a populate event
159  */
160  void handle_populate(const client_db::key_t& key);
161 
162  /**
163  * Handle a replay event
164  */
165  void handle_replay();
166 
167  /**
168  * Show the object in the Singular DB
169  */
170  void show(std::ostream& os);
171 
172  /**
173  * Get the sortable Id of the listener
174  */
175  dependency_t order() const;
176  };
177 
178  /**
179  * Event handle to register with OM
180  */
181  static event_handler m_evh;
182 
183  /**
184  * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
185  */
186  void update(const vxlan_tunnel& obj);
187 
188  /**
189  * Return the matching 'instance' of the sub-interface
190  * over-ride from the base class
191  */
192  std::shared_ptr<interface> singular_i() const;
193 
194  /**
195  * Find the VXLAN tunnel in the OM
196  */
197  static std::shared_ptr<vxlan_tunnel> find_or_add(const vxlan_tunnel& temp);
198 
199  /*
200  * It's the VPPHW class that updates the objects in HW
201  */
202  friend class OM;
203 
204  /**
205  * It's the singular_db class that calls replay()
206  */
208 
209  /**
210  * Sweep/reap the object if still stale
211  */
212  void sweep(void);
213 
214  /**
215  * replay the object to create it in hardware
216  */
217  void replay(void);
218 
219  /**
220  * Tunnel enpoint/key
221  */
222  endpoint_t m_tep;
223 
224  /**
225  * The tunnel mode
226  */
227  mode_t m_mode;
228 
229  /**
230  * The interface on which to send the packets if the destination
231  * is multicast
232  */
233  std::shared_ptr<interface> m_mcast_itf;
234 
235  /**
236  * The RD an L3 interface is bound to
237  */
238  std::shared_ptr<const route_domain> m_rd;
239 
240  /**
241  * HW state of the VPP table mapping
242  */
243  HW::item<route::table_id_t> m_table_id;
244 
245  /**
246  * Construct a unique name for the tunnel
247  */
248  static std::string mk_name(const boost::asio::ip::address& src,
250  const mode_t& mode,
251  uint32_t vni);
252 };
253 
254 /**
255  * Ostream output for a tunnel endpoint
256  */
257 std::ostream& operator<<(std::ostream& os, const vxlan_tunnel::endpoint_t& ep);
258 
259 }; // namespace VOM
260 
261 /*
262  * fd.io coding-style-patch-verification: OFF
263  *
264  * Local Variables:
265  * eval: (c-set-style "mozilla")
266  * End:
267  */
268 
269 #endif
VOM::HW::item< route::table_id_t >
VOM::vxlan_tunnel::find
static std::shared_ptr< vxlan_tunnel > find(const interface::key_t &k)
Fond the singular instance of the interface in the DB by key.
Definition: vxlan_tunnel.cpp:151
VOM::vxlan_tunnel::endpoint_t::dst
boost::asio::ip::address dst
The destination IP address of the endpoint.
Definition: vxlan_tunnel.hpp:70
VOM::vxlan_tunnel::mode_t::STANDARD
const static mode_t STANDARD
Definition: vxlan_tunnel.hpp:84
VOM::vxlan_tunnel::endpoint_t::operator==
bool operator==(const endpoint_t &o) const
Comparison operator.
Definition: vxlan_tunnel.cpp:53
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
om.hpp
VOM::OM
The interface to writing objects into VPP OM.
Definition: om.hpp:140
vni
u32 vni
Definition: flow_types.api:160
VOM::inspect::command_handler
inspect command handler Handler
Definition: inspect.hpp:54
mode
vl_api_tunnel_mode_t mode
Definition: gre.api:48
VOM::OM::listener
Class definition for listeners to OM events.
Definition: om.hpp:284
VOM::vxlan_tunnel::endpoint_t::vni
uint32_t vni
The VNI of the endpoint.
Definition: vxlan_tunnel.hpp:75
VOM::vxlan_tunnel::to_string
virtual std::string to_string() const
Debug rpint function.
Definition: vxlan_tunnel.cpp:208
VOM::vxlan_tunnel::mode_t::GBP_L3
const static mode_t GBP_L3
Definition: vxlan_tunnel.hpp:86
VOM::interface::key
const key_t & key() const
Return the interface type.
Definition: interface.cpp:277
VOM::enum_base
A template base class for all enum types.
Definition: enum_base.hpp:30
VOM::vxlan_tunnel::endpoint_t::src
boost::asio::ip::address src
The src IP address of the endpoint.
Definition: vxlan_tunnel.hpp:65
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
hw.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
VOM::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
address
manual_print typedef address
Definition: ip_types.api:96
VOM::vxlan_tunnel
A representation of a VXLAN Tunnel in VPP.
Definition: vxlan_tunnel.hpp:32
src
vl_api_address_t src
Definition: gre.api:54
VOM::operator<<
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
Definition: acl_binding.cpp:201
VOM::vxlan_tunnel::handle
const handle_t & handle() const
Return VPP's handle to this object.
Definition: vxlan_tunnel.cpp:145
inspect.hpp
VOM::vxlan_tunnel::endpoint_t::endpoint_t
endpoint_t()
Default constructor.
Definition: vxlan_tunnel.cpp:46
VOM::vxlan_tunnel::mode_t::~mode_t
~mode_t()=default
singular_db.hpp
VOM::vxlan_tunnel::mode_t::GPE
const static mode_t GPE
Definition: vxlan_tunnel.hpp:87
prefix.hpp
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
VOM::vxlan_tunnel::mode_t::GBP_L2
const static mode_t GBP_L2
Definition: vxlan_tunnel.hpp:85
interface.hpp
VOM::vxlan_tunnel::operator==
bool operator==(const vxlan_tunnel &vx) const
comparison operator
Definition: vxlan_tunnel.cpp:138
VOM::vxlan_tunnel::endpoint_t::to_string
std::string to_string() const
Debug print function.
Definition: vxlan_tunnel.cpp:59
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::vxlan_tunnel::mode_t
mode for the tunnel
Definition: vxlan_tunnel.hpp:81
route_domain.hpp
VOM::vxlan_tunnel::~vxlan_tunnel
~vxlan_tunnel()
Definition: vxlan_tunnel.cpp:201
VOM::vxlan_tunnel::vxlan_tunnel
vxlan_tunnel(const boost::asio::ip::address &src, const boost::asio::ip::address &dst, uint32_t vni, const mode_t &mode=mode_t::STANDARD)
Construct a new object matching the desried state.
Definition: vxlan_tunnel.cpp:84
VOM::interface::key_t
std::string key_t
The key for interface's key.
Definition: interface.hpp:56
VOM::vxlan_tunnel::singular
std::shared_ptr< vxlan_tunnel > singular() const
Return the matching 'singular instance'.
Definition: vxlan_tunnel.cpp:256
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
object_base.hpp
VOM::vxlan_tunnel::endpoint_t
Combaintion of attributes that are a unique key for a VXLAN tunnel.
Definition: vxlan_tunnel.hpp:39
string
const char *const string
Definition: cJSON.h:172