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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __VOM_VXLAN_TUNNEL_H__
17 #define __VOM_VXLAN_TUNNEL_H__
20 #include "vom/inspect.hpp"
21 #include "vom/interface.hpp"
22 #include "vom/object_base.hpp"
24 #include "vom/prefix.hpp"
25 #include "vom/route_domain.hpp"
26 #include "vom/rpc_cmd.hpp"
27 #include "vom/singular_db.hpp"
29 #include <vapi/vxlan.api.vapi.hpp>
33 * A representation of a VXLAN Tunnel in VPP
35 class vxlan_tunnel : public interface
39 * Combaintion of attributes that are a unique key
49 * Constructor taking endpoint values
51 endpoint_t(const boost::asio::ip::address& src,
52 const boost::asio::ip::address& dst,
56 * less-than operator for map storage
58 bool operator<(const endpoint_t& o) const;
63 bool operator==(const endpoint_t& o) const;
66 * Debug print function
68 std::string to_string() const;
71 * The src IP address of the endpoint
73 boost::asio::ip::address src;
76 * The destination IP address of the endpoint
78 boost::asio::ip::address dst;
81 * The VNI of the endpoint
87 * Construct a new object matching the desried state
89 vxlan_tunnel(const boost::asio::ip::address& src,
90 const boost::asio::ip::address& dst,
94 * Construct a new object matching the desried state with a handle
97 vxlan_tunnel(const handle_t& hdl,
98 const boost::asio::ip::address& src,
99 const boost::asio::ip::address& dst,
110 vxlan_tunnel(const vxlan_tunnel& o);
113 * Return the matching 'singular instance'
115 std::shared_ptr<vxlan_tunnel> singular() const;
118 * Debug rpint function
120 virtual std::string to_string() const;
123 * Return VPP's handle to this object
125 const handle_t& handle() const;
128 * Dump all L3Configs into the stream provided
130 static void dump(std::ostream& os);
133 * A Command class that creates an VXLAN tunnel
135 class create_cmd : public interface::create_cmd<vapi::Vxlan_add_del_tunnel>
139 * Create command constructor taking HW item to update and the
142 create_cmd(HW::item<handle_t>& item,
143 const std::string& name,
144 const endpoint_t& ep);
147 * Issue the command to VPP/HW
149 rc_t issue(connection& con);
151 * convert to string format for debug purposes
153 std::string to_string() const;
156 * Comparison operator - only used for UT
158 bool operator==(const create_cmd& i) const;
162 * Enpoint values of the tunnel to be created
164 const endpoint_t m_ep;
168 * A functor class that creates an VXLAN tunnel
170 class delete_cmd : public interface::delete_cmd<vapi::Vxlan_add_del_tunnel>
174 * delete command constructor taking HW item to update and the
177 delete_cmd(HW::item<handle_t>& item, const endpoint_t& ep);
180 * Issue the command to VPP/HW
182 rc_t issue(connection& con);
185 * convert to string format for debug purposes
187 std::string to_string() const;
190 * Comparison operator - only used for UT
192 bool operator==(const delete_cmd& i) const;
196 * Enpoint values of the tunnel to be deleted
198 const endpoint_t m_ep;
202 * A cmd class that Dumps all the Vpp interfaces
204 class dump_cmd : public VOM::dump_cmd<vapi::Vxlan_tunnel_dump>
208 * Default Constructor
213 * Issue the command to VPP/HW
215 rc_t issue(connection& con);
217 * convert to string format for debug purposes
219 std::string to_string() const;
222 * Comparison operator - only used for UT
224 bool operator==(const dump_cmd& i) const;
229 * Class definition for listeners to OM events
231 class event_handler : public OM::listener, public inspect::command_handler
235 virtual ~event_handler() = default;
238 * Handle a populate event
240 void handle_populate(const client_db::key_t& key);
243 * Handle a replay event
245 void handle_replay();
248 * Show the object in the Singular DB
250 void show(std::ostream& os);
253 * Get the sortable Id of the listener
255 dependency_t order() const;
259 * Event handle to register with OM
261 static event_handler m_evh;
264 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
266 void update(const vxlan_tunnel& obj);
269 * Return the matching 'instance' of the sub-interface
270 * over-ride from the base class
272 std::shared_ptr<interface> singular_i() const;
275 * Find the VXLAN tunnel in the OM
277 static std::shared_ptr<vxlan_tunnel> find_or_add(const vxlan_tunnel& temp);
280 * It's the VPPHW class that updates the objects in HW
285 * It's the singular_db class that calls replay()
287 friend class singular_db<endpoint_t, vxlan_tunnel>;
290 * Sweep/reap the object if still stale
295 * replay the object to create it in hardware
305 * A map of all VLAN tunnela against thier key
307 static singular_db<endpoint_t, vxlan_tunnel> m_db;
310 * Construct a unique name for the tunnel
312 static std::string mk_name(const boost::asio::ip::address& src,
313 const boost::asio::ip::address& dst,
318 * Ostream output for a tunnel endpoint
320 std::ostream& operator<<(std::ostream& os, const vxlan_tunnel::endpoint_t& ep);
324 * fd.io coding-style-patch-verification: ON
327 * eval: (c-set-style "mozilla")