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 #include "vom/gbp_vxlan.hpp"
17 #include "vom/gbp_vxlan_cmds.hpp"
18 #include "vom/interface.hpp"
19 #include "vom/singular_db_funcs.hpp"
23 const std::string GBP_VXLAN_NAME = "gbp-vxlan";
26 * A DB of al the interfaces, key on the name
28 singular_db<gbp_vxlan::key_t, gbp_vxlan> gbp_vxlan::m_db;
30 gbp_vxlan::event_handler gbp_vxlan::m_evh;
32 gbp_vxlan::gbp_vxlan(uint32_t vni, const gbp_route_domain& grd)
33 : interface(mk_name(vni),
34 interface::type_t::UNKNOWN,
35 interface::admin_state_t::UP)
38 , m_grd(grd.singular())
41 gbp_vxlan::gbp_vxlan(uint32_t vni, const gbp_bridge_domain& gbd)
42 : interface(mk_name(vni),
43 interface::type_t::UNKNOWN,
44 interface::admin_state_t::UP)
46 , m_gbd(gbd.singular())
51 gbp_vxlan::gbp_vxlan(const gbp_vxlan& vt)
60 gbp_vxlan::mk_name(uint32_t vni)
64 s << GBP_VXLAN_NAME << "-" << vni;
69 const gbp_vxlan::key_t
70 gbp_vxlan::key() const
76 gbp_vxlan::operator==(const gbp_vxlan& vt) const
78 return (m_vni == vt.m_vni);
84 if (rc_t::OK == m_hdl) {
85 HW::enqueue(new gbp_vxlan_cmds::delete_cmd(m_hdl, m_vni));
93 if (rc_t::OK == m_hdl) {
95 HW::enqueue(new gbp_vxlan_cmds::create_cmd(m_hdl, name(), m_vni, false,
98 HW::enqueue(new gbp_vxlan_cmds::create_cmd(m_hdl, name(), m_vni, true,
103 gbp_vxlan::~gbp_vxlan()
106 m_db.release(key(), this);
110 gbp_vxlan::to_string() const
112 std::ostringstream s;
113 s << "gbp-vxlan:[" << m_vni << "]";
118 std::shared_ptr<gbp_vxlan>
119 gbp_vxlan::find(const key_t key)
121 return (m_db.find(key));
125 gbp_vxlan::update(const gbp_vxlan& desired)
128 * the desired state is always that the interface should be created
130 if (rc_t::OK != m_hdl) {
132 HW::enqueue(new gbp_vxlan_cmds::create_cmd(m_hdl, name(), m_vni, false,
135 HW::enqueue(new gbp_vxlan_cmds::create_cmd(m_hdl, name(), m_vni, true,
140 std::shared_ptr<gbp_vxlan>
141 gbp_vxlan::find_or_add(const gbp_vxlan& temp)
143 return (m_db.find_or_add(temp.key(), temp));
146 std::shared_ptr<gbp_vxlan>
147 gbp_vxlan::singular() const
149 return find_or_add(*this);
152 std::shared_ptr<interface>
153 gbp_vxlan::singular_i() const
155 return find_or_add(*this);
159 gbp_vxlan::dump(std::ostream& os)
165 gbp_vxlan::event_handler::handle_populate(const client_db::key_t& key)
168 * dump VPP Bridge domains
170 std::shared_ptr<gbp_vxlan_cmds::dump_cmd> cmd =
171 std::make_shared<gbp_vxlan_cmds::dump_cmd>();
176 for (auto& record : *cmd) {
177 auto& payload = record.get_payload();
179 if (GBP_VXLAN_TUNNEL_MODE_L3 == payload.tunnel.mode) {
180 auto rd = gbp_route_domain::find(payload.tunnel.bd_rd_id);
183 gbp_vxlan vt(payload.tunnel.vni, *rd);
185 VOM_LOG(log_level_t::DEBUG) << "dump: " << vt.to_string();
188 auto bd = gbp_bridge_domain::find(payload.tunnel.bd_rd_id);
191 gbp_vxlan vt(payload.tunnel.vni, *bd);
193 VOM_LOG(log_level_t::DEBUG) << "dump: " << vt.to_string();
199 gbp_vxlan::event_handler::event_handler()
201 OM::register_listener(this);
202 inspect::register_handler({ "gvt", "gbp-vxlan-tunnel" }, "GBP VXLAN Tunnels",
207 gbp_vxlan::event_handler::handle_replay()
213 gbp_vxlan::event_handler::order() const
215 return (dependency_t::BINDING);
219 gbp_vxlan::event_handler::show(std::ostream& os)
226 * fd.io coding-style-patch-verification: ON
229 * eval: (c-set-style "mozilla")