blob: 77b1bfaacde2ca5de7cc23358ec1bb18cd857d0f [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -07001/*
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15
16#include "vom/arp_proxy_binding.hpp"
17#include "vom/cmd.hpp"
18
19namespace VOM {
20
21/**
22 * A DB of all LLDP configs
23 */
24singular_db<interface::key_type, arp_proxy_binding> arp_proxy_binding::m_db;
25
26arp_proxy_binding::event_handler arp_proxy_binding::m_evh;
27
28arp_proxy_binding::arp_proxy_binding(const interface& itf,
29 const arp_proxy_config& proxy_cfg)
30 : m_itf(itf.singular())
31 , m_arp_proxy_cfg(proxy_cfg.singular())
32 , m_binding(true)
33{
34}
35
36arp_proxy_binding::arp_proxy_binding(const arp_proxy_binding& o)
37 : m_itf(o.m_itf)
38 , m_arp_proxy_cfg(o.m_arp_proxy_cfg)
39 , m_binding(o.m_binding)
40{
41}
42
43arp_proxy_binding::~arp_proxy_binding()
44{
45 sweep();
46
47 // not in the DB anymore.
48 m_db.release(m_itf->key(), this);
49}
50
51void
52arp_proxy_binding::sweep()
53{
54 if (m_binding) {
55 HW::enqueue(new unbind_cmd(m_binding, m_itf->handle()));
56 }
57 HW::write();
58}
59
60void
61arp_proxy_binding::dump(std::ostream& os)
62{
63 m_db.dump(os);
64}
65
66void
67arp_proxy_binding::replay()
68{
69 if (m_binding) {
70 HW::enqueue(new bind_cmd(m_binding, m_itf->handle()));
71 }
72}
73
74std::string
75arp_proxy_binding::to_string() const
76{
77 std::ostringstream s;
78 s << "ArpProxy-binding: " << m_itf->to_string();
79
80 return (s.str());
81}
82
83void
84arp_proxy_binding::update(const arp_proxy_binding& desired)
85{
86 /*
87 * the desired state is always that the interface should be created
88 */
89 if (!m_binding) {
90 HW::enqueue(new bind_cmd(m_binding, m_itf->handle()));
91 }
92}
93
94std::shared_ptr<arp_proxy_binding>
95arp_proxy_binding::find_or_add(const arp_proxy_binding& temp)
96{
97 return (m_db.find_or_add(temp.m_itf->key(), temp));
98}
99
100std::shared_ptr<arp_proxy_binding>
101arp_proxy_binding::singular() const
102{
103 return find_or_add(*this);
104}
105
106arp_proxy_binding::event_handler::event_handler()
107{
108 OM::register_listener(this);
109 inspect::register_handler({ "arp-proxy" }, "ARP proxy bindings", this);
110}
111
112void
113arp_proxy_binding::event_handler::handle_replay()
114{
115 m_db.replay();
116}
117
118void
119arp_proxy_binding::event_handler::handle_populate(const client_db::key_t& key)
120{
121 // FIXME
122}
123
124dependency_t
125arp_proxy_binding::event_handler::order() const
126{
127 return (dependency_t::BINDING);
128}
129
130void
131arp_proxy_binding::event_handler::show(std::ostream& os)
132{
133 m_db.dump(os);
134}
135}
136/*
137 * fd.io coding-style-patch-verification: ON
138 *
139 * Local Variables:
140 * eval: (c-set-style "mozilla")
141 * End:
142 */