VPP Object Model (VOM)
[vpp.git] / src / vpp-api / vom / arp_proxy_config.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_config.hpp"
17 #include "vom/cmd.hpp"
18
19 namespace VOM {
20 /**
21  * A DB of all LLDP configs
22  */
23 singular_db<arp_proxy_config::key_t, arp_proxy_config> arp_proxy_config::m_db;
24
25 arp_proxy_config::event_handler arp_proxy_config::m_evh;
26
27 arp_proxy_config::arp_proxy_config(const boost::asio::ip::address_v4& low,
28                                    const boost::asio::ip::address_v4& high)
29   : m_low(low)
30   , m_high(high)
31   , m_config(true)
32 {
33 }
34
35 arp_proxy_config::arp_proxy_config(const arp_proxy_config& o)
36   : m_low(o.m_low)
37   , m_high(o.m_high)
38   , m_config(o.m_config)
39 {
40 }
41
42 arp_proxy_config::~arp_proxy_config()
43 {
44   sweep();
45
46   // not in the DB anymore.
47   m_db.release(std::make_pair(m_low, m_high), this);
48 }
49
50 void
51 arp_proxy_config::sweep()
52 {
53   if (m_config) {
54     HW::enqueue(new unconfig_cmd(m_config, m_low, m_high));
55   }
56   HW::write();
57 }
58
59 void
60 arp_proxy_config::dump(std::ostream& os)
61 {
62   m_db.dump(os);
63 }
64
65 void
66 arp_proxy_config::replay()
67 {
68   if (m_config) {
69     HW::enqueue(new config_cmd(m_config, m_low, m_high));
70   }
71 }
72
73 std::string
74 arp_proxy_config::to_string() const
75 {
76   std::ostringstream s;
77   s << "ARP-proxy:"
78     << " low:" << m_low.to_string() << " high:" << m_high.to_string();
79
80   return (s.str());
81 }
82
83 void
84 arp_proxy_config::update(const arp_proxy_config& desired)
85 {
86   if (!m_config) {
87     HW::enqueue(new config_cmd(m_config, m_low, m_high));
88   }
89 }
90
91 std::shared_ptr<arp_proxy_config>
92 arp_proxy_config::find_or_add(const arp_proxy_config& temp)
93 {
94   return (m_db.find_or_add(std::make_pair(temp.m_low, temp.m_high), temp));
95 }
96
97 std::shared_ptr<arp_proxy_config>
98 arp_proxy_config::singular() const
99 {
100   return find_or_add(*this);
101 }
102
103 arp_proxy_config::event_handler::event_handler()
104 {
105   OM::register_listener(this);
106   inspect::register_handler({ "arp-proxy" }, "ARP Proxy configurations", this);
107 }
108
109 void
110 arp_proxy_config::event_handler::handle_replay()
111 {
112   m_db.replay();
113 }
114
115 void
116 arp_proxy_config::event_handler::handle_populate(const client_db::key_t& key)
117 {
118   // VPP provides no dump for ARP proxy.
119 }
120
121 dependency_t
122 arp_proxy_config::event_handler::order() const
123 {
124   return (dependency_t::GLOBAL);
125 }
126
127 void
128 arp_proxy_config::event_handler::show(std::ostream& os)
129 {
130   m_db.dump(os);
131 }
132
133 std::ostream&
134 operator<<(std::ostream& os, const arp_proxy_config::key_t& key)
135 {
136   os << "[" << key.first << ", " << key.second << "]";
137
138   return (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  */