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_IP_UNNUMBERED_H__
17 #define __VOM_IP_UNNUMBERED_H__
20 #include "vom/inspect.hpp"
21 #include "vom/interface.hpp"
22 #include "vom/object_base.hpp"
24 #include "vom/rpc_cmd.hpp"
25 #include "vom/singular_db.hpp"
29 * A representation of IP unnumbered configuration on an interface
31 class ip_unnumbered : public object_base
35 * Construct a new object matching the desried state
37 * @param itf - The interface with no IP address
38 * @param l3_itf - The interface that has the IP address we wish to
41 ip_unnumbered(const interface& itf, const interface& l3_itf);
46 ip_unnumbered(const ip_unnumbered& o);
54 * Return the 'singular instance' of the L3-Config that matches this
57 std::shared_ptr<ip_unnumbered> singular() const;
60 * convert to string format for debug purposes
62 std::string to_string() const;
65 * Dump all ip_unnumbereds into the stream provided
67 static void dump(std::ostream& os);
70 * The key type for ip_unnumbereds
72 typedef interface::key_type key_t;
75 * Find an singular instance in the DB for the interface passed
77 static std::shared_ptr<ip_unnumbered> find(const interface& i);
80 * A command class that configures the IP unnumbered
83 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Sw_interface_set_unnumbered>
89 config_cmd(HW::item<bool>& item,
91 const handle_t& l3_itf);
94 * Issue the command to VPP/HW
96 rc_t issue(connection& con);
98 * convert to string format for debug purposes
100 std::string to_string() const;
103 * Comparison operator - only used for UT
105 bool operator==(const config_cmd& i) const;
109 * Reference to the interface for which the address is required
111 const handle_t& m_itf;
113 * Reference to the interface which has an address
115 const handle_t& m_l3_itf;
119 * A cmd class that Unconfigs L3 Config from an interface
122 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Sw_interface_set_unnumbered>
128 unconfig_cmd(HW::item<bool>& item,
130 const handle_t& l3_itf);
133 * Issue the command to VPP/HW
135 rc_t issue(connection& con);
137 * convert to string format for debug purposes
139 std::string to_string() const;
142 * Comparison operator - only used for UT
144 bool operator==(const unconfig_cmd& i) const;
148 * Reference to the interface for which the address is required
150 const handle_t& m_itf;
152 * Reference to the interface which has an address
154 const handle_t& m_l3_itf;
159 * Class definition for listeners to OM events
161 class event_handler : public OM::listener, public inspect::command_handler
165 virtual ~event_handler() = default;
168 * Handle a populate event
170 void handle_populate(const client_db::key_t& key);
173 * Handle a replay event
175 void handle_replay();
178 * Show the object in the Singular DB
180 void show(std::ostream& os);
183 * Get the sortable Id of the listener
185 dependency_t order() const;
189 * event_handler to register with OM
191 static event_handler m_evh;
194 * Enquue commonds to the VPP command Q for the update
196 void update(const ip_unnumbered& obj);
199 * Find or add the singular instance in the DB
201 static std::shared_ptr<ip_unnumbered> find_or_add(const ip_unnumbered& temp);
204 * It's the VPPHW class that updates the objects in HW
209 * It's the singular_db class that calls replay
211 friend class singular_db<key_t, ip_unnumbered>;
214 * Sweep/reap the object if still stale
219 * replay the object to create it in hardware
224 * A reference counting pointer the interface that requires an address.
226 const std::shared_ptr<interface> m_itf;
228 * A reference counting pointer the interface that has an address.
230 const std::shared_ptr<interface> m_l3_itf;
233 * HW configuration for the binding. The bool representing the
236 HW::item<bool> m_config;
239 * A map of all L3 configs keyed against a combination of the interface
242 static singular_db<key_t, ip_unnumbered> m_db;
247 * fd.io coding-style-patch-verification: ON
250 * eval: (c-set-style "mozilla")