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_BRIDGE_DOMAIN_H__
17 #define __VOM_BRIDGE_DOMAIN_H__
19 #include "vom/enum_base.hpp"
21 #include "vom/inspect.hpp"
22 #include "vom/object_base.hpp"
24 #include "vom/singular_db.hpp"
28 * A base class for all object_base in the VPP object_base-Model.
29 * provides the abstract interface.
31 class bridge_domain : public object_base
35 * Key Type for Bridge Domains in the sigular DB
37 typedef uint32_t key_t;
40 * Bridge Domain Learning mode
42 struct learning_mode_t : enum_base<learning_mode_t>
44 const static learning_mode_t ON;
45 const static learning_mode_t OFF;
49 * Private constructor taking the value and the string name
51 learning_mode_t(int v, const std::string& s);
55 * Bridge Domain ARP termination mode
57 struct arp_term_mode_t : enum_base<arp_term_mode_t>
59 const static arp_term_mode_t ON;
60 const static arp_term_mode_t OFF;
64 * Private constructor taking the value and the string name
66 arp_term_mode_t(int v, const std::string& s);
70 * Bridge Domain MAC aging mode
72 struct mac_age_mode_t : enum_base<mac_age_mode_t>
74 const static mac_age_mode_t ON;
75 const static mac_age_mode_t OFF;
79 * Private constructor taking the value and the string name
81 mac_age_mode_t(int v, const std::string& s);
85 * Bridge Domain Learning mode
87 struct flood_mode_t : enum_base<flood_mode_t>
89 const static flood_mode_t ON;
90 const static flood_mode_t OFF;
94 * Private constructor taking the value and the string name
96 flood_mode_t(int v, const std::string& s);
100 * The value of the defaultbridge domain
102 const static uint32_t DEFAULT_TABLE = 0;
105 * Construct a new object matching the desried state
107 bridge_domain(uint32_t id,
108 const learning_mode_t& lmode = learning_mode_t::ON,
109 const arp_term_mode_t& amode = arp_term_mode_t::ON,
110 const flood_mode_t& fmode = flood_mode_t::ON,
111 const mac_age_mode_t& mmode = mac_age_mode_t::OFF);
116 bridge_domain(const bridge_domain& o);
124 * Comparison operator - for UT
126 bool operator==(const bridge_domain& b) const;
129 * Return the bridge domain's VPP ID
134 * Return the bridge domain's key
136 const key_t& key() const;
139 * Return the matchin 'singular' instance of the bridge-domain
141 std::shared_ptr<bridge_domain> singular() const;
144 * convert to string format for debug purposes
146 std::string to_string(void) const;
149 * Static function to find the bridge_domain in the model
151 static std::shared_ptr<bridge_domain> find(const key_t& key);
154 * Dump all bridge-doamin into the stream provided
156 static void dump(std::ostream& os);
160 * Class definition for listeners to OM events
162 class event_handler : public OM::listener, public inspect::command_handler
166 virtual ~event_handler() = default;
169 * Handle a populate event
171 void handle_populate(const client_db::key_t& key);
174 * Handle a replay event
176 void handle_replay();
179 * Show the object in the Singular DB
181 void show(std::ostream& os);
184 * Get the sortable Id of the listener
186 dependency_t order() const;
190 * Instance of the event handler to register with OM
192 static event_handler m_evh;
195 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
197 void update(const bridge_domain& obj);
200 * Find or add an singular of a Bridge-Domain in the object_base Model
202 static std::shared_ptr<bridge_domain> find_or_add(const bridge_domain& temp);
205 * It's the OM class that calls singular()
210 * It's the singular_db class that calls replay()
212 friend class singular_db<key_t, bridge_domain>;
215 * Sweep/reap the object if still stale
220 * replay the object to create it in hardware
225 * The ID we assign to this BD and the HW result in VPP
227 HW::item<uint32_t> m_id;
230 * The learning mode of the bridge
232 learning_mode_t m_learning_mode;
235 * The ARP termination mode of the bridge
237 arp_term_mode_t m_arp_term_mode;
240 * The flood mode of the bridge
242 flood_mode_t m_flood_mode;
245 * The MAC aging mode of the bridge
247 mac_age_mode_t m_mac_age_mode;
250 * A map of all interfaces key against the interface's name
252 static singular_db<key_t, bridge_domain> m_db;
257 * fd.io coding-style-patch-verification: ON
260 * eval: (c-set-style "mozilla")