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_EMULATION_H__
17 #define __VOM_L2_EMULATION_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_emulation : public object_base
36 * Key type for an L2 emulation in the singular DB
38 typedef interface::key_t key_t;
41 * Construct a new object matching the desried state
43 l2_emulation(const interface& itf);
48 l2_emulation(const l2_emulation& o);
56 * Return the binding's key
58 const key_t& key() const;
61 * Comparison operator - for UT
63 bool operator==(const l2_emulation& l) const;
66 * Return the 'singular instance' of the L2 config that matches this
69 std::shared_ptr<l2_emulation> singular() const;
72 * convert to string format for debug purposes
74 std::string to_string() const;
77 * Dump all l2_emulations into the stream provided
79 static void dump(std::ostream& os);
82 * Static function to find the bridge_domain in the model
84 static std::shared_ptr<l2_emulation> find(const key_t& key);
88 * Class definition for listeners to OM events
90 class event_handler : public OM::listener, public inspect::command_handler
94 virtual ~event_handler() = default;
97 * Handle a populate event
99 void handle_populate(const client_db::key_t& key);
102 * Handle a replay event
104 void handle_replay();
107 * Show the object in the Singular DB
109 void show(std::ostream& os);
112 * Get the sortable Id of the listener
114 dependency_t order() const;
118 * event_handler to register with OM
120 static event_handler m_evh;
123 * Enquue commonds to the VPP command Q for the update
125 void update(const l2_emulation& obj);
128 * Find or Add the singular instance in the DB
130 static std::shared_ptr<l2_emulation> find_or_add(const l2_emulation& temp);
133 * It's the OM class that calls singular()
138 * It's the singular_db class that calls replay()
140 friend class singular_db<key_t, l2_emulation>;
143 * Sweep/reap the object if still stale
148 * replay the object to create it in hardware
153 * A reference counting pointer the interface that this L2 layer
154 * represents. By holding the reference here, we can guarantee that
155 * this object will outlive the interface
157 const std::shared_ptr<interface> m_itf;
160 * HW configuration for the emulation. The bool representing the
163 HW::item<bool> m_emulation;
166 * A map of all L2 emulation configurations
168 static singular_db<key_t, l2_emulation> m_db;
173 * fd.io coding-style-patch-verification: ON
176 * eval: (c-set-style "mozilla")