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)
40 gbp_route_domain::gbp_route_domain(const route_domain& rd,
41 const interface& ip4_uu_fwd,
42 const interface& ip6_uu_fwd)
45 , m_ip4_uu_fwd(ip4_uu_fwd.singular())
46 , m_ip6_uu_fwd(ip6_uu_fwd.singular())
50 gbp_route_domain::gbp_route_domain(const route_domain& rd)
56 const gbp_route_domain::key_t
57 gbp_route_domain::key() const
63 gbp_route_domain::id() const
65 return (m_rd->table_id());
69 gbp_route_domain::operator==(const gbp_route_domain& b) const
73 if (m_ip4_uu_fwd && b.m_ip4_uu_fwd)
74 equal &= (m_ip4_uu_fwd->key() == b.m_ip4_uu_fwd->key());
75 else if (!m_ip4_uu_fwd && !b.m_ip4_uu_fwd)
80 if (m_ip6_uu_fwd && b.m_ip6_uu_fwd)
81 equal &= (m_ip6_uu_fwd->key() == b.m_ip6_uu_fwd->key());
82 else if (!m_ip6_uu_fwd && !b.m_ip6_uu_fwd)
87 return ((m_rd->key() == b.m_rd->key()) && equal);
91 gbp_route_domain::sweep()
93 if (rc_t::OK == m_id.rc()) {
94 HW::enqueue(new gbp_route_domain_cmds::delete_cmd(m_id));
100 gbp_route_domain::replay()
102 if (rc_t::OK == m_id.rc()) {
103 if (m_ip4_uu_fwd && m_ip6_uu_fwd)
104 HW::enqueue(new gbp_route_domain_cmds::create_cmd(
105 m_id, m_ip4_uu_fwd->handle(), m_ip6_uu_fwd->handle()));
107 HW::enqueue(new gbp_route_domain_cmds::create_cmd(m_id, handle_t::INVALID,
112 gbp_route_domain::~gbp_route_domain()
116 // not in the DB anymore.
117 m_db.release(m_id.data(), this);
121 gbp_route_domain::to_string() const
123 std::ostringstream s;
124 s << "gbp-route-domain:[" << m_rd->to_string() << "]";
129 std::shared_ptr<gbp_route_domain>
130 gbp_route_domain::find(const key_t& key)
132 return (m_db.find(key));
136 gbp_route_domain::update(const gbp_route_domain& desired)
139 * the desired state is always that the interface should be created
141 if (rc_t::OK != m_id.rc()) {
142 if (m_ip4_uu_fwd && m_ip6_uu_fwd)
143 HW::enqueue(new gbp_route_domain_cmds::create_cmd(
144 m_id, m_ip4_uu_fwd->handle(), m_ip6_uu_fwd->handle()));
146 HW::enqueue(new gbp_route_domain_cmds::create_cmd(m_id, handle_t::INVALID,
151 std::shared_ptr<gbp_route_domain>
152 gbp_route_domain::find_or_add(const gbp_route_domain& temp)
154 return (m_db.find_or_add(temp.m_id.data(), temp));
157 std::shared_ptr<gbp_route_domain>
158 gbp_route_domain::singular() const
160 return find_or_add(*this);
164 gbp_route_domain::dump(std::ostream& os)
170 gbp_route_domain::event_handler::handle_populate(const client_db::key_t& key)
173 * dump VPP Route domains
175 std::shared_ptr<gbp_route_domain_cmds::dump_cmd> cmd =
176 std::make_shared<gbp_route_domain_cmds::dump_cmd>();
181 for (auto& record : *cmd) {
182 auto& payload = record.get_payload();
184 std::shared_ptr<interface> ip6_uu_fwd =
185 interface::find(payload.rd.ip6_uu_sw_if_index);
186 std::shared_ptr<interface> ip4_uu_fwd =
187 interface::find(payload.rd.ip4_uu_sw_if_index);
189 if (ip6_uu_fwd && ip4_uu_fwd) {
190 gbp_route_domain rd(payload.rd.rd_id, *ip4_uu_fwd, *ip6_uu_fwd);
192 VOM_LOG(log_level_t::DEBUG) << "dump: " << rd.to_string();
194 gbp_route_domain rd(payload.rd.rd_id);
196 VOM_LOG(log_level_t::DEBUG) << "dump: " << rd.to_string();
201 gbp_route_domain::event_handler::event_handler()
203 OM::register_listener(this);
204 inspect::register_handler({ "grd", "groute" }, "GBP Route Domains", this);
208 gbp_route_domain::event_handler::handle_replay()
214 gbp_route_domain::event_handler::order() const
216 return (dependency_t::TABLE);
220 gbp_route_domain::event_handler::show(std::ostream& os)
227 * fd.io coding-style-patch-verification: ON
230 * eval: (c-set-style "mozilla")