FD.io VPP  v18.10-34-gcce845e
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  * less-than operator for map storage
54  */
55  bool operator<(const endpoint_t& o) const;
56 
57  /**
58  * Comparison operator
59  */
60  bool operator==(const endpoint_t& o) const;
61 
62  /**
63  * Debug print function
64  */
65  std::string to_string() const;
66 
67  /**
68  * The src IP address of the endpoint
69  */
71 
72  /**
73  * The destination IP address of the endpoint
74  */
76 
77  /**
78  * The VNI of the endpoint
79  */
80  uint32_t vni;
81  };
82 
83  /**
84  * Construct a new object matching the desried state
85  */
88  uint32_t vni);
89 
90  /**
91  * Construct a new object matching the desried state with a handle
92  * read from VPP
93  */
94  vxlan_tunnel(const handle_t& hdl,
97  uint32_t vni);
98 
99  /*
100  * Destructor
101  */
102  ~vxlan_tunnel();
103 
104  /**
105  * Copy constructor
106  */
107  vxlan_tunnel(const vxlan_tunnel& o);
108 
109  /**
110  * Return the matching 'singular instance'
111  */
112  std::shared_ptr<vxlan_tunnel> singular() const;
113 
114  /**
115  * Debug rpint function
116  */
117  virtual std::string to_string() const;
118 
119  /**
120  * Return VPP's handle to this object
121  */
122  const handle_t& handle() const;
123 
124  /**
125  * Dump all L3Configs into the stream provided
126  */
127  static void dump(std::ostream& os);
128 
129 private:
130  /**
131  * Class definition for listeners to OM events
132  */
134  {
135  public:
136  event_handler();
137  virtual ~event_handler() = default;
138 
139  /**
140  * Handle a populate event
141  */
142  void handle_populate(const client_db::key_t& key);
143 
144  /**
145  * Handle a replay event
146  */
147  void handle_replay();
148 
149  /**
150  * Show the object in the Singular DB
151  */
152  void show(std::ostream& os);
153 
154  /**
155  * Get the sortable Id of the listener
156  */
157  dependency_t order() const;
158  };
159 
160  /**
161  * Event handle to register with OM
162  */
163  static event_handler m_evh;
164 
165  /**
166  * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
167  */
168  void update(const vxlan_tunnel& obj);
169 
170  /**
171  * Return the matching 'instance' of the sub-interface
172  * over-ride from the base class
173  */
174  std::shared_ptr<interface> singular_i() const;
175 
176  /**
177  * Find the VXLAN tunnel in the OM
178  */
179  static std::shared_ptr<vxlan_tunnel> find_or_add(const vxlan_tunnel& temp);
180 
181  /*
182  * It's the VPPHW class that updates the objects in HW
183  */
184  friend class OM;
185 
186  /**
187  * It's the singular_db class that calls replay()
188  */
190 
191  /**
192  * Sweep/reap the object if still stale
193  */
194  void sweep(void);
195 
196  /**
197  * replay the object to create it in hardware
198  */
199  void replay(void);
200 
201  /**
202  * Tunnel enpoint/key
203  */
204  endpoint_t m_tep;
205 
206  /**
207  * A map of all VLAN tunnela against thier key
208  */
210 
211  /**
212  * Construct a unique name for the tunnel
213  */
214  static std::string mk_name(const boost::asio::ip::address& src,
216  uint32_t vni);
217 };
218 
219 /**
220  * Ostream output for a tunnel endpoint
221  */
222 std::ostream& operator<<(std::ostream& os, const vxlan_tunnel::endpoint_t& ep);
223 
224 }; // namespace VOM
225 
226 /*
227  * fd.io coding-style-patch-verification: ON
228  *
229  * Local Variables:
230  * eval: (c-set-style "mozilla")
231  * End:
232  */
233 
234 #endif
std::string to_string() const
Debug print function.
A representation of a VXLAN Tunnel in VPP.
typedef address
Definition: ip_types.api:35
Combaintion of attributes that are a unique key for a VXLAN 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
boost::asio::ip::address dst
The destination IP address of the endpoint.
static void dump(std::ostream &os)
Dump all L3Configs into the stream provided.
std::shared_ptr< vxlan_tunnel > singular() const
Return the matching &#39;singular instance&#39;.
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
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:228
endpoint_t()
Default constructor.
void event_handler(void *tls_async)
Definition: tls_async.c:339
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)
vxlan_tunnel(const boost::asio::ip::address &src, const boost::asio::ip::address &dst, uint32_t vni)
Construct a new object matching the desried state.
bool operator<(const endpoint_t &o) const
less-than operator for map storage
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
bool operator==(const endpoint_t &o) const
Comparison operator.
uint32_t vni
The VNI of the endpoint.
boost::asio::ip::address src
The src IP address of the endpoint.
const key_t & key() const
Return the interface type.
Definition: interface.cpp:271
const handle_t & handle() const
Return VPP&#39;s handle to this object.