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_tunnel.hpp"
17 #include "vom/gbp_vxlan_tunnel_cmds.hpp"
18 #include "vom/interface.hpp"
19 #include "vom/singular_db_funcs.hpp"
24 * A DB of al the interfaces, key on the name
26 singular_db<uint32_t, gbp_vxlan_tunnel> gbp_vxlan_tunnel::m_db;
28 gbp_vxlan_tunnel::event_handler gbp_vxlan_tunnel::m_evh;
31 * Construct a new object matching the desried state
33 gbp_vxlan_tunnel::gbp_vxlan_tunnel(const vxlan_tunnel& vt)
39 gbp_vxlan_tunnel::gbp_vxlan_tunnel(uint32_t vni)
40 : interface(mk_name(vni),
41 interface::type_t::UNKNOWN,
42 interface::admin_state_t::UP)
47 const gbp_vxlan_tunnel::key_t
48 gbp_vxlan_tunnel::key() const
54 gbp_vxlan_tunnel::operator==(const gbp_vxlan_tunnel& vt) const
56 return (m_vni == vt.m_vni);
60 gbp_vxlan_tunnel::sweep()
62 if (rc_t::OK == m_id.rc()) {
63 HW::enqueue(new gbp_vxlan_tunnel_cmds::delete_cmd(m_vni));
69 gbp_vxlan_tunnel::replay()
71 if (rc_t::OK == m_hdl) {
72 HW::enqueue(new gbp_vxlan_tunnel_cmds::create_cmd(m_vni));
76 gbp_vxlan_tunnel::~gbp_vxlan_tunnel()
79 m_db.release(m_id.data(), this);
83 gbp_vxlan_tunnel::to_string() const
86 s << "gbp-vxlan:[" << m_vni << "]";
91 std::shared_ptr<gbp_vxlan_tunnel>
92 gbp_vxlan_tunnel::find(const key_t& key)
94 return (m_db.find(key));
98 gbp_vxlan_tunnel::update(const gbp_vxlan_tunnel& desired)
101 * the desired state is always that the interface should be created
103 if (rc_t::OK != m_hdl) {
104 HW::enqueue(new gbp_vxlan_tunnel_cmds::create_cmd(m_vni));
108 std::shared_ptr<gbp_vxlan_tunnel>
109 gbp_vxlan_tunnel::find_or_add(const gbp_vxlan_tunnel& temp)
111 return (m_db.find_or_add(temp.m_id.data(), temp));
114 std::shared_ptr<gbp_vxlan_tunnel>
115 gbp_vxlan_tunnel::singular() const
117 return find_or_add(*this);
121 gbp_vxlan_tunnel::dump(std::ostream& os)
127 gbp_vxlan_tunnel::event_handler::handle_populate(const client_db::key_t& key)
130 * dump VPP Bridge domains
132 std::shared_ptr<gbp_vxlan_tunnel_cmds::dump_cmd> cmd =
133 std::make_shared<gbp_vxlan_tunnel_cmds::dump_cmd>();
138 for (auto& record : *cmd) {
139 auto& payload = record.get_payload();
141 gbp_vxlan_tunnel vt(payload.tunnel.vni, );
143 VOM_LOG(log_level_t::DEBUG) << "dump: " << vt.to_string();
147 gbp_vxlan_tunnel vt(payload.vt.vt_id);
149 VOM_LOG(log_level_t::DEBUG) << "dump: " << vt.to_string();
154 gbp_vxlan_tunnel::event_handler::event_handler()
156 OM::register_listener(this);
157 inspect::register_handler({ "gvt", "gbp-vxlan-tunnel" }, "GBP VXLAN Tunnels",
162 gbp_vxlan_tunnel::event_handler::handle_replay()
168 gbp_vxlan_tunnel::event_handler::order() const
170 return (dependency_t::INTERFACE);
174 gbp_vxlan_tunnel::event_handler::show(std::ostream& os)
181 * fd.io coding-style-patch-verification: ON
184 * eval: (c-set-style "mozilla")