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/dhcp_config.hpp"
17 #include "vom/dhcp_config_cmds.hpp"
18 #include "vom/singular_db_funcs.hpp"
22 * A DB of all DHCP configs
24 singular_db<interface::key_t, dhcp_config> dhcp_config::m_db;
26 dhcp_config::event_handler dhcp_config::m_evh;
28 dhcp_config::dhcp_config(const interface& itf,
29 const std::string& hostname,
30 bool set_broadcast_flag)
31 : m_itf(itf.singular())
32 , m_hostname(hostname)
33 , m_client_id(l2_address_t::ZERO)
34 , m_set_broadcast_flag(set_broadcast_flag)
39 dhcp_config::dhcp_config(const interface& itf,
40 const std::string& hostname,
41 const l2_address_t& client_id,
42 bool set_broadcast_flag)
43 : m_itf(itf.singular())
44 , m_hostname(hostname)
45 , m_client_id(client_id)
46 , m_set_broadcast_flag(set_broadcast_flag)
51 dhcp_config::dhcp_config(const dhcp_config& o)
53 , m_hostname(o.m_hostname)
54 , m_client_id(o.m_client_id)
55 , m_set_broadcast_flag(o.m_set_broadcast_flag)
60 dhcp_config::~dhcp_config()
64 // not in the DB anymore.
65 m_db.release(m_itf->key(), this);
69 dhcp_config::operator==(const dhcp_config& l) const
71 return ((key() == l.key()) && (m_hostname == l.m_hostname) &&
72 (m_client_id == l.m_client_id));
75 const dhcp_config::key_t&
76 dhcp_config::key() const
78 return (m_itf->key());
86 new dhcp_config_cmds::unbind_cmd(m_binding, m_itf->handle(), m_hostname));
92 dhcp_config::dump(std::ostream& os)
101 HW::enqueue(new dhcp_config_cmds::bind_cmd(m_binding, m_itf->handle(),
102 m_hostname, m_client_id));
107 dhcp_config::to_string() const
109 std::ostringstream s;
110 s << "Dhcp-config: " << m_itf->to_string() << " hostname:" << m_hostname
111 << " client_id:[" << m_client_id << "] " << m_binding.to_string();
117 dhcp_config::update(const dhcp_config& desired)
120 * the desired state is always that the interface should be created
123 HW::enqueue(new dhcp_config_cmds::bind_cmd(m_binding, m_itf->handle(),
124 m_hostname, m_client_id));
128 std::shared_ptr<dhcp_config>
129 dhcp_config::find_or_add(const dhcp_config& temp)
131 return (m_db.find_or_add(temp.m_itf->key(), temp));
134 std::shared_ptr<dhcp_config>
135 dhcp_config::find(const key_t& k)
137 return (m_db.find(k));
140 std::shared_ptr<dhcp_config>
141 dhcp_config::singular() const
143 return find_or_add(*this);
146 dhcp_config::event_listener::event_listener()
147 : m_status(rc_t::NOOP)
152 dhcp_config::event_listener::status()
157 dhcp_config::event_handler::event_handler()
159 OM::register_listener(this);
160 inspect::register_handler({ "dhcp" }, "DHCP configurations", this);
164 dhcp_config::event_handler::handle_replay()
170 dhcp_config::event_handler::handle_populate(const client_db::key_t& key)
176 dhcp_config::event_handler::order() const
178 return (dependency_t::BINDING);
182 dhcp_config::event_handler::show(std::ostream& os)
189 * fd.io coding-style-patch-verification: ON
192 * eval: (c-set-style "mozilla")