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/route_domain.hpp"
17 #include "vom/cmd.hpp"
18 #include "vom/route_domain_cmds.hpp"
19 #include "vom/singular_db_funcs.hpp"
23 route_domain::event_handler route_domain::m_evh;
26 * A DB of al the interfaces, key on the name
28 singular_db<route::table_id_t, route_domain> route_domain::m_db;
31 * Construct a new object matching the desried state
33 route_domain::route_domain(route::table_id_t id)
40 route_domain::route_domain(const route_domain& o)
43 , m_table_id(o.m_table_id)
48 route_domain::operator==(const route_domain& r) const
50 return (m_table_id == r.m_table_id);
54 route_domain::table_id() const
60 route_domain::key() const
70 new route_domain_cmds::delete_cmd(m_hw_v4, l3_proto_t::IPV4, m_table_id));
74 new route_domain_cmds::delete_cmd(m_hw_v6, l3_proto_t::IPV6, m_table_id));
80 route_domain::replay()
84 new route_domain_cmds::create_cmd(m_hw_v4, l3_proto_t::IPV4, m_table_id));
88 new route_domain_cmds::create_cmd(m_hw_v6, l3_proto_t::IPV6, m_table_id));
92 route_domain::~route_domain()
96 // not in the DB anymore.
97 m_db.release(m_table_id, this);
101 route_domain::to_string() const
103 std::ostringstream s;
104 s << "route-domain:["
105 << "table-id:" << m_table_id << " v4:" << m_hw_v4.to_string()
106 << " v6:" << m_hw_v6.to_string() << "]";
111 std::shared_ptr<route_domain>
112 route_domain::find(const key_t& k)
114 return (m_db.find(k));
118 route_domain::update(const route_domain& desired)
121 * create the table if it is not yet created
123 if (rc_t::OK != m_hw_v4.rc()) {
125 new route_domain_cmds::create_cmd(m_hw_v4, l3_proto_t::IPV4, m_table_id));
127 if (rc_t::OK != m_hw_v6.rc()) {
129 new route_domain_cmds::create_cmd(m_hw_v6, l3_proto_t::IPV6, m_table_id));
133 std::shared_ptr<route_domain>
134 route_domain::get_default()
136 route_domain rd(route::DEFAULT_TABLE);
138 return (find_or_add(rd));
141 std::shared_ptr<route_domain>
142 route_domain::find_or_add(const route_domain& temp)
144 return (m_db.find_or_add(temp.m_table_id, temp));
147 std::shared_ptr<route_domain>
148 route_domain::singular() const
150 return find_or_add(*this);
154 route_domain::dump(std::ostream& os)
160 route_domain::event_handler::handle_populate(const client_db::key_t& key)
164 route_domain::event_handler::event_handler()
166 OM::register_listener(this);
167 inspect::register_handler({ "rd", "route-domain" }, "Route Domains", this);
171 route_domain::event_handler::handle_replay()
177 route_domain::event_handler::order() const
179 return (dependency_t::TABLE);
183 route_domain::event_handler::show(std::ostream& os)
191 * fd.io coding-style-patch-verification: ON
194 * eval: (c-set-style "mozilla")