blob: 141b98b672f2da71ef027a3af2e380ababc3d31f [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_NEIGHBOUR_H__
17#define __VOM_NEIGHBOUR_H__
18
19#include "vom/dump_cmd.hpp"
20#include "vom/interface.hpp"
21#include "vom/singular_db.hpp"
22#include "vom/types.hpp"
23
24#include <vapi/l2.api.vapi.hpp>
25
26namespace VOM {
27/**
28 * A entry in the ARP termination table of a Bridge Domain
29 */
30class neighbour : public object_base
31{
32public:
33 /**
34 * The key for a bridge_domain ARP entry;
35 * the BD, IP address and MAC address
36 */
37 typedef std::tuple<interface::key_type,
38 mac_address_t,
39 boost::asio::ip::address>
40 key_t;
41
42 /**
43 * Construct an ARP entry
44 */
45 neighbour(const interface& itf,
46 const mac_address_t& mac,
47 const boost::asio::ip::address& ip_addr);
48
49 /**
50 * Copy Construct
51 */
52 neighbour(const neighbour& r);
53
54 /**
55 * Destructor
56 */
57 ~neighbour();
58
59 /**
60 * Return the matching 'singular instance'
61 */
62 std::shared_ptr<neighbour> singular() const;
63
64 /**
65 * Find the instnace of the bridge_domain domain in the OM
66 */
67 static std::shared_ptr<neighbour> find(const neighbour& temp);
68
69 /**
70 * Dump all bridge_domain-doamin into the stream provided
71 */
72 static void dump(std::ostream& os);
73
74 /**
75 * replay the object to create it in hardware
76 */
77 void replay(void);
78
79 /**
80 * Convert to string for debugging
81 */
82 std::string to_string() const;
83
84 /**
85 * A command class that creates or updates the bridge domain ARP Entry
86 */
87 class create_cmd
88 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Ip_neighbor_add_del>
89 {
90 public:
91 /**
92 * Constructor
93 */
94 create_cmd(HW::item<bool>& item,
95 handle_t itf,
96 const mac_address_t& mac,
97 const boost::asio::ip::address& ip_addr);
98
99 /**
100 * Issue the command to VPP/HW
101 */
102 rc_t issue(connection& con);
103
104 /**
105 * convert to string format for debug purposes
106 */
107 std::string to_string() const;
108
109 /**
110 * Comparison operator - only used for UT
111 */
112 bool operator==(const create_cmd& i) const;
113
114 private:
115 handle_t m_itf;
116 mac_address_t m_mac;
117 boost::asio::ip::address m_ip_addr;
118 };
119
120 /**
121 * A cmd class that deletes a bridge domain ARP entry
122 */
123 class delete_cmd
124 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Ip_neighbor_add_del>
125 {
126 public:
127 /**
128 * Constructor
129 */
130 delete_cmd(HW::item<bool>& item,
131 handle_t itf,
132 const mac_address_t& mac,
133 const boost::asio::ip::address& ip_addr);
134
135 /**
136 * Issue the command to VPP/HW
137 */
138 rc_t issue(connection& con);
139
140 /**
141 * convert to string format for debug purposes
142 */
143 std::string to_string() const;
144
145 /**
146 * Comparison operator - only used for UT
147 */
148 bool operator==(const delete_cmd& i) const;
149
150 private:
151 handle_t m_itf;
152 mac_address_t m_mac;
153 boost::asio::ip::address m_ip_addr;
154 };
155
156 /**
157 * A cmd class that Dumps all the neighbours
158 */
159 class dump_cmd : public VOM::dump_cmd<vapi::Ip_neighbor_dump>
160 {
161 public:
162 /**
163 * Constructor
164 */
165 dump_cmd(const handle_t& itf, const l3_proto_t& proto);
166 dump_cmd(const dump_cmd& d);
167
168 /**
169 * Issue the command to VPP/HW
170 */
171 rc_t issue(connection& con);
172 /**
173 * convert to string format for debug purposes
174 */
175 std::string to_string() const;
176
177 /**
178 * Comparison operator - only used for UT
179 */
180 bool operator==(const dump_cmd& i) const;
181
182 private:
183 /**
184 * HW reutrn code
185 */
186 HW::item<bool> item;
187
188 /**
189 * The interface to dump
190 */
191 handle_t m_itf;
192
193 /**
194 * V4 or V6
195 */
196 l3_proto_t m_proto;
197 };
198
199private:
200 /**
201 * Class definition for listeners to OM events
202 */
203 class event_handler : public OM::listener, public inspect::command_handler
204 {
205 public:
206 event_handler();
207 virtual ~event_handler() = default;
208
209 /**
210 * Handle a populate event
211 */
212 void handle_populate(const client_db::key_t& key);
213
214 /**
215 * Handle a replay event
216 */
217 void handle_replay();
218
219 /**
220 * Show the object in the Singular DB
221 */
222 void show(std::ostream& os);
223
224 /**
225 * Get the sortable Id of the listener
226 */
227 dependency_t order() const;
228 };
229
230 /**
231 * event_handler to register with OM
232 */
233 static event_handler m_evh;
234
235 /**
236 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
237 */
238 void update(const neighbour& obj);
239
240 /**
241 * Do the populate work
242 */
243 static void populate_i(const client_db::key_t& key,
244 std::shared_ptr<interface> itf,
245 const l3_proto_t& proto);
246
247 /**
248 * Find or add the instnace of the bridge_domain domain in the OM
249 */
250 static std::shared_ptr<neighbour> find_or_add(const neighbour& temp);
251
252 /*
253 * It's the VPPHW class that updates the objects in HW
254 */
255 friend class OM;
256
257 /**
258 * It's the singular_db class that calls replay()
259 */
260 friend class singular_db<key_t, neighbour>;
261
262 /**
263 * Sweep/reap the object if still stale
264 */
265 void sweep(void);
266
267 /**
268 * HW configuration for the result of creating the bridge_domain
269 */
270 HW::item<bool> m_hw;
271
272 /**
273 * The bridge_domain domain the bridge_domain is in.
274 */
275 std::shared_ptr<interface> m_itf;
276
277 /**
278 * The mac to match
279 */
280 mac_address_t m_mac;
281
282 /**
283 * The IP address
284 */
285 boost::asio::ip::address m_ip_addr;
286
287 /**
288 * A map of all bridge_domains
289 */
290 static singular_db<key_t, neighbour> m_db;
291};
292
293std::ostream& operator<<(std::ostream& os, const neighbour::key_t& key);
294};
295
296/*
297 * fd.io coding-style-patch-verification: ON
298 *
299 * Local Variables:
300 * eval: (c-set-style "mozilla")
301 * End:
302 */
303
304#endif