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"
21 * A DB of al the interfaces, key on the name
23 singular_db<route::table_id_t, route_domain> route_domain::m_db;
26 * Construct a new object matching the desried state
28 route_domain::route_domain(route::table_id_t id)
35 route_domain::route_domain(const route_domain& o)
38 , m_table_id(o.m_table_id)
43 route_domain::table_id() const
49 route_domain::key() const
58 HW::enqueue(new delete_cmd(m_hw_v4, l3_proto_t::IPV4, m_table_id));
61 HW::enqueue(new delete_cmd(m_hw_v6, l3_proto_t::IPV6, m_table_id));
67 route_domain::replay()
70 HW::enqueue(new create_cmd(m_hw_v4, l3_proto_t::IPV4, m_table_id));
73 HW::enqueue(new create_cmd(m_hw_v6, l3_proto_t::IPV6, m_table_id));
77 route_domain::~route_domain()
81 // not in the DB anymore.
82 m_db.release(m_table_id, this);
86 route_domain::to_string() const
90 << "table-id:" << m_table_id << " v4:" << m_hw_v4 << " v6:" << m_hw_v6
96 std::shared_ptr<route_domain>
97 route_domain::find(const route_domain& temp)
99 std::shared_ptr<route_domain> rd;
101 auto it = m_db.cbegin();
103 while (it != m_db.cend()) {
105 * The key in the DB is a pair of the interface's name and prefix.
106 * If the keys match, save the L3-config
108 auto key = it->first;
110 if (temp.table_id() == key) {
111 rd = it->second.lock();
122 route_domain::update(const route_domain& desired)
125 * create the table if it is not yet created
127 if (rc_t::OK != m_hw_v4.rc()) {
128 HW::enqueue(new create_cmd(m_hw_v4, l3_proto_t::IPV4, m_table_id));
130 if (rc_t::OK != m_hw_v6.rc()) {
131 HW::enqueue(new create_cmd(m_hw_v6, l3_proto_t::IPV6, m_table_id));
135 std::shared_ptr<route_domain>
136 route_domain::get_default()
138 route_domain rd(route::DEFAULT_TABLE);
140 return (find_or_add(rd));
143 std::shared_ptr<route_domain>
144 route_domain::find_or_add(const route_domain& temp)
146 return (m_db.find_or_add(temp.m_table_id, temp));
149 std::shared_ptr<route_domain>
150 route_domain::singular() const
152 return find_or_add(*this);
156 route_domain::dump(std::ostream& os)
162 * fd.io coding-style-patch-verification: ON
165 * eval: (c-set-style "mozilla")