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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __VOM_L3_BINDING_H__
17 #define __VOM_L3_BINDING_H__
19 #include "vom/dump_cmd.hpp"
21 #include "vom/inspect.hpp"
22 #include "vom/interface.hpp"
23 #include "vom/object_base.hpp"
25 #include "vom/rpc_cmd.hpp"
26 #include "vom/singular_db.hpp"
28 #include <vapi/ip.api.vapi.hpp>
32 * A representation of L3 configuration on an interface
34 class l3_binding : public object_base
38 * Construct a new object matching the desried state
40 l3_binding(const interface& itf, const route::prefix_t& pfx);
45 l3_binding(const l3_binding& o);
53 * Return the 'singular instance' of the L3-Config that matches this
56 std::shared_ptr<l3_binding> singular() const;
59 * convert to string format for debug purposes
61 std::string to_string() const;
64 * Return the prefix associated with this L3config
66 const route::prefix_t& prefix() const;
69 * Dump all l3_bindings into the stream provided
71 static void dump(std::ostream& os);
74 * The key type for l3_bindings
76 typedef std::pair<interface::key_type, route::prefix_t> key_type_t;
79 * Find an singular instance in the DB for the interface passed
81 static std::deque<std::shared_ptr<l3_binding>> find(const interface& i);
84 * A functor class that binds the L3 config to the interface
87 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Sw_interface_add_del_address>
93 bind_cmd(HW::item<bool>& item,
95 const route::prefix_t& pfx);
98 * Issue the command to VPP/HW
100 rc_t issue(connection& con);
102 * convert to string format for debug purposes
104 std::string to_string() const;
107 * Comparison operator - only used for UT
109 bool operator==(const bind_cmd& i) const;
113 * Reference to the interface to bind to
115 const handle_t& m_itf;
120 const route::prefix_t& m_pfx;
124 * A cmd class that Unbinds L3 Config from an interface
127 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Sw_interface_add_del_address>
133 unbind_cmd(HW::item<bool>& item,
135 const route::prefix_t& pfx);
138 * Issue the command to VPP/HW
140 rc_t issue(connection& con);
142 * convert to string format for debug purposes
144 std::string to_string() const;
147 * Comparison operator - only used for UT
149 bool operator==(const unbind_cmd& i) const;
153 * Reference to the interface to unbind fomr
155 const handle_t& m_itf;
158 * The prefix to unbind
160 const route::prefix_t& m_pfx;
164 * A cmd class that Dumps all the IPv4 L3 configs
166 class dump_v4_cmd : public dump_cmd<vapi::Ip_address_dump>
172 dump_v4_cmd(const handle_t& itf);
173 dump_v4_cmd(const dump_v4_cmd& d);
176 * Issue the command to VPP/HW
178 rc_t issue(connection& con);
180 * convert to string format for debug purposes
182 std::string to_string() const;
185 * Comparison operator - only used for UT
187 bool operator==(const dump_v4_cmd& i) const;
196 * The interface to get the addresses for
198 const handle_t& m_itf;
203 * Class definition for listeners to OM events
205 class event_handler : public OM::listener, public inspect::command_handler
209 virtual ~event_handler() = default;
212 * Handle a populate event
214 void handle_populate(const client_db::key_t& key);
217 * Handle a replay event
219 void handle_replay();
222 * Show the object in the Singular DB
224 void show(std::ostream& os);
227 * Get the sortable Id of the listener
229 dependency_t order() const;
233 * event_handler to register with OM
235 static event_handler m_evh;
238 * Enquue commonds to the VPP command Q for the update
240 void update(const l3_binding& obj);
243 * Find or add the singular instance in the DB
245 static std::shared_ptr<l3_binding> find_or_add(const l3_binding& temp);
248 * It's the VPPHW class that updates the objects in HW
253 e* It's the singular_db class that calls replay()
255 friend class singular_db<key_type_t, l3_binding>;
258 * Sweep/reap the object if still stale
263 * replay the object to create it in hardware
268 * A reference counting pointer the interface that this L3 layer
269 * represents. By holding the reference here, we can guarantee that
270 * this object will outlive the interface
272 const std::shared_ptr<interface> m_itf;
275 * The prefix for this L3 configuration
277 const route::prefix_t& m_pfx;
280 * HW configuration for the binding. The bool representing the
283 HW::item<bool> m_binding;
286 * A map of all L3 configs keyed against a combination of the interface
289 static singular_db<key_type_t, l3_binding> m_db;
293 * Ostream output for the key
295 std::ostream& operator<<(std::ostream& os, const l3_binding::key_type_t& key);
299 * fd.io coding-style-patch-verification: ON
302 * eval: (c-set-style "mozilla")