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/singular_db.hpp"
29 * A Clas representing the binding of an L2 interface to a bridge-domain
30 * and the properties of that binding.
32 class l2_binding : public object_base
36 * Key type for an L2 binding in the singular DB
38 typedef interface::key_t key_t;
40 struct l2_vtr_op_t : public enum_base<l2_vtr_op_t>
42 l2_vtr_op_t(const l2_vtr_op_t& l) = default;
43 ~l2_vtr_op_t() = default;
45 const static l2_vtr_op_t L2_VTR_DISABLED;
46 const static l2_vtr_op_t L2_VTR_PUSH_1;
47 const static l2_vtr_op_t L2_VTR_PUSH_2;
48 const static l2_vtr_op_t L2_VTR_POP_1;
49 const static l2_vtr_op_t L2_VTR_POP_2;
50 const static l2_vtr_op_t L2_VTR_TRANSLATE_1_1;
51 const static l2_vtr_op_t L2_VTR_TRANSLATE_1_2;
52 const static l2_vtr_op_t L2_VTR_TRANSLATE_2_1;
53 const static l2_vtr_op_t L2_VTR_TRANSLATE_2_2;
56 l2_vtr_op_t(int v, const std::string s);
60 * Construct a new object matching the desried state
62 l2_binding(const interface& itf, const bridge_domain& bd);
67 l2_binding(const l2_binding& o);
75 * Return the binding's key
77 const key_t& key() const;
80 * Comparison operator - for UT
82 bool operator==(const l2_binding& l) const;
85 * Return the 'singular instance' of the L2 config that matches this
88 std::shared_ptr<l2_binding> singular() const;
91 * convert to string format for debug purposes
93 std::string to_string() const;
96 * Dump all l2_bindings into the stream provided
98 static void dump(std::ostream& os);
101 * Set the VTR operation on the binding/interface
103 void set(const l2_vtr_op_t& op, uint16_t tag);
106 * Static function to find the bridge_domain in the model
108 static std::shared_ptr<l2_binding> find(const key_t& key);
112 * Class definition for listeners to OM events
114 class event_handler : public OM::listener, public inspect::command_handler
118 virtual ~event_handler() = default;
121 * Handle a populate event
123 void handle_populate(const client_db::key_t& key);
126 * Handle a replay event
128 void handle_replay();
131 * Show the object in the Singular DB
133 void show(std::ostream& os);
136 * Get the sortable Id of the listener
138 dependency_t order() const;
142 * event_handler to register with OM
144 static event_handler m_evh;
147 * Enquue commonds to the VPP command Q for the update
149 void update(const l2_binding& obj);
152 * Find or Add the singular instance in the DB
154 static std::shared_ptr<l2_binding> find_or_add(const l2_binding& temp);
157 * It's the OM class that calls singular()
162 * It's the singular_db class that calls replay()
164 friend class singular_db<key_t, l2_binding>;
167 * Sweep/reap the object if still stale
172 * replay the object to create it in hardware
177 * A reference counting pointer the interface that this L2 layer
178 * represents. By holding the reference here, we can guarantee that
179 * this object will outlive the interface
181 const std::shared_ptr<interface> m_itf;
184 * A reference counting pointer the Bridge-Domain that this L2
185 * interface is bound to. By holding the reference here, we can
186 * guarantee that this object will outlive the BD.
188 std::shared_ptr<bridge_domain> m_bd;
191 * HW configuration for the binding. The bool representing the
194 HW::item<bool> m_binding;
197 * HW configuration for the VTR option
199 HW::item<l2_vtr_op_t> m_vtr_op;
202 * The Dot1q tag for the VTR operation
204 uint16_t m_vtr_op_tag;
207 * A map of all L2 interfaces key against the interface's handle_t
209 static singular_db<key_t, l2_binding> m_db;
214 * fd.io coding-style-patch-verification: ON
217 * eval: (c-set-style "mozilla")