2 * Copyright (c) 2018 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_XCONNECT_H__
17 #define __VOM_L2_XCONNECT_H__
20 #include "vom/inspect.hpp"
21 #include "vom/interface.hpp"
22 #include "vom/l2_vtr.hpp"
23 #include "vom/object_base.hpp"
25 #include "vom/singular_db.hpp"
29 * A Class representing the cross connnect of an L2 interface with another
32 class l2_xconnect : public object_base
36 * Key type for an L2 xconnect in the singular DB
38 typedef std::pair<interface::key_t, interface::key_t> key_t;
41 * Construct a new object matching the desried state
43 l2_xconnect(const interface& east_itf, const interface& west_itf);
48 l2_xconnect(const l2_xconnect& o);
56 * Return the xconnect's key
58 const key_t key() const;
61 * Comparison operator - for UT
63 bool operator==(const l2_xconnect& l) const;
66 * Return the 'singular instance' of the L2 config that matches this
69 std::shared_ptr<l2_xconnect> singular() const;
72 * convert to string format for debug purposes
74 std::string to_string() const;
77 * Dump all l2_xconnects into the stream provided
79 static void dump(std::ostream& os);
82 * Set the VTR operation on the binding/interface
84 void set(const l2_vtr::option_t& op, uint16_t tag);
87 * Static function to find the bridge_domain in the model
89 static std::shared_ptr<l2_xconnect> find(const key_t& key);
93 * Class definition for listeners to OM events
95 class event_handler : public OM::listener, public inspect::command_handler
99 virtual ~event_handler() = default;
102 * Handle a populate event
104 void handle_populate(const client_db::key_t& key);
107 * Handle a replay event
109 void handle_replay();
112 * Show the object in the Singular DB
114 void show(std::ostream& os);
117 * Get the sortable Id of the listener
119 dependency_t order() const;
123 * event_handler to register with OM
125 static event_handler m_evh;
128 * Enque commands to the VPP command Q for the update
130 void update(const l2_xconnect& obj);
133 * Find or Add the singular instance in the DB
135 static std::shared_ptr<l2_xconnect> find_or_add(const l2_xconnect& temp);
138 * It's the OM class that calls singular()
143 * It's the singular_db class that calls replay()
145 friend class singular_db<key_t, l2_xconnect>;
148 * Sweep/reap the object if still stale
153 * replay the object to create it in hardware
158 * A reference counting pointer the interface that this L2 layer
159 * represents. By holding the reference here, we can guarantee that
160 * this object will outlive the interface
162 const std::shared_ptr<interface> m_east_itf;
165 * A reference counting pointer the Bridge-Domain that this L2
166 * interface is bound to. By holding the reference here, we can
167 * guarantee that this object will outlive the BD.
169 const std::shared_ptr<interface> m_west_itf;
172 * HW configuration for the xconnect. The bool representing the
175 HW::item<bool> m_xconnect_east;
178 * HW configuration for the xconnect. The bool representing the
181 HW::item<bool> m_xconnect_west;
184 * HW configuration for the VTR option
186 HW::item<l2_vtr::option_t> m_vtr_op;
189 * The Dot1q tag for the VTR operation
191 uint16_t m_vtr_op_tag;
194 * A map of all L2 interfaces key against the interface's handle_t
196 static singular_db<key_t, l2_xconnect> m_db;
199 std::ostream& operator<<(std::ostream& os, const l2_xconnect::key_t& key);
203 * fd.io coding-style-patch-verification: ON
206 * eval: (c-set-style "mozilla")