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/object_base.hpp"
24 #include "vom/singular_db.hpp"
28 * A Class representing the cross connnect of an L2 interface with another
31 class l2_xconnect : public object_base
35 * Key type for an L2 xconnect in the singular DB
37 typedef std::pair<interface::key_t, interface::key_t> key_t;
40 * Construct a new object matching the desried state
42 l2_xconnect(const interface& east_itf, const interface& west_itf);
47 l2_xconnect(const l2_xconnect& o);
55 * Return the xconnect's key
57 const key_t key() const;
60 * Comparison operator - for UT
62 bool operator==(const l2_xconnect& l) const;
65 * Return the 'singular instance' of the L2 config that matches this
68 std::shared_ptr<l2_xconnect> singular() const;
71 * convert to string format for debug purposes
73 std::string to_string() const;
76 * Dump all l2_xconnects into the stream provided
78 static void dump(std::ostream& os);
81 * Static function to find the bridge_domain in the model
83 static std::shared_ptr<l2_xconnect> find(const key_t& key);
87 * Class definition for listeners to OM events
89 class event_handler : public OM::listener, public inspect::command_handler
93 virtual ~event_handler() = default;
96 * Handle a populate event
98 void handle_populate(const client_db::key_t& key);
101 * Handle a replay event
103 void handle_replay();
106 * Show the object in the Singular DB
108 void show(std::ostream& os);
111 * Get the sortable Id of the listener
113 dependency_t order() const;
117 * event_handler to register with OM
119 static event_handler m_evh;
122 * Enque commands to the VPP command Q for the update
124 void update(const l2_xconnect& obj);
127 * Find or Add the singular instance in the DB
129 static std::shared_ptr<l2_xconnect> find_or_add(const l2_xconnect& temp);
132 * It's the OM class that calls singular()
137 * It's the singular_db class that calls replay()
139 friend class singular_db<key_t, l2_xconnect>;
142 * Sweep/reap the object if still stale
147 * replay the object to create it in hardware
152 * A reference counting pointer the interface that this L2 layer
153 * represents. By holding the reference here, we can guarantee that
154 * this object will outlive the interface
156 const std::shared_ptr<interface> m_east_itf;
159 * A reference counting pointer the Bridge-Domain that this L2
160 * interface is bound to. By holding the reference here, we can
161 * guarantee that this object will outlive the BD.
163 const std::shared_ptr<interface> m_west_itf;
166 * HW configuration for the xconnect. The bool representing the
169 HW::item<bool> m_xconnect_east;
172 * HW configuration for the xconnect. The bool representing the
175 HW::item<bool> m_xconnect_west;
178 * A map of all L2 interfaces key against the interface's handle_t
180 static singular_db<key_t, l2_xconnect> m_db;
183 std::ostream& operator<<(std::ostream& os, const l2_xconnect::key_t& key);
187 * fd.io coding-style-patch-verification: ON
190 * eval: (c-set-style "mozilla")