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/l2_vtr.hpp"
24 #include "vom/object_base.hpp"
26 #include "vom/singular_db.hpp"
30 * A Clas representing the binding of an L2 interface to a bridge-domain
31 * and the properties of that binding.
33 class l2_binding : public object_base
37 * Key type for an L2 binding in the singular DB
39 typedef interface::key_t key_t;
41 struct l2_port_type_t : public enum_base<l2_port_type_t>
43 l2_port_type_t(const l2_port_type_t& l) = default;
44 ~l2_port_type_t() = default;
46 const static l2_port_type_t L2_PORT_TYPE_NORMAL;
47 const static l2_port_type_t L2_PORT_TYPE_BVI;
48 const static l2_port_type_t L2_PORT_TYPE_UU_FWD;
51 l2_port_type_t(int v, const std::string s);
55 * Construct a new object matching the desried state
57 l2_binding(const interface& itf, const bridge_domain& bd);
58 l2_binding(const interface& itf,
59 const bridge_domain& bd,
60 const l2_port_type_t& port_type);
65 l2_binding(const l2_binding& o);
73 * Return the binding's key
75 const key_t& key() const;
78 * Comparison operator - for UT
80 bool operator==(const l2_binding& l) const;
83 * Return the 'singular instance' of the L2 config that matches this
86 std::shared_ptr<l2_binding> singular() const;
89 * convert to string format for debug purposes
91 std::string to_string() const;
94 * Dump all l2_bindings into the stream provided
96 static void dump(std::ostream& os);
99 * Set the VTR operation on the binding/interface
101 void set(const l2_vtr::option_t& op, uint16_t tag);
104 * Static function to find the bridge_domain in the model
106 static std::shared_ptr<l2_binding> find(const key_t& key);
110 * Class definition for listeners to OM events
112 class event_handler : public OM::listener, public inspect::command_handler
116 virtual ~event_handler() = default;
119 * Handle a populate event
121 void handle_populate(const client_db::key_t& key);
124 * Handle a replay event
126 void handle_replay();
129 * Show the object in the Singular DB
131 void show(std::ostream& os);
134 * Get the sortable Id of the listener
136 dependency_t order() const;
140 * event_handler to register with OM
142 static event_handler m_evh;
145 * Enquue commonds to the VPP command Q for the update
147 void update(const l2_binding& obj);
150 * Find or Add the singular instance in the DB
152 static std::shared_ptr<l2_binding> find_or_add(const l2_binding& temp);
155 * It's the OM class that calls singular()
160 * It's the singular_db class that calls replay()
162 friend class singular_db<key_t, l2_binding>;
165 * Sweep/reap the object if still stale
170 * replay the object to create it in hardware
175 * A reference counting pointer the interface that this L2 layer
176 * represents. By holding the reference here, we can guarantee that
177 * this object will outlive the interface
179 const std::shared_ptr<interface> m_itf;
182 * A reference counting pointer the Bridge-Domain that this L2
183 * interface is bound to. By holding the reference here, we can
184 * guarantee that this object will outlive the BD.
186 std::shared_ptr<bridge_domain> m_bd;
189 * l2 port type i.e. normal, bvi or unknown unicast
191 l2_port_type_t m_port_type;
194 * HW configuration for the binding. The bool representing the
197 HW::item<bool> m_binding;
200 * HW configuration for the VTR option
202 HW::item<l2_vtr::option_t> m_vtr_op;
205 * The Dot1q tag for the VTR operation
207 uint16_t m_vtr_op_tag;
210 * A map of all L2 interfaces key against the interface's handle_t
212 static singular_db<key_t, l2_binding> m_db;
217 * fd.io coding-style-patch-verification: ON
220 * eval: (c-set-style "mozilla")