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_route_domain.hpp"
17 #include "vom/gbp_route_domain_cmds.hpp"
18 #include "vom/interface.hpp"
19 #include "vom/l2_binding.hpp"
20 #include "vom/singular_db_funcs.hpp"
25 * A DB of al the interfaces, key on the name
27 singular_db<uint32_t, gbp_route_domain> gbp_route_domain::m_db;
29 gbp_route_domain::event_handler gbp_route_domain::m_evh;
32 * Construct a new object matching the desried state
34 gbp_route_domain::gbp_route_domain(const gbp_route_domain& rd)
38 , m_ip4_uu_fwd(rd.m_ip4_uu_fwd)
39 , m_ip6_uu_fwd(rd.m_ip6_uu_fwd)
43 gbp_route_domain::gbp_route_domain(const route_domain& rd,
45 const interface& ip4_uu_fwd,
46 const interface& ip6_uu_fwd)
50 , m_ip4_uu_fwd(ip4_uu_fwd.singular())
51 , m_ip6_uu_fwd(ip6_uu_fwd.singular())
55 gbp_route_domain::gbp_route_domain(const route_domain& rd,
57 const std::shared_ptr<interface> ip4_uu_fwd,
58 const std::shared_ptr<interface> ip6_uu_fwd)
62 , m_ip4_uu_fwd(ip4_uu_fwd)
63 , m_ip6_uu_fwd(ip6_uu_fwd)
66 m_ip4_uu_fwd = m_ip4_uu_fwd->singular();
68 m_ip6_uu_fwd = m_ip6_uu_fwd->singular();
71 gbp_route_domain::gbp_route_domain(const route_domain& rd, scope_t scope)
80 const gbp_route_domain::key_t
81 gbp_route_domain::key() const
87 gbp_route_domain::id() const
89 return (m_rd->table_id());
92 const std::shared_ptr<route_domain>
93 gbp_route_domain::get_route_domain() const
98 const std::shared_ptr<interface>
99 gbp_route_domain::get_ip4_uu_fwd() const
104 const std::shared_ptr<interface>
105 gbp_route_domain::get_ip6_uu_fwd() const
111 gbp_route_domain::operator==(const gbp_route_domain& b) const
115 if (m_ip4_uu_fwd && b.m_ip4_uu_fwd)
116 equal &= (m_ip4_uu_fwd->key() == b.m_ip4_uu_fwd->key());
117 else if (!m_ip4_uu_fwd && !b.m_ip4_uu_fwd)
122 if (m_ip6_uu_fwd && b.m_ip6_uu_fwd)
123 equal &= (m_ip6_uu_fwd->key() == b.m_ip6_uu_fwd->key());
124 else if (!m_ip6_uu_fwd && !b.m_ip6_uu_fwd)
129 return ((m_rd->key() == b.m_rd->key()) && m_scope == b.m_scope && equal);
133 gbp_route_domain::sweep()
135 if (rc_t::OK == m_id.rc()) {
136 HW::enqueue(new gbp_route_domain_cmds::delete_cmd(m_id));
142 gbp_route_domain::replay()
144 if (rc_t::OK == m_id.rc()) {
145 if (m_ip4_uu_fwd && m_ip6_uu_fwd)
146 HW::enqueue(new gbp_route_domain_cmds::create_cmd(
147 m_id, m_scope, m_ip4_uu_fwd->handle(), m_ip6_uu_fwd->handle()));
149 HW::enqueue(new gbp_route_domain_cmds::create_cmd(
150 m_id, m_scope, handle_t::INVALID, handle_t::INVALID));
154 gbp_route_domain::~gbp_route_domain()
158 // not in the DB anymore.
159 m_db.release(m_id.data(), this);
163 gbp_route_domain::to_string() const
165 std::ostringstream s;
166 s << "gbp-route-domain:[" << m_rd->to_string() << "scope:" << m_scope;
169 s << " v4-uu:[" << m_ip4_uu_fwd->to_string() << "]";
171 s << " v6-uu:[" << m_ip6_uu_fwd->to_string() << "]";
178 std::shared_ptr<gbp_route_domain>
179 gbp_route_domain::find(const key_t& key)
181 return (m_db.find(key));
185 gbp_route_domain::update(const gbp_route_domain& desired)
187 if (rc_t::OK != m_id.rc()) {
188 if (m_ip4_uu_fwd && m_ip6_uu_fwd)
189 HW::enqueue(new gbp_route_domain_cmds::create_cmd(
190 m_id, m_scope, m_ip4_uu_fwd->handle(), m_ip6_uu_fwd->handle()));
192 HW::enqueue(new gbp_route_domain_cmds::create_cmd(
193 m_id, m_scope, handle_t::INVALID, handle_t::INVALID));
197 std::shared_ptr<gbp_route_domain>
198 gbp_route_domain::find_or_add(const gbp_route_domain& temp)
200 return (m_db.find_or_add(temp.key(), temp));
203 std::shared_ptr<gbp_route_domain>
204 gbp_route_domain::singular() const
206 return find_or_add(*this);
210 gbp_route_domain::dump(std::ostream& os)
216 gbp_route_domain::event_handler::handle_populate(const client_db::key_t& key)
219 * dump VPP Route domains
221 std::shared_ptr<gbp_route_domain_cmds::dump_cmd> cmd =
222 std::make_shared<gbp_route_domain_cmds::dump_cmd>();
227 for (auto& record : *cmd) {
228 auto& payload = record.get_payload();
230 std::shared_ptr<interface> ip6_uu_fwd =
231 interface::find(payload.rd.ip6_uu_sw_if_index);
232 std::shared_ptr<interface> ip4_uu_fwd =
233 interface::find(payload.rd.ip4_uu_sw_if_index);
235 if (ip6_uu_fwd && ip4_uu_fwd) {
236 gbp_route_domain rd(payload.rd.rd_id, payload.rd.scope, *ip4_uu_fwd,
239 VOM_LOG(log_level_t::DEBUG) << "dump: " << rd.to_string();
241 gbp_route_domain rd(payload.rd.rd_id, payload.rd.scope);
243 VOM_LOG(log_level_t::DEBUG) << "dump: " << rd.to_string();
248 gbp_route_domain::event_handler::event_handler()
250 OM::register_listener(this);
251 inspect::register_handler({ "grd", "groute" }, "GBP Route Domains", this);
255 gbp_route_domain::event_handler::handle_replay()
261 gbp_route_domain::event_handler::order() const
263 return (dependency_t::VIRTUAL_TABLE);
267 gbp_route_domain::event_handler::show(std::ostream& os)
274 * fd.io coding-style-patch-verification: ON
277 * eval: (c-set-style "mozilla")