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