blob: 7053390b7c73884c121a07339b78c158fc607115 [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"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070017#include "vom/arp_proxy_binding_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070018
19namespace VOM {
20
21/**
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070022 * A DB of all ARP proxy bindings configs
Neale Ranns812ed392017-10-16 04:20:13 -070023 */
Neale Rannsfd920602017-11-23 12:15:00 -080024singular_db<interface::key_t, arp_proxy_binding> arp_proxy_binding::m_db;
Neale Ranns812ed392017-10-16 04:20:13 -070025
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) {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070055 HW::enqueue(
56 new arp_proxy_binding_cmds::unbind_cmd(m_binding, m_itf->handle()));
Neale Ranns812ed392017-10-16 04:20:13 -070057 }
58 HW::write();
59}
60
61void
62arp_proxy_binding::dump(std::ostream& os)
63{
64 m_db.dump(os);
65}
66
67void
68arp_proxy_binding::replay()
69{
70 if (m_binding) {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070071 HW::enqueue(
72 new arp_proxy_binding_cmds::bind_cmd(m_binding, m_itf->handle()));
Neale Ranns812ed392017-10-16 04:20:13 -070073 }
74}
75
76std::string
77arp_proxy_binding::to_string() const
78{
79 std::ostringstream s;
80 s << "ArpProxy-binding: " << m_itf->to_string();
81
82 return (s.str());
83}
84
85void
86arp_proxy_binding::update(const arp_proxy_binding& desired)
87{
88 /*
89 * the desired state is always that the interface should be created
90 */
91 if (!m_binding) {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070092 HW::enqueue(
93 new arp_proxy_binding_cmds::bind_cmd(m_binding, m_itf->handle()));
Neale Ranns812ed392017-10-16 04:20:13 -070094 }
95}
96
97std::shared_ptr<arp_proxy_binding>
98arp_proxy_binding::find_or_add(const arp_proxy_binding& temp)
99{
100 return (m_db.find_or_add(temp.m_itf->key(), temp));
101}
102
103std::shared_ptr<arp_proxy_binding>
104arp_proxy_binding::singular() const
105{
106 return find_or_add(*this);
107}
108
109arp_proxy_binding::event_handler::event_handler()
110{
111 OM::register_listener(this);
Mohsin Kazmib5eb3b12018-02-26 18:36:17 +0100112 inspect::register_handler({ "arp-proxy-binding" }, "ARP proxy bindings",
113 this);
Neale Ranns812ed392017-10-16 04:20:13 -0700114}
115
116void
117arp_proxy_binding::event_handler::handle_replay()
118{
119 m_db.replay();
120}
121
122void
123arp_proxy_binding::event_handler::handle_populate(const client_db::key_t& key)
124{
125 // FIXME
126}
127
128dependency_t
129arp_proxy_binding::event_handler::order() const
130{
131 return (dependency_t::BINDING);
132}
133
134void
135arp_proxy_binding::event_handler::show(std::ostream& os)
136{
137 m_db.dump(os);
138}
139}
140/*
141 * fd.io coding-style-patch-verification: ON
142 *
143 * Local Variables:
144 * eval: (c-set-style "mozilla")
145 * End:
146 */