blob: 78fc81a894a0e93709e759e8576e3286e8b78fde [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#ifndef __VOM_ARP_PROXY_CONFIG_H__
17#define __VOM_ARP_PROXY_CONFIG_H__
18
19#include "vom/dump_cmd.hpp"
20#include "vom/hw.hpp"
21#include "vom/inspect.hpp"
22#include "vom/object_base.hpp"
23#include "vom/om.hpp"
24#include "vom/rpc_cmd.hpp"
25#include "vom/singular_db.hpp"
26
27#include <vapi/vpe.api.vapi.hpp>
28
29namespace VOM {
30/**
31 * A representation of LLDP client configuration on an interface
32 */
33class arp_proxy_config : public object_base
34{
35public:
36 /**
37 * Key type
38 */
39 typedef std::pair<boost::asio::ip::address_v4, boost::asio::ip::address_v4>
40 key_t;
41
42 /**
43 * Construct a new object matching the desried state
44 */
45 arp_proxy_config(const boost::asio::ip::address_v4& low,
46 const boost::asio::ip::address_v4& high);
47
48 /**
49 * Copy Constructor
50 */
51 arp_proxy_config(const arp_proxy_config& o);
52
53 /**
54 * Destructor
55 */
56 ~arp_proxy_config();
57
58 /**
59 * Return the 'singular' of the LLDP config that matches this object
60 */
61 std::shared_ptr<arp_proxy_config> singular() const;
62
63 /**
64 * convert to string format for debug purposes
65 */
66 std::string to_string() const;
67
68 /**
69 * Dump all LLDP configs into the stream provided
70 */
71 static void dump(std::ostream& os);
72
73 /**
74 * A command class that adds the ARP Proxy config
75 */
76 class config_cmd
77 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Proxy_arp_add_del>
78 {
79 public:
80 /**
81 * Constructor
82 */
83 config_cmd(HW::item<bool>& item,
84 const boost::asio::ip::address_v4& lo,
85 const boost::asio::ip::address_v4& high);
86
87 /**
88 * Issue the command to VPP/HW
89 */
90 rc_t issue(connection& con);
91 /**
92 * convert to string format for debug purposes
93 */
94 std::string to_string() const;
95
96 /**
97 * Comparison operator - only used for UT
98 */
99 bool operator==(const config_cmd& i) const;
100
101 private:
102 /**
103 * Address range
104 */
105 const boost::asio::ip::address_v4 m_low;
106 const boost::asio::ip::address_v4 m_high;
107 };
108
109 /**
110 * A cmd class that Unconfigs ArpProxy Config from an interface
111 */
112 class unconfig_cmd
113 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Proxy_arp_add_del>
114 {
115 public:
116 /**
117 * Constructor
118 */
119 unconfig_cmd(HW::item<bool>& item,
120 const boost::asio::ip::address_v4& lo,
121 const boost::asio::ip::address_v4& hig);
122
123 /**
124 * Issue the command to VPP/HW
125 */
126 rc_t issue(connection& con);
127 /**
128 * convert to string format for debug purposes
129 */
130 std::string to_string() const;
131
132 /**
133 * Comparison operator - only used for UT
134 */
135 bool operator==(const unconfig_cmd& i) const;
136
137 private:
138 /**
139 * Address range
140 */
141 const boost::asio::ip::address_v4 m_low;
142 const boost::asio::ip::address_v4 m_high;
143 };
144
145private:
146 /**
147 * Class definition for listeners to OM events
148 */
149 class event_handler : public OM::listener, public inspect::command_handler
150 {
151 public:
152 event_handler();
153 virtual ~event_handler() = default;
154
155 /**
156 * Handle a populate event
157 */
158 void handle_populate(const client_db::key_t& key);
159
160 /**
161 * Handle a replay event
162 */
163 void handle_replay();
164
165 /**
166 * Show the object in the Singular DB
167 */
168 void show(std::ostream& os);
169
170 /**
171 * Get the sortable Id of the listener
172 */
173 dependency_t order() const;
174 };
175
176 /**
177 * event_handler to register with OM
178 */
179 static event_handler m_evh;
180
181 /**
182 * Enquue commonds to the VPP command Q for the update
183 */
184 void update(const arp_proxy_config& obj);
185
186 /**
187 * Find or add LLDP config to the OM
188 */
189 static std::shared_ptr<arp_proxy_config> find_or_add(
190 const arp_proxy_config& temp);
191
192 /*
193 * It's the OM class that calls singular()
194 */
195 friend class OM;
196
197 /**
198 * It's the singular_db class that calls replay()
199 */
200 friend class singular_db<arp_proxy_config::key_t, arp_proxy_config>;
201
202 /**
203 * Sweep/reap the object if still stale
204 */
205 void sweep(void);
206
207 /**
208 * replay the object to create it in hardware
209 */
210 void replay(void);
211
212 /**
213 * Address range
214 */
215 const boost::asio::ip::address_v4 m_low;
216 const boost::asio::ip::address_v4 m_high;
217
218 /**
219 * A map of all ArpProxy configs keyed against the interface.
220 */
221 static singular_db<arp_proxy_config::key_t, arp_proxy_config> m_db;
222
223 /**
224 * HW configuration for the config. The bool representing the
225 * do/don't configured/unconfigured.
226 */
227 HW::item<bool> m_config;
228};
229
230std::ostream& operator<<(std::ostream& os, const arp_proxy_config::key_t& key);
231};
232
233/*
234 * fd.io coding-style-patch-verification: ON
235 *
236 * Local Variables:
237 * eval: (c-set-style "mozilla")
238 * End:
239 */
240
241#endif