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/singular_db.hpp"
30 * A representation of a VXLAN Tunnel in VPP
32 class vxlan_tunnel : public interface
36 * Combaintion of attributes that are a unique key
46 * Constructor taking endpoint values
48 endpoint_t(const boost::asio::ip::address& src,
49 const boost::asio::ip::address& dst,
55 bool operator==(const endpoint_t& o) const;
58 * Debug print function
60 std::string to_string() const;
63 * The src IP address of the endpoint
65 boost::asio::ip::address src;
68 * The destination IP address of the endpoint
70 boost::asio::ip::address dst;
73 * The VNI of the endpoint
81 struct mode_t : public enum_base<mode_t>
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;
90 mode_t(int v, const std::string s);
95 * Construct a new object matching the desried state
97 vxlan_tunnel(const boost::asio::ip::address& src,
98 const boost::asio::ip::address& dst,
100 const mode_t& mode = mode_t::STANDARD);
101 vxlan_tunnel(const boost::asio::ip::address& src,
102 const boost::asio::ip::address& dst,
104 const interface& mcast_itf,
105 const mode_t& mode = mode_t::STANDARD);
106 vxlan_tunnel(const boost::asio::ip::address& src,
107 const boost::asio::ip::address& dst,
109 const route_domain& rd,
110 const mode_t& mode = mode_t::STANDARD);
120 vxlan_tunnel(const vxlan_tunnel& o);
123 * comparison operator
125 bool operator==(const vxlan_tunnel& vx) const;
128 * Return the matching 'singular instance'
130 std::shared_ptr<vxlan_tunnel> singular() const;
133 * Debug rpint function
135 virtual std::string to_string() const;
138 * Return VPP's handle to this object
140 const handle_t& handle() const;
143 * Fond the singular instance of the interface in the DB by key
145 static std::shared_ptr<vxlan_tunnel> find(const interface::key_t& k);
149 * Class definition for listeners to OM events
151 class event_handler : public OM::listener, public inspect::command_handler
155 virtual ~event_handler() = default;
158 * Handle a populate event
160 void handle_populate(const client_db::key_t& key);
163 * Handle a replay event
165 void handle_replay();
168 * Show the object in the Singular DB
170 void show(std::ostream& os);
173 * Get the sortable Id of the listener
175 dependency_t order() const;
179 * Event handle to register with OM
181 static event_handler m_evh;
184 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
186 void update(const vxlan_tunnel& obj);
189 * Return the matching 'instance' of the sub-interface
190 * over-ride from the base class
192 std::shared_ptr<interface> singular_i() const;
195 * Find the VXLAN tunnel in the OM
197 static std::shared_ptr<vxlan_tunnel> find_or_add(const vxlan_tunnel& temp);
200 * It's the VPPHW class that updates the objects in HW
205 * It's the singular_db class that calls replay()
207 friend class singular_db<endpoint_t, vxlan_tunnel>;
210 * Sweep/reap the object if still stale
215 * replay the object to create it in hardware
230 * The interface on which to send the packets if the destination
233 std::shared_ptr<interface> m_mcast_itf;
236 * The RD an L3 interface is bound to
238 std::shared_ptr<const route_domain> m_rd;
241 * HW state of the VPP table mapping
243 HW::item<route::table_id_t> m_table_id;
246 * Construct a unique name for the tunnel
248 static std::string mk_name(const boost::asio::ip::address& src,
249 const boost::asio::ip::address& dst,
255 * Ostream output for a tunnel endpoint
257 std::ostream& operator<<(std::ostream& os, const vxlan_tunnel::endpoint_t& ep);
262 * fd.io coding-style-patch-verification: ON
265 * eval: (c-set-style "mozilla")