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_L2_BINDING_H__
17 #define __VOM_L2_BINDING_H__
19 #include "vom/bridge_domain.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"
27 #include "vom/vxlan_tunnel.hpp"
31 * A Clas representing the binding of an L2 interface to a bridge-domain
32 * and the properties of that binding.
34 class l2_binding : public object_base
37 struct l2_vtr_op_t : public enum_base<l2_vtr_op_t>
39 l2_vtr_op_t(const l2_vtr_op_t& l) = default;
40 ~l2_vtr_op_t() = default;
42 const static l2_vtr_op_t L2_VTR_DISABLED;
43 const static l2_vtr_op_t L2_VTR_PUSH_1;
44 const static l2_vtr_op_t L2_VTR_PUSH_2;
45 const static l2_vtr_op_t L2_VTR_POP_1;
46 const static l2_vtr_op_t L2_VTR_POP_2;
47 const static l2_vtr_op_t L2_VTR_TRANSLATE_1_1;
48 const static l2_vtr_op_t L2_VTR_TRANSLATE_1_2;
49 const static l2_vtr_op_t L2_VTR_TRANSLATE_2_1;
50 const static l2_vtr_op_t L2_VTR_TRANSLATE_2_2;
53 l2_vtr_op_t(int v, const std::string s);
57 * Construct a new object matching the desried state
59 l2_binding(const interface& itf, const bridge_domain& bd);
64 l2_binding(const l2_binding& o);
72 * Return the 'singular instance' of the L2 config that matches this
75 std::shared_ptr<l2_binding> singular() const;
78 * convert to string format for debug purposes
80 std::string to_string() const;
83 * Dump all l2_bindings into the stream provided
85 static void dump(std::ostream& os);
88 * Set the VTR operation on the binding/interface
90 void set(const l2_vtr_op_t& op, uint16_t tag);
93 * A functor class that binds L2 configuration to an interface
96 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Sw_interface_set_l2_bridge>
102 bind_cmd(HW::item<bool>& item,
108 * Issue the command to VPP/HW
110 rc_t issue(connection& con);
112 * convert to string format for debug purposes
114 std::string to_string() const;
117 * Comparison operator - only used for UT
119 bool operator==(const bind_cmd& i) const;
123 * The interface to bind
125 const handle_t m_itf;
128 * The bridge-domain to bind to
133 * Is it a BVI interface that is being bound
139 * A cmd class that Unbinds L2 configuration from an interface
142 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Sw_interface_set_l2_bridge>
148 unbind_cmd(HW::item<bool>& item,
154 * Issue the command to VPP/HW
156 rc_t issue(connection& con);
158 * convert to string format for debug purposes
160 std::string to_string() const;
163 * Comparison operator - only used for UT
165 bool operator==(const unbind_cmd& i) const;
169 * The interface to bind
171 const handle_t m_itf;
174 * The bridge-domain to bind to
179 * Is it a BVI interface that is being bound
185 * A cmd class sets the VTR operation
187 class set_vtr_op_cmd : public rpc_cmd<HW::item<l2_vtr_op_t>,
189 vapi::L2_interface_vlan_tag_rewrite>
195 set_vtr_op_cmd(HW::item<l2_vtr_op_t>& item,
200 * Issue the command to VPP/HW
202 rc_t issue(connection& con);
205 * convert to string format for debug purposes
207 std::string to_string() const;
210 * Comparison operator - only used for UT
212 bool operator==(const set_vtr_op_cmd& i) const;
216 * The interface to bind
218 const handle_t m_itf;
221 * The tag for the operation
228 * Class definition for listeners to OM events
230 class event_handler : public OM::listener, public inspect::command_handler
234 virtual ~event_handler() = default;
237 * Handle a populate event
239 void handle_populate(const client_db::key_t& key);
242 * Handle a replay event
244 void handle_replay();
247 * Show the object in the Singular DB
249 void show(std::ostream& os);
252 * Get the sortable Id of the listener
254 dependency_t order() const;
258 * event_handler to register with OM
260 static event_handler m_evh;
263 * Enquue commonds to the VPP command Q for the update
265 void update(const l2_binding& obj);
268 * Find or Add the singular instance in the DB
270 static std::shared_ptr<l2_binding> find_or_add(const l2_binding& temp);
273 * It's the OM class that calls singular()
278 * It's the singular_db class that calls replay()
280 friend class singular_db<const handle_t, l2_binding>;
283 * Sweep/reap the object if still stale
288 * replay the object to create it in hardware
293 * A reference counting pointer the interface that this L2 layer
294 * represents. By holding the reference here, we can guarantee that
295 * this object will outlive the interface
297 const std::shared_ptr<interface> m_itf;
300 * A reference counting pointer the Bridge-Domain that this L2
301 * interface is bound to. By holding the reference here, we can
302 * guarantee that this object will outlive the BD.
304 const std::shared_ptr<bridge_domain> m_bd;
307 * HW configuration for the binding. The bool representing the
310 HW::item<bool> m_binding;
313 * HW configuration for the VTR option
315 HW::item<l2_vtr_op_t> m_vtr_op;
318 * The Dot1q tag for the VTR operation
320 uint16_t m_vtr_op_tag;
323 * A map of all L2 interfaces key against the interface's handle_t
325 static singular_db<const handle_t, l2_binding> m_db;
330 * fd.io coding-style-patch-verification: ON
333 * eval: (c-set-style "mozilla")