FD.io VPP  v19.01.3-6-g70449b9b9
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;
86  const static mode_t GPE;
87 
88  private:
89  mode_t(int v, const std::string s);
90  mode_t() = default;
91  };
92 
93  /**
94  * Construct a new object matching the desried state
95  */
98  uint32_t vni,
99  const mode_t& mode = mode_t::STANDARD);
102  uint32_t vni,
103  const interface& mcast_itf,
104  const mode_t& mode = mode_t::STANDARD);
105 
106  /*
107  * Destructor
108  */
109  ~vxlan_tunnel();
110 
111  /**
112  * Copy constructor
113  */
114  vxlan_tunnel(const vxlan_tunnel& o);
115 
116  /**
117  * Return the matching 'singular instance'
118  */
119  std::shared_ptr<vxlan_tunnel> singular() const;
120 
121  /**
122  * Debug rpint function
123  */
124  virtual std::string to_string() const;
125 
126  /**
127  * Return VPP's handle to this object
128  */
129  const handle_t& handle() const;
130 
131  /**
132  * Fond the singular instance of the interface in the DB by key
133  */
134  static std::shared_ptr<vxlan_tunnel> find(const interface::key_t& k);
135 
136 private:
137  /**
138  * Class definition for listeners to OM events
139  */
141  {
142  public:
143  event_handler();
144  virtual ~event_handler() = default;
145 
146  /**
147  * Handle a populate event
148  */
149  void handle_populate(const client_db::key_t& key);
150 
151  /**
152  * Handle a replay event
153  */
154  void handle_replay();
155 
156  /**
157  * Show the object in the Singular DB
158  */
159  void show(std::ostream& os);
160 
161  /**
162  * Get the sortable Id of the listener
163  */
164  dependency_t order() const;
165  };
166 
167  /**
168  * Event handle to register with OM
169  */
170  static event_handler m_evh;
171 
172  /**
173  * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
174  */
175  void update(const vxlan_tunnel& obj);
176 
177  /**
178  * Return the matching 'instance' of the sub-interface
179  * over-ride from the base class
180  */
181  std::shared_ptr<interface> singular_i() const;
182 
183  /**
184  * Find the VXLAN tunnel in the OM
185  */
186  static std::shared_ptr<vxlan_tunnel> find_or_add(const vxlan_tunnel& temp);
187 
188  /*
189  * It's the VPPHW class that updates the objects in HW
190  */
191  friend class OM;
192 
193  /**
194  * It's the singular_db class that calls replay()
195  */
197 
198  /**
199  * Sweep/reap the object if still stale
200  */
201  void sweep(void);
202 
203  /**
204  * replay the object to create it in hardware
205  */
206  void replay(void);
207 
208  /**
209  * Tunnel enpoint/key
210  */
211  endpoint_t m_tep;
212 
213  /**
214  * The tunnel mode
215  */
216  mode_t m_mode;
217 
218  /**
219  * The interface on which to send the packets if the destination
220  * is multicast
221  */
222  std::shared_ptr<interface> m_mcast_itf;
223 
224  /**
225  * Construct a unique name for the tunnel
226  */
227  static std::string mk_name(const boost::asio::ip::address& src,
229  const mode_t& mode,
230  uint32_t vni);
231 };
232 
233 /**
234  * Ostream output for a tunnel endpoint
235  */
236 std::ostream& operator<<(std::ostream& os, const vxlan_tunnel::endpoint_t& ep);
237 
238 }; // namespace VOM
239 
240 /*
241  * fd.io coding-style-patch-verification: ON
242  *
243  * Local Variables:
244  * eval: (c-set-style "mozilla")
245  * End:
246  */
247 
248 #endif
A representation of a VXLAN Tunnel in VPP.
typedef address
Definition: ip_types.api:30
static const mode_t GPE
static std::shared_ptr< vxlan_tunnel > find(const interface::key_t &k)
Fond the singular instance of the interface in the DB by key.
A template base class for all enum types.
Definition: enum_base.hpp:30
Combaintion of attributes that are a unique key for a VXLAN tunnel.
mode for the tunnel
const 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
static const mode_t GBP
boost::asio::ip::address dst
The destination IP address of the endpoint.
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:33
A representation of an interface in VPP.
Definition: interface.hpp:41
const handle_t & handle() const
Return VPP&#39;s handle to this object.
Class definition for listeners to OM events.
Definition: om.hpp:284
inspect command handler Handler
Definition: inspect.hpp:54
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
endpoint_t()
Default constructor.
void event_handler(void *tls_async)
Definition: tls_async.c:340
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
The interface to writing objects into VPP OM.
Definition: om.hpp:140
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
static const mode_t STANDARD
bool operator==(const endpoint_t &o) const
Comparison operator.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
std::shared_ptr< vxlan_tunnel > singular() const
Return the matching &#39;singular instance&#39;.
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
uint32_t vni
The VNI of the endpoint.
vl_api_gbp_vxlan_tunnel_mode_t mode
Definition: gbp.api:349
std::string to_string() const
Debug print function.
const key_t & key() const
Return the interface type.
Definition: interface.cpp:270
std::string key_t
The key for interface&#39;s key.
Definition: interface.hpp:56
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.
boost::asio::ip::address src
The src IP address of the endpoint.